191 lines
7.1 KiB
PHP
191 lines
7.1 KiB
PHP
<?php
|
||
|
||
/**
|
||
* Questo file riceve la variabile $r dal file principale
|
||
* e stampa una singola card di produzione.
|
||
*
|
||
* Variabili già presenti in scope:
|
||
* - $statusProduzioneId
|
||
* - $statusPausaId
|
||
*/
|
||
|
||
$isInProduction = $r['id_status'] == $statusProduzioneId;
|
||
$isPaused = $r['id_status'] == $statusPausaId;
|
||
|
||
$dataZibo = ($r['data_zibo'] && $r['data_zibo'] !== '0000-00-00')
|
||
? date('d/m/Y', strtotime($r['data_zibo']))
|
||
: '-';
|
||
|
||
$dataCliente = ($r['data_cliente'] && $r['data_cliente'] !== '0000-00-00')
|
||
? date('d/m/Y', strtotime($r['data_cliente']))
|
||
: '-';
|
||
|
||
$totalSeconds = (int)($r['tempo_totale_produzione'] ?? 0);
|
||
|
||
/**
|
||
* Calcolo startTime:
|
||
* - Se in produzione: usa data_avvio
|
||
* - Se in pausa: NON incrementa timer, JS se ne accorge
|
||
* - Se programmato: usa Data (data pianificazione)
|
||
*/
|
||
$startTime = ($isInProduction || $isPaused)
|
||
&& !empty($r['data_avvio'])
|
||
&& $r['data_avvio'] !== '0000-00-00 00:00:00'
|
||
? strtotime($r['data_avvio'] . ' UTC')
|
||
: strtotime($r['Data'] . ' UTC');
|
||
|
||
$badgeColor = $r['badge_color'] ?? '#6c757d';
|
||
$lineColor = $r['line_color'] ?? '#e9ecef';
|
||
$statusNome = $r['status_nome'];
|
||
$matricePhoto = $r['matrice_photo'] ?? '';
|
||
$placeholder = 'assets/images/no-photo.png';
|
||
|
||
if ($matricePhoto) {
|
||
$matricePath = 'photos/matrici/' . $matricePhoto;
|
||
} else {
|
||
$matricePath = $placeholder;
|
||
}
|
||
|
||
?>
|
||
|
||
<div class="record-card <?= $isInProduction || $isPaused ? 'in-production expanded' : 'programmed' ?>"
|
||
data-id="<?= $r['id'] ?>"
|
||
data-total-seconds="<?= $totalSeconds ?>"
|
||
data-kgsp="<?= htmlspecialchars($r['kg_sp']) ?>"
|
||
data-metri="<?= htmlspecialchars($r['metri']) ?>"
|
||
style="--line-bg: <?= $lineColor ?>; --badge-bg: <?= $badgeColor ?>;">
|
||
|
||
<!-- RIGA VISIBILE -->
|
||
<div class="record-summary">
|
||
<div class="summary-grid">
|
||
<!-- FOTO MATRICE -->
|
||
<div>
|
||
<strong>Foto</strong>
|
||
<?php if ($matricePhoto): ?>
|
||
<div class="photo-thumb"
|
||
data-full="<?= htmlspecialchars($matricePath, ENT_QUOTES) ?>"
|
||
style="width:80px;height:60px;border-radius:8px;overflow:hidden;
|
||
border:1px solid #e2e8f0;cursor:pointer;background:#f8fafc;">
|
||
<img src="<?= htmlspecialchars($matricePath, ENT_QUOTES) ?>"
|
||
alt="Foto matrice"
|
||
style="width:100%;height:100%;object-fit:cover;">
|
||
</div>
|
||
<?php else: ?>
|
||
<span style="color:#94a3b8;">Nessuna foto</span>
|
||
<?php endif; ?>
|
||
</div>
|
||
<div>
|
||
<strong>Conf. Ord.</strong>
|
||
<span data-field="conferma_ordine">
|
||
<?= htmlspecialchars($r['conferma_ordine'] ?? '') ?>
|
||
</span>
|
||
</div>
|
||
|
||
<div><strong>Linea</strong> <span><?= htmlspecialchars($r['linea']) ?></span></div>
|
||
<div><strong>Matrice</strong> <span><?= htmlspecialchars($r['matrice']) ?></span></div>
|
||
|
||
<?php
|
||
// Ricostruzione mescole con nuova struttura
|
||
$mescRaw = $r['mescole_list'] ?? ''; // il campo viene da GROUP_CONCAT
|
||
$mescArray = $mescRaw !== '' ? explode(' | ', $mescRaw) : [];
|
||
$mescCount = count($mescArray);
|
||
?>
|
||
|
||
<div>
|
||
<strong>Mescola</strong>
|
||
|
||
<?php if ($mescCount === 0): ?>
|
||
<span style="color:#999;">N/A</span>
|
||
|
||
<?php elseif ($mescCount === 1): ?>
|
||
<span><?= htmlspecialchars($mescArray[0]) ?></span>
|
||
|
||
<?php else: ?>
|
||
<button
|
||
class="btn btn-sm btn-warning showMescole"
|
||
data-list="<?= htmlspecialchars(json_encode($mescArray), ENT_QUOTES) ?>"
|
||
style="padding:3px 8px;font-size:0.8rem;">
|
||
Multi (<?= $mescCount ?>)
|
||
</button>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<div><strong>Cliente</strong> <span><?= htmlspecialchars($r['cliente'] ?? '-') ?></span></div>
|
||
<div><strong>Zibo</strong> <span><?= $dataZibo ?></span></div>
|
||
<div><strong>Data Cl.</strong> <span><?= $dataCliente ?></span></div>
|
||
<div><strong>Metri</strong> <span><?= number_format($r['metri'], 2) ?></span></div>
|
||
<div><strong>Ore</strong> <span><?= number_format($r['ore_previste'], 1) ?></span></div>
|
||
</div>
|
||
|
||
<div class="status-badge" style="background: var(--badge-bg);">
|
||
<?= strtoupper($statusNome) ?>
|
||
<?php if ($isInProduction || $isPaused): ?>
|
||
<i class="bi bi-chevron-down expand-arrow"></i>
|
||
<?php endif; ?>
|
||
</div>
|
||
</div>
|
||
|
||
|
||
<!-- RIGA ESPANSA -->
|
||
<div class="record-expanded">
|
||
<?php if ($isInProduction || $isPaused): ?>
|
||
|
||
<div class="timer-display"
|
||
data-start="<?= $r['start_time'] ? strtotime($r['start_time']) : '' ?>"
|
||
data-end="<?= $r['end_time'] ? strtotime($r['end_time']) : '' ?>">
|
||
<span class="timer">00:00:00</span>
|
||
</div>
|
||
|
||
<?php
|
||
// 🔥 Carica i parametri della linea passati dall’AJAX
|
||
$paramsLinea = $r['params_linea'] ?? [];
|
||
|
||
// 🔥 Carica già anche eventuali foto di slot parametri
|
||
// (necessario perché param_grid.php usa $photosSlots)
|
||
$photosSlots = [];
|
||
$stmt = $pdo->prepare("
|
||
SELECT param_position, filename
|
||
FROM production_photos
|
||
WHERE production_id = ?
|
||
AND photo_type = 'parametri_macchina'
|
||
");
|
||
$stmt->execute([$r['id']]);
|
||
foreach ($stmt->fetchAll() as $p) {
|
||
$photosSlots[(int)$p['param_position']] = $p['filename'];
|
||
}
|
||
|
||
// 👉 Include la griglia parametri con le variabili già disponibili
|
||
$paramsLinea = $r['param_slots'] ?? [];
|
||
include __DIR__ . "/components/param_grid.php";
|
||
?>
|
||
|
||
|
||
|
||
<!-- Teorici nascosti (per modale finale) -->
|
||
<span data-field="kg_sp" style="display:none;"><?= $r['kg_sp'] ?></span>
|
||
<span data-field="metri" style="display:none;"><?= $r['metri'] ?></span>
|
||
|
||
<div class="action-buttons">
|
||
<?php if ($isInProduction): ?>
|
||
<button class="action-btn pause-btn" data-id="<?= $r['id'] ?>">PAUSA</button>
|
||
<button class="action-btn stop-btn" data-id="<?= $r['id'] ?>">STOP</button>
|
||
<?php elseif ($isPaused): ?>
|
||
<button class="action-btn resume-btn" data-id="<?= $r['id'] ?>">RIPRENDI</button>
|
||
<button class="action-btn stop-btn" data-id="<?= $r['id'] ?>">STOP</button>
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
<?php if (in_array($r['id_status'], [2, 7])): // 2 produzione, 7 pausa
|
||
?>
|
||
<?php include __DIR__ . "/components/photo_buttons.php"; ?>
|
||
<?php endif; ?>
|
||
|
||
|
||
<?php else: ?>
|
||
|
||
<button class="action-btn start-btn" data-id="<?= $r['id'] ?>">AVVIA PRODUZIONE</button>
|
||
|
||
<?php endif; ?>
|
||
</div>
|
||
|
||
</div>
|