Untitled

 avatar
unknown
plain_text
3 years ago
1.5 kB
4
Indexable
const { sequelize } = require('../sequelize');
const { QueryTypes } = require('sequelize');

const getReport = async (request) => {
    console.log(`cal-recurring-dao getReport`);
    try {
        
        const executionDateIni = `${request.executionDateIni}`;
        const executionDateFin = `${request.executionDateFin}`;
        const statusReport = `${request.statusReport}`;
        const processor = `${request.processor}`;
      
        const params = [executionDateIni, executionDateFin,statusReport,processor];
        
        const query = ` SELECT row_number() over (order by account_id) as rownum, account_id, crp.amount, client_id, payment_type, 
                            rpe.status , rpe.execution_date
                        FROM pay_button_dev.cal_recurring_payment crp
                            inner join pay_button_dev.cal_recurring_pay_execution rpe  
                            on crp.id = rpe.id_recurring_payment
                        where to_char(rpe.execution_date,'YYYY-MM-DD')  >= $1 and 
                        to_char(rpe.execution_date,'YYYY-MM-DD') <= $2  
                        and rpe.status =$3 and payment_type =$4 `;
                         
        
        return await sequelize.query(query, {
            type: QueryTypes.SELECT,
            bind: params
        });
    } catch (error) {
        console.log(error);
        throw new Error(`An exception has occurred trying to get recurring resport : [${error.message}]`);
    }
};

module.exports = {
    getReport
};
Editor is loading...