added production

This commit is contained in:
Claudio 2025-10-30 16:40:14 +01:00
parent a4b1fb9b1f
commit edcedb8f91
3 changed files with 602 additions and 1 deletions

View File

@ -0,0 +1,18 @@
<?php
include('include/headscript.php');
header('Content-Type: application/json');
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
if (empty($_POST['id'])) {
echo json_encode(['success' => false, 'msg' => 'ID mancante']);
exit;
}
try {
$stmt = $pdo->prepare("DELETE FROM productiondata WHERE id = :id");
$stmt->execute(['id' => $_POST['id']]);
echo json_encode(['success' => true]);
} catch (Exception $e) {
echo json_encode(['success' => false, 'msg' => $e->getMessage()]);
}

View File

@ -110,7 +110,7 @@
max-width: 280px;
border: none;
border-radius: 16px;
padding: 36px 10px;
padding: 24px 10px;
color: #2b3e50;
font-size: 1.3rem;
font-weight: 600;
@ -266,6 +266,7 @@
</button>
</div>
</div>
</div>
<?php include('jsinclude.php'); ?>

View File

@ -0,0 +1,582 @@
<?php
include('include/headscript.php');
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
// --- LISTE SELECT ---
$matrici = $pdo->query("SELECT id, nome FROM matrice ORDER BY nome")->fetchAll();
$mescole = $pdo->query("SELECT id, nome FROM mescole ORDER BY nome")->fetchAll();
$linee = $pdo->query("SELECT id, line_number, name FROM production_lines ORDER BY line_number")->fetchAll();
$clienti = $pdo->query("SELECT id, nome FROM clients ORDER BY nome")->fetchAll();
$status_list = $pdo->query("SELECT id, nome, badge_color, line_color FROM production_status ORDER BY ordinamento, nome")->fetchAll();
// --- SALVATAGGIO INLINE ---
if ($_SERVER['REQUEST_METHOD'] === 'POST' && !empty($_POST['action'])) {
$action = $_POST['action'];
$data = [
'Data' => $_POST['Data'],
'idmatrice' => $_POST['idmatrice'],
'idmescola' => $_POST['idmescola'],
'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,
'data_produzione' => $_POST['data_produzione'],
'id_status' => $_POST['id_status'] ?? 1
];
try {
if ($action === 'insert') {
$sql = "INSERT INTO productiondata
(Data, idmatrice, idmescola, id_linea, id_cliente, data_zibo, data_cliente, metri, kg_sp, kg_p, ore_previste, note_extra, data_produzione, id_status)
VALUES
(:Data, :idmatrice, :idmescola, :id_linea, :id_cliente, :data_zibo, :data_cliente, :metri, :kg_sp, :kg_p, :ore_previste, :note_extra, :data_produzione, :id_status)";
$stmt = $pdo->prepare($sql);
$stmt->execute($data);
echo json_encode(['success' => true]);
} elseif ($action === 'update' && !empty($_POST['id'])) {
$data['id'] = $_POST['id'];
$sql = "UPDATE productiondata SET
Data=:Data, idmatrice=:idmatrice, idmescola=:idmescola, 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, data_produzione=:data_produzione, id_status=:id_status
WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->execute($data);
echo json_encode(['success' => true]);
}
exit;
} catch (Exception $e) {
echo json_encode(['success' => false, 'msg' => $e->getMessage()]);
exit;
}
}
?>
<!doctype html>
<html lang="it">
<head>
<?php include('cssinclude.php'); ?>
<title>Programmazione Produzione - <?= $titlewebsite ?></title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/css/select2.min.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/select2-bootstrap-5-theme@1.3.0/dist/select2-bootstrap-5-theme.min.css" rel="stylesheet">
<link href="https://cdn.datatables.net/1.13.7/css/dataTables.bootstrap5.min.css" rel="stylesheet">
<link href="https://cdn.datatables.net/responsive/2.5.0/css/responsive.bootstrap5.min.css" rel="stylesheet">
<style>
.inline-edit {
display: none;
}
.btn-sm {
border-radius: .5rem;
font-size: .8rem;
padding: .35rem .65rem;
}
.table td,
.table th {
vertical-align: middle;
}
.table th {
background: #f8f9fa;
font-weight: 600;
}
.modal-xl {
max-width: 95% !important;
}
.table-responsive {
min-height: 400px;
}
#tabProgrammazione {
width: 100% !important;
}
.dataTables_wrapper .dataTables_filter input,
.dataTables_wrapper .dataTables_length select {
border-radius: 0.375rem;
border: 1px solid #ced4da;
}
.dataTables_wrapper .dataTables_filter {
float: right;
}
.dataTables_wrapper .dataTables_length {
float: left;
}
.dataTables_wrapper .dataTables_info {
float: left;
}
.dataTables_wrapper .dataTables_paginate {
float: right;
}
.btn i {
font-size: 1rem;
}
.badge {
padding: .35em .65em;
font-size: .75rem;
border-radius: .4rem;
}
/* FILTRI SOPRA: TESTO PICCOLO */
.filters-row th {
padding: 0.4rem 0.3rem !important;
}
.filters-row input,
.filters-row select {
font-size: 0.75rem !important;
padding: 0.15rem 0.3rem !important;
height: auto !important;
}
.filters-row .select2-container {
font-size: 0.75rem !important;
}
.filters-row .select2-container--bootstrap-5 .select2-selection {
min-height: 28px !important;
padding: 0.1rem 0.3rem !important;
font-size: 0.75rem !important;
}
/* TESTO PICCOLO NEI DROPDOWN SELECT2 */
.select2-container--bootstrap-5 .select2-dropdown .select2-results__option {
font-size: 0.75rem !important;
padding: 0.2rem 0.5rem !important;
}
.select2-container--bootstrap-5 .select2-selection__placeholder {
font-size: 0.75rem !important;
}
</style>
</head>
<body>
<div class="wrapper">
<?php include('include/navbar.php');
include('include/topbar.php'); ?>
<div class="page-wrapper">
<div class="page-content">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h5 class="mb-0">Programmazione Produzione</h5>
<div>
<button class="btn btn-primary" data-bs-toggle="modal" data-bs-target="#modalNuovo">Aggiungi</button>
<button class="btn btn-secondary" onclick="location.href='production_dashboard.php'">Torna</button>
</div>
</div>
<div class="card-body pt-0">
<div class="table-responsive">
<table id="tabProgrammazione" class="table table-hover align-middle" style="width:100%">
<thead>
<tr>
<th>Data</th>
<th>Matrice</th>
<th>Mescola</th>
<th>Linea</th>
<th>Cliente</th>
<th>Zibo</th>
<th>Cliente</th>
<th>mt</th>
<th>kg sp</th>
<th>kg p</th>
<th>Ore</th>
<th>Note</th>
<th>Prod.</th>
<th>Status</th>
<th style="width: 80px;">Azioni</th>
</tr>
<!-- FILTRI SOPRA -->
<tr class="filters-row bg-light">
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="Filtra"></th>
<th><select class="filter-select form-select form-select-sm select2">
<option value="">Tutti</option><?= selectOptions($matrici) ?>
</select></th>
<th><select class="filter-select form-select form-select-sm select2">
<option value="">Tutti</option><?= selectOptions($mescole) ?>
</select></th>
<th><select class="filter-select form-select form-select-sm select2">
<option value="">Tutti</option><?= selectOptions($linee, null, 'id', 'name') ?>
</select></th>
<th><select class="filter-select form-select form-select-sm select2">
<option value="">Tutti</option>
<option value="">-</option><?= selectOptions($clienti) ?>
</select></th>
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="Zibo"></th>
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="Cliente"></th>
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="mt"></th>
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="kg sp"></th>
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="kg p"></th>
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="Ore"></th>
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="Note"></th>
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="Prod."></th>
<th><select class="filter-select form-select form-select-sm select2">
<option value="">Tutti</option><?= selectOptions($status_list, null, 'id', 'nome') ?>
</select></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT
p.*,
m.nome AS matrice,
ms.nome AS mescola,
l.name AS linea,
c.nome AS cliente,
s.nome AS status_nome,
COALESCE(s.badge_color, '#6c757d') AS badge_color,
COALESCE(s.line_color, '#ffffff') AS line_color
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
LEFT JOIN production_status s ON p.id_status = s.id
ORDER BY p.data_produzione DESC, p.Data DESC";
foreach ($pdo->query($sql) as $r) {
$lineColor = htmlspecialchars($r['line_color'] ?? '#ffffff');
$badgeColor = htmlspecialchars($r['badge_color'] ?? '#6c757d');
$statusName = htmlspecialchars(ucfirst($r['status_nome'] ?? 'N/D'));
echo "<tr data-id='{$r['id']}' style='background-color: {$lineColor} !important;'>
<td><span class='view'>" . date('d/m', strtotime($r['Data'])) . "</span>
<input class='inline-edit form-control form-control-sm' name='Data' type='date' value='{$r['Data']}'></td>
<td><span class='view'>{$r['matrice']}</span>
<select class='inline-edit form-select form-select-sm select2' name='idmatrice'>" . selectOptions($matrici, $r['idmatrice']) . "</select></td>
<td><span class='view'>{$r['mescola']}</span>
<select class='inline-edit form-select form-select-sm select2' name='idmescola'>" . selectOptions($mescole, $r['idmescola']) . "</select></td>
<td><span class='view'>{$r['linea']}</span>
<select class='inline-edit form-select form-select-sm select2' name='id_linea'>" . selectOptions($linee, $r['id_linea'], 'id', 'name') . "</select></td>
<td><span class='view'>" . ($r['cliente'] ?? '-') . "</span>
<select class='inline-edit form-select form-select-sm select2' name='id_cliente'><option value=''>-</option>" . selectOptions($clienti, $r['id_cliente']) . "</select></td>
<td><span class='view'>" . ($r['data_zibo'] ? date('d/m', strtotime($r['data_zibo'])) : '-') . "</span>
<input class='inline-edit form-control form-control-sm' name='data_zibo' type='date' value='{$r['data_zibo']}'></td>
<td><span class='view'>" . ($r['data_cliente'] ? date('d/m', strtotime($r['data_cliente'])) : '-') . "</span>
<input class='inline-edit form-control form-control-sm' name='data_cliente' type='date' value='{$r['data_cliente']}'></td>
<td><span class='view'>{$r['metri']}</span><input class='inline-edit form-control form-control-sm' name='metri' type='number' step='0.01' value='{$r['metri']}'></td>
<td><span class='view'>{$r['kg_sp']}</span><input class='inline-edit form-control form-control-sm' name='kg_sp' type='number' step='0.01' value='{$r['kg_sp']}'></td>
<td><span class='view'>{$r['kg_p']}</span><input class='inline-edit form-control form-control-sm' name='kg_p' type='number' step='0.01' value='{$r['kg_p']}'></td>
<td><span class='view'>{$r['ore_previste']}</span><input class='inline-edit form-control form-control-sm' name='ore_previste' type='number' step='0.01' value='{$r['ore_previste']}'></td>
<td><span class='view' style='max-width:120px;white-space:pre-wrap;'>" . htmlspecialchars($r['note_extra'] ?? '') . "</span>
<input class='inline-edit form-control form-control-sm' name='note_extra' value='" . htmlspecialchars($r['note_extra'] ?? '') . "'></td>
<td><span class='view'>" . date('d/m', strtotime($r['data_produzione'])) . "</span>
<input class='inline-edit form-control form-control-sm' name='data_produzione' type='date' value='{$r['data_produzione']}'></td>
<td>
<span class='badge view' style='background-color: {$badgeColor}; color: #fff;'>{$statusName}</span>
<select class='inline-edit form-select form-select-sm select2' name='id_status'>" . selectOptions($status_list, $r['id_status'], 'id', 'nome') . "</select>
</td>
<td>
<button class='btn btn-sm btn-outline-primary edit-row' title='Modifica'><i class='bi bi-pencil'></i></button>
<button class='btn btn-sm btn-success save-row d-none' title='Salva'><i class='bi bi-check-lg'></i></button>
<button class='btn btn-sm btn-secondary cancel-row d-none' title='Annulla'><i class='bi bi-x-lg'></i></button>
<button class='btn btn-sm btn-outline-danger delete-row' title='Elimina'><i class='bi bi-trash-fill'></i></button>
</td>
</tr>";
}
function selectOptions($arr, $sel = null, $val = 'id', $txt = 'nome')
{
$opt = '';
foreach ($arr as $a) {
$selected = ($sel !== null && $a[$val] == $sel) ? 'selected' : '';
$opt .= "<option value='{$a[$val]}' $selected>" . htmlspecialchars($a[$txt]) . "</option>";
}
return $opt;
}
?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<?php include('include/footer.php'); ?>
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/select2@4.1.0-rc.0/dist/js/select2.full.min.js"></script>
<script src="https://cdn.datatables.net/1.13.7/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.13.7/js/dataTables.bootstrap5.min.js"></script>
<script src="https://cdn.datatables.net/responsive/2.5.0/js/dataTables.responsive.min.js"></script>
<script src="https://cdn.datatables.net/responsive/2.5.0/js/responsive.bootstrap5.min.js"></script>
<?php include('jsinclude.php'); ?>
<script>
$(function() {
const table = $('#tabProgrammazione').DataTable({
responsive: true,
language: {
url: 'https://cdn.datatables.net/plug-ins/1.13.7/i18n/it-IT.json'
},
order: [
[12, 'desc'],
[0, 'desc']
],
columnDefs: [{
orderable: false,
targets: 14
},
{
responsivePriority: 1,
targets: 0
},
{
responsivePriority: 2,
targets: 14
},
{
targets: [1, 2, 3, 4, 13],
render: function(data, type, row, meta) {
if (type === 'filter') {
const td = table.cell(meta.row, meta.col).node();
const select = $(td).find('select.inline-edit');
return select.length ? select.val() || '' : $(data).text().trim();
}
return data;
}
}
],
pageLength: 25,
lengthMenu: [10, 25, 50, 100],
dom: '<"row"<"col-sm-12 col-md-6"l><"col-sm-12 col-md-6"f>>rtip',
initComplete: function() {
// Inizializza Select2
$('.filters-row .select2').select2({
theme: 'bootstrap-5',
width: '100%',
minimumResultsForSearch: 10
});
// Gestione filtri
$('.filters-row th').each(function(idx) {
const input = $(this).find('input, select');
if (!input.length) return;
if (input.is('select')) {
input.on('change', function() {
table.column(idx).search(this.value).draw();
});
} else {
input.on('keyup change', function() {
if (table.column(idx).search() !== this.value) {
table.column(idx).search(this.value).draw();
}
});
}
});
}
});
// --- INLINE EDIT ---
let original = {};
$('#tabProgrammazione').on('click', '.edit-row', function() {
const tr = $(this).closest('tr');
original = tr.find('.view').map((i, e) => $(e).text()).get();
tr.find('.view').hide();
tr.find('.inline-edit').show();
tr.find('.edit-row').addClass('d-none');
tr.find('.save-row, .cancel-row').removeClass('d-none');
tr.find('.inline-edit.select2').each(function() {
if (!$(this).hasClass('select2-hidden-accessible')) {
$(this).select2({
theme: 'bootstrap-5',
width: '100%'
});
}
});
});
$('#tabProgrammazione').on('click', '.cancel-row', function() {
const tr = $(this).closest('tr');
tr.find('.view').show().each((i, e) => $(e).text(original[i]));
tr.find('.inline-edit').hide();
tr.find('.edit-row').removeClass('d-none');
tr.find('.save-row, .cancel-row').addClass('d-none');
tr.find('.inline-edit.select2').select2('destroy');
});
$('#tabProgrammazione').on('click', '.save-row', function() {
const tr = $(this).closest('tr');
const data = tr.find('.inline-edit').serializeArray();
data.push({
name: 'action',
value: 'update'
}, {
name: 'id',
value: tr.data('id')
});
$.post('', data, r => r.success ? location.reload() : alert(r.msg || 'Errore'), 'json');
});
// --- RESTO INVARIATO ---
let deleteRow;
$('#tabProgrammazione').on('click', '.delete-row', function(e) {
e.preventDefault();
deleteRow = $(this).closest('tr');
$('#deleteId').val(deleteRow.data('id'));
const md = bootstrap.Modal.getOrCreateInstance(document.getElementById('modalDelete'));
md.show();
});
$('#confirmDelete').on('click', function() {
const id = $('#deleteId').val();
$.post('delete_productiondata.php', {
id
}, function(r) {
if (r.success) {
bootstrap.Modal.getInstance(document.getElementById('modalDelete')).hide();
deleteRow.fadeOut(300, () => deleteRow.remove());
} else alert(r.msg);
}, 'json');
});
$('#modalNuovo').on('shown.bs.modal', function() {
$(this).find('.select2').each(function() {
if (!$(this).hasClass('select2-hidden-accessible')) {
$(this).select2({
theme: 'bootstrap-5',
width: '100%'
});
}
});
});
$('#formNuovo').on('submit', function(e) {
e.preventDefault();
const data = $(this).serializeArray();
data.push({
name: 'action',
value: 'insert'
});
$.post('', data, r => r.success ? location.reload() : alert('Errore: ' + (r.msg || 'Fallito')), 'json');
});
$('#modalNuovo').on('hidden.bs.modal', function() {
$(this).find('form')[0].reset();
$(this).find('.select2').select2('destroy');
$('body').removeClass('modal-open');
$('.modal-backdrop').remove();
});
});
</script>
<!-- MODALE AGGIUNGI (identico) -->
<div class="modal fade" id="modalNuovo" tabindex="-1" aria-labelledby="modalNuovoLabel" aria-hidden="true">
<div class="modal-dialog modal-xl" style="max-width: 95vw;">
<div class="modal-content">
<form id="formNuovo">
<div class="modal-header">
<h5 class="modal-title" id="modalNuovoLabel">Aggiungi Programmazione</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Data</label>
<input type="date" class="form-control" name="Data" required>
</div>
<div class="col-md-6">
<label class="form-label">Data Produzione</label>
<input type="date" class="form-control" name="data_produzione" required>
</div>
<div class="col-md-6">
<label class="form-label">Matrice</label>
<select class="form-select select2" name="idmatrice" required>
<option value="">Seleziona...</option>
<?php foreach ($matrici as $m): ?>
<option value="<?= $m['id'] ?>"><?= htmlspecialchars($m['nome']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Mescola</label>
<select class="form-select select2" name="idmescola" required>
<option value="">Seleziona...</option>
<?php foreach ($mescole as $m): ?>
<option value="<?= $m['id'] ?>"><?= htmlspecialchars($m['nome']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Linea</label>
<select class="form-select select2" name="id_linea" required>
<option value="">Seleziona...</option>
<?php foreach ($linee as $l): ?>
<option value="<?= $l['id'] ?>"><?= htmlspecialchars($l['name']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Cliente</label>
<select class="form-select select2" name="id_cliente">
<option value="">Nessuno</option>
<?php foreach ($clienti as $c): ?>
<option value="<?= $c['id'] ?>"><?= htmlspecialchars($c['nome']) ?></option>
<?php endforeach; ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Data Zibo</label>
<input type="date" class="form-control" name="data_zibo">
</div>
<div class="col-md-6">
<label class="form-label">Data Cliente</label>
<input type="date" class="form-control" name="data_cliente">
</div>
<div class="col-md-3">
<label class="form-label">Metri</label>
<input type="number" step="0.01" class="form-control" name="metri" value="0">
</div>
<div class="col-md-3">
<label class="form-label">Kg SP</label>
<input type="number" step="0.01" class="form-control" name="kg_sp" value="0">
</div>
<div class="col-md-3">
<label class="form-label">Kg P</label>
<input type="number" step="0.01" class="form-control" name="kg_p" value="0">
</div>
<div class="col-md-3">
<label class="form-label">Ore Previste</label>
<input type="number" step="0.01" class="form-control" name="ore_previste" value="0">
</div>
<div class="col-12">
<label class="form-label">Note Extra</label>
<textarea class="form-control" name="note_extra" rows="2"></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Annulla</button>
<button type="submit" class="btn btn-primary">Salva</button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>