Check if Period Validity

This commit is contained in:
Ibnu Maksum 2024-03-12 09:06:11 +07:00
parent 61c1d25096
commit 171b938d3a
No known key found for this signature in database
GPG Key ID: 7FC82848810579E5

View File

@ -206,6 +206,7 @@ class Package
} }
$t->save(); $t->save();
if ($p['validity_unit'] == 'Period') {
// 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) {
@ -219,6 +220,7 @@ class Package
$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'] .
@ -256,23 +258,26 @@ class Package
} }
$d->save(); $d->save();
// 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 ($p['validity_unit'] == 'Period') {
// 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
$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']) { if ($gi > $p['price']) {
$t->price = $p['price']; $t->price = $p['price'];
} else { } else {
$t->price = $gi; $t->price = $gi;
} }
} else {
$t->price = $p['price'];
}
$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;
@ -287,6 +292,7 @@ class Package
} }
$t->save(); $t->save();
if ($p['validity_unit'] == 'Period') {
// 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) {
@ -304,6 +310,7 @@ class Package
$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 .
@ -384,9 +391,9 @@ class Package
} }
$t->save(); $t->save();
if ($p['validity_unit'] == 'Period') {
// 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;
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'];
@ -398,6 +405,7 @@ class Package
$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 .
@ -434,23 +442,26 @@ class Package
} }
$d->save(); $d->save();
// 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 ($p['validity_unit'] == 'Period') {
// 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
$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']) { if ($gi > $p['price']) {
$t->price = $p['price']; $t->price = $p['price'];
} else { } else {
$t->price = $gi; $t->price = $gi;
} }
} else {
$t->price = $p['price'];
}
$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;
@ -465,6 +476,7 @@ class Package
$t->type = "PPPOE"; $t->type = "PPPOE";
$t->save(); $t->save();
if ($p['validity_unit'] == 'Period') {
// 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) {
@ -482,6 +494,7 @@ class Package
$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 .