2016-09-06 15:32:52 +02:00
< ? php
require_once ( PS_ADMIN_DIR . '/helpers/HelperForm.php' );
require_once ( PS_ADMIN_DIR . '/helpers/HelperList.php' );
class AdminPhileaMagistor extends AdminTab {
const TIME_DISPLAY = 0 ; // list displaying time in days. 0 to disable
static $_crrlist_cache = NULL ;
public function postProcess () {
if ( Tools :: isSubmit ( 'submitPhilea' )) {
$id_sale = ( int ) Tools :: getValue ( 'id_sale' );
if ( $id_sale ) {
if ( ! Db :: getInstance () -> getRow ( '
SELECT *
2016-09-07 11:42:38 +02:00
FROM `'._DB_PREFIX_.'philea_sync`
2016-09-06 15:32:52 +02:00
WHERE `id_sale` = '.(int) $id_sale.'
AND `status` = 0
' )) {
Db :: getInstance () -> execute ( '
2016-09-07 11:42:38 +02:00
INSERT INTO `'._DB_PREFIX_.'philea_sync`
2016-09-06 15:32:52 +02:00
VALUES (
DEFAULT ,
'.(int) $id_sale.' ,
0 ,
NOW ()
)
' );
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 = '
2016-09-07 11:42:38 +02:00
INSERT INTO `'._DB_PREFIX_.'philea_auto_sync`
2016-09-06 15:32:52 +02:00
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 *
2016-09-07 11:42:38 +02:00
FROM `'._DB_PREFIX_.'philea_sync`
2016-09-06 15:32:52 +02:00
WHERE `id_sale` = '.(int) $id_sale.'
AND ( `status` = 2
OR `status` = 4 )
' )) {
Db :: getInstance () -> ExecuteS ( '
2016-09-07 11:42:38 +02:00
UPDATE `'._DB_PREFIX_.'philea_sync`
2016-09-06 15:32:52 +02:00
SET `status` = 3
WHERE id_sale = '.(int) $id_sale.'
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 ( '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 ();
2016-09-07 11:42:38 +02:00
$sql_insert = 'INSERT INTO `' . _DB_PREFIX_ . 'philea_archive` (`id_sale`, `date_add`) VALUES' ;
2016-09-06 15:32:52 +02:00
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 ( '
2016-09-07 11:42:38 +02:00
DELETE FROM `' . _DB_PREFIX_ . 'philea_archive`
2016-09-06 15:32:52 +02:00
WHERE `id_sale` = ' . (int) Tools::getValue(' id_sale_unarchive ') . '
LIMIT 1
' )){
echo '<p class="conf">' . $this -> l ( 'Vente désarchivée' ) . '</p><br />' ;
}
else {
echo '<p class="error">' . $this -> l ( 'La vente n\'a pas pu être désarchivée.' ) . '</p><br />' ;
}
}
}
public function exportCsv ( $id_sale , $filename ){
$sql = '
SELECT *
2016-09-07 11:42:38 +02:00
FROM `'._DB_PREFIX_.'philea_reception`
2016-09-06 15:32:52 +02:00
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 = '<h2>' . $this -> l ( 'Philea' ) . '</h2>' ;
$base_link = $currentIndex . '&token=' . Tools :: getAdminTokenLite ( 'AdminPhileaMagistor' );
$id_sale_options = array ();
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT p . `id_sale` , c . `name`
FROM `'._DB_PREFIX_.'privatesale` p
LEFT JOIN `'._DB_PREFIX_.'category_lang` c ON ( c . `id_category` = p . `id_category` )
WHERE c . `id_lang` = '.$cookie->id_lang.'
AND p . `date_start` > " 2015-01-01 00:00:00 "
ORDER BY p . `id_sale` DESC
' ) as $row ) {
$id_sale_options [] = array (
'label' => ( int ) $row [ 'id_sale' ] . ' - ' . $row [ 'name' ],
'value' => ( int ) $row [ 'id_sale' ]
);
}
$helperForm = new HelperForm ();
$helperForm -> _forms = array (
array (
'action' => $base_link ,
'legend' => $this -> l ( 'Philea' ),
'inputs' => array (
array (
'type' => 'select' ,
'name' => 'id_sale' ,
'label' => $this -> l ( 'Select a sale' ),
'options' => $id_sale_options ,
'filter' => true ,
'filter_text' => $this -> l ( 'Filter par vente' )
),
array (
'type' => 'checkbox' ,
'name' => 'force_rec_file' ,
'label' => $this -> l ( 'Forcer l\'envoi' ),
'text' => $this -> l ( 'Force un nouvel envoi du fichier REC.' )
)
),
'actions' => array (
array (
'type' => 'submit' ,
'name' => 'submitPhilea' ,
'label' => $this -> l ( 'Envoyer à Philea' )
)
)
)
);
$form .= $helperForm -> renderForm ( false , NULL , NULL , true );
// $form .= '
// <form action="' . $base_link . '" method="post" class="form"><div class="clear"> </div>
// <fieldset><legend>'.$this->l('Philea').'</legend>
// <p class="select">
// <label for="id_sale">'.$this->l('Select a sale').'</label>
// <select name="id_sale" id="id_sale">';
// foreach(Db::getInstance()->ExecuteS('
// SELECT p.`id_sale`, c.`name`
// FROM `'._DB_PREFIX_.'privatesale` p
// LEFT JOIN `'._DB_PREFIX_.'category_lang` c
// ON c.`id_category` = p.`id_category`
// LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` s
// ON s.`id_sale` = p.`id_sale`
// WHERE c.`id_lang` = 2
// AND s.`id_shipping` = '.(int) self::ID_SHIPPING.'
// AND p.`date_start` > "2015-01-01 00:00:00"
// ORDER BY p.`id_sale` DESC
// ') as $row) {
// $form .= '<option value="'.(int) $row['id_sale'].'">'.(int) $row['id_sale'].' - '.$row['name'].'</option>';
// }
// $form .= '</select>
// </p>
// <p class="center submit">
// <input type="submit" class="button" title="'.$this->l('Envoi des fichiers ART et REC').'" value="'.$this->l('Envoyer à Philea').'" name="submitPhilea" />
// </p>
// </fieldset></form>';
//
// <input type="submit" class="button" title="'.$this->l('Programmer l\'export automatique ART et REC').'" value="'.$this->l('Export automatique').'" name="submitPhileaAutoExport" />
$CRR_list = $this -> getCRRList ();
$form .= '
< form id = " upload_form " action = " ' . $base_link . ' " method = " post " class = " form " >< div class = " clear " >& nbsp ; </ div >
< fieldset >< legend > '.$this->l(' Orders CRR ').' </ legend >
< 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 button " name = " philea_archive_submit " value = " ' . $this->l ('Archiver la sélection') . ' " /></ p >
< table class = " table " >
< thead >
< tr >
< th colspan = " 2 " > ' . $this->l(' ID sale ') . ' </ th >
< th width = " 250 " > ' . $this->l(' Name ') . ' </ th >
< th > ' . $this->l(' Date envoi ( ART + REC ) ') . ' </ th >
< th > ' . $this->l(' Télécharger le CRR ') . ' </ th >
< th > ' . $this->l(' Date Reçu CRR ') . ' </ th >
< th > ' . $this->l(' Envoyer la commande ') . ' </ th >
< th > ' . $this->l(' Date envoi ( CMD ) ') . ' </ th >
< th > ' . $this->l(' Envoi auto ') . ' </ th >
</ tr >
</ thead >
< tbody > ' ;
$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';
$form .= ' < tr >
< td >< input type = " checkbox " id = " check_sale_'.(int) $CRR['id_sale'] .' " name = " id_sales[] " value = " '.(int) $CRR['id_sale'] .' " /></ td >
< td >< label style = " float:none; width:auto; padding: 0; text-align: left; font-weight: normal; " 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; " for = " check_sale_'.(int) $CRR['id_sale'] .' " > '.$CRR[' name '].' </ label ></ td >
< td style = " text-align: center; " > '.$CRR[' sync_date '].' </ td >
< td style = " text-align: center; " > ' . $dl_link . ' </ td >
< td style = " text-align: center; " > '.$CRR[' recep_date '].' </ td >
< td style = " text-align: center; " >< a title = " '. $this->l ('Envoi du fichier CDC').' " class = " button upload_link " data - id = " ' . (int) $CRR['id_sale'] . ' " href = " '. $submit_link .' " title = " '. $this->l ('Upload CDC file').' " >< img src = " ../img/admin/export.gif " /> '.$this->l(' Envoyer à Philea ').' </ a ></ td >
< td style = " text-align: center; " > '.$CRR[' sent_date '].' </ td >
< td style = " text-align: center; " > '.$auto_sync_btn.' </ td >
</ tr > ' ;
}
$form .= '
</ tbody >
</ table >
< p >< input type = " submit " class = " btn button " name = " philea_archive_submit " value = " ' . $this->l ('Archiver la sélection') . ' " /></ p >
</ fieldset >
</ form >
< script type = " text/javascript " >
$ ( " document " ) . ready ( function (){
$ ( " .upload_link " ) . click ( function ( e ){
e . preventDefault ();
$ ( " #id_sale_hidden " ) . val ( $ ( this ) . data ( " id " ));
$ ( " #upload_form " ) . submit ();
});
});
</ script >
' ;
$form .= $this -> displayArchives ();
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`
2016-09-07 11:42:38 +02:00
FROM `'._DB_PREFIX_.'philea_sync` pm_sync
LEFT JOIN `'._DB_PREFIX_.'philea_archive` pm_arch
2016-09-06 15:32:52 +02:00
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`
2016-09-07 11:42:38 +02:00
FROM `'._DB_PREFIX_.'philea_reception` pm_r
2016-09-06 15:32:52 +02:00
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` ,
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`
2016-09-07 11:42:38 +02:00
FROM `'._DB_PREFIX_.'philea_auto_sync` pm_as
2016-09-06 15:32:52 +02:00
WHERE `id_sale` IN ( ' . implode(' , ', $id_sales) . ' )
AND pm_as . `active` = 1 ' ;
foreach ( Db :: getInstance () -> executeS ( $sql ) as $row )
$pm_active [] = ( int ) $row [ 'id_sale' ];
$pm_sent = array ();
$sql = '
SELECT
pm_s . `id_sale` ,
MAX ( pm_s . `date_add` ) as `sent_date`
2016-09-07 11:42:38 +02:00
FROM `'._DB_PREFIX_.'philea_sent` pm_s
2016-09-06 15:32:52 +02:00
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 ;
$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' ]
);
}
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
2016-09-07 11:42:38 +02:00
// FROM `'._DB_PREFIX_.'philea_sync` pmsync
// LEFT JOIN `'._DB_PREFIX_.'philea_sent` pms
2016-09-06 15:32:52 +02:00
// 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`
2016-09-07 11:42:38 +02:00
// LEFT JOIN `'._DB_PREFIX_.'philea_reception` pmr
2016-09-06 15:32:52 +02:00
// ON pmsync.`id_sale` = pmr.`id_sale`
2016-09-07 11:42:38 +02:00
// LEFT JOIN `'._DB_PREFIX_.'philea_auto_sync` pmas
2016-09-06 15:32:52 +02:00
// ON pmas.`id_sale` = pmsync.`id_sale`
2016-09-07 11:42:38 +02:00
// LEFT JOIN `'._DB_PREFIX_.'philea_archive` pm_arch
2016-09-06 15:32:52 +02:00
// 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`
2016-09-07 11:42:38 +02:00
FROM `' . _DB_PREFIX_ . 'philea_archive` a
2016-09-06 15:32:52 +02:00
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' ]
);
}
$helperForm = new HelperForm ();
$helperForm -> _forms = array (
array (
'action' => $base_link ,
'legend' => $this -> l ( 'Archives' ),
'inputs' => array (
array (
'type' => 'select' ,
'name' => 'id_sale_unarchive' ,
'label' => $this -> l ( 'Désarchiver une vente' ),
'options' => $archives_options ,
'filter' => true ,
'filter_text' => $this -> l ( 'Filter par vente' )
)
),
'actions' => array (
array (
'type' => 'submit' ,
'name' => 'unarchiveSale' ,
'label' => $this -> l ( 'Désarchiver la vente' )
)
)
)
);
return $helperForm -> renderForm ( false , NULL , NULL , true );
}
}