Merge branch 'ticket11985-invoiceMR' into develop

This commit is contained in:
Marion Muszynski 2017-06-16 17:51:35 +02:00
commit 8d98b4f8e1
4 changed files with 90 additions and 95 deletions

View File

@ -117,7 +117,8 @@ function generateInvoicesPDFPrivateSales()
include(dirname(__FILE__).'/../modules/privatesales/Sale.php');
if($sale = new Sale((int) Tools::getValue('id_sale'))) {
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = $sale->getOrdersFromSale($statuts);
$carrier = Tools::getValue('carrier')? Tools::getValue('carrier') : 'lp';
$orders = $sale->getOrdersFromSale($statuts, true, false, $carrier);
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));
}
@ -191,7 +192,8 @@ function generateInvoicesPDFPrivateSalesAll()
include(dirname(__FILE__).'/../modules/privatesales/Sale.php');
if($sale = new Sale((int) Tools::getValue('id_sale'))) {
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = $sale->getOrdersFromSale($statuts, FALSE, TRUE);
$carrier = Tools::getValue('carrier') ? Tools::getValue('carrier'):'lp';
$orders = $sale->getOrdersFromSale($statuts, FALSE, TRUE, $carrier);
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));
}
@ -262,8 +264,9 @@ function generateInvoicesPDFPrivateM2Plus()
if (!Validate::isDate(Tools::getValue('date_from')))
die (Tools::displayError('Invalid end date'));
$carrier = Tools::getValue('carrier')?Tools::getValue('carrier'):'lp';
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = Sale::getOrdersM2($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'));
$orders = Sale::getOrdersM2($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'), false, $carrier);
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));

View File

