From a15510e62ac4d119dc83dcda58156ee83f933a2c Mon Sep 17 00:00:00 2001 From: gerandonk Date: Fri, 15 Mar 2024 04:07:30 +0700 Subject: [PATCH] postpaid always zero for first time recharge and invoice atribute for next month for postpaid customer invoice reminder and order get from invoice attribute --- system/autoload/Package.php | 74 +++++++++++++++++++++--------------- system/controllers/order.php | 26 ++++++++++++- system/cron_reminder.php | 13 ++++++- 3 files changed, 80 insertions(+), 33 deletions(-) diff --git a/system/autoload/Package.php b/system/autoload/Package.php index 83a7415b..018f9198 100644 --- a/system/autoload/Package.php +++ b/system/autoload/Package.php @@ -246,7 +246,17 @@ class Package $t->invoice = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; - $t->price = $p['price'] + $add_cost; + if ($p['validity_unit'] == 'Period') { + // Postpaid price from field + $add_inv = User::getAttribute("Invoice", $id_customer); + if (empty ($add_inv) or $add_inv == 0) { + $t->price = $p['price'] + $add_cost; + } else { + $t->price = $add_inv + $add_cost; + } + } else { + $t->price = $p['price'] + $add_cost; + } $t->recharged_on = $date_only; $t->recharged_time = $time_only; $t->expiration = $date_exp; @@ -263,7 +273,7 @@ class Package $t->save(); if ($p['validity_unit'] == 'Period') { - // insert to fields + // insert price to fields for invoice next month $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); if (!$fl) { $fl = ORM::for_table('tbl_customers_fields')->create(); @@ -319,18 +329,9 @@ class Package $t->invoice = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; - if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { - // Calculating Price - $sd = new DateTime("$date_only"); - $ed = new DateTime("$date_exp"); - $td = $ed->diff($sd); - $fd = $td->format("%a"); - $gi = ($p['price'] / 30) * $fd; - if ($gi > $p['price']) { - $t->price = $p['price'] + $add_cost; - } else { - $t->price = $gi + $add_cost; - } + if ($p['validity_unit'] == 'Period') { + // Postpaid price always zero for first time + $t->price = 0 + $add_cost; } else { $t->price = $p['price'] + $add_cost; } @@ -350,12 +351,18 @@ class Package $t->save(); if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { - // insert to fields + // insert price to fields for invoice next month $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); if (!$fl) { $fl = ORM::for_table('tbl_customers_fields')->create(); $fl->customer_id = $c['id']; $fl->field_name = 'Invoice'; + // Calculating Price + $sd = new DateTime("$date_only"); + $ed = new DateTime("$date_exp"); + $td = $ed->diff($sd); + $fd = $td->format("%a"); + $gi = ($p['price'] / 30) * $fd; if ($gi > $p['price']) { $fl->field_value = $p['price']; } else { @@ -433,7 +440,17 @@ class Package $t->invoice = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; - $t->price = $p['price'] + $add_cost; + if ($p['validity_unit'] == 'Period') { + // Postpaid price from field + $add_inv = User::getAttribute("Invoice", $id_customer); + if (empty ($add_inv) or $add_inv == 0) { + $t->price = $p['price'] + $add_cost; + } else { + $t->price = $add_inv + $add_cost; + } + } else { + $t->price = $p['price'] + $add_cost; + } $t->recharged_on = $date_only; $t->recharged_time = $time_only; $t->expiration = $date_exp; @@ -450,7 +467,7 @@ class Package $t->save(); if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { - // insert to fields + // insert price to fields for invoice next month $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); if (!$fl) { $fl = ORM::for_table('tbl_customers_fields')->create(); @@ -505,18 +522,9 @@ class Package $t->invoice = "INV-" . Package::_raid(); $t->username = $c['username']; $t->plan_name = $p['name_plan']; - if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { - // Calculating Price - $sd = new DateTime("$date_only"); - $ed = new DateTime("$date_exp"); - $td = $ed->diff($sd); - $fd = $td->format("%a"); - $gi = ($p['price'] / 30) * $fd; - if ($gi > $p['price']) { - $t->price = $p['price'] + $add_cost; - } else { - $t->price = $gi + $add_cost; - } + if ($p['validity_unit'] == 'Period') { + // Postpaid price always zero for first time + $t->price = 0 + $add_cost; } else { $t->price = $p['price'] + $add_cost; } @@ -536,12 +544,18 @@ class Package $t->save(); if ($p['validity_unit'] == 'Period' && $p['price'] != 0) { - // insert to fields + // insert price to fields for invoice next month $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); if (!$fl) { $fl = ORM::for_table('tbl_customers_fields')->create(); $fl->customer_id = $c['id']; $fl->field_name = 'Invoice'; + // Calculating Price + $sd = new DateTime("$date_only"); + $ed = new DateTime("$date_exp"); + $td = $ed->diff($sd); + $fd = $td->format("%a"); + $gi = ($p['price'] / 30) * $fd; if ($gi > $p['price']) { $fl->field_value = $p['price']; } else { diff --git a/system/controllers/order.php b/system/controllers/order.php index f439d3de..877fb80b 100644 --- a/system/controllers/order.php +++ b/system/controllers/order.php @@ -379,7 +379,18 @@ switch ($action) { $d->plan_name = $plan['name_plan']; $d->routers_id = $router['id']; $d->routers = $router['name']; - $d->price = ($plan['price'] + $add_cost); + if ($plan['validity_unit'] == 'Period') { + // Postpaid price from field + $add_inv = User::getAttribute("Invoice", $id_customer); + if (empty ($add_inv) or $add_inv == 0) { + $d->price = ($plan['price'] + $add_cost); + } else { + $d->price = ($add_inv + $add_cost); + } + } else { + $d->price = ($plan['price'] + $add_cost); + } + //$d->price = ($plan['price'] + $add_cost); $d->created_date = date('Y-m-d H:i:s'); $d->status = 1; $d->save(); @@ -391,7 +402,18 @@ switch ($action) { $d->plan_name = $plan['name_plan']; $d->routers_id = $router['id']; $d->routers = $router['name']; - $d->price = ($plan['price'] + $add_cost); + if ($plan['validity_unit'] == 'Period') { + // Postpaid price from field + $add_inv = User::getAttribute("Invoice", $id_customer); + if (empty ($add_inv) or $add_inv == 0) { + $d->price = ($plan['price'] + $add_cost); + } else { + $d->price = ($add_inv + $add_cost); + } + } else { + $d->price = ($plan['price'] + $add_cost); + } + //$d->price = ($plan['price'] + $add_cost); $d->created_date = date('Y-m-d H:i:s'); $d->status = 1; $d->save(); diff --git a/system/cron_reminder.php b/system/cron_reminder.php index aff8182b..cc8260b5 100644 --- a/system/cron_reminder.php +++ b/system/cron_reminder.php @@ -38,7 +38,18 @@ foreach ($d as $ds) { $u = ORM::for_table('tbl_user_recharges')->where('id', $ds['id'])->find_one(); $p = ORM::for_table('tbl_plans')->where('id', $u['plan_id'])->find_one(); $c = ORM::for_table('tbl_customers')->where('id', $ds['customer_id'])->find_one(); - $price = Lang::moneyFormat($p['price']); + if ($p['validity_unit'] == 'Period') { + // Postpaid price from field + $add_inv = User::getAttribute("Invoice", $ds['customer_id']); + if (empty ($add_inv) or $add_inv == 0) { + $price = Lang::moneyFormat($p['price']); + } else { + $price = Lang::moneyFormat($add_inv); + } + } else { + $price = Lang::moneyFormat($p['price']); + } + //$price = Lang::moneyFormat($p['price']); if ($ds['expiration'] == $day7) { echo Message::sendPackageNotification($c, $p['name_plan'], $price, Lang::getNotifText('reminder_7_day'), $config['user_notification_reminder']) . "\n"; } else if ($ds['expiration'] == $day3) {