Script form server

This commit is contained in:
Michael RICOIS 2017-12-18 17:14:31 +01:00
commit f63b399633
39 changed files with 9268 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
/.settings/
/.buildpath
/.project

42
_cron_vouchers.php Normal file
View File

@ -0,0 +1,42 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
$categories = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_category`
FROM `'._DB_PREFIX_.'category`
WHERE `active` = 1
') as $c) {
$categories[] = $c['id_category'];
}
foreach(Db::getInstance()->ExecuteS('
SELECT `id_discount`
FROM `'._DB_PREFIX_.'discount`
WHERE `date_from` <= NOW()
AND `date_to` > NOW()
AND `quantity` > 0
AND `active` = 1
') as $voucher) {
$voucher_categories = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_category`
FROM `'._DB_PREFIX_.'discount_category`
WHERE `id_discount` = '.(int) $voucher['id_discount'].'
') as $vc) {
$voucher_categories[] = $vc['id_category'];
}
$diff = array_diff($categories, $voucher_categories);
$query = array();
foreach($diff as $d) {
$query[] = '('.$d.', '.(int) $voucher['id_discount'].')';
}
Db::getInstance()->Execute('
INSERT INTO `'._DB_PREFIX_.'discount_category`
VALUES '.implode(', ', $query).'
');
}

35
bbb.php Normal file
View File

@ -0,0 +1,35 @@
<?php
die;
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['HTTP_HOST'] = $_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/config/config.inc.php';
include dirname(__FILE__).'/init.php';
require_once(dirname(__FILE__).'/modules/product_vouchers/product_vouchers.php');
define('_PS_BASE_URL_', 'http://www.bebeboutik.com');
global $cookie;
if (!$cookie || !$cookie->id_lang){
@$cookie->id_lang = 2;
}
$sql = '
SELECT o.`id_order`, (od.`product_quantity` - ( od.`product_quantity_refunded` + od.`product_quantity_return`)) AS `quantity`
FROM `ps_order_detail` od
LEFT JOIN `ps_orders` o ON (o.`id_order` = od.`id_order`)
WHERE o.`valid` = 1
AND od.`product_id` IN (
SELECT cache.`id_product`
FROM `ps_product_ps_cache` cache
WHERE cache.`id_sale` = 3986
)
AND o.id_order <> 238884
';
$details = Db::getInstance()->executeS($sql);
// :215569 => Commande test pour >>>> thibault@antadis.com
// test sendMail
ProductVouchers::sendMail(1, 215569, 'TEST');
foreach ($details as $key => $detail) {
ProductVouchers::associateCodeToOrder(1, $detail['quantity'], $detail['id_order']);
}

48
clean_image.php Executable file
View File

@ -0,0 +1,48 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = 80;
include dirname(__FILE__).'/www/config/config.inc.php';
$link = new Link();
$id_product = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_product`
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_sale` > 2500
AND `id_sale` < 3500
-- AND `id_product` < 100000
') as $row) {
$id_product[] = (int) $row['id_product'];
}
echo count($id_product)."\n\n";
foreach(Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'image`
WHERE `id_product` IN ('.implode(', ', $id_product).')
-- AND `id_product` NOT IN (23606, 3522, 23607, 24483, 11752, 35837, 85644, 124519, 269752)
') as $row) {
$folder = Image::getImgFolderStatic((int) $row['id_image']);
unlink(dirname(__FILE__).'/www/img/p/'.$folder.(int) $row['id_image'].'-thickbox.jpg');
unlink(dirname(__FILE__).'/www/img/p/'.$folder.(int) $row['id_image'].'-small.jpg');
unlink(dirname(__FILE__).'/www/img/p/'.$folder.(int) $row['id_image'].'-medium.jpg');
unlink(dirname(__FILE__).'/www/img/p/'.$folder.(int) $row['id_image'].'-large.jpg');
unlink(dirname(__FILE__).'/www/img/p/'.$folder.(int) $row['id_image'].'-home.jpg');
// unlink(dirname(__FILE__).'/www/img/p/'.(int) $row['id_product'].'-'.(int) $row['id_image'].'-thickbox.jpg');
// unlink(dirname(__FILE__).'/www/img/p/'.(int) $row['id_product'].'-'.(int) $row['id_image'].'-small.jpg');
// unlink(dirname(__FILE__).'/www/img/p/'.(int) $row['id_product'].'-'.(int) $row['id_image'].'-medium.jpg');
// unlink(dirname(__FILE__).'/www/img/p/'.(int) $row['id_product'].'-'.(int) $row['id_image'].'-large.jpg');
// unlink(dirname(__FILE__).'/www/img/p/'.(int) $row['id_product'].'-'.(int) $row['id_image'].'-home.jpg');
if((int) $row['id_product'] % 200 == 0) {
echo $row['id_product']."\n";
}
}

97
cron_criteo.php Executable file
View File

@ -0,0 +1,97 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = 80;
echo "Attente de deploiement !! \n";
die();
include dirname(__FILE__).'/www/config/config.inc.php';
ini_set('memory_limit', '2G');
class XML extends SimpleXMLElement {
public function addChildAuto($name, $value=NULL) {
if(is_string($value)) {
return $this->addChildCDATA($name, $value);
} else {
return $this->addChild($name, $value);
}
}
public function addChildCDATA($name, $value=NULL) {
$new_child = $this->addChild($name);
if ($new_child !== NULL) {
$node = dom_import_simplexml($new_child);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($value));
}
return $new_child;
}
}
setlocale('LC_TIME', 'fr_FR.utf8');
$id_lang = 2;
// --> flux catalogue products
$xml = new XML('<?xml version="1.0" encoding="UTF-8"?><products />');
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT p.`id_product`, p.`price`, p.`quantity`, pl.`name`, pl.`link_rewrite`, cl.`name` as `category_name`, (sp.`reduction`) as `discount`, psl.`description`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'product_ps_cache` psc ON p.`id_product` = psc.`id_product`
LEFT JOIN `'._DB_PREFIX_.'product_lang` pl ON pl.`id_product` = p.`id_product`
LEFT JOIN `'._DB_PREFIX_.'specific_price` sp ON p.`id_product` = sp.`id_product`
LEFT JOIN `'._DB_PREFIX_.'privatesale` ps ON psc.`id_sale` = ps.`id_sale`
LEFT JOIN `'._DB_PREFIX_.'privatesale_site_version` psv ON psv.`id_sale` = ps.`id_sale`
LEFT JOIN `'._DB_PREFIX_.'privatesale_lang` psl ON psl.`id_sale` = ps.`id_sale`
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON ps.`id_category` = cl.`id_category`
WHERE ps.`date_start` < NOW()
AND ps.`date_end` > NOW()
AND ps.`enabled` = 1
AND psv.`version` = "fr"
AND cl.`id_lang` = '.(int) $id_lang.'
AND pl.`id_lang` = '.(int) $id_lang.'
AND psl.`id_lang` = '.(int) $id_lang.'
AND ps.`id_sale` IS NOT NULL
ORDER BY ps.`id_sale`
') as $row) {
$s = $xml->addChildAuto('product');
$s->addAttribute("id",$row['id_product']);
$s->addChildAuto('name', htmlentities($row['name']));
$s->addChildAuto('producturl', 'http://www.bebeboutik.com/?utm_source=retargeting&utm_medium=cpc&utm_campaign=criteo&lp=criteo');
/* Image Cover */
$cover = Product::getCover((int)$row['id_product']);
$link = new Link();
$smallimage = $link->getImageLink($row['link_rewrite'], (int)$cover['id_image'], 'small');
$bigimage = $link->getImageLink($row['link_rewrite'], (int)$cover['id_image'], 'thickbox');
$s->addChildAuto('smallimage', $smallimage);
$s->addChildAuto('bigimage', $bigimage);
$s->addChildAuto('description', htmlentities($row['description']));
/* Prices */
$tax_rate = Tax::getProductTaxRate((int)$row['id_product']);
$retailprice = (float)$row['price'] * (1 + ($tax_rate / 100));
$retailprice = Tools::ps_round($retailprice, 2);
$s->addChildAuto('retailprice', $retailprice);
/* Price with reduction */
$price_notax = (float)$row['price'] * (1 - (float)$row['discount']);
$price = $price_notax * (1 + ($tax_rate / 100));
$price = Tools::ps_round($price, 2);
$s->addChildAuto('price', $price);
$instock = 0;
if((int)$row['quantity']>0) {
$instock = 1;
}
$s->addChildAuto('instock', $instock);
$s->addChildAuto('category1', htmlentities($row['category_name']));
$discount = Tools::ps_round(((float)$row['discount'] * 100), 0);
$s->addChildAuto('discount', $discount);
}
/*file_put_contents(dirname(__FILE__).'/www/criteo_sales.fr.xml', $xml->asXML());*/
file_put_contents(dirname(__FILE__).'/www/modules/criteo_bbb/criteo_sales.fr.xml', $xml->asXML());

21
cron_customer_segmentation.php Executable file
View File

@ -0,0 +1,21 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['SERVER_ADDR'] = '37.187.137.153';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
include dirname(__FILE__).'/www/config/config.inc.php';
if(!class_exists('CustomGroup')){
require_once(_PS_MODULE_DIR_.'ant_customgroup/models/CustomGroup.php');
}
foreach (CustomGroup::getGroups(true) as $custom_group) {
CustomGroup::refreshCustomGroupStatic($custom_group['id_custom_group']);
}
exit;

View File

@ -0,0 +1,37 @@
<?php
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include_once dirname(__FILE__).'/www/config/config.inc.php';
$db = Db::getInstance();
foreach(glob(dirname(__FILE__).'/emarsys/*.csv') as $filename) {
$f = fopen($filename, 'r');
fgetcsv($f);
while($line = fgetcsv($f, 0, ';', '"')) {
if(in_array((int) $line[1], array(0, 1, 2)) && !empty($line[2]) && in_array(strtolower($line[3]), array('vrai', 'faux')) && Validate::isEmail($line[2])) {
if($customer = $db->getRow('
SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer`
WHERE `email` = "'.pSQL($line[2]).'"
')) {
if(strtolower($line[3]) == 'faux') {
$active = 0;
} else {
$active = (int) $line[1];
}
$db->ExecuteS('
UPDATE `'._DB_PREFIX_.'customer`
SET `newsletter` = '.(int) $active.',
`newsletter_date_add` = NOW()
WHERE `email` = "'.pSQL($line[2]).'"
LIMIT 1
');
}
}
}
fclose($f);
rename($filename, str_replace('/emarsys/', '/emarsys_done/', $filename));
}

263
cron_export_cohort.php Normal file
View File

@ -0,0 +1,263 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
ini_set('memory_limit', '4G');
$monthdiff = ((int) date('Y') - 2012 + 1) * 12 - (12 - (int) date('m'));
$file = fopen(dirname(__FILE__).'/extracts/cohort/'.date('Y-m-d').'_1.csv', 'w');
$headers = array(
'date',
'customers',
);
for($i=0; $i < $monthdiff - 1; $i++) {
$headers[] = 'month'.($i > 0? ' + '.$i: '');
}
fputcsv($file, $headers, ';', '"');
for($y=2012, $ynow=(int) date('Y'); $y <= $ynow; $y++) {
for($m=1; $m < 13; $m++) {
if(date('Y-m') == $y.'-'.sprintf('%02d', $m)) {
break;
}
$customers = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_customer`
FROM `'._DB_PREFIX_.'customer`
WHERE `date_add` BETWEEN "'.$y.'-'.sprintf('%02d', $m).'-01 00:00:00" AND "'.($m + 1 > 12? $y + 1: $y).'-'.($m + 1 > 12? '01': sprintf('%02d', $m + 1)).'-01 00:00:00"
') as $row) {
$customers[] = (int) $row['id_customer'];
}
echo $y.'-'.sprintf('%02d', $m);
$results = array($y.'-'.sprintf('%02d', $m), count($customers));
$date = new DateTime($y.'-'.sprintf('%02d', $m).'-01');
for($i = 1; $i < $monthdiff; $i++) {
$d1 = clone $date;
$d2 = clone $date;
$d1->add(new DateInterval('P'.($i - 1).'M'));
$d2->add(new DateInterval('P'.$i.'M'));
$total = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_customer`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_customer` IN ('.implode(', ', $customers).')
AND (`invoice_date` BETWEEN "'.$d1->format('Y-m-d').' 00:00:00" AND "'.$d2->format('Y-m-d').' 00:00:00")
') as $row) {
$total[] = (int) $row['id_customer'];
}
$results[] = count($total);
$customers = array_diff($customers, $total);
echo ' '.$i;
}
fputcsv($file, $results, ';', '"');
echo "\n";
$monthdiff--;
}
}
fclose($file);
/** End of cohort 1 **/
$monthdiff = ((int) date('Y') - 2012 + 1) * 12 - (12 - (int) date('m'));
$file2 = fopen(dirname(__FILE__).'/extracts/cohort/'.date('Y-m-d').'_2.csv', 'w');
$file3 = fopen(dirname(__FILE__).'/extracts/cohort/'.date('Y-m-d').'_3.csv', 'w');
$headers = array(
'date',
'first_orders',
);
for($i=0; $i < $monthdiff - 1; $i++) {
$headers[] = 'month'.($i > 0? ' + '.$i: '');
}
fputcsv($file2, $headers, ';', '"');
fputcsv($file3, $headers, ';', '"');
for($y=2012, $ynow=(int) date('Y'); $y <= $ynow; $y++) {
for($m=1; $m < 13; $m++) {
if(date('Y-m') == $y.'-'.sprintf('%02d', $m)) {
break;
}
$first_orders = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT o.`id_customer`
FROM `'._DB_PREFIX_.'orders` o
INNER JOIN (
SELECT `id_customer`, MIN(`invoice_date`) AS `mindate`
FROM `'._DB_PREFIX_.'orders`
GROUP BY `id_customer`
) o2
ON o.`id_customer` = o2.`id_customer`
WHERE o2.`mindate` BETWEEN "'.$y.'-'.sprintf('%02d', $m).'-01 00:00:00" AND "'.($m + 1 > 12? $y + 1: $y).'-'.($m + 1 > 12? '01': sprintf('%02d', $m + 1)).'-01 00:00:00"
') as $row) {
$first_orders[] = (int) $row['id_customer'];
}
echo $y.'-'.sprintf('%02d', $m);
$results = array($y.'-'.sprintf('%02d', $m), count($first_orders));
$results2 = array($y.'-'.sprintf('%02d', $m), count($first_orders));
$date = new DateTime($y.'-'.sprintf('%02d', $m).'-01');
for($i = 1; $i < $monthdiff; $i++) {
$d1 = clone $date;
$d2 = clone $date;
$d1->add(new DateInterval('P'.($i - 1).'M'));
$d2->add(new DateInterval('P'.$i.'M'));
if(count($first_orders) > 0) {
$total = Db::getInstance()->getValue('
SELECT COUNT(`id_order`)
FROM `'._DB_PREFIX_.'orders`
WHERE `id_customer` IN ('.implode(', ', $first_orders).')
AND (`invoice_date` BETWEEN "'.$d1->format('Y-m-d').' 00:00:00" AND "'.$d2->format('Y-m-d').' 00:00:00")
');
$results[] = $total;
$total2 = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_customer`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_customer` IN ('.implode(', ', $first_orders).')
AND (`invoice_date` BETWEEN "'.$d1->format('Y-m-d').' 00:00:00" AND "'.$d2->format('Y-m-d').' 00:00:00")
') as $row) {
$total2[] = (int) $row['id_customer'];
}
$results2[] = count($total2);
} else {
$results[] = 0;
$results2[] = 0;
}
echo ' '.$i;
}
fputcsv($file2, $results, ';', '"');
fputcsv($file3, $results2, ';', '"');
echo "\n";
$monthdiff--;
}
}
fclose($file2);
fclose($file3);
/** End of cohort 1 **/
$monthdiff = ((int) date('Y') - 2012 + 1) * 12 - (12 - (int) date('m'));
$file4 = fopen(dirname(__FILE__).'/extracts/cohort/'.date('Y-m-d').'_4.csv', 'w');
$headers = array(
'date',
'first_orders',
);
for($i=0; $i < $monthdiff - 1; $i++) {
$headers[] = 'month'.($i > 0? ' + '.$i: '');
}
fputcsv($file4, $headers, ';', '"');
$double_orders_customers = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_customer`
FROM `'._DB_PREFIX_.'orders`
GROUP BY `id_customer`
HAVING COUNT(`id_order`) > 1
') as $row) {
$double_orders_customers[] = (int) $row['id_customer'];
}
for($y=2012, $ynow=(int) date('Y'); $y <= $ynow; $y++) {
for($m=1; $m < 13; $m++) {
if(date('Y-m') == $y.'-'.sprintf('%02d', $m)) {
break;
}
$first_orders = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT o.`id_customer`
FROM `'._DB_PREFIX_.'orders` o
INNER JOIN (
SELECT `id_customer`, MIN(`invoice_date`) AS `mindate`
FROM `'._DB_PREFIX_.'orders`
GROUP BY `id_customer`
) o2
ON o.`id_customer` = o2.`id_customer`
WHERE o2.`mindate` BETWEEN "'.$y.'-'.sprintf('%02d', $m).'-01 00:00:00" AND "'.($m + 1 > 12? $y + 1: $y).'-'.($m + 1 > 12? '01': sprintf('%02d', $m + 1)).'-01 00:00:00"
') as $row) {
if(in_array((int) $row['id_customer'], $double_orders_customers)) {
$first_orders[] = (int) $row['id_customer'];
}
}
echo $y.'-'.sprintf('%02d', $m);
$results = array($y.'-'.sprintf('%02d', $m), count($first_orders));
$date = new DateTime($y.'-'.sprintf('%02d', $m).'-01');
for($i = 1; $i < $monthdiff; $i++) {
$d1 = clone $date;
$d2 = clone $date;
$d1->add(new DateInterval('P'.($i - 1).'M'));
$d2->add(new DateInterval('P'.$i.'M'));
if(count($first_orders) > 0) {
$total = Db::getInstance()->getValue('
SELECT COUNT(`id_order`)
FROM `'._DB_PREFIX_.'orders`
WHERE `id_customer` IN ('.implode(', ', $first_orders).')
AND (`invoice_date` BETWEEN "'.$d1->format('Y-m-d').' 00:00:00" AND "'.$d2->format('Y-m-d').' 00:00:00")
');
$results[] = $total;
} else {
$results[] = 0;
}
echo ' '.$i;
}
fputcsv($file4, $results, ';', '"');
echo "\n";
$monthdiff--;
}
}
fclose($file4);

View File

@ -0,0 +1,841 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
$now = $argv[1].' 00:00:00';
$f = fopen('extracts/monthly_compta/'.date('Y-m-d', strtotime($now)).'_recap.csv', 'w');
$headers = array(
'',
'',
'',
'',
'',
'FRANCE',
'',
'',
'',
'BELGIQUE',
'',
'',
'',
'ESPAGNE',
'',
'',
'',
'',
'ITALIE',
'',
'',
'',
'',
'ALLEMAGNE',
'',
'',
'',
'',
'ROYAUME-UNI',
'',
'',
'',
'',
'LUXEMBOURG',
'',
'',
'',
'',
'PORTUGAL',
'',
'',
'',
'',
'PAYS-BAS',
'',
'',
);
fwrite($f, implode(';', $headers)."\n");
$headers2 = array(
'PAYBOX',
'PAYPAL',
'CDE GRATUITE',
'VTE 20%',
'VTE 5,5%',
'VTE 2,10%',
'PORT',
'DISCOUNT',
'VTE 21%',
'VTE 6%',
'PORT',
'DISCOUNT',
'VTE 21%',
'VTE 4%',
'PORT',
'DISCOUNT',
'VTE 20%',
'VTE 5,5%',
'VTE 2,10%',
'PORT',
'DISCOUNT',
'VTE 20%',
'VTE 5,5%',
'VTE 2,10%',
'PORT',
'DISCOUNT',
'VTE 20%',
'VTE 5,5%',
'VTE 2,10%',
'PORT',
'DISCOUNT',
'VTE 20%',
'VTE 5,5%',
'VTE 2,10%',
'PORT',
'DISCOUNT',
'VTE 20%',
'VTE 5,5%',
'VTE 2,10%',
'PORT',
'DISCOUNT',
'VTE 20%',
'VTE 5,5%',
'VTE 2,10%',
'PORT',
'DISCOUNT',
);
fwrite($f, implode(';', $headers2)."\n");
// ORDERS
$orders = Db::getInstance()->ExecuteS('
SELECT o.`id_order`
FROM `'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'order_detail` d,
`'._DB_PREFIX_.'customer` c
WHERE
(o.valid = 1
OR (
o.valid = 0
AND (
(SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 6
OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 7
OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 11
)
))
AND c.id_customer = o.id_customer
AND d.id_order = o.id_order
AND o.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 2 MONTH, \'%Y-%m-01 00:00:00\')
AND o.date_add <= DATE_FORMAT(LAST_DAY("'.$now.'" - INTERVAL 2 MONTH), \'%Y-%m-%d 23:59:59\')
GROUP BY o.id_order
');
foreach($orders as $o) {
$order = Db::getInstance()->ExecuteS('
SELECT c.*, o.*
FROM `'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'customer` c
WHERE
o.id_order = '.$o['id_order'].'
AND c.`id_customer` = o.`id_customer`
');
$order = $order[0];
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$order_details = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_detail` d
WHERE d.id_order = '.$o['id_order']
);
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_60= array();
$total_taxes_60= array();
$total_products_wo_taxes_40 = array();
$total_taxes_40 = array();
$total_products_wo_taxes_export = array();
// calcul prix d'achat de la commande
$wholesale_price = Db::getInstance()->ExecuteS('
SELECT `wholesale_price`, p.`id_product`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` o ON o.`product_id` = p.`id_product`
WHERE o.`id_order` = '. (int) $order['id_order']
);
$prix_achat = array();
foreach ($wholesale_price as $key => $price) {
$prix_achat[$price['id_product']] = $price['wholesale_price'];
}
$total_achat = 0;
$ldetails = array();
foreach($order_details as $detail) {
$total_achat += $detail['product_quantity'] * $prix_achat[$detail['product_id']];
$ldetails[$detail['id_order_detail']] = $detail;
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '20.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.2);
}
} elseif($detail['tax_rate'] == '21.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.21);
}
} elseif($detail['tax_rate'] == '19.600') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.196);
}
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.055);
}
} elseif($detail['tax_rate'] == '2.100') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.021);
}
} elseif($detail['tax_rate'] == '6.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.060);
} else {
$total_products_wo_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.060);
}
} elseif($detail['tax_rate'] == '4.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.040);
} else {
$total_products_wo_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.040);
}
} else {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
}
} else {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
}
}
$total_tax_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$total_tax_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$total_tax_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$total_tax_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$total_tax_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$total_tax_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$total_tax_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$total_tax_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$total_tax_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$total_tax_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$total_tax_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$total_tax_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$total_tax_60 = 0.0;
foreach($total_products_wo_taxes_60 as $value) {
$total_tax_60 += $value;
}
$_total_taxes_60 = 0.0;
foreach($total_taxes_60 as $value) {
$_total_taxes_60 += $value;
}
$total_tax_40 = 0.0;
foreach($total_products_wo_taxes_40 as $value) {
$total_tax_40 += $value;
}
$_total_taxes_40 = 0.0;
foreach($total_taxes_40 as $value) {
$_total_taxes_40 += $value;
}
$total_tax_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$total_tax_export += $value;
}
$tabs = array(
// fr
8 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// be
3 => array('tax_210' => 0,'tax_60' => 0,'port' => 0,'discount' => 0),
// es
6 => array('tax_210' => 0,'tax_40' => 0,'port' => 0,'discount' => 0),
// it
10 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// de
1 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// gb
17 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// lu
12 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// pt
15 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// nl
13 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
);
switch ($address['id_country']) {
case '8':
$tabs[8] = array(
'tax_200' => $total_tax_200,
'tax_55' => $total_tax_55,
'tax_21' => $total_tax_21,
'port' => (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196),
'discount' => $order['total_discounts']
);
break;
case '3':
$tabs[3] = array(
'tax_210' => $total_tax_210,
'tax_60' => $total_tax_60,
'port' => (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196),
'discount' => $order['total_discounts']
);
break;
case '6':
$tabs[6] = array(
'tax_210' => $total_tax_210,
'tax_40' => $total_tax_40,
'port' => (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196),
'discount' => $order['total_discounts']
);
break;
case '10':
case '1':
case '12':
case '13':
case '15':
case '17':
$tabs[(int)$address['id_country']] = array(
'tax_200' => $total_tax_200,
'tax_55' => $total_tax_55,
'tax_21' => $total_tax_21,
'port' => (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196),
'discount' => $order['total_discounts']
);
break;
default:
break;
}
fwrite($f, implode(';', array(
($order['payment'] == 'Paybox'?1:0),
($order['payment'] == 'PayPal'?1:0),
0,
$tabs[8]['tax_200'],
$tabs[8]['tax_55'],
$tabs[8]['tax_21'],
$tabs[8]['port'],
$tabs[8]['discount'],
$tabs[3]['tax_210'],
$tabs[3]['tax_60'],
$tabs[3]['port'],
$tabs[3]['discount'],
$tabs[6]['tax_210'],
$tabs[6]['tax_40'],
$tabs[6]['port'],
$tabs[6]['discount'],
$tabs[10]['tax_200'],
$tabs[10]['tax_55'],
$tabs[10]['tax_21'],
$tabs[10]['port'],
$tabs[10]['discount'],
$tabs[1]['tax_200'],
$tabs[1]['tax_55'],
$tabs[1]['tax_21'],
$tabs[1]['port'],
$tabs[1]['discount'],
$tabs[17]['tax_200'],
$tabs[17]['tax_55'],
$tabs[17]['tax_21'],
$tabs[17]['port'],
$tabs[17]['discount'],
$tabs[12]['tax_200'],
$tabs[12]['tax_55'],
$tabs[12]['tax_21'],
$tabs[12]['port'],
$tabs[12]['discount'],
$tabs[15]['tax_200'],
$tabs[15]['tax_55'],
$tabs[15]['tax_21'],
$tabs[15]['port'],
$tabs[15]['discount'],
$tabs[13]['tax_200'],
$tabs[13]['tax_55'],
$tabs[13]['tax_21'],
$tabs[13]['port'],
$tabs[13]['discount'],
))."\n");
}
// REFUND
$slips = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_slip` os
WHERE os.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 1 MONTH, \'%Y-%m-01 00:00:00\')
AND os.date_add <= DATE_FORMAT(LAST_DAY("'.$now.'" - INTERVAL 1 MONTH), \'%Y-%m-%d 23:59:59\')
');
if(count($slips) > 0) {
foreach($slips as $slip) {
$order = Db::getInstance()->getRow('
SELECT o.*, c.*
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON o.`id_customer` = c.`id_customer`
WHERE
o.id_order = '.$slip['id_order'].'
');
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$order_details = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_detail` d
WHERE d.id_order = '.(int) $slip['id_order'].'
AND d.`id_order_detail` IN (
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_slip_detail`
WHERE `id_order_slip` = '.(int) $slip['id_order_slip'].'
)
');
$ldetails = array();
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_60 = array();
$total_taxes_60 = array();
$total_products_wo_taxes_40 = array();
$total_taxes_40 = array();
$total_products_wo_taxes_export = array();
foreach($order_details as $detail) {
$ldetails[$detail['id_order_detail']] = $detail;
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '19.600') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.196);
}
} elseif($detail['tax_rate'] == '21.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.21);
}
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.055);
}
} elseif($detail['tax_rate'] == '2.100') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.021);
}
} elseif($detail['tax_rate'] == '20.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.2);
}
} elseif($detail['tax_rate'] == '6.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.06);
} else {
$total_products_wo_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.06);
}
} elseif($detail['tax_rate'] == '4.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.04);
} else {
$total_products_wo_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.04);
}
} else {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
}
} else {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
}
}
$total_tax_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$total_tax_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$total_tax_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$total_tax_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$total_tax_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$total_tax_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$total_tax_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$total_tax_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$total_tax_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$total_tax_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$total_tax_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$total_tax_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$total_tax_60 = 0.0;
foreach($total_products_wo_taxes_60 as $value) {
$total_tax_60 += $value;
}
$_total_taxes_60 = 0.0;
foreach($total_taxes_60 as $value) {
$_total_taxes_60 += $value;
}
$total_tax_40 = 0.0;
foreach($total_products_wo_taxes_40 as $value) {
$total_tax_40 += $value;
}
$_total_taxes_40 = 0.0;
foreach($total_taxes_40 as $value) {
$_total_taxes_40 += $value;
}
$total_tax_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$total_tax_export += $value;
}
$tabs = array(
// fr
8 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// be
3 => array('tax_210' => 0,'tax_60' => 0,'port' => 0,'discount' => 0),
// es
6 => array('tax_210' => 0,'tax_40' => 0,'port' => 0,'discount' => 0),
// it
10 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// de
1 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// gb
17 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// lu
12 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// pt
15 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
// nl
13 => array('tax_200' => 0,'tax_55' => 0,'tax_21' => 0,'port' => 0,'discount' => 0),
);
switch ($address['id_country']) {
case '8':
$tabs[8] = array(
'tax_200' => $total_tax_200,
'tax_55' => $total_tax_55,
'tax_21' => $total_tax_21,
'port' => ($slip['shipping_cost'] == 1? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0),
'discount' => 0.0
);
break;
case '3':
$tabs[3] = array(
'tax_210' => $total_tax_210,
'tax_60' => $total_tax_60,
'port' => ($slip['shipping_cost'] == 1? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0),
'discount' => 0.0
);
break;
case '6':
$tabs[6] = array(
'tax_210' => $total_tax_210,
'tax_40' => $total_tax_40,
'port' => ($slip['shipping_cost'] == 1? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0),
'discount' => 0.0
);
break;
case '10':
case '1':
case '12':
case '13':
case '15':
case '17':
$tabs[(int)$address['id_country']] = array(
'tax_200' => $total_tax_200,
'tax_55' => $total_tax_55,
'tax_21' => $total_tax_21,
'port' => ($slip['shipping_cost'] == 1? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0),
'discount' => 0.0
);
break;
default:
break;
}
fwrite($f, implode(';', array(
($order['payment'] == 'Paybox'?1:0),
($order['payment'] == 'PayPal'?1:0),
0,
'-'.$tabs[8]['tax_200'],
'-'.$tabs[8]['tax_55'],
'-'.$tabs[8]['tax_21'],
'-'.$tabs[8]['port'],
'-'.$tabs[8]['discount'],
'-'.$tabs[3]['tax_210'],
'-'.$tabs[3]['tax_60'],
'-'.$tabs[3]['port'],
'-'.$tabs[3]['discount'],
'-'.$tabs[6]['tax_210'],
'-'.$tabs[6]['tax_40'],
'-'.$tabs[6]['port'],
'-'.$tabs[6]['discount'],
'-'.$tabs[10]['tax_200'],
'-'.$tabs[10]['tax_55'],
'-'.$tabs[10]['tax_21'],
'-'.$tabs[10]['port'],
'-'.$tabs[10]['discount'],
'-'.$tabs[1]['tax_200'],
'-'.$tabs[1]['tax_55'],
'-'.$tabs[1]['tax_21'],
'-'.$tabs[1]['port'],
'-'.$tabs[1]['discount'],
'-'.$tabs[17]['tax_200'],
'-'.$tabs[17]['tax_55'],
'-'.$tabs[17]['tax_21'],
'-'.$tabs[17]['port'],
'-'.$tabs[17]['discount'],
'-'.$tabs[12]['tax_200'],
'-'.$tabs[12]['tax_55'],
'-'.$tabs[12]['tax_21'],
'-'.$tabs[12]['port'],
'-'.$tabs[12]['discount'],
'-'.$tabs[15]['tax_200'],
'-'.$tabs[15]['tax_55'],
'-'.$tabs[15]['tax_21'],
'-'.$tabs[15]['port'],
'-'.$tabs[15]['discount'],
'-'.$tabs[13]['tax_200'],
'-'.$tabs[13]['tax_55'],
'-'.$tabs[13]['tax_21'],
'-'.$tabs[13]['port'],
'-'.$tabs[13]['discount'],
))."\n");
}
}
fclose($f);
exit;

