static void CreateAndPostPurch(Args _args) { List il = new List(Types::Record); DocumentNum DocumentNum; TmpFrmVirtual TmpFrmVirtual; PurchLine localPurchLine; PurchTable localPurchTable; VendPackingSlipJour ventPackingSlipJour; PurchFormLetter_PackingSlip purchFormLetter_PackintSlip = PurchFormLetter::construct(DocumentStatus::PackingSlip); PurchFormLetter_PackingSlip purchFormLetter_Invoice = PurchFormLetter::construct(DocumentStatus::Invoice); ; ttsbegin; localPurchTable.clear(); localPurchTable.initValue(); localPurchTable.PurchId = NumberSeq::newGetNumFromCode("PONUM").num(); localPurchTable.initFromVendTable(VendTable::find("V-00001")); localPurchTable.PurchaseType = PurchaseType::Purch; localPurchTable.CurrencyCode = "RMB"; localPurchTable.PurchPoolId = "NOR"; localPurchTable.DeliveryDate = systemdateget(); localPurchTable.insert(); localPurchLine.clear(); localPurchLine.initValue(); localPurchLine.initFromPurchTable(localPurchTable); localPurchLine.ItemId = "100XA00125"; localPurchLine.initFromInventTable(InventTable::find(localPurchLine.ItemId)); localPurchLine.PurchQty = 1; localPurchLine.PurchUnit = InventTableModule::find(localPurchLine.ItemId,ModuleInventPurchSales::Invent).UnitId; localPurchLine.THK_2ndPurchQty = 0; localPurchLine.THK_2ndPurchUnit = InventTableModule::find(localPurchLine.ItemId,ModuleInventPurchSales::Invent).THK_2ndUnit; localPurchLine.PurchPrice = 1; localPurchLine.LineAmount = localPurchLine.calcLineAmount(); localPurchLine.THK_2ndQtyOrdered = localPurchLine.THK_2ndcalcQtyOrdered(); localPurchLine.QtyOrdered = localPurchLine.calcQtyOrdered(); localPurchLine.DeliveryDate = systemdateget(); localPurchLine.InventDimId = "T00309533"; localPurchLine.createLine(); info(strfmt("@SYS82024", localPurchTable.PurchId),'', SysInfoAction_TableField::newBuffer(localPurchTable)); if(localPurchTable) { DocumentNum = NumberSeq::newGetNumFromCode("POPS").num(); purchFormLetter_PackintSlip.update(localPurchTable, DocumentNum, systemDateGet(), PurchUpdate::All, AccountOrder::Account, NoYes::No, NoYes::No, false, noYes::Yes); } while select ventPackingSlipJour where ventPackingSlipJour.PurchId == localPurchTable.PurchId { tmpFrmVirtual.clear(); tmpFrmVirtual.TableNum = tableNum(VendPackingSlipJour); tmpFrmVirtual.RecordNo = ventPackingSlipJour.recid; tmpFrmVirtual.insert(); il.addEnd(tmpFrmVirtual); } purchFormLetter_Invoice.update(localPurchTable, NumberSeq::newGetNumFromCode("POINV").num(), systemDateGet(), PurchUpdate::All, AccountOrder::Account, NoYes::No, NoYes::No, false, noYes::Yes, il.pack()); ttscommit; }
template 2
static void CreatePurchTemplate2(Args _args) { SalesTable salesTable = SalesTable::find("VS1000031"); PurchCreateFromSalesOrder purchCreate; SalesLine getSalesLine; QueryRun queryRun; Query querySalesLine; TmpPurchLinePrice tmpPurchLinePrice; ; purchCreate = PurchCreateFromSalesOrder::construct(); purchCreate.getLast(); purchCreate.resetCurrentListCS(); purchCreate.salesTable(salesTable); purchCreate.callerRecord(salesTable); querySalesLine = new Query(); querySalesLine.addDataSource(tablenum(SalesLine)); queryRun = new QueryRun(purchCreate.querySalesLine(querySalesLine)); while (queryRun.next()) { getSalesLine = queryRun.get(tablenum(SalesLine)); select tmpPurchLinePrice where tmpPurchLinePrice.SalesId == getSalesLine.SalesId && tmpPurchLinePrice.LineNum == getSalesLine.LineNum && tmpPurchLinePrice.SalesLineRefRecId == getSalesLine.RecId; tmpPurchLinePrice.initFromInventTable(InventTable::find(getSalesLine.ItemId)); tmpPurchLinePrice.SalesId = getSalesLine.SalesId; tmpPurchLinePrice.LineNum = getSalesLine.LineNum; tmpPurchLinePrice.SalesLineRefRecId = getSalesLine.RecId; tmpPurchLinePrice.ItemId = getSalesLine.ItemId; tmpPurchLinePrice.AccountNum = "V-10001"; tmpPurchLinePrice.PurchQty = getSalesLine.SalesQty; tmpPurchLinePrice.PurchUnit = getSalesLine.SalesUnit; tmpPurchLinePrice.PriceUnit = getSalesLine.PriceUnit; tmpPurchLinePrice.CurrencyCode = "HKD"; tmpPurchLinePrice.Price = getSalesLine.SalesPrice; tmpPurchLinePrice.Included = NoYes::Yes; tmpPurchLinePrice.PriceSearched = NoYes::Yes; tmpPurchLinePrice.InventDimId = getSalesLine.InventDimId; tmpPurchLinePrice.write(); tmpPurchLinePrice.setLineAmount(); tmpPurchLinePrice.write(); } purchCreate.tmpPurchLinePrice(tmpPurchLinePrice); purchCreate.run(); }