Post by adwordsvouchersshop » Fri Jan 27, 2012 5:03 pm

When i choose the order to be "CANCELLED or REFUND, should not the "Total Sales This Month" and "Total Sales This Year" decrease the amount? (dollars, euros...). If it is not a bug can it be done?

New member

Posts

Joined
Fri Mar 11, 2011 7:00 am

Post by i2Paq » Fri Jan 27, 2012 7:34 pm

Known issue.

Norman in 't Veldt
Moderator OpenCart Forums

_________________ READ and Search BEFORE POSTING _________________

Our FREE search: Find your answer FAST!.

[How to] BTW + Verzend + betaal setup.


User avatar
Global Moderator

Posts

Joined
Mon Nov 09, 2009 7:00 pm
Location - Winkel - The Netherlands

Post by jty » Fri Jan 27, 2012 9:42 pm

adwordsvouchersshop wrote:When i choose the order to be "CANCELLED or REFUND, should not the "Total Sales This Month" and "Total Sales This Year" decrease the amount? (dollars, euros...). If it is not a bug can it be done?
This is because Open Cart does not know what order_status_id is Cancelled. On your site, Cancelled may be an order status of 5 but on my site it may an order status of 10. So, Open Cart doesn't know what Cancelled is and hence it cannot be used to adjust the totals on a standard install.

But you could hard code it into the model file - put in a Where clause to exclude the order status id that is cancelled on your site.

in admin/model/sale/order, look for the function getTotalSales and change the where clause to suit

jty
Active Member

Posts

Joined
Sat Aug 30, 2008 8:19 am

Post by straightlight » Fri Jan 27, 2012 10:27 pm

jty wrote:
adwordsvouchersshop wrote:When i choose the order to be "CANCELLED or REFUND, should not the "Total Sales This Month" and "Total Sales This Year" decrease the amount? (dollars, euros...). If it is not a bug can it be done?
This is because Open Cart does not know what order_status_id is Cancelled. On your site, Cancelled may be an order status of 5 but on my site it may an order status of 10. So, Open Cart doesn't know what Cancelled is and hence it cannot be used to adjust the totals on a standard install.

But you could hard code it into the model file - put in a Where clause to exclude the order status id that is cancelled on your site.

in admin/model/sale/order, look for the function getTotalSales and change the where clause to suit
Another alternative would be to add and to use a default value from the settings page which would only be specific to cancellation then to use the registered configuration object from the codes.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by jty » Fri Jan 27, 2012 11:56 pm

straightlight wrote:Another alternative would be to add and to use a default value from the settings page which would only be specific to cancellation then to use the registered configuration object from the codes.
my thought was to add another field to the order_status table to flag the order statii as canceled or not but that's because I avoid the settings table as much as possible.

jty
Active Member

Posts

Joined
Sat Aug 30, 2008 8:19 am

Post by straightlight » Fri Jan 27, 2012 11:59 pm

By adding a new field into the settings, it is still to know what would be the default defined value from configuration or setting a default value straight from the SQL field which would be the same result.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by fido-x » Sat Jan 28, 2012 10:55 am

Really, it's just the db queries in the model that need to be fixed so that the sales figures that are displayed are based on "Completed" orders instead of all orders where the order status id is greater than zero. Or new queries written specifically for the dashboard page.

Insert the following db queries into "admin/model/sale/order.php"

Code: Select all

public function getDashboardTotalSales() {
    $query = $this->db->query("SELECT SUM(total) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id = '" . (int)$this->config->get('config_complete_status_id') . "'");

    return $query->row['total'];
} 

Code: Select all

public function getDashboardTotalSalesByYear($year) {
    $query = $this->db->query("SELECT SUM(total) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id = '" . (int)$this->config->get('config_complete_status_id') . "' AND YEAR(date_added) = '" . (int)$year . "'");

    return $query->row['total'];
} 

Code: Select all

public function getDashboardTotalSales() {
    $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id = '" . (int)$this->config->get('config_complete_status_id') . "'");

    return $query->row['total'];
}  
Then, in "admin/controller/common/home.php" replace the following (lines 142-144):

Code: Select all

$this->data['total_sale'] = $this->currency->format($this->model_sale_order->getTotalSales(), $this->config->get('config_currency'));
$this->data['total_sale_year'] = $this->currency->format($this->model_sale_order->getTotalSalesByYear(date('Y')), $this->config->get('config_currency'));
$this->data['total_order'] = $this->model_sale_order->getTotalOrders(); 
with:

Code: Select all

