Jump to content

[report] Monthly Domain Sales


nike.stars

Recommended Posts

Hi there, this is my first post in whmcs and i would like to share one of my report module called "Monthly Domain Sales"

 

The reason i create this report is because every month i need to count my revenue each month only from my webhosting account. Since whmcs only provide standard report for total income/transactions every month so i create this report so i can use this report to subtract from total sales per month and then i can get nett income for webhosting :)

 

this report still has a bug in the month selector, i appreciate any help i can get.

 

also i create this report according to my need so it maybe inappropriate for some of you.

 

please check this line:

if ($amount != '0')
$balance += $amount;
elseif (substr($domain, -3, 3) == 'com' || 'net' || 'org' || 'info')
$balance += '90000';

 

i use that line because i have a free domain promotion for every big package order and because of that the invoice for the domain is 0 (zero). so i add the code above to manually add domain prices for this "free domain". you can also modify it according to your needs.

 

and if you don't need any of that, just replace the above code with this:

$balance += $amount;

 

hopefully you guys like it :)

monthly_domain_sales.zip

Link to comment
Share on other sites

@Giannis

in line 38 there is a bug...

 

Replace that line with this one:

 

$reportdata["tablevalues"][] = array($date,"<a href='/admin/invoices.php?action=edit&id=".$invoiceid."'>".$invoiceid."</a>","<a href='/admin/invoices.php?action=edit&id=".$invoicenum."'>".$invoicenum."</a>",$amount,$type,$domain,"<a href='/admin/clientssummary.php?userid=".$userid."'>".$userid."</a>",$firstname, $lastname);

Link to comment
Share on other sites

@ nike.stars

 

The problem with the month you are talking about in the first script can be resolved using this code

 

if ($month<"10") {

$month="0".$month;

 

}

 

The code has to be placed after your

 

if ($month=="") {

$month=date("m");

$year=date("Y");

 

 

}

 

code.

Link to comment
Share on other sites

This should get it going for you

<?php

if (!defined("WHMCS"))
   die("This file cannot be accessed directly");

$months = array('January','February','March','April','May','June','July','August','September','October','November','December');

if ($month=="") {
   $month=date("m");
   $year=date("Y");
}

$pmonth = str_pad($month, 2, "0", STR_PAD_LEFT);  

$reportdata["title"] = "Monthly Domain Sales Report for ".$months[$month-1]." ".$year;
$reportdata["description"] = "This report shows a transactions summary for a selected month.";

$reportdata["tableheadings"] = array("Date", "Invoice ID", "Invoice Number" ,"Amount","Type","Domain","User ID","First Name","Last Name");

$query = "SELECT i.date, i.id, i.invoicenum, t.amount, t.type, d.domain, t.userid, c.firstname, c.lastname FROM tblinvoices i, tblinvoiceitems t, tblclients c, tbldomains d WHERE i.userid = t.userid AND t.invoiceid = i.id AND c.id = t.userid AND d.userid = c.id AND d.id = t.relid AND t.type = 'Domain' AND i.status = 'Paid' AND i.date LIKE '$year-$month-%'";

   $result=mysql_query($query);
   while ($data = mysql_fetch_array($result) ) {
       $date = $data[0];
       $invoiceid = $data[1];
       $invoicenum = $data[2];
       $amount = $data[3];
       $type = $data[4];
       $domain = $data[5];
       $userid = $data[6];
       $firstname = $data[7];
       $lastname = $data[8];
       $balance += $amount;


       $reportdata["tablevalues"][] = array($date, "<a href='invoices.php?action=edit&id=".$invoiceid."'>".$invoiceid."</a>", "<a href='invoices.php?action=edit&id=".$invoicenum."'>".$invoicenum."</a>", $amount,$type,$domain,"<a href='clientssummary.php?userid=".$userid."'>".$userid."</a>",$firstname,$lastname);
   }

$balance = sprintf("%01.2f",$balance);

$data["footertext"]="<p align=right><b>Balance: ".$CONFIG["CurrencySymbol"].$balance."</b></p><table width=90% align=center><tr><td>";
if ($month=="1") {
   $data["footertext"].="<a href=\"$PHP_SELF?report=$report&month=12&year=".($year-1)."\"><< December ".($year-1)."</a>";
} else {
   $data["footertext"].="<a href=\"$PHP_SELF?report=$report&month=".($month-1)."&year=".$year."\"><< ".$months[($month-2)]." $year</a>";
}
$data["footertext"].="</td><td align=right>";
if ($month=="12") {
   $data["footertext"].="<a href=\"$PHP_SELF?report=$report&month=1&year=".($year+1)."\">January ".($year+1)." >></a>";
} else {
   $data["footertext"].="<a href=\"$PHP_SELF?report=$report&month=".($month+1)."&year=".$year."\">".$months[(($month+1)-1)]." $year >></a>";
}
$data["footertext"].="</td></tr></table>";

?>

Link to comment
Share on other sites

WHERE i.userid = t.userid AND t.invoiceid = i.id AND c.id = t.userid AND d.userid = c.id AND d.id = t.relid

 

I'd highly recommend you look at the mysql website and learn what a *JOIN* is :)

 

And your report will include them in the month of the invoice, not necessarily the month of the payment recieved - might want to switch it to checking datepaid instead :)

Link to comment
Share on other sites

  • 11 months later...
  • 4 months later...

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