const ServiceBase = require("../../sve.base");
const system = require("../../../system");
const moment = require('moment')
/**
 * 交付商 提交的信息
 */
class IInvoiceService extends ServiceBase {
  constructor() {
    super("invoice", ServiceBase.getDaoName(IInvoiceService));
    let is = system.getObject("util.invoiceStatus");
    this.invoiceStatus = is.status;

    this.iinvoicesummaryinfoDao = system.getObject("db.invoice.iinvoicesummaryinfoDao");
    this.iinvoiceprocessDao = system.getObject("db.invoice.iinvoiceprocessDao");
    this.iinvoiceinforegDao = system.getObject("db.invoice.iinvoiceinforegDao");
    this.iinvoicedeliverDao = system.getObject("db.invoice.iinvoicedeliverDao");
  }

  /**
   * 发票申请
   * @param {*} params 
   */
  async invoiceApply(params){
  }




//**********************************************以下是旧版本************************************************************ */
  /**
   * 构建产品流程对象
   * @param productPid
   * @param chooseProductIds
   * @returns {Promise<void>}
   */
  async buildProcess(params) {
    let productPid = params.productPid || 50010000;
    // 查询产品流程
    let productProcessList = await this.oproductprocessDao.byProductPid(productPid);
    if (!productProcessList || productProcessList.length == 0) {
      return [];
    }

    let invoiceProcessList = [];
    // 批量查流程
    let processMap = await this.oprocessDao.mapAll();

    for (let productProcess of productProcessList) {
      // 风还钻该处理每一个子项流程 变为 订单流程对象
      let process = processMap[productProcess.process_id];
      let nextArr = this.trim(productProcess.next_status).split(",");
      let nextStatus = [];
      for (let nextId of nextArr) {
        nextId = Number(nextId || 0);
        let nextObj = processMap[nextId];
        if (!nextObj) {
          continue;
        }
        nextStatus.push({ next_status: nextObj.status, next_name: nextObj.name });
      }

      let orderProcess = {
        product_id: productPid,
        name: process.name,
        status: process.status,
        func: productProcess.func,
        next_status: JSON.stringify(nextStatus),
        name1: productProcess.name1,
        name2: productProcess.name2,
        name3: productProcess.name3,
        name4: productProcess.name4,
        sort: productProcess.sort,
        autoIncrement: true
      };
      invoiceProcessList.push(orderProcess);
    }

    return invoiceProcessList;
  }
}
module.exports = IInvoiceService;