'
;*/
}
public function getStats() {
return Db::getInstance()->executeS('
SELECT
e.`id_employee`,
e.`email`,
e.`lastname`,
e.`firstname`,
SUM(s.`nb_product`) AS `nb_product`,
SUM(s.`quantity`) AS `quantity`,
SUM(s.`nb_package`) AS `nb_package`
FROM `'._DB_PREFIX_.'stats_logistic` s
LEFT JOIN `'._DB_PREFIX_.'employee` e USING(`id_employee`)
WHERE s.`date` BETWEEN "'.pSQL($this->date_begin).'" AND "'.pSQL($this->date_end).'"
GROUP BY s.`id_employee`
');
}
public function getTotalColis() {
return Db::getInstance()->getValue('
SELECT
SUM(s.`nb_package`) AS `nb_package`
FROM `'._DB_PREFIX_.'stats_logistic` s
WHERE s.`date` BETWEEN "'.pSQL($this->date_begin).'" AND "'.pSQL($this->date_end).'"
');
}
public function getReport($day = 25, $state = 2) {
return 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 o.`date_add` < DATE_SUB("'.pSQL($this->date_stock).'",INTERVAL '.((int)$day-1).' DAY)
AND oh.`id_order_state` = '.(int)$state.'
AND 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
-- (
-- SELECT `id_order_state`
-- FROM '._DB_PREFIX_.'order_history oh
-- WHERE o.id_order = oh.id_order
-- ORDER BY id_order_history DESC
-- LIMIT 1
-- ) = '.(int)$state.'
');
}
public function getSaleDetails($product_ids) {
return Db::getInstance()->ExecuteS('
SELECT od.*, rr.`id_reason`
FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'order_slip` os ON (os.`id_order` = od.`id_order`)
LEFT JOIN `'._DB_PREFIX_.'refundreason` rr ON (rr.`id_order_slip` = os.`id_order_slip`)
WHERE od.`product_id` IN ('.implode(',', $product_ids).')
-- AND od.`product_quantity_refunded`>0
ORDER BY rr.`id_reason`
');
return Db::getInstance()->ExecuteS('
SELECT od.*
FROM `'._DB_PREFIX_.'order_detail` od
WHERE od.`product_id` IN ('.implode(',', $product_ids).')
');
}
public function getSales() {
return Db::getInstance()->ExecuteS('
SELECT `id_sale`
FROM `'._DB_PREFIX_.'privatesale`
WHERE `date_start` BETWEEN "'.pSQL($this->date_export_begin).'" AND "'.pSQL($this->date_export_end).'"
');
}
public function getProducts($id_sale) {
return Db::getInstance()->ExecuteS('
SELECT `id_product`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_sale`='.(int)$id_sale.'
');
}
public function exportCSV () {
$fp = fopen("php://output", 'w+');
$delim = ';';
$row_1 = array("","","","","","","","");
$data=array();
foreach ($row_definition as $col) {
$data[] = $col;
}
fputcsv ($fp,$data,$delim);
foreach ($items as $item) {
$data = array();
foreach ($row_definition as $key => $col) {
$data[] = (isset($item->$key) ? $item->$key : '');
}
fputcsv ($fp,array_map('utf8_decode',array_values($data)),$delim);
}
fclose($fp);
}
}