const db = require('../db');
const xlsx = require('node-xlsx').default;
const fs = require('fs');
const _ = require('lodash');
const moment = require('moment');
async function task(argument) {
	
  const bill = await db.getCollection('bills');
  const agent = await db.getAgentCollection('account');
  const dspRecognition = await db.getCollection('dspRecognition');
  const billID = '5bc70d358651710007979214';
  const tobill = await bill.findOne({ _id : db.ObjectID(billID) });

  let count = await dspRecognition.count({ billID:billID });
  let discount = tobill.agent.discount;
  let rep = await bill.update({ _id: db.ObjectID(billID) },{ $set: { 'agent.number' : (8 * count * discount).toFixed(1) , number: count * 8, pre: false, 'platform.number' : count * 8 }})
  let _rep = await agent.update({ 'preNumber.billID': { '$in' : [ db.ObjectID(billID),billID ]} },{ $pull: { 'preNumber' : { billID : {'$in': [ db.ObjectID(billID),billID ] }} }})
  console.dir(rep.result.nModified);
  console.dir(rep.result.nModified);
}

task();


