From 14126961568944a42973c467bef55e677078fb9a Mon Sep 17 00:00:00 2001 From: Marion Muszynski Date: Fri, 28 Jul 2017 12:16:24 +0200 Subject: [PATCH] addition of solution field for supplier demand --- .../AdminAntSupplierDemand.php | 36 ++++++- .../ant_supplierdemand/ant_supplierdemand.php | 1 + .../models/SupplierDemand.php | 9 ++ .../classes/MakeStats.php | 93 +++++++++++-------- 4 files changed, 98 insertions(+), 41 deletions(-) diff --git a/modules/ant_supplierdemand/AdminAntSupplierDemand.php b/modules/ant_supplierdemand/AdminAntSupplierDemand.php index 52567a3e..40e499db 100644 --- a/modules/ant_supplierdemand/AdminAntSupplierDemand.php +++ b/modules/ant_supplierdemand/AdminAntSupplierDemand.php @@ -72,6 +72,17 @@ class AdminAntSupplierDemand extends AdminTab }, locale:"fr" }); + + if($("select#id_state").val()==5){ + $("select#solution").show(); + } + $("select#id_state").change(function(){ + if($(this).val()==5){ + $("select#solution").show(); + } else { + $("select#solution").hide(); + } + }); '; } @@ -143,6 +154,7 @@ class AdminAntSupplierDemand extends AdminTab $supplier_demands = SupplierDemand::getDemands($query_state); } $states = SupplierDemand::$states; + $solutions = SupplierDemand::$solutions; $counts = array( "done" => SupplierDemand::getCountDemands(array(5)), "no_answered" => SupplierDemand::getCountDemands(array(4)), @@ -190,6 +202,7 @@ class AdminAntSupplierDemand extends AdminTab '.$this->l('Status').' '.$this->l('Date').' '.$this->l('Renewed').' + '.$this->l('Solution').' '.$this->l('Action').' @@ -207,6 +220,7 @@ class AdminAntSupplierDemand extends AdminTab '.$states[$supplier_demand['id_state']]['name'].' '.date('d/m/Y',strtotime($supplier_demand['date_add'])).' '.($renews_number>1?''.$renews_number.'':''.$renews_number.'').' + '.((int)$supplier_demand['solution']>0?$solutions[(int)$supplier_demand['solution']]:'/').'
@@ -228,6 +242,7 @@ class AdminAntSupplierDemand extends AdminTab global $cookie, $currentIndex; $_current_index = ($this->config_tab ? $currentIndex . '&token=' . Tools::getAdminTokenLite($this->controller) : $_SERVER['REQUEST_URI']); $states = SupplierDemand::$states; + $solutions = SupplierDemand::$solutions; $customer = SupplierDemand::getCustomer($this->_object->id); $histories = SupplierDemand::getHistoryStatic($this->_object->id); $product = SupplierDemand::getProductStatic($this->_object->id); @@ -357,10 +372,18 @@ class AdminAntSupplierDemand extends AdminTab
- '; foreach ($states as $key => $state) { $this->_html .= ''; } + $this->_html.=' +
+
+
@@ -392,7 +415,14 @@ class AdminAntSupplierDemand extends AdminTab $supplierDemand->comment = Tools::getValue('comment'); } if(Tools::getValue('id_state')){ - $supplierDemand->id_state = (int)Tools::getValue('id_state'); + $id_state = (int)Tools::getValue('id_state'); + if($id_state == 5 && (!Tools::getValue('solution') || Tools::getValue('solution') == 0)){ + return HelperFormBootstrap::displayErrors($this->l('You have to choose a solution')); + } + if(Tools::getValue('solution')){ + $supplierDemand->solution = (int)Tools::getValue('solution'); + } + $supplierDemand->id_state = $id_state; $supplierDemand->addHistory(); } } else { @@ -406,7 +436,7 @@ class AdminAntSupplierDemand extends AdminTab if ($supplierDemand->save()) { return HelperFormBootstrap::displaySuccess($this->l('Demand has been created')); } else { - return HelperFormBootstrap::displayError($this->l('Error occured while creating demand')); + return HelperFormBootstrap::displayErrors($this->l('Error occured while creating demand')); } } } diff --git a/modules/ant_supplierdemand/ant_supplierdemand.php b/modules/ant_supplierdemand/ant_supplierdemand.php index d2337c48..8d8cfc68 100644 --- a/modules/ant_supplierdemand/ant_supplierdemand.php +++ b/modules/ant_supplierdemand/ant_supplierdemand.php @@ -52,6 +52,7 @@ class Ant_Supplierdemand extends Module `qty` INTEGER NOT NULL, `id_state` INTEGER NOT NULL DEFAULT 1, `comment` TEXT, + `solution` INTEGER NOT NULL DEFAULT 0, `date_add` DATETIME NOT NULL, `date_upd` DATETIME NOT NULL, PRIMARY KEY(`id_supplier_demand`) diff --git a/modules/ant_supplierdemand/models/SupplierDemand.php b/modules/ant_supplierdemand/models/SupplierDemand.php index f7f5a4df..4e977d75 100644 --- a/modules/ant_supplierdemand/models/SupplierDemand.php +++ b/modules/ant_supplierdemand/models/SupplierDemand.php @@ -28,11 +28,18 @@ class SupplierDemand extends ObjectModel ), ); + public static $solutions = array( + 1 => 'Remboursement/Avoir', + 2 => 'Remplacement du produit', + 3 => 'Autre' + ); + public $id_order; public $id_order_detail; public $qty; public $id_state; public $comment; + public $solution; public $date_add; public $date_upd; @@ -43,6 +50,7 @@ class SupplierDemand extends ObjectModel 'qty' => 'isUnsignedId', 'id_state' => 'isUnsignedId', 'comment' => 'isString', + 'solution' => 'isInt', 'date_add' => 'isDate', 'date_upd' => 'isDate', ); @@ -60,6 +68,7 @@ class SupplierDemand extends ObjectModel $fields['qty'] = (int)$this->qty; $fields['id_state'] = (int)$this->id_state; $fields['comment'] = pSQL($this->comment); + $fields['solution'] = (int)$this->solution; $fields['date_add'] = pSQL($this->date_add); $fields['date_upd'] = pSQL($this->date_upd); diff --git a/modules/privatesales_logistique/classes/MakeStats.php b/modules/privatesales_logistique/classes/MakeStats.php index d57f5471..bf50e843 100755 --- a/modules/privatesales_logistique/classes/MakeStats.php +++ b/modules/privatesales_logistique/classes/MakeStats.php @@ -1,6 +1,6 @@ = $i ; $j--) { + for ($i=0; $i < $size; $i++) { + for ($j=$size-1; $j >= $i ; $j--) { if($array[$j+1]['total_ht'] > $array[$j]['total_ht'] ) { $temp = $array[$j+1]; $array[$j+1] = $array[$j]; @@ -40,7 +40,7 @@ class MakeStats { return $array; } - public static function orderForReorder($array) + public static function orderForReorder($array) { $array_tmp = array(); $i = 0; @@ -62,27 +62,40 @@ class MakeStats { return (float)( $values['product_price']*( 1-($values['reduction_percent']/100) ) ); } + public static function getItemPackSoldQuantity($id_item) + { + $query = Db::getInstance()->getRow(' + SELECT SUM(od.`product_quantity` - od.`product_quantity_reinjected`) as quantity_sold , p.`quantity` + FROM `'._DB_PREFIX_.'pack` p + LEFT JOIN `'._DB_PREFIX_.'order_detail` od ON (od.`product_id` = p.`id_product_pack`) + LEFT JOIN `'._DB_PREFIX_.'order_state_current` oc ON (oc.`id_order`=od.`id_order`) + WHERE oc.`id_order_state` IN (13,4,17,9,1,11,10,5,14,12,2,3,18) + AND p.`id_product_item` = '.(int)$id_item.' + '); + return ($query['quantity_sold'] * $query['quantity']); + } + public static function record_sort($records, $field, $reverse=false) { $hash = array(); - + foreach($records as $record) { $hash[$record[$field]] = $record; } - + ($reverse)? krsort($hash) : ksort($hash); - + $records = array(); - + foreach($hash as $record) { $records []= $record; } - + return $records; } - + public static function getArrayLines($lines, $by_product_price = false, $id_sale = 0) { $arrayTmp = array(); @@ -143,14 +156,18 @@ class MakeStats { if (isset($line['product_quantity'])) { $quantity = $line['product_quantity'] - $line['product_quantity_reinjected']; } else { - $quantity = 0; + if(Pack::isPacked($line['product_id'])){ + $quantity = self::getItemPackSoldQuantity($line['product_id']); + } else { + $quantity = 0; + } } $stock = (isset($line['attribute_quantity']))?$line['attribute_quantity']:$line['stock']; if($by_product_price) { $arrayTmp[$line['product_id']][$line['product_attribute_id']][$product_price]['total'] += $quantity; $arrayTmp[$line['product_id']][$line['product_attribute_id']][$product_price]['stock'] = $stock; - } else { + } else { $arrayTmp[$line['product_id']][$line['product_attribute_id']]['total'] += $quantity; $arrayTmp[$line['product_id']][$line['product_attribute_id']]['stock'] = $stock; } @@ -189,25 +206,25 @@ class MakeStats { { $req = 'SELECT od.*, p.name as product_name_base, pd.quantity as stock FROM '._DB_PREFIX_.'order_detail od - RIGHT JOIN '._DB_PREFIX_.'orders o + RIGHT JOIN '._DB_PREFIX_.'orders o ON ( - od.id_order = o.id_order - AND (SELECT id_order_state + 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 + 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.'"' : '' ).' ) - LEFT OUTER JOIN `'._DB_PREFIX_.'product_lang` p - ON p.id_product = od.product_id + LEFT OUTER JOIN `'._DB_PREFIX_.'product_lang` p + ON p.id_product = od.product_id AND p.id_lang = 2 - LEFT OUTER JOIN `'._DB_PREFIX_.'product` pd - ON pd.id_product = od.product_id + LEFT OUTER JOIN `'._DB_PREFIX_.'product` pd + ON pd.id_product = od.product_id WHERE product_id IN ("'.implode('","', $ids_products).'")'; - + $res = Db::getInstance()->ExecuteS($req); $id_lang = 2; foreach($res as $k => $r) @@ -215,7 +232,7 @@ class MakeStats { // override product_name $res[$k]['product_name'] = $res[$k]['product_name_base']; $r['product_name'] = $r['product_name_base']; - if (!empty($r['product_attribute_id']) + if (!empty($r['product_attribute_id']) && $r['product_attribute_id'] != 0) { $product_attribute = Db::getInstance()->ExecuteS(' SELECT pa.*, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, al.`name` AS attribute_name, a.`id_attribute`, pa.`unit_price_impact` @@ -256,52 +273,52 @@ class MakeStats { // Adding - fev 2016 (récupération de Tous les produits de la vente et pas seulement ceux vendus) public static function getDetailsByIdsProduct($ids_products = array(), $order_states = array(), $date_from = null, $date_to = null) { - $req = 'SELECT + $req = 'SELECT od.*, p.name as product_name_base, pd.quantity as stock FROM '._DB_PREFIX_.'order_detail od - RIGHT JOIN '._DB_PREFIX_.'orders o + RIGHT JOIN '._DB_PREFIX_.'orders o ON ( - od.id_order = o.id_order - AND (SELECT id_order_state + 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 + 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.'"' : '' ).' ) - LEFT OUTER JOIN `'._DB_PREFIX_.'product_lang` p - ON p.id_product = od.product_id + LEFT OUTER JOIN `'._DB_PREFIX_.'product_lang` p + ON p.id_product = od.product_id AND p.id_lang = 2 - LEFT OUTER JOIN `'._DB_PREFIX_.'product` pd - ON pd.id_product = od.product_id + LEFT OUTER JOIN `'._DB_PREFIX_.'product` pd + ON pd.id_product = od.product_id WHERE product_id IN ("'.implode('","', $ids_products).'")'; $res = Db::getInstance()->ExecuteS($req); - $req2 = 'SELECT + $req2 = 'SELECT p.id_product as product_id, p.price as product_price, p.price as product_price, p.ean13 as product_ean13, p.reference as product_reference, p.supplier_reference as product_supplier_reference, p.weight as product_weight, pl.name as product_name_base, p.quantity as stock, pa.id_product_attribute as product_attribute_id FROM '._DB_PREFIX_.'product p - LEFT OUTER JOIN `'._DB_PREFIX_.'product_lang` pl - ON pl.id_product = p.id_product + LEFT OUTER JOIN `'._DB_PREFIX_.'product_lang` pl + ON pl.id_product = p.id_product AND pl.id_lang = 2 LEFT OUTER JOIN `'._DB_PREFIX_.'product_attribute` pa ON (pa.`id_product` = p.`id_product`) WHERE p.id_product IN ("'.implode('","', $ids_products).'")'; $res2 = Db::getInstance()->ExecuteS($req2); $ids_in_order = array(); - foreach($res as $k => $r) { + foreach($res as $k => $r) { $ids_in_order[$res[$k]['product_id']] = $res[$k]['product_attribute_id']; } foreach ($res2 as $k => $value) { if(isset($value['product_attribute_id']) && in_array($value['product_attribute_id'], $ids_in_order)) { unset($res2[$k]); - } elseif (!isset($value['product_attribute_id']) + } elseif (!isset($value['product_attribute_id']) && array_key_exists($value['product_id'], $ids_in_order) && $ids_in_order[$value['product_id']] == 0 ){ @@ -313,11 +330,11 @@ class MakeStats { $id_lang = 2; foreach($res as $k => $r) { - + // override product_name $res[$k]['product_name'] = $res[$k]['product_name_base']; $r['product_name'] = $r['product_name_base']; - if (!empty($r['product_attribute_id']) + if (!empty($r['product_attribute_id']) && $r['product_attribute_id'] != 0) { $product_attribute = Db::getInstance()->ExecuteS(' SELECT pa.*, ag.`id_attribute_group`, ag.`is_color_group`, agl.`name` AS group_name, al.`name` AS attribute_name, a.`id_attribute`, pa.`unit_price_impact`