Wednesday 6 January 2016

PO creation by ax web service for multiple lines

void createPO()
{
TxtPoStaging poStaging, poStagingLine, poStagingError;
TxtPoStaging poStagingLineQtyChk;
VendAccount vendor;
PurchTable purchTable;
PurchLine purchLine;
VendTable vendTable;
AxPurchTable axPurchTable;
AxPurchLine axPurchLine;
sParameters sParamaters;
InventDim inventDim;
//boolean poInvoiced;
//boolean registerIMEI;
boolean poLineCreate;
//DmsMdmOrderReasonParameter orderReasonParam;
ProductConfigView productVariantsPerCompany;
EcoResConfiguration configuration;
ItemId itemId;

while select poStaging
group by CompInvNo, CompInvDate, DistCode, PurchaseOrder
where poStaging.Processed == NoYes::No
&& poStaging.Error == NoYes::No
&& poStaging.DistributionChannel == @'YPN1'
{

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
}
}
}

}

No comments:

Post a Comment

intercompany PO multiple product receipt by x++

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