UNPKG

docparse-supplier-nge

Version:

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

67 lines (59 loc) 2.06 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 * @param {Bill} data.bill is the bill document which was just created prior * @see {Function} save_bill_data */ module.exports = function(data, cb) { var keys = ['bill']; var err = rk.truthySync(data, keys); if (err) { return cb(err); } 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 = bill.supplier; saveData.supplierCode = bill.supplier_code; saveData.billingSupplierCode = bill.supplier_code; saveData.billingSupplierID = bill.supplier; saveData.accountNumber = bill.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: 'utility', commodity: 'electricity' }; saveData.costSupply = data.costSupply; toPay = toPay.add(data.costSupply); saveData.costDelivery = data.costDelivery; toPay = toPay.add(data.costDelivery); toPay = toPay.add(data.costOther.total); saveData.costOther = data.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); };