Pages.php 8.1 KB

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