View File

@ -0,0 +1,804 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
ini_set('memory_limit', '8G');
set_time_limit(3600);
//$date_to = '"'.date('Y-m-d').' 00:00:00"';
$date_to = '"'.$argv[1].' 00:00:00"';
//~ $date_to = '"2012-08-27 00:00:00"';
$orders = array();
$shipping = array();
$discounts = array();
$slips = array();
$slips_shipping = array();
$slips_discounts = array();
$orders_date = array();
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT `id_order`
FROM `'._DB_PREFIX_.'order_history`
WHERE (`id_order_state` = 2
OR `id_order_state` = 13)
AND `date_add` >= DATE_FORMAT(DATE_SUB('.$date_to.', INTERVAL 1 DAY), \'%Y-%m-%d 00:00:00\')
AND `date_add` < '.$date_to.'
AND `id_order` NOT IN (
SELECT `id_order`
FROM `'._DB_PREFIX_.'order_history`
WHERE (`id_order_state` = 2
OR `id_order_state` = 13)
AND `date_add` < DATE_FORMAT(DATE_SUB('.$date_to.', INTERVAL 1 DAY), \'%Y-%m-%d 00:00:00\')
)
ORDER BY `id_order`
') as $o) {
$orders_date[] = (int) $o['id_order'];
}
if(count($orders_date) > 0) {
$query = '
SELECT
ps.`id_sale`,
psl.`name` AS sale_title,
o.id_order AS id_order,
o.`id_cart` AS `id_cart`,
c.id_customer AS id_customer,
c.email AS email,
c.firstname AS firstname,
c.lastname AS lastname,
a.firstname AS shipping_firstname,
a.lastname AS shipping_lastname,
a.address1 AS shipping_street,
a.address2 AS shipping_street2,
a.postcode AS shipping_postcode,
a.city AS shipping_city,
a.phone AS shipping_phone,
a.phone_mobile AS shipping_phone_mobile,
REPLACE(REPLACE(REPLACE(a.other, "\n", " "), "\r", " "), " ", " ") AS other_info,
l.name AS shipping_country,
d.product_id AS id_product,
d.product_attribute_id AS id_product_attribute,
d.product_name AS order_product_name,
d.product_quantity AS product_quantity,
d.product_price AS product_price_base_wo_taxes,
d.tax_rate AS tax_rate,
p.name AS product_name,
IF(d.product_attribute_id=0,"",REPLACE(d.product_name, CONCAT(p.name, " - "), "")) AS product_combination,
ROUND((d.product_price * (1 - d.reduction_percent / 100) - d.reduction_amount), 6) AS product_price_wo_taxes,
ROUND((d.product_price * (1 - d.reduction_percent / 100) - d.reduction_amount) * (1 + d.tax_rate / 100), 6) AS product_price,
pr.wholesale_price AS wholesale_price,
pa.wholesale_price AS combination_wholesale_price,
d.product_supplier_reference AS supplier_reference,
o.total_shipping AS total_shipping,
CAST(DATE_SUB('.$date_to.', INTERVAL 1 DAY) AS DATE) AS `date`,
o.invoice_number AS invoice_number,
o.payment AS payment_type,
sl.`name` AS `order_state`,
"" AS `refund_reason`,
"" AS `refund_employee`,
IF(ps.`id_employee` = 0, "", CONCAT(e.`firstname`, " ", e.`lastname`)) AS `sale_employee`,
(SELECT pssl.`value` FROM `'._DB_PREFIX_.'privatesale_shipping_lang` pssl LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` psss ON pssl.`id_shipping` = psss.`id_shipping` WHERE psss.`id_sale` = ps.`id_sale` AND pssl.`id_lang` = 2 LIMIT 1) AS `sale_shipping`,
"" AS `spay_transaction`,
"" AS `paypal_transaction`,
"" AS `picker`,
d.product_ean13 AS product_ean13,
"" AS `vip`
FROM
`'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'customer` c,
`'._DB_PREFIX_.'address` a,
`'._DB_PREFIX_.'privatesale_category` psc,
`'._DB_PREFIX_.'category_lang` psl,
`'._DB_PREFIX_.'country_lang` l,
`'._DB_PREFIX_.'order_state_lang` sl,
`'._DB_PREFIX_.'product` pr,
`'._DB_PREFIX_.'product_lang` p,
`'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
ON pa.id_product_attribute = d.product_attribute_id,
`'._DB_PREFIX_.'privatesale` ps
LEFT JOIN `'._DB_PREFIX_.'employee` e
ON e.`id_employee` = ps.`id_employee`
WHERE c.id_customer = o.id_customer
AND l.id_country = a.id_country
AND l.id_lang = 2
AND psl.`id_lang` = 2
AND psc.`id_category` = (
SELECT `id_category_default`
FROM `ps_product`
WHERE `id_product` = d.product_id LIMIT 1
)
AND ps.`id_sale` = psc.`id_sale`
AND psl.`id_category` = ps.`id_category`
AND o.id_address_delivery = a.id_address
AND d.id_order = o.id_order
AND p.id_product = d.product_id
AND pr.id_product = d.product_id
AND p.id_lang = 2
AND sl.`id_lang` = 2
AND sl.`id_order_state` = (
SELECT h.`id_order_state` FROM `'._DB_PREFIX_.'order_history` h
WHERE h.`id_order` = o.`id_order`
ORDER BY h.`date_add` DESC
LIMIT 1
)
AND o.`id_order` IN ('.implode(', ', $orders_date).')
';
$orders = Db::getInstance()->ExecuteS($query);
$query = '
SELECT
0 AS id_sale,
"" AS sale_title,
o.id_order AS id_order,
o.`id_cart` AS `id_cart`,
c.id_customer AS id_customer,
c.email AS email,
c.firstname AS firstname,
c.lastname AS lastname,
a.firstname AS shipping_firstname,
a.lastname AS shipping_lastname,
a.address1 AS shipping_street,
a.address2 AS shipping_street2,
a.postcode AS shipping_postcode,
a.city AS shipping_city,
a.phone AS shipping_phone,
a.phone_mobile AS shipping_phone_mobile,
REPLACE(REPLACE(REPLACE(a.other, "\n", " "), "\r", " "), " ", " ") AS other_info,
l.name AS shipping_country,
od.id_discount AS id_product,
0 AS id_product_attribute,
od.name AS order_product_name,
1 AS product_quantity,
0-od.value AS product_price_base_wo_taxes,
0 AS tax_rate,
od.name AS product_name,
"" AS product_combination,
0-od.value AS product_price_wo_taxes,
0-od.value AS product_price,
0 AS wholesale_price,
0 AS combination_wholesale_price,
"DISCOUNT" AS supplier_reference,
0 AS total_shipping,
o.date_add AS `date`,
o.invoice_number AS invoice_number,
o.payment AS payment_type,
sl.`name` AS `order_state`,
"" AS `refund_reason`,
"" AS `refund_employee`,
"" AS `sale_employee`,
"" AS `sale_shipping`,
"" AS `spay_transaction`,
"" AS `paypal_transaction`,
"" AS `picker`,
"" AS product_ean13,
"" AS `vip`
FROM
`'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'order_discount` od,
`'._DB_PREFIX_.'customer` c,
`'._DB_PREFIX_.'address` a,
`'._DB_PREFIX_.'order_state_lang` sl,
`'._DB_PREFIX_.'country_lang` l
WHERE c.id_customer = o.id_customer
AND o.`id_order` = od.`id_order`
AND l.id_country = a.id_country
AND l.id_lang = 2
AND o.id_address_delivery = a.id_address
AND sl.`id_lang` = 2
AND sl.`id_order_state` = (
SELECT h.`id_order_state` FROM `'._DB_PREFIX_.'order_history` h
WHERE h.`id_order` = o.`id_order`
ORDER BY h.`date_add` DESC
LIMIT 1
)
AND o.`id_order` IN ('.implode(', ', $orders_date).')
GROUP BY c.id_customer, od.id_discount
';
$discounts = Db::getInstance()->ExecuteS($query);
$query = '
SELECT
0 AS id_sale,
"" AS sale_title,
o.id_order AS id_order,
o.`id_cart` AS `id_cart`,
c.id_customer AS id_customer,
c.email AS email,
c.firstname AS firstname,
c.lastname AS lastname,
a.firstname AS shipping_firstname,
a.lastname AS shipping_lastname,
a.address1 AS shipping_street,
a.address2 AS shipping_street2,
a.postcode AS shipping_postcode,
a.city AS shipping_city,
a.phone AS shipping_phone,
a.phone_mobile AS shipping_phone_mobile,
REPLACE(REPLACE(REPLACE(a.other, "\n", " "), "\r", " "), " ", " ") AS other_info,
l.name AS shipping_country,
ca.id_carrier AS id_product,
0 AS id_product_attribute,
ca.name AS order_product_name,
1 AS product_quantity,
o.total_shipping / (1 + o.carrier_tax_rate / 100) AS product_price_base_wo_taxes,
o.carrier_tax_rate AS tax_rate,
ca.name AS product_name,
"" AS product_combination,
o.total_shipping / (1 + o.carrier_tax_rate / 100) AS product_price_wo_taxes,
o.total_shipping AS product_price,
0 AS wholesale_price,
0 AS combination_wholesale_price,
"SHIPPING" AS supplier_reference,
0 AS total_shipping,
o.date_add AS `date`,
o.invoice_number AS invoice_number,
o.payment AS payment_type,
sl.`name` AS `order_state`,
"" AS `refund_reason`,
"" AS `refund_employee`,
"" AS `sale_employee`,
"" AS `sale_shipping`,
"" AS product_ean13,
"" AS `vip`
FROM
`'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'carrier` ca,
`'._DB_PREFIX_.'customer` c,
`'._DB_PREFIX_.'address` a,
`'._DB_PREFIX_.'order_state_lang` sl,
`'._DB_PREFIX_.'country_lang` l
WHERE c.id_customer = o.id_customer
AND l.id_country = a.id_country
AND l.id_lang = 2
AND o.id_address_delivery = a.id_address
AND o.id_carrier = ca.id_carrier
AND sl.`id_lang` = 2
AND o.id_address_delivery = a.id_address
AND sl.`id_lang` = 2
AND sl.`id_order_state` = (
SELECT h.`id_order_state` FROM `'._DB_PREFIX_.'order_history` h
WHERE h.`id_order` = o.`id_order`
ORDER BY h.`date_add` DESC
LIMIT 1
)
AND o.`id_order` IN ('.implode(', ', $orders_date).')
';
$shipping = Db::getInstance()->ExecuteS($query);
}
$query = '
SELECT
ps.`id_sale`,
psl.`name` AS sale_title,
o.id_order AS id_order,
o.`id_cart` AS `id_cart`,
c.id_customer AS id_customer,
c.email AS email,
c.firstname AS firstname,
c.lastname AS lastname,
a.firstname AS shipping_firstname,
a.lastname AS shipping_lastname,
a.address1 AS shipping_street,
a.address2 AS shipping_street2,
a.postcode AS shipping_postcode,
a.city AS shipping_city,
a.phone AS shipping_phone,
a.phone_mobile AS shipping_phone_mobile,
REPLACE(REPLACE(REPLACE(a.other, "\n", " "), "\r", " "), " ", " ") AS other_info,
l.name AS shipping_country,
d.product_id AS id_product,
d.product_attribute_id AS id_product_attribute,
d.product_name AS order_product_name,
-osd.product_quantity AS product_quantity,
d.product_price AS product_price_base_wo_taxes,
d.tax_rate AS tax_rate,
p.name AS product_name,
IF(d.product_attribute_id=0,"",REPLACE(d.product_name, CONCAT(p.name, " - "), "")) AS product_combination,
ROUND((d.product_price * (1 - d.reduction_percent / 100) - d.reduction_amount), 6) AS product_price_wo_taxes,
ROUND((d.product_price * (1 - d.reduction_percent / 100) - d.reduction_amount) * (1 + d.tax_rate / 100), 6) AS product_price,
pr.wholesale_price AS wholesale_price,
pa.wholesale_price AS combination_wholesale_price,
d.product_supplier_reference AS supplier_reference,
o.total_shipping AS total_shipping,
oss.date_add AS `date`,
o.invoice_number AS invoice_number,
o.payment AS payment_type,
sl.`name` AS `order_state`,
IFNULL((SELECT `id_reason` FROM `'._DB_PREFIX_.'refundreason` rr WHERE rr.`id_order_slip` = oss.`id_order_slip` LIMIT 1), "---") AS `refund_reason`,
IFNULL((SELECT CONCAT(`firstname`, " ", `lastname`) FROM `'._DB_PREFIX_.'employee` WHERE `id_employee` = (SELECT rr.`id_employee` FROM `'._DB_PREFIX_.'refundreason` rr WHERE rr.`id_order_slip` = oss.`id_order_slip` LIMIT 1)), "") AS `refund_employee`,
IF(ps.`id_employee` = 0, "", CONCAT(e.`firstname`, " ", e.`lastname`)) AS `sale_employee`,
(SELECT pssl.`value` FROM `'._DB_PREFIX_.'privatesale_shipping_lang` pssl LEFT JOIN `'._DB_PREFIX_.'privatesale_shipping_sale` psss ON pssl.`id_shipping` = psss.`id_shipping` WHERE psss.`id_sale` = ps.`id_sale` AND pssl.`id_lang` = 2 LIMIT 1) AS `sale_shipping`,
"" AS `spay_transaction`,
"" AS `paypal_transaction`,
"" AS `picker`,
d.product_ean13 AS product_ean13,
"" AS `vip`
FROM
`'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'customer` c,
`'._DB_PREFIX_.'address` a,
`'._DB_PREFIX_.'order_state_lang` sl,
`'._DB_PREFIX_.'country_lang` l,
`'._DB_PREFIX_.'product` pr,
`'._DB_PREFIX_.'product_lang` p,
`'._DB_PREFIX_.'privatesale_category` psc,
`'._DB_PREFIX_.'category_lang` psl,
`'._DB_PREFIX_.'order_slip` oss,
`'._DB_PREFIX_.'order_slip_detail` osd,
`'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'product_attribute` pa
ON pa.id_product_attribute = d.product_attribute_id,
`'._DB_PREFIX_.'privatesale` ps
LEFT JOIN `'._DB_PREFIX_.'employee` e
ON e.`id_employee` = ps.`id_employee`
WHERE c.id_customer = o.id_customer
AND l.id_country = a.id_country
AND l.id_lang = 2
AND ps.`id_sale` = psc.`id_sale`
AND psl.`id_lang` = 2
AND psc.`id_category` = (
SELECT `id_category_default`
FROM `ps_product`
WHERE `id_product` = d.product_id LIMIT 1
)
AND psl.`id_category` = ps.`id_category`
AND o.id_address_delivery = a.id_address
AND d.id_order = o.id_order
AND p.id_product = d.product_id
AND sl.`id_lang` = 2
AND sl.`id_order_state` =(
SELECT h.`id_order_state`
FROM `'._DB_PREFIX_.'order_history` h
WHERE h.`id_order` = o.`id_order`
ORDER BY h.`date_add` DESC
LIMIT 1
)
AND pr.id_product = d.product_id
AND oss.`id_order_slip` IN (
SELECT sd.`id_order_slip`
FROM `'._DB_PREFIX_.'order_slip` sd
WHERE sd.date_add >= DATE_FORMAT(DATE_SUB('.$date_to.', INTERVAL 1 DAY), \'%Y-%m-%d 00:00:00\')
AND sd.date_add <= '.$date_to.'
)
AND osd.`id_order_slip` = oss.`id_order_slip`
AND osd.`id_order_detail` = d.`id_order_detail`
AND p.id_lang = 2
';
$slips = Db::getInstance()->ExecuteS($query);
$query = '
SELECT
0 as `id_sale`,
"" as `sale_title`,
o.id_order AS id_order,
o.`id_cart` AS `id_cart`,
c.id_customer AS id_customer,
c.email AS email,
c.firstname AS firstname,
c.lastname AS lastname,
a.firstname AS shipping_firstname,
a.lastname AS shipping_lastname,
a.address1 AS shipping_street,
a.address2 AS shipping_street2,
a.postcode AS shipping_postcode,
a.city AS shipping_city,
a.phone AS shipping_phone,
a.phone_mobile AS shipping_phone_mobile,
REPLACE(REPLACE(REPLACE(a.other, "\n", " "), "\r", " "), " ", " ") AS other_info,
l.name AS shipping_country,
ca.id_carrier AS id_product,
0 AS id_product_attribute,
ca.name AS order_product_name,
-1 AS product_quantity,
o.total_shipping / (1 + o.carrier_tax_rate / 100) AS product_price_base_wo_taxes,
o.carrier_tax_rate AS tax_rate,
ca.name AS product_name,
"" AS product_combination,
o.total_shipping / (1 + o.carrier_tax_rate / 100) AS product_price_wo_taxes,
o.total_shipping AS product_price,
0 AS wholesale_price,
0 AS combination_wholesale_price,
"SHIPPING" AS supplier_reference,
0 AS total_shipping,
oss.date_add AS `date`,
o.invoice_number AS invoice_number,
o.payment AS payment_type,
sl.`name` AS `order_state`,
IFNULL((SELECT `id_reason` FROM `'._DB_PREFIX_.'refundreason` rr WHERE rr.`id_order_slip` = oss.`id_order_slip` LIMIT 1), "---") AS `refund_reason`,
IFNULL((SELECT CONCAT(`firstname`, " ", `lastname`) FROM `'._DB_PREFIX_.'employee` WHERE `id_employee` = (SELECT rr.`id_employee` FROM `'._DB_PREFIX_.'refundreason` rr WHERE rr.`id_order_slip` = oss.`id_order_slip` LIMIT 1)), "") AS `refund_employee`,
"" AS `sale_employee`,
"" AS `sale_shipping`,
"" AS `spay_transaction`,
"" AS `paypal_transaction`,
"" AS `picker`,
"" AS product_ean13,
"" AS `vip`
FROM
`'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'carrier` ca,
`'._DB_PREFIX_.'customer` c,
`'._DB_PREFIX_.'address` a,
`'._DB_PREFIX_.'order_state_lang` sl,
`'._DB_PREFIX_.'order_slip` oss,
`'._DB_PREFIX_.'country_lang` l
WHERE c.id_customer = o.id_customer
AND l.id_country = a.id_country
AND l.id_lang = 2
AND o.id_address_delivery = a.id_address
AND o.id_carrier = ca.id_carrier
AND sl.`id_lang` = 2
AND sl.`id_order_state` = (
SELECT h.`id_order_state`
FROM `'._DB_PREFIX_.'order_history` h
WHERE h.`id_order` = o.`id_order`
ORDER BY h.`date_add` DESC
LIMIT 1
)
AND oss.`id_order_slip` IN (
SELECT sd.`id_order_slip`
FROM `'._DB_PREFIX_.'order_slip` sd
WHERE sd.date_add >= DATE_FORMAT(DATE_SUB('.$date_to.', INTERVAL 1 DAY), \'%Y-%m-%d 00:00:00\')
AND sd.date_add <= '.$date_to.'
AND `shipping_cost` = 1
)
AND oss.`id_order` = o.`id_order`
GROUP BY o.id_order
';
$slips_shipping = Db::getInstance()->ExecuteS($query);
$canceled_orders = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order`
FROM `'._DB_PREFIX_.'order_history`
WHERE (`id_order_state` = 6
OR `id_order_state` = 7)
AND `date_add` >= DATE_FORMAT(DATE_SUB('.$date_to.', INTERVAL 1 DAY), \'%Y-%m-%d 00:00:00\')
AND `date_add` <= '.$date_to.'
GROUP BY `id_order`
ORDER BY `date_add` DESC
') as $o) {
$canceled_orders[] = (int) $o['id_order'];
}
if(count($canceled_orders) > 0) {
$query = '
SELECT
0 AS id_sale,
"" AS sale_title,
o.id_order AS id_order,
o.`id_cart` AS `id_cart`,
c.id_customer AS id_customer,
c.email AS email,
c.firstname AS firstname,
c.lastname AS lastname,
a.firstname AS shipping_firstname,
a.lastname AS shipping_lastname,
a.address1 AS shipping_street,
a.address2 AS shipping_street2,
a.postcode AS shipping_postcode,
a.city AS shipping_city,
a.phone AS shipping_phone,
a.phone_mobile AS shipping_phone_mobile,
REPLACE(REPLACE(REPLACE(a.other, "\n", " "), "\r", " "), " ", " ") AS other_info,
l.name AS shipping_country,
od.id_discount AS id_product,
0 AS id_product_attribute,
od.name AS order_product_name,
-1 AS product_quantity,
od.value AS product_price_base_wo_taxes,
0 AS tax_rate,
od.name AS product_name,
"" AS product_combination,
od.value AS product_price_wo_taxes,
od.value AS product_price,
0 AS wholesale_price,
0 AS combination_wholesale_price,
"DISCOUNT" AS supplier_reference,
0 AS total_shipping,
(
SELECT h.`date_add`
FROM `'._DB_PREFIX_.'order_history` h
WHERE h.`id_order` = o.`id_order`
AND (h.`id_order_state` = 6
OR h.`id_order_state` = 7)
ORDER BY h.`date_add` DESC
LIMIT 1
) AS `date`,
o.invoice_number AS invoice_number,
o.payment AS payment_type,
sl.`name` AS `order_state`,
"" AS `refund_reason`,
"" AS `refund_employee`,
"" AS `sale_employee`,
"" AS `sale_shipping`,
"" AS `spay_transaction`,
"" AS `paypal_transaction`,
"" AS `picker`,
"" AS product_ean13,
"" AS `vip`
FROM
`'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'order_discount` od,
`'._DB_PREFIX_.'customer` c,
`'._DB_PREFIX_.'address` a,
`'._DB_PREFIX_.'order_state_lang` sl,
`'._DB_PREFIX_.'country_lang` l
WHERE c.id_customer = o.id_customer
AND l.id_country = a.id_country
AND l.id_lang = 2
AND o.id_address_delivery = a.id_address
AND od.id_order = o.id_order
AND sl.`id_lang` = 2
AND o.valid = 0
AND o.`id_order` IN ('.implode(', ', $canceled_orders).')
AND sl.`id_order_state` = (
SELECT h.`id_order_state`
FROM `'._DB_PREFIX_.'order_history` h
WHERE h.`id_order` = o.`id_order`
ORDER BY h.`date_add` DESC
LIMIT 1
)
GROUP BY c.id_customer, od.id_discount
';
$slips_discounts = Db::getInstance()->ExecuteS($query);
}
$partially_canceled_orders = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order`
FROM `'._DB_PREFIX_.'order_slip`
WHERE `date_add` >= DATE_FORMAT(DATE_SUB('.$date_to.', INTERVAL 1 DAY), \'%Y-%m-%d 00:00:00\')
AND `date_add` <= '.$date_to.'
GROUP BY `id_order`
ORDER BY `date_add` ASC
') as $o) {
if(!in_array((int) $o['id_order'], $canceled_orders)) {
$o_order = Db::getInstance()->getRow('
SELECT `total_paid`, `total_shipping`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_order` = '.(int) $o['id_order'].'
');
$o_discounts = Db::getInstance()->getRow('
SELECT SUM(`value`) AS `value`
FROM `'._DB_PREFIX_.'discount`
WHERE `id_discount` IN (
SELECT `id_discount`
FROM `'._DB_PREFIX_.'order_discount`
WHERE `id_order` = '.(int) $o['id_order'].'
)
');
$o_slip = Db::getInstance()->getRow('
SELECT `shipping_cost`
FROM `'._DB_PREFIX_.'order_slip`
WHERE `id_order` = '.$o['id_order'].'
');
$o_products = Db::getInstance()->getRow('
SELECT SUM(ROUND((d.product_price * (1 - d.reduction_percent / 100) - d.reduction_amount) * (1 + d.tax_rate / 100), 6) * (d.`product_quantity` - d.`product_quantity_return`)) AS product_price
FROM `'._DB_PREFIX_.'order_detail` d
WHERE d.`id_order` = '.(int) $o['id_order'].'
AND (d.`product_quantity` - d.`product_quantity_return`) > 0
');
$total = ($o_slip['shipping_cost'] == 1? 0: (float) $o_order['total_shipping']) + (float) $o_products['product_price'];
$total_discounts = (float) $o_discounts['value'];
if($total < $total_discounts) {
$partially_canceled_orders[(int) $o['id_order']] = $total - $total_discounts;
}
}
}
// TODO: find a better solution with a single query
foreach($partially_canceled_orders as $porder => $value) {
$query = '
SELECT
0 AS id_sale,
"" AS sale_title,
o.id_order AS id_order,
o.`id_cart` AS `id_cart`,
c.id_customer AS id_customer,
c.email AS email,
c.firstname AS firstname,
c.lastname AS lastname,
a.firstname AS shipping_firstname,
a.lastname AS shipping_lastname,
a.address1 AS shipping_street,
a.address2 AS shipping_street2,
a.postcode AS shipping_postcode,
a.city AS shipping_city,
a.phone AS shipping_phone,
a.phone_mobile AS shipping_phone_mobile,
REPLACE(REPLACE(REPLACE(a.other, "\n", " "), "\r", " "), " ", " ") AS other_info,
l.name AS shipping_country,
0 AS id_product,
0 AS id_product_attribute,
"DISCOUNT (DIFF)" AS order_product_name,
-1 AS product_quantity,
'.(float) $value.' AS product_price_base_wo_taxes,
0 AS tax_rate,
"DISCOUNT (DIFF)" AS product_name,
"" AS product_combination,
'.(float) $value.' AS product_price_wo_taxes,
'.(float) $value.' AS product_price,
0 AS wholesale_price,
0 AS combination_wholesale_price,
"DISCOUNT (DIFF)" AS supplier_reference,
0 AS total_shipping,
(
SELECT h.`date_add`
FROM `'._DB_PREFIX_.'order_history` h
WHERE h.`id_order` = o.`id_order`
ORDER BY h.`date_add` DESC
LIMIT 1
) AS `date`,
o.invoice_number AS invoice_number,
o.payment AS payment_type,
sl.`name` AS `order_state`,
"" AS `refund_reason`,
"" AS `refund_employee`,
"" AS `sale_employee`,
"" AS `sale_shipping`,
"" AS `spay_transaction`,
"" AS `paypal_transaction`,
"" AS `picker`,
"" AS product_ean13,
"" AS `vip`
FROM
`'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'customer` c,
`'._DB_PREFIX_.'address` a,
`'._DB_PREFIX_.'order_state_lang` sl,
`'._DB_PREFIX_.'country_lang` l
WHERE c.id_customer = o.id_customer
AND l.id_country = a.id_country
AND l.id_lang = 2
AND o.id_address_delivery = a.id_address
AND sl.`id_lang` = 2
AND o.`id_order` = '.(int) $porder.'
AND sl.`id_order_state` = (
SELECT h.`id_order_state`
FROM `'._DB_PREFIX_.'order_history` h
WHERE h.`id_order` = o.`id_order`
ORDER BY h.`date_add` DESC
LIMIT 1
)
';
$slips_discounts[] = Db::getInstance()->getRow($query);
}
$spay_transactions = array();
$paypal_transactions = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order`, `id_transaction`
FROM `'._DB_PREFIX_.'paypal_order`
') as $row) {
$paypal_transactions[(int) $row['id_order']] = $row['id_transaction'];
}
$paypal_refunds = array();
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order`, `message`, `date_add`
FROM `'._DB_PREFIX_.'message`
WHERE `message` LIKE "%Remboursement fini avec PayPal%"
') as $row) {
$m = explode('REFUNDTRANSACTIONID: ', $row['message']);
$m = explode('<br>', $m[1]);
$paypal_refunds[$row['id_order']] = array(array($row['date_add'], $m[0]));
}
foreach(Db::getInstance()->ExecuteS('
SELECT `id_order`, `message`, `date_add`
FROM `'._DB_PREFIX_.'message`
WHERE `message` LIKE "A product%"
AND `message` NOT LIKE "%ACK: Failure%"
') as $row) {
$m = explode('REFUNDTRANSACTIONID: ', $row['message']);
if(count($m) > 1) {
$m = explode('<br>', $m[1]);
if(!isset($paypal_refunds[$row['id_order']])) {
$paypal_refunds[$row['id_order']] = array();
}
$paypal_refunds[$row['id_order']][] = array($row['date_add'], $m[0]);
}
}
$shipping_details = array();
function exportCSV($items, $slips=FALSE) {
global $spay_transactions;
global $paypal_transactions;
global $spay_refunds;
global $paypal_refunds;
global $shipping_details;
$float = array('tax_rate', 'product_price_base_wo_taxes', 'product_price_wo_taxes', 'product_price', 'wholesale_price', 'combination_wholesale_price', 'total_shipping');
if($items && count($items)) {
$data = '';
foreach($items as $row) {
$line = '';
foreach($row as $k => $v) {
if(in_array($k, $float)) {
$v = str_replace('.', ',', (string) $v);
}
if($k == 'other_info') {
$line .= ';"'.str_replace(';', ',', str_replace('"', '\"', $v)).'"';
} else {
$line .= ';'.str_replace(';', ',', str_replace(array("\r", "\n"), '', str_replace('"', '\"', $v)));
}
}
if(strtolower($row['payment_type']) == 'paypal') {
if($slips) {
$refunds = isset($paypal_refunds[(int) $row['id_order']])? $paypal_refunds[(int) $row['id_order']]: '';
if($refunds) {
$ids = array();
foreach($refunds as $r) {
if(abs(strtotime($r[0]) - strtotime($row['date'])) != 60) {
$ids[] = $r[1];
}
}
$line .= ';;'.implode(',', $ids);
} else {
$line .= ';;';
}
} else {
$line .= ';;'.(isset($paypal_transactions[(int) $row['id_order']])? $paypal_transactions[(int) $row['id_order']]: '');
}
} else {
if($slips) {
$refunds = isset($spay_refunds[(int) $row['id_cart']])? $spay_refunds[(int) $row['id_cart']]: '';
if($refunds) {
$ids = array();
foreach($refunds as $r) {
if(abs(strtotime($r[0]) - strtotime($row['date'])) != 60) {
$ids[] = $r[1];
}
}
$line .= ';'.implode(',', $ids).';';
} else {
$line .= ';;';
}
} else {
$line .= ';'.(isset($spay_transactions[(int) $row['id_cart']])? $spay_transactions[(int) $row['id_cart']]: '').';';
}
}
$line .= ';'.(isset($shipping_details[(int) $row['id_order']]) && isset($shipping_details[(int) $row['id_order']][(int) $row['id_product'].'_'.(int) $row['id_product_attribute']])? $shipping_details[(int) $row['id_order']][(int) $row['id_product'].'_'.(int) $row['id_product_attribute']]: '');
$data .= "\n".substr($line, 1);
}
return $data;
}
}
//$result = 'id_sale;sale_title;id_order;id_cart;id_customer;email;firstname;lastname;shipping_firstname;shipping_lastname;shipping_street;shipping_street2;shipping_postcode;shipping_city;shipping_phone;shipping_phone_mobile;other_info;shipping_country;id_product;id_product_attribute;order_product_name;product_quantity;product_price_base_wo_taxes;tax_rate;product_name;product_combination;product_price_wo_taxes;product_price;wholesale_price;combination_wholesale_price;supplier_reference;total_shipping;date;invoice_number;payment_type;order_state;refund_reason;refund_employee;sale_employee;spay_transaction;paypal_transaction;picker;product_ean13;vip';
$result = '';
$result .= exportCSV($orders);
$result .= exportCSV($shipping);
$result .= exportCSV($discounts);
$result .= exportCSV($slips, TRUE);
$result .= exportCSV($slips_shipping, TRUE);
$result .= exportCSV($slips_discounts, TRUE);
echo $result;
//file_put_contents('extract/daily-daily/'.date('Y-m-d', mktime()).'-dailydaily2_test.csv', $result);
//~ file_put_contents('extract/daily-daily/2012-08-27-dailydaily2.csv', $result);
exit;

View File

@ -0,0 +1,775 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
//require_once realpath(dirname(__FILE__).'/../').'/www/config/config.inc.php';
require_once realpath(dirname(__FILE__).'/../').'/bebeboutik/config/config.inc.php';
$now = $argv[1].' 00:00:00';
function getChildren($id=0) {
return Db::getInstance()->ExecuteS('
SELECT id_parent, id_category
FROM `'._DB_PREFIX_.'category`
WHERE `id_parent` = '.$id
);
}
function getCat($id=0, $title='') {
$products = Db::getInstance()->ExecuteS('
SELECT id_product, "'.addslashes($title).'" AS `title`
FROM `'._DB_PREFIX_.'product`
WHERE `id_category_default` = '.$id
);
foreach(getChildren($id) as $child) {
$products = array_merge($products, getCat($child['id_category']));
}
return $products;
}
$f = fopen('extracts/monthly_compta/'.date('Y-m-d', strtotime($now)).'_new.csv', 'w');
$headers = array(
'date',
'id_order',
'id_order_slip',
'invoice_number',
'multisale',
'id_customer',
'firstname',
'lastname',
'total_products_wo_taxes_210',
'total_taxes_210',
'total_products_wo_taxes_200',
'total_taxes_200',
'total_products_wo_taxes_196',
'total_taxes_196',
'total_products_wo_taxes_100',
'total_taxes_100',
'total_products_wo_taxes_55',
'total_taxes_55',
'total_products_wo_taxes_21',
'total_taxes_21',
'total_products_wo_taxes_60',
'total_taxes_60',
'total_products_wo_taxes_40',
'total_taxes_40',
'total_products_wo_taxes_export',
'shipping_wo_taxes_196-200',
'shipping_wo_taxes_export',
'shipping_country',
'discounts',
'total_paid',
'total_paid_real',
'wholesale_price',
'payment_type',
'direct_payment',
'refund_reason',
'date_subsribe',
'pays',
'device',
);
fwrite($f, implode(';', $headers)."\n");
$query_orders = array();
$orders = array();
// ORDERS
foreach(Db::getInstance()->ExecuteS('
SELECT DISTINCT o.`id_order`,
(CASE o.`appli`
WHEN 0 THEN "DESKTOP"
WHEN 1 THEN "APPLICATION"
WHEN 2 THEN "MOBILE"
END) AS device
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_detail` d ON d.id_order = o.id_order
LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.id_customer = o.id_customer
LEFT JOIN `'._DB_PREFIX_.'order_state_current` os ON os.id_order = o.id_order
WHERE
(o.valid = 1
OR (
o.valid = 0
AND ( os.id_order_state = 6 OR os.id_order_state = 7 OR os.id_order_state = 11)
))
AND o.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 1 MONTH, \'%Y-%m-01 00:00:00\')
AND o.date_add <= DATE_FORMAT(LAST_DAY("'.$now.'" - INTERVAL 1 MONTH), \'%Y-%m-%d 23:59:59\')
GROUP BY o.id_order
') as $row){
$orders[(int)$row['id_order']] = array();
$query_orders[(int)$row['id_order']] = (int)$row['id_order'];
}
// CUSTOMERS
foreach(Db::getInstance()->ExecuteS('
SELECT c.*, c.`date_add` as subscribe, o.*, v.`version`,
(CASE o.`appli`
WHEN 0 THEN "DESKTOP"
WHEN 1 THEN "APPLICATION"
WHEN 2 THEN "MOBILE"
END) AS device
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = o.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'customer_version` v ON v.`id_customer` = c.`id_customer`
WHERE o.id_order IN ('.implode(',',$query_orders).')
') as $row){
if(isset($orders[(int)$row['id_order']])){
$orders[(int)$row['id_order']] = $row;
}
}
// MULTI
foreach(Db::getInstance()->ExecuteS('
SELECT COUNT(DISTINCT c.`id_sale`) as multi, o.`id_order`
FROM `'._DB_PREFIX_.'product_ps_cache` c
LEFT JOIN `'._DB_PREFIX_.'order_detail` o ON o.product_id = c.`id_product`
WHERE o.`id_order` IN ('.implode(',',$query_orders).')
GROUP BY o.`id_order`
') as $row){
if(isset($orders[(int)$row['id_order']])){
$orders[(int)$row['id_order']]['multi'] = (int)$row['multi'] == 1?'S':'M';
}
}
// ORDER DETAILS
foreach(Db::getInstance()->ExecuteS('
SELECT d.*, p.`wholesale_price`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = d.`product_id`)
WHERE d.id_order IN ('.implode(',',$query_orders).')
') as $row){
if(isset($orders[(int)$row['id_order']])){
if(!isset($orders[(int)$row['id_order']]['order_details'])){
$orders[(int)$row['id_order']]['order_details'] = array();
}
$orders[(int)$row['id_order']]['order_details'][] = $row;
}
}
foreach($orders as $order) {
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$invoice_address = Db::getInstance()->ExecuteS('
SELECT firstname, lastname
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.$order['id_address_invoice']
);
$invoice_address = $invoice_address[0];
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_60 = array();
$total_taxes_60 = array();
$total_products_wo_taxes_40 = array();
$total_taxes_40 = array();
$total_products_wo_taxes_export = array();
$country = Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_country` = (
SELECT `id_country`
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $order['id_address_delivery'].'
LIMIT 1
)
AND `id_lang` = 2
');
$date_send = Db::getInstance()->getValue('
SELECT `date_add`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order_state` = 4
AND `id_order` = '.(int) $order['id_order'].'
ORDER BY `date_add` ASC
');
$ldetails = array();
$wholesale_price = 0;
foreach($order['order_details'] as $detail) {
$ldetails[$detail['id_order_detail']] = $detail;
$wholesale_price += (float) ($detail['wholesale_price'] * $detail['product_quantity']);
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '20.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.2);
}
} elseif($detail['tax_rate'] == '21.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.21);
}
} elseif($detail['tax_rate'] == '19.600') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.196);
}
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.055);
}
} elseif($detail['tax_rate'] == '2.100') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.021);
}
} elseif($detail['tax_rate'] == '6.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.060);
} else {
$total_products_wo_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.060);
}
} elseif($detail['tax_rate'] == '4.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.040);
} else {
$total_products_wo_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.040);
}
} else {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
}
} else {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
}
}
$_total_products_wo_taxes_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$_total_products_wo_taxes_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$_total_products_wo_taxes_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$_total_products_wo_taxes_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$_total_products_wo_taxes_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$_total_products_wo_taxes_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$_total_products_wo_taxes_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$_total_products_wo_taxes_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$_total_products_wo_taxes_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$_total_products_wo_taxes_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$_total_products_wo_taxes_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$_total_products_wo_taxes_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$_total_products_wo_taxes_60 = 0.0;
foreach($total_products_wo_taxes_60 as $value) {
$_total_products_wo_taxes_60 += $value;
}
$_total_taxes_60 = 0.0;
foreach($total_taxes_60 as $value) {
$_total_taxes_60 += $value;
}
$_total_products_wo_taxes_40 = 0.0;
foreach($total_products_wo_taxes_40 as $value) {
$_total_products_wo_taxes_40 += $value;
}
$_total_taxes_40 = 0.0;
foreach($total_taxes_40 as $value) {
$_total_taxes_40 += $value;
}
$_total_products_wo_taxes_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$_total_products_wo_taxes_export += $value;
}
// Find if it's a saved card or account for the payment (Direct payment)
$is_direct_payment = 0;
if($order['payment'] == 'Paybox') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_saved_card`
FROM `'._DB_PREFIX_.'paybox_transaction`
WHERE `id_cart` = '.(int) $order['id_cart'].'
');
} elseif ($order['payment'] == 'PayPal') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_billing`
FROM `'._DB_PREFIX_.'paypal_order`
WHERE `id_order` = '.(int) $order['id_order'].'
');
}
if((int)$is_direct_payment != 0) {
$order['direct_payment'] = "Oui";
} else {
$order['direct_payment'] = "Non";
}
fwrite($f, implode(';', array(
$order['date_add'],
$order['id_order'],
0,
$order['invoice_number'],
$order['multi'],
$order['id_customer'],
$invoice_address['firstname'],
$invoice_address['lastname'],
$_total_products_wo_taxes_210,
$_total_taxes_210,
$_total_products_wo_taxes_200,
$_total_taxes_200,
$_total_products_wo_taxes_196,
$_total_taxes_196,
$_total_products_wo_taxes_100,
$_total_taxes_100,
$_total_products_wo_taxes_55,
$_total_taxes_55,
$_total_products_wo_taxes_21,
$_total_taxes_21,
$_total_products_wo_taxes_60,
$_total_taxes_60,
$_total_products_wo_taxes_40,
$_total_taxes_40,
$_total_products_wo_taxes_export,
($address['id_country'] != 19? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0),
($address['id_country'] != 19? 0.0: $order['total_shipping']),
$country,
$order['total_discounts'],
$order['total_paid'],
$order['total_paid_real'],
$wholesale_price,
$order['payment'],
$order['direct_payment'],
'',
$order['subscribe'],
$order['version'],
$order['device']
))."\n");
}
// This order has been refunded
$slips = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_slip` os
WHERE os.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 1 MONTH, \'%Y-%m-01 00:00:00\')
AND os.date_add <= DATE_FORMAT(LAST_DAY("'.$now.'" - INTERVAL 1 MONTH), \'%Y-%m-%d 23:59:59\')
');
$refundreasons = array(
'',
'CLIENT : Annulation pré-envoi',
'CLIENT : Rétractation post-envoi',
'BBB : Erreur Achat / Prod',
'FEUR : Problème SAV',
'FEUR : Produit manquant',
'BBB : Erreur logistique',
'Autre',
'BBB : Pbme Site / Paiement',
'TRANS : Colis détruit',
'TRANS : Colis perdu',
'CLIENT : Annulation pour ré-achat',
'BBB : Suspicion de fraude',
);
if(count($slips) > 0) {
foreach($slips as $slip) {
$order = Db::getInstance()->getRow('
SELECT o.*, c.*, c.`date_add` as subscribe, v.`version`
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON o.`id_customer` = c.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'customer_version` v
ON c.`id_customer` = v.`id_customer`
WHERE
o.id_order = '.$slip['id_order'].'
');
$multi = Db::getInstance()->getValue('
SELECT COUNT(DISTINCT `id_sale`)
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` IN (
SELECT `product_id` FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order['id_order'].'
)
') == 1? 'S': 'M';
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$invoice_address = Db::getInstance()->ExecuteS('
SELECT firstname, lastname
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.$order['id_address_invoice']
);
$invoice_address = $invoice_address[0];
$order_details = Db::getInstance()->ExecuteS('
SELECT d.*, p.`wholesale_price`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = d.`product_id`)
WHERE d.id_order = '.(int) $slip['id_order'].'
AND d.`id_order_detail` IN (
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_slip_detail`
WHERE `id_order_slip` = '.(int) $slip['id_order_slip'].'
)
');
$country = Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_country` = (
SELECT `id_country`
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $order['id_address_delivery'].'
LIMIT 1
)
AND `id_lang` = 2
');
$date_send = Db::getInstance()->getValue('
SELECT `date_add`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order_state` = 4
AND `id_order` = '.(int) $order['id_order'].'
ORDER BY `date_add` ASC
');
$ldetails = array();
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_60 = array();
$total_taxes_60 = array();
$total_products_wo_taxes_40 = array();
$total_taxes_40 = array();
$total_products_wo_taxes_export = array();
$wholesale_price = 0;
foreach($order_details as $detail) {
$ldetails[$detail['id_order_detail']] = $detail;
$wholesale_price += (float) ($detail['wholesale_price'] * $detail['product_quantity_refunded']);
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '19.600') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.196);
}
} elseif($detail['tax_rate'] == '21.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.21);
}
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.055);
}
} elseif($detail['tax_rate'] == '2.100') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.021);
}
} elseif($detail['tax_rate'] == '20.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.2);
}
} elseif($detail['tax_rate'] == '6.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.06);
} else {
$total_products_wo_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.06);
}
} elseif($detail['tax_rate'] == '4.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.04);
} else {
$total_products_wo_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.04);
}
} else {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
}
} else {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
}
}
$_total_products_wo_taxes_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$_total_products_wo_taxes_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$_total_products_wo_taxes_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$_total_products_wo_taxes_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$_total_products_wo_taxes_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$_total_products_wo_taxes_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$_total_products_wo_taxes_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$_total_products_wo_taxes_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$_total_products_wo_taxes_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$_total_products_wo_taxes_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$_total_products_wo_taxes_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$_total_products_wo_taxes_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$_total_products_wo_taxes_60 = 0.0;
foreach($total_products_wo_taxes_60 as $value) {
$_total_products_wo_taxes_60 += $value;
}
$_total_taxes_60 = 0.0;
foreach($total_taxes_60 as $value) {
$_total_taxes_60 += $value;
}
$_total_products_wo_taxes_40 = 0.0;
foreach($total_products_wo_taxes_40 as $value) {
$_total_products_wo_taxes_40 += $value;
}
$_total_taxes_40 = 0.0;
foreach($total_taxes_40 as $value) {
$_total_taxes_40 += $value;
}
$_total_products_wo_taxes_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$_total_products_wo_taxes_export += $value;
}
$refundreason = Db::getInstance()->getValue('
SELECT `id_reason`
FROM `'._DB_PREFIX_.'refundreason`
WHERE `id_order_slip` = '.(int) $slip['id_order_slip'].'
');
$refundreason = $refundreasons[(int) $refundreason];
// Find if it's a saved card or account for the payment (Direct payment)
$is_direct_payment = 0;
if($order['payment'] == 'Paybox') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_saved_card`
FROM `'._DB_PREFIX_.'paybox_transaction`
WHERE `id_cart` = '.(int) $order['id_cart'].'
');
} elseif ($order['payment'] == 'PayPal') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_billing`
FROM `'._DB_PREFIX_.'paypal_order`
WHERE `id_order` = '.(int) $order['id_order'].'
');
}
if((int)$is_direct_payment != 0) {
$order['direct_payment'] = "Oui";
} else {
$order['direct_payment'] = "Non";
}
fwrite($f, implode(';', array(
$slip['date_add'],
$order['id_order'],
$slip['id_order_slip'],
$order['invoice_number'],
$multi,
$order['id_customer'],
$invoice_address['firstname'],
$invoice_address['lastname'],
'-'.$_total_products_wo_taxes_210,
'-'.$_total_taxes_210,
'-'.$_total_products_wo_taxes_200,
'-'.$_total_taxes_200,
'-'.$_total_products_wo_taxes_196,
'-'.$_total_taxes_196,
'-'.$_total_products_wo_taxes_100,
'-'.$_total_taxes_100,
'-'.$_total_products_wo_taxes_55,
'-'.$_total_taxes_55,
'-'.$_total_products_wo_taxes_21,
'-'.$_total_taxes_21,
'-'.$_total_products_wo_taxes_60,
'-'.$_total_taxes_60,
'-'.$_total_products_wo_taxes_40,
'-'.$_total_taxes_40,
'-'.$_total_products_wo_taxes_export,
'-'.($slip['shipping_cost'] == 1? ($address['id_country'] != 19? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0): 0.0),
'-'.($slip['shipping_cost'] == 1? ($address['id_country'] != 19? 0.0: $order['total_shipping']): 0.0),
$country,
'-0.0',
'-'.($_total_products_wo_taxes_210 + $_total_taxes_210 + $_total_products_wo_taxes_200 + $_total_taxes_200 + $_total_products_wo_taxes_196 + $_total_taxes_196 + $_total_products_wo_taxes_100 + $_total_taxes_100 + $_total_products_wo_taxes_55 + $_total_taxes_55 + $_total_products_wo_taxes_21 + $_total_taxes_21 + $_total_products_wo_taxes_60 + $_total_taxes_60 + $_total_products_wo_taxes_40 + $_total_taxes_40 + $_total_products_wo_taxes_export + ($slip['shipping_cost'] == 1? (float) $order['total_shipping']: 0.0)),
'-'.($_total_products_wo_taxes_210 + $_total_taxes_210 + $_total_products_wo_taxes_200 + $_total_taxes_200 + $_total_products_wo_taxes_196 + $_total_taxes_196 + $_total_products_wo_taxes_100 + $_total_taxes_100 + $_total_products_wo_taxes_55 + $_total_taxes_55 + $_total_products_wo_taxes_21 + $_total_taxes_21 + $_total_products_wo_taxes_60 + $_total_taxes_60 + $_total_products_wo_taxes_40 + $_total_taxes_40 + $_total_products_wo_taxes_export + ($slip['shipping_cost'] == 1? (float) $order['total_shipping']: 0.0)),
'-'.$wholesale_price,
'REFUND '.strtoupper($order['payment']),
$order['direct_payment'],
$refundreason,
$order['subscribe'],
$order['version'],
))."\n");
}
}
fclose($f);
exit;