$this->data['total_sale'] = $this->currency->format($this->model_sale_order->getDashboardTotalSales(), $this->config->get('config_currency'));
$this->data['total_sale_year'] = $this->currency->format($this->model_sale_order->getDashboardTotalSalesByYear(date('Y')), $this->config->get('config_currency'));
$this->data['total_order'] = $this->model_sale_order->getDashboardTotalOrders(); 
Your dashboard sales and order figures in the overview should now display figures based on completed orders.

Image
Modules for OpenCart 2.3.0.2
Homepage Module [Free - since OpenCart 0.7.7]
Multistore Extensions
Store Manager Multi-Vendor/Multi-Store management tool

If you're not living on the edge ... you're taking up too much space!


User avatar
Expert Member

Posts

Joined
Sat Jun 28, 2008 1:09 am
Location - Tasmania, Australia

Post by adwordsvouchersshop » Sat Jan 28, 2012 5:18 pm

Thanks for the codes Fido, but it doesn't work for me, when i add them i get a blank page. I have a vqmod installed :
http://www.opencart.com/index.php?route ... _id=100547, a part of the code from this vqmod modifies the following:

Code: Select all

<file name="adminmodzcp/model/sale/order.php">
		<operation>
			<search position="before"><![CDATA[public function getTotalSalesByYear($year) {]]></search>
			<add><![CDATA[	public function getTotalSalesByMonth($month, $year) {
      	$query = $this->db->query("SELECT SUM(total) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id > '0' AND MONTH(date_added) = '" . $month . "' AND YEAR(date_added) = '" . (int)$year . "'");

		return $query->row['total'];
	}]]></add>
		</operation>
	</file>
and

Code: Select all

<file name="adminmodzcp/controller/common/home.php">
		<operation>
			<search position="replace"><![CDATA[		$this->data['text_total_sale_year'] = $this->language->get('text_total_sale_year');]]></search>
			<add><![CDATA[		$this->data['text_total_sale_year'] = $this->language->get('text_total_sale_year');
		$this->data['text_total_sale_month'] = $this->language->get('text_total_sale_month');]]></add>
		</operation>
		<operation>
			<search position="replace"><![CDATA[		$this->data['text_total_affiliate_approval'] = $this->language->get('text_total_affiliate_approval');]]></search>
			<add><![CDATA[		$this->data['text_total_affiliate_approval'] = $this->language->get('text_total_affiliate_approval');
		$this->data['text_returns_approval'] = $this->language->get('text_returns_approval');]]></add>
		</operation>
		<operation>
			<search position="replace"><![CDATA[		$this->data['total_sale_year'] = $this->currency->format($this->model_sale_order->getTotalSalesByYear(date('Y')), $this->config->get('config_currency'));]]></search>
			<add><![CDATA[		$this->data['total_sale_year'] = $this->currency->format($this->model_sale_order->getTotalSalesByYear(date('Y')), $this->config->get('config_currency'));
		$this->data['total_sale_month'] = $this->currency->format($this->model_sale_order->getTotalSalesByMonth(date("m"), date('Y')), $this->config->get('config_currency'));
]]></add>
		</operation>
		<operation>
			<search position="replace"><![CDATA[		$this->data['total_affiliate_approval'] = $this->model_sale_affiliate->getTotalAffiliatesAwaitingApproval();]]></search>
			<add><![CDATA[		$this->data['total_affiliate_approval'] = $this->model_sale_affiliate->getTotalAffiliatesAwaitingApproval();
				
		$this->load->model('sale/return');
		
		$data['filter_return_status_id']=4;
		$this->data['total_returns_approval'] = $this->model_sale_return->getTotalReturns($data);
]]></add>
		</operation>
	</file>
I have tried to add the 3 public functions to there respectives in the xml, still no luck.

New member

Posts

Joined
Fri Mar 11, 2011 7:00 am

Post by adwordsvouchersshop » Sat Jan 28, 2012 6:33 pm

The odd thing is that i tried disabling all the xml mods and put the lines of code as it is where you have said, but i still get the blank page.

New member

Posts

Joined
Fri Mar 11, 2011 7:00 am

Post by straightlight » Sat Jan 28, 2012 9:38 pm

If you go to your System - > Error logs under the admin, what does the error message report regarding the blank page ?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by adwordsvouchersshop » Sat Jan 28, 2012 11:32 pm

LOL, nothing, it doesn't show any errors.

New member

Posts

Joined
Fri Mar 11, 2011 7:00 am

Post by straightlight » Sat Jan 28, 2012 11:38 pm

Follow this solution: http://forum.opencart.com/viewtopic.php ... rs#p239001 . Then, you'll be able to report the problem once you retry the action on your site.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by adwordsvouchersshop » Sun Jan 29, 2012 12:38 am

I have made what you suggested, but still no errors. It is very odd. I have never encountered such thing. I will try it on a clean install, and update you with any progress made.

New member

Posts

Joined
Fri Mar 11, 2011 7:00 am

Post by straightlight » Sun Jan 29, 2012 12:44 am

While installing a fresh install is also good suggestion, to check your php.ini for enabling the errors would also provide advantage on seeing those errors. ;)

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by adwordsvouchersshop » Sun Jan 29, 2012 1:01 am

