From 894f6920126392cdc304d70ca5fe687081e6dc1d Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 21 Jun 2024 12:15:54 +0700 Subject: [PATCH] Filter in voucher list --- system/autoload/Paginator.php | 4 +- system/controllers/plan.php | 62 ++++++--- system/lan/english.json | 1 - ui/ui/voucher.tpl | 238 +++++++++++++++++++--------------- 4 files changed, 185 insertions(+), 120 deletions(-) diff --git a/system/autoload/Paginator.php b/system/autoload/Paginator.php index 85441b8c..3899d7b9 100644 --- a/system/autoload/Paginator.php +++ b/system/autoload/Paginator.php @@ -8,7 +8,7 @@ class Paginator { - public static function findMany($query, $search = [], $per_page = '10') + public static function findMany($query, $search = [], $per_page = '10', $append_url = "") { global $routes, $ui; $adjacents = "2"; @@ -18,7 +18,7 @@ class Paginator if (count($search) > 0) { $url .= '&' . http_build_query($search); } - $url .= '&p='; + $url .= $append_url.'&p='; $totalReq = $query->count(); $lastpage = ceil($totalReq / $per_page); $lpm1 = $lastpage - 1; diff --git a/system/controllers/plan.php b/system/controllers/plan.php index aacf1c77..7d8982e5 100644 --- a/system/controllers/plan.php +++ b/system/controllers/plan.php @@ -352,12 +352,47 @@ switch ($action) { case 'voucher': $ui->assign('_title', Lang::T('Vouchers')); $search = _req('search'); + $router = _req('router'); + $customer = _req('customer'); + $plan = _req('plan'); + $status = _req('status'); + $ui->assign('router', $router); + $ui->assign('customer', $customer); + $ui->assign('status', $status); + $ui->assign('plan', $plan); + + $query = ORM::for_table('tbl_plans') + ->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan')); + + if (!empty($router)) { + $query->where('tbl_voucher.routers', $router); + } + + if ($status == '1' || $status == '0') { + $query->where('tbl_voucher.status', $status); + } + + if (!empty($plan)) { + $query->where('tbl_voucher.id_plan', $plan); + } + + if (!empty($customer)) { + $query->where('tbl_voucher.user', $customer); + } + + $append_url = "&search=" . urlencode($search) . "&router=" . urlencode($router) . "&customer=" . urlencode($customer) . "&plan=" . urlencode($plan) . "&status=" . urlencode($status); + + // option customers + $ui->assign('customers', ORM::for_table('tbl_voucher')->distinct()->select("user")->whereNotEqual("user", '0')->findArray()); + // option plans + $plns = ORM::for_table('tbl_voucher')->distinct()->select("id_plan")->findArray(); + $ui->assign('plans', ORM::for_table('tbl_plans')->selects(["id", 'name_plan'])->whereIdIn(array_column($plns, 'id_plan'))->findArray()); + + $ui->assign('routers', array_column(ORM::for_table('tbl_voucher')->distinct()->select("routers")->findArray(), 'routers')); + if ($search != '') { if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - $query = ORM::for_table('tbl_plans')->where('enabled', '1') - ->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan')) - ->where_like('tbl_voucher.code', '%' . $search . '%'); - $d = Paginator::findMany($query, ["search" => $search]); + $query->where_like('tbl_voucher.code', '%' . $search . '%'); } else if ($admin['user_type'] == 'Agent') { $sales = []; $sls = ORM::for_table('tbl_users')->select('id')->where('root', $admin['id'])->findArray(); @@ -365,17 +400,11 @@ switch ($action) { $sales[] = $s['id']; } $sales[] = $admin['id']; - $query = ORM::for_table('tbl_plans') - ->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan')) - ->where_in('generated_by', $sales) + $query->where_in('generated_by', $sales) ->where_like('tbl_voucher.code', '%' . $search . '%'); - $d = Paginator::findMany($query, ["search" => $search]); } } else { if (in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { - $query = ORM::for_table('tbl_plans')->where('enabled', '1') - ->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan')); - $d = Paginator::findMany($query); } else if ($admin['user_type'] == 'Agent') { $sales = []; $sls = ORM::for_table('tbl_users')->select('id')->where('root', $admin['id'])->findArray(); @@ -383,12 +412,14 @@ switch ($action) { $sales[] = $s['id']; } $sales[] = $admin['id']; - $query = ORM::for_table('tbl_plans') - ->left_outer_join('tbl_voucher', array('tbl_plans.id', '=', 'tbl_voucher.id_plan')) - ->where_in('generated_by', $sales); - $d = Paginator::findMany($query); + $query->where_in('generated_by', $sales); } } + if ($search != '') { + $d = Paginator::findMany($query, ["search" => $search], 10, $append_url); + } else { + $d = Paginator::findMany($query, [], 10, $append_url); + } // extract admin $admins = []; foreach ($d as $k) { @@ -411,6 +442,7 @@ switch ($action) { $admins[$adm['id']] = $adm['fullname'] . $tipe; } } + $ui->assign('admins', $admins); $ui->assign('d', $d); $ui->assign('search', $search); diff --git a/system/lan/english.json b/system/lan/english.json index 246fcde4..a0684a4e 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -647,4 +647,3 @@ "Summary": "Summary", "Devices_Not_Found": "Devices Not Found", "Income_reset_date": "Income reset date" -} \ No newline at end of file diff --git a/ui/ui/voucher.tpl b/ui/ui/voucher.tpl index f1392b7a..ec6f4c37 100644 --- a/ui/ui/voucher.tpl +++ b/ui/ui/voucher.tpl @@ -1,110 +1,144 @@ {include file="sections/header.tpl"} -
-
-
-
- {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} - - {/if} -   +
+
+
+ -
-
-
- -
- -
- -
-
- Print -
-
-
  -
