separate la poste invoices and mr invoices

This commit is contained in:
Marion Muszynski 2017-06-16 17:51:19 +02:00
parent dde433e46a
commit dadf16f8fb
3 changed files with 61 additions and 28 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

@ -223,20 +223,20 @@ class AdminInvoices extends AdminTab
<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 - La Poste" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&gift=1&laposte=1&token='.$this->token.'">
<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>
<a title="Facture - Mondial Relay" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&gift=1&mondialrelay=1&token='.$this->token.'">
<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>
<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 title="Facture - La Poste" onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printAll=1&id_sale='. $sale['id_sale'] .'&gift=1&laposte=1&token='.$this->token.'">
<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&mondialrelay=1&token='.$this->token.'">
<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>
@ -615,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);
}
}
}
@ -632,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);
}
}
}
@ -672,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');
@ -682,12 +686,13 @@ 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');
@ -702,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

@ -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'];