id_lang,FALSE);
krsort($categories[1]);
$option .= "";
foreach($categories[1] as $categorie){
$select = "";
if($id_category == $categorie['infos']['id_category']){
$select = "selected='selected'";
}
$option .= "";
}
return $option;
}
public function getCategoryChildren($id_category = NULL,$test = true){
global $cookie;
$html = "";
if(!$id_category){
$categoriesFirst = CategoryCore::getCategories($cookie->id_lang,FALSE);
$i = 0;
foreach($categoriesFirst[1] as $categorie){
if( $i == 0){
$id_category= $categorie['infos']['id_category'];
}
$i++;
}
}
$categories = CategoryCore::getChildren($id_category, $cookie->id_lang,FALSE);
if($test){
$html .= " Exporter
";
}
if($categories){
$i = 0;
foreach($categories as $categorie){
if( $i == 0){
$display = " show";
$plus =" moins";
}else{
$display = " hide";
$plus =" plus";
}
$products = self::getProductsByCat($categorie['id_category']);
if($products){
$y = 0;
$html .= "
".$categorie['name']."
";
$html .= "";
$html .= self::MvtsAllProducts($products)."
";
$html .= "
Exporter
";
foreach ($products as $value) {
if( $y == 0 && $i == 0){
$display = " show";
$plus =" moins";
$html .= '';
}else{
$display = " hide";
$plus =" plus";
}
$featuresValue = "";
if($value['features']){
foreach($value['features'] as $feature){
if($feature['name'] == "COULEUR" ){
$featuresValue = $feature['value'];
}
}
}
$html .= "
".$value['reference']." - ".$value['name']." - Couleur : ".$featuresValue." - Ref/Frn : ".$value['supplier_reference']."
";
$html .= "
";
$y++;
}
$html .= "
";
$i++;
}else{
$html .= "".$categorie['name']."
";
$html .= "";
$html .= Inventory::getCategoryChildren($categorie['id_category'],FALSE);
$html .= "
";
}
}
}else{
$html .= "";
}
return $html;
}
public function getProductsByCat($id_cat = NULL){
global $cookie;
$category = new CategoryCore($id_cat);
$products = $category->getProducts( $cookie->id_lang , "1", "1000000000000000000", "id_product",NULL , NULL, FALSE , FALSE );
return $products;
}
public function getProductInfo($id_product = NULL){
global $cookie;
$html = "" ;
$product = new ProductCore($id_product);
$features = $product->getFrontFeatures($cookie->id_lang);
$id_image = $product->getCoverWs();
if($id_image){
$image = new ImageCore($id_image);
$html .= "";
}
$html .="Désignation : ".$product->name[$cookie->id_lang]."
Ref : ".$product->reference."
Ref/Frn : ".$product->supplier_reference."
";
if(isset($features)){
foreach($features as $feature){
$html .= "".ucfirst(strtolower($feature['name']))." : ".$feature['value']."
";
}
}
$html .= "
";
$html .= "";
$attributes = $product->getAttributesGroups($cookie->id_lang);
if($attributes){
$html .= self::TabAttributes($attributes,$product);
}else{
$html .= self::TabNoAttributes($product);
}
$html .= "";
return $html;
}
public function TabAttributes($attributes,$product){
global $cookie;
$html = "
Déclinaisons |
Stock total |
Ventes totales |
CA |
Stock |
Vendues |
Restantes |
";
$totalRestant = 0;
$totalQuantiteInitial = 0;
$totalQuantiteTotalStock = 0;
$totalQuantiteVendu = 0;
$totalQuantiteTotalVendu = 0;
$totalCA = 0;
foreach($attributes as $attribute){
$mvts = self::getStockMouvements($cookie->id_lang,$product->id,$attribute['id_product_attribute']);
$i=0;
$quantiteInitial = 0;
$quantiteTotalStock = 0;
$quantiteTotalVendu = 0;
$quantiteVendu = 0;
$CA = 0;
foreach($mvts as $mvt){
if($mvt['reason'] == "Augmenter"){
$quantiteInitial += $mvt['quantity'];
$quantiteTotalStock += $mvt['quantity'];
$quantiteVendu = 0;
}
if($mvt['reason'] == "Commande"){
$quantiteInitial -= $mvt['quantity'];
$quantiteVendu -= $mvt['quantity'];
$quantiteTotalVendu -= $mvt['quantity'];
}
if($mvt['reason'] == "Diminuer"){
$quantiteInitial += $mvt['quantity'];
}
}
$quantiteTotalStock = $quantiteVendu + $attribute['quantity'];
$CA = $quantiteTotalVendu * $product->getPrice(true, null, 2);
$html .= "
".$attribute['group_name']." : ".$attribute['attribute_name']." |
".$quantiteInitial." |
".$quantiteTotalVendu." |
".$CA." € |
".$quantiteTotalStock." |
".$quantiteVendu." |
".$attribute['quantity']." |
";
$totalRestant += $attribute['quantity'];
$totalQuantiteInitial += $quantiteInitial;
$totalQuantiteTotalStock += $quantiteTotalStock;
$totalQuantiteVendu += $quantiteVendu;
$totalQuantiteTotalVendu += $quantiteTotalVendu;
$totalCA += $CA;
}
$html .= "
Totaux |
".$totalQuantiteInitial." |
".$totalQuantiteTotalVendu." |
".$totalCA." € |
".$totalQuantiteTotalStock." |
".$totalQuantiteVendu." |
".$totalRestant." |
";
return $html;
}
public function TabNoAttributes($product){
global $cookie;
$html = "
Stock total |
Ventes totales |
CA |
Stock |
Vendues |
Restantes |
";
$mvts = self::getStockMouvements($cookie->id_lang,$product->id);
$i=0;
$quantiteInitial = 0;
$quantiteTotalStock = 0;
$quantiteTotalVendu = 0;
$quantiteVendu = 0;
$CA = 0;
foreach($mvts as $mvt){
if($mvt['reason'] == "Augmenter"){
$quantiteInitial += $mvt['quantity'];
$quantiteTotalStock += $mvt['quantity'];
$quantiteVendu = 0;
}
if($mvt['reason'] == "Commande"){
$quantiteVendu -= $mvt['quantity'];
$quantiteTotalVendu -= $mvt['quantity'];
$quantiteInitial -= $mvt['quantity'];
}
if($mvt['reason'] == "Diminuer"){
$quantiteInitial += $mvt['quantity'];
}
}
$quantiteTotalStock = $quantiteVendu + $product->quantity;
$totalQuantiteInitial += $quantiteInitial + $product->quantity;
$CA = $quantiteTotalVendu * $product->getPrice(true, null, 2);
$html .= "
".$totalQuantiteInitial." |
".$quantiteTotalVendu." |
".$CA." € |
".$quantiteTotalStock." |
".$quantiteVendu." |
".$product->quantity." |
";
return $html;
}
public function MvtsAllProducts($products){
global $cookie;
$html = "
Stock total |
Ventes totales |
CA |
Stock |
Vendues |
Restantes |
";
$totalRestant = 0;
$totalQuantiteInitial = 0;
$totalQuantiteTotalStock = 0;
$totalQuantiteVendu = 0;
$totalQuantiteTotalVendu = 0;
$CA = 0;
foreach($products as $product){
$Obj_product = new ProductCore($product['id_product']);
if($Obj_product->hasAttributes()){
$attribute = true;
}else{
$attribute = false;
}
$mvts = self::getStockMouvements($cookie->id_lang,$product['id_product'],NULL,$attribute);
$i=0;
$quantiteInitial = 0;
$quantiteTotalStock = 0;
$quantiteTotalVendu = 0;
$quantiteVendu = 0;
foreach($mvts as $mvt){
if($mvt['reason'] == "Augmenter"){
$quantiteInitial += $mvt['quantity'];
$quantiteTotalStock += $mvt['quantity'];
$quantiteVendu = 0;
}
if($mvt['reason'] == "Commande"){
$quantiteInitial -= $mvt['quantity'];
$quantiteVendu -= $mvt['quantity'];
$quantiteTotalVendu -= $mvt['quantity'];
}
if($mvt['reason'] == "Diminuer"){
$quantiteInitial += $mvt['quantity'];
}
}
$totalRestant += $Obj_product->getQuantity($product['id_product']);
$totalQuantiteInitial += $quantiteInitial + $Obj_product->getQuantity($product['id_product']);
$totalQuantiteVendu += $quantiteVendu;
$totalQuantiteTotalVendu += $quantiteTotalVendu;
$CA += $quantiteTotalVendu * $Obj_product->getPrice(true, null, 2);
}
$totalQuantiteTotalStock = $totalQuantiteVendu + $totalRestant;
$html .= "
".$totalQuantiteInitial." |
".$totalQuantiteTotalVendu." |
".$CA." € |
".$totalQuantiteTotalStock." |
".$totalQuantiteVendu." |
".$totalRestant." |
";
return $html;
}
public function calculStockMvt($mvts, $product)
{
$i=0;
$quantiteInitial = 0;
$quantiteTotalStock = 0;
$quantiteTotalVendu = 0;
$quantiteVendu = 0;
foreach($mvts as $mvt){
if($mvt['reason'] == "Commande"){
$quantiteInitial -= $mvt['quantity'];
$quantiteVendu -= $mvt['quantity'];
$quantiteTotalVendu -= $mvt['quantity'];
}
}
$array = array();
$array['restant'] = Product::getQuantity($product->id);
$array['quantiteInitial'] = $quantiteInitial;
$array['quantiteVendu'] = $quantiteVendu;
$array['quantiteTotalVendu'] = $quantiteTotalVendu;
return $array;
}
public function getStockMouvements($id_lang, $id_product, $id_attribute = NULL , $all = false, $date_from = null, $date_to = null) {
if($id_attribute){
$attr = ' sm.id_product_attribute='.(int)$id_attribute;
}else{
$attr = ' sm.id_product='.(int)$id_product;
}
$form = "";
if($all){
$attr .= ' AND pa.id_product_attribute = sm.id_product_attribute';
$form .= ", `"._DB_PREFIX_."product_attribute` pa ";
}
if($date_from !== null && $date_to !== null && Validate::isDate($date_from) && Validate::isDate($date_to))
$attr .= ' AND sm.date_add >= "'.$date_from.'" AND sm.date_add <= "'.$date_to.'"';
$sql = '
SELECT sm.id_product ,sm.id_product_attribute , sm.date_add, sm.id_stock_mvt, sm.date_add, sm.quantity, sm.id_order, CONCAT(pl.name, \' \', GROUP_CONCAT(IFNULL(al.name, \'\'), \'\')) product_name, pl.name as product_name_simple, CONCAT(e.lastname, \' \', e.firstname) employee, mrl.name reason FROM `'._DB_PREFIX_.'stock_mvt` sm
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON (sm.id_product = pl.id_product AND pl.id_lang = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'stock_mvt_reason_lang` mrl ON (sm.id_stock_mvt_reason = mrl.id_stock_mvt_reason AND mrl.id_lang = '.(int)$id_lang.')
LEFT JOIN `'._DB_PREFIX_.'employee` e ON (e.id_employee = sm.id_employee) LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON (pac.id_product_attribute = sm.id_product_attribute) LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (al.id_attribute = pac.id_attribute AND al.id_lang = '.(int)$id_lang.')'.$form.' WHERE '.$attr.' GROUP BY sm.id_stock_mvt' ;
return Db::getInstance()->ExecuteS($sql);
}
public function getOrdersByIdsProduct($ids_products = array(), $order_states = array(), $date_from = null, $date_to = null)
{
$req = 'SELECT od.*
FROM '._DB_PREFIX_.'order_detail od
RIGHT JOIN '._DB_PREFIX_.'orders o
ON (
od.id_order = o.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)
IN ("'.implode('","', $order_states).'")
'.($date_from !== null && $date_to !== null && Validate::isDate($date_from) && Validate::isDate($date_to) ?
'AND o.date_add >= "'.$date_from.'" AND o.date_add <= "'.$date_to.'"' : '' ).'
)
WHERE product_id IN ("'.implode('","', $ids_products).'")';
$res = Db::getInstance()->ExecuteS($req);
return $res;
}
}
?>