Monday 30 January 2017

Code for progress bar in ax 2012

static void Progressbar_ProgressbarBars(Args _args)
{
#AviFiles
SysOperationProgress Progressbar = new SysOperationProgress();
int i;
;
Progressbar.setCaption("Progressbar bar example…");
Progressbar.setAnimation(#AviUpdate);
Progressbar.setTotal(50000);
    for (i = 1; i <= 50000; i++)
    {
    Progressbar.setText(strfmt("The value of i is %1", i));
    Progressbar.setCount(i, 1);
   }
}

Creation of PO from the AX service in ax 2012

void createPO()
{
DmsTxtPoStaging poStaging, poStagingLine, poStagingError;
DmsTxtPoStaging poStagingLineQtyChk;
VendAccount vendor;
PurchTable purchTable;
PurchLine purchLine;
VendTable vendTable;
AxPurchTable axPurchTable;
AxPurchLine axPurchLine;
DmsParameters dmsParamaters;
InventDim inventDim;
//boolean poInvoiced;
//boolean registerIMEI;
boolean poLineCreate;
//DmsMdmOrderReasonParameter orderReasonParam;
DmsProductConfigView productVariantsPerCompany;
EcoResConfiguration configuration;
DmsILSImeiDetails imeiDetails,imeiDetailsQtyChk;
DmsErrorLog errorLog;
ItemId itemId;
DmsBuyer dmsBuyer;
SelectableDataArea curDataArea;
DmsProductPriceMarginModel priceMarginModel;
PurchPrice purchprice;
while select poStaging
group by CompInvNo, CompInvDate, DistCode, PurchaseOrder
where poStaging.Processed == NoYes::No
&& poStaging.Error == NoYes::No
&& poStaging.DistributionChannel == @'YPN1'
{
if(!CompanyInfo::findByDmsPartnerCode(poStaging.DistCode).DmsTier1)
throw error("@DMS2484");
/*
if(!CompanyInfo::findByDmsPartnerCode(poStaging.DistCode).DmsTier1)
{
select firstOnly SellerCompany from dmsBuyer
where dmsBuyer.Buyer == poStaging.DistCode
&& dmsBuyer.SellerPartnerLevel == 1
&& dmsBuyer.FromDate >= today()
&& dmsBuyer.ToDate <= today();
curDataArea = dmsBuyer.SellerCompany;
}
else
{
curDataArea = CompanyInfo::findByDmsPartnerCode(poStaging.DistCode).DataArea;
}
if( curDataArea == "")
throw error("@DMS2896");
*/
changeCompany(CompanyInfo::findByDmsPartnerCode(poStaging.DistCode).DataArea)
// changeCompany(curDataArea)
{
try
{
info(curext());
poLineCreate = false;
vendor = DmsParameters::find().DefaultVendor;
vendTable = VendTable::find(vendor);
if(!vendor && !vendTable)
throw error("@DMS2408");
dmsParamaters = DmsParameters::find();
ttsBegin;
purchTable.clear();
purchTable.initFromVendTable(vendTable);
axPurchTable = axPurchTable::newPurchTable(purchTable);
axPurchTable.parmPurchaseType(PurchaseType::Purch);
axPurchTable.parmDocumentStatus(DocumentStatus::PurchaseOrder);
axPurchTable.parmAccountingDate(systemDateGet());
axPurchTable.parmDeliveryDate(systemDateGet());
axPurchTable.parmPurchStatus(PurchStatus::Backorder);
axPurchTable.parmInventSiteId(dmsParamaters.Site);
axPurchTable.parmInventLocationId(dmsParamaters.Warehouse);
axPurchTable.doSave();
purchTable.selectForUpdate(true);
purchTable.DmsDOReferenceNumber = poStaging.CompInvNo;
purchTable.DmsDOReferenceDate = poStaging.CompInvDate;
purchTable.update();
setPrefix(strFmt("@DMS2617",poStaging.CompInvNo));
setPrefix(strFmt("@DMS2407",purchTable.PurchId));
//create PurchLine
while select * from poStagingLine where
poStagingLine.CompInvNo == poStaging.CompInvNo &&
poStagingLine.CompInvDate == poStaging.CompInvDate &&
poStagingLine.DistCode == poStaging.DistCode &&
poStagingLine.PurchaseOrder == poStaging.PurchaseOrder &&
poStagingLine.DistributionChannel == @'YPN1' &&
poStagingLine.Processed == NoYes::No
{
poLineCreate = true;
//Item Id
//itemId = InventTable::findByProduct(EcoResProduct::findByDisplayProductNumber(DmsSkuDetailsTable::findBySkuCode(poStagingLine.SkuCode).ProductCode).RecId).ItemId;
itemId = InventTable::findByProduct(EcoResProduct::findByDisplayProductNumber(DmsProductSKUMapping::findProductbySkuCode(poStagingLine.SkuCode)).RecId).ItemId;
if(!itemId )
throw error("@DMS2641");
poStagingLine.selectForUpdate(true);
poStagingLine.ProductCode = itemId;
poStagingLine.update();
//Product dimension
select InventDimId,RetailVariantId,ItemId,Configuration
from productVariantsPerCompany
where productVariantsPerCompany.ItemId == poStagingLine.ProductCode
join configuration
where productVariantsPerCompany.Configuration == configuration.RecId
&& configuration.Name == poStagingLine.OrderReason;
if(productVariantsPerCompany.InventDimId)
{
inventDim = InventDim::find(productVariantsPerCompany.InventDimId);
inventDim.InventSiteId = purchTable.InventSiteId;
inventDim.InventLocationId = purchTable.InventLocationId;
}
else
throw error("@DMS2457");
purchLine.clear();
purchLine.initFromPurchTable(purchTable);
axPurchLine = AxPurchLine::newPurchLine(purchLine);
axpurchLine.parmItemId(poStagingLine.ProductCode);
axPurchLine.parmPurchQty(poStagingLine.IndentQty);
axPurchLine.parmPurchUnit(InventTableModule::find(poStagingLine.ProductCode,ModuleInventPurchSales::Invent).UnitId);
axPurchLine.parmInventDimId(InventDim::findOrCreate(inventDim).inventDimId);
axPurchLine.parmPurchReceivedNow(poStagingLine.IndentQty);
// axPurchLine.parmPurchPrice(InventTable::find(poStagingLine.ProductCode).purchPcsPrice());
axpurchLine.parmVariantId(productVariantsPerCompany.RetailVariantId);
//For price - 16112015
priceMarginModel = new DmsProductPriceMarginModel();
purchprice = priceMarginModel.calculateProcessPurch(itemId,vendor);
axpurchLine.parmPurchPrice(purchprice );
axpurchLine.parmLineAmount(poStagingLine.IndentQty * purchprice);
//purchLine.PurchPrice = priceMarginModel.calculateProcessPurch(purchLine.ItemId, purchLine.VendAccount);
axPurchLine.doSave();
 
poStagingLine.selectForUpdate(true);
poStagingLine.PurchId = purchTable.PurchId;
poStagingLine.doupdate();
if( DmsSkuDetailsTable::findBySkuCode(poStagingLine.SkuCode).DmsSerialNumTracking)
{
select count(qty) from imeiDetailsQtyChk
where imeiDetailsQtyChk.Flag == NoYes::No
join poStagingLineQtyChk
where poStagingLineQtyChk.CompInvDate == imeiDetailsQtyChk.CompInvDate
&& poStagingLineQtyChk.CompInvNo == imeiDetailsQtyChk.CompInvNo
&& poStagingLineQtyChk.ProductCode == imeiDetailsQtyChk.ItemId
&& poStagingLineQtyChk.PurchId == purchLine.PurchId
&& poStagingLineQtyChk.ProductCode == purchLine.ItemId
&& poStagingLineQtyChk.Error == NoYes::No;
if(imeiDetailsQtyChk.Qty != purchLine.PurchReceivedNow)
{
throw error(strFmt("@DMS2394",imeiDetailsQtyChk.CompInvNo));
}
this.IMEInumInsert(purchLine,poStagingLine);
this.insSerialNumTable(purchLine,poStagingLine); //Only run when auto invoice will be done - 151015
}
 
 
}
//Register Serial number
//registerIMEI = this.registerIMEI(purchTable.PurchId, poStaging);
poLineCreate = false;
//Invoice PO
//if(registerIMEI)
//poInvoiced = this.invoicePO(purchTable);
//if(poInvoiced)
{
//this.serialNumTransInsert(purchTable.PurchId);
while select forUpdate poStagingLine where
poStagingLine.CompInvNo == poStaging.CompInvNo &&
poStagingLine.CompInvDate == poStaging.CompInvDate &&
poStagingLine.DistCode == poStaging.DistCode &&
poStagingLine.PurchaseOrder == poStaging.PurchaseOrder &&
poStagingLine.DistributionChannel == @'YPN1' &&
poStagingLine.Processed == NoYes::No
{
poStagingLine.Processed = NoYes::Yes;
poStagingLine.update();
}
}
ttsCommit;
update_recordSet imeiDetails
setting Flag = NoYes::Yes
join poStagingLine where
poStagingLine.CompInvDate == imeiDetails.CompInvDate
&& poStagingLine.CompInvNo == imeiDetails.CompInvNo
&& poStagingLine.ProductCode == imeiDetails.ItemId
&& poStagingLine.PurchId == purchTable.PurchId;
if(purchTable.PurchId)
info(strFmt("@DMS2535",purchTable.PurchId));
}
catch
{
ttsAbort;
//error log
ttsBegin;
while select forUpdate poStagingError where
poStagingError.CompInvNo == poStaging.CompInvNo &&
poStagingError.CompInvDate == poStaging.CompInvDate &&
poStagingError.DistCode == poStaging.DistCode &&
poStagingError.PurchaseOrder == poStaging.PurchaseOrder &&
poStagingError.DistributionChannel == @'YPN1'
{
poStagingError.Error = NoYes::Yes;
if(poLineCreate && poStagingError.RecId == poStagingLine.RecId) //error in po line
poStagingError.ErrorLog = strFmt("%1 %2 %3",poStagingError.ErrorLog, execDateTime,strRem(infolog.text(infologLine()),'\t'));
else if(!poLineCreate)
poStagingError.ErrorLog = strFmt("%1 %2 %3",poStagingError.ErrorLog, execDateTime,strRem(infolog.text(infologLine()),'\t'));
poStagingError.update();
}
ttsCommit;
}
}
}
}


Thursday 19 January 2017

job for posting SO

static void PostSO(Args _args)
{


    SalesTable                  salesTable;
    SalesFormLetter             salesFormLetter;
    SalesFormLetter_PackingSlip packingSlip;
    SalesFormLetter_Invoice     invoice;
    CustInvoiceJour             custInvoiceJour;
    str                         parmArgs;
    DmsInterCompanyPO           interCompanyPO = new DmsInterCompanyPO();

    salesTable = SalesTable::find('E618-002657'); //_args.record();
    //parmArgs = _args.parm();

    try
    {
        ttsBegin;


        salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
        salesFormLetter.update(salesTable);

        //for intercompany order
        /*
        if (parmArgs != "IntercompanyTransferOrder")
        {
            interCompanyPO.run(SalesTable.SalesId);
        }
        */

        packingSlip = salesFormLetter::construct(DocumentStatus::PackingSlip);
        packingSlip.showQueryForm(false);
        packingSlip.update(salesTable,today(),SalesUpdate::All,AccountOrder::None,false,false);

        invoice = salesFormLetter::construct(DocumentStatus::Invoice);
        invoice.showQueryForm(false);
        invoice.update(salesTable,today(),SalesUpdate::PackingSlip,AccountOrder::None,false,false);


        ttsCommit;

        select InvoiceId from custInvoiceJour order by InvoiceId where custInvoiceJour.SalesId == salesTable.SalesId;
        info(strFmt("@DMS1834",custInvoiceJour.InvoiceId));
    }
    catch
    {
        ttsAbort;
        error("@DMS1835");
    }


}

cancel SO in ax 2012

        salesTable = _args.record();
        //Cancel sales return
        SalesUpdateRemain::cancelRemainderOnOpenSalesLines(salestable);

by calling the above method the open salesline of a particular sales order will get cancelled.

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...