@ -197,27 +197,16 @@ class AdminInvoices extends AdminTab
<form id="invoices_form" action="'.$currentIndex.'&token='.$this->token.'" method="post">
<table class="table table-custombordered">';
/*echo '
<tr>
<td colspan="6"></td>
<td align="center"><a id="checkm3" data-checked="0" href="#">'. $this->l('Check all') .'</a></td>
</tr>*/
$form .= '<tr>
<th colspan="2">'.$this->l('ID Sale').'</th>
<th>'.$this->l('Name sale').'</th>
<th>'.$this->l('Date start').'</th>';
/*<th align="center">48h</th>';
if ($cookie->id_employee == 1) {
echo '<th align="center">48H bis</th>';
}*/
$form .= '<th>M1</th>';
/*<th>M2</th>*/
$form .= '<th>M2+</th>
<th>'.$this->l('Date start').'</th>
<th>M1</th>
<th>M2+</th>
<th>Même marque</th>
<th>All</th>
<th>'. $this->l('Delay') .'</th>
</tr>';
// <th align="center">M2\'</th>
$id_sales = unserialize(Configuration::get("ANT_CHECKED_SALES"));
foreach ($this->print_sales as $key => $sale) {
if( $key%2 == 0) {
@ -231,78 +220,44 @@ class AdminInvoices extends AdminTab
<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>';
/*<td align="center">';
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 '-';
}*/
/*if ($cookie->id_employee == 1) {
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 '-';
}
}
echo '</td>*/
$form .= '</td>
<td align="center"><p style="padding:0px;color: #565485;font-size:12px;">'. $date->format('Y-m-d') .'</p></td>
</td>
<td align="center">
<!--a title="Facture - Avec prix" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
<span class="text-green-light anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a-->
<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>
<a title="Facture - La Poste" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&gift=1&carrier=lp&token='.$this->token.'">
<span class="text-yellow anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
</td>';
/*<td align="center">
<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 title="Facture - Mondial Relay" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&gift=1&carrier=mr&token='.$this->token.'">
<span class="text-red-light anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
</td>*/
$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>
</td>
<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>
<td align="center"><input id="multi_plus_'. $sale['id_sale'].'" type="checkbox" name="multiPlus[]" value="'.$sale['id_sale'].'"/></td>
<td align="center">
<!--a onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printAll=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
<span class="text-green-light anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a-->
<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>
<a title="Facture - La Poste" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printAll=1&id_sale='. $sale['id_sale'] .'&gift=1&carrier=lp&token='.$this->token.'">
<span class="text-yellow anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
<a title="Facture - Mondial Relay" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printAll=1&id_sale='. $sale['id_sale'] .'&gift=1&carrier=mr&token='.$this->token.'">
<span class="text-red-light anticon anticon-file-pdf" style="cursor:pointer;"></span>
</a>
</td>
<td align="center" '.($sale['delivery_delay'] != 1?'style="background:#f49ac1;"':'').'>'.(isset($sale['delivery_delay_name'])?$sale['delivery_delay_name']:'').'</td>
</tr>';
}
// <td align="center"><input id="m2_'. $sale['id_sale'].'" type="checkbox" name="m2[]" value="'.$sale['id_sale'].'" /></td>
$form .= '<tr>
<td colspan="5" style="padding:5px;"></td>';
// <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>';
/*<td align="center">
<input type="submit" name="submitPrintM2Bis" class="button" value="'.$this->l('Print M2\'').'" />
</td>*/
$form .= '<td align="center" style="padding:5px;">
$form .= '
<tr>
<td colspan="5" style="padding:5px;"></td>
<td align="center" 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') .'" />
<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').'" />
<input type="submit" name="submitPrintM2PlusLP" class="btn btn-default btn-xs" value="'.$this->l('M2+ LP').'" />
<input type="submit" name="submitPrintM2PlusMR" class="btn btn-default btn-xs" value="'.$this->l('M2+ MR').'" />
<!-- input type="submit" name="resetPrintM2Plus" class="btn btn-default btn-xs" value="'.$this->l('Unselect all').'" / -->
</td>
<td align="center" style="padding:5px;">
<input type="submit" name="submitPrintMPlus" class="btn btn-default btn-xs" value="'.$this->l('Print Même Marque').'" />
<input type="submit" name="submitPrintMPlusLP" class="btn btn-default btn-xs" value="'.$this->l('LP').'" />
<input type="submit" name="submitPrintMPlusMR" class="btn btn-default btn-xs" value="'.$this->l('MR').'" />
</td>
<td style="padding:5px;">
<p><label style="float:none;"><input type="checkbox" name="gift" value="1" /> '.$this->l('Factures Cadeaux').'</label></p>
@ -660,12 +615,14 @@ class AdminInvoices extends AdminTab
include_once(dirname(__FILE__).'/../../modules/privatesales/Sale.php');
if($sale = new Sale((int) Tools::getValue('id_sale'))) {
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = $sale->getOrdersFromSale($statuts, FALSE, TRUE);
$carrier = Tools::getValue('carrier') ? Tools::getValue('carrier'):'lp';
$orders = $sale->getOrdersFromSale($statuts, FALSE, TRUE, $carrier);
echo '<pre>';var_dump($orders);echo '</pre>';die();
if(sizeof($orders)) {
if(Tools::getValue('gift') == 1) {
Tools::redirectAdmin('pdf.php?privatesalesAll&gift=1&id_sale='.(int) $sale->id.'&token='.$this->token);
Tools::redirectAdmin('pdf.php?privatesalesAll&gift=1&id_sale='.(int) $sale->id.'&carrier='.$carrier.'&token='.$this->token);
} else {
Tools::redirectAdmin('pdf.php?privatesalesAll&id_sale='.(int) $sale->id.'&token='.$this->token);
Tools::redirectAdmin('pdf.php?privatesalesAll&id_sale='.(int) $sale->id.'&carrier='.$carrier.'&token='.$this->token);
}
}
}
@ -677,12 +634,14 @@ class AdminInvoices extends AdminTab
include_once(dirname(__FILE__).'/../../modules/privatesales/Sale.php');
if($sale = new Sale((int) Tools::getValue('id_sale'))) {
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = $sale->getOrdersFromSale($statuts);
$carrier = Tools::getValue('carrier') ? Tools::getValue('carrier'):'lp';
$orders = $sale->getOrdersFromSale($statuts, TRUE, FALSE, $carrier);
echo '<pre>';var_dump($orders);echo '</pre>';die();
if(sizeof($orders)) {
if(Tools::getValue('gift') == 1) {
Tools::redirectAdmin('pdf.php?privatesales&gift=1&id_sale='.(int) $sale->id.'&token='.$this->token);
Tools::redirectAdmin('pdf.php?privatesales&gift=1&id_sale='.(int) $sale->id.(Tools::getValue('carrier')?'&carrier='.Tools::getValue('carrier'):'').'&token='.$this->token);
} else {
Tools::redirectAdmin('pdf.php?privatesales&id_sale='.(int) $sale->id.'&token='.$this->token);
Tools::redirectAdmin('pdf.php?privatesales&id_sale='.(int) $sale->id.(Tools::getValue('carrier')?'&carrier='.Tools::getValue('carrier'):'').'&token='.$this->token);
}
}
}
@ -717,7 +676,7 @@ class AdminInvoices extends AdminTab
}
}
// print multi (M2+)
elseif (Tools::isSubmit('submitPrintM2Plus')) {
elseif (Tools::isSubmit('submitPrintM2PlusLP') || Tools::isSubmit('submitPrintM2PlusMR')) {
include_once(dirname(__FILE__).'/../../modules/privatesales/Sale.php');
$id_sales = Tools::getValue('multi2');
@ -727,19 +686,20 @@ class AdminInvoices extends AdminTab
$this->_errors[] = $this->l('You must select 2 sales minimum for print M2+');
} else {
$statuts = array(17, (int)Configuration::get('PS_OS_PAYMENT'));
$orders = Sale::getOrdersM2($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'));
$carrier = Tools::isSubmit('submitPrintM2PlusMR')?'mr':'lp';
$orders = Sale::getOrdersM2($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'), false, $carrier);
if(sizeof($orders)) {
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);
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')).'&carrier='.$carrier.'&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);
Tools::redirectAdmin('pdf.php?privatesalesM2Plus&id_sale='.implode(',', $id_sales) .'&date_from='.urlencode(Tools::getValue('date_from')).'&date_to='.urlencode(Tools::getValue('date_to')).'&carrier='.$carrier.'&token='.$this->token);
}
}
$this->_errors[] = $this->l('No invoice found for these sales');
}
}
// print multi with same brand
elseif (Tools::isSubmit('submitPrintMPlus')) {
elseif (Tools::isSubmit('submitPrintMPlusLP') || Tools::isSubmit('submitPrintMPlusMR')) {
include_once(dirname(__FILE__).'/../../modules/privatesales/Sale.php');
$id_sales = Tools::getValue('multiPlus');
@ -747,12 +707,13 @@ class AdminInvoices extends AdminTab
$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'));
$carrier = Tools::isSubmit('submitPrintMPlusMR')?'mr':'lp';
$orders = Sale::getOrdersM2($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'), false, $carrier);
if(sizeof($orders)) {
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);
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')).'&carrier='.$carrier.'&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);
Tools::redirectAdmin('pdf.php?privatesalesM2Plus&id_sale='.implode(',', $id_sales) .'&date_from='.urlencode(Tools::getValue('date_from')).'&date_to='.urlencode(Tools::getValue('date_to')).'&carrier='.$carrier.'&token='.$this->token);
}
}
$this->_errors[] = $this->l('No invoice found for these sales');

