Browse Source

* Changed some of FindBoxService outputs
* FIX: added addslashes()
* Refactor using ORM classes
* Changed some MAV logics
* Some of small changes.

Giancarlo Voci 8 years ago
parent
commit
cd8f161629

+ 2 - 2
src/Modules/Dimatec/Dimatec.php

@@ -23,12 +23,12 @@ class Dimatec extends PluginStrategy
     $this->AddRoute("GET|POST /bind", __NAMESPACE__ . '\Pages->Bind');
     $this->AddRoute("GET /dualframe", __NAMESPACE__ . '\Dimatec->IcamControlIFrame');
     $this->AddRoute("GET /mav2as400", __NAMESPACE__ . '\Pages->MAV2AS400');
-    $this->AddRoute('GET /as4002mav', __NAMESPACE__ . '\Pages->AS4002MAV');
+    $this->AddRoute('GET /importfromas400', __NAMESPACE__ . '\Pages->ImportFromAS400');
 
     $imgClass = 'shadow p-3 rounded bg-white';
 
     $this->AddMenuItem('mav2as400', ['order' => 1, 'url' => 'mav2as400', 'imgClass' => $imgClass, 'image' => 'ui/images/mav2as400.png', 'permissionName' => 'importdata']);
-    $this->AddMenuItem('as4002mav', ['order' => 2, 'url' => 'as4002mav', 'imgClass' => $imgClass, 'image' => 'ui/images/import.png', 'permissionName' => 'importdata']);
+    $this->AddMenuItem('ImportFromAS400', ['order' => 2, 'url' => 'importfromas400', 'imgClass' => $imgClass, 'image' => 'ui/images/import.png', 'permissionName' => 'importdata']);
     $this->AddMenuItem('bind', ['url' => 'bind', 'imgClass' => $imgClass, 'image' => 'ui/images/bind.png']);
     $this->AddMenuItem('pick2light', ['url' => 'pick2light/1', 'imgClass' => $imgClass, 'image' => 'ui/images/magazzinoverticale.png']);
   }

+ 8 - 66
src/Modules/Dimatec/Distinta.php

@@ -19,28 +19,19 @@ class Distinta
 
   public function __construct()
   {
-    $a = get_declared_classes();
-
-    $this->dbHandle = \F3::get('DB');
-    $this->userId = \F3::get('USER')->id;
+    global $f3;
+    $this->dbHandle = $f3->get('DB');
+    $this->userId = $f3->get('USER')->id;
   }
 
   /**
-   * Virtual delete commessa, set delete=1 in database only
+   * Virtual delete and article of a commessa by set deleted=1 in database field
    *
-   * @param string $commessa
-   */
-  public function DeleteCommessa(string $commessa)
-  {
-    $this->dbHandle->exec("UPDATE `distinte` SET deleted=1 WHERE commessa='{$commessa}' AND idUtente={$this->userId} AND deleted=0");
-  }
-
-  /**
-   * Virtual delete all commesse of an user, set to delete=1 in database only
+   * @param string $article
    */
-  public function DeleteAllCommesse()
+  public function DeleteCommessaArticle(string $article, string $commessa)
   {
-    $this->dbHandle->exec("UPDATE `distinte` SET deleted=1 WHERE idUtente={$this->userId} AND deleted=0");
+    $this->dbHandle->exec("UPDATE `distinte` SET deleted=1 WHERE commessa='{$commessa}' AND barcode='{$article}' AND idUtente={$this->userId} AND deleted=0");
   }
 
   /**
@@ -49,7 +40,7 @@ class Distinta
    * @param string $barcode
    * @return bool
    */
-  public function isCommessaPresent(string $barcode): bool
+  public function commessaExists(string $barcode): bool
   {
     return (count($this->dbHandle->exec("SELECT * FROM `distinte` WHERE `commessa` = '{$barcode}' AND `idUtente` = '{$this->userId}' AND `deleted` = '0'")) > 0);
   }
@@ -129,53 +120,4 @@ class Distinta
       return $label[0]['label_id'];
     return null;
   }
-
-  public function SendToIcamStorage(array $commesse)
-  {
-    $xml = <<<SOAP
-<?xml version="1.0" encoding="utf-8"?>
-<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ser="http://servizi_xchange.org/">
-  <soapenv:Header/>
-  <soapenv:Body>
-    <ser:ImportLists>
-SOAP;
-
-    $xmlData = '';
-    foreach($commesse as $commessa) {
-      $listaCode = 'OpenMindTestList' . rand(10, 200);
-      $xmlData .= <<<SOAP
-<ser:InputLists>
-  <ser:ListToImport>
-    <ser:ListHead>
-      <ser:external_list_code>{$listaCode}</ser:external_list_code>
-      <ser:operation_type>SCARICO</ser:operation_type>
-      <ser:operation>SCARICO</ser:operation>
-      <ser:user_id>sa</ser:user_id>
-    </ser:ListHead>
-    <ser:ListDetail>
-      <ser:item_id>{$commessa['barcode']}</ser:item_id>
-      <ser:quantity>{$commessa['qta_prelevare']}</ser:quantity>
-    </ser:ListDetail>
-  </ser:ListToImport>
-</ser:InputLists>
-SOAP;
-
-    }
-
-    $xml .= $xmlData;
-
-    $xml .= <<<SOAP
-      <ser:Output_Type>1</ser:Output_Type>
-    </ser:ImportLists>
-  </soapenv:Body>
-</soapenv:Envelope>
-SOAP;
-
-
-    $mvHost = \F3::get('VERTICALSTORAGE.MV_ADDRESS');
-    if (!empty($mvHost)) {
-      $icam = new Soap("http://{$mvHost}/servizi_xchange.asmx");
-      $icam->ImportLists($xml, 'http://servizi_xchange.org/ImportLists');
-    }
-  }
 }