-
- - - - - - - - - - - - - - - - {foreach $d as $ds} - - - - - - - - - - - - {/foreach} - -
ID{Lang::T('Type')}{Lang::T('Routers')}{Lang::T('Plan Name')}{Lang::T('Code Voucher')}{Lang::T('Status Voucher')}{Lang::T('Customer')}{Lang::T('Generated By')}{Lang::T('Manage')}
{$ds['id']}{$ds['type']}{$ds['routers']}{$ds['name_plan']} - {$ds['code']}{if $ds['status'] eq '0'} {else} - {/if}{if $ds['user'] eq '0'} - - {else}{$ds['user']} - {/if}{if $ds['generated_by']} - {$admins[$ds['generated_by']]} - {else} - - {/if} - - {if $ds['status'] neq '1'} -   {Lang::T('View')}   - {/if} - {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} - - {/if} -
-
- {include file="pagination.tpl"} +
- - +
+
+ {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} + + {/if} +   +
+
+ +
+
+ + + + + + + + + + + + + + + + {foreach $d as $ds} + + + + + + + + + + + + {/foreach} + +
ID{Lang::T('Type')}{Lang::T('Routers')}{Lang::T('Plan Name')}{Lang::T('Code Voucher')}{Lang::T('Status Voucher')}{Lang::T('Customer')}{Lang::T('Generated By')}{Lang::T('Manage')}
{$ds['id']}{$ds['type']}{$ds['routers']}{$ds['name_plan']} + {$ds['code']}{if $ds['status'] eq '0'} {else} + {/if}{if $ds['user'] eq '0'} - + {else}{$ds['user']} + {/if}{if $ds['generated_by']} + {$admins[$ds['generated_by']]} + {else} - + {/if} + + {if $ds['status'] neq '1'} +   {Lang::T('View')}   + {/if} + {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} + + {/if} +
+
+
+ {include file="pagination.tpl"} +
+
{include file="sections/footer.tpl"} \ No newline at end of file