Skip to content

Instantly share code, notes, and snippets.

@jongravois
Created October 23, 2020 11:13
Show Gist options
  • Save jongravois/c0eb1c07bd8310546d1ea3088e680a4f to your computer and use it in GitHub Desktop.
Save jongravois/c0eb1c07bd8310546d1ea3088e680a4f to your computer and use it in GitHub Desktop.
<?php
namespace App\Console\Commands;
use App\Models\AcModel;
use App\Models\Part;
use App\Models\PartMaster;
use App\Models\PartsModeled;
use App\Models\User;
use App\Notifications\OccmImportCompleted;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Storage;
use Rap2hpoutre\FastExcel\FastExcel;
class ProcessOCCM extends Command
{
protected $signature = 'uam:process-occm {id}';
protected $description = 'triggered command to process uploaded OCCM';
public function __construct()
{
parent::__construct();
}
public function handle()
{
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0);
$modelId = $this->argument('id');
$model = AcModel::find($modelId);
$collection = (new FastExcel)
->import(Storage::disk('occms')
->path($model->occm_path));
foreach($collection as $part){
$master = PartMaster::wherePartNumber($part['part_number'])->first();
$newb = Part::updateOrCreate([
'part_number' => $part['part_number'],
'msn' => $part['msn'],
],[
'part_master_id' => ($master ? $master->id : null),
'model_value' => ($master ? $master->model_value : null),
'ipc' => ($part['ipc'] ? $part['ipc'] : ($master ? $master->ipc : null)),
'ata' => ($part['ata'] ? $part['ata'] : ($master ? $master->ata : null)),
'cage' => ($part['cage'] ? $part['cage'] : ($master ? $master->cage : null)),
'cat' => ($part['cat'] ? $part['cat'] : ($master ? $master->cat : null)),
'eu' => ($master ? $master->eu : null),
'variance' => ($master ? $master->variance : false),
'is_priority' => false,
'is_esd' => false,
'is_hazmat' => false,
'qty_per_ac' => ($master ? $master->qty_per_ac : null),
'can_8130' => ($master ? $master->can_8130 : false),
'should_repair' => ($master ? $master->should_repair : false),
'should_overhaul' => ($master ? $master->should_overhaul : false),
'should_recertify' => ($master ? $master->should_recertify : false),
'was_removed' => false,
'top_performer' => false,
'description' => ($master ? $master->description : null),
]);
PartsModeled::updateOrCreate([
'ac_model_id' => $modelId,
'part_id' => $newb->id,
'lot_code' => $model->title,
], [
'break_from_master' => false,
]);
$this->info("{$part['part_number']} created");
} // end foreach
$this->info('All processed. Sending notification');
$modeler = User::find($model->user_id);
$modeler->notify(new OccmImportCompleted($model));
$model->updateModelValues();
$model->was_uploaded = true;
$model->status = 'active';
$model->save();
return 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment