update invoice
This commit is contained in:
parent
e7e7f8381c
commit
3d4d7b16e2
28
adm/pdf.php
28
adm/pdf.php
@ -48,6 +48,7 @@ $functionArray = array(
|
||||
'privatesales2' => 'generateInvoicesPDFPrivateSales2',
|
||||
'privatesalesM2' => 'generateInvoicesPDFPrivateMulti',
|
||||
'privatesalesM2Bis' => 'generateInvoicesPDFPrivateM2Bis',
|
||||
'privatesalesM2Plus' => 'generateInvoicesPDFPrivateM2Plus',
|
||||
'privatesalesM3' => 'generateInvoicesPDFPrivateM3',
|
||||
'privatesalesAll' => 'generateInvoicesPDFPrivateSalesAll',
|
||||
);
|
||||
@ -225,6 +226,33 @@ function generateInvoicesPDFPrivateM3()
|
||||
}
|
||||
|
||||
|
||||
function generateInvoicesPDFPrivateM2Plus()
|
||||
{
|
||||
if(Module::isInstalled('privatesales')) {
|
||||
ini_set('max_execution_time', 1800);
|
||||
include(dirname(__FILE__).'/../modules/privatesales/Sale.php');
|
||||
$sales = Tools::getValue('id_sale');
|
||||
$id_sales = explode(',', $sales);
|
||||
if (empty($id_sales) || (count($id_sales) < 2) ) {
|
||||
die (Tools::displayError('You must select 2 sales minimum for print M2+'));
|
||||
} else {
|
||||
if (!Validate::isDate(Tools::getValue('date_from')))
|
||||
die (Tools::displayError('Invalid from date'));
|
||||
if (!Validate::isDate(Tools::getValue('date_from')))
|
||||
die (Tools::displayError('Invalid end date'));
|
||||
|
||||
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
|
||||
$orders = Sale::getOrdersM2($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'));
|
||||
|
||||
if(count($orders) == 0) {
|
||||
die (Tools::displayError('No invoices found'));
|
||||
}
|
||||
PDF::multipleInvoices($orders, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function generateInvoicesPDFPrivateM2Bis()
|
||||
{
|
||||
if(Module::isInstalled('privatesales')) {
|
||||
|
@ -92,23 +92,24 @@ class AdminInvoices extends AdminTab
|
||||
echo '<form action="'.$currentIndex.'&token='.$this->token.'" method="post">
|
||||
<table class="table" style="margin-top:30px; width: 100%">';
|
||||
|
||||
echo '
|
||||
/*echo '
|
||||
<tr>
|
||||
<td colspan="6"></td>
|
||||
<td align="center"><a id="checkm3" data-checked="0" href="#">'. $this->l('Check all') .'</a></td>
|
||||
</tr>
|
||||
<tr>
|
||||
</tr>*/
|
||||
echo '<tr>
|
||||
<th align="center" width="50">'.$this->l('Id Sale').'</th>
|
||||
<th>'.$this->l('Name sale').' (%ean)</th>
|
||||
<th align="center">'.$this->l('Date start').'</th>
|
||||
<th align="center">48h</th>';
|
||||
<th>'.$this->l('Name sale').'</th>
|
||||
<th align="center">'.$this->l('Date start').'</th>';
|
||||
/*<th align="center">48h</th>';
|
||||
if ($cookie->id_employee == 1) {
|
||||
echo '<th align="center">48H bis</th>';
|
||||
}
|
||||
echo '<th align="center">M1</th>
|
||||
<th align="center">M2</th>
|
||||
<th align="center">M3+</th>
|
||||
}*/
|
||||
echo '<th align="center">M1</th>';
|
||||
/*<th align="center">M2</th>*/
|
||||
echo '<th align="center">M2+</th>
|
||||
<th align="center">All</th>
|
||||
<th align="center">'. $this->l('Delay') .'</th>
|
||||
</tr>';
|
||||
// <th align="center">M2\'</th>
|
||||
foreach ($this->print_sales as $key => $sale) {
|
||||
@ -121,9 +122,9 @@ class AdminInvoices extends AdminTab
|
||||
|
||||
echo '<tr class="'.$class.'">
|
||||
<td align="center">'. $sale['id_sale'] .'</td>
|
||||
<td><label for="multi_'.$sale['id_sale'].'" style="text-align: left; font-weight: normal">'. $sale['title'] .' ('. $sale['percent_ean'] .'%)<label></td>
|
||||
<td>'. $date->format('Y-m-d') .'</td>
|
||||
<td align="center">';
|
||||
<td><label for="multi_'.$sale['id_sale'].'" style="text-align: left; font-weight: normal">'. $sale['title'] .'<label></td>
|
||||
<td>'. $date->format('Y-m-d') .'</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.'">
|
||||
@ -131,8 +132,8 @@ class AdminInvoices extends AdminTab
|
||||
</a>';
|
||||
} else {
|
||||
echo '-';
|
||||
}
|
||||
if ($cookie->id_employee == 1) {
|
||||
}*/
|
||||
/*if ($cookie->id_employee == 1) {
|
||||
echo '</td><td align="center">';
|
||||
if ($sale['delivery_delay'] == 2
|
||||
|| $sale['delivery_delay'] == 6) {
|
||||
@ -143,37 +144,41 @@ class AdminInvoices extends AdminTab
|
||||
echo '-';
|
||||
}
|
||||
}
|
||||
echo '</td>*/
|
||||
echo '</td>
|
||||
<td align="center">
|
||||
<a onclick="this.target=\'_blank\'" href="'.$currentIndex.'&printM1=1&id_sale='. $sale['id_sale'] .'&token='.$this->token.'">
|
||||
<img src="../img/admin/pdf.gif" alt="">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center">
|
||||
</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>
|
||||
</td>
|
||||
<td align="center"><input id="multi_'. $sale['id_sale'].'" type="checkbox" name="multi3[]" value="'.$sale['id_sale'].'" /></td>
|
||||
</td>*/
|
||||
echo '<td align="center"><input id="multi_'. $sale['id_sale'].'" type="checkbox" name="multi2[]" 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.'">
|
||||
<img src="../img/admin/pdf.gif" alt="">
|
||||
</a>
|
||||
</td>
|
||||
<td align="center" '.($sale['delivery_delay'] != 1?'style="background:#FFD3D3;"':'').'>'.(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>
|
||||
echo '<tr>
|
||||
<td colspan="5">
|
||||
<td colspan="4">
|
||||
<input type="hidden" name="date_to" value="'. Tools::getValue('date_to') .'" />
|
||||
<input type="hidden" name="date_from" value="'. Tools::getValue('date_from') .'" />
|
||||
</td>
|
||||
<td align="center">
|
||||
</td>';
|
||||
/*<td align="center">
|
||||
<input type="submit" name="submitPrintM2Bis" class="button" value="'.$this->l('Print M2\'').'" />
|
||||
</td>*/
|
||||
echo '<td align="center">
|
||||
<input type="submit" name="submitPrintM2Plus" class="button" value="'.$this->l('Print M2+').'" />
|
||||
</td>
|
||||
<td align="center">
|
||||
<input type="submit" name="submitPrintM3" class="button" value="'.$this->l('Print M3+').'" />
|
||||
</td>
|
||||
<td></td>
|
||||
<td></td>
|
||||
</tr>';
|
||||
echo '</table>
|
||||
</form>';
|
||||
@ -365,7 +370,7 @@ class AdminInvoices extends AdminTab
|
||||
$this->_errors[] = $this->l('Invalid end date');
|
||||
|
||||
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
|
||||
$sales = Sale::getSalesByDate($statuts, Tools::getValue('date_from'), Tools::getValue('date_to'));
|
||||
$sales = Sale::getSalesByDateBis($statuts, Tools::getValue('date_from'), Tools::getValue('date_to'));
|
||||
if($sales) {
|
||||
$this->print_sales = $sales;
|
||||
}
|
||||
@ -458,6 +463,21 @@ class AdminInvoices extends AdminTab
|
||||
$this->_errors[] = $this->l('No invoice found for these sales');
|
||||
}
|
||||
}
|
||||
// print multi (M2+)
|
||||
elseif (Tools::isSubmit('submitPrintM2Plus')) {
|
||||
include_once(dirname(__FILE__).'/../../modules/privatesales/Sale.php');
|
||||
$id_sales = Tools::getValue('multi2');
|
||||
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)) {
|
||||
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);
|
||||
}
|
||||
$this->_errors[] = $this->l('No invoice found for these sales');
|
||||
}
|
||||
}
|
||||
// print M3
|
||||
elseif (Tools::isSubmit('submitPrintM3')) {
|
||||
include_once(dirname(__FILE__).'/../../modules/privatesales/Sale.php');
|
||||
|
@ -803,6 +803,145 @@ class Sale {
|
||||
return $order_print;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $id_status
|
||||
* @param array $id_sales
|
||||
* @param date $date_from, $date_to
|
||||
* @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) {
|
||||
if($id_sales < 2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$orders = array();
|
||||
|
||||
foreach ($id_sales as $key => $id_sale) {
|
||||
$sale = new Sale($id_sale);
|
||||
$products = $sale->getProducts();
|
||||
|
||||
if(count($products) > 0) {
|
||||
if($id_status === NULL) {
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT DISTINCT d.`id_order`
|
||||
FROM `'._DB_PREFIX_.'order_detail` d
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = d.`id_order`
|
||||
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"
|
||||
') as $order) {
|
||||
$orders[] = (int) $order['id_order'];
|
||||
}
|
||||
} else {
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT DISTINCT h1.`id_order` AS `id_order`
|
||||
FROM `'._DB_PREFIX_.'order_history` h1
|
||||
LEFT JOIN `'._DB_PREFIX_.'orders` o ON o.`id_order` = h1.`id_order`
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_history` h2
|
||||
ON (h1.`id_order` = h2.`id_order` AND h1.`id_order_history` < h2.`id_order_history`)
|
||||
WHERE h2.`id_order_history` IS NULL
|
||||
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 h1.`id_order` IN (
|
||||
SELECT DISTINCT `id_order`
|
||||
FROM `'._DB_PREFIX_.'order_detail`
|
||||
WHERE `product_id` IN ('.implode(', ', $products).')
|
||||
)
|
||||
') as $order) {
|
||||
$orders[] = (int) $order['id_order'];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$orders = array_unique($orders);
|
||||
|
||||
if(count($orders) > 0) {
|
||||
$_orders = array();
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT d.`id_order`, p.`id_product`, c.`id_sale`, GREATEST(d.`product_quantity` - d.`product_quantity_return`, 0) AS `product_quantity`
|
||||
FROM `'._DB_PREFIX_.'privatesale_category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON c.`id_category` = p.`id_category_default`
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
|
||||
ON d.`product_id` = p.`id_product`
|
||||
WHERE d.`id_order` IN ('.implode(', ', $orders).')
|
||||
ORDER BY d.`product_quantity` ASC
|
||||
') as $row) {
|
||||
if(!isset($_orders[(int)$row['id_order']])) {
|
||||
$_orders[(int)$row['id_order']] = array();
|
||||
}
|
||||
if(!isset($_orders[(int)$row['id_order']][$row['id_sale']]) ) {
|
||||
$_orders[(int)$row['id_order']][$row['id_sale']] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
$order_print = array();
|
||||
$order_sales = array();
|
||||
|
||||
foreach ($_orders as $key => $order) {
|
||||
|
||||
// supprime les orders avec plus de 2 ventes pour les multi only
|
||||
if($multi_only) {
|
||||
if (count($order) > 2) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// exclu les ventes avec des id_sales non selectionnes
|
||||
$sales_order = array_keys($order);
|
||||
foreach ($sales_order as $sale) {
|
||||
if (!in_array($sale, $id_sales)) {
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$diff = array_intersect($sales_order, $id_sales);
|
||||
if (count($diff) > 1) {
|
||||
$order_sales[(int)$key] = count($diff);
|
||||
}
|
||||
|
||||
if ($multi_only) {
|
||||
// si multionly, test différence exacte
|
||||
if (count($diff) == 2) {
|
||||
$order_print[] = $key;
|
||||
}
|
||||
} else {
|
||||
if (count($diff) >= 2) {
|
||||
$order_print[] = $key;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(count($order_print) > 0) {
|
||||
$printed = array();
|
||||
foreach($order_print as $order) {
|
||||
$printed[] = '('.(int) $order.')';
|
||||
}
|
||||
|
||||
Db::getInstance()->ExecuteS('
|
||||
INSERT IGNORE INTO `'._DB_PREFIX_.'privatesale_printedinvoices`
|
||||
VALUES '.implode(', ', $printed).'
|
||||
');
|
||||
}
|
||||
|
||||
if ($multi_only) {
|
||||
return $order_print;
|
||||
} else {
|
||||
// tri par date pour les M2+
|
||||
|
||||
usort($order_print, function ($a, $b) {
|
||||
return ($order_sales[$a] < $order_sales[$b]) ? -1 : 1;
|
||||
});
|
||||
return $order_print;
|
||||
}
|
||||
|
||||
return $order_print;
|
||||
}
|
||||
|
||||
|
||||
public function getOrdersFromSale($id_status=NULL, $single_only=TRUE, $send_test = FALSE) {
|
||||
$orders = array();
|
||||
@ -1055,6 +1194,75 @@ class Sale {
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function getSalesByDateBis($id_status = array(), $date_start=NULL, $date_end=NULL) {
|
||||
$sales_ids = array();
|
||||
$result = array();
|
||||
|
||||
if($date_start != NULL) {
|
||||
$where[] = ' `invoice_date` >= "'.pSQL($date_start).' 00:00:00"';
|
||||
}
|
||||
if($date_end != NULL) {
|
||||
$where[] = ' `invoice_date` <= "'.pSQL($date_end).' 23:59:59"';
|
||||
}
|
||||
|
||||
foreach(Db::getInstance()->ExecuteS('
|
||||
SELECT DISTINCT h1.`id_order` AS `id_order`
|
||||
FROM `'._DB_PREFIX_.'order_history` h1
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_history` h2
|
||||
ON (h1.`id_order` = h2.`id_order` AND h1.`id_order_history` < h2.`id_order_history`)
|
||||
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_.'orders`
|
||||
'.(count($where) > 0? 'WHERE '.implode(' AND ', $where): '').'
|
||||
)
|
||||
') as $order) {
|
||||
$orders[] = (int) $order['id_order'];
|
||||
}
|
||||
|
||||
$total_orders = count($orders);
|
||||
$_orders = array_chunk($orders, 150);
|
||||
|
||||
foreach ($_orders as $key => $order_ids) {
|
||||
foreach (Db::getInstance()->ExecuteS('
|
||||
SELECT d.`id_order`, p.`id_product`, c.`id_sale`, GREATEST(d.`product_quantity` - d.`product_quantity_return`, 0) AS `product_quantity`, ps.`date_start`
|
||||
FROM `'._DB_PREFIX_.'privatesale_category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'product` p
|
||||
ON c.`id_category` = p.`id_category_default`
|
||||
LEFT JOIN `'._DB_PREFIX_.'privatesale` ps
|
||||
ON ps.`id_sale` = c.`id_sale`
|
||||
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
|
||||
ON d.`product_id` = p.`id_product`
|
||||
WHERE d.`id_order` IN ('.implode(', ', $order_ids).')
|
||||
ORDER BY ps.`date_start` ASC
|
||||
') as $row) {
|
||||
if (!in_array($row['id_sale'], $sales_ids)) {
|
||||
$sales_ids[] = $row['id_sale'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// tri par date de début
|
||||
$sales_ids_bis = array();
|
||||
foreach (Db::getInstance()->ExecuteS('
|
||||
SELECT `id_sale`
|
||||
FROM `'._DB_PREFIX_.'privatesale`
|
||||
WHERE `id_sale` IN ('.implode(', ', $sales_ids).')
|
||||
ORDER BY `date_start` ASC') as $row ) {
|
||||
if (!in_array($row['id_sale'], $sales_ids_bis)) {
|
||||
$sales_ids_bis[] = $row['id_sale'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($sales_ids_bis as $key => $sale_id) {
|
||||
$data = self::_getInfoSaleMore((int)$sale_id);
|
||||
$result[] = $data[0];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
private static function _getNbNoEANProduct($products) {
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT `id_product`
|
||||
@ -1080,6 +1288,24 @@ class Sale {
|
||||
LIMIT 1');
|
||||
}
|
||||
|
||||
private static function _getInfoSaleMore($id_sale) {
|
||||
return Db::getInstance()->executeS('
|
||||
SELECT
|
||||
p.`id_sale`,
|
||||
p.`date_start`,
|
||||
l.`name` as title,
|
||||
p.`delivery_delay` as delivery_delay,
|
||||
dl.`name` as delivery_delay_name
|
||||
FROM `'._DB_PREFIX_.'privatesale` p
|
||||
LEFT JOIN `'._DB_PREFIX_.'privatesale_category` c ON c.`id_sale` = p.`id_sale`
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` l ON l.`id_category` = p.`id_category`
|
||||
LEFT JOIN `'._DB_PREFIX_.'privatesale_delay_lang` dl ON dl.`id_delay` = p.`delivery_delay`
|
||||
WHERE p.`id_sale` = '.(int) $id_sale.'
|
||||
AND l.`id_lang` = '. (int) Context::getContext()->language->id.'
|
||||
AND dl.`id_lang` = '. (int) Context::getContext()->language->id.'
|
||||
LIMIT 1');
|
||||
}
|
||||
|
||||
public static function getOrdersByDate($crossed_only=TRUE, $date_start=NULL, $date_end=NULL, $id_status=NULL) {
|
||||
set_time_limit(180);
|
||||
global $cookie;
|
||||
|
Loading…
Reference in New Issue
Block a user