Пример #1
0
 function print_neraca_gabungan()
 {
     $data['periode'] = $this->input->post('tgl_start');
     $data['pembanding'] = $this->input->post('tgl_banding');
     $data['users'] = $this->session->userdata('userid');
     $unte = $this->input->post('unite');
     $periode = tglToSql($this->input->post('tgl_start'));
     $data['awal'] = getPrevDays($periode, 365);
     $awal = getPrevDays($periode, 365);
     $this->neraca_model->build_data($periode);
     $this->neraca_model->tmp_balance();
     $this->neraca_model->generate_shu($awal, $periode, $unte);
     //$data['temp_rec']	=$this->neraca_model->neraca_kalkulasi($periode,$unite);
     $this->zetro_auth->menu_id(array('trans_beli'));
     $this->list_data($data);
     $this->View("laporan/neraca_print_gabung");
 }
Пример #2
0
 function generate_shu($tglAwal, $tglAkhir, $Unit)
 {
     //define variable
     //echo $Unit;
     $saldoA = 0;
     $Saldo = 0;
     $idCalc = '';
     $saldoNc = 0;
     $saldoNc1 = 0;
     //create temporary table for store saldo shu
     $tmp = "CREATE TABLE IF NOT EXISTS `tmp_" . $this->user . "_total_shu` (\r\n\t\t\t\t\t`tglAwal` DATE NULL,\r\n\t\t\t\t\t`tglAkhir` DATE NULL,\r\n\t\t\t\t\t`saldo` DOUBLE NULL DEFAULT '0',\r\n\t\t\t\t\t`saldo2` DOUBLE NULL DEFAULT '0',\r\n\t\t\t\t\t`unit` INT NULL,\r\n\t\t\t\t\tPRIMARY KEY (`unit`)\r\n\t\t\t\t)\r\n\t\t\t\tCOLLATE='latin1_swedish_ci'\r\n\t\t\t\tENGINE=MyISAM;";
     mysql_query($tmp) or die(mysql_error());
     mysql_query("truncate table tmp_" . $this->user . "_total_shu");
     // proces data jika Unit bukan gabungan
     if ($Unit != '3') {
         $nm_unit = rdb("unit_jurnal", "Unit", "Unit", "where ID='{$Unit}'");
         //read lap_jenis
         $tglAwal2 = getPrevDays($tglAwal, 366);
         $tglAkhir2 = getPrevDays($tglAkhir, 366);
         $sql = "select * from lap_jenis where ID_Head='0' order by ID";
         $rs = mysql_query($sql) or die($sql . mysql_error());
         while ($row = mysql_fetch_object($rs)) {
             $saldo = 0;
             $saldo1 = 0;
             $sql2 = "select * from lap_subjenis where ID_Jenis='" . $row->ID . "' and ID_{$nm_unit}='1' order by NoUrut";
             $rs2 = mysql_query($sql2) or die($sql2 . mysql_error());
             while ($row2 = mysql_fetch_object($rs2)) {
                 $saldoA = rdb("perkiraan", 'SaldoAwal', 'sum(SaldoAwal) as SaldoAwal', "where ID_Laporan='1' and ID_Unit='{$Unit}' and ID_LapDetail='" . $row2->ID . "'");
                 $idCalc = rdb("perkiraan", 'ID_Calc', 'ID_Calc', "where ID_Laporan='1' and ID_Unit='{$Unit}' and ID_LapDetail='" . $row2->ID . "'");
                 //process total shu akhir periode
                 $sql3 = "select id_calc,sum(debet) as debet,sum(kredit) as kredit from tmp_" . $this->user . "_transaksi_rekap where (Tanggal between '" . $tglAwal . "' and '" . $tglAkhir . "') and ID_Laporan='1' and ID_Unit='{$Unit}' and id_lapdetail='" . $row2->ID . "'";
                 $rs3 = mysql_query($sql3) or die($sql3 . mysql_error());
                 while ($row3 = mysql_fetch_object($rs3)) {
                     $Saldo = $idCalc == 1 ? $saldoA + ($row3->debet - $row3->kredit) : $saldoA + ($row3->kredit - $row3->debet);
                     $saldoNc = $row2->ID_Calc == 1 ? $saldoNc - $Saldo : $saldoNc + $Saldo;
                 }
                 //process total shu tahun sebelumnya
                 $sql31 = "select id_calc,sum(debet) as debet,sum(kredit) as kredit from tmp_" . $this->user . "_transaksi_rekap where (Tanggal between '" . $tglAwal2 . "' and '" . $tglAkhir2 . "') and ID_Laporan='1' and ID_Unit='{$Unit}' and id_lapdetail='" . $row2->ID . "'";
                 //echo $sql31;
                 $rs31 = mysql_query($sql31) or die($sql31 . mysql_error());
                 while ($row31 = mysql_fetch_object($rs31)) {
                     $Saldo1 = $idCalc == 1 ? $saldoA + ($row31->debet - $row31->kredit) : $saldoA + ($row31->kredit - $row31->debet);
                     $saldoNc1 = $row2->ID_Calc == 1 ? $saldoNc1 - $Saldo1 : $saldoNc1 + $Saldo1;
                 }
             }
         }
         $simpan = "replace into tmp_" . $this->user . "_total_shu values('{$tglAwal}','{$tglAkhir}','" . $saldoNc . "','" . $saldoNc1 . "','" . $Unit . "')";
         mysql_query($simpan) or die(mysql_error());
     } else {
         if ($Unit == '3') {
             //jika data adalah gabungan
             $nm_unit = '';
             $rsg = mysql_query("select ID from unit_jurnal order by ID");
             while ($rwg = mysql_fetch_object($rsg)) {
                 $saldoNc = 0;
                 $saldoNc1 = 0;
                 $nm_unit = rdb("unit_jurnal", "Unit", "Unit", "where ID='" . $rwg->ID . "'");
                 //read lap_jenis
                 $tglAwal2 = getPrevDays($tglAwal, 366);
                 $tglAkhir2 = getPrevDays($tglAkhir, 366);
                 $sql = "select * from lap_jenis where ID_Head='0' order by ID";
                 $rs = mysql_query($sql) or die($sql . mysql_error());
                 while ($row = mysql_fetch_object($rs)) {
                     $saldo = 0;
                     $saldo1 = 0;
                     $sql2 = "select * from lap_subjenis where ID_Jenis='" . $row->ID . "' and ID_{$nm_unit}='1' order by NoUrut";
                     $rs2 = mysql_query($sql2) or die($sql2 . mysql_error());
                     while ($row2 = mysql_fetch_object($rs2)) {
                         $saldoA = rdb("perkiraan", 'SaldoAwal', 'sum(SaldoAwal) as SaldoAwal', "where ID_Laporan='1' and ID_Unit='" . $rwg->ID . "' and ID_LapDetail='" . $row2->ID . "'");
                         $idCalc = rdb("perkiraan", 'ID_Calc', 'ID_Calc', "where ID_Laporan='1' and ID_Unit='" . $rwg->ID . "' and ID_LapDetail='" . $row2->ID . "'");
                         //process total shu akhir periode
                         $sql3 = "select id_calc,sum(debet) as debet,sum(kredit) as kredit from tmp_" . $this->user . "_transaksi_rekap where (Tanggal between '" . $tglAwal . "' and '" . $tglAkhir . "') and ID_Laporan='1' and ID_Unit='" . $rwg->ID . "' and id_lapdetail='" . $row2->ID . "'";
                         $rs3 = mysql_query($sql3) or die($sql3 . mysql_error());
                         while ($row3 = mysql_fetch_object($rs3)) {
                             $Saldo = $idCalc == 1 ? $saldoA + ($row3->debet - $row3->kredit) : $saldoA + ($row3->kredit - $row3->debet);
                             $saldoNc = $row2->ID_Calc == 1 ? $saldoNc - $Saldo : $saldoNc + $Saldo;
                         }
                         //process total shu tahun sebelumnya
                         $sql31 = "select id_calc,sum(debet) as debet,sum(kredit) as kredit from tmp_" . $this->user . "_transaksi_rekap where (Tanggal between '" . $tglAwal2 . "' and '" . $tglAkhir2 . "') and ID_Laporan='1' and ID_Unit='" . $rwg->ID . "' and id_lapdetail='" . $row2->ID . "'";
                         //echo $sql31;
                         $rs31 = mysql_query($sql31) or die($sql31 . mysql_error());
                         while ($row31 = mysql_fetch_object($rs31)) {
                             $Saldo1 = $idCalc == 1 ? $saldoA + ($row31->debet - $row31->kredit) : $saldoA + ($row31->kredit - $row31->debet);
                             $saldoNc1 = $row2->ID_Calc == 1 ? $saldoNc1 - $Saldo1 : $saldoNc1 + $Saldo1;
                         }
                     }
                 }
                 $simpan = "replace into tmp_" . $this->user . "_total_shu values('{$tglAwal}','{$tglAkhir}','" . $saldoNc . "','" . $saldoNc1 . "','" . $rwg->ID . "')";
                 mysql_query($simpan) or die(mysql_error());
             }
         }
     }
     //echo $sql31;
 }