added drag and photos
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
require_once(__DIR__ . "/class/db-functions.php");
|
||||
$db = DBHandlerSelect::getInstance();
|
||||
$pdo = $db->getConnection();
|
||||
|
||||
$STATUS_PROGRAMMATO = 6;
|
||||
$STATUS_DA_PROGRAMMARE = 1;
|
||||
|
||||
$jsonFile = __DIR__ . "/data/production_priority.json";
|
||||
|
||||
/* -------------------------------
|
||||
JSON HELPERS
|
||||
---------------------------------*/
|
||||
function loadPriority()
|
||||
{
|
||||
global $jsonFile;
|
||||
if (!file_exists($jsonFile)) return [];
|
||||
return json_decode(file_get_contents($jsonFile), true) ?: [];
|
||||
}
|
||||
|
||||
function savePriority($arr)
|
||||
{
|
||||
global $jsonFile;
|
||||
file_put_contents($jsonFile, json_encode($arr, JSON_PRETTY_PRINT));
|
||||
}
|
||||
|
||||
/* -------------------------------
|
||||
LOAD: PROGRAMMATI
|
||||
---------------------------------*/
|
||||
if ($_GET['mode'] === 'planned') {
|
||||
|
||||
$priority = loadPriority();
|
||||
$map = [];
|
||||
foreach ($priority as $p) $map[$p['id']] = $p['priority'];
|
||||
|
||||
$sql = "SELECT p.*, m.nome AS matrice, ms.nome AS mescola,
|
||||
l.name AS linea, c.nome AS cliente
|
||||
FROM productiondata p
|
||||
LEFT JOIN matrice m ON p.idmatrice = m.id
|
||||
LEFT JOIN mescole ms ON p.idmescola = ms.id
|
||||
LEFT JOIN production_lines l ON p.id_linea = l.id
|
||||
LEFT JOIN clients c ON p.id_cliente = c.id
|
||||
WHERE p.id_status = :s";
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute(['s' => $STATUS_PROGRAMMATO]);
|
||||
$rows = $stmt->fetchAll();
|
||||
|
||||
// Ordina per priority
|
||||
usort($rows, function ($a, $b) use ($map) {
|
||||
return ($map[$a['id']] ?? 9999) <=> ($map[$b['id']] ?? 9999);
|
||||
});
|
||||
|
||||
ob_start();
|
||||
foreach ($rows as $r):
|
||||
$prio = $map[$r['id']] ?? '-';
|
||||
?>
|
||||
<tr data-id="<?= $r['id'] ?>">
|
||||
<td><strong><?= $prio ?></strong></td>
|
||||
<td><?= date('d/m/Y', strtotime($r['Data'])) ?></td>
|
||||
<td><?= $r['matrice'] ?></td>
|
||||
<td><?= $r['mescola'] ?></td>
|
||||
<td><?= $r['linea'] ?></td>
|
||||
<td><?= $r['cliente'] ?? '-' ?></td>
|
||||
</tr>
|
||||
<?php
|
||||
endforeach;
|
||||
|
||||
echo json_encode(['html' => ob_get_clean()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* -------------------------------
|
||||
LOAD: DA PROGRAMMARE
|
||||
---------------------------------*/
|
||||
if ($_GET['mode'] === 'to_plan') {
|
||||
|
||||
$sql = "SELECT p.*, m.nome AS matrice, ms.nome AS mescola,
|
||||
l.name AS linea, c.nome AS cliente
|
||||
FROM productiondata p
|
||||
LEFT JOIN matrice m ON p.idmatrice = m.id
|
||||
LEFT JOIN mescole ms ON p.idmescola = ms.id
|
||||
LEFT JOIN production_lines l ON p.id_linea = l.id
|
||||
LEFT JOIN clients c ON p.id_cliente = c.id
|
||||
WHERE p.id_status = :s
|
||||
ORDER BY p.Data ASC";
|
||||
|
||||
$stmt = $pdo->prepare($sql);
|
||||
$stmt->execute(['s' => $STATUS_DA_PROGRAMMARE]);
|
||||
|
||||
ob_start();
|
||||
foreach ($stmt as $r): ?>
|
||||
<tr data-id="<?= $r['id'] ?>">
|
||||
<td><?= date('d/m/Y', strtotime($r['Data'])) ?></td>
|
||||
<td><?= $r['matrice'] ?></td>
|
||||
<td><?= $r['mescola'] ?></td>
|
||||
<td><?= $r['linea'] ?></td>
|
||||
<td><?= $r['cliente'] ?? '-' ?></td>
|
||||
</tr>
|
||||
<?php endforeach;
|
||||
|
||||
echo json_encode(['html' => ob_get_clean()]);
|
||||
exit;
|
||||
}
|
||||
|
||||
/* -------------------------------
|
||||
UPDATE STATUS + PRIORITY
|
||||
---------------------------------*/
|
||||
if ($_POST['mode'] === 'save') {
|
||||
|
||||
$planned = json_decode($_POST['planned'], true);
|
||||
$toPlan = json_decode($_POST['toPlan'], true);
|
||||
|
||||
$pdo->beginTransaction();
|
||||
|
||||
// Aggiorna programmati
|
||||
foreach ($planned as $i => $row) {
|
||||
$id = $row['id'];
|
||||
$stmt = $pdo->prepare("UPDATE productiondata SET id_status = :s WHERE id = :id");
|
||||
$stmt->execute(['s' => $STATUS_PROGRAMMATO, 'id' => $id]);
|
||||
$priorityArr[] = ['id' => $id, 'priority' => $i + 1];
|
||||
}
|
||||
|
||||
// Aggiorna da programmare
|
||||
foreach ($toPlan as $row) {
|
||||
$id = $row['id'];
|
||||
$stmt = $pdo->prepare("UPDATE productiondata SET id_status = :s WHERE id = :id");
|
||||
$stmt->execute(['s' => $STATUS_DA_PROGRAMMARE, 'id' => $id]);
|
||||
}
|
||||
|
||||
$pdo->commit();
|
||||
|
||||
savePriority($priorityArr);
|
||||
|
||||
echo json_encode(['success' => true]);
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user