İlk temizlik tamamlandı bir önceki projeden
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
$id = $request['key'];
|
||||
// Get the line list record before deletion
|
||||
$lineList = $oldData;
|
||||
|
||||
$lineNumber = $lineList->line_no ?? null;
|
||||
$area = $lineList->unit ?? null;
|
||||
|
||||
if ($lineNumber) {
|
||||
// Delete from paint_follow_ups where primer coating has not started
|
||||
$deletedFollowUps = db('paint_follow_ups')
|
||||
->where(
|
||||
[
|
||||
'line' => $lineNumber,
|
||||
'area' => $area,
|
||||
]
|
||||
)
|
||||
->whereNull('primer_coating_start_date')
|
||||
->whereNull('primer_coating_finish_date')
|
||||
->whereNull('start_intermediate_date2')
|
||||
->whereNull('finish_intermediate_date2')
|
||||
->whereNull('final_coat_start_date3')
|
||||
->whereNull('final_coat_finish_date3')
|
||||
->delete();
|
||||
|
||||
// Delete from construction_paint_logs (spool-based, where painting has not started)
|
||||
// Get all spools for this line from weld_logs
|
||||
$spools = db("weld_logs")
|
||||
->where("line_number", $lineNumber)
|
||||
->whereNotNull('spool_number')
|
||||
->where('spool_number', '!=', '')
|
||||
->distinct()
|
||||
->pluck('spool_number');
|
||||
|
||||
$deletedConstructionLogs = 0;
|
||||
|
||||
if ($spools->isNotEmpty()) {
|
||||
// Spool-based deletion
|
||||
$deletedConstructionLogs = db('construction_paint_logs')
|
||||
->where('line', $lineNumber)
|
||||
->whereIn('spool', $spools)
|
||||
->whereNull('blasting_date')
|
||||
->whereNull('blasting_finish_date')
|
||||
->whereNull('painting_date_1')
|
||||
->whereNull('painting_finish_date_1')
|
||||
->whereNull('painting_date_2')
|
||||
->whereNull('painting_finish_date_2')
|
||||
->whereNull('painting_date_3')
|
||||
->whereNull('painting_finish_date_3')
|
||||
->delete();
|
||||
|
||||
Log::debug("Construction Paint Logs deleted (spool-based)", [
|
||||
'line' => $lineNumber,
|
||||
'spool_count' => $spools->count(),
|
||||
'deleted_count' => $deletedConstructionLogs
|
||||
]);
|
||||
} else {
|
||||
// Fallback to unit-based deletion if no spools found
|
||||
$deletedConstructionLogs = db('construction_paint_logs')
|
||||
->where([
|
||||
'line' => $lineNumber,
|
||||
'unit' => $area,
|
||||
])
|
||||
->whereNull('blasting_date')
|
||||
->whereNull('blasting_finish_date')
|
||||
->whereNull('painting_date_1')
|
||||
->whereNull('painting_finish_date_1')
|
||||
->whereNull('painting_date_2')
|
||||
->whereNull('painting_finish_date_2')
|
||||
->whereNull('painting_date_3')
|
||||
->whereNull('painting_finish_date_3')
|
||||
->delete();
|
||||
|
||||
Log::debug("Construction Paint Logs deleted (unit-based fallback)", [
|
||||
'line' => $lineNumber,
|
||||
'unit' => $area,
|
||||
'deleted_count' => $deletedConstructionLogs
|
||||
]);
|
||||
}
|
||||
|
||||
spoolStatusChanger($lineNumber);
|
||||
|
||||
Log::info("Deleted related paint records for line: $lineNumber (Line List ID: $id)", [
|
||||
'deleted_follow_ups' => $deletedFollowUps,
|
||||
'deleted_construction_logs' => $deletedConstructionLogs,
|
||||
'spool_based' => $spools->isNotEmpty()
|
||||
]);
|
||||
} else {
|
||||
Log::error("Line number not found for line list ID: $id");
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user