1、创建盈亏日记账
// Copyright (C), 2021, CEU Co., Ltd. // USR Changed by 2021-09-24T16:33:07 谢宇帆 // Version : 1.0 // Description : // Return : static void LossProfitJounral(Args _args) { boolean post = false; SysInfoAction_Formrun formRun; void createLossProfitJournal( inventTable inventTable, inventDim inventDim, qty qty, qty costPrice = 0) { AxInventJournalTable axInventJournalTable; AxInventJournalTrans axInventJournalTrans; InventJournalId inventJournalId; InventDim newInventDim; InventDim findInventDim; inventJournalTable inventJournalTable; inventJournalTrans inventJournalTrans; ; ttsBegin; if (!inventJournalTable) { // create InventJournalTable axInventJournalTable = new AxInventJournalTable(); axInventJournalTrans = new AxInventJournalTrans(); axInventJournalTable.parmJournalType(InventJournalType::LossProfit); axInventJournalTable.parmJournalNameId(InventParameters::find().LossProfitJournalNameId); axInventJournalTable.parmNumOfLines(1); axInventJournalTable.save(); inventJournalTable = axInventJournalTable.inventJournalTable(); } // create InventJournalTrans inventJournalId = inventJournalTable.JournalId; axInventJournalTrans.parmJournalId(inventJournalId); axInventJournalTrans.parmTransDate(systemDateGet()); axInventJournalTrans.parmItemId(inventTable.ItemId); if (costPrice) axInventJournalTrans.parmCostPrice(costPrice); axInventJournalTrans.parmQty(qty); axInventJournalTrans.parmInventDimId(inventDim.inventDimId); axInventJournalTrans.setFieldAsModified(fieldnum(InventJournalTrans, ItemId)); axInventJournalTrans.save(); inventJournalTrans = axInventJournalTrans.inventJournalTrans(); //inventJournalTrans.modifiedField(fieldnum(InventJournalTrans, ItemId)); if (post && inventJournalTrans.RecId && inventJournalTrans.CostPrice) { // Posting of inventory adjustment InventJournalCheckPost::newPostJournal(inventJournalTable).run(); } ttsCommit; if (inventJournalTable) { info(strFmt("Inventory adjustment journal %1 is posted.", inventJournalTable.JournalId)); formRun = SysInfoAction_Formrun::newFormname(formStr(InventJournalTable)); formRun.parmCallerBuffer(inventJournalTable); formRun.run(); } } ; createLossProfitJournal(inventTable::find("1001"),inventDim::find("00000468_069"),100); }
2、登记盈亏日记账行数量
// Copyright (C), 2021, CEU Co., Ltd. // USR Changed by 2021-09-23T17:50:14 谢宇帆 // Version : 1.0 // Description : 登记盈亏库存日记账行 // Return : 已登记数量below is the code to automatically register AX 2009 Journal Line. void registerJournalTrans(InventQty _qty = this.Qty) { tmpInventTransWMS tmpInventTransWMS; inventTrans inventTrans; InventMovement movement; InventTransWMS_Register inventTransRegister; boolean first; inventTransIdSum inventTransIdSum; InventQty registeredQty, addQty; ; movement = InventMovement::construct(this); first = true; //if (movement.mustBeRegistered()) // 库存模型组勾选登记需求 { inventTransIdSum = new InventTransIdSum(this.inventTransId); registeredQty = inventTransIdSum.registered(); if (registeredQty >= _qty) { addQty = 0; } else { addQty = _qty - registeredQty; } while select inventTrans index hint TransIdIdx order by qty where inventTrans.inventTransId == this.InventTransId && inventTrans.statusIssue == StatusIssue::None && inventTrans.StatusReceipt >= StatusReceipt::Ordered && inventTrans.TransChildType == InventTransChildType::None && inventTrans.TransChildRefId == "" { tmpInventTransWMS.clear(); tmpInventTransWMS.initValue(); tmpInventTransWMS.initFromInventTrans(inventTrans); if (inventTrans.qty > addQty) inventTrans.updateSplit(addQty); tmpInventTransWMS.inventQty = inventTrans.Qty; tmpInventTransWMS.insert(); addQty = addQty - inventTrans.qty; first = false; if (! addQty) break; } } if (addQty) { throw error("@SYS53791"); } if (!first) { InventTransWMS_Register::updateInvent(this,tmpInventTransWMS); } }
3、取消登记
// Copyright (C), 2021, CEU Co., Ltd. // USR Changed by 2021-09-23T17:50:14 谢宇帆 // Version : 1.0 // Description : 取消登记盈亏库存日记账行 // Return : 已订购 void unRegisterJournalTrans(InventQty _qty = this.Qty) { tmpInventTransWMS tmpInventTransWMS; inventTrans inventTrans; InventMovement movement; InventTransWMS_Register inventTransRegister; boolean first; inventTransIdSum inventTransIdSum; InventQty ordered, addQty; ; movement = InventMovement::construct(this); first = true; //if (movement.mustBeRegistered()) //库存模型组勾选登记需求 { inventTransIdSum = new InventTransIdSum(this.inventTransId); ordered = inventTransIdSum.ordered(); if (ordered >= _qty) { addQty = 0; } else { addQty = _qty - ordered; } while select inventTrans index hint TransIdIdx order by qty where inventTrans.inventTransId == this.InventTransId && inventTrans.statusIssue == StatusIssue::None && inventTrans.StatusReceipt >= StatusReceipt::Registered && inventTrans.TransChildType == InventTransChildType::None && inventTrans.TransChildRefId == "" { tmpInventTransWMS.clear(); tmpInventTransWMS.initValue(); tmpInventTransWMS.initFromInventTrans(inventTrans); if (inventTrans.qty > addQty) inventTrans.updateSplit(addQty); tmpInventTransWMS.inventQty = -inventTrans.Qty;//负数代表取消登记 tmpInventTransWMS.insert(); addQty = addQty - inventTrans.qty; first = false; if (! addQty) break; } } if (addQty) { throw error("@SYS53791"); } if (!first) { InventTransWMS_Register::updateInvent(this,tmpInventTransWMS); } }