import { GeneralService } from '../share/generalservice.js'

export class ReportService {

  constructor() {
    this.generalService = new GeneralService()
  }

  async getReportController(database, number) {
    const sql = `
      SELECT 
        ${database}.translatedtl('ACTTYP', acttyp) AS actnam,
        acttyp,
        ${database}.translatedtl_multi(ARRAY['ACTCAT_INC','ACTCAT_EXP'], actcat) AS actcat,
        actqty,
        actcmt,
        actacpdtm
      FROM ${database}.actmst
      WHERE actnum = $1
    `

    const params = [number]
    const result = await this.generalService.executeQueryParam(database, sql, params);
    return result
  }

    async getCategoryColorMap(database) {
    const sql = `
        SELECT dtlcod, dtlnam, dtlmsc as dtlclr
        FROM ${database}.dtlmst
        WHERE dtltblcod IN ('ACTCAT_INC', 'ACTCAT_EXP')
    `;
    const params = []
    const rows = await this.generalService.executeQueryParam(database, sql, params);

    const map = {};
    rows.forEach(r => {
        map[r.dtlnam] = r.dtlclr;
    });

    return map;
  }
}