357 lines
12 KiB
PHP
Executable File
357 lines
12 KiB
PHP
Executable File
<?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: 6594 $
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
|
|
* International Registered Trademark & Property of PrestaShop SA
|
|
*/
|
|
session_start();
|
|
define('PS_ADMIN_DIR', getcwd());
|
|
|
|
include(PS_ADMIN_DIR.'/../config/config.inc.php');
|
|
|
|
/* Header can't be included, so cookie must be created here */
|
|
$cookie = new Cookie('psAdmin');
|
|
if (!$cookie->id_employee)
|
|
Tools::redirectAdmin('login.php');
|
|
|
|
$functionArray = array(
|
|
'pdf' => 'generateInvoicePDF',
|
|
'id_order_slip' => 'generateOrderSlipPDF',
|
|
'id_delivery' => 'generateDeliverySlipPDF',
|
|
'invoices' => 'generateInvoicesPDF',
|
|
'invoices2' => 'generateInvoicesPDF2',
|
|
'slips' => 'generateOrderSlipsPDF',
|
|
'deliveryslips' => 'generateDeliverySlipsPDF',
|
|
'privatesales' => 'generateInvoicesPDFPrivateSales',
|
|
'privatesales48h' => 'generateInvoicesPDFPrivateSales48h',
|
|
'privatesales48hbis' => 'generateInvoicesPDFPrivateSales48hBis',
|
|
'privatesales2' => 'generateInvoicesPDFPrivateSales2',
|
|
'privatesalesM2' => 'generateInvoicesPDFPrivateMulti',
|
|
'privatesalesM2Bis' => 'generateInvoicesPDFPrivateM2Bis',
|
|
'privatesalesM2Plus' => 'generateInvoicesPDFPrivateM2Plus',
|
|
'privatesalesM3' => 'generateInvoicesPDFPrivateM3',
|
|
'privatesalesAll' => 'generateInvoicesPDFPrivateSalesAll',
|
|
'pendingorders' => 'generatePendingOrdersInvoice',
|
|
'privatesalesManyOrders' => 'generateManyInvoicesPDF',
|
|
);
|
|
|
|
foreach ($functionArray as $var => $function)
|
|
if (isset($_GET[$var]))
|
|
{
|
|
call_user_func($function);
|
|
die;
|
|
}
|
|
|
|
|
|
function generateManyInvoicesPDF()
|
|
{
|
|
if (!isset($_SESSION['id_orders']))
|
|
die (Tools::displayError('Missing order ID'));
|
|
$orders = $_SESSION['id_orders'];
|
|
unset($_SESSION['id_orders']);
|
|
session_destroy();
|
|
PDF::multipleInvoices($orders, false, true, false, true);
|
|
}
|
|
|
|
function generateInvoicePDF()
|
|
{
|
|
if (!isset($_GET['id_order']))
|
|
die (Tools::displayError('Missing order ID'));
|
|
$order = new Order((int)($_GET['id_order']));
|
|
if (!Validate::isLoadedObject($order))
|
|
die(Tools::displayError('Cannot find order in database'));
|
|
PDF::invoice($order);
|
|
}
|
|
|
|
function generateOrderSlipPDF()
|
|
{
|
|
$orderSlip = new OrderSlip((int)($_GET['id_order_slip']));
|
|
$order = new Order((int)($orderSlip->id_order));
|
|
if (!Validate::isLoadedObject($order))
|
|
die(Tools::displayError('Cannot find order in database'));
|
|
$order->products = OrderSlip::getOrdersSlipProducts($orderSlip->id, $order);
|
|
$tmp = NULL;
|
|
PDF::invoice($order, 'D', false, $tmp, $orderSlip);
|
|
}
|
|
|
|
function generateDeliverySlipPDF()
|
|
{
|
|
$order = Order::getByDelivery((int)($_GET['id_delivery']));
|
|
if (!Validate::isLoadedObject($order))
|
|
die(Tools::displayError('Cannot find order in database'));
|
|
$tmp = NULL;
|
|
PDF::invoice($order, 'D', false, $tmp, false, $order->delivery_number);
|
|
}
|
|
|
|
function generateInvoicesPDF()
|
|
{
|
|
$orders = Order::getOrdersIdInvoiceByDate($_GET['date_from'], $_GET['date_to'], NULL, 'invoice');
|
|
if (!is_array($orders))
|
|
die (Tools::displayError('No invoices found'));
|
|
PDF::multipleInvoices($orders);
|
|
}
|
|
|
|
function generateInvoicesPDFPrivateSales()
|
|
{
|
|
if(Module::isInstalled('privatesales')) {
|
|
include(dirname(__FILE__).'/../modules/privatesales/Sale.php');
|
|
if($sale = new Sale((int) Tools::getValue('id_sale'))) {
|
|
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
|
|
$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'));
|
|
}
|
|
if(Tools::getValue('gift')){
|
|
PDF::multipleInvoices($orders, false, true, false, true);
|
|
} else {
|
|
PDF::multipleInvoices($orders, false, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function generateInvoicesPDFPrivateSales48h()
|
|
{
|
|
if(Module::isInstalled('privatesales')) {
|
|
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);
|
|
if(count($orders) == 0) {
|
|
die (Tools::displayError('No invoices found'));
|
|
}
|
|
PDF::multipleInvoices($orders, false, true, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
function generateInvoicesPDFPrivateSales48hBis()
|
|
{
|
|
if(Module::isInstalled('privatesales')) {
|
|
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);
|
|
if(count($orders) == 0) {
|
|
die (Tools::displayError('No invoices found'));
|
|
}
|
|
|
|
$orders2 = array();
|
|
foreach (Db::getInstance()->ExecuteS('
|
|
SELECT DISTINCT od.`id_order`
|
|
FROM `'._DB_PREFIX_.'order_detail` od
|
|
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` c ON (c.`id_product` = od.`product_id`)
|
|
LEFT JOIN `'._DB_PREFIX_.'privatesale` s ON (s.`id_sale` = c.`id_sale`)
|
|
WHERE od.`id_order` IN ('.implode(',', $orders).')
|
|
AND od.`product_quantity` - od.`product_quantity_return` != 0
|
|
AND (s.delivery_delay != 2 AND s.delivery_delay != 6)
|
|
') as $row){
|
|
$orders2[] = (int)$row['id_order'];
|
|
}
|
|
if (!empty($orders2)) {
|
|
foreach ($orders as $key => $order) {
|
|
if (in_array($order, $orders2)) {
|
|
unset($orders[$key]);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!empty($orders2)) {
|
|
PDF::multipleInvoices2($orders, $orders2, true, true);
|
|
} else {
|
|
PDF::multipleInvoices($orders, false, true, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function generateInvoicesPDFPrivateSalesAll()
|
|
{
|
|
if(Module::isInstalled('privatesales')) {
|
|
include(dirname(__FILE__).'/../modules/privatesales/Sale.php');
|
|
if($sale = new Sale((int) Tools::getValue('id_sale'))) {
|
|
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
|
|
$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'));
|
|
}
|
|
if(Tools::getValue('gift')){
|
|
PDF::multipleInvoices($orders, false, true, false, true);
|
|
} else {
|
|
PDF::multipleInvoices($orders, false, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
function generateInvoicesPDFPrivateMulti()
|
|
{
|
|
if(Module::isInstalled('privatesales')) {
|
|
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->getOrdersFromSaleMulti($statuts, 2);
|
|
if(count($orders) == 0) {
|
|
die (Tools::displayError('No invoices found'));
|
|
}
|
|
PDF::multipleInvoices($orders, true);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function generateInvoicesPDFPrivateM3()
|
|
{
|
|
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) < 3) ) {
|
|
die (Tools::displayError('You must select 3 sales minimum for print M3+'));
|
|
} 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::getOrdersM3($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 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'));
|
|
|
|
$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'), false, $carrier);
|
|
|
|
if(count($orders) == 0) {
|
|
die (Tools::displayError('No invoices found'));
|
|
}
|
|
if(Tools::getValue('gift')){
|
|
PDF::multipleInvoices($orders, false, true, false, true);
|
|
} else {
|
|
PDF::multipleInvoices($orders, false, true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
function generateInvoicesPDFPrivateM2Bis()
|
|
{
|
|
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 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::getOrdersM3($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'), true);
|
|
|
|
if(count($orders) == 0) {
|
|
die (Tools::displayError('No invoices found'));
|
|
}
|
|
PDF::multipleInvoices($orders);
|
|
}
|
|
}
|
|
}
|
|
|
|
function generateInvoicesPDFPrivateSales2()
|
|
{
|
|
if(Module::isInstalled('privatesales')) {
|
|
ini_set('max_execution_time', 1800);
|
|
include(dirname(__FILE__).'/../modules/privatesales/Sale.php');
|
|
if(Validate::isDate(Tools::getValue('date_from')) && Validate::isDate(Tools::getValue('date_to'))) {
|
|
$orders = Sale::getOrdersByDate(TRUE, Tools::getValue('date_from'), Tools::getValue('date_to'), Configuration::get('PS_OS_PAYMENT'));
|
|
if(count($orders) == 0) {
|
|
die (Tools::displayError('No invoices found'));
|
|
}
|
|
PDF::multipleInvoices($orders);
|
|
}
|
|
}
|
|
}
|
|
|
|
function generateInvoicesPDF2()
|
|
{
|
|
$allOrders = array();
|
|
foreach (explode('-', Tools::getValue('id_order_state')) as $id_order_state)
|
|
if (is_array($orders = Order::getOrderIdsByStatus((int)$id_order_state)))
|
|
$allOrders = array_merge($allOrders, $orders);
|
|
PDF::multipleInvoices($allOrders);
|
|
}
|
|
|
|
function generateOrderSlipsPDF()
|
|
{
|
|
$orderSlips = OrderSlip::getSlipsIdByDate($_GET['date_from'], $_GET['date_to']);
|
|
if (!count($orderSlips))
|
|
die (Tools::displayError('No order slips found'));
|
|
PDF::multipleOrderSlips($orderSlips);
|
|
}
|
|
|
|
function generateDeliverySlipsPDF()
|
|
{
|
|
$slips = unserialize(urldecode($_GET['deliveryslips']));
|
|
if (is_array($slips))
|
|
PDF::multipleDelivery($slips);
|
|
}
|
|
|
|
function generatePendingOrdersInvoice()
|
|
{
|
|
$orders = Tools::getValue('orders');
|
|
$id_orders = explode(',', $orders);
|
|
if (is_array($id_orders)) {
|
|
PDF::multipleInvoices($id_orders);
|
|
}
|
|
}
|