2016-01-04 12:48:08 +01:00
< ? php
define ( 'PS_ADMIN_DIR' , getcwd ());
include ( PS_ADMIN_DIR . '/../config/config.inc.php' );
/* Getting cookie or logout */
require_once ( dirname ( __FILE__ ) . '/init.php' );
require_once ( '../modules/privatesales/Sale.php' );
2017-03-21 14:39:43 +01:00
require_once ( '../modules/privatesales_delay/saledelay.php' );
2016-01-04 12:48:08 +01:00
require_once ( '../modules/privatesales_extrafields/privatesales_extrafields.php' );
2017-10-30 13:41:50 +01:00
if ( isset ( $_GET [ 'flush_sale' ])){
$replies = CacheRedis :: getInstance () -> clear ( 'sale*' );
echo '<pre>' ; var_dump ( $replies ); echo '</pre>' ; die ();
//echo 'Clear cache';
die ();
}
2016-01-04 12:48:08 +01:00
if ( isset ( $_GET [ 'getSales' ])){
2017-01-02 15:49:14 +01:00
global $cookie ;
2016-03-16 15:47:25 +01:00
$type = $_GET [ 'type' ];
2016-01-04 12:48:08 +01:00
if ( $type == 'finished' ){
2017-10-30 13:41:50 +01:00
$sales = Sale :: getSalesBack ( NULL , NULL , NULL , FALSE , FALSE , FALSE , '`position` DESC' , NULL , NULL , FALSE , FALSE );
2016-03-16 15:47:25 +01:00
} else {
2017-10-30 13:41:50 +01:00
$sales = Sale :: getSalesBack ( NULL , NULL , NULL , $type , FALSE , FALSE , '`position` DESC' , NULL , NULL , FALSE , FALSE );
2016-01-04 12:48:08 +01:00
}
$ids = array ();
foreach ( $sales as $key => $sale ) {
$ids [] = $sale -> id ;
}
$extrafields = PrivateSales_ExtraFields :: getFieldsForSale ( $ids );
$employees = array ();
2017-03-21 13:07:20 +01:00
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_employee` , `firstname` , `lastname`
FROM `'._DB_PREFIX_.'employee`
' ) as $row ) {
$employees [( int ) $row [ 'id_employee' ]] = $row [ 'firstname' ] . ' ' . $row [ 'lastname' ];
}
$sale_shipping = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT *
FROM `'._DB_PREFIX_.'privatesale_shipping_sale`
WHERE 1
' ) as $ss ) {
$sale_shipping [ $ss [ 'id_sale' ]] = $ss [ 'id_shipping' ];
}
2016-01-04 12:48:08 +01:00
echo " <thead><tr>
< th > ID </ th >
2017-03-21 14:54:06 +01:00
< th > Cat .</ th >
2016-01-04 12:48:08 +01:00
< th > Titre </ th >
< th > Début </ th >
< th > Fin </ th >
< th > Activée </ th >
< th > Nouveau </ th >
< th > Commercial </ th >
< th > FR </ th >
< th > ES </ th >
2017-03-21 14:39:43 +01:00
< th align = 'center' > Delay </ th >
2017-03-21 14:54:06 +01:00
< th > Expe </ th >
2016-01-04 12:48:08 +01:00
< th > Position </ th >
2017-01-02 15:49:14 +01:00
< th > Actions </ th >
2016-01-04 12:48:08 +01:00
</ tr ></ thead >
< tbody id = 'saleActive' class = 'sortable' > " ;
2016-03-16 15:47:25 +01:00
2016-01-04 12:48:08 +01:00
$export = true ;
2016-03-16 15:47:25 +01:00
foreach ( $sales as $key => $sale ) {
2017-03-21 14:39:43 +01:00
$delay = SaleDelay :: getDelaySmallName ( $sale -> delivery_delay , 2 );
2017-07-20 11:37:45 +02:00
echo '<tr id="item_' . $sale -> id . ' " class= " " >
2016-01-04 12:48:08 +01:00
< td > '.$sale->id.' </ td >
2016-10-05 11:25:43 +02:00
< td > '.$sale->id_category.' </ td >
2017-03-21 14:54:06 +01:00
< td >< strong > '.$sale->title[intval($cookie->id_lang)].' </ strong >< br />< span style = " color:#666; font-style:italic; font-size:11px; " > '.$extrafields[$sale->id][1].' </ span ></ td >
< td style = " font-size:11px; " > '.$sale->date_start.' </ td >
< td style = " font-size:11px; " > '.$sale->date_end.' </ td >
2017-03-21 13:07:20 +01:00
< td align = " center " > '.($sale->enabled? ' < span class = " anticon anticon-checkmark text-green-light " ></ span > ':' < span class = " anticon anticon-cross text-rose " ></ span > ').' </ td > ' ;
2016-01-04 12:48:08 +01:00
if ( $sale -> new == 0 ){
2017-03-21 13:07:20 +01:00
echo " <td align='center'>Non</td> " ;
2016-01-04 12:48:08 +01:00
}
else if ( $sale -> new == 1 ){
2017-03-21 13:07:20 +01:00
echo " <td align='center'>Oui</td> " ;
2016-01-04 12:48:08 +01:00
}
else if ( $sale -> new == 3 ){
2017-03-21 13:07:20 +01:00
echo " <td align='center'>Non défini</td> " ;
2016-01-04 12:48:08 +01:00
}
2016-03-16 15:47:25 +01:00
2016-01-04 12:48:08 +01:00
echo '<td>' . (( int ) $sale -> id_employee != 0 ? $employees [( int ) $sale -> id_employee ] : '--' ) . ' </ td >
2017-01-02 15:49:14 +01:00
< td class = " text-center '.(in_array('fr', $sale->versions ) ? 'green' : 'rose').' " > FR </ td >
< td class = " text-center '.(in_array('es', $sale->versions ) ? 'green' : 'rose').' " > ES </ td >
2017-03-21 14:39:43 +01:00
< td align = " center " > '.$delay.' </ td >
2017-09-26 14:53:38 +02:00
< td align = " center " > '.(isset($sale_shipping[(int) $sale->id])? ($sale_shipping[(int) $sale->id] == 1? ' Philéa ': ($sale_shipping[(int) $sale->id] == 2? ' Drop ' : ' ')): ' ').' </ td >
2017-01-02 15:49:14 +01:00
< td align = " center " class = " position " > ' ;
2017-07-20 11:37:45 +02:00
if ( $sale -> lock_position == 1 ){
echo '<span class="anticon anticon-lock"></span>' ;
} else {
if ( $key != 0 ){
echo '<a href="#" onclick="updatePositionVP(0,' . $sale -> position . '); return false;" class="updatePosition" data-way="0" data-position=' . $sale -> position . '><img title="Haut" alt="Haut" src="../img/admin/up.gif"></a>' ;
}
if ( $key + 1 != count ( $sales )){
echo ' <a href="#" class="updatePosition" onclick="updatePositionVP(1,' . $sale -> position . '); return false;" data-way="1" data-position=' . $sale -> position . '><img title="Bas" alt="Bas" src="../img/admin/down.gif"></a>' ;
}
2016-01-04 12:48:08 +01:00
}
2016-03-16 15:47:25 +01:00
$category_link = Link :: getCategoryLink ( $sale -> id_category );
2017-01-02 15:49:14 +01:00
$category_link_bo = '?tab=AdminCatalog&viewcategory&id_category=' . $sale -> id_category . '&token=' . Tools :: getAdminToken ( 'AdminCatalog' . ( int )( Tab :: getIdFromClassName ( 'AdminCatalog' )) . ( int )( $cookie -> id_employee ));
2016-01-04 12:48:08 +01:00
echo ' </ td >
< td >
2017-01-02 15:49:14 +01:00
< div class = " input-group-btn " role = " group " >
< button class = " btn btn-default " onclick = " itemEdition('. $sale->id .') " title = " Editer la vente " >
2017-03-21 14:57:26 +01:00
< span style = " font-size:12px; " class = " anticon anticon-pencil2 " ></ span >
2017-01-02 15:49:14 +01:00
</ button >
< a href = " '. $category_link .' " target = " _blank " class = " btn btn-default " title = " Voir la vente sur le site " >
2017-03-21 14:57:26 +01:00
< span style = " font-size:12px; " class = " anticon anticon-eye " ></ span >
2017-01-02 15:49:14 +01:00
</ a >
2017-03-21 13:07:20 +01:00
< button type = " button " class = " btn btn-default dropdown-toggle " data - toggle = " dropdown " aria - haspopup = " true " aria - expanded = " false " >
2017-03-21 14:57:26 +01:00
< span style = " font-size:12px; " class = " anticon anticon-menu " ></ span >
2017-01-02 15:49:14 +01:00
</ button >
< ul class = " dropdown-menu dropdown-menu-right " >
'.($export? '
< li >
< a onclick = " window.open(this.href); return false; " href = " '.__PS_BASE_URI__.'modules/exports/exports/privatesales.php?id_sale='. $sale->id .'&adtoken='.Tools::encrypt('PrivateSalesDirectExtract'. $sale->id ).' " >
< i class = " glyphicon glyphicon-new-window " ></ i > Exporter
</ a >
</ li > ':' ').'
< li >
< a onclick = " window.open(this.href); return false; " href = " '. $category_link_bo .' " >
< i class = " glyphicon glyphicon-eye-open " ></ i > Voir Catégorie BO
</ a >
</ li >
2017-07-20 16:51:19 +02:00
< li >
< a style = " cursor: pointer; " onclick = " '.( $sale->lock_position ?'itemUnLockPosition('. $sale->id .')':'itemLockPosition('. $sale->id .')').' " >
< span class = " anticon anticon-lock " ></ span > '.($sale->lock_position?' Défixer ':' Fixer ').' position
</ a >
</ li >
2017-01-02 15:49:14 +01:00
< li role = " separator " class = " divider " ></ li >
< li >
< a style = " cursor: pointer; " onclick = " itemDeletion('. $sale->id .') " >
< span class = " anticon anticon-bin " ></ span > Supprimer
</ a >
</ li >
</ ul >
</ div >
2016-01-04 12:48:08 +01:00
</ td >
</ tr >
' ;
2017-01-02 15:49:14 +01:00
// '.($export? '<a onclick="window.open(this.href); return false;" href="'.__PS_BASE_URI__.'modules/exports/exports/privatesales.php?id_sale='.$sale->id.'&adtoken='.Tools::encrypt('PrivateSalesDirectExtract'.$sale->id).'"><img style="cursor: pointer;" title="Exporter cette vente" alt="" src="../img/admin/export.gif"></a>': '').'
// <img style="cursor: pointer;" onclick="itemEdition('.$sale->id.')" title="Éditer cette vente" alt="" src="../img/admin/edit.gif">
// <img style="cursor: pointer;" onclick="itemDeletion('.$sale->id.')" title="Supprimer cette vente" alt="" src="../img/admin/delete.gif">
// <a href="'.$category_link.'" target="_blank">
// <img style="cursor: pointer;" title="Voir cette vente" alt="" src="../img/admin/details.gif">
// </a>
2016-01-04 12:48:08 +01:00
}
echo " </tbody> " ;
die ();
}
function getSaleType ( $sale_type ){
$type = " " ;
if ( in_array ( 1 , $sale_type )){
$type .= " Bébé " ;
}
if ( in_array ( 2 , $sale_type )){
$type .= " Enfant " ;
}
if ( in_array ( 3 , $sale_type )){
$type .= " Maman " ;
}
if ( empty ( $type )){
return " undefined " ;
}
return $type ;
}
if ( isset ( $_GET [ 'updatePosition' ])){
$position = $_GET [ 'position' ];
$way = $_GET [ 'way' ];
if ( $way == 0 ){
2016-03-16 15:47:25 +01:00
$new_position = $position + 1 ;
2016-01-04 12:48:08 +01:00
} elseif ( $way == 1 ){
$new_position = $position - 1 ;
}
updateSalePosition ( $position , $new_position );
die ();
}
2016-03-16 15:47:25 +01:00
function updateSalePosition ( $position , $new_position ){
2016-01-04 12:48:08 +01:00
$sale = Sale :: getByPosition ( $position );
$last_sale = Sale :: getByPosition ( $new_position );
2017-07-20 11:37:45 +02:00
if ( $sale -> lock_position || $last_sale -> lock_position ){
return true ;
}
2016-01-04 12:48:08 +01:00
// // update lactuelle new position
Db :: getInstance () -> autoExecute ( _DB_PREFIX_ . 'privatesale' , array (
2016-03-16 15:47:25 +01:00
'position' => $position ),
2016-01-04 12:48:08 +01:00
'UPDATE' ,
'id_sale = ' . $last_sale -> id );
2016-03-16 15:47:25 +01:00
// // update pour la nouvelle position
2016-01-04 12:48:08 +01:00
Db :: getInstance () -> autoExecute ( _DB_PREFIX_ . 'privatesale' , array (
2016-03-16 15:47:25 +01:00
'position' => $new_position ),
2016-01-04 12:48:08 +01:00
'UPDATE' ,
'id_sale = ' . $sale -> id );
return true ;
}
if ( isset ( $_GET [ 'updatePositionDrag' ])){
$id_sale = str_replace ( " item_ " , " " , $_GET [ 'id_sale' ]);
$position = $_GET [ 'position' ];
2017-07-20 11:37:45 +02:00
$sql = 'SELECT position, lock_position FROM ' . _DB_PREFIX_ . 'privatesale WHERE id_sale =' . $id_sale ;
$query = Db :: getInstance () -> getRow ( $sql );
if (( int ) $query [ 'lock_position' ] == 1 ){
die ();
}
2016-01-04 12:48:08 +01:00
2017-07-20 11:37:45 +02:00
$position_initial = ( int ) $query [ 'position' ];
2016-01-04 12:48:08 +01:00
$new_position = $position_initial + $position ;
2017-07-20 11:37:45 +02:00
$sql = 'SELECT lock_position FROM ' . _DB_PREFIX_ . 'privatesale WHERE position =' . $new_position ;
$is_lock = Db :: getInstance () -> getValue ( $sql );
if ( $is_lock == 1 ){
die ();
}
2017-07-20 16:51:19 +02:00
$lock_positions = array ();
foreach ( Db :: getInstance () -> executeS ( 'SELECT position FROM ' . _DB_PREFIX_ . 'privatesale WHERE lock_position = 1' ) as $lock ){
$lock_positions [] = ( int ) $lock [ 'position' ];
}
2017-07-20 11:37:45 +02:00
2017-07-20 16:51:19 +02:00
$_positions = array ();
2016-01-04 12:48:08 +01:00
if ( $position > 0 ){
2017-07-20 16:51:19 +02:00
$sales_sql = " SELECT id_sale, position FROM " . _DB_PREFIX_ . " privatesale WHERE position BETWEEN " . ( $position_initial + 1 ) . ' AND ' . $new_position . ' AND lock_position = 0 ORDER BY position DESC' ;
2016-03-16 15:47:25 +01:00
$sales = Db :: getInstance () -> ExecuteS ( $sales_sql );
foreach ( $sales as $key => $sale ){
2017-07-20 16:51:19 +02:00
$pos = ( int ) $sale [ 'position' ] - 1 ;
while ( in_array ( $pos , $lock_positions )){
$pos = $pos - 1 ;
2017-07-20 11:37:45 +02:00
}
2017-07-20 16:51:19 +02:00
$_positions [( int ) $sale [ 'id_sale' ]] = array (
'initial' => ( int ) $sale [ 'position' ],
'new' => $pos ,
);
//Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = '.$pos.' WHERE id_sale = '. $sale['id_sale']);
2016-01-04 12:48:08 +01:00
}
2017-07-20 11:37:45 +02:00
} else {
2017-07-20 16:51:19 +02:00
$sales_sql = " SELECT id_sale, position FROM " . _DB_PREFIX_ . " privatesale WHERE position BETWEEN " . $new_position . ' AND ' . ( $position_initial - 1 ) . ' AND lock_position = 0 ORDER BY position DESC' ;
2016-03-16 15:47:25 +01:00
$sales = Db :: getInstance () -> ExecuteS ( $sales_sql );
foreach ( $sales as $key => $sale ){
2017-07-20 16:51:19 +02:00
$pos = ( int ) $sale [ 'position' ] + 1 ;
while ( in_array ( $pos , $lock_positions )){
$pos = $pos + 1 ;
2017-07-20 11:37:45 +02:00
}
2017-07-20 16:51:19 +02:00
$_positions [( int ) $sale [ 'id_sale' ]] = array (
'initial' => ( int ) $sale [ 'position' ],
'new' => $pos ,
);
2017-07-20 11:37:45 +02:00
2017-07-20 16:51:19 +02:00
//Db::getInstance()->ExecuteS( 'UPDATE '._DB_PREFIX_.'privatesale SET position = '.$position.' WHERE id_sale = '. $sale['id_sale']);
2016-01-04 12:48:08 +01:00
}
}
2017-07-20 16:51:19 +02:00
foreach ( $_positions as $id => $value ) {
Db :: getInstance () -> ExecuteS ( 'UPDATE ' . _DB_PREFIX_ . 'privatesale SET position = ' . ( int ) $value [ 'new' ] . ' WHERE id_sale = ' . $id );
}
2016-01-04 12:48:08 +01:00
Db :: getInstance () -> ExecuteS ( 'UPDATE ' . _DB_PREFIX_ . 'privatesale SET position = ' . ( int ) $new_position . ' WHERE id_sale = ' . $id_sale );
2016-03-16 15:47:25 +01:00
2016-01-04 12:48:08 +01:00
die ();
}
if ( isset ( $_GET [ 'updatePositionImg' ])){
$id_image = str_replace ( " image_ " , " " , $_GET [ 'id_image' ]);
$position = $_GET [ 'position' ];
$sql = '
2016-03-16 15:47:25 +01:00
SELECT
2016-01-04 12:48:08 +01:00
`position` ,
`id_product`
2016-03-16 15:47:25 +01:00
FROM '._DB_PREFIX_.' image
WHERE
2016-01-04 12:48:08 +01:00
`id_image` = ' . ( int ) $id_image ;
$position_initial = Db :: getInstance () -> getRow ( $sql );
$id_product = $position_initial [ 'id_product' ];
$new_position = $position_initial [ 'position' ] + $position ;
2016-03-16 15:47:25 +01:00
2016-01-04 12:48:08 +01:00
// fix bug duplicate entry
Db :: getInstance () -> execute ( '
UPDATE `'._DB_PREFIX_.'image`
SET `position` = 0
WHERE `id_image` = ' . ( int ) $id_image
);
if ( $position > 0 ) {
Db :: getInstance () -> execute ( '
UPDATE `'._DB_PREFIX_.'image`
2016-03-16 15:47:25 +01:00
SET `position` = ( `position` - 1 )
2016-01-04 12:48:08 +01:00
WHERE `id_product` = '. (int)$id_product.'
AND `position` BETWEEN '.(int)$position_initial[' position '].' AND ' . ( int ) $new_position
);
} else {
// fix bug duplicate entry
foreach ( Db :: getInstance () -> ExecuteS ( '
2016-03-16 15:47:25 +01:00
SELECT
2016-01-04 12:48:08 +01:00
`id_image`
2016-03-16 15:47:25 +01:00
FROM `'._DB_PREFIX_.'image`
2016-01-04 12:48:08 +01:00
WHERE `id_product` = '. (int)$id_product .'
AND `position` BETWEEN '.(int)$new_position.' AND '.(int)$position_initial[' position '].'
ORDER BY position DESC ' ) as $key => $value ) {
Db :: getInstance () -> execute ( '
UPDATE `'._DB_PREFIX_.'image`
SET `position` = ( `position` + 1 )
WHERE `id_image` = '. (int)$value[' id_image ' ]
);
}
}
Db :: getInstance () -> execute ( '
UPDATE `'._DB_PREFIX_.'image`
SET `position` = '.(int)$new_position.'
WHERE `id_image` = ' . ( int ) $id_image
);
2016-03-16 15:47:25 +01:00
2016-01-04 12:48:08 +01:00
die ();
}
if ( isset ( $_GET [ 'getStats' ])) {
$id_sale = Tools :: getValue ( 'id_sale' );
if ( Validate :: isLoadedObject ( $sale = new Sale ( $id_sale ))) {
$exports = array ();
$sold_products = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT DISTINCT `product_id` , `product_attribute_id`
FROM `'._DB_PREFIX_.'order_detail` d
INNER JOIN `'._DB_PREFIX_.'orders` o ON d . id_order = o . id_order
WHERE `product_id` IN (
SELECT `id_product`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_sale` = '.(int) $sale->id.'
)
AND o . valid = 1
' ) as $row ) {
$sold_products [] = ( int ) $row [ 'product_id' ] . '-' . ( int ) $row [ 'product_attribute_id' ];
}
$detail_sales = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `product_id` , `product_attribute_id` , SUM ( `product_quantity` ) AS `quantity`
FROM `'._DB_PREFIX_.'order_detail` d
INNER JOIN `'._DB_PREFIX_.'orders` o ON o . id_order = d . id_order
WHERE `product_id` IN (
SELECT `id_product`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_sale` = '.(int) $sale->id.'
)
AND o . valid = 1
GROUP BY `product_id` , `product_attribute_id`
' ) as $row ) {
$detail_sales [( int ) $row [ 'product_id' ] . '-' . ( int ) $row [ 'product_attribute_id' ]] = ( int ) $row [ 'quantity' ];
}
// get les produits avec attributs
$query = Db :: getInstance () -> ExecuteS ( '
SELECT a . `id_product_attribute` , a . `id_product` , a . `quantity` , p . `reference` , pl . `name`
FROM `'._DB_PREFIX_.'product_attribute` a
LEFT JOIN `'._DB_PREFIX_.'product` p
ON p . `id_product` = a . `id_product`
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON p . `id_product` = pl . `id_product` AND id_lang = '.(int)$cookie->id_lang.'
WHERE a . `id_product` IN (
SELECT `id_product`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_sale` = '.(int) $sale->id.'
)
AND p . `active` = 1
GROUP BY a . `id_product_attribute`
' );
$id_attributes = array ();
foreach ( $query as $row ) {
if ( in_array (( int ) $row [ 'id_product' ] . '-' . ( int ) $row [ 'id_product_attribute' ], $sold_products )) {
$stock_actual = $row [ 'quantity' ];
$stock_sales = $detail_sales [( int ) $row [ 'id_product' ] . '-' . ( int ) $row [ 'id_product_attribute' ]];
$stock_initial = ( int ) $stock_actual + ( int ) $stock_sales ;
$percent_sale = (( int ) $stock_sales * 100 ) / ( int ) $stock_initial ;
if ( $stock_actual == 0
|| $percent_sale > 85 ) {
$exports [] = [
'id_product' => $row [ 'id_product' ] . '-' . ( int ) $row [ 'id_product_attribute' ],
2016-03-16 15:47:25 +01:00
'name' => $row [ 'name' ],
2016-01-04 12:48:08 +01:00
'reference' => $row [ 'reference' ],
'quantity' => $stock_actual ,
'quantity_sale' => $stock_sales ,
'percent_sale' => round (( 100 - $percent_sale ), 2 ),
2016-03-16 15:47:25 +01:00
];
2016-01-04 12:48:08 +01:00
}
}
$id_attributes [] = ( int ) $row [ 'id_product' ];
}
// get les produits sans attributs
$query_whitout_attributes = Db :: getInstance () -> ExecuteS ( '
SELECT p . `quantity` , p . `id_product` , pl . `name` , p . `reference`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
ON p . `id_product` = pl . `id_product` AND id_lang = '.(int)$cookie->id_lang.'
WHERE p . `id_product` IN (
SELECT `id_product`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_sale` = '.(int) $sale->id.'
)
'.((count($id_attributes) > 0)? ' AND p . `id_product` NOT IN ( '.implode(' , ', $id_attributes).' ) ': ' ').'
GROUP BY p . `id_product`
' );
foreach ( $query_whitout_attributes as $row ) {
if ( in_array (( int ) $row [ 'id_product' ] . '-0' , $sold_products )) {
2016-03-16 15:47:25 +01:00
2016-01-04 12:48:08 +01:00
$stock_actual = $row [ 'quantity' ];
$stock_sales = $detail_sales [( int ) $row [ 'id_product' ] . '-0' ];
$stock_initial = ( int ) $stock_actual + ( int ) $stock_sales ;
$percent_sale = (( int ) $stock_sales * 100 ) / ( int ) $stock_initial ;
if ( $stock_actual == 0
|| $percent_sale > 85 ) {
$exports [] = [
'id_product' => $row [ 'id_product' ],
'name' => $row [ 'name' ],
'reference' => $row [ 'reference' ],
'quantity' => $stock_actual ,
'quantity_sale' => $stock_sales ,
'percent_sale' => round (( 100 - $percent_sale ), 2 ),
];
}
}
}
$result = '' ;
if ( ! empty ( $exports )) {
$result .= '
< tr class = " details_sale_'.(int) $sale->id .' " >
< td colspan = " 15 " >
< table style = " width:100%; font-size: 13px; " >
< tr >
< th > Image </ th >
< th > Référence </ th >
< th > Nom du produit </ th >
< th > Quantité vendue </ th >
< th > Quantité restante </ th >
< th >% vendu </ th >
</ tr > ' ;
foreach ( $exports as $key => $product ) {
$id_image = Product :: getCover ( $product [ 'id_product' ]);
$link = new Link ();
if ( $id_image ) {
$href = $link -> getImageLink ( 'image' , $id_image [ 'id_image' ], 'small' );
}
$result .= '
< tr >
< td >< img src = " '. $href .' " /></ td >
< td > '.$product[' reference '].' </ td >
< td > '.$product[' name '].' </ td >
< td > '.$product[' quantity_sale '].' </ td >
< td > '.$product[' quantity '].' </ td >
< td > '.(($product[' percent_sale '] == 0) ? ' 100 ' : (100 - $product[' percent_sale '])).' %</ td >
</ tr >
' ;
}
$result .= ' </ table >
</ td >
</ tr >
' ;
}
echo $result ;
die ;
2016-03-16 15:47:25 +01:00
}
2016-01-04 12:48:08 +01:00
}