2016-06-21 17:18:24 +02:00
|
|
|
<?php
|
|
|
|
if(!defined('_PS_VERSION_')) {
|
|
|
|
exit;
|
|
|
|
}
|
2017-08-24 10:57:38 +02:00
|
|
|
require_once(PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php');
|
2016-06-21 17:18:24 +02:00
|
|
|
include _PS_ROOT_DIR_.'/modules/privatesales/Sale.php';
|
|
|
|
|
|
|
|
|
|
|
|
class AdminLogisticsPending extends AdminTab {
|
|
|
|
public $_html = '';
|
|
|
|
|
|
|
|
public function display() {
|
|
|
|
global $currentIndex, $cookie;
|
|
|
|
|
|
|
|
$sales_info = array();
|
2016-06-22 11:26:51 +02:00
|
|
|
$distinct_orders = array();
|
2016-06-21 17:18:24 +02:00
|
|
|
$link = new Link(2);
|
2016-07-11 12:35:41 +02:00
|
|
|
$total_pending_orders = Db::getInstance()->getValue('
|
|
|
|
SELECT COUNT(o.`id_order`)
|
|
|
|
FROM `'._DB_PREFIX_.'orders` o
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = o.`id_order`)
|
|
|
|
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = o.`id_order` GROUP BY moh.`id_order`)
|
|
|
|
AND oh.`id_order_state` = 19
|
|
|
|
');
|
2016-06-21 17:18:24 +02:00
|
|
|
foreach(Db::getInstance()->ExecuteS('
|
2016-06-22 11:26:51 +02:00
|
|
|
SELECT lp.*, oh.`id_order_state`
|
2017-08-24 10:57:38 +02:00
|
|
|
FROM `'._DB_PREFIX_.'logistics_pending` lp
|
2016-06-22 11:26:51 +02:00
|
|
|
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = lp.`id_order`)
|
|
|
|
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = lp.`id_order` GROUP BY moh.`id_order`)
|
|
|
|
ORDER BY lp.`id_sale`
|
2016-06-21 17:18:24 +02:00
|
|
|
') as $row) {
|
2016-06-22 11:26:51 +02:00
|
|
|
|
|
|
|
// If order status is not in pending, order is deleted from logistic_pending table
|
|
|
|
if ((int)$row['id_order_state'] != 19) {
|
|
|
|
Db::getInstance()->ExecuteS('
|
|
|
|
DELETE FROM `'._DB_PREFIX_.'logistics_pending`
|
|
|
|
WHERE `id_order` = '.(int)$row['id_order']
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// count of orders
|
|
|
|
if (!in_array((int)$row['id_order'], $distinct_orders)) {
|
|
|
|
$distinct_orders[] = (int)$row['id_order'];
|
|
|
|
}
|
|
|
|
|
2016-06-21 17:18:24 +02:00
|
|
|
if(!isset($sales_info[(int)$row['id_sale']])) {
|
|
|
|
$s = new Sale((int)$row['id_sale']);
|
|
|
|
$sales_info[(int)$row['id_sale']] = array(
|
|
|
|
'id_sale' => (int)$row['id_sale'],
|
|
|
|
'title' => $s->title[(int)$cookie->id_lang],
|
|
|
|
'date_start' => $s->date_start,
|
|
|
|
'orders' => array()
|
|
|
|
);
|
|
|
|
}
|
|
|
|
if (!isset($sales_info[(int)$row['id_sale']]['orders'][(int)$row['id_order']] )){
|
|
|
|
$order_infos = Db::getInstance()->getRow('
|
|
|
|
SELECT CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, o.`payment`, o.`total_paid`
|
|
|
|
FROM `'._DB_PREFIX_.'orders` o
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`)
|
|
|
|
WHERE o.`id_order` = '.(int)$row['id_order']
|
|
|
|
);
|
|
|
|
$sales_info[(int)$row['id_sale']]['orders'][(int)$row['id_order']] = array(
|
|
|
|
'id_order' => (int)$row['id_order'],
|
|
|
|
'customer' => $order_infos['customer'],
|
|
|
|
'payment' => $order_infos['payment'],
|
|
|
|
'total_paid' => $order_infos['total_paid'],
|
2016-06-22 11:26:51 +02:00
|
|
|
'products' => array(),
|
|
|
|
'id_state' => (int)$row['id_order_state']
|
2016-06-21 17:18:24 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
$p = Db::getInstance()->getRow('
|
|
|
|
SELECT od.`product_id`,od.`product_attribute_id`, od.`product_name`, od.`product_reference`
|
|
|
|
FROM `'._DB_PREFIX_.'order_detail` od
|
|
|
|
WHERE od.`id_order` = '.(int)$row['id_order'].'
|
|
|
|
AND od.`product_id` = '.(int)(int)$row['id_product']
|
|
|
|
);
|
|
|
|
|
|
|
|
$p['id_image'] = 0;
|
|
|
|
if((int) $p['product_attribute_id'] != 0) {
|
|
|
|
$img = Db::getInstance()->getRow('
|
|
|
|
SELECT `id_image`
|
|
|
|
FROM `'._DB_PREFIX_.'product_attribute_image`
|
|
|
|
WHERE `id_product_attribute` = '.(int) $p['product_attribute_id'].'
|
|
|
|
');
|
|
|
|
|
|
|
|
$p['id_image'] = $img['id_image'];
|
|
|
|
}
|
|
|
|
if($p['id_image'] == 0) {
|
|
|
|
$img = Db::getInstance()->getRow('
|
|
|
|
SELECT `id_image`
|
|
|
|
FROM `'._DB_PREFIX_.'image`
|
|
|
|
WHERE `cover` = 1
|
|
|
|
AND `id_product` = '.(int) $p['product_id'].'
|
|
|
|
');
|
|
|
|
|
|
|
|
$p['id_image'] = $img['id_image'];
|
|
|
|
}
|
|
|
|
$p['image'] = $link->getImageLink('image', $p['product_id'].'-'.$p['id_image'], 'home');
|
|
|
|
|
|
|
|
$sales_info[(int)$row['id_sale']]['orders'][(int)$row['id_order']]['products'][] = $p;
|
|
|
|
}
|
2017-08-24 10:57:38 +02:00
|
|
|
|
|
|
|
$helper = new HelperFormBootstrap();
|
|
|
|
|
|
|
|
$helper->_css .= '
|
|
|
|
<style>
|
2016-06-21 17:18:24 +02:00
|
|
|
.table tr th{
|
|
|
|
background: #F4E6C9 url(../adm/themes/origins_lite/news-bg.gif) repeat-x top left;
|
|
|
|
padding: 4px 6px;
|
|
|
|
}
|
2017-08-24 10:57:38 +02:00
|
|
|
.table > tbody > tr > td{
|
|
|
|
vertical-align: middle;
|
|
|
|
}
|
|
|
|
.table .table{
|
|
|
|
margin-bottom:0px;
|
|
|
|
}
|
2016-06-22 11:26:51 +02:00
|
|
|
.table tr td.product_name {
|
|
|
|
box-sizing: border-box;
|
|
|
|
width: 500px;
|
|
|
|
}
|
2017-08-24 10:57:38 +02:00
|
|
|
.table .tr-order{
|
|
|
|
background-color: #1ABB9C;
|
|
|
|
}
|
|
|
|
.table tr.tr-order td,
|
|
|
|
.table tr.tr-order td a{
|
|
|
|
color:#fff;
|
|
|
|
}
|
2016-06-21 17:18:24 +02:00
|
|
|
</style>';
|
|
|
|
|
2017-08-24 10:57:38 +02:00
|
|
|
$helper->_js .= '
|
|
|
|
<script>
|
2016-06-21 17:18:24 +02:00
|
|
|
function check_all(element)
|
|
|
|
{
|
|
|
|
$(\'#\'+element+\' input\').each(function(){
|
|
|
|
if ($(\'#all_\'+element).is(\':checked\')) {
|
2017-08-24 10:57:38 +02:00
|
|
|
if(!$(this).is(\':checked\')){
|
|
|
|
$(this).prop(\'checked\', true);
|
|
|
|
}
|
2016-06-21 17:18:24 +02:00
|
|
|
} else {
|
2017-08-24 10:57:38 +02:00
|
|
|
if($(this).is(\':checked\')){
|
|
|
|
$(this).removeAttr(\'checked\');
|
|
|
|
}
|
2016-06-21 17:18:24 +02:00
|
|
|
}
|
|
|
|
});
|
2017-08-24 10:57:38 +02:00
|
|
|
|
2016-06-21 17:18:24 +02:00
|
|
|
}
|
2017-08-24 10:57:38 +02:00
|
|
|
|
2016-07-11 12:35:41 +02:00
|
|
|
function toggleText(element, target){
|
2017-08-24 10:57:38 +02:00
|
|
|
$(target).slideToggle();
|
2016-07-11 12:35:41 +02:00
|
|
|
if ($(element).hasClass(\'toggle-more\')) {
|
|
|
|
$(element).removeClass(\'toggle-more\');
|
|
|
|
$(element).text(\'+\');
|
2017-08-24 10:57:38 +02:00
|
|
|
$(element).parent(\'tr\').css(\'background-color\',\'#fff\');
|
|
|
|
$(element).parent(\'tr\').children(\'td\').css(\'color\',\'#000\');
|
2016-07-11 12:35:41 +02:00
|
|
|
} else {
|
|
|
|
$(element).addClass(\'toggle-more\');
|
|
|
|
$(element).text(\'-\');
|
2017-08-24 10:57:38 +02:00
|
|
|
$(element).parent(\'tr\').css(\'background-color\',\'#FFA74E\');
|
|
|
|
$(element).parent(\'tr\').children(\'td\').css(\'color\',\'#fff\');
|
2016-07-11 12:35:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-21 17:18:24 +02:00
|
|
|
</script>';
|
|
|
|
|
2017-08-24 10:57:38 +02:00
|
|
|
$html = $helper->renderStyle();
|
|
|
|
$html .= '
|
|
|
|
<div class="row">
|
|
|
|
<div class="col-md-12">
|
|
|
|
<div class="panel">
|
|
|
|
<div class="panel-title">
|
|
|
|
<h2 style="font-size:24px;"><span class="anticon anticon-loop text-rose" style="font-size:24px;"></span> '.$this->l('Liste des commandes en attente').'</h2>
|
|
|
|
<div class="clearfix"></div>
|
|
|
|
</div>
|
|
|
|
<div class="panel-content">
|
|
|
|
<h6><b>'.$this->l('Commandes en attente avec produits retenus').' : '.(!empty($distinct_orders)?count($distinct_orders):'0').'</b></h6>
|
|
|
|
<h6><b>'.$this->l('Commandes en attente').' : '.$total_pending_orders.'</b></h6>';
|
|
|
|
if (!empty($sales_info)) {
|
|
|
|
$html .= '
|
|
|
|
<form action="'.$currentIndex.'&token='.$this->token.'" method="post">
|
|
|
|
<table class="table table-custombordered" style="margin-top:30px; width: 100%" cellspacing="0">
|
|
|
|
<thead>
|
|
|
|
<tr>
|
|
|
|
<th>'.$this->l('Sale ID').'</th>
|
|
|
|
<th>'.$this->l('Title').'</th>
|
|
|
|
<th>'.$this->l('Date start').'</th>
|
|
|
|
<th class="text-center">'.$this->l('Nb orders').'</th>
|
|
|
|
<th class="text-center">'.$this->l('Check all').'</th>
|
|
|
|
<th class="text-center">'.$this->l('See orders').'</th>
|
|
|
|
</tr>
|
|
|
|
</thead>
|
|
|
|
<tbody>';
|
|
|
|
foreach ($sales_info as $key => $sale) {
|
|
|
|
$html .= '
|
|
|
|
<tr style="background-color: #fff;">
|
|
|
|
<td>'.$sale['id_sale'].'</td>
|
|
|
|
<td><b>'.$sale['title'].'</b></td>
|
|
|
|
<td>'.date('d/m/Y H:i',strtotime($sale['date_start'])).'</td>
|
|
|
|
<td align="center">'.count($sale['orders']).'</td>
|
|
|
|
<td align="center"><input type="checkbox" name="sales[]" id="all_sale_'.(int)$sale['id_sale'].'" value="'.(int)$sale['id_sale'].'" onclick="check_all(\'sale_'.(int)$sale['id_sale'].'\');"/></td>
|
|
|
|
<td align="center" style="cursor:pointer;font-size: 20px;" id="sale_toggle_'.(int)$sale['id_sale'].'" onclick="toggleText(\'#sale_toggle_'.(int)$sale['id_sale'].'\', \'#sale_'.(int)$sale['id_sale'].'\');">'.$this->l('+').'</td>
|
|
|
|
</tr>
|
|
|
|
<tr id="sale_'.(int)$sale['id_sale'].'" style="display:none;">
|
|
|
|
<td colspan="6" style="padding: 0;">
|
|
|
|
<table class="table table-custombordered" style="width: 100%; border:none;" cellpadding="0" cellspacing="0">';
|
|
|
|
foreach ($sale['orders'] as $k => $order) {
|
|
|
|
$html .= '
|
|
|
|
<tr class="tr-order">
|
|
|
|
<td><a target="_blank" href="'.__PS_BASE_URI__.'adm/index.php?tab=AdminOrders&id_order='.$order['id_order'].'&vieworder&token='.Tools::getAdminTokenLite('AdminOrders').'">Cmd #'.$order['id_order'].'</a></td>
|
|
|
|
<td>'.$order['customer'].'</td>
|
|
|
|
<td>'.$order['total_paid'].' €</td>
|
|
|
|
<td><span class="anticon anticon-'.($order['payment']=="Paybox"?'credit-card':'paypal').'"></span> '.$order['payment'].'</td>
|
|
|
|
<td><input type="checkbox" name="orders[]" value="'.(int)$order['id_order'].'"/></td>
|
|
|
|
</tr>
|
|
|
|
<tr>
|
|
|
|
<td colspan="5" style="padding: 0;">
|
|
|
|
<table class="table" style="width: 100%" id="order_'.(int)$sale['id_order'].'">';
|
|
|
|
foreach ($order['products'] as $ke => $product) {
|
|
|
|
$html .= '
|
|
|
|
<tr style="background-color: #fff;font-size: 12px;">
|
|
|
|
<td align="center" style="width:100px;"><img src="'.$product['image'].'" alt="" width="70" height="auto" /></td>
|
|
|
|
<td class="alt_row product_name" valign="middle"><span>'.$product['product_name'].'</span></td>
|
|
|
|
<td class="alt_row text-center" valign="middle" align="center">'.($product['product_reference']?$product['product_reference']:'-').'</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
$html .= '
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
$html .= '
|
|
|
|
</table>
|
|
|
|
</td>
|
|
|
|
</tr>';
|
|
|
|
}
|
|
|
|
$html .= '</tbody>
|
|
|
|
</table>
|
|
|
|
<p style="width:100%;text-align:right;"><input class="btn btn-primary" type="submit" name="submitPrint" value="'.$this->l('Print').'"></p>
|
|
|
|
</form>';
|
|
|
|
} else {
|
|
|
|
$html .= '<p>'.$this->l('Aucune Commandes en attente').'</p>';
|
2016-06-22 11:26:51 +02:00
|
|
|
}
|
2017-08-24 10:57:38 +02:00
|
|
|
$html .= '
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>';
|
|
|
|
|
|
|
|
$html .= $helper->renderScript();
|
|
|
|
|
|
|
|
echo $html;
|
2016-06-21 17:18:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public function postProcess()
|
|
|
|
{
|
|
|
|
global $currentIndex;
|
|
|
|
if(Tools::isSubmit('submitPrint')) {
|
|
|
|
$orders = Tools::getValue('orders');
|
|
|
|
if (!empty($orders)) {
|
2017-08-24 10:57:38 +02:00
|
|
|
$_orders = array();
|
|
|
|
foreach(Db::getInstance()->ExecuteS('
|
|
|
|
SELECT d.`id_order`, p.`id_product`, c.`id_sale`, GREATEST(d.`product_quantity` - d.`product_quantity_return`, 0) AS `product_quantity`,
|
2017-08-28 15:40:55 +02:00
|
|
|
d.`product_reference`, COUNT(d.id_order_detail) AS `nb_p`,
|
2017-08-28 15:37:48 +02:00
|
|
|
CASE
|
|
|
|
WHEN SUBSTRING(ca.`name`, 1,1) = "T" THEN 1
|
2017-08-28 15:40:55 +02:00
|
|
|
WHEN SUBSTRING(ca.`name`, 1,1) = "C" THEN 1
|
|
|
|
ELSE 2
|
|
|
|
END AS `carrier_name`
|
2017-08-24 10:57:38 +02:00
|
|
|
FROM `'._DB_PREFIX_.'privatesale_category` c
|
2017-08-28 15:37:48 +02:00
|
|
|
LEFT JOIN `'._DB_PREFIX_.'product` p ON c.`id_category` = p.`id_category_default`
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.`product_id` = p.`id_product`
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order`
|
|
|
|
LEFT JOIN `'._DB_PREFIX_.'carrier` ca ON ca.id_carrier = o.id_carrier
|
2017-08-24 10:57:38 +02:00
|
|
|
WHERE d.`id_order` IN ('.implode(', ', $orders).')
|
|
|
|
GROUP BY d.`id_order`
|
2017-08-28 15:37:48 +02:00
|
|
|
ORDER BY `carrier_name` ASC, `nb_p` ASC, d.`product_reference`
|
2017-08-24 10:57:38 +02:00
|
|
|
') as $row) {
|
|
|
|
if(!isset($_orders[(int)$row['id_order']])) {
|
|
|
|
$_orders[(int)$row['id_order']] = (int)$row['id_order'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$_orders = array_unique($_orders);
|
|
|
|
Tools::redirectAdmin('pdf.php?pendingorders&orders='.implode(',', $_orders) .'&token='.$this->token);
|
2016-06-22 11:26:51 +02:00
|
|
|
} else {
|
|
|
|
$this->_errors[] = $this->l('No selected orders for these sales');
|
2016-06-21 17:18:24 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|