Pages.php 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  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. }
  16. else
  17. $f3->set('CONTENT', 'login.tpl');
  18. echo \Template::instance()->render('masterpage.tpl');
  19. }
  20. public function HomeMenu($f3)
  21. {
  22. $f3->set('CONTENT', 'homemenu.tpl');
  23. echo \Template::instance()->render('masterpage.tpl');
  24. }
  25. public function Pick2Light(object $f3, array $args)
  26. {
  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. $distinta->SaveLabelCarrello($stepValues['labelid'], $stepValues['labelid'], $stepValues['consegna']);
  42. $distinta->SaveProductsToFindBox('3', true, 50); // prende soltanto i primi 3 dalla tabella copia delle distinte
  43. $f3->set('COOKIE.p2l', json_encode($stepValues));
  44. $f3->set('COOKIE.consegna', $stepValues['consegna']);
  45. $f3->set('COOKIE.labelid', $stepValues['labelid']);
  46. $f3->reroute("/pick2light/4");
  47. return;
  48. break;
  49. case 4:
  50. $distinta = new \Distinta($f3);
  51. $distinta->SaveProductsToFindBox('3, 2000', false); // LIMIT 3,1000 perchè i primi 3 li ha fatti nel case 3
  52. break;
  53. case 5:
  54. $datiCommessa['consegna'] = $f3->get('COOKIE.consegna');
  55. $datiCommessa['labelid'] = $f3->get('COOKIE.labelid');
  56. $distinta = new \Distinta($f3);
  57. $pickedBarcode = $f3->get('POST.pickedlabelid');
  58. // Decrease quantity and blink label
  59. if ($pickedBarcode != null) {
  60. // ANOMALIA
  61. if ($pickedBarcode == $f3->get('BARCODE_COMMANDS.ANOMALIACODE')) {
  62. // <Se è stato ancora passato un codice anomalia, cancella l'operazione di anomalia in corso
  63. if (isset($stepValues['anomalia']))
  64. unset($stepValues['anomalia']);
  65. else
  66. $f3->set('ANOMALIA', 'In attesa del codice anomalia');
  67. //>
  68. } else if ($stepValues['anomalia']) {
  69. if ($distinta->MarkBarcodeAsAnomalia($pickedBarcode))
  70. unset($stepValues['anomalia']);
  71. else
  72. $f3->set('ANOMALIA', 'Codice non trovato!');
  73. } else { // E' stato passato un barcode
  74. if ($distinta->RemoveQuantity($pickedBarcode)) {
  75. // BlinkOFF solo se non è lo stesso barcode precedente
  76. // if ($distinta->GetArticleCount($pickedBarcode) == 0) {
  77. // SPEGNE LED ETICHETTA DOPO PICKING
  78. $CORE_SETTINGS = \F3::get('CORE.fb');
  79. $findBoxCore = new \FindBoxCoreSystem(...array_values($CORE_SETTINGS));
  80. $label = new \SmartESL($findBoxCore, [$distinta->GetLabelIdFromBarcode($pickedBarcode)]);
  81. $label->BlinkOff();
  82. sleep(3);
  83. $label->BlinkOff();
  84. // }
  85. } else
  86. $f3->set('INFOTEXT', 'Barcode non riconosciuto o non associato a nessuna etichetta elettronica arcode selezionato');
  87. }
  88. }
  89. $rowsDistinta = $distinta->getDistinta();
  90. $f3->set('PRODUCTS', $rowsDistinta);
  91. // End Picking
  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, 20, 0);
  100. $distinta->SaveProductsForLabel7($datiCommessa['labelid'], $datiCommessa['consegna']);
  101. $label->Display(1017, $datiCommessa['labelid']);
  102. // Se non ci sono anomalie torna alla homepage
  103. if (count($anomalie) == 0) {
  104. $f3->reroute('/');
  105. return;
  106. }
  107. } else {
  108. // Seleziona le prossime tre etichette
  109. foreach($rowsDistinta as $rowDist) {
  110. $CORE_SETTINGS = $f3->get('CORE.fb');
  111. $findBoxCore = new \FindBoxCoreSystem(...array_values($CORE_SETTINGS));
  112. $labelId = $distinta->GetLabelIdFromBarcode($rowDist['barcode']);
  113. if ($labelId != null) {
  114. $label = new \SmartESL($findBoxCore, [$labelId]);
  115. // Se è lo stesso barcode di quello appena pickato dall'operatore, non lo blinka di nuovo
  116. if ($distinta->GetArticleCount($rowDist['barcode']) > 0) {
  117. $label->BlinkSpecial(0, 1, 5000, 20, 0);
  118. }
  119. }
  120. }
  121. }
  122. break;
  123. }
  124. $f3->set('COOKIE.p2l', json_encode($stepValues));
  125. $f3->set('DISTINTE', $f3->Get('DB')->exec('SELECT DISTINCT consegna, time_creazione, destinazione_merci FROM distinte ORDER BY data_creazione, time_creazione'));
  126. $f3->set('STEP', $args['step']);
  127. $f3->set('PAGEVALUES', $stepValues);
  128. $f3->set('CONTENT', 'pick2light.tpl');
  129. echo \Template::instance()->render('masterpage.tpl');
  130. }
  131. public function Bind($f3, $args)
  132. {
  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. // Get template from field dev_type o label details
  147. // $details = $label->getDetails();
  148. // $devType = $details[$stepValues['labelid']]['status']['dev_type'];
  149. if ($stepValues['labelid'] == $stepValues['barcode'])
  150. $devType = 79;
  151. else
  152. $devType = 31;
  153. $labelTemplateId = \F3::get("LABELS.TEMPLATES.DT{$devType}");
  154. $label->Display($labelTemplateId[0], $stepValues['barcode']);
  155. $articles = new \DB\SQL\Mapper($this->dbHandle, 'articles');
  156. $articles->load("materiale='{$stepValues['barcode']}'");
  157. if (!$articles->dry()) {
  158. $dataFields = array(
  159. 'tipo_magazzino' => $articles['tipo_magazzino'],
  160. 'ubicazione' => $articles['ubicazione'],
  161. 'incc_intr' => $articles['incc_intr']
  162. );
  163. $err = $findBoxCore->SaveProducts($stepValues['barcode'], $articles['descrizione'], $dataFields);
  164. $dataFields = array_merge($dataFields, array(
  165. 'quantita_contenitore' => $articles['qta_contenitore'],
  166. 'quantita_magazzino' => $articles['qta_riordino']
  167. ));
  168. if ($devType == 31 && ($articles['qta_contenitore'] == 'NO' || $articles['qta_riordino'] == 'NO'))
  169. $pickTemplateId = $labelTemplateId[1];
  170. else
  171. $pickTemplateId = $labelTemplateId[2];
  172. $eslData = json_encode($dataFields);
  173. $this->dbHandle->exec("DELETE FROM label_bindings WHERE label_id='{$stepValues['labelid']}'");
  174. $this->dbHandle->exec("INSERT INTO label_bindings (label_id, barcode, template_id, esl_datafields) VALUES ('{$stepValues['labelid']}', '{$stepValues['barcode']}', '{$pickTemplateId}', '{$eslData}')");
  175. }
  176. }
  177. $f3->set('STEP', $args['step']);
  178. $f3->set('CONTENT', 'bind.tpl');
  179. $f3->set('AUTOFOCUS' . $args['step'], 'autofocus');
  180. echo \Template::instance()->render('masterpage.tpl');
  181. }
  182. public function ElencoDistinta($f3)
  183. {
  184. $distinta = new \Distinta($f3);
  185. $f3->set('PRODUCTS', $distinta->getDistinte());
  186. $f3->set('CONTENT', 'distinta.tpl');
  187. echo \Template::instance()->render('masterpage.tpl');
  188. }
  189. }