app = $app; $this->db = $db; $this->app_gel = (array) $session->get('APP_GEL'); $this->reg_name = $session->get('WEB_APP')['REG_NAME']; $this->gel = new Gel($app); } private function prepare() { $apre = [ 'bulan1' => Param::Int("Bulan1"), 'bulan2' => Param::Int("Bulan2"), 'tahun' => Param::Int("Tahun"), 'level' => Param::Int("Level"), ]; $tgl_akhir = tgl_akhbln("01-".isi_nol($apre['bulan2'],2)."-".(string) $apre['tahun']); // generate report header $apre['periode'] = '01-'.isi_nol($apre['bulan1'],2).'-'.(string) $apre['tahun'].' s/d '.$tgl_akhir; $apre['data'] = $this->gel->RugiLaba($apre['bulan1'], $apre['tahun'], $apre['bulan2'], $apre['tahun'], $apre['level']); return $apre; } public function print() { $apre = $this->prepare(); $pre = new PrintHTML($this->app); $pre->add_title([strtoupper($this->reg_name), "RUGI / LABA", "Periode : ".$apre['periode']]); $pre->add_field("Keterangan",150,"L"); for ($i=0; $i<$apre['level']; $i++) { $pre->add_field("Jumlah ".(string) $i,50,"R","rupiah"); } $pre->show_titles(); $pre->show_headers(true); $tot_pend = 0; $strpad = "   "; $pre->add_span([ ["A. PENDAPATAN",($apre['level']+1),"L,B"] ]); foreach ($apre['data'] as $row) { if ($row['Grup_RekID'] === 4 && !($row['Mode'] === "D" && $row['Jumlah'] === 0) && $row['Level'] > 1) { $njum = $row['Jumlah'] * -1; $temp_array = [str_repeat($strpad, ($row['Level']-1))." ".$row['Nama_Rek']]; for ($i=($apre['level']+1); $i>1; $i--) { $temp_array[] = ($row['Level'] === $i) ? $njum : ""; } $pre->add_row($temp_array); if ($row['Level'] === 2) $tot_pend += $njum; } } $pre->add_span([ ["JUMLAH PENDAPATAN",$apre['level'],"L,B,I"],[$tot_pend,1,"R,B,I","rupiah"] ]); $pre->add_row([ "" ]); $pre->add_span([ ["B. BIAYA - BIAYA",($apre['level']+1),"L,B"] ]); $tot_biaya = 0; foreach ($apre['data'] as $row) { if ($row['Grup_RekID'] === 5 && !($row['Mode'] === "D" && $row['Jumlah'] === 0) && $row['Level'] > 1) { $njum = $row['Jumlah']; $temp_array = [str_repeat($strpad, $row['Level'])." ".$row['Nama_Rek']]; for ($i=$apre['level']; $i>0; $i--) { $temp_array[] = ($row['Level'] === $i) ? $njum : ""; } $pre->add_row($temp_array); if ($row['Level'] === 2) $tot_biaya += $njum; } } $pre->add_span([ ["JUMLAH BIAYA - BIAYA",$apre['level'],"L,B,I"], [$tot_biaya,1,"R,B,I","rupiah"] ]); $pre->add_span([ ["SISA HASIL USAHA (".((($tot_pend-$tot_biaya)>0)?"SURPLUS":"DEFISIT").")",$apre['level'],"L,B,I"], [$tot_pend-$tot_biaya,1,"R,B,I","rupiah"] ]); $pre->add_stamp(1, true); $pre->show(); } public function excel() { $apre = $this->prepare(); $xls = new Xlsx($this->app); $xls->set_meta([ 'title' => "Data Rugi / Laba", 'desc' => "Export Data Rugi / Laba" ]); $xls->add_title([ $this->reg_name, "RUGI / LABA", "Periode : ".$apre['periode'] ]); $xls->add_field("Keterangan", 50, "@text"); for ($i=0; $i<$apre['level']; $i++) { $xls->add_field("Jumlah ".(string) $i, 20, "#,##0.00"); } $xls->add_sheet("".str_replace("s/d","-",$apre['periode'])); $xls->show_titles(); $xls->show_headers(true); $tot_pend = 0; $strpad = " "; $xls->add_row_bold([ "A. PENDAPATAN" ]); foreach ($apre['data'] as $row) { if ($row['Grup_RekID'] === 4 && !($row['Mode'] === "D" && $row['Jumlah'] === 0) && $row['Level'] > 1) { $njum = $row['Jumlah'] * -1; $temp_array = [str_repeat($strpad, ($row['Level']-1))." ".$row['Nama_Rek']]; for ($i=($apre['level']+1); $i>1; $i--) { $temp_array[] = ($row['Level'] === $i) ? $njum : ""; } $xls->add_row($temp_array); if ($row['Level'] === 2) $tot_pend += $njum; } } $_sjudul = ["JUMLAH PENDAPATAN"]; for ($i=0; $i<($apre['level']-1); $i++) $_sjudul[] = ""; $_sjudul[] = $tot_pend; $xls->add_row_bold($_sjudul); $xls->add_row([ "" ]); $xls->add_row([ "B. BIAYA - BIAYA" ]); $tot_biaya = 0; foreach ($apre['data'] as $row) { if ($row['Grup_RekID'] === 5 && !($row['Mode'] === "D" && $row['Jumlah'] === 0) && $row['Level'] > 1) { $njum = $row['Jumlah']; $temp_array = [str_repeat($strpad, $row['Level'])." ".$row['Nama_Rek']]; for ($i=$apre['level']; $i>0; $i--) { $temp_array[] = ($row['Level'] === $i) ? $njum : ""; } $xls->add_row($temp_array); if ($row['Level'] === 2) $tot_biaya += $njum; } } $_sjudul = ["JUMLAH BIAYA - BIAYA"]; for ($i=0; $i<($apre['level']-1); $i++) $_sjudul[] = ""; $_sjudul[] = $tot_biaya; $xls->add_row_bold($_sjudul); $_sjudul = ["SISA HASIL USAHA (".((($tot_pend-$tot_biaya)>0)?"SURPLUS":"DEFISIT").")"]; for ($i=0; $i<($apre['level']-1); $i++) $_sjudul[] = ""; $_sjudul[] = $tot_pend - $tot_biaya; $xls->add_row_bold($_sjudul); $xls->add_stamp(1, true); $xls->download("Data Rugi Laba ".str_replace("s/d","-",$apre['periode']).".xlsx"); unset($xls); } public function index() { $alevel = []; for ($i=2; $i<=($this->app_gel['MAX_LEVEL']-1); $i++) $alevel[$i] = "Level ".$i; $form = new Form($this->app); $tbulan1 = $form->option("_", "Bulan1", date("n"), true, false, bulan_array()); $tbulan2 = $form->option("_", "Bulan2", date("n"), true, false, bulan_array()); $ttahun = $form->option("_", "Tahun", date("Y"), true, false, $this->gel->Tahun_Array()); $tlevel = $form->option("_", "Level", 3, true, false, $alevel); $this->app->json([ 'html' => '
'.$tbulan1.''.$tbulan2.'
'.$ttahun.'
'.$tlevel.'
' ]); } }