2016-01-04 12:49:26 +01:00
< ? php
/*
* To change this template , choose Tools | Templates
* and open the template in the editor .
*/
include_once ( _PS_ROOT_DIR_ . '/modules/privatesales_logistique/classes/OrderForm.php' );
include_once ( _PS_ROOT_DIR_ . '/modules/privatesales_logistique/classes/DateManager.php' );
include_once ( _PS_ROOT_DIR_ . '/modules/privatesales_logistique/classes/MakeStats.php' );
include_once ( _PS_ROOT_DIR_ . '/modules/privatesales_logistique/classes/SaleStats.php' );
2017-06-14 17:03:25 +02:00
include_once ( PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php' );
2016-01-04 12:49:26 +01:00
/**
* Description of AdminPrivateSalesLogistique
*
* @ author Pierre
*/
class AdminPrivateSalesLogistique extends AdminTab {
2016-09-14 17:42:08 +02:00
2016-01-04 12:49:26 +01:00
public $category ;
public $html = '' ;
2016-09-14 17:42:08 +02:00
public function __construct ()
2016-01-04 12:49:26 +01:00
{
parent :: __construct ();
}
2016-09-14 17:42:08 +02:00
public function _postProcess ()
2016-01-04 12:49:26 +01:00
{
2016-09-14 17:42:08 +02:00
if ( Tools :: isSubmit ( 'changeCategory' ))
2016-01-04 12:49:26 +01:00
{
$this -> category = new Category ( Tools :: getValue ( " id " ));
}
if ( Tools :: getValue ( " actionform " ) == 'delete' )
{
if ( Tools :: getValue ( 'idorderform' ) !== false && Validate :: isLoadedObject ( $order_form = new OrderForm (( int ) Tools :: getValue ( 'idorderform' ))))
{
if ( $order_form -> delete ())
echo 'Suppression effectuée' ;
else
echo 'Erreur durant la suppression' ;
}
else
echo 'Mauvais id de bon de commande' ;
exit ;
}
2016-05-18 16:14:24 +02:00
if ( Tools :: getValue ( " action " ) == 'getSaleExport' ) {
$this -> getSaleExport ();
}
2016-09-14 17:42:08 +02:00
if ( Tools :: isSubmit ( 'submitExport' ))
{
$id_lang = Tools :: getValue ( 'export_id_lang' , $cookie -> id_lang );
if ( $id_category = ( int ) Tools :: getValue ( 'export_category' )) {
2016-09-15 11:14:09 +02:00
$this -> getSaleExport ( $id_category , $id_lang );
2016-09-14 17:42:08 +02:00
} elseif ( Tools :: getValue ( 'date_start' ) && Tools :: getValue ( 'date_end' )) {
2016-09-15 11:14:09 +02:00
2016-09-14 17:42:08 +02:00
$date_start = Tools :: getValue ( 'date_start' );
$date_end = Tools :: getValue ( 'date_end' );
2016-09-15 11:14:09 +02:00
$this -> getSaleExportsByDate ( $date_start , $date_end , $id_lang );
} else {
2017-06-14 17:03:25 +02:00
HelperFormBootstrap :: displayErrors ( $this -> l ( 'Vous devez choisir une vente ou une période' ));
2016-09-14 17:42:08 +02:00
}
}
2016-01-04 12:49:26 +01:00
}
2017-06-14 17:03:25 +02:00
public function _displayHeader ( $helperForm )
2016-01-04 12:49:26 +01:00
{
global $currentIndex ;
2017-06-14 17:03:25 +02:00
$helperForm -> _select2 = true ;
$helperForm -> _dateTimePicker = true ;
$helperForm -> _inputSwitch = true ;
$helperForm -> _inputMask = true ;
$helperForm -> _css .= '
#content .bootstrap-datetimepicker-widget tr th {
border - radius : 0 px ! important ;
}
' ;
$this -> html .= $helperForm -> renderStyle ();
$helperForm -> _js .= '
< script type = " text/javascript " >
2016-01-04 12:49:26 +01:00
jQuery ( function () {
2016-09-14 17:42:08 +02:00
$ ( " #category " ) . change ( function (){
2016-01-04 12:49:26 +01:00
current_location = " '. $currentIndex .'&token='.Tools::getAdminTokenLite('AdminPrivateSalesLogistique').' " ;
document . location . href = current_location + " &changeCategory&id= " + $ ( " #category " ) . val ();
});
});
2016-09-14 17:42:08 +02:00
2016-01-04 12:49:26 +01:00
$ ( document ) . ready ( function (){
2017-06-14 17:03:25 +02:00
$ ( " #date_start " ) . inputmask ( " 9999-99-99 " );
$ ( " #date_end " ) . inputmask ( " 9999-99-99 " );
$ ( " #hasDatepicker_1 " ) . datetimepicker ({
format : " DD/MM/YYYY hh:mm:ss " ,
widgetPositioning : {
horizontal : " auto " ,
vertical : " bottom "
},
locale : " fr "
2016-01-04 12:49:26 +01:00
});
2017-06-14 17:03:25 +02:00
$ ( " #hasDatepicker_2 " ) . datetimepicker ({
format : " DD/MM/YYYY hh:mm:ss " ,
widgetPositioning : {
horizontal : " auto " ,
vertical : " bottom "
},
locale : " fr "
});
if ( $ ( " #hidden_category " ) . length > 0 ){
$ ( " #sale_name " ) . text ( $ ( " #category option[value= " + $ ( " #hidden_category " ) . val () + " ] " ) . text ());
}
2016-01-04 12:49:26 +01:00
$ ( " #exportorderform " ) . click ( function (){
var export_last = $ ( " #export_last " ) . is ( " :checked " ), req ;
2016-09-14 17:42:08 +02:00
2017-06-14 17:03:25 +02:00
req = " &id= " + $ ( " #hidden_category " ) . val ();
2016-01-04 12:49:26 +01:00
if ( export_last ) {
req += " &last "
}
else {
var from = $ ( " #hasDatepicker_1 " ) . val ();
var to = $ ( " #hasDatepicker_2 " ) . val ();
req += " &from= " + from + " &to= " + to ;
}
2016-09-14 17:42:08 +02:00
2017-06-14 17:03:25 +02:00
var type = $ ( " #export_form select[name=export_type] " ) . val ();
2016-01-04 12:49:26 +01:00
2016-05-18 16:14:24 +02:00
if ( type == 1 || type == 2 || type == 4 ) {
2016-01-04 12:49:26 +01:00
req += " &type= " + type ;
2017-06-14 17:03:25 +02:00
req += " &lang= " + $ ( " select[name=lang] " ) . val ();
2016-01-04 12:49:26 +01:00
$ ( this )
. attr ( " href " , " ../modules/privatesales_logistique/exportOrderForm.php?action=getOrderForm " + req )
. attr ( " target " , " _blank " );
return true ;
2016-05-18 16:14:24 +02:00
} else if ( type == 5 ) {
req += " &type= " + type ;
2017-06-14 17:03:25 +02:00
req += " &lang= " + $ ( " select[name=lang] " ) . val ();
2016-05-18 17:07:19 +02:00
var url_dest = " '. $currentIndex .'&token='.Tools::getAdminTokenLite('AdminPrivateSalesLogistique').'&changeCategory&action=getSaleExport " ;
2016-05-18 16:14:24 +02:00
$ ( this ) . attr ( " href " , url_dest + req );
console . log ( $ ( this ) . attr ( " href " ));
return true ;
2016-01-04 12:49:26 +01:00
} else {
var from = $ ( " #hasDatepicker_1 " ) . val ();
var to = $ ( " #hasDatepicker_2 " ) . val ();
req += " &from= " + from + " &to= " + to ;
req += " &type= " + type ;
var url_dest = " '. $currentIndex .'&token='.Tools::getAdminTokenLite('AdminPrivateSalesLogistique').'&action=getStats " ;
$ ( this )
. attr ( " href " , url_dest + req )
. attr ( " target " , " _blank " );
return true ;
}
});
});
</ script > ' ;
}
2017-06-14 17:03:25 +02:00
public function _displayAfterContent ( $helperForm , $option_sales , $option_select_langs )
2016-09-14 17:42:08 +02:00
{
global $cookie ;
$this -> html .= '
2017-06-14 17:03:25 +02:00
< div class = " col-md-12 " >
< div class = " panel " >
< div class = " panel-title " >
< h2 >< span class = " text-rose anticon anticon-upload " ></ span > '.$this->l(' Export ').' </ h2 >
< div class = " clearfix " ></ div >
2016-09-14 17:42:08 +02:00
</ div >
2017-06-14 17:03:25 +02:00
< div class = " panel-content " >
< form action = " '.Tools::safeOutput( $_SERVER['REQUEST_URI'] ).' " method = " post " enctype = " multipart/form-data " >
< br >
< div class = " col-md-5 " > ' ;
$input = array (
'type' => 'select2' ,
'name' => 'export_category' ,
'id' => 'export_category' ,
'label' => $this -> l ( 'Select a category to export:' ),
'label-class' => 'col-md-12' ,
'input-class' => 'col-md-12' ,
'select-class' => 'col-md-12' ,
'options' => $option_sales
);
$this -> html .= $helperForm -> generateInput ( $input ) .
'</div>' ;
$this -> html .= ' < div class = " col-md-2 text-center " >< span class = " lateral-delimiter " ></ span ></ div >
< div class = " col-md-5 " > ' ;
$input = array (
'type' => 'simpleDate' ,
'period' => true ,
'class-from' => 'col-md-6' ,
'class-to' => 'col-md-6' ,
'label' => 'Du :' ,
'label-to' => 'Au :' ,
'id' => 'date_start' ,
'id-to' => 'date_end' ,
'name' => 'date_start' ,
'name-to' => 'date_end' ,
'before' => '<span class="glyphicon glyphicon-calendar"></span>' ,
'before-to' => '<span class="glyphicon glyphicon-calendar"></span>' ,
);
$this -> html .= $helperForm -> generateInput ( $input ) .
' < p class = " text-center help-block " > Format : AAAA - MM - JJ </ p >
</ div >
< div class = " clearfix " ></ div >
< br >
< div class = " col-md-4 col-md-offset-4 text-center " > ' ;
$input = array (
'type' => 'select' ,
'name' => 'export_id_lang' ,
'id' => 'export_id_lang' ,
'label' => $this -> l ( 'Select a language:' ),
'label-class' => 'col-md-12 text-center' ,
'input-class' => 'col-md-12' ,
'options' => $option_select_langs
);
$this -> html .= $helperForm -> generateInput ( $input ) .
' </ div >
< div class = " clearfix " ></ div > ' ;
2017-06-15 16:42:13 +02:00
$this -> html .= '
2017-06-14 17:03:25 +02:00
< div class = " clearfix " ></ div >
< div class = " ln_solid " ></ div >
< div class = " form-group text-right " >
< button type = " submit " class = " btn btn-primary " name = " submitExport " > '.$this->l(' Upload ').' </ button >
</ div >
</ form >
2016-09-14 17:42:08 +02:00
</ div >
2017-06-14 17:03:25 +02:00
</ div >
< div class = " clearfix " ></ div >
</ div > ' ;
2016-09-14 17:42:08 +02:00
}
2017-06-14 17:03:25 +02:00
public function _displayContent ( $helperForm , $option_sales )
2016-01-04 12:49:26 +01:00
{
global $cookie ;
2017-06-14 17:03:25 +02:00
$this -> html .= '
< div class = " col-md-12 " >
< div class = " panel " >
< div class = " panel-title " >
< h2 >< span class = " text-rose anticon anticon-wrench " ></ span > '.$this->l(' Inventory Tracking ').' </ h2 >
< div class = " clearfix " ></ div >
</ div >
< div class = " panel-content " >
< div class = " row " >
< div class = " col-md-6 " > ' ;
if ( count ( $option_sales ) > 1 ) {
$input = array (
'type' => 'select2' ,
'name' => 'category' ,
'id' => 'category' ,
'label' => $this -> l ( 'Ventes :' ),
'label-class' => 'text-left col-md-12' ,
'input-class' => 'col-md-12' ,
'select-class' => 'col-md-12' ,
'options' => $option_sales
);
$this -> html .= $helperForm -> generateInput ( $input ) .
'<div class="clearfix"></div>' ;
} else {
$this -> html .= '<p>Aucune vente !</p>' ;
}
$this -> html .= ' </ div >
< div class = " col-md-6 form-group text-right " >
< label class = " col-md-12 " style = " opacity:0 " > A </ label >
< button type = " button " class = " btn btn-primary btn-sm " data - toggle = " modal " data - target = " #BDCModal " >
Informations sur le bon de commande
</ button >
</ div >
</ div > ' ;
if ( ! empty ( $this -> category )) {
$this -> html .= $this -> getFormOrderForm ( $this -> category );
}
2016-01-04 12:49:26 +01:00
2017-06-14 17:03:25 +02:00
if ( Tools :: getIsset ( 'action' ) && Tools :: getValue ( 'action' ) == 'getStats' ) {
$this -> html .= $this -> getStatsArray ();
}
2016-01-04 12:49:26 +01:00
2017-06-14 17:03:25 +02:00
$this -> html .= '
</ div >
</ div >
</ div >
< div class = " clearfix " ></ div > ' ;
2016-01-04 12:49:26 +01:00
2017-06-14 17:03:25 +02:00
}
2016-09-14 17:42:08 +02:00
2017-06-14 17:03:25 +02:00
public function display ()
{
global $currentIndex , $cookie ;
2016-01-04 12:49:26 +01:00
2017-06-14 17:03:25 +02:00
$helperForm = new HelperFormBootstrap ();
$option_sales = array ();
$option_sales [] = array (
'value' => 0 ,
'label' => 'Selectionner une vente'
);
$categories = Db :: getInstance () -> ExecuteS ( '
SELECT c . `id_category` , l . `name`
FROM `'._DB_PREFIX_.'category_lang` l
LEFT JOIN `'._DB_PREFIX_.'category` c ON c . `id_category` = l . `id_category`
WHERE l . `id_lang` = '.(int) $cookie->id_lang.'
AND c . `id_parent` = 1
ORDER BY c . id_category DESC
2017-07-19 14:34:05 +02:00
LIMIT 3000
2017-06-14 17:03:25 +02:00
' );
$ids = array ();
foreach ( $categories as $key => $category ) {
$ids [] = ( int ) $category [ 'id_category' ];
2016-01-04 12:49:26 +01:00
}
2017-06-14 17:03:25 +02:00
$extrafields = Category :: getSalesInfosWithDate ( $ids );
2016-09-14 17:42:08 +02:00
2017-06-14 17:03:25 +02:00
foreach ( $categories as $category ) {
$option_sales [] = array (
'value' => $category [ 'id_category' ],
'label' => '#' . $category [ 'id_category' ] . ( isset ( $extrafields [( int ) $category [ 'id_category' ]]) ? ' (' . date ( " d/m/Y " , strtotime ( $extrafields [( int ) $category [ 'id_category' ]][ 'date_start' ])) . ')' : '' ) . ' - ' . $category [ 'name' ] . ( isset ( $extrafields [( int ) $category [ 'id_category' ]]) ? ' - ' . $extrafields [( int ) $category [ 'id_category' ]][ 'sales' ][ 1 ] : '' )
);
2016-01-04 12:49:26 +01:00
}
2017-06-14 17:03:25 +02:00
$option_select_langs = array ();
foreach ( Language :: getLanguages ( false ) as $key => $value ) {
$option_select_langs [ $key ] = array (
'value' => $value [ 'id_lang' ],
'label' => $value [ 'name' ]
);
if ( $value [ 'id_lang' ] == 2 ){
$option_select_langs [ $key ][ 'selected' ] = 1 ;
}
}
//krsort($categories);
2016-01-04 12:49:26 +01:00
$this -> _postProcess ();
2017-06-14 17:03:25 +02:00
$this -> _displayHeader ( $helperForm );
$this -> html .= $this -> getFormOrderFormInfo ();
$this -> _displayContent ( $helperForm , $option_sales );
$this -> _displayAfterContent ( $helperForm , $option_sales , $option_select_langs );
$this -> html .= '<div class="clearfix"></div>'
. ( Tools :: getValue ( 'id' ) ? '<input type="hidden" value="' . Tools :: getValue ( 'id' ) . '" id="hidden_category"/>' : '' )
. $helperForm -> renderScript ();
2016-05-18 16:14:24 +02:00
2016-01-04 12:49:26 +01:00
echo $this -> html ;
}
2016-09-14 17:42:08 +02:00
public function getStatsArray ()
2016-01-04 12:49:26 +01:00
{
global $cookie ;
if ( ! Tools :: getIsset ( 'id' )) {
return false ;
}
2017-06-14 17:03:25 +02:00
$lang_id = Tools :: getValue ( 'lang' , 'fr' );
2016-01-04 12:49:26 +01:00
// GET INFO FOR STAT
$date_from = new DateManager ( Tools :: getValue ( 'from' ));
$date_to = new DateManager ( Tools :: getValue ( 'to' ));
2016-09-14 17:42:08 +02:00
2016-01-04 12:49:26 +01:00
$date_from -> setLangue ( strtoupper ( $lang_id ));
$date_to -> setLangue ( strtoupper ( $lang_id ));
$id_category = Tools :: getValue ( 'id' );
$sale = Sale :: getSaleFromCategory ( $id_category );
$category = new Category ( $id_category , $cookie -> id_lang );
$products = MakeStats :: getProductsByCat ( $id_category );
$arrayProduct = array ();
foreach ( $products as $product )
$array_product [ $product [ 'id_product' ]] = $arrayProduct [ $product [ 'id_product' ]] = new Product ( $product [ 'id_product' ]);
2016-09-14 17:42:08 +02:00
2016-01-04 12:49:26 +01:00
$order_states = explode ( ',' , Configuration :: get ( 'PS_IT_OF_ORDER_STATES' ));
$lines = MakeStats :: getOrdersByIdsProduct ( array_keys ( $arrayProduct ), $order_states , $date_from -> getDate ( 'SQL' ), $date_to -> getDate ( 'SQL' ));
// for stats
$lines_tmp = $lines ;
$lines = MakeStats :: getArrayLines ( $lines );
$stats = new SaleStats ( $sale , $category );
$stats -> loadData ();
$total_sale_product = array ();
$total_bdc_ht = 0 ;
foreach ( $lines_tmp as $key => $order_line ) {
$id_product = $order_line [ 'product_id' ];
$id_product_attribute = $order_line [ 'product_attribute_id' ];
$current_product = $array_product [ $id_product ];
if ( $id_product_attribute != 0 ) {
$combination = new Combination ( $id_product_attribute );
if ( $combination -> wholesale_price == 0 ) {
$wholesale_price = $current_product -> wholesale_price ;
} else {
$wholesale_price = $combination -> wholesale_price ;
}
} else {
$wholesale_price = $current_product -> wholesale_price ;
}
$quantity_to_cmd = $order_line [ 'product_quantity' ] - $order_line [ 'product_quantity_reinjected' ];
$total_sale_ht += $quantity_to_cmd * $wholesale_price ;
if ( ! is_array ( $total_sale_product [( int ) $id_product ]) ){
$total_sale_product [( int ) $id_product ] = array ();
$total_sale_product [( int ) $id_product ][ 'total_ht' ] = 0 ;
$total_sale_product [( int ) $id_product ][ 'quantiy' ] = 0 ;
$total_sale_product [( int ) $id_product ][ 'name' ] = $current_product -> name [ 2 ];
2017-11-15 13:01:03 +01:00
$total_sale_product [( int ) $id_product ][ 'supplier_reference' ] = $current_product -> supplier_reference ;
2016-01-04 12:49:26 +01:00
}
$total_sale_product [( int ) $id_product ][ 'total_ht' ] += ( $wholesale_price * $quantity_to_cmd );
$total_sale_product [( int ) $id_product ][ 'quantiy' ] += $quantity_to_cmd ;
}
$stats -> addToStats ( 'total_bdc_ht' , $total_sale_ht );
$bestsales = MakeStats :: orderMultiArray ( $total_sale_product , 'total_ht' );
$bestsales_extract = array_slice ( $bestsales , 0 , 3 );
$i = 1 ;
2016-09-14 17:42:08 +02:00
foreach ( $bestsales_extract as $key => $bestsalesProduct ) {
2016-01-04 12:49:26 +01:00
$stats -> addToStats ( 'bestsale_' . $i . '_product' , $bestsalesProduct [ 'name' ]);
2017-11-15 13:01:03 +01:00
$stats -> addToStats ( 'bestsale_' . $i . '_ref' , $bestsalesProduct [ 'supplier_reference' ]);
2016-01-04 12:49:26 +01:00
$stats -> addToStats ( 'bestsale_' . $i . '_quantity' , $bestsalesProduct [ 'quantiy' ]);
$stats -> addToStats ( 'bestsale_' . $i . '_ca' , $bestsalesProduct [ 'total_ht' ]);
$i ++ ;
}
$stats -> loadDataForSubCategory ();
$html = '
< style >
. red {
color : red
}
. stats td {
padding : 5 px 10 px ;
}
. stats tr . grey {
background : #f1f1f1
}
. stats tr . blue {
background : #81c4f3;
color : #fff;
}
</ style >
2017-06-14 17:03:25 +02:00
< br >
< div style = " font-size:1em; " >
< h2 class = " text-center text-purple-dark " >< b > '.$this->l(' Rapport Stats ').' Vente : '.$stats->data_stats[' name '].' </ b > </ h2 > ' ;
$html .= '<div class="ln_solid"></div>' ;
2016-01-04 12:49:26 +01:00
$html .= '<table class="stats" style="width:45%; float:left">' ;
$html .= '<tr>' ;
$html .= '<td>' . $stats -> lang [ 'date_start' ] . '</td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'date_start' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<td>' . $stats -> lang [ 'date_end' ] . '</b></td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'date_end' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr class="grey">' ;
$html .= '<td>' . $stats -> lang [ 'duration' ] . '</b></td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'duration' ] . '</td>' ;
$html .= '</tr>' ;
$html .= ' < tr class = " blue " >
< td colspan = 2 > STATS VENTES </ td >
</ tr > ' ;
$html .= '<tr>' ;
$html .= '<td>' . $stats -> lang [ 'nb_ref' ] . '</td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'nb_ref' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<td>' . $stats -> lang [ 'nb_quantity_start' ] . '</td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'nb_quantity_start' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr class="grey">' ;
$html .= '<td>' . $stats -> lang [ 'nb_order_simple' ] . '</td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'nb_order_simple' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr class="grey">' ;
$html .= '<td>' . $stats -> lang [ 'nb_order_multi' ] . '</td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'nb_order_multi' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<td>' . $stats -> lang [ 'nb_order_total' ] . '</td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'nb_order_total' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<td>' . $stats -> lang [ 'taux_multi' ] . '</td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'taux_multi' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<td class="red">' . $stats -> lang [ 'quantity_sale' ] . '</td>' ;
$html .= '<td class="red" align="right">' . $stats -> data_stats [ 'quantity_sale' ] . '</td>' ;
$html .= '<tr class="grey">' ;
$html .= '<td class="red">' . $stats -> lang [ 'percent_sale' ] . '</td>' ;
$html .= '<td class="red" align="right">' . $stats -> data_stats [ 'percent_sale' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<td class="red">' . $stats -> lang [ 'percent_out_of_stock' ] . '</td>' ;
$html .= '<td class="red" align="right">' . $stats -> data_stats [ 'percent_out_of_stock' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<td>' . $stats -> lang [ 'ca_ttc' ] . '</td>' ;
$html .= '<td align="right">' . Tools :: displayPrice ( $stats -> data_stats [ 'ca_ttc' ]) . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<tr>' ;
$html .= '<td class="red">' . $stats -> lang [ 'total_bdc_ht' ] . '</td>' ;
$html .= '<td class="red" align="right">' . Tools :: displayPrice ( $stats -> data_stats [ 'total_bdc_ht' ]) . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr class="grey">' ;
$html .= '<td>' . $stats -> lang [ 'marge' ] . '</td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'marge' ] . '</td>' ;
$html .= '</tr>' ;
$html .= ' < tr class = " blue " >
< td colspan = 2 > BEST SELLERS </ td >
</ tr > ' ;
2016-09-14 17:42:08 +02:00
for ( $i = 1 ; $i <= 3 ; $i ++ ) {
2016-01-04 12:49:26 +01:00
$html .= '<tr class="grey">' ;
$html .= '<td>' . $stats -> lang [ 'bestsale_' . $i . '_product' ] . '</td>' ;
2017-11-15 13:01:03 +01:00
$html .= '<td align="right">' . $stats -> data_stats [ 'bestsale_' . $i . '_product' ] . ' - ' . $stats -> data_stats [ 'bestsale_' . $i . '_ref' ] . '</td>' ;
2016-01-04 12:49:26 +01:00
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<td>' . $stats -> lang [ 'bestsale_' . $i . '_quantity' ] . '</td>' ;
$html .= '<td align="right">' . $stats -> data_stats [ 'bestsale_' . $i . '_quantity' ] . '</td>' ;
$html .= '</tr>' ;
$html .= '<tr>' ;
$html .= '<td>' . $stats -> lang [ 'bestsale_' . $i . '_ca' ] . '</td>' ;
$html .= '<td align="right">' . Tools :: displayPrice ( $stats -> data_stats [ 'bestsale_' . $i . '_ca' ]) . '</td>' ;
$html .= '</tr>' ;
}
$html .= '</table>' ;
$html .= '<table class="stats" style="width:45%; float:right">' ;
$html .= '<tr class="blue">' ;
$html .= '<td colspan="2">SOUS CATEGORIES</td>' ;
$html .= '</tr>' ;
$i = 0 ;
foreach ( $stats -> data_subcategories as $key => $subcategories ) {
foreach ( $subcategories as $key_2 => $subcategory ) {
if ( $i % 4 == 0 ) {
$html .= '<tr class="grey">' ;
} else {
$html .= '<tr>' ;
}
$html .= '<td>' . $stats -> lang [ $key_2 ] . '</td>' ;
if ( $key_2 == 'total_amount_wholesale_price' ) {
$html .= '<td>' . Tools :: displayPrice ( $subcategory ) . '</td>' ;
} else {
$html .= '<td>' . $subcategory . '</td>' ;
}
$html .= '</tr>' ;
$i ++ ;
}
}
$html .= ' </ table >
2017-06-14 17:03:25 +02:00
</ div > ' ;
2016-01-04 12:49:26 +01:00
return $html ;
}
2016-09-14 17:42:08 +02:00
2016-01-04 12:49:26 +01:00
public function getFormOrderForm ( $category )
{
global $link , $cookie ;
require_once ( _PS_ROOT_DIR_ . '/modules/privatesales/Sale.php' );
$sale = Sale :: getSaleFromCategory ( $category -> id );
$date = new DateTime ( $sale -> date_start );
$date_end = new DateTime ( $sale -> date_end );
$date_end -> modify ( '+2 hour' );
$date_first_of_month = $date -> format ( 'd/m/Y H:i:s' );
$date_now = $date_end -> format ( 'd/m/Y H:i:s' );
$export_list = OrderForm :: getByCategorie ( $category -> id );
2017-06-14 17:03:25 +02:00
if ( $export_list && count ( $export_list ) > 0 ) {
2016-01-04 12:49:26 +01:00
$old_date = OrderForm :: getLastByCategory ( $category -> id );
$old_date = new DateManager ( $old_date );
}
$html = '
< script type = " text/javascript " >
$ ( function (){
$ ( document ) . ready ( function (){
$ ( " .deleteOrderForm " ) . click ( function (){
var elem = $ ( this );
var id_order_form = $ ( this ) . attr ( " data-order-form " );
if ( confirm ( " '. $this->l ('Êtes vous sur de vouloir supprimer ce bon de commande ?').' " )) {
var link = " '.html_entity_decode(urldecode( $link->getLanguageLinkAdmin ( $cookie->id_lang ))).'&actionform=delete&idorderform= " + id_order_form ;
var popupnow = window . open ( link , " deleteOrderForm " + id_order_form , " height=500, width=500, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, directories=no, status=no " );
elem . parents ( " tr " ) . first () . remove ();
setTimeout ( function (){
popupnow . close ();
}, 1000 );
}
return false ;
});
});
});
</ script >
2017-06-14 17:03:25 +02:00
< div class = " ln_solid " ></ div >
< h2 class = " text-center text-purple-dark " id = " sale_name " ></ h2 >
< br >
< div class = " row " id = " export_form " >
< div class = " col-md-6 " >
< div class = " form-group row " >
< div class = " col-md-6 " >
< div class = " form-group " >
< label class = " text-left " for = " date_start " > Du :</ label >
< div class = " input-group input-group-sm " >
< div class = " input-group-addon " >< span class = " glyphicon glyphicon-calendar " ></ span ></ div >
< input type = " text " class = " form-control " value = " '. $date_first_of_month .' " name = " date_start " id = " hasDatepicker_1 " placeholder = " " >
</ div >
</ div >
</ div >
< div class = " col-md-6 " >
< div class = " form-group " >
< label class = " text-left " for = " date_end " > Au :</ label >
< div class = " input-group input-group-sm " >
< div class = " input-group-addon " >< span class = " glyphicon glyphicon-calendar " ></ span ></ div >
< input type = " text " class = " form-control " value = " '. $date_now .' " name = " date_end " id = " hasDatepicker_2 " placeholder = " " >
</ div >
</ div >
</ div >
</ div >
' . ( count ( $export_list ) > 0 ?
' < p class = " text-center " > Ou </ p >
< div class = " form-group row " >
< label for = " export_last " class = " col-md-12 text-center " >
< input type = " checkbox " id = " export_last " value = " 1 " > '.$this->l(' Depuis la génération du dernier bon ').' : '.$old_date->getDate(' STR ').'
</ label >
</ div > ':' '
) . '
</ div >
2016-09-14 17:42:08 +02:00
2017-06-14 17:03:25 +02:00
< div class = " col-md-2 " >
< div class = " form-group " >
< label class = " text-left " for = " export_type " > Fichier :</ label >
< select class = " form-control input-sm " name = " export_type " >
< option value = " 1 " > '.$this->l(' Bon de commande ').' </ option >
< option value = " 2 " > '.$this->l(' Etat de la vente ').' </ option >
< option value = " 3 " > '.$this->l(' Stats de la vente ').' </ option >
< option value = " 4 " > '.$this->l(' BDC Logistique ').' </ option >
< option value = " 5 " > '.$this->l(' Exporter la Vente ( ne tient pas compte de la date ) ').' </ option >
</ select >
</ div >
</ div >
2016-09-14 17:42:08 +02:00
2017-06-14 17:03:25 +02:00
< div class = " col-md-2 " >
< div class = " form-group " >
< label class = " text-left " for = " lang " > Langue :</ label >
< select class = " form-control input-sm " name = " lang " >
< option value = " fr " > '.$this->l(' Français ').' </ option >
< option value = " en " > '.$this->l(' Anglais ').' </ option >
</ select >
</ div >
</ div >
2016-09-14 17:42:08 +02:00
2017-06-14 17:03:25 +02:00
< div class = " col-md-2 " >
< div class = " form-group " >
< label style = " opacity:0; " > A :</ label >
< a href = " " class = " btn btn-primary btn-sm " id = " exportorderform " > '.$this->l(' Obtenir le fichier ').' </ a >
</ div >
</ div >
2016-01-04 12:49:26 +01:00
</ div >
2017-06-14 17:03:25 +02:00
< div class = " clearfix " ></ div > ' ;
// <div style="width:450px;float:left;">
// <div>
// <h4>'.$this->l('Date d\'import').'</h4>
// Du <input type="text" value="'.$date_first_of_month.'" size="20" id="hasDatepicker_1" style="text-align:center;">
// <br />
// Au <input type="text" value="'.$date_now.'" size="20" id="hasDatepicker_2" style="text-align:center;">
// '.( count($export_list) > 0 ? '<br />
// Ou
// <br />
// <input type="checkbox" id="export_last" value="1"> '.$this->l('depuis la génération du dernier bon').' : '.$old_date->getDate('STR') : '').'
// <br />
// <h4>'.$this->l('Selection du type de fichier').'</h4>
// <input type="radio" name="export_type" value="1" checked> '.$this->l('Bon de commande').'
// <br />
// <input type="radio" name="export_type" value="2"> '.$this->l('Etat de la vente').'
// <br />
// <input type="radio" name="export_type" value="3"> '.$this->l('Stats de la vente').'
// <br />
// <input type="radio" name="export_type" value="4"> '.$this->l('BDC Logistique').'
// <br />
// <input type="radio" name="export_type" value="5"> '.$this->l('Exporter la Vente (ne tient pas compte de la date)').'
// <h4>'.$this->l('Selection de la langue').'</h4>
// <input type="radio" name="lang" value="fr" checked> '.$this->l('Français').'
// <br />
// <input type="radio" name="lang" value="en"> '.$this->l('Anglais').'
// ';
// $html .= '<br /><br />
// <a href="" class="button" id="exportorderform">'.$this->l('Obtenir le fichier').'</a>
// </div>';
2016-01-04 12:49:26 +01:00
2017-06-14 17:03:25 +02:00
$html .= '
< div class = " ln_solid " ></ div >
< div class = " row " >
< div class = " col-md-12 " > ' ;
if ( $export_list && count ( $export_list ) > 0 ) {
2016-01-04 12:49:26 +01:00
$html .= '
< table class = " table " cellspacing = " 0 " cellpadding = " 0 " >
< thead >< tr >< th > '.$this->l(' ID ').' </ th >< th > '.$this->l(' Date de d\ 'export' ) . '</th><th>' . $this -> l ( 'A partir de' ) . '</th><th>' . $this -> l ( 'Jusqu\'a' ) . '</th><th style="text-align:center;">' . $this -> l ( 'Exporter à nouveau' ) . ' </ th ></ tr ></ thead >
< tbody > ' ;
2017-06-14 17:03:25 +02:00
foreach ( $export_list as $export ){
2016-01-04 12:49:26 +01:00
$html .= '
2017-06-14 17:03:25 +02:00
< tr >
< td > '.$export[' id_order_form '].' </ td >
< td > '.$export[' date_add '].' </ td >
< td > '.$export[' from '].' </ td >< td > '.$export[' to '].' </ td >
< td style = " text-align:center; " > ' ;
// <a href="../modules/privatesales_logistique/exportOrderForm.php?action=getOrderForm&id_exportorderform='.$export['id_order_form'].'&type=1" title="'.$this->l('Exporter le bon de commande').'"><img src="../img/tmp/tab_mini_AdminSuppliers.gif"></a>
$html .= '
< a href = " ../modules/privatesales_logistique/exportOrderForm.php?action=getOrderForm&id_exportorderform='. $export['id_order_form'] .'&type=1&lang=fr " title = " '. $this->l ('Exporter le bon de commande').' FR " > FR < img src = " ../img/admin/delivery.gif " ></ a >
< a href = " ../modules/privatesales_logistique/exportOrderForm.php?action=getOrderForm&id_exportorderform='. $export['id_order_form'] .'&type=1&lang=en " title = " '. $this->l ('Exporter le bon de commande').' EN " > EN < img src = " ../img/admin/delivery.gif " ></ a >
< a href = " # " title = " '. $this->l ('Supprimer cette extraction').' " class = " deleteOrderForm " data - order - form = " '. $export['id_order_form'] .' " >< img src = " /img/admin/delete.gif " ></ a >
</ td >
</ tr > ' ;
}
2016-09-14 17:42:08 +02:00
2016-01-04 12:49:26 +01:00
$html .= ' </ tbody >
</ table > ' ;
2017-06-14 17:03:25 +02:00
} else {
$html .= '<p class="text-center">' . $this -> l ( 'Il n\'y a pas d\'anciens exports de bon de commande' ) . '</p>' ;
2016-01-04 12:49:26 +01:00
}
$html .= '
2017-06-14 17:03:25 +02:00
</ div >
2016-01-04 12:49:26 +01:00
</ div >
2017-06-14 17:03:25 +02:00
< div class = " clearfix " ></ div > ' ;
2016-01-04 12:49:26 +01:00
return $html ;
}
2016-09-14 17:42:08 +02:00
public function getSaleExportsByDate ( $date_start , $date_end , $id_lang )
{
2017-01-18 11:32:54 +01:00
$order_states = explode ( ',' , Configuration :: get ( 'PS_IT_OF_ORDER_STATES' ));
2016-09-14 17:42:08 +02:00
$ids = Db :: getInstance () -> ExecuteS ( '
SELECT c . id_category
FROM `'._DB_PREFIX_.'privatesale` p
LEFT JOIN `'._DB_PREFIX_.'privatesale_category` c ON c . id_sale = p . id_sale
2016-09-15 11:14:09 +02:00
WHERE date_start BETWEEN " '. $date_start .' 00:00:00 " AND " '. $date_end .' 23:59:59 "
2016-09-14 17:42:08 +02:00
ORDER BY c . id_sale DESC
' );
$products = array ();
foreach ( $ids as $id ) {
$id_category = $id [ 'id_category' ];
$sc = new Category ( $id_category , $id_lang );
foreach ( $sc -> getProductsWs () as $p ) {
$products [] = $p [ 'id' ];
}
}
$products = array_unique ( $products );
if ( count ( $products ) > 20000 ){
2016-09-15 11:14:09 +02:00
$this -> html .= '<p class="error">Choisir une plage moins grande. <br /> Export > 20000 produits</p>' ;
exit ;
2016-09-14 17:42:08 +02:00
};
$fname = date ( " Ymd " , strtotime ( $date_start )) . '-' . date ( " Ymd " , strtotime ( $date_end )) . '.csv' ;
foreach ( glob ( dirname ( __FILE__ ) . '/*.csv' ) as $filename ) {
if ( $fname == $filename ) {
unlink ( $filename );
}
}
$f = fopen ( dirname ( __FILE__ ) . '/' . $fname , 'w' );
// uft8 sans bom pour accent
$BOM = " \xEF \xBB \xBF " ; // UTF-8 BOM
fwrite ( $f , $BOM ); // NEW LINE
fputcsv ( $f , array (
'supplier_reference' ,
2017-01-31 15:32:46 +01:00
'ean13' ,
2016-09-14 17:42:08 +02:00
'id_product' ,
'id_product_attribute' ,
'position' ,
'poids' ,
2017-01-19 09:59:58 +01:00
'stock_initial' ,
2017-01-20 09:42:39 +01:00
'quantity_sold' ,
'quantity' ,
2016-09-14 17:42:08 +02:00
'product_name' ,
'combination' ,
'NC8' ,
'Pays de fabrication' ,
// 'location',
// 'brand',
'public_price_wt' ,
'price_wt' ,
'wholesale_price' ,
'BDC HT' ,
// 'active',
'description_short' ,
'bon_a_savoir' ,
'plus' ,
'videos' ,
'livraison' ,
'images' ,
'categories' ,
'sous-categories' ,
'sous-sous-categories' ,
// 'categories_title',
), ';' , '"' );
foreach ( $products as $product ) {
$p = new Product (( int ) $product , $id_lang );
if ( ! Validate :: isLoadedObject ( $p )) {
$this -> html .= '<p class="error">Erreur produit: ' . serialize ( $product ) . ' ce produit ne figure pas dans l\'export</p>' ;
} else {
$position = Db :: getInstance () -> getValue ( '
SELECT `position`
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_category` = '.(int) $p->id_category_default.'
AND id_product = '. (int) $p->id . '
' );
$p -> position = $position ;
$categories = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_category`
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_product` = '.(int) $p->id.'
' ) as $cat ) {
$categories [] = ( int ) $cat [ 'id_category' ];
}
sort ( $categories );
$categories_title = array ();
foreach ( $categories as $category ) {
$title = Db :: getInstance () -> getValue ( '
SELECT `name`
FROM `'._DB_PREFIX_.'category_lang`
WHERE `id_category` = '.(int) $category.'
AND id_lang = '. $id_lang . '
' );
$categories_title [] = $title ;
}
$categorie_0 = '' ;
$categorie_1 = '' ;
$categorie_2 = '' ;
foreach ( $categories as $key => $cat ) {
if ( $key == 0 ) {
$categorie_0 = $categories_title [ $cat ];
} elseif ( $key == 1 ) {
$categorie_1 = $categories_title [ $cat ];
} elseif ( $key == 2 ) {
$categorie_2 = $categories_title [ $cat ];
}
}
$combinations = array ();
foreach ( $p -> getAttributeCombinaisons ( $id_lang ) as $combi ) {
if ( ! isset ( $combinations [ $combi [ 'id_product_attribute' ]])) {
$combinations [ $combi [ 'id_product_attribute' ]] = array (
'qty' => $combi [ 'quantity' ],
'name' => array ( $combi [ 'attribute_name' ]),
'ean13' => $combi [ 'ean13' ],
'location' => empty ( $combi [ 'location' ]) ? $p -> location : $combi [ 'location' ],
'brand' => $p -> manufacturer_name ,
'supplier_reference' => empty ( $combi [ 'supplier_reference' ]) ? $p -> supplier_reference : $combi [ 'supplier_reference' ],
);
} else {
$combinations [ $combi [ 'id_product_attribute' ]][ 'name' ][] = $combi [ 'attribute_name' ];
}
}
$images = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT i . `id_image` , l . `legend`
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'image_lang` l
ON l . `id_image` = i . `id_image`
WHERE l . `id_lang` = '.(int) $id_lang.'
AND i . `id_product` = '.(int) $p->id.'
ORDER BY i . `position`
' ) as $img ) {
$link_image = str_split ( $img [ 'id_image' ]);
2017-09-07 11:36:48 +02:00
$images [] = 'https://static.bebeboutik.com/img/p/' . implode ( '/' , $link_image ) . '/' . $img [ 'id_image' ] . '.jpg' ;
2016-09-14 17:42:08 +02:00
}
if ( count ( $combinations ) > 0 ) {
foreach ( $combinations as $k => $v ) {
$c_images = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT i . `id_image` , l . `legend`
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'image_lang` l
ON l . `id_image` = i . `id_image`
LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` a
ON a . `id_image` = i . `id_image`
WHERE l . `id_lang` = '.(int) $id_lang.'
AND a . `id_product_attribute` = '.(int) $k.'
' ) as $img ) {
$link_image = str_split ( $img [ 'id_image' ]);
2017-09-07 11:36:48 +02:00
$c_images [] = 'https://static.bebeboutik.com/img/p/' . implode ( '/' , $link_image ) . '/' . $img [ 'id_image' ] . '.jpg' ;
2016-09-14 17:42:08 +02:00
// $c_images[] = 'http://static.bebeboutik.com/'.(int) $p->id.'-'.$img['id_image'].'.jpg';
}
$names = array_unique ( $v [ 'name' ]);
sort ( $names , SORT_STRING );
$quantity_sold = ( int ) Db :: getInstance () -> getValue ( '
2017-01-18 11:32:54 +01:00
SELECT SUM ( d . `product_quantity` - d . `product_quantity_reinjected` )
2016-09-14 17:42:08 +02:00
FROM `'._DB_PREFIX_.'order_detail` d
2017-01-18 11:32:54 +01:00
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o . `id_order` = d . `id_order`
2016-09-15 11:14:09 +02:00
WHERE d . `product_id` = '.(int) $p->id.'
2016-09-14 17:42:08 +02:00
AND d . `product_attribute_id` = '.(int) $k.'
2017-01-18 11:32:54 +01:00
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 ).' " )
2016-09-14 17:42:08 +02:00
' );
2017-01-18 11:32:54 +01:00
// $quantity_sold = (int) Db::getInstance()->getValue('
// SELECT SUM(d.`product_quantity`)
// FROM `'._DB_PREFIX_.'order_detail` d
// LEFT JOIN `'._DB_PREFIX_.'orders` o
// ON o.`id_order` = d.`id_order`
// LEFT JOIN `'._DB_PREFIX_.'order_history` h
// ON h.`id_order` = d.`id_order`
// WHERE d.`product_id` = '.(int) $p->id.'
// AND d.`product_attribute_id` = '.(int) $k.'
// AND h.`id_order_state` = 2
// ');
2016-09-14 17:42:08 +02:00
$customs = Db :: getInstance () -> getRow ( '
SELECT `nc8` , `id_country`
FROM `'._DB_PREFIX_.'product_customs`
WHERE `id_product` = ' . ( int ) $p -> id
);
fputcsv ( $f , array (
$v [ 'supplier_reference' ],
2017-01-31 15:32:46 +01:00
$v [ 'ean13' ],
2016-09-14 17:42:08 +02:00
$p -> id ,
$k ,
$p -> position ,
str_replace ( '.' , ',' , $p -> weight ),
2017-01-19 09:59:58 +01:00
( $v [ 'qty' ] + $quantity_sold ),
2017-01-20 09:42:39 +01:00
$quantity_sold ,
$v [ 'qty' ],
2016-09-14 17:42:08 +02:00
$p -> name [ $id_lang ],
implode ( ' - ' , $names ),
$customs [ 'nc8' ],
$customs [ 'id_country' ],
// $v['location'],
// $v['brand'],
str_replace ( '.' , ',' , $p -> getPrice ( TRUE , ( int ) $k , 2 , NULL , FALSE , FALSE )),
str_replace ( '.' , ',' , $p -> getPrice ( TRUE , ( int ) $k , 2 )),
str_replace ( '.' , ',' , Tools :: ps_round ( $p -> wholesale_price , 2 )),
str_replace ( '.' , ',' , Tools :: ps_round (( $quantity_sold * $p -> wholesale_price ), 2 )),
// $p->active,
$p -> description_short [ $id_lang ],
$p -> description [ $id_lang ],
$p -> description_more [ $id_lang ],
$p -> videos [ $id_lang ],
$p -> description_delivery [ $id_lang ],
count ( $c_images ) > 0 ? implode ( ', ' , $c_images ) : implode ( ', ' , $images ),
$categorie_0 ,
$categorie_1 ,
$categorie_2 ,
// implode(', ', $categories),
// implode(', ', $categories_title),
), ';' , '"' );
}
} else {
$quantity_sold = ( int ) Db :: getInstance () -> getValue ( '
2017-01-18 11:32:54 +01:00
SELECT SUM ( d . `product_quantity` - d . `product_quantity_reinjected` )
2016-09-14 17:42:08 +02:00
FROM `'._DB_PREFIX_.'order_detail` d
2017-01-18 11:32:54 +01:00
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o . `id_order` = d . `id_order`
2016-09-14 17:42:08 +02:00
WHERE d . `product_id` = '.(int) $p->id.'
2017-01-18 11:32:54 +01:00
AND d . `product_attribute_id` = 0
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 ).' " )
2016-09-14 17:42:08 +02:00
' );
2017-01-18 11:32:54 +01:00
// $quantity_sold = (int) Db::getInstance()->getValue('
// SELECT SUM(d.`product_quantity`)
// FROM `'._DB_PREFIX_.'order_detail` d
// LEFT JOIN `'._DB_PREFIX_.'orders` o
// ON o.`id_order` = d.`id_order`
// LEFT JOIN `'._DB_PREFIX_.'order_history` h
// ON h.`id_order` = d.`id_order`
// WHERE d.`product_id` = '.(int) $p->id.'
// AND h.`id_order_state` = 2
// ');
2016-09-14 17:42:08 +02:00
$customs = Db :: getInstance () -> getRow ( '
SELECT `nc8` , `id_country`
FROM `'._DB_PREFIX_.'product_customs`
WHERE `id_product` = ' . ( int ) $p -> id
);
fputcsv ( $f , array (
$p -> supplier_reference ,
2017-01-31 15:32:46 +01:00
$p -> ean13 ,
2016-09-14 17:42:08 +02:00
$p -> id ,
0 ,
$p -> position ,
str_replace ( '.' , ',' , $p -> weight ),
2017-01-19 09:59:58 +01:00
( $p -> quantity + $quantity_sold ),
2017-01-20 09:42:39 +01:00
$quantity_sold ,
$p -> quantity ,
2016-09-14 17:42:08 +02:00
$p -> name [ $id_lang ],
'' ,
$customs [ 'nc8' ],
$customs [ 'id_country' ],
// $p->location,
// $p->manufacturer_name,
str_replace ( '.' , ',' , $p -> getPrice ( TRUE , NULL , 2 , NULL , FALSE , FALSE )),
str_replace ( '.' , ',' , $p -> getPrice ( TRUE , NULL , 2 )),
str_replace ( '.' , ',' , Tools :: ps_round ( $p -> wholesale_price , 2 )),
str_replace ( '.' , ',' , Tools :: ps_round (( $quantity_sold * $p -> wholesale_price ), 2 )),
// $p->active,
$p -> description_short [ $id_lang ],
$p -> description [ $id_lang ],
$p -> description_more [ $id_lang ],
$p -> videos [ $id_lang ],
$p -> description_delivery [ $id_lang ],
implode ( ', ' , $images ),
$categorie_0 ,
$categorie_1 ,
$categorie_2 ,
// implode(', ', $categories),
// implode(', ', $categories_title),
), ';' , '"' );
}
}
}
fclose ( $f );
$this -> html .= '<p class="conf">' . $this -> l ( 'Export complete.' ) . ' <a onclick="window.open(this.href); return false;" href="http://' . $_SERVER [ 'HTTP_HOST' ] . __PS_BASE_URI__ . 'modules/privatesales_logistique/' . $fname . '">' . $this -> l ( 'Click here to download the file' ) . '</a></p>' ;
}
2016-09-15 11:14:09 +02:00
2016-09-14 17:42:08 +02:00
public function getSaleExport ( $id_category = 0 , $id_lang = 0 )
2016-05-18 16:14:24 +02:00
{
global $link , $cookie ;
require_once ( _PS_ROOT_DIR_ . '/modules/privatesales/Sale.php' );
set_time_limit ( 300 );
2016-09-14 17:42:08 +02:00
if ( $id_category == 0 ){
$id_category = ( int ) Tools :: getValue ( 'id' );
}
if ( $id_lang == 0 ) {
$id_lang = $cookie -> id_lang ;
}
2017-01-18 11:32:54 +01:00
$order_states = explode ( ',' , Configuration :: get ( 'PS_IT_OF_ORDER_STATES' ));
2016-05-18 16:14:24 +02:00
$sale = Sale :: getSaleFromCategory ( $id_category );
$category = new Category ( $id_category , $cookie -> id_lang );
if ( $category ) {
$c = $category ;
$children = $c -> recurseLiteCategTree ( 5 , 0 , $id_lang );
$ids = $this -> _recurse_array ( array ( $children ));
$products = array ();
foreach ( $c -> getProductsWs () as $p ) {
$products [] = $p [ 'id' ];
}
foreach ( $ids as $id ) {
$sc = new Category ( $id , $id_lang );
foreach ( $sc -> getProductsWs () as $p ) {
$products [] = $p [ 'id' ];
}
}
$products = array_unique ( $products );
2017-03-03 12:04:35 +01:00
$fname = date ( " Ymd " , strtotime ( $sale -> date_start )) . '-' . $sale -> title [( int ) $id_lang ] . '-' . $id_category . '.csv' ;
2016-05-18 16:14:24 +02:00
foreach ( glob ( dirname ( __FILE__ ) . '/*.csv' ) as $filename ) {
if ( $fname == $filename ) {
unlink ( $filename );
}
}
$f = fopen ( dirname ( __FILE__ ) . '/' . $fname , 'w' );
// uft8 sans bom pour accent
2016-09-14 17:42:08 +02:00
$BOM = " \xEF \xBB \xBF " ; // UTF-8 BOM
2016-05-18 16:14:24 +02:00
fwrite ( $f , $BOM ); // NEW LINE
fputcsv ( $f , array (
'supplier_reference' ,
2017-01-31 15:32:46 +01:00
'ean13' ,
2016-05-18 16:14:24 +02:00
'id_product' ,
'id_product_attribute' ,
'position' ,
'poids' ,
2017-01-19 09:59:58 +01:00
'stock_initial' ,
2017-01-20 09:42:39 +01:00
'quantity_sold' ,
'quantity' ,
2016-05-18 16:14:24 +02:00
'product_name' ,
'combination' ,
'NC8' ,
'Pays de fabrication' ,
'public_price_wt' ,
'price_wt' ,
'wholesale_price' ,
'BDC HT' ,
'id_TVA' ,
'description_short' ,
2016-06-08 17:44:21 +02:00
'bon_a_savoir' ,
'plus' ,
'videos' ,
'livraison' ,
2016-05-18 16:14:24 +02:00
'images' ,
'nb_images' ,
'categories' ,
'sous-categories' ,
'sous-sous-categories' ,
), ';' , '"' );
foreach ( $products as $product ) {
$p = new Product (( int ) $product , $id_lang );
if ( ! Validate :: isLoadedObject ( $p )) {
2016-09-14 17:42:08 +02:00
$this -> html .= '<p class="error">Erreur produit: ' . serialize ( $product ) . ' ce produit ne figure pas dans l\'export</p>' ;
2016-05-18 16:14:24 +02:00
} else {
$position = Db :: getInstance () -> getValue ( '
SELECT `position`
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_category` = '.(int) $id_category.'
AND id_product = '. (int) $p->id . '
2016-09-14 17:42:08 +02:00
' );
2016-05-18 16:14:24 +02:00
$p -> position = $position ;
$categories = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_category`
FROM `'._DB_PREFIX_.'category_product`
WHERE `id_product` = '.(int) $p->id.'
' ) as $cat ) {
$categories [] = ( int ) $cat [ 'id_category' ];
}
sort ( $categories );
$categories_title = array ();
foreach ( $categories as $category ) {
$title = Db :: getInstance () -> getValue ( '
SELECT `name`
FROM `'._DB_PREFIX_.'category_lang`
WHERE `id_category` = '.(int) $category.'
AND id_lang = '. $id_lang . '
' );
$categories_title [( int ) $category ] = $title ;
}
$categorie_0 = '' ;
$categorie_1 = '' ;
$categorie_2 = '' ;
foreach ( $categories as $key => $cat ) {
if ( $key == 0 ) {
$categorie_0 = $categories_title [ $cat ];
} elseif ( $key == 1 ) {
$categorie_1 = $categories_title [ $cat ];
} elseif ( $key == 2 ) {
$categorie_2 = $categories_title [ $cat ];
}
}
$combinations = array ();
foreach ( $p -> getAttributeCombinaisons ( $id_lang ) as $combi ) {
if ( ! isset ( $combinations [ $combi [ 'id_product_attribute' ]])) {
$combinations [ $combi [ 'id_product_attribute' ]] = array (
'qty' => $combi [ 'quantity' ],
'name' => array ( $combi [ 'attribute_name' ]),
'ean13' => $combi [ 'ean13' ],
'location' => empty ( $combi [ 'location' ]) ? $p -> location : $combi [ 'location' ],
'brand' => $p -> manufacturer_name ,
'supplier_reference' => empty ( $combi [ 'supplier_reference' ]) ? $p -> supplier_reference : $combi [ 'supplier_reference' ],
);
} else {
$combinations [ $combi [ 'id_product_attribute' ]][ 'name' ][] = $combi [ 'attribute_name' ];
}
}
$images = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT i . `id_image` , l . `legend`
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'image_lang` l
ON l . `id_image` = i . `id_image`
WHERE l . `id_lang` = '.(int) $id_lang.'
AND i . `id_product` = '.(int) $p->id.'
' ) as $img ) {
$link_image = str_split ( $img [ 'id_image' ]);
2017-09-07 11:36:48 +02:00
$images [] = 'https://static.bebeboutik.com/img/p/' . implode ( '/' , $link_image ) . '/' . $img [ 'id_image' ] . '.jpg' ;
2016-05-18 16:14:24 +02:00
}
$customs = Db :: getInstance () -> getRow ( '
SELECT `nc8` , `id_country`
2016-09-14 17:42:08 +02:00
FROM `'._DB_PREFIX_.'product_customs`
2016-05-18 16:14:24 +02:00
WHERE `id_product` = ' . ( int ) $p -> id
);
if ( count ( $combinations ) > 0 ) {
foreach ( $combinations as $k => $v ) {
$c_images = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT i . `id_image` , l . `legend`
FROM `'._DB_PREFIX_.'image` i
LEFT JOIN `'._DB_PREFIX_.'image_lang` l
ON l . `id_image` = i . `id_image`
LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` a
ON a . `id_image` = i . `id_image`
WHERE l . `id_lang` = '.(int) $id_lang.'
AND a . `id_product_attribute` = '.(int) $k.'
ORDER BY i . `position`
' ) as $img ) {
$link_image = str_split ( $img [ 'id_image' ]);
2017-09-07 11:36:48 +02:00
$c_images [] = 'https://static.bebeboutik.com/img/p/' . implode ( '/' , $link_image ) . '/' . $img [ 'id_image' ] . '.jpg' ;
2016-05-18 16:14:24 +02:00
}
$quantity_sold = ( int ) Db :: getInstance () -> getValue ( '
2017-01-18 11:32:54 +01:00
SELECT SUM ( d . `product_quantity` - d . `product_quantity_reinjected` )
2016-05-18 16:14:24 +02:00
FROM `'._DB_PREFIX_.'order_detail` d
2017-01-18 11:32:54 +01:00
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o . `id_order` = d . `id_order`
2016-05-18 16:14:24 +02:00
WHERE d . `product_id` = '.(int) $p->id.'
AND d . `product_attribute_id` = '.(int) $k.'
2017-01-18 11:32:54 +01:00
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 ).' " )
2016-05-18 16:14:24 +02:00
' );
2017-01-18 11:32:54 +01:00
// $quantity_sold = (int) Db::getInstance()->getValue('
// SELECT SUM(d.`product_quantity`)
// FROM `'._DB_PREFIX_.'order_detail` d
// LEFT JOIN `'._DB_PREFIX_.'orders` o
// ON o.`id_order` = d.`id_order`
// LEFT JOIN `'._DB_PREFIX_.'order_history` h
// ON h.`id_order` = d.`id_order`
// WHERE d.`product_id` = '.(int) $p->id.'
// AND d.`product_attribute_id` = '.(int) $k.'
// AND h.`id_order_state` = 2
// ');
2016-05-18 16:14:24 +02:00
$names = array_unique ( $v [ 'name' ]);
sort ( $names , SORT_STRING );
fputcsv ( $f , array (
$v [ 'supplier_reference' ],
2017-01-31 15:32:46 +01:00
$v [ 'ean13' ],
2016-05-18 16:14:24 +02:00
$p -> id ,
$k ,
$p -> position ,
str_replace ( '.' , ',' , $p -> weight ),
2017-01-19 09:59:58 +01:00
( $v [ 'qty' ] + $quantity_sold ),
2017-01-20 09:42:39 +01:00
$quantity_sold ,
$v [ 'qty' ],
2016-05-18 16:14:24 +02:00
$p -> name [ $id_lang ],
implode ( ' - ' , $names ),
$customs [ 'nc8' ],
$customs [ 'id_country' ],
str_replace ( '.' , ',' , $p -> getPrice ( TRUE , ( int ) $k , 2 , NULL , FALSE , FALSE )),
str_replace ( '.' , ',' , $p -> getPrice ( TRUE , ( int ) $k , 2 )),
str_replace ( '.' , ',' , Tools :: ps_round ( $p -> wholesale_price , 2 )),
str_replace ( '.' , ',' , Tools :: ps_round (( $quantity_sold * $p -> wholesale_price ), 2 )),
$p -> id_tax_rules_group ,
// $p->active,
$p -> description_short [ $id_lang ],
$p -> description [ $id_lang ],
2016-06-08 17:44:21 +02:00
$p -> description_more [ $id_lang ],
$p -> videos [ $id_lang ],
$p -> description_delivery [ $id_lang ],
2016-05-18 16:14:24 +02:00
count ( $c_images ) > 0 ? implode ( ', ' , $c_images ) : implode ( ', ' , $images ),
count ( $c_images ) > 0 ? count ( $c_images ) : count ( $images ),
$categorie_0 ,
$categorie_1 ,
$categorie_2 ,
), ';' , '"' );
}
} else {
$quantity_sold = ( int ) Db :: getInstance () -> getValue ( '
2017-01-18 11:32:54 +01:00
SELECT SUM ( d . `product_quantity` - d . `product_quantity_reinjected` )
2016-05-18 16:14:24 +02:00
FROM `'._DB_PREFIX_.'order_detail` d
2017-01-18 11:32:54 +01:00
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o . `id_order` = d . `id_order`
2016-05-18 16:14:24 +02:00
WHERE d . `product_id` = '.(int) $p->id.'
2017-01-18 11:32:54 +01:00
AND d . `product_attribute_id` = 0
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 ).' " )
2016-05-18 16:14:24 +02:00
' );
2017-01-18 11:32:54 +01:00
// $quantity_sold = (int) Db::getInstance()->getValue('
// SELECT SUM(d.`product_quantity`)
// FROM `'._DB_PREFIX_.'order_detail` d
// LEFT JOIN `'._DB_PREFIX_.'orders` o
// ON o.`id_order` = d.`id_order`
// LEFT JOIN `'._DB_PREFIX_.'order_history` h
// ON h.`id_order` = d.`id_order`
// WHERE d.`product_id` = '.(int) $p->id.'
// AND h.`id_order_state` = 2
// ');
2016-05-18 16:14:24 +02:00
fputcsv ( $f , array (
$p -> supplier_reference ,
2017-01-31 15:32:46 +01:00
$p -> ean13 ,
2016-05-18 16:14:24 +02:00
$p -> id ,
0 ,
$p -> position ,
str_replace ( '.' , ',' , $p -> weight ),
2017-01-19 09:59:58 +01:00
( $p -> quantity + $quantity_sold ),
2017-01-20 09:42:39 +01:00
$quantity_sold ,
$p -> quantity ,
2016-05-18 16:14:24 +02:00
$p -> name [ $id_lang ],
'' ,
$customs [ 'nc8' ],
$customs [ 'id_country' ],
str_replace ( '.' , ',' , $p -> getPrice ( TRUE , NULL , 2 , NULL , FALSE , FALSE )),
str_replace ( '.' , ',' , $p -> getPrice ( TRUE , NULL , 2 )),
str_replace ( '.' , ',' , Tools :: ps_round ( $p -> wholesale_price , 2 )),
str_replace ( '.' , ',' , Tools :: ps_round (( $quantity_sold * $p -> wholesale_price ), 2 )),
$p -> id_tax_rules_group ,
$p -> description_short [ $id_lang ],
$p -> description [ $id_lang ],
2016-06-08 17:44:21 +02:00
$p -> description_more [ $id_lang ],
$p -> videos [ $id_lang ],
$p -> description_delivery [ $id_lang ],
2016-05-18 16:14:24 +02:00
implode ( ', ' , $images ),
count ( $images ),
$categorie_0 ,
$categorie_1 ,
$categorie_2 ,
), ';' , '"' );
}
}
}
fclose ( $f );
$this -> html .= '<p class="conf">' . $this -> l ( 'Export complete.' ) . ' <a onclick="window.open(this.href); return false;" href="http://' . $_SERVER [ 'HTTP_HOST' ] . __PS_BASE_URI__ . 'modules/privatesales_logistique/' . $fname . '">' . $this -> l ( 'Click here to download the file' ) . '</a></p>' ;
}
}
2016-01-04 12:49:26 +01:00
public function getFormOrderFormInfo ()
{
global $cookie ;
2017-06-14 17:03:25 +02:00
$html = '' ;
2016-01-04 12:49:26 +01:00
$array_lang = array (
'fr' , 'en'
);
$array = array (
'PS_IT_OF_ORGANISATION' => array ( 'form_organisation' , 'Organisation :' ),
'PS_IT_OF_SLOGAN' => array ( 'form_slogan' , 'Slogan :' ),
'PS_IT_OF_EMAIL' => array ( 'form_email' , 'Email :' ),
'PS_IT_OF_TVA' => array ( 'form_tva' , 'TVA :' ),
'PS_IT_OF_ADDRESS' => array ( 'form_address' , 'Adresse partie 1 :' ),
'PS_IT_OF_ADDRESS_2' => array ( 'form_address_2' , 'Adresse partie 2 :' ),
'PS_IT_OF_CP_CITY' => array ( 'form_cp_city' , 'CP et Ville :' ),
'PS_IT_OF_NUMBER_PHONE' => array ( 'form_numero_tel' , 'Numéro de téléphone :' ),
'PS_IT_OF_BAS_PAGE' => array ( 'form_bas_page' , 'Informations bas de page :' , true ),
'PS_IT_OF_BAS_PAGE_BIS' => array ( 'form_bas_page_bis' , 'Informations bas de page Bis:' , true ),
);
if ( Tools :: isSubmit ( 'submitFormInfos' ))
{
foreach ( $array_lang as $lang )
{
foreach ( $array as $k => $arr )
{
if ( isset ( $arr [ 2 ]))
$html_ = true ;
else $html_ = false ;
Configuration :: updateValue ( $k . '_' . $lang , Tools :: getValue ( $arr [ 0 ] . '_' . $lang ), $html_ );
}
}
Configuration :: updateValue ( 'PS_IT_OF_ORDER_STATES' , implode ( ',' , Tools :: getValue ( 'states' , array () )) );
$html .= '<div class="conf">' . $this -> l ( 'Informations Sauvegardé' ) . '</div>' ;
}
$html .= '
2017-06-14 17:03:25 +02:00
< div class = " modal fade " id = " BDCModal " tabindex = " -1 " role = " dialog " aria - labelledby = " BDCModalLabel " >
< div class = " modal-dialog " role = " document " >
< div class = " modal-content " >
< form method = " post " action = " # " id = " form_infos " >
< div class = " modal-header " >
< button type = " button " class = " close " data - dismiss = " modal " aria - label = " Close " >< span aria - hidden = " true " >& times ; </ span ></ button >
< h4 class = " modal-title " id = " BDCModalLabel " > Info Bon de Commande </ h4 >
</ div >
< div class = " modal-body " > ' ;
foreach ( $array_lang as $key => $lang ) {
if ( $key == 1 ){
$html .= '<div class="ln_solid"></div>' ;
}
$html .= '
< div class = " col-md-12 " >
< p class = " text-center " >< strong > '.($lang=="fr"?"Français":"Anglais").' </ strong ></ p > ' ;
foreach ( $array as $k => $arr ) {
$ { $arr [ 0 ] . '_' . $lang } = Configuration :: get ( $k . '_' . $lang );
$html .= '
< div class = " form-group " >
< label class = " text-left " > '.$arr[1].' </ label >
' . ( isset ( $arr [ 2 ])
? '<textarea class="form-control" name="' . $arr [ 0 ] . '_' . $lang . '" size="50">' . $ { $arr [ 0 ] . '_' . $lang } . '</textarea>'
: '<input class="form-control" type="text" value="' . $ { $arr [ 0 ] . '_' . $lang } . '" name="' . $arr [ 0 ] . '_' . $lang . '">' ) . '
</ div > ' ;
}
$html .= '
</ div >
< div class = " clearfix " ></ div > ' ;
}
2016-01-04 12:49:26 +01:00
2017-06-14 17:03:25 +02:00
$order_state = OrderState :: getOrderStates ( $cookie -> id_lang );
$order_state_selected = explode ( ',' , Configuration :: get ( 'PS_IT_OF_ORDER_STATES' ));
$html .= '
< div class = " clearfix " ></ div >
< div class = " ln_solid " ></ div >
< div class = " col-md-12 " >
< p class = " text-center " > '.$this->l(' Statut des commandes que vous souhaitez traiter ').' : </ p > ' ;
foreach ( $order_state as $state ) {
$html .= '
< label for = " order_state_'. $state['id_order_state'] .' " style = " float:none;padding:0;font-weight:normal;display:block;cursor:pointer;text-align:left;width:auto; " >
< input type = " checkbox " value = " '. $state['id_order_state'] .' " '.(in_array($state[' id_order_state '], $order_state_selected) ? ' checked ' : ' ').' id = " order_state_'. $state['id_order_state'] .' " name = " states[] " > '.$state[' name '].'
</ label > ' ;
}
$html .= ' </ div >
< div class = " clearfix " ></ div >
</ div >
< div class = " modal-footer " >
< button type = " button " class = " btn btn-default " data - dismiss = " modal " > Fermer </ button >
< button type = " submit " class = " btn btn-primary " name = " submitFormInfos " > Enregistrer </ button >
</ div >
</ form >
</ div >
2016-01-04 12:49:26 +01:00
</ div >
2017-06-14 17:03:25 +02:00
</ div > ' ;
2016-01-04 12:49:26 +01:00
return $html ;
}
2016-05-18 16:14:24 +02:00
private function _recurse_array ( $array ) {
$result = array ();
foreach ( $array as $i ) {
$result [] = $i [ 'id' ];
if ( count ( $i [ 'children' ]) > 0 ) {
$result = array_merge ( $result , $this -> _recurse_array ( $i [ 'children' ]));
}
}
return $result ;
}
2016-01-04 12:49:26 +01:00
}
?>