created relationships for public contract jobs and models
This commit is contained in:
67
app/Jobs/Commands/PublicContracts/PurgePublicContracts.php
Normal file
67
app/Jobs/Commands/PublicContracts/PurgePublicContracts.php
Normal 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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -35,4 +35,8 @@ class PublicContract extends Model
|
|||||||
'type',
|
'type',
|
||||||
'volume',
|
'volume',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function items() {
|
||||||
|
return $this->hasMany('App\Models\PublicContracts\PublicContractItem', 'contract_id', 'contract_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ class PublicContractItem extends Model
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
|
'contract_id',
|
||||||
'is_blueprint_copy',
|
'is_blueprint_copy',
|
||||||
'is_included',
|
'is_included',
|
||||||
'item_id',
|
'item_id',
|
||||||
@@ -28,4 +29,8 @@ class PublicContractItem extends Model
|
|||||||
'time_efficiency',
|
'time_efficiency',
|
||||||
'type_id',
|
'type_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
public function contract() {
|
||||||
|
return $this->hasOne('App\Models\PublicContracts\PublicContract', 'contract_id', 'contract_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class CreateBuyPublicContractsTable extends Migration
|
|||||||
if(!Schema::hasTable('public_contract_items')) {
|
if(!Schema::hasTable('public_contract_items')) {
|
||||||
Schema::create('public_contract_items', function (Blueprint $table) {
|
Schema::create('public_contract_items', function (Blueprint $table) {
|
||||||
$table->unsignedBigIncrements('id');
|
$table->unsignedBigIncrements('id');
|
||||||
|
$table->unsignedBigInteger('contract_id');
|
||||||
$table->boolean('is_blueprint_copy')->nullable();
|
$table->boolean('is_blueprint_copy')->nullable();
|
||||||
$table->boolean('is_included');
|
$table->boolean('is_included');
|
||||||
$table->unsignedBigInteger('item_id')->nullable();
|
$table->unsignedBigInteger('item_id')->nullable();
|
||||||
|
|||||||
Reference in New Issue
Block a user