ledgerAccount _pr;
LedgerJournalTable _ljt;
LedgerJournalEngine ledgerJournalEngine;
ledgerJournalTrans _ljtr;
Args postArgs = new Args();
;
// looking for PurchReceipt account
_pr = InventPosting::item(InventAccountType::PurchReceipt,this.ItemId);
if (! _pr) throw error("Íå çàäàí ñ÷åò Ïðèõîä ïî çàêóïêå");
// create journal
_ljt = null;
_ljt.selectForUpdate();
_ljt.clear();
_ljt.initValue();
_ljt.JournalName = SalesParameters::find().PassToAgentJournalNameSec_W;
if (! _ljt.JournalName) throw error("Íå çàäàí æóðíàë 2-õ âàë. ñêëàäà â ïàðàìåòðàõ ìîäóëÿ Ðàññ÷åòû ñ êëèåíòàìè");
_ljt.Name = "Ïåðåäà÷à íà ðåàëèçàöèþ (2-õ âàë. ñêëàä)";
_ljt.CurrencyCode = companyinfo::secondaryCurrency_RU();
_ljt.CurrentOperationsTax = CurrentOperationsTax::WarehouseCur_RU;
_ljt.insert();
ledgerJournalEngine = new BMLedgerJournalEngine(null);
ledgerJournalEngine.newJournalActive(_lJT);
if (_ljt.CurrentOperationsTax != CurrentOperationsTax::WarehouseCur_RU) throw error("Íåïðàâèëüíûé òèï ó÷åòà â æóðíàëå " +_ljt.JournalName);
// create journal lines
_ljtr = null;
_ljtr.selectForUpdate();
_ljtr.clear();
_ljtr.initValue();
_ljtr.journalNum = _lJT.journalNum;
ledgerJournalEngine.numberSeqFormHandlerJournal().parmLedgerJournalTrans(_lJTr);
ledgerJournalEngine.formMethodDataSourceCreatePost();
ledgerJournalEngine.initValue(_lJTr);
// fill journal lines
_ljtr.CurrencyCode = companyinfo::secondaryCurrency_RU();
_ljtr.TransDate = this.PassToAgentDate_W;
_ljtr.AccountType = LedgerJournalACType::Ledger;
_ljtr.AccountNum = _pr;
_ljtr.OffsetAccountType = LedgerJournalACType::Ledger;
_ljtr.OffsetAccount = InventPostingBrokerage::LedgerAccount(this.ItemId);
[_ljtr.AmountCurCredit,_ljtr.ExchRate] = this.GetAmountAndRateForJournalMain();
if ( _ljtr.AmountCurCredit < 0.01) throw error("Íåò ñåáåñòîèìîñòè â âàëþòå " + companyinfo::secondaryCurrency_RU());
_ljtr.ExchRate = 0;
_ljtr.Dimension = this.Dimension;
// write journal lines
_lJTr.validateWrite();
ledgerJournalEngine.preWrite(_lJTr);
ledgerJournalEngine.formMethodDataSourceWritePre();
_lJTr.write();
ledgerJournalEngine.write(_lJTr);
// post journal now...
postArgs.record(_lJT);
postArgs.caller(NULL);
postArgs.parmEnum(0);
LedgerJournalPost::main(postArgs);
return _ljt.JournalNum;
|