mHelper = new MoonCalc; } /** * Execute the job. * * @return void */ public function handle() { //Get the characters for each non-invoiced ledger entry $chars = Ledger::distinct('character_id')->pluck('character_id'); //Foreach character tally up the mining ledger totals to create an invoice foreach($chars as $char) { //Declare some variables we need for each loop $invoice = array(); $ores = array(); $totalPrice = 0.00; //Get the rows from the database for each character and the requirement of not been //invoiced yet $rows = Ledger::where([ 'character_id' => $char->character_id, 'invoiced' => 'No', ]); //Taly up the item composition from each row and multiply by the quantity foreach($rows as $row) { $ores[$row->type_id] = $ores[$row->type_id] + $row->quantity; } //From the item composition for each of the totaled ores, let's get the components and find the price foreach($ores as $itemId => $quantity) { //Get the price from the helper function for each unit of ore $price = $this->mHelper->CalculateOrePrice($itemId); //Add up the total and keep a running total $totalPrice += $price * $quantity; } //Reduce the total price by the take percentage $totalPrice = $totalPrice * 0.20; //Create the invoice job CreateMiningTaxesInvoiceJob::dispatch($ores, $totalPrice, $char->character_id); } } }