В общем, т. к. ни у кого не оказалось кода под рукой по моему вопросу для меня, просто оставлю это здесь. Данный код создает проводки в ГК (проводка + налоговые проводки) для закупки у которой есть ваучер накладная, проводки по поставщику и записи в TaxTrans. FYI.
X++:
static void DEV_CreateLedgerVoucherFromPostedPurch(Args _args)
{
DataAreaId dataAreaId = "XXX";
PurchId purchId = "XXXXXXXXXXX";
Voucher voucher = "XXXXXXXXXXX";
TransDate transDate = XX\XX\XXXX;
PurchTable purchTable;
PurchLine purchLine;
InventTable inventTable;
LedgerVoucher ledgerVoucher;
LedgerVoucherObject ledgerVoucherObject;
LedgerVoucherTransObject ledgerVoucherTransObject;
InventMov_Purch inventMovement;
LedgerBondClient_RU ledgerBondClient;
VendInvoiceTrans vendInvoiceTrans;
InventTrans inventTrans;
CurrencyExchangeHelper currencyExchHelper;
DimensionDefault mainAccountDefaultDimension;
LedgerDimensionDefaultAccount invoiceAccount;
Ledger ledger;
RefRecId ipRecId;
InventPosting ip;
LedgerDimensionAccount ledgerDimensionOffset;
TaxGroup taxGroup;
TaxOnItem taxOnItem;
TaxTable taxTable;
TaxAccountGroup taxAccountGroup;
TaxLedgerAccountGroup taxLedgerAccountGroup;
TaxTrans taxTransLoc;
LedgerDimensionDefaultAccount ledgerDimensionDefaultAccount;
TaxTrans findTaxTrans(voucher _v, TransDate _t, TaxCode _taxCode)
{
TaxTrans taxTransInvoice;
select firstonly taxTransInvoice
where taxTransInvoice.Voucher == _v &&
taxTransInvoice.TransDate == _t &&
taxTransInvoice.TaxCode == _taxCode;
return taxTransInvoice;
}
changeCompany (dataAreaId)
{
ledger = Ledger::findByLegalEntity(CompanyInfo::find().RecId);
ledgerVoucher = LedgerVoucher::newLedgerPost(DetailSummary::Summary, SysModule::Purch, '');
ledgerVoucher.lastTransDate(transDate);
while select purchTable where purchTable.PurchId == purchId
{
ledgerVoucherObject = LedgerVoucherObject::newReference(voucher, transDate);
ledgerVoucherObject.parmVoucherCheck(false);
ledgerVoucherObject.parmDocument(transDate, voucher);
ledgerVoucher.addVoucher(ledgerVoucherObject);
ledgerBondClient = ledgerVoucherObject.ledgerBondClient_RU();
currencyExchHelper = CurrencyExchangeHelper::newExchangeDate(Ledger::primaryLedger(CompanyInfo::findDataArea(dataAreaId).RecId), ledgerVoucherObject.parmAccountingDate());
while select purchLine
where purchLine.PurchId == purchTable.PurchId
&& ! purchLine.IsDeleted
join vendInvoiceTrans
where vendInvoiceTrans.InventTransId == purchLine.InventTransId
&& vendInvoiceTrans.PurchID == purchTable.PurchId
{
inventTable = InventTable::find(purchLine.ItemId);
inventMovement = InventMov_Purch::newFromPurchLine(purchLine);
ledgerDimensionDefaultAccount = inventMovement.accountBalanceSheet();
ledgerDimensionOffset = DimensionDefaultingService::serviceCreateLedgerDimension(
VendLedgerAccounts::summaryLedgerDimension(purchLine.VendAccount, purchTable.PostingProfile ? purchTable.PostingProfile : VendParameters::find().PostingProfile),
vendInvoiceTrans.DefaultDimension);
ledgerVoucherTransObject = LedgerVoucherTransObject::newBasicDefault(
ledgerVoucherObject,
LedgerPostingType::PurchReceipt,
DimensionDefaultingService::serviceCreateLedgerDimension(
ledgerDimensionDefaultAccount,
vendInvoiceTrans.DefaultDimension),
vendInvoiceTrans.CurrencyCode,
vendInvoiceTrans.costValuePosted(),
vendInvoiceTrans.LineAmountMST,
Currency::curAmount2CurAmount(vendInvoiceTrans.LineAmountMST, ledger.AccountingCurrency, ledger.ReportingCurrency));
ledgerVoucherObject.addTrans(ledgerVoucherTransObject);
ledgerVoucherTransObject = LedgerVoucherTransObject::newBasicDefault(
ledgerVoucherObject,
LedgerPostingType::PurchReceipt,
ledgerDimensionOffset,
vendInvoiceTrans.CurrencyCode,
- vendInvoiceTrans.costValuePosted(),
- vendInvoiceTrans.LineAmountMST,
- Currency::curAmount2CurAmount(vendInvoiceTrans.LineAmountMST, ledger.AccountingCurrency, ledger.ReportingCurrency));
ledgerVoucherObject.addTrans(ledgerVoucherTransObject);
ledgerBondClient.bondLast2();
while select taxOnItem where taxOnItem.TaxItemGroup == purchLine.TaxItemGroup
{
taxAccountGroup = TaxTable::findAccountGroup(taxOnItem.TaxCode);
if (taxAccountGroup)
{
taxLedgerAccountGroup = TaxLedgerAccountGroup::find(taxAccountGroup);
taxTransLoc = findTaxTrans(voucher, transDate, taxOnItem.TaxCode);
if (taxTransLoc)
{
ledgerVoucherTransObject = LedgerVoucherTransObject::newBasicDefault(
ledgerVoucherObject,
LedgerPostingType::PurchReceipt,
DimensionDefaultingService::serviceCreateLedgerDimension(taxLedgerAccountGroup.TaxIncomingLedgerDimension,
vendInvoiceTrans.DefaultDimension),
taxTransLoc.CurrencyCode,
taxTransLoc.taxAmountCur_W(),
taxTransLoc.netTaxAmountMST(),
Currency::curAmount2CurAmount(taxTransLoc.netTaxAmountMST(), ledger.AccountingCurrency, ledger.ReportingCurrency));
ledgerVoucherTransObject.parmTaxParentReferenceRecId(taxTransLoc.RecId);
ledgerVoucherTransObject.parmTaxParentReferenceTableId(taxTransLoc.TableId);
ledgerVoucherObject.addTrans(ledgerVoucherTransObject);
ledgerVoucherTransObject = LedgerVoucherTransObject::newBasicDefault(
ledgerVoucherObject,
LedgerPostingType::PurchReceipt,
ledgerDimensionOffset,
taxTransLoc.CurrencyCode,
- taxTransLoc.taxAmountCur_W(),
- taxTransLoc.netTaxAmountMST(),
- Currency::curAmount2CurAmount(taxTransLoc.netTaxAmountMST(), ledger.AccountingCurrency, ledger.ReportingCurrency));
ledgerVoucherTransObject.parmTaxParentReferenceRecId(taxTransLoc.RecId);
ledgerVoucherTransObject.parmTaxParentReferenceTableId(taxTransLoc.TableId);
ledgerVoucherObject.addTrans(ledgerVoucherTransObject);
ledgerBondClient.bondLast2();
}
}
}
}
ledgerVoucher.end();
}
}
info('All done.');
}
P.S.: из кода убран весь кастом.
Код который подобные закупки ищет:
X++:
static void DEV_FindEmptyGeneraFromPostedPurch(Args _args)
{
DataAreaId checkedCompany = 'XXXXXX';
LedgerPostingType ledgerPostingType = LedgerPostingType::None;
PurchTable purchTable;
VendInvoiceJour vendInvoiceJour;
VendTrans vendTrans;
LedgerEntry localLedgerEntry;
GeneralJournalEntry localGeneralJournalEntry;
GeneralJournalAccountEntry localGeneralJournalAccountEntry;
GeneralJournalAccountEntry offsetGeneralJournalAccountEntry;
GeneralJournalAccountEntry_W generalJournalAccountEntryW;
SubledgerVoucherGeneralJournalEntry localSubledgerVoucherGeneralJournalEntry;
changeCompany (checkedCompany)
{
while select vendInvoiceJour
exists join purchTable
where purchTable.PurchId == vendInvoiceJour.PurchId
exists join vendTrans
where vendTrans.Voucher == vendInvoiceJour.LedgerVoucher
&& vendTrans.TransDate == vendInvoiceJour.InvoiceDate
&& vendTrans.AccountNum == vendInvoiceJour.InvoiceAccount
{
select firstOnly RecId from localSubledgerVoucherGeneralJournalEntry
where localSubledgerVoucherGeneralJournalEntry.Voucher == vendInvoiceJour.LedgerVoucher &&
localSubledgerVoucherGeneralJournalEntry.VoucherDataAreaId == curext() &&
localSubledgerVoucherGeneralJournalEntry.AccountingDate == vendInvoiceJour.InvoiceDate
join RecId, PostingLayer, JournalCategory from localGeneralJournalEntry
where localGeneralJournalEntry.RecId == localSubledgerVoucherGeneralJournalEntry.GeneralJournalEntry &&
localGeneralJournalEntry.Ledger == Ledger::current()
join localGeneralJournalAccountEntry
where localGeneralJournalAccountEntry.GeneralJournalEntry == localGeneralJournalEntry.RecId &&
(ledgerPostingType == LedgerPostingType::None ||
localGeneralJournalAccountEntry.PostingType == ledgerPostingType)
outer join localLedgerEntry
where localLedgerEntry.GeneralJournalAccountEntry == localGeneralJournalAccountEntry.RecId
outer join * from generalJournalAccountEntryW
where generalJournalAccountEntryW.GeneralJournalAccountEntry == localGeneralJournalAccountEntry.RecId;
if (! localSubledgerVoucherGeneralJournalEntry.recid)
{
info(strFmt("Компания: %1. Заказ на покупку: %2. Поставщик: %3, %4", curext(), vendInvoiceJour.PurchId, vendInvoiceJour.purchTable().OrderAccount, vendInvoiceJour.purchTable().PurchName));
}
}
}
}