Sunday, October 26, 2014

All Account Receivable Journal Import:



Account Receivable Journal Import:

filename        = dialogFilename.value();
    transdate        = dialogFromDate.value();
    journalNameId   = dialogledger.Value();
    impBal          = dialogimpBal.value();
    journalName     = dialogJournalName.value();
    journalTxt      = dialogJournalTxt.value();

Free Taxt Invoice Journal:
CustInvoiceTable                        custInvoiceTable,custinv;
    CustInvoiceLine                         custInvoiceLine;
    CustTable                               custTable;
    MainAccount                             mainAccount;
    DimensionAttributeValueCombination      valueCombination;
    LedgerJournalTrans                      ledgerTable;
    CustPostInvoice                         custPostInvoice;
    LineNum                                 lineNum;
    int                                     i;
    str                                     offdimensn,ledgerAccount;
    container                               offdim;
    purchTable                              purchtable;
    purchPurchaseOrderController            purchPurchaseOrderController;
    PurchPurchaseOrderContract              PurchPurchaseOrderContract;
    RecordSortedList                        recordSortedList;
    CustInvoiceTable                        currentCustInvoiceTable;
    CustPrintOutInvoice                     custPrintOutInvoice;
    NoYes                                   usePrintManagement;
    FreeTextInvoiceController               freeTextInvoiceController;
    FreeTextInvoiceContract                 freeTextInvoiceContract;
    str                                     TaxGroup,TaxItemGroup,Description,CustAccount;
    Amount                                  UnitPrice;
    real                                    qty;
    first  = true;
    csvFiles = new CommaIo(filename, 'r');
    csvFiles.inFieldDelimiter(',');
    readCon = csvFiles.read();
    try
    {
        ttsBegin;
        while(csvFiles.status() == IO_Status::OK)
        {
            readCon = csvFiles.read();
            if(readCon)
            {
                CustAccount = conPeek(readCon,7);
                if (first)
                {
                    custTable = CustTable::find(CustAccount);
                    custInvoiceTable.initFromCustTable(custTable);
                    custInvoiceTable.insert();
                    first = false;
                }
                if (readCon )//dont insert first record of file : header
                {
                    qty  = conPeek(readCon,1);
                    TaxGroup = conPeek(readCon,2);
                    TaxItemGroup = conPeek(readCon,3);
                    Description = conPeek(readCon,4);
                    UnitPrice = conPeek(readCon,5);
                    ledgerAccount = conPeek(readCon,6);
                    custInvoiceLine.clear();
                    custInvoiceLine.initValue();
                    offdimensn = strFmt("%1,%1",ledgerAccount);
                    offdim =str2con(offdimensn);
                    custInvoiceLine.LedgerDimension = (AxdDimensionUtil::getLedgerAccountId(offdim));//valueCombination.RecId;
                    custInvoiceLine.initFromCustInvoiceTable(custInvoiceTable);
                    custInvoiceLine.Description     = Description;//'FreeTxIv' + int2str(i);
                    custInvoiceLine.TaxGroup        = TaxGroup;//"No-Tax";
                    custInvoiceLine.TaxItemGroup    = TaxItemGroup;//'ALL';
                    custInvoiceLine.Quantity        = qty;//1;
                    custInvoiceLine.UnitPrice       = UnitPrice;//300.00;
                    custInvoiceLine.AmountCur       = custInvoiceLine.Quantity * custInvoiceLine.UnitPrice;
                    custInvoiceLine.ParentRecId     = custInvoiceTable.RecId;
                    lineNum += 1;
                    custInvoiceLine.LineNum = lineNum;
                    custInvoiceLine.insert();
                    custPostInvoice = new CustPostInvoice(custInvoiceTable);
                    custPostInvoice.run();
                //info(strFmt("%1",custInvoiceTable.OrderAccount));
                }
            }
        }
        ttsCommit;
    icount--;//Remove header recount from total record count
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }

