| Server IP : 127.0.0.1 / Your IP : 192.168.99.1 Web Server : Apache/2.4.35 (Win64) OpenSSL/1.1.1b mod_fcgid/2.3.9 System : Windows NT WIN-JEJMB9EN0L0 10.0 build 14393 (Windows Server 2016) AMD64 User : Administrator ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /wamp/www/SIPBOS_2020/application/modules/import_scheduler/models/ |
Upload File : |
<?php
class Import_scheduler_model extends CI_Model {
var $fieldmap_aktivitas;
var $fieldmap_skrd;
var $fieldmap_rincian_skp;
var $data_aktivitas;
var $data_skrd;
var $data_rincian_skp;
var $path_xml;
var $path_logs;
var $path_uplod;
var $fieldmap_tbp;
var $fieldmap_tbp_pakai_skrd;
var $fieldmap_rincian_tbp;
var $data_tbp;
var $data_rincian_tbp;
var $data_tbp_pakai_skrd;
var $fieldmap_sts;
var $fieldmap_rincian_sts;
var $data_sts;
var $data_rincian_sts;
var $id_skp;
var $id_tbp;
var $id_sts;
var $nomor_skp;
var $nomor_tbp;
var $nomor_sts;
var $tahun;
var $username;
var $ppkd;
function __construct()
{
parent::__construct();
$this->path_xml = './xml/';
$this->path_logs = './logs/';
$this->path_uplod = './uplod/';
$this->tahun = date("Y");
$this->username = $this->get_username();
$this->ppkd = '0';
$this->fieldmap_aktivitas = array(
'id' => 'ID_AKTIVITAS',
'tipe' => 'TIPE',
'tahun' => 'TAHUN',
'nomor' => 'NOMOR',
'auto' => 'NOMOR_INT',
'tgl' => 'TANGGAL',
'deskripsi' => 'DESKRIPSI',
'id_skpd' => 'ID_SKPD',
'user' => 'USERNAME',
'ppkd' => 'IS_PPKD'
);
$this->fieldmap_skrd = array(
'id' => 'ID_AKTIVITAS',
'nm_wp' => 'NAMA_WP',
'alamat_wp' =>'ALAMAT_WP',
'npwpd' => 'NPWPD',
'tempo' => 'JATUH_TEMPO',
);
$this->fieldmap_rincian_skp = array(
'id' => 'ID_AKTIVITAS',
'idrek' => 'ID_REKENING',
'nominal' => 'NOMINAL'
);
$this->fieldmap_tbp = array(
'id' => 'ID_AKTIVITAS',
'nm_setor' => 'NAMA_PENYETOR',
'alamat_setor' =>'ALAMAT_PENYETOR',
'id_pekas' => 'ID_REKENING_PEKAS',
'bt' => 'ID_BT',
);
$this->fieldmap_tbp_pakai_skrd = array(
'id' => 'ID_SKRD',
);
$this->fieldmap_rincian_tbp = array(
'id' => 'ID_AKTIVITAS',
'idrek' => 'ID_REKENING',
'nominal' => 'NOMINAL'
);
$this->fieldmap_sts = array(
'id' => 'ID_AKTIVITAS',
'id_sd' => 'ID_SUMBER_DANA',
'id_pekas' => 'ID_REKENING_PEKAS',
'kaskpd' => 'ID_KEPALA_SKPD',
'bt' => 'ID_BT',
'pakai_tbp' => 'PAKAI_TBP',
);
$this->fieldmap_rincian_sts = array(
'id' => 'ID_AKTIVITAS',
'idrek' => 'ID_REKENING',
'nominal' => 'NOMINAL'
);
}
function fill_data_skp($data)
{
if ($data)
{
for ($i=0; $i <= count($data) - 1; $i++) {
/* ambil data aktivitas */
foreach($this->fieldmap_aktivitas as $key => $value){
switch ($key)
{
case 'tahun' : $$key = $this->tahun; break;
case 'user' : $$key = $this->username; break;
case 'ppkd' : $$key = $this->ppkd; break;
case 'auto' : $$key = isset($data[$i][$key]) ? 1 : 0; break;
case 'tgl' : $$key = isset($data[$i][$key]) && $data[$i][$key] ? prepare_date($data[$i][$key]) : NULL; break;
default : $$key = isset($data[$i][$key]) && $data[$i][$key] ? $data[$i][$key] : NULL;
}
if(isset($$key))
$this->data_aktivitas[$i][$value] = $$key;
}
/* ambil data skrd */
foreach($this->fieldmap_skrd as $key => $value){
switch ($key)
{
case 'tempo' : $$key = isset($data[$i][$key]) && $data[$i][$key] ? prepare_date($data[$i][$key]) : NULL; break;
default : $$key = isset($data[$i][$key]) && $data[$i][$key] ? $data[$i][$key] : NULL;
}
if(isset($$key))
$this->data_skrd[$i][$value] = $$key;
}
/* ambil data rincian */
for ($c=0; $c <= count($data[$i]['akun']) - 1; $c++) {
foreach($this->fieldmap_rincian_skp as $key => $value){
switch ($key){
default : $$key = isset($data[$i]['akun'][$c][$key]) && $data[$i]['akun'][$c][$key] ? $data[$i]['akun'][$c][$key] : NULL;
}
if(isset($$key))
$this->data_rincian_skp[$c][$value] = $$key;
}
}
}
}
}
function fill_data_tbp($data)
{
if ($data)
{
for ($i=0; $i <= count($data) - 1; $i++) {
/* ambil data aktivitas */
foreach($this->fieldmap_aktivitas as $key => $value){
switch ($key)
{
case 'tahun' : $$key = $this->tahun; break;
case 'user' : $$key = $this->username; break;
case 'ppkd' : $$key = $this->ppkd; break;
case 'auto' : $$key = isset($data[$i][$key]) ? 1 : 0; break;
case 'tgl' : $$key = isset($data[$i][$key]) && $data[$i][$key] ? prepare_date($data[$i][$key]) : NULL; break;
default : $$key = isset($data[$i][$key]) && $data[$i][$key] ? $data[$i][$key] : NULL;
}
if(isset($$key))
$this->data_aktivitas[$i][$value] = $$key;
}
/* ambil data tbp */
foreach($this->fieldmap_tbp as $key => $value){
switch ($key)
{
default : $$key = isset($data[$i][$key]) && $data[$i][$key] ? $data[$i][$key] : NULL;
}
if(isset($$key))
$this->data_tbp[$i][$value] = $$key;
}
/* ambil data tbp pakai skrd */
if(isset($data[$i]['skrd'])){
for ($x=0; $x <= count($data[$i]['skrd']) - 1; $x++) {
foreach($this->fieldmap_tbp_pakai_skrd as $key => $value){
switch ($key){
default : $$key = isset($data[$i]['skrd'][$x][$key]) && $data[$i]['skrd'][$x][$key] ? $data[$i]['skrd'][$x][$key] : NULL;
}
if(isset($$key))
$this->data_tbp_pakai_skrd[$x][$value] = $$key;
}
}
}
/* ambil data rincian */
for ($c=0; $c <= count($data[$i]['akun']) - 1; $c++) {
foreach($this->fieldmap_rincian_tbp as $key => $value){
switch ($key){
default : $$key = isset($data[$i]['akun'][$c][$key]) && $data[$i]['akun'][$c][$key] ? $data[$i]['akun'][$c][$key] : NULL;
}
if(isset($$key))
$this->data_rincian_tbp[$c][$value] = $$key;
}
}
}
}
}
function fill_data_sts($data)
{
if ($data)
{
for ($i=0; $i <= count($data) - 1; $i++) {
/* ambil data aktivitas */
foreach($this->fieldmap_aktivitas as $key => $value){
switch ($key)
{
case 'tahun' : $$key = $this->tahun; break;
case 'user' : $$key = $this->username; break;
case 'ppkd' : $$key = $this->ppkd; break;
case 'auto' : $$key = isset($data[$i][$key]) ? 1 : 0; break;
case 'tgl' : $$key = isset($data[$i][$key]) && $data[$i][$key] ? prepare_date($data[$i][$key]) : NULL; break;
default : $$key = isset($data[$i][$key]) && $data[$i][$key] ? $data[$i][$key] : NULL;
}
if(isset($$key))
$this->data_aktivitas[$i][$value] = $$key;
}
/* ambil data skrd */
foreach($this->fieldmap_sts as $key => $value){
switch ($key)
{
case 'pakai_tbp' : $$key = $this->input->post($key) === 'true' ? 1 : 0; break;
default : $$key = isset($data[$i][$key]) && $data[$i][$key] ? $data[$i][$key] : NULL;
}
if(isset($$key))
$this->data_sts[$i][$value] = $$key;
}
/* ambil data rincian */
for ($c=0; $c <= count($data[$i]['akun']) - 1; $c++) {
foreach($this->fieldmap_rincian_sts as $key => $value){
switch ($key){
default : $$key = isset($data[$i]['akun'][$c][$key]) && $data[$i]['akun'][$c][$key] ? $data[$i]['akun'][$c][$key] : NULL;
}
if(isset($$key))
$this->data_rincian_sts[$c][$value] = $$key;
}
}
}
}
}
protected function get_id($generator)
{
$result = $this->db->query('select gen_id('.$generator.', 1) id from rdb$database')->row_array();
return $result['ID'];
}
function check_trans_status($exception)
{
if ($this->db->trans_status() === FALSE) {
throw new Exception($exception);
}
}
function insert_skp()
{
for ($i=0; $i<count($this->data_aktivitas); $i++) {
$id = $this->get_id('g_id_aktivitas');
$this->data_aktivitas[$i]['ID_AKTIVITAS'] = $id;
$this->db->insert('AKTIVITAS', $this->data_aktivitas[$i]);
$this->check_trans_status('insert aktivitas failed');
$this->id_skp = $id;
$this->nomor_skp = $this->data_aktivitas[$i]['NOMOR'];
$this->data_skrd[$i]['ID_AKTIVITAS'] = $this->id_skp;
$this->db->insert('SKRD', $this->data_skrd[$i]);
$this->check_trans_status('insert skrd failed');
}
$jml = count($this->data_rincian_skp);
for ($i=0; $i <= $jml - 1; $i++)
{
$this->data_rincian_skp[$i]['ID_AKTIVITAS'] = $this->id_skp;
$this->db->insert('RINCIAN_SKRD', $this->data_rincian_skp[$i]);
$this->check_trans_status('insert rincian skrd failed');
}
}
function insert_tbp()
{
for ($i=0; $i<count($this->data_aktivitas); $i++) {
$id = $this->get_id('g_id_aktivitas');
$this->data_aktivitas[$i]['ID_AKTIVITAS'] = $id;
$this->db->insert('AKTIVITAS', $this->data_aktivitas[$i]);
$this->check_trans_status('insert aktivitas failed');
$this->id_tbp = $id;
$this->nomor_tbp = $this->data_aktivitas[$i]['NOMOR'];
$this->data_tbp[$i]['ID_AKTIVITAS'] = $this->id_tbp;
$this->db->insert('TBP', $this->data_tbp[$i]);
$this->check_trans_status('insert tbp failed');
}
if(isset($this->data_tbp_pakai_skrd)){
$jml = count($this->data_tbp_pakai_skrd);
for ($i=0; $i <= $jml - 1; $i++)
{
$this->data_tbp_pakai_skrd[$i]['ID_AKTIVITAS'] = $this->id_tbp;
$this->db->insert('TBP_PAKAI_SKRD', $this->data_tbp_pakai_skrd[$i]);
$this->check_trans_status('insert tbp_pakai_skrd failed');
}
}
$jml = count($this->data_rincian_tbp);
for ($i=0; $i <= $jml - 1; $i++)
{
$this->data_rincian_tbp[$i]['ID_AKTIVITAS'] = $this->id_tbp;
$this->db->insert('RINCIAN_TBP', $this->data_rincian_tbp[$i]);
$this->check_trans_status('insert rincian_tbp failed');
}
}
function insert_sts()
{
for ($i=0; $i<count($this->data_aktivitas); $i++) {
$id = $this->get_id('g_id_aktivitas');
$this->data_aktivitas[$i]['ID_AKTIVITAS'] = $id;
$this->db->insert('AKTIVITAS', $this->data_aktivitas[$i]);
$this->check_trans_status('insert aktivitas failed');
$this->id_sts = $id;
$this->nomor_sts = $this->data_aktivitas[$i]['NOMOR'];
$this->data_sts[$i]['ID_AKTIVITAS'] = $this->id_sts;
$this->db->insert('STS', $this->data_sts[$i]);
$this->check_trans_status('insert sts failed');
}
$jml = count($this->data_rincian_sts);
for ($i=0; $i <= $jml - 1; $i++)
{
$this->data_rincian_sts[$i]['ID_AKTIVITAS'] = $this->id_sts;
$this->db->insert('RINCIAN_STS', $this->data_rincian_sts[$i]);
$this->check_trans_status('insert rincian_sts failed');
}
}
function save_data($tipe)
{
$this->db->trans_begin();
try {
if($tipe=='SKP'){$this->insert_skp();}
else if($tipe=='TBP'){$this->insert_tbp();}
else if($tipe=='STS'){$this->insert_sts();}
}
catch(Exception $e){
//TODO : log error to file
}
if ($this->db->trans_status() === FALSE)
{
$this->id = NULL;
$this->nomor = NULL;
$this->last_error_id = $this->db->_error_number();
$this->last_error_message = $this->db->_error_message();
$this->db->trans_rollback();
return FALSE;
}
$this->db->trans_commit();
return TRUE;
}
function data_rekening()
{
$rek = array();
$this->db->select('r.id_rekening, r.kode_rekening')
->from('rekening r')
->where('r.tipe', '4')
->where('r.rincian <>', '');
$result = $this->db->get()->result_array();
foreach ($result as $row) {
$rek[$row['KODE_REKENING']] = $row['ID_REKENING'];
}
return $rek;
}
function data_skpd()
{
$rek = array();
$this->db->select('r.id_skpd, r.kode_skpd_lkp')
->from('v_skpd r');
$result = $this->db->get()->result_array();
foreach ($result as $row) {
$rek[$row['KODE_SKPD_LKP']] = $row['ID_SKPD'];
}
return $rek;
}
function data_skrd()
{
$rek = array();
$this->db->select('r.id_aktivitas, r.nomor')
->from('aktivitas r')
->where('r.tipe', 'SKPD')
->where('r.tahun', $this->tahun);
$result = $this->db->get()->result_array();
foreach ($result as $row) {
$rek[$row['NOMOR']] = $row['ID_AKTIVITAS'];
}
return $rek;
}
function check_duplikasi_nomor($tipe,$nomor)
{
$this->db->select('a.nomor, a.id_skpd')
->from('aktivitas a')
->where('a.nomor', $nomor)
->where('a.tipe', $tipe)
->where('a.tahun', $this->tahun);
$result = $this->db->get()->row_array();
if ($result) return TRUE;
else return FALSE;
}
function get_data_pekas($kdrek)
{
$this->db->select('a.id_rekening')
->from('sumber_dana_skpd a')
->join('rekening r','r.id_rekening=a.id_rekening')
->where('r.kode_rekening', $kdrek);
$result = $this->db->get()->row_array();
if ($result && $result['ID_REKENING'] > 0) return $result['ID_REKENING'];
else return FALSE;
}
function get_data_sumberdana($namasumberdana)
{
$this->db->select('a.id_sumber_dana')
->from('sumber_dana a')
->where('a.nama_sumber_dana', $namasumberdana);
$result = $this->db->get()->row_array();
if ($result && $result['ID_SUMBER_DANA'] > 0) return $result['ID_SUMBER_DANA'];
else return FALSE;
}
function get_data_kepalaskpd($nama)
{
$this->db->select('a.id_pejabat_skpd')
->from('pejabat_skpd a')
->where('a.nama_pejabat', $nama);
$result = $this->db->get()->row_array();
if ($result && $result['ID_PEJABAT_SKPD'] > 0) return $result['ID_PEJABAT_SKPD'];
else return FALSE;
}
function get_data_bt($nama)
{
$this->db->select('a.id_pejabat_skpd')
->from('pejabat_skpd a')
->where('a.aktif', '1')
->where('a.nama_pejabat', $nama);
$result = $this->db->get()->row_array();
if ($result && $result['ID_PEJABAT_SKPD'] > 0) return $result['ID_PEJABAT_SKPD'];
else return FALSE;
}
function get_username()
{
$this->db->select('first 1 a.USERNAME')
->from('users a')
->join('groups b','a.GROUP_ID=b.ID')
->like('upper(b.name)', 'ADMIN');
$result = $this->db->get()->row_array();
if ($result) return $result['USERNAME'];
else return NULL;
}
}