| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173 |
- <?php
- /**
- * @author Open Mind
- * @date 13/04/2018
- * @time 11:43
- */
- namespace Modules\Dimatec;
- use OpenMind\FindBox\QueueCommand;
- use OpenMind\System\QueueSystem;
- class Distinta
- {
- /** @var \DB\SQL $dbHandle */
- protected $dbHandle;
- /** @var int $userId */
- protected $userId;
- public function __construct()
- {
- global $f3;
- $this->dbHandle = $f3->get('DB');
- $this->userId = $f3->get('USER')->id;
- }
- /**
- * Delete from table all commesse present and unbind all Prebolle to ESL
- */
- public function TrashCommesse()
- {
- $this->dbHandle->exec("DELETE FROM `label_bindings` WHERE barcode IN (SELECT commessa FROM distinte WHERE idUtente={$this->userId} AND deleted=0)");
- $this->dbHandle->exec("DELETE FROM `distinte` WHERE idUtente={$this->userId} AND deleted=0");
- }
- /**
- * Virtual delete and article of a commessa by set deleted=1 in database field
- *
- * @param string $article
- */
- public function DeleteCommessaArticle(string $article, string $commessa)
- {
- $this->dbHandle->exec("UPDATE `distinte` SET deleted=1 WHERE commessa='{$commessa}' AND barcode='{$article}' AND idUtente={$this->userId} AND deleted=0");
- }
- /**
- * Check if commessa isn't deleted and present
- *
- * @param string $barcode
- * @return bool
- */
- public function commessaExists(string $barcode): bool
- {
- return (count($this->dbHandle->exec("SELECT * FROM `distinte` WHERE `commessa` = '{$barcode}' AND `idUtente` = '{$this->userId}' AND `deleted` = '0'")) > 0);
- }
- /**
- * Ottiene il codice articolo da ogni tipo di campo 'utile'
- *
- * @param string $id
- * @return null|string Codice Articolo
- */
- public function GetBarcode(string $id): ?string
- {
- $binding = $this->dbHandle->exec("SELECT barcode FROM `distinte` WHERE `barcode` = '{$id}' OR `codcliente` = '{$id}' OR `commessa` = '{$id}'");
- if (count($binding) > 0)
- return $binding[0]['barcode'];
- return null;
- }
- /**
- * Retrieve all commesse associated to a Product
- *
- * @param string $barcode
- * @return array
- */
- public function getCommesseFromProduct(string $barcode): array
- {
- return $this->dbHandle->exec("SELECT * FROM `distinte` WHERE `barcode` = '{$barcode}' AND `idUtente` = '{$this->userId}' AND `deleted` = '0' ORDER BY `commessa`");
- }
- public function UnbindAll()
- {
- global $f3;
- $labels = $this->getListeBinded();
- foreach($labels as $label) {
- $msgDisplay = new QueueCommand($label['label_id']);
- $msgDisplay->setDisplay($f3->get("LABELS.TEMPLATES.DEFAULT"), $label['label_id']);
- $msgReset = new QueueCommand($label['label_id']);
- $msgReset->saveProducts('', [
- 'Q.ta' => '',
- 'Commessa' => $label['label_id']
- ]);
- $qm = new QueueSystem('FindBoxService');
- $qm->send($msgReset);
- $qm->send($msgDisplay);
- }
- }
- /**
- * Restituisce le commesse ancora da bindare
- *
- * @return array|FALSE|int
- */
- public function getListeBinded()
- {
- return $this->dbHandle->exec("SELECT label_id FROM label_bindings WHERE barcode IN (SELECT commessa FROM `distinte` WHERE deleted=0 AND idutente={$this->userId})");
- }
- /**
- * Restituisce le commesse ancora da bindare
- *
- * @return array|FALSE|int
- */
- public function getListeToBind()
- {
- return $this->dbHandle->exec("SELECT DISTINCT commessa FROM `distinte` WHERE deleted=0 and idutente={$this->userId} AND commessa NOT IN (SELECT barcode FROM label_bindings) ORDER BY commessa");
- }
- 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}");
- }
- /**
- * @param string $barcode
- * @return array
- */
- public function MarkBarcodeAsAnomalia(string $barcode): array
- {
- global $f3;
- $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);
- }
- /**
- * Get quantity for article binded to label
- *
- * @param string $barcode
- * @return int
- */
- public function getArticleCount(string $barcode): int
- {
- $sql = "SELECT d.qta_prelevare from distinta d JOIN label_bindings b ON d.barcode = b.barcode WHERE idutente={$this->userId} AND b.barcode='{$barcode}'";
- $record = $this->dbHandle->exec($sql);
- if (count($record) > 0)
- return $record[0]['qta_prelevare'];
- return 0;
- }
- /**
- * @param string $barcode
- * @return null|string
- */
- 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;
- }
- }
|