Что-то типа того:
PHP код:
SalesLineTransfer_FLX salesLineTransfer;
InventDim inventDimTo;
InventJournalName inventJournalName;
InventJournalTable inventJournalTable;
InventJournalTrans inventJournalTrans;
LineNum lineNum = 0;
JournalTableData journalTableData;
JournalTransData journalTransData;
JournalTransMap journalTrans_last;
;
select firstfast firstonly inventJournalName
where inventJournalName.JournalNameId == SalesParameters.SalesLineTransferJournalId_FLX
&& inventJournalName.JournalType == InventJournalType::Transfer;
if (inventJournalName.RecId == 0)
{
throw error("?? ????????? ????? ?????????? ?? ?????? ????????!");
}
ttsbegin;
inventJournalTable.clear();
inventJournalTable.initValue();
inventJournalTable.DeletePostedLines = NoYes::No;
inventJournalTable.Description = inventJournalName.Description;
inventJournalTable.EmplId = EmplTable::userId2EmplId(curuserid());
inventJournalTable.JournalNameId = inventJournalName.JournalNameId;
inventJournalTable.JournalType = InventJournalType::Transfer;
inventJournalTable.VoucherSeqId = inventJournalName.VoucherSeqId;
inventJournalTable.SalesId_FLX = salesTable.SalesId;
inventJournalTable.write();
journalTableData = JournalTableData::newTable(inventJournalTable);
while select salesLineTransfer
where salesLineTransfer.SalesId == salesTable.SalesId
&& salesLineTransfer.Marked == NoYes::Yes
{
lineNum += 1;
inventDimTo = InventDim::findOrCreateInventLocationId(salesLineTransfer.MarkedLocationTo);
inventJournalTrans.clear();
inventJournalTrans.initFromInventJournalTable(inventJournalTable);
journalTransData = new journalTransData(inventJournalTrans, journalTableData);
inventJournalTrans.LineNum = lineNum;
inventJournalTrans.TransDate = systemdateget();
inventJournalTrans.ItemId = salesLineTransfer.ItemId;
inventJournalTrans.Qty = -salesLineTransfer.MarkedQty;
inventJournalTrans.ToInventDimId = inventDimTo.inventDimId;
inventJournalTrans.PriceUnit = 1.0;
inventJournalTrans.InventTransId = NumberSeq::newGetNum(InventParameters::numRefInventTransId()).num();
if (journalTableData.journalVoucherNum() && journalTableData.journalTable().voucherDraw == JournalVoucherDraw::Entering)
journalTransData.initVoucher(journalTrans_last.voucher,true);
inventJournalTrans.InventDimId = salesLineTransfer.InventDimId;
inventJournalTrans.insert();
if (inventJournalTrans.recId)
journalTrans_last = inventJournalTrans.data();
}
inventJournalTable.NumOfLines = LineNum;
inventJournalTable.write();
ttscommit;
А как разнести - это уже дело техники (PostJournal)
но я бы это свалил на пользователя... не стал бы автоматом разность.
С Уважением,
Георгий.