Merge branch 'ticket-13166-ReturnProcess' into develop

This commit is contained in:
Marion Muszynski 2017-05-11 17:43:39 +02:00
commit 66797776a2

View File

@ -114,6 +114,50 @@ class AdminAntReturnprocess extends AdminTab
} else {
HelperFormBootstrap::displayErrors(Tools::displayError('No order return ID.'));
}
} elseif(Tools::getValue('send_return_instruction') && Tools::getValue('id_order_return')) {
$id_order = (int) Tools::getValue('id_order');
$id_order_return = (int) Tools::getValue('id_order_return');
if(Validate::isLoadedObject($order = new Order($id_order))) {
$customer = new Customer($order->id_customer);
$return_link = Db::getInstance()->getRow('
SELECT `return_number`, `link`
FROM `'._DB_PREFIX_.'order_return_link`
WHERE `id_order_return` = '.(int) $id_order_return.'
');
$products = Db::getInstance()->ExecuteS('
SELECT `id_order_detail`, `product_quantity`
FROM `'._DB_PREFIX_.'order_return_detail`
WHERE `id_order_return` = '.(int) $id_order_return.'
');
$product_list = '<ul>';
$product_list_txt = array();
foreach($products as $key => $product){
$product_name = Db::getInstance()->getValue('
SELECT `product_name`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order_detail` = '.(int) $product['id_order_detail'].'
');
$product_list_txt[] = (int) $product['product_quantity'].' x '.$product_name;
$product_list .= '<li>'.(int) $product['product_quantity'].' x '.htmlentities($product_name).'</li>';
}
$product_list .= '</ul>';
Mail::Send(
intval($order->id_lang),
'order_return_2',
$subject[(int) $order->id_lang],
array(
'{id_order}' => $order->id,
'{return_link}' => $return_link['link'],
'{product_list}' => $product_list,
'{product_list_txt}' => implode("\r\n", $product_list_txt),
),
$customer->email,
$customer->firstname.' '.$customer->lastname
);
Tools::redirectAdmin($currentIndex.'&id_order_return='.(int)$id_order_return.'&updateorder_return&conf=4&token='.$this->token);
} else {
HelperFormBootstrap::displayErrors(Tools::displayError('Order ID missing.'));
}
}
}
@ -207,6 +251,14 @@ class AdminAntReturnprocess extends AdminTab
$returnProducts = OrderReturn::getOrdersReturnProducts($orderReturn->id, $order);
$orderReturnState = new OrderReturnState($orderReturn->state);
$other_returnProducts = Db::getInstance()->ExecuteS('
SELECT a.*, orsl.`name`, ord.`id_order_detail`, ord.`qty`
FROM '._DB_PREFIX_.'order_return a
LEFT JOIN '._DB_PREFIX_.'order_return_detail_qty ord ON (ord.`id_order_return` = a.`id_order_return`)
LEFT JOIN '._DB_PREFIX_.'order_return_state_lang orsl ON (orsl.`id_order_return_state` = a.`state` AND orsl.`id_lang` = '.(int)($cookie->id_lang).')
WHERE a.id_order='.(int)$order->id.' AND a.id_order_return != '.(int)$orderReturn->id.'
');
$colorStates = array(
1 => "anticon anticon-hour-glass text-orange",
2 => "anticon anticon-hour-glass text-orange",
@ -229,6 +281,16 @@ class AdminAntReturnprocess extends AdminTab
<div class="clearfix"></div>
</div>
<div class="panel-content">
<div class="row">
<div class=col-md-6>';
$return_link = Db::getInstance()->getRow('
SELECT `return_number`, `link`
FROM `'._DB_PREFIX_.'order_return_link`
WHERE `id_order_return` = '.(int) $id_order_return.'
');
$html .= '<p class="text-purple-dark" style="font-weight:bold;"><span class="anticon anticon-qrcode"></span> Lien retour Etiquette MR : '.($return_link? '<a style="color:#444;" href="'.$return_link['link'].'" onclick="window.open(this.href); return false;">'.$return_link['return_number'].'</a> <a class="text-purple-dark" title="Renvoyer les instructions retour" href="'.$currentIndex.'&send_return_instruction=1&updateorder_return&id_order_return='.$id_order_return.'&id_order='.(int)$order->id.'&token='.$this->token.'"><i class="glyphicon glyphicon-send"></i></a>':'Pas de lien retour').'<p>';
$html .='</div>
</div>
<div class="row">
<div class="col-md-6">
<table class="table">
@ -291,8 +353,56 @@ class AdminAntReturnprocess extends AdminTab
</div>
</form>
</div>
</div>
</div>
</div>';
if($other_returnProducts && !empty($other_returnProducts)){
$html .= '
<div class="row">
<div class="col-md-8">
<p class="text-purple-dark" style="font-weight:bold;">Autre(s) produit(s) en retour pour cette commande : </p>
<table class="table">
<thead>
<tr>
<th style="background:#efefef;color:#504d8b;"># Retour</th>
<th style="background:#efefef;color:#504d8b;">'.$this->l('Produit').'</th>
<th style="background:#efefef;color:#504d8b;" align="center">'.$this->l('Qté').'</th>
<th style="background:#efefef;color:#504d8b;" align="center">'.$this->l('Statut').'</th>
<th style="background:#efefef;color:#504d8b;" align="center">'.$this->l('Action').'</th>
</tr>
</thead>
<tbody>';
foreach ($other_returnProducts as $key => $return_product) {
$order_detail = new OrderDetail((int)$return_product['id_order_detail']);
$img_path = '';
$img = Db::getInstance()->getRow('
SELECT id_image
FROM `'._DB_PREFIX_.'image` i
WHERE i.`id_product` = '.(int)$order_detail->product_id.'
AND i.`cover` = 1'
);
if (isset($img['id_image']) && !empty($img['id_image'])) {
$image_obj = new Image((int)$img['id_image']);
$img_path = (isset($image_obj)?$image_obj->getExistingImgPath():'');
}
$html .= '
<tr>
<td style="text-align:center;vertical-align:middle;color:#444;font-weight:bold;">'.(int) $return_product['id_order_return'].'</td>
<td style="vertical-align:middle;color:#444;font-weight:bold;">
<a style="display: block;color:#444;" target="_blank" href="index.php?tab=AdminCatalog&id_product='.(int)($order_detail->product_id).'&updateproduct&token='.Tools::getAdminToken('AdminCatalog'.(int)(Tab::getIdFromClassName('AdminCatalog')).(int)($cookie->id_employee)).'" title="'.$this->l('View product').'">
<img style="display:inline-block;" width="50" src="'.(isset($img_path)?_THEME_PROD_DIR_.$img_path.'-small.jpg':'').'"/><span style="font-weight:bold;display:inline-block;margin-left:5px;width:150px;vertical-align:middle;">'.mb_strimwidth($order_detail->product_name, 0, 55, "...").'</span>
<div class="clearfix"></div>
</a>
</td>
<td align="center" style="vertical-align:middle;color:#444;">'.$return_product['qty'].'</td>
<td align="center" style="vertical-align:middle;color:#444;"><span style="font-size:24px;" class="'.$colorStates[$return_product['state']].'"></span> '.$return_product['name'].'</td>
<td align="center" style="vertical-align:middle;color:#444;"><a href="/adm/index.php?tab=AdminAntReturnprocess&id_order_return='.(int) $return_product['id_order_return'].'&updateorder_return&token='.Tools::getValue('token').'" title="voir"><span class="anticon anticon-eye text-purple-dark"></span></a></td>
</tr>';
}
$html .= '</tbody>
</table>
</div>
</div>';
}
$html .='</div>
</div>
</div>
</div>';
@ -378,6 +488,13 @@ class AdminAntReturnprocess extends AdminTab
if ($product['product_quantity'] > $product['customizationQuantityTotal'])
{
$quantity = $product['product_quantity'] - $product['customizationQuantityTotal'];
$stock = Db::getInstance()->getRow('
SELECT '.($product['product_attribute_id'] ? 'pa' : 'p').'.quantity
FROM '._DB_PREFIX_.'product p
'.($product['product_attribute_id'] ? 'LEFT JOIN '._DB_PREFIX_.'product_attribute pa ON p.id_product = pa.id_product' : '').'
WHERE p.id_product = '.(int)($product['product_id']).'
'.($product['product_attribute_id'] ? 'AND pa.id_product_attribute = '.(int)($product['product_attribute_id']) : '')
);
$html .='
<tr>
@ -520,7 +637,8 @@ class AdminAntReturnprocess extends AdminTab
$order_returns = Db::getInstance()->ExecuteS('
SELECT a.*, orsl.`name`
FROM '._DB_PREFIX_.'order_return a
LEFT JOIN '._DB_PREFIX_.'order_return_state_lang orsl ON (orsl.`id_order_return_state` = a.`state` AND orsl.`id_lang` = '.(int)($cookie->id_lang).')'
LEFT JOIN '._DB_PREFIX_.'order_return_state_lang orsl ON (orsl.`id_order_return_state` = a.`state` AND orsl.`id_lang` = '.(int)($cookie->id_lang).')
'.(Tools::getValue('return_order')?' WHERE a.id_order='.Tools::getValue('return_order'):'')
);
$colorStates = array(