Thursday 20 December 2018

Importing .bacpac file

How restore data base using .bacpac  file.

Open the command prompt and type below command:

C:\Program Files (x86)\Microsoft SQL Server\140\DAC\bin>SqlPackage.exe /a:Import /sf:"C:\Temp\DBBackup\test_12132018.bacpac" /tsn:localhost /tdn:AxDBUMA

File Location : C:\Temp\DBBackup\test_12132018.bacpac
UMA - is the company we are going to import.

How to calculate charge (MarkupTrans) amount from code

Calculate markup trans for Sales order including Tax

  static Amount calculateMarkupTrans(SalesId _salesId) { AmountCur markupAmount,headermarkupamt,linemarkupamt,totTaxAmountCur,lineamount; MarkupTrans markupTrans; CurrencyExchangeHelper curCurrencyExchangeHelper; SalesTable salesTable = SalesTable::find(_salesId); SalesLine salesLine; SalesTotals salestotals; container cont; // Code to calculate total tax for sales order inlucing charges tax--> salesTotals = SalesTotals::construct(salesTable, SalesUpdate::All); salesTotals.calc(); cont         = salesTotals.displayFieldsCurrency(salesTotals.currencyCode()); totTaxAmountCur = conpeek(cont, TradeTotals::posTaxTotal()); // Code to calculate total tax for sales order inlucing charges tax<-- // Code to calculate total Charge for sales order header--> while select markupTrans where markupTrans.TransTableId == salesTable.TableId &&markupTrans.TransRecId == salesTable.RecId { markupAmount = markupTrans.Value; if (markupTrans.CurrencyCode != salesTable.CurrencyCode) { // To automatically conver amount Markup::calcMarkupAmount can be used curCurrencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea(markupTrans.company()).RecId), systemDateGet()); markupAmount = curCurrencyExchangeHelper.calculateAccountingToTransaction(salesTable.CurrencyCode, markupAmount, true); } headermarkupamt =headermarkupamt+markupAmount; } // Code to calculate total Charge for sales order header <-- // Code to calculate total Charge for sales order lines--> while select salesLine where salesLine.SalesId == salesTable.SalesId { while select markupTrans where markupTrans.TransTableId == salesLine.TableId &&markupTrans.TransRecId == salesLine.RecId { markupAmount = Markup::calcTrans(markupTrans, salesLine.SalesQty, salesLine.LineAmount); if (markupTrans.CurrencyCode != salesTable.CurrencyCode) { // To automatically conver amount Markup::calcMarkupAmount can be used curCurrencyExchangeHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea(markupTrans.company()).RecId), systemDateGet()); markupAmount = curCurrencyExchangeHelper.calculateAccountingToTransaction(salesTable.CurrencyCode, markupAmount, true); } linemarkupamt = linemarkupamt+markupAmount; } } // Code to calculate total Charge for sales order lines<-- markupAmount = linemarkupamt+headermarkupamt;//Sum both line and Header Charges for Sales order // Calculate Charge lines tax if we get tax > 0 for sales order--> if(salesTable.InclTax == noyes::No && totTaxAmountCur >0)// Calculate Charge lines tax if we get tax > 0 for sales order { TaxGroupHeading taxgroup; TaxGroupData taxgroupdata; select * from taxgroupdata where taxgroupdata.TaxGroup == salesTable.TaxGroup; real taxpercent =taxgroupdata.ShowTaxValue(); markupAmount =markupAmount+(markupAmount*taxgroupdata.ShowTaxValue())/100;//Add tax amount to Charge lines when Salestable Includetax field is set to no. } // Calculate Charge lines tax if we get tax > 0 for sales order--> return markupAmount; }

Monday 10 December 2018

Deleting duplicate records in Table through code in X++

static void DeleteDuplicate(Args _args)
{
Set fieldset = new set(types::Integer);

// create dictindex from unique index 

DictIndex dictIndex = new dictIndex (tablenum(PurchTable), indexnum(PurchTable,PurchIdx));

;

// these are fields from index

// add them to set

fieldset.add(fieldnum(PurchTable ,OrderAccount));

ReleaseUpdateDB::indexAllowDup(dictIndex);

// set allow duplicates

ReleaseUpdateDB::deleteDuplicatesUsingIds(tablenum(PurchTable),0,fieldset);

//reenable duplicates

ReleaseUpdateDB::indexAllowDup(dictIndex);

info("Deletion done");


}