|
|
@@ -1,257 +0,0 @@
|
|
|
-<?php
|
|
|
-/**
|
|
|
- * @author Open Mind
|
|
|
- * @date 13/04/2018
|
|
|
- * @time 11:43
|
|
|
- */
|
|
|
-
|
|
|
-namespace Modules\KittingDynamic;
|
|
|
-
|
|
|
-use OpenMind\FindBox\FindBoxCoreSystem;
|
|
|
-use OpenMind\FindBox\SmartESL;
|
|
|
-
|
|
|
-class Distinta
|
|
|
-{
|
|
|
- private $dbHandle;
|
|
|
- private $userId;
|
|
|
-
|
|
|
- public function __construct()
|
|
|
- {
|
|
|
- global $f3;
|
|
|
- $this->dbHandle = $f3->get('DB');
|
|
|
- $this->userId = $f3->get('USER')->id;
|
|
|
- }
|
|
|
-
|
|
|
- public function CleanDistintaTable()
|
|
|
- {
|
|
|
- $this->dbHandle->exec('DELETE FROM distinta_esplosa WHERE idutente=' . $this->userId);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Esplode la disinta in modo che tutti abbiano quantità 1
|
|
|
- *
|
|
|
- * @param string $commessa
|
|
|
- * @throws \Exception
|
|
|
- */
|
|
|
- public function CopyDistinta(string $commessa)
|
|
|
- {
|
|
|
- $sql = <<<EOF
|
|
|
-SELECT DISTINCT consegna, barcode, articles.descrizione, origine, ubicazione, sequenza, qta_prelevare
|
|
|
-FROM distinte join articles on distinte.barcode = articles.materiale
|
|
|
-WHERE consegna='$commessa'
|
|
|
-ORDER BY sequenza
|
|
|
-EOF;
|
|
|
- $dataset = $this->dbHandle->exec($sql);
|
|
|
- $idutente = $this->userId;
|
|
|
-
|
|
|
- foreach($dataset as $row) {
|
|
|
- $sqlInsert = "INSERT INTO distinta_esplosa (idutente, commessa, barcode, descrizione, origine, ubicazione, sequenza, qta_prelevare, anomalie)" .
|
|
|
- "VALUES ({$idutente}, '{$row['consegna']}', '{$row['barcode']}', '{$row['descrizione']}', '{$row['origine']}', '{$row['ubicazione']}', '{$row['sequenza']}', '{$row['qta_prelevare']}', 0)";
|
|
|
- $err = $this->dbHandle->exec($sqlInsert);
|
|
|
- if (!$err)
|
|
|
- throw new \Exception(__FUNCTION__ . ' error insert in table distinta_esplosa');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * @param string $maxArticles the LIMIT mysql query parameter
|
|
|
- * @param bool $blink true if need to blink
|
|
|
- * @param int $iterations
|
|
|
- * @throws \Exception
|
|
|
- */
|
|
|
- public function SaveProductsToFindBox(string $maxArticles, bool $blink, int $iterations = 20)
|
|
|
- {
|
|
|
- $CORE_SETTINGS = \F3::get('CORE.fb');
|
|
|
- $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
|
|
|
-
|
|
|
- $datiDistinta = $this->getDistinta($maxArticles);
|
|
|
- foreach($datiDistinta as $row) {
|
|
|
-
|
|
|
- $labelId = $this->GetLabelIdFromBarcode($row['barcode']);
|
|
|
- if ($labelId != null) {
|
|
|
-
|
|
|
- $datiBind = new \DB\SQL\Mapper($this->dbHandle, 'label_bindings');
|
|
|
- $datiBind->load("label_id='{$labelId}'");
|
|
|
-
|
|
|
- if (!$datiBind->dry()) {
|
|
|
- $oldHash = md5(join('', [$datiBind->barcode, $datiBind->descrizione, $datiBind->barcode, $datiBind->qta_prelevare]));
|
|
|
- $newHash = md5(join('', [$row['barcode'], $row['descrizione'], $row['barcode'], $row['qta_prelevare']]));
|
|
|
- if ($oldHash <> $newHash) {
|
|
|
- $dataFields = array(
|
|
|
- 'qr_code' => $row['barcode'],
|
|
|
- 'qta_prelevare' => $row['qta_prelevare']
|
|
|
- );
|
|
|
- $findBoxCore->SaveProducts($row['barcode'], $row['descrizione'], $dataFields);
|
|
|
- $datiBind->copyfrom([
|
|
|
- 'barcode' => $row['barcode'],
|
|
|
- 'descrizione' => $row['descrizione'],
|
|
|
- 'qr_code' => $row['barcode'],
|
|
|
- 'qta_prelevare' => $row['qta_prelevare']
|
|
|
- ]);
|
|
|
- $datiBind->update();
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- if ($blink) {
|
|
|
- $label = new SmartESL($findBoxCore, [$labelId]);
|
|
|
- $label->BlinkSpecial(2, 1, 1000, $iterations, 0);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function getDistinta(string $maxRows = '3')
|
|
|
- {
|
|
|
- return $this->dbHandle->exec("SELECT * FROM distinta_esplosa WHERE idutente={$this->userId} AND qta_prelevare>0 and anomalie=0 ORDER BY sequenza LIMIT {$maxRows}");
|
|
|
- }
|
|
|
-
|
|
|
- public function GetLabelIdFromBarcode(string $barcode): ?string
|
|
|
- {
|
|
|
- $label = $this->dbHandle->exec("SELECT label_id FROM `label_bindings` WHERE barcode='{$barcode}'");
|
|
|
- if (count($label) > 0)
|
|
|
- return $label[0]['label_id'];
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- public function getDistinte()
|
|
|
- {
|
|
|
- return $this->dbHandle->exec('SELECT distinct consegna, commessa, ordine_produzione, data_creazione, time_creazione, destinazione_merci FROM `distinte` ORDER BY data_creazione');
|
|
|
- }
|
|
|
-
|
|
|
- public function MarkBarcodeAsAnomalia(string $barcode)
|
|
|
- {
|
|
|
- $CORE_SETTINGS = \F3::get('CORE.fb');
|
|
|
- $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
|
|
|
- $lblId = $this->GetLabelIdFromBarcode($barcode);
|
|
|
- $label = new SmartESL($findBoxCore, [$lblId]);
|
|
|
- $label->BlinkSpecial(3, 1, 1000, 10);
|
|
|
-
|
|
|
- $sql = "UPDATE distinta_esplosa d JOIN label_bindings b ON d.barcode = b.barcode SET anomalie=1 WHERE idutente={$this->userId} AND b.barcode='{$barcode}'";
|
|
|
- return $this->dbHandle->exec($sql);
|
|
|
- }
|
|
|
-
|
|
|
- public function RemoveQuantity(string $labelId)
|
|
|
- {
|
|
|
- $sql = "UPDATE distinta_esplosa d JOIN label_bindings b ON d.barcode = b.barcode SET d.qta_prelevare=d.qta_prelevare-1 WHERE idutente={$this->userId} AND b.barcode='{$labelId}' AND d.qta_prelevare>0";
|
|
|
- $ret = $this->dbHandle->exec($sql);
|
|
|
- return $ret;
|
|
|
- }
|
|
|
-
|
|
|
- public function GetArticleCount(string $barcode): int
|
|
|
- {
|
|
|
- $sql = "SELECT d.qta_prelevare from distinta_esplosa d JOIN label_bindings b ON d.barcode = b.barcode WHERE idutente={$this->userId} AND b.barcode='{$barcode}'";
|
|
|
- $record = $this->dbHandle->exec($sql);
|
|
|
- return $record[0]['qta_prelevare'];
|
|
|
- }
|
|
|
-
|
|
|
- public function GetBarcodeFromLabelId(string $labelId): ?string
|
|
|
- {
|
|
|
- $binding = $this->dbHandle->exec("SELECT barcode FROM `label_bindings` WHERE label_id='{$labelId}'");
|
|
|
- if (count($binding) > 0)
|
|
|
- return $binding[0]['barcode'];
|
|
|
- return null;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Clean label Cart display
|
|
|
- *
|
|
|
- * @param string $labelId Label ID
|
|
|
- * @throws \Exception
|
|
|
- */
|
|
|
- public function ResetLabelCarrello(string $labelId)
|
|
|
- {
|
|
|
- $CORE_SETTINGS = \F3::get('CORE.fb');
|
|
|
- $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
|
|
|
-
|
|
|
- $label = new SmartESL($findBoxCore, [$labelId]);
|
|
|
- $label->BlinkSpecial(0, 1, 1000, 8, 0);
|
|
|
-
|
|
|
- $dataFields = array(
|
|
|
- 'end_operations' => '',
|
|
|
- 'origine' => '',
|
|
|
- 'commessa' => '',
|
|
|
- 'ordine_produzione' => '',
|
|
|
- 'data_creazione' => '',
|
|
|
- 'time_creazione' => '',
|
|
|
- 'destinazione_merci' => '',
|
|
|
- 'xml' => '',
|
|
|
- 'xslt' => '');
|
|
|
-
|
|
|
- $findBoxCore->SaveProducts($labelId, '', $dataFields);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Salva i dati per l'etichetta del carrello
|
|
|
- *
|
|
|
- * @param string $labelId
|
|
|
- * @param string $barcode
|
|
|
- * @param string $consegna
|
|
|
- * @throws \Exception
|
|
|
- */
|
|
|
- public function SaveLabelCarrello(string $labelId, string $barcode, string $consegna)
|
|
|
- {
|
|
|
- $CORE_SETTINGS = \F3::get('CORE.fb');
|
|
|
- $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
|
|
|
-
|
|
|
- $sqlCommesse = "SELECT DISTINCT origine, commessa, ordine_produzione, data_creazione, time_creazione, destinazione_merci FROM `distinte` WHERE consegna = '{$consegna}'";
|
|
|
- $dataFields = $this->dbHandle->exec($sqlCommesse);
|
|
|
-
|
|
|
- $dataFields = array_shift($dataFields);
|
|
|
-
|
|
|
- $articles = $this->getArticoliByConsegna($consegna);
|
|
|
-
|
|
|
- $xmlField = '<?xml version="1.0" encoding="UTF-8"?><distinta>';
|
|
|
-
|
|
|
- foreach($articles as $i => $articolo) {
|
|
|
- $xmlField .= "<materiale anomalia=\"{$articolo['anomalie']}\"><barcode>{$articolo['barcode']}</barcode><description>{$articolo['descrizione']}</description><qta_nominale>{$articolo['qta_nominale']}</qta_nominale><qta_prelevare>{$articolo['qta_prelevare']}</qta_prelevare></materiale>";
|
|
|
- }
|
|
|
-
|
|
|
- $xmlField .= '</distinta>';
|
|
|
-
|
|
|
- $dataFields['xml'] = $xmlField;
|
|
|
- $dataFields['xslt'] = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"><xsl:template match=\"/\"><svg xmlns=\"http://www.w3.org/2000/svg\" width=\"640\" height=\"384\" viewBox=\"0 0 640 384\"><line x1=\"0\" y1=\"18\" x2=\"640\" y2=\"18\" style=\"stroke: black; stroke-width: 2px\"/><xsl:for-each select=\"distinta/materiale\"><xsl:if test=\"@anomalia='1'\"><xsl:variable name=\"posDeltaY\" select=\"(position()*15)+4\" /><rect width=\"640\" height=\"15px\" y=\"{\$posDeltaY}px\" style=\"fill:rgb(0,0,0)\" /></xsl:if></xsl:for-each><text style=\"font-family: Tahoma; font-size: 8pt; font-weight: bold\"><tspan fill=\"black\" dy=\"15px\" x=\"0\">MATERIALE</tspan><tspan fill=\"black\" x=\"90\">DESCRIZIONE</tspan><tspan fill=\"black\" x=\"300\">PR</tspan><tspan fill=\"black\" x=\"340\">MANC</tspan><xsl:for-each select=\"distinta/materiale\"><xsl:variable name=\"textcolor\"><xsl:choose><xsl:when test=\"@anomalia='1'\"><xsl:value-of select=\"'white'\" /></xsl:when><xsl:otherwise><xsl:value-of select=\"'black'\" /></xsl:otherwise></xsl:choose></xsl:variable><tspan fill=\"{\$textcolor}\" dy=\"15px\" x=\"0\"><xsl:value-of select=\"barcode\" /></tspan><tspan fill=\"{\$textcolor}\" x=\"90\"><xsl:value-of select=\"substring(description, 1, 28)\" /></tspan><tspan fill=\"{\$textcolor}\" x=\"300\"><xsl:value-of select=\"qta_nominale\" /></tspan><tspan fill=\"{\$textcolor}\" x=\"340\"><xsl:if test=\"qta_prelevare>0\"><xsl:value-of select=\"qta_prelevare\" /></xsl:if></tspan></xsl:for-each></text></svg></xsl:template></xsl:stylesheet>";
|
|
|
-
|
|
|
- $dataFields['end_operations'] = $consegna;
|
|
|
-
|
|
|
- $label = new SmartESL($findBoxCore, [$labelId]);
|
|
|
- $findBoxCore->SaveProducts($barcode, $consegna, $dataFields);
|
|
|
- $label->BlinkSpecial(0, 1, 1000, 8, 0);
|
|
|
- }
|
|
|
-
|
|
|
- private function getArticoliByConsegna(string $consegna): array
|
|
|
- {
|
|
|
- $sqlCommesse = "SELECT DISTINCT de.barcode, de.descrizione, d.qta_prelevare as qta_nominale, de.qta_prelevare, de.anomalie FROM `distinta_esplosa` AS de JOIN `distinte` AS d ON de.commessa=d.consegna WHERE idutente={$this->userId} AND de.commessa = '{$consegna}' AND de.barcode=d.barcode";
|
|
|
- return $this->dbHandle->exec($sqlCommesse);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Esegue il reset delle etichette associate alla distinta
|
|
|
- * @param string $commessa
|
|
|
- * @param string $label7Id
|
|
|
- * @throws \Exception
|
|
|
- */
|
|
|
- public function ResetDistintaLabels(string $commessa, string $label7Id)
|
|
|
- {
|
|
|
- $sql = "SELECT label_id, anomalie, b.barcode, d.descrizione FROM distinta_esplosa d JOIN label_bindings b ON d.barcode=b.barcode WHERE idutente={$this->userId} AND commessa='{$commessa}'";
|
|
|
- $dataset = $this->dbHandle->exec($sql);
|
|
|
-
|
|
|
- $CORE_SETTINGS = \F3::get('CORE.fb');
|
|
|
- $findBoxCore = new FindBoxCoreSystem(...array_values($CORE_SETTINGS));
|
|
|
-
|
|
|
- foreach($dataset as $row) {
|
|
|
- $dataFields = array(
|
|
|
- 'qr_code' => $row['barcode'],
|
|
|
- 'qta_prelevare' => ''
|
|
|
- );
|
|
|
-
|
|
|
- $findBoxCore->SaveProducts($row['barcode'], $row['descrizione'], $dataFields);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- public function getAnomalieFromConsegne(string $consegna): array
|
|
|
- {
|
|
|
- return $this->dbHandle->exec("SELECT `barcode`, `descrizione`, `qta_prelevare`, `anomalie` FROM distinta_esplosa WHERE commessa='{$consegna}' AND idutente={$this->userId} AND anomalie>0 ORDER BY sequenza");
|
|
|
- }
|
|
|
-
|
|
|
-}
|