AX 2009 创建普通日记账

void createLedgerJournal(IWS_PurchSettlementDetailsTable _detailsTable)
{
    LedgerJournalName       ledgerJournalName;
    LedgerJournalTable      ledgerJournalTable;
    LedgerJournalTrans      ledgerJournalTrans;
    LedgerJournalCheckPost  ledgerJournalCheckPost;
    NumberSeq               numberseq;
    LedgerJournalNameId     ledgerJournalNameId = "GL"; //General Journal
    VendTrans               vendTrans;
    VendTransOpen           transOpen;
    IWS_VendInvoice         vendInvoice;
    LedgerJournalEngine     ledgerJournalEngine;
    VendTable               vendTable;
    Voucher                 voucher;
    CustVendOpenTransManager manager;
    //LedgerJournalTxt        journalTxt;
    ;
    ttsbegin;

    select firstonly ledgerJournalTable
        where ledgerJournalTable.IWS_VendSettlementId == _detailsTable.VendSettlementId;
    if(ledgerJournalTable.RecId)
    {
        throw error(strfmt("@IWS1399",_detailsTable.VendSettlementId,
                                      ledgerJournalTable.JournalNum));
    }
    //create ledgerjournalTable
    ledgerJournalTable.clear();
    ledgerJournalTable.JournalNum   = JournalTableData::newTable(ledgerJournalTable).nextJournalId();
    vendTable                       = VendTable::find(_detailsTable.VendAccount);
    ledgerJournalName               = LedgerJournalName::find(LedgerJournalNameId);
    ledgerJournalTable.JournalName  = ledgerJournalName.JournalName;
    ledgerJournalTable.initFromLedgerJournalName();
    ledgerJournalTable.Name         = "@IWS1378";
    ledgerJournalTable.IWS_VendSettlementId = _detailsTable.VendSettlementId;
    ledgerJournalTable.doInsert();

    //create ledgerjournalTrans
    ledgerJournalEngine = new LedgerJournalEngine();
    ledgerJournalEngine.ledgerJournalTable(ledgerJournalTable);

    select sum(TotalAmount) from vendInvoice
        where vendInvoice.VendSettlementId == _detailsTable.VendSettlementId;
    numberseq                               = NumberSeq::newGetVoucherFromCode(ledgerJournalName.VoucherSeries);
    voucher                                 = numberseq.voucher();
    ledgerJournalTrans.Voucher              = voucher;
    ledgerJournalTrans.initValue();
    ledgerJournalTrans.JournalNum           = ledgerJournalTable.JournalNum;
    ledgerJournalTrans.AccountType          = LedgerJournalACType::Vend;
    ledgerJournalTrans.AccountNum           = _detailsTable.VendAccount;
    ledgerJournalTrans.TransDate            = systemdateget();
    ledgerJournalTrans.OffsetAccountType    = LedgerJournalACType::Ledger;
    ledgerJournalTrans.Txt                  = "@IWS1378";
    ledgerJournalEngine.IWS_initFromVendTable(ledgerJournalTrans,vendTable);
    ledgerJournalTrans.AmountCurDebit       = decround(vendInvoice.TotalAmount,2);
    ledgerJournalTrans.SettleVoucher        = SettlementType::SelectedTransact;
    ledgerJournalTrans.DocumentNum          = _detailsTable.VendSettlementId;
    ledgerJournalTrans.insert();
    select firstonly transOpen
        join  vendTrans
        where transOpen.AccountNum  == vendTrans.AccountNum
           && transOpen.RefRecId    == vendTrans.RecId
           && vendTrans.Invoice     == _detailsTable.VendSettlementId
           && vendTrans.AccountNum  == _detailsTable.VendAccount;
    if(transOpen.RecId)
    {
        manager = CustVendOpenTransManager::construct(ledgerJournalTrans);
        /*
        manager.calcAndUpdateFine_BR(transOpen.company(),
                                     transOpen,
                                     ledgerJournalTrans.TransDate);
        manager.calcAndUpdateFinInterest_BR(transOpen.company(),
                                            transOpen,
                                            ledgerJournalTrans.TransDate);
        */
        manager.updateTransMarked(transOpen, NoYes::Yes);
    }
    else
    {
        throw error(strfmt("@IWS1403",_detailsTable.VendAccount,
                                      _detailsTable.VendSettlementId));
    }
    //create branch ledgerjournaltrans
    while select vendInvoice
        where vendInvoice.VendSettlementId == _detailsTable.VendSettlementId
    {
        ledgerJournalTrans.clear();
        ledgerJournalTrans.Voucher              = voucher;
        ledgerJournalTrans.initValue();
        ledgerJournalTrans.JournalNum           = ledgerJournalTable.JournalNum;
        ledgerJournalTrans.AccountType          = LedgerJournalACType::Vend;

        ledgerJournalTrans.AccountNum           = _detailsTable.VendAccount;
        ledgerJournalTrans.TransDate            = systemdateget();
        ledgerJournalTrans.OffsetAccountType    = LedgerJournalACType::Ledger;
        ledgerJournalTrans.Txt                  = "@IWS1378";
        ledgerJournalEngine.IWS_initFromVendTable(ledgerJournalTrans,vendTable);
        ledgerJournalTrans.AmountCurCredit      = decround(vendInvoice.TotalAmount,2);
        //ledgerJournalTrans.SettleVoucher        = SettlementType::SelectedTransact;
        ledgerJournalTrans.Invoice              = vendInvoice.InvoiceId;
        ledgerJournalTrans.insert();
    }

    //create branch ledgerjournaltrans tax
    while select vendInvoice
        where vendInvoice.VendSettlementId == _detailsTable.VendSettlementId
    {
        ledgerJournalTrans.clear();
        ledgerJournalTrans.Voucher              = voucher;
        ledgerJournalTrans.initValue();
        ledgerJournalTrans.JournalNum           = ledgerJournalTable.JournalNum;
        ledgerJournalTrans.AccountType          = LedgerJournalACType::Ledger;

        ledgerJournalTrans.AccountNum           = "22210101";
        ledgerJournalTrans.TransDate            = systemdateget();
        ledgerJournalTrans.OffsetAccountType    = LedgerJournalACType::Ledger;
        //ledgerJournalTrans.SettleVoucher        = SettlementType::SelectedTransact;
        ledgerJournalTrans.Txt                  = "@IWS1378";
        ledgerJournalEngine.IWS_initFromOffsetAccount(ledgerJournalTrans);
        ledgerJournalTrans.AmountCurCredit      = decround(vendInvoice.TaxAmount,2);
        ledgerJournalTrans.Invoice              = vendInvoice.InvoiceId;
        ledgerJournalTrans.TaxCode              = "C03";
        ledgerJournalTrans.insert();
    }

    //create branch ledgerjournaltrans all tax
    select sum(TaxAmount) from vendInvoice
        where vendInvoice.VendSettlementId == _detailsTable.VendSettlementId;
    ledgerJournalTrans.clear();
    ledgerJournalTrans.Voucher              = voucher;
    ledgerJournalTrans.initValue();
    ledgerJournalTrans.JournalNum           = ledgerJournalTable.JournalNum;
    ledgerJournalTrans.AccountType          = LedgerJournalACType::Ledger;

    ledgerJournalTrans.AccountNum           = "22210101";
    ledgerJournalTrans.TransDate            = systemdateget();
    ledgerJournalTrans.OffsetAccountType    = LedgerJournalACType::Ledger;
    ledgerJournalTrans.Txt                  = "@IWS1378";
    ledgerJournalEngine.IWS_initFromOffsetAccount(ledgerJournalTrans);
    ledgerJournalTrans.AmountCurCredit      = - decround(vendInvoice.TaxAmount,2);
    //ledgerJournalTrans.SettleVoucher        = SettlementType::SelectedTransact;
    ledgerJournalTrans.Invoice              = _detailsTable.VendSettlementId;
    ledgerJournalTrans.TaxCode              = "C03";
    ledgerJournalTrans.insert();
    ttscommit;

    info(strfmt("@IWS1379",_detailsTable.VendSettlementId,
                           ledgerJournalTable.JournalNum));

}

  

posted @ 2013-03-22 14:25  adingkui  阅读(716)  评论(0编辑  收藏  举报