Jump to content

Custom Query to fetch product wise sales report


nitaish

Recommended Posts

You could use something like this to only show products registered in a specific year:

<?php
use WHMCS\Database\Capsule;
require __DIR__ . '/init.php';

$results = Capsule::table('tblhosting')
	->select('packageid', Capsule::raw('count(packageid) quantity'))
	->where('regdate', 'LIKE', '2019-%')
	->groupBy('packageid')
	->get();
	
print_r($results);

Renewals are a bit more difficult. You'd probably have to go through the tblinvoiceitems table and search by product name.

Link to comment
Share on other sites

9 hours ago, DennisHermannsen said:

You could use something like this to only show products registered in a specific year:

I don't think that would be accurate for a number of reasons - not the least of which being that you would need to get the clients currency for the results to make any sense... though I appreciate that the question didn't mention income, so that point may not be relevant.

10 hours ago, nitaish said:

I am looking for a custom mysql query to fetch report of sales per product for a specified period. For example, if I want to know which product sold the most and which one sold the least in the year 2019, how can I write a mysql query to get this report?

wouldn't it be simpler (relatively!) to duplicate (e.g don't edit the original file) the existing "Income By Product" report and modify it to suit your needs, .e g adjust the date range in the queries.

https://docs.whmcs.com/Reports

Quote

Income by Product Provides a breakdown per product/service of invoices paid in a given month. This excludes overpayments & other payments made to deposit funds (credit), and includes invoices paid from credit added in previous months, and thus may not match the income total for the month.

or you could rewrite the two product queries from the above report into SQL and run it from phpmyadmin or similar, adjusting the dates as applicable.

Edited by brian!
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated