Creation of Journal Entry for Bill

 function createJournalEntry(bill, incomeTaxAmount) {

      try {

        let vendorId = bill.getValue(‘entity’);

        let apAccount = bill.getValue(‘account’);

        let subsidiary = bill.getValue(‘subsidiary’);

        let currency = bill.getValue(‘currency’);

        let trandate = bill.getValue(‘trandate’);

        if (!apAccount) {

          log.error(‘Missing A/P account on Vendor Bill’);

          return null;

        }

        let journal = record.create({

          type: record.Type.JOURNAL_ENTRY,

          isDynamic: true

        });

        journal.setValue({ fieldId: ‘subsidiary’, value: subsidiary });

        journal.setValue({ fieldId: ‘currency’, value: currency });

        journal.setValue({ fieldId: ‘trandate’, value: trandate });

        journal.setValue({ fieldId: ‘memo’, value: ‘Auto JE for Income Tax on Vendor Bill ‘ + bill.getValue(‘tranid’) });

        // DEBIT A/P

        journal.selectNewLine({ sublistId: ‘line’ });

        journal.setCurrentSublistValue({ sublistId: ‘line’, fieldId: ‘account’, value: apAccount });

        journal.setCurrentSublistValue({ sublistId: ‘line’, fieldId: ‘debit’, value: incomeTaxAmount });

        journal.setCurrentSublistValue({ sublistId: ‘line’, fieldId: ‘entity’, value: vendorId });

        journal.commitLine({ sublistId: ‘line’ });

        // CREDIT Tax Account

        journal.selectNewLine({ sublistId: ‘line’ });

        journal.setCurrentSublistValue({ sublistId: ‘line’, fieldId: ‘account’, value: INCOME_TAX_ACCOUNT_ID });

        journal.setCurrentSublistValue({ sublistId: ‘line’, fieldId: ‘credit’, value: incomeTaxAmount });

        journal.setCurrentSublistValue({ sublistId: ‘line’, fieldId: ‘entity’, value: vendorId });

        journal.commitLine({ sublistId: ‘line’ });

        journal.setValue({ fieldId: ‘approvalstatus’, value: APPROVED_STATUS });

        let journalId = journal.save();

        log.audit(‘Journal Entry Created’, journalId);

        return journalId;

      } catch (e) {

        log.error(‘Failed to create Journal Entry’, e);

        return null;

      }

    }

Leave a comment

Your email address will not be published. Required fields are marked *