Jump to content
rawad00

Total Statistiques des ventes ne se met pas a jour apres un remboursement

Recommended Posts

Bonjour,

 

 

   Vos idees sont les bienvenues..

 

   Je rencontre un bug/processus incomplet de la reprise de marchandise.

   Apres une reprise de marchandise (RMA Return Merchandise) et un remboursement total au client (Refund) le tableau de bord indiquant les statistiques des ventes ne se met pas a jour et ne deduit pas le prix des produits retournes (Dashboard Sales total not updating total price after a complete refund)

 

  Any ideas? Des idees?

 

Merci

Share this post


Link to post
Share on other sites

Bonjour,

En fait tout se situe dans le fichier AdminHomeController.php (répertoire controllers/admin).

Je ne me sens pas le courage ce soir de tout détailler mais voici mes modifs perso qui devraient pouvoir t'aiguiller :

	public function getMonthlyStatistics()
	{
		$moisprecedent = date("m")-1;
		
		$currency = Tools::setCurrency($this->context->cookie);
		
		$resultm = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT IFNULL(SUM(`total_paid_tax_excl` / conversion_rate), "0") as total_sales, COUNT(*) as total_orders
			FROM `'._DB_PREFIX_.'orders`
			WHERE valid = 1
				AND `invoice_date` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'
				'.Shop::addSqlRestriction(Shop::SHARE_ORDER).'
		');
		$resultavoirsmttc = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT SUM(`amount`) as total_avoirs, COUNT(*) as nombre_avoirs
			FROM `'._DB_PREFIX_.'order_slip`
			WHERE `date_add` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'
		');
		$resultavoirsm = $resultavoirsmttc['total_avoirs'] / 1.2;
		$resultfinalm = ($resultm['total_sales'] - $resultavoirsn);
		$resultfinalordersm = ($resultm['total_orders'] - $resultavoirsm['nombre_avoirs']);

		$resultmmoinsun = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT IFNULL(SUM(`total_paid_tax_excl` / conversion_rate), "0") as total_sales, COUNT(*) as total_orders
			FROM `'._DB_PREFIX_.'orders`
			WHERE valid = 1
				AND `invoice_date` BETWEEN \''.date('Y').'-'.($moisprecedent).'-01 00:00:00\' AND \''.date('Y').'-'.($moisprecedent).'-31 23:59:59\'
				'.Shop::addSqlRestriction(Shop::SHARE_ORDER).'
		');
		$resultavoirsmmoinsunttc = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT SUM(`amount`) as total_avoirs, COUNT(*) as nombre_avoirs
			FROM `'._DB_PREFIX_.'order_slip`
			WHERE `date_add` BETWEEN \''.date('Y').'-'.($moisprecedent).'-01 00:00:00\' AND \''.date('Y').'-'.($moisprecedent).'-31 23:59:59\'
		');
		$resultavoirsmmoinsun = $resultavoirsmmoinsunttc['total_avoirs'] / 1.2;
		$resultfinalmmoinsun = ($resultmmoinsun['total_sales'] - $resultavoirsmmoinsun);
		$resultfinalordersmmoinsun = ($resultmmoinsun['total_orders'] - $resultavoirsmmoinsun['nombre_avoirs']);
		
		$resultinscription = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT COUNT(`id_customer`) AS total_registrations
			FROM `'._DB_PREFIX_.'customer` c
			WHERE c.`date_add` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'
				'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
		');

		$jourdumois = date("d");
		$cajour = ($resultfinalm / $jourdumois);
		$commandejour = ($resultfinalordersm / $jourdumois);
		$jourstotalmois = date("t");
		$previsionmensuelle = ($cajour * $jourstotalmois);		
		
		$paniermoyen = ($resultm['total_sales'] / $resultm['total_orders'] * 1.2);
		$paniermoyenmmoinsun = ($resultmmoinsun['total_sales'] / $resultmmoinsun['total_orders'] * 1.2);
		
		$evolutionventes = number_format(($previsionmensuelle - $resultfinalmmoinsun) / $resultfinalmmoinsun * 100, 2);
		$evolutionpaniermoyen = number_format(($paniermoyen - $paniermoyenmmoinsun) / $paniermoyenmmoinsun * 100, 2);
		
		$content = '<div class="table_info">
			<h5><a href="index.php?tab=AdminStats&token='.Tools::getAdminTokenLite('AdminStats').'">'.$this->l('View more').'</a> '.$this->l('This month\'s activity').' </h5>
			<table class="table_info_details" style="width:100%;">
					<colgroup>
						<col width="">
						<col width="80px">
					</colgroup>
				<tr class="tr_odd">
					<td class="td_align_left">
					'.$this->l('Sales').' HT
					</td>
					<td>
						'
						.Tools::displayPrice($resultfinalm, $currency)
						.'
					</td>
				</tr>			
				<tr>
					<td class="td_align_left">
						Prévisionnel HT mois en cours
					</td>
					<td>
						'.Tools::displayPrice($previsionmensuelle, $currency).'
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						Ventes M-1
					</td>
					<td>
						'.Tools::displayPrice($resultfinalmmoinsun, $currency).'
					</td>
				</tr>
				<tr>
					<td class="td_align_left">
						Evolution ventes
					</td>
					<td>
						'.($evolutionventes).' %
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						Panier moyen TTC
					</td>
					<td>
						'.Tools::displayPrice($paniermoyen, $currency).'
					</td>
				</tr>
				<tr>
					<td class="td_align_left">
						Panier moyen M-1
					</td>
					<td>
						'.Tools::displayPrice($paniermoyenmmoinsun, $currency).'
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						Evolution panier moyen
					</td>
					<td>
						'.($evolutionpaniermoyen).' %
					</td>
				</tr>
				<tr>
					<td class="td_align_left">
						'.$this->l('Total registrations').'
					</td>
					<td>
						'.(int)($resultinscription['total_registrations']).'
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						'.$this->l('Total orders').'
					</td>
					<td>
						'.(int)($resultfinalordersm).'
					</td>
				</tr>
				<tr>
					<td class="td_align_left">
						CA / jour
					</td>
					<td>
						'.Tools::displayPrice($cajour, $currency).'
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						Commandes / jour
					</td>
					<td>
						'.(int)($commandejour).'
					</td>
				</tr>
			</table>
		</div>';
		return $content;
	}

