Monday, 30 May 2016

Inventory Closing through Job

  1. Copy and Paste below code in AOT->Jobs and then run the job.

    Note : Change from and todate in the below job according to your requirement

    Example : If you are doing inventory closing from 1 JAN 2015 to 28 Feb 2015 . 
                     Give same dates in below job.


    static void UpdateInventTransPosting(Args _args)
    {
        InventTransPosting                      inventTransPosting;
        GeneralJournalEntry                     generalJournalEntry;
        GeneralJournalAccountEntry              generalJournalAccountEntry;
        SubledgerVoucherGeneralJournalEntry     subledgerVoucherGeneralJournalEntry;
        TransDate                               frmDt = mkDate(04,05,2015);// Need to change
        TransDate                               toDt = mkDate(15,05,2015);// Need to change
        ;
        startLengthyOperation();
        ttsBegin;
        while select inventTransPosting where inventTransPosting.TransDate <= frmDt && inventTransPosting.TransDate >= toDt
            && inventTransPosting.OffsetLedgerDimension
            && inventTransPosting.InventTransPostingType == InventTransPostingType::Financial
        {
            select LedgerDimension from generalJournalAccountEntry
            join RecId from generalJournalEntry
            where generalJournalEntry.RecId == generalJournalAccountEntry.GeneralJournalEntry
            && (generalJournalAccountEntry.PostingType == LedgerPostingType::InventLoss || generalJournalAccountEntry.PostingType == LedgerPostingType::InventProfit)
            join RecId from subledgerVoucherGeneralJournalEntry
            where subledgerVoucherGeneralJournalEntry.GeneralJournalEntry == generalJournalEntry.RecId
            && subledgerVoucherGeneralJournalEntry.Voucher == inventTransPosting.Voucher
            && subledgerVoucherGeneralJournalEntry.VoucherDataAreaId == inventTransPosting.dataAreaId
            && subledgerVoucherGeneralJournalEntry.AccountingDate == inventTransPosting.TransDate;
           if (generalJournalAccountEntry.LedgerDimension)
            {
                inventTransPosting.selectForUpdate(true);
                inventTransPosting.OffsetLedgerDimension = generalJournalAccountEntry.LedgerDimension;
                inventTransPosting.doUpdate();
            }
        }
        ttsCommit;
        info('Updation completed');
        endLengthyOperation();
    }


No comments:

Post a Comment