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