Advertisement
ma39isy

Untitled

Jan 15th, 2024 (edited)
778
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. try {
  2.     let offSet = null;
  3.  
  4.     let queryReporting = knex("master_permohonan")
  5.     .select('master_permohonan.id', 'master_permohonan.idcabang','master_permohonan.nmcabang', 'master_permohonan.no_rekening',
  6.             'master_permohonan.nama_nasabah', 'master_permohonan.nominal',
  7.             'master_permohonan.eq', 'master_permohonan.no_rekening', 'master_permohonan.nisbah', 'master_permohonan.tanggal',
  8.             'master_permohonan.tanggal_penempatan', 'master_permohonan.tanggal_jt', 'master_permohonan.tanggal_jt_sebelumnya',                
  9.             'ref_jangka.jangka_waktu','ref_jangka.hari',  'ref_status.status')
  10.     .select(knex.raw(case when master_permohonan.jenis_permohonan=1 then 'Penempatan Baru' else 'Perpanjangan' end as pengajuan))            
  11.     .select(knex.raw(case when master_permohonan.jenis_kepemilikan=1 then 'Ritel' else 'Korporasi' end as pemilik))
  12.     .select(knex.raw(case when master_permohonan.jenis_deposito=1 then 'Bagi Hasil' else 'Jualah' end as deposito))            
  13.     .leftJoin('ref_jangka', 'ref_jangka.id', 'master_permohonan.idjangka')
  14.     .leftJoin('ref_status', 'ref_status.id', 'master_permohonan.status')
  15.  
  16.     if (tanggalAwal && tanggalAkhir) {
  17.       queryReporting.whereBetween("master_permohonan.tanggal", [tanggalAwal, tanggalAkhir]);
  18.     }
  19.  
  20.     if (namaNasabah) {
  21.       queryReporting.where("master_permohonan.nama_nasabah", "ilike", %${namaNasabah}%);
  22.     }
  23.  
  24.     if (idCabang) {
  25.       queryReporting.where("master_permohonan.idcabang", idCabang);
  26.     }
  27.  
  28.     const total = (await queryReporting).length;
  29.  
  30.     if (page && limit) {
  31.       offSet = (page - 1) * limit;
  32.       queryReporting.offset(offSet).limit(limit);
  33.     }
  34.  
  35.     const listReporting = await queryReporting;
  36.  
  37.     const result = {
  38.         total,
  39.         per_page: limit ? limit : null,
  40.         offset: page && limit ? offSet : null,
  41.         from: page && limit ? offSet + 1 : null,
  42.         to: offSet + listReporting.length,
  43.         current_page: page ? page : null,
  44.         last_page: limit ? Math.ceil(total / limit) : null,
  45.         data: listReporting,
  46.     };
  47.  
  48.     return result;
  49.    
  50.   } catch (error) {
  51.     throw error;
  52.   }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement