Merge branch 'develop' of gitlab.antadis.net:dev-antadis/bebeboutik into develop

This commit is contained in:
Christophe Latour 2017-07-28 12:17:35 +02:00
commit 467867f10e
10 changed files with 156 additions and 61 deletions

View File

@ -272,12 +272,6 @@ if (isset($_GET['updatePositionDrag'])){
foreach ($_positions as $id => $value) {
Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = '. (int)$value['new'].' WHERE id_sale = '. $id);
}
// die(json_encode(array(
// "position" => $position,
// "position_initial" => $position_initial,
// "new_position" => $new_position,
// "sale_positions" => $_positions,
// )));
Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = '. (int)$new_position.' WHERE id_sale = '. $id_sale);

View File

@ -898,7 +898,9 @@ class AdminImport extends AdminTab
$image->id_product = (int)($product->id);
$image->position = Image::getHighestPosition($product->id) + 1;
$image->cover = (!$key AND !$productHasImages) ? true : false;
$image->legend = self::createMultiLangField($product->name);
if(isset($product->name[2])){
$image->legend = self::createMultiLangField($product->name[2]);
}
if (($fieldError = $image->validateFields(UNFRIENDLY_ERROR, true)) === true AND ($langFieldError = $image->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true AND $image->add())
{
if (!self::copyImg($product->id, $image->id, $url))

View File

@ -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();
}
});
</script>';
}
@ -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
<th class="text-center">'.$this->l('Status').'</th>
<th class="text-center">'.$this->l('Date').'</th>
<th class="text-center">'.$this->l('Renewed').'</th>
<th class="text-center">'.$this->l('Solution').'</th>
<th class="text-center">'.$this->l('Action').'</th>
</tr>
</thead>
@ -207,6 +220,7 @@ class AdminAntSupplierDemand extends AdminTab
<td valign="middle" align="center"><span class="'.$states[$supplier_demand['id_state']]['icon'].'"></span> '.$states[$supplier_demand['id_state']]['name'].'</td>
<td valign="middle" align="center">'.date('d/m/Y',strtotime($supplier_demand['date_add'])).'</td>
<td valign="middle" align="center">'.($renews_number>1?'<span class="label label-danger">'.$renews_number.'</span>':'<span class="label label-default">'.$renews_number.'</span>').'</td>
<td valign="middle" align="center">'.((int)$supplier_demand['solution']>0?$solutions[(int)$supplier_demand['solution']]:'/').'</td>
<td valign="middle" align="center">
<div class="input-group-btn" role="group" aria-label="...">
<a href="'.$_current_index.'&updateSupplierDemand=1&id='.$supplier_demand['id_supplier_demand'].'" class="btn btn-default"><span class="anticon anticon-pencil2"></span></a>
@ -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
<form style="padding:10px 20px;background:#efefef;" action="'.$_current_index.'&updateSupplierDemand=1&id='.$this->_object->id.'" method="post">
<input type="hidden" name="id_supplier_demand" value="'.$this->_object->id.'" />
<div class="form-group">
<select class="form-control" name="id_state">';
<select class="form-control" name="id_state" id="id_state">';
foreach ($states as $key => $state) {
$this->_html .= '<option value="'.$key.'"'.($this->_object->id_state == $key ? ' selected="selected"' : '').'>'.$state['name'].'</option>';
}
$this->_html.='</select>
</div>
<div class="form-group">
<select class="form-control" name="solution" id="solution" style="display:none;">
<option value="0">'.$this->l('Solution...').'</option>';
foreach ($solutions as $key => $solution) {
$this->_html .= '<option value="'.$key.'"'.($this->_object->solution == $key ? ' selected="selected"' : '').'>'.$solution.'</option>';
}
$this->_html.='</select>
</div>
<div class="form-group">
@ -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'));
}
}
}

View File

