static void FAJournalCreation(Args _args)
{
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
COMVariantType type;
FilenameOpen filename;
dialogField dialogFilename;
Dialog dialog;
Integer row = 1;
itemId itemId;
Dialog d;
DialogField df1;
CommaTextIo file;
container rec;
dimensionAttribute dimensionAttribute;
dimensionAttributevalue dimensionAttributevalue;
DimensionAttributeValueSetStorage dimstorage;
RecId ret;
int i,num,coun;
NumberSequenceTable numberSequenceTable;
Voucher voucher;
str accountType;
Amount amountCurDebit,amountCurCredit,amtcrdt,amtdebt;
container conSplitValue,offdim;
str 64 custAccount,ledgerAccount;
str costcenter,department,revenueDimension,description;
LedgerJournalACTypE acctype,offacctype;
DimensionStorage DimensionStorage;
LedgerJournalTrans_Asset ledgerJournalTransAssets;
AssetTable assetTable ;
LedgerDimensionDefaultAccount defaultAccount;
LedgerJournalEngine ledgerJournalEngine;
ledgerJournalTable ledgerJournalTable;
AssetBook assetBook;
str 64 assetid;
AssetTransTypeJournal transtype;
LedgerJournalName ledgerJournalName;
//DimensionStorage DimensionStorage;
LedgerAccountContract ledgerAccountContract,OffledgerAccountContract;
str ledgerAcc,departmentval,service,employee,phase,event;
DimensionAttributeValueContract attributeValueContract;
ledgerJournalTrans ledgerJournalTrans;
AssetLedgeraccounts assetLedgerAccounts;
MainAccount mainaccount;
RecId recMainaccount;
//DimensionAttributeValueSetStorage dimStorage;
boolean first = true;
DialogField dialogFromDate,dialogledger,dialogimpBal,dialogJournalName,dialogJournalTxt,dig;
int j;
TransDate TransactionDate,Fromdate,TransDate,StartDate,enddate,reversedate;
Ledgerjournalnameid Ledgerjournalnameid1,LedgerJournalNameId,JournalNameId;
//(PYLVacation).VacationTransId
str journalName, journalTxt;
str dimensn,dimension1,dimension2,dimension3,dimension4,dimension5;
container dimm;
currencycode currencycode;
str COMVariant2Str(COMVariant _cv,int _decimals = 0, int _characters = 0, int _separator1 = 0, int _separator2 = 0)
{
switch (_cv.variantType())
{
case (COMVariantType::VT_BSTR):
return _cv.bStr();
case (COMVariantType::VT_R8):
return num2str(_cv.double(),_characters,_decimals,_separator1,_separator2);
case (COMVariantType::VT_DATE):
return date2str(_cv.date(),123,2,1,2,1,4);
case (COMVariantType::VT_EMPTY):
return '';
default:
throw error(strfmt("@SYS26908", _cv.variantType()));
}
}
;
dialog = new Dialog('LeaveTransactions');
dialogFilename = dialog.addField(ExtendedTypeStr("FilenameOpen"));
dialogFromDate = dialog.addFieldValue(extendedtypestr(TransDate), TransactionDate,"TransactionDate");
dialogledger = dialog.addFieldvalue(extendedtypestr(LedgerJournalNameid)," ","JournalName");
dialogJournalTxt = dialog.addFieldvalue(extendedtypestr(str60)," ","Journal Txt");
dialog.filenameLookupTitle('Import from excel.');
dialog.caption('Import From Excel');
//dialog.addText("This is to import General Journal Account Entry records directly\n");
//dialog.addText("Following are mandatory in the display value :\n1. MainAccount\n2. LineOfBusiness Dimension\n3. Investment Dimension\n4. Department dimension is optional").displayHeight(6);
//dialog.addText("Template order:\n");
//dialog.addText(strFmt("%1\n%2\n%3\n%4\n","DisplayValue","AccountingCurrencyAmount","GeneralJournalEntryRecid","Currency Code - Hardcoded here")).displayHeight(15);
dialogFilename.value(filename);
if(dialog.run())
{
filename = dialogFilename.value();
fromDate = dialogFromDate.value();
journalNameId = dialogledger.Value();
journalTxt = dialogJournalTxt.value();
application = SysExcelApplication::construct();
workbooks = application.workbooks();
try
{
workbooks.open(filename);
}
catch (Exception::Error)
{
throw error('File cannot be opened.');
}
workbook = workbooks.item(1);
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
try
{
ttsbegin;
do
{
row++;
type = cells.item(row+1, 1).value().variantType();
if(first) //Create Journal Header
{
Select ledgerjournalname where ledgerjournalname.JournalName == JournalNameId;
if(!ledgerJournalName.RecId)
{
throw error ("ledgerJournalName doesn't exist");
}
ledgerJournalTable.clear();
ledgerJournalTable.initValue();
ledgerJournalTable.initFromLedgerJournalName(ledgerJournalName.JournalName);
ledgerJournalTable.JournalNum = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
ledgerJournalTable.journalType = LedgerJournalType::Assets;
ledgerJournalTable.JournalName = ledgerJournalName.JournalName;
ledgerJournalTable.Name = journalName;
ledgerJournalTable.insert();
first = false;
}
amountCurDebit = 0;
amountCurCredit = 0;
numberSequenceTable = NumberSequenceTable::find(LedgerJournalName::find(journalNameId).NumberSequenceTable);
voucher = NumberSeq::newGetVoucherFromCode(numberSequenceTable.NumberSequence).voucher();
description = journalTxt;
currencycode = CompanyInfo::standardCurrency();
acctype = LedgerJournalACType::FixedAssets;
assetid = ((COMVariant2Str(cells.item(row, 1).value())));//conPeek(readCon,1);
amountCurDebit = (cells.item(row, 2).value().double());//conPeek(readCon,2);
amountCurCredit = (((cells.item(row, 3).value().double())));//conPeek(readCon,3);
//ledgerAccount = ((COMVariant2Str(cells.item(row, 4).value())));//conPeek(readCon,4);
//departmentval = ((COMVariant2Str(cells.item(row, 5).value())));//conPeek(readCon,5);
//service = ((COMVariant2Str(cells.item(row, 6).value())));//conPeek(readCon,6);
//phase = ((COMVariant2Str(cells.item(row, 7).value())));//conPeek(readCon,7);
//event = ((COMVariant2Str(cells.item(row, 8).value())));//conPeek(readCon,8);
//employee = ((COMVariant2Str(cells.item(row, 9).value())));//conPeek(readCon,9);
//transtype = AssetTransTypeJournal::Depreciation;
department = "";
service = "";
phase = "";
event = "";
employee = "";
ledgerAcc = "";
assetTable = assetTable::find(assetid);
select assetBook where assetbook.AssetId == AssetId;
select assetLedgerAccounts where assetLedgerAccounts.AccountRelation == assetTable.AssetGroup
&& assetLedgerAccounts.TransType == AssetTransType::Depreciation;
recMainaccount = DimensionStorage::getMainAccountIdFromLedgerDimension(assetLedgerAccounts.OffsetLedgerDimension);
select MainAccount where MainAccount.RecId == recMainaccount;
ledgerAcc = MainAccount.MainAccountId;
dimStorage = DimensionAttributeValueSetStorage::find(assetbook.DefaultDimension);
for (j=1 ; j<= dimStorage.elements() ; j++)
{
//info(DimensionAttribute::find(dimStorage.getAttributeByIndex(i)).Name +"----" +dimStorage.getDisplayValueByIndex(i));
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(j)).Name == "department")
department = dimStorage.getDisplayValueByIndex(j);
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(j)).Name == "Employee")
Employee = dimStorage.getDisplayValueByIndex(j);
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(j)).Name == "Phase")
Phase = dimStorage.getDisplayValueByIndex(j);
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(j)).Name == "Event")
Event = dimStorage.getDisplayValueByIndex(j);
if(DimensionAttribute::find(dimStorage.getAttributeByIndex(j)).Name == "Service")
Service = dimStorage.getDisplayValueByIndex(j);
}
ledgerJournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerAccountContract = new LedgerAccountContract();
ledgerAccountContract.parmValues(new List(Types::Class));
ledgerAccountContract.parmMainAccount(ledgerAcc);
if (department)
{
attributeValueContract = new DimensionAttributeValueContract();
attributeValueContract.parmName("Department");
attributeValueContract.parmValue(department);
ledgerAccountContract.parmValues().addEnd(attributeValueContract);
}
if (phase)
{
attributeValueContract = new DimensionAttributeValueContract();
attributeValueContract.parmName("phase");
attributeValueContract.parmValue(phase);
ledgerAccountContract.parmValues().addEnd(attributeValueContract);
}
if (service)
{
attributeValueContract = new DimensionAttributeValueContract();
attributeValueContract.parmName("Service");
attributeValueContract.parmValue(service);
ledgerAccountContract.parmValues().addEnd(attributeValueContract);
}
if (event)
{
attributeValueContract = new DimensionAttributeValueContract();
attributeValueContract.parmName("Event");
attributeValueContract.parmValue(Event);
ledgerAccountContract.parmValues().addEnd(attributeValueContract);
}
if (employee)
{
attributeValueContract = new DimensionAttributeValueContract();
attributeValueContract.parmName("employee");
attributeValueContract.parmValue(employee);
ledgerAccountContract.parmValues().addEnd(attributeValueContract);
}
ledgerJournalTrans.CurrencyCode = currencyCode;
ledgerJournalTrans.initValue();
ledgerJournalTrans.LedgerDimension = DimensionStorage::getDynamicAccount(assetid,acctype);
ledgerJournalTrans.parmAccount(AssetId, LedgerJournalACType::FixedAssets);
ledgerJournalTrans.TransDate = transDate;
ledgerJournalTrans.Txt = assetTable::find(assetid).Name;//description;
ledgerJournalTrans.AccountType = acctype;
ledgerJournalTrans.Voucher = voucher;
ledgerJournalTrans.PostingProfile =AssetParameters::find().PostingProfile;
ledgerJournalTrans.Company = curext();
ledgerJournalTrans.OffsetCompany = curext();
dimensionStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(ledgerAccountContract);
ledgerJournalTrans.OffsetLedgerDimension= dimensionStorage.save();
ledgerJournalTrans.AmountCurCredit = amountCurCredit;
ledgerJournalTrans.AmountCurDebit = amountCurDebit;
dimStorage = new DimensionAttributeValueSetStorage();
dimensionAttribute = AxdDimensionUtil::validateFinancialDimension("SystemGeneratedAttributeFixedAsset");
dimensionAttributeValue = AxdDimensionUtil::validateFinancialDimensionValue(dimensionAttribute, custAccount);
dimStorage.addItem(dimensionAttributeValue);
ledgerJournalTrans.DefaultDimension = dimStorage.save();//CustFinancialDimension::CreateDimension(AssetId);
ledgerJournalTrans.OffsetAccountType = ledgerJournalTable.OffsetAccountType;
ledgerJournalTrans.calcAmountMST();
ledgerJournalTrans.insert();
ledgerJournalTransAssets.BookId = assetBook.BookId;
ledgerJournalTransAssets.TransType = AssetTransTypeJournal::Depreciation;
ledgerJournalTransAssets.AssetId = ledgerJournalTrans.parmAccount();
ledgerJournalTransAssets.Company = ledgerJournalTrans.Company;
ledgerJournalEngine = new LedgerJournalEngine();
ledgerJournalEngine.initDefaultDimension(ledgerJournalTrans, ledgerJournalTransAssets);
ledgerJournalTransAssets.RefRecId = ledgerJournalTrans.RecId;
ledgerJournalTransAssets.insert();
CodeAccessPermission::revertAssert();
num++;
info(strFmt("%1",num));
coun++;
print(coun);
} // do
// info(strFmt(" %1 Records Updated", num));
while (type != COMVariantType::VT_EMPTY);
info(strFmt("No of records updated - %1",num));
ttscommit;
application.quit();
}// try
catch
{
throw error('Error in Update.');
}
}
pause;
}