ikinci temizlik tamamlandı
This commit is contained in:
@@ -0,0 +1,477 @@
|
||||
<?php
|
||||
|
||||
if (!defined('STAY_ALIVE')) {
|
||||
header('Content-Type: application/json');
|
||||
}
|
||||
|
||||
use Carbon\Carbon;
|
||||
|
||||
if (isset($_POST['paint']) || isset($_REQUEST['paint'])) {
|
||||
$paint_release_number_pattern = setting("paint_release_number_pattern");
|
||||
$checkNo = str_replace("{number}", get_counter($paint_release_number_pattern), $paint_release_number_pattern);
|
||||
|
||||
// Check if ISO+SPL pairs are provided (new format)
|
||||
if (isset($_POST['iso_spool_pairs']) && !empty($_POST['iso_spool_pairs'])) {
|
||||
$pairs = explode(",", $_POST['iso_spool_pairs']);
|
||||
$count = 0;
|
||||
|
||||
foreach ($pairs as $pair) {
|
||||
$pairParts = explode("|", trim($pair));
|
||||
if (count($pairParts) == 2) {
|
||||
$isoNumber = trim($pairParts[0]);
|
||||
$spoolNumber = trim($pairParts[1]);
|
||||
|
||||
if (!empty($isoNumber) && !empty($spoolNumber)) {
|
||||
$result = db("weld_logs")
|
||||
->where("iso_number", $isoNumber)
|
||||
->where("spool_number", $spoolNumber)
|
||||
->whereNotIn("spool_status", ['Completed'])
|
||||
->whereIn("spool_status", ['Paint', 'Spool Release', 'NDT Release', 'QC', 'Manufacturing'])
|
||||
->update([
|
||||
"spool_paint_check" => u() ? (u() ? u()->id : 0) : 0,
|
||||
"paint_release_no" => $checkNo,
|
||||
"paint_release_date" => simdi(),
|
||||
"spool_status" => "Completed"
|
||||
]);
|
||||
$count += $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Include paint follow-up updater
|
||||
ob_start();
|
||||
// echo view('admin.type.spool-release.paint-follow-up-updater')->render();
|
||||
ob_end_clean();
|
||||
|
||||
// Dispatch cache blade views
|
||||
dispatchCacheBladeViews();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => $count . ' row sign check affected',
|
||||
'count' => $count
|
||||
]);
|
||||
if (defined('STAY_ALIVE'))
|
||||
return;
|
||||
exit();
|
||||
}
|
||||
// Fallback to old format for backward compatibility
|
||||
elseif (isset($_POST['iso_number']) && !empty($_POST['iso_number'])) {
|
||||
$spoolNumbers = explode(",", $_POST['spool_number']);
|
||||
$isoNumbers = explode(",", $_POST['iso_number']);
|
||||
$count = 0;
|
||||
foreach ($isoNumbers as $isoNumber) {
|
||||
|
||||
$maxAttempts = 5;
|
||||
$attempt = 0;
|
||||
$result = db("weld_logs")
|
||||
->where("iso_number", $isoNumber)
|
||||
->where("spool_number", $spoolNumbers[$count])
|
||||
->whereNotIn("spool_status", ['Completed'])
|
||||
->whereIn("spool_status", ['Paint', 'Spool Release', 'NDT Release', 'QC', 'Manufacturing', 'Weld Complete'])
|
||||
->update([
|
||||
"spool_paint_check" => u() ? (u() ? u()->id : 0) : 0,
|
||||
"paint_release_no" => $checkNo,
|
||||
"paint_release_date" => simdi(),
|
||||
"spool_status" => "Completed"
|
||||
]);
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
// Include paint follow-up updater
|
||||
ob_start();
|
||||
echo view('admin.type.spool-release.paint-follow-up-updater')->render();
|
||||
ob_end_clean();
|
||||
|
||||
// Dispatch cache blade views
|
||||
dispatchCacheBladeViews();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => $count . ' row sign check affected',
|
||||
'count' => $count
|
||||
]);
|
||||
if (defined('STAY_ALIVE'))
|
||||
return;
|
||||
exit();
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'ISO number is required in POST data'
|
||||
]);
|
||||
if (defined('STAY_ALIVE'))
|
||||
return;
|
||||
exit();
|
||||
}
|
||||
|
||||
} else {
|
||||
// Handle NDT Release
|
||||
if (isset($_POST['ndt_release']) && !empty($_POST['ndt_release'])) {
|
||||
$ndt_release_number_pattern = setting("ndt_release_number_pattern");
|
||||
$newReleaseNo = str_replace("{number}", get_counter($ndt_release_number_pattern), $ndt_release_number_pattern);
|
||||
|
||||
// Check if ISO+SPL pairs are provided (new format)
|
||||
if (isset($_POST['iso_spool_pairs']) && !empty($_POST['iso_spool_pairs'])) {
|
||||
$pairs = explode(",", $_POST['iso_spool_pairs']);
|
||||
$totalAffectedRows = 0;
|
||||
|
||||
foreach ($pairs as $pair) {
|
||||
$pairParts = explode("|", trim($pair));
|
||||
if (count($pairParts) == 2) {
|
||||
$isoNumber = trim($pairParts[0]);
|
||||
$spoolNumber = trim($pairParts[1]);
|
||||
|
||||
if (!empty($isoNumber) && !empty($spoolNumber)) {
|
||||
$weldInfos = db("weld_logs");
|
||||
$weldInfos = $weldInfos->where("iso_number", $isoNumber);
|
||||
$weldInfos = $weldInfos->where("spool_number", $spoolNumber);
|
||||
$weldInfos = $weldInfos->whereNotNull("spool_ndt_check_no");
|
||||
$weldInfos = $weldInfos->whereNull("ndt_release_no");
|
||||
|
||||
$affectedRows = $weldInfos->update([
|
||||
"ndt_release_no" => $newReleaseNo,
|
||||
"ndt_release_check" => u() ? (u() ? u()->id : 0) : 0,
|
||||
"ndt_release_date" => Carbon::now(),
|
||||
'spool_status' => "Paint",
|
||||
]);
|
||||
|
||||
$totalAffectedRows += $affectedRows;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dispatch cache blade views
|
||||
dispatchCacheBladeViews();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => $totalAffectedRows . ' row affected',
|
||||
'count' => $totalAffectedRows
|
||||
]);
|
||||
if (defined('STAY_ALIVE'))
|
||||
return;
|
||||
exit();
|
||||
}
|
||||
// Fallback to old format for backward compatibility
|
||||
else {
|
||||
$weldInfos = db("weld_logs");
|
||||
|
||||
// Apply filters from POST data
|
||||
$get = $_POST;
|
||||
unset($get['ndt_release'], $get['ndt_paint_release'], $get['page'], $get['rollback'], $get['_token'], $get['checklist-ok'], $get['iso_spool_pairs']);
|
||||
|
||||
foreach ($get as $col => $value) {
|
||||
if ($col == "iso_number") {
|
||||
$value = explode(",", $value);
|
||||
}
|
||||
if ($col == "spool_number") {
|
||||
$value = explode(",", $value);
|
||||
}
|
||||
|
||||
if ($value != "") {
|
||||
if (is_array($value)) {
|
||||
$weldInfos = $weldInfos->whereIn($col, $value);
|
||||
} else {
|
||||
$weldInfos = $weldInfos->where($col, trim($value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$ndtReleaseUpdate = $weldInfos;
|
||||
$ndtReleaseUpdate = $ndtReleaseUpdate->whereNotNull("spool_ndt_check_no");
|
||||
$ndtReleaseUpdate = $ndtReleaseUpdate->whereNull("ndt_release_no");
|
||||
$affectedRows = $ndtReleaseUpdate->update([
|
||||
"ndt_release_no" => $newReleaseNo,
|
||||
"ndt_release_check" => u() ? (u() ? u()->id : 0) : 0,
|
||||
"ndt_release_date" => Carbon::now(),
|
||||
'spool_status' => "Paint",
|
||||
]);
|
||||
|
||||
// Dispatch cache blade views
|
||||
dispatchCacheBladeViews();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => $affectedRows . ' row affected',
|
||||
'count' => $affectedRows
|
||||
]);
|
||||
if (defined('STAY_ALIVE'))
|
||||
return;
|
||||
exit();
|
||||
}
|
||||
}
|
||||
|
||||
// Handle NDT & Paint Release
|
||||
if (isset($_POST['ndt_paint_release']) && !empty($_POST['ndt_paint_release'])) {
|
||||
$paint_release_number_pattern = setting("paint_release_number_pattern");
|
||||
$totalAffectedRows = 0;
|
||||
|
||||
// Check if ISO+SPL pairs are provided (new format)
|
||||
if (isset($_POST['iso_spool_pairs']) && !empty($_POST['iso_spool_pairs'])) {
|
||||
$pairs = explode(",", $_POST['iso_spool_pairs']);
|
||||
|
||||
foreach ($pairs as $pair) {
|
||||
$pairParts = explode("|", trim($pair));
|
||||
if (count($pairParts) == 2) {
|
||||
$isoNumber = trim($pairParts[0]);
|
||||
$spoolNumber = trim($pairParts[1]);
|
||||
|
||||
if (!empty($isoNumber) && !empty($spoolNumber)) {
|
||||
$newRequestNo = $paint_release_number_pattern;
|
||||
$newRequestNo = str_replace("{number}", get_counter($newRequestNo), $newRequestNo);
|
||||
|
||||
$whereData = [
|
||||
'iso_number' => $isoNumber,
|
||||
'spool_number' => $spoolNumber
|
||||
];
|
||||
|
||||
$checkPaintingCycle = db("weld_logs")
|
||||
->where($whereData)
|
||||
->select("painting_cycle")
|
||||
->first();
|
||||
|
||||
$spoolStatus = (!empty($checkPaintingCycle) && !empty($checkPaintingCycle->painting_cycle)) ? "Paint" : "Completed";
|
||||
|
||||
$updateData = [
|
||||
"ndt_release_no" => $newRequestNo,
|
||||
"ndt_release_check" => u() ? (u() ? u()->id : 0) : 0,
|
||||
"ndt_release_date" => Carbon::now(),
|
||||
'spool_status' => $spoolStatus,
|
||||
];
|
||||
|
||||
$ndtReleaseUpdate = db("weld_logs");
|
||||
$ndtReleaseUpdate = $ndtReleaseUpdate->where($whereData);
|
||||
$ndtReleaseUpdate = $ndtReleaseUpdate->whereNotNull("spool_ndt_check_no");
|
||||
$ndtReleaseUpdate = $ndtReleaseUpdate->whereNull("ndt_release_date");
|
||||
$affectedRows = $ndtReleaseUpdate->update($updateData);
|
||||
$totalAffectedRows += $affectedRows;
|
||||
|
||||
// Include paint follow-up updater (capture ALL output to prevent HTML output)
|
||||
if ($affectedRows > 0) {
|
||||
try {
|
||||
// Start output buffering to capture any HTML output (including from bilgi() function)
|
||||
// Use multiple levels to ensure we catch everything
|
||||
ob_start();
|
||||
ob_start();
|
||||
// Render the view - this will execute bilgi() and capture its output
|
||||
$rendered = view('admin.type.spool-release.paint-follow-up-updater')->render();
|
||||
// Clean all output buffers
|
||||
ob_end_clean();
|
||||
ob_end_clean();
|
||||
} catch (\Exception $e) {
|
||||
// Silently catch any errors and clean all output buffers
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Fallback to old format for backward compatibility
|
||||
elseif (isset($_POST['iso_number']) && !empty($_POST['iso_number'])) {
|
||||
$isoNumbers = explode(",", $_POST['iso_number']);
|
||||
$spoolNumbers = [];
|
||||
if (isset($_POST['spool_number']) && !empty($_POST['spool_number'])) {
|
||||
$spoolNumbers = explode(",", $_POST['spool_number']);
|
||||
}
|
||||
|
||||
// Calculate total updates - if spool_numbers exist, use min, otherwise use iso_numbers count
|
||||
$totalUpdates = count($isoNumbers);
|
||||
if (count($spoolNumbers) > 0) {
|
||||
$totalUpdates = min(count($isoNumbers), count($spoolNumbers));
|
||||
}
|
||||
|
||||
for ($i = 0; $i < $totalUpdates; $i++) {
|
||||
$newRequestNo = $paint_release_number_pattern;
|
||||
$newRequestNo = str_replace("{number}", get_counter($newRequestNo), $newRequestNo);
|
||||
$whereData = [
|
||||
'iso_number' => trim($isoNumbers[$i]),
|
||||
];
|
||||
|
||||
if (isset($spoolNumbers[$i]) && !empty($spoolNumbers[$i])) {
|
||||
$whereData['spool_number'] = trim($spoolNumbers[$i]);
|
||||
}
|
||||
|
||||
$checkPaintingCycle = db("weld_logs")
|
||||
->where($whereData)
|
||||
->select("painting_cycle")
|
||||
->first();
|
||||
|
||||
$spoolStatus = (!empty($checkPaintingCycle) && !empty($checkPaintingCycle->painting_cycle)) ? "Paint" : "Completed";
|
||||
|
||||
$updateData = [
|
||||
"ndt_release_no" => $newRequestNo,
|
||||
"ndt_release_check" => u() ? (u() ? u()->id : 0) : 0,
|
||||
"ndt_release_date" => Carbon::now(),
|
||||
'spool_status' => $spoolStatus,
|
||||
];
|
||||
|
||||
$ndtReleaseUpdate = db("weld_logs");
|
||||
$ndtReleaseUpdate = $ndtReleaseUpdate->where($whereData);
|
||||
$ndtReleaseUpdate = $ndtReleaseUpdate->whereNotNull("spool_ndt_check_no");
|
||||
$ndtReleaseUpdate = $ndtReleaseUpdate->whereNull("ndt_release_date");
|
||||
$affectedRows = $ndtReleaseUpdate->update($updateData);
|
||||
$totalAffectedRows += $affectedRows;
|
||||
|
||||
// Include paint follow-up updater (capture ALL output to prevent HTML output)
|
||||
if ($affectedRows > 0) {
|
||||
try {
|
||||
$isoNumber = trim($isoNumbers[$i]);
|
||||
// Start output buffering to capture any HTML output (including from bilgi() function)
|
||||
// Use multiple levels to ensure we catch everything
|
||||
ob_start();
|
||||
ob_start();
|
||||
// Render the view - this will execute bilgi() and capture its output
|
||||
$rendered = view('admin.type.spool-release.paint-follow-up-updater')->render();
|
||||
// Clean all output buffers
|
||||
ob_end_clean();
|
||||
ob_end_clean();
|
||||
} catch (\Exception $e) {
|
||||
// Silently catch any errors and clean all output buffers
|
||||
while (ob_get_level() > 0) {
|
||||
ob_end_clean();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Dispatch cache blade views
|
||||
dispatchCacheBladeViews();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => $totalAffectedRows . ' row affected',
|
||||
'count' => $totalAffectedRows
|
||||
]);
|
||||
if (defined('STAY_ALIVE'))
|
||||
return;
|
||||
exit();
|
||||
}
|
||||
|
||||
// Handle Checklist OK (existing functionality)
|
||||
$spool_release_check_number_pattern = setting("spool_release_check_number_pattern");
|
||||
$checkNo = str_replace("{number}", get_counter($spool_release_check_number_pattern), $spool_release_check_number_pattern);
|
||||
if (isset($_POST['checklist-ok'])) {
|
||||
// Check if ISO+SPL pairs are provided (new format)
|
||||
if (isset($_POST['iso_spool_pairs']) && !empty($_POST['iso_spool_pairs'])) {
|
||||
$pairs = explode(",", $_POST['iso_spool_pairs']);
|
||||
$totalAffectedRows = 0;
|
||||
|
||||
foreach ($pairs as $pair) {
|
||||
$pairParts = explode("|", trim($pair));
|
||||
if (count($pairParts) == 2) {
|
||||
$isoNumber = trim($pairParts[0]);
|
||||
$spoolNumber = trim($pairParts[1]);
|
||||
|
||||
if (!empty($isoNumber) && !empty($spoolNumber)) {
|
||||
$result = db("weld_logs")
|
||||
->where("iso_number", $isoNumber)
|
||||
->where("spool_number", $spoolNumber)
|
||||
->whereIn("spool_status", ["Spool Release", "Manufacturing", "Weld Complete"])
|
||||
->update([
|
||||
"spool_ndt_check" => u() ? (u() ? u()->id : 0) : 0,
|
||||
"spool_ndt_check_no" => $checkNo,
|
||||
"spool_ndt_check_date" => simdi(),
|
||||
"spool_status" => "NDT Release"
|
||||
]);
|
||||
|
||||
$totalAffectedRows += $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Include spool document generate
|
||||
ob_start();
|
||||
echo view('admin.type.spool-release.spool-document-generate')->render();
|
||||
ob_end_clean();
|
||||
|
||||
// Include spool status changer
|
||||
ob_start();
|
||||
echo view('cron.spool-status-changer', [
|
||||
'iso_spool_pairs' => $_POST['iso_spool_pairs']
|
||||
])->render();
|
||||
ob_end_clean();
|
||||
|
||||
// Dispatch cache blade views
|
||||
dispatchCacheBladeViews();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => $totalAffectedRows . ' row sign check',
|
||||
'count' => $totalAffectedRows
|
||||
]);
|
||||
if (defined('STAY_ALIVE'))
|
||||
return;
|
||||
exit();
|
||||
}
|
||||
// Fallback to old format for backward compatibility
|
||||
elseif (isset($_POST['iso_number']) && !empty($_POST['iso_number'])) {
|
||||
$isoNumbers = explode(",", $_POST['iso_number']);
|
||||
$spoolNumbers = explode(",", $_POST['spool_number']);
|
||||
|
||||
$totalUpdates = min(count($isoNumbers), count($spoolNumbers));
|
||||
$totalAffectedRows = 0;
|
||||
|
||||
for ($i = 0; $i < $totalUpdates; $i++) {
|
||||
$currentIso = trim($isoNumbers[$i]);
|
||||
$currentSpool = trim($spoolNumbers[$i]);
|
||||
$result = db("weld_logs")
|
||||
->where("iso_number", $currentIso)
|
||||
->where("spool_number", $currentSpool)
|
||||
->whereIn("spool_status", ["Spool Release", "Manufacturing", "Weld Complete"])
|
||||
->update([
|
||||
"spool_ndt_check" => u() ? (u() ? u()->id : 0) : 0,
|
||||
"spool_ndt_check_no" => $checkNo,
|
||||
"spool_ndt_check_date" => simdi(),
|
||||
"spool_status" => "NDT Release"
|
||||
]);
|
||||
|
||||
$totalAffectedRows += $result;
|
||||
}
|
||||
|
||||
// Include spool document generate
|
||||
ob_start();
|
||||
echo view('admin.type.spool-release.spool-document-generate')->render();
|
||||
ob_end_clean();
|
||||
|
||||
// Include spool status changer
|
||||
ob_start();
|
||||
echo view('cron.spool-status-changer', [
|
||||
'iso_number' => $_POST['iso_number'],
|
||||
'spool_number' => $_POST['spool_number']
|
||||
])->render();
|
||||
ob_end_clean();
|
||||
|
||||
// Dispatch cache blade views
|
||||
dispatchCacheBladeViews();
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'success',
|
||||
'message' => $totalAffectedRows . ' row sign check',
|
||||
'count' => $totalAffectedRows
|
||||
]);
|
||||
if (defined('STAY_ALIVE'))
|
||||
return;
|
||||
exit();
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'ISO number is required in POST data'
|
||||
]);
|
||||
exit();
|
||||
}
|
||||
} else {
|
||||
echo json_encode([
|
||||
'status' => 'error',
|
||||
'message' => 'No valid action specified'
|
||||
]);
|
||||
if (defined('STAY_ALIVE'))
|
||||
return;
|
||||
exit();
|
||||
}
|
||||
}
|
||||
?>
|
||||
Reference in New Issue
Block a user