Pages.php 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. <?php
  2. /**
  3. * @author Open Mind
  4. * @date 10/04/2018
  5. * @time 09:43
  6. */
  7. namespace Modules\Dimatec;
  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. $distinta = new Distinta();
  33. switch ($args['step']) {
  34. case 3:
  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->SaveProductsToFindBox('3, 2000', false); // LIMIT 3,1000 perchè i primi 3 sono stati fatti nel case 3
  48. break;
  49. case 5:
  50. $datiCommessa['consegna'] = $f3->get('COOKIE.consegna');
  51. $datiCommessa['labelid'] = $f3->get('COOKIE.labelid');
  52. $pickedBarcode = $f3->get('POST.pickedlabelid');
  53. // Decrease quantity and blink label
  54. if ($pickedBarcode != null) {
  55. // ANOMALIA
  56. if ($pickedBarcode == $f3->get('BARCODE_COMMANDS.ANOMALIACODE')) {
  57. // <Se è stato ancora passato un codice anomalia, cancella l'operazione di anomalia in corso
  58. if (isset($stepValues['anomalia']))
  59. unset($stepValues['anomalia']);
  60. else
  61. $f3->set('ANOMALIA', 'In attesa del codice anomalia');
  62. //>
  63. } else if ($stepValues['anomalia']) {
  64. if ($distinta->MarkBarcodeAsAnomalia($pickedBarcode))
  65. unset($stepValues['anomalia']);
  66. else
  67. $f3->set('ANOMALIA', 'Codice non trovato!');
  68. } else { // E' stato passato un codice
  69. $codeFromLabelId = $distinta->GetBarcodeFromLabelId($pickedBarcode);
  70. $pickedBarcode = $codeFromLabelId ?? $pickedBarcode;
  71. if ($distinta->RemoveQuantity($pickedBarcode)) {
  72. // SPEGNE LED ETICHETTA DOPO PICKING
  73. $label = new SmartESL($this->findBoxCore, [$distinta->GetLabelIdFromBarcode($pickedBarcode)]);
  74. $label->BlinkOff();
  75. } else {
  76. $f3->set('INFOTEXT', 'Barcode non riconosciuto o non associato ad alcuna etichetta elettronica');
  77. file_put_contents('not_found.log', $pickedBarcode . "\r\n", FILE_APPEND);
  78. }
  79. }
  80. }
  81. $rowsDistinta = $distinta->getDistinta();
  82. $f3->set('PRODUCTS', $rowsDistinta);
  83. // End Picking List
  84. if (count($rowsDistinta) == 0) {
  85. //$distinta->ResetDistintaLabels($datiCommessa['consegna'], $datiCommessa['labelid']);
  86. $anomalie = $distinta->getAnomalieFromConsegne($datiCommessa['consegna']);
  87. $f3->set('LISTANOMALIE', $anomalie);
  88. //$label = new SmartESL($this->findBoxCore, [$datiCommessa['labelid']]);
  89. $distinta->SaveLabelCarrello($datiCommessa['labelid'], $datiCommessa['labelid'], $datiCommessa['consegna']);
  90. // Se non ci sono anomalie torna alla homepage
  91. if (count($anomalie) == 0) {
  92. $f3->reroute('/');
  93. return;
  94. }
  95. } else {
  96. // Seleziona le prossime tre etichette
  97. foreach($rowsDistinta as $rowDist) {
  98. $labelId = $distinta->GetLabelIdFromBarcode($rowDist['barcode']);
  99. if ($labelId != null) {
  100. $label = new SmartESL($this->findBoxCore, [$labelId]);
  101. // Se è lo stesso barcode di quello appena pickato dall'operatore, non lo blinka di nuovo
  102. if ($distinta->GetArticleCount($rowDist['barcode']) > 0) {
  103. $label->BlinkSpecial(2, 1, 1000, 20);
  104. }
  105. }
  106. }
  107. }
  108. break;
  109. }
  110. $f3->set('COOKIE.p2l', json_encode($stepValues));
  111. $distinte = $distinta->getListeToBind();
  112. $f3->set('DISTINTE', $distinte);
  113. $f3->set('STEP', $args['step']);
  114. $f3->set('PAGEVALUES', $stepValues);
  115. $f3->set('CONTENT', 'pick2light.tpl');
  116. echo \Template::instance()->render('masterpage.tpl');
  117. }
  118. public function Bind($f3)
  119. {
  120. $params = $this->getSanitizedPostRequest();
  121. $distinta = new Distinta();
  122. if (count($params)) {
  123. $bindData = array_map('strtoupper', $this->getSanitizedPostRequest());
  124. $err = $this->findBoxCore->Bind($bindData['labelid'], $bindData['labelid']);
  125. $label = new SmartESL($this->findBoxCore, [$bindData['labelid']]);
  126. $labelTemplateId = \F3::get("LABELS.TEMPLATES.DT31");
  127. $err = $label->Display($labelTemplateId, $bindData['labelid']);
  128. // TODO assegnare il template corretto ed i custom field
  129. $eslData = array(
  130. 'Q.ta' => 0,
  131. 'Commessa' => $bindData['commessa']
  132. );
  133. $j_eslData = json_encode($eslData);
  134. $err = $this->findBoxCore->SaveProducts($bindData['labelid'], '', $eslData);
  135. $this->dbHandle->exec("DELETE FROM label_bindings WHERE label_id='{$bindData['labelid']}'");
  136. $this->dbHandle->exec(
  137. "INSERT INTO label_bindings (label_id, barcode, template_id, esl_datafields, descrizione) VALUES " .
  138. "('{$bindData['labelid']}', '{$bindData['commessa']}', '{$labelTemplateId}', '{$j_eslData}', '{$bindData['commessa']}')"
  139. );
  140. }
  141. $liste = $distinta->getListeToBind();
  142. $f3->set('ORDINE', $liste[0]['commessa']);
  143. $f3->set('LISTE', $liste);
  144. $f3->set('CONTENT', 'bind.tpl');
  145. echo \Template::instance()->render('masterpage.tpl');
  146. }
  147. /**
  148. * @deprecated for now not used
  149. * @param $f3
  150. * @param array $args
  151. */
  152. public function UnBind($f3, array $args)
  153. {
  154. $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
  155. if ($args['step'] == 2) {
  156. $success = $this->findBoxCore->UnBind($stepValues['labelid']);
  157. if ($success['err'] <> 0) {
  158. $f3->set('INFOTEXT', $success['value']);
  159. }
  160. }
  161. $f3->set('STEP', $args['step']);
  162. $f3->set('CONTENT', 'unbind.tpl');
  163. echo \Template::instance()->render('masterpage.tpl');
  164. }
  165. /**
  166. * @deprecated for now not used
  167. * @param $f3
  168. */
  169. public function ElencoDistinta($f3)
  170. {
  171. $distinta = new Distinta();
  172. $f3->set('PRODUCTS', $distinta->getDistinte());
  173. $f3->set('CONTENT', 'distinta.tpl');
  174. echo \Template::instance()->render('masterpage.tpl');
  175. }
  176. }