public void CreatePaymentJournal(AccountNum _accountNum, CurrencyCode _currencyCode , str _invoiceNum , SalesTable _salestable)
{
CustTable CustTable,CustTableBank;
Ledgerjournalname ledgerjournalname;
LedgerjournalTable LedgerjournalTable;
LedgerjournalTrans LedgerjournalTrans;
LedgerjournalCheckPost LedgerjournalCheckPost;
BIShopifyParameter _shopifyParamter;
NumberSeq numberSeq;
;
select firstOnly _shopifyParamter;
select firstOnly CustTable where custTable.AccountNum == _accountNum;
//select firstOnly CustTableBank where custTable.AccountNum like “BNK.01”;
// create journal
ttsBegin;
LedgerjournalTable.JournalName = _shopifyParamter.JournalName;
LedgerjournalTable.initFromLedgerJournalName();
LedgerjournalTable.JournalNum = JournalTableData::newTable(LedgerjournalTable).nextJournalId();
LedgerjournalTable.insert();
ttsCommit;
ttsBegin;
// create journal Lines
// numberSeq = NumberSeq::newGetVoucherFromId((ledgerjournalname.NumberSequenceTable));
numberSeq = NumberSeq::newGetVoucherFromId(LedgerJournalName::find(_shopifyParamter.JournalName).NumberSequenceTable, true, false, UnknownNoYes::No);
LedgerjournalTrans.Voucher = numberSeq.voucher();
LedgerjournalTrans.JournalNum = LedgerjournalTable.JournalNum;
LedgerjournalTrans.CurrencyCode = _currencyCode;
LedgerjournalTrans.ExchRate = Currency::exchRate(LedgerjournalTrans.CurrencyCode);
LedgerjournalTrans.AccountType = LedgerJournalACType::Cust;
LedgerjournalTrans.parmAccount(CustTable.AccountNum,LedgerjournalTrans.AccountType);
LedgerjournalTrans.Txt = 'Shopify Customer payment journal';
// LedgerjournalTrans.Invoice =_invoiceNum ;
LedgerjournalTrans.MarkedInvoice =_invoiceNum ;
LedgerjournalTrans.AmountCurCredit = abs(CustTrans::findFromInvoice(_invoiceNum,CustTable.AccountNum).AmountCur) ;
LedgerjournalTrans.PaymMode = _salestable.PaymMode;
LedgerjournalTrans.TransDate = systemDateGet(); //mkDate(3,5,2022);
LedgerjournalTrans.TransactionType = LedgerTransType::Payment;
LedgerjournalTrans.OffsetAccountType = CustPaymModeTable::find(_salestable.PaymMode).AccountType;// LedgerJournalACType::Bank;
LedgerjournalTrans.OffsetLedgerDimension= CustPaymModeTable::find(_salestable.PaymMode).PaymentLedgerDimension;// DimensionStorage::getDynamicAccount(this.getPamenAccount(_salestable.PaymMode), CustPaymModeTable::find(_salestable.PaymMode).AccountType);
LedgerjournalTrans.DefaultDimension = CustTable::find(CustTable.AccountNum).DefaultDimension;
LedgerjournalTrans.OffsetDefaultDimension = CustTable::find(CustTable.AccountNum).DefaultDimension;
LedgerjournalTrans.LedgerDimension = DimensionStorage::getDynamicAccount(CustTable.AccountNum, LedgerJournalACType::Cust);
LedgerjournalTrans.PaymReference = 'Shopify';
LedgerjournalTrans.insert();
ttsCommit;
info(strFmt("Payment Journal Created %1",LedgerjournalTrans.JournalNum));
// posting
LedgerjournalCheckPost = LedgerjournalCheckPost::newLedgerJournalTable(LedgerjournalTable,NoYes::Yes);
LedgerjournalCheckPost.run();
this.AutosettlePayment(_accountNum,_invoiceNum , LedgerjournalTrans.Voucher);
}
Settle transactions
public void AutosettlePayment( AccountNum custAccount, InvoiceId invoiceNum , Voucher Voucher)
{
CustTable custTable;
CustTrans invCustTrans, payCustTrans;
SpecTransManager manager;
CustVendTransData custVendTransData;
;
custTable = CustTable::find(custAccount);
// Find the oldest unsettled invoice
select firstonly invCustTrans
// order by TransDate asc
where invCustTrans.AccountNum == custTable.AccountNum &&
invCustTrans.TransType == LedgerTransType::Sales &&
invCustTrans.Invoice == invoiceNum ;
// !invCustTrans.closed;
// Find the oldest unsettled payment
select firstonly payCustTrans
// order by TransDate asc
where payCustTrans.AccountNum == custTable.AccountNum &&
payCustTrans.TransType == LedgerTransType::Payment &&
payCustTrans.Voucher == Voucher ;
// && !payCustTrans.closed;
ttsbegin;
// Create an object of the CustVendTransData class with the invoice transaction as parameter
custVendTransData = CustVendTransData::construct(invCustTrans);
// Mark it for settlement
custVendTransData.markForSettlement(CustTable);
// Create an object of the CustVendTransData class with the payment transaction as parameter
custVendTransData = CustVendTransData::construct(payCustTrans);
//mark it for settlement
custVendTransData.markForSettlement(CustTable);
ttscommit;
// Settle all marked transactions
if(CustTrans::settleTransact(custTable, null, true,
SettleDatePrinc::DateOfPayment, systemdateget()))
info("Transactions settled");
}