@ -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`)

View File

@ -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);

View File

@ -955,6 +955,7 @@ class AdminPrivateSalesSales extends AdminTab {
<button type="submit" name="not_ended" class="tri btn btn-default active">Ventes actuelles</button>
<button type="submit" name="finished" class="tri btn btn-default">Ventes terminées</button>
<button type="submit" name="all" class="tri btn btn-default">Toutes les ventes</button>
<!--a style="cursor: pointer;" onclick="resortPosition();" class="btn btn-default">Resort</a-->
</div>
</div>
<div class="clearfix"></div>
@ -1291,5 +1292,17 @@ class AdminPrivateSalesSales extends AdminTab {
Sale::unlockPosition($id_sale);
Tools::redirectAdmin($currentIndex.'&token='.Tools::getAdminTokenLite('AdminPrivateSalesSales'));
}
// elseif(isset($_GET['resort_position'])){
// $nb_sales = Db::getInstance()->getValue('
// SELECT COUNT(p.`id_sale`)
// FROM `ps_privatesale` p
// WHERE CAST(p.`date_start` AS DATE) = CAST(NOW() AS DATE)
// AND `date_end` > NOW()
// ');
// if($nb_sales>0) {
// Sale::sortActiveSaleAfterAdd($nb_sales);
// }
// }
}
}

View File

@ -268,8 +268,12 @@ class Sale {
)
');
}
self::sortActiveSaleAfterAdd();
// $today = strtotime(date("Y-m-d H:i:s"));
// $start = strtotime($sale->date_start);
// $end = strtotime($sale->date_end);
// if($start <= $today && $end > $today){
// self::sortActiveSaleAfterAdd(1);
// }
Module::hookExec('privatesales_create', array('sale' => $this));
}
@ -299,18 +303,21 @@ class Sale {
}
}
public static function sortActiveSaleAfterAdd(){
foreach(Db::getInstance()->executeS('
SELECT id_sale, position
FROM '._DB_PREFIX_.'privatesale
WHERE lock_position = 1
AND `date_end` > NOW()
ORDER BY position DESC
') as $sale){
$pos = $sale['position']+1;
public static function sortActiveSaleAfterAdd($nb = 1){
for ($i=0; $i < $nb; $i++) {
foreach(Db::getInstance()->executeS('
SELECT id_sale, position
FROM '._DB_PREFIX_.'privatesale
WHERE lock_position = 1
AND `date_end` > NOW()
AND `date_start` < NOW()
ORDER BY position DESC
') as $sale){
$pos = $sale['position']+1;
Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = position-1 WHERE position = '. $pos);
Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = position+1 WHERE id_sale = '. $sale['id_sale']);
Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = position-1 WHERE position = '. $pos);
Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = position+1 WHERE id_sale = '. $sale['id_sale']);
}
}
}

View File

@ -0,0 +1,19 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) exit;
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include(dirname(__FILE__).'/../../config/config.inc.php');
include(dirname(__FILE__).'/Sale.php');
$nb_sales = Db::getInstance()->getValue('
SELECT COUNT(p.`id_sale`)
FROM `ps_privatesale` p
WHERE CAST(p.`date_start` AS DATE) = CAST(NOW() AS DATE)
AND `date_end` > NOW()
');
if($nb_sales>0) {
Sale::sortActiveSaleAfterAdd($nb_sales);
}

View File

@ -21,3 +21,6 @@ function itemLockPosition(linkId) {
function itemUnLockPosition(linkId) {
document.location.href = current_location + "&id=" + linkId + "&unlock_position=1";
}
function resortPosition() {
document.location.href = current_location + "&resort_position=1";
}

View File

@ -1,6 +1,6 @@
<?php
class MakeStats {
public static function getProductsByCat($id_cat = NULL)
{
global $cookie;
@ -28,8 +28,8 @@ class MakeStats {
{
$array = self::orderForReorder($multi_array);
$size = count($array);
for ($i=0; $i < $size; $i++) {
for ($j=$size-1; $j >= $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`