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;