const system = require("../../../system");
const Dao = require("../../dao.base");
const moment = require("moment");
class InvoiceDao extends Dao {
  constructor() {
    super(Dao.getModelName(InvoiceDao));
    // this.invoiceStatusDict = {
    //   "00": "开票申请",
    //   "10": "已撤回",
    //   "20": "审核驳回",
    //   "30": "审核通过",
    //   "40": "已开票",
    //   "50": "已邮寄"
    // };
  }
  //批量插入数据
  async builkSave(invoices){
    if(invoices.length>0 && invoices){
      return await this.model.bulkCreate(invoices);
    }else{
      return  null;
    }
    
  }

  // async getInvoiceStatusName(status) {
  //   return this.invoiceStatusDict[status || ""] || "";
  // }

  // async findAllAmtByCreditCode(creditCode, invoiceDay) {
  //   var year = moment(invoiceDay).format("YYYY");
  //   var beginTime = year + "-01-01 00:00:00";
  //   var endTime = year + "-01-01 00:00:00";
  //   var sql = [];
  //   sql.push("SELECT SUM(invoiceAmt) AS totalAmt");
  //   sql.push("FROM xgg_invoice");
  //   sql.push("WHERE businessmenCreditCode = :creditCode");
  //   sql.push("AND invoiceTime >= :beginTime AND invoiceTime <= :endTime ");
  //   var list = await this.customQuery(sql.join(" "), {
  //     creditCode: creditCode,
  //     beginTime: beginTime,
  //     endTime: endTime,
  //   }) || [];

  //   var totalAmt = 0;
  //   for(var item of list) {
  //     totalAmt = item.totalAmt || 0;
  //   }
  //   return totalAmt;
  // }

  // async findMonthAmtByCreditCode(creditCode, invoiceDay, statuses) {
  //   var month = moment(invoiceDay).month();
  //   const beginTime = moment().month(month).startOf('month').format("YYYY-MM-DD") + " 00:00:00";
  //   const endTime = moment().month(month).endOf('month').format("YYYY-MM-DD") + " 23:59:59";

  //   console.log(beginTime, endTime);
  //   var sql = [];
  //   sql.push("SELECT * ");
  //   sql.push("FROM xgg_invoice");
  //   sql.push("WHERE businessmenCreditCode = :creditCode");
  //   sql.push("AND invoiceTime >= :beginTime");
  //   sql.push("AND invoiceTime <= :endTime");
  //   if(statuses && statuses.length > 0) {
  //     sql.push("AND invoiceStatus IN (:statuses)")
  //   }
  //   var map = {};
  //   var list = await this.customQuery(sql.join(" "), {
  //     creditCode: creditCode,
  //     beginTime: beginTime,
  //     endTime: endTime,
  //     statuses: statuses || "",
  //   });
  //   return list || [];
  // }

  // async findMapByIds(ids, attrs) {
  //   var result = {};
  //   if(!ids || ids.length == 0) {
  //     return result;
  //   }

  //   attrs = attrs || "*";
  //   var sql = "SELECT " + attrs + " FROM xgg_invoice where id IN (:ids) ";
  //   var list = await this.customQuery(sql, {ids: ids});
  //   if(!list || list.length == 0) {
  //     return result;
  //   }

  //   for(var item of list) {
  //     result[item.id] = item;
  //   }
  //   return result;
  // }
}
module.exports = InvoiceDao;
// var u=new UserDao();
// var roledao=system.getObject("db.roleDao");
// (async ()=>{
//   var users=await u.model.findAll({where:{app_id:1}});
//   var role=await roledao.model.findOne({where:{code:"guest"}});
//   console.log(role);
//   for(var i=0;i<users.length;i++){
//     await users[i].setRoles([role]);
//     console.log(i);
//   }
//
// })();