'isUnsignedId',
'id_address_invoice' => 'isUnsignedId',
'id_cart' => 'isUnsignedId',
'id_currency' => 'isUnsignedId',
'id_lang' => 'isUnsignedId',
'id_customer' => 'isUnsignedId',
'id_carrier' => 'isUnsignedId',
'secure_key' => 'isMd5',
'payment' => 'isGenericName',
'recyclable' => 'isBool',
'gift' => 'isBool',
'gift_message' => 'isMessage',
'total_discounts' => 'isPrice',
'total_paid' => 'isPrice',
'total_paid_real' => 'isPrice',
'total_products' => 'isPrice',
'total_products_wt' => 'isPrice',
'total_shipping' => 'isPrice',
'carrier_tax_rate' => 'isFloat',
'total_wrapping' => 'isPrice',
'shipping_number' => 'isUrl',
'conversion_rate' => 'isFloat',
'appli' => 'isUnsignedInt',
);
public function getFields()
{
ObjectModel::validateFields();
$fields['id_address_delivery'] = (int)($this->id_address_delivery);
$fields['id_address_invoice'] = (int)($this->id_address_invoice);
$fields['id_cart'] = (int)($this->id_cart);
$fields['id_currency'] = (int)($this->id_currency);
$fields['id_lang'] = (int)($this->id_lang);
$fields['id_customer'] = (int)($this->id_customer);
$fields['id_carrier'] = (int)($this->id_carrier);
$fields['secure_key'] = pSQL($this->secure_key);
$fields['payment'] = pSQL($this->payment);
$fields['module'] = pSQL($this->module);
$fields['conversion_rate'] = (float)($this->conversion_rate);
$fields['recyclable'] = (int)($this->recyclable);
$fields['gift'] = (int)($this->gift);
$fields['gift_message'] = pSQL($this->gift_message);
$fields['shipping_number'] = pSQL($this->shipping_number);
$fields['total_discounts'] = (float)($this->total_discounts);
$fields['total_paid'] = (float)($this->total_paid);
$fields['total_paid_real'] = (float)($this->total_paid_real);
$fields['total_products'] = (float)($this->total_products);
$fields['total_products_wt'] = (float)($this->total_products_wt);
$fields['total_shipping'] = (float)($this->total_shipping);
$fields['carrier_tax_rate'] = (float)($this->carrier_tax_rate);
$fields['total_wrapping'] = (float)($this->total_wrapping);
$fields['invoice_number'] = (int)($this->invoice_number);
$fields['delivery_number'] = (int)($this->delivery_number);
$fields['invoice_date'] = pSQL($this->invoice_date);
$fields['delivery_date'] = pSQL($this->delivery_date);
$fields['valid'] = (int)($this->valid) ? 1 : 0;
$fields['appli'] = (int)($this->appli);
$fields['date_add'] = pSQL($this->date_add);
$fields['date_upd'] = pSQL($this->date_upd);
return $fields;
}
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 '';
}
public function printAppliIcons($value, $params)
{
$name = ((int)$value?'mobile':'computer');
return '';
}
public function printDeviceIcons($value, $params)
{
switch($value) {
default:
case 0:
$name = 'computer';
$icon = 'display';
break;
case 1:
$name = 'application';
$icon = 'android';
break;
case 2:
$name = 'mobile';
$icon = 'mobile';
break;
}
return '';
}
public function printCarrier($value, $params)
{
$laposte_carriers = unserialize(Configuration::get('LAPOSTEWS_CARRIERS', serialize(array())));
$mondialrelay_carriers = unserialize(Configuration::get('MONDIALRELAYWS_CARRIERS', serialize(array())));
$carriers_drop = explode(',',Configuration::get('ANT_CARRIER_DROP'));
if(in_array((int)$value,$mondialrelay_carriers)){
return '';
}elseif(in_array((int)$value,$laposte_carriers) || in_array((int)$value,$carriers_drop)){
return '';
}
}
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();
if (is_array($ids) && !empty($ids)) {
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'];
}
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT
d.`id_order_detail`,
IF(
(SELECT COUNT(p.`id_order_detail`)
FROM `'._DB_PREFIX_.'mondialrelay_parcel` p
WHERE d.`id_order_detail` = p.`id_order_detail`),
(SELECT SUM(p.`quantity`)
FROM `'._DB_PREFIX_.'mondialrelay_parcel` 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) {
if($data[$info['id_order_detail']]==0){
$data[$info['id_order_detail']] = $info['total_send'];
}
}
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT
d.`id_order_detail`,
IF(
(SELECT COUNT(p.`id_order_detail`)
FROM `'._DB_PREFIX_.'ant_dropshipping_parcel` p
WHERE d.`id_order_detail` = p.`id_order_detail`),
(SELECT SUM(p.`quantity`)
FROM `'._DB_PREFIX_.'ant_dropshipping_parcel` 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) {
if($data[$info['id_order_detail']]==0){
$data[$info['id_order_detail']] = $info['total_send'];
}
}
foreach (Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
SELECT
d.`id_order_detail`,
IF(
(SELECT COUNT(p.`id_order_detail`)
FROM `'._DB_PREFIX_.'philea_parcel` p
WHERE d.`id_order_detail` = p.`id_order_detail`),
(SELECT SUM(p.`quantity`)
FROM `'._DB_PREFIX_.'philea_parcel` 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) {
if($data[$info['id_order_detail']]==0){
$data[$info['id_order_detail']] = $info['total_send'];
}
}
}
return $data;
}
public static function getCurrentIdState($id_order)
{
$id_order_state = Db::getInstance()->getValue('
SELECT `id_order_state`
FROM `'._DB_PREFIX_.'order_state_current`
WHERE `id_order`='.(int)$id_order
);
return $id_order_state?$id_order_state:false;
}
}