Merge branch 'ticket-philea'
This commit is contained in:
commit
5b3ac86cc5
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||||
include dirname(__FILE__).'/../../config/config.inc.php';
|
include dirname(__FILE__).'/../../config/config.inc.php';
|
||||||
|
die('test');
|
||||||
if(isset($_SERVER['REMOTE_ADDR'])) {
|
if(isset($_SERVER['REMOTE_ADDR'])) {
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
@ -39,11 +39,11 @@ if($row = Db::getInstance()->getRow('
|
|||||||
ORDER BY `date_add` ASC
|
ORDER BY `date_add` ASC
|
||||||
')) {
|
')) {
|
||||||
// SEND CDC02
|
// SEND CDC02
|
||||||
/*Db::getInstance()->ExecuteS('
|
Db::getInstance()->ExecuteS('
|
||||||
UPDATE `'._DB_PREFIX_.'philea_sync`
|
UPDATE `'._DB_PREFIX_.'philea_sync`
|
||||||
SET `status` = 4
|
SET `status` = 4
|
||||||
WHERE `id_sync` = '.(int) $row['id_sync'].'
|
WHERE `id_sync` = '.(int) $row['id_sync'].'
|
||||||
LIMIT 1
|
LIMIT 1
|
||||||
');
|
');
|
||||||
system('cd '.dirname(__FILE__).'/script && php send_commande.php '.(int) $row['id_sale']);*/
|
system('cd '.dirname(__FILE__).'/script && php send_commande.php '.(int) $row['id_sale']);
|
||||||
}
|
}
|
@ -1,442 +1,464 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
include('../../../config/settings.inc.php');
|
include('../../../config/settings.inc.php');
|
||||||
include('../../../config/config.inc.php');
|
include('../../../config/config.inc.php');
|
||||||
|
|
||||||
$_SERVER['SERVER_PORT'] = 80;
|
$_SERVER['SERVER_PORT'] = 80;
|
||||||
|
|
||||||
include( dirname(__FILE__) . '/../philea_magistor.php');
|
include( dirname(__FILE__) . '/../philea_magistor.php');
|
||||||
global $regex_file_in;
|
global $regex_file_in;
|
||||||
$regex_file_in = '@^CRE(.*)\.(BAL|DAT)@';
|
$regex_file_in = '@^CRE(.*)\.(BAL|DAT)@';
|
||||||
@ini_set('display_errors', 'on');
|
@ini_set('display_errors', 'on');
|
||||||
$magistorModule = new philea_magistor();
|
$magistorModule = new philea_magistor();
|
||||||
|
|
||||||
|
|
||||||
//$id_shipping = 4; // PHILEA
|
//$id_shipping = 4; // PHILEA
|
||||||
|
|
||||||
$CRE = array(
|
$CRE = array(
|
||||||
'OP_CODE' => array(1,10),
|
'OP_CODE' => array(1,10),
|
||||||
'CODE_SOC' => array(11,20),
|
'CODE_SOC' => array(11,20),
|
||||||
'NO_CLIENT' => array(31,8),
|
'NO_CLIENT' => array(31,8),
|
||||||
'N_CDE' => array(39,50),
|
'N_CDE' => array(39,50),
|
||||||
'NO_COLIS' => array(89,50),
|
'NO_COLIS' => array(89,50),
|
||||||
'NO_TRACKING' => array(139,50),
|
'NO_TRACKING' => array(139,50),
|
||||||
'NO_EXPEDITION' => array(189,50),
|
'NO_EXPEDITION' => array(189,50),
|
||||||
'DATE_EXPED' => array(239,8),
|
'DATE_EXPED' => array(239,8),
|
||||||
'TRANSPORTEUR' => array(247,50),
|
'TRANSPORTEUR' => array(247,50),
|
||||||
);
|
'CODE_ART' => array(297, 50),
|
||||||
|
'QTE' => array(347, 10),
|
||||||
|
);
|
||||||
|
|
||||||
$tab_conversion_carrier = philea_magistor::getTabState();
|
$tab_conversion_carrier = philea_magistor::getTabState();
|
||||||
|
|
||||||
$socol_to_magistor = array(
|
$socol_to_magistor = array(
|
||||||
'DOM' => 'SOCOLMDSS',
|
'DOM' => 'SOCOLMDSS',
|
||||||
'DOS' => 'SOCOLMDS',
|
'DOS' => 'SOCOLMDS',
|
||||||
'RDV' => 'SOCOLMRDV',
|
'RDV' => 'SOCOLMRDV',
|
||||||
'CIT' => 'SOCOLCITY',
|
'CIT' => 'SOCOLCITY',
|
||||||
'BPR' => 'SOCOLMBP',
|
'BPR' => 'SOCOLMBP',
|
||||||
'CDI' => 'SOCOLMBP',
|
'CDI' => 'SOCOLMBP',
|
||||||
'A2P' => 'SOCOLMC',
|
'A2P' => 'SOCOLMC',
|
||||||
'ACP' => 'SOCOLMBP',
|
'ACP' => 'SOCOLMBP',
|
||||||
);
|
);
|
||||||
|
|
||||||
$mr_to_magistor = array(
|
$mr_to_magistor = array(
|
||||||
'24R' => 'MRMDSS', // Point relais
|
'24R' => 'MRMDSS', // Point relais
|
||||||
'DRI' => 'MRMDS', // Colis drive
|
'DRI' => 'MRMDS', // Colis drive
|
||||||
'LD1' => 'MRMRDV', // Domicile RDC (1 pers)
|
'LD1' => 'MRMRDV', // Domicile RDC (1 pers)
|
||||||
'LDS' => 'MRCITY', // Domicile spé (2 pers)
|
'LDS' => 'MRCITY', // Domicile spé (2 pers)
|
||||||
'HOM' => 'MRMBP', // Domicile spé
|
'HOM' => 'MRMBP', // Domicile spé
|
||||||
);
|
);
|
||||||
|
|
||||||
$format = $CRE;
|
$format = $CRE;
|
||||||
if($magistorModule->active) {
|
if($magistorModule->active) {
|
||||||
require_once('connection_ftp.php');
|
//require_once('connection_ftp.php');
|
||||||
@set_time_limit(0);
|
@set_time_limit(0);
|
||||||
|
|
||||||
// Checking for ".bal" files with a "CRE" prefix that has an equivalent ".dat" file and process them...
|
// Checking for ".bal" files with a "CRE" prefix that has an equivalent ".dat" file and process them...
|
||||||
$inFolder = dirname(__FILE__) . '/IN/';
|
$inFolder = dirname(__FILE__) . '/IN/';
|
||||||
|
|
||||||
$iterator = new DirectoryIterator($inFolder);
|
$iterator = new DirectoryIterator($inFolder);
|
||||||
$id_order_state = Configuration::get('PHILEA_MAGISTOR_STATUS_CRE');
|
$id_order_state = Configuration::get('PHILEA_MAGISTOR_STATUS_CRE');
|
||||||
|
|
||||||
foreach ($iterator as $fileinfo) {
|
foreach ($iterator as $fileinfo) {
|
||||||
if ($fileinfo->isFile()) {
|
if ($fileinfo->isFile()) {
|
||||||
if( preg_match('@^CRE(.*)\.BAL@', $fileinfo->getFilename())) {
|
if( preg_match('@^CRE(.*)\.BAL@', $fileinfo->getFilename())) {
|
||||||
$datFile = $fileinfo->getPath() . '/' . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() );
|
$datFile = $fileinfo->getPath() . '/' . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() );
|
||||||
|
|
||||||
if(file_exists($datFile)) {
|
if(file_exists($datFile)) {
|
||||||
$content = file_get_contents($datFile);
|
$content = file_get_contents($datFile);
|
||||||
$lines = preg_split('@\n@',$content);
|
$lines = preg_split('@\n@',$content);
|
||||||
|
|
||||||
if(!empty($lines)) {
|
|
||||||
foreach( $lines as $line ) {
|
|
||||||
$data = array();
|
|
||||||
foreach($format as $field=>$value) {
|
|
||||||
$data[] = substr($line, ($value[0]-1), $value[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!isset($data[2]) || (isset($data[2]) && !$data[2])){
|
$id_order_details = array();
|
||||||
continue;
|
$shipping_numbers = array();
|
||||||
}
|
$parcel_carrier = array();
|
||||||
|
if(!empty($lines)) {
|
||||||
|
foreach( $lines as $line ) {
|
||||||
|
|
||||||
$id_sale = 0;
|
$data = array();
|
||||||
$id_order = (string) $data[3];
|
foreach($format as $field=>$value) {
|
||||||
if(substr($id_order, 0, 2) == 'OP') {
|
$data[] = substr($line, ($value[0]-1), $value[1]);
|
||||||
$id_order = explode('-', $id_order);
|
}
|
||||||
if(count($id_order) < 2) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
$id_sale = (int) str_replace('OP', '', $id_order[0]);
|
|
||||||
$id_order = (int) $id_order[1];
|
|
||||||
} else {
|
|
||||||
$id_order = (int) $id_order;
|
|
||||||
}
|
|
||||||
|
|
||||||
if($detail = Db::getInstance()->getRow('
|
if(!isset($data[2]) || (isset($data[2]) && !$data[2])){
|
||||||
SELECT `id_order_detail`, `product_quantity` - GREATEST(`product_quantity_return`, `product_quantity_refunded`) AS `quantity`
|
continue;
|
||||||
FROM `'._DB_PREFIX_.'order_detail`
|
}
|
||||||
WHERE `id_order` = '.(int) $id_order.'
|
|
||||||
AND (
|
|
||||||
`product_ean13` = "'.pSQL($data[9]).'"
|
|
||||||
OR `product_supplier_reference` = "'.pSQL($data[9]).'"
|
|
||||||
)
|
|
||||||
')) {
|
|
||||||
$sent = (int) Db::getInstance()->getValue('
|
|
||||||
SELECT SUM(`quantity`)
|
|
||||||
FROM `'._DB_PREFIX_.'philea_parcel`
|
|
||||||
WHERE `id_order_detail` = '.(int) $detail['id_order_detail'].'
|
|
||||||
');
|
|
||||||
|
|
||||||
$to_send = (int) $detail['quantity'] - $sent;
|
$id_sale = 0;
|
||||||
|
$id_order = (string) $data[3];
|
||||||
|
if(substr($id_order, 0, 2) == 'OP') {
|
||||||
|
$id_order = explode('-', $id_order);
|
||||||
|
if(count($id_order) < 2) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
$id_sale = (int) str_replace('OP', '', $id_order[0]);
|
||||||
|
$id_order = (int) $id_order[1];
|
||||||
|
} else {
|
||||||
|
$id_order = (int) $id_order;
|
||||||
|
}
|
||||||
|
|
||||||
if((int) $data[10] <= $to_send) {
|
$order = new Order((int) $id_order);
|
||||||
if(trim($data[5]) != '') {
|
|
||||||
Db::getInstance()->ExecuteS('
|
|
||||||
INSERT INTO `'._DB_PREFIX_.'philea_parcel`
|
|
||||||
VALUES (
|
|
||||||
'.(int) $detail['id_order_detail'].',
|
|
||||||
'.(int) $data[10].',
|
|
||||||
"'.pSQL(trim($data[5])).'",
|
|
||||||
"'.pSQL(substr($data[7], 0, 4).'-'.substr($data[7], 4, 2).'-'.substr($data[7], 6, 2).' 18:00:00').'"
|
|
||||||
)
|
|
||||||
');
|
|
||||||
|
|
||||||
$id_order_details[] = (int) $detail['id_order_detail'];
|
$code_art = explode("_", trim($data[9]));
|
||||||
$shipping_numbers[] = '"'.pSQL(trim($data[5])).'"';
|
if(count($code_art)>1) {
|
||||||
|
list($id_product, $id_attribute) = $code_art;
|
||||||
|
} else {
|
||||||
|
$id_product = $code_art[0];
|
||||||
|
$id_attribute = 0;
|
||||||
|
}
|
||||||
|
if($detail = Db::getInstance()->getRow('
|
||||||
|
SELECT `id_order_detail`, `product_quantity` - GREATEST(`product_quantity_return`, `product_quantity_refunded`) AS `quantity`
|
||||||
|
FROM `'._DB_PREFIX_.'order_detail`
|
||||||
|
WHERE `id_order` = '.(int) $id_order.'
|
||||||
|
AND `product_id` = '.(int) $id_product.'
|
||||||
|
AND `product_attribute_id` = '.(int) $id_attribute.'
|
||||||
|
')) {
|
||||||
|
$sent = (int) Db::getInstance()->getValue('
|
||||||
|
SELECT SUM(`quantity`)
|
||||||
|
FROM `'._DB_PREFIX_.'philea_parcel`
|
||||||
|
WHERE `id_order_detail` = '.(int) $detail['id_order_detail'].'
|
||||||
|
');
|
||||||
|
|
||||||
if (isset($data[8]) && $data[8]){
|
$to_send = (int) $detail['quantity'] - $sent;
|
||||||
$carrier_name = trim($data[8]);
|
|
||||||
$carriers = philea_magistor::getCarriersIdByRef($carrier_name);
|
|
||||||
if ($carriers){
|
|
||||||
foreach ($carriers as $carrier) {
|
|
||||||
if ($carrier['name'] == 'GLS' && $carrier_name == 'DPD') {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if ($carrier['active'] == 1 && $carrier['deleted'] == 0) {
|
|
||||||
$id_active_carrier = (int) $carrier['id_carrier'];
|
|
||||||
}
|
|
||||||
if ($carrier['active'] == 0 && $carrier['deleted'] == 0) {
|
|
||||||
$id_inactive_carrier = (int) $carrier['id_carrier'];
|
|
||||||
}
|
|
||||||
// if ((int) $order->id_carrier == (int) $carrier['id_carrier']){
|
|
||||||
// $carrier_found = (int) $order->id_carrier;
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isset($id_active_carrier) && $id_active_carrier) {
|
if((int) $data[10] <= $to_send) {
|
||||||
$parcel_carrier[(int) $id_order.'|'.trim($data[5])] = $carriers[$data[8]];
|
if(trim($data[5]) != '') {
|
||||||
} else { // MISSING CARRIER
|
Db::getInstance()->ExecuteS('
|
||||||
$errors[] = array(
|
INSERT INTO `'._DB_PREFIX_.'philea_parcel`
|
||||||
$data[3],
|
VALUES (
|
||||||
$data[8], // carrier name
|
'.(int) $detail['id_order_detail'].',
|
||||||
$data[9],
|
'.(int) $data[10].',
|
||||||
$data[10], // quantity
|
"'.pSQL(trim($data[5])).'",
|
||||||
$data[5], // shipping number
|
"'.pSQL(substr($data[7], 0, 4).'-'.substr($data[7], 4, 2).'-'.substr($data[7], 6, 2).' 18:00:00').'"
|
||||||
$data[7],
|
)
|
||||||
'carrier_missing',
|
');
|
||||||
);
|
|
||||||
}
|
|
||||||
} else { // SHIPPING NUMBER IS EMPTY
|
|
||||||
$errors[] = array(
|
|
||||||
$data[3],
|
|
||||||
$data[8],
|
|
||||||
$data[9],
|
|
||||||
$data[10],
|
|
||||||
$data[5],
|
|
||||||
$data[7],
|
|
||||||
'empty_shipping_number',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// TOO MUCH
|
|
||||||
$errors[] = array(
|
|
||||||
$data[3],
|
|
||||||
$data[8],
|
|
||||||
$data[9],
|
|
||||||
$data[10],
|
|
||||||
$data[5],
|
|
||||||
$data[7],
|
|
||||||
'wrong_quantities',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// NOT FOUND
|
|
||||||
$errors[] = array(
|
|
||||||
$data[3],
|
|
||||||
$data[8],
|
|
||||||
$data[9],
|
|
||||||
$data[10],
|
|
||||||
$data[5],
|
|
||||||
$data[7],
|
|
||||||
'product_not_found',
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$id_order_details = array_unique($id_order_details);
|
$id_order_details[] = (int) $detail['id_order_detail'];
|
||||||
$shipping_numbers = array_unique($shipping_numbers);
|
$shipping_numbers[] = '"'.pSQL(trim($data[5])).'"';
|
||||||
|
|
||||||
if(count($id_order_details) > 0) {
|
// GET CARRIER ID
|
||||||
$id_orders = array();
|
$carrier_found = false;
|
||||||
$orders_infos = array();
|
$id_active_carrier = false;
|
||||||
|
$id_inactive_carrier = false;
|
||||||
|
if (isset($data[8]) && $data[8]){
|
||||||
|
$carrier_name = trim($data[8]);
|
||||||
|
$carriers = philea_magistor::getCarriersIdByRef($carrier_name);
|
||||||
|
if ($carriers){
|
||||||
|
foreach ($carriers as $carrier) {
|
||||||
|
if ($carrier['name'] == 'GLS' && $carrier_name == 'DPD') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($carrier['active'] == 1 && $carrier['deleted'] == 0) {
|
||||||
|
$id_active_carrier = (int) $carrier['id_carrier'];
|
||||||
|
}
|
||||||
|
if ($carrier['active'] == 0 && $carrier['deleted'] == 0) {
|
||||||
|
$id_inactive_carrier = (int) $carrier['id_carrier'];
|
||||||
|
}
|
||||||
|
if ((int) $order->id_carrier == (int) $carrier['id_carrier']){
|
||||||
|
$carrier_found = (int) $order->id_carrier;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach(Db::getInstance()->ExecuteQ('
|
if ($carrier_found)
|
||||||
SELECT d.`id_order`, p.`shipping_number`, p.`date_add`
|
$id_carrier = (int) $carrier_found;
|
||||||
FROM `'._DB_PREFIX_.'philea_parcel` p
|
elseif ($id_active_carrier)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
|
$id_carrier = (int) $id_active_carrier;
|
||||||
ON p.`id_order_detail` = d.`id_order_detail`
|
elseif ($id_inactive_carrier)
|
||||||
WHERE d.`id_order_detail` IN ('.implode(', ', $id_order_details).')
|
$id_carrier = (int) $id_inactive_carrier;
|
||||||
AND p.`shipping_number` IN ('.implode(', ', $shipping_numbers).')
|
else
|
||||||
GROUP BY d.`id_order`, p.`shipping_number`
|
$id_carrier = (int) $order->id_carrier;
|
||||||
') as $row) {
|
|
||||||
Db::getInstance()->ExecuteS('
|
|
||||||
INSERT INTO `'._DB_PREFIX_.'shipping_history`
|
|
||||||
VALUES (
|
|
||||||
'.(int) $row['id_order'].',
|
|
||||||
"'.pSQL($row['shipping_number']).'",
|
|
||||||
"'.pSQL($row['date_add']).'",
|
|
||||||
'.(int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']].',
|
|
||||||
0
|
|
||||||
)
|
|
||||||
');
|
|
||||||
|
|
||||||
$id_orders[] = (int) $row['id_order'];
|
if(isset($id_carrier) && $id_carrier) {
|
||||||
if(!isset($orders_infos[(int) $row['id_order']])) {
|
$parcel_carrier[(int) $id_order.'|'.trim($data[5])] = $id_carrier;
|
||||||
$orders_infos[(int) $row['id_order']] = array();
|
} else { // MISSING CARRIER
|
||||||
}
|
$errors[] = array(
|
||||||
$orders_infos[(int) $row['id_order']][] = array($row['shipping_number'], $row['date_add'], (int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']]);
|
$data[3],
|
||||||
}
|
$data[8], // carrier name
|
||||||
|
$data[9], // code article productId_attributeId
|
||||||
|
$data[10], // quantity
|
||||||
|
$data[5], // shipping number
|
||||||
|
$data[7],
|
||||||
|
'carrier_missing',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else { // SHIPPING NUMBER IS EMPTY
|
||||||
|
$errors[] = array(
|
||||||
|
$data[3],
|
||||||
|
$data[8],
|
||||||
|
$data[9],
|
||||||
|
$data[10],
|
||||||
|
$data[5],
|
||||||
|
$data[7],
|
||||||
|
'empty_shipping_number',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TOO MUCH
|
||||||
|
$errors[] = array(
|
||||||
|
$data[3],
|
||||||
|
$data[8],
|
||||||
|
$data[9],
|
||||||
|
$data[10],
|
||||||
|
$data[5],
|
||||||
|
$data[7],
|
||||||
|
'wrong_quantities',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// NOT FOUND
|
||||||
|
$errors[] = array(
|
||||||
|
$data[3],
|
||||||
|
$data[8],
|
||||||
|
$data[9],
|
||||||
|
$data[10],
|
||||||
|
$data[5],
|
||||||
|
$data[7],
|
||||||
|
'product_not_found',
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$id_orders = array_unique($id_orders);
|
$id_order_details = array_unique($id_order_details);
|
||||||
|
$shipping_numbers = array_unique($shipping_numbers);
|
||||||
|
|
||||||
$products = Db::getInstance()->ExecuteQ('
|
if(count($id_order_details) > 0) {
|
||||||
SELECT d.`id_order_detail`, d.`id_order`, c.`id_sale`, d.`product_quantity` - GREATEST(d.`product_quantity_refunded`, d.`product_quantity_return`) AS `quantity`
|
$id_orders = array();
|
||||||
FROM ps_order_detail d
|
$orders_infos = array();
|
||||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c
|
|
||||||
ON d.`product_id` = c.`id_product`
|
|
||||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
|
||||||
');
|
|
||||||
|
|
||||||
$sent_sales = array();
|
foreach(Db::getInstance()->ExecuteS('
|
||||||
foreach(Db::getInstance()->ExecuteQ('
|
SELECT d.`id_order`, p.`shipping_number`, p.`date_add`
|
||||||
SELECT `id_order`, `id_sale`
|
FROM `'._DB_PREFIX_.'philea_parcel` p
|
||||||
FROM `'._DB_PREFIX_.'shipping_history`
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (p.`id_order_detail` = d.`id_order_detail`)
|
||||||
WHERE `id_order` IN ('.implode(', ', $id_orders).')
|
WHERE d.`id_order_detail` IN ('.implode(', ', $id_order_details).')
|
||||||
AND `id_sale` != 0
|
AND p.`shipping_number` IN ('.implode(', ', $shipping_numbers).')
|
||||||
GROUP BY `id_order`, `id_sale`
|
GROUP BY d.`id_order`, p.`shipping_number`
|
||||||
') as $row) {
|
') as $row) {
|
||||||
if(!isset($sent_sales[(int) $row['id_order']])) {
|
Db::getInstance()->ExecuteS('
|
||||||
$sent_sales[(int) $row['id_order']] = array();
|
INSERT INTO `'._DB_PREFIX_.'shipping_history`
|
||||||
}
|
VALUES (
|
||||||
$sent_sales[(int) $row['id_order']][] = (int) $row['id_sale'];
|
'.(int) $row['id_order'].',
|
||||||
}
|
"'.pSQL($row['shipping_number']).'",
|
||||||
|
"'.pSQL($row['date_add']).'",
|
||||||
|
'.(int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']].',
|
||||||
|
0
|
||||||
|
)
|
||||||
|
');
|
||||||
|
|
||||||
$to_send = array();
|
$id_orders[] = (int) $row['id_order'];
|
||||||
foreach($products as $product) {
|
if(!isset($orders_infos[(int) $row['id_order']])) {
|
||||||
if((int) $product['quantity'] > 0
|
$orders_infos[(int) $row['id_order']] = array();
|
||||||
&& (!isset($sent_sales[(int) $product['id_order']])
|
}
|
||||||
|| !in_array((int) $product['id_sale'], $sent_sales[(int) $product['id_order']]))) {
|
$orders_infos[(int) $row['id_order']][] = array($row['shipping_number'], $row['date_add'], (int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']]);
|
||||||
$to_send[] = $product;
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($products);
|
$id_orders = array_unique($id_orders);
|
||||||
|
|
||||||
$sent_products = array();
|
$products = Db::getInstance()->ExecuteS('
|
||||||
foreach(Db::getInstance()->ExecuteQ('
|
SELECT d.`id_order_detail`, d.`id_order`, c.`id_sale`, d.`product_quantity` - GREATEST(d.`product_quantity_refunded`, d.`product_quantity_return`) AS `quantity`
|
||||||
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
|
FROM ps_order_detail d
|
||||||
FROM `'._DB_PREFIX_.'lapostews` l
|
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON (d.`product_id` = c.`id_product`)
|
||||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
|
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||||
ON l.`id_order_detail` = d.`id_order_detail`
|
');
|
||||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
|
||||||
GROUP BY l.`id_order_detail`
|
|
||||||
') as $row) {
|
|
||||||
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
|
||||||
}
|
|
||||||
foreach(Db::getInstance()->ExecuteQ('
|
|
||||||
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
|
|
||||||
FROM `'._DB_PREFIX_.'philea_parcel` l
|
|
||||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
|
|
||||||
ON l.`id_order_detail` = d.`id_order_detail`
|
|
||||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
|
||||||
GROUP BY l.`id_order_detail`
|
|
||||||
') as $row) {
|
|
||||||
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$orders_to_send = array();
|
$sent_sales = array();
|
||||||
$orders_list = array();
|
foreach(Db::getInstance()->ExecuteS('
|
||||||
|
SELECT `id_order`, `id_sale`
|
||||||
|
FROM `'._DB_PREFIX_.'shipping_history`
|
||||||
|
WHERE `id_order` IN ('.implode(', ', $id_orders).')
|
||||||
|
AND `id_sale` != 0
|
||||||
|
GROUP BY `id_order`, `id_sale`
|
||||||
|
') as $row) {
|
||||||
|
if(!isset($sent_sales[(int) $row['id_order']])) {
|
||||||
|
$sent_sales[(int) $row['id_order']] = array();
|
||||||
|
}
|
||||||
|
$sent_sales[(int) $row['id_order']][] = (int) $row['id_sale'];
|
||||||
|
}
|
||||||
|
|
||||||
$total = count($to_send);
|
$to_send = array();
|
||||||
|
foreach($products as $product) {
|
||||||
|
if ((int) $product['quantity'] > 0
|
||||||
|
&& (!isset($sent_sales[(int) $product['id_order']])
|
||||||
|
|| !in_array((int) $product['id_sale'], $sent_sales[(int) $product['id_order']]))) {
|
||||||
|
$to_send[] = $product;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach($to_send as $product) {
|
unset($products);
|
||||||
if(!in_array((int) $product['id_order'], $orders_list)) {
|
|
||||||
$orders_list[] = (int) $product['id_order'];
|
|
||||||
}
|
|
||||||
if(!in_array((int) $product['id_order'], $orders_to_send)) {
|
|
||||||
if(!isset($sent_products[(int) $product['id_order_detail']])
|
|
||||||
|| $product['quantity'] > $sent_products[(int) $product['id_order_detail']]) {
|
|
||||||
$orders_to_send[] = (int) $product['id_order'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($sent_products);
|
$sent_products = array();
|
||||||
unset($to_send);
|
foreach(Db::getInstance()->ExecuteS('
|
||||||
|
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
|
||||||
|
FROM `'._DB_PREFIX_.'lapostews` l
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
|
||||||
|
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||||
|
GROUP BY l.`id_order_detail`
|
||||||
|
') as $row) {
|
||||||
|
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
||||||
|
}
|
||||||
|
foreach(Db::getInstance()->ExecuteS('
|
||||||
|
SELECT l.`id_order_detail`, SUM(l.`quantity`) AS `quantity`
|
||||||
|
FROM `'._DB_PREFIX_.'philea_parcel` l
|
||||||
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (l.`id_order_detail` = d.`id_order_detail`)
|
||||||
|
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||||
|
GROUP BY l.`id_order_detail`
|
||||||
|
') as $row) {
|
||||||
|
$sent_products[(int) $row['id_order_detail']] = (int) $row['quantity'];
|
||||||
|
}
|
||||||
|
|
||||||
$orders_sent = array();
|
$orders_to_send = array();
|
||||||
foreach($orders_list as $order) {
|
$orders_list = array();
|
||||||
if(!in_array($order, $orders_to_send)) {
|
|
||||||
$orders_sent[] = $order;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($orders_list);
|
$total = count($to_send);
|
||||||
|
|
||||||
$status_sent = array();
|
foreach($to_send as $product) {
|
||||||
$status_partially_sent = array();
|
if(!in_array((int) $product['id_order'], $orders_list)) {
|
||||||
|
$orders_list[] = (int) $product['id_order'];
|
||||||
|
}
|
||||||
|
if(!in_array((int) $product['id_order'], $orders_to_send)) {
|
||||||
|
if(!isset($sent_products[(int) $product['id_order_detail']])
|
||||||
|
|| $product['quantity'] > $sent_products[(int) $product['id_order_detail']]) {
|
||||||
|
$orders_to_send[] = (int) $product['id_order'];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach($orders_sent as $order) {
|
unset($sent_products);
|
||||||
if((int) Db::getInstance()->getValue('
|
unset($to_send);
|
||||||
SELECT `id_order_state`
|
|
||||||
FROM `'._DB_PREFIX_.'order_history`
|
|
||||||
WHERE `id_order` = '.(int) $order.'
|
|
||||||
ORDER BY `date_add` DESC
|
|
||||||
') != 4) {
|
|
||||||
$status_sent[] = (int) $order;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($id_orders as $order) {
|
$orders_sent = array();
|
||||||
if(!in_array($order, $status_sent)) {
|
foreach($orders_list as $order) {
|
||||||
if(!in_array((int) Db::getInstance()->getValue('
|
if(!in_array($order, $orders_to_send)) {
|
||||||
SELECT `id_order_state`
|
$orders_sent[] = $order;
|
||||||
FROM `'._DB_PREFIX_.'order_history`
|
}
|
||||||
WHERE `id_order` = '.(int) $order.'
|
}
|
||||||
ORDER BY `date_add` DESC
|
|
||||||
'), array(4, 17, 9))) {
|
|
||||||
$status_partially_sent[] = (int) $order;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unset($orders_sent);
|
unset($orders_list);
|
||||||
unset($orders_to_send);
|
|
||||||
|
|
||||||
foreach($orders_infos as $id_order => $parcels) {
|
$status_sent = array();
|
||||||
$order = new Order($id_order);
|
$status_partially_sent = array();
|
||||||
$customer = new Customer((int) $order->id_customer);
|
|
||||||
|
|
||||||
foreach($parcels as $parcel) {
|
foreach($orders_sent as $order) {
|
||||||
$products_sent = '';
|
if((int) Db::getInstance()->getValue('
|
||||||
|
SELECT `id_order_state`
|
||||||
|
FROM `'._DB_PREFIX_.'order_history`
|
||||||
|
WHERE `id_order` = '.(int) $order.'
|
||||||
|
ORDER BY `date_add` DESC LIMIT 1
|
||||||
|
') != 4) {
|
||||||
|
$status_sent[] = (int) $order;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$products_names = array();
|
foreach($id_orders as $order) {
|
||||||
|
if(!in_array($order, $status_sent)) {
|
||||||
|
if(!in_array((int) Db::getInstance()->getValue('
|
||||||
|
SELECT `id_order_state`
|
||||||
|
FROM `'._DB_PREFIX_.'order_history`
|
||||||
|
WHERE `id_order` = '.(int) $order.'
|
||||||
|
ORDER BY `date_add` DESC LIMIT 1
|
||||||
|
'), array(4, 17, 9, 19))) {
|
||||||
|
$status_partially_sent[] = (int) $order;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
foreach(Db::getInstance()->ExecuteQ('
|
unset($orders_sent);
|
||||||
SELECT d.`id_order_detail`, d.`product_name`, SUM(p.`quantity`) AS `quantity`
|
unset($orders_to_send);
|
||||||
FROM `'._DB_PREFIX_.'philea_parcel` p
|
|
||||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
|
|
||||||
ON p.`id_order_detail` = d.`id_order_detail`
|
|
||||||
WHERE d.`id_order` = '.(int) $id_order.'
|
|
||||||
AND p.`shipping_number` = "'.pSQL($parcel[0]).'"
|
|
||||||
AND p.`date_add` = "'.pSQL($parcel[1]).'"
|
|
||||||
GROUP BY d.`id_order_detail`
|
|
||||||
') as $p) {
|
|
||||||
$products_sent .= '<br />'."\r\n".$p['quantity'].' x '.$p['product_name'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$carrier = new Carrier($parcel[2], (int) $order->id_lang);
|
foreach($orders_infos as $id_order => $parcels) {
|
||||||
|
$order = new Order($id_order);
|
||||||
|
$customer = new Customer((int) $order->id_customer);
|
||||||
|
|
||||||
if((int) $order->id_lang == 3) {
|
foreach($parcels as $parcel) {
|
||||||
if(in_array((int) $carrier->id, array(145, 152, 103))) {
|
$products_sent = '';
|
||||||
$carrier->url .= '&language=es_ES';
|
|
||||||
}
|
|
||||||
$content_html = '<strong>Contenido del paquete:</strong>';
|
|
||||||
$content_txt = 'Contenido del paquete:';
|
|
||||||
} else {
|
|
||||||
$content_html = '<strong>Contenu du colis :</strong>';
|
|
||||||
$content_txt = 'Contenu du colis :';
|
|
||||||
}
|
|
||||||
|
|
||||||
$templateVars = array(
|
$products_names = array();
|
||||||
'{followup}' => str_replace('@', $parcel[0], $carrier->url),
|
|
||||||
'{firstname}' => $customer->firstname,
|
|
||||||
'{lastname}' => $customer->lastname,
|
|
||||||
'{id_order}' => (int) $order->id,
|
|
||||||
'{product_list}' => !empty($products_sent)? $content_html.$products_sent: '',
|
|
||||||
'{product_list_txt}' => !empty($products_sent)? $content_txt.strip_tags($products_sent): '',
|
|
||||||
);
|
|
||||||
|
|
||||||
if(in_array($order->id, $status_sent)) {
|
foreach(Db::getInstance()->ExecuteS('
|
||||||
$history = new OrderHistory();
|
SELECT d.`id_order_detail`, d.`product_name`, SUM(p.`quantity`) AS `quantity`
|
||||||
$history->id_order = (int) $order->id;
|
FROM `'._DB_PREFIX_.'philea_parcel` p
|
||||||
$history->changeIdOrderState(4, (int) $order->id);
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON (p.`id_order_detail` = d.`id_order_detail`)
|
||||||
$history->addWithemail(TRUE, $templateVars);
|
WHERE d.`id_order` = '.(int) $id_order.'
|
||||||
} elseif(in_array($order->id, $status_partially_sent)) {
|
AND p.`shipping_number` = "'.pSQL($parcel[0]).'"
|
||||||
$history = new OrderHistory();
|
AND p.`date_add` = "'.pSQL($parcel[1]).'"
|
||||||
$history->id_order = (int) $order->id;
|
GROUP BY d.`id_order_detail`
|
||||||
$history->changeIdOrderState(17, (int) $order->id);
|
') as $p) {
|
||||||
$history->addWithemail(TRUE, $templateVars);
|
$products_sent .= '<br />'."\r\n".$p['quantity'].' x '.$p['product_name'];
|
||||||
}
|
}
|
||||||
|
|
||||||
$subjects = array(
|
$carrier = new Carrier($parcel[2], (int) $order->id_lang);
|
||||||
1 => 'Package in transit',
|
|
||||||
2 => 'Livraison en cours',
|
|
||||||
3 => 'Pedido en tránsito',
|
|
||||||
);
|
|
||||||
|
|
||||||
Mail::Send(
|
if((int) $order->id_lang == 3) {
|
||||||
intval($order->id_lang),
|
if(preg_match('/colissimo/i', $carrier->name)) {
|
||||||
'in_transit',
|
$carrier->url .= '&language=es_ES';
|
||||||
$subjects[(int) $order->id_lang],
|
}
|
||||||
$templateVars,
|
$content_html = '<strong>Contenido del paquete:</strong>';
|
||||||
$customer->email,
|
$content_txt = 'Contenido del paquete:';
|
||||||
$customer->firstname.' '.$customer->lastname
|
} else {
|
||||||
);
|
$content_html = '<strong>Contenu du colis :</strong>';
|
||||||
}
|
$content_txt = 'Contenu du colis :';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(count($errors) > 0) {
|
$templateVars = array(
|
||||||
mail('marion@antadis.com', '[BBB] Erreurs integration envoi Philea', serialize($errors));
|
'{followup}' => str_replace('@', $parcel[0], $carrier->url),
|
||||||
}
|
'{firstname}' => $customer->firstname,
|
||||||
}
|
'{lastname}' => $customer->lastname,
|
||||||
|
'{id_order}' => (int) $order->id,
|
||||||
|
'{product_list}' => !empty($products_sent)? $content_html.$products_sent: '',
|
||||||
|
'{product_list_txt}' => !empty($products_sent)? $content_txt.strip_tags($products_sent): '',
|
||||||
|
);
|
||||||
|
|
||||||
$repo_archive = './archives/IN/LIVRAISON/';
|
if(in_array($order->id, $status_sent)) {
|
||||||
$repo_paths = array(date('Y'), date('m'));
|
$history = new OrderHistory();
|
||||||
foreach ($repo_paths as $repo_path) {
|
$history->id_order = (int) $order->id;
|
||||||
$repo_archive .= $repo_path . '/';
|
$history->changeIdOrderState(4, (int) $order->id);
|
||||||
if (!file_exists($repo_archive))
|
$history->addWithemail(true, $templateVars);
|
||||||
mkdir($repo_archive);
|
} elseif(in_array($order->id, $status_partially_sent)) {
|
||||||
}
|
$history = new OrderHistory();
|
||||||
|
$history->id_order = (int) $order->id;
|
||||||
|
$history->changeIdOrderState(17, (int) $order->id);
|
||||||
|
$history->addWithemail(true, $templateVars);
|
||||||
|
}
|
||||||
|
|
||||||
copy($datFile, $repo_archive . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() ));
|
$subjects = array(
|
||||||
unlink($inFolder.$fileinfo->getFilename());
|
1 => 'Package in transit',
|
||||||
unlink($datFile);
|
2 => 'Livraison en cours',
|
||||||
}
|
3 => 'Pedido en tránsito',
|
||||||
}
|
);
|
||||||
}
|
|
||||||
}
|
Mail::Send(
|
||||||
}
|
intval($order->id_lang),
|
||||||
echo 'fin';
|
'in_transit',
|
||||||
|
$subjects[(int) $order->id_lang],
|
||||||
|
$templateVars,
|
||||||
|
$customer->email,
|
||||||
|
$customer->firstname.' '.$customer->lastname
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(count($errors) > 0) {
|
||||||
|
mail('marion@antadis.com', '[BBB] Erreurs integration envoi Philea', serialize($errors));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$repo_archive = './archives/IN/LIVRAISON/';
|
||||||
|
$repo_paths = array(date('Y'), date('m'));
|
||||||
|
foreach ($repo_paths as $repo_path) {
|
||||||
|
$repo_archive .= $repo_path . '/';
|
||||||
|
if (!file_exists($repo_archive))
|
||||||
|
mkdir($repo_archive);
|
||||||
|
}
|
||||||
|
|
||||||
|
copy($datFile, $repo_archive . preg_replace( '@BAL$@', 'DAT', $fileinfo->getFilename() ));
|
||||||
|
unlink($inFolder.$fileinfo->getFilename());
|
||||||
|
unlink($datFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
echo 'fin';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
|
||||||
$_SERVER['HTTP_HOST'] = 'www.bricoprive.com';
|
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
|
||||||
include('../../../config/settings.inc.php');
|
include('../../../config/settings.inc.php');
|
||||||
include('../../../config/config.inc.php');
|
include('../../../config/config.inc.php');
|
||||||
|
|
||||||
|
@ -48,6 +48,23 @@ if($magistorModule->active) {
|
|||||||
$db = Db::getInstance();
|
$db = Db::getInstance();
|
||||||
$id_order_state = 2;
|
$id_order_state = 2;
|
||||||
|
|
||||||
|
// for dev
|
||||||
|
// $include_orders = array();
|
||||||
|
// foreach($db->ExecuteS('
|
||||||
|
// SELECT DISTINCT d.`id_order`
|
||||||
|
// FROM `'._DB_PREFIX_.'order_detail` d
|
||||||
|
// 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` = d.`id_order`)
|
||||||
|
// LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = d.`id_order`)
|
||||||
|
// WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = d.`id_order` GROUP BY moh.`id_order`)
|
||||||
|
// AND oh.`id_order_state` IN (2, 3, 4, 13, 17, 9, 18, 19)
|
||||||
|
// AND c.`id_sale` = '.(int) $id_sale.'
|
||||||
|
// AND pms.`id_order` IS NULL
|
||||||
|
// AND d.`product_quantity` - d.`product_quantity_refunded` > 0
|
||||||
|
// ') as $row) {
|
||||||
|
// $include_orders[] = (int) $row['id_order'];
|
||||||
|
// }
|
||||||
|
|
||||||
$include_orders = array();
|
$include_orders = array();
|
||||||
foreach($db->ExecuteS('
|
foreach($db->ExecuteS('
|
||||||
SELECT DISTINCT o.`id_order`
|
SELECT DISTINCT o.`id_order`
|
||||||
|
Loading…
Reference in New Issue
Block a user