View File

@ -3362,6 +3362,13 @@ span.anticon{
.text-purple-light{
color: #796dc7!important;
}
.text-yellow{
color: #f2be04!important;
}
.text-red-light{
color: #CA0047!important;
color: #CA0047!important;
}
a.link-anticon{
color: #796dc7!important;
}

View File

@ -810,11 +810,17 @@ class Sale {
* @param boolean $multi_only (if true, check only sales past in params)
* @return array order_print
*/
public static function getOrdersM2($id_status=NULL, $id_sales = array(), $date_from, $date_to, $multi_only = false) {
public static function getOrdersM2($id_status=NULL, $id_sales = array(), $date_from, $date_to, $multi_only = false, $carrier = 'lp') {
if($id_sales < 2) {
return false;
}
if($carrier === "lp") {
$carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_SOCOL')));
} else {
$carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_MR')));
}
$orders = array();
foreach ($id_sales as $key => $id_sale) {
@ -830,6 +836,7 @@ class Sale {
WHERE `product_id` IN ('.implode(', ', $products).')
AND o.`invoice_date` >= "'.pSQL($date_from).' 00:00:00"
AND o.`invoice_date` <= "'.pSQL($date_to).' 23:59:59"
AND o.`id_carrier` IN ('.implode(',', $carriers).')
') as $order) {
$orders[] = (int) $order['id_order'];
}
@ -844,6 +851,7 @@ class Sale {
AND h1.`id_order_state` IN ('.implode(',', $id_status).')
AND o.`invoice_date` >= "'.pSQL($date_from).' 00:00:00"
AND o.`invoice_date` <= "'.pSQL($date_to).' 23:59:59"
AND o.`id_carrier` IN ('.implode(',', $carriers).')
AND h1.`id_order` IN (
SELECT DISTINCT `id_order`
FROM `'._DB_PREFIX_.'order_detail`
@ -951,16 +959,24 @@ class Sale {
}
public function getOrdersFromSale($id_status=NULL, $single_only=TRUE, $send_test = FALSE) {
public function getOrdersFromSale($id_status=NULL, $single_only=TRUE, $send_test = FALSE, $carrier = 'lp') {
$orders = array();
$products = $this->getProducts();
if($carrier === "lp") {
$carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_SOCOL')));
} else {
$carriers = array_map('intval',explode(',', Configuration::get('ANT_CARRIERS_MR')));
}
if(count($products) > 0) {
if($id_status === NULL) {
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_order`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `product_id` IN ('.implode(', ', $products).')
SELECT DISTINCT od.`id_order`
FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = od.`id_order`
WHERE od.`product_id` IN ('.implode(', ', $products).')
AND o.`id_carrier` IN ('.implode(',', $carriers).')
') as $order) {
$orders[] = (int) $order['id_order'];
}
@ -973,9 +989,11 @@ class Sale {
WHERE h2.`id_order_history` IS NULL
AND h1.`id_order_state` IN ( '.implode(',', $id_status) .')
AND h1.`id_order` IN (
SELECT DISTINCT `id_order`
FROM `'._DB_PREFIX_.'order_detail`
WHERE `product_id` IN ('.implode(', ', $products).')
SELECT DISTINCT od.`id_order`
FROM `'._DB_PREFIX_.'order_detail` od
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = od.`id_order`
WHERE od.`product_id` IN ('.implode(', ', $products).')
AND o.`id_carrier` IN ('.implode(',', $carriers).')
)
') as $order) {
$orders[] = (int) $order['id_order'];
@ -985,6 +1003,7 @@ class Sale {
// TEST pour les commandes en 48h
if ($send_test) {
$orders_not_sended = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT(o.`id_order`) AS `id_order`
FROM `'._DB_PREFIX_.'order_detail` od
@ -995,6 +1014,11 @@ class Sale {
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'lapostews` la
WHERE la.`quantity` = (od.`product_quantity` - od.`product_quantity_refunded`)
)
AND od.`id_order_detail` NOT IN (
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'mondialrelay_parcel` mr
WHERE mr.`quantity` = (od.`product_quantity` - od.`product_quantity_refunded`)
)'
) as $order) {
$orders_not_sended[] = $order['id_order'];