send mining taxes invoice

This commit is contained in:
2021-05-12 09:51:43 +09:00
parent 44e969d24b
commit d447f6f34d

View File

@@ -61,6 +61,7 @@ class SendMiningTaxesInvoices implements ShouldQueue
//Gather up all of the ledgers from the character and its alts. //Gather up all of the ledgers from the character and its alts.
$ledgers = $this->LedgersWithAlts($char->character_id); $ledgers = $this->LedgersWithAlts($char->character_id);
//If the size of the ledgers array is greater than 0, then we need to invoice the ledgers
if(sizeof($ledgers) > 0) { if(sizeof($ledgers) > 0) {
//Create an invoice from the ledger rows //Create an invoice from the ledger rows
$this->CreateInvoice($char->character_id, $ledgers, $mailDelay); $this->CreateInvoice($char->character_id, $ledgers, $mailDelay);
@@ -185,7 +186,7 @@ class SendMiningTaxesInvoices implements ShouldQueue
'character_id' => $charId, 'character_id' => $charId,
'invoiced' => 'No', 'invoiced' => 'No',
])->update([ ])->update([
'invoiced' => 'No', 'invoiced' => 'Yes',
'invoice_id' => $invoiceId, 'invoice_id' => $invoiceId,
]); ]);
@@ -201,6 +202,7 @@ class SendMiningTaxesInvoices implements ShouldQueue
$invoice = array(); $invoice = array();
$ores = array(); $ores = array();
$characters = array(); $characters = array();
$characterIds = array();
$totalPrice = 0.00; $totalPrice = 0.00;
$body = null; $body = null;
$lookup = new LookupHelper; $lookup = new LookupHelper;
@@ -208,15 +210,22 @@ class SendMiningTaxesInvoices implements ShouldQueue
if(sizeof($ledgers) > 0) { if(sizeof($ledgers) > 0) {
foreach($ledgers as $ledger) { foreach($ledgers as $ledger) {
//Create the ores array indexes, then totalize the ores from each ledger entry
if(!isset($ores[$ledger['type_id']])) { if(!isset($ores[$ledger['type_id']])) {
$ores[$ledger['type_id']] = 0; $ores[$ledger['type_id']] = 0;
} }
$ores[$ledger['type_id']] = $ores[$ledger['type_id']] + $ledger['quantity']; $ores[$ledger['type_id']] = $ores[$ledger['type_id']] + $ledger['quantity'];
$totalPrice = $totalPrice + $ledger['amount']; $totalPrice = $totalPrice + $ledger['amount'];
//Create a list of character names for the mail body
if(!isset($characters[$ledger['character_name']])) { if(!isset($characters[$ledger['character_name']])) {
$characters[$ledger['character_name']] = $ledger['character_name']; $characters[$ledger['character_name']] = $ledger['character_name'];
} }
//Create a list of character id's to update invoices before the end of the function
if(!isset($characterIds[$ledger['character_id']])) {
$characterIds[$ledger['character_id']] = $ledger['character_id'];
}
} }
$invoiceAmount = round(($totalPrice * $config['mining_tax']), 2); $invoiceAmount = round(($totalPrice * $config['mining_tax']), 2);
@@ -289,17 +298,19 @@ class SendMiningTaxesInvoices implements ShouldQueue
$invoice->mail_body = $body; $invoice->mail_body = $body;
$invoice->save(); $invoice->save();
foreach($ledgers as $ledger) { //Mark the invoices as paid
foreach($characterIds as $charId) {
Ledger::where([ Ledger::where([
'character_id' => $ledger['character_id'], 'character_id' => $charId,
'invoiced' => 'No', 'invoiced' => 'No',
])->update([ ])->update([
'invoiced' => 'Yes', 'invoiced' => 'Yes',
'invoice_id' => $invoiceId, 'invoice_id' => $invoiceId,
]); ]);
$mailDelay += 20;
} }
//Increase the delay for the next mail
$mailDelay += 20;
} else { } else {
return null; return null;
} }
@@ -323,12 +334,12 @@ class SendMiningTaxesInvoices implements ShouldQueue
'invoiced' => 'No', 'invoiced' => 'No',
])->get(); ])->get();
$mainCount = Ledger::where([ $mainLedgerCount = Ledger::where([
'character_id' => $charId, 'character_id' => $charId,
'invoiced' => 'No', 'invoiced' => 'No',
])->count(); ])->count();
if($mainCount > 0) { if($mainLedgerCount > 0) {
foreach($rows as $row) { foreach($rows as $row) {
array_push($ledgers, [ array_push($ledgers, [
'character_id' => $row->character_id, 'character_id' => $row->character_id,