Hi Rajdip,
I wrote some quick (and dirty) code for you...
hopefully it will give you a good indication on what needs to be done..
AmountCur sumTransAmountCur;
CustInvoiceSalesLink custInvoiceSalesLink;
CustTable custTable;
LedgerJournalTable ledgerJournalTable;
LedgerJournalTrans ledgerJournalTrans;
CustTrans custTrans;
CustTransOpen custTransOpen;
CustInvoiceJour custInvoiceJour;
Specification_OffsetVoucher specOffsetVoucher;
Num orderID; // = this will be your order id..
;
// find the custTable record
custTable = CustTable::find(this.getInvoiceAccount());
// create a specification offset voucher for the current customer
specOffsetVoucher =
new Specification_OffsetVoucher(custTable.tableId, custTable.recID);
// clear any marked transactions
specOffsetVoucher.deleteSpecifications();
while select RecID, AmountCur from custTransOpen
join CurrencyCode from custTrans
join Voucher from ledgerJournalTrans
join JournalNum from ledgerJournalTable
where ledgerJournalTrans.JournalNum == ledgerJournalTable.JournalNum
&& custTrans.AccountNum == custTable.AccountNum
&& custTrans.Voucher == ledgerJournalTrans.Voucher
&& custTransOpen.RefRecId == custTrans.RecId
{
sumTransAmountCur += custTransOpen.AmountCur;
specOffsetVoucher.create(custTransOpen.TableId,
custTransOpen.RecId,
custTransOpen.AmountCur,
custTrans.CurrencyCode);
}
//Clear table buffers... being over cautious
custTransOpen = null;
custTrans = null;
custInvoiceJour = null;
// add open invoice transactions to the offset voucher
while select RecID, AmountCur from custTransOpen
join CurrencyCode from custTrans
//join LedgerVoucher from custInvoiceJour
join LedgerVoucher,salesid from CustInvoiceJour
join salesID,origSalesID from custInvoiceSalesLink
where custInvoiceSalesLink.origSalesId == orderID
&& custInvoiceJour.SalesId == custInvoiceSalesLink.salesId
&& custTrans.AccountNum == custTable.AccountNum
&& custTrans.Voucher == custInvoiceJour.LedgerVoucher
&& custTransOpen.RefRecId == custTrans.RecId
{
sumTransAmountCur += custTransOpen.AmountCur;
specOffsetVoucher.create(custTransOpen.TableId,
custTransOpen.RecId,
custTransOpen.AmountCur,
custTrans.CurrencyCode);
}
// only settle if:
// 1) the transactions balance, or
// 2) the full sales amount has been invoiced
// or any other business logic
if (// apply the logic explaind above) )
{
// settle the transactions
custTrans::settleTransact(custTable);
}
else
{
specOffsetVoucher.deleteSpecifications();
}
let us know if you have any more questions.
regards,
Mohammed Rasheeed
www.dynamic-ax.co.uk