Il faut sortir le total des ventes, puis le total des avoirs, pour finalement calculer la différence des deux.

Dans le code, il y a quelques stats utiles dans mon domaine d'activité, à implémenter ou non dans ton cas.

J'ai intégré le taux de TVA à 20% en dur dans le code, il faudrait voir pour récupérer la variable du taux de taxe pour quelque chose de pérenne à long terme, mais pas le temps de m'en occuper dans l'immédiat.

Have fun ;)

Share this post


Link to post
Share on other sites

Bonjour,

En fait tout se situe dans le fichier AdminHomeController.php (répertoire controllers/admin).

Je ne me sens pas le courage ce soir de tout détailler mais voici mes modifs perso qui devraient pouvoir t'aiguiller :

	public function getMonthlyStatistics()
	{
		$moisprecedent = date("m")-1;
		
		$currency = Tools::setCurrency($this->context->cookie);
		
		$resultm = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT IFNULL(SUM(`total_paid_tax_excl` / conversion_rate), "0") as total_sales, COUNT(*) as total_orders
			FROM `'._DB_PREFIX_.'orders`
			WHERE valid = 1
				AND `invoice_date` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'
				'.Shop::addSqlRestriction(Shop::SHARE_ORDER).'
		');
		$resultavoirsmttc = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT SUM(`amount`) as total_avoirs, COUNT(*) as nombre_avoirs
			FROM `'._DB_PREFIX_.'order_slip`
			WHERE `date_add` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'
		');
		$resultavoirsm = $resultavoirsmttc['total_avoirs'] / 1.2;
		$resultfinalm = ($resultm['total_sales'] - $resultavoirsn);
		$resultfinalordersm = ($resultm['total_orders'] - $resultavoirsm['nombre_avoirs']);

		$resultmmoinsun = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT IFNULL(SUM(`total_paid_tax_excl` / conversion_rate), "0") as total_sales, COUNT(*) as total_orders
			FROM `'._DB_PREFIX_.'orders`
			WHERE valid = 1
				AND `invoice_date` BETWEEN \''.date('Y').'-'.($moisprecedent).'-01 00:00:00\' AND \''.date('Y').'-'.($moisprecedent).'-31 23:59:59\'
				'.Shop::addSqlRestriction(Shop::SHARE_ORDER).'
		');
		$resultavoirsmmoinsunttc = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT SUM(`amount`) as total_avoirs, COUNT(*) as nombre_avoirs
			FROM `'._DB_PREFIX_.'order_slip`
			WHERE `date_add` BETWEEN \''.date('Y').'-'.($moisprecedent).'-01 00:00:00\' AND \''.date('Y').'-'.($moisprecedent).'-31 23:59:59\'
		');
		$resultavoirsmmoinsun = $resultavoirsmmoinsunttc['total_avoirs'] / 1.2;
		$resultfinalmmoinsun = ($resultmmoinsun['total_sales'] - $resultavoirsmmoinsun);
		$resultfinalordersmmoinsun = ($resultmmoinsun['total_orders'] - $resultavoirsmmoinsun['nombre_avoirs']);
		
		$resultinscription = Db::getInstance(_PS_USE_SQL_SLAVE_)->getRow('
			SELECT COUNT(`id_customer`) AS total_registrations
			FROM `'._DB_PREFIX_.'customer` c
			WHERE c.`date_add` BETWEEN \''.date('Y-m').'-01 00:00:00\' AND \''.date('Y-m').'-31 23:59:59\'
				'.Shop::addSqlRestriction(Shop::SHARE_CUSTOMER).'
		');

		$jourdumois = date("d");
		$cajour = ($resultfinalm / $jourdumois);
		$commandejour = ($resultfinalordersm / $jourdumois);
		$jourstotalmois = date("t");
		$previsionmensuelle = ($cajour * $jourstotalmois);		
		
		$paniermoyen = ($resultm['total_sales'] / $resultm['total_orders'] * 1.2);
		$paniermoyenmmoinsun = ($resultmmoinsun['total_sales'] / $resultmmoinsun['total_orders'] * 1.2);
		
		$evolutionventes = number_format(($previsionmensuelle - $resultfinalmmoinsun) / $resultfinalmmoinsun * 100, 2);
		$evolutionpaniermoyen = number_format(($paniermoyen - $paniermoyenmmoinsun) / $paniermoyenmmoinsun * 100, 2);
		
		$content = '<div class="table_info">
			<h5><a href="index.php?tab=AdminStats&token='.Tools::getAdminTokenLite('AdminStats').'">'.$this->l('View more').'</a> '.$this->l('This month\'s activity').' </h5>
			<table class="table_info_details" style="width:100%;">
					<colgroup>
						<col width="">
						<col width="80px">
					</colgroup>
				<tr class="tr_odd">
					<td class="td_align_left">
					'.$this->l('Sales').' HT
					</td>
					<td>
						'
						.Tools::displayPrice($resultfinalm, $currency)
						.'
					</td>
				</tr>			
				<tr>
					<td class="td_align_left">
						Prévisionnel HT mois en cours
					</td>
					<td>
						'.Tools::displayPrice($previsionmensuelle, $currency).'
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						Ventes M-1
					</td>
					<td>
						'.Tools::displayPrice($resultfinalmmoinsun, $currency).'
					</td>
				</tr>
				<tr>
					<td class="td_align_left">
						Evolution ventes
					</td>
					<td>
						'.($evolutionventes).' %
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						Panier moyen TTC
					</td>
					<td>
						'.Tools::displayPrice($paniermoyen, $currency).'
					</td>
				</tr>
				<tr>
					<td class="td_align_left">
						Panier moyen M-1
					</td>
					<td>
						'.Tools::displayPrice($paniermoyenmmoinsun, $currency).'
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						Evolution panier moyen
					</td>
					<td>
						'.($evolutionpaniermoyen).' %
					</td>
				</tr>
				<tr>
					<td class="td_align_left">
						'.$this->l('Total registrations').'
					</td>
					<td>
						'.(int)($resultinscription['total_registrations']).'
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						'.$this->l('Total orders').'
					</td>
					<td>
						'.(int)($resultfinalordersm).'
					</td>
				</tr>
				<tr>
					<td class="td_align_left">
						CA / jour
					</td>
					<td>
						'.Tools::displayPrice($cajour, $currency).'
					</td>
				</tr>
				<tr class="tr_odd">
					<td class="td_align_left">
						Commandes / jour
					</td>
					<td>
						'.(int)($commandejour).'
					</td>
				</tr>
			</table>
		</div>';
		return $content;
	}

