UNPKG

docparse-supplier-nge

Version:

process ngrid electric utility bill data for use in the docparse system

71 lines (62 loc) 2.31 kB
var rk = require('required-keys'); var num = require('num'); var moment = require('moment'); var inspect = require('eyespect').inspector(); /** * Save an invoice to the database from the input data. * This function should only be called for NGrid Electric invoices supplied a * different competitive supplier * @param {Bill} data.bill is the bill document which was just created prior * @param {Supplier} data.competitive_supplier is the supplier to use when creating the invoice * @see {Function} save_bill_data */ module.exports = function(data, cb) { var keys = ['bill', 'compData']; var err = rk.truthySync(data, keys); if (err) { return cb(err); } var compData = data.compData; var saveData = {}; var bill = data.bill; var toPay = num(0); saveData.bill = bill._id; saveData.billID = bill._id.toString(); saveData.customerID = data.customerID; saveData.loginID = data.loginID; saveData.billNumberPrinted = false; saveData.billNumber = bill.bill_number; saveData.hash = data.hash; saveData.dataType = 'pdf'; saveData.supplierID = compData.supplierID; saveData.supplierCode = compData.supplierCode; saveData.billingSupplierCode = bill.supplier_code; saveData.billingSupplierID = bill.supplier; saveData.accountNumber = compData.accountNumber; saveData.fromDate = bill.fromDate; saveData.toDate = bill.toDate; if (!data.readType && bill.readType) { data.readType = bill.readType; } saveData.readType = data.readType; saveData.days = data.days; saveData.use = data.use; saveData.demandKw = data.demandKw; saveData.invoiceType = { type: 'supplier', commodity: 'electricity' }; saveData.costDelivery = compData.costDelivery || '0'; saveData.costSupply = compData.costSupply; toPay = toPay.add(compData.costSupply); toPay = toPay.add(compData.costOther.total); saveData.costOther = compData.costOther; saveData.capacityChargeUse = data.capacityChargeUse; saveData.capacityCharge = data.capacityCharge; saveData.capacityChargeAdjustment = data.capacityChargeAdjustment; saveData.datePayReport = moment().format('MM/DD/YY'); saveData.toPay = toPay.toString(); var saveInvoice = data.saveInvoice; if (!saveInvoice) { saveInvoice = require('docparse-save-invoice'); } saveInvoice(saveData, cb); };