created relationships for public contract jobs and models

This commit is contained in:
2020-05-14 22:10:28 -05:00
parent 774d8b866e
commit 2a08fd71a2
4 changed files with 77 additions and 0 deletions

View File

@@ -0,0 +1,67 @@
<?php
namespace App\Jobs\Commands\PublicContracts;
//Internal Library
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Carbon\Carbon;
use Log;
//Library
//Models
use App\Models\PublicContracts\PublicContract;
use App\Models\PublicContracts\PublicContractItem;
/**
* Job to purge some old data from the public contracts
*/
class PurgePublicContracts implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public function __construct()
{
//Nothing to do in this part of the job
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
//Get today's date
$today = Carbon::now();
//If the date for a contract has expired, then purge it from the system
$contracts = PublicContract::all();
//Check each contract to see if it has expired
foreach($contracts as $contract) {
//If the contract has expired, then delete the contract and all of it's items
if($today->greaterThan($contract->date_expired)) {
//Delete the contract
PublicContract::where([
'id' => $contract->id,
])->delete();
//Delete the items from the contract from the other table
PublicContract::where([
'contract_id' => $contract->id,
])->delete();
}
}
}
}

View File

@@ -35,4 +35,8 @@ class PublicContract extends Model
'type',
'volume',
];
public function items() {
return $this->hasMany('App\Models\PublicContracts\PublicContractItem', 'contract_id', 'contract_id');
}
}

View File

@@ -18,6 +18,7 @@ class PublicContractItem extends Model
* @var array
*/
protected $fillable = [
'contract_id',
'is_blueprint_copy',
'is_included',
'item_id',
@@ -28,4 +29,8 @@ class PublicContractItem extends Model
'time_efficiency',
'type_id',
];
public function contract() {
return $this->hasOne('App\Models\PublicContracts\PublicContract', 'contract_id', 'contract_id');
}
}

View File

@@ -44,6 +44,7 @@ class CreateBuyPublicContractsTable extends Migration
if(!Schema::hasTable('public_contract_items')) {
Schema::create('public_contract_items', function (Blueprint $table) {
$table->unsignedBigIncrements('id');
$table->unsignedBigInteger('contract_id');
$table->boolean('is_blueprint_copy')->nullable();
$table->boolean('is_included');
$table->unsignedBigInteger('item_id')->nullable();