View File

@ -0,0 +1,918 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
$now = $argv[1].' 00:00:00';
function getChildren($id=0) {
return Db::getInstance()->ExecuteS('
SELECT id_parent, id_category
FROM `'._DB_PREFIX_.'category`
WHERE `id_parent` = '.$id
);
}
function getCat($id=0, $title='') {
$products = Db::getInstance()->ExecuteS('
SELECT id_product, "'.addslashes($title).'" AS `title`
FROM `'._DB_PREFIX_.'product`
WHERE `id_category_default` = '.$id
);
foreach(getChildren($id) as $child) {
$products = array_merge($products, getCat($child['id_category']));
}
return $products;
}
// $f = fopen('extracts/monthly_compta/decembre2014.csv', 'w');
$f = fopen('extracts/monthly_compta/'.date('Y-m-d', strtotime($now)).'_last.csv', 'w');
//$f = fopen('extracts/monthly_compta/2012-01-01_ok2.csv', 'w');
$headers = array(
'date',
//'sale_title',
'id_order',
'id_order_slip',
'invoice_number',
'multisale',
'id_customer',
'firstname',
'lastname',
'total_products_wo_taxes_210',
'total_taxes_210',
'total_products_wo_taxes_200',
'total_taxes_200',
'total_products_wo_taxes_196',
'total_taxes_196',
'total_products_wo_taxes_100',
'total_taxes_100',
'total_products_wo_taxes_55',
'total_taxes_55',
'total_products_wo_taxes_21',
'total_taxes_21',
'total_products_wo_taxes_60',
'total_taxes_60',
'total_products_wo_taxes_40',
'total_taxes_40',
'total_products_wo_taxes_export',
'shipping_wo_taxes_196-200',
'shipping_wo_taxes_export',
'shipping_country',
'discounts',
'total_paid',
'total_paid_real',
'total_achat',
'payment_type',
'direct_payment',
'date_send',
'refund_reason',
'new',
);
fwrite($f, implode(';', $headers)."\n");
$orders = Db::getInstance()->ExecuteS('
SELECT o.id_order
FROM `'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'order_detail` d,
`'._DB_PREFIX_.'customer` c
WHERE
(o.valid = 1
OR (
o.valid = 0
AND (
(SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 6
OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 7
OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 11
)
))
AND c.id_customer = o.id_customer
AND d.id_order = o.id_order
AND o.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 2 MONTH, \'%Y-%m-01 00:00:00\')
AND o.date_add <= DATE_FORMAT(LAST_DAY("'.$now.'" - INTERVAL 2 MONTH), \'%Y-%m-%d 23:59:59\')
GROUP BY o.id_order
');
// $orders = Db::getInstance()->ExecuteS('
// SELECT o.id_order
// FROM `'._DB_PREFIX_.'orders` o,
// `'._DB_PREFIX_.'order_detail` d,
// `'._DB_PREFIX_.'customer` c
// WHERE
// (o.valid = 1
// OR (
// o.valid = 0
// AND (
// (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 6
// OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 7
// OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 11
// )
// ))
// AND c.id_customer = o.id_customer
// AND d.id_order = o.id_order
// AND o.date_add >= "2014-12-01 00:00:00"
// AND o.date_add <= "2014-12-31 23:59:59"
// GROUP BY o.id_order
// ');
foreach($orders as $o) {
$order = Db::getInstance()->ExecuteS('
SELECT c.*, o.*
FROM `'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'customer` c
WHERE
o.id_order = '.$o['id_order'].'
AND c.`id_customer` = o.`id_customer`
');
$order = $order[0];
$multi = Db::getInstance()->getValue('
SELECT COUNT(DISTINCT `id_sale`)
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` IN (
SELECT `product_id` FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order['id_order'].'
)
') == 1? 'S': 'M';
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$invoice_address = Db::getInstance()->ExecuteS('
SELECT firstname, lastname
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.$order['id_address_invoice']
);
$invoice_address = $invoice_address[0];
$order_details = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_detail` d
WHERE d.id_order = '.$o['id_order']
);
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_60= array();
$total_taxes_60= array();
$total_products_wo_taxes_40 = array();
$total_taxes_40 = array();
$total_products_wo_taxes_export = array();
$country = Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_country` = (
SELECT `id_country`
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $order['id_address_delivery'].'
LIMIT 1
)
AND `id_lang` = 2
');
$date_send = Db::getInstance()->getValue('
SELECT `date_add`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order_state` = 4
AND `id_order` = '.(int) $order['id_order'].'
ORDER BY `date_add` ASC
');
// calcul prix d'achat de la commande
$wholesale_price = Db::getInstance()->ExecuteS('
SELECT `wholesale_price`, p.`id_product`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` o ON o.`product_id` = p.`id_product`
WHERE o.`id_order` = '. (int) $order['id_order']
);
$prix_achat = array();
foreach ($wholesale_price as $key => $price) {
$prix_achat[$price['id_product']] = $price['wholesale_price'];
}
$total_achat = 0;
$ldetails = array();
foreach($order_details as $detail) {
$total_achat += $detail['product_quantity'] * $prix_achat[$detail['product_id']];
$ldetails[$detail['id_order_detail']] = $detail;
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '20.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.2);
}
/*}*/
} elseif($detail['tax_rate'] == '21.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_quantity_discount'] / 1.196);
$total_taxes_196[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.196);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.21);
}
/*}*/
}elseif($detail['tax_rate'] == '19.600') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_quantity_discount'] / 1.196);
$total_taxes_196[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.196);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.196);
}
/*}*/
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_quantity_discount'] / 1.055);
$total_taxes_55[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.055);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.055);
}
/*}*/
} elseif($detail['tax_rate'] == '2.100') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.021);
}
/*}*/
} elseif($detail['tax_rate'] == '6.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.060);
} else {
$total_products_wo_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.060);
}
/*}*/
} elseif($detail['tax_rate'] == '4.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.040);
} else {
$total_products_wo_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.040);
}
/*}*/
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
/*}*/
}
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
/*}*/
}
}
$_total_products_wo_taxes_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$_total_products_wo_taxes_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$_total_products_wo_taxes_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$_total_products_wo_taxes_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$_total_products_wo_taxes_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$_total_products_wo_taxes_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$_total_products_wo_taxes_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$_total_products_wo_taxes_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$_total_products_wo_taxes_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$_total_products_wo_taxes_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$_total_products_wo_taxes_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$_total_products_wo_taxes_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$_total_products_wo_taxes_60 = 0.0;
foreach($total_products_wo_taxes_60 as $value) {
$_total_products_wo_taxes_60 += $value;
}
$_total_taxes_60 = 0.0;
foreach($total_taxes_60 as $value) {
$_total_taxes_60 += $value;
}
$_total_products_wo_taxes_40 = 0.0;
foreach($total_products_wo_taxes_40 as $value) {
$_total_products_wo_taxes_40 += $value;
}
$_total_taxes_40 = 0.0;
foreach($total_taxes_40 as $value) {
$_total_taxes_40 += $value;
}
$_total_products_wo_taxes_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$_total_products_wo_taxes_export += $value;
}
// Find if it's a saved card or account for the payment (Direct payment)
$is_direct_payment = 0;
if($order['payment'] == 'Paybox') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_saved_card`
FROM `'._DB_PREFIX_.'paybox_transaction`
WHERE `id_cart` = '.(int) $order['id_cart'].'
');
} elseif ($order['payment'] == 'PayPal') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_billing`
FROM `'._DB_PREFIX_.'paypal_order`
WHERE `id_order` = '.(int) $order['id_order'].'
');
}
if((int)$is_direct_payment != 0) {
$order['direct_payment'] = "Oui";
} else {
$order['direct_payment'] = "Non";
}
fwrite($f, implode(';', array(
$order['date_add'],
//addslashes(implode(' / ', $sale_names)),
$order['id_order'],
0,
$order['invoice_number'],
$multi,
$order['id_customer'],
$invoice_address['firstname'],
$invoice_address['lastname'],
$_total_products_wo_taxes_210,
$_total_taxes_210,
$_total_products_wo_taxes_200,
$_total_taxes_200,
$_total_products_wo_taxes_196,
$_total_taxes_196,
$_total_products_wo_taxes_100,
$_total_taxes_100,
$_total_products_wo_taxes_55,
$_total_taxes_55,
$_total_products_wo_taxes_21,
$_total_taxes_21,
$_total_products_wo_taxes_60,
$_total_taxes_60,
$_total_products_wo_taxes_40,
$_total_taxes_40,
$_total_products_wo_taxes_export,
($address['id_country'] != 19? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0),
($address['id_country'] != 19? 0.0: $order['total_shipping']),
$country,
$order['total_discounts'],
$order['total_paid'],
$order['total_paid_real'],
$total_achat,
$order['payment'],
$order['direct_payment'],
$date_send,
'',
(int) Db::getInstance()->getValue('
SELECT `id_order`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_customer` = '.(int) $order['id_customer'].'
AND `id_order` != '.(int) $order['id_order'].'
') == 0,
))."\n");
}
// This order has been refunded
$slips = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_slip` os
WHERE os.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 1 MONTH, \'%Y-%m-01 00:00:00\')
AND os.date_add <= DATE_FORMAT(LAST_DAY("'.$now.'" - INTERVAL 1 MONTH), \'%Y-%m-%d 23:59:59\')
');
// $slips = Db::getInstance()->ExecuteS('
// SELECT *
// FROM `'._DB_PREFIX_.'order_slip` os
// WHERE os.date_add >= "2014-12-01 00:00:00"
// AND os.date_add <= "2014-12-31 23:59:59"
// ');
// $slips = Db::getInstance()->ExecuteS('
// SELECT *
// FROM `'._DB_PREFIX_.'order_slip` os
// AND os.date_add >= "'. date('Y') .'-01-01 00:00:00"
// ');
$refundreasons = array(
'',
'CLIENT : Annulation pré-envoi',
'CLIENT : Rétractation post-envoi',
'BBB : Erreur Achat / Prod',
'FEUR : Problème SAV',
'FEUR : Produit manquant',
'BBB : Erreur logistique',
'Autre',
'BBB : Pbme Site / Paiement',
'TRANS : Colis détruit',
'TRANS : Colis perdu',
'CLIENT : Annulation pour ré-achat',
'BBB : Suspicion de fraude',
);
if(count($slips) > 0) {
foreach($slips as $slip) {
$order = Db::getInstance()->getRow('
SELECT o.*, c.*
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON o.`id_customer` = c.`id_customer`
WHERE
o.id_order = '.$slip['id_order'].'
');
$multi = Db::getInstance()->getValue('
SELECT COUNT(DISTINCT `id_sale`)
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` IN (
SELECT `product_id` FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order['id_order'].'
)
') == 1? 'S': 'M';
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$invoice_address = Db::getInstance()->ExecuteS('
SELECT firstname, lastname
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.$order['id_address_invoice']
);
$invoice_address = $invoice_address[0];
$order_details = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_detail` d
WHERE d.id_order = '.(int) $slip['id_order'].'
AND d.`id_order_detail` IN (
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_slip_detail`
WHERE `id_order_slip` = '.(int) $slip['id_order_slip'].'
)
');
$country = Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_country` = (
SELECT `id_country`
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $order['id_address_delivery'].'
LIMIT 1
)
AND `id_lang` = 2
');
$date_send = Db::getInstance()->getValue('
SELECT `date_add`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order_state` = 4
AND `id_order` = '.(int) $order['id_order'].'
ORDER BY `date_add` ASC
');
// calcul prix d'achat de la commande
$wholesale_price_slip = Db::getInstance()->ExecuteS('
SELECT `wholesale_price`, p.`id_product`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` o ON o.`product_id` = p.`id_product`
WHERE o.`id_order` = '. (int) $slip['id_order']
);
$prix_achat_slip = array();
foreach ($wholesale_price_slip as $key => $price) {
$prix_achat_slip[$price['id_product']] = $price['wholesale_price'];
}
$total_achat_slip = 0;
$ldetails = array();
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_60 = array();
$total_taxes_60 = array();
$total_products_wo_taxes_40 = array();
$total_taxes_40 = array();
$total_products_wo_taxes_export = array();
foreach($order_details as $detail) {
$total_achat_slip += $detail['product_quantity'] * $prix_achat_slip[$detail['product_id']];
/*$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_export = array();*/
$ldetails[$detail['id_order_detail']] = $detail;
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '19.600') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_quantity_discount'] / 1.196);
$total_taxes_196[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.196);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.196);
}
/*}*/
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_quantity_discount'] / 1.055);
$total_taxes_55[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.055);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.055);
}
/*}*/
} elseif($detail['tax_rate'] == '2.100') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.021);
}
/*}*/
} elseif($detail['tax_rate'] == '20.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.2);
}
/*}*/
} elseif($detail['tax_rate'] == '21.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.21);
}
/*}*/
} elseif($detail['tax_rate'] == '6.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.06);
} else {
$total_products_wo_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.06);
}
/*}*/
} elseif($detail['tax_rate'] == '4.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.04);
} else {
$total_products_wo_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.04);
}
/*}*/
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
/*}*/
}
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
/*}*/
}
}
$_total_products_wo_taxes_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$_total_products_wo_taxes_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$_total_products_wo_taxes_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$_total_products_wo_taxes_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$_total_products_wo_taxes_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$_total_products_wo_taxes_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$_total_products_wo_taxes_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$_total_products_wo_taxes_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$_total_products_wo_taxes_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$_total_products_wo_taxes_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$_total_products_wo_taxes_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$_total_products_wo_taxes_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$_total_products_wo_taxes_60 = 0.0;
foreach($total_products_wo_taxes_60 as $value) {
$_total_products_wo_taxes_60 += $value;
}
$_total_taxes_60 = 0.0;
foreach($total_taxes_60 as $value) {
$_total_taxes_60 += $value;
}
$_total_products_wo_taxes_40 = 0.0;
foreach($total_products_wo_taxes_40 as $value) {
$_total_products_wo_taxes_40 += $value;
}
$_total_taxes_40 = 0.0;
foreach($total_taxes_40 as $value) {
$_total_taxes_40 += $value;
}
$_total_products_wo_taxes_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$_total_products_wo_taxes_export += $value;
}
// Find if it's a saved card or account for the payment (Direct payment)
$is_direct_payment = 0;
if($order['payment'] == 'Paybox') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_saved_card`
FROM `'._DB_PREFIX_.'paybox_transaction`
WHERE `id_cart` = '.(int) $order['id_cart'].'
');
} elseif ($order['payment'] == 'PayPal') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_billing`
FROM `'._DB_PREFIX_.'paypal_order`
WHERE `id_order` = '.(int) $order['id_order'].'
');
}
if((int)$is_direct_payment != 0) {
$order['direct_payment'] = "Oui";
} else {
$order['direct_payment'] = "Non";
}
$refundreason = Db::getInstance()->getValue('
SELECT `id_reason`
FROM `'._DB_PREFIX_.'refundreason`
WHERE `id_order_slip` = '.(int) $slip['id_order_slip'].'
');
$refundreason = $refundreasons[(int) $refundreason];
fwrite($f, implode(';', array(
$slip['date_add'],
//addslashes(implode(' / ', $sale_names)),
$order['id_order'],
$slip['id_order_slip'],
$order['invoice_number'],
$multi,
$order['id_customer'],
$invoice_address['firstname'],
$invoice_address['lastname'],
'-'.$_total_products_wo_taxes_210,
'-'.$_total_taxes_210,
'-'.$_total_products_wo_taxes_200,
'-'.$_total_taxes_200,
'-'.$_total_products_wo_taxes_196,
'-'.$_total_taxes_196,
'-'.$_total_products_wo_taxes_100,
'-'.$_total_taxes_100,
'-'.$_total_products_wo_taxes_55,
'-'.$_total_taxes_55,
'-'.$_total_products_wo_taxes_21,
'-'.$_total_taxes_21,
'-'.$_total_products_wo_taxes_60,
'-'.$_total_taxes_60,
'-'.$_total_products_wo_taxes_40,
'-'.$_total_taxes_40,
'-'.$_total_products_wo_taxes_export,
'-'.($slip['shipping_cost'] == 1? ($address['id_country'] != 19? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0): 0.0),
'-'.($slip['shipping_cost'] == 1? ($address['id_country'] != 19? 0.0: $order['total_shipping']): 0.0),
$country,
'-0.0',
'-'.($_total_products_wo_taxes_210 + $_total_taxes_210 + $_total_products_wo_taxes_200 + $_total_taxes_200 + $_total_products_wo_taxes_196 + $_total_taxes_196 + $_total_products_wo_taxes_100 + $_total_taxes_100 + $_total_products_wo_taxes_55 + $_total_taxes_55 + $_total_products_wo_taxes_21 + $_total_taxes_21 + $_total_products_wo_taxes_60 + $_total_taxes_60 + $_total_products_wo_taxes_40 + $_total_taxes_40 + $_total_products_wo_taxes_export + ($slip['shipping_cost'] == 1? (float) $order['total_shipping']: 0.0)),
'-'.($_total_products_wo_taxes_210 + $_total_taxes_210 + $_total_products_wo_taxes_200 + $_total_taxes_200 + $_total_products_wo_taxes_196 + $_total_taxes_196 + $_total_products_wo_taxes_100 + $_total_taxes_100 + $_total_products_wo_taxes_55 + $_total_taxes_55 + $_total_products_wo_taxes_21 + $_total_taxes_21 + $_total_products_wo_taxes_60 + $_total_taxes_60 + $_total_products_wo_taxes_40 + $_total_taxes_40 + $_total_products_wo_taxes_export + ($slip['shipping_cost'] == 1? (float) $order['total_shipping']: 0.0)),
$total_achat_slip,
'REFUND '.strtoupper($order['payment']),
$order['direct_payment'],
$date_send,
$refundreason,
'',
))."\n");
}
}
fclose($f);
exit;

View File

@ -0,0 +1,889 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
$now = $argv[1].' 00:00:00';
function getChildren($id=0) {
return Db::getInstance()->ExecuteS('
SELECT id_parent, id_category
FROM `'._DB_PREFIX_.'category`
WHERE `id_parent` = '.$id
);
}
function getCat($id=0, $title='') {
$products = Db::getInstance()->ExecuteS('
SELECT id_product, "'.addslashes($title).'" AS `title`
FROM `'._DB_PREFIX_.'product`
WHERE `id_category_default` = '.$id
);
foreach(getChildren($id) as $child) {
$products = array_merge($products, getCat($child['id_category']));
}
return $products;
}
$f = fopen('extracts/monthly_compta/'.date('Y-m-d', strtotime($now)).'_new.csv', 'w');
//$f = fopen('extracts/monthly_compta/2012-01-01_ok2.csv', 'w');
$headers = array(
'date',
//'sale_title',
'id_order',
'id_order_slip',
'invoice_number',
'multisale',
'id_customer',
'firstname',
'lastname',
'total_products_wo_taxes_210',
'total_taxes_210',
'total_products_wo_taxes_200',
'total_taxes_200',
'total_products_wo_taxes_196',
'total_taxes_196',
'total_products_wo_taxes_100',
'total_taxes_100',
'total_products_wo_taxes_55',
'total_taxes_55',
'total_products_wo_taxes_21',
'total_taxes_21',
'total_products_wo_taxes_60',
'total_taxes_60',
'total_products_wo_taxes_40',
'total_taxes_40',
'total_products_wo_taxes_export',
'shipping_wo_taxes_196-200',
'shipping_wo_taxes_export',
'shipping_country',
'discounts',
'total_paid',
'total_paid_real',
'wholesale_price',
'payment_type',
'direct_payment',
//'date_send',
'refund_reason',
'date_subsribe',
'pays',
//'new',
);
fwrite($f, implode(';', $headers)."\n");
$orders = Db::getInstance()->ExecuteS('
SELECT o.id_order
FROM `'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'order_detail` d,
`'._DB_PREFIX_.'customer` c
WHERE
(o.valid = 1
OR (
o.valid = 0
AND (
(SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 6
OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 7
OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 11
)
))
AND c.id_customer = o.id_customer
AND d.id_order = o.id_order
AND o.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 1 MONTH, \'%Y-%m-01 00:00:00\')
AND o.date_add <= DATE_FORMAT(LAST_DAY("'.$now.'" - INTERVAL 1 MONTH), \'%Y-%m-%d 23:59:59\')
GROUP BY o.id_order
');
// $orders = Db::getInstance()->ExecuteS('
// SELECT o.id_order
// FROM `'._DB_PREFIX_.'orders` o,
// `'._DB_PREFIX_.'order_detail` d,
// `'._DB_PREFIX_.'customer` c
// WHERE
// (o.valid = 1
// OR (
// o.valid = 0
// AND (
// (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 6
// OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 7
// OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 11
// )
// ))
// AND c.id_customer = o.id_customer
// AND d.id_order = o.id_order
// AND o.date_add >= "'. date('Y') .'-01-01 00:00:00"
// GROUP BY o.id_order
// ');
foreach($orders as $o) {
$order = Db::getInstance()->ExecuteS('
SELECT c.*, c.`date_add` as subscribe, o.*, v.`version`
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c ON c.`id_customer` = o.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'customer_version` v ON v.`id_customer` = c.`id_customer`
WHERE o.id_order = '.$o['id_order'].'
');
$order = $order[0];
$multi = Db::getInstance()->getValue('
SELECT COUNT(DISTINCT `id_sale`)
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` IN (
SELECT `product_id` FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order['id_order'].'
)
') == 1? 'S': 'M';
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$invoice_address = Db::getInstance()->ExecuteS('
SELECT firstname, lastname
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.$order['id_address_invoice']
);
$invoice_address = $invoice_address[0];
$order_details = Db::getInstance()->ExecuteS('
SELECT d.*, p.`wholesale_price`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = d.`product_id`)
WHERE d.id_order = '.$o['id_order']
);
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_60 = array();
$total_taxes_60 = array();
$total_products_wo_taxes_40 = array();
$total_taxes_40 = array();
$total_products_wo_taxes_export = array();
$country = Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_country` = (
SELECT `id_country`
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $order['id_address_delivery'].'
LIMIT 1
)
AND `id_lang` = 2
');
$date_send = Db::getInstance()->getValue('
SELECT `date_add`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order_state` = 4
AND `id_order` = '.(int) $order['id_order'].'
ORDER BY `date_add` ASC
');
$ldetails = array();
$wholesale_price = 0;
foreach($order_details as $detail) {
$ldetails[$detail['id_order_detail']] = $detail;
$wholesale_price += (float) ($detail['wholesale_price'] * $detail['product_quantity']);
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '20.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.2);
}
/*}*/
} elseif($detail['tax_rate'] == '21.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_quantity_discount'] / 1.196);
$total_taxes_196[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.196);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.21);
}
/*}*/
} elseif($detail['tax_rate'] == '19.600') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_quantity_discount'] / 1.196);
$total_taxes_196[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.196);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.196);
}
/*}*/
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_quantity_discount'] / 1.055);
$total_taxes_55[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.055);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.055);
}
/*}*/
} elseif($detail['tax_rate'] == '2.100') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.021);
}
/*}*/
} elseif($detail['tax_rate'] == '6.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.060);
} else {
$total_products_wo_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.060);
}
/*}*/
} elseif($detail['tax_rate'] == '4.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.040);
} else {
$total_products_wo_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.040);
}
/*}*/
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
/*}*/
}
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
/*}*/
}
}
$_total_products_wo_taxes_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$_total_products_wo_taxes_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$_total_products_wo_taxes_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$_total_products_wo_taxes_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$_total_products_wo_taxes_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$_total_products_wo_taxes_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$_total_products_wo_taxes_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$_total_products_wo_taxes_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$_total_products_wo_taxes_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$_total_products_wo_taxes_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$_total_products_wo_taxes_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$_total_products_wo_taxes_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$_total_products_wo_taxes_60 = 0.0;
foreach($total_products_wo_taxes_60 as $value) {
$_total_products_wo_taxes_60 += $value;
}
$_total_taxes_60 = 0.0;
foreach($total_taxes_60 as $value) {
$_total_taxes_60 += $value;
}
$_total_products_wo_taxes_40 = 0.0;
foreach($total_products_wo_taxes_40 as $value) {
$_total_products_wo_taxes_40 += $value;
}
$_total_taxes_40 = 0.0;
foreach($total_taxes_40 as $value) {
$_total_taxes_40 += $value;
}
$_total_products_wo_taxes_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$_total_products_wo_taxes_export += $value;
}
// Find if it's a saved card or account for the payment (Direct payment)
$is_direct_payment = 0;
if($order['payment'] == 'Paybox') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_saved_card`
FROM `'._DB_PREFIX_.'paybox_transaction`
WHERE `id_cart` = '.(int) $order['id_cart'].'
');
} elseif ($order['payment'] == 'PayPal') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_billing`
FROM `'._DB_PREFIX_.'paypal_order`
WHERE `id_order` = '.(int) $order['id_order'].'
');
}
if((int)$is_direct_payment != 0) {
$order['direct_payment'] = "Oui";
} else {
$order['direct_payment'] = "Non";
}
fwrite($f, implode(';', array(
$order['date_add'],
//addslashes(implode(' / ', $sale_names)),
$order['id_order'],
0,
$order['invoice_number'],
$multi,
$order['id_customer'],
$invoice_address['firstname'],
$invoice_address['lastname'],
$_total_products_wo_taxes_210,
$_total_taxes_210,
$_total_products_wo_taxes_200,
$_total_taxes_200,
$_total_products_wo_taxes_196,
$_total_taxes_196,
$_total_products_wo_taxes_100,
$_total_taxes_100,
$_total_products_wo_taxes_55,
$_total_taxes_55,
$_total_products_wo_taxes_21,
$_total_taxes_21,
$_total_products_wo_taxes_60,
$_total_taxes_60,
$_total_products_wo_taxes_40,
$_total_taxes_40,
$_total_products_wo_taxes_export,
($address['id_country'] != 19? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0),
($address['id_country'] != 19? 0.0: $order['total_shipping']),
$country,
$order['total_discounts'],
$order['total_paid'],
$order['total_paid_real'],
$wholesale_price,
$order['payment'],
$order['direct_payment'],
//$date_send,
'',
$order['subscribe'],
$order['version']
// (int) Db::getInstance()->getValue('
// SELECT `id_order`
// FROM `'._DB_PREFIX_.'orders`
// WHERE `id_customer` = '.(int) $order['id_customer'].'
// AND `id_order` != '.(int) $order['id_order'].'
// ') == 0,
))."\n");
}
// This order has been refunded
$slips = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_slip` os
WHERE os.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 1 MONTH, \'%Y-%m-01 00:00:00\')
AND os.date_add <= DATE_FORMAT(LAST_DAY("'.$now.'" - INTERVAL 1 MONTH), \'%Y-%m-%d 23:59:59\')
');
// $slips = Db::getInstance()->ExecuteS('
// SELECT *
// FROM `'._DB_PREFIX_.'order_slip` os
// AND os.date_add >= "'. date('Y') .'-01-01 00:00:00"
// ');
$refundreasons = array(
'',
'CLIENT : Annulation pré-envoi',
'CLIENT : Rétractation post-envoi',
'BBB : Erreur Achat / Prod',
'FEUR : Problème SAV',
'FEUR : Produit manquant',
'BBB : Erreur logistique',
'Autre',
'BBB : Pbme Site / Paiement',
'TRANS : Colis détruit',
'TRANS : Colis perdu',
'CLIENT : Annulation pour ré-achat',
'BBB : Suspicion de fraude',
);
if(count($slips) > 0) {
foreach($slips as $slip) {
$order = Db::getInstance()->getRow('
SELECT o.*, c.*, c.`date_add` as subscribe, v.`version`
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON o.`id_customer` = c.`id_customer`
LEFT JOIN `'._DB_PREFIX_.'customer_version` v
ON c.`id_customer` = v.`id_customer`
WHERE
o.id_order = '.$slip['id_order'].'
');
$multi = Db::getInstance()->getValue('
SELECT COUNT(DISTINCT `id_sale`)
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` IN (
SELECT `product_id` FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order['id_order'].'
)
') == 1? 'S': 'M';
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$invoice_address = Db::getInstance()->ExecuteS('
SELECT firstname, lastname
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.$order['id_address_invoice']
);
$invoice_address = $invoice_address[0];
$order_details = Db::getInstance()->ExecuteS('
SELECT d.*, p.`wholesale_price`
FROM `'._DB_PREFIX_.'order_detail` d
LEFT JOIN `'._DB_PREFIX_.'product` p ON (p.`id_product` = d.`product_id`)
WHERE d.id_order = '.(int) $slip['id_order'].'
AND d.`id_order_detail` IN (
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_slip_detail`
WHERE `id_order_slip` = '.(int) $slip['id_order_slip'].'
)
');
$country = Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_country` = (
SELECT `id_country`
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $order['id_address_delivery'].'
LIMIT 1
)
AND `id_lang` = 2
');
$date_send = Db::getInstance()->getValue('
SELECT `date_add`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order_state` = 4
AND `id_order` = '.(int) $order['id_order'].'
ORDER BY `date_add` ASC
');
$ldetails = array();
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_60 = array();
$total_taxes_60 = array();
$total_products_wo_taxes_40 = array();
$total_taxes_40 = array();
$total_products_wo_taxes_export = array();
$wholesale_price = 0;
foreach($order_details as $detail) {
/*$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_export = array();*/
$ldetails[$detail['id_order_detail']] = $detail;
$wholesale_price += (float) ($detail['wholesale_price'] * $detail['product_quantity_refunded']);
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '19.600') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_quantity_discount'] / 1.196);
$total_taxes_196[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.196);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.196);
}
/*}*/
} elseif($detail['tax_rate'] == '21.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_quantity_discount'] / 1.055);
$total_taxes_55[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.055);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.21);
}
/*}*/
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_quantity_discount'] / 1.055);
$total_taxes_55[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.055);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.055);
}
/*}*/
} elseif($detail['tax_rate'] == '2.100') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.021);
}
/*}*/
} elseif($detail['tax_rate'] == '20.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.2);
}
/*}*/
} elseif($detail['tax_rate'] == '6.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_60[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_60[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_60[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.06);
} else {
$total_products_wo_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_60[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.06);
}
/*}*/
} elseif($detail['tax_rate'] == '4.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_40[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_40[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_40[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.04);
} else {
$total_products_wo_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_40[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.04);
}
/*}*/
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
/*}*/
}
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
/*}*/
}
}
$_total_products_wo_taxes_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$_total_products_wo_taxes_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$_total_products_wo_taxes_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$_total_products_wo_taxes_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$_total_products_wo_taxes_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$_total_products_wo_taxes_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$_total_products_wo_taxes_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$_total_products_wo_taxes_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$_total_products_wo_taxes_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$_total_products_wo_taxes_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$_total_products_wo_taxes_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$_total_products_wo_taxes_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$_total_products_wo_taxes_60 = 0.0;
foreach($total_products_wo_taxes_60 as $value) {
$_total_products_wo_taxes_60 += $value;
}
$_total_taxes_60 = 0.0;
foreach($total_taxes_60 as $value) {
$_total_taxes_60 += $value;
}
$_total_products_wo_taxes_40 = 0.0;
foreach($total_products_wo_taxes_40 as $value) {
$_total_products_wo_taxes_40 += $value;
}
$_total_taxes_40 = 0.0;
foreach($total_taxes_40 as $value) {
$_total_taxes_40 += $value;
}
$_total_products_wo_taxes_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$_total_products_wo_taxes_export += $value;
}
$refundreason = Db::getInstance()->getValue('
SELECT `id_reason`
FROM `'._DB_PREFIX_.'refundreason`
WHERE `id_order_slip` = '.(int) $slip['id_order_slip'].'
');
$refundreason = $refundreasons[(int) $refundreason];
// Find if it's a saved card or account for the payment (Direct payment)
$is_direct_payment = 0;
if($order['payment'] == 'Paybox') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_saved_card`
FROM `'._DB_PREFIX_.'paybox_transaction`
WHERE `id_cart` = '.(int) $order['id_cart'].'
');
} elseif ($order['payment'] == 'PayPal') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_billing`
FROM `'._DB_PREFIX_.'paypal_order`
WHERE `id_order` = '.(int) $order['id_order'].'
');
}
if((int)$is_direct_payment != 0) {
$order['direct_payment'] = "Oui";
} else {
$order['direct_payment'] = "Non";
}
fwrite($f, implode(';', array(
$slip['date_add'],
//addslashes(implode(' / ', $sale_names)),
$order['id_order'],
$slip['id_order_slip'],
$order['invoice_number'],
$multi,
$order['id_customer'],
$invoice_address['firstname'],
$invoice_address['lastname'],
'-'.$_total_products_wo_taxes_210,
'-'.$_total_taxes_210,
'-'.$_total_products_wo_taxes_200,
'-'.$_total_taxes_200,
'-'.$_total_products_wo_taxes_196,
'-'.$_total_taxes_196,
'-'.$_total_products_wo_taxes_100,
'-'.$_total_taxes_100,
'-'.$_total_products_wo_taxes_55,
'-'.$_total_taxes_55,
'-'.$_total_products_wo_taxes_21,
'-'.$_total_taxes_21,
'-'.$_total_products_wo_taxes_60,
'-'.$_total_taxes_60,
'-'.$_total_products_wo_taxes_40,
'-'.$_total_taxes_40,
'-'.$_total_products_wo_taxes_export,
'-'.($slip['shipping_cost'] == 1? ($address['id_country'] != 19? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0): 0.0),
'-'.($slip['shipping_cost'] == 1? ($address['id_country'] != 19? 0.0: $order['total_shipping']): 0.0),
$country,
'-0.0',
'-'.($_total_products_wo_taxes_210 + $_total_taxes_210 + $_total_products_wo_taxes_200 + $_total_taxes_200 + $_total_products_wo_taxes_196 + $_total_taxes_196 + $_total_products_wo_taxes_100 + $_total_taxes_100 + $_total_products_wo_taxes_55 + $_total_taxes_55 + $_total_products_wo_taxes_21 + $_total_taxes_21 + $_total_products_wo_taxes_60 + $_total_taxes_60 + $_total_products_wo_taxes_40 + $_total_taxes_40 + $_total_products_wo_taxes_export + ($slip['shipping_cost'] == 1? (float) $order['total_shipping']: 0.0)),
'-'.($_total_products_wo_taxes_210 + $_total_taxes_210 + $_total_products_wo_taxes_200 + $_total_taxes_200 + $_total_products_wo_taxes_196 + $_total_taxes_196 + $_total_products_wo_taxes_100 + $_total_taxes_100 + $_total_products_wo_taxes_55 + $_total_taxes_55 + $_total_products_wo_taxes_21 + $_total_taxes_21 + $_total_products_wo_taxes_60 + $_total_taxes_60 + $_total_products_wo_taxes_40 + $_total_taxes_40 + $_total_products_wo_taxes_export + ($slip['shipping_cost'] == 1? (float) $order['total_shipping']: 0.0)),
'-'.$wholesale_price,
'REFUND '.strtoupper($order['payment']),
$order['direct_payment'],
//$date_send,
$refundreason,
$order['subscribe'],
$order['version'],
//'',
))."\n");
}
}
fclose($f);
exit;

