170 lines
7.0 KiB
PHP
170 lines
7.0 KiB
PHP
<?php
|
|
|
|
/*******************************************************************
|
|
|
|
PHP Class : /Controller/Report/Gel/BulanrlcabController
|
|
Description : Laporan Rugi / Laba Cabang
|
|
Created By : Siau Pheng ([email protected]).
|
|
Created Date : July 12th, 2008.
|
|
Last Modified : October 24th, 2026.
|
|
|
|
(c) 3FONIA Software; WWW.3FONIA.COM.
|
|
|
|
*******************************************************************/
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Controller\Report\Gel;
|
|
|
|
use App\Utils\Gel;
|
|
use flight\Engine;
|
|
use flight\database\SimplePdo;
|
|
use flight\Session;
|
|
use Webapp\Data\Xlsx;
|
|
use Webapp\Printer\PrintHTML;
|
|
use Webapp\Web\Form;
|
|
use Webapp\Web\Param;
|
|
|
|
class BulanrlcabController {
|
|
|
|
private string $reg_name;
|
|
private string $rek_hpp;
|
|
private int $id_cab;
|
|
private Gel $gel;
|
|
protected Engine $app;
|
|
protected SimplePdo $db;
|
|
|
|
public function __construct(Engine $app, SimplePdo $db, Session $session) {
|
|
$this->app = $app;
|
|
$this->db = $db;
|
|
$this->reg_name = $session->get('WEB_APP')['REG_NAME'];
|
|
$this->rek_hpp = (string) $session->get('APP_GEL')['HPP'];
|
|
$this->id_cab = Param::Int("CabID", 0);
|
|
$this->gel = new Gel($app);
|
|
}
|
|
|
|
private function prepare() {
|
|
$apre = [
|
|
'bulan1' => Param::Int("Bulan1"),
|
|
'bulan2' => Param::Int("Bulan2"),
|
|
'tahun' => Param::Int("Tahun"),
|
|
];
|
|
$tgl_akhir = tgl_akhbln("01-".isi_nol($apre['bulan2'],2)."-".(string) $apre['tahun']);
|
|
|
|
$apre['nama_cab'] = ($this->id_cab > 0) ? ($this->db->fetchField("SELECT Nama_Cab FROM para_cabang WHERE CabID=?", [$this->id_cab]) ?? '') : '';
|
|
|
|
// generate report header
|
|
$apre['periode'] = '01-'.isi_nol($apre['bulan1'],2).'-'.(string) $apre['tahun'].' s/d '.$tgl_akhir;
|
|
|
|
$tsql = ''; $asql = [$apre['tahun']."-".isi_nol($apre['bulan1'], 2)."-01" , tgl_sql2str($tgl_akhir)];
|
|
if ($this->id_cab > 0) {
|
|
$tsql .= " AND CabID=?";
|
|
array_push($asql, $this->id_cab);
|
|
}
|
|
|
|
$apre['pend'] = $this->db->fetchAll("SELECT D.*,R.Nama_Rek FROM (SELECT Kode_Rek,SUM(-Jumlah) Jumlah FROM gel_jurnal_detail WHERE (Tgl_Ref BETWEEN ? AND ?) AND (LEFT(Kode_Rek,1)='4' OR Kode_Rek='".$this->rek_hpp."')".$tsql." GROUP BY Kode_Rek ORDER BY Kode_Rek) D LEFT JOIN gel_acc R ON (D.Kode_Rek=R.Kode_Rek)", $asql);
|
|
$apre['biaya'] = $this->db->fetchAll("SELECT D.*,R.Nama_Rek FROM (SELECT Kode_Rek,SUM(Jumlah) Jumlah FROM gel_jurnal_detail WHERE (Tgl_Ref BETWEEN ? AND ?) AND LEFT(Kode_Rek,1)='5'".$tsql." GROUP BY Kode_Rek ORDER BY Kode_Rek) D LEFT JOIN gel_acc R ON (D.Kode_Rek=R.Kode_Rek)", $asql);
|
|
return $apre;
|
|
}
|
|
|
|
public function print() {
|
|
$apre = $this->prepare();
|
|
|
|
$pre = new PrintHTML($this->app);
|
|
$pre->add_title([strtoupper($this->reg_name), "RUGI / LABA CABANG", "Periode : ".$apre['periode']]);
|
|
|
|
$pre->add_field("No.",10,"C");
|
|
$pre->add_field("Kode",20,"C");
|
|
$pre->add_field("Nama Rekening",150,"L");
|
|
$pre->add_field("Jumlah",50,"R","kurung2");
|
|
|
|
if ($this->id_cab > 0) $pre->add_sub_title("Nama Cabang : ".$apre['nama_cab']);
|
|
|
|
$pre->show_titles();
|
|
$pre->show_headers();
|
|
|
|
$nomor = 0; $tot_pend = 0; $tot_biaya = 0;
|
|
foreach ($apre['pend'] as $row) {
|
|
$tot_pend += $row['Jumlah'];
|
|
$pre->add_row([ ++$nomor, $row['Kode_Rek'], $row['Nama_Rek'], $row['Jumlah'] ]);
|
|
}
|
|
$pre->add_span([ ["TOTAL PENDAPATAN KOTOR",3,"L,B"],[$tot_pend,1,"R,B","kurung2"] ]);
|
|
|
|
$pre->add_row([ "" ]);
|
|
foreach ($apre['biaya'] as $row) {
|
|
if ((string) $row['Kode_Rek'] === $this->rek_hpp) continue;
|
|
$tot_biaya += $row['Jumlah'];
|
|
$pre->add_row([ ++$nomor, $row['Kode_Rek'], $row['Nama_Rek'], $row['Jumlah'] ]);
|
|
}
|
|
$pre->add_span([ ["TOTAL BIAYA",3,"L,B"],[$tot_biaya,1,"R,B","kurung2"] ]);
|
|
$pre->add_span([ ["SELISIH R / L CABANG ( ".($tot_pend>$tot_biaya?"PROFIT":"DEFISIT")." )",3,"L,B"],[$tot_pend - $tot_biaya,1,"R,B","kurung2"] ]);
|
|
|
|
$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 Cabang",
|
|
'desc' => "Export Data Rugi / Laba Cabang"
|
|
]);
|
|
$xls->add_title([ $this->reg_name, "RUGI / LABA CABANG", "Periode : ".$apre['periode'] ]);
|
|
|
|
$xls->add_field("No.", 5, "@integer");
|
|
$xls->add_field("Kode", 10, "@text");
|
|
$xls->add_field("Nama Rekening", 40, "@text");
|
|
$xls->add_field("Jumlah", 20, "#,##0.00");
|
|
$xls->add_sheet("".str_replace("s/d","-",$apre['periode']));
|
|
|
|
if ($this->id_cab > 0) $xls->add_sub_title("Nama Cabang : ".$apre['nama_cab']);
|
|
|
|
$xls->show_titles();
|
|
$xls->show_headers();
|
|
|
|
$nomor = 0; $tot_pend = 0; $tot_biaya = 0;
|
|
foreach ($apre['pend'] as $row) {
|
|
$tot_pend += $row['Jumlah'];
|
|
$xls->add_row([ ++$nomor, $row['Kode_Rek'], $row['Nama_Rek'], $row['Jumlah'] ]);
|
|
}
|
|
$xls->add_row_bold([ "", "", "TOTAL PENDAPATAN KOTOR", $tot_pend ]);
|
|
|
|
$xls->add_row([ "" ]);
|
|
foreach ($apre['biaya'] as $row) {
|
|
if ((string) $row['Kode_Rek'] === $this->rek_hpp) continue;
|
|
$tot_biaya += $row['Jumlah'];
|
|
$xls->add_row([ ++$nomor, $row['Kode_Rek'], $row['Nama_Rek'], $row['Jumlah'] ]);
|
|
}
|
|
$xls->add_row_bold([ "", "", "TOTAL BIAYA", $tot_biaya ]);
|
|
$xls->add_row_bold([ "", "", "SELISIH R / L CABANG ( ".($tot_pend>$tot_biaya?"PROFIT":"DEFISIT")." )", $tot_pend - $tot_biaya ]);
|
|
|
|
$xls->add_stamp(1, true);
|
|
$xls->download("Data Rugi Laba Cabang ".str_replace("s/d","-",$apre['periode']).".xlsx");
|
|
unset($xls);
|
|
}
|
|
|
|
public function index() {
|
|
$form = new Form($this->app);
|
|
$tcab = $form->option_db("_", "CabID", $this->id_cab, true, false, "para_cabang", ["CabID","Nama_Cab"], "Aktif=1 ORDER BY CabID", [0,"SEMUA CABANG"]);
|
|
$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());
|
|
$this->app->json([ 'html' => '
|
|
<div class="row mb-1">
|
|
<label class="col-sm-6 col-lg-4 col-form-label" for="CabID">Nama Cabang</label>
|
|
<div class="col">'.$tcab.'</div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-6 col-lg-4 col-form-label" for="Bulan1">Periode Laporan</label>
|
|
<div class="col"><div class="input-group">'.$tbulan1.'<span class="input-group-text"><i class="bi-arrow-right-short"></i></span>'.$tbulan2.'</div></div>
|
|
</div>
|
|
<div class="row mb-1">
|
|
<label class="col-sm-6 col-lg-4 col-form-label" for="Tahun">Tahun Data</label>
|
|
<div class="col-sm-6 col-lg-6">'.$ttahun.'</div>
|
|
</div>'
|
|
]);
|
|
}
|
|
|
|
}
|