Pistoletabilles Posted September 1, 2022 Share Posted September 1, 2022 Bonjour, Je sais qu'il y a des modules pour la déclaration de TVA intracommunautaire mais j'ai des besoins spécifiques de la part de mon responsable. Étant débutant en programmation, je suis entrain de créer mon module à l'aide du livre de Fabien Serny "Développez vos propres modules E-commerce". J'ai déja créé mes requêtes sql pour faire remonter les infomations que je veux, je suis à l'étape de l'intégrer dans un module mais j'ai recontre un problème avec les dates. Je souhaiterais que l'on mette une date de début et une date de fin, on valide la recherche, cela aurait pour effet de remplir les variables de date dans ma requête sql et sortir le résultat attendu. Je ne vois pas comment utiliser la recherche par date comme dans le menu statistique. Merci d'avance de vos réponses, en espérant avoir été clair dans ma demande. Link to comment Share on other sites More sharing options...
coeos.pro Posted September 1, 2022 Share Posted September 1, 2022 Bonjour, pour tester facilement les requêtes SQL je te conseil mon module gratuit https://www.coeos.pro/fr/modules-prestashop/118-big-data-les-donnees-sql-en-csv-avec-facilite.html il y a une requete déjà enregistrée qui se nomme "Détail des commandes sur les 3 derniers mois, avec frais de livraisons, pour la boutique "1"" en n°5 Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 1, 2022 Author Share Posted September 1, 2022 Merci pour cette réponse, mais mes requêtes fonctionnent si je mets les dates manuellement, je voudrais récupérer les date de manière dynamique avec ce que prestashop propose comme dans les statistiques. Par ailleurs quand j'ai installé ton module, j'ai cette erreur Notice à la ligne 69 du fichier /home/www/pistoletabilles/prestashop/var/cache/dev/smarty/compile/de/c2/53/dec253de9e4cd126aff7c9aa7275849491c7d670_0.file.bigdata.tpl.php [8] Undefined index: tpl_dir Notice à la ligne 69 du fichier /home/www/pistoletabilles/prestashop/var/cache/dev/smarty/compile/de/c2/53/dec253de9e4cd126aff7c9aa7275849491c7d670_0.file.bigdata.tpl.php [8] Trying to get property 'value' of non-object Link to comment Share on other sites More sharing options...
Mediacom87 Posted September 1, 2022 Share Posted September 1, 2022 Bonjour, La déclaration de TVA intra se faisant sur des trimestres et non les périodes proposées par PrestaShop, cela me semble une mauvaise idée de s'appuyer sur les données de date des statistiques, car cela va obliger à chaque fois de remettre les bonnes périodes pour toutes les autres données, donc perte de temps. C'est pour cela que j'intègre ce choix de date directement dans mon module, permettant ainsi de ne pas perturber le reste des usages de PrestaShop. Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 1, 2022 Author Share Posted September 1, 2022 Je dois sortir le chiffre HT et TTC d'affaire mois par mois suivant différent moyen de paiement et market place donc je dois intégrer des dates pour exécuter mes requêtes. Après c'est notre comptable qui se charge de faire la déclaration de TVA. J'aimerais faire ce module pour que cela puisse être fait dans le backoffice par une autre personne que moi si je suis absent. Link to comment Share on other sites More sharing options...
Mediacom87 Posted September 1, 2022 Share Posted September 1, 2022 Ok, donc affichage d'une statistique mensuelle. Donc cohérent. Regardez comment les autres modules statistiques récupèrent cette information. Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 2, 2022 Author Share Posted September 2, 2022 23 hours ago, Mediacom87 said: Ok, donc affichage d'une statistique mensuelle. Donc cohérent. Regardez comment les autres modules statistiques récupèrent cette information. J'ai essayer de comprendre avec le fichier statsbestproducts.php, je l'ai dupliqué, modifié et mis ma requête mais le tableau s'affiche vide. Je ne comprends pas pourquoi mes données ne remontent pas Link to comment Share on other sites More sharing options...
Mediacom87 Posted September 2, 2022 Share Posted September 2, 2022 il y a 11 minutes, Pistoletabilles a dit : J'ai essayer de comprendre avec le fichier statsbestproducts.php, je l'ai dupliqué, modifié et mis ma requête mais le tableau s'affiche vide. Je ne comprends pas pourquoi mes données ne remontent pas Il faudrait déjà vérifier que la requête retourne quelque chose, donc tester la requête dans votre client SQL, car le souci peut être à ce niveau. Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 2, 2022 Author Share Posted September 2, 2022 Oui la requête fonctionne et pour essayer j'ai mis une requête toute simple pour voir l'affichage, je l'utilise depuis sequel pro.` SELECT `id_product`,`reference`, `quantity`, `price` from `ps_product` where `active` = 1'; Une fois que celle ci s'affichera correctement je mettrais ma requête pour le chriffre d'affaire Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 2, 2022 Author Share Posted September 2, 2022 2 hours ago, Mediacom87 said: Il faudrait déjà vérifier que la requête retourne quelque chose, donc tester la requête dans votre client SQL, car le souci peut être à ce niveau. Voila ce que j'ai écrit if (!defined('_PS_VERSION_')) { exit; } class blockoss extends ModuleGrid { private $html = null; private $query = null; private $columns = null; private $default_sort_column = null; private $default_sort_direction = null; private $empty_message = null; private $paging_message = null; public function __construct() { $this->name = 'blockoss'; $this->tab = 'analytics_stats'; $this->version = '0.0.1'; $this->author = 'Jérôme Pepermans'; $this->need_instance = 0; parent::__construct(); $this->default_sort_column = 'PAYS'; $this->empty_message = $this->trans('An empty record-set was returned.', array(), 'Modules.Statsbestproducts.Admin'); $this->paging_message = $this->trans('Displaying %1$s of %2$s', array('{0} - {1}', '{2}'), 'Admin.Global'); $this->columns = array( array( 'id' => 'id_product', 'header' => $this->trans('Id Produit', array(), 'Admin.Global'), 'dataIndex' => 'id_product', 'align' => 'left' ), array( 'id' => 'reference', 'header' => $this->trans('reference', array(), 'Admin.Global'), 'dataIndex' => 'reference', 'align' => 'left' ), array( 'id' => 'quantity', 'header' => $this->trans('qtt', array(), 'Admin.Global'), 'dataIndex' => 'quantity', 'align' => 'center' ), array( 'id' => 'price', 'header' => $this->trans('prix', array(), 'Admin.Global'), 'dataIndex' => 'price', 'align' => 'right' ) ); $this->displayName = 'Chiffre d\'affaire OSS'; $this->description = $this->trans('Adds a list of the best-selling products to the Stats dashboard.', array(), 'Modules.Statsbestproducts.Admin'); $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_); } public function install() { return (parent::install() && $this->registerHook('AdminStatsModules')); } public function hookAdminStatsModules($params) { $engine_params = array( 'id' => 'id_product', 'title' => $this->displayName, 'columns' => $this->columns, 'defaultSortColumn' => $this->default_sort_column, 'defaultSortDirection' => $this->default_sort_direction, 'emptyMessage' => $this->empty_message, 'pagingMessage' => $this->paging_message ); if (Tools::getValue('export')) { $this->csvExport($engine_params); } return '<div class="panel-heading">'.$this->displayName.'</div> '.$this->engine($engine_params).' <a class="btn btn-default export-csv" href="'.Tools::safeOutput($_SERVER['REQUEST_URI'].'&export=1').'"> <i class="icon-cloud-upload"></i> '.$this->trans('CSV Export', array(), 'Admin.Global').' </a>'; } public function getData() { $currency = new Currency(Configuration::get('PS_CURRENCY_DEFAULT')); $date_between = $this->getDate(); $this->query = 'SELECT `id_product`,`reference`, `quantity`, `price` from `'._DB_PREFIX_.'product` where `active` = 1 and date_add between '.$date_between.''; $values = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($this->query); foreach ($values as &$value) { $value['id_product']; $value['reference']; $value['quantity']; $value['price'] = Tools::displayPrice($value['price'], $currency); } } } Link to comment Share on other sites More sharing options...
coeos.pro Posted September 2, 2022 Share Posted September 2, 2022 il y a déjà une différence entre Il y a 2 heures, Pistoletabilles a dit : je l'utilise depuis sequel pro.` SELECT `id_product`,`reference`, `quantity`, `price` from `ps_product` where `active` = 1'; et il y a 2 minutes, Pistoletabilles a dit : $date_between = $this->getDate(); $this->query = 'SELECT `id_product`,`reference`, `quantity`, `price` from `'._DB_PREFIX_.'product` where `active` = 1 and date_add between '.$date_between.''; Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 2, 2022 Author Share Posted September 2, 2022 1 minute ago, coeos.pro said: il y a déjà une différence entre et SELECT `id_product`,`reference`, `quantity`, `price` from `ps_product` where `active` = 1 and `date_add` BETWEEN '2022-05-01 0:0:0' AND '2022-05-31 23:59:59'; Link to comment Share on other sites More sharing options...
Mediacom87 Posted September 2, 2022 Share Posted September 2, 2022 il y a 28 minutes, Pistoletabilles a dit : SELECT `id_product`,`reference`, `quantity`, `price` from `ps_product` where `active` = 1 and `date_add` BETWEEN '2022-05-01 0:0:0' AND '2022-05-31 23:59:59'; Et elle fonctionne dans sequel ? Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 2, 2022 Author Share Posted September 2, 2022 3 minutes ago, Mediacom87 said: Et elle fonctionne dans sequel ? Oui bien sur je mets la capture d'écran Link to comment Share on other sites More sharing options...
Mediacom87 Posted September 2, 2022 Share Posted September 2, 2022 et getData est bien appelé ? Sinon dans le module originel, on a cela pour les dates : $date_between = $this->getDate(); $array_date_between = explode(' AND ', $date_between); Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 22, 2022 Author Share Posted September 22, 2022 J'ai pu faire le module et l'intégrer aux statistiques (plutot satisfait etant mon premier module), Je voudrais vos conseils pour savoir s'il y a moyen de le simplifier ? Merci d'avance de vos retours <?php /* * 2007-2015 PrestaShop * * NOTICE OF LICENSE * * This source file is subject to the Academic Free License (AFL 3.0) * that is bundled with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://opensource.org/licenses/afl-3.0.php * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to [email protected] so we can send you a copy immediately. * * DISCLAIMER * * Do not edit or add to this file if you wish to upgrade PrestaShop to newer * versions in the future. If you wish to customize PrestaShop for your * needs please refer to http://www.prestashop.com for more information. * * @author PrestaShop SA <[email protected]> * @copyright 2007-2015 PrestaShop SA * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * International Registered Trademark & Property of PrestaShop SA */ if (!defined('_PS_VERSION_')) { exit; } class blockoss extends Module { private $html = ''; private $module = ''; private $payment = ''; public function __construct() { $this->name = 'blockoss'; $this->tab = 'analytics_stats'; $this->version = '0.0.1'; $this->author = 'Jérôme Pepermans'; $this->need_instance = 0; parent::__construct(); $this->displayName = 'Chiffre d\'affaire OSS'; $this->description = $this->trans('Adds a list of the best-selling products to the Stats dashboard.', array(), 'Modules.Statsbestproducts.Admin'); $this->ps_versions_compliancy = array('min' => '1.7.1.0', 'max' => _PS_VERSION_); } public function install() { return (parent::install() && $this->registerHook('AdminStatsModules')); } public function hookAdminStatsModules() { $currency = new Currency((int)Configuration::get('PS_CURRENCY_DEFAULT')); $this->html = ' <div class="panel-heading"> ' . $this->displayName . ' </div>'; $oss = $this->getCb(); $total = $this->getTotalCb(); $this->html .= ' <h2>PISTOLET A BILLES</h2> <h4>Paiement Carte bancaire</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($oss as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; $paypal = $this->getPaypal(); $total = $this->getTotalPaypal(); $this->html .= ' <h4>Paiement Paypal</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($paypal as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; $transfert = $this->getTransfert(); $total = $this->getTotalTransfert(); $this->html .= ' <h4>Paiement Virement bancaire</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($transfert as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; $alma = $this->getAlma(); $total = $this->getTotalAlma(); $this->html .= ' <h4>Paiement Alma</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($alma as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; $natCb = $this->getNatCb(); $total = $this->getTotalNatCb(); $this->html .= ' <h2>NATURABUY</h2> <h4>Paiement Naturabuy Carte bancaire</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($natCb as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; $natPay = $this->getNatPay(); $total = $this->getTotalNatPaypal(); $this->html .= ' <h4>Paiement Naturabuy Paypal</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($natPay as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; $natCb3x = $this->getNatCb3x(); $total = $this->getTotalNatCb3(); $this->html .= ' <h4>Paiement Naturabuy CB3X</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($natCb3x as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; $natCb4x = $this->getNatCb4x(); $total = $this->getTotalNatCb4(); $this->html .= ' <h4>Paiement Naturabuy CB4X</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($natCb4x as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; $rak = $this->getRak(); $total = $this->getTotalRak(); $this->html .= ' <h2>RAKUTEN</h2> <h4>Paiement Rakuten</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($rak as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; $ali = $this->getAli(); $total = $this->getTotalAli(); $this->html .= ' <h2>ALIEXPRESS</h2> <h4>Paiement Aliexpress</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; foreach ($ali as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; return $this->html; } // total Carte bancaire private function getTotalCb() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("monetico", "atos") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // total paypal site private function getTotalPaypal() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("paypal") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // total Virement private function getTotalTransfert() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("ps_wirepayment", "bankwire") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // total Alma site private function getTotalAlma() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("alma") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // total Naturabuy CB private function getTotalNatCb() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("NaturaBuyPayment") AND o.payment LIKE ("cb") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // total Naturabuy paypal private function getTotalNatPaypal() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("NaturaBuyPayment") AND o.payment LIKE ("paypal") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // total Naturabuy Cb3x private function getTotalNatCb3() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("NaturaBuyPayment") AND o.payment LIKE ("cb3x") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // total Naturabuy Cb4x private function getTotalNatCb4() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("NaturaBuyPayment") AND o.payment LIKE ("cb4x") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // total Rakuten private function getTotalRak() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("priceminister") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // total Aliexpress private function getTotalAli() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("aliexpress_payment") AND cl.id_lang = 1'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // paiement Carte bancaire private function getCb() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("monetico", "atos") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql); } // Paiement Paypal private function getPaypal() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module LIKE ("paypal") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } // Paiement Virement private function getTransfert() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("ps_wirepayment", "bankwire") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } // Paiement Alma private function getAlma() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("alma") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } // Paiement Naturabuy CB private function getNatCb() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("NaturaBuyPayment") AND o.payment LIKE ("cb") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } // Paiement Naturabuy Paypal private function getNatPay() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("NaturaBuyPayment") AND o.payment LIKE ("paypal") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } // Paiement Naturabuy CB3X private function getNatCb3x() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("NaturaBuyPayment") AND o.payment LIKE ("cb3x") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } // Paiement Naturabuy CB4X private function getNatCb4x() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("NaturaBuyPayment") AND o.payment LIKE ("cb4x") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } // Paiement Rakuten private function getRak() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("priceminister") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } // Paiement Aliexpress private function getAli() { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("aliexpress_payment") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } } Link to comment Share on other sites More sharing options...
coeos.pro Posted September 22, 2022 Share Posted September 22, 2022 tu utilises 9 fois la même requête SQL, c'est juste la ligne "AND o.module IN..." qui change, créé une seule fonction comme : private function getDatasPayment($paiement) { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module LIKE ("'.pSQL($paiement).'") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } et au lieu de mettre $ali = $this->getAli(); tu mets : $ali = $this->getDatasPayment('aliexpress_payment'); Link to comment Share on other sites More sharing options...
coeos.pro Posted September 22, 2022 Share Posted September 22, 2022 idem pour le code qui est utilisé 5 fois: <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; ou encore <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr> Link to comment Share on other sites More sharing options...
Mediacom87 Posted September 22, 2022 Share Posted September 22, 2022 N'utilisez pas de code HTML dans le fichier, mais bien des template tpl cela sera plus simple à gérer et à maintenir. Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 22, 2022 Author Share Posted September 22, 2022 4 hours ago, coeos.pro said: idem pour le code qui est utilisé 5 fois: <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; ou encore <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr> Merci pour ton aide, j'ai réduit le nombre de requête mais comment faire avec ce code html pour éviter de l'avoir plusieurs fois ? Link to comment Share on other sites More sharing options...
coeos.pro Posted September 22, 2022 Share Posted September 22, 2022 quelque chose comme : complète tous les paiements au début, ensuite le HTML est, comme le dit Mediacom87, à mettre dans un fichier tpl (langage SMARTY) <?php $paiements = array( 'paypal' => 'Paiement Paypal', 'NATURABUY' => 'Paiement Naturabuy Carte bancaire', 'NaturaBuyPayment' => 'Paiement Naturabuy CB3X', ); foreach ($paiements as $paiement => $name) { $this->html .= ' <h4>'.$name.'</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; $datas = $this->getDatasPayment($paiement); foreach ($datas as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } $total = $this->getTotalDatasPayment($paiement); foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; } private function getDatasPayment($paiement) { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module LIKE ("'.pSQL($paiement).'") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } private function getTotalDatasPayment($paiement) { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("'.pSQL($paiement).'") AND cl.id_lang = 1'; return Db::getInstance()->executeS($sql); } Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 23, 2022 Author Share Posted September 23, 2022 (edited) 10 hours ago, coeos.pro said: quelque chose comme : complète tous les paiements au début, ensuite le HTML est, comme le dit Mediacom87, à mettre dans un fichier tpl (langage SMARTY) <?php $paiements = array( 'paypal' => 'Paiement Paypal', 'NATURABUY' => 'Paiement Naturabuy Carte bancaire', 'NaturaBuyPayment' => 'Paiement Naturabuy CB3X', ); foreach ($paiements as $paiement => $name) { $this->html .= ' <h4>'.$name.'</h4> <table class="table" style="border: 0; cellspacing: 0;"> <thead> <tr> <th> <span class="title_box active">Pays</span> </th> <th> <span class="title_box active">Nombre de commandes</span> </th> <th> <span class="title_box active">Total HT</span> </th> <th> <span class="title_box active">Total TTC</span> </th> </tr> </thead> <tboby>'; $datas = $this->getDatasPayment($paiement); foreach ($datas as $result) { $this->html .= ' <tr> <td>' . $result['PAYS'] . '</td> <td>' . $result['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($result['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($result['CA_TTC'], $currency) . '</td> </tr>'; } $total = $this->getTotalDatasPayment($paiement); foreach ($total as $sum) $this->html .= ' <thead> <tr> <td> <strong>Total</strong> </td> <td>' . $sum['Nombre_total_cmde'] . '</td> <td>' . Tools::displayPrice($sum['CA_HT'], $currency) . '</td> <td>' . Tools::displayPrice($sum['CA_TTC'], $currency) . '</td> </tr> </thead> </tboby> </table> <hr>'; } private function getDatasPayment($paiement) { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module LIKE ("'.pSQL($paiement).'") AND cl.id_lang = 1 GROUP BY a.id_country'; return Db::getInstance()->executeS($sql); } private function getTotalDatasPayment($paiement) { $sql = 'SELECT cl.name AS PAYS, COUNT(o.id_order) AS Nombre_total_cmde, ROUND(SUM(o.total_paid_tax_excl), 2) AS CA_HT, ROUND(SUM(o.total_paid), 2) AS CA_TTC FROM ' . _DB_PREFIX_ . 'orders o LEFT JOIN ' . _DB_PREFIX_ . 'address a ON o.id_address_invoice = a.id_address LEFT JOIN ' . _DB_PREFIX_ . 'country_lang cl ON cl.id_country = a.id_country WHERE o.date_add BETWEEN ' . ModuleGraph::getDateBetween() . ' AND o.current_state IN (2, 3, 4 ,5, 9, 18, 25, 26, 20, 31, 32, 33) AND o.module IN ("'.pSQL($paiement).'") AND cl.id_lang = 1'; return Db::getInstance()->executeS($sql); } Super merci, je vais essayer de me débrouiller avec ces aides mais comment faire car je dois ajouter une condition AND o.payment après la condition AND o.module pour filtrer un peu plus sur le module Naturabuy Edited September 23, 2022 by Pistoletabilles (see edit history) Link to comment Share on other sites More sharing options...
coeos.pro Posted September 23, 2022 Share Posted September 23, 2022 si tu as le nom du module, il doit être unique (exemple ps_checkpayment) et tu le retrouves dans la colonne module de ps_orders, change les requetes sql et la variable $paiements = array( 'ps_checkpayment' => 'Paiement par cheque', ... et "Paiement par cheque" peut de toute façon être retrouvé dans la colonne payment de ps_orders Link to comment Share on other sites More sharing options...
Pistoletabilles Posted September 23, 2022 Author Share Posted September 23, 2022 1 minute ago, coeos.pro said: si tu as le nom du module, il doit être unique (exemple ps_checkpayment) et tu le retrouves dans la colonne module de ps_orders, change les requetes sql et la variable $paiements = array( 'ps_checkpayment' => 'Paiement par cheque', ... et "Paiement par cheque" peut de toute façon être retrouvé dans la colonne payment de ps_orders oui je filtre par module mais le problème se pose avec le module naturabuy qui a plusieurs moyens de paiement : cb, cb3x, cb4x et aussi paypal Il faut que je dissocie chaque moyen de paiement par module car si je filtre sur le moyen de paiement, tous les paiements paypal se mélangent. Link to comment Share on other sites More sharing options...
coeos.pro Posted September 23, 2022 Share Posted September 23, 2022 et avec $sql = 'SELECT module FROM ' . _DB_PREFIX_ . 'orders GROUP BY module'; $paiements = Db::getInstance()->executeS($sql); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now