if ($p['validity_unit'] == 'Period') then add Expired Date

This commit is contained in:
Ibnu Maksum 2024-03-06 12:03:24 +07:00
parent 37a5ee8566
commit cfefd38a31
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5

View File

@ -31,14 +31,16 @@ class Package
$c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one(); $c = ORM::for_table('tbl_customers')->where('id', $id_customer)->find_one();
$p = ORM::for_table('tbl_plans')->where('id', $plan_id)->where('enabled', '1')->find_one(); $p = ORM::for_table('tbl_plans')->where('id', $plan_id)->where('enabled', '1')->find_one();
$f = ORM::for_table('tbl_customers_fields')->where('field_name', 'Expired Date')->where('customer_id', $c['id'])->find_one(); if ($p['validity_unit'] == 'Period') {
if (!$f) { $f = ORM::for_table('tbl_customers_fields')->where('field_name', 'Expired Date')->where('customer_id', $c['id'])->find_one();
$f = ORM::for_table('tbl_customers_fields')->create(); if (!$f) {
$f->customer_id = $c['id']; $f = ORM::for_table('tbl_customers_fields')->create();
$f->field_name = 'Expired Date'; $f->customer_id = $c['id'];
$f->field_value = 20; $f->field_name = 'Expired Date';
$f->save(); $f->field_value = 20;
} $f->save();
}
}
if ($router_name == 'balance') { if ($router_name == 'balance') {
// insert table transactions // insert table transactions
@ -108,18 +110,18 @@ class Package
$mikrotik = Mikrotik::info($router_name); $mikrotik = Mikrotik::info($router_name);
if ($p['validity_unit'] == 'Months') { if ($p['validity_unit'] == 'Months') {
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' month')); $date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' month'));
} else if ($p['validity_unit'] == 'Period') { } else if ($p['validity_unit'] == 'Period') {
$date_tmp = date("Y-m-{$f['field_value']}", strtotime('+' . $p['validity'] . ' month')); $date_tmp = date("Y-m-{$f['field_value']}", strtotime('+' . $p['validity'] . ' month'));
$dt1 = new DateTime("$date_only"); $dt1 = new DateTime("$date_only");
$dt2 = new DateTime("$date_tmp"); $dt2 = new DateTime("$date_tmp");
$diff = $dt2->diff($dt1); $diff = $dt2->diff($dt1);
$sum = $diff->format("%a");// => 453 $sum = $diff->format("%a"); // => 453
if ($sum >= 35) { if ($sum >= 35) {
$date_exp = date("Y-m-{$f['field_value']}", strtotime('+0 month')); $date_exp = date("Y-m-{$f['field_value']}", strtotime('+0 month'));
} else { } else {
$date_exp = date("Y-m-{$f['field_value']}", strtotime('+' . $p['validity'] . ' month')); $date_exp = date("Y-m-{$f['field_value']}", strtotime('+' . $p['validity'] . ' month'));
}; };
$time = date("23:59:00"); $time = date("23:59:00");
} else if ($p['validity_unit'] == 'Days') { } else if ($p['validity_unit'] == 'Days') {
$date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' day')); $date_exp = date("Y-m-d", strtotime('+' . $p['validity'] . ' day'));
} else if ($p['validity_unit'] == 'Hrs') { } else if ($p['validity_unit'] == 'Hrs') {
@ -139,9 +141,9 @@ class Package
if ($p['validity_unit'] == 'Months') { if ($p['validity_unit'] == 'Months') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months')); $date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
$time = $b['time']; $time = $b['time'];
} else if ($p['validity_unit'] == 'Period') { } else if ($p['validity_unit'] == 'Period') {
$date_exp = date("Y-m-{$f['field_value']}", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months')); $date_exp = date("Y-m-{$f['field_value']}", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
$time = date("23:59:00"); $time = date("23:59:00");
} else if ($p['validity_unit'] == 'Days') { } else if ($p['validity_unit'] == 'Days') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' days')); $date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' days'));
$time = $b['time']; $time = $b['time'];
@ -204,26 +206,26 @@ class Package
} }
$t->save(); $t->save();
// insert to fields // insert to fields
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one();
if (!$fl) { if (!$fl) {
$fl = ORM::for_table('tbl_customers_fields')->create(); $fl = ORM::for_table('tbl_customers_fields')->create();
$fl->customer_id = $c['id']; $fl->customer_id = $c['id'];
$fl->field_name = 'Invoice'; $fl->field_name = 'Invoice';
$fl->field_value = $p['price']; $fl->field_value = $p['price'];
$fl->save(); $fl->save();
} else { } else {
$fl->customer_id = $c['id']; $fl->customer_id = $c['id'];
$fl->field_value = $p['price']; $fl->field_value = $p['price'];
$fl->save(); $fl->save();
} }
Message::sendTelegram("#u$c[username] $c[fullname] #recharge #Hotspot \n" . $p['name_plan'] . Message::sendTelegram("#u$c[username] $c[fullname] #recharge #Hotspot \n" . $p['name_plan'] .
"\nRouter: " . $router_name . "\nRouter: " . $router_name .
"\nGateway: " . $gateway . "\nGateway: " . $gateway .
"\nChannel: " . $channel . "\nChannel: " . $channel .
"\nPrice: " . Lang::moneyFormat($p['price'])); "\nPrice: " . Lang::moneyFormat($p['price']));
} else { } else {
if ($p['is_radius']) { if ($p['is_radius']) {
Radius::customerAddPlan($c, $p, "$date_exp $time"); Radius::customerAddPlan($c, $p, "$date_exp $time");
@ -254,23 +256,23 @@ class Package
} }
$d->save(); $d->save();
// Calculating Price // Calculating Price
$sd = new DateTime("$date_only"); $sd = new DateTime("$date_only");
$ed = new DateTime("$date_exp"); $ed = new DateTime("$date_exp");
$td = $ed->diff($sd); $td = $ed->diff($sd);
$fd = $td->format("%a"); $fd = $td->format("%a");
$gi = ($p['price']/30)*$fd; $gi = ($p['price'] / 30) * $fd;
// insert table transactions // insert table transactions
$t = ORM::for_table('tbl_transactions')->create(); $t = ORM::for_table('tbl_transactions')->create();
$t->invoice = "INV-" . Package::_raid(5); $t->invoice = "INV-" . Package::_raid(5);
$t->username = $c['username']; $t->username = $c['username'];
$t->plan_name = $p['name_plan']; $t->plan_name = $p['name_plan'];
if ($gi > $p['price']) { if ($gi > $p['price']) {
$t->price = $p['price']; $t->price = $p['price'];
} else { } else {
$t->price = $gi; $t->price = $gi;
} }
$t->recharged_on = $date_only; $t->recharged_on = $date_only;
$t->recharged_time = $time_only; $t->recharged_time = $time_only;
$t->expiration = $date_exp; $t->expiration = $date_exp;
@ -285,31 +287,30 @@ class Package
} }
$t->save(); $t->save();
// insert to fields // insert to fields
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one();
if (!$fl) { if (!$fl) {
$fl = ORM::for_table('tbl_customers_fields')->create(); $fl = ORM::for_table('tbl_customers_fields')->create();
$fl->customer_id = $c['id']; $fl->customer_id = $c['id'];
$fl->field_name = 'Invoice'; $fl->field_name = 'Invoice';
if ($gi > $p['price']) { if ($gi > $p['price']) {
$fl->field_value = $p['price']; $fl->field_value = $p['price'];
} else { } else {
$fl->field_value = $gi; $fl->field_value = $gi;
} }
$fl->save(); $fl->save();
} else { } else {
$fl->customer_id = $c['id']; $fl->customer_id = $c['id'];
$fl->field_value = $p['price']; $fl->field_value = $p['price'];
$fl->save(); $fl->save();
} }
Message::sendTelegram("#u$c[username] $c[fullname] #buy #Hotspot \n" . $p['name_plan'] . Message::sendTelegram("#u$c[username] $c[fullname] #buy #Hotspot \n" . $p['name_plan'] .
"\nRouter: " . $router_name . "\nRouter: " . $router_name .
"\nGateway: " . $gateway . "\nGateway: " . $gateway .
"\nChannel: " . $channel . "\nChannel: " . $channel .
"\nPrice: " . Lang::moneyFormat($p['price'])); "\nPrice: " . Lang::moneyFormat($p['price']));
} }
} else { } else {
if ($b) { if ($b) {
@ -318,9 +319,9 @@ class Package
if ($p['validity_unit'] == 'Months') { if ($p['validity_unit'] == 'Months') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months')); $date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
$time = $b['time']; $time = $b['time'];
} else if ($p['validity_unit'] == 'Period') { } else if ($p['validity_unit'] == 'Period') {
$date_exp = date("Y-m-{$f['field_value']}", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months')); $date_exp = date("Y-m-{$f['field_value']}", strtotime($b['expiration'] . ' +' . $p['validity'] . ' months'));
$time = date("23:59:00"); $time = date("23:59:00");
} else if ($p['validity_unit'] == 'Days') { } else if ($p['validity_unit'] == 'Days') {
$date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' days')); $date_exp = date("Y-m-d", strtotime($b['expiration'] . ' +' . $p['validity'] . ' days'));
$time = $b['time']; $time = $b['time'];
@ -383,26 +384,26 @@ class Package
} }
$t->save(); $t->save();
// insert to fields // insert to fields
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one();
$gp = $gi; $gp = $gi;
if (!$fl) { if (!$fl) {
$fl = ORM::for_table('tbl_customers_fields')->create(); $fl = ORM::for_table('tbl_customers_fields')->create();
$fl->customer_id = $c['id']; $fl->customer_id = $c['id'];
$fl->field_name = 'Invoice'; $fl->field_name = 'Invoice';
$fl->field_value = $p['price']; $fl->field_value = $p['price'];
$fl->save(); $fl->save();
} else { } else {
$fl->customer_id = $c['id']; $fl->customer_id = $c['id'];
$fl->field_value = $p['price']; $fl->field_value = $p['price'];
$fl->save(); $fl->save();
} }
Message::sendTelegram("#u$c[username] $c[fullname] #recharge #PPPOE \n" . $p['name_plan'] . Message::sendTelegram("#u$c[username] $c[fullname] #recharge #PPPOE \n" . $p['name_plan'] .
"\nRouter: " . $router_name . "\nRouter: " . $router_name .
"\nGateway: " . $gateway . "\nGateway: " . $gateway .
"\nChannel: " . $channel . "\nChannel: " . $channel .
"\nPrice: " . Lang::moneyFormat($p['price'])); "\nPrice: " . Lang::moneyFormat($p['price']));
} else { } else {
if ($p['is_radius']) { if ($p['is_radius']) {
Radius::customerAddPlan($c, $p, "$date_exp $time"); Radius::customerAddPlan($c, $p, "$date_exp $time");
@ -433,12 +434,12 @@ class Package
} }
$d->save(); $d->save();
// Calculating Price // Calculating Price
$sd = new DateTime("$date_only"); $sd = new DateTime("$date_only");
$ed = new DateTime("$date_exp"); $ed = new DateTime("$date_exp");
$td = $ed->diff($sd); $td = $ed->diff($sd);
$fd = $td->format("%a"); $fd = $td->format("%a");
$gi = ($p['price']/30)*$fd; $gi = ($p['price'] / 30) * $fd;
// insert table transactions // insert table transactions
$t = ORM::for_table('tbl_transactions')->create(); $t = ORM::for_table('tbl_transactions')->create();
@ -446,10 +447,10 @@ class Package
$t->username = $c['username']; $t->username = $c['username'];
$t->plan_name = $p['name_plan']; $t->plan_name = $p['name_plan'];
if ($gi > $p['price']) { if ($gi > $p['price']) {
$t->price = $p['price']; $t->price = $p['price'];
} else { } else {
$t->price = $gi; $t->price = $gi;
} }
$t->recharged_on = $date_only; $t->recharged_on = $date_only;
$t->recharged_time = $time_only; $t->recharged_time = $time_only;
$t->expiration = $date_exp; $t->expiration = $date_exp;
@ -464,31 +465,30 @@ class Package
$t->type = "PPPOE"; $t->type = "PPPOE";
$t->save(); $t->save();
// insert to fields // insert to fields
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); $fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one();
if (!$fl) { if (!$fl) {
$fl = ORM::for_table('tbl_customers_fields')->create(); $fl = ORM::for_table('tbl_customers_fields')->create();
$fl->customer_id = $c['id']; $fl->customer_id = $c['id'];
$fl->field_name = 'Invoice'; $fl->field_name = 'Invoice';
if ($gi > $p['price']) { if ($gi > $p['price']) {
$fl->field_value = $p['price']; $fl->field_value = $p['price'];
} else { } else {
$fl->field_value = $gi; $fl->field_value = $gi;
} }
$fl->save(); $fl->save();
} else { } else {
$fl->customer_id = $c['id']; $fl->customer_id = $c['id'];
$fl->field_value = $p['price']; $fl->field_value = $p['price'];
$fl->save(); $fl->save();
} }
Message::sendTelegram("#u$c[username] $c[fullname] #buy #PPPOE \n" . $p['name_plan'] . Message::sendTelegram("#u$c[username] $c[fullname] #buy #PPPOE \n" . $p['name_plan'] .
"\nRouter: " . $router_name . "\nRouter: " . $router_name .
"\nGateway: " . $gateway . "\nGateway: " . $gateway .
"\nChannel: " . $channel . "\nChannel: " . $channel .
"\nPrice: " . Lang::moneyFormat($p['price'])); "\nPrice: " . Lang::moneyFormat($p['price']));
} }
} }
run_hook("recharge_user_finish"); run_hook("recharge_user_finish");
Message::sendInvoice($c, $t); Message::sendInvoice($c, $t);