pack gestion at expedition reception
This commit is contained in:
parent
58776438d1
commit
0a9afab232
@ -75,8 +75,9 @@
|
||||
if(!empty($lines)) {
|
||||
$details = array();
|
||||
$order_details = array();
|
||||
foreach( $lines as $line ) {
|
||||
|
||||
// GET DATA
|
||||
foreach( $lines as $line ) {
|
||||
$data = array();
|
||||
foreach($format as $field=>$value) {
|
||||
$data[] = substr($line, ($value[0]-1), $value[1]);
|
||||
@ -207,7 +208,6 @@
|
||||
}
|
||||
} // end foreach lines
|
||||
|
||||
echo '<pre>';var_dump($details,$order_details);echo '</pre>';die();
|
||||
foreach($order_details as $order => $order_detail){
|
||||
foreach ($order_detail as $key => $product) {
|
||||
if(isset($details[(int)$order][$key]) && $details[(int)$order][$key]['quantity'] <= $product['quantity_to_sent']) {
|
||||
@ -225,7 +225,7 @@
|
||||
');
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else {
|
||||
foreach($product['id_order_details'] as $id_order_detail => $row) {
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT INTO `'._DB_PREFIX_.'philea_parcel`
|
||||
@ -276,80 +276,193 @@
|
||||
}
|
||||
$orders_infos[(int) $row['id_order']][] = array($row['shipping_number'], $row['date_add'], (int) $parcel_carrier[(int) $row['id_order'].'|'.$row['shipping_number']]);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($orders_infos as $id_order => $parcels) {
|
||||
$order = new Order($id_order);
|
||||
$customer = new Customer((int) $order->id_customer);
|
||||
$id_orders = array_unique($id_orders);
|
||||
|
||||
foreach($parcels as $parcel) {
|
||||
$products_sent = '';
|
||||
$products = Db::getInstance()->ExecuteS('
|
||||
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`
|
||||
FROM ps_order_detail d
|
||||
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON (d.`product_id` = c.`id_product`)
|
||||
WHERE d.`id_order` IN ('.implode(', ', $id_orders).')
|
||||
');
|
||||
|
||||
$products_names = array();
|
||||
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT d.`id_order_detail`, d.`product_name`, SUM(p.`quantity`) AS `quantity`
|
||||
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'];
|
||||
$sent_sales = 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'];
|
||||
}
|
||||
|
||||
$carrier = new Carrier($parcel[2], (int) $order->id_lang);
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
||||
if((int) $order->id_lang == 3) {
|
||||
if(preg_match('/colissimo/i', $carrier->name)) {
|
||||
$carrier->url .= '&language=es_ES';
|
||||
unset($products);
|
||||
|
||||
$sent_products = array();
|
||||
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_to_send = array();
|
||||
$orders_list = array();
|
||||
|
||||
$total = count($to_send);
|
||||
|
||||
foreach($to_send as $product) {
|
||||
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'];
|
||||
}
|
||||
$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(
|
||||
'{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): '',
|
||||
);
|
||||
unset($sent_products);
|
||||
unset($to_send);
|
||||
|
||||
$order->shipping_number = $parcel[0];
|
||||
$order->update();
|
||||
|
||||
if(in_array($order->id, $status_sent)) {
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int) $order->id;
|
||||
$history->changeIdOrderState(4, (int) $order->id);
|
||||
$history->addWithemail(true, $templateVars);
|
||||
} 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);
|
||||
$orders_sent = array();
|
||||
foreach($orders_list as $order) {
|
||||
if(!in_array($order, $orders_to_send)) {
|
||||
$orders_sent[] = $order;
|
||||
}
|
||||
}
|
||||
|
||||
$subjects = array(
|
||||
1 => 'Package in transit',
|
||||
2 => 'Livraison en cours',
|
||||
3 => 'Pedido en tránsito',
|
||||
);
|
||||
unset($orders_list);
|
||||
|
||||
Mail::Send(
|
||||
intval($order->id_lang),
|
||||
'in_transit',
|
||||
$subjects[(int) $order->id_lang],
|
||||
$templateVars,
|
||||
$customer->email,
|
||||
$customer->firstname.' '.$customer->lastname
|
||||
);
|
||||
$status_sent = array();
|
||||
$status_partially_sent = array();
|
||||
|
||||
foreach($orders_sent as $order) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unset($orders_sent);
|
||||
unset($orders_to_send);
|
||||
|
||||
foreach($orders_infos as $id_order => $parcels) {
|
||||
$order = new Order($id_order);
|
||||
$customer = new Customer((int) $order->id_customer);
|
||||
|
||||
foreach($parcels as $parcel) {
|
||||
$products_sent = '';
|
||||
|
||||
$products_names = array();
|
||||
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT d.`id_order_detail`, d.`product_name`, SUM(p.`quantity`) AS `quantity`
|
||||
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);
|
||||
|
||||
if((int) $order->id_lang == 3) {
|
||||
if(preg_match('/colissimo/i', $carrier->name)) {
|
||||
$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(
|
||||
'{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): '',
|
||||
);
|
||||
|
||||
$order->shipping_number = $parcel[0];
|
||||
$order->update();
|
||||
|
||||
if(in_array($order->id, $status_sent)) {
|
||||
$history = new OrderHistory();
|
||||
$history->id_order = (int) $order->id;
|
||||
$history->changeIdOrderState(4, (int) $order->id);
|
||||
$history->addWithemail(true, $templateVars);
|
||||
} 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);
|
||||
}
|
||||
|
||||
$subjects = array(
|
||||
1 => 'Package in transit',
|
||||
2 => 'Livraison en cours',
|
||||
3 => 'Pedido en tránsito',
|
||||
);
|
||||
|
||||
Mail::Send(
|
||||
intval($order->id_lang),
|
||||
'in_transit',
|
||||
$subjects[(int) $order->id_lang],
|
||||
$templateVars,
|
||||
$customer->email,
|
||||
$customer->firstname.' '.$customer->lastname
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -372,119 +485,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// $id_orders = array_unique($id_orders);
|
||||
|
||||
// $products = Db::getInstance()->ExecuteS('
|
||||
// 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`
|
||||
// FROM ps_order_detail d
|
||||
// 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('
|
||||
// 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'];
|
||||
// }
|
||||
|
||||
// $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;
|
||||
// }
|
||||
// }
|
||||
|
||||
// unset($products);
|
||||
|
||||
// $sent_products = array();
|
||||
// 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_to_send = array();
|
||||
// $orders_list = array();
|
||||
|
||||
// $total = count($to_send);
|
||||
|
||||
// foreach($to_send as $product) {
|
||||
// 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);
|
||||
// unset($to_send);
|
||||
|
||||
// $orders_sent = array();
|
||||
// foreach($orders_list as $order) {
|
||||
// if(!in_array($order, $orders_to_send)) {
|
||||
// $orders_sent[] = $order;
|
||||
// }
|
||||
// }
|
||||
|
||||
// unset($orders_list);
|
||||
|
||||
// $status_sent = array();
|
||||
// $status_partially_sent = array();
|
||||
|
||||
// foreach($orders_sent as $order) {
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
|
||||
// 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;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
// unset($orders_sent);
|
||||
// unset($orders_to_send);
|
||||
echo 'fin';
|
||||
|
Loading…
Reference in New Issue
Block a user