fixed worksheet modal
This commit is contained in:
@@ -64,6 +64,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
|
||||
|
||||
$approved_by = trim($_POST['approved_by'] ?? '');
|
||||
$notes = trim($_POST['notes'] ?? '');
|
||||
$worksheet_number = null;
|
||||
|
||||
if ($id > 0) {
|
||||
$stmt = $pdo->prepare("
|
||||
@@ -128,34 +129,65 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
|
||||
exit;
|
||||
}
|
||||
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$stmtNum = $pdo->query("
|
||||
SELECT IFNULL(MAX(worksheet_number), 0) + 1 AS next_number
|
||||
FROM work_sheets
|
||||
");
|
||||
$worksheet_number = (int)$stmtNum->fetchColumn();
|
||||
if ($worksheet_number <= 0) {
|
||||
$worksheet_number = 1;
|
||||
}
|
||||
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO work_sheets
|
||||
(
|
||||
idmatrice, worksheet_date, customer_name, profile_type_code, marking,
|
||||
prod_control_measure_settings, control_frequency_cut, control_frequency_drawing,
|
||||
control_frequency_jig, control_mode_jig,
|
||||
requested_package_code, meters_per_package, meters_per_package_tolerance, meters_per_package_notes,
|
||||
box_type, packages_or_pieces_per_box, meters_per_box,
|
||||
pallet_type, boxes_or_packages_per_pallet,
|
||||
speed_expected_kg_h, speed_actual_kg_h, speed_expected_m_h, speed_actual_m_h,
|
||||
approved_by, notes
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?,
|
||||
?, ?, ?,
|
||||
?, ?,
|
||||
?, ?, ?, ?,
|
||||
?, ?
|
||||
)
|
||||
");
|
||||
INSERT INTO work_sheets
|
||||
(
|
||||
worksheet_number,
|
||||
idmatrice,
|
||||
worksheet_date,
|
||||
customer_name,
|
||||
profile_type_code,
|
||||
revision_code,
|
||||
worksheet_status,
|
||||
marking,
|
||||
prod_control_measure_settings,
|
||||
control_frequency_cut,
|
||||
control_frequency_drawing,
|
||||
control_frequency_jig,
|
||||
control_mode_jig,
|
||||
requested_package_code,
|
||||
meters_per_package,
|
||||
meters_per_package_tolerance,
|
||||
meters_per_package_notes,
|
||||
box_type,
|
||||
packages_or_pieces_per_box,
|
||||
meters_per_box,
|
||||
pallet_type,
|
||||
boxes_or_packages_per_pallet,
|
||||
speed_expected_kg_h,
|
||||
speed_actual_kg_h,
|
||||
speed_expected_m_h,
|
||||
speed_actual_m_h,
|
||||
approved_by,
|
||||
notes
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?,
|
||||
?, ?, ?, ?, ?, ?
|
||||
)
|
||||
");
|
||||
$stmt->execute([
|
||||
$worksheet_number,
|
||||
$idmatrice,
|
||||
$worksheet_date,
|
||||
$customer_name !== '' ? $customer_name : null,
|
||||
$profile_code !== '' ? $profile_code : null,
|
||||
null, // revision_code = vuoto => revisione 0
|
||||
'active', // worksheet_status
|
||||
$marking,
|
||||
$prod_control !== '' ? $prod_control : null,
|
||||
$freq_cut !== '' ? $freq_cut : null,
|
||||
@@ -180,7 +212,14 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['aj
|
||||
]);
|
||||
|
||||
$newId = (int)$pdo->lastInsertId();
|
||||
echo json_encode(['success' => true, 'id' => $newId]);
|
||||
$pdo->commit();
|
||||
|
||||
echo json_encode([
|
||||
'success' => true,
|
||||
'id' => $newId,
|
||||
'worksheet_number' => $worksheet_number,
|
||||
'worksheet_number_label' => worksheet_number_label($worksheet_number)
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -399,6 +438,12 @@ function h($v)
|
||||
return htmlspecialchars((string)$v, ENT_QUOTES);
|
||||
}
|
||||
|
||||
function worksheet_number_label($n)
|
||||
{
|
||||
$n = (int)$n;
|
||||
return $n > 0 ? 'FL' . $n : 'Non assegnato';
|
||||
}
|
||||
|
||||
function ws_options($rows, $selectedValue, $defaultValue = '')
|
||||
{
|
||||
$selectedValue = (string)$selectedValue;
|
||||
@@ -855,8 +900,20 @@ $isEdit = ($worksheet_id > 0);
|
||||
<div class="value"><?= $isEdit ? 'In modifica' : 'Nuovo foglio' ?></div>
|
||||
</div>
|
||||
<div class="summary-item">
|
||||
<div class="label">ID foglio</div>
|
||||
<div class="value" id="summaryWsId"><?= $worksheet_id > 0 ? (int)$worksheet_id : 'Non salvato' ?></div>
|
||||
<div class="label">Foglio / Revisione</div>
|
||||
<div class="value" id="summaryWsId">
|
||||
<?php
|
||||
$wsNumberLabel = ($worksheet && !empty($worksheet['worksheet_number']))
|
||||
? worksheet_number_label($worksheet['worksheet_number'])
|
||||
: 'Non assegnato';
|
||||
|
||||
$wsRevisionLabel = ($worksheet && isset($worksheet['revision_code']) && trim((string)$worksheet['revision_code']) !== '')
|
||||
? trim((string)$worksheet['revision_code'])
|
||||
: '0';
|
||||
|
||||
echo h($wsNumberLabel . ' / Rev. ' . $wsRevisionLabel);
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
<div class="summary-item">
|
||||
<div class="label">Mescole inserite</div>
|
||||
@@ -1298,11 +1355,14 @@ $isEdit = ($worksheet_id > 0);
|
||||
if (id > 0) {
|
||||
btnAddMix.prop('disabled', false);
|
||||
$('#mixWorksheetId').val(id);
|
||||
summaryWsId.text(id);
|
||||
|
||||
if (!summaryWsId.text().trim()) {
|
||||
summaryWsId.text('Assegnato');
|
||||
}
|
||||
} else {
|
||||
btnAddMix.prop('disabled', true);
|
||||
$('#mixWorksheetId').val('0');
|
||||
summaryWsId.text('Non salvato');
|
||||
summaryWsId.text('Non assegnato');
|
||||
}
|
||||
}
|
||||
enableMixButtonIfSaved();
|
||||
@@ -1350,6 +1410,11 @@ $isEdit = ($worksheet_id > 0);
|
||||
}
|
||||
|
||||
wsIdInput.val(data.id);
|
||||
|
||||
if (data.worksheet_number_label) {
|
||||
summaryWsId.text(data.worksheet_number_label);
|
||||
}
|
||||
|
||||
enableMixButtonIfSaved();
|
||||
|
||||
if (!window.location.search.includes('id=')) {
|
||||
@@ -1360,7 +1425,7 @@ $isEdit = ($worksheet_id > 0);
|
||||
Swal.fire({
|
||||
icon: 'success',
|
||||
title: 'Testata salvata',
|
||||
text: 'Vuoi aggiungere subito le mescole?',
|
||||
text: (data.worksheet_number_label ? ('Foglio ' + data.worksheet_number_label + ' creato correttamente. Vuoi aggiungere subito le mescole?') : 'Vuoi aggiungere subito le mescole?'),
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Sì, aggiungi mescole',
|
||||
cancelButtonText: 'No'
|
||||
|
||||
Reference in New Issue
Block a user