37
cron_loyalty.php Normal file
View File

@ -0,0 +1,37 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
include dirname(__FILE__).'/www/config/config.inc.php';
include dirname(__FILE__).'/www/modules/loyalty/LoyaltyStateModule.php';
include dirname(__FILE__).'/www//modules/loyalty/LoyaltyModule.php';
$loyaltyStateValidation = new LoyaltyStateModule(LoyaltyStateModule::getValidationId());
foreach (Db::getInstance()->ExecuteS('
SELECT lo.`id_order`, oh.`id_order_state`
FROM `'._DB_PREFIX_.'loyalty` lo
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = lo.`id_order`)
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = lo.`id_order` GROUP BY moh.`id_order`)
AND oh.`id_order_state` = 4 AND lo.`id_loyalty_state` NOT IN (2,4)
') as $order) {
if (!Validate::isLoadedObject($loyalty = new LoyaltyModule(LoyaltyModule::getByOrderId((int)$order['id_order'])))) {
continue;
}
if ((int)Configuration::get('PS_LOYALTY_NONE_AWARD') AND $loyalty->id_loyalty_state == LoyaltyStateModule::getNoneAwardId()) {
continue;
}
if ((int)$order['id_order_state'] == $loyaltyStateValidation->id_order_state)
{
$loyalty->id_loyalty_state = LoyaltyStateModule::getValidationId();
if ((float)($loyalty->discount_value) == 0) {
$loyalty->discount_value = LoyaltyModule::getOrderDiscountValue($order);
}
}
$loyalty->save();
}

