Pages.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. <?php
  2. /**
  3. * @author Open Mind
  4. * @date 10/04/2018
  5. * @time 09:43
  6. */
  7. namespace Modules\KittingDynamic;
  8. use OpenMind\FindBox\FindBoxCoreSystem;
  9. use OpenMind\FindBox\SmartESL;
  10. class Pages extends \OpenMind\Web\Controller
  11. {
  12. private $CORE_SETTINGS;
  13. private $findBoxCore;
  14. public function __construct($f3)
  15. {
  16. parent::__construct($f3);
  17. $this->CORE_SETTINGS = $f3->get('CORE.fb');
  18. $this->findBoxCore = new FindBoxCoreSystem(...array_values($this->CORE_SETTINGS));
  19. }
  20. public function Pick2Light(object $f3, array $args)
  21. {
  22. $stepValues = [];
  23. if ($args['step'] == 1) {
  24. $f3->clear('COOKIE.p2l');
  25. $f3->clear('COOKIE.consegna');
  26. $f3->clear('COOKIE.labelid');
  27. } else {
  28. $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
  29. if (count($stepValues) == 0)
  30. $stepValues = json_decode($f3->get('COOKIE.p2l'), true);
  31. }
  32. switch ($args['step']) {
  33. case 3:
  34. $distinta = new Distinta();
  35. $distinta->CleanDistintaTable();
  36. $distinta->CopyDistinta($stepValues['consegna']);
  37. $label = new SmartESL($this->findBoxCore, [$stepValues['labelid']]);
  38. $label->BlinkSpecial(0, 1, 1000, 8, 0);
  39. $distinta->SaveProductsToFindBox('3', true, 50); // prende soltanto i primi 3 dalla tabella copia delle distinte
  40. $f3->set('COOKIE.p2l', json_encode($stepValues));
  41. $f3->set('COOKIE.consegna', $stepValues['consegna']);
  42. $f3->set('COOKIE.labelid', $stepValues['labelid']);
  43. $f3->reroute("/pick2light/4");
  44. return;
  45. break;
  46. case 4:
  47. $distinta = new Distinta();
  48. $distinta->SaveProductsToFindBox('3, 2000', false); // LIMIT 3,1000 perchè i primi 3 sono stati fatti nel case 3
  49. break;
  50. case 5:
  51. $datiCommessa['consegna'] = $f3->get('COOKIE.consegna');
  52. $datiCommessa['labelid'] = $f3->get('COOKIE.labelid');
  53. $distinta = new Distinta();
  54. $pickedBarcode = $f3->get('POST.pickedlabelid');
  55. // Decrease quantity and blink label
  56. if ($pickedBarcode != null) {
  57. // ANOMALIA
  58. if ($pickedBarcode == $f3->get('BARCODE_COMMANDS.ANOMALIACODE')) {
  59. // <Se è stato ancora passato un codice anomalia, cancella l'operazione di anomalia in corso
  60. if (isset($stepValues['anomalia']))
  61. unset($stepValues['anomalia']);
  62. else
  63. $f3->set('ANOMALIA', 'In attesa del codice anomalia');
  64. //>
  65. } else if ($stepValues['anomalia']) {
  66. if ($distinta->MarkBarcodeAsAnomalia($pickedBarcode))
  67. unset($stepValues['anomalia']);
  68. else
  69. $f3->set('ANOMALIA', 'Codice non trovato!');
  70. } else { // E' stato passato un codice
  71. $codeFromLabelId = $distinta->GetBarcodeFromLabelId($pickedBarcode);
  72. $pickedBarcode = $codeFromLabelId ?? $pickedBarcode;
  73. if ($distinta->RemoveQuantity($pickedBarcode)) {
  74. // SPEGNE LED ETICHETTA DOPO PICKING
  75. $label = new SmartESL($this->findBoxCore, [$distinta->GetLabelIdFromBarcode($pickedBarcode)]);
  76. $label->BlinkOff();
  77. } else {
  78. $f3->set('INFOTEXT', 'Barcode non riconosciuto o non associato ad alcuna etichetta elettronica');
  79. file_put_contents('not_found.log', $pickedBarcode . "\r\n", FILE_APPEND);
  80. }
  81. }
  82. }
  83. $rowsDistinta = $distinta->getDistinta();
  84. $f3->set('PRODUCTS', $rowsDistinta);
  85. // End Picking List
  86. if (count($rowsDistinta) == 0) {
  87. //$distinta->ResetDistintaLabels($datiCommessa['consegna'], $datiCommessa['labelid']);
  88. $anomalie = $distinta->getAnomalieFromConsegne($datiCommessa['consegna']);
  89. $f3->set('LISTANOMALIE', $anomalie);
  90. //$label = new SmartESL($this->findBoxCore, [$datiCommessa['labelid']]);
  91. $distinta->SaveLabelCarrello($datiCommessa['labelid'], $datiCommessa['labelid'], $datiCommessa['consegna']);
  92. // Se non ci sono anomalie torna alla homepage
  93. if (count($anomalie) == 0) {
  94. $f3->reroute('/');
  95. return;
  96. }
  97. } else {
  98. // Seleziona le prossime tre etichette
  99. foreach ($rowsDistinta as $rowDist) {
  100. $labelId = $distinta->GetLabelIdFromBarcode($rowDist['barcode']);
  101. if ($labelId != null) {
  102. $label = new SmartESL($this->findBoxCore, [$labelId]);
  103. // Se è lo stesso barcode di quello appena pickato dall'operatore, non lo blinka di nuovo
  104. if ($distinta->GetArticleCount($rowDist['barcode']) > 0) {
  105. $label->BlinkSpecial(2, 1, 1000, 20);
  106. }
  107. }
  108. }
  109. }
  110. break;
  111. }
  112. $f3->set('COOKIE.p2l', json_encode($stepValues));
  113. $f3->set('DISTINTE', $f3->Get('DB')->exec('SELECT DISTINCT consegna, DATE_FORMAT(data_creazione,"%d/%m/%Y") as data_creazione, time_creazione, destinazione_merci FROM `distinte` d JOIN articles a ON a.materiale=d.barcode ORDER BY data_creazione, time_creazione, destinazione_merci'));
  114. $f3->set('STEP', $args['step']);
  115. $f3->set('PAGEVALUES', $stepValues);
  116. $f3->set('CONTENT', 'pick2light.tpl');
  117. echo \Template::instance()->render('masterpage.tpl');
  118. }
  119. public function Bind($f3, array $args)
  120. {
  121. $stepValues = [];
  122. if ($args['step'] == 1)
  123. $f3->clear('COOKIE.bind');
  124. else {
  125. $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
  126. if (count($stepValues) == 0)
  127. $stepValues = json_decode($f3->get('COOKIE.p2l'), true);
  128. }
  129. $f3->set('COOKIE.bind', json_encode($stepValues));
  130. if ($args['step'] == 3) {
  131. $this->findBoxCore->Bind($stepValues['labelid'], $stepValues['barcode']);
  132. $label = new SmartESL($this->findBoxCore, [$stepValues['labelid']]);
  133. if ($stepValues['labelid'] == $stepValues['barcode'])
  134. $devType = 79;
  135. else
  136. $devType = 31;
  137. $labelTemplateId = \F3::get("LABELS.TEMPLATES.DT{$devType}");
  138. $label->Display($labelTemplateId[0], $stepValues['barcode']);
  139. // Reset label carrello if barcode = label id
  140. if ($stepValues['labelid'] == $stepValues['barcode']) {
  141. $d = new Distinta();
  142. $d->ResetLabelCarrello($stepValues['labelid']);
  143. } else {
  144. $articles = new \DB\SQL\Mapper($this->dbHandle, 'articles');
  145. $articles->load("materiale='{$stepValues['barcode']}'");
  146. if (!$articles->dry()) {
  147. $dataFields = array(
  148. 'tipo_magazzino' => $articles['tipo_magazzino'],
  149. 'ubicazione' => $articles['ubicazione'],
  150. 'incc_intr' => $articles['incc_intr']
  151. );
  152. $dataFields = array_merge($dataFields, array(
  153. 'quantita_contenitore' => $articles['qta_contenitore'],
  154. 'quantita_magazzino' => $articles['qta_riordino']
  155. ));
  156. $this->findBoxCore->SaveProducts($stepValues['barcode'], $articles['descrizione'], $dataFields);
  157. if ($devType == 31 && ($articles['qta_contenitore'] == 'NO' || $articles['qta_riordino'] == 'NO'))
  158. $pickTemplateId = $labelTemplateId[1];
  159. else
  160. $pickTemplateId = $labelTemplateId[2];
  161. $eslData = json_encode($dataFields);
  162. $this->dbHandle->exec("DELETE FROM label_bindings WHERE label_id='{$stepValues['labelid']}'");
  163. $this->dbHandle->exec("INSERT INTO label_bindings (label_id, barcode, template_id, esl_datafields, descrizione) VALUES ('{$stepValues['labelid']}', '{$stepValues['barcode']}', '{$pickTemplateId}', '{$eslData}', '{$articles['descrizione']}')");
  164. }
  165. }
  166. }
  167. $f3->set('STEP', $args['step']);
  168. $f3->set('CONTENT', 'bind.tpl');
  169. $f3->set('AUTOFOCUS' . $args['step'], 'autofocus');
  170. echo \Template::instance()->render('masterpage.tpl');
  171. }
  172. public function UnBind($f3, array $args)
  173. {
  174. $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
  175. if ($args['step'] == 2) {
  176. $success = $this->findBoxCore->UnBind($stepValues['labelid']);
  177. if ($success['err'] <> 0) {
  178. $f3->set('INFOTEXT', $success['value']);
  179. }
  180. }
  181. $f3->set('STEP', $args['step']);
  182. $f3->set('CONTENT', 'unbind.tpl');
  183. echo \Template::instance()->render('masterpage.tpl');
  184. }
  185. public function ElencoDistinta($f3)
  186. {
  187. $distinta = new Distinta();
  188. $f3->set('PRODUCTS', $distinta->getDistinte());
  189. $f3->set('CONTENT', 'distinta.tpl');
  190. echo \Template::instance()->render('masterpage.tpl');
  191. }
  192. }