542 lines
26 KiB
PHP
542 lines
26 KiB
PHP
<?php
|
||
// Check if this is a bulk rollback (array of IDs) or single rollback
|
||
$rollbackIds = request()->input('rollback_ids', []);
|
||
$singleId = get("rollback");
|
||
|
||
// If rollback_ids is provided (bulk operation), use it; otherwise use single ID
|
||
$isBulkOperation = !empty($rollbackIds) && is_array($rollbackIds);
|
||
|
||
if($isBulkOperation) {
|
||
// BULK ROLLBACK OPERATION
|
||
$totalProcessed = 0;
|
||
$totalAffectedRows = 0;
|
||
$constructionUpdatedCount = 0;
|
||
$paintFollowUpUpdatedCount = 0;
|
||
$statusChanges = [];
|
||
$processedSpools = [];
|
||
|
||
foreach($rollbackIds as $rollbackId) {
|
||
// Get the initial data to get iso_number and spool_number
|
||
$initialData = db("weld_logs")->where("id", $rollbackId)->first();
|
||
|
||
if(!$initialData) {
|
||
continue; // Skip if record not found
|
||
}
|
||
|
||
// Get all records with same iso_number and spool_number
|
||
$allRecords = db("weld_logs")
|
||
->where("iso_number", $initialData->iso_number)
|
||
->where("spool_number", $initialData->spool_number)
|
||
->get();
|
||
|
||
// Process each record individually
|
||
foreach($allRecords as $data) {
|
||
$prevStatus = $data->spool_status;
|
||
$updateData = null;
|
||
$nowStatus = null;
|
||
|
||
// Determine rollback status for each individual record
|
||
if($data->spool_status == "Completed") {
|
||
if($data->paint_release_no != "") {
|
||
$nowStatus = "Paint";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"paint_release_date" => null,
|
||
"paint_release_no" => null,
|
||
"spool_paint_check" => null,
|
||
"register_date" => null,
|
||
"register_paint_no" => null,
|
||
];
|
||
} else {
|
||
$nowStatus = "NDT Release";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"ndt_release_date" => null,
|
||
"ndt_release_no" => null,
|
||
"ndt_release_check" => null,
|
||
];
|
||
}
|
||
} elseif($data->spool_status == "Paint") {
|
||
$nowStatus = "NDT Release";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"ndt_release_date" => null,
|
||
"ndt_release_no" => null,
|
||
"ndt_release_check" => null,
|
||
];
|
||
} elseif($data->spool_status == "NDT Release") {
|
||
$nowStatus = "Spool Release";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"spool_ndt_check" => null,
|
||
"spool_paint_check" => null,
|
||
"spool_ndt_check_no" => null,
|
||
"spool_ndt_check_date" => null,
|
||
];
|
||
} elseif($data->spool_status == "Spool Release") {
|
||
if(!rejected_date($data->welding_date)) {
|
||
$nowStatus = "Spool Release";
|
||
} else {
|
||
$nowStatus = "On Going";
|
||
}
|
||
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"spool_ndt_check" => null,
|
||
"spool_paint_check" => null,
|
||
"spool_ndt_check_no" => null,
|
||
"ndt_release_check" => null,
|
||
"clearance_date" => null,
|
||
"clearance_no" => null
|
||
];
|
||
} elseif($data->spool_status == "QC") {
|
||
$nowStatus = "Spool Release";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"spool_ndt_check" => null,
|
||
"spool_paint_check" => null,
|
||
"spool_ndt_check_no" => null,
|
||
"ndt_release_check" => null,
|
||
"clearance_date" => null,
|
||
"clearance_no" => null
|
||
];
|
||
}
|
||
|
||
// Apply update for this specific record
|
||
if($updateData) {
|
||
$affectedRows = db("weld_logs")
|
||
->where("id", $data->id)
|
||
->update($updateData);
|
||
|
||
$totalAffectedRows += $affectedRows;
|
||
|
||
// Track status changes for reporting
|
||
if(!isset($statusChanges[$prevStatus])) {
|
||
$statusChanges[$prevStatus] = $nowStatus;
|
||
}
|
||
|
||
// Handle construction paint logs deletion for each record
|
||
if($data->spool_status == "Completed" || $data->spool_status == "Paint") {
|
||
// Construction paint logs'daki date sütunlarını null yap
|
||
$constructionUpdatedCount += db("construction_paint_logs")
|
||
->where("iso_drawings", $data->iso_number)
|
||
->where("spool", $data->spool_number)
|
||
->where("painting_system_type_1", $data->painting_cycle)
|
||
->update([
|
||
'dn_1' => null,
|
||
'dn_2' => null,
|
||
'dn_3' => null,
|
||
'line_pipe_mm_1' => null,
|
||
'line_pipe_mm_2' => null,
|
||
'cutting_mm' => null,
|
||
'total_line_mm' => null,
|
||
'elbow_pcs' => null,
|
||
'elbow_45_pcs' => null,
|
||
'elbow_m2' => null,
|
||
'tee_pcs' => null,
|
||
'tee_m2' => null,
|
||
'reductions_pcs' => null,
|
||
'reductions_m2' => null,
|
||
'vent_pcs' => null,
|
||
'vent_m2' => null,
|
||
'cap_pcs' => null,
|
||
'cap_m2' => null,
|
||
'flange_pcs' => null,
|
||
'flange_m2' => null,
|
||
'fittings_m2' => null,
|
||
'pipe_m2' => null,
|
||
'total_m2' => null,
|
||
'first_layer' => null,
|
||
'second_layer' => null,
|
||
'third_layer' => null,
|
||
'total_layer' => null,
|
||
'construction_report_no' => null,
|
||
'blasting_date' => null,
|
||
'blasting_finish_date' => null,
|
||
'blasting_rfi_no' => null,
|
||
'painting_date_1' => null,
|
||
'painting_finish_date_1' => null,
|
||
'rfi_date_1' => null,
|
||
'rfi_no_1' => null,
|
||
'painting_date_2' => null,
|
||
'painting_finish_date_2' => null,
|
||
'rfi_date_2' => null,
|
||
'rfi_no_2' => null,
|
||
'painting_date_3' => null,
|
||
'painting_finish_date_3' => null,
|
||
'rfi_date_3' => null,
|
||
'rfi_no_3' => null
|
||
]);
|
||
}
|
||
|
||
$whereData = [
|
||
'iso_number' => $data->iso_number,
|
||
'spool_no_joint_no' => $data->spool_number,
|
||
'cycle' => $data->painting_cycle
|
||
];
|
||
|
||
// Paint follow ups'daki date sütunlarını null yap
|
||
$paintFollowUpUpdatedCount += db("paint_follow_ups")
|
||
->where($whereData)
|
||
->update([
|
||
'incoming_control_akt_no_1' => null,
|
||
'incoming_control_rfi_no_1' => null,
|
||
'akt_date_1' => null,
|
||
'standartgost_iso_en_1' => null,
|
||
'certificate_passport_no_1' => null,
|
||
'certificate_passport_date_1' => null,
|
||
'incoming_control_akt_no_2' => null,
|
||
'incoming_control_rfi_no_2' => null,
|
||
'akt_date_2' => null,
|
||
'standartgost_iso_en_2' => null,
|
||
'certificate_passport_no_2' => null,
|
||
'certificate_passport_date_2' => null,
|
||
'incoming_control_akt_no_3' => null,
|
||
'incoming_control_rfi_no_3' => null,
|
||
'akt_date_3' => null,
|
||
'standartgost_iso_en_3' => null,
|
||
'certificate_passport_no_3' => null,
|
||
'certificate_passport_date_3' => null,
|
||
'surface_preparation_equipment' => null,
|
||
'surface_roughness' => null,
|
||
'standartgost_iso_en_cleaning' => null,
|
||
'protocol_no_cleaning' => null,
|
||
'protocol_date_cleaning' => null,
|
||
'surface_preparation_rfi_no' => null,
|
||
'substrate_temprature' => null,
|
||
'ambient_temprature' => null,
|
||
'primer_measured_thickness_1' => null,
|
||
'primer_coating_protocol_no' => null,
|
||
'primer_coating_protocol_date' => null,
|
||
'primer_coating_start_date' => null,
|
||
'primer_coating_finish_date' => null,
|
||
'primer_coating_rfi_no' => null,
|
||
'primer_coating_rfi_date_1' => null,
|
||
'volume_1' => null,
|
||
'intermediate_measured_thickness_2' => null,
|
||
'intermediate_coating_protocol_no_2' => null,
|
||
'intermediate_coating_protocol_date2' => null,
|
||
'start_intermediate_date2' => null,
|
||
'finish_intermediate_date2' => null,
|
||
'intermediate_coating_rfi_no2' => null,
|
||
'intermediate_coating_rfi_date_3' => null,
|
||
'volume_2' => null,
|
||
'final_coating_measured_thickness_3' => null,
|
||
'final_coating_protocol_no_3' => null,
|
||
'final_coatingprotocol_date_3' => null,
|
||
'final_coat_start_date3' => null,
|
||
'final_coat_finish_date3' => null,
|
||
'final_coating_rfi_no3' => null,
|
||
'final_coating_rfi_date_3' => null,
|
||
'volume_3' => null,
|
||
'total_volume' => null,
|
||
'total_thickness' => null,
|
||
'brend_name' => null,
|
||
'passport_no' => null,
|
||
'passport_date' => null
|
||
]);
|
||
}
|
||
}
|
||
|
||
// Track processed spools
|
||
$processedSpools[] = $initialData->iso_number . ' - ' . $initialData->spool_number;
|
||
$totalProcessed++;
|
||
|
||
// Run spool status changer for each processed spool
|
||
include(resource_path('views/cron/spool-status-changer.blade.php'));
|
||
}
|
||
|
||
// Generate status change summary
|
||
$statusChangeText = "";
|
||
foreach($statusChanges as $prevStatus => $nowStatus) {
|
||
$statusChangeText .= $prevStatus . " ⏩ " . $nowStatus . "<br>";
|
||
}
|
||
|
||
if($totalAffectedRows > 0) {
|
||
// Dispatch cache blade views
|
||
dispatchCacheBladeViews();
|
||
|
||
$spoolList = implode('<br>', $processedSpools);
|
||
|
||
echo __("Bulk Rollback Successful! <br><br>
|
||
<b>Processed Spools (:processed_count):</b><br>
|
||
:spool_list
|
||
<br><br><b>Status Changes:</b><br>:status_changes
|
||
<br><small>(:count weld log rows affected)</small>
|
||
<br><small>Construction data updated: :construction_count rows</small>
|
||
<br><small>Paint follow up data updated: :paint_followup_count rows</small>",
|
||
[
|
||
'processed_count' => $totalProcessed,
|
||
'spool_list' => $spoolList,
|
||
'status_changes' => $statusChangeText,
|
||
'count' => $totalAffectedRows,
|
||
'construction_count' => $constructionUpdatedCount,
|
||
'paint_followup_count' => $paintFollowUpUpdatedCount
|
||
]);
|
||
} else {
|
||
echo __("No records were updated. Please check your selection.");
|
||
}
|
||
|
||
} else {
|
||
// SINGLE ROLLBACK OPERATION (Original Code)
|
||
// Get the initial data to get iso_number and spool_number
|
||
$initialData = db("weld_logs")->where("id", $singleId)->first();
|
||
|
||
// Get all records with same iso_number and spool_number
|
||
$allRecords = db("weld_logs")
|
||
->where("iso_number", $initialData->iso_number)
|
||
->where("spool_number", $initialData->spool_number)
|
||
->get();
|
||
|
||
$totalAffectedRows = 0;
|
||
$constructionUpdatedCount = 0;
|
||
$paintFollowUpUpdatedCount = 0;
|
||
$statusChanges = [];
|
||
|
||
// Process each record individually
|
||
foreach($allRecords as $data) {
|
||
$prevStatus = $data->spool_status;
|
||
$updateData = null;
|
||
$nowStatus = null;
|
||
|
||
// Determine rollback status for each individual record
|
||
if($data->spool_status == "Completed") {
|
||
if($data->paint_release_no != "") {
|
||
$nowStatus = "Paint";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"paint_release_date" => null,
|
||
"paint_release_no" => null,
|
||
"spool_paint_check" => null,
|
||
"register_date" => null,
|
||
"register_paint_no" => null,
|
||
];
|
||
} else {
|
||
$nowStatus = "NDT Release";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"ndt_release_date" => null,
|
||
"ndt_release_no" => null,
|
||
"ndt_release_check" => null,
|
||
];
|
||
}
|
||
} elseif($data->spool_status == "Paint") {
|
||
$nowStatus = "NDT Release";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"ndt_release_date" => null,
|
||
"ndt_release_no" => null,
|
||
"ndt_release_check" => null,
|
||
];
|
||
} elseif($data->spool_status == "NDT Release") {
|
||
$nowStatus = "Spool Release";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"spool_ndt_check" => null,
|
||
"spool_paint_check" => null,
|
||
"spool_ndt_check_no" => null,
|
||
"spool_ndt_check_date" => null,
|
||
];
|
||
} elseif($data->spool_status == "Spool Release") {
|
||
if(!rejected_date($data->welding_date)) {
|
||
$nowStatus = "Spool Release";
|
||
} else {
|
||
$nowStatus = "On Going";
|
||
}
|
||
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"spool_ndt_check" => null,
|
||
"spool_paint_check" => null,
|
||
"spool_ndt_check_no" => null,
|
||
"ndt_release_check" => null,
|
||
"clearance_date" => null,
|
||
"clearance_no" => null
|
||
];
|
||
} elseif($data->spool_status == "QC") {
|
||
$nowStatus = "Spool Release";
|
||
$updateData = [
|
||
"spool_status" => $nowStatus,
|
||
"spool_ndt_check" => null,
|
||
"spool_paint_check" => null,
|
||
"spool_ndt_check_no" => null,
|
||
"ndt_release_check" => null,
|
||
"clearance_date" => null,
|
||
"clearance_no" => null
|
||
];
|
||
}
|
||
|
||
// Apply update for this specific record
|
||
if($updateData) {
|
||
$affectedRows = db("weld_logs")
|
||
->where("id", $data->id)
|
||
->update($updateData);
|
||
|
||
$totalAffectedRows += $affectedRows;
|
||
|
||
// Track status changes for reporting
|
||
if(!isset($statusChanges[$prevStatus])) {
|
||
$statusChanges[$prevStatus] = $nowStatus;
|
||
}
|
||
|
||
// Handle construction paint logs deletion for each record
|
||
if($data->spool_status == "Completed" || $data->spool_status == "Paint") {
|
||
|
||
// Construction paint logs'daki date sütunlarını null yap (blasting_date boş olanları)
|
||
$constructionUpdatedCount += db("construction_paint_logs")
|
||
->where("iso_drawings", $data->iso_number)
|
||
->where("spool", $data->spool_number)
|
||
->where("painting_system_type_1", $data->painting_cycle)
|
||
->update([
|
||
// All construction paint log fields are set to null for rollback operation
|
||
'dn_1' => null,
|
||
'dn_2' => null,
|
||
'dn_3' => null,
|
||
'line_pipe_mm_1' => null,
|
||
'line_pipe_mm_2' => null,
|
||
'cutting_mm' => null,
|
||
'total_line_mm' => null,
|
||
'elbow_pcs' => null,
|
||
'elbow_45_pcs' => null,
|
||
'elbow_m2' => null,
|
||
'tee_pcs' => null,
|
||
'tee_m2' => null,
|
||
'reductions_pcs' => null,
|
||
'reductions_m2' => null,
|
||
'vent_pcs' => null,
|
||
'vent_m2' => null,
|
||
'cap_pcs' => null,
|
||
'cap_m2' => null,
|
||
'flange_pcs' => null,
|
||
'flange_m2' => null,
|
||
'fittings_m2' => null,
|
||
'pipe_m2' => null,
|
||
'total_m2' => null,
|
||
'first_layer' => null,
|
||
'second_layer' => null,
|
||
'third_layer' => null,
|
||
'total_layer' => null,
|
||
'construction_report_no' => null,
|
||
'blasting_date' => null,
|
||
'blasting_finish_date' => null,
|
||
'blasting_rfi_no' => null,
|
||
'painting_date_1' => null,
|
||
'painting_finish_date_1' => null,
|
||
'rfi_date_1' => null,
|
||
'rfi_no_1' => null,
|
||
'painting_date_2' => null,
|
||
'painting_finish_date_2' => null,
|
||
'rfi_date_2' => null,
|
||
'rfi_no_2' => null,
|
||
'painting_date_3' => null,
|
||
'painting_finish_date_3' => null,
|
||
'rfi_date_3' => null,
|
||
'rfi_no_3' => null
|
||
]);
|
||
}
|
||
$whereData = [
|
||
'iso_number' => $data->iso_number,
|
||
'spool_no_joint_no' => $data->spool_number,
|
||
'cycle' => $data->painting_cycle
|
||
];
|
||
// Paint follow ups'daki date sütunlarını null yap
|
||
$paintFollowUpUpdatedCount += db("paint_follow_ups")
|
||
->where($whereData)
|
||
->update([
|
||
// All paint follow up date and related fields are set to null for rollback operation
|
||
'incoming_control_akt_no_1' => null,
|
||
'incoming_control_rfi_no_1' => null,
|
||
'akt_date_1' => null,
|
||
'standartgost_iso_en_1' => null,
|
||
'certificate_passport_no_1' => null,
|
||
'certificate_passport_date_1' => null,
|
||
'incoming_control_akt_no_2' => null,
|
||
'incoming_control_rfi_no_2' => null,
|
||
'akt_date_2' => null,
|
||
'standartgost_iso_en_2' => null,
|
||
'certificate_passport_no_2' => null,
|
||
'certificate_passport_date_2' => null,
|
||
'incoming_control_akt_no_3' => null,
|
||
'incoming_control_rfi_no_3' => null,
|
||
'akt_date_3' => null,
|
||
'standartgost_iso_en_3' => null,
|
||
'certificate_passport_no_3' => null,
|
||
'certificate_passport_date_3' => null,
|
||
'surface_preparation_equipment' => null,
|
||
'surface_roughness' => null,
|
||
'standartgost_iso_en_cleaning' => null,
|
||
'protocol_no_cleaning' => null,
|
||
'protocol_date_cleaning' => null,
|
||
'surface_preparation_rfi_no' => null,
|
||
'substrate_temprature' => null,
|
||
'ambient_temprature' => null,
|
||
'primer_measured_thickness_1' => null,
|
||
'primer_coating_protocol_no' => null,
|
||
'primer_coating_protocol_date' => null,
|
||
'primer_coating_start_date' => null,
|
||
'primer_coating_finish_date' => null,
|
||
'primer_coating_rfi_no' => null,
|
||
'primer_coating_rfi_date_1' => null,
|
||
'volume_1' => null,
|
||
'intermediate_measured_thickness_2' => null,
|
||
'intermediate_coating_protocol_no_2' => null,
|
||
'intermediate_coating_protocol_date2' => null,
|
||
'start_intermediate_date2' => null,
|
||
'finish_intermediate_date2' => null,
|
||
'intermediate_coating_rfi_no2' => null,
|
||
'intermediate_coating_rfi_date_3' => null,
|
||
'volume_2' => null,
|
||
'final_coating_measured_thickness_3' => null,
|
||
'final_coating_protocol_no_3' => null,
|
||
'final_coatingprotocol_date_3' => null,
|
||
'final_coat_start_date3' => null,
|
||
'final_coat_finish_date3' => null,
|
||
'final_coating_rfi_no3' => null,
|
||
'final_coating_rfi_date_3' => null,
|
||
'volume_3' => null,
|
||
'total_volume' => null,
|
||
'total_thickness' => null,
|
||
'brend_name' => null,
|
||
'passport_no' => null,
|
||
'passport_date' => null
|
||
]);
|
||
}
|
||
}
|
||
|
||
// Generate status change summary
|
||
$statusChangeText = "";
|
||
foreach($statusChanges as $prevStatus => $nowStatus) {
|
||
$statusChangeText .= $prevStatus . " ⏩ " . $nowStatus . "<br>";
|
||
}
|
||
|
||
if($totalAffectedRows > 0) {
|
||
// Dispatch cache blade views
|
||
dispatchCacheBladeViews();
|
||
|
||
echo __("Rollback is successful <br>
|
||
<b>
|
||
:iso_number
|
||
:spool_number
|
||
</b>
|
||
<br>Status Changes:<br>:status_changes
|
||
<small>(:count rows affected)</small>
|
||
<br><small>Construction data updated: :construction_count rows</small>
|
||
<br><small>Paint follow up data updated: :paint_followup_count rows</small>",
|
||
[
|
||
'status_changes' => $statusChangeText,
|
||
'count' => $totalAffectedRows,
|
||
'construction_count' => $constructionUpdatedCount,
|
||
'paint_followup_count' => $paintFollowUpUpdatedCount,
|
||
'iso_number' => $initialData->iso_number,
|
||
'spool_number' => $initialData->spool_number
|
||
]);
|
||
} else {
|
||
echo __("You cannot revert this data because no changes were made." );
|
||
}
|
||
}
|
||
?>
|
||
|
||
@if(!$isBulkOperation && isset($initialData))
|
||
@include("cron.spool-status-changer", ['iso_number' => $initialData->iso_number, 'spool_number' => $initialData->spool_number])
|
||
@endif
|