bebeboutik/adm/pdf.php

357 lines
12 KiB
PHP
Raw Permalink Normal View History

2016-01-04 12:48:08 +01:00
<?php
/*
2016-12-02 10:15:51 +01:00
* 2007-2011 PrestaShop
2016-01-04 12:48:08 +01:00
*
* 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();
2016-01-04 12:48:08 +01:00
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');
2016-12-02 10:15:51 +01:00
2016-01-04 12:48:08 +01:00
$functionArray = array(
'pdf' => 'generateInvoicePDF',
'id_order_slip' => 'generateOrderSlipPDF',
'id_delivery' => 'generateDeliverySlipPDF',
'invoices' => 'generateInvoicesPDF',
'invoices2' => 'generateInvoicesPDF2',
'slips' => 'generateOrderSlipsPDF',
'deliveryslips' => 'generateDeliverySlipsPDF',
'privatesales' => 'generateInvoicesPDFPrivateSales',
'privatesales48h' => 'generateInvoicesPDFPrivateSales48h',
2016-06-10 11:41:50 +02:00
'privatesales48hbis' => 'generateInvoicesPDFPrivateSales48hBis',
2016-01-04 12:48:08 +01:00
'privatesales2' => 'generateInvoicesPDFPrivateSales2',
'privatesalesM2' => 'generateInvoicesPDFPrivateMulti',
'privatesalesM2Bis' => 'generateInvoicesPDFPrivateM2Bis',
2016-06-20 12:49:32 +02:00
'privatesalesM2Plus' => 'generateInvoicesPDFPrivateM2Plus',
2016-01-04 12:48:08 +01:00
'privatesalesM3' => 'generateInvoicesPDFPrivateM3',
'privatesalesAll' => 'generateInvoicesPDFPrivateSalesAll',
2016-06-21 17:18:24 +02:00
'pendingorders' => 'generatePendingOrdersInvoice',
'privatesalesManyOrders' => 'generateManyInvoicesPDF',
2016-01-04 12:48:08 +01:00
);
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);
}
2016-01-04 12:48:08 +01:00
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);
2016-01-04 12:48:08 +01:00
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));
}
2016-12-02 10:15:51 +01:00
if(Tools::getValue('gift')){
PDF::multipleInvoices($orders, false, true, false, true);
} else {
PDF::multipleInvoices($orders, false, true);
}
2016-01-04 12:48:08 +01:00
}
}
}
function generateInvoicesPDFPrivateSales48h()
2016-06-10 11:41:50 +02:00
{
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()
2016-01-04 12:48:08 +01:00
{
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'));
2016-06-10 14:37:34 +02:00
$orders = $sale->getOrdersFromSale($statuts, FALSE, TRUE);
2016-01-04 12:48:08 +01:00
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));
}
2016-06-08 16:56:43 +02:00
2016-06-10 14:52:32 +02:00
$orders2 = array();
foreach (Db::getInstance()->ExecuteS('
2016-06-10 14:37:34 +02:00
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)
2016-06-10 14:52:32 +02:00
') as $row){
$orders2[] = (int)$row['id_order'];
}
2016-06-08 16:56:43 +02:00
if (!empty($orders2)) {
2016-06-10 14:44:45 +02:00
foreach ($orders as $key => $order) {
2016-06-10 14:45:46 +02:00
if (in_array($order, $orders2)) {
2016-06-10 14:44:45 +02:00
unset($orders[$key]);
2016-06-08 16:56:43 +02:00
}
}
}
2016-06-10 14:44:45 +02:00
if (!empty($orders2)) {
PDF::multipleInvoices2($orders, $orders2, true, true);
} else {
PDF::multipleInvoices($orders, false, true, true);
}
2016-01-04 12:48:08 +01:00
}
}
}
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);
2016-01-04 12:48:08 +01:00
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));
}
2016-12-02 10:15:51 +01:00
if(Tools::getValue('gift')){
PDF::multipleInvoices($orders, false, true, false, true);
} else {
PDF::multipleInvoices($orders, false, true);
}
2016-01-04 12:48:08 +01:00
}
}
}
function generateInvoicesPDFPrivateMulti()
{
if(Module::isInstalled('privatesales')) {
include(dirname(__FILE__).'/../modules/privatesales/Sale.php');
if($sale = new Sale((int) Tools::getValue('id_sale'))) {
2016-12-02 10:15:51 +01:00
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
2016-01-04 12:48:08 +01:00
$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);
}
}
}
2016-06-20 12:49:32 +02:00
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';
2016-06-20 12:49:32 +02:00
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'));
$orders = Sale::getOrdersM2($statuts, $id_sales, Tools::getValue('date_from'), Tools::getValue('date_to'), false, $carrier);
2016-06-20 12:49:32 +02:00
if(count($orders) == 0) {
die (Tools::displayError('No invoices found'));
}
2016-12-02 10:15:51 +01:00
if(Tools::getValue('gift')){
PDF::multipleInvoices($orders, false, true, false, true);
} else {
PDF::multipleInvoices($orders, false, true);
}
2016-06-20 12:49:32 +02:00
}
}
}
2016-01-04 12:48:08 +01:00
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'));
2016-12-02 10:15:51 +01:00
2016-01-04 12:48:08 +01:00
$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);
}
2016-06-21 17:18:24 +02:00
function generatePendingOrdersInvoice()
{
$orders = Tools::getValue('orders');
$id_orders = explode(',', $orders);
if (is_array($id_orders)) {
PDF::multipleInvoices($id_orders);
}
}