İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Models\WeldLog;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class VerifyMechanicalSummaries extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'mechanical:verify-summaries
|
||||
{--columns=nps_1,nps_2,outside_diameter_1,outside_diameter_2 : Comma separated numeric columns to inspect}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Compare SUM values for welded vs mechanical joints across selected columns';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle(): int
|
||||
{
|
||||
$columns = collect(explode(',', $this->option('columns')))
|
||||
->map(fn ($column) => trim($column))
|
||||
->filter()
|
||||
->unique()
|
||||
->values();
|
||||
|
||||
if ($columns->isEmpty()) {
|
||||
$this->error('Please provide at least one column via --columns option.');
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$rows = [];
|
||||
|
||||
foreach ($columns as $column) {
|
||||
if (!Schema::hasColumn('weld_logs', $column)) {
|
||||
$this->warn("Column '{$column}' does not exist on weld_logs table. Skipping.");
|
||||
continue;
|
||||
}
|
||||
|
||||
$weldedSum = apply_welded_filter(WeldLog::query())->sum($column);
|
||||
$mechanicalSum = apply_mechanical_filter(WeldLog::query())->sum($column);
|
||||
$total = $weldedSum + $mechanicalSum;
|
||||
|
||||
$rows[] = [
|
||||
'Column' => $column,
|
||||
'SUM (Welded)' => $weldedSum,
|
||||
'SUM (Mechanical)' => $mechanicalSum,
|
||||
'SUM (Total)' => $total,
|
||||
];
|
||||
}
|
||||
|
||||
if (empty($rows)) {
|
||||
$this->warn('No valid columns were processed.');
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$this->table(
|
||||
['Column', 'SUM (Welded)', 'SUM (Mechanical)', 'SUM (Total)'],
|
||||
$rows
|
||||
);
|
||||
|
||||
$this->info('Verification completed. Ensure mechanical sums are zero to confirm filtering.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user