Advertisement
jfreak53

WHMCS Dedicated Server Revenue Report

Jul 10th, 2012
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.63 KB | None | 0 0
  1. <?php
  2.  
  3. if (!defined("WHMCS"))
  4.     die("This file cannot be accessed directly");
  5.    
  6. # The title of your report
  7. $reportdata["title"] = "Dedicated Server Revenue";
  8.  
  9. # The description of your report
  10. $reportdata["description"] = "";
  11.  
  12. # Header text - this gets displayed above the report table of data
  13. $reportdata["headertext"] = "";
  14.  
  15. # Report Table of Data Column Headings - should be an array of values
  16. $reportdata["tableheadings"] = array("Server Name","Base Cost per Month","Base Profit per Server","Servers","Monthly Earnings");
  17.  
  18. # Report Table Values - one of these lines for each row you want in the table
  19. # should be an array of values to match the column headings
  20. $query = "SELECT
  21.  p.id,
  22.  p.name
  23. FROM tblproducts AS p
  24.  LEFT JOIN tblpricing pr
  25.    ON (p.id = pr.relid)
  26.  LEFT JOIN tblcustomfields c
  27.    ON (p.id = c.relid)
  28.  LEFT JOIN tblcustomfieldsvalues v
  29.    ON (v.fieldid = c.id)
  30. WHERE c.fieldname = 'Cost' AND p.type = 'server' AND pr.type = 'product'
  31. GROUP BY p.id";
  32. $result=mysql_query($query);
  33. $s = array();
  34. while ($d = mysql_fetch_array($result)) {
  35.     $s[$d[0]]['name'] = $d[1];
  36.     $s[$d[0]]['count'] = 0;
  37. }
  38.  
  39. $query = "SELECT
  40.  p.id,
  41.  p.name,
  42.  pr.monthly,
  43.  c.fieldname,
  44.  c.fieldoptions,
  45.  v.value,
  46.  h.amount
  47. FROM tblproducts AS p
  48.  LEFT JOIN tblpricing pr
  49.    ON (p.id = pr.relid)
  50.  LEFT JOIN tblcustomfields c
  51.    ON (p.id = c.relid)
  52.  RIGHT JOIN tblhosting h
  53.    ON (h.packageid = p.id)
  54.  LEFT JOIN tblcustomfieldsvalues v
  55.    ON (v.fieldid = c.id AND v.relid = h.id)
  56. WHERE c.fieldname = 'Cost' AND p.type = 'server' AND pr.type = 'product' AND h.domainstatus = 'Active'
  57. GROUP BY h.id, p.id";
  58. $result1=mysql_query($query);
  59. $c = 0;
  60. while ($data = mysql_fetch_array($result1)) {
  61.     $cost = ($data[5] > '' ? $data[5] : $data[4]);
  62.     $prof = ($data[2] <> $data[6] ? $data[6] - $cost : $data[2] - $cost);
  63.    
  64.     if($data[2] <> $data[6] || $data[5] > '') $n = $data[0]+$c;
  65.     else $n = $data[0];
  66.    
  67.     $s[$n]['name'] = $data[1].($data[2] <> $data[6] || $data[5] > '' ? ' (Custom)' : '');
  68.     $s[$n]['cost'] = $cost;
  69.     $s[$n]['profit'] = $prof;
  70.     $s[$n]['count'] += 1;
  71.    
  72.     $c++;
  73. }
  74.  
  75. foreach($s as $f) {
  76.     $totalexpenditure+=($f['cost']*$f['count']);
  77.     $totalgrossprofit+=($f['profit']*$f['count']);
  78.     $reportdata["tablevalues"][] = array($f['name'],number_format($f['cost'],2),number_format($f['profit'],2),$f['count'],number_format($f['profit']*$f['count'],2));
  79. }
  80.  
  81. # Report Footer Text - this gets displayed below the report table of data
  82. $data["footertext"]="<B>Total Gross Profit:</B> ".number_format($totalgrossprofit,2)."<br><B>Total Expenses:</B> ".number_format($totalexpenditure,2)."<br><b>Total Server's:</b> $c";
  83.  
  84. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement