class DTPaymentTrackingBatchServiceLoc extends SysOperationServiceBase
{
public void processOperation()
{
CustInvoiceSalesLink custInvoiceSalesLink;
SalesTable salesTable;
InterCompanyPurchSalesReference interCompanyPurchSalesReference;
//TO GET RELATED PURCHASE ORDER FROM INVOICED SALES ID
while select * from custInvoiceSalesLink
join salesTable
where salesTable.SalesId == custInvoiceSalesLink.SalesId
{
select firstonly purchid from interCompanyPurchSalesReference
where interCompanyPurchSalesReference.SalesId == salesTable.SalesId;
if(interCompanyPurchSalesReference.PurchId != "")
{
this.InsertInvoicesDetails(custInvoiceSalesLink,salesTable);
}
}
}
public void InsertInvoicesDetails(CustInvoiceSalesLink _custInvoiceSalesLink,SalesTable _salesTable)
{
CustInvoiceSalesLink custInvoiceSalesLinkloc;
SalesTable salestable;
DTCustomerDetailsTable dTCustomerDetailsTable;
InterCompanyPurchSalesReference InterCompanyPurchSalesReference;
Purchtable purchTable,purchTableloc;
VendTrans vendTrans;
Custtable custtable;
DirPartyTable dirPartyTable;
HCMWORKER HcmWorker;
VendInvoiceJour vendInvoiceJour,vendInvoiceJourloc;
DTPaymentTrackingTbl dTPaymentTrackingTbl,dTPaymentTrackingTblUpdate;
//InterCompanyPurchId PruchId;
container intPruchId;
CustInvoiceId invoiceid;
InterCompanyCompanyId intercompanyId;
AmountCur amountCur;
//SalesId salesId;
VendInvoiceId vendInvoiceId;
VendInvoiceAccount vendInvoiceAccount;
TransDate transDate;
Voucher voucher;
str salesId,salesStatus,value;
AmountMST remainingAmountMST;
AmountMSTDebCred amountMST;
int i, length;
//TO GET THE RELATED PURCHID FROM REFRENCE TABLE.
while select PurchId from InterCompanyPurchSalesReference
where InterCompanyPurchSalesReference.SalesId == _salestable.SalesId
&& salestable.SalesId == _custInvoiceSalesLink.SalesId
{
intPruchId += InterCompanyPurchSalesReference.PurchId;
}
invoiceid = _custInvoiceSalesLink.InvoiceId;
//intercompanyId = salestable.InterCompanyCompanyId;
salesId = _custInvoiceSalesLink.SalesId;
salesStatus = enum2Str(salestable.SalesStatus);
dTPaymentTrackingTbl.DTWorkerName = HcmWorker::find(salesTable.WorkerSalesResponsible).name();
dTPaymentTrackingTbl.InvoiceAccount = _custInvoiceSalesLink.InvoiceAccount;
dTPaymentTrackingTbl.Name = _custInvoiceSalesLink.custTable_OrderAccount().name();
dTPaymentTrackingTbl.CustomerRef = salestable.CustomerRef;
dTPaymentTrackingTbl.SalesId = salesId;
dTPaymentTrackingTbl.InvoiceId = invoiceid;
//TO GET SALES ORDER DETAILS FROM CUSTOMER DETAILS TABLE
select * from dTCustomerDetailsTable
where dTCustomerDetailsTable.InvoiceId == invoiceid
&& dTCustomerDetailsTable.SalesId == salesId
&& dTCustomerDetailsTable.CustAccount == _custInvoiceSalesLink.InvoiceAccount
&& dTCustomerDetailsTable.InvoiceDate == _custInvoiceSalesLink.InvoiceDate;
dTPaymentTrackingTbl.PackingSlipId = dTCustomerDetailsTable.PackingSlipId;
dTPaymentTrackingTbl.InvoiceAmount = dTCustomerDetailsTable.InvoiceAmount;
dTPaymentTrackingTbl.AmountNotSettled = dTCustomerDetailsTable.AmountNotSettled;
dTPaymentTrackingTbl.DTCustInvoicePaymtType = dTCustomerDetailsTable.DTCustInvoicePaymtType;
dTPaymentTrackingTbl.DTInvoiceStatus = salesStatus;
// LOOP TO GET THE DATA OF PURCH TABLE
length = conLen(intPruchId);
for (i = 1; i <= length; i++)
{
value = conPeek(intPruchId,i);
dTPaymentTrackingTbl.InterCompanyPurchId += value;
select * from purchTable
where purchTable.PurchId == value;
dTPaymentTrackingTbl.DTDateTime = purchTable.CreatedDateTime;
while select sum(InvoiceAmount) from vendInvoiceJour
where vendInvoiceJour.PurchId == value
{
amountCur += vendInvoiceJour.InvoiceAmount;
}
dTPaymentTrackingTbl.VendInvoiceAMT = amountCur;
select vendInvoiceJourloc
where vendInvoiceJourloc.PurchId == value;
vendInvoiceId = vendInvoiceJourloc.InvoiceId;
vendInvoiceAccount = vendInvoiceJourloc.InvoiceAccount;
transDate = vendInvoiceJourloc.InvoiceDate;
voucher = vendInvoiceJourloc.LedgerVoucher;
while select * from vendtrans
where vendtrans.Invoice == vendInvoiceId
&& vendtrans.AccountNum == vendInvoiceAccount
&& vendtrans.TransDate == transDate
&& vendtrans.Voucher == voucher
&& vendtrans.TransType == 3
{
amountMST += vendtrans.AmountMST;
remainingAmountMST += vendtrans.remainAmountMST();
}
if(vendtrans)
{
if(amountMST == remainingAmountMST && remainingAmountMST != 0 && amountMST != 0)
{
dTPaymentTrackingTbl.PurchStatus = DTVendInvoicePaymentType::NotPaid;
}
else if(amountMST != remainingAmountMST && remainingAmountMST != 0)
{
dTPaymentTrackingTbl.PurchStatus = DTVendInvoicePaymentType::PartiallyPaid;
}
else if(amountMST != 0 && remainingAmountMST == 0)
{
dTPaymentTrackingTbl.PurchStatus = DTVendInvoicePaymentType::FullyPaid;
}
}
}
select firstonly dTPaymentTrackingTblUpdate
where dTPaymentTrackingTblUpdate.SalesId == dTPaymentTrackingTbl.SalesId
&& dTPaymentTrackingTblUpdate.InterCompanyPurchId == dTPaymentTrackingTbl.InterCompanyPurchId
&& dTPaymentTrackingTblUpdate.InvoiceId == dTPaymentTrackingTbl.InvoiceId
&& dTPaymentTrackingTblUpdate.PackingSlipId == dTPaymentTrackingTbl.PackingSlipId;
if(dTPaymentTrackingTblUpdate.RecId != 0)
{
this.UpdateInvoicesDetails(dTPaymentTrackingTbl);
}
else
{
dTPaymentTrackingTbl.insert();
}
}
class DTPaymentTrackingBatchServiceLoc extends SysOperationServiceBase
{
public void processOperation()
{
CustInvoiceJour custInvoiceJour;
SalesTable salesTable;
InterCompanyPurchSalesReference interCompanyPurchSalesReference;
while select * from custInvoiceJour
join salesTable
where salesTable.SalesId == custInvoiceJour.SalesId
join interCompanyPurchSalesReference
where interCompanyPurchSalesReference.SalesId == salesTable.SalesId
//&& salesTable.SalesId == 'SO09-10000540'
{
this.InsertInvoicesDetails(custInvoiceJour,salesTable);
}
}
public void InsertInvoicesDetails(CustInvoiceJour _custInvoiceJour,SalesTable _salesTable)
{
CustInvoiceJour custInvoiceJourloc;
SalesTable salestable;
DTCustomerDetailsTable dTCustomerDetailsTable;
InterCompanyPurchSalesReference InterCompanyPurchSalesReference;
Purchtable purchTable,purchTableloc;
Purchline purchLine;
Custtable custtable;
DirPartyTable dirPartyTable;
HCMWORKER HcmWorker;
DTPaymentTrackingTbl dTPaymentTrackingTbl,dTPaymentTrackingTblUpdate;
InterCompanyPurchId intPruchId;
CustInvoiceId invoiceid;
InterCompanyCompanyId intercompanyId;
//SalesId salesId;
str salesId,salesStatus;
while select crosscompany * from salestable
join InterCompanyPurchSalesReference
where InterCompanyPurchSalesReference.SalesId == _salestable.SalesId
&& salestable.SalesId == _custInvoiceJour.SalesId
{
intPruchId = InterCompanyPurchSalesReference.PurchId;
invoiceid = _custInvoiceJour.InvoiceId;
//intercompanyId = salestable.InterCompanyCompanyId;
salesId = salestable.SalesId;
salesStatus = enum2Str(salestable.SalesStatus);
dTPaymentTrackingTbl.DTWorkerName = HcmWorker::find(salesTable.WorkerSalesResponsible).name();
dTPaymentTrackingTbl.InvoiceAccount = _custInvoiceJour.InvoiceAccount;
dTPaymentTrackingTbl.Name = _custInvoiceJour.custTable_OrderAccount().name();
dTPaymentTrackingTbl.CustomerRef = salestable.CustomerRef;
while select crosscompany SalesId,PackingSlipId,InvoiceId,InvoiceAmount,AmountNotSettled,
DTCustInvoicePaymtType,DTInvoiceStatus,DataAreaId from dTCustomerDetailsTable
group by SalesId,PackingSlipId,InvoiceId,InvoiceAmount,AmountNotSettled,
DTCustInvoicePaymtType,DTInvoiceStatus,DataAreaId
where dTCustomerDetailsTable.SalesId == salesId
{
dTPaymentTrackingTbl.SalesId = dTCustomerDetailsTable.SalesId;
dTPaymentTrackingTbl.PackingSlipId = dTCustomerDetailsTable.PackingSlipId;
dTPaymentTrackingTbl.InvoiceId = dTCustomerDetailsTable.InvoiceId;
dTPaymentTrackingTbl.InvoiceAmount = dTCustomerDetailsTable.InvoiceAmount;
dTPaymentTrackingTbl.AmountNotSettled = dTCustomerDetailsTable.AmountNotSettled;
dTPaymentTrackingTbl.DTCustInvoicePaymtType = dTCustomerDetailsTable.DTCustInvoicePaymtType;
dTPaymentTrackingTbl.DTInvoiceStatus = salesStatus;
while select crosscompany CustomerRef,sum(LineAmount) from purchLine
join * from purchTable
group by purchTable.PurchId,purchTable.PurchStatus,purchTable.InterCompanyCompanyId,purchTable.CreatedDateTime
where purchLine.PurchId == purchTable.PurchId
&& purchTable.PurchId == intPruchId
{
dTPaymentTrackingTbl.InterCompanyPurchId = purchTable.PurchId;
dTPaymentTrackingTbl.PurchStatus = purchTable.PurchStatus;
dTPaymentTrackingTbl.DTDateTime = purchTable.CreatedDateTime;
dTPaymentTrackingTbl.LineAmount = purchLine.LineAmount;
dTPaymentTrackingTbl.DTEntityName = purchTable.InterCompanyCompanyId;
}
select firstonly dTPaymentTrackingTblUpdate
where dTPaymentTrackingTblUpdate.SalesId == dTPaymentTrackingTbl.SalesId
&& dTPaymentTrackingTblUpdate.InterCompanyPurchId == dTPaymentTrackingTbl.InterCompanyPurchId
&& dTPaymentTrackingTblUpdate.InvoiceId == dTPaymentTrackingTbl.InvoiceId
&& dTPaymentTrackingTblUpdate.PackingSlipId == dTPaymentTrackingTbl.PackingSlipId;
if(dTPaymentTrackingTblUpdate.RecId != 0)
{
this.UpdateInvoicesDetails(dTPaymentTrackingTbl);
}
else
{
dTPaymentTrackingTbl.insert();
}
}
}
}
public void UpdateInvoicesDetails(DTPaymentTrackingTbl _dTPaymentTrackingTbl)
{
DTPaymentTrackingTbl dTPaymentTrackingTbl;
ttsbegin;
select forupdate dTPaymentTrackingTbl
where dTPaymentTrackingTbl.InvoiceId == _dTPaymentTrackingTbl.InvoiceId
&& dTPaymentTrackingTbl.PackingSlipId == _dTPaymentTrackingTbl.PackingSlipId
&& dTPaymentTrackingTbl.SalesId == _dTPaymentTrackingTbl.SalesId
&& dTPaymentTrackingTbl.InterCompanyPurchId == _dTPaymentTrackingTbl.InterCompanyPurchId;
if(dTPaymentTrackingTbl)
{
dTPaymentTrackingTbl.InvoiceAccount = _dTPaymentTrackingTbl.InvoiceAccount;
dTPaymentTrackingTbl.Name = _dTPaymentTrackingTbl.Name;
dTPaymentTrackingTbl.DTWorkerName = _dTPaymentTrackingTbl.DTWorkerName;
dTPaymentTrackingTbl.SalesId = _dTPaymentTrackingTbl.SalesId;
dTPaymentTrackingTbl.PackingSlipId = _dTPaymentTrackingTbl.PackingSlipId;
dTPaymentTrackingTbl.InvoiceId = _dTPaymentTrackingTbl.InvoiceId;
dTPaymentTrackingTbl.InvoiceAmount = _dTPaymentTrackingTbl.InvoiceAmount;
dTPaymentTrackingTbl.AmountNotSettled = _dTPaymentTrackingTbl.AmountNotSettled;
dTPaymentTrackingTbl.DTCustInvoicePaymtType = _dTPaymentTrackingTbl.DTCustInvoicePaymtType;
dTPaymentTrackingTbl.DTInvoiceStatus = _dTPaymentTrackingTbl.DTInvoiceStatus;
dTPaymentTrackingTbl.InterCompanyPurchId = _dTPaymentTrackingTbl.InterCompanyPurchId;
dTPaymentTrackingTbl.PurchStatus = _dTPaymentTrackingTbl.PurchStatus;
dTPaymentTrackingTbl.DTDateTime = _dTPaymentTrackingTbl.DTDateTime;
dTPaymentTrackingTbl.CustomerRef = _dTPaymentTrackingTbl.CustomerRef;
dTPaymentTrackingTbl.LineAmount = _dTPaymentTrackingTbl.LineAmount;
dTPaymentTrackingTbl.update();
}
ttscommit;
}
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 290,277 Super User 2024 Season 2
Martin Dráb 228,135 Most Valuable Professional
nmaenpaa 101,148