SetStartStatus(); //Setup helper classes $hFinances = new FinanceHelper(); $start = Carbon::now()->startOfMonth()->subMonth(); $end = Carbon::now()->endOfMOnth()->subMonth(); $end->hour = 23; $end->minute = 59; $end->second = 59; //Get the set of corporations from the structure table $corps = CorpStructure::where(['structure_type' => 'Citadel'])->distinct('corporation_id'); foreach($corps as $corp) { //Get the number of citadel counts to use in fuel block calculation $citadelCount = CorpStructure::where(['corporation_id' => $corp->corporation_id, 'structure_type' => 'Citadel'])->count(); //From the corp journal add up the taxes from the last month $marketTaxes = CorpJournal::where(['ref_type' => 'brokers_fee', 'corporation_id' => $corp->corporation_id]) ->whereBetween('date', [$start, $end]) ->sum('amount'); //Calculate the market fuel cost $marketFuel = $hFinances->CalculateFuelBlockCost('market'); //Calculate the market tax $mTax = CorpStructure::where(['corporation_id' => $corp->corporation_id, 'structure_type' => 'Citadel'])->avg('tax'); //Subtract the fuel cost from the market taxes $tempTaxes = $marketTaxes - ($marketFuel * $citadelCount); //Calculate the final tax in order to store in the database $finalTaxes = $hFinancees->CalculateTax($tempTaxes, $mTax, 'market'); //Check for a negative number and zero out if negative if($finalTaxes < 0.00) { $finalTaxes = 0.00; } else { $finalTaxes = number_format($finalTaxes, 2, '.', ','); } //Get the info about the structures from the database $info = CorpStructure::where(['corporation_id' => $corp->corporation_id])->first(); //Store the value in the database $bill = new MonthlyMarketTax; $bill->character_id = $info->character_id; $bill->character_name = $info->character_name; $bill->corporation_id = $corp->corporation_id; $bill->corporation_name = $info->corporation_name; $bill->taxed_owed = $finalTaxes; $bill->month = $start->monthName; $bill->year = $start->year; $bill->save(); } //Mark the job as finished $task->SetStopStatus(); } }