generate LedgerDimension x++ D365

///

/// generates lederdimensionRecid dyanmically
///

/// container with dimensions
/// main account number
/// Ledger dimension record identification number
protected DimensionDynamicAccount getLedgerDimension(container _conData, AccountNum _accountNum)
{
int hierarchyCount;
int hierarchyIdx;
DimensionDynamicAccount ledgerRecId;
mainAccountNum mainAccountId = conPeek(_conData, 1);
MainAccount mainAccount;
RefRecId recordvalue;
DimensionAttribute dimensionAttribute;
DimensionAttributeValue dimensionAttributeValue;
DimensionSetSegmentName DimensionSet;
DimensionStorage dimStorage;
LedgerAccountContract LedgerAccountContract = new LedgerAccountContract();
DimensionAttributeValueContract ValueContract;
List valueContracts = new List(Types::Class);
dimensionAttributeValueCombination dimensionAttributeValueCombination;

mainAccount = MainAccount::findByMainAccountId(mainAccountId);
recordvalue = DimensionHierarchy::getAccountStructure(mainAccount.RecId,Ledger::current());
hierarchyCount = DimensionHierarchy::getLevelCount(recordvalue);
DimensionSet = DimensionHierarchyLevel::getDimensionHierarchyLevelNames(recordvalue);
for(hierarchyIdx = 1;hierarchyIdx<=hierarchyCount;hierarchyIdx++)
{
if(hierarchyIdx == 1)
{
continue;
}
dimensionAttribute = DimensionAttribute::findByLocalizedName(DimensionSet[hierarchyIdx],false, CompanyInfo::find().LanguageId);

if(dimensionAttribute)
{
dimensionAttributeValue = DimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,conPeek(_conData,hierarchyIdx));
if(dimensionAttributeValue)
{
ValueContract = new DimensionAttributeValueContract();
ValueContract.parmName(dimensionAttribute.Name) ;
ValueContract.parmValue(dimensionAttributeValue.CachedDisplayValue);
valueContracts.addEnd(ValueContract);
}
}
}
LedgerAccountContract.parmMainAccount(mainAccountId);
LedgerAccountContract.parmValues(valueContracts);
dimStorage = DimensionServiceProvider::buildDimensionStorageForLedgerAccount(LedgerAccountContract);
dimensionAttributeValueCombination = DimensionAttributeValueCombination::find(dimStorage.save());
ledgerRecId = dimensionAttributeValueCombination.RecId;
return ledgerRecId;
}

Leave a comment

Filed under Uncategorized

Post a journal X++ D365

protected void PostJournal(LedgerJournalTable _ledgerJournalTable)
{

//POST
ledgerJournalValiate = ledgerJournalCheckPost::newLedgerJournalTable(
_ledgerJournalTable,
NoYes::No);

if (_ledgerJournalTable.numOfLines() > 0)
{
ledgerJournalValiate.runOperation();

if (!ledgerJournalValiate.tableErrorLog())
{
ledgerJournalPost = ledgerJournalCheckPost::newLedgerJournalTable(
_ledgerJournalTable,
NoYes::Yes);
ledgerJournalPost.runOperation();

}
else
{
errorLog += “\n” + ledgerJournalValiate.tableErrorLog();

}
}
else
{
errorLog += “\n” + “@NHVRSuite:CannotPostJournal” ;
}

}

Leave a comment

Filed under Uncategorized

Create general journal X++ D365

protected JournalId createJournal(Filename _batchNumber)
{
VendParameters vendParameters = VendParameters::find();
LedgerJournalTable ledgerJournalTable;
JournalTableData journalTableData;
LedgerjournalTrans ledgerjournalTrans;

if (vendParameters.NHVRJournalName &&
LedgerJournalName::exist(vendParameters.NHVRJournalName))
{
ledgerJournalTable.initFromLedgerJournalName(vendParameters.NHVRJournalName);
journalTableData = JournalTableData::newTable(ledgerJournalTable);
ledgerJournalTable.JournalNum = journalTableData.nextJournalId();
ledgerJournalTable.Name = _batchNumber;
ledgerJournalTable.CurrencyCode = CompanyInfoHelper::standardCurrency();
if (ledgerJournalTable.validateWrite())
{
ledgerJournalTable.insert();
}

if (ledgerJournalTable.RecId)
{
while select sum(Amount), LedgerDimension, AmountCreditDebit , TransDate from tmpPayroll
group by LedgerDimension, AmountCreditDebit , TransDate
where tmpPayroll.ReferenceNumber == _batchNumber
{
ledgerjournalTrans.clear();
ledgerjournalTrans.initvalue();
ledgerjournalTrans.JournalNum = ledgerJournalTable.JournalNum;
ledgerjournalTrans.Company = curext();
ledgerjournalTrans.TransDate = tmpPayroll.Transdate;
ledgerjournalTrans.CurrencyCode = CompanyInfoHelper::standardCurrency();
ledgerjournalTrans.Txt = “@NHVRSuite:PayrollHelpText”;
ledgerjournalTrans.AccountType = LedgerJournalACType::Ledger;
ledgerjournalTrans.LedgerDimension = tmpPayroll.LedgerDimension;
ledgerjournalTrans.OffsetAccountType = LedgerJournalACType::Ledger;
ledgerjournalTrans.OffsetLedgerDimension = 0;
if (tmpPayroll.AmountCreditDebit == Debit)
{
ledgerjournalTrans.AmountCurDebit = tmpPayroll.Amount;
ledgerjournalTrans.AmountCurCredit = 0;
}
else
{
ledgerjournalTrans.AmountCurCredit = -tmpPayroll.Amount;
ledgerjournalTrans.AmountCurDebit = 0;
}

ledgerjournalTrans.Approved = NoYes::Yes;
ledgerJournalTrans.SkipBlockedForManualEntryCheck = true;
ledgerJournalTrans.defaultRow();

if (ledgerJournalTrans.validateWrite())
{
ledgerjournalTrans.insert();
}
}
}
else
{
throw Exception::Error;
}
}

return ledgerJournalTable.JournalNum;
}