//
//
AR à Payment Journal import:
LedgerJournalName       ledgerJournalName;
    AxLedgerJournalTrans    trans  = new AxLedgerJournalTrans();
    AxLedgerJournalTable    header = new AxLedgerJournalTable();
    str                     invoiceNumber,vendorAccount,txt,dimensn,offdimensn,offsetAccount;
    container               dimm,offdim;
    Amount                  amountCurDebit,amountCurCredit;
    MainAccount             mainAccount;
    VendTable               vendTable;
    first  = true;
    csvFiles = new CommaIo(filename, 'r');
    csvFiles.inFieldDelimiter(',');
    readCon = csvFiles.read();
    try
    {
        ttsBegin;
        while(csvFiles.status() == IO_Status::OK)
        {
            icount++;
            readCon = csvFiles.read();

            if(readCon)
            {
                if (first)
                {
                    header.parmJournalName(journalNameId);
                    select ledgerJournalName where ledgerJournalName.JournalName == journalNameId;
                    header.parmJournalType(ledgerJournalName.JournalType);

                    header.save();
                    first = false;
                }
                if (readCon && icount )//dont insert first record of file : header
                {
                    Transactiondate = transdate;
                    invoiceNumber = conPeek(readCon,1);
                    vendorAccount = conPeek(readCon,2);
                    txt = conPeek(readCon,3);
                    currencycode = conPeek(readCon,4);
                    amountCurDebit = conPeek(readCon,5);
                    amountCurCredit = conPeek(readCon,6);
                    offsetAccount    = conPeek(readCon,7);

                    trans.parmJournalNum(header.ledgerJournalTable().JournalNum);
                    dimensn = strFmt("%1,%1",vendorAccount);//strFmt("%1-%2-%3,%1,2,department,%2,costcenter,%3",ledgerAccount,department,costcenter);
                    dimm = str2con(dimensn);
                    trans.parmAccountType(LedgerJournalACTypE::Vend);
                    trans.parmLedgerDimension(DimensionStorage::getDynamicAccount(vendorAccount, LedgerJournalACType::vend)); //AxdDimensionUtil::getLedgerAccountId(dimm));
                    trans.parmTxt(txt);
                    trans.parmDocumentDate(TransDate);
                    trans.parmTransDate(TransDate);
                    trans.parmAmountCurDebit(AmountCurDebit);
                    trans.parmAmountCurCredit(AmountCurCredit) ;
                    trans.parmCompany(curext());
                    trans.parmCurrencyCode(currencycode);
                    trans.parmInvoice(invoiceNumber);
                    trans.parmExchRate(1);
                    offdimensn = strFmt("%1,%1",offsetAccount);
                    offdim =str2con(offdimensn);
                    mainAccount = mainAccount::findByMainAccountId(offsetAccount);
                    if(!mainAccount)
                    {
                        trans.parmOffsetLedgerDimension( DimensionStorage::getDynamicAccount(offsetAccount, LedgerJournalACType::Bank));
                            trans.parmOffsetAccountType(LedgerJournalACTypE::Bank);
                    }
                    else
                    {
                        trans.parmOffsetLedgerDimension(AxdDimensionUtil::getLedgerAccountId(offdim));
                        trans.parmOffsetAccountType(LedgerJournalACTypE::Ledger);
                    }
                    trans.parmVoucher(NumberSeq::newGetVoucherFromId((LedgerJournalName::find(JournalNameId).NumberSequenceTable)).voucher());
                    Trans.currentRecord().insert();
                    inserted++;
                    trans.save();
                 }
           }
        }
        ttsCommit;
     icount--;//Remove header recount from total record count
    }
    catch(Exception::Error)
    {
        info(strFmt("%1 %2",Exception::Error,icount));
    }

    args = new Args();
    args.record(LedgerJournalTable::find(header.ledgerJournalTable().JournalNum ));

    new MenuFunction(MenuItemDisplayStr(LedgerJournalTable),MenuItemType::Display).run(args);
//
//

No comments:

Post a Comment

Convert Call stack to readable format in D365FO X++

//Input --container _xppCallStack = xSession::xppCallStack();  Public static str POL_formatXppCallStack(container _xppCallStack, int _skipFr...