PageRenderTime 27ms CodeModel.GetById 20ms RepoModel.GetById 0ms app.codeStats 0ms

/web/js/components/jqwidgets/demos/interactivedemos/salesreport/data.php

https://github.com/jonphipps/Metadata-Registry
PHP | 207 lines | 179 code | 25 blank | 3 comment | 33 complexity | 0bb469e20d53f4286965471dac600e93 MD5 | raw file
Possible License(s): AGPL-3.0, LGPL-2.1, Apache-2.0, MIT, BSD-3-Clause, MPL-2.0-no-copyleft-exception
  1. <?php
  2. // Include the connect.php file
  3. include ('connect.php');
  4. // Connect to the database
  5. $mysqli = new mysqli($hostname, $username, $password, $database);
  6. /* check connection */
  7. if (mysqli_connect_errno())
  8. {
  9. printf("Connect failed: %s\n", mysqli_connect_error());
  10. exit();
  11. }
  12. if(!isset($_GET['usedwidget'])){
  13. trigger_error("Missing/Invalid widget", E_USER_ERROR);
  14. }
  15. switch ($_GET['usedwidget']) {
  16. case 'employeedropdown':
  17. $query = "SELECT EmployeeID, FirstName, LastName, Photo from Employees where EmployeeID<9";
  18. $result = $mysqli->prepare($query);
  19. $result->execute();
  20. $result->bind_result($employeeId, $FirstName, $LastName, $Photo);
  21. while ($result->fetch())
  22. {
  23. $response[] = array(
  24. 'employeeId' => $employeeId,
  25. 'employeeName' => $FirstName." ".$LastName,
  26. 'employeePhoto' => strtolower($FirstName).".png",
  27. );
  28. }
  29. break;
  30. case 'salespermonthchart':
  31. $query = "SELECT distinct t2.ShippedDate, sum(t1.UnitPrice * t1.Quantity * (1 - t1.Discount)) as Subtotal from `Order Details` t1 left join Orders t2 on (t1.OrderID=t2.OrderID) where t2.EmployeeID=".$_GET['employeeid']." and t2.ShippedDate between date('1997-01-01') and date('1997-12-31') GROUP BY YEAR(t2.ShippedDate), MONTH(t2.ShippedDate) ASC";
  32. $result = $mysqli->prepare($query);
  33. $result->execute();
  34. $result->bind_result( $OrderDate, $Subtotal);
  35. while ($result->fetch())
  36. {
  37. $response[] = array(
  38. 'OrderDate' => substr($OrderDate, 0, -11)."01 00:00:00",
  39. 'Subtotal' => $Subtotal
  40. );
  41. }
  42. break;
  43. case 'salespermonthgrid':
  44. for($i=0; $i<13; $i++){
  45. $month = $i<10 ? "0".$i : $i;
  46. $response[] = array(
  47. 'OrderDate' => "1997-".$month."-01 00:00:00",
  48. 'Subtotal1' => 0,
  49. 'Subtotal2' => 0);
  50. }
  51. $query = "SELECT distinct t2.ShippedDate, sum(t1.UnitPrice * t1.Quantity * (1 - t1.Discount)) as Subtotal from `Order Details` t1 left join Orders t2 on (t1.OrderID=t2.OrderID) where t2.EmployeeID=".$_GET['employeeid1']." and t2.ShippedDate between date('1997-01-01') and date('1997-12-31') GROUP BY YEAR(t2.ShippedDate), MONTH(t2.ShippedDate) ASC";
  52. $result = $mysqli->prepare($query);
  53. $result->execute();
  54. $result->bind_result($OrderDate, $Subtotal);
  55. while ($result->fetch())
  56. {
  57. for($i=0; $i<13; $i++){
  58. if($response[$i]['OrderDate']==substr($OrderDate, 0, -11)."01 00:00:00"){
  59. $response[$i]['Subtotal1']=$Subtotal;
  60. }
  61. }
  62. }
  63. $query = "SELECT distinct t2.ShippedDate, sum(t1.UnitPrice * t1.Quantity * (1 - t1.Discount)) as Subtotal from `Order Details` t1 left join Orders t2 on (t1.OrderID=t2.OrderID) where t2.EmployeeID=".$_GET['employeeid2']." and t2.ShippedDate between date('1997-01-01') and date('1997-12-31') GROUP BY YEAR(t2.ShippedDate), MONTH(t2.ShippedDate) ASC";
  64. $result = $mysqli->prepare($query);
  65. $result->execute();
  66. $result->bind_result( $OrderDate, $Subtotal);
  67. while ($result->fetch())
  68. {
  69. for($i=0; $i<13; $i++){
  70. if($response[$i]['OrderDate']==substr($OrderDate, 0, -11)."01 00:00:00"){
  71. $response[$i]['Subtotal2']=$Subtotal;
  72. }
  73. }
  74. }
  75. array_shift($response);
  76. break;
  77. case 'expensespermonthgridchart':
  78. for($i=0; $i<13; $i++){
  79. $month = $i<10 ? "0".$i : $i;
  80. $response[] = array(
  81. 'OrderDate' => "1997-".$month."-01 00:00:00",
  82. 'Subtotal1' => 0,
  83. 'Subtotal2' => 0);
  84. }
  85. $query = "SELECT distinct t2.ShippedDate, (sum(t1.UnitPrice * t1.Quantity * (1 - t1.Discount))*0.8 - 50) as Subtotal from `Order Details` t1 left join Orders t2 on (t1.OrderID=t2.OrderID) where t2.EmployeeID=".$_GET['employeeid1']." and t2.ShippedDate between date('1997-01-01') and date('1997-12-31') GROUP BY YEAR(t2.ShippedDate), MONTH(t2.ShippedDate) ASC";
  86. $result = $mysqli->prepare($query);
  87. $result->execute();
  88. $result->bind_result($OrderDate, $Subtotal);
  89. while ($result->fetch())
  90. {
  91. for($i=0; $i<13; $i++){
  92. if($response[$i]['OrderDate']==substr($OrderDate, 0, -11)."01 00:00:00"){
  93. $response[$i]['Subtotal1']=$Subtotal;
  94. }
  95. }
  96. }
  97. $query = "SELECT distinct t2.ShippedDate, (sum(t1.UnitPrice * t1.Quantity * (1 - t1.Discount))*0.8 - 50) as Subtotal from `Order Details` t1 left join Orders t2 on (t1.OrderID=t2.OrderID) where t2.EmployeeID=".$_GET['employeeid2']." and t2.ShippedDate between date('1997-01-01') and date('1997-12-31') GROUP BY YEAR(t2.ShippedDate), MONTH(t2.ShippedDate) ASC";
  98. $result = $mysqli->prepare($query);
  99. $result->execute();
  100. $result->bind_result( $OrderDate, $Subtotal);
  101. while ($result->fetch())
  102. {
  103. for($i=0; $i<13; $i++){
  104. if($response[$i]['OrderDate']==substr($OrderDate, 0, -11)."01 00:00:00"){
  105. $response[$i]['Subtotal2']=$Subtotal;
  106. }
  107. }
  108. }
  109. array_shift($response);
  110. break;
  111. case 'salarygridchart':
  112. for($i=0; $i<13; $i++){
  113. $month = $i<10 ? "0".$i : $i;
  114. $response[] = array(
  115. 'OrderDate' => "1997-".$month."-01 00:00:00",
  116. 'Subtotal1' => 0,
  117. 'Subtotal2' => 0);
  118. }
  119. $query = "SELECT distinct t2.ShippedDate, sum(t1.UnitPrice * t1.Quantity * (1 - t1.Discount))*0.2 as Subtotal from `Order Details` t1 left join Orders t2 on (t1.OrderID=t2.OrderID) where t2.EmployeeID=".$_GET['employeeid1']." and t2.ShippedDate between date('1997-01-01') and date('1997-12-31') GROUP BY YEAR(t2.ShippedDate), MONTH(t2.ShippedDate) ASC";
  120. $result = $mysqli->prepare($query);
  121. $result->execute();
  122. $result->bind_result($OrderDate, $Subtotal);
  123. while ($result->fetch())
  124. {
  125. for($i=0; $i<13; $i++){
  126. if($response[$i]['OrderDate']==substr($OrderDate, 0, -11)."01 00:00:00"){
  127. $response[$i]['Subtotal1']=$Subtotal;
  128. }
  129. }
  130. }
  131. $query = "SELECT distinct t2.ShippedDate, sum(t1.UnitPrice * t1.Quantity * (1 - t1.Discount))*0.2 as Subtotal from `Order Details` t1 left join Orders t2 on (t1.OrderID=t2.OrderID) where t2.EmployeeID=".$_GET['employeeid2']." and t2.ShippedDate between date('1997-01-01') and date('1997-12-31') GROUP BY YEAR(t2.ShippedDate), MONTH(t2.ShippedDate) ASC";
  132. $result = $mysqli->prepare($query);
  133. $result->execute();
  134. $result->bind_result( $OrderDate, $Subtotal);
  135. while ($result->fetch())
  136. {
  137. for($i=0; $i<13; $i++){
  138. if($response[$i]['OrderDate']==substr($OrderDate, 0, -11)."01 00:00:00"){
  139. $response[$i]['Subtotal2']=$Subtotal;
  140. }
  141. }
  142. }
  143. array_shift($response);
  144. break;
  145. case 'yearcomparisonchart':
  146. for($i=0; $i<3; $i++){
  147. $month = $i<10 ? "0".$i : $i;
  148. $response[] = array(
  149. 'OrderDate' => (1996 + $i)."-01-01 00:00:00",
  150. 'Subtotal1' => 0,
  151. 'Subtotal2' => 0);
  152. }
  153. $query = "SELECT distinct t2.ShippedDate, sum(t1.UnitPrice * t1.Quantity * (1 - t1.Discount)) as Subtotal from `Order Details` t1 left join Orders t2 on (t1.OrderID=t2.OrderID) where t2.EmployeeID=".$_GET['employeeid1']." GROUP BY YEAR(t2.ShippedDate) ASC";
  154. $result = $mysqli->prepare($query);
  155. $result->execute();
  156. $result->bind_result($OrderDate, $Subtotal);
  157. while ($result->fetch())
  158. {
  159. for($i=0; $i<3; $i++){
  160. if($response[$i]['OrderDate']==substr($OrderDate, 0, -14)."01-01 00:00:00"){
  161. $response[$i]['Subtotal1']=$Subtotal;
  162. }
  163. }
  164. }
  165. $query = "SELECT distinct t2.ShippedDate, sum(t1.UnitPrice * t1.Quantity * (1 - t1.Discount)) as Subtotal from `Order Details` t1 left join Orders t2 on (t1.OrderID=t2.OrderID) where t2.EmployeeID=".$_GET['employeeid2']." GROUP BY YEAR(t2.ShippedDate) ASC";
  166. $result = $mysqli->prepare($query);
  167. $result->execute();
  168. $result->bind_result( $OrderDate, $Subtotal);
  169. while ($result->fetch())
  170. {
  171. for($i=0; $i<3; $i++){
  172. if($response[$i]['OrderDate']==substr($OrderDate, 0, -14)."01-01 00:00:00"){
  173. $response[$i]['Subtotal2']=$Subtotal;
  174. }
  175. }
  176. }
  177. break;
  178. default:
  179. trigger_error("Missing/Invalid category", E_USER_ERROR);
  180. }
  181. echo json_encode($response);
  182. ?>