27f782f659
refactored mining tax invoice jobs with a job chain and new directory structure added views and forms for mining operations added navbar button for mining operations refactored how admin dashboard controller checks for permissions versus roles
100 lines
2.4 KiB
PHP
100 lines
2.4 KiB
PHP
<?php
|
|
|
|
namespace App\Jobs\Jobs\Commands\MiningTaxes\Invoices;
|
|
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Bus;
|
|
use Carbon\Carbon;
|
|
use Log;
|
|
|
|
//Models
|
|
use App\Models\MiningTax\MiningOperation;
|
|
use App\Models\MiningTax\Ledger;
|
|
|
|
class ProcessAllianceMiningOperations implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
/**
|
|
* Timeout in seconds
|
|
*
|
|
* @var int
|
|
*/
|
|
public $timeout = 3600;
|
|
|
|
/**
|
|
* Number of job retries
|
|
*
|
|
* @var int
|
|
*/
|
|
public $tries = 3;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
//Set job parameters
|
|
$this->connection = 'redis';
|
|
$this->onQueue('miningtaxes');
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
$count = MiningOperation::where([
|
|
'processed' => 'No',
|
|
])->count()
|
|
|
|
if($count > 0) {
|
|
$operations = MiningOperation::where([
|
|
'processed' => 'No',
|
|
])->get();
|
|
|
|
foreach($operations as $operation) {
|
|
$ledgers = Ledger::where([
|
|
'observer_id' => $operation->structure_id,
|
|
'invoiced' => 'No',
|
|
])->get();
|
|
|
|
foreach($ledgers as $ledger) {
|
|
Ledger::where([
|
|
'observer_id' => $operation->structure_id,
|
|
'invoiced' => 'No',
|
|
])->update([
|
|
'invoiced' => 'Yes',
|
|
'invoice_id' => 'Mining Op ',
|
|
]);
|
|
}
|
|
|
|
MiningOperation::where([
|
|
'id' => $operation->id,
|
|
])->update([
|
|
'processed' => 'Yes',
|
|
'processed_on' => Carbon::now(),
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Set the tags for Horzion
|
|
*
|
|
* @var array
|
|
*/
|
|
public function tags() {
|
|
return ['ProcessAllianceMiningOperations', 'MiningTaxes', 'MiningOperations'];
|
|
}
|
|
}
|