| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- /**
- * @author Open Mind
- * @date 10/04/2018
- * @time 09:43
- */
- namespace Modules\Dimatec;
- use DB\SQL;
- use OpenMind\FindBox\FindBoxCoreSystem;
- use OpenMind\FindBox\QueueCommand;
- use OpenMind\FindBox\SmartESL;
- use OpenMind\System\QueueSystem;
- use OpenMind\Web\Controller;
- class Pages extends Controller
- {
- private $CORE_SETTINGS;
- private $findBoxCore;
- public function __construct($f3)
- {
- parent::__construct($f3);
- $this->CORE_SETTINGS = $f3->get('CORE.fb');
- $this->findBoxCore = new FindBoxCoreSystem(...array_values($this->CORE_SETTINGS));
- }
- /**
- * Send QueueSystem command for all labels associated
- *
- * @param Distinta $distinta
- * @param array $commesse
- */
- private function sendLabelMsg($distinta, array $commesse)
- {
- global $f3;
- foreach($commesse as $commessa) {
- $labelid = $distinta->GetLabelIdFromBarcode($commessa['commessa']);
- if ($labelid == null) {
- $f3->set('INFOTEXT', "Alcune etichette non accenderano il led in quanto non associate.");
- continue;
- }
- $msgBlink = new QueueCommand($labelid);
- $msgSaveP = new QueueCommand($labelid);
- $msgBlink->setLeds(2, 1, 1000, 16, 0);
- $msgSaveP->saveProducts($commessa['descrizione'], [
- 'Q.ta' => $commessa['qta_prelevare'],
- 'Commessa' => $commessa['commessa']
- ]);
- $qm = new QueueSystem('FindBoxService');
- $qm->send($msgBlink);
- $qm->send($msgSaveP);
- }
- }
- public function Pick2Light(object $f3, array $args)
- {
- $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
- $distinta = new Distinta();
- switch ($args['step']) {
- case 1:
- if (count($stepValues) == 0) {
- $f3->clear('INFOTEXT');
- $f3->clear('SESSION.barcode_mv');
- $f3->set('NEXTSTEP', 1);
- break;
- }
- $commesse = $distinta->getCommesseFromProduct($stepValues['barcode_mv']);
- if (count($commesse) == 0) {
- $f3->set('INFOTEXT', "Nessuna commessa associata al prodotto selezionato");
- $f3->set('NEXTSTEP', 1);
- break;
- }
- // Send blink to all labels associated to barcode
- $this->sendLabelMsg($distinta, $commesse);
- $f3->set('SESSION.barcode_mv', $stepValues['barcode_mv']);
- $f3->reroute("/pick2light/2");
- return;
- break;
- case 2:
- $f3->set('NEXTSTEP', 2);
- if (isset($stepValues['commessa'])) {
- if (!$distinta->commessaExists($stepValues['commessa'])) {
- $f3->set('INFOTEXT', "Codice cesta non corretto");
- } else {
- $labelid = $distinta->GetLabelIdFromBarcode($stepValues['commessa']);
- if ($labelid != null) {
- // Send BlinkOFF
- $obj = new QueueCommand($labelid);
- $obj->setToBlinkOff();
- // Send command to queue
- $qm = new QueueSystem('FindBoxService');
- $qm->send($obj);
- $distinta->DeleteCommessaArticle($stepValues['barcode_mv'], $stepValues['commessa']);
- }
- }
- }
- $commesse = $distinta->getCommesseFromProduct($f3->get('SESSION.barcode_mv'));
- if (count($commesse) == 0) {
- $f3->set('INFOTEXT', "Ventilazione terminata");
- $f3->set('RESTART_VENTILAZIONE', TRUE);
- }
- /* foreach($commesse as $commessa) {
- $labelid = $distinta->GetLabelIdFromBarcode($commessa['commessa']);
- if ($labelid == null) {
- $f3->set('INFOTEXT', "Alcune etichette non accenderano il led in quanto non associate.");
- continue;
- }
- }*/
- $f3->set('COMMESSE', $commesse);
- break;
- }
- $f3->set('CONTENT', 'pick2light.tpl');
- echo \Template::instance()->render('masterpage.tpl');
- }
- public function Bind($f3)
- {
- $params = $this->getSanitizedPostRequest();
- $distinta = new Distinta();
- if (count($params)) {
- $bindData = array_map('strtoupper', $this->getSanitizedPostRequest());
- //$err = $this->findBoxCore->Bind($bindData['labelid'], $bindData['labelid']);
- $label = new SmartESL($this->findBoxCore, [$bindData['labelid']]);
- $labelTemplateId = \F3::get("LABELS.TEMPLATES.DT31");
- $err = $label->Display($labelTemplateId, $bindData['labelid']);
- $eslData = array(
- 'Q.ta' => 0,
- 'Commessa' => $bindData['commessa']
- );
- $j_eslData = json_encode($eslData);
- $err = $this->findBoxCore->SaveProducts($bindData['labelid'], '', $eslData);
- // Add or Update label
- $label = new SQL\Mapper($f3->get('DB'), 'label_bindings');
- $label->load(['label_id=?', $bindData['labelid']]);
- $label->label_id = $bindData['labelid'];
- $label->barcode = $bindData['commessa'];
- $label->template_id = $labelTemplateId;
- $label->esl_datafields = $j_eslData;
- $label->descrizione = $bindData['codcliente'];
- $label->save();
- /* $this->dbHandle->exec("DELETE FROM label_bindings WHERE label_id='{$bindData['labelid']}'");
- $this->dbHandle->exec(
- "INSERT INTO label_bindings (label_id, barcode, template_id, esl_datafields, descrizione) VALUES " .
- "('{$bindData['labelid']}', '{$bindData['commessa']}', '{$labelTemplateId}', '{$j_eslData}', '{$bindData['codcliente']}')"
- );*/
- }
- $liste = $distinta->getListeToBind();
- $f3->set('ORDINE', $liste[0]['commessa']);
- $f3->set('LISTE', $liste);
- $f3->set('CONTENT', 'bind.tpl');
- echo \Template::instance()->render('masterpage.tpl');
- }
- /**
- * @deprecated for now not used
- * @param $f3
- * @param array $args
- */
- public function UnBind($f3, array $args)
- {
- $stepValues = array_map('strtoupper', $this->getSanitizedPostRequest());
- if ($args['step'] == 2) {
- $success = $this->findBoxCore->UnBind($stepValues['labelid']);
- if ($success['err'] <> 0) {
- $f3->set('INFOTEXT', $success['value']);
- }
- }
- $f3->set('STEP', $args['step']);
- $f3->set('CONTENT', 'unbind.tpl');
- echo \Template::instance()->render('masterpage.tpl');
- }
- /**
- * @deprecated for now not used
- * @param $f3
- */
- public function ElencoDistinta($f3)
- {
- $distinta = new Distinta();
- $f3->set('PRODUCTS', $distinta->getDistinte());
- $f3->set('CONTENT', 'distinta.tpl');
- echo \Template::instance()->render('masterpage.tpl');
- }
- /**
- * Import lists from as400
- * @param $f3
- */
- public function ImportFromAS400($f3)
- {
- $migData = new MigrationData();
- $migData->SoapConnector($f3->get('VERTICALSTORAGE.MV_ADDRESS'));
- $migData->DatabaseConnector($f3->get('VERTICALSTORAGE.DB2_ADDRESS'));
- // Get lists from as400
- $data = $migData->query($migData->strQueryMassificata('SCARICO'));
- // Compile xml for SOAP
- $migData->soapCompileFrom($data, 'SCARICO');
- if (!$migData->sendToIcam())
- $f3->set('IMPORT_RESULT', "Errore durante l'invio della lista al Magazzino Verticale.<br/><br/>Controllare la console ICAM per gli errori.");
- else {
- // Importo la lista nel database di OM-Link solamente se non ci sono stati errori nell'invio al Magazzino Verticale
- $count = $migData->saveDistinta($data);
- $f3->set('IMPORT_RESULT', "Liste inviate correttamente al Magazzino Verticale<br/><br/>Righe con massimizzazione importate: $count");
- }
- $f3->set('CONTENT', 'import.tpl');
- echo \Template::instance()->render('masterpage.tpl');
- }
- /**
- * Send list of all goods loaded into MAV to as400
- * @param $f3
- */
- public function MAV2AS400($f3)
- {
- echo \Template::instance()->render('masterpage.tpl');
- }
- }
|