View File

@ -0,0 +1,2 @@
<?php

1310
cron_queue_bdc.php Normal file

File diff suppressed because it is too large Load Diff

28
cron_sale_cache.php Normal file
View File

@ -0,0 +1,28 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/www/config/config.inc.php';
$min_id_product = Db::getInstance()->getValue('
SELECT MIN(`id_product`) FROM `'._DB_PREFIX_.'product` WHERE `date_add` > DATE_SUB(NOW(), INTERVAL 10 DAY)
');
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` >= '.$min_id_product.'
');
Db::getInstance()->ExecuteS('
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
SELECT p.id_product, IFNULL(
(
SELECT s.id_sale
FROM `'._DB_PREFIX_.'privatesale_category` s
WHERE s.`id_category` = p.`id_category_default`
LIMIT 1)
, 0
)
FROM `'._DB_PREFIX_.'product` p
WHERE p.`id_product` >= '.$min_id_product.'
)
');

129
cron_sales.php Normal file
View File

@ -0,0 +1,129 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/www/config/config.inc.php';
include dirname(__FILE__).'/www/modules/exports/exports/privatesales.php';
$date = $argv[1];
$file = fopen(dirname(__FILE__).'/extracts/sales_weekly/'.$date.'.csv', 'w');
fputcsv($file, array(
'id_sale',
'sale_title',
'id_order',
'id_customer',
'gender',
'email',
'firstname',
'lastname',
'shipping_firstname',
'shipping_lastname',
'shipping_street',
'shipping_street2',
'shipping_postcode',
'shipping_city',
'shipping_phone',
'shipping_phone_mobile',
'other_info',
'shipping_country',
'id_product',
'id_product_attribute',
'order_product_name',
'product_quantity',
'product_price_base_wo_taxes',
'tax_rate',
'product_name',
'product_combination',
'product_price_wo_taxes',
'product_price',
'wholesale_price',
'combination_wholesale_price',
'supplier_reference',
'quantity_refunded',
'quantity_returned',
'total_shipping',
'single',
'date',
'invoice_number',
'payment_type',
'order_state',
'delivery_mode',
'version',
'family',
'domaine',
), ';', '"');
foreach(Db::getInstance()->ExecuteS('
SELECT `id_sale`
FROM `'._DB_PREFIX_.'privatesale`
WHERE `date_start` < "'.pSQL($argv[1]).' 00:00:00"
AND `id_sale` > 3000
') as $row) {
$sale = new Sale($row['id_sale']);
$e = new CronExport('privatesales', array(
'headers' => array(
'id_sale',
'sale_title',
'id_order',
'id_customer',
'gender',
'email',
'firstname',
'lastname',
'shipping_firstname',
'shipping_lastname',
'shipping_street',
'shipping_street2',
'shipping_postcode',
'shipping_city',
'shipping_phone',
'shipping_phone_mobile',
'other_info',
'shipping_country',
'id_product',
'id_product_attribute',
'order_product_name',
'product_quantity',
'product_price_base_wo_taxes',
'tax_rate',
'product_name',
'product_combination',
'product_price_wo_taxes',
'product_price',
'wholesale_price',
'combination_wholesale_price',
'supplier_reference',
'quantity_refunded',
'quantity_returned',
'total_shipping',
'single',
'date',
'invoice_number',
'payment_type',
'order_state',
'delivery_mode',
'version',
'family',
'domaine',
),
'postfix' => '_'.$id_sale.'_manual',
'dest_path' => '/../extracts/sales',
'params' => array(
'sale' => $sale,
'date_start' => date('Y-m-d 00:00:00', strtotime($argv[1].' 00:00:00') - 7*86400),
'date_end' => date('Y-m-d 23:59:59', strtotime($argv[1].' 00:00:00') - 1),
),
));
$e->run();
$export = fopen($e->filename, 'r');
fgets($export);
while(!feof($export)) {
fwrite($file, fgets($export));
}
fclose($export);
unlink($e->filename);
}
fclose($file);

122
cron_sales_accepted.php Executable file
View File

@ -0,0 +1,122 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/www/config/config.inc.php';
include dirname(__FILE__).'/www/modules/exports/exports/privatesales_accepted.php';
$date = $argv[1];
$file = fopen(dirname(__FILE__).'/extracts/sales_weekly_accepted/'.$date.'.csv', 'w');
fputcsv($file, array(
'id_sale',
'sale_title',
'id_order',
'id_customer',
'gender',
'email',
'firstname',
'lastname',
'shipping_firstname',
'shipping_lastname',
'shipping_street',
'shipping_street2',
'shipping_postcode',
'shipping_city',
'shipping_phone',
'shipping_phone_mobile',
'other_info',
'shipping_country',
'id_product',
'id_product_attribute',
'order_product_name',
'product_quantity',
'product_price_base_wo_taxes',
'tax_rate',
'product_name',
'product_combination',
'product_price_wo_taxes',
'product_price',
'wholesale_price',
'combination_wholesale_price',
'supplier_reference',
'quantity_refunded',
'quantity_returned',
'total_shipping',
'single',
'date',
'invoice_number',
'payment_type',
'order_state',
'version',
), ';', '"');
foreach(Db::getInstance()->ExecuteS('
SELECT `id_sale`
FROM `'._DB_PREFIX_.'privatesale`
WHERE `date_start` < "'.pSQL($argv[1]).' 00:00:00"
') as $row) {
$sale = new Sale($row['id_sale']);
$e = new CronExport('privatesales', array(
'headers' => array(
'id_sale',
'sale_title',
'id_order',
'id_customer',
'gender',
'email',
'firstname',
'lastname',
'shipping_firstname',
'shipping_lastname',
'shipping_street',
'shipping_street2',
'shipping_postcode',
'shipping_city',
'shipping_phone',
'shipping_phone_mobile',
'other_info',
'shipping_country',
'id_product',
'id_product_attribute',
'order_product_name',
'product_quantity',
'product_price_base_wo_taxes',
'tax_rate',
'product_name',
'product_combination',
'product_price_wo_taxes',
'product_price',
'wholesale_price',
'combination_wholesale_price',
'supplier_reference',
'quantity_refunded',
'quantity_returned',
'total_shipping',
'single',
'date',
'invoice_number',
'payment_type',
'order_state',
'version',
),
'postfix' => '_'.$id_sale.'_manual_accepted',
'dest_path' => '/../extracts/sales',
'params' => array(
'sale' => $sale,
'date_start' => date('Y-m-d 00:00:00', strtotime($argv[1].' 00:00:00') - 60*86400),
'date_end' => date('Y-m-d 23:59:59', strtotime($argv[1].' 00:00:00') - 1),
),
));
$e->run();
$export = fopen($e->filename, 'r');
fgets($export);
while(!feof($export)) {
fwrite($file, fgets($export));
}
fclose($export);
unlink($e->filename);
}
fclose($file);

203
cron_weekly_stats.php Normal file
View File

@ -0,0 +1,203 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) exit;
$_SERVER['SERVER_PORT'] = 80;
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/www/config/config.inc.php';
include dirname(__FILE__).'/www/init.php';
include dirname(__FILE__).'/www/modules/privatesales/Sale.php';
include dirname(__FILE__).'/www/modules/privatesales_logistique/classes/OrderForm.php';
include dirname(__FILE__).'/www/modules/privatesales_logistique/classes/MakeStats.php';
include dirname(__FILE__).'/www/modules/privatesales_logistique/classes/SaleStats.php';
$now = $argv[1].' 00:00:00';
$f = fopen('extracts/sales_stats/'.date('Y-m-d', strtotime($now)).'.csv', 'w');
$headers = array(
'sale_id',
'name',
'date_start',
'date_end',
'duration',
'nb_ref',
'nb_quantity_start',
'nb_order_simple',
'nb_order_multi',
'nb_order_total',
'taux_multi',
'quantity_sale',
'percent_in_stock',
'percent_out_of_stock',
'ca_ttc_product',
'bdc_ht',
'marge',
'bestsale1',
'quantity',
'ht',
'bestsale2',
'quantity',
'ht',
'bestsale3',
'quantity',
'ht',
'category_title',
'nb_id',
'quantity_sold',
'total_buy_ht',
'category_title',
'nb_id',
'quantity_sold',
'total_buy_ht',
'category_title',
'nb_id',
'quantity_sold',
'total_buy_ht',
'category_title',
'nb_id',
'quantity_sold',
'total_buy_ht',
'category_title',
'nb_id',
'quantity_sold',
'total_buy_ht',
'category_title',
'nb_id',
'quantity_sold',
'total_buy_ht',
'category_title',
'nb_id',
'quantity_sold',
'total_buy_ht',
'category_title',
'nb_id',
'quantity_sold',
'total_buy_ht',
'category_title',
'nb_id',
'quantity_sold',
'total_buy_ht',
);
fwrite($f, implode(';', $headers)."\n");
$id_lang = 2;
$sales = Db::getInstance()->ExecuteS('
SELECT `id_sale`, `id_category`
FROM `'._DB_PREFIX_.'privatesale`
WHERE `date_end` >= DATE_FORMAT("'.$now.'" - INTERVAL 7 DAY, \'%Y-%m-%d 00:00:00\')
AND `date_end` < DATE_FORMAT("'.$now.'", \'%Y-%m-%d 00:00:00\')
ORDER BY `date_end`
');
//echo "<pre>";var_dump($sales);echo "</pre>";die();
foreach($sales as $row) {
//echo $row['id_sale']." - ".$row['id_category']."\n";
$id_category = (int) $row['id_category'];
$category = new Category($id_category, $id_lang);
$sale = new Sale((int)$row['id_sale']);
$products = $category->getProductsStats($id_lang , "1", "1000000000000000000", "reference",NULL , FALSE, FALSE , FALSE );
$arrayProduct = array();
foreach($products as $product)
$array_product[$product['id_product']] = $arrayProduct[$product['id_product']] = new Product($product['id_product']);
$order_states = explode(',', Configuration::get('PS_IT_OF_ORDER_STATES'));
$lines = MakeStats::getOrdersByIdsProduct(array_keys($arrayProduct), $order_states);
// for stats
$lines_tmp = $lines;
$lines = MakeStats::getArrayLines($lines);
$stats = new SaleStats($sale, $category);
$stats->loadData();
$total_sale_product = array();
$total_sale_ht = 0;
foreach ($lines_tmp as $key => $order_line) {
$id_product = $order_line['product_id'];
$id_product_attribute = $order_line['product_attribute_id'];
$current_product = $array_product[$id_product];
if($id_product_attribute != 0) {
$combination = new Combination($id_product_attribute);
if($combination->wholesale_price == 0) {
$wholesale_price = $current_product->wholesale_price;
} else {
$wholesale_price = $combination->wholesale_price;
}
} else {
$wholesale_price = $current_product->wholesale_price;
}
$quantity_to_cmd = $order_line['product_quantity'] - $order_line['product_quantity_reinjected'];
$total_sale_ht += $quantity_to_cmd * $wholesale_price;
if (!is_array($total_sale_product[(int)$id_product]) ){
$total_sale_product[(int)$id_product] = array();
$total_sale_product[(int)$id_product]['total_ht'] = 0;
$total_sale_product[(int)$id_product]['quantiy'] = 0;
$total_sale_product[(int)$id_product]['name'] = $current_product->name[2];
}
$total_sale_product[(int)$id_product]['total_ht'] += ($wholesale_price * $quantity_to_cmd);
$total_sale_product[(int)$id_product]['quantiy'] += $quantity_to_cmd;
}
$stats->addToStats('total_bdc_ht', $total_sale_ht);
$bestsales = MakeStats::orderMultiArray($total_sale_product, 'total_ht');
$bestsales_extract = array_slice($bestsales, 0, 3);
$i = 1;
foreach ($bestsales_extract as $key => $bestsalesProduct) {
$stats->addToStats('bestsale_'.$i.'_product', $bestsalesProduct['name']);
$stats->addToStats('bestsale_'.$i.'_quantity', $bestsalesProduct['quantiy']);
$stats->addToStats('bestsale_'.$i.'_ca', $bestsalesProduct['total_ht']);
$i++;
}
$stats->loadDataForSubCategory();
$csv_row = array(
$row['id_sale'],
$stats->data_stats['name'],
$stats->data_stats['date_start'],
$stats->data_stats['date_end'],
$stats->data_stats['duration'],
$stats->data_stats['nb_ref'],
$stats->data_stats['nb_quantity_start'],
$stats->data_stats['nb_order_simple'],
$stats->data_stats['nb_order_multi'],
$stats->data_stats['nb_order_total'],
$stats->data_stats['taux_multi'],
$stats->data_stats['quantity_sale'],
$stats->data_stats['percent_sale'],
$stats->data_stats['percent_out_of_stock'],
Tools::displayPrice($stats->data_stats['ca_ttc']),
Tools::displayPrice($stats->data_stats['total_bdc_ht']),
$stats->data_stats['marge'],
(isset($stats->data_stats['bestsale_1_product'])?$stats->data_stats['bestsale_1_product']:''),
(isset($stats->data_stats['bestsale_1_quantity'])?$stats->data_stats['bestsale_1_quantity']:''),
(isset($stats->data_stats['bestsale_1_ca'])?Tools::displayPrice($stats->data_stats['bestsale_1_ca']):0),
(isset($stats->data_stats['bestsale_2_product'])?$stats->data_stats['bestsale_2_product']:''),
(isset($stats->data_stats['bestsale_2_quantity'])?$stats->data_stats['bestsale_2_quantity']:''),
(isset($stats->data_stats['bestsale_2_ca'])?Tools::displayPrice($stats->data_stats['bestsale_2_ca']):0),
(isset($stats->data_stats['bestsale_3_product'])?$stats->data_stats['bestsale_3_product']:''),
(isset($stats->data_stats['bestsale_3_quantity'])?$stats->data_stats['bestsale_3_quantity']:''),
(isset($stats->data_stats['bestsale_3_ca'])?Tools::displayPrice($stats->data_stats['bestsale_3_ca']):0),
);
foreach ($stats->data_subcategories as $key => $subcategories) {
foreach ($subcategories as $key_2 => $subcategory) {
if ($key_2 == 'total_amount_wholesale_price') {
$csv_row[] = Tools::displayPrice($subcategory);
} else {
$csv_row[]= $subcategory;
}
$i++;
}
}
fwrite($f, implode(';', $csv_row)."\n");
}
fclose($f);
exit;

56
export_cart.php Normal file
View File

@ -0,0 +1,56 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
include('www/config/config.inc.php');
$date_current = new DateTime('2015-04-21');
$date_end = new DateTime('2015-04-29');
$export_total = fopen('export_avril.csv', 'w');
$headers = array(
'Id cart',
'Name',
'Total',
'Carrier',
'Date'
);
fputcsv($export_total, $headers, ';');
while ($date_current <= $date_end) {
$file = fopen('tmp/export-'.$date_current->format('Y-m-d').'.csv', 'w');
$batch = 50;
$i = 0;
$data = '';
foreach ( Db::getInstance()->executeS('
SELECT CONCAT(c.lastname," ", c.firstname) as name, ca.name carrier, a.id_cart, a.id_customer, a.id_currency, a.date_add
FROM ps_cart a
LEFT JOIN `ps_customer` c ON (c.`id_customer` = a.`id_customer`)
LEFT JOIN `ps_carrier` ca ON (ca.`id_carrier` = a.`id_carrier`)
WHERE a.date_add >= "'.$date_current->format('Y-m-d').' 00:00:00"
AND a.date_add <= "'.$date_current->format('Y-m-d').' 23:59:59"
') as $key => $cart) {
$cartObj = new Cart($cart['id_cart']);
$data.= $cart['id_cart'].';'.$cart['name'].';'.$cartObj->getOrderTotal().';'.$cart['carrier'].';'.$cart['date_add']."\n";
$i++;
if($i % $batch == 0) {
writeFile($file, $data);
$data = '';
$i = 0;
}
}
writeFile($file, $data);
fwrite($export_total, file_get_contents('tmp/export-'.$date_current->format('Y-m-d').'.csv') );
fclose($file);
unlink('tmp/export-'.$date_current->format('Y-m-d').'.csv');
$date_current->add(new DateInterval('P1D'));
}
fclose($export_total);
function writeFile($file, $data) {
fwrite($file, $data);
}

298
export_laposte.php Executable file
View File

@ -0,0 +1,298 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['SERVER_ADDR'] = '37.187.137.153';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
include dirname(__FILE__).'/www/config/config.inc.php';
function csv($file_handle, $data, $field_separator=';', $enclosure='"', $record_separator="\n") {
escape(FALSE, $enclosure);
$data = array_map('escape', $data);
fwrite($file_handle, $enclosure.implode($enclosure.$field_separator.$enclosure, $data).$enclosure.$record_separator);
}
function escape($data, $enclosure=FALSE) {
static $enc;
if($enclosure === FALSE) {
return str_replace($enc, '\\'.$enc, $data);
}
$enc = $enclosure;
}
function getPublicHolidays(DateTime $date=NULL) {
if($date === NULL) {
$date = new DateTime();
}
$easterDate = new DateTime('@'.easter_date($date->format('Y')));
// Set Visitor / Customer TimeZone (If server not configured or using e-commerce website for ex.)
$easterDate->setTimezone(new DateTimeZone('Europe/Paris'));
$date->setTimezone(new DateTimeZone('Europe/Paris'));
// Fixed date list
$publicHolidaysList = array(
new DateTime($date->format('Y-1-1')), // New Year
new DateTime($date->format('Y-5-1')), // Labor day
new DateTime($date->format('Y-5-8')), // 1945
new DateTime($date->format('Y-7-14')), // National Holiday
new DateTime($date->format('Y-8-15')), // Assumption
new DateTime($date->format('Y-11-1')), // All Saints Day
new DateTime($date->format('Y-11-11')), // Armistice
new DateTime($date->format('Y-12-25')), // Christmas
);
$easterDate1 = new DateTime($easterDate->format('Y-m-d'));
$easterDate1->modify('+1 day');
$easterDate2 = new DateTime($easterDate->format('Y-m-d'));
$easterDate2->modify('+39 day');
$easterDate3 = new DateTime($easterDate->format('Y-m-d'));
$easterDate3->modify('+50 day');
$publicHolidaysList[] = $easterDate1;
$publicHolidaysList[] = $easterDate2;
$publicHolidaysList[] = $easterDate3;
// Sort DateTime
usort($publicHolidaysList, function($a, $b) {
$interval = $a->diff($b);
return $interval->invert? 1: -1;
});
return $publicHolidaysList;
}
$holidays = getPublicHolidays();
$contract = Configuration::get('LAPOSTEWS_API_CONTRACT');
$contract2 = Configuration::get('LAPOSTEWS_API_CONTRACT2');
$now = new Datetime();
$now->setTimezone(new DateTimeZone('Europe/Paris'));
//$now->modify('-1 day');
$id_orders = array();
$orders_to_print = array();
$f = fopen(dirname(__FILE__).'/extracts/itinsell/'.$now->format('Y-m-d').'_laposte.csv', 'w');
//$f = fopen(dirname(__FILE__).'/extracts/itinsell/'.$now->format('Y-m-d').'_philea_laposte.csv', 'w');
csv($f, array(
'shipping_number',
'product_code',
'reference',
'recipient',
'address1',
'address2',
'address3',
'address4',
'postcode',
'city',
'country',
'phone',
'email',
'weight',
'parcel_quantity',
'saturday_delivery',
'oversized',
'instructions',
'contract',
'summary_number',
'summary_date',
'description',
'value',
'order_value',
'customer_shipping_value',
'pod_value',
'insurance_value',
'shipping_value',
'delivery_date',
'id_delivery_point',
));
// $orders_laposte = array();
$orders_laposte = Db::getInstance()->ExecuteS('
SELECT l.`shipping_number`, o.`id_order`, o.`id_cart`, o.`id_address_delivery`, l.`date_add`
FROM `'._DB_PREFIX_.'lapostews` l
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON l.`id_order_detail` = d.`id_order_detail`
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON d.`id_order` = o.`id_order`
WHERE l.`date_add` >= "'.pSQL($now->format('Y-m-d 00:00:00')).'" and l.`date_add` <= "'.pSQL($now->format('Y-m-d 23:59:59')).'"
GROUP BY l.`shipping_number`
');
// $orders_philea = Db::getInstance()->ExecuteS('
// SELECT pp.`shipping_number`, o.`id_order`, o.`id_cart`, o.`id_address_delivery`, pp.`date_add`
// FROM `'._DB_PREFIX_.'philea_parcel` pp
// LEFT JOIN `'._DB_PREFIX_.'order_detail` d
// ON pp.`id_order_detail` = d.`id_order_detail`
// LEFT JOIN `'._DB_PREFIX_.'orders` o
// ON d.`id_order` = o.`id_order`
// WHERE pp.`date_add` >= "'.pSQL($now->format('Y-m-d 00:00:00')).'" and pp.`date_add` <= "'.pSQL($now->format('Y-m-d 23:59:59')).'"
// GROUP BY pp.`shipping_number`
// ');
// $orders = array_merge($orders_laposte, $orders_philea);
foreach($orders_laposte as $row) {
$orders_to_print[] = (int) $row['id_order'];
$delivery_so = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $row['id_cart'].'
');
$delivery = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $row['id_address_delivery'].'
');
$delivery_date = FALSE;
$hour = explode(' ', $row['date_add']);
$hour = explode(':', $hour[1]);
if($delivery_so && $delivery_so['cecountry'] == 'FR' || $delivery['id_country'] == 8) {
$delivery_date = new DateTime($now->format('Y-m-d'));
$delivery_date->setTimezone(new DateTimeZone('Europe/Paris'));
$delivery_date->modify('+1 day');
if((int) $hour[0] > 16 || ((int) $hour[0] == 16 && (int) $hour[1] >= 30)) {
$delivery_date->modify('+1 day');
}
$i = 1;
while($i > 0) {
$is_holiday = FALSE;
foreach($holidays as $holiday) {
if($holiday->format('Y-m-d') == $delivery_date->format('Y-m-d')) {
$is_holiday = TRUE;
break;
}
}
if((int) $delivery_date->format('w') == 0) {
$is_holiday = TRUE;
}
$delivery_date->modify('+1 day');
if(!$is_holiday) {
$i--;
}
}
}
if(!$delivery_so) {
csv($f, array(
$row['shipping_number'],
'',
$row['id_order'],
($delivery['company'] != ''? $delivery['company'].' - ': '').$delivery['firstname'].' '.$delivery['lastname'],
trim(str_replace(array("\n", "\r"), ' ', $delivery['address1'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery['address2'])),
'',
'',
(string) $delivery['postcode'],
$delivery['city'],
Country::getIsoById((int) $delivery['id_country']),
str_replace(' ', '', (string) ($delivery['phone_mobile'] != ''? $delivery['phone_mobile']: $delivery['phone'])),
Db::getInstance()->getValue('SELECT `email` FROM `'._DB_PREFIX_.'customer` WHERE `id_customer` = '.(int) $delivery['id_customer']),
0.24,
1,
1,
'N',
trim(str_replace(array("\n", "\r"), ' ', $delivery['other'])),
(int) $delivery['id_country'] == 8? $contract: $contract2,
$now->format('Ymd'),
$now->format('d/m/Y'),
'',
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
$delivery_date? $delivery_date->format('d/m/Y'): '',
'',
));
} else {
csv($f, array(
$row['shipping_number'],
'',
$row['id_order'],
str_replace(array("\n", "\r"), ' ', ($delivery_so['prcompladress'] != ''? $delivery_so['prcompladress'].' - ': '').($delivery_so['cecompanyname'] != ''? $delivery_so['cecompanyname'].' - ': '').$delivery_so['prfirstname'].' '.$delivery_so['prname']),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress3'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress4'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress1'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress2'])),
(string) $delivery_so['przipcode'],
$delivery_so['prtown'],
$delivery_so['cecountry'],
str_replace(' ', '', $delivery_so['cephonenumber'] != ''? (string) $delivery_so['cephonenumber']: ((string) ($delivery['phone_mobile'] != ''? $delivery['phone_mobile']: $delivery['phone']))),
$delivery_so['ceemail'],
0.24,
1,
1,
'N',
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['cedeliveryinformation'])),
$delivery_so['cecountry'] == 'FR'? $contract: $contract2,
$now->format('Ymd'),
$now->format('d/m/Y'),
'',
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
$delivery_date? $delivery_date->format('d/m/Y'): '',
$delivery_so['prid'],
));
}
$pdf = new PDF('P', 'mm', 'A4');
$order = new Order((int) $row['id_order']);
if(Validate::isLoadedObject($order)) {
$id_orders[] = (int) $order->id;
PDF::invoice($order, 'F', TRUE, $pdf);
$pdf->Output(dirname(__FILE__).'/extracts/invoices/'.(int) $order->id.'.pdf', 'F');
}
}
fclose($f);
/**
* Regeneration invoices for specific orders
* using this includes to comment all about csv
*/
// $orders_to_reprint = array(350385,302554,300088,286495,290190,296685,290539,291935,287612,284108,285930,285284,288626,290659,295252,292214,287915,278572,282846,281120,281324,292999,279299,278681,276840,272366,274417,276233,272552,267126,273451,267563,266108,267186,269235,258571,257172,258306,259788,259000,259547,254186,225736,334010,332694,325773,325773,323595,323595,306923,306923,304776,304776,302960,302960,305645,305645,285700,274391,272544,271819,265852,260292,259059,265544,257100,234423,240829,240829,233767,217497,205633,203823,201126,187387,185462,179854,166753,176233,183491,177402,369986,367072,367383,367970,368338,339107,339107,338759,334924,327402,320364,320364,332667,332667,320441,320441,311542,311542,308895,308895,307577,307577,266573,277760,274366,274318,273079,257063,256322,250723,245678,238412,237659,196253,192709,180700,180046,175868,381283,369164,367304,367982,367104,370224,366966,370107,366177,369315,362975,367252,361380,365123,370909,359931,360698,363246,358396,361919,361608,357811,357270,367977,357509,356946,357199,357199,351217,351217,335669,335669,339127,336501,334378,334378,348116,348116,335330,336653,336653,331109,330480,330480,332355,332355,328706,328706,338370,338370,330071,330071,328154,328154,327939,327939,327736,327736,328201,328201,324345,324345,324978,324978,323388,323388,324598,324598,320183,320183,320935,320935,319958,319958,302878,292803,292803,298027,297052,298746,291544,292090,290810,290168,287607,287277,285811,289946,289048,285813,287451,285987,291066,289082,288720,286209,283027,289347,284717,295020,283355,280889,284988,278545,284070,282825,280327,279775,277188,278137,278137,281455,277836,271812,275407,274469,279319,271066,270306,271764,273388,267492,272076,277800,284796,284462,275265,270320,270486,270171,269886,266411,266333,268554,264148,265590,262954,262851,260846,262689,261596,262103,261976,261521,262447,260983,259890,262905,260747,261067,258471,243813,225221,229011,222430,203373,204814,206033,204894,200585,200839,200125,198425,188263,197940,194892,187277,188266,176280,372718,356628,357331,357178,357326,353230,353230,356461,356461,353210,353210,363733,363733,351215,353296,349932,350221,350221,349221,349358,349221,349894,348980,349745,345763,347674,347674,356852,346516,346516,345297,345297,347205,347205,343485,343485,345911,345911,344243,344243,354164,354164,342709,340429,340429,342041,342041,314782,314782,317374,317374,315947,315947,312628,312628,313425,313425,312877,312877,311916,311916,313144,311534,311534,310128,310128,309820,309820,310808,310808,309611,309611,308859,308859,307387,307387,306365,306365,305878,305878,315960,315960,304861,304861,306712,304406,304406,307734,307734,303634,303634,301336,301336,301295,301295,302048,302048,301446,301446,301446,301446,309768,309768,307734,301235,305236,304360,294794,256386,267588,259733,255594,250994,255479,253251,252393,252441,251929,252987,252734,249873,250484,249240,248519,248202,256012,250175,248340,250448,248500,246880,249146,247554,247139,246179,246930,245615,246352,241094,244392,241484,241314,240026,240797,240427,239982,240330,237796,237127,238402,239833,239833,245077);
// foreach ($orders_to_reprint as $key => $order_id) {
// $pdf = new PDF('P', 'mm', 'A4');
// $order = new Order((int) $order_id);
// if(Validate::isLoadedObject($order)) {
// $id_orders[] = (int) $order->id;
// PDF::invoice($order, 'F', TRUE, $pdf);
// $pdf->Output(dirname(__FILE__).'/extracts/invoices/'.(int) $order->id.'.pdf', 'F');
// }
// }
$ftp = ftp_connect('ftp.itrack.itinsell.com');
ftp_login($ftp, '800914', 'xt954hVUbg');
ftp_put($ftp, 'CSV/'.$now->format('Y-m-d').'_bbb_laposte.csv', dirname(__FILE__).'/extracts/itinsell/'.$now->format('Y-m-d').'_laposte.csv', FTP_BINARY);
foreach($id_orders as $id_order) {
ftp_put($ftp, 'FacturesCommerciales/'.(int) $id_order.'.pdf', dirname(__FILE__).'/extracts/invoices/'.(int) $id_order.'.pdf', FTP_BINARY);
unlink(dirname(__FILE__).'/extracts/invoices/'.(int) $id_order.'.pdf');
}
ftp_close($ftp);

783
export_multi_monthly.php Executable file
View File

@ -0,0 +1,783 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
$now = '2017-01-01 00:00:00';
function getChildren($id=0) {
return Db::getInstance()->ExecuteS('
SELECT id_parent, id_category
FROM `'._DB_PREFIX_.'category`
WHERE `id_parent` = '.$id
);
}
function getCat($id=0, $title='') {
$products = Db::getInstance()->ExecuteS('
SELECT id_product, "'.addslashes($title).'" AS `title`
FROM `'._DB_PREFIX_.'product`
WHERE `id_category_default` = '.$id
);
foreach(getChildren($id) as $child) {
$products = array_merge($products, getCat($child['id_category']));
}
return $products;
}
$f = fopen('extracts/monthly_compta/'.date('Y-m-d', strtotime($now)).'_big.csv', 'w');
$headers = array(
'date',
//'sale_title',
'id_order',
'id_order_slip',
'invoice_number',
'multisale',
'id_customer',
'firstname',
'lastname',
'total_products_wo_taxes_210',
'total_taxes_210',
'total_products_wo_taxes_200',
'total_taxes_200',
'total_products_wo_taxes_196',
'total_taxes_196',
'total_products_wo_taxes_100',
'total_taxes_100',
'total_products_wo_taxes_55',
'total_taxes_55',
'total_products_wo_taxes_21',
'total_taxes_21',
'total_products_wo_taxes_export',
'shipping_wo_taxes_196-200',
'shipping_wo_taxes_export',
'shipping_country',
'discounts',
'total_paid',
'total_paid_real',
'total_achat',
'payment_type',
'direct_payment',
'date_send',
'refund_reason',
'new',
);
fwrite($f, implode(';', $headers)."\n");
$orders = Db::getInstance()->ExecuteS('
SELECT o.id_order
FROM `'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'order_detail` d,
`'._DB_PREFIX_.'customer` c
WHERE
(o.valid = 1
OR (
o.valid = 0
AND (
(SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 6
OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 7
OR (SELECT h.id_order_state FROM `'._DB_PREFIX_.'order_history` h WHERE h.id_order = o.id_order ORDER BY h.date_add DESC LIMIT 1) = 11
)
))
AND c.id_customer = o.id_customer
AND d.id_order = o.id_order
AND o.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 4 MONTH, \'%Y-%m-01 00:00:00\')
AND o.date_add <= "'.$now.'"
GROUP BY o.id_order
');
foreach($orders as $o) {
$order = Db::getInstance()->ExecuteS('
SELECT c.*, o.*
FROM `'._DB_PREFIX_.'orders` o,
`'._DB_PREFIX_.'customer` c
WHERE
o.id_order = '.$o['id_order'].'
AND c.`id_customer` = o.`id_customer`
');
$order = $order[0];
$multi = Db::getInstance()->getValue('
SELECT COUNT(DISTINCT `id_sale`)
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` IN (
SELECT `product_id` FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order['id_order'].'
)
') == 1? 'S': 'M';
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$invoice_address = Db::getInstance()->ExecuteS('
SELECT firstname, lastname
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.$order['id_address_invoice']
);
$invoice_address = $invoice_address[0];
$order_details = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_detail` d
WHERE d.id_order = '.$o['id_order']
);
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_export = array();
$country = Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_country` = (
SELECT `id_country`
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $order['id_address_delivery'].'
LIMIT 1
)
AND `id_lang` = 2
');
$date_send = Db::getInstance()->getValue('
SELECT `date_add`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order_state` = 4
AND `id_order` = '.(int) $order['id_order'].'
ORDER BY `date_add` ASC
');
// calcul prix d'achat de la commande
$wholesale_price = Db::getInstance()->ExecuteS('
SELECT `wholesale_price`, p.`id_product`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` o ON o.`product_id` = p.`id_product`
WHERE o.`id_order` = '. (int) $order['id_order']
);
$prix_achat = array();
foreach ($wholesale_price as $key => $price) {
$prix_achat[$price['id_product']] = $price['wholesale_price'];
}
$total_achat = 0;
$ldetails = array();
foreach($order_details as $detail) {
$total_achat += $detail['product_quantity'] * $prix_achat[$detail['product_id']];
$ldetails[$detail['id_order_detail']] = $detail;
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '20.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.2);
}
/*}*/
} elseif($detail['tax_rate'] == '21.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_quantity_discount'] / 1.196);
$total_taxes_196[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.196);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.21);
}
/*}*/
}elseif($detail['tax_rate'] == '19.600') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_quantity_discount'] / 1.196);
$total_taxes_196[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.196);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.196);
}
/*}*/
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_quantity_discount'] / 1.055);
$total_taxes_55[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.055);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.055);
}
/*}*/
} elseif($detail['tax_rate'] == '2.100') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity'] * 0.021);
}
/*}*/
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
/*}*/
}
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity']);
}
/*}*/
}
}
$_total_products_wo_taxes_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$_total_products_wo_taxes_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$_total_products_wo_taxes_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$_total_products_wo_taxes_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$_total_products_wo_taxes_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$_total_products_wo_taxes_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$_total_products_wo_taxes_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$_total_products_wo_taxes_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$_total_products_wo_taxes_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$_total_products_wo_taxes_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$_total_products_wo_taxes_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$_total_products_wo_taxes_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$_total_products_wo_taxes_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$_total_products_wo_taxes_export += $value;
}
// Find if it's a saved card or account for the payment (Direct payment)
$is_direct_payment = 0;
if($order['payment'] == 'Paybox') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_saved_card`
FROM `'._DB_PREFIX_.'paybox_transaction`
WHERE `id_cart` = '.(int) $order['id_cart'].'
');
} elseif ($order['payment'] == 'PayPal') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_billing`
FROM `'._DB_PREFIX_.'paypal_order`
WHERE `id_order` = '.(int) $order['id_order'].'
');
}
if((int)$is_direct_payment != 0) {
$order['direct_payment'] = "Oui";
} else {
$order['direct_payment'] = "Non";
}
fwrite($f, implode(';', array(
$order['date_add'],
//addslashes(implode(' / ', $sale_names)),
$order['id_order'],
0,
$order['invoice_number'],
$multi,
$order['id_customer'],
$invoice_address['firstname'],
$invoice_address['lastname'],
$_total_products_wo_taxes_210,
$_total_taxes_210,
$_total_products_wo_taxes_200,
$_total_taxes_200,
$_total_products_wo_taxes_196,
$_total_taxes_196,
$_total_products_wo_taxes_100,
$_total_taxes_100,
$_total_products_wo_taxes_55,
$_total_taxes_55,
$_total_products_wo_taxes_21,
$_total_taxes_21,
$_total_products_wo_taxes_export,
($address['id_country'] != 19? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0),
($address['id_country'] != 19? 0.0: $order['total_shipping']),
$country,
$order['total_discounts'],
$order['total_paid'],
$order['total_paid_real'],
$total_achat,
$order['payment'],
$order['direct_payment'],
$date_send,
'',
(int) Db::getInstance()->getValue('
SELECT `id_order`
FROM `'._DB_PREFIX_.'orders`
WHERE `id_customer` = '.(int) $order['id_customer'].'
AND `id_order` != '.(int) $order['id_order'].'
') == 0,
))."\n");
}
// This order has been refunded
$slips = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_slip` os
WHERE os.date_add >= DATE_FORMAT("'.$now.'" - INTERVAL 4 MONTH, \'%Y-%m-01 00:00:00\')
AND os.date_add <= "'.$now.'"
');
// $slips = Db::getInstance()->ExecuteS('
// SELECT *
// FROM `'._DB_PREFIX_.'order_slip` os
// WHERE os.date_add >= "2014-12-01 00:00:00"
// AND os.date_add <= "2014-12-31 23:59:59"
// ');
// $slips = Db::getInstance()->ExecuteS('
// SELECT *
// FROM `'._DB_PREFIX_.'order_slip` os
// AND os.date_add >= "'. date('Y') .'-01-01 00:00:00"
// ');
$refundreasons = array(
'',
'CLIENT : Annulation pré-envoi',
'CLIENT : Rétractation post-envoi',
'BBB : Erreur Achat / Prod',
'FEUR : Problème SAV',
'FEUR : Produit manquant',
'BBB : Erreur logistique',
'Autre',
'BBB : Pbme Site / Paiement',
'TRANS : Colis détruit',
'TRANS : Colis perdu',
'CLIENT : Annulation pour ré-achat',
'BBB : Suspicion de fraude',
);
if(count($slips) > 0) {
foreach($slips as $slip) {
$order = Db::getInstance()->getRow('
SELECT o.*, c.*
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'customer` c
ON o.`id_customer` = c.`id_customer`
WHERE
o.id_order = '.$slip['id_order'].'
');
$multi = Db::getInstance()->getValue('
SELECT COUNT(DISTINCT `id_sale`)
FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` IN (
SELECT `product_id` FROM `'._DB_PREFIX_.'order_detail`
WHERE `id_order` = '.(int) $order['id_order'].'
)
') == 1? 'S': 'M';
$address = Db::getInstance()->ExecuteS('
SELECT a.*, c.`id_zone`
FROM `'._DB_PREFIX_.'address` a, `'._DB_PREFIX_.'country` c
WHERE a.`id_address` = '.$order['id_address_delivery'].'
AND a.`id_country` = c.`id_country`
');
$address = $address[0];
$invoice_address = Db::getInstance()->ExecuteS('
SELECT firstname, lastname
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.$order['id_address_invoice']
);
$invoice_address = $invoice_address[0];
$order_details = Db::getInstance()->ExecuteS('
SELECT *
FROM `'._DB_PREFIX_.'order_detail` d
WHERE d.id_order = '.(int) $slip['id_order'].'
AND d.`id_order_detail` IN (
SELECT `id_order_detail`
FROM `'._DB_PREFIX_.'order_slip_detail`
WHERE `id_order_slip` = '.(int) $slip['id_order_slip'].'
)
');
$country = Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'country_lang`
WHERE `id_country` = (
SELECT `id_country`
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $order['id_address_delivery'].'
LIMIT 1
)
AND `id_lang` = 2
');
$date_send = Db::getInstance()->getValue('
SELECT `date_add`
FROM `'._DB_PREFIX_.'order_history`
WHERE `id_order_state` = 4
AND `id_order` = '.(int) $order['id_order'].'
ORDER BY `date_add` ASC
');
// calcul prix d'achat de la commande
$wholesale_price_slip = Db::getInstance()->ExecuteS('
SELECT `wholesale_price`, p.`id_product`
FROM `'._DB_PREFIX_.'product` p
LEFT JOIN `'._DB_PREFIX_.'order_detail` o ON o.`product_id` = p.`id_product`
WHERE o.`id_order` = '. (int) $slip['id_order']
);
$prix_achat_slip = array();
foreach ($wholesale_price_slip as $key => $price) {
$prix_achat_slip[$price['id_product']] = $price['wholesale_price'];
}
$total_achat_slip = 0;
$ldetails = array();
$total_products_wo_taxes_210 = array();
$total_taxes_210 = array();
$total_products_wo_taxes_200 = array();
$total_taxes_200 = array();
$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_100 = array();
$total_taxes_100 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_export = array();
foreach($order_details as $detail) {
$total_achat_slip += $detail['product_quantity'] * $prix_achat_slip[$detail['product_id']];
/*$total_products_wo_taxes_196 = array();
$total_taxes_196 = array();
$total_products_wo_taxes_55 = array();
$total_taxes_55 = array();
$total_products_wo_taxes_21 = array();
$total_taxes_21 = array();
$total_products_wo_taxes_export = array();*/
$ldetails[$detail['id_order_detail']] = $detail;
if($address['id_country'] != 19) {
if($detail['tax_rate'] == '19.600') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_quantity_discount'] / 1.196);
$total_taxes_196[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.196);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.196);
} else {
$total_products_wo_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_196[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.196);
}
/*}*/
} elseif($detail['tax_rate'] == '10.000') {
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.100);
} else {
$total_products_wo_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_100[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.100);
}
} elseif($detail['tax_rate'] == '5.500') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_quantity_discount'] / 1.055);
$total_taxes_55[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.055);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.055);
} else {
$total_products_wo_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_55[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.055);
}
/*}*/
} elseif($detail['tax_rate'] == '2.100') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_quantity_discount'] / 1.021);
$total_taxes_21[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.021);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.021);
} else {
$total_products_wo_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_21[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.021);
}
/*}*/
} elseif($detail['tax_rate'] == '20.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.2);
} else {
$total_products_wo_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_200[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.2);
}
/*}*/
} elseif($detail['tax_rate'] == '21.000') {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_200[] = (float) ($detail['product_quantity_discount'] / 1.2);
$total_taxes_200[] = (float) ($detail['product_quantity_discount'] - $detail['product_quantity_discount'] / 1.2);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded'] * 0.21);
} else {
$total_products_wo_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
$total_taxes_210[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded'] * 0.21);
}
/*}*/
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
/*}*/
}
} else {
/*if((float) $detail['product_quantity_discount'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_quantity_discount']);
} else {*/
if((float) $detail['reduction_percent'] != 0.0) {
$total_products_wo_taxes_export[] = (float) ($detail['product_price'] * (1 - (float) $detail['reduction_percent'] / 100) * $detail['product_quantity_refunded']);
} else {
$total_products_wo_taxes_export[] = (float) (($detail['product_price'] - (float) $detail['reduction_amount']) * $detail['product_quantity_refunded']);
}
/*}*/
}
}
$_total_products_wo_taxes_210 = 0.0;
foreach($total_products_wo_taxes_210 as $value) {
$_total_products_wo_taxes_210 += $value;
}
$_total_taxes_210 = 0.0;
foreach($total_taxes_210 as $value) {
$_total_taxes_210 += $value;
}
$_total_products_wo_taxes_200 = 0.0;
foreach($total_products_wo_taxes_200 as $value) {
$_total_products_wo_taxes_200 += $value;
}
$_total_taxes_200 = 0.0;
foreach($total_taxes_200 as $value) {
$_total_taxes_200 += $value;
}
$_total_products_wo_taxes_196 = 0.0;
foreach($total_products_wo_taxes_196 as $value) {
$_total_products_wo_taxes_196 += $value;
}
$_total_taxes_196 = 0.0;
foreach($total_taxes_196 as $value) {
$_total_taxes_196 += $value;
}
$_total_products_wo_taxes_100 = 0.0;
foreach($total_products_wo_taxes_100 as $value) {
$_total_products_wo_taxes_100 += $value;
}
$_total_taxes_100 = 0.0;
foreach($total_taxes_100 as $value) {
$_total_taxes_100 += $value;
}
$_total_products_wo_taxes_55 = 0.0;
foreach($total_products_wo_taxes_55 as $value) {
$_total_products_wo_taxes_55 += $value;
}
$_total_taxes_55 = 0.0;
foreach($total_taxes_55 as $value) {
$_total_taxes_55 += $value;
}
$_total_products_wo_taxes_21 = 0.0;
foreach($total_products_wo_taxes_21 as $value) {
$_total_products_wo_taxes_21 += $value;
}
$_total_taxes_21 = 0.0;
foreach($total_taxes_21 as $value) {
$_total_taxes_21 += $value;
}
$_total_products_wo_taxes_export = 0.0;
foreach($total_products_wo_taxes_export as $value) {
$_total_products_wo_taxes_export += $value;
}
// Find if it's a saved card or account for the payment (Direct payment)
$is_direct_payment = 0;
if($order['payment'] == 'Paybox') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_saved_card`
FROM `'._DB_PREFIX_.'paybox_transaction`
WHERE `id_cart` = '.(int) $order['id_cart'].'
');
} elseif ($order['payment'] == 'PayPal') {
$is_direct_payment = Db::getInstance()->getValue('
SELECT `is_billing`
FROM `'._DB_PREFIX_.'paypal_order`
WHERE `id_order` = '.(int) $order['id_order'].'
');
}
if((int)$is_direct_payment != 0) {
$order['direct_payment'] = "Oui";
} else {
$order['direct_payment'] = "Non";
}
$refundreason = Db::getInstance()->getValue('
SELECT `id_reason`
FROM `'._DB_PREFIX_.'refundreason`
WHERE `id_order_slip` = '.(int) $slip['id_order_slip'].'
');
$refundreason = $refundreasons[(int) $refundreason];
fwrite($f, implode(';', array(
$slip['date_add'],
//addslashes(implode(' / ', $sale_names)),
$order['id_order'],
$slip['id_order_slip'],
$order['invoice_number'],
$multi,
$order['id_customer'],
$invoice_address['firstname'],
$invoice_address['lastname'],
'-'.$_total_products_wo_taxes_210,
'-'.$_total_taxes_210,
'-'.$_total_products_wo_taxes_200,
'-'.$_total_taxes_200,
'-'.$_total_products_wo_taxes_196,
'-'.$_total_taxes_196,
'-'.$_total_products_wo_taxes_100,
'-'.$_total_taxes_100,
'-'.$_total_products_wo_taxes_55,
'-'.$_total_taxes_55,
'-'.$_total_products_wo_taxes_21,
'-'.$_total_taxes_21,
'-'.$_total_products_wo_taxes_export,
'-'.($slip['shipping_cost'] == 1? ($address['id_country'] != 19? (float) $order['total_shipping'] / (strtotime($order['date_add']) >= mktime(0, 0, 0, 1, 1, 2014)? 1.2: 1.196): 0.0): 0.0),
'-'.($slip['shipping_cost'] == 1? ($address['id_country'] != 19? 0.0: $order['total_shipping']): 0.0),
$country,
'-0.0',
'-'.($_total_products_wo_taxes_210 + $_total_taxes_210 + $_total_products_wo_taxes_200 + $_total_taxes_200 + $_total_products_wo_taxes_196 + $_total_taxes_196 + $_total_products_wo_taxes_55 + $_total_taxes_55 + $_total_products_wo_taxes_21 + $_total_taxes_21 + $_total_products_wo_taxes_export + ($slip['shipping_cost'] == 1? (float) $order['total_shipping']: 0.0)),
'-'.($_total_products_wo_taxes_210 + $_total_taxes_210 + $_total_products_wo_taxes_200 + $_total_taxes_200 + $_total_products_wo_taxes_196 + $_total_taxes_196 + $_total_products_wo_taxes_55 + $_total_taxes_55 + $_total_products_wo_taxes_21 + $_total_taxes_21 + $_total_products_wo_taxes_export + ($slip['shipping_cost'] == 1? (float) $order['total_shipping']: 0.0)),
$total_achat_slip,
'REFUND '.strtoupper($order['payment']),
$order['direct_payment'],
$date_send,
$refundreason,
'',
))."\n");
}
}
fclose($f);
exit;

65
export_pdf.php Normal file
View File

@ -0,0 +1,65 @@
<?php
if (isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['SERVER_ADDR'] = '127.0.0:1';
$_SERVER['REMOTE_ADDR'] = '127.0.0:1';
include dirname(__FILE__).'/www/config/config.inc.php';
// $cookie = new Cookie('ps');
// foreach( array(299018, 288941, 289938, 284443, 289421, 285700, 289459, 274391,
// 273319, 272544, 271819, 269964, 265852, 260292, 259059, 265544, 261308,
// 257100, 234423, 240829, 240829, 233767, 217497, 205633, 203823, 201126,
// 187387, 185462, 179854, 166753, 176233, 183491, 177402, 279535, 292812,
// 266573, 277760, 274366, 274318, 273079, 257063, 256322, 250723, 245678,
// 238412, 237659, 196253, 192709, 180700, 180046, 175868, 302878, 298027,
// 297853, 299159, 297052, 294427, 293780, 298746, 298927, 297934, 298480,
// 291756, 291544, 296747, 290810, 290168, 287607, 287277, 285811, 289946,
// 288263, 288795, 288591, 289048, 285813, 287451, 285987, 287996, 291066,
// 289082, 288720, 284603, 286209, 291216, 283027, 289347, 284423, 288667,
// 284717, 278478, 294520, 294799, 281439, 295020, 284542, 287228, 289790,
// 282791, 283355, 280889, 280188, 284988, 278545, 284070, 282825, 280327,
// 279775, 277188, 283192, 278137, 278137, 281455, 277836, 271812, 275759,
// 275407, 274469, 279319, 274013, 271066, 270306, 271764, 273388, 276328,
// 267492, 272076, 277800, 284796, 284462, 275265, 270320, 270486, 270171,
// 267818, 267585, 269886, 266411, 266333, 268554, 264148, 265590, 262954,
// 262851, 260846, 262689, 261596, 262103, 261976, 261521, 262447, 260983,
// 259890, 262905, 260747, 261067, 258471, 235844, 243813, 225221, 229011,
// 222430, 203373, 204814, 206033, 204894, 200585, 200839, 200125, 198425,
// 188263, 197940, 194892, 187277, 188266, 176280, 294794, 256386, 267588,
// 259733, 255594, 250994, 255479, 253251, 252393, 252441, 251929, 252987,
// 252734, 249873, 250484, 249240, 248519, 248202, 256012, 250175, 248340,
// 250448, 248500, 246880, 249146, 247554, 247139, 246179, 246930, 245615,
// 246352, 241094, 244392, 241484, 241314, 240026, 240797, 240427, 239982,
// 240330, 237796, 237127, 238402, 239833, 239833, 236551, 245077, 300088,
// 286495, 290190, 296685, 290539, 291935, 287612, 284108, 285930, 285284,
// 288626, 290659, 295252, 292214, 287915, 278572, 282846, 281120, 281324,
// 292999, 279299, 278681, 276840, 272366, 274417, 276233, 272552, 267126,
// 273451, 267563, 266108, 267186, 269235, 258571, 257172, 258306, 259788,
// 259000, 259547, 254186, 225736) as $id_order) {
// $pdf = new PDF('P', 'mm', 'A4');
// $order = new Order((int) $id_order);
// if(Validate::isLoadedObject($order)) {
// PDF::invoice($order, 'F', TRUE, $pdf);
// $pdf->Output(dirname(__FILE__).'/pdf/'.(int) $id_order.'.pdf', 'F');
// } else {
// echo $id_order."\n";
// }
// }
//
foreach( array('8R27056095774' '7R00015822420' '7R00015822253' '6A10909980655' '6A09248520172') as $id_order) {
$pdf = new PDF('P', 'mm', 'A4');
$order = new Order((int) $id_order);
if(Validate::isLoadedObject($order)) {
PDF::invoice($order, 'F', TRUE, $pdf);
$pdf->Output(dirname(__FILE__).'/pdf/'.(int) $id_order.'.pdf', 'F');
} else {
echo $id_order."\n";
}
}

301
export_philea_laposte.php Normal file
View File

@ -0,0 +1,301 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['SERVER_ADDR'] = '37.187.137.153';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
include dirname(__FILE__).'/www/config/config.inc.php';
function csv($file_handle, $data, $field_separator=';', $enclosure='"', $record_separator="\n") {
escape(FALSE, $enclosure);
$data = array_map('escape', $data);
fwrite($file_handle, $enclosure.implode($enclosure.$field_separator.$enclosure, $data).$enclosure.$record_separator);
}
function escape($data, $enclosure=FALSE) {
static $enc;
if($enclosure === FALSE) {
return str_replace($enc, '\\'.$enc, $data);
}
$enc = $enclosure;
}
function getPublicHolidays(DateTime $date=NULL) {
if($date === NULL) {
$date = new DateTime();
}
$easterDate = new DateTime('@'.easter_date($date->format('Y')));
// Set Visitor / Customer TimeZone (If server not configured or using e-commerce website for ex.)
$easterDate->setTimezone(new DateTimeZone('Europe/Paris'));
$date->setTimezone(new DateTimeZone('Europe/Paris'));
// Fixed date list
$publicHolidaysList = array(
new DateTime($date->format('Y-1-1')), // New Year
new DateTime($date->format('Y-5-1')), // Labor day
new DateTime($date->format('Y-5-8')), // 1945
new DateTime($date->format('Y-7-14')), // National Holiday
new DateTime($date->format('Y-8-15')), // Assumption
new DateTime($date->format('Y-11-1')), // All Saints Day
new DateTime($date->format('Y-11-11')), // Armistice
new DateTime($date->format('Y-12-25')), // Christmas
);
$easterDate1 = new DateTime($easterDate->format('Y-m-d'));
$easterDate1->modify('+1 day');
$easterDate2 = new DateTime($easterDate->format('Y-m-d'));
$easterDate2->modify('+39 day');
$easterDate3 = new DateTime($easterDate->format('Y-m-d'));
$easterDate3->modify('+50 day');
$publicHolidaysList[] = $easterDate1;
$publicHolidaysList[] = $easterDate2;
$publicHolidaysList[] = $easterDate3;
// Sort DateTime
usort($publicHolidaysList, function($a, $b) {
$interval = $a->diff($b);
return $interval->invert? 1: -1;
});
return $publicHolidaysList;
}
$holidays = getPublicHolidays();
$contract = Configuration::get('LAPOSTEWS_API_CONTRACT');
$contract2 = Configuration::get('LAPOSTEWS_API_CONTRACT2');
$now = new Datetime();
$now->setTimezone(new DateTimeZone('Europe/Paris'));
$now->modify('-1 day');
$id_orders = array();
$orders_to_print = array();
// $f = fopen(dirname(__FILE__).'/extracts/itinsell/'.$now->format('Y-m-d').'_laposte.csv', 'w');
$f = fopen(dirname(__FILE__).'/extracts/itinsell/'.$now->format('Y-m-d').'_philea_laposte.csv', 'w');
csv($f, array(
'shipping_number',
'product_code',
'reference',
'recipient',
'address1',
'address2',
'address3',
'address4',
'postcode',
'city',
'country',
'phone',
'email',
'weight',
'parcel_quantity',
'saturday_delivery',
'oversized',
'instructions',
'contract',
'summary_number',
'summary_date',
'description',
'value',
'order_value',
'customer_shipping_value',
'pod_value',
'insurance_value',
'shipping_value',
'delivery_date',
'id_delivery_point',
));
// $orders_laposte = array();
// $orders_laposte = Db::getInstance()->ExecuteS('
// SELECT l.`shipping_number`, o.`id_order`, o.`id_cart`, o.`id_address_delivery`, l.`date_add`
// FROM `'._DB_PREFIX_.'lapostews` l
// LEFT JOIN `'._DB_PREFIX_.'order_detail` d
// ON l.`id_order_detail` = d.`id_order_detail`
// LEFT JOIN `'._DB_PREFIX_.'orders` o
// ON d.`id_order` = o.`id_order`
// WHERE l.`date_add` >= "'.pSQL($now->format('Y-m-d 00:00:00')).'" and l.`date_add` <= "'.pSQL($now->format('Y-m-d 23:59:59')).'"
// GROUP BY l.`shipping_number`
// ');
$orders_philea = Db::getInstance()->ExecuteS('
SELECT pp.`shipping_number`, o.`id_order`, o.`id_cart`, o.`id_address_delivery`, pp.`date_add`
FROM `'._DB_PREFIX_.'philea_parcel` pp
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON pp.`id_order_detail` = d.`id_order_detail`
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON d.`id_order` = o.`id_order`
WHERE pp.`date_add` >= "'.pSQL($now->format('Y-m-d 00:00:00')).'" and pp.`date_add` <= "'.pSQL($now->format('Y-m-d 23:59:59')).'"
GROUP BY pp.`shipping_number`
');
foreach($orders_philea as $row) {
$orders_to_print[] = (int) $row['id_order'];
$delivery_so = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $row['id_cart'].'
');
$delivery = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $row['id_address_delivery'].'
');
$delivery_date = FALSE;
$hour = explode(' ', $row['date_add']);
$hour = explode(':', $hour[1]);
if($delivery_so && $delivery_so['cecountry'] == 'FR' || $delivery['id_country'] == 8) {
$delivery_date = new DateTime($now->format('Y-m-d'));
$delivery_date->setTimezone(new DateTimeZone('Europe/Paris'));
$delivery_date->modify('+1 day');
if((int) $hour[0] > 16 || ((int) $hour[0] == 16 && (int) $hour[1] >= 30)) {
$delivery_date->modify('+1 day');
}
$i = 1;
while($i > 0) {
$is_holiday = FALSE;
foreach($holidays as $holiday) {
if($holiday->format('Y-m-d') == $delivery_date->format('Y-m-d')) {
$is_holiday = TRUE;
break;
}
}
if((int) $delivery_date->format('w') == 0) {
$is_holiday = TRUE;
}
$delivery_date->modify('+1 day');
if(!$is_holiday) {
$i--;
}
}
}
if(!$delivery_so) {
csv($f, array(
$row['shipping_number'],
'',
$row['id_order'],
($delivery['company'] != ''? $delivery['company'].' - ': '').$delivery['firstname'].' '.$delivery['lastname'],
trim(str_replace(array("\n", "\r"), ' ', $delivery['address1'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery['address2'])),
'',
'',
(string) $delivery['postcode'],
$delivery['city'],
Country::getIsoById((int) $delivery['id_country']),
str_replace(' ', '', (string) ($delivery['phone_mobile'] != ''? $delivery['phone_mobile']: $delivery['phone'])),
Db::getInstance()->getValue('SELECT `email` FROM `'._DB_PREFIX_.'customer` WHERE `id_customer` = '.(int) $delivery['id_customer']),
0.24,
1,
1,
'N',
trim(str_replace(array("\n", "\r"), ' ', $delivery['other'])),
(int) $delivery['id_country'] == 8? $contract: $contract2,
$now->format('Ymd'),
$now->format('d/m/Y'),
'',
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
$delivery_date? $delivery_date->format('d/m/Y'): '',
'',
));
} else {
csv($f, array(
$row['shipping_number'],
'',
$row['id_order'],
str_replace(array("\n", "\r"), ' ', ($delivery_so['prcompladress'] != ''? $delivery_so['prcompladress'].' - ': '').($delivery_so['cecompanyname'] != ''? $delivery_so['cecompanyname'].' - ': '').$delivery_so['prfirstname'].' '.$delivery_so['prname']),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress3'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress4'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress1'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress2'])),
(string) $delivery_so['przipcode'],
$delivery_so['prtown'],
$delivery_so['cecountry'],
str_replace(' ', '', $delivery_so['cephonenumber'] != ''? (string) $delivery_so['cephonenumber']: ((string) ($delivery['phone_mobile'] != ''? $delivery['phone_mobile']: $delivery['phone']))),
$delivery_so['ceemail'],
0.24,
1,
1,
'N',
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['cedeliveryinformation'])),
$delivery_so['cecountry'] == 'FR'? $contract: $contract2,
$now->format('Ymd'),
$now->format('d/m/Y'),
'',
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
$delivery_date? $delivery_date->format('d/m/Y'): '',
$delivery_so['prid'],
));
}
$pdf = new PDF('P', 'mm', 'A4');
$order = new Order((int) $row['id_order']);
if(Validate::isLoadedObject($order)) {
$id_orders[] = (int) $order->id;
PDF::invoice($order, 'F', TRUE, $pdf);
$pdf->Output(dirname(__FILE__).'/extracts/invoices/'.(int) $order->id.'.pdf', 'F');
}
}
fclose($f);
/**
* Regeneration invoices for specific orders
* using this includes to comment all about csv
*/
// $orders_to_reprint = array(350385,302554,300088,286495,290190,296685,290539,291935,287612,284108,285930,285284,288626,290659,295252,292214,287915,278572,282846,281120,281324,292999,279299,278681,276840,272366,274417,276233,272552,267126,273451,267563,266108,267186,269235,258571,257172,258306,259788,259000,259547,254186,225736,334010,332694,325773,325773,323595,323595,306923,306923,304776,304776,302960,302960,305645,305645,285700,274391,272544,271819,265852,260292,259059,265544,257100,234423,240829,240829,233767,217497,205633,203823,201126,187387,185462,179854,166753,176233,183491,177402,369986,367072,367383,367970,368338,339107,339107,338759,334924,327402,320364,320364,332667,332667,320441,320441,311542,311542,308895,308895,307577,307577,266573,277760,274366,274318,273079,257063,256322,250723,245678,238412,237659,196253,192709,180700,180046,175868,381283,369164,367304,367982,367104,370224,366966,370107,366177,369315,362975,367252,361380,365123,370909,359931,360698,363246,358396,361919,361608,357811,357270,367977,357509,356946,357199,357199,351217,351217,335669,335669,339127,336501,334378,334378,348116,348116,335330,336653,336653,331109,330480,330480,332355,332355,328706,328706,338370,338370,330071,330071,328154,328154,327939,327939,327736,327736,328201,328201,324345,324345,324978,324978,323388,323388,324598,324598,320183,320183,320935,320935,319958,319958,302878,292803,292803,298027,297052,298746,291544,292090,290810,290168,287607,287277,285811,289946,289048,285813,287451,285987,291066,289082,288720,286209,283027,289347,284717,295020,283355,280889,284988,278545,284070,282825,280327,279775,277188,278137,278137,281455,277836,271812,275407,274469,279319,271066,270306,271764,273388,267492,272076,277800,284796,284462,275265,270320,270486,270171,269886,266411,266333,268554,264148,265590,262954,262851,260846,262689,261596,262103,261976,261521,262447,260983,259890,262905,260747,261067,258471,243813,225221,229011,222430,203373,204814,206033,204894,200585,200839,200125,198425,188263,197940,194892,187277,188266,176280,372718,356628,357331,357178,357326,353230,353230,356461,356461,353210,353210,363733,363733,351215,353296,349932,350221,350221,349221,349358,349221,349894,348980,349745,345763,347674,347674,356852,346516,346516,345297,345297,347205,347205,343485,343485,345911,345911,344243,344243,354164,354164,342709,340429,340429,342041,342041,314782,314782,317374,317374,315947,315947,312628,312628,313425,313425,312877,312877,311916,311916,313144,311534,311534,310128,310128,309820,309820,310808,310808,309611,309611,308859,308859,307387,307387,306365,306365,305878,305878,315960,315960,304861,304861,306712,304406,304406,307734,307734,303634,303634,301336,301336,301295,301295,302048,302048,301446,301446,301446,301446,309768,309768,307734,301235,305236,304360,294794,256386,267588,259733,255594,250994,255479,253251,252393,252441,251929,252987,252734,249873,250484,249240,248519,248202,256012,250175,248340,250448,248500,246880,249146,247554,247139,246179,246930,245615,246352,241094,244392,241484,241314,240026,240797,240427,239982,240330,237796,237127,238402,239833,239833,245077);
// foreach ($orders_to_reprint as $key => $order_id) {
// $pdf = new PDF('P', 'mm', 'A4');
// $order = new Order((int) $order_id);
// if(Validate::isLoadedObject($order)) {
// $id_orders[] = (int) $order->id;
// PDF::invoice($order, 'F', TRUE, $pdf);
// $pdf->Output(dirname(__FILE__).'/extracts/invoices/'.(int) $order->id.'.pdf', 'F');
// }
// }
$ftp = ftp_connect('ftp.itinsell.com');
ftp_login($ftp, 'CPTXSC', 'c8PssQoLQUYd');
ftp_put($ftp, 'Colissimo/831400/CSV/'.$now->format('Y-m-d').'_bbb_laposte.csv', dirname(__FILE__).'/extracts/itinsell/'.$now->format('Y-m-d').'_philea_laposte.csv', FTP_BINARY);
ftp_close($ftp);
$ftp = ftp_connect('ftp.itrack.itinsell.com');
ftp_login($ftp, '800914', 'xt954hVUbg');
foreach($id_orders as $id_order) {
ftp_put($ftp, 'FacturesCommerciales/'.(int) $id_order.'.pdf', dirname(__FILE__).'/extracts/invoices/'.(int) $id_order.'.pdf', FTP_BINARY);
unlink(dirname(__FILE__).'/extracts/invoices/'.(int) $id_order.'.pdf');
}
ftp_close($ftp);

312
export_webdav.php Normal file
View File

@ -0,0 +1,312 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
include('www/config/config.inc.php');
ini_set('memory_limit', '6G');
class WebDAV {
var $host;
var $user;
var $pass;
var $connected;
var $fp;
function WebDAV($host,$user,$pass) {
$this->host = $host;
$this->user = $user;
$this->pass = $pass;
$this->connected = false;
}
function connect() {
$this->fp = fsockopen($this->host, 80, $errno, $errstr, 5);
if(!$this->fp) {
$this->connected = false;
return false;
} else {
$this->connected = true;
return true;
}
}
/**
* check if the connection was established
* returns true if connected otherwise false
*/
function isConnected() {
return $this->connected;
}
/*
* get the file listing from webdav
*/
function getListing($directory='/') {
$listing = array();
if ($this->isConnected() == false) {
$this->connect();
}
if ($this->isConnected() == false) {
return $listing;
} else {
$data = 'PROPFIND '.$directory.' HTTP/1.0
Host: '.$this->host.'
Connection: close
Authorization: Basic '.base64_encode($this->user.':'.$this->pass).'
Depth: 1
Content-Type: text/xml; charset="utf-8"
Content-Length: 93
<?xml version="1.0" encoding="utf-8" ?>
<D:propfind xmlns:D="DAV:"><D:allprop/></D:propfind>
';
fwrite($this->fp,$data);
$xml = '';
while (!feof($this->fp)) {
$xml .= fgets($this->fp, 8192);
}
$responses = $this->getContentInTag('d:response',$xml,true);
foreach ($responses as $response) {
$hrefs = $this->getContentInTag('d:href',$response,true);
$rtype = $this->getContentInTag('d:resourcetype',$response,true);
if (trim($rtype[0]) == '') {
$listing[$hrefs[0]] = 'file';
} else {
$listing[$hrefs[0]] = 'dir';
}
}
$this->disconnect();
return $listing;
}
}
function storeFile($filename, $destFile) {
if (!file_exists($filename)) {
print "No such file for upload: $filename\n";
return false;
}
if ($this->isConnected() == false) {
$this->connect();
}
if ($this->isConnected() == false) {
return false;
}
$data = 'PUT '.$destFile.' HTTP/1.0
Host: '.$this->host.'
Connection: close
Authorization: Basic '.base64_encode($this->user.':'.$this->pass).'
Content-Type: application/octet-stream
Content-Length: '.filesize($filename).'
';
fwrite($this->fp,$data);
// print $data;
$fh = fopen($filename,'rb');
while (!feof($fh)) {
$data = fread($fh,8192);
fwrite($this->fp,$data);
// print $data;
}
fclose($fh);
$this->disconnect();
}
function disconnect() {
if ($this->isConnected() == true) {
fclose($this->fp);
$this->connected = false;
}
}
function getContentInTag($tag,&$xml,$stripcdata=false) {
$ret = array();
if ($xml == '') {
print "No XML for tag ".$tag."\n";
}
$matches = array();
if (preg_match_all('|<'.$tag.'[^>]*>(.*?)</'.$tag.'>|is',$xml,$matches)) {
if ($stripcdata == true) {
foreach ($matches[1] as $match) {
if (strpos($match,'&lt;![CDATA[')!==false) {
$match = preg_replace('/\s*&lt;!\[CDATA\[/','',$match);
$match = preg_replace('/\]\]&gt;\s*/','',$match);
$ret[] = $match;
} else {
$ret[] = $match;
}
}
} else {
$ret = array();
foreach ($matches[1] as $match) {
$ret[] = html_entity_decode ($match);
}
return $ret;
}
}
return $ret;
}
}
$customers_to_import = array();
// Customer informations
foreach (Db::getInstance()->ExecuteS('
SELECT
c.`id_customer`,
c.`firstname`,
c.`lastname`,
c.`email`,
c.`ip_registration_newsletter`,
IF(c.`deleted` = 1, 0, IF(c.`active` = 0, 0, c.`newsletter`)) AS `newsletter`,
IFNULL(v.`version`, "fr") AS `version`
FROM `ps_customer` c
LEFT JOIN `ps_customer_version` v ON v.`id_customer` = c.`id_customer`
ORDER BY `id_customer` ASC
') as $row) {
$customers_to_import[(int)$row['id_customer']] = array(
'id_customer' => $row['id_customer'],
'firstname' => $row['firstname'],
'lastname' => $row['lastname'],
'email' => $row['email'],
'ip_registration_newsletter' => $row['ip_registration_newsletter'],
'newsletter' => (int)$row['newsletter'],
'version' => $row['version'],
'date_first_order' => "",
'date_last_order' => "",
'discount' => ""
);
}
$id_customers = array_keys($customers_to_import);
$filename = date('Y-m-d', mktime()).'.csv';
$f = fopen('extracts/webdav/'.$filename, 'w');
fputcsv($f, array('id_customer', 'firstname', 'lastname', 'email', 'ip_registration_newsletter', 'newsletter', 'langue', 'date de premier achat', 'Date de dernier achat', 'discount'), ';', '"');
for($i=0, $l=count($id_customers); $i < $l; $i+=5000) {
// first order
foreach (Db::getInstance()->ExecuteS('
SELECT o.`id_customer`, DATE_FORMAT(o.`date_add`,\'%d/%m/%Y\') AS `date_first_order`
FROM `'._DB_PREFIX_.'orders` o
LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON o.`id_order` = oh.`id_order`
WHERE oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = o.`id_order` GROUP BY moh.`id_order`)
AND oh.`id_order_state` NOT IN (1,14,15,18,6,8,10,11)
AND o.`id_customer` IN ('.implode(', ', array_slice($id_customers, $i, 5000)).')
GROUP BY o.`id_customer`
ORDER BY o.`id_order` DESC
') as $row) {
$customers_to_import[(int)$row['id_customer']]['date_first_order'] = $row['date_first_order'];
}
// last order
foreach (Db::getInstance()->ExecuteS('
SELECT o.`id_customer`, DATE_FORMAT(MAX(h.`date_add`), \'%d/%m/%Y\') AS `date_last_order`
FROM `'._DB_PREFIX_.'order_history` h
LEFT JOIN `'._DB_PREFIX_.'orders` o ON h.`id_order` = o.`id_order`
WHERE h.`id_order_state` NOT IN (1,14,15,18,6,8,10,11)
AND o.`id_customer` IN ('.implode(', ', array_slice($id_customers, $i, 5000)).')
GROUP BY o.`id_customer`
ORDER BY h.`id_order` DESC
') as $row) {
$customers_to_import[(int)$row['id_customer']]['date_last_order'] = $row['date_last_order'];
}
// Discount
foreach (Db::getInstance()->ExecuteS('
SELECT dh.`id_customer`, dh.`code` as `discount`
FROM `'._DB_PREFIX_.'ant_discount_history` dh
WHERE dh.`id_customer` IN ('.implode(', ', array_slice($id_customers, $i, 5000)).')
AND dh.`used` = 0
GROUP BY dh.`id_customer`
ORDER BY dh.`date_add` DESC
') as $row) {
$customers_to_import[(int)$row['id_customer']]['discount'] = $row['discount'];
}
}
foreach ($customers_to_import as $customer) {
fwrite($f, implode(';', array_values($customer))."\n");
}
fclose($f);
// Ancienne requete trop longue
// foreach(Db::getInstance()->ExecuteS('
// SELECT
// c.`id_customer`,
// c.`firstname`,
// c.`lastname`,
// c.`email`,
// c.`ip_registration_newsletter`,
// IF(c.`deleted` = 1, 0, IF(c.`active` = 0, 0, c.`newsletter`)) AS `newsletter`,
// IFNULL(v.`version`, "fr") AS `version`,
// IFNULL(
// (
// SELECT DATE_FORMAT(o.`date_add`,\'%m/%d/%Y\')
// FROM `'._DB_PREFIX_.'orders` o
// LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = o.`id_order`)
// WHERE o.`id_customer` = c.`id_customer`
// AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = o.`id_order` GROUP BY moh.`id_order`)
// AND oh.id_order_state NOT IN (1,14,15,18,6,8,10,11)
// ORDER BY o.`date_add` ASC LIMIT 1
// )
// ,"") AS `date_first_order`,
// IFNULL(
// (
// SELECT DATE_FORMAT(o.`date_add`,\'%m/%d/%Y\')
// FROM `'._DB_PREFIX_.'orders` o
// LEFT JOIN `'._DB_PREFIX_.'order_history` oh ON (oh.`id_order` = o.`id_order`)
// WHERE o.`id_customer` = c.`id_customer`
// AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `'._DB_PREFIX_.'order_history` moh WHERE moh.`id_order` = o.`id_order` GROUP BY moh.`id_order`)
// AND oh.id_order_state NOT IN (1,14,15,18,6,8,10,11)
// ORDER BY o.`date_add` DESC LIMIT 1
// )
// ,"") AS `date_last_order`,
// IFNULL(
// (
// SELECT dh.`code`
// FROM `'._DB_PREFIX_.'ant_discount_history` dh
// WHERE dh.`id_customer` = c.`id_customer`
// AND dh.`used` = 0
// ORDER BY dh.`date_add` DESC LIMIT 1
// )
// ,"") AS `discount`
// FROM `'._DB_PREFIX_.'customer` c
// LEFT JOIN `'._DB_PREFIX_.'customer_version` v ON v.`id_customer` = c.`id_customer`
// ORDER BY `id_customer` ASC LIMIT '.$i.','.($i+10000).'
// ') as $customer) {
// fputcsv($f, $customer, ';', '"');
// }
/*
$user = 'admin';
$pw = 'v6S385Vf';
$account = 'bebeboutik';
$host = 'suite.emarsys.net';
$w = new WebDAV($host, $user, $pw);
$w->connect();
$w->storeFile('extracts/webdav/'.$filename, '/storage/'.$account.'/newsletter.csv');
*/
$ftp = ftp_connect('ftp.emarsys.fr');
ftp_login($ftp, 'emarsys-bbb', 'XuCVuK64');
ftp_put($ftp, $filename, 'extracts/webdav/'.$filename, FTP_BINARY);
ftp_close($ftp);

View File

@ -0,0 +1 @@
date;id_order;id_order_slip;invoice_number;multisale;id_customer;firstname;lastname;total_products_wo_taxes_210;total_taxes_210;total_products_wo_taxes_200;total_taxes_200;total_products_wo_taxes_196;total_taxes_196;total_products_wo_taxes_100;total_taxes_100;total_products_wo_taxes_55;total_taxes_55;total_products_wo_taxes_21;total_taxes_21;total_products_wo_taxes_60;total_taxes_60;total_products_wo_taxes_40;total_taxes_40;total_products_wo_taxes_export;shipping_wo_taxes_196-200;shipping_wo_taxes_export;shipping_country;discounts;total_paid;total_paid_real;wholesale_price;payment_type;direct_payment;refund_reason;date_subsribe;pays;device
1 date id_order id_order_slip invoice_number multisale id_customer firstname lastname total_products_wo_taxes_210 total_taxes_210 total_products_wo_taxes_200 total_taxes_200 total_products_wo_taxes_196 total_taxes_196 total_products_wo_taxes_100 total_taxes_100 total_products_wo_taxes_55 total_taxes_55 total_products_wo_taxes_21 total_taxes_21 total_products_wo_taxes_60 total_taxes_60 total_products_wo_taxes_40 total_taxes_40 total_products_wo_taxes_export shipping_wo_taxes_196-200 shipping_wo_taxes_export shipping_country discounts total_paid total_paid_real wholesale_price payment_type direct_payment refund_reason date_subsribe pays device

View File

@ -0,0 +1 @@
date;id_order;id_order_slip;invoice_number;multisale;id_customer;firstname;lastname;total_products_wo_taxes_210;total_taxes_210;total_products_wo_taxes_200;total_taxes_200;total_products_wo_taxes_196;total_taxes_196;total_products_wo_taxes_100;total_taxes_100;total_products_wo_taxes_55;total_taxes_55;total_products_wo_taxes_21;total_taxes_21;total_products_wo_taxes_60;total_taxes_60;total_products_wo_taxes_40;total_taxes_40;total_products_wo_taxes_export;shipping_wo_taxes_196-200;shipping_wo_taxes_export;shipping_country;discounts;total_paid;total_paid_real;wholesale_price;payment_type;direct_payment;refund_reason;date_subsribe;pays;device
1 date id_order id_order_slip invoice_number multisale id_customer firstname lastname total_products_wo_taxes_210 total_taxes_210 total_products_wo_taxes_200 total_taxes_200 total_products_wo_taxes_196 total_taxes_196 total_products_wo_taxes_100 total_taxes_100 total_products_wo_taxes_55 total_taxes_55 total_products_wo_taxes_21 total_taxes_21 total_products_wo_taxes_60 total_taxes_60 total_products_wo_taxes_40 total_taxes_40 total_products_wo_taxes_export shipping_wo_taxes_196-200 shipping_wo_taxes_export shipping_country discounts total_paid total_paid_real wholesale_price payment_type direct_payment refund_reason date_subsribe pays device

240
fichier_test.php Normal file
View File

@ -0,0 +1,240 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
include('www/config/config.inc.php');
$id_order = 501425;
$order = new Order($id_order);
if(Validate::isLoadedObject($order)) {
$product_type = '';
$dst_customer = new Customer($order->id_customer);
$dst_address = new Address($order->id_address_delivery);
$dst_country = new Country($dst_address->id_country);
$langs = array(
1 => 'EN',
2 => 'FR',
3 => 'ES',
5 => 'IT',
6 => 'EN',
);
$dst_address = array(
'companyName' => '',
'lastName' => '',
'firstName' => '',
'line0' => '',
'line1' => '',
'line2' => '',
'line3' => '',
'countryCode' => '',
'city' => '',
'zipCode' => '',
'phoneNumber' => '',
'mobileNumber' => '',
'doorCode1' => '',
'doorCode2' => '',
'email' => '',
'intercom' => '',
'language' => $langs[(int) $order->id_lang],
);
$prid = '';
$instructions = '';
$unicode_ack = json_decode('"\u0006"');
$unicode_ack2 = json_decode('"\u00ad"');
if(Module::isInstalled('socolissimo')
&& ($so_data = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $order->id_cart.'
AND `id_customer` = '.(int) $order->id_customer.'
'))
&& (
(strpos(Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'carrier`
WHERE `id_carrier` = '.(int) $order->id_carrier.'
'), 'La Poste') !== FALSE)
|| (strpos(Db::getInstance()->getValue('
SELECT `name`
FROM `'._DB_PREFIX_.'carrier`
WHERE `id_carrier` = '.(int) $order->id_carrier.'
'), 'Colissimo') !== FALSE)
)) {
$product_type = $so_data['delivery_mode'];
if($product_type == 'BOM') {
$product_type = 'DOM';
}
if($so_data['cecountry'] == 'ES' && $product_type == 'DOM') {
$product_type = 'DOS';
}
if(!in_array($so_data['cecountry'], array('ES', 'BE', 'AD', 'MC', 'FR', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$product_type = 'DOS';
}
if($so_data['cecountry'] == 'IT'){
$product_type = 'COLI';
}
$dst_address['email'] = $so_data['ceemail'];
if(empty($dst_address['email'])) {
$dst_address['email'] = $dst_customer->email;
}
if(!empty($so_data['cename'])) {
$dst_address['lastName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','İ'), array(' ', '', '', '', 'a', 'a','a','A','l','i'), $so_data['cename']), 0, 35);
} else {
$dst_address['lastName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','İ'), array(' ', '', '', '', 'a', 'a','a','A','l','i'), $so_data['prname']), 0, 35);
}
if(!empty($so_data['cefirstname'])) {
$dst_address['firstName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ'), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i'), $so_data['cefirstname']), 0, 29);
} else {
$dst_address['firstName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ'), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i'), $so_data['prfirstname']), 0, 29);
}
if(!empty($so_data['cecompanyname'])) {
$dst_address['companyName'] = mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ'), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i'), $so_data['cecompanyname']), 0, 35);
}
$address_lines = array();
for($i = 1; $i < 5; $i++) {
if(($line = (string) mb_substr($so_data['pradress'.$i], 0, 32)) != '') {
$address_lines[] = trim($line);
}
}
if(count($address_lines) == 1) {
$dst_address['line2'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[0]);
} elseif(count($address_lines) == 2) {
$dst_address['line2'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[0]);
$dst_address['line3'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[1]);
} elseif(count($address_lines) == 3) {
$dst_address['line0'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[0]);
$dst_address['line2'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[1]);
$dst_address['line3'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[2]);
} else {
$dst_address['line0'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[0]);
$dst_address['line1'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[1]);
$dst_address['line2'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[2]);
$dst_address['line3'] = str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª'), array(' ', '', '', '', 'a', 'a','a'), $address_lines[3]);
}
$dst_address['countryCode'] = $so_data['cecountry'];
if(strtolower($so_data['cecountry']) == 'sl') {
$dst_address['zipCode'] = (string) str_ireplace(array('SI-', 'SL-'), '', mb_substr($so_data['przipcode'], 0, 5));
} elseif(strtolower($so_data['cecountry']) == 'pt') {
$dst_address['zipCode'] = (string) $so_data['przipcode'];
} else {
$dst_address['zipCode'] = (string) mb_substr($so_data['przipcode'], 0, 5);
}
$dst_address['city'] = (string) mb_substr($so_data['prtown'], 0, 35);
$dst_address['mobileNumber'] = (string) mb_substr(str_replace(array('.','°', '|', ' ', '’',"/"),'',$so_data['cephonenumber']), 0, 32);
if(strlen($dst_address['mobileNumber']) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dst_address['mobileNumber'])) {
$dst_address['mobileNumber'] = '0'.mb_substr(mb_substr($dst_address['mobileNumber'], -10), 1);
}
if(strtolower($so_data['cecountry']) == 'be' && preg_match('/^(0032|32)[0-9]{9,10}$/', $dst_address['mobileNumber'])) {
$dst_address['mobileNumber'] = '+32'.mb_substr(mb_substr($dst_address['mobileNumber'], -10), 1);
}
} elseif(strtolower($so_data['cecountry']) == 'fr' && preg_match('/^[0-9]{9,10}$/', $dst_address['mobileNumber'])) {
if(strlen($dst_address['mobileNumber']) == 9) {
$dst_address['mobileNumber'] = '0'.$dst_address['mobileNumber'];
} elseif(strlen($dst_address['mobileNumber']) == 10) {
$dst_address['mobileNumber'] = '0'.mb_substr(mb_substr($dst_address['mobileNumber'], -10), 1);
}
} elseif(strtolower($so_data['cecountry']) == 'be' && preg_match('/^[0-9]{9,10}$/', $dst_address['mobileNumber'])) {
if(strlen($dst_address['mobileNumber']) == 9) {
$dst_address['mobileNumber'] = '+32'.$dst_address['mobileNumber'];
} elseif(strlen($dst_address['mobileNumber']) == 10) {
$dst_address['mobileNumber'] = '+32'.mb_substr(mb_substr($dst_address['mobileNumber'], -10), 1);
}
}
if(strtolower($so_data['cecountry']) == 'fr' && mb_substr($dst_address['mobileNumber'], 0, 2) != '06' && mb_substr($dst_address['mobileNumber'], 0, 2) != '07') {
$dst_address['mobileNumber'] = '0600000000';
}
if(($doorcode = (string) mb_substr($so_data['cedoorcode1'], 0, 8)) != '') {
$dst_address['doorCode1'] = (string) mb_substr($so_data['cedoorcode1'], 0, 8);
}
if(($doorcode = (string) mb_substr($so_data['cedoorcode2'], 8, 8)) != '') {
$dst_address['doorCode2'] = (string) mb_substr($so_data['cedoorcode1'], 8, 8);
}
$instructions = trim(str_replace(array('°', '|', ' ', '’', "\n", "\r"), ' ', (string) $so_data['cedeliveryinformation']));
$prid = $so_data['prid'];
} else {
$dst_address['companyName'] = (string) mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ', $unicode_ack, $unicode_ack2), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i',' ',' '), $dst_address->company), 0, 35);
$dst_address['lastName'] = (string) mb_substr(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ', $unicode_ack, $unicode_ack2), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i',' ',' '), $dst_address->firstname), 0, 35);
$dst_address['firstName'] = (string) mb_substr(strtoupper(str_replace(array('°', 'º', 'º', 'º', 'ª', 'ā','ª','Á','ł','','İ', $unicode_ack, $unicode_ack2), array(' ', '', '', '', 'a', 'a','a','A','l',' ','i',' ',' '), $dst_address->lastname)), 0, 29);
$dst_address['email'] = (string) $dst_customer->email;
if($dst_address->id_country == 193) {
$dst_address['zipCode'] = mb_substr((string) str_ireplace(array('SI-', 'SL-'), '', $dst_address->postcode), 0, 5);
} else {
$dst_address['zipCode'] = mb_substr((string) str_replace(array(' ', '-'), '', $dst_address->postcode), 0, 5);
}
$dst_address['city'] = (string) mb_substr(strtoupper($dst_address->city), 0, 35);
if(in_array($dst_country->iso_code, array('GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$dst_address['countryCode'] = 'FR';
} else {
$dst_address['countryCode'] = (string) $dst_country->iso_code;
}
$dst_address['line2'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), (string) $dst_address->address1);
$dst_address['line3'] = str_replace(array('º', 'º', 'º', 'ª',), array('', '', '', 'a'), (string) $dst_address->address2);
$instructions = trim(str_replace(array('°', '|', ' ', '’', "\n", "\r"), ' ', (string) $dst_address->other));
if(in_array($dst_country->iso_code, array('FR', 'AD', 'MC', 'GP', 'RE', 'MQ', 'YT', 'NC', 'PM', 'GF'))) {
$dst_address->phone = ($dst_address->phone != ''? (string) str_replace(array('.','°', '|', ' ', '’',"/"),'',$dst_address->phone) : '');
$dst_address->phone_mobile = ($dst_address->phone_mobile != ''? (string) str_replace(array('.','°', '|', ' ', '’',"/"),'',$dst_address->phone_mobile) : '');
if($dst_address->phone != '' && preg_match('/^0[67][0-9]+$/', $dst_address->phone)) {
$dst_address['phoneNumber'] = (string) $dst_address->phone;
} elseif($dst_address->phone_mobile != '' && preg_match('/^0[67][0-9]+$/', $dst_address->phone_mobile)) {
$dst_address['phoneNumber'] = (string) $dst_address->phone_mobile;
}
if(strlen($dst_address['phoneNumber']) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dst_address['phoneNumber'])) {
$dst_address['phoneNumber'] = '0'.mb_substr(mb_substr($dst_address['phoneNumber'], -10), 1);
}
}
if(strlen($dst_address['mobileNumber']) > 10) {
if(preg_match('/^(0033|\+33|33)[0-9]{9,10}$/', $dst_address['mobileNumber'])) {
$dst_address['mobileNumber'] = '0'.mb_substr(mb_substr($dst_address['mobileNumber'], -10), 1);
}
}
} else {
if($dst_country->iso_code == 'BE') {
if($dst_address->phone != '') {
$dst_address['phoneNumber'] = (string) $dst_address->phone;
} else {
$dst_address['phoneNumber'] = (string) $dst_address->phone_mobile;
}
$dst_address['mobileNumber'] = '';
} else {
if($dst_address->phone != '') {
$dst_address['phoneNumber'] = (string) $dst_address->phone;
}
if($dst_address->phone_mobile != '') {
$dst_address['mobileNumber'] = (string) $dst_address->phone_mobile;
}
}
}
if($dst_country->iso_code == 'FR' || $dst_country->iso_code == 'MC' || $dst_country->iso_code == 'BE') {
//$product_type = 'COLD'; // Amené a disparaitre
$product_type = 'DOM';
} else {
$product_type = 'COLI';
}
}
}
echo '<pre>';var_dump($product_type, $dst_address);echo '</pre>';die();

