135 lines
3.9 KiB
PHP
135 lines
3.9 KiB
PHP
<?php
|
|
class Order extends OrderCore {
|
|
public function printMixedSale($value, $params) {
|
|
return Db::getInstance()->getValue('
|
|
SELECT COUNT(DISTINCT `id_sale`)
|
|
FROM `'._DB_PREFIX_.'product_ps_cache`
|
|
WHERE `id_product` IN (
|
|
SELECT `product_id` FROM `'._DB_PREFIX_.'order_detail`
|
|
WHERE `id_order` = '.(int) $value.'
|
|
)
|
|
') == 1? 'S': 'M';
|
|
}
|
|
|
|
public function printCountry($value, $params)
|
|
{
|
|
return '<img src="/img/flags/'.(int) $value.'.png" alt="" />';
|
|
}
|
|
|
|
|
|
public static function getTotalbyDate($date_start, $date_end, $state = 0){
|
|
if($state == 0){
|
|
if($date_start == $date_end){
|
|
return Db::getInstance()->getValue('
|
|
SELECT SUM(`total_paid`)
|
|
FROM `ps_orders` o
|
|
WHERE `date_add` LIKE "'.$date_start.'%"
|
|
');
|
|
}else{
|
|
return Db::getInstance()->getValue('
|
|
SELECT SUM(`total_paid`)
|
|
FROM `ps_orders` o
|
|
WHERE `date_add` BETWEEN "'.$date_start.' 00:00:00" AND "'.$date_end.' 23:59:59"
|
|
');
|
|
}
|
|
}else{
|
|
if($date_start == $date_end){
|
|
return Db::getInstance()->getValue('
|
|
SELECT SUM(`total_paid`)
|
|
FROM `ps_orders` o
|
|
WHERE `date_add` LIKE "'.$date_start.'%"
|
|
AND (SELECT id_order_state FROM ps_order_history hi WHERE o.id_order = hi.id_order ORDER BY id_order_history DESC LIMIT 1) = '.$state.'
|
|
');
|
|
}else{
|
|
return Db::getInstance()->getValue('
|
|
SELECT SUM(`total_paid`)
|
|
FROM `ps_orders` o
|
|
WHERE `date_add` BETWEEN "'.$date_start.' 00:00:00" AND "'.$date_end.' 23:59:59"
|
|
AND (SELECT id_order_state FROM ps_order_history hi WHERE o.id_order = hi.id_order ORDER BY id_order_history DESC LIMIT 1) = '.$state.'
|
|
');
|
|
}
|
|
}
|
|
}
|
|
|
|
public function getProducts($products = false, $selectedProducts = false, $selectedQty = false, $tri = false)
|
|
{
|
|
if (!$products)
|
|
$products = $this->getProductsDetail($tri);
|
|
$resultArray = array();
|
|
|
|
$ids_order_detail = array_column($products, 'id_order_detail');
|
|
$send_infos = Order::getIfSended($ids_order_detail);
|
|
|
|
foreach ($products AS $row)
|
|
{
|
|
if( $send_infos[$row['id_order_detail']]
|
|
== ($row['product_quantity'] - ($row['product_quantity_return'] + $row['product_quantity_refunded']) )
|
|
) {
|
|
$row['sended'] = 1;
|
|
} else {
|
|
$row['sended'] = 0;
|
|
}
|
|
|
|
// Change qty if selected
|
|
if ($selectedQty)
|
|
{
|
|
$row['product_quantity'] = 0;
|
|
foreach ($selectedProducts AS $key => $id_product)
|
|
if ($row['id_order_detail'] == $id_product)
|
|
$row['product_quantity'] = (int)($selectedQty[$key]);
|
|
if (!$row['product_quantity'])
|
|
continue ;
|
|
}
|
|
$this->setProductPrices($row);
|
|
|
|
/* Add information for virtual product */
|
|
if ($row['download_hash'] AND !empty($row['download_hash']))
|
|
$row['filename'] = ProductDownload::getFilenameFromIdProduct($row['product_id']);
|
|
|
|
/* Stock product */
|
|
$resultArray[(int)($row['id_order_detail'])] = $row;
|
|
}
|
|
return $resultArray;
|
|
}
|
|
|
|
public function getProductsDetail($tri = false)
|
|
{
|
|
if ($tri) {
|
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'order_detail` od
|
|
WHERE od.`id_order` = '.(int)($this->id) . '
|
|
ORDER BY product_reference ASC');
|
|
} else {
|
|
return Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
|
SELECT *
|
|
FROM `'._DB_PREFIX_.'order_detail` od
|
|
WHERE od.`id_order` = '.(int)($this->id));
|
|
}
|
|
}
|
|
|
|
public static function getIfSended($ids) {
|
|
$data = array();
|
|
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
|
|
SELECT
|
|
d.`id_order_detail`,
|
|
IF(
|
|
(SELECT COUNT(p.`id_order_detail`)
|
|
FROM `'._DB_PREFIX_.'lapostews` p
|
|
WHERE d.`id_order_detail` = p.`id_order_detail`),
|
|
(SELECT SUM(p.`quantity`)
|
|
FROM `'._DB_PREFIX_.'lapostews` p
|
|
WHERE d.`id_order_detail` = p.`id_order_detail`),
|
|
0
|
|
) as `total_send`
|
|
FROM `'._DB_PREFIX_.'order_detail` d
|
|
WHERE d.`id_order_detail` IN ('.implode(',', $ids).')
|
|
') as $key => $info) {
|
|
$data[$info['id_order_detail']] = $info['total_send'];
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
|
|
}
|