+ 41 - 11
src/Modules/Dimatec/MigrationData.php

@@ -131,7 +131,7 @@ EOF;
   }
 
   /**
-   * Ritorna la query di massificazione dalla tabella INTMAVOF
+   * Ritorna la query di massificazione (raggruppamento delle quantità per codice articolo e prebolla) dalla tabella INTMAVOF
    *
    * @param string $operationType values: 'CARICO' or 'SCARICO'
    * @return string
@@ -141,11 +141,11 @@ EOF;
     $filter = $this->fixOperationTypeValue($operationType);
 
     return <<<EOF
-SELECT tb1.MXARTI, tb1.MXQTMI, tb1.MXDESC, tb2.qty FROM INTMAV0F AS tb1
-JOIN (SELECT MXARTI, sum(MXQTMI) AS qty FROM INTMAV0F WHERE $filter GROUP BY MXARTI) AS tb2
-ON tb1.MXARTI = tb2.mxarti
-WHERE $filter
-ORDER BY tb1.MXARTI, tb1.MXIDDM
+SELECT MXCORD, MXARTI, MXDESC, MXRIFC, SUM(MXQTMI) AS QTY
+FROM SMEDAT_DIM.INTMAV0F
+WHERE $filter AND MXSTAT<>80
+GROUP BY MXARTI, MXCORD, MXDESC, MXRIFC
+ORDER BY MXCORD, MXARTI
 EOF;
 
   }
@@ -159,7 +159,7 @@ EOF;
   public function soapCompileFrom(iterable $data, string $operationType)
   {
     $idList = 'ID-' . uniqid();
-    $dateTime = date("d/m/Y alle H:i:s");
+    $dateTime = date("d/m/Y H:i:s");
     $operationType = $operationType == 'CARICO' ? 'CARICO' : 'SCARICO';
 
     foreach($data as $row) {
@@ -183,7 +183,7 @@ EOF;
 $this->listXml
         </ser:ListToImport>
       </ser:InputLists>
-      <ser:Output_Type>0</ser:Output_Type>
+      <ser:Output_Type>1</ser:Output_Type>
     </ser:ImportLists>
   </soapenv:Body>
 </soapenv:Envelope>
@@ -196,15 +196,45 @@ EOF;
    * @param $xmlSoap
    * @return bool true if successful
    */
-  public function sendToIcam($xmlSoap): bool
+  public function sendToIcam(): bool
   {
     global $f3;
 
     $ws_url = 'http://' . $f3->get('VERTICALSTORAGE.MV_ADDRESS') . '/servizi_xchange.asmx';
 
-    $ret = $this->soapClient->__doRequest($xmlSoap, $ws_url, $this->soapAction, SOAP_1_1);
+    $ret = $this->soapClient->__doRequest($this->finalXml, $ws_url, $this->soapAction, SOAP_1_1);
 
-    return is_string($ret);
+    return boolval($ret);
   }
 
+  /**
+   * Importa la distinta sul database di OM-Link
+   *
+   * @param $dataRows
+   * @return int number of rows imported
+   */
+  public function saveDistinta($dataRows): int
+  {
+    global $f3;
+    /** @var SQL $db */
+    $db = $f3->get('DB');
+
+    $idUtente = $f3->get('USER')->id;
+
+    $distinta = new SQL\Mapper($db, 'distinte');
+    foreach($dataRows as $count => $data) {
+      $distinta->reset();
+      $distinta->idUtente = $idUtente;
+      $distinta->origine = $data['MXUBIC'];
+      $distinta->consegna = $data['MXIDDM'];
+      $distinta->commessa = trim($data['MXCORD']);
+      $distinta->codcliente = trim(substr($data['MXRIFC'], 7));
+      $distinta->barcode = trim($data['MXARTI']);
+      $distinta->descrizione = trim($data['MXDESC']);
+      $distinta->qta_prelevare = $data['QTY'];
+      $distinta->qta_mancante = 0;
+      $distinta->save();
+    }
+    return $count;
+  }
 }

+ 27 - 16
src/Modules/Dimatec/Pages.php

@@ -7,6 +7,7 @@
 
 namespace Modules\Dimatec;
 
+use DB\SQL;
 use OpenMind\FindBox\FindBoxCoreSystem;
 use OpenMind\FindBox\QueueCommand;
 use OpenMind\FindBox\SmartESL;