This is the error that i get on a fresh install:
Fatal error: Cannot redeclare ModelSaleOrder::getDashboardTotalSales() in /teststore/admin/model/sale/order.php on line 14

It is a fresh install and the only thing changed is the codes from fido.
I attached the order.php to see how it looks after adding the codes.

New member

Posts

Joined
Fri Mar 11, 2011 7:00 am

Post by straightlight » Sun Jan 29, 2012 1:05 am

The instructions above was stated to add this method name twice which is obviously not possible:

Code: Select all

public function getDashboardTotalSales() {
    $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id = '" . (int)$this->config->get('config_complete_status_id') . "'");

    return $query->row['total'];
}
to redeclare the same method names or function names within PHP. The total count and summary should rather be returned from one call either from two different methods or from the same method but two different indexes within an array which is why you encounter this error message right now. ;)

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by adwordsvouchersshop » Sun Jan 29, 2012 1:10 am

Sorry, i am a noob on programing, i know only some html , few things about php, what would be the fix?

New member

Posts

Joined
Fri Mar 11, 2011 7:00 am

Post by straightlight » Sun Jan 29, 2012 1:21 am

A good start would be to eliminate the duplicated: getDashboardTotalSales() method paragraph and to replace the first one:

Code: Select all

public function getDashboardTotalSales() {
    $query = $this->db->query("SELECT COUNT(*) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id = '" . (int)$this->config->get('config_complete_status_id') . "'");

    return $query->row['total'];
}
with this one:

Code: Select all

public function getDashboardTotalSalesCount() {
    $query = $this->db->query("SELECT COUNT(total) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id = '" . (int)$this->config->get('config_complete_status_id') . "'");

   return $query->row['total'];
}

public function getDashboardTotalSalesSum() {
    $query = $this->db->query("SELECT SUM(total) AS total FROM `" . DB_PREFIX . "order` WHERE order_status_id = '" . (int)$this->config->get('config_complete_status_id') . "'");

   return $query->row['total'];
}
Then, in your admin/view/template/common/home.tpl file,

to replace:

Code: Select all

<td><?php echo $total_sale; ?></td>
with:

Code: Select all

<td><?php echo $total_count_sale; ?><br /><?php echo $total_sum_sale; ?></td>
Then, in your admin/controller/common/home.php file,

to replace:

Code: Select all

    $this->data['total_sale'] = $this->currency->format($this->model_sale_order->getDashboardTotalSales(), $this->config->get('config_currency'));
    $this->data['total_sale_year'] = $this->currency->format($this->model_sale_order->getDashboardTotalSalesByYear(date('Y')), $this->config->get('config_currency'));
    $this->data['total_order'] = $this->model_sale_order->getDashboardTotalOrders(); 
with:

Code: Select all

    $this->data['total_count_sale'] = $this->currency->format($this->model_sale_order->getDashboardTotalSalesCount(), $this->config->get('config_currency'));
    $this->data['total_sum_sale'] = $this->currency->format($this->model_sale_order->getDashboardTotalSalesSum(), $this->config->get('config_currency'));
    $this->data['total_sale_year'] = $this->currency->format($this->model_sale_order->getDashboardTotalSalesByYear(date('Y')), $this->config->get('config_currency'));
    $this->data['total_order'] = $this->model_sale_order->getDashboardTotalOrders(); 
This should return the expected results.
Last edited by straightlight on Sun Jan 29, 2012 2:58 am, edited 2 times in total.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by straightlight » Sun Jan 29, 2012 1:38 am

I have edited the steps above.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by adwordsvouchersshop » Sun Jan 29, 2012 2:34 am

I get this error now:

Code: Select all

Notice: Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '*) AS sum_total FROM `order` WHERE order_status_id = '5'' at line 1
Error No: 1064
SELECT COUNT(*) AS count_total, SUM(*) AS sum_total FROM `order` WHERE order_status_id = '5' in /teststore/system/database/mysql.php on line 49
I have attached the files home.php and order.php

New member

Posts

Joined
Fri Mar 11, 2011 7:00 am
Who is online

Users browsing this forum: No registered users and 19 guests