Check if Period Validity

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

View File

@ -206,18 +206,20 @@ class Package
} }
$t->save(); $t->save();
// insert to fields if ($p['validity_unit'] == 'Period') {
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); // insert to fields
if (!$fl) { $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')->create(); if (!$fl) {
$fl->customer_id = $c['id']; $fl = ORM::for_table('tbl_customers_fields')->create();
$fl->field_name = 'Invoice'; $fl->customer_id = $c['id'];
$fl->field_value = $p['price']; $fl->field_name = 'Invoice';
$fl->save(); $fl->field_value = $p['price'];
} else { $fl->save();
$fl->customer_id = $c['id']; } else {
$fl->field_value = $p['price']; $fl->customer_id = $c['id'];
$fl->save(); $fl->field_value = $p['price'];
$fl->save();
}
} }
@ -256,22 +258,25 @@ class Package
} }
$d->save(); $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;
// 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 ($p['validity_unit'] == 'Period') {
$t->price = $p['price']; // 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'];
} else {
$t->price = $gi;
}
} else { } else {
$t->price = $gi; $t->price = $p['price'];
} }
$t->recharged_on = $date_only; $t->recharged_on = $date_only;
$t->recharged_time = $time_only; $t->recharged_time = $time_only;
@ -287,22 +292,24 @@ class Package
} }
$t->save(); $t->save();
// insert to fields if ($p['validity_unit'] == 'Period') {
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); // insert to fields
if (!$fl) { $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')->create(); if (!$fl) {
$fl->customer_id = $c['id']; $fl = ORM::for_table('tbl_customers_fields')->create();
$fl->field_name = 'Invoice'; $fl->customer_id = $c['id'];
if ($gi > $p['price']) { $fl->field_name = 'Invoice';
$fl->field_value = $p['price']; if ($gi > $p['price']) {
$fl->field_value = $p['price'];
} else {
$fl->field_value = $gi;
}
$fl->save();
} else { } else {
$fl->field_value = $gi; $fl->customer_id = $c['id'];
$fl->field_value = $p['price'];
$fl->save();
} }
$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'] . Message::sendTelegram("#u$c[username] $c[fullname] #buy #Hotspot \n" . $p['name_plan'] .
@ -384,19 +391,20 @@ class Package
} }
$t->save(); $t->save();
// insert to fields if ($p['validity_unit'] == 'Period') {
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); // insert to fields
$gp = $gi; $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 #PPPOE \n" . $p['name_plan'] . Message::sendTelegram("#u$c[username] $c[fullname] #recharge #PPPOE \n" . $p['name_plan'] .
@ -434,22 +442,25 @@ class Package
} }
$d->save(); $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;
// 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 ($p['validity_unit'] == 'Period') {
$t->price = $p['price']; // 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'];
} else {
$t->price = $gi;
}
} else { } else {
$t->price = $gi; $t->price = $p['price'];
} }
$t->recharged_on = $date_only; $t->recharged_on = $date_only;
$t->recharged_time = $time_only; $t->recharged_time = $time_only;
@ -465,22 +476,24 @@ class Package
$t->type = "PPPOE"; $t->type = "PPPOE";
$t->save(); $t->save();
// insert to fields if ($p['validity_unit'] == 'Period') {
$fl = ORM::for_table('tbl_customers_fields')->where('field_name', 'Invoice')->where('customer_id', $c['id'])->find_one(); // insert to fields
if (!$fl) { $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')->create(); if (!$fl) {
$fl->customer_id = $c['id']; $fl = ORM::for_table('tbl_customers_fields')->create();
$fl->field_name = 'Invoice'; $fl->customer_id = $c['id'];
if ($gi > $p['price']) { $fl->field_name = 'Invoice';
$fl->field_value = $p['price']; if ($gi > $p['price']) {
$fl->field_value = $p['price'];
} else {
$fl->field_value = $gi;
}
$fl->save();
} else { } else {
$fl->field_value = $gi; $fl->customer_id = $c['id'];
$fl->field_value = $p['price'];
$fl->save();
} }
$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'] . Message::sendTelegram("#u$c[username] $c[fullname] #buy #PPPOE \n" . $p['name_plan'] .