fixed view and multi
This commit is contained in:
@@ -24,21 +24,6 @@ function selectOptions($arr, $sel = null, $val = 'id', $txt = 'nome')
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
$action = $_POST['action'];
|
||||
|
||||
$data = [
|
||||
'idmatrice' => $_POST['idmatrice'],
|
||||
'id_linea' => $_POST['id_linea'],
|
||||
'id_cliente' => $_POST['id_cliente'] ?: null,
|
||||
'data_zibo' => $_POST['data_zibo'] ?: null,
|
||||
'data_cliente' => $_POST['data_cliente'] ?: null,
|
||||
'metri' => $_POST['metri'] ?: 0,
|
||||
'kg_sp' => $_POST['kg_sp'] ?: 0,
|
||||
'kg_p' => $_POST['kg_p'] ?: 0,
|
||||
'ore_previste' => $_POST['ore_previste'] ?: 0,
|
||||
'note_extra' => $_POST['note_extra'] ?: null,
|
||||
'id_status' => $_POST['id_status'] ?? 1
|
||||
];
|
||||
|
||||
|
||||
try {
|
||||
|
||||
// ============================
|
||||
@@ -46,24 +31,42 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
// ============================
|
||||
if ($action === 'insert') {
|
||||
|
||||
$dataInsert = [
|
||||
'Data' => $_POST['Data'],
|
||||
'data_produzione' => $_POST['data_produzione'],
|
||||
'idmatrice' => $_POST['idmatrice'],
|
||||
'id_linea' => $_POST['id_linea'],
|
||||
'id_cliente' => $_POST['id_cliente'] ?: null,
|
||||
'data_zibo' => $_POST['data_zibo'] ?: null,
|
||||
'data_cliente' => $_POST['data_cliente'] ?: null,
|
||||
'metri' => $_POST['metri'] ?: 0,
|
||||
'kg_sp' => $_POST['kg_sp'] ?: 0,
|
||||
'kg_p' => $_POST['kg_p'] ?: 0,
|
||||
'ore_previste' => $_POST['ore_previste'] ?: 0,
|
||||
'note_extra' => $_POST['note_extra'] ?: null,
|
||||
'id_status' => $_POST['id_status'] ?? 1,
|
||||
'conferma_ordine' => $_POST['conferma_ordine'] ?: null,
|
||||
];
|
||||
|
||||
$sql = "INSERT INTO productiondata
|
||||
(Data, idmatrice, id_linea, id_cliente, data_zibo, data_cliente,
|
||||
metri, kg_sp, kg_p, ore_previste, note_extra, data_produzione, id_status)
|
||||
(Data, data_produzione, conferma_ordine,
|
||||
idmatrice, id_linea, id_cliente, data_zibo, data_cliente,
|
||||
metri, kg_sp, kg_p, ore_previste, note_extra, id_status)
|
||||
VALUES
|
||||
(:Data, :idmatrice, :id_linea, :id_cliente, :data_zibo, :data_cliente,
|
||||
:metri, :kg_sp, :kg_p, :ore_previste, :note_extra, :data_produzione, :id_status)";
|
||||
(:Data, :data_produzione, :conferma_ordine,
|
||||
:idmatrice, :id_linea, :id_cliente, :data_zibo, :data_cliente,
|
||||
:metri, :kg_sp, :kg_p, :ore_previste, :note_extra, :id_status)";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($data);
|
||||
$stmt->execute($dataInsert);
|
||||
|
||||
// QUI devi prendere il nuovo ID
|
||||
// nuovo ID
|
||||
$idProd = $pdo->lastInsertId();
|
||||
|
||||
// cancella vecchie associazioni (non serve ma per sicurezza)
|
||||
// reset associazioni mescole
|
||||
$pdo->prepare("DELETE FROM productiondata_mescole WHERE id_productiondata=?")
|
||||
->execute([$idProd]);
|
||||
|
||||
// aggiungi nuove
|
||||
if (!empty($_POST['mescole'])) {
|
||||
$ins = $pdo->prepare("INSERT INTO productiondata_mescole (id_productiondata, id_mescola) VALUES (?, ?)");
|
||||
foreach ($_POST['mescole'] as $m) {
|
||||
@@ -79,27 +82,41 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
// ============================
|
||||
elseif ($action === 'update' && !empty($_POST['id'])) {
|
||||
|
||||
$data['id'] = $_POST['id'];
|
||||
$dataUpdate = [
|
||||
'id' => $_POST['id'],
|
||||
'idmatrice' => $_POST['idmatrice'],
|
||||
'id_linea' => $_POST['id_linea'],
|
||||
'id_cliente' => $_POST['id_cliente'] ?: null,
|
||||
'data_zibo' => $_POST['data_zibo'] ?: null,
|
||||
'data_cliente' => $_POST['data_cliente'] ?: null,
|
||||
'metri' => $_POST['metri'] ?: 0,
|
||||
'kg_sp' => $_POST['kg_sp'] ?: 0,
|
||||
'kg_p' => $_POST['kg_p'] ?: 0,
|
||||
'ore_previste' => $_POST['ore_previste'] ?: 0,
|
||||
'note_extra' => $_POST['note_extra'] ?: null,
|
||||
'id_status' => $_POST['id_status'] ?? 1,
|
||||
'conferma_ordine' => $_POST['conferma_ordine'] ?: null,
|
||||
];
|
||||
|
||||
$sql = "UPDATE productiondata SET
|
||||
idmatrice=:idmatrice,
|
||||
id_linea=:id_linea,
|
||||
id_cliente=:id_cliente,
|
||||
data_zibo=:data_zibo,
|
||||
data_cliente=:data_cliente,
|
||||
metri=:metri,
|
||||
kg_sp=:kg_sp,
|
||||
kg_p=:kg_p,
|
||||
ore_previste=:ore_previste,
|
||||
note_extra=:note_extra,
|
||||
id_status=:id_status
|
||||
WHERE id = :id
|
||||
";
|
||||
idmatrice = :idmatrice,
|
||||
id_linea = :id_linea,
|
||||
id_cliente = :id_cliente,
|
||||
data_zibo = :data_zibo,
|
||||
data_cliente = :data_cliente,
|
||||
metri = :metri,
|
||||
kg_sp = :kg_sp,
|
||||
kg_p = :kg_p,
|
||||
ore_previste = :ore_previste,
|
||||
note_extra = :note_extra,
|
||||
id_status = :id_status,
|
||||
conferma_ordine = :conferma_ordine
|
||||
WHERE id = :id";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute($data);
|
||||
$stmt->execute($dataUpdate);
|
||||
|
||||
// QUI devi usare L'ID ESISTENTE !
|
||||
// ID esistente
|
||||
$idProd = $_POST['id'];
|
||||
|
||||
$pdo->prepare("DELETE FROM productiondata_mescole WHERE id_productiondata=?")
|
||||
@@ -122,6 +139,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
<!doctype html>
|
||||
<html lang="it">
|
||||
@@ -337,7 +355,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div class="wrapper">
|
||||
<div class="wrapper toggled">
|
||||
<?php include('include/navbar.php');
|
||||
include('include/topbar.php'); ?>
|
||||
<div class="page-wrapper">
|
||||
@@ -371,6 +389,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
GROUP_CONCAT(ms.id SEPARATOR ',') AS mescole_ids,
|
||||
l.name AS linea,
|
||||
c.nome AS cliente,
|
||||
p.conferma_ordine,
|
||||
s.nome AS status_nome,
|
||||
COALESCE(s.badge_color, '#6c757d') AS badge_color,
|
||||
COALESCE(s.line_color, '#ffffff') AS line_color
|
||||
@@ -402,6 +421,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
<table id="tabSpecial" class="table table-hover align-middle" style="width:100%">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Conf. Ord.</th>
|
||||
<th>Matrice</th>
|
||||
<th>Mescola</th>
|
||||
<th>Linea</th>
|
||||
@@ -433,7 +453,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
|
||||
|
||||
|
||||
|
||||
<td><?= htmlspecialchars($r['conferma_ordine']) ?></td>
|
||||
<td><?= htmlspecialchars($r['matrice']) ?></td>
|
||||
<td><?= htmlspecialchars($r['mescola']) ?></td>
|
||||
<td data-line-id="<?= $r['id_linea'] ?>"><?= htmlspecialchars($r['linea']) ?></td>
|
||||
@@ -494,6 +514,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
<tr>
|
||||
<th style="width:30px;"></th>
|
||||
<th>Priority</th>
|
||||
<th>Conf. Ord.</th>
|
||||
<th>Matrice</th>
|
||||
<th>Mescola</th>
|
||||
<th>Linea</th>
|
||||
@@ -535,6 +556,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
<tr>
|
||||
<th style="width:30px;"></th>
|
||||
<th></th>
|
||||
<th>Conf. Ord.</th>
|
||||
<th>Matrice</th>
|
||||
<th>Mescola</th>
|
||||
<th>Linea</th>
|
||||
@@ -804,17 +826,32 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
|
||||
let sortProgrammati = Sortable.create(document.getElementById("programmatiBlock"), {
|
||||
group: "prod",
|
||||
group: {
|
||||
name: "prod",
|
||||
pull: true,
|
||||
put: true
|
||||
},
|
||||
forceFallback: true,
|
||||
fallbackOnBody: true,
|
||||
fallbackTolerance: 3,
|
||||
animation: 150,
|
||||
onEnd: updatePriority
|
||||
});
|
||||
|
||||
let sortDaProgrammare = Sortable.create(document.getElementById("daProgrammareBlock"), {
|
||||
group: "prod",
|
||||
group: {
|
||||
name: "prod",
|
||||
pull: true,
|
||||
put: true
|
||||
},
|
||||
forceFallback: true,
|
||||
fallbackOnBody: true,
|
||||
fallbackTolerance: 3,
|
||||
animation: 150,
|
||||
onEnd: updatePriority
|
||||
});
|
||||
|
||||
|
||||
// disabilito sortable sulla tabella special (è sola lettura)
|
||||
const specialTbody = document.querySelector("#tabSpecial tbody");
|
||||
if (specialTbody) {
|
||||
@@ -830,24 +867,36 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
let programmati = [];
|
||||
let daProgrammare = [];
|
||||
|
||||
// → Righe nella tabella PROGRAMMATI (status deve diventare 6)
|
||||
// → PROGRAMMATI (status 6)
|
||||
$("#programmatiBlock tr").each(function(index) {
|
||||
const id = $(this).data("id");
|
||||
|
||||
// se il TR non ha data-id (es. riga child DataTables) lo salto
|
||||
if (typeof id === "undefined" || id === null || id === "") {
|
||||
return; // continue
|
||||
}
|
||||
|
||||
programmati.push({
|
||||
id: $(this).data("id"),
|
||||
id: id,
|
||||
priority: index + 1,
|
||||
status: 6
|
||||
});
|
||||
});
|
||||
|
||||
// → Righe nella tabella DA PROGRAMMARE (status deve diventare 1)
|
||||
// → DA PROGRAMMARE (status 1)
|
||||
$("#daProgrammareBlock tr").each(function(index) {
|
||||
const id = $(this).data("id");
|
||||
|
||||
if (typeof id === "undefined" || id === null || id === "") {
|
||||
return; // continue
|
||||
}
|
||||
|
||||
daProgrammare.push({
|
||||
id: $(this).data("id"),
|
||||
id: id,
|
||||
priority: index + 1
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
$.post("ajax_update_priority.php", {
|
||||
programmati: JSON.stringify(programmati),
|
||||
daProgrammare: JSON.stringify(daProgrammare)
|
||||
@@ -861,6 +910,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -875,6 +925,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
|
||||
</div>
|
||||
<div class="modal-body">
|
||||
<div class="row g-3">
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Conferma d'ordine</label>
|
||||
<input type="text" class="form-control" name="conferma_ordine">
|
||||
</div>
|
||||
|
||||
<div class="col-md-6">
|
||||
<label class="form-label">Data</label>
|
||||
<input type="date" class="form-control" name="Data" required>
|
||||
|
||||
Reference in New Issue
Block a user