first commit
This commit is contained in:
@@ -0,0 +1,176 @@
|
||||
<?php
|
||||
|
||||
/*******************************************************************
|
||||
|
||||
PHP Class : /Controller/Report/Member/PointController
|
||||
Description : Laporan Point Member
|
||||
Created By : Siau Pheng ([email protected]).
|
||||
Created Date : May 9th, 2017.
|
||||
Last Modified : October 17th, 2026.
|
||||
|
||||
(c) 3FONIA Software; WWW.3FONIA.COM.
|
||||
|
||||
*******************************************************************/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controller\Report\Member;
|
||||
|
||||
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 PointController {
|
||||
|
||||
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 = [
|
||||
'id_tipe' => Param::Int("Point_TipeID", 0),
|
||||
'id_grup_mem' => Param::Int("Grup_MemberID", 0),
|
||||
'urut' => Param::Get("Urut", "P"),
|
||||
'tgl_from' => Param::Get("Tgl_From"),
|
||||
'tgl_to' => Param::Get("Tgl_To"),
|
||||
];
|
||||
|
||||
$apre['nama_tipe'] = ($apre['id_tipe'] > 0) ? ($this->db->fetchField("SELECT UPPER(Nama_Tipe) FROM inv_point_tipe WHERE Point_TipeID=?", [$apre['id_tipe']]) ?? '') : '';
|
||||
|
||||
// generate report header
|
||||
$apre['periode'] = $apre['tgl_from'] . ($apre['tgl_from'] !== $apre['tgl_to'] ? ' s/d '.$apre['tgl_to'] : '');
|
||||
|
||||
$tsql1 = ''; $tsql2 = ''; $asql1 = []; $asql2 = [$apre['id_tipe'], tgl_sql2str($apre['tgl_from']), tgl_sql2str($apre['tgl_to'])];
|
||||
if ($this->id_cab > 0) {
|
||||
$tsql2 .= " AND CabID=?";
|
||||
array_push($asql2, $this->id_cab);
|
||||
}
|
||||
if ($apre['id_grup_mem'] > 0) {
|
||||
$tsql1 .= " AND Grup_MemberID=?";
|
||||
array_push($asql1, $apre['id_grup_mem']);
|
||||
}
|
||||
$torder = ($apre['urut'] === "N") ? "M.Nama_Member ASC" : "P.Sisa_Point DESC";
|
||||
$torder = ($apre['urut'] === "P") ? "P.Tambah_Point DESC" : $torder;
|
||||
|
||||
$apre['query'] = $this->db->runQuery("SELECT M.*,G.Nama_Grup,P.* FROM (SELECT * FROM para_member WHERE (IM=1 OR (IM=0 AND Kode_Member<>''))".$tsql1.") M LEFT JOIN para_member_grup G ON (G.Grup_MemberID=M.Grup_MemberID) LEFT JOIN (SELECT MemberID,SUM(IF(Nilai_Point>0,Nilai_Point,0)) Tambah_Point,SUM(IF(Nilai_Point<0,-Nilai_Point,0)) Kurang_Point,SUM(Nilai_Point) Sisa_Point FROM inv_point_tx WHERE Point_TipeID=? AND Tgl_TX BETWEEN ? AND ?".$tsql2." GROUP BY MemberID ORDER BY MemberID) P ON (P.MemberID=M.MemberID) ORDER BY ".$torder, array_merge($asql1, $asql2));
|
||||
return $apre;
|
||||
}
|
||||
|
||||
public function print() {
|
||||
$apre = $this->prepare();
|
||||
|
||||
$pre = new PrintHTML($this->app);
|
||||
$pre->add_title([strtoupper($this->reg_name), "JUMLAH POINT MEMBER ".$apre['nama_tipe'], "Periode : ".$apre['periode']]);
|
||||
|
||||
$pre->add_field("No.",10,"C");
|
||||
$pre->add_field("ID Member",20,"L");
|
||||
$pre->add_field("Grup Member",40,"L");
|
||||
$pre->add_field("Nama Member",80,"L");
|
||||
$pre->add_field("No. Telp",80,"L");
|
||||
$pre->add_field("Alamat Member",120,"L");
|
||||
$pre->add_field("Jumlah Point",20,"R","rupiah");
|
||||
$pre->add_field("Jumlah Tukar",20,"R","rupiah");
|
||||
$pre->add_field("Sisa Point",20,"R","rupiah");
|
||||
|
||||
$pre->show_titles();
|
||||
$pre->show_headers();
|
||||
|
||||
$nomor = 0; $tot_point = 0; $tot_tukar = 0; $tot_sisa = 0;
|
||||
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$tot_point += $row['Tambah_Point'];
|
||||
$tot_tukar += $row['Kurang_Point'];
|
||||
$tot_sisa += $row['Sisa_Point'];
|
||||
$pre->add_row([ ++$nomor, $row['Kode_Member'], $row['Nama_Grup'], $row['Nama_Member'], $row['Telp_Member'], $row['Alamat_Member'], $row['Tambah_Point'], $row['Kurang_Point'], $row['Sisa_Point'] ]);
|
||||
}
|
||||
$pre->add_span([ ["GRAND TOTAL",6,"R,B"],[$tot_point,1,"R,B","rupiah"],[$tot_tukar,1,"R,B","rupiah"],[$tot_sisa,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 Jumlah Point Member",
|
||||
'desc' => "Export Data Jumlah Point Member"
|
||||
]);
|
||||
$xls->add_title([ $this->reg_name, "DATA JUMLAH POINT MEMBER ".$apre['nama_tipe'], "Periode : ".$apre['periode'] ]);
|
||||
|
||||
$xls->add_field("No.", 5, "@integer");
|
||||
$xls->add_field("ID Member", 10, "@text");
|
||||
$xls->add_field("Grup Member", 15, "@text");
|
||||
$xls->add_field("Nama Member", 15, "@text");
|
||||
$xls->add_field("No. Telp", 12, "@text");
|
||||
$xls->add_field("Alamat Member", 25, "@text");
|
||||
$xls->add_field("Jumlah Point", 15, "#,##0.00");
|
||||
$xls->add_field("Jumlah Tukar", 15, "#,##0.00");
|
||||
$xls->add_field("Sisa Point", 15, "#,##0.00");
|
||||
$xls->add_sheet("".str_replace("s/d","-",$apre['periode']));
|
||||
|
||||
$xls->show_titles();
|
||||
$xls->show_headers();
|
||||
|
||||
$nomor = 0; $tot_point = 0; $tot_tukar = 0; $tot_sisa = 0;
|
||||
while ($row = $apre['query']->fetch(SimplePdo::FETCH_ASSOC)) {
|
||||
$tot_point += $row['Tambah_Point'];
|
||||
$tot_tukar += $row['Kurang_Point'];
|
||||
$tot_sisa += $row['Sisa_Point'];
|
||||
$xls->add_row([ ++$nomor, $row['Kode_Member'], $row['Nama_Grup'], $row['Nama_Member'], $row['Telp_Member'], $row['Alamat_Member'], $row['Tambah_Point'], $row['Kurang_Point'], $row['Sisa_Point'] ]);
|
||||
}
|
||||
$xls->add_row_bold([ "", "", "", "GRAND TOTAL", "", "", $tot_point, $tot_tukar, $tot_sisa ]);
|
||||
|
||||
$xls->add_stamp(1, true);
|
||||
$xls->download("Data Jumlah Point Member ".str_replace("s/d","-",$apre['periode']).".xlsx");
|
||||
unset($xls);
|
||||
}
|
||||
|
||||
public function index() {
|
||||
$form = new Form($this->app);
|
||||
$ttipe = $form->option_db("_", "Point_TipeID", 0, true, false, "inv_point_tipe", ["Point_TipeID","Nama_Tipe"], "TRUE ORDER BY Point_TipeID", [0," "]);
|
||||
$tcab = $form->option_db("_", "CabID", $this->id_cab, true, false, "para_cabang", ["CabID","Nama_Cab"], "Aktif=1 ORDER BY CabID", [0,"SEMUA CABANG"]);
|
||||
$tgrup_mem = $form->option_db("_", "Grup_MemberID", 0, true, false, "para_member_grup", ["Grup_MemberID","Nama_Grup"], "TRUE ORDER BY Nama_Grup", [0,"SEMUA GRUP"]);
|
||||
$turut = $form->radio("_", "Urut", "B", true, false, ['N'=>"Nama (A-Z)",'P'=>"Jumlah Point (Z-A)",'S'=>"Sisa Point (Z-A)"]);
|
||||
$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="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="Point_TipeID">Tipe Point</label>
|
||||
<div class="col">'.$ttipe.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Grup_MemberID">Grup Member</label>
|
||||
<div class="col">'.$tgrup_mem.'</div>
|
||||
</div>
|
||||
<div class="row mb-1">
|
||||
<label class="col-sm-4 col-lg-3 col-form-label" for="Urut">Urut Berdasarkan</label>
|
||||
<div class="col">'.$turut.'</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