Generate expense Journal Lines in Proj Module
class ALE_GenerateExpenseJournalLines extends RunBase
{
int recordsCount;
TransDate fromDate,toDate;
ProjId projId;
Name peroid;
LedgerJournalId journalId,journalIdLoc;
DialogField dlgPeriod;
DialogField dlgProjId;
#define.CurrentVersion(1)
#localmacro.CurrentList
peroid,
projId
#endmacro
}
//////////////////////////////////////////////////
public static void main(Args args)
{
JournalId journalId;
LedgerJournalTable ledgerJournalTable;
ALE_GenerateExpenseJournalLines generateExpenseJournalLines = new ALE_GenerateExpenseJournalLines();
ledgerJournalTable = args.record();
journalId = ledgerJournalTable.JournalNum;
generateExpenseJournalLines.getJournalId(journalId);
if(generateExpenseJournalLines.prompt())
{
generateExpenseJournalLines.run();
}
}
.................................................................................
protected Object dialog()
{
Dialog dialog;
FormStringControl controlPeriodName;
dialog = super();
dialog.caption('Generate Expense Journal lines');
dlgPeriod = dialog.addFieldValue(extendedTypeStr(Name),peroid);
dlgProjId = dialog.addFieldValue(extendedTypeStr(ProjId),projId);
controlPeriodName = dlgPeriod.control();
controlPeriodName.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(ALE_GenerateJournalLines,lookupPeriodName), this);
return dialog;
}
.................................................................................................
public boolean getFromDialog()
{
boolean ret;
ret = super();
peroid = dlgPeriod.value();
projId = dlgProjId.value();
return ret;
}
...............................................................................................
public void getJournalId(JournalId journalIdB)
{
journalId = journalIdB;
}
....................................................................
public void lookupPeriodName(FormStringControl _control)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(Ale_PeriodMaster),_control);
sysTableLookup.addLookupField(fieldNum(Ale_PeriodMaster, Name));
queryBuildDataSource = query.addDataSource(tableNum(Ale_PeriodMaster));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
...............................................................................
public container pack()
{
return [#CurrentVersion,#CurrentList];
}
...........................................................................
public void run()
{
ProjForecastUnion projForecastUnion;
LedgerJournalTable ledgerJournalTableLoc;
Ale_VehicleUploader vehicleUploader;
Ale_PeriodMaster periodMaster;
TransDate periodFromDate,periodToDate;
ALE_GenerateExpenseJournalLines generareJournalLines = new ALE_GenerateExpenseJournalLines();
journalIdLoc = journalId;
select StartDate,Enddate from periodMaster where periodMaster.Name == peroid;
periodFromDate = periodMaster.StartDate;
periodToDate = periodMaster.Enddate;
try
{
ttsBegin;
ledgerJournalTableLoc = LedgerJournalTable::find(journalIdLoc);
if(LedgerJournalName::find(LedgerJournalTable::find(journalIdLoc).JournalName).Ale_VehiclePrice != NoYes::Yes)
{
while select projForecastUnion group by ProjId,CategoryId,Ale_Period where projForecastUnion.ProjId == projId
&& projForecastUnion.Ale_Period == peroid
&& projForecastUnion.ProjTransType == ProjTransType::Cost
{
recordsCount++;
generareJournalLines.createExpenseJournals(projForecastUnion,journalIdLoc);
}
}
info(strFmt('%1 journals has been created',recordsCount));
ttsCommit;
}
catch(Exception::Deadlock)
{
error('Caught an exception');
retry;
}
}
..............................................................................
public boolean unpack(container packedClass)
{
Integer version = conPeek(packedClass,1);
switch (version)
{
case #CurrentVersion :
[version,#CurrentList] = packedClass;
break;
default :
return false;
}
return true;
}
......................................................................./////////////////////////???????????????????
private void createExpenseJournals(ProjForecastUnion _projForecastUnion,LedgerJournalId _journalId)
{
ProjPosting projPosting;
ProjSalesAmount salesAmount;
int64 recId,ledgerDim;
AmountMST expenseAssesableValue;
//ProjForecastUnion projForecastUnionTransId;
AxLedgerJournalTable axLedgerJournalTable = new AxLedgerJournalTable();
AxLedgerJournalTrans axLedgerJournalTrans = new AxLedgerJournalTrans();
ProjForecastUnion projForecastUnionLoc,projForecastUnionCat;
ProjBudgetLineDetail projBudgetLineDetail;
ProjForecastCost projForecastCost;
LedgerJournalTable ledgerJournalTable,ledgerJournalTableLoc;
LedgerJournalTrans ledgerJournalTrans;
NumberSequenceTable numberSequenceTable;
LedgerJournalTrans_Project ledgerJournalTrans_Project;
LedgerJournalTrans_ProjectTaxExtensionIN ledgerJournalTrans_ProjectTaxExtensionIN;
DefaultDimensionView defaultDimensionView;
DimensionAttributeValueCombination ledgerDimensionvalueCombination;
DimensionAttributeValueCombination davc;
ProjTable projTable;
projForecastUnionLoc.clear();
select Worker,CurrencyId,Qty,LinePropertyId,TransId from projForecastUnionLoc where projForecastUnionLoc.ProjId == _projForecastUnion.ProjId
&& projForecastUnionLoc.CategoryId == _projForecastUnion.CategoryId
&& projForecastUnionLoc.Ale_PositionId == _projForecastUnion.Ale_PositionId
&& projForecastUnionLoc.Ale_Period == _projForecastUnion.Ale_Period;
ledgerJournalTable = LedgerJournalTable::find(_journalId);
ledgerJournalTrans.JournalNum = axLedgerJournalTable.LedgerJournalTable().JournalNum;
//ledgerJournalTrans.DefaultDimension = DimensionDefault;
ledgerJournalTrans.AccountType = LedgerJournalACTypE::Project;
numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find(ledgerJournalTable.JournalName).NumberSequenceTable);
ledgerJournalTrans.Voucher = NumberSeq::newGetVoucherFromCode(numberSequenceTable.NumberSequence).voucher();
select firstonly ProjId from projTable join RecId from ledgerDimensionvalueCombination where ledgerDimensionvalueCombination.DisplayValue == projTable.ProjId
&& projTable.ProjId == _projForecastUnion.ProjId;
select LedgerDimension from projPosting where projPosting.ProjCategoryRelation == _projForecastUnion.CategoryId
&& projPosting.CategoryCode == TableGroupAll::Table;
select DefaultDimension from defaultDimensionView where defaultDimensionView.DisplayValue == HcmWorker::find(ProjForecastCost::find(projForecastUnionLoc.TransId).Worker).PersonnelNumber;
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerJournalTrans.Company = curext();
ledgerJournalTrans.CurrencyCode = projForecastUnionLoc.CurrencyId;//ProjTable::find(_projForecastUnion.ProjId).DefaultDimension
ledgerJournalTrans.DefaultDimension = DimensionDefaultingService::serviceMergeDefaultDimensions(ProjForecastCost::find(projForecastUnionLoc.TransId).DefaultDimension,defaultDimensionView.DefaultDimension);
ledgerJournalTrans.Qty = projForecastUnionLoc.Qty;
ledgerJournalTrans.TransDate = systemDateGet();
this.createDefaultDimensions(_projForecastUnion,projForecastUnionLoc);
if(HcmWorker::find(ProjForecastCost::find(projForecastUnionLoc.TransId).Worker).PersonnelNumber)
{
//ledgerDim = DimensionDefaultingService::serviceCreateLedgerDimension(projPosting.LedgerDimension);//,ledgerJournalTrans.DefaultDimension,defaultDimensionView.DefaultDimension
//ledgerJournalTrans.OffsetLedgerDimension = DimensionDefaultingService::serviceMergeDefaultDimensions(ledgerDim,defaultDimensionView.DefaultDimension);
ledgerJournalTrans.OffsetLedgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(projPosting.LedgerDimension,ledgerJournalTrans.DefaultDimension,defaultDimension);
}
else
{
select DefaultDimension from defaultDimensionView where defaultDimensionView.DisplayValue == 'Blank';
ledgerJournalTrans.OffsetLedgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension( projPosting.LedgerDimension,ledgerJournalTrans.DefaultDimension,defaultDimensionView.DefaultDimension,defaultDimension);
}
if(ledgerDimensionvalueCombination.recid != 0)
{
ledgerJournalTrans.ledgerDimension = ledgerDimensionvalueCombination.recid;
}
else
{
recId = DimensionStorage::getDynamicAccount(_projForecastUnion.ProjId, 3, 129);
davc = DimensionAttributeValueCombination::find(recId);
ledgerJournalTrans.DefaultDimension = davc.RecId;
}
ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
ledgerJournalTrans.insert();
// Strat by somendra
if(ledgerJournalTrans.recid)
{
select forUpdate ledgerJournalTableLoc where ledgerJournalTableLoc.JournalNum == ledgerJournalTrans.JournalNum;
ledgerJournalTableLoc.ALE_ProjId = _projForecastUnion.ProjId;//projTable.ProjId;//projId;
ledgerJournalTableLoc.Ale_Period = _projForecastUnion.Ale_Period;
ledgerJournalTableLoc.update();
}
//End by somendra
salesAmount = 0;
while select TransId from projForecastUnionCat where projForecastUnionCat.ProjId == _projForecastUnion.ProjId
&& projForecastUnionCat.CategoryId == _projForecastUnion.CategoryId
&& projForecastUnionCat.Ale_Period == _projForecastUnion.Ale_Period
&& projForecastUnionCat.ProjTransType == ProjTransType::Cost
{
//select SalesPrice from projBudgetLineDetail where projBudgetLineDetail.Ale_TransactionID == projForecastUnionCat.TransId; //
//salesAmount += projBudgetLineDetail.SalesPrice;
while select SalesPrice from projForecastCost where projForecastCost.TransId == projForecastUnionCat.TransId
{
salesAmount += projForecastCost.SalesPrice;
}
}
expenseAssesableValue = 0;
ledgerJournalTrans_Project.CategoryId = _projForecastUnion.CategoryId;
ledgerJournalTrans_Project.Qty = projForecastUnionLoc.Qty;
ledgerJournalTrans_Project.ALE_PeriodName = _projForecastUnion.Ale_Period;
ledgerJournalTrans_Project.ProjTransDate = systemDateGet();
ledgerJournalTrans_Project.SalesPrice = salesAmount;
ledgerJournalTrans_Project.SalesCurrencyId = projForecastUnionLoc.CurrencyId;
ledgerJournalTrans_Project.PositionId = _projForecastUnion.Ale_PositionId;
ledgerJournalTrans_Project.LinePropertyId = projForecastUnionLoc.LinePropertyId;
ledgerJournalTrans_Project.ProjId = _projForecastUnion.ProjId;
ledgerJournalTrans_Project.RefRecId = ledgerJournalTrans.RecId;
expenseAssesableValue = ledgerJournalTrans_Project.Qty * ledgerJournalTrans_Project.SalesPrice;
ledgerJournalTrans_Project.Worker = ProjForecastCost::find(projForecastUnionLoc.TransId).Worker;
ledgerJournalTrans_Project.insert();
ledgerJournalTrans_ProjectTaxExtensionIN.LedgerJournalTrans_Project = ledgerJournalTrans_Project.RecId;
ledgerJournalTrans_ProjectTaxExtensionIN.AssessableValue = expenseAssesableValue;
ledgerJournalTrans_ProjectTaxExtensionIN.insert();
ledgerJournalTrans_Project.clear();
ledgerJournalTrans.clear();
}
........................................................................................
class ALE_GenerateExpenseJournalLines extends RunBase
{
int recordsCount;
TransDate fromDate,toDate;
ProjId projId;
Name peroid;
LedgerJournalId journalId,journalIdLoc;
DialogField dlgPeriod;
DialogField dlgProjId;
#define.CurrentVersion(1)
#localmacro.CurrentList
peroid,
projId
#endmacro
}
//////////////////////////////////////////////////
public static void main(Args args)
{
JournalId journalId;
LedgerJournalTable ledgerJournalTable;
ALE_GenerateExpenseJournalLines generateExpenseJournalLines = new ALE_GenerateExpenseJournalLines();
ledgerJournalTable = args.record();
journalId = ledgerJournalTable.JournalNum;
generateExpenseJournalLines.getJournalId(journalId);
if(generateExpenseJournalLines.prompt())
{
generateExpenseJournalLines.run();
}
}
.................................................................................
protected Object dialog()
{
Dialog dialog;
FormStringControl controlPeriodName;
dialog = super();
dialog.caption('Generate Expense Journal lines');
dlgPeriod = dialog.addFieldValue(extendedTypeStr(Name),peroid);
dlgProjId = dialog.addFieldValue(extendedTypeStr(ProjId),projId);
controlPeriodName = dlgPeriod.control();
controlPeriodName.registerOverrideMethod(methodStr(FormStringControl, lookup),methodStr(ALE_GenerateJournalLines,lookupPeriodName), this);
return dialog;
}
.................................................................................................
public boolean getFromDialog()
{
boolean ret;
ret = super();
peroid = dlgPeriod.value();
projId = dlgProjId.value();
return ret;
}
...............................................................................................
public void getJournalId(JournalId journalIdB)
{
journalId = journalIdB;
}
....................................................................
public void lookupPeriodName(FormStringControl _control)
{
Query query = new Query();
QueryBuildDataSource queryBuildDataSource;
SysTableLookup sysTableLookup = SysTableLookup::newParameters(tableNum(Ale_PeriodMaster),_control);
sysTableLookup.addLookupField(fieldNum(Ale_PeriodMaster, Name));
queryBuildDataSource = query.addDataSource(tableNum(Ale_PeriodMaster));
sysTableLookup.parmQuery(query);
sysTableLookup.performFormLookup();
}
...............................................................................
public container pack()
{
return [#CurrentVersion,#CurrentList];
}
...........................................................................
public void run()
{
ProjForecastUnion projForecastUnion;
LedgerJournalTable ledgerJournalTableLoc;
Ale_VehicleUploader vehicleUploader;
Ale_PeriodMaster periodMaster;
TransDate periodFromDate,periodToDate;
ALE_GenerateExpenseJournalLines generareJournalLines = new ALE_GenerateExpenseJournalLines();
journalIdLoc = journalId;
select StartDate,Enddate from periodMaster where periodMaster.Name == peroid;
periodFromDate = periodMaster.StartDate;
periodToDate = periodMaster.Enddate;
try
{
ttsBegin;
ledgerJournalTableLoc = LedgerJournalTable::find(journalIdLoc);
if(LedgerJournalName::find(LedgerJournalTable::find(journalIdLoc).JournalName).Ale_VehiclePrice != NoYes::Yes)
{
while select projForecastUnion group by ProjId,CategoryId,Ale_Period where projForecastUnion.ProjId == projId
&& projForecastUnion.Ale_Period == peroid
&& projForecastUnion.ProjTransType == ProjTransType::Cost
{
recordsCount++;
generareJournalLines.createExpenseJournals(projForecastUnion,journalIdLoc);
}
}
info(strFmt('%1 journals has been created',recordsCount));
ttsCommit;
}
catch(Exception::Deadlock)
{
error('Caught an exception');
retry;
}
}
..............................................................................
public boolean unpack(container packedClass)
{
Integer version = conPeek(packedClass,1);
switch (version)
{
case #CurrentVersion :
[version,#CurrentList] = packedClass;
break;
default :
return false;
}
return true;
}
......................................................................./////////////////////////???????????????????
private void createExpenseJournals(ProjForecastUnion _projForecastUnion,LedgerJournalId _journalId)
{
ProjPosting projPosting;
ProjSalesAmount salesAmount;
int64 recId,ledgerDim;
AmountMST expenseAssesableValue;
//ProjForecastUnion projForecastUnionTransId;
AxLedgerJournalTable axLedgerJournalTable = new AxLedgerJournalTable();
AxLedgerJournalTrans axLedgerJournalTrans = new AxLedgerJournalTrans();
ProjForecastUnion projForecastUnionLoc,projForecastUnionCat;
ProjBudgetLineDetail projBudgetLineDetail;
ProjForecastCost projForecastCost;
LedgerJournalTable ledgerJournalTable,ledgerJournalTableLoc;
LedgerJournalTrans ledgerJournalTrans;
NumberSequenceTable numberSequenceTable;
LedgerJournalTrans_Project ledgerJournalTrans_Project;
LedgerJournalTrans_ProjectTaxExtensionIN ledgerJournalTrans_ProjectTaxExtensionIN;
DefaultDimensionView defaultDimensionView;
DimensionAttributeValueCombination ledgerDimensionvalueCombination;
DimensionAttributeValueCombination davc;
ProjTable projTable;
projForecastUnionLoc.clear();
select Worker,CurrencyId,Qty,LinePropertyId,TransId from projForecastUnionLoc where projForecastUnionLoc.ProjId == _projForecastUnion.ProjId
&& projForecastUnionLoc.CategoryId == _projForecastUnion.CategoryId
&& projForecastUnionLoc.Ale_PositionId == _projForecastUnion.Ale_PositionId
&& projForecastUnionLoc.Ale_Period == _projForecastUnion.Ale_Period;
ledgerJournalTable = LedgerJournalTable::find(_journalId);
ledgerJournalTrans.JournalNum = axLedgerJournalTable.LedgerJournalTable().JournalNum;
//ledgerJournalTrans.DefaultDimension = DimensionDefault;
ledgerJournalTrans.AccountType = LedgerJournalACTypE::Project;
numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find(ledgerJournalTable.JournalName).NumberSequenceTable);
ledgerJournalTrans.Voucher = NumberSeq::newGetVoucherFromCode(numberSequenceTable.NumberSequence).voucher();
select firstonly ProjId from projTable join RecId from ledgerDimensionvalueCombination where ledgerDimensionvalueCombination.DisplayValue == projTable.ProjId
&& projTable.ProjId == _projForecastUnion.ProjId;
select LedgerDimension from projPosting where projPosting.ProjCategoryRelation == _projForecastUnion.CategoryId
&& projPosting.CategoryCode == TableGroupAll::Table;
select DefaultDimension from defaultDimensionView where defaultDimensionView.DisplayValue == HcmWorker::find(ProjForecastCost::find(projForecastUnionLoc.TransId).Worker).PersonnelNumber;
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerJournalTrans.Company = curext();
ledgerJournalTrans.CurrencyCode = projForecastUnionLoc.CurrencyId;//ProjTable::find(_projForecastUnion.ProjId).DefaultDimension
ledgerJournalTrans.DefaultDimension = DimensionDefaultingService::serviceMergeDefaultDimensions(ProjForecastCost::find(projForecastUnionLoc.TransId).DefaultDimension,defaultDimensionView.DefaultDimension);
ledgerJournalTrans.Qty = projForecastUnionLoc.Qty;
ledgerJournalTrans.TransDate = systemDateGet();
this.createDefaultDimensions(_projForecastUnion,projForecastUnionLoc);
if(HcmWorker::find(ProjForecastCost::find(projForecastUnionLoc.TransId).Worker).PersonnelNumber)
{
//ledgerDim = DimensionDefaultingService::serviceCreateLedgerDimension(projPosting.LedgerDimension);//,ledgerJournalTrans.DefaultDimension,defaultDimensionView.DefaultDimension
//ledgerJournalTrans.OffsetLedgerDimension = DimensionDefaultingService::serviceMergeDefaultDimensions(ledgerDim,defaultDimensionView.DefaultDimension);
ledgerJournalTrans.OffsetLedgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension(projPosting.LedgerDimension,ledgerJournalTrans.DefaultDimension,defaultDimension);
}
else
{
select DefaultDimension from defaultDimensionView where defaultDimensionView.DisplayValue == 'Blank';
ledgerJournalTrans.OffsetLedgerDimension = DimensionDefaultingService::serviceCreateLedgerDimension( projPosting.LedgerDimension,ledgerJournalTrans.DefaultDimension,defaultDimensionView.DefaultDimension,defaultDimension);
}
if(ledgerDimensionvalueCombination.recid != 0)
{
ledgerJournalTrans.ledgerDimension = ledgerDimensionvalueCombination.recid;
}
else
{
recId = DimensionStorage::getDynamicAccount(_projForecastUnion.ProjId, 3, 129);
davc = DimensionAttributeValueCombination::find(recId);
ledgerJournalTrans.DefaultDimension = davc.RecId;
}
ledgerJournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
ledgerJournalTrans.insert();
// Strat by somendra
if(ledgerJournalTrans.recid)
{
select forUpdate ledgerJournalTableLoc where ledgerJournalTableLoc.JournalNum == ledgerJournalTrans.JournalNum;
ledgerJournalTableLoc.ALE_ProjId = _projForecastUnion.ProjId;//projTable.ProjId;//projId;
ledgerJournalTableLoc.Ale_Period = _projForecastUnion.Ale_Period;
ledgerJournalTableLoc.update();
}
//End by somendra
salesAmount = 0;
while select TransId from projForecastUnionCat where projForecastUnionCat.ProjId == _projForecastUnion.ProjId
&& projForecastUnionCat.CategoryId == _projForecastUnion.CategoryId
&& projForecastUnionCat.Ale_Period == _projForecastUnion.Ale_Period
&& projForecastUnionCat.ProjTransType == ProjTransType::Cost
{
//select SalesPrice from projBudgetLineDetail where projBudgetLineDetail.Ale_TransactionID == projForecastUnionCat.TransId; //
//salesAmount += projBudgetLineDetail.SalesPrice;
while select SalesPrice from projForecastCost where projForecastCost.TransId == projForecastUnionCat.TransId
{
salesAmount += projForecastCost.SalesPrice;
}
}
expenseAssesableValue = 0;
ledgerJournalTrans_Project.CategoryId = _projForecastUnion.CategoryId;
ledgerJournalTrans_Project.Qty = projForecastUnionLoc.Qty;
ledgerJournalTrans_Project.ALE_PeriodName = _projForecastUnion.Ale_Period;
ledgerJournalTrans_Project.ProjTransDate = systemDateGet();
ledgerJournalTrans_Project.SalesPrice = salesAmount;
ledgerJournalTrans_Project.SalesCurrencyId = projForecastUnionLoc.CurrencyId;
ledgerJournalTrans_Project.PositionId = _projForecastUnion.Ale_PositionId;
ledgerJournalTrans_Project.LinePropertyId = projForecastUnionLoc.LinePropertyId;
ledgerJournalTrans_Project.ProjId = _projForecastUnion.ProjId;
ledgerJournalTrans_Project.RefRecId = ledgerJournalTrans.RecId;
expenseAssesableValue = ledgerJournalTrans_Project.Qty * ledgerJournalTrans_Project.SalesPrice;
ledgerJournalTrans_Project.Worker = ProjForecastCost::find(projForecastUnionLoc.TransId).Worker;
ledgerJournalTrans_Project.insert();
ledgerJournalTrans_ProjectTaxExtensionIN.LedgerJournalTrans_Project = ledgerJournalTrans_Project.RecId;
ledgerJournalTrans_ProjectTaxExtensionIN.AssessableValue = expenseAssesableValue;
ledgerJournalTrans_ProjectTaxExtensionIN.insert();
ledgerJournalTrans_Project.clear();
ledgerJournalTrans.clear();
}
........................................................................................
No comments:
Post a Comment