marici foglio lavoro

This commit is contained in:
Claudio 2026-03-20 22:09:39 +01:00
parent 53b990ff40
commit d2f2a9089e
2 changed files with 1461 additions and 284 deletions

View File

@ -459,49 +459,371 @@ $isEdit = ($worksheet_id > 0);
<style>
body {
font-size: 0.95rem;
background: #f8fafc;
font-size: 0.96rem;
background:
radial-gradient(circle at top right, rgba(59, 130, 246, 0.08), transparent 24%),
radial-gradient(circle at bottom left, rgba(16, 185, 129, 0.07), transparent 28%),
#f4f7fb;
}
.card {
.page-title-wrap {
display: flex;
align-items: flex-start;
justify-content: space-between;
gap: 15px;
flex-wrap: wrap;
margin-bottom: 20px;
}
.page-title-box {
background: linear-gradient(135deg, #1d4ed8, #2563eb);
color: #fff;
border-radius: 20px;
padding: 22px 24px;
box-shadow: 0 14px 35px rgba(37, 99, 235, 0.18);
flex: 1 1 auto;
}
.page-title-box h4 {
color: #fff;
margin-bottom: 6px;
font-weight: 800;
}
.page-title-box .subtitle {
margin: 0;
color: rgba(255, 255, 255, 0.92);
font-size: 0.93rem;
}
.top-actions {
display: flex;
gap: 10px;
align-items: center;
flex-wrap: wrap;
}
.btn-history {
background: #fff !important;
color: #1f2937 !important;
border: 1px solid #dbe3ef !important;
border-radius: 12px;
font-weight: 700;
padding: 11px 18px;
box-shadow: 0 6px 18px rgba(15, 23, 42, 0.06);
}
.main-card {
border: 0;
border-radius: 22px;
overflow: hidden;
box-shadow: 0 12px 34px rgba(15, 23, 42, 0.08);
background: #fff;
}
.section-block {
border: 1px solid #e7edf5;
border-radius: 18px;
background: #fff;
box-shadow: 0 4px 12px rgba(15, 23, 42, 0.03);
overflow: hidden;
margin-bottom: 18px;
}
.section-header {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
padding: 14px 18px;
border-bottom: 1px solid rgba(255, 255, 255, 0.25);
}
.section-header h6 {
margin: 0;
font-size: 1rem;
font-weight: 800;
}
.section-header .section-hint {
font-size: 0.84rem;
opacity: 0.92;
margin: 0;
}
.section-body {
padding: 18px;
}
.theme-blue .section-header {
background: linear-gradient(135deg, #dbeafe, #bfdbfe);
color: #123b7a;
}
.theme-green .section-header {
background: linear-gradient(135deg, #dcfce7, #bbf7d0);
color: #14532d;
}
.theme-orange .section-header {
background: linear-gradient(135deg, #ffedd5, #fed7aa);
color: #9a3412;
}
.theme-purple .section-header {
background: linear-gradient(135deg, #ede9fe, #ddd6fe);
color: #5b21b6;
}
.theme-gray .section-header {
background: linear-gradient(135deg, #f3f4f6, #e5e7eb);
color: #374151;
}
.theme-cyan .section-header {
background: linear-gradient(135deg, #cffafe, #a5f3fc);
color: #155e75;
}
.section-grid-note {
font-size: 0.84rem;
color: #6b7280;
margin-top: -4px;
margin-bottom: 10px;
}
.form-label {
font-weight: 700;
color: #1f2937;
margin-bottom: 6px;
}
.form-control,
.form-select {
border-radius: 12px;
min-height: 46px;
border: 1px solid #d7e0ea;
box-shadow: none !important;
}
textarea.form-control {
min-height: auto;
}
.form-control:focus,
.form-select:focus {
border-color: #60a5fa;
}
.input-tip {
font-size: 0.79rem;
color: #6b7280;
margin-top: 4px;
}
.required-badge {
display: inline-flex;
align-items: center;
gap: 6px;
background: #fee2e2;
color: #991b1b;
border-radius: 999px;
padding: 5px 10px;
font-size: 0.77rem;
font-weight: 700;
}
.soft-badge {
display: inline-flex;
align-items: center;
gap: 6px;
background: #eef2ff;
color: #3730a3;
border-radius: 999px;
padding: 5px 10px;
font-size: 0.77rem;
font-weight: 700;
}
.action-bar {
position: sticky;
bottom: 12px;
z-index: 20;
background: rgba(255, 255, 255, 0.92);
backdrop-filter: blur(8px);
border: 1px solid #e5edf6;
border-radius: 18px;
padding: 14px;
box-shadow: 0 10px 28px rgba(15, 23, 42, 0.10);
margin-top: 14px;
}
.btn-main-save {
background: linear-gradient(135deg, #16a34a, #22c55e);
color: #fff;
border: 0;
border-radius: 12px;
padding: 12px 22px;
font-weight: 800;
box-shadow: 0 10px 24px rgba(34, 197, 94, 0.18);
}
.btn-main-save:hover {
color: #fff;
opacity: 0.96;
}
.btn-mix {
background: linear-gradient(135deg, #2563eb, #3b82f6);
color: #fff;
border: 0;
border-radius: 12px;
padding: 12px 20px;
font-weight: 800;
box-shadow: 0 10px 24px rgba(59, 130, 246, 0.18);
}
.btn-mix:disabled {
background: #cbd5e1;
box-shadow: none;
color: #fff;
}
.summary-strip {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 12px;
margin-bottom: 18px;
}
.summary-item {
background: #fff;
border: 1px solid #e5edf6;
border-radius: 16px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
padding: 14px 16px;
box-shadow: 0 6px 18px rgba(15, 23, 42, 0.04);
}
.back-dashboard {
background: #cfe3ff !important;
color: #1f2d3d !important;
border: 1px solid #bcd4f4 !important;
border-radius: 10px;
font-weight: 600;
padding: 10px 18px;
.summary-item .label {
font-size: 0.80rem;
color: #6b7280;
margin-bottom: 4px;
font-weight: 700;
}
.btn-add {
background: #0d6efd;
color: white;
border-radius: 8px;
padding: 10px 20px;
font-weight: 500;
.summary-item .value {
font-size: 1rem;
color: #111827;
font-weight: 800;
}
.table thead {
background: #cfe3ff;
color: #1f2d3d;
.table-wrap {
border: 1px solid #e5edf6;
border-radius: 18px;
overflow: hidden;
background: #fff;
}
.table thead th {
background: #e0efff !important;
color: #163a63;
font-weight: 800;
border-bottom: 1px solid #cde0f6 !important;
vertical-align: middle;
}
.table td {
vertical-align: middle;
}
.mix-table-title {
display: flex;
align-items: center;
justify-content: space-between;
gap: 12px;
flex-wrap: wrap;
margin-bottom: 14px;
}
.mix-table-title h5 {
margin: 0;
font-weight: 800;
color: #111827;
}
.mix-helper {
color: #6b7280;
font-size: 0.86rem;
}
.mini-pill {
display: inline-flex;
align-items: center;
border-radius: 999px;
padding: 4px 9px;
font-size: 0.75rem;
font-weight: 700;
background: #eef6ff;
color: #1d4ed8;
}
.modal-content {
border-radius: 16px;
border-radius: 20px;
overflow: hidden;
border: 0;
box-shadow: 0 18px 44px rgba(15, 23, 42, 0.18);
}
.section-title {
font-weight: 700;
color: #1f2d3d;
.modal-header {
border-bottom: 0;
padding: 16px 20px;
}
.small-hint {
color: #6b7280;
font-size: 0.85rem;
.modal-body {
padding: 20px;
}
.mix-modal-head {
background: linear-gradient(135deg, #dbeafe, #bfdbfe);
color: #123b7a;
}
.select2-container--bootstrap4 .select2-selection {
min-height: 46px !important;
border-radius: 12px !important;
border-color: #d7e0ea !important;
}
.select2-container--bootstrap4 .select2-selection--single .select2-selection__rendered {
line-height: 44px !important;
}
.select2-container--bootstrap4 .select2-selection--single .select2-selection__arrow {
height: 44px !important;
}
@media (max-width: 992px) {
.summary-strip {
grid-template-columns: repeat(2, minmax(0, 1fr));
}
}
@media (max-width: 576px) {
.summary-strip {
grid-template-columns: 1fr;
}
.page-title-box {
padding: 18px;
}
.section-body {
padding: 14px;
}
.action-bar {
padding: 12px;
}
}
</style>
</head>
@ -514,24 +836,56 @@ $isEdit = ($worksheet_id > 0);
<div class="page-wrapper">
<div class="page-content">
<div class="card p-3">
<div class="card-header d-flex justify-content-between align-items-center">
<div>
<h5 class="mb-0"><?= $isEdit ? 'Modifica Foglio di Lavoro' : 'Nuovo Foglio di Lavoro' ?></h5>
<div class="small-hint">Prima salva la testata, poi aggiungi le mescole con il modale</div>
<div class="page-title-wrap">
<div class="page-title-box">
<h4><?= $isEdit ? 'Modifica Foglio di Lavoro' : 'Nuovo Foglio di Lavoro' ?></h4>
<p class="subtitle">
Pagina pensata per uso operativo in produzione: prima salva la testata, poi inserisci le mescole
</p>
</div>
<div class="d-flex gap-2">
<button class="btn back-dashboard" onclick="location.href='worksheets.php'">↩️ Storico</button>
<div class="top-actions">
<button class="btn btn-history" onclick="location.href='worksheets.php'">↩️ Storico fogli</button>
</div>
</div>
<div class="card-body">
<div class="summary-strip">
<div class="summary-item">
<div class="label">Stato foglio</div>
<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>
<div class="summary-item">
<div class="label">Mescole inserite</div>
<div class="value"><?= count($mixRows) ?></div>
</div>
<div class="summary-item">
<div class="label">Passaggio operativo</div>
<div class="value"><?= $worksheet_id > 0 ? 'Puoi aggiungere mescole' : 'Salva prima la testata' ?></div>
</div>
</div>
<div class="card main-card">
<div class="card-body p-4 p-lg-4">
<form id="worksheetHeaderForm">
<input type="hidden" name="id" id="wsId" value="<?= (int)$worksheet_id ?>">
<div class="section-block theme-blue">
<div class="section-header">
<div>
<h6>1. Dati principali del foglio</h6>
<p class="section-hint mb-0">Campi iniziali per identificare il lavoro</p>
</div>
<div class="required-badge">Obbligatorio: matrice / profilo</div>
</div>
<div class="section-body">
<div class="row g-3">
<div class="col-md-6">
<label class="form-label fw-semibold">Matrice / Profilo *</label>
<div class="col-lg-6">
<label class="form-label">Matrice / Profilo *</label>
<select class="form-select" name="idmatrice" id="idmatrice" required>
<option value="">-- Seleziona --</option>
<?php foreach ($matrici as $m): ?>
@ -541,187 +895,263 @@ $isEdit = ($worksheet_id > 0);
</option>
<?php endforeach; ?>
</select>
<div class="input-tip">Seleziona il profilo da produrre</div>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Data foglio</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Data foglio</label>
<input type="date" class="form-control" name="worksheet_date"
value="<?= $worksheet ? h($worksheet['worksheet_date']) : '' ?>">
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Codice profilo</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Codice profilo</label>
<input type="text" class="form-control" name="profile_type_code"
value="<?= $worksheet ? h($worksheet['profile_type_code']) : '' ?>">
</div>
<div class="col-md-6">
<label class="form-label fw-semibold">Cliente (override)</label>
<div class="col-lg-6">
<label class="form-label">Cliente (override)</label>
<input type="text" class="form-control" name="customer_name"
value="<?= $worksheet ? h($worksheet['customer_name']) : '' ?>">
<div class="input-tip">Compila solo se vuoi specificare un nome cliente manuale</div>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Marchiatura</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Marchiatura</label>
<select class="form-select" name="marking" id="marking">
<?= ws_options($lookup['marking'] ?? [], $worksheet['marking'] ?? '', $lookupDefault['marking'] ?? '') ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Visto / Approvazione</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Visto / Approvazione</label>
<input type="text" class="form-control" name="approved_by"
value="<?= $worksheet ? h($worksheet['approved_by']) : '' ?>">
</div>
<div class="col-12">
<label class="form-label fw-semibold">Impostazione misure controllo produzione</label>
<textarea class="form-control" name="prod_control_measure_settings" rows="2"><?= $worksheet ? h($worksheet['prod_control_measure_settings']) : '' ?></textarea>
</div>
</div>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Controlli - Taglio</label>
<div class="section-block theme-green">
<div class="section-header">
<div>
<h6>2. Controlli di produzione</h6>
<p class="section-hint mb-0">Istruzioni e frequenze di controllo per loperatore</p>
</div>
<div class="soft-badge">Sezione operativa</div>
</div>
<div class="section-body">
<div class="row g-3">
<div class="col-12">
<label class="form-label">Impostazione misure controllo produzione</label>
<textarea class="form-control" name="prod_control_measure_settings" rows="3"><?= $worksheet ? h($worksheet['prod_control_measure_settings']) : '' ?></textarea>
</div>
<div class="col-lg-3 col-md-6">
<label class="form-label">Controlli - Taglio</label>
<select class="form-select" name="control_frequency_cut" id="control_frequency_cut">
<?= ws_options($lookup['control_frequency_cut'] ?? [], $worksheet['control_frequency_cut'] ?? '', $lookupDefault['control_frequency_cut'] ?? '') ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Controlli - Disegno</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Controlli - Disegno</label>
<select class="form-select" name="control_frequency_drawing" id="control_frequency_drawing">
<?= ws_options($lookup['control_frequency_drawing'] ?? [], $worksheet['control_frequency_drawing'] ?? '', $lookupDefault['control_frequency_drawing'] ?? '') ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Controlli - Dima</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Controlli - Dima</label>
<select class="form-select" name="control_frequency_jig" id="control_frequency_jig">
<?= ws_options($lookup['control_frequency_jig'] ?? [], $worksheet['control_frequency_jig'] ?? '', $lookupDefault['control_frequency_jig'] ?? '') ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Modalità dima</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Modalità dima</label>
<select class="form-select" name="control_mode_jig" id="control_mode_jig">
<?= ws_options($lookup['control_mode_jig'] ?? [], $worksheet['control_mode_jig'] ?? '', $lookupDefault['control_mode_jig'] ?? '') ?>
</select>
</div>
</div>
</div>
</div>
<div class="col-md-4">
<label class="form-label fw-semibold">Codice confezione</label>
<div class="section-block theme-orange">
<div class="section-header">
<div>
<h6>3. Imballo e confezionamento</h6>
<p class="section-hint mb-0">Dati per confezione, scatola e bancale</p>
</div>
<div class="soft-badge">Packaging</div>
</div>
<div class="section-body">
<div class="section-grid-note">Compila prima la confezione, poi eventuali dettagli di scatola e bancale</div>
<div class="row g-3">
<div class="col-lg-4">
<label class="form-label">Codice confezione</label>
<select class="form-select" name="requested_package_code" id="requested_package_code">
<?= packaging_options($packagingLookup['PACKAGING_TYPE'] ?? [], $worksheet['requested_package_code'] ?? '') ?>
</select>
</div>
<div class="col-md-4">
<label class="form-label fw-semibold">Metri per confezione</label>
<div class="col-lg-4 col-md-6">
<label class="form-label">Metri per confezione</label>
<input type="number" class="form-control" name="meters_per_package"
value="<?= $worksheet ? h($worksheet['meters_per_package']) : '' ?>">
</div>
<div class="col-md-4">
<label class="form-label fw-semibold">Tolleranza metri/confezione</label>
<div class="col-lg-4 col-md-6">
<label class="form-label">Tolleranza metri/confezione</label>
<input type="text" class="form-control" name="meters_per_package_tolerance"
value="<?= $worksheet ? h($worksheet['meters_per_package_tolerance']) : '' ?>"
placeholder="es. +/- 4m">
</div>
<div class="col-12">
<label class="form-label fw-semibold">Note metri/confezione</label>
<label class="form-label">Note metri/confezione</label>
<input type="text" class="form-control" name="meters_per_package_notes"
value="<?= $worksheet ? h($worksheet['meters_per_package_notes']) : '' ?>">
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Scatola (tipo)</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Scatola (tipo)</label>
<select class="form-select" name="box_type" id="box_type">
<?= packaging_options($packagingLookup['BOX'] ?? [], $worksheet['box_type'] ?? '') ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold"> conf./pezzi per scatola</label>
<div class="col-lg-3 col-md-6">
<label class="form-label"> conf./pezzi per scatola</label>
<input type="number" class="form-control" name="packages_or_pieces_per_box"
value="<?= $worksheet ? h($worksheet['packages_or_pieces_per_box']) : '' ?>">
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Metri per scatola</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Metri per scatola</label>
<input type="number" class="form-control" name="meters_per_box"
value="<?= $worksheet ? h($worksheet['meters_per_box']) : '' ?>">
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Bancale (tipo)</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Bancale (tipo)</label>
<select class="form-select" name="pallet_type" id="pallet_type">
<?= packaging_options($packagingLookup['PALLET'] ?? [], $worksheet['pallet_type'] ?? '') ?>
</select>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Scatole/conf. per bancale</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Scatole/conf. per bancale</label>
<input type="number" class="form-control" name="boxes_or_packages_per_pallet"
value="<?= $worksheet ? h($worksheet['boxes_or_packages_per_pallet']) : '' ?>">
</div>
</div>
</div>
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Vel. prevista (kg/h)</label>
<div class="section-block theme-purple">
<div class="section-header">
<div>
<h6>4. Velocità di produzione</h6>
<p class="section-hint mb-0">Confronto tra velocità prevista ed effettiva</p>
</div>
<div class="soft-badge">Prestazioni linea</div>
</div>
<div class="section-body">
<div class="row g-3">
<div class="col-lg-3 col-md-6">
<label class="form-label">Vel. prevista (kg/h)</label>
<input type="number" step="0.01" class="form-control" name="speed_expected_kg_h"
value="<?= $worksheet ? h($worksheet['speed_expected_kg_h']) : '' ?>">
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Vel. effettiva (kg/h)</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Vel. effettiva (kg/h)</label>
<input type="number" step="0.01" class="form-control" name="speed_actual_kg_h"
value="<?= $worksheet ? h($worksheet['speed_actual_kg_h']) : '' ?>">
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Vel. prevista (m/h)</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Vel. prevista (m/h)</label>
<input type="number" step="0.01" class="form-control" name="speed_expected_m_h"
value="<?= $worksheet ? h($worksheet['speed_expected_m_h']) : '' ?>">
</div>
<div class="col-md-3">
<label class="form-label fw-semibold">Vel. effettiva (m/h)</label>
<div class="col-lg-3 col-md-6">
<label class="form-label">Vel. effettiva (m/h)</label>
<input type="number" step="0.01" class="form-control" name="speed_actual_m_h"
value="<?= $worksheet ? h($worksheet['speed_actual_m_h']) : '' ?>">
</div>
<div class="col-12">
<label class="form-label fw-semibold">Note</label>
<textarea class="form-control" name="notes" rows="2"><?= $worksheet ? h($worksheet['notes']) : '' ?></textarea>
</div>
</div>
</div>
<div class="col-12 d-flex justify-content-center gap-2 mt-2">
<button type="submit" class="btn btn-add">💾 Salva Testata</button>
<button type="button" class="btn btn-outline-primary"
<div class="section-block theme-gray">
<div class="section-header">
<div>
<h6>5. Note finali</h6>
<p class="section-hint mb-0">Annotazioni operative o indicazioni aggiuntive</p>
</div>
<div class="soft-badge">Facoltativo</div>
</div>
<div class="section-body">
<div class="row g-3">
<div class="col-12">
<label class="form-label">Note</label>
<textarea class="form-control" name="notes" rows="3"><?= $worksheet ? h($worksheet['notes']) : '' ?></textarea>
</div>
</div>
</div>
</div>
<div class="action-bar">
<div class="d-flex flex-column flex-md-row justify-content-between align-items-center gap-3">
<div>
<div class="fw-bold text-dark">Flusso consigliato</div>
<div class="text-muted small">1. Compila la testata 2. Salva 3. Aggiungi una o più mescole</div>
</div>
<div class="d-flex gap-2 flex-wrap">
<button type="submit" class="btn btn-main-save">💾 Salva testata</button>
<button type="button" class="btn btn-mix"
id="btnAddMix" data-bs-toggle="modal" data-bs-target="#mixModal" disabled>
Aggiungi Mescola
Aggiungi mescola
</button>
</div>
</div>
</div>
</form>
<hr class="my-4">
<div class="d-flex justify-content-between align-items-center mb-2">
<div class="section-title">Mescole associate al foglio</div>
<div class="small-hint">Usa “Aggiungi Mescola” per inserire una o più righe</div>
<div class="section-block theme-cyan mt-4 mb-0">
<div class="section-header">
<div>
<h6>6. Mescole associate al foglio</h6>
<p class="section-hint mb-0">Inserisci una o più righe mescola dopo il salvataggio della testata</p>
</div>
<div class="mini-pill"><?= count($mixRows) ?> righe</div>
</div>
<div class="section-body">
<div class="mix-table-title">
<div>
<h5>Elenco mescole</h5>
<div class="mix-helper">Puoi modificare o eliminare ogni riga direttamente dalla tabella</div>
</div>
</div>
<div class="table-wrap">
<div class="table-responsive">
<table id="tabellaMixRows" class="table table-striped table-bordered">
<table id="tabellaMixRows" class="table table-striped table-bordered mb-0">
<thead>
<tr>
<th>Pos</th>
<th style="width:70px;">Pos</th>
<th>Mescola</th>
<th>Peso (g/m)</th>
<th>Densità</th>
<th>Durezza</th>
<th>Lubr.</th>
<th>Azioni</th>
<th style="width:120px;">Peso (g/m)</th>
<th style="width:140px;">Densità</th>
<th style="width:150px;">Durezza</th>
<th style="width:120px;">Lubr.</th>
<th style="width:170px;">Azioni</th>
</tr>
</thead>
<tbody>
@ -729,9 +1159,9 @@ $isEdit = ($worksheet_id > 0);
<tr>
<td><?= (int)$r['mix_position'] ?></td>
<td>
<?= h($r['mescola_nome'] ?? '-') ?>
<div class="fw-bold"><?= h($r['mescola_nome'] ?? '-') ?></div>
<?php if (!empty($r['mescola_uscita'])): ?>
<div class="small-hint"><?= h($r['mescola_uscita']) ?></div>
<div class="text-muted small"><?= h($r['mescola_uscita']) ?></div>
<?php endif; ?>
</td>
<td><?= h($r['mix_weight_g_m'] ?? '-') ?></td>
@ -753,6 +1183,10 @@ $isEdit = ($worksheet_id > 0);
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
@ -765,20 +1199,24 @@ $isEdit = ($worksheet_id > 0);
<!-- MODAL MIX -->
<div class="modal fade" id="mixModal" tabindex="-1">
<div class="modal-dialog modal-lg">
<div class="modal-dialog modal-lg modal-dialog-centered">
<div class="modal-content">
<div class="modal-header" style="background:#cfe3ff;">
<h5 class="modal-title" id="mixModalTitle">Aggiungi Mescola</h5>
<div class="modal-header mix-modal-head">
<div>
<h5 class="modal-title mb-1" id="mixModalTitle">Aggiungi Mescola</h5>
<div class="small">Compila i dati della mescola da associare al foglio</div>
</div>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<form id="mixForm">
<input type="hidden" name="worksheet_id" id="mixWorksheetId" value="<?= (int)$worksheet_id ?>">
<input type="hidden" name="row_id" id="mixRowId" value="0">
<input type="hidden" name="mix_position" id="mix_position" value="">
<div class="row g-3">
<div class="col-md-8">
<label class="form-label fw-semibold">Mescola *</label>
<div class="col-lg-8">
<label class="form-label">Mescola *</label>
<select class="form-select" name="idmescola" id="idmescola" required>
<option value="">-- Seleziona --</option>
<?php foreach ($mescole as $me): ?>
@ -789,37 +1227,35 @@ $isEdit = ($worksheet_id > 0);
</select>
</div>
<input type="hidden" name="mix_position" id="mix_position" value="">
<div class="col-md-4">
<label class="form-label fw-semibold">Peso metro mescola (g/m)</label>
<div class="col-lg-4">
<label class="form-label">Peso metro mescola (g/m)</label>
<input type="number" step="0.01" class="form-control" name="mix_weight_g_m" id="mix_weight_g_m">
</div>
<div class="col-md-4">
<label class="form-label fw-semibold">Densità richiesta</label>
<div class="col-lg-4">
<label class="form-label">Densità richiesta</label>
<input type="text" class="form-control" name="required_density" id="required_density" placeholder="es. 1,22 +/- 0,03">
</div>
<div class="col-md-4">
<label class="form-label fw-semibold">Durezza richiesta (shore A)</label>
<div class="col-lg-4">
<label class="form-label">Durezza richiesta (shore A)</label>
<input type="text" class="form-control" name="required_hardness_shore_a" id="required_hardness_shore_a" placeholder="es. 70 +/- 5">
</div>
<div class="col-md-4">
<label class="form-label fw-semibold">Lubrificazione</label>
<div class="col-lg-4">
<label class="form-label">Lubrificazione</label>
<select class="form-select" name="lubrication_type" id="lubrication_type">
<?= ws_options($lookup['lubrication_type'] ?? [], '', $lookupDefault['lubrication_type'] ?? '') ?>
</select>
</div>
<div class="col-md-8">
<label class="form-label fw-semibold">Note lubrificazione</label>
<div class="col-12">
<label class="form-label">Note lubrificazione</label>
<input type="text" class="form-control" name="lubrication_notes" id="lubrication_notes">
</div>
<div class="col-12 text-center mt-2">
<button type="submit" class="btn btn-add">💾 Salva Mescola</button>
<button type="submit" class="btn btn-main-save">💾 Salva mescola</button>
</div>
</div>
</form>
@ -834,6 +1270,7 @@ $isEdit = ($worksheet_id > 0);
$(document).ready(function() {
const wsIdInput = $('#wsId');
const btnAddMix = $('#btnAddMix');
const summaryWsId = $('#summaryWsId');
if ($('#idmatrice').length) {
$('#idmatrice').select2({
@ -861,9 +1298,11 @@ $isEdit = ($worksheet_id > 0);
if (id > 0) {
btnAddMix.prop('disabled', false);
$('#mixWorksheetId').val(id);
summaryWsId.text(id);
} else {
btnAddMix.prop('disabled', true);
$('#mixWorksheetId').val('0');
summaryWsId.text('Non salvato');
}
}
enableMixButtonIfSaved();

View File

@ -1,4 +1,226 @@
<?php include('include/headscript.php'); ?>
<?php
ob_start();
ini_set('display_errors', 1);
error_reporting(E_ALL);
include('include/headscript.php');
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
/**
* Helpers
*/
function h($v)
{
return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8');
}
function formatDateIT($d)
{
if (!$d || $d === '0000-00-00') return '';
return date("d/m/Y", strtotime($d));
}
function formatDateTimeIT($d)
{
if (!$d || $d === '0000-00-00 00:00:00') return '';
return date("d/m/Y H:i", strtotime($d));
}
function formatNullable($v, $fallback = '—')
{
$v = trim((string)$v);
return $v !== '' ? $v : $fallback;
}
/**
* AJAX HANDLERS
*/
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['ajax']) && $_POST['ajax'] == '1') {
while (ob_get_level()) {
ob_end_clean();
}
header('Content-Type: application/json; charset=utf-8');
$action = $_POST['action'] ?? '';
try {
if ($action === 'get_matrice_worksheets') {
$idmatrice = isset($_POST['idmatrice']) ? (int)$_POST['idmatrice'] : 0;
if ($idmatrice <= 0) {
echo json_encode([
'success' => false,
'message' => 'ID matrice non valido'
]);
exit;
}
$stmt = $pdo->prepare("
SELECT
ws.id,
ws.idmatrice,
ws.worksheet_date,
ws.customer_name,
ws.profile_type_code,
ws.marking,
ws.approved_by,
ws.created_at,
ws.updated_at,
(
SELECT COUNT(*)
FROM work_sheet_mescole wsm
WHERE wsm.worksheet_id = ws.id
) AS mix_count
FROM work_sheets ws
WHERE ws.idmatrice = ?
ORDER BY
CASE WHEN ws.worksheet_date IS NULL THEN 1 ELSE 0 END,
ws.worksheet_date DESC,
ws.id DESC
");
$stmt->execute([$idmatrice]);
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
$data = [];
foreach ($rows as $r) {
$data[] = [
'id' => (int)$r['id'],
'idmatrice' => (int)$r['idmatrice'],
'worksheet_date' => $r['worksheet_date'],
'worksheet_date_it' => formatDateIT($r['worksheet_date']),
'customer_name' => $r['customer_name'] ?? '',
'profile_type_code' => $r['profile_type_code'] ?? '',
'marking' => $r['marking'] ?? '',
'approved_by' => $r['approved_by'] ?? '',
'created_at' => $r['created_at'] ?? '',
'created_at_it' => formatDateTimeIT($r['created_at'] ?? ''),
'updated_at' => $r['updated_at'] ?? '',
'updated_at_it' => formatDateTimeIT($r['updated_at'] ?? ''),
'mix_count' => (int)($r['mix_count'] ?? 0)
];
}
echo json_encode([
'success' => true,
'worksheets' => $data
]);
exit;
}
if ($action === 'get_worksheet_detail') {
$worksheetId = isset($_POST['worksheet_id']) ? (int)$_POST['worksheet_id'] : 0;
if ($worksheetId <= 0) {
echo json_encode([
'success' => false,
'message' => 'ID foglio non valido'
]);
exit;
}
$stmt = $pdo->prepare("
SELECT
ws.*,
m.nome AS matrice_nome,
m.cliente AS matrice_cliente
FROM work_sheets ws
LEFT JOIN matrice m ON m.id = ws.idmatrice
WHERE ws.id = ?
LIMIT 1
");
$stmt->execute([$worksheetId]);
$ws = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$ws) {
echo json_encode([
'success' => false,
'message' => 'Foglio di lavoro non trovato'
]);
exit;
}
$stmtMix = $pdo->prepare("
SELECT
wsm.*,
me.nome AS mescola_nome,
me.nomeuscita AS mescola_uscita
FROM work_sheet_mescole wsm
LEFT JOIN mescole me ON me.id = wsm.idmescola
WHERE wsm.worksheet_id = ?
ORDER BY wsm.mix_position ASC, wsm.id ASC
");
$stmtMix->execute([$worksheetId]);
$mixRows = $stmtMix->fetchAll(PDO::FETCH_ASSOC);
echo json_encode([
'success' => true,
'worksheet' => [
'id' => (int)$ws['id'],
'idmatrice' => (int)$ws['idmatrice'],
'matrice_nome' => $ws['matrice_nome'] ?? '',
'matrice_cliente' => $ws['matrice_cliente'] ?? '',
'worksheet_date' => $ws['worksheet_date'] ?? '',
'worksheet_date_it' => formatDateIT($ws['worksheet_date'] ?? ''),
'customer_name' => $ws['customer_name'] ?? '',
'profile_type_code' => $ws['profile_type_code'] ?? '',
'marking' => $ws['marking'] ?? '',
'prod_control_measure_settings' => $ws['prod_control_measure_settings'] ?? '',
'control_frequency_cut' => $ws['control_frequency_cut'] ?? '',
'control_frequency_drawing' => $ws['control_frequency_drawing'] ?? '',
'control_frequency_jig' => $ws['control_frequency_jig'] ?? '',
'control_mode_jig' => $ws['control_mode_jig'] ?? '',
'requested_package_code' => $ws['requested_package_code'] ?? '',
'meters_per_package' => $ws['meters_per_package'] ?? '',
'meters_per_package_tolerance' => $ws['meters_per_package_tolerance'] ?? '',
'meters_per_package_notes' => $ws['meters_per_package_notes'] ?? '',
'box_type' => $ws['box_type'] ?? '',
'packages_or_pieces_per_box' => $ws['packages_or_pieces_per_box'] ?? '',
'meters_per_box' => $ws['meters_per_box'] ?? '',
'pallet_type' => $ws['pallet_type'] ?? '',
'boxes_or_packages_per_pallet' => $ws['boxes_or_packages_per_pallet'] ?? '',
'speed_expected_kg_h' => $ws['speed_expected_kg_h'] ?? '',
'speed_actual_kg_h' => $ws['speed_actual_kg_h'] ?? '',
'speed_expected_m_h' => $ws['speed_expected_m_h'] ?? '',
'speed_actual_m_h' => $ws['speed_actual_m_h'] ?? '',
'approved_by' => $ws['approved_by'] ?? '',
'notes' => $ws['notes'] ?? '',
'created_at' => $ws['created_at'] ?? '',
'created_at_it' => formatDateTimeIT($ws['created_at'] ?? ''),
'updated_at' => $ws['updated_at'] ?? '',
'updated_at_it' => formatDateTimeIT($ws['updated_at'] ?? '')
],
'mix_rows' => array_map(function ($r) {
return [
'id' => (int)$r['id'],
'mix_position' => (int)$r['mix_position'],
'mescola_nome' => $r['mescola_nome'] ?? '',
'mescola_uscita' => $r['mescola_uscita'] ?? '',
'mix_weight_g_m' => $r['mix_weight_g_m'] ?? '',
'required_density' => $r['required_density'] ?? '',
'required_hardness_shore_a' => $r['required_hardness_shore_a'] ?? '',
'lubrication_type' => $r['lubrication_type'] ?? '',
'lubrication_notes' => $r['lubrication_notes'] ?? ''
];
}, $mixRows)
]);
exit;
}
echo json_encode([
'success' => false,
'message' => 'Azione AJAX sconosciuta'
]);
exit;
} catch (Exception $e) {
echo json_encode([
'success' => false,
'message' => $e->getMessage()
]);
exit;
}
}
?>
<!doctype html>
<html lang="it">
@ -57,6 +279,21 @@
font-weight: 600;
}
.btn-worksheets {
background: linear-gradient(135deg, #0d6efd, #3b82f6);
color: #fff;
border: none;
border-radius: 10px;
padding: 10px 18px;
font-weight: 700;
box-shadow: 0 6px 16px rgba(13, 110, 253, 0.18);
}
.btn-worksheets:hover {
color: #fff;
opacity: .95;
}
.table thead {
background-color: #b9ebc7;
text-align: center;
@ -90,6 +327,10 @@
color: #0dcaf0;
}
.worksheets {
color: #0d6efd;
}
.thumb-img:hover {
transform: scale(1.05);
transition: 0.2s;
@ -172,14 +413,20 @@
#tabellaMatrici th:nth-child(4),
#tabellaMatrici td:nth-child(4) {
width: 220px;
max-width: 220px;
width: 240px;
max-width: 240px;
}
#tabellaMatrici th:nth-child(5),
#tabellaMatrici td:nth-child(5) {
width: 220px;
max-width: 220px;
width: 130px;
max-width: 130px;
}
#tabellaMatrici th:nth-child(6),
#tabellaMatrici td:nth-child(6) {
width: 260px;
max-width: 260px;
}
#tabellaMatrici td:nth-child(1) img {
@ -276,6 +523,16 @@
width: 95vw;
}
.modal-worksheet-list {
max-width: 980px;
width: 94vw;
}
.modal-worksheet-view {
max-width: 1500px;
width: 97vw;
}
.section-box {
background: #f8fafc;
border: 1px solid #e9ecef;
@ -289,6 +546,129 @@
text-align: center;
padding: 18px 8px;
}
.worksheet-chip {
display: inline-flex;
align-items: center;
gap: 6px;
padding: 4px 10px;
border-radius: 999px;
background: #e7f1ff;
color: #0d6efd;
font-weight: 700;
font-size: .82rem;
}
.worksheet-counter-badge {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 34px;
height: 34px;
border-radius: 999px;
background: linear-gradient(135deg, #0d6efd, #3b82f6);
color: #fff;
font-weight: 800;
font-size: .95rem;
box-shadow: 0 4px 12px rgba(13, 110, 253, 0.22);
}
.worksheet-counter-zero {
background: #e9ecef;
color: #6c757d;
box-shadow: none;
}
.worksheet-list-table th {
background: #e7f1ff !important;
color: #0b3d91;
}
.readonly-card {
border: 1px solid #e9ecef;
border-radius: 16px;
background: #fff;
overflow: hidden;
box-shadow: 0 2px 8px rgba(0, 0, 0, .04);
height: 100%;
}
.readonly-card-header {
background: linear-gradient(135deg, #e7f1ff, #d6e9ff);
color: #0b3d91;
font-weight: 800;
padding: 12px 16px;
border-bottom: 1px solid #cfe2ff;
}
.readonly-card-body {
padding: 16px;
}
.readonly-grid {
display: grid;
grid-template-columns: 220px 1fr;
gap: 8px 16px;
}
.readonly-label {
font-weight: 700;
color: #495057;
}
.readonly-value {
color: #1f2d3d;
word-break: break-word;
}
.worksheet-open-link {
background: #fff;
border: 1px solid #b6d4fe;
color: #0d6efd;
font-weight: 700;
border-radius: 10px;
padding: 9px 14px;
text-decoration: none;
display: inline-flex;
align-items: center;
gap: 8px;
}
.worksheet-open-link:hover {
color: #0a58ca;
background: #f4f9ff;
}
.worksheet-title-box {
background: linear-gradient(135deg, #0d6efd, #3b82f6);
color: #fff;
border-radius: 18px;
padding: 18px 20px;
box-shadow: 0 8px 24px rgba(13, 110, 253, 0.2);
}
.worksheet-title-box small {
color: rgba(255, 255, 255, .9);
}
.mix-readonly-table thead th {
background: #dbeafe !important;
color: #0b3d91;
}
.btn-view-worksheet {
background: linear-gradient(135deg, #0d6efd, #3b82f6);
color: #fff;
border: 0;
border-radius: 8px;
padding: 8px 14px;
font-weight: 700;
}
.btn-view-worksheet:hover {
color: #fff;
opacity: .95;
}
</style>
</head>
@ -321,21 +701,20 @@
<th>Nome</th>
<th>Cliente</th>
<th>Linee</th>
<th>Fogli</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php
$db = DBHandlerSelect::getInstance();
$pdo = $db->getConnection();
$stmt = $pdo->query("
SELECT
m.*,
COALESCE(lg.linee_associate, '—') AS linee_associate,
COALESCE(mg.mescole_associate, '') AS mescole_associate,
COALESCE(mg.mescole_count, 0) AS mescole_count
COALESCE(mg.mescole_count, 0) AS mescole_count,
COALESCE(wsg.worksheets_count, 0) AS worksheets_count
FROM matrice m
LEFT JOIN (
SELECT
@ -354,19 +733,20 @@
JOIN mescole ms ON ms.id = mm.idmescola
GROUP BY mm.idmatrice
) mg ON mg.idmatrice = m.id
LEFT JOIN (
SELECT
ws.idmatrice,
COUNT(*) AS worksheets_count
FROM work_sheets ws
GROUP BY ws.idmatrice
) wsg ON wsg.idmatrice = m.id
ORDER BY
CASE WHEN TRIM(COALESCE(m.nome, '')) = '' THEN 1 ELSE 0 END,
m.nome ASC
");
function formatDateIT($d)
{
if (!$d || $d == '0000-00-00') return '';
return date("d/m/Y", strtotime($d));
}
if ($stmt->rowCount() === 0) {
echo "<tr><td colspan='5' class='text-muted'>Nessuna matrice presente</td></tr>";
echo "<tr><td colspan='6' class='text-muted'>Nessuna matrice presente</td></tr>";
} else {
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$dataIT = formatDateIT($row['data_produzione']);
@ -411,6 +791,7 @@
$lineeTxt = $row['linee_associate'] ?? '—';
$mescoleTxt = $row['mescole_associate'] ?? '';
$mescoleCount = (int)($row['mescole_count'] ?? 0);
$worksheetsCount = (int)($row['worksheets_count'] ?? 0);
$btnMescole = '';
if ($mescoleCount > 0) {
@ -428,6 +809,26 @@
. $btnMescole
. "</td>";
echo "<td>
<div class='d-flex justify-content-center align-items-center gap-2'>
<span class='worksheet-counter-badge " . ($worksheetsCount <= 0 ? "worksheet-counter-zero" : "") . "'>{$worksheetsCount}</span>";
if ($worksheetsCount > 0) {
echo "<button type='button'
class='btn btn-sm btn-outline-primary show-worksheets'
data-id='" . (int)$row['id'] . "'
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
data-bs-toggle='tooltip'
data-bs-title='Apri fogli di lavoro collegati'>
<i class='fa-solid fa-clipboard-list'></i>
</button>";
} else {
echo "<span class='text-muted small'>—</span>";
}
echo " </div>
</td>";
echo "<td>
<button class='action-btn edit'
data-id='{$row['id']}'
@ -458,6 +859,13 @@
<i class='fa-solid fa-flask'></i>
</button>
<button class='action-btn worksheets'
data-id='{$row['id']}'
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
data-bs-toggle='tooltip' data-bs-title='Fogli di lavoro profilo'>
<i class='fa-solid fa-clipboard-list'></i>
</button>
<button class='action-btn files'
data-id='{$row['id']}'
data-nome='" . htmlspecialchars($row['nome'], ENT_QUOTES) . "'
@ -696,6 +1104,67 @@
</div>
</div>
<!-- MODALE LISTA FOGLI DI LAVORO -->
<div class="modal fade" id="worksheetsListModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-worksheet-list">
<div class="modal-content">
<div class="modal-header" style="background:linear-gradient(135deg,#e7f1ff,#d6e9ff);">
<div>
<h5 class="modal-title mb-0">
<i class="fa-solid fa-clipboard-list me-2"></i>Fogli di lavoro collegati
</h5>
<small class="text-muted">Elenco fogli associati al profilo selezionato</small>
</div>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<input type="hidden" id="wl_idmatrice">
<div class="fw-semibold mb-3" id="wl_matrice_name" style="color:#0b3d91;"></div>
<div id="worksheetsListContainer">
<div class="text-muted">Caricamento fogli di lavoro...</div>
</div>
</div>
</div>
</div>
</div>
<!-- MODALE DETTAGLIO FOGLIO DI LAVORO -->
<div class="modal fade" id="worksheetDetailModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-worksheet-view">
<div class="modal-content" style="min-height:92vh;">
<div class="modal-header" style="background:linear-gradient(135deg,#ede9fe,#ddd6fe);">
<div>
<h5 class="modal-title mb-0">
<i class="fa-solid fa-file-lines me-2"></i>Dettaglio foglio di lavoro
</h5>
<small class="text-muted">Visualizzazione completa in sola lettura</small>
</div>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body" id="worksheetDetailContainer">
<div class="text-muted">Caricamento dettaglio foglio...</div>
</div>
</div>
</div>
</div>
<!-- MODALE PREVIEW FILE -->
<div class="modal fade" id="filePreviewModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" style="max-width:1400px; width:98vw;">
<div class="modal-content" style="height:92vh;">
<div class="modal-header" style="background-color:#b9ebc7;">
<h5 class="modal-title" id="filePreviewTitle">Anteprima file</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div id="filePreviewContainer" style="height:calc(92vh - 64px); overflow:hidden; background:#f8fafc;"></div>
</div>
</div>
</div>
<?php include('jsinclude.php'); ?>
<script>
@ -752,6 +1221,17 @@
return ['jpg', 'jpeg', 'png', 'gif', 'bmp', 'webp', 'heic', 'heif'].includes(ext);
}
function valueOrDash(v) {
return (v === null || v === undefined || String(v).trim() === '') ? '—' : escapeHtml(v);
}
function renderReadonlyField(label, value) {
return `
<div class="readonly-label">${escapeHtml(label)}</div>
<div class="readonly-value">${valueOrDash(value)}</div>
`;
}
let selectedAttachmentFiles = [];
function renderSelectedAttachments() {
@ -941,6 +1421,262 @@
modal.show();
}
function loadMatriceWorksheets(idmatrice, matriceNome) {
$("#wl_idmatrice").val(idmatrice);
$("#wl_matrice_name").html(`<span class="worksheet-chip"><i class="fa-solid fa-layer-group"></i>${escapeHtml(matriceNome || '')}</span>`);
$("#worksheetsListContainer").html('<div class="text-muted">Caricamento fogli di lavoro...</div>');
fetch(window.location.href, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'ajax=1&action=get_matrice_worksheets&idmatrice=' + encodeURIComponent(idmatrice)
})
.then(r => r.json())
.then(data => {
if (!data.success) {
$("#worksheetsListContainer").html('<div class="text-danger">Errore nel caricamento dei fogli</div>');
return;
}
const rows = data.worksheets || [];
if (!rows.length) {
$("#worksheetsListContainer").html('<div class="text-muted">Nessun foglio di lavoro collegato a questo profilo</div>');
return;
}
let html = `
<div class="table-responsive">
<table class="table table-striped align-middle worksheet-list-table">
<thead>
<tr>
<th style="width:90px;">ID</th>
<th style="width:140px;">Data foglio</th>
<th>Cliente</th>
<th>Codice profilo</th>
<th style="width:110px;">Mescole</th>
<th style="width:230px;">Azioni</th>
</tr>
</thead>
<tbody>
`;
rows.forEach(r => {
html += `
<tr>
<td><strong>#${r.id}</strong></td>
<td>${escapeHtml(r.worksheet_date_it || '—')}</td>
<td title="${escapeHtml(r.customer_name || '')}">${escapeHtml(r.customer_name || '—')}</td>
<td>${escapeHtml(r.profile_type_code || '—')}</td>
<td>${escapeHtml(String(r.mix_count || 0))}</td>
<td class="text-nowrap">
<button type="button"
class="btn btn-view-worksheet open-worksheet-detail"
data-id="${r.id}">
<i class="fa-solid fa-eye me-1"></i>Apri dettaglio
</button>
<a class="worksheet-open-link ms-1"
href="manage-worksheet.php?id=${r.id}"
target="_blank">
<i class="fa-solid fa-arrow-up-right-from-square"></i>Apri pagina
</a>
</td>
</tr>
`;
});
html += `
</tbody>
</table>
</div>
`;
$("#worksheetsListContainer").html(html);
})
.catch(() => {
$("#worksheetsListContainer").html('<div class="text-danger">Errore nel caricamento dei fogli</div>');
});
}
function loadWorksheetDetail(worksheetId) {
$("#worksheetDetailContainer").html('<div class="text-muted">Caricamento dettaglio foglio...</div>');
fetch(window.location.href, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
body: 'ajax=1&action=get_worksheet_detail&worksheet_id=' + encodeURIComponent(worksheetId)
})
.then(r => r.json())
.then(data => {
if (!data.success) {
$("#worksheetDetailContainer").html('<div class="text-danger">Errore nel caricamento del dettaglio foglio</div>');
return;
}
const ws = data.worksheet || {};
const mixRows = data.mix_rows || [];
let mixHtml = `
<div class="text-muted">Nessuna mescola associata</div>
`;
if (mixRows.length) {
mixHtml = `
<div class="table-responsive">
<table class="table table-striped align-middle mix-readonly-table">
<thead>
<tr>
<th style="width:80px;">Pos</th>
<th>Mescola</th>
<th style="width:120px;">Peso g/m</th>
<th style="width:140px;">Densità</th>
<th style="width:150px;">Durezza</th>
<th style="width:130px;">Lubr.</th>
<th>Note lubr.</th>
</tr>
</thead>
<tbody>
`;
mixRows.forEach(r => {
const nomeMescola = r.mescola_uscita ?
`${escapeHtml(r.mescola_nome || '—')} <div class="small text-muted">${escapeHtml(r.mescola_uscita)}</div>` :
escapeHtml(r.mescola_nome || '—');
mixHtml += `
<tr>
<td>${escapeHtml(String(r.mix_position || ''))}</td>
<td>${nomeMescola}</td>
<td>${valueOrDash(r.mix_weight_g_m)}</td>
<td>${valueOrDash(r.required_density)}</td>
<td>${valueOrDash(r.required_hardness_shore_a)}</td>
<td>${valueOrDash(r.lubrication_type)}</td>
<td>${valueOrDash(r.lubrication_notes)}</td>
</tr>
`;
});
mixHtml += `
</tbody>
</table>
</div>
`;
}
const html = `
<div class="worksheet-title-box mb-4">
<div class="d-flex justify-content-between align-items-start gap-3 flex-wrap">
<div>
<h4 class="mb-1">Foglio di lavoro #${escapeHtml(String(ws.id || ''))}</h4>
<small>Profilo: ${escapeHtml(ws.matrice_nome || '—')} ${ws.matrice_cliente ? '• Cliente matrice: ' + escapeHtml(ws.matrice_cliente) : ''}</small>
</div>
<div>
<a href="manage-worksheet.php?id=${escapeHtml(String(ws.id || ''))}"
target="_blank"
class="worksheet-open-link">
<i class="fa-solid fa-arrow-up-right-from-square"></i>
Apri foglio completo
</a>
</div>
</div>
</div>
<div class="row g-3">
<div class="col-lg-6">
<div class="readonly-card">
<div class="readonly-card-header">Dati principali</div>
<div class="readonly-card-body">
<div class="readonly-grid">
${renderReadonlyField('ID foglio', ws.id)}
${renderReadonlyField('Data foglio', ws.worksheet_date_it)}
${renderReadonlyField('Cliente override', ws.customer_name)}
${renderReadonlyField('Codice profilo', ws.profile_type_code)}
${renderReadonlyField('Marchiatura', ws.marking)}
${renderReadonlyField('Approvato da', ws.approved_by)}
${renderReadonlyField('Creato il', ws.created_at_it)}
${renderReadonlyField('Ultimo aggiornamento', ws.updated_at_it)}
</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="readonly-card">
<div class="readonly-card-header">Controlli produzione</div>
<div class="readonly-card-body">
<div class="readonly-grid">
${renderReadonlyField('Taglio', ws.control_frequency_cut)}
${renderReadonlyField('Disegno', ws.control_frequency_drawing)}
${renderReadonlyField('Dima', ws.control_frequency_jig)}
${renderReadonlyField('Modalità dima', ws.control_mode_jig)}
</div>
<hr>
<div class="readonly-label mb-2">Impostazione misure controllo produzione</div>
<div class="readonly-value" style="white-space:pre-wrap;">${valueOrDash(ws.prod_control_measure_settings)}</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="readonly-card">
<div class="readonly-card-header">Packaging / Confezionamento</div>
<div class="readonly-card-body">
<div class="readonly-grid">
${renderReadonlyField('Codice confezione', ws.requested_package_code)}
${renderReadonlyField('Metri per confezione', ws.meters_per_package)}
${renderReadonlyField('Tolleranza metri/conf.', ws.meters_per_package_tolerance)}
${renderReadonlyField('Scatola tipo', ws.box_type)}
${renderReadonlyField('Conf./pezzi per scatola', ws.packages_or_pieces_per_box)}
${renderReadonlyField('Metri per scatola', ws.meters_per_box)}
${renderReadonlyField('Bancale tipo', ws.pallet_type)}
${renderReadonlyField('Scatole/conf. per bancale', ws.boxes_or_packages_per_pallet)}
</div>
<hr>
<div class="readonly-label mb-2">Note metri / confezione</div>
<div class="readonly-value" style="white-space:pre-wrap;">${valueOrDash(ws.meters_per_package_notes)}</div>
</div>
</div>
</div>
<div class="col-lg-6">
<div class="readonly-card">
<div class="readonly-card-header">Velocità e note</div>
<div class="readonly-card-body">
<div class="readonly-grid">
${renderReadonlyField('Vel. prevista kg/h', ws.speed_expected_kg_h)}
${renderReadonlyField('Vel. effettiva kg/h', ws.speed_actual_kg_h)}
${renderReadonlyField('Vel. prevista m/h', ws.speed_expected_m_h)}
${renderReadonlyField('Vel. effettiva m/h', ws.speed_actual_m_h)}
</div>
<hr>
<div class="readonly-label mb-2">Note</div>
<div class="readonly-value" style="white-space:pre-wrap;">${valueOrDash(ws.notes)}</div>
</div>
</div>
</div>
<div class="col-12">
<div class="readonly-card">
<div class="readonly-card-header">Mescole associate al foglio</div>
<div class="readonly-card-body">
${mixHtml}
</div>
</div>
</div>
</div>
`;
$("#worksheetDetailContainer").html(html);
})
.catch(() => {
$("#worksheetDetailContainer").html('<div class="text-danger">Errore nel caricamento del dettaglio foglio</div>');
});
}
$(document).ready(function() {
$('#tabellaMatrici').DataTable({
@ -953,7 +1689,7 @@
return data;
}
}, {
targets: 4,
targets: 5,
orderable: false,
searchable: false
}],
@ -1119,7 +1855,6 @@
const $sel = $("#mm_mescole");
$sel.empty();
// Placeholder temporaneo mentre carica
const loadingOption = new Option("Caricamento mescole...", "", false, false);
$sel.append(loadingOption).trigger("change");
@ -1381,6 +2116,22 @@
document.getElementById('filePreviewModal').addEventListener('hidden.bs.modal', function() {
$("#filePreviewContainer").html("");
});
// OPEN WORKSHEETS LIST
$(document).on("click", ".worksheets, .show-worksheets", function() {
const idmatrice = $(this).data("id");
const nome = $(this).data("nome") || "";
loadMatriceWorksheets(idmatrice, nome);
new bootstrap.Modal(document.getElementById('worksheetsListModal')).show();
});
// OPEN WORKSHEET DETAIL
$(document).on("click", ".open-worksheet-detail", function() {
const worksheetId = $(this).data("id");
loadWorksheetDetail(worksheetId);
new bootstrap.Modal(document.getElementById('worksheetDetailModal')).show();
});
});
$(document).on("click", ".thumb-img", function() {
@ -1395,19 +2146,6 @@
});
});
</script>
<!-- MODALE PREVIEW FILE -->
<div class="modal fade" id="filePreviewModal" tabindex="-1" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" style="max-width:1400px; width:98vw;">
<div class="modal-content" style="height:92vh;">
<div class="modal-header" style="background-color:#b9ebc7;">
<h5 class="modal-title" id="filePreviewTitle">Anteprima file</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal"></button>
</div>
<div id="filePreviewContainer" style="height:calc(92vh - 64px); overflow:hidden; background:#f8fafc;"></div>
</div>
</div>
</div>
</body>
</html>