696 lines
35 KiB
PHP
696 lines
35 KiB
PHP
<?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">
|
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/flatpickr/dist/flatpickr.min.css">
|
|
|
|
<style>
|
|
.inline-edit {
|
|
display: none;
|
|
}
|
|
|
|
.btn-xs {
|
|
padding: 0.15rem 0.35rem;
|
|
font-size: 0.7rem;
|
|
line-height: 1.2;
|
|
border-radius: .4rem;
|
|
}
|
|
|
|
.btn-xs i {
|
|
font-size: 0.85rem;
|
|
}
|
|
|
|
.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-clear-filters {
|
|
margin-left: 0.5rem;
|
|
padding: 0.25rem 0.5rem;
|
|
font-size: 0.75rem;
|
|
}
|
|
|
|
.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;
|
|
}
|
|
|
|
.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;
|
|
}
|
|
|
|
/* ICONA NOTE */
|
|
.note-icon {
|
|
font-size: 1.1rem;
|
|
cursor: pointer;
|
|
transition: color 0.2s;
|
|
color: #6c757d;
|
|
}
|
|
|
|
.note-icon.has-note {
|
|
color: #dc3545 !important;
|
|
}
|
|
|
|
.note-icon:hover {
|
|
color: #0056b3;
|
|
}
|
|
|
|
#modalNoteView .modal-body {
|
|
white-space: pre-wrap;
|
|
max-height: 60vh;
|
|
overflow-y: auto;
|
|
font-size: 0.95rem;
|
|
}
|
|
|
|
/* Flatpickr nei filtri */
|
|
.flatpickr-input {
|
|
font-size: 0.75rem !important;
|
|
padding: 0.15rem 0.3rem !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>Data Zibo</th>
|
|
<th>Data 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="gg/mm/aaaa"></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="gg/mm/aaaa"></th>
|
|
<th><input type="text" class="filter-input form-control form-control-sm" placeholder="gg/mm/aaaa"></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="gg/mm/aaaa"></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'));
|
|
$hasNote = !empty($r['note_extra']);
|
|
|
|
echo "<tr data-id='{$r['id']}' style='background-color: {$lineColor} !important;'>
|
|
<td><span class='view'>" . date('d/m/Y', 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/Y', 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/Y', 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'>
|
|
<i class='bi bi-file-text note-icon " . ($hasNote ? 'has-note' : '') . "'
|
|
data-note='" . htmlspecialchars($r['note_extra'] ?? '') . "'
|
|
data-bs-toggle='modal' data-bs-target='#modalNoteView'></i>
|
|
</span>
|
|
<textarea class='inline-edit form-control form-control-sm' name='note_extra' rows='2'>" . htmlspecialchars($r['note_extra'] ?? '') . "</textarea>
|
|
</td>
|
|
<td><span class='view'>" . date('d/m/Y', 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-xs btn-outline-primary edit-row' title='Modifica'><i class='bi bi-pencil'></i></button>
|
|
<button class='btn btn-xs btn-success save-row d-none' title='Salva'><i class='bi bi-check-lg'></i></button>
|
|
<button class='btn btn-xs btn-secondary cancel-row d-none' title='Annulla'><i class='bi bi-x-lg'></i></button>
|
|
<button class='btn btn-xs 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>
|
|
|
|
<!-- MODALE VISUALIZZAZIONE NOTE -->
|
|
<div class="modal fade" id="modalNoteView" tabindex="-1" aria-hidden="true">
|
|
<div class="modal-dialog modal-lg">
|
|
<div class="modal-content">
|
|
<div class="modal-header">
|
|
<h5 class="modal-title">Note Extra</h5>
|
|
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
|
|
</div>
|
|
<div class="modal-body" id="noteContent">
|
|
<!-- Contenuto caricato via JS -->
|
|
</div>
|
|
<div class="modal-footer">
|
|
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Chiudi</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</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>
|
|
<script src="https://cdn.jsdelivr.net/npm/flatpickr"></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><"col-sm-12 col-md-3 offset-md-3" B>>rtip',
|
|
initComplete: function() {
|
|
// Inizializza Select2
|
|
$('.filters-row .select2').select2({
|
|
theme: 'bootstrap-5',
|
|
width: '100%',
|
|
minimumResultsForSearch: 10
|
|
});
|
|
|
|
// Inizializza Flatpickr sui filtri data
|
|
const dateInputs = $('.filters-row input[placeholder*="aaaa"]');
|
|
dateInputs.each(function() {
|
|
flatpickr(this, {
|
|
dateFormat: "d/m/Y",
|
|
allowInput: true,
|
|
onChange: function(selectedDates, dateStr, instance) {
|
|
const colIdx = $(instance.element).closest('th').index();
|
|
table.column(colIdx).search(dateStr).draw();
|
|
}
|
|
});
|
|
});
|
|
|
|
// Gestione filtri non-data
|
|
$('.filters-row th').each(function(idx) {
|
|
const input = $(this).find('input, select').not('[placeholder*="aaaa"]');
|
|
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();
|
|
}
|
|
});
|
|
}
|
|
});
|
|
|
|
// AGGIUNGI BOTTONE PULISCI FILTRO
|
|
$('.dataTables_filter').append(
|
|
'<button type="button" class="btn btn-outline-secondary btn-sm btn-clear-filters" title="Pulisci tutti i filtri">' +
|
|
'<i class="bi bi-x-circle"></i> Pulisci</button>'
|
|
);
|
|
}
|
|
});
|
|
|
|
// --- FUNZIONE PULISCI TUTTI I FILTRO ---
|
|
$(document).on('click', '.btn-clear-filters', function() {
|
|
// Svuota tutti i filtri DataTables
|
|
table.columns().search('').draw();
|
|
|
|
// Svuota campi testo
|
|
$('.filters-row input[type="text"]').val('');
|
|
|
|
// Svuota select
|
|
$('.filters-row select').val('').trigger('change');
|
|
|
|
// Svuota Flatpickr (date inputs)
|
|
$('.filters-row input[placeholder*="aaaa"]').each(function() {
|
|
const fpInstance = $(this).data('flatpickr');
|
|
if (fpInstance) {
|
|
fpInstance.clear();
|
|
fpInstance.setDate('');
|
|
} else {
|
|
$(this).val('');
|
|
}
|
|
});
|
|
|
|
// Svuota search principale
|
|
$('.dataTables_filter input').val('');
|
|
});
|
|
|
|
// --- APERTURA MODALE NOTE ---
|
|
$(document).on('click', '.note-icon', function() {
|
|
const note = $(this).data('note') || '';
|
|
$('#noteContent').text(note || '(Nessuna nota)');
|
|
});
|
|
|
|
// --- INLINE EDIT ---
|
|
let original = {};
|
|
$('#tabProgrammazione').on('click', '.edit-row', function() {
|
|
const tr = $(this).closest('tr');
|
|
original = tr.find('.view').map((i, e) => $(e).html()).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).html(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');
|
|
});
|
|
|
|
// --- ELIMINAZIONE ---
|
|
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');
|
|
});
|
|
|
|
// --- MODALE AGGIUNGI ---
|
|
$('#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 -->
|
|
<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>
|