SetStartStatus(); //Declare variables for the function $lookup = new LookupHelper; $currentTime = Carbon::now(); $config = config('esi'); $esiHelper = new Esi; //Check for the esi scope if(!$esiHelper->HaveEsiScope($config['primary'], 'esi-contracts.read_corporation_contracts.v1')) { Log::critical('Esi scopes were not found for MiningTaxesPayments'); print("Esi scope not found."); return; } //Get the refresh token $refreshToken = $esiHelper->GetRefreshToken($config['primary']); //Get the esi variable $esi = $esiHelper->SetupEsiAuthentication($refreshToken); //Get all of the contracts from esi try { $response = $esi->invoke('get', '/corporations/{corporation_id}/contracts/', [ 'corporation_id' => $config['corporation'], ]); } catch(RequestFailedException $e) { Log::critical("Failed to get contrcts in MiningTaxesPayments command."); Log::critical($e); dd($e); } //Decode the contracts from the json response $contracts = json_decode($response->raw, false); //Get the outstanding invoices $outstanding = Invoice::where([ 'status' => 'Pending', ])->get(); //Use the player donation and the journal in order to check over the pending contracts to attempt //to pay the contract foreach($outstanding as $invoice) { //See if we have a reason with the correct uniqid from the player donation journal $found = AllianceWalletJournal::where([ 'ref_type' => 'player_donation', 'reason' => "MMT: " . $invoice->invoice_id, ])->count(); if($found == 1) { //If the bill is paid on time, then update the invoice as such if($currentTime->lessThanOrEqualTo($invoice->due_date)) { Invoice::where([ 'invoice_id' => $invoice->invoice_id, ])->update([ 'status' => 'Paid', ]); } //If the bill is paid late, then update the invoice as such if($currentTime->greaterThan($invoice->due_date)) { Invoice::where([ 'invoice_id' => $invoice->invoice_id, ])->update([ 'status' => 'Paid Late', ]); } } else { //If we didn't found a journal entry, then we shall check the contracts for a correct entry foreach($contracts as $contract) { if(($contract->title == ("MMT: " . $invoice->invoice_id)) && ($currentTime->lessThanOrEqualTo($invoice->due_date))) { Invoice::where([ 'invoice_id' => $invoice->invoice_id, ])->update([ 'stauts' => 'Paid' ]); } if(($contract->title == ("MMT: " . $invoice->invoice_id)) && ($currentTime->greaterThan($invoice->due_date))) { Invoice::where([ 'invoice_id' => $invoice->invoice_id, ])->update([ 'status' => 'Paid Late', ]); } } } } //Set the task as stopped $task->SetStopStatus(); return 0; } }