blocking creation of Free text Invoice for a customer whose invoice yr & membership no has already a invoice posted.

Dear All,

I have following query :

Scenario: I have created a module name membership module where i have option to generate unposted free text invoice . the parameter which i provide in my batch of billing are invoice yr, membership num . Each membership num is attached to a customer . so my batch creates a FTI in AR> FTI with combination of these fileds. i have already added a invoice yr and membership num filed in my CustInvoiceTable. Now once a invoice created through my batch is posted it should not allow the creation of another invoice of same combination until and unless it is reversed. when i reverse that invoice and then create another invoice (of same combination) and post it, till here its working fine…2nd time after creation of invoice and posting i have not reversed it, but here is the problem, it is allowing me to create the FTI of same combination which should not happen.

simply, If my invoice is reversed i can create new invoice. after creation and posting it should not allow me to create new unposted invoice.

Kindly help where i am missing.

following code i have written.:

public void run()

{

GOD_PrimaryMemSubscriptionFixedRate fixed;

GOD_Membership membership,god_memberShipSelect;

GOD_MembershipType type;

// KK Modified

CustTrans trans;

CustInvoiceJour jour;

// KK Modified

CustInvoiceTable custInvoiceTable,custInvoiceCheck;

CustTable custTable;

CustInvoiceLine custInvoiceLine;

ServiceCodeTable_IN code;

int lineNum;

CustInvoiceLineTaxExtensionIN custInvoiceLineTaxExtensionIN;

GOD_MembershipNumber currentMemberShip;

GOD_MembershipPostingProfile god_Post;

container conLedgerDimension;

AXCustInvoiceLine line;

AxCustInvoiceTable intable;

Struct struct;

container ledgerDimension;

DimensionDefault defaultDimension;

real calcValue;

int DiffYear;

int i = 0;

int j = 0;

GOD_Membership gOD_Membership;

GOD_MembershipNum gOD_MembershipNum;

GOD_GrossSalesTurnover gOD_GrossSalesTurnover,lastGSTAmount;

real calculatedAmount;

GOD_PrimaryMemSubscriptionRate gOD_PrimaryMemSubscriptionRate;

boolean insertEntrance = false,interNationalFlag = false,gstAmount = false , nGstAmount = false, reverseTrans;

GOD_BillingCycle goD_BillingCycle;

str 2 quaters;

GOD_InternationalSubscriptionRate internationalSubscriptionRate;

;

line = new AXCustInvoiceLine();

intable = new AxCustInvoiceTable();

struct = new Struct();

ttsbegin;

while(queryrun.next())

{

ledgerDimension = conNull();

conLedgerDimension = conNull();

gstAmount = false ;

nGstAmount = false;

membership = queryrun.get(tableNum(GOD_Membership));

custInvoiceCheck.clear();

// KK Modified- 18/12/2014

trans.clear();

// For inactive members -KK modified -12/24/2014

if(membership.MembershipStatus == GOD_MembershipStatus::Active)

{

// KK modified -12/24/2014

select * from custInvoiceCheck

where custInvoiceCheck.GOD_InvoiceYear == InvoiceYr

&& custInvoiceCheck.GOD_MembershipNum == membership.MembershipNum

&& custInvoiceCheck.OrderAccount == membership.Customer ;

select * from trans where trans.Invoice == custInvoiceCheck.InvoiceId;

reverseTrans = TransactionReversalTrans::findTransactionReversalTrans(tableNum(CustTrans), trans.RecId).Reversed ;

// KK Modified -18/12/2014

// if (!custInvoiceCheck) // KK Commented -18/12/2014

if (reverseTrans|| !custInvoiceCheck ) // KK Modified

{

calculatedAmount = 0;

gOD_MembershipNum = membership.MembershipNum;

select fixed

where fixed.MembershipType == membership.MembershipType;

select god_Post

where god_Post.MembershipType == membership.MembershipType

&& god_Post.Region == membership.Region;

if (membership.DateOfJoining >= str2date(“01-Jan-”+int2str(InvoiceYr),123) && membership.DateOfJoining <= str2date(“31-Dec-”+int2str(InvoiceYr),123))

insertEntrance = true;

conLedgerDimension = [“MAINACCOUNT”, god_Post.MainAccountId];

if(membership.PrimaryMemberRegion !="")

{

struct.add(‘Region’,membership.PrimaryMemberRegion );

i+=1;

}

struct.add(‘Group’ , ‘Membership’);

i+=1;

if(membership.Location !="")

{

struct.add(‘Location’,membership.Location);

i+=1;

}

if(membership.State !="")

{

Struct.add(‘Departments’,membership.State);

i+=1;

}

if(membership.dataAreaId == ‘nr’ )

{

Struct.add(‘Analysis’,‘Membership Subscription - NR’);

i+=1;

}

if( membership.dataAreaId == ‘er’)

{

Struct.add(‘Analysis’,‘Membership Subscription - ER’);

i+=1;

}

if( membership.dataAreaId == ‘wr’ )

{

Struct.add(‘Analysis’,‘Membership Subscription - WR’);

i+=1;

}

if( membership.dataAreaId == ‘sr’)

{

Struct.add(‘Analysis’,‘Membership Subscription - SR’);

i+=1;

}

custInvoiceTable.clear();

custTable = CustTable::find(membership.Customer);

custInvoiceTable.initFromCustTable(custTable);

custInvoiceTable.OrderAccount = membership.Customer;

custInvoiceTable.GOD_CustAddress = membership.Address;//LogisticsPostalAddress::findRecId(CustInvoiceTable.PostalAddress).Address;

custInvoiceTable.InvoiceDate = InvoiceDate;

custInvoiceTable.numberSequenceGroup = “MEM-” + custInvoiceLine.dataAreaId;// KK modifed(21-11-2014)

custInvoiceTable.GOD_InvoiceYear = InvoiceYr;

custInvoiceTable.GOD_MembershipNum = membership.MembershipNum;

// KK Modified -18/12/2014 - updating Bank Account

if( membership.dataAreaId == ‘nr’)

{

custInvoiceTable.GOD_BankAccount = “NR/ICICI/0420”;

}

if( membership.dataAreaId == ‘sr’)

{

custInvoiceTable.GOD_BankAccount = “SR/ICICI/4914”;

}

if( membership.dataAreaId == ‘er’)

{

custInvoiceTable.GOD_BankAccount = “ER/ICICI/9180”;

}

if( membership.dataAreaId == ‘wr’)

{

custInvoiceTable.GOD_BankAccount = “WR/ICICI/8006”;

}

// KK Modified -18/12/2014 - updating Bank Account

ledgerDimension += struct.fields();

for(j=1 ; j<= i ; j++)

{

ledgerDimension += struct.fieldName(j);

ledgerDimension += struct.valueIndex(j);

}

defaultDimension = AxdDimensionUtil::getDimensionAttributeValueSetId(ledgerDimension);

custInvoiceTable.DefaultDimension =defaultDimension;

if (membership.MembershipType == ‘International Membership’)

custInvoiceTable.CurrencyCode = ‘USD’;

custInvoiceTable.insert();

select firstOnly code

where code.ServiceCode == ‘MEMBERSHIP’;

select god_Post

where god_Post.MembershipType == membership.MembershipType

&& god_Post.Region == membership.Region;

custInvoiceLine.clear();

custInvoiceLine.initValue();

custInvoiceLine.initFromCustInvoiceTable(custInvoiceTable);

if (insertEntrance)

{

if (mthOfYr(membership.DateOfJoining ) <= 3 )

quaters = ‘Q1’ ;

else if (mthOfYr(membership.DateOfJoining ) >= 4 && mthOfYr(membership.DateOfJoining ) <= 6 )

quaters = ‘Q2’ ;

else if (mthOfYr(membership.DateOfJoining ) >= 7 && mthOfYr(membership.DateOfJoining ) <= 9)

quaters = ‘Q3’ ;

else if (mthOfYr(membership.DateOfJoining ) >= 10 && mthOfYr(membership.DateOfJoining ) <= 12)

quaters = ‘Q4’ ;

}

select goD_BillingCycle where goD_BillingCycle.Quarter == quaters;

switch (membership.MembershipType)

{

case “Primary Membership” :

if (membership.FixedSubscriptionCheck == NoYes::Yes)

{

custInvoiceLine.AmountCur = membership.FixedSubscriptionAmount;

// KK Modified - 17/12/2014

custInvoiceLine.Description = strFmt(‘Membership Subscription for ’ + int2str(InvoiceYr) + ’ CII(’ + CompanyInfo::findDataArea(membership.dataAreaId).Name + ‘)’ + ’ Period :’ +‘1- jan- ‘+ int2str(InvoiceYr)+’ to’ + ’ 31-Dec- ’ + int2str(InvoiceYr) + ’ On gross sales turnover 31 - March ’ + int2str(InvoiceYr-1) + ’ Rs.____________________’);// + int642str( custInvoiceLine.AmountCur) );

// KK Modified -17/12/2014

}

else

{

select gOD_GrossSalesTurnover WHERE gOD_GrossSalesTurnover.MembershipNumber == membership.MembershipNum

&& gOD_GrossSalesTurnover.ToYear == (InvoiceYr -1);

select lastGSTAmount order by fromyear desc where lastGSTAmount.MembershipNumber == membership.MembershipNum

&& lastGSTAmount.ToYear <= (InvoiceYr)

&& lastGSTAmount.GST != 0;

DiffYear = InvoiceYr - lastGSTAmount.ToYear;

if (gOD_GrossSalesTurnover.GST )

{

calculatedAmount = gOD_GrossSalesTurnover.GST;

gstAmount = true;

}

else

{

calculatedAmount = gOD_GrossSalesTurnover.NotionalGST;

nGstAmount = true;

}

select gOD_PrimaryMemSubscriptionRate where gOD_PrimaryMemSubscriptionRate.From <= calculatedAmount

&& gOD_PrimaryMemSubscriptionRate.TO >= calculatedAmount;

if (goD_BillingCycle.PercentageOfSubcription /100 > 0)

{

custInvoiceLine.AmountCur = gOD_PrimaryMemSubscriptionRate.SubscriptionAmount * goD_BillingCycle.PercentageOfSubcription /100 ;

if ( gstAmount == true)

custInvoiceLine.Description = strFmt(‘Membership Subscription for ’ + int2str(InvoiceYr) + ’ CII(’ + CompanyInfo::findDataArea(membership.dataAreaId).Name + ‘)’ + ’ Period :’ +date2str(membership.DateOfJoining,123,1,3,3,3,2)+’ to’ + ’ 31-Dec- ’ + int2str(InvoiceYr) + ’ On gross sales turnover 31 - March ’ + int2str(InvoiceYr-1) + ’ Rs.’ + int642str(calculatedAmount) );// KK modified(31-March added) on 16/12/2014

else if (nGstAmount == true )

custInvoiceLine.Description = strFmt(‘Membership Subscription for ’ + int2str(InvoiceYr) + ’ CII(’ + CompanyInfo::findDataArea(membership.dataAreaId).Name + ‘) Period : ’ + date2str(membership.DateOfJoining,123,1,3,3,3,2)+ ’ to’ + ’ 31-Dec-’ + int2str(InvoiceYr) + ‘On Estimated Gross Sale Turnover During the Year End 31 - March ’ + int2str(lastGSTAmount.ToYear) + ’ Rs.’+ int642str(lastGSTAmount.GST)) + ’ Add :(Rule 10 Explanation(V) of The Confederation As Amended on 1st January,1997 20% increase in Sales Turnover In Each year for the Last’ +int2str(DiffYear -1) + ’ year(s) cumulative Rs.’ + int642str(gOD_GrossSalesTurnover.NotionalGST-lastGSTAmount.GST)+ ’ Gross Sales Turnover for the purpose of current years membership subscription Rs.’ + int642str(gOD_GrossSalesTurnover.NotionalGST);

}

else

{

custInvoiceLine.AmountCur = gOD_PrimaryMemSubscriptionRate.SubscriptionAmount ;

if ( gstAmount == true)

custInvoiceLine.Description = strFmt(‘Membership Subscription for ’ + int2str(InvoiceYr) + ’ CII(’ + CompanyInfo::findDataArea(membership.dataAreaId).Name + ‘)’ + ’ Period ’ +‘1- jan- ‘+ int2str(InvoiceYr)+’ to’ + ’ 31-Dec- ’ + int2str(InvoiceYr) + ’ On gross sales turnover during the year end 31 - March’ + int2str(InvoiceYr-1) + ’ Rs.’ + int642str(calculatedAmount) );// KK modified(31-March added) on 16/12/2014

else if (nGstAmount == true )

custInvoiceLine.Description = strFmt(‘Membership Subscription for ’ + int2str(InvoiceYr) + ’ CII(’ + CompanyInfo::findDataArea(membership.dataAreaId).Name + ‘) Period : ’ + ‘1- jan- ‘+ int2str(InvoiceYr)+ ’ to’ + ’ 31-Dec-’ + int2str(InvoiceYr) + ‘On Estimated Gross Sale Turnover During the Year End 31 - March ’ + int2str(lastGSTAmount.ToYear) + ’ Rs.’+ int642str(lastGSTAmount.GST)) + ’ Add :(Rule 10 Explanation(V) of The Confederation As Amended on 1st January,1997 20% increase in Sales Turnover In Each year for the Last’ +int2str(DiffYear -1) + ’ year(s) cumulative Rs.’ + int642str(gOD_GrossSalesTurnover.NotionalGST-lastGSTAmount.GST)+ ’ Gross Sales Turnover for the purpose of current years membership subscription Rs.’ + int642str(gOD_GrossSalesTurnover.NotionalGST);

}

custInvoiceLine.InvoiceTxt = custInvoiceLine.Description ;

}

break;

case “Multiple Membership” :

SELECT gOD_GrossSalesTurnover WHERE gOD_GrossSalesTurnover.MembershipNumber == membership.MembershipNum

&& gOD_GrossSalesTurnover.ToYear == (InvoiceYr -1);

select lastGSTAmount order by fromyear desc where lastGSTAmount.MembershipNumber == membership.MembershipNum

&& lastGSTAmount.ToYear <= (InvoiceYr)

&& lastGSTAmount.GST != 0;

DiffYear = InvoiceYr - gOD_GrossSalesTurnover.ToYear;

if (gOD_GrossSalesTurnover.GST )

calculatedAmount = gOD_GrossSalesTurnover.GST;

else

calculatedAmount = gOD_GrossSalesTurnover.NotionalGST;

select gOD_PrimaryMemSubscriptionRate where gOD_PrimaryMemSubscriptionRate.From <= calculatedAmount

&& gOD_PrimaryMemSubscriptionRate.TO >= calculatedAmount;

calcValue = gOD_PrimaryMemSubscriptionRate.SubscriptionAmount * 15/100;

if (calcValue >= 2000)

{