From 852fbffa98a71acbc337bce219c35daa3eec2ea3 Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 1 Feb 2018 15:14:52 +0100 Subject: [PATCH] Reassing MR by sale ID when id relay is not set --- reassign_mr.php | 91 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 reassign_mr.php diff --git a/reassign_mr.php b/reassign_mr.php new file mode 100644 index 0000000..e523047 --- /dev/null +++ b/reassign_mr.php @@ -0,0 +1,91 @@ +ExecuteS(' + SELECT mr_s.* + FROM `'._DB_PREFIX_.'mr_selected` mr_s + WHERE mr_s.`id_order` IN ( + SELECT DISTINCT o.id_order + FROM `'._DB_PREFIX_.'orders` o + LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON o.`id_order` = d.`id_order` + LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON d.`product_id` = c.`id_product` + LEFT JOIN `'._DB_PREFIX_.'philea_sent` pms ON (pms.`id_sale` = c.`id_sale` AND pms.`id_order` = o.`id_order`) + WHERE c.`id_sale` = '.$sale.' AND o.id_carrier = 91 + ) AND MR_Selected_Num = "" +'); + +$orderNb = count($order); +echo date('Y-m-d H:i:s')." - $orderNb commandes sans num MR\n"; +if ($orderNb > 0) { + foreach ($order as $o) { + // Looks for MR + $mr = Db::getInstance()->ExecuteS(' + SELECT * FROM `'._DB_PREFIX_.'mondialrelay_relais` + WHERE colnom = "'.$o['MR_Selected_LgAdr1'].'" + AND colrue = "'.$o['MR_Selected_LgAdr3'].'" + AND codpos = "'.$o['MR_Selected_CP'].'" + '); + if (count($mr) == 1) { + $relai = $mr[0]; + echo "Order ".$o['id_order']." - MR : ".$relai['direction']."\n"; + + // Update + if (!empty($relai['direction'])) { + $sql = 'UPDATE `'._DB_PREFIX_.'mr_selected` SET MR_Selected_Num = '.$relai['direction']. + ' WHERE id_mr_selected = '.$o['id_mr_selected'].' AND id_order = '.$o['id_order']; + if ($optVerbose) { + echo $sql."\n"; + } + if (!$optTest) { + Db::getInstance()->ExecuteS($sql); + } + } + } + elseif (count($mr) > 1) { + echo "Order ".$o['id_order']." - MR > 1 - manual.\n"; + } else { + echo "Order ".$o['id_order']." - MR not found.\n"; + } + } +} + +echo date('Y-m-d H:i:s')." - END \n";