public PurchIdBase createPO(ItemId _itemid,Vendaccount _vendaccount,Inventsiteid _id,Inventlocationid _whs,
PurchPrice _price,Weight _grosswieght,Weight _netweight,purchunit _uom)
{
NumberSeq numberSeq;
PurchFormLetter purchFormLetter;
PurchLine purchLine;
InventDim inventDimloc;
InventItemPrice inventItemPriceLoc;
PurchId purchid;
ttsBegin;
numberSeq = NumberSeq::newGetNum(PurchParameters::numRefPurchId());
numberSeq.used();
purchTable.PurchId = numberSeq.num();
purchTable.initValue();
purchTable.OrderAccount= _vendaccount;
purchTable.initFromVendTable(VendTable::find(_vendaccount));
if (!purchTable.validateWrite())
{
throw Exception::Error;
}
purchTable.insert();
purchLine.clear();
purchLine.PurchId = purchTable.PurchId;
purchLine.ItemId = _itemid;
inventDimloc.clear();
inventDimloc.InventSiteId = _id;
inventDimloc.InventLocationId =_whs;
purchLine.InventDimId=InventDim::findOrCreate(inventDimloc).inventDimId;
inventItemPriceLoc = InventItemPrice::findCurrent(_itemid,CostingVersionPriceType::Cost,inventDimloc.inventDimId,
systemDateGet(),_id,InventItemCostingType::Standard);
//purchLine.RFGrossWeight = _grosswieght;
purchLine.RFNetWeight = _netweight;
purchLine.PurchUnit = _uom;
purchLine.createLine(true, true, true, true, true, true);
// get random amount nubmer
// purchLine.LineAmount = purchLine.calcLineAmount();
purchLine.selectForUpdate(true);
purchLine.PurchPrice = _price;
purchLine.PurchQty = _grosswieght;
purchLine.update();
ttsCommit;
info(strFmt("<%1> Purchase order has been created",purchTable.PurchId));
//po confirmation
ttsBegin;
purchTable = PurchTable::find(purchTable.PurchId);
purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
purchFormLetter.update(purchTable, strFmt("Inv_%1", purchTable.PurchId));
ttsCommit;
//PO Product Receipt
//ttsBegin;
//purchFormLetter = purchFormLetter::construct(DocumentStatus::PackingSlip);
//purchFormLetter.update(purchtable,
//"PO_"+purchTable.PurchId, // Invoice Number
//systemdateget()); // Transaction date
//Info(strFmt("%1 Product reciept recived with no. %1","PO_"+purchTable.PurchId ));
//ttsCommit;
return purchid;
}
No comments:
Post a Comment