Pages.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. <?php
  2. /**
  3. * @author Open Mind
  4. * @date 10/04/2018
  5. * @time 09:43
  6. */
  7. namespace Modules\Dimatec;
  8. use DB\SQL;
  9. use OpenMind\FindBox\FindBoxCoreSystem;
  10. use OpenMind\FindBox\QueueCommand;
  11. use OpenMind\FindBox\SmartESL;
  12. use OpenMind\System\QueueSystem;
  13. use OpenMind\Web\Controller;
  14. class Pages extends Controller
  15. {
  16. private $CORE_SETTINGS;
  17. private $findBoxCore;
  18. public function __construct($f3)
  19. {
  20. parent::__construct($f3);
  21. $this->CORE_SETTINGS = $f3->get('CORE.fb');
  22. $this->findBoxCore = new FindBoxCoreSystem(...array_values($this->CORE_SETTINGS));
  23. }
  24. /**
  25. * Send QueueSystem command for all labels associated
  26. *
  27. * @param Distinta $distinta
  28. * @param array $commesse
  29. */
  30. private function sendLabelMsg($distinta, array $commesse)
  31. {
  32. global $f3;
  33. foreach($commesse as $commessa) {
  34. $labelid = $distinta->GetLabelIdFromBarcode($commessa['commessa']);
  35. if ($labelid == null) {
  36. $f3->set('INFOTEXT', "Alcune etichette non accenderano il led in quanto non associate.");
  37. continue;
  38. }
  39. $msgBlink = new QueueCommand($labelid);
  40. $msgSaveP = new QueueCommand($labelid);
  41. $msgBlink->setLeds(2, 1, 1000, 16, 0);
  42. $msgSaveP->saveProducts($commessa['descrizione'], [
  43. 'Q.ta' => $commessa['qta_prelevare'],
  44. 'Commessa' => $commessa['commessa']
  45. ]);
  46. $qm = new QueueSystem('FindBoxService');
  47. $qm->send($msgBlink);
  48. $qm->send($msgSaveP);
  49. }
  50. }
  51. public function Pick2Light(object $f3, array $args)
  52. {
  53. $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
  54. $distinta = new Distinta();
  55. switch ($args['step']) {
  56. case 1:
  57. if (count($stepValues) == 0) {
  58. $f3->clear('INFOTEXT');
  59. $f3->clear('SESSION.barcode_mv');
  60. $f3->set('NEXTSTEP', 1);
  61. break;
  62. }
  63. $commesse = $distinta->getCommesseFromProduct($stepValues['barcode_mv']);
  64. if (count($commesse) == 0) {
  65. $f3->set('INFOTEXT', "Nessuna commessa associata al prodotto selezionato");
  66. $f3->set('NEXTSTEP', 1);
  67. break;
  68. }
  69. // Send blink to all labels associated to barcode
  70. $this->sendLabelMsg($distinta, $commesse);
  71. $f3->set('SESSION.barcode_mv', $stepValues['barcode_mv']);
  72. $f3->reroute("/pick2light/2");
  73. return;
  74. break;
  75. case 2:
  76. $f3->set('NEXTSTEP', 2);
  77. if (isset($stepValues['commessa'])) {
  78. if (!$distinta->commessaExists($stepValues['commessa'])) {
  79. $f3->set('INFOTEXT', "Codice cesta non corretto");
  80. } else {
  81. $labelid = $distinta->GetLabelIdFromBarcode($stepValues['commessa']);
  82. if ($labelid != null) {
  83. // Send BlinkOFF
  84. $obj = new QueueCommand($labelid);
  85. $obj->setToBlinkOff();
  86. // Send command to queue
  87. $qm = new QueueSystem('FindBoxService');
  88. $qm->send($obj);
  89. $distinta->DeleteCommessaArticle($stepValues['barcode_mv'], $stepValues['commessa']);
  90. }
  91. }
  92. }
  93. $commesse = $distinta->getCommesseFromProduct($f3->get('SESSION.barcode_mv'));
  94. if (count($commesse) == 0) {
  95. $f3->set('INFOTEXT', "Ventilazione terminata");
  96. $f3->set('RESTART_VENTILAZIONE', TRUE);
  97. }
  98. /* foreach($commesse as $commessa) {
  99. $labelid = $distinta->GetLabelIdFromBarcode($commessa['commessa']);
  100. if ($labelid == null) {
  101. $f3->set('INFOTEXT', "Alcune etichette non accenderano il led in quanto non associate.");
  102. continue;
  103. }
  104. }*/
  105. $f3->set('COMMESSE', $commesse);
  106. break;
  107. }
  108. $f3->set('CONTENT', 'pick2light.tpl');
  109. echo \Template::instance()->render('masterpage.tpl');
  110. }
  111. public function Bind($f3)
  112. {
  113. $params = $this->getSanitizedPostRequest();
  114. $distinta = new Distinta();
  115. if (count($params)) {
  116. $bindData = array_map('strtoupper', $this->getSanitizedPostRequest());
  117. //$err = $this->findBoxCore->Bind($bindData['labelid'], $bindData['labelid']);
  118. $label = new SmartESL($this->findBoxCore, [$bindData['labelid']]);
  119. $labelTemplateId = \F3::get("LABELS.TEMPLATES.DT31");
  120. $err = $label->Display($labelTemplateId, $bindData['labelid']);
  121. $eslData = array(
  122. 'Q.ta' => 0,
  123. 'Commessa' => $bindData['commessa']
  124. );
  125. $j_eslData = json_encode($eslData);
  126. $err = $this->findBoxCore->SaveProducts($bindData['labelid'], '', $eslData);
  127. // Add or Update label
  128. $label = new SQL\Mapper($f3->get('DB'), 'label_bindings');
  129. $label->load(['label_id=?', $bindData['labelid']]);
  130. $label->label_id = $bindData['labelid'];
  131. $label->barcode = $bindData['commessa'];
  132. $label->template_id = $labelTemplateId;
  133. $label->esl_datafields = $j_eslData;
  134. $label->descrizione = $bindData['codcliente'];
  135. $label->save();
  136. /* $this->dbHandle->exec("DELETE FROM label_bindings WHERE label_id='{$bindData['labelid']}'");
  137. $this->dbHandle->exec(
  138. "INSERT INTO label_bindings (label_id, barcode, template_id, esl_datafields, descrizione) VALUES " .
  139. "('{$bindData['labelid']}', '{$bindData['commessa']}', '{$labelTemplateId}', '{$j_eslData}', '{$bindData['codcliente']}')"
  140. );*/
  141. }
  142. $liste = $distinta->getListeToBind();
  143. $f3->set('ORDINE', $liste[0]['commessa']);
  144. $f3->set('LISTE', $liste);
  145. $f3->set('CONTENT', 'bind.tpl');
  146. echo \Template::instance()->render('masterpage.tpl');
  147. }
  148. /**
  149. * @deprecated for now not used
  150. * @param $f3
  151. * @param array $args
  152. */
  153. public function UnBind($f3, array $args)
  154. {
  155. $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
  156. if ($args['step'] == 2) {
  157. $success = $this->findBoxCore->UnBind($stepValues['labelid']);
  158. if ($success['err'] <> 0) {
  159. $f3->set('INFOTEXT', $success['value']);
  160. }
  161. }
  162. $f3->set('STEP', $args['step']);
  163. $f3->set('CONTENT', 'unbind.tpl');
  164. echo \Template::instance()->render('masterpage.tpl');
  165. }
  166. /**
  167. * @deprecated for now not used
  168. * @param $f3
  169. */
  170. public function ElencoDistinta($f3)
  171. {
  172. $distinta = new Distinta();
  173. $f3->set('PRODUCTS', $distinta->getDistinte());
  174. $f3->set('CONTENT', 'distinta.tpl');
  175. echo \Template::instance()->render('masterpage.tpl');
  176. }
  177. /**
  178. * Import lists from as400
  179. * @param $f3
  180. */
  181. public function ImportFromAS400($f3)
  182. {
  183. $migData = new MigrationData();
  184. $migData->SoapConnector($f3->get('VERTICALSTORAGE.MV_ADDRESS'));
  185. $migData->DatabaseConnector($f3->get('VERTICALSTORAGE.DB2_ADDRESS'));
  186. // Get lists from as400
  187. $data = $migData->query($migData->strQueryMassificata('SCARICO'));
  188. // Compile xml for SOAP
  189. $migData->soapCompileFrom($data, 'SCARICO');
  190. if (!$migData->sendToIcam())
  191. $f3->set('IMPORT_RESULT', "Errore durante l'invio della lista al Magazzino Verticale.<br/><br/>Controllare la console ICAM per gli errori.");
  192. else {
  193. // Importo la lista nel database di OM-Link solamente se non ci sono stati errori nell'invio al Magazzino Verticale
  194. $count = $migData->saveDistinta($data);
  195. $f3->set('IMPORT_RESULT', "Liste inviate correttamente al Magazzino Verticale<br/><br/>Righe con massimizzazione importate: $count");
  196. }
  197. $f3->set('CONTENT', 'import.tpl');
  198. echo \Template::instance()->render('masterpage.tpl');
  199. }
  200. /**
  201. * Send list of all goods loaded into MAV to as400
  202. * @param $f3
  203. */
  204. public function MAV2AS400($f3)
  205. {
  206. echo \Template::instance()->render('masterpage.tpl');
  207. }
  208. }