2016-01-04 12:48:08 +01:00
< ? php
/*
* 2007 - 2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License ( OSL 3.0 )
* that is bundled with this package in the file LICENSE . txt .
* It is also available through the world - wide - web at this URL :
* http :// opensource . org / licenses / osl - 3.0 . php
* If you did not receive a copy of the license and are unable to
* obtain it through the world - wide - web , please send an email
* to license @ prestashop . com so we can send you a copy immediately .
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future . If you wish to customize PrestaShop for your
* needs please refer to http :// www . prestashop . com for more information .
*
* @ author PrestaShop SA < contact @ prestashop . com >
* @ copyright 2007 - 2011 PrestaShop SA
* @ version Release : $Revision : 9146 $
* @ license http :// opensource . org / licenses / osl - 3.0 . php Open Software License ( OSL 3.0 )
* International Registered Trademark & Property of PrestaShop SA
*/
2016-12-23 12:06:36 +01:00
require_once ( PS_ADMIN_DIR . '/helpers/HelperFormBootstrap.php' );
require_once ( PS_ADMIN_DIR . '/helpers/HelperList.php' );
2016-01-04 12:48:08 +01:00
class AdminInvoices extends AdminTab
{
public $print_sales ;
public function __construct ()
{
global $cookie ;
$this -> table = 'invoice' ;
$this -> optionTitle = $this -> l ( 'Invoice options' );
$this -> _fieldsOptions = array (
'PS_INVOICE' => array ( 'title' => $this -> l ( 'Enable invoices:' ), 'desc' => $this -> l ( 'Select whether or not to activate invoices for your shop' ), 'cast' => 'intval' , 'type' => 'bool' ),
'PS_INVOICE_PREFIX' => array ( 'title' => $this -> l ( 'Invoice prefix:' ), 'desc' => $this -> l ( 'Prefix used for invoices' ), 'size' => 6 , 'type' => 'textLang' ),
'PS_INVOICE_START_NUMBER' => array ( 'title' => $this -> l ( 'Invoice number:' ), 'desc' => $this -> l ( 'The next invoice will begin with this number, and then increase with each additional invoice. Set to 0 if you want to keep the current number (#' ) . ( Order :: getLastInvoiceNumber () + 1 ) . ').' , 'size' => 6 , 'type' => 'text' , 'cast' => 'intval' ),
'PS_INVOICE_FREE_TEXT' => array ( 'title' => $this -> l ( 'Free Text:' ), 'desc' => $this -> l ( 'This text will appear at the bottom of the invoice' ), 'size' => 6 , 'type' => 'textareaLang' ,
'cols' => 40 , 'rows' => 8 )
);
parent :: __construct ();
}
public function displayForm ( $isMainTab = true )
{
global $currentIndex , $cookie ;
$statuses = OrderState :: getOrderStates ( $cookie -> id_lang );
$result = Db :: getInstance ( _PS_USE_SQL_SLAVE_ ) -> ExecuteS ( '
SELECT COUNT ( * ) as nbOrders , (
SELECT oh . id_order_state
FROM '._DB_PREFIX_.' order_history oh
WHERE oh . id_order = o . id_order
ORDER BY oh . date_add DESC , oh . id_order_history DESC
LIMIT 1
) id_order_state
FROM '._DB_PREFIX_.' orders o
GROUP BY id_order_state ' );
$statusStats = array ();
foreach ( $result as $row )
$statusStats [ $row [ 'id_order_state' ]] = $row [ 'nbOrders' ];
2016-12-23 12:06:36 +01:00
$helperForm = new HelperFormBootstrap ();
$helperForm -> _inputMask = true ;
$helperForm -> _forms = array (
array (
'action' => $currentIndex . '&token=' . $this -> token ,
'title' => $this -> l ( 'Print PDF ' ) . ' - ' . $this -> l ( 'By date and Sale' ),
'icon' => '<span class="anticon anticon-file-pdf"></span> ' ,
'class' => 'form-horizontal' ,
'class_div' => 'col-md-6' ,
'sections' => array (
array (
'inputs' => array (
array (
'type' => 'simpleDate' ,
'period' => true ,
'class-from' => 'col-md-6' ,
'class-to' => 'col-md-6' ,
'id' => 'date_from' ,
'id-to' => 'date_to' ,
'name' => 'date_from' ,
'name-to' => 'date_to' ,
'label' => $this -> l ( 'De :' ),
'label-to' => $this -> l ( 'A :' ),
'label-class' => 'text-left' ,
'before' => '<span class="glyphicon glyphicon-calendar"></span>' ,
'before-to' => '<span class="glyphicon glyphicon-calendar"></span>' ,
'value' => ( ! empty ( Tools :: getValue ( 'date_from' )) ? Tools :: getValue ( 'date_from' ) : date ( 'Y-m-d' )),
'value-to' => ( ! empty ( Tools :: getValue ( 'date_to' )) ? Tools :: getValue ( 'date_to' ) : date ( 'Y-m-d' )),
),
),
'actions' => array (
array (
'type' => 'submit' ,
'class' => 'btn-primary' ,
'name' => 'submitGetSale' ,
'value' => $this -> l ( 'Get Sales' )
)
),
'actions-class' => 'text-right' ,
),
),
),
array (
'action' => $currentIndex . '&token=' . $this -> token ,
'title' => $this -> l ( 'Print PDF invoices' ) . ' - ' . $this -> l ( 'By date' ),
'icon' => '<span class="anticon anticon-file-pdf"></span> ' ,
'class' => 'form-horizontal' ,
'class_div' => 'col-md-6' ,
'sections' => array (
array (
'inputs' => array (
array (
'type' => 'simpleDate' ,
'period' => true ,
'class-from' => 'col-md-6' ,
'class-to' => 'col-md-6' ,
'id' => 'date_from2' ,
'id-to' => 'date_to2' ,
'name' => 'date_from' ,
'name-to' => 'date_to' ,
'label' => $this -> l ( 'De :' ),
'label-to' => $this -> l ( 'A :' ),
'label-class' => 'text-left' ,
'before' => '<span class="glyphicon glyphicon-calendar"></span>' ,
'before-to' => '<span class="glyphicon glyphicon-calendar"></span>' ,
'value' => date ( 'Y-m-d' ),
'value-to' => date ( 'Y-m-d' ),
),
),
'actions' => array (
array (
'type' => 'submit' ,
'class' => 'btn-primary' ,
'name' => 'submitPrint' ,
'value' => $this -> l ( 'Generate PDF file' )
)
),
'actions-class' => 'text-right' ,
),
),
)
);
2016-01-04 12:48:08 +01:00
2016-12-23 13:04:16 +01:00
$helperForm -> _css .= '
#invoices_form .table tr th {
text - align : center ;
font - size : 12 px ;
}
#invoices_form .table tr td {
border - bottom : 1 px solid #DEDEDE;
color : #000;
height : auto ;
padding : 5 px 4 px ;
vertical - align : middle ;
}
#invoices_form .table tr td label {
font - size : 13 px ;
}
#invoices_form input[type=checkbox],
#invoices_form input[type=radio] {
margin : 0 ;
}
' ;
2016-01-04 12:48:08 +01:00
2016-12-23 12:06:36 +01:00
$helperForm -> _js .= '
< script >
$ ( document ) . ready ( function () {
$ ( " #date_from " ) . inputmask ( " 9999-99-99 " );
$ ( " #date_to " ) . inputmask ( " 9999-99-99 " );
$ ( " #date_from2 " ) . inputmask ( " 9999-99-99 " );
$ ( " #date_to2 " ) . inputmask ( " 9999-99-99 " );
});
</ script > ' ;
2016-01-04 12:48:08 +01:00
2016-12-23 12:06:36 +01:00
$form .= $helperForm -> renderStyle ();
$form .= '<div class="row">' . $helperForm -> renderForm ( false , NULL , NULL , true ) . '</div>' ;
if ( $this -> print_sales ) {
2016-12-23 13:04:16 +01:00
$form .= ' < div class = " panel " >
< div class = " panel-title " >
< h2 > Factures par vente </ h2 >
< div class = " clearfix " ></ div >
</ div >
< div class = " panel-content " >
< form id = " invoices_form " action = " '. $currentIndex .'&token='. $this->token .' " method = " post " >
< table class = " table table-custombordered " > ' ;
2016-01-04 12:48:08 +01:00
2016-06-20 12:49:32 +02:00
/* echo '
2016-01-04 12:48:08 +01:00
< tr >
2016-12-23 12:06:36 +01:00
< td colspan = " 6 " ></ td >
2016-01-04 12:48:08 +01:00
< td align = " center " >< a id = " checkm3 " data - checked = " 0 " href = " # " > '. $this->l(' Check all ') .' </ a ></ td >
2016-06-20 12:49:32 +02:00
</ tr >*/
2016-12-23 12:06:36 +01:00
$form .= ' < tr >
2016-12-23 13:04:16 +01:00
< th colspan = " 2 " > '.$this->l(' ID Sale ').' </ th >
2016-06-20 12:49:32 +02:00
< th > '.$this->l(' Name sale ').' </ th >
2016-12-23 13:04:16 +01:00
< th > '.$this->l(' Date start ').' </ th > ' ;
2016-06-20 12:49:32 +02:00
/*< th align = " center " > 48 h </ th > ' ;
2016-06-10 11:41:50 +02:00
if ( $cookie -> id_employee == 1 ) {
echo '<th align="center">48H bis</th>' ;
2016-06-20 12:49:32 +02:00
} */
2016-12-23 13:04:16 +01:00
$form .= '<th>M1</th>' ;
/*<th>M2</th>*/
$form .= ' < th > M2 +</ th >
< th > Même marque </ th >
< th > All </ th >
< th > '. $this->l(' Delay ') .' </ th >
2016-01-04 12:48:08 +01:00
</ tr > ' ;
// <th align="center">M2\'</th>
2016-08-23 14:26:07 +02:00
$id_sales = unserialize ( Configuration :: get ( " ANT_CHECKED_SALES " ));
2016-01-04 12:48:08 +01:00
foreach ( $this -> print_sales as $key => $sale ) {
if ( $key % 2 == 0 ) {
$class = 'alt_row' ;
} else {
$class = '' ;
}
$date = DateTime :: createFromFormat ( 'Y-m-d H:i:s' , $sale [ 'date_start' ]);
2016-12-23 12:06:36 +01:00
$form .= '<tr class="' . $class . ' " >
2016-12-23 13:04:16 +01:00
< td ></ td >
< td >< label for = " multi_'. $sale['id_sale'] .' " style = " float:none; width:auto; padding: 0; text-align: left; font-weight: normal; margin:0; " > '. $sale[' id_sale '] .' </ label ></ td >
< td >< label for = " multi_'. $sale['id_sale'] .' " style = " float:none; width:auto; padding: 0; text-align: left; font-weight: normal; margin:0; " >< strong > '. $sale[' title '] .' </ strong ></ label ></ td >
< td align = " center " >< p style = " padding:0px;color: #565485;font-size:12px; " > '. $date->format(' Y - m - d ') .' </ p ></ td > ' ;
2016-06-20 12:49:32 +02:00
/*< td align = " center " > ' ;
2016-01-04 12:48:08 +01:00
if ( $sale [ 'delivery_delay' ] == 2
|| $sale [ 'delivery_delay' ] == 6 ) {
echo '<a onclick="this.target=\'_blank\'" href="' . $currentIndex . '&print48h=1&id_sale=' . $sale [ 'id_sale' ] . '&token=' . $this -> token . ' " >
< img src = " ../img/admin/pdf.gif " alt = " " >
</ a > ' ;
} else {
echo '-' ;
2016-06-20 12:49:32 +02:00
} */
/* if ( $cookie -> id_employee == 1 ) {
2016-06-10 11:41:50 +02:00
echo '</td><td align="center">' ;
if ( $sale [ 'delivery_delay' ] == 2
|| $sale [ 'delivery_delay' ] == 6 ) {
echo '<a onclick="this.target=\'_blank\'" href="' . $currentIndex . '&print48hbis=1&id_sale=' . $sale [ 'id_sale' ] . '&token=' . $this -> token . ' " >
< img src = " ../img/admin/pdf.gif " alt = " " >
</ a > ' ;
} else {
echo '-' ;
}
}
2016-06-20 12:49:32 +02:00
echo ' </ td >*/
2016-12-23 12:06:36 +01:00
$form .= ' </ td >
2016-01-04 12:48:08 +01:00
< td align = " center " >
2016-12-21 12:24:31 +01:00
<!-- a title = " Facture - Avec prix " onclick = " this.target= \ '_blank \ ' " href = " '. $currentIndex .'&printM1=1&id_sale='. $sale['id_sale'] .'&token='. $this->token .' " >
2016-12-02 10:15:51 +01:00
< span class = " text-green-light anticon anticon-file-pdf " style = " cursor:pointer; " ></ span >
2016-12-21 12:24:31 +01:00
</ a -->
2016-12-02 10:15:51 +01:00
< a title = " Facture cadeau - Sans prix " onclick = " this.target= \ '_blank \ ' " href = " '. $currentIndex .'&printM1=1&id_sale='. $sale['id_sale'] .'&gift=1&token='. $this->token .' " >
< span class = " text-rose anticon anticon-file-pdf " style = " cursor:pointer; " ></ span >
2016-01-04 12:48:08 +01:00
</ a >
2016-06-20 12:49:32 +02:00
</ td > ' ;
/*< td align = " center " >
2016-01-04 12:48:08 +01:00
< a onclick = " this.target= \ '_blank \ ' " href = " '. $currentIndex .'&printM2=1&id_sale='. $sale['id_sale'] .'&token='. $this->token .' " >
< img src = " ../img/admin/pdf.gif " alt = " " >
</ a >
2016-06-20 12:49:32 +02:00
</ td >*/
2016-08-19 18:08:32 +02:00
2016-12-23 12:06:36 +01:00
$form .= '<td align="center"><input id="multi_' . $sale [ 'id_sale' ] . '" type="checkbox" name="multi2[]" value="' . $sale [ 'id_sale' ] . '" ' . ( in_array (( int ) $sale [ 'id_sale' ], $id_sales ) ? 'checked' : '' ) . ' /></ td >
2016-07-04 17:51:26 +02:00
< td align = " center " >< input id = " multi_plus_'. $sale['id_sale'] .' " type = " checkbox " name = " multiPlus[] " value = " '. $sale['id_sale'] .' " /></ td >
2016-01-04 12:48:08 +01:00
< td align = " center " >
2016-12-21 12:24:31 +01:00
<!-- a onclick = " this.target= \ '_blank \ ' " href = " '. $currentIndex .'&printAll=1&id_sale='. $sale['id_sale'] .'&token='. $this->token .' " >
2016-12-02 10:15:51 +01:00
< span class = " text-green-light anticon anticon-file-pdf " style = " cursor:pointer; " ></ span >
2016-12-21 12:24:31 +01:00
</ a -->
2016-12-02 10:15:51 +01:00
< a onclick = " this.target= \ '_blank \ ' " href = " '. $currentIndex .'&printAll=1&id_sale='. $sale['id_sale'] .'&gift=1&token='. $this->token .' " >
< span class = " text-rose anticon anticon-file-pdf " style = " cursor:pointer; " ></ span >
2016-01-04 12:48:08 +01:00
</ a >
</ td >
2016-12-02 10:15:51 +01:00
< td align = " center " '.($sale[' delivery_delay '] != 1?' style = " background:#f49ac1; " ':' ').' > '.(isset($sale[' delivery_delay_name '])?$sale[' delivery_delay_name ']:' ').' </ td >
2016-01-04 12:48:08 +01:00
</ tr > ' ;
2016-12-23 12:06:36 +01:00
2016-01-04 12:48:08 +01:00
}
// <td align="center"><input id="m2_'. $sale['id_sale'].'" type="checkbox" name="m2[]" value="'.$sale['id_sale'].'" /></td>
2016-12-23 13:04:16 +01:00
2016-12-23 12:06:36 +01:00
$form .= ' < tr >
2016-12-23 13:04:16 +01:00
< td colspan = " 5 " style = " padding:5px; " ></ td > ' ;
2016-12-21 12:24:31 +01:00
// <td colspan="4" style="padding:5px;">
// <input type="hidden" name="date_to" value="'. Tools::getValue('date_to') .'" />
// <input type="hidden" name="date_from" value="'. Tools::getValue('date_from') .'" />
// <label style="float:none;" class="text-green-light "><span class="anticon anticon-file-pdf"></span> '.$this->l('Avec prix').'</label>
// <label style="float:none;" class="text-rose "><span class="anticon anticon-file-pdf"></span> '.$this->l('Sans prix').'</label>
// </td>';
2016-06-20 12:49:32 +02:00
/*< td align = " center " >
2016-01-04 12:48:08 +01:00
< input type = " submit " name = " submitPrintM2Bis " class = " button " value = " '. $this->l ('Print M2 \ '').' " />
2016-06-20 12:49:32 +02:00
</ td >*/
2016-12-23 13:04:16 +01:00
$form .= ' < td align = " center " style = " padding:5px; " >
< input type = " submit " name = " submitPrintM2Plus " class = " btn btn-default btn-xs " value = " '. $this->l ('Print M2+').' " />
< input type = " submit " name = " resetPrintM2Plus " class = " btn btn-default btn-xs " value = " '. $this->l ('Unselect all').' " />
2016-01-04 12:48:08 +01:00
</ td >
2016-12-02 10:15:51 +01:00
< td align = " center " style = " padding:5px; " >
2016-12-23 13:04:16 +01:00
< input type = " submit " name = " submitPrintMPlus " class = " btn btn-default btn-xs " value = " '. $this->l ('Print Même Marque').' " />
2016-12-02 10:15:51 +01:00
</ td >
< td style = " padding:5px; " >
2016-12-23 13:04:16 +01:00
< p >< label style = " float:none; " >< input type = " checkbox " name = " gift " value = " 1 " /> '.$this->l(' Factures Cadeaux ').' </ label ></ p >
2016-07-04 17:51:26 +02:00
</ td >
2016-06-20 12:49:32 +02:00
< td ></ td >
2016-01-04 12:48:08 +01:00
</ tr > ' ;
2016-12-23 12:06:36 +01:00
$form .= ' </ table >
2016-12-23 13:04:16 +01:00
</ form >
</ div >
</ div > ' ;
2016-01-04 12:48:08 +01:00
}
2016-12-23 13:04:16 +01:00
$form .= '<div class="row">' ;
2016-01-04 12:48:08 +01:00
if ( Module :: isInstalled ( 'privatesales' )) {
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
2016-12-23 13:04:16 +01:00
$form .= ' < div class = " col-md-6 " >
< div class = " panel " >
< div class = " panel-title " >
< h2 > '.$this->l(' By private sale ').' </ h2 >
< div class = " clearfix " ></ div >
</ div >
< div class = " panel-content " >
< form action = " '. $currentIndex .'&token='. $this->token .' " method = " post " >
< div >< strong > '.$this->l(' Orders from a single sale ').' </ strong ></ div >
< br />
< label style = " width:90px " > '.$this->l(' Select a sale : ').' </ label >
< div class = " margin-form " style = " padding-left:100px " >< br />
< select name = " id_sale " >
' ;
// foreach(Sale::getSales(NULL, NULL, NULL, NULL, FALSE, FALSE, '`date_start` DESC') as $sale) {
// echo '<option value="'.$sale->id.'">'.$sale->id.' - '.$sale->title[(int) $cookie->id_lang].'</option>';
// }
$form .= ' </ select >
< div class = " clear " ></ div >
</ div >
< div class = " margin-form " style = " padding-left:100px " >
< input type = " submit " value = " '. $this->l ('Generate PDF file').' " name = " submitPrintOneSale " class = " button " />
</ div >
2016-01-04 12:48:08 +01:00
2016-12-23 13:04:16 +01:00
< br />
2016-01-04 12:48:08 +01:00
2016-12-23 13:04:16 +01:00
< div >< strong > '.$this->l(' Orders from multiple sales ').' </ strong ></ div >
< br />
< label style = " width:90px " > '.$this->l(' From : ').' </ label >
< div class = " margin-form " style = " padding-left:100px " >
< input type = " text " size = " 4 " maxlength = " 10 " name = " date_from " value = " '.(date('Y-m-d')).' " style = " width: 120px; " /> < sup >*</ sup >
< p class = " clear " > '.$this->l(' Format : 2007 - 12 - 31 ( inclusive ) ').' </ p >
</ div >
< label style = " width:90px " > '.$this->l(' To : ').' </ label >
< div class = " margin-form " style = " padding-left:100px " >
< input type = " text " size = " 4 " maxlength = " 10 " name = " date_to " value = " '.(date('Y-m-d')).' " style = " width: 120px; " /> < sup >*</ sup >
< p class = " clear " > '.$this->l(' Format : 2008 - 12 - 31 ( inclusive ) ').' </ p >
</ div >
< div class = " margin-form " style = " padding-left:100px " >
< input type = " submit " value = " '. $this->l ('Generate PDF file').' " name = " submitPrintMultipleSales " class = " button " />
</ div >
< div class = " small " >< sup >*</ sup > '.$this->l(' Required fields ').' </ div >
</ form >
< br />< br />
< div style = " padding-left:100px " > ' ;
if ( Tools :: getValue ( 'check_print' )) {
$check = '' ;
$token = Tools :: getAdminTokenLite ( 'AdminOrders' );
foreach ( Db :: getInstance () -> ExecuteS ( '
SELECT *
FROM `'._DB_PREFIX_.'orders` o
WHERE o . `invoice_number` != 0
AND o . `id_order` NOT IN (
SELECT p . `id_order`
FROM `'._DB_PREFIX_.'privatesale_printedinvoices` p
)
' ) as $not_printed ) {
$check .= '<li><a href="/adm/index.php?tab=AdminOrders&vieworder&id_order=' . $not_printed [ 'id_order' ] . '&token=' . $token . '" onclick="window.open(this.href); return false;">' . $not_printed [ 'id_order' ] . '</a></li>' ;
}
$form .= '<strong>' . $this -> l ( 'Unprinted orders:' ) . '</strong><ul>' . $check . '</ul>' ;
} else {
$form .= '<a class="button" href="' . $_SERVER [ 'REQUEST_URI' ] . '&check_print=1">' . $this -> l ( 'Display unprinted orders' ) . '</a>' ;
}
$form .= ' </ div >
< br />
</ div >
2016-01-04 12:48:08 +01:00
</ div >
2016-12-23 13:04:16 +01:00
</ div > ' ;
2016-01-04 12:48:08 +01:00
}
2016-12-23 12:06:36 +01:00
2016-12-23 13:04:16 +01:00
$form .= ' < div class = " col-md-6 " >
< div class = " panel " >
< div class = " panel-title " >
< h2 > '.$this->l(' By statuses ').' </ h2 >
< div class = " clearfix " ></ div >
</ div >
< div class = " panel-content " >
< form action = " '. $currentIndex .'&token='. $this->token .' " method = " post " >
< label style = " width:90px " > '.$this->l(' Statuses ').' :</ label >
< div class = " margin-form " style = " padding-left:100px " >
< ul > ' ;
foreach ( $statuses as $status )
$form .= ' < li style = " list-style: none; " >
< input type = " checkbox " name = " id_order_state[] " value = " '.(int) $status['id_order_state'] .' " id = " id_order_state_'.(int) $status['id_order_state'] .' " >
< label for = " id_order_state_'.(int) $status['id_order_state'] .' " style = " float:none;'.((isset( $statusStats[$status['id_order_state'] ]) AND $statusStats[$status['id_order_state'] ]) ? '' : 'font-weight:normal;').'padding:0;text-align:left;width:100%;color:#000 " >
< img src = " ../img/admin/charged_'.( $status['invoice'] ? 'ok' : 'ko').'.gif " alt = " " />
'.$status[' name '].' ( '.((isset($statusStats[$status[' id_order_state ']]) AND $statusStats[$status[' id_order_state ']]) ? $statusStats[$status[' id_order_state ']] : ' 0 ').' )
</ label >
</ li > ' ;
$form .= ' </ ul >
< p class = " clear " > '.$this->l(' You can also export orders which have not been charged yet . ').' ( < img src = " ../img/admin/charged_ko.gif " alt = " " /> ) </ p >
</ div >
< div class = " margin-form " >
< input type = " submit " value = " '. $this->l ('Generate PDF file').' " name = " submitPrint2 " class = " button " />
</ div >
</ form >
2016-01-04 12:48:08 +01:00
</ div >
2016-12-23 13:04:16 +01:00
</ div >
</ div >
< div class = " clearfix " ></ div > ' ;
2016-01-04 12:48:08 +01:00
2016-12-23 13:04:16 +01:00
$form .= '</div>' ;
2016-12-23 12:06:36 +01:00
$form .= $helperForm -> renderScript ();
echo $form ;
echo ' < script >
$ ( \ ' input [ name = " m2[] " ] \ ' ) . on ( " click " , function ( e ){
2016-01-04 12:48:08 +01:00
if ( $ ( \ ' input [ name = " m2[] " ] : checked\ ' ) . length > 2 ) {
alert ( " You can choose only 2 sales for this export " );
return false ;
} else {
return true ;
}
});
2016-12-23 12:06:36 +01:00
$ ( " #checkm3 " ) . on ( " click " , function ( e ){
2016-01-04 12:48:08 +01:00
e . preventDefault ();
if ( $ ( this ) . attr ( " data-checked " ) == 0 ) {
$ ( \ ' input [ name = " multi3[] " ] \ ' ) . each ( function (){
this . checked = true ;
});
$ ( this ) . attr ( " data-checked " , 1 );
} else if ( $ ( this ) . attr ( " data-checked " ) == 1 ) {
$ ( \ ' input [ name = " multi3[] " ] \ ' ) . each ( function (){
this . checked = false ;
});
$ ( this ) . attr ( " data-checked " , 0 );
}
});
2016-08-22 10:30:03 +02:00
$ ( " input[name=resetPrintM2Plus] " ) . click ( function () {
2016-12-23 12:06:36 +01:00
2016-08-19 18:08:32 +02:00
var haveChecked = $ ( " input[name= \ 'multi2[] \ ']:checked " ) . length > 0 ;
2016-08-22 10:30:03 +02:00
if ( haveChecked && confirm ( \ '' . $this -> l ( " Are you sure to unselect all ? " ) . ' \ ' )) {
2016-08-19 18:08:32 +02:00
$ ( " input[name= \ 'multi2[] \ '] " ) . each ( function () {
$ ( this ) . attr ( \ ' checked\ ' , false );
2016-12-23 12:06:36 +01:00
});
2016-08-19 18:08:32 +02:00
$ . post ( \ ' ajax - tab . php\ ' ,
\ 'action=resetPrintM2Plus&tab=AdminInvoices&token=' . $this -> token . ' \ '
2016-12-23 12:06:36 +01:00
);
2016-08-19 18:08:32 +02:00
}
2016-12-23 12:06:36 +01:00
2016-08-19 18:08:32 +02:00
return false ;
});
2016-01-04 12:48:08 +01:00
</ script > ' ;
return parent :: displayForm ();
}
2016-08-19 18:08:32 +02:00
public function ajaxProcessResetPrintM2Plus ()
{
2016-08-23 14:26:07 +02:00
Configuration :: updateValue ( " ANT_CHECKED_SALES " , '' );
2016-08-19 18:08:32 +02:00
}
2016-01-04 12:48:08 +01:00
public function display ()
{
$this -> displayForm ();
$this -> displayOptionsList ();
}
public function postProcess ()
{
2016-08-23 14:26:07 +02:00
global $currentIndex ;
2016-01-04 12:48:08 +01:00
if ( Tools :: isSubmit ( 'submitPrint' ))
{
if ( ! Validate :: isDate ( Tools :: getValue ( 'date_from' )))
$this -> _errors [] = $this -> l ( 'Invalid from date' );
if ( ! Validate :: isDate ( Tools :: getValue ( 'date_to' )))
$this -> _errors [] = $this -> l ( 'Invalid end date' );
if ( ! sizeof ( $this -> _errors ))
{
$orders = Order :: getOrdersIdInvoiceByDate ( Tools :: getValue ( 'date_from' ), Tools :: getValue ( 'date_to' ), NULL , 'invoice' );
if ( sizeof ( $orders ))
Tools :: redirectAdmin ( 'pdf.php?invoices&date_from=' . urlencode ( Tools :: getValue ( 'date_from' )) . '&date_to=' . urlencode ( Tools :: getValue ( 'date_to' )) . '&token=' . $this -> token );
$this -> _errors [] = $this -> l ( 'No invoice found for this period' );
}
}
elseif ( Tools :: isSubmit ( 'submitPrint2' ))
{
if ( ! is_array ( $statusArray = Tools :: getValue ( 'id_order_state' )) OR ! count ( $statusArray ))
$this -> _errors [] = $this -> l ( 'Invalid order statuses' );
else
{
foreach ( $statusArray as $id_order_state )
if ( count ( $orders = Order :: getOrderIdsByStatus (( int ) $id_order_state )))
Tools :: redirectAdmin ( 'pdf.php?invoices2&id_order_state=' . implode ( '-' , $statusArray ) . '&token=' . $this -> token );
$this -> _errors [] = $this -> l ( 'No invoice found for this status' );
}
}
elseif ( Tools :: isSubmit ( 'submitGetSale' ))
{
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
if ( ! Validate :: isDate ( Tools :: getValue ( 'date_from' )))
$this -> _errors [] = $this -> l ( 'Invalid from date' );
if ( ! Validate :: isDate ( Tools :: getValue ( 'date_to' )))
$this -> _errors [] = $this -> l ( 'Invalid end date' );
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
2016-06-20 12:49:32 +02:00
$sales = Sale :: getSalesByDateBis ( $statuts , Tools :: getValue ( 'date_from' ), Tools :: getValue ( 'date_to' ));
2016-01-04 12:48:08 +01:00
if ( $sales ) {
$this -> print_sales = $sales ;
}
}
// print 48h
elseif ( Tools :: getValue ( 'print48h' ) == 1 )
2016-12-23 12:06:36 +01:00
{
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
2016-01-04 12:48:08 +01:00
if ( $sale = new Sale (( int ) Tools :: getValue ( 'id_sale' ))) {
if ( ! in_array ( $sale -> delivery_delay , array ( 2 , 6 ) )) {
$this -> _errors [] = $this -> l ( 'This sale is not delivery 48h' );
} else {
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
$orders = $sale -> getOrdersFromSale ( $statuts , FALSE , TRUE );
if ( sizeof ( $orders )) {
Tools :: redirectAdmin ( 'pdf.php?privatesales48h&id_sale=' . ( int ) $sale -> id . '&token=' . $this -> token );
}
}
}
$this -> _errors [] = $this -> l ( 'No invoice found for this sale' );
}
2016-06-10 11:41:50 +02:00
// print 48h bis (distinct multi)
elseif ( Tools :: getValue ( 'print48hbis' ) == 1 )
2016-12-23 12:06:36 +01:00
{
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
2016-06-10 11:41:50 +02:00
if ( $sale = new Sale (( int ) Tools :: getValue ( 'id_sale' ))) {
if ( ! in_array ( $sale -> delivery_delay , array ( 2 , 6 ) )) {
$this -> _errors [] = $this -> l ( 'This sale is not delivery 48h' );
} else {
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
$orders = $sale -> getOrdersFromSale ( $statuts , FALSE , TRUE );
if ( sizeof ( $orders )) {
Tools :: redirectAdmin ( 'pdf.php?privatesales48hbis&id_sale=' . ( int ) $sale -> id . '&token=' . $this -> token );
}
}
}
$this -> _errors [] = $this -> l ( 'No invoice found for this sale' );
}
2016-01-04 12:48:08 +01:00
// print printAll
elseif ( Tools :: getValue ( 'printAll' ) == 1 )
2016-12-23 12:06:36 +01:00
{
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
if ( $sale = new Sale (( int ) Tools :: getValue ( 'id_sale' ))) {
2016-01-04 12:48:08 +01:00
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
$orders = $sale -> getOrdersFromSale ( $statuts , FALSE , TRUE );
if ( sizeof ( $orders )) {
2016-12-02 10:15:51 +01:00
if ( Tools :: getValue ( 'gift' ) == 1 ) {
Tools :: redirectAdmin ( 'pdf.php?privatesalesAll&gift=1&id_sale=' . ( int ) $sale -> id . '&token=' . $this -> token );
} else {
Tools :: redirectAdmin ( 'pdf.php?privatesalesAll&id_sale=' . ( int ) $sale -> id . '&token=' . $this -> token );
}
2016-01-04 12:48:08 +01:00
}
}
$this -> _errors [] = $this -> l ( 'No invoice found for this sale' );
}
// print M1
elseif ( Tools :: getValue ( 'printM1' ) == 1 )
2016-12-23 12:06:36 +01:00
{
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
2016-01-04 12:48:08 +01:00
if ( $sale = new Sale (( int ) Tools :: getValue ( 'id_sale' ))) {
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
$orders = $sale -> getOrdersFromSale ( $statuts );
if ( sizeof ( $orders )) {
2016-12-02 10:15:51 +01:00
if ( Tools :: getValue ( 'gift' ) == 1 ) {
Tools :: redirectAdmin ( 'pdf.php?privatesales&gift=1&id_sale=' . ( int ) $sale -> id . '&token=' . $this -> token );
} else {
Tools :: redirectAdmin ( 'pdf.php?privatesales&id_sale=' . ( int ) $sale -> id . '&token=' . $this -> token );
}
2016-01-04 12:48:08 +01:00
}
}
$this -> _errors [] = $this -> l ( 'No invoice found for this sale' );
}
// print M2
elseif ( Tools :: getValue ( 'printM2' ) == 1 )
2016-12-23 12:06:36 +01:00
{
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
2016-01-04 12:48:08 +01:00
if ( $sale = new Sale (( int ) Tools :: getValue ( 'id_sale' ))) {
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
$orders = $sale -> getOrdersFromSaleMulti ( $statuts , 2 );
if ( sizeof ( $orders )) {
Tools :: redirectAdmin ( 'pdf.php?privatesalesM2&id_sale=' . ( int ) $sale -> id . '&token=' . $this -> token );
}
}
$this -> _errors [] = $this -> l ( 'No invoice found for this sale' );
}
// print M2'
elseif ( Tools :: isSubmit ( 'submitPrintM2Bis' )) {
2016-12-23 12:06:36 +01:00
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
2016-01-04 12:48:08 +01:00
$id_sales = Tools :: getValue ( 'm2' );
if ( empty ( $id_sales ) || ( count ( $id_sales ) != 2 ) ) {
$this -> _errors [] = $this -> l ( 'You must select 2 sales for print M2\'' );
} else {
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
$orders = Sale :: getOrdersM3 ( $statuts , $id_sales , Tools :: getValue ( 'date_from' ), Tools :: getValue ( 'date_to' ), true );
if ( sizeof ( $orders )) {
Tools :: redirectAdmin ( 'pdf.php?privatesalesM2Bis&id_sale=' . implode ( ',' , $id_sales ) . '&date_from=' . urlencode ( Tools :: getValue ( 'date_from' )) . '&date_to=' . urlencode ( Tools :: getValue ( 'date_to' )) . '&token=' . $this -> token );
}
$this -> _errors [] = $this -> l ( 'No invoice found for these sales' );
}
}
2016-06-20 12:49:32 +02:00
// print multi (M2+)
elseif ( Tools :: isSubmit ( 'submitPrintM2Plus' )) {
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
$id_sales = Tools :: getValue ( 'multi2' );
2016-06-22 11:48:28 +02:00
2016-08-23 14:26:07 +02:00
Configuration :: updateValue ( " ANT_CHECKED_SALES " , serialize ( $id_sales ));
2016-06-22 11:48:28 +02:00
2016-07-04 17:51:26 +02:00
if ( empty ( $id_sales ) || ( count ( $id_sales ) < 2 ) ) {
$this -> _errors [] = $this -> l ( 'You must select 2 sales minimum for print M2+' );
} else {
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
$orders = Sale :: getOrdersM2 ( $statuts , $id_sales , Tools :: getValue ( 'date_from' ), Tools :: getValue ( 'date_to' ));
if ( sizeof ( $orders )) {
2016-12-02 10:15:51 +01:00
if ( Tools :: getValue ( 'gift' ) == 1 ) {
Tools :: redirectAdmin ( 'pdf.php?privatesalesM2Plus&gift=1&id_sale=' . implode ( ',' , $id_sales ) . '&date_from=' . urlencode ( Tools :: getValue ( 'date_from' )) . '&date_to=' . urlencode ( Tools :: getValue ( 'date_to' )) . '&token=' . $this -> token );
} else {
Tools :: redirectAdmin ( 'pdf.php?privatesalesM2Plus&id_sale=' . implode ( ',' , $id_sales ) . '&date_from=' . urlencode ( Tools :: getValue ( 'date_from' )) . '&date_to=' . urlencode ( Tools :: getValue ( 'date_to' )) . '&token=' . $this -> token );
}
2016-07-04 17:51:26 +02:00
}
$this -> _errors [] = $this -> l ( 'No invoice found for these sales' );
}
}
// print multi with same brand
elseif ( Tools :: isSubmit ( 'submitPrintMPlus' )) {
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
$id_sales = Tools :: getValue ( 'multiPlus' );
2016-06-20 12:49:32 +02:00
if ( empty ( $id_sales ) || ( count ( $id_sales ) < 2 ) ) {
$this -> _errors [] = $this -> l ( 'You must select 2 sales minimum for print M2+' );
} else {
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
$orders = Sale :: getOrdersM2 ( $statuts , $id_sales , Tools :: getValue ( 'date_from' ), Tools :: getValue ( 'date_to' ));
if ( sizeof ( $orders )) {
2016-12-02 10:15:51 +01:00
if ( Tools :: getValue ( 'gift' ) == 1 ) {
Tools :: redirectAdmin ( 'pdf.php?privatesalesM2Plus&gift=1&id_sale=' . implode ( ',' , $id_sales ) . '&date_from=' . urlencode ( Tools :: getValue ( 'date_from' )) . '&date_to=' . urlencode ( Tools :: getValue ( 'date_to' )) . '&token=' . $this -> token );
} else {
Tools :: redirectAdmin ( 'pdf.php?privatesalesM2Plus&id_sale=' . implode ( ',' , $id_sales ) . '&date_from=' . urlencode ( Tools :: getValue ( 'date_from' )) . '&date_to=' . urlencode ( Tools :: getValue ( 'date_to' )) . '&token=' . $this -> token );
}
2016-06-20 12:49:32 +02:00
}
$this -> _errors [] = $this -> l ( 'No invoice found for these sales' );
}
}
2016-01-04 12:48:08 +01:00
// print M3
elseif ( Tools :: isSubmit ( 'submitPrintM3' )) {
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
$id_sales = Tools :: getValue ( 'multi3' );
if ( empty ( $id_sales ) || ( count ( $id_sales ) < 3 ) ) {
$this -> _errors [] = $this -> l ( 'You must select 3 sales minimum for print M3+' );
} else {
$statuts = array ( 17 , Configuration :: get ( 'PS_OS_PAYMENT' ));
$orders = Sale :: getOrdersM3 ( $statuts , $id_sales , Tools :: getValue ( 'date_from' ), Tools :: getValue ( 'date_to' ));
if ( sizeof ( $orders )) {
Tools :: redirectAdmin ( 'pdf.php?privatesalesM3&id_sale=' . implode ( ',' , $id_sales ) . '&date_from=' . urlencode ( Tools :: getValue ( 'date_from' )) . '&date_to=' . urlencode ( Tools :: getValue ( 'date_to' )) . '&token=' . $this -> token );
}
$this -> _errors [] = $this -> l ( 'No invoice found for these sales' );
}
}
elseif ( Tools :: isSubmit ( 'submitOptionsinvoice' ))
{
if (( int )( Tools :: getValue ( 'PS_INVOICE_START_NUMBER' )) != 0 AND ( int )( Tools :: getValue ( 'PS_INVOICE_START_NUMBER' )) <= Order :: getLastInvoiceNumber ())
$this -> _errors [] = $this -> l ( 'Invalid invoice number (must be > ' ) . Order :: getLastInvoiceNumber () . ')' ;
else
parent :: postProcess ();
} elseif ( Module :: isInstalled ( 'privatesales' )) {
include_once ( dirname ( __FILE__ ) . '/../../modules/privatesales/Sale.php' );
if ( Tools :: isSubmit ( 'submitPrintMultipleSales' )) {
if ( ! Validate :: isDate ( Tools :: getValue ( 'date_from' )))
$this -> _errors [] = $this -> l ( 'Invalid from date' );
if ( ! Validate :: isDate ( Tools :: getValue ( 'date_to' )))
$this -> _errors [] = $this -> l ( 'Invalid end date' );
if ( ! sizeof ( $this -> _errors ))
{
$orders = Sale :: getOrdersByDate ( TRUE , Tools :: getValue ( 'date_from' ), Tools :: getValue ( 'date_to' ), Configuration :: get ( 'PS_OS_PAYMENT' ));
if ( sizeof ( $orders )) {
Tools :: redirectAdmin ( 'pdf.php?privatesales2&date_from=' . urlencode ( Tools :: getValue ( 'date_from' )) . '&date_to=' . urlencode ( Tools :: getValue ( 'date_to' )) . '&token=' . $this -> token );
}
$this -> _errors [] = $this -> l ( 'No invoice found for this period' );
}
} elseif ( Tools :: isSubmit ( 'submitPrintOneSale' )) {
if ( $sale = new Sale (( int ) Tools :: getValue ( 'id_sale' ))) {
$orders = $sale -> getOrdersFromSale ( Configuration :: get ( 'PS_OS_PAYMENT' ));
if ( sizeof ( $orders )) {
Tools :: redirectAdmin ( 'pdf.php?privatesales&id_sale=' . ( int ) $sale -> id . '&token=' . $this -> token );
}
}
$this -> _errors [] = $this -> l ( 'No invoice found for this sale' );
}
}
else
parent :: postProcess ();
}
}