2016-09-06 15:32:52 +02:00
< ? php
require_once ( PS_ADMIN_DIR . '/helpers/HelperForm.php' );
2016-12-12 18:27:45 +01:00
require_once ( PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php' );
2016-09-06 15:32:52 +02:00
require_once ( PS_ADMIN_DIR . '/helpers/HelperList.php' );
class AdminPhileaMagistor extends AdminTab {
2016-10-21 16:06:36 +02:00
const TIME_DISPLAY = 0 ; // list displaying time in days. 0 to disable
static $_crrlist_cache = NULL ;
public function postProcess () {
2016-10-27 12:26:49 +02:00
if ( Tools :: isSubmit ( 'submitProductSaleCache' )) {
2016-11-23 16:33:55 +01:00
global $cookie ;
2016-11-23 15:55:51 +01:00
$fileName = 'cron_sale_cache.php' ;
$output = shell_exec ( " ps -ax | grep $fileName | wc -l " );
2016-11-04 10:24:04 +01:00
$hour = ( int ) date ( 'H' );
$min = ( int ) date ( 'i' );
2016-12-12 18:27:45 +01:00
if ( $output > 2 ){
echo '<p class="error">' . $this -> l ( 'Association automatique en cours, réessayez plus tard' ) . '</p><br />' ;
} elseif ( $hour % 3 == 0 && $min <= 20 && $min >= 10 ){
2016-11-04 10:24:04 +01:00
echo '<p class="error">' . $this -> l ( 'Association automatique en cours, réessayez plus tard' ) . '</p><br />' ;
} else {
$min_id_product = Db :: getInstance () -> getValue ( '
SELECT MIN ( `id_product` ) FROM `'._DB_PREFIX_.'product` WHERE `date_add` > DATE_SUB ( NOW (), INTERVAL 10 DAY )
2016-10-27 12:26:49 +02:00
' );
2016-11-04 10:24:04 +01:00
if ( $min_id_product ) {
Db :: getInstance () -> ExecuteS ( '
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` >= '.$min_id_product.'
' );
2016-10-27 12:26:49 +02:00
2016-11-04 10:24:04 +01:00
Db :: getInstance () -> ExecuteS ( '
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
SELECT p . id_product , IFNULL (
(
SELECT s . id_sale
FROM `'._DB_PREFIX_.'privatesale_category` s
WHERE s . `id_category` = p . `id_category_default`
LIMIT 1 )
, 0
)
FROM `'._DB_PREFIX_.'product` p
WHERE p . `id_product` >= '.$min_id_product.'
2016-10-27 12:26:49 +02:00
)
2016-11-04 10:24:04 +01:00
' );
2016-11-23 16:33:55 +01:00
// LOG ACTION
Db :: getInstance () -> execute ( '
INSERT INTO `'._DB_PREFIX_.'ant_log`
VALUES (
DEFAULT ,
'.(int) $cookie->id_employee.' ,
" '.pSQL('Association manuelle product_ps_cache via Philéa').' " ,
NOW ()
)
' );
2016-11-04 10:24:04 +01:00
echo '<p class="conf">' . $this -> l ( 'Produits associés aux ventes depuis le produit #' ) . $min_id_product . '</p><br />' ;
} else {
echo '<p class="error">' . $this -> l ( 'Pas de produit ajouté depuis 10 jours' ) . '</p><br />' ;
}
2016-10-27 12:26:49 +02:00
}
} elseif ( Tools :: isSubmit ( 'submitPhilea' )) {
2016-10-21 16:06:36 +02:00
$id_sale = ( int ) Tools :: getValue ( 'id_sale' );
if ( $id_sale ) {
if ( ! Db :: getInstance () -> getRow ( '
SELECT *
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `id_sale` = '.(int) $id_sale.'
' )) {
Db :: getInstance () -> execute ( '
INSERT INTO `'._DB_PREFIX_.'philea_sync`
VALUES (
DEFAULT ,
'.(int) $id_sale.' ,
0 ,
NOW ()
)
' );
// no REC on BBB
// if (Tools::getValue('force_rec_file')){
// // get last sync order form for this sale
// $last_order_sync = Db::getInstance()->getRow(
// 'SELECT * FROM `' . _DB_PREFIX_ . 'philea_supplier_order_sync`
// WHERE `id_sale` = ' . (int) $id_sale . '
// ORDER BY `date_add` DESC');
// if ($last_order_sync && isset($last_order_sync['id_order_form'])){
// Db::getInstance()->execute('
// DELETE FROM `' . _DB_PREFIX_ . 'philea_supplier_order_sync`
// WHERE `id_sale` = ' . (int) $id_sale . '
// AND `id_order_form` = ' . (int) $last_order_sync['id_order_form'] . '
// ORDER BY `date_add` DESC
// LIMIT 1');
// }
// }
echo '<p class="conf">' . $this -> l ( 'Sale added to queue successfully' ) . '</p><br />' ;
} else {
echo '<p class="error">' . $this -> l ( 'Sync already in progress for this sale' ) . '</p><br />' ;
}
} else {
echo '<p class="error">' . $this -> l ( 'Invalid sale id' ) . '</p><br />' ;
}
}
elseif ( Tools :: isSubmit ( 'auto_sync' ) && Tools :: isSubmit ( 'active' )){
$id_sale = ( int ) Tools :: getValue ( 'id_sale' );
if ( $id_sale ) {
$active = ( int ) Tools :: getValue ( 'active' );
$sql = '
INSERT INTO `'._DB_PREFIX_.'philea_auto_sync`
VALUES (
'.(int) $id_sale.' ,
'.(int) $active.' ,
" 0000-00-00 00:00:00 "
)
ON DUPLICATE KEY
UPDATE `active` = ' . ( int ) $active ;
if ( Db :: getInstance () -> execute ( $sql )){
echo '<p class="conf">' . $this -> l ( 'Export auto activé' ) . '</p><br />' ;
} else {
echo '<p class="error">' . $this -> l ( 'Export auto désactivé' ) . '</p><br />' ;
}
} else {
echo '<p class="error">' . $this -> l ( 'Invalid sale id' ) . '</p><br />' ;
}
}
elseif ( Tools :: isSubmit ( 'addCDC' ) && Tools :: getValue ( 'id_sale' )){
$id_sale = ( int ) Tools :: getValue ( 'id_sale' );
if ( $id_sale ) {
if ( Db :: getInstance () -> getRow ( '
SELECT *
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `id_sale` = '.(int) $id_sale.'
AND ( `status` = 2
OR `status` = 4 )
' )) {
Db :: getInstance () -> ExecuteS ( '
UPDATE `'._DB_PREFIX_.'philea_sync`
SET `status` = 3
WHERE id_sale = '.(int) $id_sale.'
LIMIT 1
' );
2016-10-28 11:37:41 +02:00
echo '<p class="conf">' . $this -> l ( 'CDC for this Sale added to queue successfully' ) . '</p><br />' ;
2016-10-21 16:06:36 +02:00
} else {
2016-11-23 15:55:51 +01:00
if ( Db :: getInstance () -> getRow ( '
SELECT *
FROM `'._DB_PREFIX_.'philea_sync`
WHERE `id_sale` = '.(int) $id_sale.'
AND `status` = 0
' )) {
echo '<p class="error">' . $this -> l ( 'Vous ne pouvez pas envoyer les commandes car la base produits de cette vente n\'a pas encore été envoyée' ) . '</p><br />' ;
} else {
echo '<p class="error">' . $this -> l ( 'CDC Sync already in progress for this sale' ) . '</p><br />' ;
}
2016-10-21 16:06:36 +02:00
}
} else {
echo '<p class="error">' . $this -> l ( 'Invalid sale id' ) . '</p><br />' ;
}
}
elseif ( Tools :: isSubmit ( 'getCsv' ) && Tools :: getValue ( 'id_sale' ) && Tools :: getValue ( 'filename' )){
$id_sale = ( int ) Tools :: getValue ( 'id_sale' );
$filename = Tools :: getValue ( 'filename' );
$this -> exportCsv (( int ) $id_sale , $filename );
}
elseif ( Tools :: isSubmit ( 'philea_archive_submit' )){
$id_sales = Tools :: getValue ( 'id_sales' );
if ( count ( $id_sales )){
$sql_values = array ();
$sql_insert = 'INSERT INTO `' . _DB_PREFIX_ . 'philea_archive` (`id_sale`, `date_add`) VALUES' ;
foreach ( $id_sales as $id_sale )
$sql_values [] = '(' . ( int ) $id_sale . ', NOW())' ;
$sql_insert .= implode ( ', ' , $sql_values ) . ' ON DUPLICATE KEY UPDATE `date_add` = NOW()' ;
if ( Db :: getInstance () -> execute ( $sql_insert )){
echo '<p class="conf">' . $this -> l ( 'Sales successfully archived' ) . '</p><br />' ;
}
else {
echo '<p class="conf">' . $this -> l ( 'Sales cannot be archived' ) . '</p><br />' ;
}
}
else {
echo '<p class="error">' . $this -> l ( 'No sale selected.' ) . '</p><br />' ;
}
}
elseif ( Tools :: isSubmit ( 'unarchiveSale' ) && Tools :: getValue ( 'id_sale_unarchive' )){
if ( Db :: getInstance () -> executeS ( '
DELETE FROM `' . _DB_PREFIX_ . 'philea_archive`
WHERE `id_sale` = ' . (int) Tools::getValue(' id_sale_unarchive ') . '
LIMIT 1
' )){
echo '<p class="conf">' . $this -> l ( 'Vente désarchivée' ) . '</p><br />' ;
2016-12-12 18:27:45 +01:00
} else {
2016-10-21 16:06:36 +02:00
echo '<p class="error">' . $this -> l ( 'La vente n\'a pas pu être désarchivée.' ) . '</p><br />' ;
}
2016-12-08 10:34:49 +01:00
} elseif ( Tools :: isSubmit ( 'exportCMDPhilea' )){
$from = Tools :: getValue ( 'date_from' );
$to = Tools :: getValue ( 'date_to' );
$philea_sales = array ();
2016-12-08 11:28:05 +01:00
foreach ( Db :: getInstance () -> ExecuteS ( '
2016-12-08 10:34:49 +01:00
SELECT `id_sale`
2016-12-08 11:28:05 +01:00
FROM `'._DB_PREFIX_.'philea_sync`
2016-12-08 10:34:49 +01:00
' ) as $row ) {
2016-12-08 11:28:05 +01:00
if ( ! isset ( $philea_sales [( int ) $row [ 'id_sale' ]])) {
2016-12-08 10:34:49 +01:00
$philea_sales [( int ) $row [ 'id_sale' ]] = ( int ) $row [ 'id_sale' ];
}
}
2016-12-08 11:28:05 +01:00
$cmd = Db :: getInstance () -> ExecuteS ( '
2016-12-08 11:46:35 +01:00
SELECT o . `id_order` as order_id , o . `date_add` as date_cmd , CONCAT ( os . `name` , " ( " , CAST ( osc . `date_upd` AS DATE ), " ) " ) as status , CONCAT ( c . `id_sale` , " - " , cl . `name` ) as sale , IF ( phs . `date_add` IS NULL , " NON " , " OK " ) as sent , phs . `date_add` as sent_to_philea
2016-12-08 11:28:05 +01:00
FROM `'._DB_PREFIX_.'orders` o
2016-12-08 10:34:49 +01:00
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON ( o . `id_order` = d . `id_order` )
2016-12-08 11:28:05 +01:00
LEFT JOIN `'._DB_PREFIX_.'order_state_current` osc ON ( o . `id_order` = osc . `id_order` )
LEFT JOIN `'._DB_PREFIX_.'order_state_lang` os ON ( osc . `id_order_state` = os . `id_order_state` AND os . `id_lang` = 2 )
LEFT JOIN `'._DB_PREFIX_.'philea_sent` phs ON ( o . `id_order` = phs . `id_order` )
2016-12-08 10:34:49 +01:00
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON ( d . `product_id` = c . `id_product` )
2016-12-08 11:46:35 +01:00
LEFT JOIN `'._DB_PREFIX_.'privatesale` p ON ( c . `id_sale` = p . `id_sale` )
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ( p . `id_category` = cl . `id_category` AND cl . `id_lang` = 2 )
2016-12-08 11:28:05 +01:00
WHERE o . `date_add` >= " '. $from .' 00:00:00 "
AND o . `date_add` <= " '. $to .' 23:59:59 "
2016-12-08 10:34:49 +01:00
AND c . `id_sale` IN ( '.implode(' , ',$philea_sales).' )
2016-12-08 11:28:05 +01:00
GROUP BY o . id_order
2016-12-08 10:34:49 +01:00
' );
if ( $cmd ){
2016-12-08 11:28:05 +01:00
header ( " Content-Type: text/csv; charset=UTF-8 " );
header ( " Content-Disposition: attachment;filename=export- " . date ( 'dmYHi' ) . " .csv; " );
$this -> exportCmdCsv ( $cmd );
die ();
2016-12-08 10:34:49 +01:00
}
else {
echo '<p class="error">' . $this -> l ( 'Pas de commandes trouvées pour cette période.' ) . '</p><br />' ;
}
2016-10-21 16:06:36 +02:00
}
}
2016-12-08 11:28:05 +01:00
public function exportCmdCsv ( $items ){
$row_definition = array (
'order_id' => 'Commande' ,
'date_cmd' => 'Date' ,
2016-12-08 11:46:35 +01:00
'status' => 'Statut' ,
'sale' => 'Vente' ,
2016-12-08 11:28:05 +01:00
'sent' => 'Envoyee a Philea' ,
'sent_to_philea' => 'Date envoi' ,
);
ob_clean ();
$fp = fopen ( 'php://output' , 'w' );
$delim = ';' ;
// first row
$data = array ();
foreach ( $row_definition as $col_name ) {
$data [] = Tools :: htmlentitiesDecodeUTF8 ( $col_name );
}
fputcsv ( $fp , $data , $delim );
foreach ( $items as $item ) {
$data = array ();
foreach ( $row_definition as $key => $col ) {
$data [] = ( isset ( $item [ $key ]) ? $item [ $key ] : '' );
}
fputcsv ( $fp , array_map ( 'utf8_decode' , array_values ( $data )), $delim );
}
fclose ( $fp );
}
2016-10-21 16:06:36 +02:00
public function exportCsv ( $id_sale , $filename ){
$sql = '
SELECT *
FROM `'._DB_PREFIX_.'philea_reception`
WHERE `id_sale` = ' . (int) $id_sale . '
AND `filename` LIKE " ' . pSQL( $filename ) . ' " ' ;
$recept = Db :: getInstance () -> getRow ( $sql );
if ( ! $recept )
return ;
$Y = date ( 'Y' , strtotime ( $recept [ 'date_add' ]));
$m = date ( 'm' , strtotime ( $recept [ 'date_add' ]));
$filepath = dirname ( __FILE__ ) . '/script/archives/IN/RECEPTION/' ;
$filepath .= $Y . '/' . $m . '/' . $recept [ 'filename' ];
$content = file_get_contents ( $filepath );
$lines = preg_split ( '@\n@' , $content );
header ( 'Pragma: public' );
header ( 'Expires: 0' );
header ( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
header ( 'Content-Description: File Transfer' );
header ( 'Content-Type: application/csv; charset=utf-8' );
header ( 'Content-Disposition: attachment; filename=' . $filename . '_' . ( int ) $id_sale . '.csv;' );
header ( 'Content-Transfer-Encoding: binary' );
$format = array (
'OP_CODE' => array ( 1 , 10 ),
'CODE_SOC' => array ( 11 , 20 ),
'N_CDE' => array ( 31 , 20 ),
'DATE_RECEP' => array ( 51 , 8 ),
'CODE_ART' => array ( 59 , 50 ),
'QTE' => array ( 109 , 10 ),
'OTHER' => array ( 119 , 28 ),
);
ob_clean ();
//open file pointer to standard output
$fp = fopen ( 'php://output' , 'w' );
$delim = ';' ;
// first row
$data = array ();
foreach ( $format as $col_name => $array_def )
$data [] = Tools :: htmlentitiesDecodeUTF8 ( $col_name );
fputcsv ( $fp , $data , $delim );
foreach ( $lines as $line ) {
$data = array ();
foreach ( $format as $field => $value ) {
$data [] = substr ( $line , ( $value [ 0 ] - 1 ), $value [ 1 ]);
}
fputcsv ( $fp , array_map ( 'utf8_decode' , array_values ( $data )), $delim );
}
fclose ( $fp );
exit ;
}
public function display () {
global $cookie , $currentIndex ;
$form = ' < style type = " text/css " >
. path_bar {
background - color : #F1F1F1;
border : 1 px solid #565485;
}
h2 {
color : #565485;
}
fieldset {
background : #F1F1F1;
border : 1 px solid #565485;
}
legend {
background : #565485;
background : rgba ( 86 , 84 , 133 , 0.9 );
border : 1 px solid #565485;
color : #fff;
}
. table {
border : 1 px solid #565485;
}
. table tr th {
background : #565485;
background : rgba ( 86 , 84 , 133 , 0.9 );
text - align : center ;
color : #fff;
2016-12-12 18:27:45 +01:00
font - size : 12 px ;
2016-10-21 16:06:36 +02:00
}
. table tr {
background : #fff;
}
. table tr : nth - child ( even ){
background : #F1F1F1;
}
2016-12-12 18:27:45 +01:00
#upload_form .table tr td {
2016-10-21 16:06:36 +02:00
border - bottom : 1 px solid #DEDEDE;
color : #000;
height : auto ;
2016-12-12 18:27:45 +01:00
padding : 5 px 4 px ;
vertical - align : middle ;
2016-10-21 16:06:36 +02:00
}
. table tr td [ id *= ART ] p ,
. table tr td [ id *= CDC ] p {
font - size : 11 px ;
}
. table tr td label {
font - size : 13 px ;
}
input [ type = " text " ], input [ type = " password " ],
input [ type = " file " ], textarea , select {
border : 1 px solid #565485;
}
. button {
background - color : rgba ( 86 , 84 , 133 , 0.7 );
border : 1 px solid #565485;
border - left : 1 px solid rgba ( 86 , 84 , 133 , 0.6 );
border - top : 1 px solid rgba ( 86 , 84 , 133 , 0.6 );
color : rgba ( 255 , 255 , 255 , 0.9 );
padding : 3 px ;
}
. button : hover {
background - color : #565485;
border : 1 px solid rgba ( 86 , 84 , 133 , 0.6 );
border - left : 1 px solid #565485;
border - top : 1 px solid #565485;
color : #fff;
padding : 3 px ;
}
. button : focus {
background - color : rgba ( 86 , 84 , 133 , 0.6 );
}
. table td div {
margin : 5 px 0 ;
2016-10-28 13:09:19 +02:00
margin - bottom : 12 px ;
2016-10-21 16:06:36 +02:00
}
. table td . button {
2016-11-02 10:26:40 +01:00
padding : 5 px 2 px ;
2016-10-21 16:06:36 +02:00
}
. div_report_overlay {
background : rgb ( 181 , 189 , 200 ); /* Old browsers */
background : - moz - linear - gradient ( top , rgba ( 181 , 189 , 200 , 0.4 ) 0 % , rgba ( 130 , 140 , 149 , 0.4 ) 36 % , rgba ( 40 , 52 , 59 , 0.4 ) 100 % ); /* FF3.6+ */
background : - webkit - gradient ( linear , left top , left bottom , color - stop ( 0 % , rgba ( 181 , 189 , 200 , 0.4 )), color - stop ( 36 % , rgba ( 130 , 140 , 149 , 0.4 )), color - stop ( 100 % , rgba ( 40 , 52 , 59 , 0.4 ))); /* Chrome,Safari4+ */
background : - webkit - linear - gradient ( top , rgba ( 181 , 189 , 200 , 0.4 ) 0 % , rgba ( 130 , 140 , 149 , 0.4 ) 36 % , rgba ( 40 , 52 , 59 , 0.4 ) 100 % ); /* Chrome10+,Safari5.1+ */
background : - o - linear - gradient ( top , rgba ( 181 , 189 , 200 , 0.4 ) 0 % , rgba ( 130 , 140 , 149 , 0.4 ) 36 % , rgba ( 40 , 52 , 59 , 0.4 ) 100 % ); /* Opera 11.10+ */
background : - ms - linear - gradient ( top , rgba ( 181 , 189 , 200 , 0.4 ) 0 % , rgba ( 130 , 140 , 149 , 0.4 ) 36 % , rgba ( 40 , 52 , 59 , 0.4 ) 100 % ); /* IE10+ */
background : linear - gradient ( to bottom , rgba ( 181 , 189 , 200 , 0.4 ) 0 % , rgba ( 130 , 140 , 149 , 0.4 ) 36 % , rgba ( 40 , 52 , 59 , 0.4 ) 100 % ); /* W3C */
position : fixed ;
top : 0 ;
left : 0 ;
width : 100 % ;
z - index : 998 ;
height : 100 % ;
cursor : pointer ;
display : none ;
}
2016-09-19 11:58:14 +02:00
. div_report {
2016-10-21 16:06:36 +02:00
display : none ;
position : fixed ;
z - index : 999 ;
left : 50 % ;
margin - left : - 287.5 px ;
position : fixed ;
top : 15 % ;
padding : 15 px ;
padding - top : 20 px ;
background : #fff;
border : 1 px solid ;
line - height : 20 px ;
text - align : left ;
max - height : 300 px ;
width : 575 px ;
overflow : auto ;
color : #000;
}
. div_report h3 { text - align : center ;}
2016-09-16 16:36:16 +02:00
</ style > ' ;
2016-10-21 16:06:36 +02:00
$form .= '<h2>' . $this -> l ( 'Philea' ) . '</h2>' ;
$base_link = $currentIndex . '&token=' . Tools :: getAdminTokenLite ( 'AdminPhileaMagistor' );
2016-12-12 18:27:45 +01:00
$philea_sales = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT `id_sale`
FROM `'._DB_PREFIX_.'philea_sync`
' ) as $row ) {
$philea_sales [] = $row [ 'id_sale' ];
}
2016-10-21 16:06:36 +02:00
$id_sale_options = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT p . `id_sale` , c . `name` , c . `id_category`
FROM `'._DB_PREFIX_.'privatesale` p
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON ( c . `id_category` = p . `id_category` )
2016-11-18 12:09:00 +01:00
LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` pss ON ( pss . `id_sale` = p . `id_sale` )
2016-10-21 16:06:36 +02:00
WHERE c . `id_lang` = '.$cookie->id_lang.'
2016-12-12 18:27:45 +01:00
AND p . `id_sale` NOT IN ( '.implode(' , ',$philea_sales).' )
AND p . `date_start` > " 2016-01-01 00:00:00 "
2016-11-18 12:09:00 +01:00
AND pss . `id_shipping` = 1
2016-10-21 16:06:36 +02:00
ORDER BY p . `id_sale` DESC
' ) as $row ) {
$extrafields = Category :: getSalesInfos ( array (( int ) $row [ 'id_category' ]));
$id_sale_options [] = array (
'label' => ( int ) $row [ 'id_sale' ] . ' - ' . $row [ 'name' ] . ( empty ( $extrafields [( int ) $row [ 'id_category' ]][ 'sales' ][ 1 ]) ? '' : ' - ' . $extrafields [( int ) $row [ 'id_category' ]][ 'sales' ][ 1 ]) ,
'value' => ( int ) $row [ 'id_sale' ]
);
}
2016-12-13 14:52:58 +01:00
2016-12-12 18:27:45 +01:00
$helperForm = new HelperFormBootstrap ();
2016-12-13 14:52:58 +01:00
$helperForm -> _select2 = true ;
$helperForm -> _inputMask = true ;
2016-10-27 12:26:49 +02:00
$helperForm -> _forms = array (
array (
2016-12-12 18:27:45 +01:00
'action' => $base_link ,
'title' => $this -> l ( 'Association Produits' ),
'icon' => '<span class="glyphicon glyphicon-refresh"></span> ' ,
'class' => 'form-horizontal' ,
'class_div' => 'col-md-3' ,
'information' => 'Permet d\'associer les produits aux ventes lorsque le cron n\'est pas encore passé' ,
'sections' => array (
2016-10-27 12:26:49 +02:00
array (
2016-12-12 18:27:45 +01:00
'inputs' => array (
array (
'type' => 'submit' ,
'class' => 'btn-primary' ,
'name' => 'submitProductSaleCache' ,
'value' => $this -> l ( 'Mettre à jour l\'association' ),
),
),
),
),
2016-10-27 12:26:49 +02:00
)
);
2016-12-12 18:27:45 +01:00
$helperForm -> _forms [] = array (
'action' => $base_link ,
'title' => $this -> l ( 'Synchronisation des ventes' ),
'icon' => '<span class="glyphicon glyphicon-cog"></span> ' ,
'class' => 'form-horizontal' ,
2016-12-13 10:15:43 +01:00
'class_div' => 'col-md-4' ,
2016-12-12 18:27:45 +01:00
'sections' => array (
array (
'inputs' => array (
array (
'type' => 'select2' ,
'class-select' => '' ,
'name' => 'id_sale' ,
'options' => $id_sale_options ,
),
),
'actions' => array (
array (
'type' => 'submit' ,
'class' => 'btn-primary' ,
'name' => 'submitPhilea' ,
'value' => $this -> l ( 'Synchroniser vers Philéa' )
)
2016-10-21 16:06:36 +02:00
),
2016-12-12 18:27:45 +01:00
'actions-class' => 'text-right' ,
2016-10-21 16:06:36 +02:00
),
2016-12-12 18:27:45 +01:00
),
2016-10-21 16:06:36 +02:00
);
2016-12-12 18:27:45 +01:00
$helperForm -> _forms [] = array (
'action' => $base_link ,
'title' => $this -> l ( 'Extracts suivi cmd' ),
'icon' => '<span class="glyphicon glyphicon-save-file"></span> ' ,
'class' => 'form-horizontal' ,
2016-12-13 10:15:43 +01:00
'class_div' => 'col-md-5' ,
2016-12-12 18:27:45 +01:00
'sections' => array (
array (
'inputs' => array (
array (
2016-12-13 14:52:58 +01:00
'type' => 'simpleDate' ,
'period' => true ,
2016-12-13 10:15:43 +01:00
'class-from' => 'col-md-6' ,
2016-12-13 14:52:58 +01:00
'class-to' => 'col-md-6' ,
'id' => 'date_from' ,
'id-to' => 'date_to' ,
'name' => 'date_from' ,
'name-to' => 'date_to' ,
'before' => '<span class="glyphicon glyphicon-calendar"></span>' ,
'before-to' => '<span class="glyphicon glyphicon-calendar"></span>' ,
2016-12-12 18:27:45 +01:00
),
2016-12-08 10:34:49 +01:00
),
2016-12-12 18:27:45 +01:00
'actions' => array (
array (
'type' => 'submit' ,
'class' => 'btn-primary' ,
'name' => 'exportCMDPhilea' ,
'value' => $this -> l ( 'Exporter' )
)
2016-12-08 11:54:04 +01:00
),
2016-12-12 18:27:45 +01:00
'actions-class' => 'text-right' ,
2016-12-08 11:54:04 +01:00
),
2016-12-12 18:27:45 +01:00
),
2016-12-08 11:54:04 +01:00
);
2016-12-08 10:34:49 +01:00
2016-12-13 14:52:58 +01:00
$helperForm -> _js .= '
< script >
$ ( document ) . ready ( function () {
$ ( " #date_from " ) . inputmask ( " 9999-99-99 " );
$ ( " #date_to " ) . inputmask ( " 9999-99-99 " );
});
</ script > ' ;
2016-12-12 18:27:45 +01:00
2016-12-13 14:52:58 +01:00
$form .= $helperForm -> renderStyle ();
2016-12-12 18:27:45 +01:00
$form .= '<div class="row">' . $helperForm -> renderForm ( false , NULL , NULL , true ) . '</div>' ;
2016-12-08 10:34:49 +01:00
2016-10-21 16:06:36 +02:00
$CRR_list = $this -> getCRRList ();
2016-12-12 18:27:45 +01:00
$form .= ' < div class = " panel " >
< div class = " panel-title " >
< h2 > Ventes Philéa </ h2 >
< div class = " clearfix " ></ div >
</ div >
< div class = " panel-content " >
< form id = " upload_form " action = " ' . $base_link . ' " method = " post " class = " form " >
< p > '.$this->l(' Historique des ventes envoyées à Philea '). (self::TIME_DISPLAY > 0 ? ' ( ' . self::TIME_DISPLAY . ' ' . $this->l(' derniers jours ') . ' ) ' : ' ').' </ p >
< input type = " hidden " id = " id_sale_hidden " name = " id_sale " value = " " />
< input type = " hidden " name = " addCDC " />
< p >< input type = " submit " class = " btn btn-primary " name = " philea_archive_submit " value = " ' . $this->l ('Archiver la sélection') . ' " /></ p >
< table class = " table table-custombordered " >
< thead >
< tr >
< th colspan = " 2 " > ' . $this->l(' ID sale ') . ' </ th >
< th width = " 325 " > ' . $this->l(' Name ') . ' </ th >
< th > ' . $this->l(' Date envoi ( ART ) ') . ' </ th >
< th > ' . $this->l(' Envoyer commandes ') . ' </ th >
< th > ' . $this->l(' Date envoi ( CMD ) ') . ' </ th >
< th > ' . $this->l(' Préparation ( CRP ) ') . ' </ th >
< th > ' . $this->l(' Envoi auto ') . ' </ th >
</ tr >
</ thead >
< tbody > ' ;
2016-10-21 16:06:36 +02:00
$dowload_link = _MODULE_DIR_ . 'philea_magistor/script/archives/IN/RECEPTION/' ;
$upload_link = $base_link ;
$now = date ( 'Y-m-d H:i:s' , mktime ( date ( 'H' ) - 1 ));
foreach ( $CRR_list as $CRR ) {
$_recep = FALSE ;
if ( isset ( $CRR [ 'recep_date' ]) && $CRR [ 'recep_date' ] && isset ( $CRR [ 'filename' ]) && $CRR [ 'filename' ]){
$_recep = TRUE ;
$Y = date ( 'Y' , strtotime ( $CRR [ 'recep_date' ]));
$m = date ( 'm' , strtotime ( $CRR [ 'recep_date' ]));
$dl_link = $dowload_link . $Y . '/' . $m . '/' . $CRR [ 'filename' ];
$dl_csv = $base_link . '&getCsv&id_sale=' . ( int ) $CRR [ 'id_sale' ] . '&filename=' . $CRR [ 'filename' ];
$dl_link = '<a class="button" target="_blank" href="' . $dl_link . '" title="' . $this -> l ( 'Download CRR file' ) . '"><img src="../img/admin/import.gif"/>' . $this -> l ( '.DAT' ) . '</a> ' ;
//$dl_link .= '<a class="button" target="_blank" href="' . $dl_csv . '" title="'.$this->l('Download CRR file').'"><img src="../img/admin/import.gif"/>'.$this->l('.CSV').'</a>';
}
else {
$CRR [ 'recep_date' ] = '--' ;
$dl_link = '' ;
}
$auto_sync = ( isset ( $CRR [ 'auto_sync_active' ]) && $CRR [ 'auto_sync_active' ]) ? true : false ;
$title = ( $auto_sync ? $this -> l ( 'Désactiver l\'envoi automatique pour la vente' ) : $this -> l ( 'Activer l\'envoi automatique pour la vente' ) );
if ( isset ( $CRR [ 'date_end' ]) && $CRR [ 'date_end' ] >= $now )
$auto_sync_btn = '<a title="' . $title . ' ' . ( int ) $CRR [ 'id_sale' ] . '" data-id_sale = "' . ( int ) $CRR [ 'id_sale' ] . '" class="auto_sync_btn' . ( $auto_sync ? ' active' : '' ) . '" href="' . $currentIndex . '&token=' . $this -> token . '&auto_sync&id_sale=' . ( int ) $CRR [ 'id_sale' ] . '&active=' . ( int ) ! $auto_sync . '"><img src="../img/admin/' . ( $auto_sync ? 'module_install.png' : 'module_disabled.png' ) . '"/></a>' ;
else
$auto_sync_btn = '<span style="opacity: 0.4;" title="' . $this -> l ( 'La vente est terminée' ) . '"><img src="../img/admin/' . ( $auto_sync ? 'module_install.png' : 'module_notinstall.png' ) . '"/></span>' ;
$submit_link = $upload_link ; // . '&id_sale=' . (int) $CRR['id_sale'] . '&addCDC=1';
$art_reports = Db :: getInstance () -> executeS ( '
SELECT `report_data` , `report_date` , `id_sale`
FROM `'._DB_PREFIX_.'philea_syncreport`
WHERE `id_sale` = '.(int) $CRR[' id_sale '] .'
AND `filename` LIKE " ART% "
AND `report_data` IS NOT NULL
' );
$cdc_reports = Db :: getInstance () -> executeS ( '
SELECT `report_data` , `report_date` , `id_sale`
FROM `'._DB_PREFIX_.'philea_syncreport`
WHERE `id_sale` = '.(int) $CRR[' id_sale '] .'
AND `filename` LIKE " CDC% "
AND `report_data` IS NOT NULL
' );
$crp_reports = Db :: getInstance () -> executeS ( '
SELECT `report_data` , `report_date` , `id_sale`
FROM `'._DB_PREFIX_.'philea_syncreport`
WHERE `id_sale` = '.(int) $CRR[' id_sale '] .'
AND `filename` LIKE " CRP% "
AND `report_data` IS NOT NULL
' );
$form .= ' < tr >
< td >< input type = " checkbox " id = " check_sale_'.(int) $CRR['id_sale'] .' " name = " id_sales[] " value = " '.(int) $CRR['id_sale'] .' " /></ td >
2016-12-12 18:27:45 +01:00
< td >< label style = " float:none; width:auto; padding: 0; text-align: left; font-weight: normal; margin:0; " for = " check_sale_'.(int) $CRR['id_sale'] .' " > '.(int) $CRR[' id_sale '].' </ label ></ td >
< td >< label style = " float:none; width:auto; padding: 0; text-align: left; font-weight: normal; margin:0; " for = " check_sale_'.(int) $CRR['id_sale'] .' " >< strong > '.$CRR[' name '].' </ strong > - '.$CRR[' subtitle '].' </ label ></ td >
2016-10-21 16:06:36 +02:00
< td style = " text-align: center; " id = " ART_'. (int) $CRR['id_sale'] .' " >
2016-12-12 18:27:45 +01:00
< p style = " color: #565485;font-size:12px; " > '.(!empty($CRR[' sync_date '])?' < span style = " font-size: 12px; " class = " anticon anticon-clock " ></ span > '.date(' d / m / Y H : i ',strtotime($CRR[' sync_date '])):' -- ').' </ p > ' ;
2016-10-21 16:06:36 +02:00
if ( ! empty ( $art_reports )){
foreach ( $art_reports as $key => $report ) {
$form .= ' < div >
2016-12-12 18:27:45 +01:00
< a class = " btn btn-primary btn-xs see_report " data - id = " '. (int) $CRR['id_sale'] .' " data - key = " '.(int) $key .' " data - type = " ART " href = " # " title = " '. $this->l ('See ART report').' " >< span class = " anticon anticon-file-text2 " ></ span > '.date(' d / m / Y H : i ',strtotime($report[' report_date '])).' </ a >
2016-10-21 16:06:36 +02:00
< div id = " '.(int) $CRR['id_sale'] .'_'. $key .'_ART " style = " display:none " > '.(!empty($report[' report_data '])?$report[' report_data ']:' Pas encore de Rapport ').' </ div >
</ div > ' ;
}
}
$form .= ' </ td >
2016-12-12 18:27:45 +01:00
< td style = " text-align: center; " >< a title = " '. $this->l ('Envoi du fichier CDC').' " class = " btn btn-primary btn-xs upload_link " data - id = " ' . (int) $CRR['id_sale'] . ' " href = " '. $submit_link .' " title = " '. $this->l ('Upload CDC file').' " >< span class = " anticon anticon-upload2 " ></ span > '.$this->l(' Envoyer à Philea ').' </ a ></ td >
2016-10-21 16:06:36 +02:00
< td style = " text-align: center; " id = " CDC_'. (int) $CRR['id_sale'] .' " >
2016-12-12 18:27:45 +01:00
< p style = " color: #565485; font-size:12px; " > '.(!empty($CRR[' sent_date '])?' < span style = " font-size: 12px; " class = " anticon anticon-clock " ></ span > '.date(' d / m / Y H : i ',strtotime($CRR[' sent_date '])):' -- ').' </ p > ' ;
2016-10-21 16:06:36 +02:00
if ( ! empty ( $cdc_reports )){
2016-11-02 17:41:06 +01:00
$form .= '<span class="see_more anticon anticon-zoom-in" style="color:#565485;cursor:pointer"></span><div class="reports" style="display:none">' ;
2016-10-21 16:06:36 +02:00
foreach ( $cdc_reports as $key => $report ) {
$form .= ' < div >
2016-12-12 18:27:45 +01:00
< a class = " btn btn-primary btn-xs see_report " data - id = " '. (int) $CRR['id_sale'] .' " data - key = " '.(int) $key .' " data - type = " CDC " href = " # " title = " '. $this->l ('See CDC report').' " >< span class = " anticon anticon-file-text2 " ></ span > '.date(' d / m / Y H : i ',strtotime($report[' report_date '])).' </ a >
2016-10-21 16:06:36 +02:00
< div id = " '.(int) $CRR['id_sale'] .'_'. $key .'_CDC " style = " display:none " > '.(!empty($report[' report_data '])?$report[' report_data ']:' Pas encore de Rapport ').' </ div >
</ div > ' ;
}
2016-11-02 17:41:06 +01:00
$form .= '</div>' ;
2016-10-21 16:06:36 +02:00
}
$form .= ' </ td >
< td style = " text-align: center; " id = " CRP_'. (int) $CRR['id_sale'] .' " > ' ;
if ( ! empty ( $crp_reports )){
2016-12-12 18:27:45 +01:00
$form .= '<p style="color: #565485; font-size:12px;"><span style="font-size: 12px;" class="anticon anticon-clock"></span> ' . date ( 'd/m/Y H:i' , strtotime ( $crp_reports [ 0 ][ 'report_date' ])) . ' </ p >
2016-11-02 17:41:06 +01:00
< span class = " see_more anticon anticon-zoom-in " style = " color:#565485;cursor:pointer " ></ span >< div class = " reports " style = " display:none " > ' ;
2016-10-21 16:06:36 +02:00
foreach ( $crp_reports as $key => $report ) {
$form .= ' < div >
2016-12-12 18:27:45 +01:00
< a class = " btn btn-primary btn-xs see_report " data - id = " '. (int) $CRR['id_sale'] .' " data - key = " '.(int) $key .' " data - type = " CRP " href = " # " title = " '. $this->l ('See CDC report').' " >< span class = " anticon anticon-file-text2 " ></ span > '.date(' d / m / Y H : i ',strtotime($report[' report_date '])).' </ a >
2016-10-21 16:06:36 +02:00
< div id = " '.(int) $CRR['id_sale'] .'_'. $key .'_CRP " style = " display:none " > '.(!empty($report[' report_data '])?$report[' report_data ']:' Pas encore de Rapport ').' </ div >
</ div > ' ;
}
2016-11-02 17:41:06 +01:00
$form .= '</div>' ;
2016-10-21 16:06:36 +02:00
}
$form .= ' </ td >
< td style = " text-align: center; " > '.$auto_sync_btn.' </ td >
</ tr > ' ;
}
2016-12-12 18:27:45 +01:00
$form .= ' </ tbody >
</ table >
< div class = " report_error div_report " ></ div >
< p >< input type = " submit " class = " btn btn-primary " name = " philea_archive_submit " value = " ' . $this->l ('Archiver la sélection') . ' " /></ p >
</ form >
</ div >
</ div >
2016-10-21 16:06:36 +02:00
< div class = " div_report_overlay " ></ div >
< script type = " text/javascript " >
$ ( " document " ) . ready ( function (){
2016-11-02 17:41:06 +01:00
$ ( " .see_more " ) . click ( function (){
$ ( this ) . toggleClass ( " anticon-zoom-in " );
$ ( this ) . toggleClass ( " anticon-zoom-out " );
$ ( this ) . next ( " div.reports " ) . toggle ();
});
2016-10-21 16:06:36 +02:00
$ ( " .upload_link " ) . click ( function ( e ){
e . preventDefault ();
$ ( " #id_sale_hidden " ) . val ( $ ( this ) . data ( " id " ));
$ ( " #upload_form " ) . submit ();
});
$ ( " .see_report " ) . each ( function (){
$ ( this ) . click ( function ( e ){
e . preventDefault ();
$ ( " .report_error " ) . empty ();
$ ( " .report_error " ) . hide ();
id_sale = $ ( this ) . data ( " id " );
type = $ ( this ) . data ( " type " );
key = $ ( this ) . data ( " key " );
report_data = $ ( " div# " + id_sale + " _ " + key + " _ " + type ) . html ();
console . log ( report_data );
$ ( " .div_report " ) . append ( " <h3>Rapport " + type + " vente " + id_sale + " </h3> " + report_data + " " );
if ( type == " ART " ) {
$ ( " .div_report " ) . css ( " text-align " , " left " );
} else {
$ ( " .div_report " ) . css ( " text-align " , " center " );
}
$ ( " .div_report " ) . show ();
$ ( " .div_report_overlay " ) . show ();
})
});
$ ( " .div_report_overlay " ) . click ( function ( e ){
$ ( " .div_report " ) . empty ();
$ ( " .div_report " ) . hide ();
$ ( " .div_report_overlay " ) . hide ();
});
});
</ script >
' ;
$form .= $this -> displayArchives ();
2016-12-13 14:52:58 +01:00
$form .= $helperForm -> renderScript ();
2016-10-21 16:06:36 +02:00
echo $form ;
}
/**
* Get CRR files for not sent sales
*/
public function getCRRList (){
if ( isset ( self :: $_crrlist_cache ) && self :: $_crrlist_cache )
return self :: $_crrlist_cache ;
// Get CRR if CDC has not been sent OR sync_date < TIME_DISPLAY DAYs
$id_sales = array ();
$pm_sync = array ();
$sql = '
SELECT
pm_sync . `id_sale` ,
MAX ( pm_sync . `date_add` ) as `sync_date`
FROM `'._DB_PREFIX_.'philea_sync` pm_sync
LEFT JOIN `'._DB_PREFIX_.'philea_archive` pm_arch
ON pm_arch . `id_sale` = pm_sync . `id_sale`
WHERE 1
AND `pm_arch` . `id_sale` IS NULL
GROUP BY pm_sync . `id_sale`
' . ((int) self::TIME_DISPLAY > 0 ? ' HAVING `sync_date` > DATE_SUB ( NOW (), INTERVAL ' . self::TIME_DISPLAY . ' DAY ) ' : ' ') . '
ORDER BY `sync_date` DESC ' ;
foreach ( Db :: getInstance () -> executeS ( $sql ) as $row ) {
$id_sales [] = ( int ) $row [ 'id_sale' ];
$pm_sync [( int ) $row [ 'id_sale' ]] = $row [ 'sync_date' ];
}
$receptions = array ();
$sql = '
SELECT
pm_r . `id_sale` ,
pm_r . `filename` ,
MAX ( pm_r . `date_add` ) as `recep_date`
FROM `'._DB_PREFIX_.'philea_reception` pm_r
WHERE `id_sale` IN ( ' . implode(' , ', $id_sales) . ' )
GROUP BY `id_sale` ' ;
foreach ( Db :: getInstance () -> executeS ( $sql ) as $row )
$receptions [ $row [ 'id_sale' ]] = $row ;
$sales = array ();
$sql = '
SELECT
p . `id_sale` ,
c . `name` ,
c . `id_category` ,
p . `date_start` ,
p . `date_end`
FROM `'._DB_PREFIX_.'privatesale` p
LEFT JOIN `'._DB_PREFIX_.'category_lang` c
ON c . `id_category` = p . `id_category`
AND c . `id_lang` = 2
WHERE p . `id_sale` IN ( ' .implode(' , ', $id_sales) . ' ) ' ;
foreach ( Db :: getInstance () -> executeS ( $sql ) as $row )
$sales [( int ) $row [ 'id_sale' ]] = $row ;
$pm_autosales = array ();
$sql = '
SELECT
pm_as . `id_sale` ,
pm_as . `active` as `auto_sync_active`
FROM `'._DB_PREFIX_.'philea_auto_sync` pm_as
WHERE `id_sale` IN ( ' . implode(' , ', $id_sales) . ' )
AND pm_as . `active` = 1 ' ;
foreach ( Db :: getInstance () -> executeS ( $sql ) as $row )
2016-11-03 17:20:09 +01:00
$pm_active [( int ) $row [ 'id_sale' ]] = ( int ) $row [ 'auto_sync_active' ];
2016-10-21 16:06:36 +02:00
$pm_sent = array ();
$sql = '
SELECT
pm_s . `id_sale` ,
MAX ( pm_s . `date_add` ) as `sent_date`
FROM `'._DB_PREFIX_.'philea_sent` pm_s
WHERE pm_s . `id_sale` IN ( ' . implode(' , ', $id_sales) . ' )
GROUP BY pm_s . `id_sale` ' ;
foreach ( Db :: getInstance () -> executeS ( $sql ) as $row )
$pm_sent [( int ) $row [ 'id_sale' ]] = $row [ 'sent_date' ];
$CRR_list = array ();
foreach ( $id_sales as $id_sale ) {
$sync_date = ( isset ( $pm_sync [( int ) $id_sale ]) ? $pm_sync [( int ) $id_sale ] : '' );
$recep = ( isset ( $receptions [( int ) $id_sale ]) ? $receptions [( int ) $id_sale ] : array ( 'filename' => '' , 'recep_date' => '' ));
$sale = ( isset ( $sales [( int ) $id_sale ]) ? $sales [( int ) $id_sale ] : array ( 'name' => '' , 'date_start' => '' , 'date_end' => '' ));
$sent_date = ( isset ( $pm_sent [( int ) $id_sale ]) ? $pm_sent [( int ) $id_sale ] : '' );
$as_active = ( isset ( $pm_active [( int ) $id_sale ])) ? 1 : 0 ;
$extrafields = Category :: getSalesInfos ( array (( int ) $sales [( int ) $id_sale ][ 'id_category' ]));
$CRR_list [ $id_sale ] = array (
'id_sale' => $id_sale ,
'sync_date' => $sync_date ,
'filename' => $recep [ 'filename' ],
'recep_date' => $recep [ 'recep_date' ],
'name' => $sale [ 'name' ],
'sent_date' => $sent_date ,
'auto_sync_active' => $as_active ,
'date_start' => $sale [ 'date_start' ],
'date_end' => $sale [ 'date_end' ],
'subtitle' => $extrafields [( int ) $sales [( int ) $id_sale ][ 'id_category' ]][ 'sales' ][ 1 ]
);
}
self :: $_crrlist_cache = $CRR_list ;
return self :: $_crrlist_cache ;
// $CRR_files = Db::getInstance()->executeS('
// SELECT
// pmsync.id_sale,
// MAX(pmsync.`date_add`) as `sync_date`,
// pmr.`filename`,
// MAX(pmr.`date_add`) as `recep_date`,
// c.`name`,
// MAX(pms.date_add) as `sent_date`,
// pmas.`active` as `auto_sync_active`,
// p.date_start,
// p.date_end
// FROM `'._DB_PREFIX_.'philea_sync` pmsync
// LEFT JOIN `'._DB_PREFIX_.'philea_sent` pms
// ON pms.`id_sale` = pmsync.`id_sale`
// LEFT JOIN `'._DB_PREFIX_.'privatesale` p
// ON p.`id_sale` = pmsync.`id_sale`
// LEFT JOIN `'._DB_PREFIX_.'category_lang` c
// ON c.`id_category` = p.`id_category`
// LEFT JOIN `'._DB_PREFIX_.'philea_reception` pmr
// ON pmsync.`id_sale` = pmr.`id_sale`
// LEFT JOIN `'._DB_PREFIX_.'philea_auto_sync` pmas
// ON pmas.`id_sale` = pmsync.`id_sale`
// LEFT JOIN `'._DB_PREFIX_.'philea_archive` pm_arch
// ON pm_arch.`id_sale` = pmsync.`id_sale`
// WHERE 1
// AND c.id_lang = 2
// AND `pm_arch`.id_sale IS NULL
// ' . ((int) self::TIME_DISPLAY > 0 ? 'AND pmsync.`date_add` > DATE_SUB(NOW(), INTERVAL ' . self::TIME_DISPLAY . ' DAY)' : '') . '
// GROUP BY pmsync.`id_sale`
// ' . ((int) self::TIME_DISPLAY > 0 ? '
// HAVING (
// MAX(pms.date_add) IS NULL
// OR MAX(pmsync.`date_add`) > DATE_SUB(NOW(), INTERVAL ' . self::TIME_DISPLAY . ' DAY)
// OR pmsync.id_sale = 6304
// )' : '') . '
// ORDER BY `sync_date` DESC, `recep_date` DESC');
// self::$_crrlist_cache = $CRR_files;
// return self::$_crrlist_cache;
}
public function displayArchives (){
global $cookie , $currentIndex ;
$base_link = $currentIndex . '&token=' . Tools :: getAdminTokenLite ( 'AdminPhileaMagistor' );
$archives_options = array ();
foreach ( Db :: getInstance () -> executeS ( '
SELECT a . `id_sale` , cl . `name`
FROM `' . _DB_PREFIX_ . 'philea_archive` a
LEFT JOIN `' . _DB_PREFIX_ . 'privatesale` p
ON p . `id_sale` = a . `id_sale`
LEFT JOIN `' . _DB_PREFIX_ . 'category_lang` cl
ON cl . `id_category` = p . `id_category`
AND cl . `id_lang` = ' . Configuration::get(' PS_LANG_DEFAULT ') . '
' ) as $row ){
$archives_options [] = array (
'label' => ( int ) $row [ 'id_sale' ] . ' - ' . $row [ 'name' ],
'value' => ( int ) $row [ 'id_sale' ]
);
}
2016-12-12 18:27:45 +01:00
$helperForm = new HelperFormBootstrap ();
$helperForm -> _select2 = true ;
2016-10-21 16:06:36 +02:00
$helperForm -> _forms = array (
array (
'action' => $base_link ,
2016-12-12 18:27:45 +01:00
'title' => $this -> l ( 'Archives' ),
'icon' => '<span class="glyphicon glyphicon-level-up"></span> ' ,
'class' => 'form-horizontal' ,
'sections' => array (
2016-10-21 16:06:36 +02:00
array (
2016-12-12 18:27:45 +01:00
'inputs' => array (
array (
'type' => 'select2' ,
'class-select' => '' ,
'name' => 'id_sale_unarchive' ,
'label' => $this -> l ( 'Choisir une vente' ),
'options' => $archives_options ,
),
),
'actions' => array (
array (
'type' => 'submit' ,
'class' => 'btn-primary' ,
'name' => 'unarchiveSale' ,
'value' => $this -> l ( 'Désarchiver la vente' )
)
),
'actions-class' => 'text-right' ,
),
2016-10-21 16:06:36 +02:00
),
2016-12-12 18:27:45 +01:00
),
2016-10-21 16:06:36 +02:00
);
return $helperForm -> renderForm ( false , NULL , NULL , true );
}
2016-09-06 15:32:52 +02:00
}