const system = require("../../../system");
const ServiceBase = require("../../sve.base");
const settings = require("../../../../config/settings");

class InvoiceService extends ServiceBase {
  constructor() {
    super("all", ServiceBase.getDaoName(InvoiceService));
  }

  async pageByCondition(params) {
    let currentPage = Number(params.currentPage || 1);
    let pageSize = Number(params.pageSize || 10);

    var where = {};
    if (params.title) {
      where.title = {
        [this.db.Op.like]: "%" + params.title + "%"
      };
    }

    if (params.invoiceType) {
      where.invoiceType = Number(params.invoiceType);
    }

    var orderby = [
      ["id", 'desc']
    ];
    var page = await this.getPageList(currentPage, pageSize, where, orderby);
    if (page && page.rows) {
      for (var row of page.rows) {
        this.handleDate(row, ["invoice_time"], "YYYY-MM-DD");
      }
    }
    return page;
  }
}

module.exports = InvoiceService;