@@ -28,7 +29,7 @@ class Pages extends Controller
   /**
    * Send QueueSystem command for all labels associated
    *
-   * @param $distinta
+   * @param Distinta $distinta
    * @param array $commesse
    */
   private function sendLabelMsg($distinta, array $commesse)
@@ -81,8 +82,6 @@ class Pages extends Controller
         // Send blink to all labels associated to barcode
         $this->sendLabelMsg($distinta, $commesse);
 
-        $distinta->SendToIcamStorage($commesse);
-
         $f3->set('SESSION.barcode_mv', $stepValues['barcode_mv']);
         $f3->reroute("/pick2light/2");
         return;
@@ -90,7 +89,7 @@ class Pages extends Controller
       case 2:
         $f3->set('NEXTSTEP', 2);
         if (isset($stepValues['commessa'])) {
-          if (!$distinta->isCommessaPresent($stepValues['commessa'])) {
+          if (!$distinta->commessaExists($stepValues['commessa'])) {
             $f3->set('INFOTEXT', "Codice cesta non corretto");
           } else {
             $labelid = $distinta->GetLabelIdFromBarcode($stepValues['commessa']);
@@ -103,7 +102,7 @@ class Pages extends Controller
               $qm = new QueueSystem('FindBoxService');
               $qm->send($obj);
 
-              $distinta->DeleteCommessa($stepValues['commessa']);
+              $distinta->DeleteCommessaArticle($stepValues['barcode_mv'], $stepValues['commessa']);
             }
           }
         }
@@ -148,11 +147,21 @@ class Pages extends Controller
       $j_eslData = json_encode($eslData);
       $err = $this->findBoxCore->SaveProducts($bindData['labelid'], '', $eslData);
 
-      $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['commessa']}')"
-      );
+      // 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']}')"
+            );*/
     }
 
 
@@ -196,10 +205,10 @@ class Pages extends Controller
 
 
   /**
-   * Import lists from as400 to MAV
+   * Import lists from as400
    * @param $f3
    */
-  public function AS4002MAV($f3)
+  public function ImportFromAS400($f3)
   {
     $migData = new MigrationData();
 
@@ -211,11 +220,13 @@ class Pages extends Controller
 
     // Compile xml for SOAP
     $migData->soapCompileFrom($data, 'SCARICO');
-
-    if (!$migData->sendToIcam($this->finalXml))
+    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
-      $f3->set('IMPORT_RESULT', 'Liste inviate correttamente al Magazzino Verticale');
+    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');

+ 1 - 1
src/OpenMind/DataManager/CSVImporter.php

@@ -142,7 +142,7 @@ class CSVImporter
     global $f3;
     $this->dbMysql->query("TRUNCATE TABLE `distinte`");
     foreach($data as $dataRow) {
-      $descr = $dataRow[10];
+      $descr = addslashes($dataRow[10]);
       $sql = <<<EOL
 INSERT INTO distinte (
 origine, consegna, commessa, ordine_produzione, data_creazione, time_creazione, destinazione_merci, barcode, descrizione, qta_prelevare, qta_mancante

+ 4 - 3
src/OpenMind/FindBox/FindBoxService.php

@@ -39,7 +39,7 @@ class FindBoxService
 
   private function getCurrentQueue()
   {
-    echo "Checking QueueSystem               \n";
+    //echo "Checking QueueSystem               \n";
     $table = new QueueSystem('FindBoxService');
     while (!$table->check()) {
 
@@ -90,13 +90,14 @@ class FindBoxService
    */
   public function Main($f3)
   {
+    echo "Starting FindBoxService main loop\n";
     while (true) {
 
       $this->updateServiceStatus();
 
       $this->getCurrentQueue();
 
-      echo 'Label in cache: ' . count($this->labelToBlink) . "     \n";
+      //echo 'Label in cache: ' . count($this->labelToBlink) . "     \n";
       foreach($this->labelToBlink as $labelId => $label) {
 
 
@@ -129,7 +130,7 @@ class FindBoxService
       }
 
       sleep(1);
-      echo "Restart loop                  \n";
+      //echo "Restart loop                  \n";
       ob_flush();
       flush();
 

+ 1 - 1
test/test.xml

@@ -36,7 +36,7 @@
           </ser:ListDetail>
         </ser:ListToImport>
       </ser:InputLists>
-      <ser:Output_Type>0</ser:Output_Type>
+      <ser:Output_Type>1</ser:Output_Type>
     </ser:ImportLists>
   </soapenv:Body>
 </soapenv:Envelope>

+ 8 - 3
ui/css/omlink.css

@@ -35,9 +35,14 @@ body {
   src: local("Roboto"), local("Roboto-Regular"), url("ui/fonts/Roboto-Regular.ttf") format("truetype");
   unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+2074, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
 }
-.error_body {
-  background-image: url("ui/images/error_bg.png");
-  background-repeat: no-repeat;
+.error_body:before {
+  content: "";
+  position: absolute;
+  left: 0;
+  top: 0;
+  width: 100%;
+  height: 100%;
+  background: url("ui/images/error_bg.png");
   background-size: cover;
 }