Il faut sortir le total des ventes, puis le total des avoirs, pour finalement calculer la différence des deux.

Dans le code, il y a quelques stats utiles dans mon domaine d'activité, à implémenter ou non dans ton cas.

J'ai intégré le taux de TVA à 20% en dur dans le code, il faudrait voir pour récupérer la variable du taux de taxe pour quelque chose de pérenne à long terme, mais pas le temps de m'en occuper dans l'immédiat.

Have fun ;)

 

 

Merci pour ta reponse, j'ai cherche dans mon prestashop version 1.6.

 

J'ai trouve un controlleur different, AdminHomeController.php n'existant plus dans la 1.6, a la place j'ai trouve AdminStatsController.php contenant la methode suivante :

	public static function getTotalSales($date_from, $date_to, $granularity = false)
	{
		if ($granularity == 'day')
		{
			$sales = array();
			$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
			SELECT LEFT(`invoice_date`, 10) as date, SUM(total_paid_tax_excl / o.conversion_rate) as sales
			FROM `'._DB_PREFIX_.'orders` o
			WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
			'.Shop::addSqlRestriction(false, 'o').'
			GROUP BY LEFT(`invoice_date`, 10)');
			foreach ($result as $row)
				$sales[strtotime($row['date'])] = $row['sales'];
			return $sales;
		}
		elseif ($granularity == 'month')
		{
			$sales = array();
			$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
			SELECT LEFT(`invoice_date`, 7) as date, SUM(total_paid_tax_excl / o.conversion_rate) as sales
			FROM `'._DB_PREFIX_.'orders` o
			WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
			'.Shop::addSqlRestriction(false, 'o').'
			GROUP BY LEFT(`invoice_date`, 7)');
			foreach ($result as $row)
				$sales[strtotime($row['date'].'-01')] = $row['sales'];
			return $sales;
		}
		else
			return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue('
			SELECT SUM(total_paid_tax_excl / o.conversion_rate)
			FROM `'._DB_PREFIX_.'orders` o
			WHERE `invoice_date` BETWEEN "'.pSQL($date_from).' 00:00:00" AND "'.pSQL($date_to).' 23:59:59"
			'.Shop::addSqlRestriction(false, 'o'));
	}

Par contre, une boucle for est utilise, je ne vois comment deduire les retour marchandise du calcul. Vous vous baser sur la table credit-slips? ca veut dire peut importe le moyen de payment utiliser (remboursement direct, remboursement par coupon, ...) ca suffira? Vous avez une idee comment mettre a jour cette version afin de corriger ce bug?

 

Merci d'avance

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More