|
|
@@ -10,11 +10,29 @@ namespace Modules\Dimatec;
|
|
|
|
|
|
use DB\SQL;
|
|
|
|
|
|
+// DB2 Connection
|
|
|
+define('DB2DSN', "odbc:Driver={iSeries Access ODBC Driver};DefaultLibraries=SMEDAT_DIM;SYSTEM=");
|
|
|
+define('DB2UID', 'icam');
|
|
|
+define('DB2PWD', 'icam');
|
|
|
+
|
|
|
+// MAV DB Connection
|
|
|
+define('MAVDBDSN', "sqlsrv:Database=icamdbstore;Encrypt=false;TrustServerCertificate=false;Server=");
|
|
|
+define('MAVDBUID', 'sa');
|
|
|
+define('MAVDBPWD', 'sa');
|
|
|
+
|
|
|
class MigrationData
|
|
|
{
|
|
|
+
|
|
|
+ const STATUS_NEW = 0;
|
|
|
+ CONST STATUS_PENDING = 50;
|
|
|
+ CONST STATUS_DONE = 80;
|
|
|
+
|
|
|
/** @var SQL $dbHandle DB2 */
|
|
|
private $dbHandle;
|
|
|
|
|
|
+ /** @var SQL $dbHandle MSSQL Server */
|
|
|
+ private $dbMAVHandle;
|
|
|
+
|
|
|
/** @var \SoapClient $soapClient MAV client */
|
|
|
private $soapClient;
|
|
|
|
|
|
@@ -25,6 +43,15 @@ class MigrationData
|
|
|
private $finalXml;
|
|
|
private $listXml;
|
|
|
|
|
|
+ // The ids of current articles to move from DB2 to MAV
|
|
|
+ private $db2RowsId = [];
|
|
|
+
|
|
|
+ public function ClearCachedIDs()
|
|
|
+ {
|
|
|
+ global $System;
|
|
|
+ $System->getCache()->clear('db2RowsId');
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Create the connection client to a SOAP server
|
|
|
* @param string $serverAddress IP Address
|
|
|
@@ -38,26 +65,78 @@ class MigrationData
|
|
|
));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get all missions from DB2 without status 0
|
|
|
+ * @param string $operationType
|
|
|
+ */
|
|
|
+ public function selectAvailableMissions(string $operationType)
|
|
|
+ {
|
|
|
+ global $System;
|
|
|
+
|
|
|
+ $filter = $this->fixOperationTypeValue($operationType);
|
|
|
+
|
|
|
+ $this->db2RowsId = array_column($this->query("SELECT MXIDDM FROM SMEDAT_DIM.INTMAV0F WHERE $filter AND MXSTAT=0"), 'MXIDDM');
|
|
|
+ $System->getCache()->set('db2RowsId', $this->db2RowsId);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Set mission status on AS400
|
|
|
+ * @param int $status
|
|
|
+ * @param $listaId
|
|
|
+ */
|
|
|
+ public function MarkMissions(int $status, $listaId)
|
|
|
+ {
|
|
|
+ global $System;
|
|
|
+
|
|
|
+ $this->db2RowsId = $System->getCache()->get('db2RowsId');
|
|
|
+ $ids = join(", ", $this->db2RowsId);
|
|
|
+ $this->query("UPDATE SMEDAT_DIM.INTMAV0F SET MXSTAT=$status, MXNOLS='$listaId' WHERE MXIDDM IN ($ids)");
|
|
|
+ }
|
|
|
+
|
|
|
+ public function SetMissionsBarcodes(string $barcode, string $commessa)
|
|
|
+ {
|
|
|
+ global $System;
|
|
|
+
|
|
|
+ $this->db2RowsId = $System->getCache()->get('db2RowsId');
|
|
|
+ $ids = join(", ", $this->db2RowsId);
|
|
|
+ $this->query("UPDATE SMEDAT_DIM.INTMAV0F SET MXNCON='$barcode' WHERE MXCORD='$commessa' AND MXIDDM IN ($ids)");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * MAV DB constructor.
|
|
|
+ * @param string $serverAddress IP Address
|
|
|
+ */
|
|
|
+ public function MAVDatabaseConnector()
|
|
|
+ {
|
|
|
+ global $f3;
|
|
|
+ $this->dbMAVHandle = new SQL(
|
|
|
+ MAVDBDSN . $f3->get('VERTICALSTORAGE.MV_ADDRESS'),
|
|
|
+ MAVDBUID, MAVDBPWD,
|
|
|
+ array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* PDO constructor.
|
|
|
* @param string $serverAddress IP Address
|
|
|
*/
|
|
|
- public function DatabaseConnector(string $serverAddress)
|
|
|
+ public function DB2Connector()
|
|
|
{
|
|
|
+ global $f3;
|
|
|
$this->dbHandle = new SQL(
|
|
|
- "odbc:Driver={iSeries Access ODBC Driver};DefaultLibraries=SMEDAT_DIM;SYSTEM=$serverAddress;",
|
|
|
+ DB2DSN . $f3->get('VERTICALSTORAGE.DB2_ADDRESS'),
|
|
|
'icam', 'icam',
|
|
|
array(\PDO::ATTR_ERRMODE => \PDO::ERRMODE_EXCEPTION));
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* @param $sql
|
|
|
- * @param int $mode default \PDO::FETCH_ASSOC
|
|
|
* @return array
|
|
|
*/
|
|
|
- public function query($sql, $mode = \PDO::FETCH_ASSOC): array
|
|
|
+ public function query($sql)
|
|
|
{
|
|
|
- return $this->dbHandle->exec($sql, $mode);
|
|
|
+ return $this->dbHandle->exec($sql);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -113,9 +192,9 @@ EOF;
|
|
|
*/
|
|
|
public function copyAllToAS400($data): bool
|
|
|
{
|
|
|
- $this->dbHandle->exec("TRUNCATE TABLE INTMUB0F");
|
|
|
+ $this->dbHandle->exec("TRUNCATE TABLE SMEDAT_DIM.INTMUB0F");
|
|
|
foreach($data as $key => $value) {
|
|
|
- $this->dbHandle->exec("INSERT INTO INTMUB0F (UXSTAT, UXCOAP, UXQTGC, UXQTMA) VALUES (10, '${value['UXCOAP']}', ${value['UXQTGC']}, ${value['UXQTMA']})");
|
|
|
+ $this->dbHandle->exec("INSERT INTO SMEDAT_DIM.INTMUB0F (UXSTAT, UXCOAP, UXQTGC, UXQTMA) VALUES (10, '${value['UXCOAP']}', ${value['UXQTGC']}, ${value['UXQTMA']})");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -140,14 +219,48 @@ EOF;
|
|
|
{
|
|
|
$filter = $this->fixOperationTypeValue($operationType);
|
|
|
|
|
|
+ $status = MigrationData::STATUS_NEW;
|
|
|
return <<<EOF
|
|
|
SELECT MXCORD, MXARTI, MXDESC, MXRIFC, SUM(MXQTMI) AS QTY
|
|
|
FROM SMEDAT_DIM.INTMAV0F
|
|
|
-WHERE $filter AND MXSTAT<>80
|
|
|
+WHERE $filter AND MXSTAT=$status
|
|
|
GROUP BY MXARTI, MXCORD, MXDESC, MXRIFC
|
|
|
ORDER BY MXCORD, MXARTI
|
|
|
EOF;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Ritorna la query di massificazione (raggruppamento delle quantità per codice articolo ignorando la prebolla) dalla tabella INTMAVOF
|
|
|
+ *
|
|
|
+ * @param string $operationType values: 'CARICO' or 'SCARICO'
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function strQueryPerMAV(string $operationType): string
|
|
|
+ {
|
|
|
+ $filter = $this->fixOperationTypeValue($operationType);
|
|
|
+
|
|
|
+ $status = MigrationData::STATUS_NEW;
|
|
|
+ return <<<EOF
|
|
|
+SELECT MXARTI, MXDESC, SUM(MXQTMI) AS QTY
|
|
|
+FROM (SELECT * FROM SMEDAT_DIM.INTMAV0F ORDER BY MXCORD) AS tbl
|
|
|
+WHERE $filter AND MXSTAT={$status}
|
|
|
+GROUP BY MXARTI, MXDESC
|
|
|
+EOF;
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * Query da eseguire sul database di OM-Link, ottiene una lista massificata per quantità articolo, UDS e ordinata per esso
|
|
|
+ *
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function strQueryMassificazioneByUDS(): string
|
|
|
+ {
|
|
|
+ return <<<EOF
|
|
|
+SELECT `uds`, `barcode`, `descrizione`, SUM(`qta_prelevare`) AS `qta`
|
|
|
+FROM `distinte`
|
|
|
+GROUP BY `barcode`
|
|
|
+ORDER BY `uds`
|
|
|
+EOF;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -155,8 +268,9 @@ EOF;
|
|
|
*
|
|
|
* @param string $operationType values: 'CARICO' or 'SCARICO'
|
|
|
* @param iterable $data
|
|
|
+ * @return string return id list
|
|
|
*/
|
|
|
- public function soapCompileFrom(iterable $data, string $operationType)
|
|
|
+ public function soapCompileFrom(iterable $data, string $operationType): string
|
|
|
{
|
|
|
$idList = 'ID-' . uniqid();
|
|
|
$dateTime = date("d/m/Y H:i:s");
|
|
|
@@ -166,10 +280,10 @@ EOF;
|
|
|
|
|
|
// List Head
|
|
|
$this->soapAddHead($idList, $operationType, "Lista di $operationType da as400 del $dateTime", '');
|
|
|
- $descArti = trim($row['MXDESC']); // trim($row['MXCORD']) . ' ' . trim(substr($row['MXRIFC'], 7)) . ' ' . trim($row['MXDESC']);
|
|
|
+ $descArti = trim($row['descrizione']); // trim($row['commessa']) . ' ' . trim(substr($row['codcliente'], 7)) . ' ' . trim($row['descrizione']);
|
|
|
|
|
|
// List Article
|
|
|
- $this->soapAddArticle($row['MXARTI'], $row['QTY'], $descArti);
|
|
|
+ $this->soapAddArticle($row['barcode'], $row['qta_prelevare'], $descArti);
|
|
|
}
|
|
|
|
|
|
$this->finalXml = <<<EOF
|
|
|
@@ -189,6 +303,7 @@ $this->listXml
|
|
|
</soapenv:Envelope>
|
|
|
EOF;
|
|
|
|
|
|
+ return $idList;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -208,33 +323,71 @@ EOF;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * Importa la distinta sul database di OM-Link
|
|
|
+ * Prepara la distinta da importare sul database di OM-Link
|
|
|
*
|
|
|
* @param $dataRows
|
|
|
- * @return int number of rows imported
|
|
|
+ * @param array $uds
|
|
|
+ * @return array
|
|
|
*/
|
|
|
- public function saveDistinta($dataRows): int
|
|
|
+ public function prepareDistinta($dataRows, array $uds)
|
|
|
{
|
|
|
global $f3;
|
|
|
- /** @var SQL $db */
|
|
|
- $db = $f3->get('DB');
|
|
|
+
|
|
|
+ $ret = [];
|
|
|
|
|
|
$idUtente = $f3->get('USER')->id;
|
|
|
|
|
|
- $distinta = new SQL\Mapper($db, 'distinte');
|
|
|
+ $cols = array_column($uds, 'item_id');
|
|
|
foreach($dataRows as $count => $data) {
|
|
|
+ $container_id = '';
|
|
|
+ $colId = array_search(trim($data['MXARTI']), $cols);
|
|
|
+ if ($colId !== false)
|
|
|
+ $container_id = $uds[$colId]['container_id'];
|
|
|
+
|
|
|
+ $ret[] = [
|
|
|
+ 'idUtente' => $idUtente,
|
|
|
+ 'origine' => $data['MXUBIC'],
|
|
|
+ 'consegna' => $data['MXIDDM'],
|
|
|
+ 'commessa' => trim($data['MXCORD']), // Codice prebolla
|
|
|
+ 'codcliente' => trim(substr($data['MXRIFC'], 7)),
|
|
|
+ 'barcode' => trim($data['MXARTI']),
|
|
|
+ 'descrizione' => trim($data['MXDESC']),
|
|
|
+ 'qta_prelevare' => $data['QTY'],
|
|
|
+ 'qta_mancante' => 0,
|
|
|
+ 'uds' => $container_id // posizione UDS
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ // Sort menus buy 'order' option
|
|
|
+ usort($ret, function ($obj1, $obj2) {
|
|
|
+ return $obj1['uds'] <=> $obj2['uds'];
|
|
|
+ });
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Importa la distinta sul database di OM-Link
|
|
|
+ *
|
|
|
+ * @param array $data
|
|
|
+ */
|
|
|
+ public function saveDistinta(array $data)
|
|
|
+ {
|
|
|
+ global $f3;
|
|
|
+
|
|
|
+ $distinta = new SQL\Mapper($f3->get('DB'), 'distinte');
|
|
|
+ foreach($data as $row) {
|
|
|
$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->copyfrom($row);
|
|
|
$distinta->save();
|
|
|
}
|
|
|
- return $count;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Get all UDS positions of MAV articles
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function getUDSs(): array
|
|
|
+ {
|
|
|
+ return $this->dbMAVHandle->exec('SELECT item_id, container_id, subcontainer_id from dbo.vw_item_positions');
|
|
|
+ }
|
|
|
+
|
|
|
}
|