✏️ 正在编辑: amexportcompta.php
路径:
/home/bpioifn/www/pigmentse/modules/amexportcompta/amexportcompta.php
提示:
您可以编辑任何文件(包括二进制文件),但请注意不当修改可能导致文件损坏。
<?php /** * @author Arnaud Merigeau - https://www.arnaud-merigeau.fr * @copyright www.arnaud-merigeau.fr * @license Commercial */ if (!defined('_PS_VERSION_')) { exit; } class amexportcompta extends Module { private $output = ''; private $post_errors = array(); private $line_header = '1'; private $file = array(); private $separator = ''; private $format = ''; private $list_countries_cee = ["Allemagne", "Belgique", "Autriche", "Bulgarie", "Chypre", "Croatie", "Danemark", "Espagne", "Estonie", "Finlande", "France", "France (Continentale)", "Grèce", "Hongrie", "Irlande", "Italie", "Lettonie", "Lituanie", "Luxembourg", "Malte", "Pays-Bas", "Pologne", "Portugal", "Tchéquie", "Roumanie", "Slovaquie", "Slovénie", "Suède"]; public function __construct() { $this->name = 'amexportcompta'; $this->tab = 'administration'; $this->version = '2.5.0'; $this->author = 'LATOUTFRANCAIS - Arnaud Merigeau'; $this->need_instance = 0; $this->context = Context::getContext(); $this->bootstrap = true; parent::__construct(); $this->displayName = $this->l('(AM) Accounting export'); $this->description = $this->l('Export your orders formated for accounting'); $this->confirmUninstall = $this->l('Are you sure you want to uninstall this module ?'); $this->module_key = '893573b506a1f16edb311bd9ee5223e1'; } public function install() { if (!parent::install()) { return false; } if (!$this->registerHook('displayBackOfficeHeader')) { return false; } $shops = Shop::getContextListShopID(); $shop_groups_list = array(); /* Setup each shop */ foreach ($shops as $shop_id) { $shop_group_id = (int)Shop::getGroupFromShop($shop_id, true); if (!in_array($shop_group_id, $shop_groups_list)) { $shop_groups_list[] = $shop_group_id; } /* Sets up configuration */ Configuration::updateValue('PS_INVOICE_TAXES_BREAKDOWN', 1, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_header', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_invoice_date', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_orderslip_date', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_amae_decimal_separator', '.', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_emptyvalue', 1, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_currencyfirstchar', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_customername', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_customername', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_cmpte_payment_other', '', false, $shop_group_id, $shop_id); Configuration::updateValue('column_date_order', 1, false, $shop_group_id, $shop_id); Configuration::updateValue('column_account_1', 2, false, $shop_group_id, $shop_id); Configuration::updateValue('column_account', 3, false, $shop_group_id, $shop_id); Configuration::updateValue('column_invoice_number', 4, false, $shop_group_id, $shop_id); Configuration::updateValue('column_libelle', 5, false, $shop_group_id, $shop_id); Configuration::updateValue('column_debit', 6, false, $shop_group_id, $shop_id); Configuration::updateValue('column_credit', 7, false, $shop_group_id, $shop_id); Configuration::updateValue('column_devise', 8, false, $shop_group_id, $shop_id); Configuration::updateValue('column_customer', 9, false, $shop_group_id, $shop_id); Configuration::updateValue('column_company', 10, false, $shop_group_id, $shop_id); Configuration::updateValue('column_country', 11, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_col_jou', 'VEN', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_col_aux', '9DIVER', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_country', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_company', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_mail_recipient', '', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_type_compte_prod', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_type_compte_shipping', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_type_compte_tax_shipping', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_compte_cee', '', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_compte_hors_cee', '', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_compte_discount', '', false, $shop_group_id, $shop_id); $shipping_methods = Carrier::getCarriers($this->context->cookie->id_lang, false, false, false, null, ALL_CARRIERS); foreach ($shipping_methods as $shipping_method) { Configuration::updateValue('amae_cmpte_shipping_'.$shipping_method['id_reference'], null, false, $shop_group_id, $shop_id); } foreach ($shipping_methods as $shipping_method) { Configuration::updateValue('amae_cmpte_tax_shipping_'.$shipping_method['id_reference'], null, false, $shop_group_id, $shop_id); } $payments_methods = PaymentModule::getInstalledPaymentModules(); foreach ($payments_methods as $payments_method) { Configuration::updateValue('amae_cmpte_payment_'.$payments_method['name'], null, false, $shop_group_id, $shop_id); } $tax = new Tax(); $taxes = $tax->getTaxes($this->context->cookie->id_lang, true); foreach ($taxes as $tax) { Configuration::updateValue('amae_cmpte_total_product_'.$tax['id_tax'], null, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_cmpte_total_tax_'.$tax['id_tax'], null, false, $shop_group_id, $shop_id); } } /* Sets up Shop Group configuration */ if (count($shop_groups_list)) { foreach ($shop_groups_list as $shop_group_id) { Configuration::updateValue('PS_INVOICE_TAXES_BREAKDOWN', 1, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_header', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_invoice_date', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_orderslip_date', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_decimal_separator', '.', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_emptyvalue', 1, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_currencyfirstchar', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_customername', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_cmpte_payment_other', '', false, $shop_group_id, $shop_id); Configuration::updateValue('column_date_order', 1, false, $shop_group_id, $shop_id); Configuration::updateValue('column_account_1', 2, false, $shop_group_id, $shop_id); Configuration::updateValue('column_account', 3, false, $shop_group_id, $shop_id); Configuration::updateValue('column_invoice_number', 4, false, $shop_group_id, $shop_id); Configuration::updateValue('column_libelle', 5, false, $shop_group_id, $shop_id); Configuration::updateValue('column_debit', 6, false, $shop_group_id, $shop_id); Configuration::updateValue('column_credit', 7, false, $shop_group_id, $shop_id); Configuration::updateValue('column_devise', 8, false, $shop_group_id, $shop_id); Configuration::updateValue('column_customer', 9, false, $shop_group_id, $shop_id); Configuration::updateValue('column_company', 10, false, $shop_group_id, $shop_id); Configuration::updateValue('column_country', 11, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_col_jou', 'VEN', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_col_aux', '9DIVER', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_country', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_company', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_mail_recipient', '', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_type_compte_prod', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_type_compte_shipping', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_type_compte_tax_shipping', 0, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_compte_cee', '', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_compte_hors_cee', '', false, $shop_group_id, $shop_id); Configuration::updateValue('amae_compte_discount', '', false, $shop_group_id, $shop_id); $shipping_methods = Carrier::getCarriers($this->context->cookie->id_lang, false, false, false, null, ALL_CARRIERS); foreach ($shipping_methods as $shipping_method) { Configuration::updateValue('amae_cmpte_shipping_'.$shipping_method['id_reference'], null, false, $shop_group_id, $shop_id); } foreach ($shipping_methods as $shipping_method) { Configuration::updateValue('amae_cmpte_tax_shipping_'.$shipping_method['id_reference'], null, false, $shop_group_id, $shop_id); } $payments_methods = PaymentModule::getInstalledPaymentModules(); foreach ($payments_methods as $payments_method) { Configuration::updateValue('amae_cmpte_payment_'.$payments_method['name'], null, false, $shop_group_id, $shop_id); } $tax = new Tax(); $taxes = $tax->getTaxes($this->context->cookie->id_lang, true); foreach ($taxes as $tax) { Configuration::updateValue('amae_cmpte_total_product_'.$tax['id_tax'], null, false, $shop_group_id, $shop_id); Configuration::updateValue('amae_cmpte_total_tax_'.$tax['id_tax'], null, false, $shop_group_id, $shop_id); } } } /* Sets up Global configuration */ Configuration::updateValue('PS_INVOICE_TAXES_BREAKDOWN', 1); Configuration::updateValue('amae_header', 0); Configuration::updateValue('amae_invoice_date', 0); Configuration::updateValue('amae_orderslip_date', 0); Configuration::updateValue('amae_decimal_separator', '.'); Configuration::updateValue('amae_emptyvalue', 1); Configuration::updateValue('amae_currencyfirstchar', 0); Configuration::updateValue('amae_customername', 0); Configuration::updateValue('amae_cmpte_payment_other', ''); Configuration::updateValue('column_date_order', 1); Configuration::updateValue('column_account_1', 2); Configuration::updateValue('column_account', 3); Configuration::updateValue('column_invoice_number', 4); Configuration::updateValue('column_libelle', 5); Configuration::updateValue('column_debit', 6); Configuration::updateValue('column_credit', 7); Configuration::updateValue('column_devise', 8); Configuration::updateValue('column_customer', 9); Configuration::updateValue('column_company', 10); Configuration::updateValue('column_country', 11); Configuration::updateValue('amae_col_jou', 'VEN'); Configuration::updateValue('amae_col_aux', '9DIVER'); Configuration::updateValue('amae_country', 0); Configuration::updateValue('amae_company', ''); Configuration::updateValue('amae_mail_recipient', ''); Configuration::updateValue('amae_type_compte_prod', 0); Configuration::updateValue('amae_type_compte_shipping', 0); Configuration::updateValue('amae_type_compte_tax_shipping', 0); Configuration::updateValue('amae_compte_cee', ''); Configuration::updateValue('amae_compte_hors_cee', ''); Configuration::updateValue('amae_compte_discount', ''); $shipping_methods = Carrier::getCarriers($this->context->cookie->id_lang, false, false, false, null, ALL_CARRIERS); foreach ($shipping_methods as $shipping_method) { Configuration::updateValue('amae_cmpte_shipping_'.$shipping_method['id_reference'], null); } foreach ($shipping_methods as $shipping_method) { Configuration::updateValue('amae_cmpte_tax_shipping_'.$shipping_method['id_reference'], null); } $payments_methods = PaymentModule::getInstalledPaymentModules(); foreach ($payments_methods as $payments_method) { Configuration::updateValue('amae_cmpte_payment_'.$payments_method['name'], null); } $tax = new Tax(); $taxes = $tax->getTaxes($this->context->cookie->id_lang, true); foreach ($taxes as $tax) { Configuration::updateValue('amae_cmpte_total_product_'.$tax['id_tax'], null); Configuration::updateValue('amae_cmpte_total_tax_'.$tax['id_tax'], null); } return true; } public function uninstall() { // Configuration::deleteByName('amae_header'); // Configuration::deleteByName('amae_invoice_date'); // Configuration::deleteByName('amae_orderslip_date'); // Configuration::deleteByName('amae_decimal_separator'); // Configuration::deleteByName('amae_emptyvalue'); // Configuration::deleteByName('amae_currencyfirstchar'); // Configuration::deleteByName('amae_customername'); // Configuration::deleteByName('amae_cmpte_payment_other'); // Configuration::deleteByName('column_date_order'); // Configuration::deleteByName('column_account_1'); // Configuration::deleteByName('column_account'); // Configuration::deleteByName('column_invoice_number'); // Configuration::deleteByName('column_libelle'); // Configuration::deleteByName('column_debit'); // Configuration::deleteByName('column_credit'); // Configuration::deleteByName('column_devise'); // Configuration::deleteByName('column_customer'); // Configuration::deleteByName('column_company'); // Configuration::deleteByName('column_country'); // Configuration::deleteByName('amae_col_jou'); // Configuration::deleteByName('amae_col_aux'); // Configuration::deleteByName('amae_country'); // Configuration::deleteByName('amae_company'); // Configuration::deleteByName('amae_mail_recipient'); // Configuration::deleteByName('amae_compte_cee'); // Configuration::deleteByName('amae_compte_hors_cee'); // Configuration::deleteByName('amae_compte_discount'); return parent::uninstall(); } public function hookDisplayBackOfficeHeader() { $isCurrentModule = Tools::getValue('configure', 'amexportcompta'); if ($this->context->controller->controller_name == 'AdminModules' && $isCurrentModule == $this->name) { $this->context->controller->addCss($this->_path.'views/css/admin.css'); } } public function getContent() { // If values have been submitted in the form, process. if (((bool)Tools::isSubmit('submit_export_options')) == true) { $this->postProcess('amae_header'); $this->postProcess('amae_invoice_date'); $this->postProcess('amae_orderslip_date'); $this->postProcess('amae_decimal_separator'); $this->postProcess('amae_emptyvalue'); $this->postProcess('amae_currencyfirstchar'); $this->postProcess('amae_customername'); $this->postProcess('amae_country'); $this->postProcess('amae_company'); $this->postProcess('amae_mail_recipient'); $this->output .= $this->displayConfirmation($this->l('Update successful')); } elseif (((bool)Tools::isSubmit('submit_columns_order')) == true) { $this->postProcess('column_date_order'); $this->postProcess('column_account_1'); $this->postProcess('column_account'); $this->postProcess('column_invoice_number'); $this->postProcess('column_libelle'); $this->postProcess('column_debit'); $this->postProcess('column_credit'); $this->postProcess('column_devise'); $this->postProcess('column_customer'); $this->postProcess('column_company'); $this->postProcess('column_country'); $this->output .= $this->displayConfirmation($this->l('Update successful')); } elseif (((bool)Tools::isSubmit('submit_general_options')) == true) { $this->postProcess('amae_col_jou'); $this->postProcess('amae_col_aux'); $this->output .= $this->displayConfirmation($this->l('Update successful')); } elseif (((bool)Tools::isSubmit('submit_product_options')) == true) { $tax = new Tax(); $taxes = $tax->getTaxes($this->context->cookie->id_lang, true); $this->postProcess('amae_compte_cee'); $this->postProcess('amae_compte_hors_cee'); $this->postProcess('amae_type_compte_prod'); foreach ($taxes as $tax) { $type_product = Tools::getValue('amae_cmpte_total_product_'.$tax['id_tax']); $this->postProcess('amae_cmpte_total_product_'.$tax['id_tax'], $type_product); } $this->output .= $this->displayConfirmation($this->l('Update successful')); } elseif (((bool)Tools::isSubmit('submit_shipping_options')) == true) { $countries = Country::getCountries($this->context->cookie->id_lang, true, false, false); $shipping_methods = Carrier::getCarriers($this->context->cookie->id_lang, false, false, false, null, ALL_CARRIERS); foreach ($shipping_methods as $shipping_method) { $shipping_method_account = Tools::getValue('amae_cmpte_shipping_'.$shipping_method['id_reference']); $this->postProcess('amae_cmpte_shipping_'.$shipping_method['id_reference'], $shipping_method_account); } foreach ($countries as $country) { foreach ($shipping_methods as $shipping_method) { $shipping_method_country_account = Tools::getValue('amae_cmpte_shipping_'.$shipping_method['id_reference'].'_c'.$country['id_country']); $this->postProcess('amae_cmpte_shipping_'.$shipping_method['id_reference'].'_c'.$country['id_country'], $shipping_method_country_account); } } $this->postProcess('amae_type_compte_shipping'); $this->output .= $this->displayConfirmation($this->l('Update successful')); } elseif (((bool)Tools::isSubmit('submit_payment_options')) == true) { $this->postProcess('amae_cmpte_payment_other'); $payments_methods = PaymentModule::getInstalledPaymentModules(); foreach ($payments_methods as $payments_method) { $pm_value = Tools::getValue('amae_cmpte_payment_'.$payments_method['name']); $this->postProcess('amae_cmpte_payment_'.$payments_method['name'], $pm_value); } $this->output .= $this->displayConfirmation($this->l('Update successful')); } elseif (((bool)Tools::isSubmit('submit_tax_options')) == true) { $tax = new Tax(); $taxes = $tax->getTaxes($this->context->cookie->id_lang, true); foreach ($taxes as $tax) { $type_tax = Tools::getValue('amae_cmpte_total_tax_'.$tax['id_tax']); $this->postProcess('amae_cmpte_total_tax_'.$tax['id_tax'], $type_tax); } $this->output .= $this->displayConfirmation($this->l('Update successful')); } elseif (((bool)Tools::isSubmit('submit_shippingtax_options')) == true) { $countries = Country::getCountries($this->context->cookie->id_lang, true, false, false); $shipping_taxes = Carrier::getCarriers($this->context->cookie->id_lang, false, false, false, null, ALL_CARRIERS); foreach ($shipping_taxes as $shipping_tax) { $shipping_tax_account = Tools::getValue('amae_cmpte_tax_shipping_'.$shipping_tax['id_reference']); $this->postProcess('amae_cmpte_tax_shipping_'.$shipping_tax['id_reference'], $shipping_tax_account); } foreach ($countries as $country) { foreach ($shipping_taxes as $shipping_tax) { $shipping_tax_country_account = Tools::getValue('amae_cmpte_tax_shipping_'.$shipping_tax['id_reference'].'_c'.$country['id_country']); $this->postProcess('amae_cmpte_tax_shipping_'.$shipping_tax['id_reference'].'_c'.$country['id_country'], $shipping_tax_country_account); } } $this->postProcess('amae_type_compte_tax_shipping'); $this->output .= $this->displayConfirmation($this->l('Update successful')); } elseif (((bool)Tools::isSubmit('submit_discount_options')) == true) { $this->postProcess('amae_compte_discount'); $this->output .= $this->displayConfirmation($this->l('Update successful')); } elseif (Tools::isSubmit('btnSubmitExport')) { $sizeof_errors = sizeof($this->post_errors); if (!$sizeof_errors) { $this->postExport(); } else { $errors = $this->post_errors; foreach ($errors as $err) { $this->_errors[] = $err; } } } elseif (Tools::isSubmit('btnSubmitDelete')) { $file_to_delete = Tools::getValue('file_to_delete'); if (version_compare(_PS_VERSION_, '1.7.0', '>=')) { $store_url = $this->context->link->getBaseLink(); } else { $store_url = Tools::getHttpHost(true).__PS_BASE_URI__; } if (isset($file_to_delete) && $file_to_delete != '') { if (unlink(_PS_ROOT_DIR_.'/modules/'.$this->name.'/export/'.$file_to_delete)) { $conf = $this->l('File deleted : '); $this->output .= $this->displayConfirmation($conf . $file_to_delete); } } } else { $this->output .= ''; } return $this->output . $this->displayConfig() . $this->stayInTouch(); } protected function postProcess($key) { $shop_context = Shop::getContext(); $shop_groups_list = array(); $shops = Shop::getContextListShopID(); foreach ($shops as $shop_id) { $shop_group_id = (int)Shop::getGroupFromShop($shop_id, true); if (!in_array($shop_group_id, $shop_groups_list)) { $shop_groups_list[] = $shop_group_id; } Configuration::updateValue($key, Tools::getValue($key), false, $shop_group_id, $shop_id); } /* Update global shop context if needed*/ switch ($shop_context) { case Shop::CONTEXT_ALL: Configuration::updateValue($key, Tools::getValue($key)); if (count($shop_groups_list)) { foreach ($shop_groups_list as $shop_group_id) { Configuration::updateValue($key, Tools::getValue($key), false, $shop_group_id); } } break; case Shop::CONTEXT_GROUP: if (count($shop_groups_list)) { foreach ($shop_groups_list as $shop_group_id) { Configuration::updateValue($key, Tools::getValue($key), false, $shop_group_id); } } break; } } public function displayConfig() { $this->context->controller->addJS($this->_path . 'views/js/back.js'); if (version_compare(_PS_VERSION_, '1.7.0', '>=')) { $store_url = $this->context->link->getBaseLink(); } else { $store_url = Tools::getHttpHost(true).__PS_BASE_URI__; } $moduledir = _MODULE_DIR_ . $this->name . '/'; $states = OrderState::getOrderStates($this->context->cookie->id_lang); $countries = Country::getCountries($this->context->cookie->id_lang, true, false, false); $exportFiles = array(); $files = scandir(dirname(__FILE__) . '/export', 1); foreach ($files as $k => $file) { if (strpos($file, 'export-compta') !== false) { $exportFiles[$k]['url'] = $store_url.'modules/'.$this->name.'/export/'.$file; $exportFiles[$k]['filename'] = $file; } } // obtenir les comptes de transporteurs $shipping_methods = Carrier::getCarriers($this->context->cookie->id_lang, false, false, false, null, ALL_CARRIERS); foreach ($shipping_methods as $key => $shipping_method) { $shipping_method_account = Configuration::get('amae_cmpte_shipping_'.$shipping_method['id_reference']); $shipping_methods[$key]['account'] = $shipping_method_account; } foreach ($countries as $country) { foreach ($shipping_methods as $key => $shipping_method) { $shipping_method_country_account = Configuration::get('amae_cmpte_shipping_'.$shipping_method['id_reference'].'_c'.$country['id_country']); $shipping_methods[$key]['countries_accounts'][$country['id_country']]['account'] = $shipping_method_country_account; } } // obtenir les comptes de paiements $payments_methods = PaymentModule::getInstalledPaymentModules(); foreach ($payments_methods as $key => $payments_method) { $pm_type = Configuration::get('amae_cmpte_payment_'.$payments_method['name']); $payments_methods[$key]['type'] = $pm_type; } // obtenir les comptes de taxes $tax = new Tax(); $taxes = $tax->getTaxes($this->context->cookie->id_lang, true); foreach ($taxes as $key => $tax) { $tax_type = Configuration::get('amae_cmpte_total_tax_'.$tax['id_tax']); $tax_type_product = Configuration::get('amae_cmpte_total_product_'.$tax['id_tax']); $taxes[$key]['type'] = $tax_type; $taxes[$key]['type_product'] = $tax_type_product; } // obtenir les comptes de taxes transporteurs $shipping_taxes = Carrier::getCarriers($this->context->cookie->id_lang, false, false, false, null, ALL_CARRIERS); foreach ($shipping_taxes as $key => $shipping_tax) { $shipping_tax_account = Configuration::get('amae_cmpte_tax_shipping_'.$shipping_tax['id_reference']); $shipping_taxes[$key]['account'] = $shipping_tax_account; } foreach ($countries as $country) { foreach ($shipping_taxes as $key => $shipping_tax) { $shipping_tax_country_account = Configuration::get('amae_cmpte_tax_shipping_'.$shipping_method['id_reference'].'_c'.$country['id_country']); $shipping_taxes[$key]['countries_accounts'][$country['id_country']]['account'] = $shipping_tax_country_account; } } // variables smarty $this->context->smarty->assign(array( 'action' => AdminController::$currentIndex.'&configure='.$this->name.'&token='.Tools::getAdminTokenLite('AdminModules'), 'prestashop_ssl' => Configuration::get('PS_SSL_ENABLED'), 'shop' => $this->context->shop, 'shop_id' => $this->context->shop->id, 'shops_id' => Shop::getContextListShopID(), 'shops' => Shop::getShops(), 'cookie' => _COOKIE_IV_, 'moduledir' => $moduledir, 'shipping_methods' => $shipping_methods, 'payments_methods' => $payments_methods, 'taxes' => $taxes, 'shipping_taxes' => $shipping_taxes, 'countries' => $countries, 'amae_header' => Configuration::get('amae_header'), 'amae_invoice_date' => Configuration::get('amae_invoice_date'), 'amae_orderslip_date' => Configuration::get('amae_orderslip_date'), 'amae_decimal_separator' => Configuration::get('amae_decimal_separator'), 'amae_emptyvalue' => Configuration::get('amae_emptyvalue'), 'amae_currencyfirstchar' => Configuration::get('amae_currencyfirstchar'), 'amae_customername' => Configuration::get('amae_customername'), 'amae_cmpte_payment_other' => Configuration::get('amae_cmpte_payment_other'), 'amae_col_jou' => Configuration::get('amae_col_jou'), 'amae_col_aux' => Configuration::get('amae_col_aux'), 'amae_country' => Configuration::get('amae_country'), 'amae_company' => Configuration::get('amae_company'), 'amae_mail_recipient' => Configuration::get('amae_mail_recipient'), 'amae_type_compte_prod' => Configuration::get('amae_type_compte_prod'), 'amae_type_compte_shipping' => Configuration::get('amae_type_compte_shipping'), 'amae_type_compte_tax_shipping' => Configuration::get('amae_type_compte_tax_shipping'), 'amae_compte_cee' => Configuration::get('amae_compte_cee'), 'amae_compte_hors_cee' => Configuration::get('amae_compte_hors_cee'), 'amae_compte_discount' => Configuration::get('amae_compte_discount'), 'prestashop_version' => Configuration::get('PS_VERSION_DB'), 'module_version' => $this->version, 'states' => $states, 'exportFiles' => $exportFiles, 'amae_cron_one_shop' => $store_url . 'modules/' . $this->name . '/cron.php?token=' . Tools::substr(Tools::encrypt($this->name . '/cron'), 0, 10) . '&id_shop=' . $this->context->shop->id, 'amae_cron' => $store_url . 'modules/' . $this->name . '/cron.php?token=' . Tools::substr(Tools::encrypt($this->name . '/cron'), 0, 10) . '&id_shop=', 'list_countries_cee' => $this->list_countries_cee, )); return $this->display(__FILE__, 'views/templates/admin/configuration.tpl'); } public function postExport() { $export_type = 'export-compta'; $this->format = 'csv'; $this->separator = ';'; // traitement if (!Tools::getValue('date_start')) { $date_start = date('Y-m-d', strtotime('first day of last month')).' 00:00:00'; } else { $date_start = Tools::getValue('date_start').' 00:00:00'; } if (!Tools::getValue('date_end')) { $date_end = date('Y-m-d', strtotime('last day of last month')).' 23:59:59'; } else { $date_end = Tools::getValue('date_end').' 23:59:59'; } if (!Tools::getValue('shop_context')) { $shop_context = 1; } else { $shop_context = Tools::getValue('shop_context'); } if ($this->exportAccounting($date_start, $date_end, $shop_context)) { // création du fichier $this->createFile($export_type, $shop_context); } if (count($this->file) > 1) { $message = $this->l('Export done, check download url in export tab'); $this->output .= $this->displayConfirmation($message); } else { $this->_errors[] = $this->l('Nothing to export'); } } private function getOrders($date_start, $date_end, $shop_context = 1) { $id_order_state = Tools::getValue('id_order_state'); $SHOP = 'AND o.`id_shop`="'.pSQL($shop_context).'"'; if (!empty($id_order_state)) { $AND = 'AND o.`current_state`="'.pSQL($id_order_state).'"'; } else { $AND = ''; } $amae_invoice_date = Configuration::get('amae_invoice_date'); if ($amae_invoice_date) { return $orders = Db::getInstance()->ExecuteS(' SELECT o.*, o.`invoice_date` AS date_add, cu.`firstname`, cu.`lastname`, ca.`id_reference` FROM '._DB_PREFIX_.'orders o LEFT JOIN '._DB_PREFIX_.'customer as cu ON cu.`id_customer` = o.`id_customer` LEFT JOIN '._DB_PREFIX_.'carrier as ca ON ca.`id_carrier` = o.`id_carrier` WHERE o.`invoice_date` >= "'.pSQL($date_start).'" AND o.`invoice_date` <= "'.pSQL($date_end).'" ', $SHOP.' '. $AND); } else { return $orders = Db::getInstance()->ExecuteS(' SELECT o.*, cu.`firstname`, cu.`lastname`, ca.`id_reference` FROM '._DB_PREFIX_.'orders o LEFT JOIN '._DB_PREFIX_.'customer as cu ON cu.`id_customer` = o.`id_customer` LEFT JOIN '._DB_PREFIX_.'carrier as ca ON ca.`id_carrier` = o.`id_carrier` WHERE o.`date_add` >= "'.pSQL($date_start).'" AND o.`date_add` <= "'.pSQL($date_end).'"'. $SHOP.' '. $AND); } } private function getOrderSlips($date_start, $date_end, $order_id) { if (!$order_id) { return; } return $order_slips = Db::getInstance()->ExecuteS(' SELECT os.`id_order_slip`, os.`date_add`, os.`total_products_tax_incl`, os.`total_shipping_tax_incl`, os.`total_products_tax_excl`, os.`total_shipping_tax_excl` FROM '._DB_PREFIX_.'order_slip os WHERE os.`date_add` >= "'.pSQL($date_start).'" AND os.`date_add` <= "'.pSQL($date_end).'" AND os.`id_order`="'.$order_id.'"'); } private function exportAccounting($date_start, $date_end, $shop_context) { $ps_tax_address_type = Configuration::get('PS_TAX_ADDRESS_TYPE'); $amae_header = Configuration::get('amae_header'); $amae_orderslip_date = Configuration::get('amae_orderslip_date'); $amae_decimal_separator = Configuration::get('amae_decimal_separator'); $amae_emptyvalue = Configuration::get('amae_emptyvalue'); if ($amae_emptyvalue) { $amae_emptyvalue = 0; } else { $amae_emptyvalue = ''; } $amae_currencyfirstchar = Configuration::get('amae_currencyfirstchar'); $amae_customername = Configuration::get('amae_customername'); $amae_col_jou = Configuration::get('amae_col_jou'); $amae_col_aux = Configuration::get('amae_col_aux'); $amae_country = Configuration::get('amae_country'); $amae_company = Configuration::get('amae_company'); $amae_type_compte_prod = Configuration::get('amae_type_compte_prod'); $amae_type_compte_shipping = Configuration::get('amae_type_compte_shipping'); $amae_type_compte_tax_shipping = Configuration::get('amae_type_compte_tax_shipping'); $amae_compte_cee = Configuration::get('amae_compte_cee'); $amae_compte_hors_cee = Configuration::get('amae_compte_hors_cee'); $amae_compte_discount = Configuration::get('amae_compte_discount'); $invoicePrefix = Configuration::get('PS_INVOICE_PREFIX', $this->context->cookie->id_lang); $orderslipPrefix = Configuration::get('PS_CREDIT_SLIP_PREFIX', $this->context->cookie->id_lang); $orders = $this->getOrders($date_start, $date_end, $shop_context); if ($orders) { if ($amae_header) { $header_line = array(); $header_line[Configuration::get('column_date_order')] = $this->l('Date'); $header_line[Configuration::get('column_account_1')] = $this->l('General account 1'); $header_line[Configuration::get('column_account')] = $this->l('Account'); $header_line[Configuration::get('column_invoice_number')] = $this->l('Invoice number'); $header_line[Configuration::get('column_libelle')] = $this->l('Libelle'); $header_line[Configuration::get('column_debit')] = $this->l('Debit'); $header_line[Configuration::get('column_credit')] = $this->l('Credit'); $header_line[Configuration::get('column_devise')] = $this->l('Devise'); $header_line[Configuration::get('column_customer')] = $this->l('Customer'); if ($amae_company) { $header_line[Configuration::get('column_company')] = $this->l('Company'); } if ($amae_country) { $header_line[Configuration::get('column_country')] = $this->l('Country'); } ksort($header_line); $this->file[] = $header_line; } foreach ($orders as $order) { $Customer = new Customer($order['id_customer']); if (Customer::customerIdExistsStatic($order['id_customer']) && $Customer->validateFields(false)) { $i = 0; $o = new Order($order['id_order']); $invoice = new Address((int)($o->id_address_invoice)); $delivery = new Address((int)($o->id_address_delivery)); $currency = new Currency((int)$o->id_currency); if ($amae_currencyfirstchar) { $currency_value = substr($currency->iso_code, 0, 1); } else { $currency_value = $currency->iso_code; } $customer_name = ''; if ($amae_customername) { $customer_name = ' - ' . $order['firstname'] . ' ' .$order['lastname']; } if (Configuration::get('amae_cmpte_payment_'.$order['module'])) { $payment_account = Configuration::get('amae_cmpte_payment_'.$order['module']); } else { $payment_account = Configuration::get('amae_cmpte_payment_other'); } // Si pays hors CEE => Total produit HT = Total produit if ($amae_type_compte_prod || !$amae_type_compte_prod && in_array($invoice->country, $this->list_countries_cee)) { $oi = new OrderInvoice((int)$order['invoice_number']); $products_taxes = $oi->getProductTaxesBreakdown($o); } else { $products_taxes = array(); $products_taxes[0]['total_price_tax_excl'] = $order["total_products"]; // Total amount à 0 pour ne pas rentrer dans la condition pour afficher le total taxes prdouits $products_taxes[0]['total_amount'] = $amae_emptyvalue; } // ligne : total ttc $i++; $csv_line1 = array(); $csv_line1[Configuration::get('column_date_order')] = date("d/m/Y", strtotime($order['date_add'])); $csv_line1[Configuration::get('column_account_1')] = $amae_col_jou; $csv_line1[Configuration::get('column_account')] = $payment_account; $csv_line1[Configuration::get('column_invoice_number')] = $invoicePrefix . $order['invoice_number']; $csv_line1[Configuration::get('column_libelle')] = $this->l('Order') . ' ' . $order['id_order'] . $customer_name; $csv_line1[Configuration::get('column_debit')] = number_format($order['total_paid_tax_incl'], 2, $amae_decimal_separator, ' '); $csv_line1[Configuration::get('column_credit')] = $amae_emptyvalue; $csv_line1[Configuration::get('column_devise')] = $currency_value; $csv_line1[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { $csv_line1[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { $csv_line1[Configuration::get('column_country')] = $invoice->country; } ksort($csv_line1); $this->file[] = $csv_line1; // ligne : total produits ht $totalProductsHt = 0; foreach ($products_taxes as $key => $pt) { $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = date("d/m/Y", strtotime($order['date_add'])); ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; if (!$amae_type_compte_prod) { if (in_array($invoice->country, $this->list_countries_cee)) { ${'csv_line'.$i}[Configuration::get('column_account')] = $amae_compte_cee; } else { ${'csv_line'.$i}[Configuration::get('column_account')] = $amae_compte_hors_cee; } } else { ${'csv_line'.$i}[Configuration::get('column_account')] = Configuration::get('amae_cmpte_total_product_'.$pt['id_tax']); } ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $invoicePrefix . $order['invoice_number']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Products without tax under VAT') . ' ' . (int)$pt['rate'].'% ' . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_credit')] = number_format($order['total_products'], 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { ${'csv_line'.$i}[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { ${'csv_line'.$i}[Configuration::get('column_country')] = $invoice->country; } ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; $totalProductsHt += $pt['total_price_tax_excl']; } // ligne : total livraison ht if ( $amae_type_compte_shipping ) { $id_country = ( $ps_tax_address_type == 'id_address_delivery' ) ? $delivery->id_country : $invoice->id_country; $shipping_account = Configuration::get('amae_cmpte_shipping_'.$order['id_reference'].'_c'.$id_country); } else { $shipping_account = Configuration::get('amae_cmpte_shipping_'.$order['id_reference']); } if ($order['total_shipping_tax_excl'] > 0) { $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = date("d/m/Y", strtotime($order['date_add'])); ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; ${'csv_line'.$i}[Configuration::get('column_account')] = $shipping_account; ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $invoicePrefix . $order['invoice_number']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Shipping without tax') . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_credit')] = number_format($o->total_shipping_tax_excl, 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { ${'csv_line'.$i}[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { ${'csv_line'.$i}[Configuration::get('column_country')] = $invoice->country; } ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; } // ligne : total taxes produits $totalProductsTaxesHt = 0; foreach ($products_taxes as $key => $pt) { if ($pt['total_amount'] > 0) { $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = date("d/m/Y", strtotime($order['date_add'])); ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; ${'csv_line'.$i}[Configuration::get('column_account')] = Configuration::get('amae_cmpte_total_tax_'.$pt['id_tax']); ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $invoicePrefix . $order['invoice_number']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Products taxes') . ' ' . (int)$pt['rate'] . '% ' . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_credit')] = number_format(($order['total_products_wt'] - $order['total_products']), 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { ${'csv_line'.$i}[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { ${'csv_line'.$i}[Configuration::get('column_country')] = $invoice->country; } ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; $totalProductsTaxesHt += $pt['total_amount']; } } // ligne : total taxes livraison if ( $amae_type_compte_tax_shipping ) { $id_country = ( $ps_tax_address_type == 'id_address_delivery' ) ? $delivery->id_country : $invoice->id_country; $shipping_tax_account = Configuration::get('amae_cmpte_tax_shipping_'.$order['id_reference'].'_c'.$id_country); } else { $shipping_tax_account = Configuration::get('amae_cmpte_tax_shipping_'.$order['id_reference']); } $total_shipping_tax = $o->total_shipping_tax_incl - $o->total_shipping_tax_excl; if ($total_shipping_tax) { $carrier = new Carrier((int)$o->id_carrier); $taxesRate = $carrier->getTaxesRate($invoice); $taxesRate = number_format($taxesRate, 0); $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = date("d/m/Y", strtotime($order['date_add'])); ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; ${'csv_line'.$i}[Configuration::get('column_account')] = $shipping_tax_account; ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $invoicePrefix . $order['invoice_number']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Shipping taxes ') . ' ' . $taxesRate . '% ' . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_credit')] = number_format($total_shipping_tax, 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { ${'csv_line'.$i}[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { ${'csv_line'.$i}[Configuration::get('column_country')] = $invoice->country; } ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; } // ligne : total réduction $isTotalOrderEqualsSubTotals = $order['total_paid_tax_incl'] - $totalProductsHt - $order['total_shipping_tax_excl'] - $totalProductsTaxesHt - $total_shipping_tax; if ($o->total_discounts_tax_incl > 0 && $amae_compte_discount) { $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = date("d/m/Y", strtotime($order['date_add'])); ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; ${'csv_line'.$i}[Configuration::get('column_account')] = $amae_compte_discount; ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $invoicePrefix . $order['invoice_number']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Discounts with tax') . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_credit')] = '-'.number_format($o->total_discounts_tax_incl, 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { ${'csv_line'.$i}[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { ${'csv_line'.$i}[Configuration::get('column_country')] = $invoice->country; } ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; } // lignes avoirs if ($this->getOrderSlipId($order['id_order'])) { $order_slips = $this->getOrderSlips($date_start, $date_end, $order['id_order']); foreach ($order_slips as $key => $os) { $orderSlip = new OrderSlip($os['id_order_slip']); $order_slip_products = $orderSlip->getProducts(); if ($amae_orderslip_date) { $orderslip_date = date("d/m/Y", strtotime($order['date_add'])); } else { $orderslip_date = date("d/m/Y", strtotime($orderSlip->date_add)); } // ligne avoir : total ttc $total_ttc_refund = $os['total_products_tax_incl'] + $os['total_shipping_tax_incl']; $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = $orderslip_date; ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; ${'csv_line'.$i}[Configuration::get('column_account')] = $payment_account; ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $orderslipPrefix . $os['id_order_slip']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Order slip') . ' ' . $order['id_order'] . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = '-'.number_format($total_ttc_refund, 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_credit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { ${'csv_line'.$i}[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { ${'csv_line'.$i}[Configuration::get('column_country')] = $invoice->country; } ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; // ligne avoir : total produits ht if ($os['total_products_tax_excl'] > 0) { foreach ($order_slip_products as $key => $osp) { if ($osp['total_refunded_tax_excl'] > 0) { $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = $orderslip_date; ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; if (!$amae_type_compte_prod) { if (in_array($invoice->country, $this->list_countries_cee)) { ${'csv_line'.$i}[Configuration::get('column_account')] = $amae_compte_cee; } else { ${'csv_line'.$i}[Configuration::get('column_account')] = $amae_compte_hors_cee; } } else { ${'csv_line'.$i}[Configuration::get('column_account')] = Configuration::get('amae_cmpte_total_product_'.$osp['id_tax_rules_group']); } ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $orderslipPrefix . $os['id_order_slip']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Products without tax') . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_credit')] = '-'.number_format($osp['amount_tax_excl'], 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { ${'csv_line'.$i}[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { ${'csv_line'.$i}[Configuration::get('column_country')] = $invoice->country; } ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; } } } // ligne avoir : total livraison ht if ($os['total_shipping_tax_excl'] > 0 ) { $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = $orderslip_date; ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; ${'csv_line'.$i}[Configuration::get('column_account')] = Configuration::get('amae_cmpte_shipping_'.$order['id_reference']); ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $orderslipPrefix . $os['id_order_slip']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Shipping without tax') . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_credit')] = '-'.number_format($os['total_shipping_tax_excl'], 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { ${'csv_line'.$i}[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { ${'csv_line'.$i}[Configuration::get('column_country')] = $invoice->country; } ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; } // ligne avoir : total taxes produits foreach ($order_slip_products as $key => $osp) { $total_tax_refunded = $osp['amount_tax_incl'] - $osp['amount_tax_excl']; $total_tax_refunded = round($total_tax_refunded, 2); if ($total_tax_refunded > 0) { $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = $orderslip_date; ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; ${'csv_line'.$i}[Configuration::get('column_account')] = Configuration::get('amae_cmpte_total_tax_'.$osp['id_tax_rules_group']); ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $orderslipPrefix . $os['id_order_slip']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Products taxes') . ' ' . (int)$osp['tax_rate'] . '% ' . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_credit')] = '-'.number_format($total_tax_refunded, 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; if ($amae_company) { ${'csv_line'.$i}[Configuration::get('column_company')] = $invoice->company; } if ($amae_country) { ${'csv_line'.$i}[Configuration::get('column_country')] = $invoice->country; } ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; } } // ligne avoir : total taxes livraison $total_shipping_tax = $os['total_shipping_tax_incl'] - $os['total_shipping_tax_excl']; $total_shipping_rate = (($os['total_shipping_tax_incl'] - $os['total_shipping_tax_excl']) / $os['total_shipping_tax_excl']) * 100; if ($total_shipping_tax > 0) { $i++; ${'csv_line'.$i} = array(); ${'csv_line'.$i}[Configuration::get('column_date_order')] = $orderslip_date; ${'csv_line'.$i}[Configuration::get('column_account_1')] = $amae_col_jou; ${'csv_line'.$i}[Configuration::get('column_account')] = Configuration::get('amae_cmpte_tax_shipping_'.$order['id_reference']); ${'csv_line'.$i}[Configuration::get('column_invoice_number')] = $orderslipPrefix . $os['id_order_slip']; ${'csv_line'.$i}[Configuration::get('column_libelle')] = $this->l('Shipping taxes') . ' ' . (int)$total_shipping_rate . '% ' . $customer_name; ${'csv_line'.$i}[Configuration::get('column_debit')] = $amae_emptyvalue; ${'csv_line'.$i}[Configuration::get('column_credit')] = '-'.number_format($total_shipping_tax, 2, $amae_decimal_separator, ' '); ${'csv_line'.$i}[Configuration::get('column_devise')] = $currency_value; ${'csv_line'.$i}[Configuration::get('column_customer')] = $order['firstname'] . ' ' .$order['lastname']; ksort(${'csv_line'.$i}); $this->file[] = ${'csv_line'.$i}; } } } } // end if customer exist + valid } // end foreach return true; } else { return false; } } private function createFile($export_type, $shop_context) { $file_content = ''; $f = fopen(dirname(__FILE__).'/export/'.$export_type.'-idshop'.$shop_context.'-'.date('Ymdhis').'.'.$this->format, 'w+'); // parcours file afin d'avoir un fichier avec x lignes foreach ($this->file as $line) { $count_field = 0; $last_field = count($line); // if ($this->format == 'csv') { // // On force la conversion pour que ce soit lisible avec excel // $line = Tools::substr(chr(255).chr(254).mb_convert_encoding($line, "UTF-16LE", "UTF-8"), 2); // } // force l'encodage $char_utf8_write = Configuration::get('CUSTOMEXPORTER_CHAR_UTF8_WRITE'); if ($char_utf8_write) { $line = utf8_decode($line); } fputcsv($f, $line, $this->separator); } if (!$f) { $this->_errors[] = $this->l('Error during file creation. Please check the folder /export/ is CHMOD 777.'); } fclose($f); // envoi du mail if (Configuration::get('amae_mail_recipient')) { $subject = $this->l('Accounting export from') . ' ' . Configuration::get('PS_SHOP_NAME'); $vars = array( '{shop_name}' => Configuration::get('PS_SHOP_NAME'), '{date}' => date('Ymd'), ); if(!$_SERVER['DOCUMENT_ROOT']){ $root = realpath(__DIR__); $csv = $root.'/export/'.$export_type.'-idshop'.$shop_context.'-'.date('Ymdhis').'.'.$this->format; }else{ define('DIR_LOG', $_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.'amdataflow/log/'); $csv = $_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$this->name.'/export/'.$export_type.'-idshop'.$shop_context.'-'.date('Ymdhis').'.'.$this->format; } $file_attachement['content'] = file_get_contents($csv); $file_attachement['mime'] = 'text/csv'; $file_attachement['name'] = $export_type.'-idshop'.$shop_context.'-'.date('Ymdhis').'.'.$this->format; $to = Configuration::get('amae_mail_recipient'); Mail::Send( $this->context->cookie->id_lang, 'msg', $subject, $vars, $to, null, // name null, // from email null, // from name $file_attachement, // $file_attachement null, dirname(__FILE__).'/mails/', false ); } } /** * Returns ID order slip with ID order. * @param int $id_order * @return int */ private function getOrderSlipId($id_order) { return (int) Db::getInstance()->getValue(' SELECT `id_order_slip` FROM `'._DB_PREFIX_.'order_slip` WHERE `id_order` = '.(int)$id_order); } /** * Returns the product taxes breakdown. * @param Order $order * @return array */ private function getProductTaxesBreakdown($order = null) { if (!$order) { $order = $this->getOrder(); } $oi = new OrderInvoice(); $sum_composite_taxes = !$oi->useOneAfterAnotherTaxComputationMethod(); $breakdown = array(); $details = $order->getProductTaxesDetails(); if ($sum_composite_taxes) { $grouped_details = array(); foreach ($details as $row) { if (!isset($grouped_details[$row['id_order_detail']])) { $grouped_details[$row['id_order_detail']] = array( 'tax_rate' => 0, 'total_tax_base' => 0, 'total_amount' => 0, 'id_tax' => $row['id_tax'], ); } $grouped_details[$row['id_order_detail']]['tax_rate'] += $row['tax_rate']; $grouped_details[$row['id_order_detail']]['total_tax_base'] += $row['total_tax_base']; $grouped_details[$row['id_order_detail']]['total_amount'] += $row['total_amount']; } $details = $grouped_details; } foreach ($details as $row) { $rate = sprintf('%.3f', $row['tax_rate']); if (!isset($breakdown[$rate])) { $breakdown[$rate] = array( 'total_price_tax_excl' => 0, 'total_amount' => 0, 'id_tax' => $row['id_tax'], 'rate' => $rate, ); } $breakdown[$rate]['total_price_tax_excl'] += $row['total_tax_base']; $breakdown[$rate]['total_amount'] += $row['total_amount']; } foreach ($breakdown as $rate => $data) { $breakdown[$rate]['total_price_tax_excl'] = Tools::ps_round($data['total_price_tax_excl'], _PS_PRICE_COMPUTE_PRECISION_, $order->round_mode); $breakdown[$rate]['total_amount'] = Tools::ps_round($data['total_amount'], _PS_PRICE_COMPUTE_PRECISION_, $order->round_mode); } ksort($breakdown); return $breakdown; } /** * Returns currency * @param int $id_currency * @return array */ private function getCurrency($id_currency) { $Currency = new Currency($id_currency); if (empty($Currency->id)) { $Currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); } return $Currency->getFields(); } /** * Clean string * @param string $string * @return $string */ private function sanitize($string) { // conversion UTF $char_utf8 = Configuration::get('CUSTOMEXPORTER_CHAR_UTF8'); if ($char_utf8) { $string = Tools::htmlentitiesDecodeUTF8($string); } $string = htmlspecialchars_decode($string); $string = html_entity_decode($string); $string = strip_tags($string); // cleanage du contenu en général $string = str_replace(';', ':', $string); $string = str_replace('"', '', $string); $string = str_replace(CHR(13).CHR(10), "", $string); $string = preg_replace('/<br\\s*?\/??>/i', '', $string); $string = trim($string); $string = str_replace("\r", '', $string); $string = str_replace("\n", '', $string); // remplacer des caractère déformé $char_spec = Configuration::get('CUSTOMEXPORTER_CHAR_SPEC'); if ($char_spec) { $string = str_replace('é', 'é', $string); $string = str_replace('à‰', 'É', $string); $string = str_replace('’', "'", $string); $string = str_replace('Ã', 'à', $string); $string = str_replace('à¨', 'è', $string); $string = str_replace('àª', 'ê', $string); $string = str_replace('à§', 'ç', $string); $string = str_replace('à¢', 'â', $string); $string = str_replace('', '', $string); $string = str_replace('Â', '', $string); $string = str_replace('â„¢', '', $string); $string = str_replace("%&", '', $string); $string = str_replace('|', ' ', $string); } return $string; } /** * Debug function * @param var / array * @return - */ private function debug($var) { echo '<pre>'; print_r($var); echo '</pre>'; } /** * Debug function * @param var / array * @return - */ private function debugd($var) { echo '<pre>'; print_r($var); echo '</pre>'; die; } private function stayInTouch() { $this->context->controller->addCSS($this->_path.'css/style.css'); if (version_compare(_PS_VERSION_, '1.6.0', '<')) { return $this->display(__FILE__, 'views/templates/admin/stayintouch16.tpl'); } else { return $this->display(__FILE__, 'views/templates/admin/stayintouch17.tpl'); } } }
💾 保存文件
← 返回文件管理器