Leave a comment

Filed under Uncategorized

Upload Image to products D365 x++

class UploadFileFromFilePath
{
///

/// Runs the class with the specified arguments.
///

/// The specified arguments.
public static void main(Args _args)
{
//FileUploadTemporaryStorageResult result = File::UseFileFromURL(“E:\\Linfox.png”) as FileUploadTemporaryStorageResult;
System.IO.Stream attachmentStream = File::UseFileFromURL(“E:\\LINFOX.PNG”);//result.openResult();
DocuRef docuRef;
// EcoResProductImage ecoResProductImage;

InventTable inventTable = InventTable::find(‘Audit-2’);

ttsbegin;

docuRef = DocumentManagement::attachFile(inventTable.TableId, inventTable.RecId, inventTable.DataAreaId, “Image”, attachmentStream,
“Capture.PNG”,”image/png”, “Capture”);

EcoResProductImage ecoResProductImage = EcoResProductImage::create(docuRef);
EcoResProductImage::updateDefault(docuRef.RefRecId, docuRef.RefTableId, docuRef.RefCompanyId, ecoResProductImage.RecId);

ttscommit;

info(‘done’);
}

}

Leave a comment

Filed under Uncategorized

NetPrice of an item using X++ Ax2012 R2 and R3.

Below is a test job to find the Net-Price of an item, considering different Trade Agreement settings.

static void NetAmountwithdiscounts(Args _args)
{

PriceDisc_Price             priceDisc_Price    = PriceDisc_Price::construct();
PriceDisc_LineDisc          priceDisc_LineDisc = PriceDisc_LineDisc::construct();
InventDim                   inventDim;
AmountCur                   LineAmount;

priceDisc_Price.parmModuleType( ModuleInventPurchSales::Sales);
priceDisc_Price.parmItemId(“iphone7”);
priceDisc_Price.parmInventDim(InventDim);
priceDisc_Price.parmUnitID(“ea”);
priceDisc_Price.parmPriceDate(systemDateGet());
priceDisc_Price.parmQty(1);
priceDisc_Price.parmAccountNum(“”);
priceDisc_Price.parmCurrencyCode(“USD”);
priceDisc_Price.parmPriceGroupId(“”);
print priceDisc_Price.price();
print priceDisc_Price.priceUnit();
pause;

priceDisc_LineDisc.parmModuleType( ModuleInventPurchSales::Sales);
priceDisc_LineDisc.parmItemId(“iphone7”);
priceDisc_LineDisc.parmInventDim(inventDim);
priceDisc_LineDisc.parmUnitID(“ea”);
priceDisc_LineDisc.parmDiscDate(systemDateGet());

priceDisc_LineDisc.parmQty(1);
priceDisc_LineDisc.parmAccountNum(“”);
priceDisc_LineDisc.parmCurrencyCode(“USD”);
priceDisc_LineDisc.parmAccountLineDiscCode();
priceDisc_LineDisc.parmItemLineDiscCode(InventTableModule::find(“iphone7”, ModuleInventPurchSales::Sales).LineDisc);
//  priceDisc_LineDisc.parmSalesPurchLine(_salesPurchLine);
priceDisc_LineDisc.findLineDiscAgreement();
print priceDisc_LineDisc.discAmount();   //linedisc
print priceDisc_LineDisc.discPct(); //LinePercent
pause;

LineAmount = PriceDisc::price2Amount(priceDisc_Price.price(),
priceDisc_Price.priceUnit(), //1
PriceDisc::discAmount(SalesParameters::find().Disc, priceDisc_LineDisc.discAmount(), 0),//should call this,
1,                   // deliver now
1,
0,
PriceDisc::discPercent(SalesParameters::find().Disc, priceDisc_LineDisc.discPct(), 0),
“USD”,
0,
true);

print LineAmount;
pause;

}

Leave a comment

Filed under Uncategorized