Create PO from code - Ref pepper
static void CreatePO(ItemId _itemId,
InventSiteId _inventSiteId,
InventLocationId _inventLocationId,
PurchPrice _purchPrice,
PurchQty _purchQty,
EcomBusinessModel _ecomBusinessModel,
VendAccount _vendAccount)
{
NumberSeq numberSeq;
PurchTable purchTable;
PurchLine purchLine;
boolean purchOrderCreated, PurchLineAvailable = false;
PurchaseType purchaseType;
InventDim inventDim;
str preVendAccount;
int64 i;
PurchFormLetter purchFormLetter;
PurchTable_Ecom purchTableEcom;
EcommerceParameters ecomParameter = EcommerceParameters::find();
ttsbegin;
if (preVendAccount != _vendAccount)
{
purchOrderCreated = false;
if (!purchOrderCreated)
{
purchTable.clear();
purchTable.initValue();
purchTable.initFromVendTable(VendTable::find(_vendAccount));
numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
numberSeq.used();
purchTable.PurchaseType = PurchaseType::Purch;
purchTable.PurchId = numberSeq.num();
purchTable.CurrencyCode = VendTable::find(_vendAccount).Currency;
purchTable.InventSiteId = _inventSiteId;
purchTable.InventLocationId = _inventLocationId;
purchTable.AccountingDate = today();
purchTable.DeliveryDate = today();
if (!purchTable.validateWrite())
throw Exception::Error;
else
purchTable.insert();
purchTableEcom = purchTable.purchTable_Ecom();
purchTableEcom.EcomDocumentType = EcomProcurementType::OnDemand;
purchTable.packPurchTable_Ecom(purchTableEcom);
purchTable.SysExtensionSerializerMap::postUpdate();
purchOrderCreated = true;
i = 0;
}
i = i + 1;
purchLine.clear();
inventDim.clear();
purchLine.initValue();
purchLine.ItemId = _itemId;
purchLine.PurchaseType = PurchaseType::Purch;
purchLine.PurchId = purchTable.PurchId;
inventDim.InventSiteId = _inventSiteId;
inventDim.InventLocationId = _inventLocationId;
purchLine.InventDimId = InventDim::findOrCreate(inventDim).InventDimId;
purchLine.PurchPrice = _purchPrice;
purchLine.createLine(true,true,true,true,true,false,true);
purchLine.PurchQty = _purchQty;
purchLine.QtyOrdered = _purchQty;
purchLine.PurchPrice = _purchPrice;
purchLine.EcomBusinessModel = _ecomBusinessModel;
purchLine.LineAmount = purchLine.calcLineAmount();
purchLine.calcQtyOrdered(purchLine.PurchQty);
purchLine::modifyPurchQty(purchLine,inventDim,false);
InventMovement::bufferSetRemainQty(purchLine);
purchLine.TaxGroup = VendTable::find(_vendAccount).TaxGroup;
purchLine.Update();
preVendAccount = _vendAccount;
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable,purchTable.PurchId,systemDateGet(),PurchUpdate::All,AccountOrder::None,false,false);
ttsCommit;
}
}
static void CreatePO(ItemId _itemId,
InventSiteId _inventSiteId,
InventLocationId _inventLocationId,
PurchPrice _purchPrice,
PurchQty _purchQty,
EcomBusinessModel _ecomBusinessModel,
VendAccount _vendAccount)
{
NumberSeq numberSeq;
PurchTable purchTable;
PurchLine purchLine;
boolean purchOrderCreated, PurchLineAvailable = false;
PurchaseType purchaseType;
InventDim inventDim;
str preVendAccount;
int64 i;
PurchFormLetter purchFormLetter;
PurchTable_Ecom purchTableEcom;
EcommerceParameters ecomParameter = EcommerceParameters::find();
ttsbegin;
if (preVendAccount != _vendAccount)
{
purchOrderCreated = false;
if (!purchOrderCreated)
{
purchTable.clear();
purchTable.initValue();
purchTable.initFromVendTable(VendTable::find(_vendAccount));
numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
numberSeq.used();
purchTable.PurchaseType = PurchaseType::Purch;
purchTable.PurchId = numberSeq.num();
purchTable.CurrencyCode = VendTable::find(_vendAccount).Currency;
purchTable.InventSiteId = _inventSiteId;
purchTable.InventLocationId = _inventLocationId;
purchTable.AccountingDate = today();
purchTable.DeliveryDate = today();
if (!purchTable.validateWrite())
throw Exception::Error;
else
purchTable.insert();
purchTableEcom = purchTable.purchTable_Ecom();
purchTableEcom.EcomDocumentType = EcomProcurementType::OnDemand;
purchTable.packPurchTable_Ecom(purchTableEcom);
purchTable.SysExtensionSerializerMap::postUpdate();
purchOrderCreated = true;
i = 0;
}
i = i + 1;
purchLine.clear();
inventDim.clear();
purchLine.initValue();
purchLine.ItemId = _itemId;
purchLine.PurchaseType = PurchaseType::Purch;
purchLine.PurchId = purchTable.PurchId;
inventDim.InventSiteId = _inventSiteId;
inventDim.InventLocationId = _inventLocationId;
purchLine.InventDimId = InventDim::findOrCreate(inventDim).InventDimId;
purchLine.PurchPrice = _purchPrice;
purchLine.createLine(true,true,true,true,true,false,true);
purchLine.PurchQty = _purchQty;
purchLine.QtyOrdered = _purchQty;
purchLine.PurchPrice = _purchPrice;
purchLine.EcomBusinessModel = _ecomBusinessModel;
purchLine.LineAmount = purchLine.calcLineAmount();
purchLine.calcQtyOrdered(purchLine.PurchQty);
purchLine::modifyPurchQty(purchLine,inventDim,false);
InventMovement::bufferSetRemainQty(purchLine);
purchLine.TaxGroup = VendTable::find(_vendAccount).TaxGroup;
purchLine.Update();
preVendAccount = _vendAccount;
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable,purchTable.PurchId,systemDateGet(),PurchUpdate::All,AccountOrder::None,false,false);
ttsCommit;
}
}
No comments:
Post a Comment