first commit
This commit is contained in:
@@ -0,0 +1,195 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
PHP Class : /Controller/Report/Ppob/JualController
|
||||
Description : Laporan Penjualan PPOB
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : April 12th, 2011.
|
||||
Last Modified : October 8th, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Report\Ppob;
|
||||
|
||||
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 JualController {
|
||||
|
||||
private int $id_cab;
|
||||
private string $reg_name;
|
||||
protected Engine $app;
|
||||
protected SimplePdo $db;
|
||||
|
||||
public function __construct(Engine $app, SimplePdo $db, Session $session) {
|
||||
$this->app = $app;
|
||||
$this->db = $db;
|
||||
$this->id_cab = Param::Int("CabID", 0);
|
||||
$this->reg_name = $session->get('WEB_APP')['REG_NAME'];
|
||||
}
|
||||
|
||||
private function prepare() {
|
||||
$apre = [
|
||||
'tipe' => Param::Get("Tipe", "R"), // R or D
|
||||
'tgl_from' => Param::Get("Tgl_From"),
|
||||
'tgl_to' => Param::Get("Tgl_To"),
|
||||
];
|
||||
|
||||
// generate report header
|
||||
$apre['periode'] = $apre['tgl_from'] . ($apre['tgl_from'] !== $apre['tgl_to'] ? ' s/d '.$apre['tgl_to'] : '');
|
||||
|
||||
$tsql = ''; $asql = [tgl_sql2str($apre['tgl_from']), tgl_sql2str($apre['tgl_to'])];
|
||||
if ($this->id_cab > 0) {
|
||||
$tsql .= " AND CabID=?";
|
||||
array_push($asql, $this->id_cab);
|
||||
}
|
||||
|
||||
if ($apre['tipe'] === "R") {
|
||||
$apre['query'] = $this->db->runQuery("SELECT P.Nama_Produk,J.*,O.OpeID,O.N_Ope FROM (SELECT ProdukID,SUM(Harga_Jual) Total,COUNT(*) Qty FROM ppob_tx WHERE (Tgl_TX BETWEEN ? AND ?)".$tsql." GROUP BY ProdukID) J LEFT JOIN ppob_produk P ON (J.ProdukID=P.ProdukID) LEFT JOIN ppob_operator O ON (P.OpeID=O.OpeID) ORDER BY P.Nama_Produk", $asql);
|
||||
} else {
|
||||
$apre['query'] = $this->db->runQuery("SELECT J.*,P.Nama_Produk FROM (SELECT * FROM ppob_tx WHERE (Tgl_TX BETWEEN ? AND ?)".$tsql.") J LEFT JOIN ppob_produk P ON (J.ProdukID=P.ProdukID) ORDER BY J.No_TX", $asql);
|
||||
}
|
||||
return $apre;
|
||||
}
|
||||
|
||||
public function print() {
|
||||
$apre = $this->prepare();
|
||||
|
||||
$pre = new PrintHTML($this->app);
|
||||
$pre->add_title([strtoupper($this->reg_name), ($apre['tipe']==="R"?"REKAP":"DETAIL")." PENJUALAN PRABAYAR PPOB", "Periode : ".$apre['periode']]);
|
||||
|
||||
if ($apre['tipe'] === "R") {
|
||||
$pre->add_field("No.",10,"C");
|
||||
$pre->add_field("Nama Produk",50,"L");
|
||||
$pre->add_field("Qty",20,"R","rupiah");
|
||||
$pre->add_field("Total",20,"R","rupiah");
|
||||
|
||||
$pre->show_titles();
|
||||
$pre->show_headers();
|
||||
|
||||
$tot_jual = 0; $tot_qty = 0; $nomor = 0; $id_ope = 0;
|
||||
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
if ($id_ope <> $row['OpeID']) {
|
||||
$pre->add_span([$row['N_Ope'],4,"L,B"]);
|
||||
$id_ope = $row['OpeID'];
|
||||
}
|
||||
$tot_jual += $row['Total'];
|
||||
$tot_qty += $row['Qty'];
|
||||
$pre->add_row([ ++$nomor, $row['Nama_Produk'], $row['Qty'], $row['Total'] ]);
|
||||
}
|
||||
$pre->add_span([ ["GRAND TOTAL",2,"R,B"],[$tot_qty,1,"R,B","rupiah"],[$tot_jual,1,"R,B","rupiah"] ]);
|
||||
|
||||
} else {
|
||||
$pre->add_field("No. Nota",30,"C");
|
||||
$pre->add_field("Tgl. Nota",30,"C", "tgl_sql2str");
|
||||
$pre->add_field("Nama Produk",50,"L");
|
||||
$pre->add_field("No. Tujuan",20,"L");
|
||||
$pre->add_field("No. HP",20,"L");
|
||||
$pre->add_field("Total",30,"R","rupiah");
|
||||
|
||||
$pre->show_titles();
|
||||
$pre->show_headers();
|
||||
|
||||
$tot_jual = 0;
|
||||
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$tot_jual += $row['Harga_Jual'];
|
||||
$pre->add_row([ $row['No_TX'], $row['Tgl_TX'], $row['Nama_Produk'], $row['Tujuan'], $row['No_HP'], $row['Harga_Jual'] ]);
|
||||
}
|
||||
$pre->add_span([ ["GRAND TOTAL",5,"R,B"],[$tot_jual,1,"R,B","rupiah"] ]);
|
||||
}
|
||||
$pre->add_stamp(1, true);
|
||||
$pre->show();
|
||||
}
|
||||
|
||||
public function excel() {
|
||||
$apre = $this->prepare();
|
||||
$xls = new Xlsx($this->app);
|
||||
$xls->set_meta([
|
||||
'title' => "Data Penjualan Prabayar PPOB",
|
||||
'desc' => "Export Data Penjualan Prabayar PPOB Periode : ".$apre['periode'],
|
||||
]);
|
||||
$xls->add_title([ $this->reg_name, "DATA ".($apre['tipe']==="R"?"REKAP":"DETAIL")." PENJUALAN PRABAYAR PPOB", "Periode : ".$apre['periode'] ]);
|
||||
|
||||
if ($apre['tipe'] === "R") {
|
||||
$xls->add_field("No.", 5, "@integer");
|
||||
$xls->add_field("Nama Produk", 25, "@text");
|
||||
$xls->add_field("Qty", 15, "#,##0.00");
|
||||
$xls->add_field("Total", 15, "#,##0.00");
|
||||
$xls->add_sheet("".str_replace("s/d","-",$apre['periode']));
|
||||
|
||||
$xls->show_titles();
|
||||
$xls->show_headers();
|
||||
|
||||
$tot_jual = 0; $tot_qty = 0; $nomor = 0; $id_ope = 0;
|
||||
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
if ($id_ope <> $row['OpeID']) {
|
||||
$xls->add_row_bold([ $row['N_Ope'] ]);
|
||||
$id_ope = $row['OpeID'];
|
||||
}
|
||||
$tot_jual += $row['Total'];
|
||||
$tot_qty += $row['Qty'];
|
||||
$xls->add_row([ ++$nomor, $row['Nama_Produk'], $row['Qty'], $row['Total'] ]);
|
||||
}
|
||||
$xls->add_row_bold([ "", "GRAND TOTAL", $tot_qty, $tot_jual ]);
|
||||
|
||||
} else {
|
||||
$xls->add_field("No. Nota", 15, "@");
|
||||
$xls->add_field("Tgl. Nota", 12, "@date");
|
||||
$xls->add_field("Nama Produk", 20, "@text");
|
||||
$xls->add_field("No. Tujuan", 15, "@text");
|
||||
$xls->add_field("No. HP", 15, "@text");
|
||||
$xls->add_field("Total", 15, "#,##0.00");
|
||||
$xls->add_sheet("".str_replace("s/d","-",$apre['periode']));
|
||||
|
||||
$xls->show_titles();
|
||||
$xls->show_headers();
|
||||
|
||||
$tot_jual = 0;
|
||||
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$tot_jual += $row['Harga_Jual'];
|
||||
$xls->add_row([ $row['No_TX'], $row['Tgl_TX'], $row['Nama_Produk'], $row['Tujuan'], $row['No_HP'], $row['Harga_Jual'] ]);
|
||||
}
|
||||
$xls->add_row_bold([ "", "", "GRAND TOTAL", "", "", $tot_jual ]);
|
||||
}
|
||||
$xls->add_stamp(1, true);
|
||||
$xls->download("Data Penjualan Prabayar PPOB ".str_replace("s/d","-",$apre['periode']).".xlsx");
|
||||
unset($xls);
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$form = new Form($this->app);
|
||||
$ttipe = $form->radio("_", "Tipe", "R", true, false, ["R"=>"Rekap","D"=>"Detail"]);
|
||||
$tcab = $form->option_db("_", "CabID", $this->id_cab, true, false, "para_cabang", ["CabID","Nama_Cab"], "Aktif=1 ORDER BY CabID", [0,"SEMUA CABANG"]);
|
||||
$tfrom = $form->datebox("_", "Tgl_From", tgl_ymd(), true, false);
|
||||
$tto = $form->datebox("_", "Tgl_To", tgl_ymd(), true, false);
|
||||
$ajson['html'] = '
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Tipe">Tipe Laporan</label>
|
||||
<div class="col">'.$ttipe.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="CabID">Nama Cabang</label>
|
||||
<div class="col">'.$tcab.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Tgl_From">Dari Tanggal</label>
|
||||
<div class="col-sm-6 col-lg-5">'.$tfrom.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Tgl_To">Sampai Tanggal</label>
|
||||
<div class="col-sm-6 col-lg-5">'.$tto.'</div>
|
||||
</div>';
|
||||
$this->app->json($ajson);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user