14
find_token.php Normal file
View File

@ -0,0 +1,14 @@
<?php
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['HTTP_HOST'] = $_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/www/config/config.inc.php';
define('_PS_BASE_URL_', 'http://www.bebeboutik.com');
foreach(Db::getInstance()->ExecuteS('
SELECT `id_employee`
FROM `'._DB_PREFIX_.'employee`
') as $row) {
echo Tools::getAdminToken('AdminImport'.(int) Tab::getIdFromClassName('AdminImport').(int) $row['id_employee'])."\t".$row['id_employee'];
echo "\n";
}

View File

@ -0,0 +1,21 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/www/config/config.inc.php';
$orders = Db::getInstance()->ExecuteS('
SELECT `id_order`, `shipping_number`
FROM `'._DB_PREFIX_.'shipping_history`
WHERE `id_order` IN
(449596,449617,449642,449643,449645,449664,449668,449669,449670,449674,449681,449688,449692,449714,449728,449736,449771,449798,449805,449831,449832,449849,449855,449858,449883,449885,449886,449899,449903,449915,449952,449962,449969,449981,449983,450001,450004,450013,450014,450016,450024,450041,450082,450084,450110,450116,450126,450129,450154,450163,450199,450214,450215,450218,450262,450268,450272,450278,450289,450332,450345,450415,450457,450555,450568,450573,450576,450597,450672,450680,450681,450700,450759,450788,450831,450844,450883,450923,450994,451022,451065,451081,451106,451162,451209,451223,451236,451242,451359,451459,451499,451555,451573,451605,451615,451620,451625,451814,451826,451828,451861,451878,451928,451935,451950,452064,452146)
');
//echo '<pre>';var_dump($orders);echo "</pre>\n";die();
foreach ($orders as $key => $order) {
Db::getInstance()->ExecuteS('
UPDATE `'._DB_PREFIX_.'orders`
SET `shipping_number` = "'.pSQL($order['shipping_number']).'"
WHERE `id_order` = '.(int) $order['id_order'].'
LIMIT 1
');
}

83
regenerate_images.php Normal file
View File

@ -0,0 +1,83 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = 80;
include dirname(__FILE__).'/www/config/config.inc.php';
include dirname(__FILE__).'/www/images.inc.php';
include dirname(__FILE__).'/www/modules/privatesales/Sale.php';
$id_sale = 5383;
$id_cat = 8721860;
$sale = new Sale($id_sale);
$products = $sale->getProducts();
//echo "<pre>";var_dump($products);echo "</pre>";die();
$productsImages = Db::getInstance()->ExecuteS('
SELECT `id_image`, `id_product`
FROM `'._DB_PREFIX_.'image`
WHERE `id_product` IN ('.implode(',',$products).')
ORDER BY `id_image` ASC');
$dir = _PS_PROD_IMG_DIR_;
$type = ImageType::getImagesTypes('products');
/*$type = array();
$type[] = array('name' => 'thickbox');
$type[] = array('name' => 'small');
$type[] = array('name' => 'medium');
$type[] = array('name' => 'large');
$type[] = array('name' => 'home');*/
//echo "<pre>";var_dump($productsImages,$type);echo "</pre>";die();
$start_time = time();
$max_execution_time = 7200;
foreach ($productsImages AS $k => $image)
{
// delete old rezise image
if (!is_dir($dir)) {
continue;
}
$toDel = scandir($dir);
foreach ($toDel AS $d) {
foreach ($type AS $imageType) {
if (preg_match('/^[0-9]+\-[0-9]+\-'.$imageType['name'].'\.jpg$/', $d) OR preg_match('/^([[:lower:]]{2})\-default\-(.*)\.jpg$/', $d)) {
if (file_exists($dir.$d)) {
unlink($dir.$d);
}
}
}
}
$imageObj = new Image($image['id_image']);
$imageObj->id_product = $image['id_product'];
if (file_exists($dir.$imageObj->getImgFolder()))
{
$toDel = scandir($dir.$imageObj->getImgFolder());
foreach ($toDel AS $d) {
foreach ($type AS $imageType) {
if (preg_match('/^[0-9]+\-'.$imageType['name'].'\.jpg$/', $d)) {
if (file_exists($dir.$imageObj->getImgFolder().$d)) {
unlink($dir.$imageObj->getImgFolder().$d);
}
}
}
}
}
// regenerate new
if (file_exists($dir.$imageObj->getExistingImgPath().'.jpg')) {
foreach ($type AS $k => $imageType)
{
if (!file_exists($dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg')) {
if (!imageResize($dir.$imageObj->getExistingImgPath().'.jpg', $dir.$imageObj->getExistingImgPath().'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])))
$errors = true;
}
if (time() - $start_time > $max_execution_time - 4) { // stop 4 seconds before the tiemout, just enough time to process the end of the page on a slow server
return 'timeout';
}
}
}
if((int) $image['id_product'] % 100 == 0) {
echo $image['id_product']."\n";
}
}

View File

@ -0,0 +1,279 @@
<?php
if(isset($_SERVER['REMOTE_ADDR'])) {
exit;
}
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['SERVER_NAME'] = 'www.bebeboutik.com';
$_SERVER['HTTP_PORT'] = 80;
$_SERVER['SERVER_ADDR'] = '37.187.137.153';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
include dirname(__FILE__).'/www/config/config.inc.php';
function csv($file_handle, $data, $field_separator=';', $enclosure='"', $record_separator="\n") {
escape(FALSE, $enclosure);
$data = array_map('escape', $data);
fwrite($file_handle, $enclosure.implode($enclosure.$field_separator.$enclosure, $data).$enclosure.$record_separator);
}
function escape($data, $enclosure=FALSE) {
static $enc;
if($enclosure === FALSE) {
return str_replace($enc, '\\'.$enc, $data);
}
$enc = $enclosure;
}
function getPublicHolidays(DateTime $date=NULL) {
if($date === NULL) {
$date = new DateTime();
}
$easterDate = new DateTime('@'.easter_date($date->format('Y')));
// Set Visitor / Customer TimeZone (If server not configured or using e-commerce website for ex.)
$easterDate->setTimezone(new DateTimeZone('Europe/Paris'));
$date->setTimezone(new DateTimeZone('Europe/Paris'));
// Fixed date list
$publicHolidaysList = array(
new DateTime($date->format('Y-1-1')), // New Year
new DateTime($date->format('Y-5-1')), // Labor day
new DateTime($date->format('Y-5-8')), // 1945
new DateTime($date->format('Y-7-14')), // National Holiday
new DateTime($date->format('Y-8-15')), // Assumption
new DateTime($date->format('Y-11-1')), // All Saints Day
new DateTime($date->format('Y-11-11')), // Armistice
new DateTime($date->format('Y-12-25')), // Christmas
);
$easterDate1 = new DateTime($easterDate->format('Y-m-d'));
$easterDate1->modify('+1 day');
$easterDate2 = new DateTime($easterDate->format('Y-m-d'));
$easterDate2->modify('+39 day');
$easterDate3 = new DateTime($easterDate->format('Y-m-d'));
$easterDate3->modify('+50 day');
$publicHolidaysList[] = $easterDate1;
$publicHolidaysList[] = $easterDate2;
$publicHolidaysList[] = $easterDate3;
// Sort DateTime
usort($publicHolidaysList, function($a, $b) {
$interval = $a->diff($b);
return $interval->invert? 1: -1;
});
return $publicHolidaysList;
}
function generateCsv($now,$holidays,$contract,$contract2) {
$now->setTimezone(new DateTimeZone('Europe/Paris'));
$id_orders = array();
$orders_to_print = array();
// $f = fopen(dirname(__FILE__).'/extracts/itinsell/'.$now->format('Y-m-d').'_laposte.csv', 'w');
$f = fopen(dirname(__FILE__).'/extracts/itinsell/philea/'.$now->format('Y-m-d').'_philea_laposte.csv', 'w');
csv($f, array(
'shipping_number',
'product_code',
'reference',
'recipient',
'address1',
'address2',
'address3',
'address4',
'postcode',
'city',
'country',
'phone',
'email',
'weight',
'parcel_quantity',
'saturday_delivery',
'oversized',
'instructions',
'contract',
'summary_number',
'summary_date',
'description',
'value',
'order_value',
'customer_shipping_value',
'pod_value',
'insurance_value',
'shipping_value',
'delivery_date',
'id_delivery_point',
));
// $orders_laposte = array();
// $orders_laposte = Db::getInstance()->ExecuteS('
// SELECT l.`shipping_number`, o.`id_order`, o.`id_cart`, o.`id_address_delivery`, l.`date_add`
// FROM `'._DB_PREFIX_.'lapostews` l
// LEFT JOIN `'._DB_PREFIX_.'order_detail` d
// ON l.`id_order_detail` = d.`id_order_detail`
// LEFT JOIN `'._DB_PREFIX_.'orders` o
// ON d.`id_order` = o.`id_order`
// WHERE l.`date_add` >= "'.pSQL($now->format('Y-m-d 00:00:00')).'" and l.`date_add` <= "'.pSQL($now->format('Y-m-d 23:59:59')).'"
// GROUP BY l.`shipping_number`
// ');
$orders_philea = Db::getInstance()->ExecuteS('
SELECT pp.`shipping_number`, o.`id_order`, o.`id_cart`, o.`id_address_delivery`, pp.`date_add`
FROM `'._DB_PREFIX_.'philea_parcel` pp
LEFT JOIN `'._DB_PREFIX_.'order_detail` d
ON pp.`id_order_detail` = d.`id_order_detail`
LEFT JOIN `'._DB_PREFIX_.'orders` o
ON d.`id_order` = o.`id_order`
WHERE pp.`date_add` >= "'.pSQL($now->format('Y-m-d 00:00:00')).'" and pp.`date_add` <= "'.pSQL($now->format('Y-m-d 23:59:59')).'"
GROUP BY pp.`shipping_number`
');
foreach($orders_philea as $row) {
$orders_to_print[] = (int) $row['id_order'];
$delivery_so = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'socolissimo_delivery_info`
WHERE `id_cart` = '.(int) $row['id_cart'].'
');
$delivery = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'address`
WHERE `id_address` = '.(int) $row['id_address_delivery'].'
');
$delivery_date = FALSE;
$hour = explode(' ', $row['date_add']);
$hour = explode(':', $hour[1]);
if($delivery_so && $delivery_so['cecountry'] == 'FR' || $delivery['id_country'] == 8) {
$delivery_date = new DateTime($now->format('Y-m-d'));
$delivery_date->setTimezone(new DateTimeZone('Europe/Paris'));
$delivery_date->modify('+1 day');
if((int) $hour[0] > 16 || ((int) $hour[0] == 16 && (int) $hour[1] >= 30)) {
$delivery_date->modify('+1 day');
}
$i = 1;
while($i > 0) {
$is_holiday = FALSE;
foreach($holidays as $holiday) {
if($holiday->format('Y-m-d') == $delivery_date->format('Y-m-d')) {
$is_holiday = TRUE;
break;
}
}
if((int) $delivery_date->format('w') == 0) {
$is_holiday = TRUE;
}
$delivery_date->modify('+1 day');
if(!$is_holiday) {
$i--;
}
}
}
if(!$delivery_so) {
csv($f, array(
$row['shipping_number'],
'',
$row['id_order'],
($delivery['company'] != ''? $delivery['company'].' - ': '').$delivery['firstname'].' '.$delivery['lastname'],
trim(str_replace(array("\n", "\r"), ' ', $delivery['address1'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery['address2'])),
'',
'',
(string) $delivery['postcode'],
$delivery['city'],
Country::getIsoById((int) $delivery['id_country']),
str_replace(' ', '', (string) ($delivery['phone_mobile'] != ''? $delivery['phone_mobile']: $delivery['phone'])),
Db::getInstance()->getValue('SELECT `email` FROM `'._DB_PREFIX_.'customer` WHERE `id_customer` = '.(int) $delivery['id_customer']),
0.24,
1,
1,
'N',
trim(str_replace(array("\n", "\r"), ' ', $delivery['other'])),
(int) $delivery['id_country'] == 8? $contract: $contract2,
$now->format('Ymd'),
$now->format('d/m/Y'),
'',
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
$delivery_date? $delivery_date->format('d/m/Y'): '',
'',
));
} else {
csv($f, array(
$row['shipping_number'],
'',
$row['id_order'],
str_replace(array("\n", "\r"), ' ', ($delivery_so['prcompladress'] != ''? $delivery_so['prcompladress'].' - ': '').($delivery_so['cecompanyname'] != ''? $delivery_so['cecompanyname'].' - ': '').$delivery_so['prfirstname'].' '.$delivery_so['prname']),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress3'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress4'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress1'])),
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['pradress2'])),
(string) $delivery_so['przipcode'],
$delivery_so['prtown'],
$delivery_so['cecountry'],
str_replace(' ', '', $delivery_so['cephonenumber'] != ''? (string) $delivery_so['cephonenumber']: ((string) ($delivery['phone_mobile'] != ''? $delivery['phone_mobile']: $delivery['phone']))),
$delivery_so['ceemail'],
0.24,
1,
1,
'N',
trim(str_replace(array("\n", "\r"), ' ', $delivery_so['cedeliveryinformation'])),
$delivery_so['cecountry'] == 'FR'? $contract: $contract2,
$now->format('Ymd'),
$now->format('d/m/Y'),
'',
0.0,
0.0,
0.0,
0.0,
0.0,
0.0,
$delivery_date? $delivery_date->format('d/m/Y'): '',
$delivery_so['prid'],
));
}
// $pdf = new PDF('P', 'mm', 'A4');
// $order = new Order((int) $row['id_order']);
// if(Validate::isLoadedObject($order)) {
// $id_orders[] = (int) $order->id;
// PDF::invoice($order, 'F', TRUE, $pdf);
// $pdf->Output(dirname(__FILE__).'/extracts/invoices/'.(int) $order->id.'.pdf', 'F');
// }
}
fclose($f);
}
$date_from = new DateTime('2016-09-30');
$date_to = new DateTime('2016-12-15');
$holidays = getPublicHolidays();
$contract = Configuration::get('LAPOSTEWS_API_CONTRACT');
$contract2 = Configuration::get('LAPOSTEWS_API_CONTRACT2');
$date = $date_from;
while ($date<=$date_to) {
generateCsv($date,$holidays,$contract,$contract2);
$date->modify('+1 day');
}

33
regeneration_monthly.php Executable file
View File

@ -0,0 +1,33 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
//$cmd = 'php cron_export_sales_monthly_new.php 2012-05-01 2> /dev/null';
//echo exec($cmd);
// Historique:
// 22/08/2016 - ($y=2; $y < 4; $y++)
// 23/08/2016 - ($y=4; $y < 5; $y++)
// 24/08/2016 - ($y=5; $y < 6; $y++)
// 25/08/2016 - ($y=6; $y < 7; $y++)
// 17/11/2017 - ($y=7; $y < 8; $y++)
// new
for ($y=7; $y < 8; $y++) {
$year = '201'.$y;
$start = ($y==2)?4:1;
$end = ($y==7)?11:13;
for ($m=$start; $m < $end; $m++) {
if ($m == 10 || $m == 11 | $m == 12) {
$month = $m;
} else {
$month = '0'.$m;
}
//echo $year."-".$month."-01\n";
echo exec('php cron_export_sales_monthly.php '.$year.'-'.$month.'-01 2> /dev/null');
}
}
exit;

View File

@ -0,0 +1,31 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
exit;
//$id_sale = 5840;
// foreach(Db::getInstance()->ExecuteS('
// SELECT DISTINCT o.`id_order`, oh.`id_order_state`
// FROM `ps_orders` o
// LEFT JOIN `ps_order_history` oh ON (oh.`id_order` = o.`id_order`)
// LEFT JOIN `ps_order_detail` d ON o.`id_order` = d.`id_order`
// LEFT JOIN `ps_product_ps_cache` c ON d.`product_id` = c.`id_product`
// LEFT JOIN `ps_philea_sent` pms ON (pms.`id_sale` = c.`id_sale` AND pms.`id_order` = o.`id_order`)
// WHERE c.`id_sale` = '.(int) $id_sale.'
// AND oh.`id_order_history` = (SELECT MAX(`id_order_history`) FROM `ps_order_history` moh WHERE moh.`id_order` = o.`id_order` GROUP BY moh.`id_order`)
// -- AND oh.`id_order_state` IN (2, 3, 4, 13, 17, 9, 18, 19)
// AND pms.`id_order` IS NULL
// -- AND d.`product_quantity` - d.`product_quantity_refunded` > 0
// ') as $row){
// Db::getInstance()->ExecuteS('
// INSERT INTO `'._DB_PREFIX_.'order_state_current`
// VALUES (
// '.(int) $row['id_order'].',
// '.(int) $row['id_order_state'].',
// NOW()
// )
// ON DUPLICATE KEY UPDATE
// `id_order_state` = '.(int) $row['id_order_state'].',
// `date_upd` = NOW()
// ');
// }

View File

@ -0,0 +1,27 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include dirname(__FILE__).'/www/config/config.inc.php';
Db::getInstance()->ExecuteS('
DELETE FROM `'._DB_PREFIX_.'product_ps_cache`
WHERE `id_product` < 5081878
AND `id_product` > 5063468
');
Db::getInstance()->ExecuteS('
INSERT IGNORE INTO `'._DB_PREFIX_.'product_ps_cache` (
SELECT p.id_product, IFNULL(
(
SELECT s.id_sale
FROM `'._DB_PREFIX_.'privatesale_category` s
WHERE s.`id_category` = p.`id_category_default`
LIMIT 1)
, 0
)
FROM `'._DB_PREFIX_.'product` p
WHERE `id_product` < 5081878
AND `id_product` > 5063468
)
');

View File

@ -0,0 +1,60 @@
<?php
ini_set('memory_limit', '4096M');
ini_set('max_execution_time', 0);
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
function getMondaysInRange($date_from, $date_to)
{
$dateFrom = new DateTime($date_from);
$dateTo = new DateTime($date_to);
$dates = array();
if ($dateFrom > $dateTo) {
return $dates;
}
if (1 != $dateFrom->format('N')) {
$dateFrom->modify('next monday');
}
while ($dateFrom <= $dateTo) {
$dates[] = $dateFrom->format('Y-m-d');
$dateFrom->modify('+1 week');
}
return $dates;
}
// Historique:
// 23/08/2016 - $date_from = 2015-01-01; $date_to = 2015-02-28;
// 24/08/2016 - $date_from = 2015-02-28; $date_to = 2015-04-30;
// 25/08/2016 - $date_from = 2015-04-30; $date_to = 2015-06-30;
// 25/08/2016 - $date_from = 2015-06-30; $date_to = 2015-08-31;
// 29/08/2016 - $date_from = 2015-08-31; $date_to = 2015-10-31;
// 30/08/2016 - $date_from = 2015-10-31; $date_to = 2015-12-31;
// 31/08/2016 - $date_from = 2015-12-31; $date_to = 2016-02-29;
// 01/09/2016 - $date_from = 2016-02-29; $date_to = 2016-04-30;
// 02/09/2016 - $date_from = 2016-04-30; $date_to = 2016-06-30;
// 02/09/2016 - $date_from = 2016-06-30; $date_to = 2016-08-14;
// 08/09/2016 - $date_from = 2016-05-31; $date_to = 2016-07-31;
// 08/09/2016 - $date_from = 2016-03-31; $date_to = 2016-05-31;
// 08/09/2016 - $date_from = 2016-01-31; $date_to = 2016-03-31;
// 09/09/2016 - $date_from = 2015-12-31; $date_to = 2016-01-31;
// 09/09/2016 - $date_from = 2015-10-31; $date_to = 2015-12-31;
// 09/09/2016 - $date_from = 2015-08-31; $date_to = 2015-10-31;
// 09/09/2016 - $date_from = 2015-06-30; $date_to = 2015-08-30;
// 15/09/2016 - $date_from = 2015-03-01; $date_to = 2015-04-30;
// 15/09/2016 - $date_from = 2015-01-01; $date_to = 2015-02-24;
$date_from = '2015-01-01';
$date_to = '2015-02-24';
$mondays = getMondaysInRange($date_from, $date_to);
foreach ($mondays as $key => $monday) {
echo $monday."\n";
echo exec('php cron_weekly_stats.php '.$monday.' 2> /dev/null');
}
exit;

49
rename_csv_import.php Normal file
View File

@ -0,0 +1,49 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
$_SERVER['REMOTE_ADDR'] = '127.0.0.1';
$_SERVER['SERVER_PORT'] = 80;
include dirname(__FILE__).'/www/config/config.inc.php';
$filesToImport = scandir(dirname(__FILE__).'/www/adm/import');
uasort($filesToImport, '_usortFiles');
$fileTokeep = array();
foreach ($filesToImport AS $k => &$filename) {
//exclude . .. .svn and index.php and all hidden files
if (preg_match('/^\..*|index.php/Ui', $filename)) {
unset($filesToImport[$k]);
}
// ANTADIS - evite d'importer plusieurs fois le même fichier
if (substr($filename, 0, 3) == 'old') {
unset($filesToImport[$k]);
}
if (isset($filesToImport[$k])) {
$date = strrev(substr(strrev($filesToImport[$k]), 0, 14));
$years = substr($date, 0, 4);
$month = substr($date, 4, 2);
$day = substr($date, 6, 2);
$now = new DateTime("now");
$date2 = new DateTime($years.'-'.$month.'-'.$day);
$interval = $date2->diff($now);
if ((int)$interval->format('%a')<7) {
$fileTokeep[] = $filesToImport[$k];
unset($filesToImport[$k]);
}
}
}
foreach ($filesToImport AS $k => &$filename) {
rename(dirname(__FILE__).'/www/adm/import/'.$filename, dirname(__FILE__).'/www/adm/import/old_'.$filename);
}
function _usortFiles($a, $b)
{
$a = strrev(substr(strrev($a), 0, 14));
$b = strrev(substr(strrev($b), 0, 14));
if ($a == $b)
return 0;
return ($a < $b) ? 1 : -1;
}

10
sandbox.php Normal file
View File

@ -0,0 +1,10 @@
<?php
$_SERVER['HTTP_HOST'] = 'www.bebeboutik.com';
include('www/config/config.inc.php');
include('www/modules/privatesales/Sale.php');
$sale = new Sale(3412);
$statuts = array(17, Configuration::get('PS_OS_PAYMENT'), 4);
$orders = $sale->getOrdersFromSaleMulti($statuts, 2);
p($orders);