From e1272ec53137abc21eca3660adf654cc50390a84 Mon Sep 17 00:00:00 2001 From: Ibnu Maksum Date: Fri, 16 Feb 2024 16:54:13 +0700 Subject: [PATCH] print 1 voucher will go to print or share --- system/controllers/prepaid.php | 81 +++++++++++++++++++++++++++++++-- system/controllers/settings.php | 12 +++-- system/lan/english.json | 5 +- ui/ui/customers.tpl | 12 +++-- ui/ui/invoice-print.tpl | 2 + ui/ui/invoice.tpl | 16 ++----- ui/ui/prepaid.tpl | 31 +++++++------ ui/ui/users.tpl | 2 +- ui/ui/voucher-view.tpl | 27 +++++++++++ ui/ui/voucher.tpl | 42 ++++++++++++----- 10 files changed, 180 insertions(+), 50 deletions(-) create mode 100644 ui/ui/voucher-view.tpl diff --git a/system/controllers/prepaid.php b/system/controllers/prepaid.php index 83759307..e9782bd4 100644 --- a/system/controllers/prepaid.php +++ b/system/controllers/prepaid.php @@ -156,11 +156,16 @@ switch ($action) { case 'print': - $id = _post('id'); - $d = ORM::for_table('tbl_transactions')->where('id', $id)->find_one(); - $ui->assign('in', $d); + $content = $_POST['content']; + if(!empty($content)){ + $ui->assign('content', $content); + }else{ + $id = _post('id'); + $d = ORM::for_table('tbl_transactions')->where('id', $id)->find_one(); + $ui->assign('in', $d); + $ui->assign('date', Lang::dateAndTimeFormat($d['recharged_on'], $d['recharged_time'])); + } - $ui->assign('date', Lang::dateAndTimeFormat($d['recharged_on'], $d['recharged_time'])); run_hook('print_invoice'); #HOOK $ui->display('invoice-print.tpl'); break; @@ -282,7 +287,29 @@ switch ($action) { ->offset($paginator['startpoint']) ->limit($paginator['limit'])->find_many(); } - + // extract admin + $admins = []; + foreach ($d as $k) { + if(!empty($k['generated_by'])){ + $admins[] = $k['generated_by']; + } + } + if(count($admins) > 0){ + $adms = ORM::for_table('tbl_users')->where_in('id', $admins)->find_many(); + unset($admins); + foreach($adms as $adm){ + $tipe = $adm['user_type']; + if($tipe == 'Sales'){ + $tipe = ' [S]'; + }else if($tipe == 'Agent'){ + $tipe = ' [A]'; + }else{ + $tipe == ''; + } + $admins[$adm['id']] = $adm['fullname'].$tipe; + } + } + $ui->assign('admins', $admins); $ui->assign('d', $d); $ui->assign('_code', $code); $ui->assign('paginator', $paginator); @@ -466,6 +493,9 @@ switch ($action) { $d->generated_by = $admin['id']; $d->save(); } + if($numbervoucher == 1){ + r2(U . 'prepaid/voucher-view/'.$d->id(), 's', Lang::T('Create Vouchers Successfully')); + } r2(U . 'prepaid/voucher', 's', Lang::T('Create Vouchers Successfully')); } else { @@ -473,6 +503,47 @@ switch ($action) { } break; + case 'voucher-view': + if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { + $voucher = ORM::for_table('tbl_voucher')->find_one($id); + }else{ + $voucher = ORM::for_table('tbl_voucher')->where('generated_by', $admin['id'])->find_one($id); + } + $plan = ORM::for_table('tbl_plans')->find_one($d['id_plan']); + if ($voucher && $plan) { + $content = Lang::pad($config['CompanyName'],' ', 2)."\n"; + $content .= Lang::pad($config['address'],' ', 2)."\n"; + $content .= Lang::pad($config['phone'],' ', 2)."\n"; + $content .= Lang::pad("", '=')."\n"; + $content .= Lang::pads('ID', $voucher['id'], ' ')."\n"; + $content .= Lang::pads(Lang::T('Code'), $voucher['code'], ' ')."\n"; + $content .= Lang::pads(Lang::T('Plan Name'), $plan['name_plan'], ' ')."\n"; + $content .= Lang::pads(Lang::T('Type'), $voucher['type'], ' ')."\n"; + $content .= Lang::pads(Lang::T('Plan Price'), Lang::moneyFormat($plan['price']), ' ')."\n"; + $content .= Lang::pads(Lang::T('Sales'), $admin['fullname'].' #'.$admin['id'], ' ')."\n"; + $content .= Lang::pad("", '=')."\n"; + $content .= Lang::pad($config['note'],' ', 2)."\n"; + $ui->assign('print', $content); + $config['printer_cols'] = 30; + $content = Lang::pad($config['CompanyName'],' ', 2)."\n"; + $content .= Lang::pad($config['address'],' ', 2)."\n"; + $content .= Lang::pad($config['phone'],' ', 2)."\n"; + $content .= Lang::pad("", '=')."\n"; + $content .= Lang::pads('ID', $voucher['id'], ' ')."\n"; + $content .= Lang::pads(Lang::T('Code'), $voucher['code'], ' ')."\n"; + $content .= Lang::pads(Lang::T('Plan Name'), $plan['name_plan'], ' ')."\n"; + $content .= Lang::pads(Lang::T('Type'), $voucher['type'], ' ')."\n"; + $content .= Lang::pads(Lang::T('Plan Price'), Lang::moneyFormat($plan['price']), ' ')."\n"; + $content .= Lang::pads(Lang::T('Sales'), $admin['fullname'].' #'.$admin['id'], ' ')."\n"; + $content .= Lang::pad("", '=')."\n"; + $content .= Lang::pad($config['note'],' ', 2)."\n"; + $ui->assign('_title', Lang::T('View')); + $ui->assign('wa', urlencode("```$content```")); + $ui->display('voucher-view.tpl'); + }else{ + r2(U . 'prepaid/voucher/', 'e', Lang::T('Voucher Not Found')); + } + break; case 'voucher-delete': if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin'])) { r2(U . "dashboard", 'e', Lang::T('You do not have permission to access this page')); diff --git a/system/controllers/settings.php b/system/controllers/settings.php index 2c3108df..e4c85b2c 100644 --- a/system/controllers/settings.php +++ b/system/controllers/settings.php @@ -129,6 +129,7 @@ switch ($action) { $d = ORM::for_table('tbl_users') ->where_like('username', '%' . $username . '%') ->where('root', $admin['id']) + ->where('id', $admin['id']) ->offset($paginator['startpoint']) ->limit($paginator['limit'])->order_by_asc('id')->find_many(); } @@ -145,7 +146,12 @@ switch ($action) { ])->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); } else { $paginator = Paginator::build(ORM::for_table('tbl_users')); - $d = ORM::for_table('tbl_users')->where('root', $admin['id'])->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); + $d = ORM::for_table('tbl_users') + ->where_any_is([ + ['id' => $admin['id']], + ['root' => $admin['id']] + ]) + ->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_asc('id')->find_many(); } } @@ -255,7 +261,7 @@ switch ($action) { $d->ward = $ward; $d->status = 'Active'; $d->creationdate = $date_now; - if($admin['user_type']=='Agent'){ + if ($admin['user_type'] == 'Agent') { $d->root = $admin['id']; } $d->save(); @@ -324,7 +330,7 @@ switch ($action) { if ($d['username'] != $username) { $c = ORM::for_table('tbl_users')->where('username', $username)->find_one(); if ($c) { - $msg .= "$username ".Lang::T('Account already axist') . '
'; + $msg .= "$username " . Lang::T('Account already axist') . '
'; } } run_hook('edit_admin'); #HOOK diff --git a/system/lan/english.json b/system/lan/english.json index b976ab02..ba1370ad 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -408,5 +408,8 @@ "SuperAdmin": "SuperAdmin", "Admin": "Admin", "Report": "Report", - "Agent": "Agent" + "Agent": "Agent", + "Send To Customer": "Send To Customer", + "Code": "Code", + "Generated By": "Generated By" } \ No newline at end of file diff --git a/ui/ui/customers.tpl b/ui/ui/customers.tpl index 651bddd1..32812082 100644 --- a/ui/ui/customers.tpl +++ b/ui/ui/customers.tpl @@ -4,11 +4,13 @@
-
- CSV -
+ {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} +
+ CSV +
+ {/if} {Lang::T('Manage Contact')}
diff --git a/ui/ui/invoice-print.tpl b/ui/ui/invoice-print.tpl index d43aeb66..91252805 100644 --- a/ui/ui/invoice-print.tpl +++ b/ui/ui/invoice-print.tpl @@ -21,6 +21,7 @@
+ {if $content}
{$content}
{else}
{Lang::pad($_c['CompanyName'],' ', 2)}
 {Lang::pad($_c['address'],' ', 2)}
 {Lang::pad($_c['phone'],' ', 2)}
@@ -42,6 +43,7 @@
 {/if}
 {Lang::pad("", '=')}
 {Lang::pad($_c['note'],' ', 2)}
+{/if}
diff --git a/ui/ui/invoice.tpl b/ui/ui/invoice.tpl index 3ded00c5..f282a209 100644 --- a/ui/ui/invoice.tpl +++ b/ui/ui/invoice.tpl @@ -5,7 +5,9 @@
{$in['invoice']}
-
{Lang::pad($_c['CompanyName'],' ', 2)}
+
+

+
     
     {Lang::T('Finish')}
@@ -35,19 +36,12 @@
     
 
-
{include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/prepaid.tpl b/ui/ui/prepaid.tpl index 541fc1a5..cd74f2cc 100644 --- a/ui/ui/prepaid.tpl +++ b/ui/ui/prepaid.tpl @@ -4,16 +4,19 @@
-
- sync -
-
- CSV -
{Lang::T('Prepaid Users')} + {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} +
+ sync +
+
+ CSV +
+ {/if} + {Lang::T('Prepaid Users')}
@@ -63,9 +66,11 @@ {Lang::T('Edit')} - + {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} + + {/if} {/foreach} diff --git a/ui/ui/users.tpl b/ui/ui/users.tpl index b60a5190..4db65135 100644 --- a/ui/ui/users.tpl +++ b/ui/ui/users.tpl @@ -55,7 +55,7 @@ {Lang::T('Edit')} - {if ($_admin['username']) neq ($ds['username'])} + {if ($_admin['id']) neq ($ds['id'])} {/if} diff --git a/ui/ui/voucher-view.tpl b/ui/ui/voucher-view.tpl new file mode 100644 index 00000000..1da313f0 --- /dev/null +++ b/ui/ui/voucher-view.tpl @@ -0,0 +1,27 @@ +{include file="sections/header.tpl"} + +
+
+
+
+
+

+                    
+                    
+                    {Lang::T('Finish')}
+                     {Lang::T("Send To Customer")}
+                    
+                
+ + +
+
+
+
+ +{include file="sections/footer.tpl"} \ No newline at end of file diff --git a/ui/ui/voucher.tpl b/ui/ui/voucher.tpl index acc80633..e52ec5ee 100644 --- a/ui/ui/voucher.tpl +++ b/ui/ui/voucher.tpl @@ -4,11 +4,14 @@
- - {Lang::T('Prepaid Vouchers')} + {if in_array($_admin['user_type'],['SuperAdmin','Admin'])} + + {/if} + {Lang::T('Prepaid Vouchers')}
@@ -50,12 +53,13 @@ {Lang::T('Code Voucher')} {Lang::T('Status Voucher')} {Lang::T('Customer')} + {Lang::T('Generated By')} {Lang::T('Manage')} {foreach $d as $ds} - + {$ds['id']} {$ds['type']} {$ds['routers']} @@ -64,14 +68,30 @@ style="width:120px;border: 0px; text-align: right;" class="pull-right" onmouseleave="this.type = 'password'" onmouseenter="this.type = 'text'" onclick="this.select()"> - {if $ds['status'] eq '0'}