Daily Journal Create
//daily journal create and payment and settled
//Class Declaration .......................public Class DailyJournalCreate
{
ledgerJournalTableExt ledgerJournalTableExt;
LedgerJournalTransExt ledgerJournalTransExt;
ledgerJournalTable ledgerJournalTableloc;
ledgerJournalTrans ledgerJournalTransloc;
}
//Importing journals---------------------------------------------------------------(method)
Public void CImport(LedgerJournalTrans _ledgerJournalTrans,int _row)
{
int WrkShtNum;
COMVariantType type;
Name AccountTypeId,markedInvoice,dim3,dim4,dim5,AccountNum,LedgerAccountValue,
LedgerOffsetAccountValue,OffsetAccount,dim6,dim7,offdim1,
formatValue,offdim3,offdim4,offdim5,offdim6,offdim7;
LedgerJournalTransTaxExtensionIN LedgerJournalTransTaxExtensionIN;
LedgerDimensionAccount LedgerDim,DefDimension;
LedgerDimensionAccount OffsetledgerDim;
LedgerJournalTrans ledgerJournalTrans;
ledgerJournalTable ledgerJournalTable,ledgerJournalTab;
LedgerJournalACType OffsetAccountType;
TransDate transDate;
CurrencyCode currencyCode;
NoYes noYes;
LedgerJournalNameId ledgerJournalNameId;
numberSeq numberSeq;
AmountCur AmountCurCredit,AmountCurDebit;
boolean value;
SalesParameters salesParameters;
LedgerJournalCheckPost _LedgerJournalCheckPost;
CustTransOpen custTransOpen;
DimensionAttributeValueCombination dim;
AccountNum journal;
int i,j;
int row;
str 250 error;
Dimension accountingRegion;
recid ledger;
select salesParameters;
if(_row==1)
{
ttsbegin;
ledgerJournalTableloc.JournalName = salesParameters.CPayOffJournalName;
ledgerJournalTableloc.initFromLedgerJournalName(ledgerJournalTableloc.JournalName);
ledgerJournalTableloc.insert();
select ledgerJournalTableExt
where ledgerJournalTableExt.LedgerJournalTable == ledgerJournalTableloc.RecId;
if(!ledgerJournalTableExt)
{
ledgerJournalTableExt.LedgerJournalTable = ledgerJournalTableloc.RecId;
ledgerJournalTableExt.insert();
}
ttsCommit;
}
select ledgerJournalTab where ledgerJournalTab.journalnum == ledgerJournalTableloc.JournalNum;
journal = ledgerJournalTab.JournalNum;
ttsBegin;
ledgerJournalTransloc.initValue();
ledgerJournalTransloc.initFromLedgerJournalTable_LT(ledgerJournalTableloc);
numberSeq = NumberSeq::newGetVoucherFromCode(NumberSequenceTable::find(ledgerJournalName::find(salesParameters.CICPayOffJournalName).NumberSequenceTable).NumberSequence);
ledgerJournalTransloc.voucher = numberseq.voucher();
ledgerJournalTransloc.TransDate = _ledgerJournalTrans.TransDate;
ledgerJournalTransloc.CurrencyCode = _ledgerJournalTrans.CurrencyCode;
ledgerJournalTransloc.Company = curext();
ledgerJournalTransloc.OffsetCompany = _ledgerJournalTrans.OffsetCompany;
ledgerJournalTransloc.AccountType = LedgerJournalACType::Cust;
ledgerJournalTransloc.JournalNum = ledgerJournalTableloc.JournalNum;
ledgerJournalTransloc.DefaultDimension = _ledgerJournalTrans.DefaultDimension;
select dim where dim.RecId == _ledgerJournalTrans.ledgerdimension;
ledger = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum(salesParameters.CPayOffLedger), _ledgerJournalTrans.DefaultDimension);
ledgerJournalTransloc.LedgerDimension = dim.RecId;
ledgerJournalTransloc.OffsetLedgerDimension = ledger;
LedgerAccountValue = dim.DisplayValue;
MarkedInvoice = _ledgerJournalTrans.MarkedInvoice;
ledgerJournalTransloc.Txt = _ledgerJournalTrans.Txt;
AmountCurCredit = _ledgerJournalTrans.AmountCurCredit;
AmountCurDebit = _ledgerJournalTrans.AmountCurDebit;
OffsetAccountType = LedgerJournalACType::Ledger;
//journalTrans.clearField(fieldNum(ledgerJournalTrans,offsetLedgerDimension), false);
//LedgerOffsetAccountValue = ledger;
//AccountTypeId = 0001;
//ledgerJournalTransloc.PaymMode = formatcheck(10);
//ledgerJournalTransloc.PaymReference = formatcheck(11);
/// ledgerJournalTransloc.CICDrawername = 'ABC';
ledgerJournalTransloc.Approved = NoYes::Yes;
ledgerJournalTransloc.Approver = HcmWorker::userId2Worker(curUserId());
ledgerJournalTransloc.Due = ledgerJournalTransloc.TransDate;
ledgerJournalTransloc.TransactionType = LedgerTransType::Payment;
if(LedgerAccountValue)
{
ledgerDim = DimensionStorage::getDynamicAccount(LedgerAccountValue, ledgerJournalTransloc.AccountType);
ledgerJournalTransloc.LedgerDimension = DimensionAttributeValueCombination::find(ledgerDim).Recid;
if(LedgerJournalTransloc.AccountType == LedgerJournalACType::cust)
{
LedgerJournalTransloc.PostingProfile = CustParameters::findByCompany(LedgerJournalTransloc.Company).PostingProfile;
}
if(LedgerJournalTransloc.AccountType == LedgerJournalACType::Vend)
{
LedgerJournalTransloc.PostingProfile = VendParameters::find().PostingProfile;
}
}
ledgerJournalTransloc.OffsetAccountType = OffsetAccountType;
if(LedgerOffsetAccountValue)
{
if(ledgerJournalTransloc.OffsetAccountType == LedgerJournalACType::Ledger)
{
OffsetledgerDim = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum(LedgerOffsetAccountValue), DefDimension);
ledgerJournalTransloc.OffsetLedgerDimension = OffsetledgerDim;
}
else
{
OffsetledgerDim = DimensionStorage::getDynamicAccount(LedgerOffsetAccountValue, ledgerJournalTransloc.OffsetAccountType);
ledgerJournalTransloc.OffsetLedgerDimension = DimensionAttributeValueCombination::find(OffsetledgerDim).Recid;
}
}
ledgerJournalTransloc.LineNum = ledgerJournalTrans::lastLineNum(ledgerJournalTransloc.JournalNum) + 1;
ledgerJournalTransloc.ExchRate = Currency::exchRate(ledgerJournalTransloc.CurrencyCode, ledgerJournalTransloc.TransDate);
ledgerJournalTransloc.insert();
ledgerJournalTransExt.LedgerJournalTrans = ledgerJournalTransloc.RecId;
ledgerJournalTransExt.AccountTypeId = AccountTypeId;
ledgerJournalTransExt.insert();
ledgerJournalTransTaxExtensionIN.LedgerJournalTrans = ledgerJournalTransloc.RecId;
ledgerJournalTransTaxExtensionIN.TaxInformation_IN = TaxInformation_IN::findDefaultbyLocation(CompanyInfo::findByCompany_IN().PrimaryAddressLocation).RecId;
ledgerJournalTransTaxExtensionIN.insert();
if (ledgerJournalTransloc.AccountType == LedgerJournalACType::Cust)
{
value = this.customersettlement(_ledgerJournalTrans.MarkedInvoice,_ledgerJournalTrans.AmountCurCredit,dim.DisplayValue);
}
select count(RecId) from ledgerJournalTrans where ledgerJournalTrans.JournalNum == _ledgerJournalTrans.JournalNum;
select ledgerJournalTable where ledgerJournalTable.JournalNum == journal;
if (!value && ledgerJournalTrans.RecId==_row)
{
_LedgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable,noYes::Yes);//(journalTable.ledgerJournalTable(),NoYes::Yes);
_LedgerJournalCheckPost.run();
ttscommit;
}
}
//Payment of Journal-----------------------------------------------------(Method)
public void CICPayoffJournalImport(LedgerJournalTrans _ledgerJournalTrans)
{
AxLedgerJournalTable journalTable;
AxLedgerJournalTrans journalTrans;
container _acctPattern;
container _offSetAcctPattern;
LedgerJournalTable _LedgerJournalTable;
LedgerJournalCheckPost _LedgerJournalCheckPost;
DimensionAttributeValueCombination dim;
SalesParameters salesParameters;
recid ledger;
;
JournalTable = new AxLedgerJournalTable();
JournalTrans = new AxLedgerJournalTrans();
select salesParameters;
journalTable.parmJournalName(salesParameters.CPayOffJournalName);
journalTable.save();
journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
journalTrans.parmTransDate(_ledgerJournalTrans.TransDate);
journalTrans.parmCurrencyCode(_ledgerJournalTrans.CurrencyCode);
journalTrans.parmAmountCurDebit(_ledgerJournalTrans.AmountCurDebit);
journalTrans.parmAmountCurCredit(_ledgerJournalTrans.AmountCurCredit);
journalTrans.parmDefaultDimension(_ledgerJournalTrans.DefaultDimension);
journalTrans.parmInvoice(_ledgerJournalTrans.MarkedInvoice);
journalTrans.parmTransactionType(LedgerTransType::GeneralJournal);
journalTrans.parmAccountType(LedgerJournalACType::Cust);
journalTrans.parmOffsetAccountType(LedgerJournalACType::Ledger);
select dim where dim.RecId == _ledgerJournalTrans.ledgerdimension;
journalTrans.parmLedgerDimension(dim.RecId);
//journalTrans.parmLedgerDimension(DimensionDefaultingService::serviceCreateLedgerDimFromLedgerDim(_GeneralJournalAccountEntry.LedgerDimension));
journalTrans.clearField(fieldNum(ledgerJournalTrans,offsetLedgerDimension), false);
ledger = DimensionDefaultingService::serviceCreateLedgerDimension(DimensionStorage::getDefaultAccountForMainAccountNum(salesParameters.CICPayOffLedger), _ledgerJournalTrans.DefaultDimension);
journalTrans.parmOffsetLedgerDimension(ledger);
this.customersettlement(_ledgerJournalTrans.MarkedInvoice,_ledgerJournalTrans.AmountCurCredit,dim.DisplayValue);
journalTrans.save();
_LedgerJournalCheckPost = LedgerJournalCheckPost::newLedgerJournalTable(journalTable.ledgerJournalTable(),NoYes::Yes);
_LedgerJournalCheckPost.run();
}
//Customer Settlement-------------------------------------------------------------(Method)
public boolean customerSettlement(InvoiceId invoice, amountcur Credit,CustAccount accountNum)
{
custvendopentransmanager manager;
CustTransOpen CustTransOpen;
CustTrans CustTransExt;
ExchangeRateHelper exchangeRateHelper;
AmountCur totalSettlement;
boolean value;
select CustTransopen where CustTransOpen.AccountNum == accountNum
join CustTransExt where CustTransExt.Invoice == invoice
&& CustTransExt.RecId == CustTransopen.RefRecId
&& CustTransExt.AccountNum == CustTransOpen.AccountNum;
if(CustTransopen )//&& CustTransOpen.AmountCur >= Credit)
{
manager = custvendopentransmanager::construct(ledgerJournalTransloc);
manager.updateTransMarked(CustTransOpen,true);
exchangeRateHelper = ExchangeRateHelper::newCurrency(Ledger::primaryLedger(CompanyInfo::findDataArea(ledgerJournalTransloc.Company).RecId),ledgerJournalTransloc.CurrencyCode);
totalSettlement = SpecTransManager::getTotalSettleAmountForSpecReference(
ledgerJournalTransloc.Company,
ledgerJournalTransloc.TableId,
ledgerJournalTransloc.RecId,
ledgerJournalTransloc.CurrencyCode,
ledgerJournalTransloc.Company,
ledgerJournalTransloc.TransDate,
exchangeRateHelper.prepareExchangeRateForStorage(ledgerJournalTransloc.crossrate()));
ttsBegin;
ledgerJournalTransloc.selectForUpdate(true);
//info(strFmt("%1" ,CustTransOpen.AmountCur));
if (Credit <= abs(totalSettlement))
{
ledgerJournalTransloc.AmountCurCredit = CustTransOpen.AmountCur;
}
ledgerJournalTransloc.SettleVoucher = SettlementType::SelectedTransact;
if (!ledgerJournalTransloc.Invoice)
{
ledgerJournalTransloc.MarkedInvoice = invoice;
ledgerJournalTransloc.DefaultDimension = CustTransExt.DefaultDimension;
ledgerJournalTransloc.OffsetDefaultDimension = CustTransExt.DefaultDimension;
}
ledgerJournalTransloc.doupdate();
ttsCommit;
}
else
{
value = true;
checkFailed("Please check the invoice amount.");
}
return value;
}
No comments:
Post a Comment