diff --git a/app/Http/Controllers/Test/TestController.php b/app/Http/Controllers/Test/TestController.php
index fc16afefc..ac0ab2e2b 100644
--- a/app/Http/Controllers/Test/TestController.php
+++ b/app/Http/Controllers/Test/TestController.php
@@ -142,10 +142,7 @@ class TestController extends Controller
* Send the collected information over to the function to send the actual mail
*/
if($ledgers->count() > 0) {
- $invoiceAmount = round(((float)$ledgers->sum('amount') * (float)$config['mining_tax']), 2);
- var_dump($ledgers);
- var_dump($invoiceAmount);
- var_dump(number_format($invoiceAmount, 2, ".", ","));
+
}
}
@@ -153,6 +150,111 @@ class TestController extends Controller
return view('test.miningtax.invoice')->with('perms', $perms);
}
+ /**
+ * Create the invoice to the mail out
+ *
+ * @var charId
+ * @var ledgers
+ * @var mailDelay
+ */
+ private function CreateInvoice($charId, Collection $ledgers, int &$mailDelay) {
+ $ores = array();
+ $characters = array();
+ $characterIds = array();
+ $totalPrice = 0.00;
+ $body = null;
+ $lookup = new LookupHelper;
+ $config = config('esi');
+
+ //Create an invoice id
+ $invoiceId = "M" . uniqid();
+
+ //Collect the total price of all of the ledgers
+ $totalPrice = round((float)$ledgers->sum('amount'), 2);
+
+ //Get the sum of all the ledgers
+ $invoiceAmount = round(($totalPrice * (float)$config['minig_tax']), 2);
+
+ //Get the character name from the lookup table
+ $charName = $lookup->CharacterIdToName($charId);
+
+ //Create the date due and the invoice date
+ $dateDue = Carbon::now()->addDays(7);
+ $invoiceDate = Carbon::now();
+
+ //Set the mining tax from the config file
+ $numberMiningTax = number_format(((float)$config['mining_tax'] * (float)100.00), 2, ".", ",");
+
+ //Create the list of ores to put in the mail
+ $temp = $ledgers->toArray();
+ foreach($temp as $t) {
+ //If the key isn't set, set it to the default of 0
+ if(!isset($ores[$t['type_id']])) {
+ $ores[$t['type_id']] = (int)0;
+ }
+
+ //Add the quantity into the ores array
+ $ores[$t['type_id']] += (int)$t['quantity'];
+
+ //Create a list of character names
+ if(!isset($characters[$t['character_name']])) {
+ $characters[$t['character_name']] = $t['character_name'];
+ }
+
+ //Create a list of character ids
+ if(!isset($characterIds[$t['character_id']])) {
+ $characterIds[$t['character_id']] = $t['character_id'];
+ }
+ }
+
+ /**
+ * Create the mail body to send to the main character
+ */
+ $body .= "Dear " . $charName . ",
";
+ $body .= "Mining Taxes are due for the following ores mined from alliance moons:
";
+ foreach($ores as $ore => $quantity) {
+ $oreName = $lookup->ItemIdToName($ore);
+ $body .= $oreName . ": " . number_format($quantity, 0, ".", ",") . "
";
+ }
+ $body .= "Total Value of Ore Mined: " . number_format($totalPrice, 2, ".", ",") . " ISK.";
+ $body .= "
";
+ $body .= "Please remit " . number_format($invoiceAmount, 2, ".", ",") . " ISK to Spatial Forces by " . $dateDue . "
";
+ $body .= "Set the reason for transfer as " . $invoiceId . "
";
+ $body .= "The mining taxes are currently set to " . $numberMiningTax . "%.
";
+ $body .= "
";
+ $body .= "You can also send a contract with the following ores in the contract with the reason set as: " . $invoiceId . "
";
+ foreach($ores as $ore => $quantity) {
+ $oreName = $lookup->ItemIdToName($ore);
+ $body .= $oreName . ": " . number_format(round($quantity * $config['mining_tax']), 0, ".", ",") . "
";
+ }
+ $body .= "
";
+ $body .= "Characters Processed:
";
+ foreach($characters as $character) {
+ $body .= $character . "
";
+ }
+ $body .= "
";
+ $body .= "
Sincerely,
Warped Intentions Leadership
";
+
+ //Check if the mail body is greater than 2000 characters. If greater than 2,000 characters, then
+ if(strlen($body) > 2000) {
+ $body = "Dear " . $charName . "
";
+ $body .= "Total Value of Ore Mined: " . number_format($totalPrice, 2, ".", ",") . " ISK.";
+ $body .= "
";
+ $body .= "Please remit " . number_format($invoiceAmount, 2, ".", ",") . " ISK to Spatial Forces by " . $dateDue . "
";
+ $body .= "Set the reason for transfer as: " . $invoiceId . "
";
+ $body .= "The mining taxes are currently set to " . $numberMiningTax . "%.
";
+ $body .= "
";
+ $body .= "
Sincerely,
Warped Intentions Leadership
";
+ }
+
+ var_dump($body);
+
+ /**
+ * Increment the mail delay for the next cycle
+ */
+ $mailDelay += 20;
+ }
+
public function DebugMiningObservers() {
//Declare variables
$mailDelay = 15;
diff --git a/app/Jobs/Commands/MiningTaxes/SendMiningTaxesInvoices.php b/app/Jobs/Commands/MiningTaxes/SendMiningTaxesInvoices.php
index aaeca1918..917b1b11b 100644
--- a/app/Jobs/Commands/MiningTaxes/SendMiningTaxesInvoices.php
+++ b/app/Jobs/Commands/MiningTaxes/SendMiningTaxesInvoices.php
@@ -187,6 +187,9 @@ class SendMiningTaxesInvoices implements ShouldQueue
//Create an invoice id
$invoiceId = "M" . uniqid();
+ //Collect the total price of all of the ledgers
+ $totalPrice = round((float)$ledgers->sum('amount'), 2);
+
//Get the sum of all the ledgers
$invoiceAmount = round(((float)$ledgers->sum('amount') * (float)$config['mining_tax']), 2);