Hi Sanjeev,

Following is the code that creates the Journal, marks the transaction 
(indicated by invoiceid) for settlement and then posts the Journal.


server static boolean ProcessPayment(CustPaymMode _paymMode, 
AccountNum _accountNum, InvoiceId _invoiceId, AmountCurCredit 
_amountCurCredit, TransDate _transDate = SystemDateGet())
{
    LedgerJournalName       ledgerJournalName;
    LedgerJournalTable      ledgerJournalTable;
    LedgerJournalTrans      ledgerJournalTrans;
    LedgerJournalCheckPost  ledgerJournalCheckPost;

    Common                  common;
    NumberSeq               numberseq;
    CustTransOpen           custTransOpen;
    CustInvoiceSalesLink    custInvoiceSalesLink;
    Specification           specOffsetVoucher;

    boolean                 result = false;
    CompanyInfo             company = CompanyInfo::find();
    SalesId                 salesId = '';
    CustTable               cust = CustTable::find(_accountNum);
    ;

    // if we have invoice id that means we are applying a payment
    // on invoice otherwise on account payment
    if(_invoiceId != '')
    {
        select firstonly custInvoiceSalesLink
            where custInvoiceSalesLink.invoiceId == _invoiceId;

    }


    try
    {
        ttsbegin;

        // Journal Name should be warehouse specific
        select firstonly ledgerJournalName
            where ledgerJournalName.JournalType == 
LedgerJournalType::CustPayment
                && ledgerJournalName.JournalName == 'Cust';

        if(ledgerJournalName)
        {
            ledgerJournalTable.JournalName = 
ledgerJournalName.JournalName;
            ledgerJournalTable.Name = ledgerJournalName.Name;
            ledgerJournalTable.insert();

            if(ledgerJournalTable)
            {
                numberseq = NumberSeq::NewGetVoucherFromCode
(ledgerJournalName.VoucherSeries);
                ledgerJournalTrans.JournalNum           = 
ledgerJournalTable.JournalNum;
                ledgerJournalTrans.Voucher              = 
numberseq.voucher();
                ledgerJournalTrans.TransDate            = _transDate;
                ledgerJournalTrans.AccountType          = 
LedgerJournalACType::Cust;
                ledgerJournalTrans.Txt                  = strfmt('%1%
2', parameters.AdvSetTransTxt, _transDate);
                ledgerJournalTrans.OffsetAccountType    = 
ledgerJournalName.OffsetAccountType;
                ledgerJournalTrans.OffsetAccount        = 
ledgerJournalName.OffsetAccount;
                ledgerJournalTrans.Dimension            = 
ledgerJournalName.Dimension;
                ledgerJournalTrans.CurrencyCode         = 
company.CurrencyCode;
                ledgerJournalTrans.ExchRate             = 
ExchRates::find(company.CurrencyCode, datenull(), NoYes::No, 
NoYes::No).ExchRate;
                ledgerJournalTrans.TransactionType      = 
LedgerTransType::Payment;
                ledgerJournalTrans.Dimension[4]         = 
routeTable.DriverName1;
                ledgerJournalTrans.PaymMode             = _paymMode;
                if(_invoiceId != '')
                    ledgerJournalTrans.SettleVoucher    = 
SettlementType::SelectedTransact;
                else
                    ledgerJournalTrans.SettleVoucher    = 
SettlementType::None;
                ledgerJournalTrans.AccountNum           = _accountNum;
                ledgerJournalTrans.AmountCurCredit      = 
_amountCurCredit;
                ledgerJournalTrans.insert();

                // Mark invoice for settlement only if we are doing 
invoice payment
                // not for account payment.
                if(_invoiceId != '')
                {
                    select custTransOpen
                        where custTransOpen.AccountNum == _accountNum
                            && custTransOpen.RefRecId == 
CustTrans::findFromInvoice(_invoiceId).RecId;
                    if(custTransOpen)
                    {
                        common = ledgerJournalTrans;
                        specOffsetVoucher = 
Specification_OffsetVoucher::newCommon(common, true);
                        if (!specOffsetVoucher.isMarked
(custTransOpen.TableId, custTransOpen.RecId))
                        {
                            if (ledgerJournalTrans.RecId)
                            {
                                specOffsetVoucher.create
(custTransOpen.TableId, custTransOpen.RecId, _amountCurCredit, 
company.CurrencyCode);
                            }
                        }
                    }
                }

                // Journal Created now post it
                ledgerJournalCheckPost = 
LedgerJournalCheckPost::newLedgerJournalTable(ledgerJournalTable, 
NoYes::Yes);
                ledgerJournalCheckPost.run();

                result = true;
            }
        }
        ttscommit;
    }
    catch
    {
        result = false;
    }

    return result;
}

You can create a form that opens the text file and then load the data 
into a temporary table and then when the user is satisfied with the 
data create the journal using above code(above code creates a jounral 
for one transaction only but it can be modified). Hope this will help.

Navid



--- In Axapta-Knowledge-Village@yahoogroups.com, "Armaan" 
<[EMAIL PROTECTED]> wrote:
>
> Hi friends,
> i have a requirement like i have a text file i need to import the 
text
> file and create a journal and line with the customer name..and for
> that customer i need to check all the open transactions and mark the
> transactions for settlement..
> the file contains all major details like invoice number,paym
> reference,total amount,voucher number etc...
>  i need to start the process form AR periodic,i need to have a 
dialog
> box ..open the file ,,read the file and create journal,line and 
settle
> the open transactions..all the logic lies in class and from class am
> not able to access the markstrans method of custopentrans form..
> can u guys help me how can i check the checkbox marktrans without
> opening the form ..how to check it while reading the file ...
> 
> Thanks in advance,
> Sanjeev
>


Reply via email to