PageRenderTime 52ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/p078_dealerd1/p077_DealLog1/GSM_Main/GSM_Grid/ajax/Work_In_Progress_Stats.php

https://bitbucket.org/rlm3/rlm3_staging
PHP | 1379 lines | 1209 code | 150 blank | 20 comment | 127 complexity | c98db197fdd20a288eebddc9ef9f4133 MD5 | raw file
Possible License(s): MPL-2.0-no-copyleft-exception, GPL-2.0, BSD-3-Clause, GPL-3.0, LGPL-2.1

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. include_once ($_SERVER['DOCUMENT_ROOT']."/p093_includes/bootstrap.php");
  3. include_once('../include/functions.php');
  4. $grid = new GSM\Grid($_REQUEST);
  5. $departments = $grid->getDepartments();
  6. $departmentNames = $grid->getDepartmentsNames();
  7. $dptWhere = $db->prepareQuery("`dpt`.`cDepartment_ID` IN (%%1)", $grid->getDepartmentsIds());
  8. $data = array();
  9. $data['Recon Cars'] = array_fill_keys($departmentNames, 0);
  10. $data['Stock Cars'] = array_fill_keys($departmentNames, 0);
  11. $data['Deal Situation'] = array_fill_keys($departmentNames, 0);
  12. $data['Orphans (Net) >30min'] = array_fill_keys($departmentNames, 0);
  13. $data['Orphans >1hr'] = array_fill_keys($departmentNames, 0);
  14. $data['Orphans >16hrs'] = array_fill_keys($departmentNames, 0);
  15. $data['Internet Escalated'] = array_fill_keys($departmentNames, 0);
  16. $data['Lost >1day'] = array_fill_keys($departmentNames, 0);
  17. $data['Recon Current'] = array_fill_keys($departmentNames, 0);
  18. $data['Avg Sales Days'] = array_fill_keys($departmentNames, 0);
  19. $data['Wholesale < 10 Days'] = array_fill_keys($departmentNames, 0);
  20. $data['Wholesale 11 - 20 Days'] = array_fill_keys($departmentNames, 0);
  21. $data['Wholesale > 20 Days'] = array_fill_keys($departmentNames, 0);
  22. $data['Deliveries Today'] = array_fill_keys($departmentNames, array('Today' => 0, 'Yesterday' => 0, 'DayBefore' => 0));
  23. $data['Sales2Service Handover'] = array_fill_keys($departmentNames, array('Y' => 0, 'All' => 0));
  24. $data['Call Center Penetration'] = array_fill_keys($departmentNames, array('Surveyed' => 0, 'Total' => 0));
  25. $data['NPS'] = array_fill_keys($departmentNames, array('Promoters' => 0, 'Detractors' => 0, 'Total' => 0));
  26. $data['Parts Not Fitted on Delivery (Outstanding)'] = array_fill_keys($departmentNames, 0);
  27. $data['Parts Not Fitted on Delivery (Booked)'] = array_fill_keys($departmentNames, 0);
  28. $data['Target Gross'] = array_fill_keys($departmentNames, 0);
  29. $data['Target Units'] = array_fill_keys($departmentNames, 0);
  30. $data['Weekly Dots Gross'] = array_fill_keys($departmentNames, 0);
  31. $data['Weekly Dots Units'] = array_fill_keys($departmentNames, 0);
  32. $data['ITU (Individual)'] = array_fill_keys($departmentNames, 0);
  33. $data['Total Completed'] = array_fill_keys($departmentNames, 0);
  34. $data['Total Scheduled'] = array_fill_keys($departmentNames, 0);
  35. $data['Total Waiting Manager Approval'] = array_fill_keys($departmentNames, 0);
  36. $data['Total Waiting HR Approval'] = array_fill_keys($departmentNames, 0);
  37. $today = $grid->getToday();
  38. $yesterday = $grid->getYesterday();
  39. $daybefore = $grid->getDayBeforeYesterday();
  40. /* Recon Cars */
  41. $sql = "SELECT `dpt`.`Short_Desc`,
  42. `dpt`.`DMS_DPT_Code`,
  43. COUNT(*) as `Count`
  44. FROM `p133_Recon` `r`
  45. INNER JOIN `p133_Recon_Status` `rs` ON `rs`.`Recon_Stat_Code` = `r`.`p133_Recon_Status`
  46. INNER JOIN `p109_Veh_Stk` `veh` ON `veh`.`p109_STKNO` = `r`.`p133_Stock_no`
  47. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `r`.`p133_cDepartment_Sales` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y'
  48. WHERE (`rs`.`Is_Current` = 'Y' OR (`r`.`p133_Recon_Status` = 'Instock' AND `veh`.`Status` < 90)) AND `r`.`p133_Stock_Car` = 'N' AND `rs`.`p133_Recon_Time_Count_As_ID` = 1
  49. GROUP BY `r`.`p133_cDepartment_Sales`";
  50. $db->query($sql);
  51. while ($row = $db->fetchRow())
  52. {
  53. if (isset($data['Recon Cars'][$row['Short_Desc']]))
  54. {
  55. $data['Recon Cars'][$row['Short_Desc']] = $row['Count'];
  56. }
  57. }
  58. /* Stock Cars */
  59. $sql = "SELECT `dpt`.`Short_Desc`,
  60. `dpt`.`DMS_DPT_Code`,
  61. COUNT(*) as `Count`
  62. FROM `p133_Recon` `r`
  63. INNER JOIN `p133_Recon_Status` `rs` ON `rs`.`Recon_Stat_Code` = `r`.`p133_Recon_Status`
  64. INNER JOIN `p109_Veh_Stk` `veh` ON `veh`.`p109_STKNO` = `r`.`p133_Stock_no`
  65. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `r`.`p133_cDepartment_Sales` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y'
  66. WHERE (`rs`.`Is_Current` = 'Y' OR (`r`.`p133_Recon_Status` = 'Instock' AND `veh`.`Status` < 90)) AND `r`.`p133_Stock_Car` = 'Y' AND `rs`.`p133_Recon_Time_Count_As_ID` = 1
  67. GROUP BY `r`.`p133_cDepartment_Sales`";
  68. $db->query($sql);
  69. while ($row = $db->fetchRow())
  70. {
  71. if (isset($data['Stock Cars'][$row['Short_Desc']]))
  72. {
  73. $data['Stock Cars'][$row['Short_Desc']] = $row['Count'];
  74. }
  75. }
  76. /* Deal Situation Cars */
  77. $where = "`d`.`SM_Delivery_Month` = '{$_REQUEST['period']}'";
  78. $sql = "SELECT `dpt`.`Short_Desc`,
  79. `dpt`.`DMS_DPT_Code`,
  80. COUNT(*) as `Count`
  81. FROM `p077_Deal_Log` `d`
  82. INNER JOIN `p077_Deal_Situation_Status` `dss` ON `dss`.`Deal_Situation_Status` = `d`.`p077_Deal_Situation`
  83. INNER JOIN `p109_Veh_Stk` `vs` ON `vs`.`p109_STKNO` = `d`.`p077_Stock_Num`
  84. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `d`.`p077_DPTID` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y'
  85. WHERE $where
  86. GROUP BY `dpt`.`DMS_DPT_Code`";
  87. $db->query($sql);
  88. while ($row = $db->fetchRow())
  89. {
  90. if (isset($data['Deal Situation'][$row['Short_Desc']]))
  91. {
  92. $data['Deal Situation'][$row['Short_Desc']] = $row['Count'];
  93. }
  94. }
  95. /* Orphans >1hr */
  96. $sql = "SELECT `dpt`.`Short_Desc`,
  97. `l`.`L_Day`,
  98. `l`.`p108_Lead_Type_ID`
  99. FROM `p108_Leads` `l`
  100. INNER JOIN `cDepartment` `dpt` ON (`dpt`.`cDepartment_ID` = `l`.`L_cDepartment_ID` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y')
  101. WHERE `l`.`p108_Lead_Status_ID` = '1'";
  102. $db->query($sql);
  103. while ($row = $db->fetchRow())
  104. {
  105. $hours = (time() - strtotime($row['L_Day'])) / 3600;
  106. $minutes = $hours - (int) $hours;
  107. if ($minutes < 0.5)
  108. {
  109. $hours = floor($hours);
  110. }
  111. if (isset($data['Orphans >1hr'][$row['Short_Desc']]) && $hours >= 1)
  112. {
  113. $data['Orphans >1hr'][$row['Short_Desc']]++;
  114. }
  115. if (isset($data['Orphans >16hrs'][$row['Short_Desc']]) && $hours >= 16)
  116. {
  117. $data['Orphans >16hrs'][$row['Short_Desc']]++;
  118. }
  119. if (isset($data['Orphans (Net) >30min'][$row['Short_Desc']]) && $hours >= 0.5 && $row['p108_Lead_Type_ID'] == 3)
  120. {
  121. $data['Orphans (Net) >30min'][$row['Short_Desc']]++;
  122. }
  123. }
  124. /* Internet Escalated */
  125. $sql = "SELECT `dpt`.`Short_Desc`,
  126. `l`.`p108_Lead_Type_ID`,
  127. COUNT(*) as `Count`
  128. FROM `p108_Leads` `l`
  129. INNER JOIN `cDepartment` `dpt` ON (`dpt`.`cDepartment_ID` = `l`.`L_cDepartment_ID` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y')
  130. WHERE DATE(`l`.`L_Day`) = CURDATE() AND `l`.`Escalation_SMS` = 'Y' AND `l`.`p108_Lead_Type_ID` = 3
  131. GROUP BY `l`.`L_cDepartment_ID`";
  132. $db->query($sql);
  133. while ($row = $db->fetchRow())
  134. {
  135. $data['Internet Escalated'][$row['Short_Desc']] = $row['Count'];
  136. }
  137. $lostDays = 1;
  138. if (Date::format('D') == 'Mon')
  139. {
  140. $lostDays = 3;
  141. }
  142. /* Lost >1day */
  143. $sql = "SELECT `dpt`.`Short_Desc`,
  144. SUM(DATEDIFF(NOW(), `l`.`L_Day`) > $lostDays) as `Days`
  145. FROM `p108_Leads` `l`
  146. INNER JOIN `cDepartment` `dpt` ON (`dpt`.`cDepartment_ID` = `l`.`L_cDepartment_ID` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y')
  147. WHERE `l`.`p108_Lead_Status_ID` = '11'
  148. GROUP BY `l`.`L_cDepartment_ID`";
  149. $db->query($sql);
  150. while ($row = $db->fetchRow())
  151. {
  152. if (isset($data["Lost >$lostDays day"][$row['Short_Desc']]))
  153. {
  154. $data["Lost >$lostDays day"][$row['Short_Desc']] = $row['Days'];
  155. }
  156. }
  157. /* Avg Sales Days */
  158. $sql = "SELECT SUM(`rdl`.`Status_Days_Adjusted`) as `Days`,
  159. `dpt`.`Short_Desc`,
  160. COUNT(DISTINCT `r`.`p133_Recon_ID`) as `Count`
  161. FROM `p133_Recon` `r`
  162. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `r`.`p133_cDepartment_Sales` AND $dptWhere AND `dpt`.`Dpt_Active` = 'Y'
  163. INNER JOIN `p133_Recon_Days_Log` `rdl` ON `rdl`.`Recon_Master_Log_ID` = `r`.`p133_Recon_ID`
  164. INNER JOIN `p133_Recon_Status` `rs` ON `r`.`p133_Recon_Status` = `rs`.`Recon_Stat_Code`
  165. INNER JOIN `M012_Tasks` `t` ON `t`.`M012_Task_Driver_Parm5` = `r`.`p133_Stock_no`
  166. WHERE `rs`.`p133_Recon_Status_ID` = '6' AND `t`.`M012_Task_Type` = 'Used Recon' AND `rs`.`Is_Recon` = 'Y' AND `r`.`p133_Stock_Car` = 'N'
  167. AND DATE_FORMAT(`r`.`p133_Recon_Completed`, '%Y-%m-01') = DATE_FORMAT('{$_REQUEST['period']}', '%Y-%m-01')
  168. GROUP BY `r`.`p133_cDepartment_Sales`";
  169. $db->query($sql);
  170. while ($row = $db->fetchRow())
  171. {
  172. if (empty($data['Avg Sales Days'][$row['Short_Desc']]))
  173. {
  174. $data['Avg Sales Days'][$row['Short_Desc']] = array('Count' => 0, 'Days' => 0);
  175. }
  176. $data['Avg Sales Days'][$row['Short_Desc']]['Count'] = $row['Count'];
  177. $data['Avg Sales Days'][$row['Short_Desc']]['Days'] = $row['Days'];
  178. }
  179. /* Recon Current */
  180. $sql = "SELECT SUM(`rdl`.`Status_Days_Adjusted`) as `Days`,
  181. `dpt`.`Short_Desc`,
  182. `rtca`.`p133_Recon_Time_Count_As_ID`,
  183. `rtca`.`p133_Target`,
  184. `r`.`p133_Recon_ID`,
  185. `r`.`p133_Stock_no`
  186. FROM `p133_Recon` `r`
  187. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `r`.`p133_cDepartment_Sales` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y'
  188. INNER JOIN `p133_Recon_Days_Log` `rdl` ON `rdl`.`Recon_Master_Log_ID` = `r`.`p133_Recon_ID`
  189. INNER JOIN `p133_Recon_Time_Count_As` `rtca` ON `rtca`.`p133_Recon_Time_Count_As_ID` = `rdl`.`p133_Recon_Time_Count_As_ID`
  190. INNER JOIN `p133_Recon_Status` `rs` ON `r`.`p133_Recon_Status` = `rs`.`Recon_Stat_Code`
  191. INNER JOIN `M012_Tasks` `t` ON `t`.`M012_Task_Driver_Parm5` = `r`.`p133_Stock_no`
  192. WHERE `rs`.`p133_Recon_Status_ID` = '6' AND `t`.`M012_Task_Type` = 'Used Recon' AND `rs`.`Is_Recon` = 'Y' AND `r`.`p133_Stock_Car` = 'N'
  193. AND DATE_FORMAT(`r`.`p133_Recon_Completed`, '%Y-%m-01') = DATE_FORMAT('{$_REQUEST['period']}', '%Y-%m-01')
  194. GROUP BY `r`.`p133_Recon_ID`, `rtca`.`p133_Recon_Time_Count_As_ID`
  195. HAVING `Days` > `rtca`.`p133_Target`";
  196. $sql = "SELECT * FROM ($sql) t
  197. GROUP BY `t`.`p133_Recon_ID`";
  198. $db->query($sql);
  199. while ($row = $db->fetchRow())
  200. {
  201. $data['Recon Current'][$row['Short_Desc']]++;
  202. }
  203. /* Wholesale */
  204. $sql = "SELECT `dpt`.`Short_Desc`,
  205. DATEDIFF(NOW(), `vehs`.`IntoStock_Date`) as `Days`
  206. FROM `p109_Veh_Stk` `vehs`
  207. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `vehs`.`Dept` AND `dpt`.`Dpt_Active` = 'Y'
  208. WHERE `vehs`.`Dept` IN (180, 380) AND `vehs`.`On_Order` = 'N'";
  209. $db->query($sql);
  210. while ($row = $db->fetchRow())
  211. {
  212. if ($row['Days'] < 10)
  213. {
  214. $data['Wholesale < 10 Days'][$row['Short_Desc']]++;
  215. }
  216. elseif ($row['Days'] >= 10 && $row['Days'] < 20)
  217. {
  218. $data['Wholesale 11 - 20 Days'][$row['Short_Desc']]++;
  219. }
  220. elseif ($row['Days'] >= 20)
  221. {
  222. $data['Wholesale > 20 Days'][$row['Short_Desc']]++;
  223. }
  224. }
  225. /* Deliveries Today */
  226. $sql = "SELECT `dpt`.`Short_Desc`,
  227. SUM(DATE(`d`.`Cust_Handover_Date`) = '%%1') AS `Today`,
  228. SUM(DATE(`d`.`Cust_Handover_Date`) = '%%2') AS `Yesterday`,
  229. SUM(DATE(`d`.`Cust_Handover_Date`) = '%%3') AS `DayBefore`
  230. FROM `p077_Deal_Log` `d`
  231. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `d`.`p077_DPTID` AND `dpt`.`Department_Types_ID` = 1 AND `sale_cat` = 'R' AND `dpt`.`Dpt_Active` = 'Y'
  232. GROUP BY `d`.`p077_DPTID`";
  233. $db->query($sql, $today, $yesterday, $daybefore);
  234. while ($row = $db->fetchRow())
  235. {
  236. $data['Deliveries Today'][$row['Short_Desc']]['Today'] = $row['Today'];
  237. $data['Deliveries Today'][$row['Short_Desc']]['Yesterday'] = $row['Yesterday'];
  238. $data['Deliveries Today'][$row['Short_Desc']]['DayBefore'] = $row['DayBefore'];
  239. }
  240. /* Sales2Service Handover */
  241. $sql = "SELECT `dpt`.`Short_Desc`,
  242. SUM(`d`.`STS_Handover` = 'Y') as `Y`,
  243. SUM(`d`.`STS_Handover` IN ('Y', 'N', 'DOS', 'NS')) as `All`
  244. FROM `p077_Deal_Log` `d`
  245. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `d`.`p077_DPTID` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y'
  246. WHERE DATE(`d`.`Cust_Handover_Date`) = CURDATE()
  247. GROUP BY `d`.`p077_DPTID`";
  248. $db->query($sql);
  249. while ($row = $db->fetchRow())
  250. {
  251. $data['Sales2Service Handover'][$row['Short_Desc']]['Y'] = $row['Today'];
  252. $data['Sales2Service Handover'][$row['Short_Desc']]['All'] = $row['All'];
  253. }
  254. /* Call Center Penetration */
  255. $sql = "SELECT SUM(`nm`.`p101_NPS_Score` BETWEEN 9 AND 10) as `Promoters`,
  256. SUM(`nm`.`p101_NPS_Score` BETWEEN 7 AND 8) as `Passives`,
  257. SUM(`nm`.`p101_NPS_Score` BETWEEN 0 AND 6) as `Detractors`,
  258. COUNT(*) as `Total`,
  259. `dpt`.`Short_Desc`
  260. FROM `p101_NPS_Master` nm
  261. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `nm`.`p101_AOC2` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y'
  262. WHERE DATE_FORMAT(`nm`.`p101_Interaction_Date`, '%Y-%m-01') = '%%1' AND `nm`.`p101_AOC1` = 'Sales'
  263. GROUP BY `dpt`.`DMS_DPT_Code`";
  264. $db->query($sql, $_REQUEST['period']);
  265. while ($row = $db->fetchRow())
  266. {
  267. $data['Call Center Penetration'][$row['Short_Desc']]['Surveyed'] = $row['Promoters'] + $row['Passives'] + $row['Detractors'];
  268. $data['Call Center Penetration'][$row['Short_Desc']]['Total'] = $row['Total'];
  269. }
  270. /* NPS */
  271. $sql = "SELECT SUM(`nm`.`p101_NPS_Score` BETWEEN 9 AND 10) as `Promoters`,
  272. SUM(`nm`.`p101_NPS_Score` BETWEEN 0 AND 6) as `Detractors`,
  273. SUM(`nm`.`p101_NPS_Score` > -1) as `Total`,
  274. `dpt`.`Short_Desc`
  275. FROM `p101_NPS_Master` nm
  276. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `nm`.`p101_AOC2` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y'
  277. WHERE DATE(`nm`.`p101_Surveyed`) = CURDATE() AND `nm`.`p101_AOC1` = 'Sales' AND `nm`.`p101_NPS_Status` = 'Completed'
  278. GROUP BY `dpt`.`DMS_DPT_Code`";
  279. $db->query($sql);
  280. while ($row = $db->fetchRow())
  281. {
  282. $data['NPS'][$row['Short_Desc']]['Promoters'] = $row['Promoters'];
  283. $data['NPS'][$row['Short_Desc']]['Detractors'] = $row['Detractors'];
  284. $data['NPS'][$row['Short_Desc']]['Total'] = $row['Total'];
  285. }
  286. /* Parts Not Fitted on Delivery (Outstanding) */
  287. $sql = "SELECT `dpt`.`Short_Desc`,
  288. `dpt`.`DMS_DPT_Code`
  289. FROM `p077_Deal_Log` `d`
  290. INNER JOIN `p077_Deal_DET` `det` ON `det`.`p077_Deal_Log_ID` = `d`.`p077_Deal_Log_ID`
  291. INNER JOIN `p109_Veh_Stk` `veh` ON `veh`.`p109_STKNO` = `d`.`p077_Stock_Num`
  292. INNER JOIN `p077_Deal_PNFD_Status` `pnfds` USING(`p077_Deal_PNFD_Status_ID`)
  293. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `d`.`p077_DPTID` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y'
  294. WHERE `pnfds`.`p077_PNFD_Completed_Status` = 'N' AND `pnfds`.`p077_Deal_PNFD_Status_ID` <> 4
  295. GROUP BY `d`.`p077_Deal_Log_ID`";
  296. $sql = "SELECT *,
  297. COUNT(*) as `Count`
  298. FROM ($sql) t
  299. GROUP BY `t`.`DMS_DPT_Code`";
  300. $db->query($sql);
  301. while ($row = $db->fetchRow())
  302. {
  303. if (isset($data['Parts Not Fitted on Delivery (Outstanding)'][$row['Short_Desc']]))
  304. {
  305. $data['Parts Not Fitted on Delivery (Outstanding)'][$row['Short_Desc']] = $row['Count'];
  306. }
  307. }
  308. /* Parts Not Fitted on Delivery (Booked) */
  309. $sql = "SELECT `dpt`.`Short_Desc`,
  310. `dpt`.`DMS_DPT_Code`
  311. FROM `p077_Deal_Log` `d`
  312. INNER JOIN `p077_Deal_DET` `det` ON `det`.`p077_Deal_Log_ID` = `d`.`p077_Deal_Log_ID`
  313. INNER JOIN `p109_Veh_Stk` `veh` ON `veh`.`p109_STKNO` = `d`.`p077_Stock_Num`
  314. INNER JOIN `p077_Deal_PNFD_Status` `pnfds` USING(`p077_Deal_PNFD_Status_ID`)
  315. INNER JOIN `cDepartment` `dpt` ON `dpt`.`DMS_DPT_Code` = `d`.`p077_DPTID` AND `dpt`.`Department_Types_ID` = 1 AND `dpt`.`Dpt_Active` = 'Y'
  316. WHERE `pnfds`.`p077_Deal_PNFD_Status_ID` = 4
  317. GROUP BY `d`.`p077_Deal_Log_ID`";
  318. $sql = "SELECT *,
  319. COUNT(*) as `Count`
  320. FROM ($sql) t
  321. GROUP BY `t`.`DMS_DPT_Code`";
  322. $db->query($sql);
  323. while ($row = $db->fetchRow())
  324. {
  325. if (isset($data['Parts Not Fitted on Delivery (Booked)'][$row['Short_Desc']]))
  326. {
  327. $data['Parts Not Fitted on Delivery (Booked)'][$row['Short_Desc']] = $row['Count'];
  328. }
  329. }
  330. /* Target Gross */
  331. $exportCodes = array();
  332. foreach($departments as $department)
  333. {
  334. $exportCodes[] = "DL\\\\DB\\\\SM\\\\{$department->DMS_DPT_Code}\\\\Target\\\\TOT_EX_FI";
  335. }
  336. $exportCodes = implode("', '", $exportCodes);
  337. $sql = "SELECT * FROM `b005_MSTDET_Share`
  338. WHERE `b005_CODE` IN ('$exportCodes') AND DATE_FORMAT(`ASAT`, '%Y-%m-01') = '%%1'";
  339. $db->query($sql, $_REQUEST['period']);
  340. while ($row = $db->fetchRow())
  341. {
  342. $b005_CODE = $row['b005_CODE'];
  343. $DMS_DPT_Code = substr(substr($b005_CODE, 9), 0, -17);
  344. $Short_Desc = $departments[$DMS_DPT_Code]->Short_Desc;
  345. $data['Target Gross'][$Short_Desc] = $row['Result'];
  346. }
  347. /* Target Units */
  348. $exportCodes = array();
  349. foreach($departments as $department)
  350. {
  351. $exportCodes[] = "DL\\\\DB\\\\SM\\\\{$department->DMS_DPT_Code}\\\\Target\\\\DelTarget";
  352. }
  353. $exportCodes = implode("', '", $exportCodes);
  354. $sql = "SELECT * FROM `b005_MSTDET_Share`
  355. WHERE `b005_CODE` IN ('$exportCodes') AND DATE_FORMAT(`ASAT`, '%Y-%m-01') = '%%1'";
  356. $db->query($sql, $_REQUEST['period']);
  357. while ($row = $db->fetchRow())
  358. {
  359. $b005_CODE = $row['b005_CODE'];
  360. $DMS_DPT_Code = substr(substr($b005_CODE, 9), 0, -17);
  361. $Short_Desc = $departments[$DMS_DPT_Code]->Short_Desc;
  362. $data['Target Units'][$Short_Desc] = $row['Result'];
  363. }
  364. /* Weekly Dots Gross */
  365. $exportCodes = array();
  366. foreach($departments as $department)
  367. {
  368. $exportCodes[] = "DL\\\\DB\\\\DPT\\\\{$department->DMS_DPT_Code}\\\\Dots\\\\Week1\\\\TOT_EX_FI";
  369. $exportCodes[] = "DL\\\\DB\\\\DPT\\\\{$department->DMS_DPT_Code}\\\\Dots\\\\Week2\\\\TOT_EX_FI";
  370. $exportCodes[] = "DL\\\\DB\\\\DPT\\\\{$department->DMS_DPT_Code}\\\\Dots\\\\Week3\\\\TOT_EX_FI";
  371. $exportCodes[] = "DL\\\\DB\\\\DPT\\\\{$department->DMS_DPT_Code}\\\\Dots\\\\Week4\\\\TOT_EX_FI";
  372. }
  373. $exportCodes = implode("', '", $exportCodes);
  374. $sql = "SELECT * FROM `b005_MSTDET_Share`
  375. WHERE `b005_CODE` IN ('$exportCodes') AND DATE_FORMAT(`ASAT`, '%Y-%m-01') = '%%1'";
  376. $db->query($sql, $_REQUEST['period']);
  377. while ($row = $db->fetchRow())
  378. {
  379. $b005_CODE = $row['b005_CODE'];
  380. $tokens = explode('\\', $b005_CODE);
  381. $DMS_DPT_Code = $tokens[3];
  382. $Short_Desc = $departments[$DMS_DPT_Code]->Short_Desc;
  383. $data['Weekly Dots Gross'][$Short_Desc] += $row['Result'];
  384. }
  385. /* Weekly Dots Units */
  386. $exportCodes = array();
  387. foreach($departments as $department)
  388. {
  389. $exportCodes[] = "DL\\\\DB\\\\DPT\\\\{$department->DMS_DPT_Code}\\\\Dots\\\\Week1\\\\DelTarget";
  390. $exportCodes[] = "DL\\\\DB\\\\DPT\\\\{$department->DMS_DPT_Code}\\\\Dots\\\\Week2\\\\DelTarget";
  391. $exportCodes[] = "DL\\\\DB\\\\DPT\\\\{$department->DMS_DPT_Code}\\\\Dots\\\\Week3\\\\DelTarget";
  392. $exportCodes[] = "DL\\\\DB\\\\DPT\\\\{$department->DMS_DPT_Code}\\\\Dots\\\\Week4\\\\DelTarget";
  393. }
  394. $exportCodes = implode("', '", $exportCodes);
  395. $sql = "SELECT * FROM `b005_MSTDET_Share`
  396. WHERE `b005_CODE` IN ('$exportCodes') AND DATE_FORMAT(`ASAT`, '%Y-%m-01') = '%%1'";
  397. $db->query($sql, $_REQUEST['period']);
  398. while ($row = $db->fetchRow())
  399. {
  400. $b005_CODE = $row['b005_CODE'];
  401. $tokens = explode('\\', $b005_CODE);
  402. $DMS_DPT_Code = $tokens[3];
  403. $Short_Desc = $departments[$DMS_DPT_Code]->Short_Desc;
  404. $data['Weekly Dots Units'][$Short_Desc] += $row['Result'];
  405. }
  406. /* ITU (Individual) */
  407. $departmentCodes = implode("', '", array_keys($departments));
  408. $sql = "SELECT `p`.`cPeople_ID`,
  409. `p`.`SLMID`,
  410. `dpt`.`DMS_DPT_Code`
  411. FROM `cPeople` `p`
  412. INNER JOIN `cDepartment` `dpt` ON `dpt`.`cDepartment_ID` = `p`.`cDepartment` AND `dpt`.`Dpt_Active` = 'Y'
  413. WHERE `p`.`Active` <> 0 AND `dpt`.`DMS_DPT_Code` IN ('$departmentCodes')
  414. ORDER BY `p`.`cPeople_ID` ASC";
  415. $db->query($sql);
  416. $peopleDepartments = array();
  417. $shareCodes = array();
  418. while ($row = $db->fetchRow())
  419. {
  420. $shareCodes[] = "DL\\\\DB\\\\SM\\\\{$row['SLMID']}\\\\Target\\\\DelTarget";
  421. $peopleDepartments[$row['SLMID']] = $row['DMS_DPT_Code'];
  422. }
  423. $shareCodes = implode("', '", $shareCodes);
  424. $sql = "SELECT * FROM `b005_MSTDET_Share`
  425. WHERE `b005_CODE` IN ('$shareCodes') AND DATE_FORMAT(`ASAT`, '%Y-%m-01') = '%%1'";
  426. $db->query($sql, $_REQUEST['period']);
  427. while ($row = $db->fetchRow())
  428. {
  429. $b005_CODE = $row['b005_CODE'];
  430. $SLMID = substr(substr($b005_CODE, 9), 0, -17);
  431. $DMS_DPT_Code = $peopleDepartments[$SLMID];
  432. $Short_Desc = $departments[$DMS_DPT_Code]->Short_Desc;
  433. if (!isset($data['ITU (Individual)'][$Short_Desc]))
  434. {
  435. $data['ITU (Individual)'][$Short_Desc] = 0;
  436. }
  437. $data['ITU (Individual)'][$Short_Desc] += $row['Result'];
  438. }
  439. /* Total Completed */
  440. $sql = "SELECT `dpt`.`Short_Desc`,
  441. SUM(`h`.`completed_date` <> '0000-00-00 00:00:00' AND DATE(`p`.`Review_Due`) >= DATE(NOW())) as `Total_Completed`,
  442. SUM(DATE(`p`.`Review_Due`) > DATE(NOW())) as `Total_Scheduled`,
  443. SUM(`h`.`p115_Status` = 'Completed' AND `h`.`hr_status` = 'Ready') as `Total_Waiting_HR_Approval`,
  444. SUM(`h`.`p115_Status` = 'Completed' AND `h`.`mgrs_mgr_status` = 'Ready') as `Total_Waiting_Manager_Approval`,
  445. COUNT(*) as `Count`
  446. FROM `cDepartment` `dpt`
  447. INNER JOIN `cPeople` `p` ON `p`.`PhoneBook_cDepartment_ID` = `dpt`.`cDepartment_ID`
  448. INNER JOIN `p115_Per_R_Header` `h` ON `h`.`employee_id` = `p`.`cPeople_ID`
  449. WHERE `dpt`.`DMS_DPT_Code` IN ('$departmentCodes') AND `p`.`p115_Include` = 'Y' AND `p`.`Active` <> 0 AND `dpt`.`Show_Per_Review_Summary` = 'Y' AND `dpt`.`Dpt_Active` = 'Y'
  450. GROUP BY `dpt`.`DMS_DPT_Code`";
  451. $db->query($sql);
  452. while ($row = $db->fetchRow())
  453. {
  454. $data['Total Completed'][$row['Short_Desc']] += $row['Total_Completed'];
  455. $data['Total Scheduled'][$row['Short_Desc']] += $row['Total_Scheduled'];
  456. $data['Total Waiting Manager Approval'][$row['Short_Desc']] += $row['Total_Waiting_Manager_Approval'];
  457. $data['Total Waiting HR Approval'][$row['Short_Desc']] += $row['Total_Waiting_HR_Approval'];
  458. }
  459. ?>
  460. <h3>Stats below are Work in Progress</h3>
  461. <table class="list-table highlight-row" cellpadding="0" cellspacing="0" id="sales-departments-table">
  462. <tr>
  463. <th>&nbsp;</th>
  464. <th>Total</th>
  465. <?php foreach ($departments as $department): ?>
  466. <th><?php echo $department->Short_Desc; ?></th>
  467. <?php endforeach ?>
  468. </tr>
  469. <?php $name = 'Orphans (Net) >30min'; $total = 0 ?>
  470. <tr>
  471. <td><?php echo $name; ?></td>
  472. <?php ob_start() ?>
  473. <?php foreach ($departments as $department): ?>
  474. <td class="align-center">
  475. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  476. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  477. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=<?php echo $department->cDepartment_ID; ?>&status=1&salesperson=%40All&leadTypeId=3&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=%40All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  478. <?php else: ?>
  479. &nbsp;
  480. <?php endif ?>
  481. <?php $total += $data[$name][$department->Short_Desc]; ?>
  482. <?php else: ?>
  483. 0
  484. <?php endif ?>
  485. </td>
  486. <?php endforeach ?>
  487. <?php $html = ob_get_clean() ?>
  488. <td class="align-center bold">
  489. <?php if ($total > 0): ?>
  490. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=&status=1&salesperson=%40All&leadTypeId=3&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=%40All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($total, 0); ?></a>
  491. <?php else: ?>
  492. &nbsp;
  493. <?php endif ?>
  494. </td>
  495. <?php echo $html; ?>
  496. </tr>
  497. <?php $name = 'Orphans >1hr'; $total = 0 ?>
  498. <tr>
  499. <td><?php echo $name; ?></td>
  500. <?php ob_start() ?>
  501. <?php foreach ($departments as $department): ?>
  502. <td class="align-center">
  503. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  504. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  505. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=<?php echo $department->cDepartment_ID; ?>&status=1&salesperson=%40All&leadTypeId=&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=%40All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  506. <?php else: ?>
  507. &nbsp;
  508. <?php endif ?>
  509. <?php $total += $data[$name][$department->Short_Desc]; ?>
  510. <?php else: ?>
  511. 0
  512. <?php endif ?>
  513. </td>
  514. <?php endforeach ?>
  515. <?php $html = ob_get_clean() ?>
  516. <td class="align-center bold">
  517. <?php if ($total > 0): ?>
  518. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=&status=1&salesperson=%40All&leadTypeId=&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=%40All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($total, 0); ?></a>
  519. <?php else: ?>
  520. &nbsp;
  521. <?php endif ?>
  522. </td>
  523. <?php echo $html; ?>
  524. </tr>
  525. <?php $name = 'Orphans >16hrs'; $total = 0 ?>
  526. <tr>
  527. <td><?php echo $name; ?></td>
  528. <?php ob_start() ?>
  529. <?php foreach ($departments as $department): ?>
  530. <td class="align-center">
  531. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  532. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  533. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=<?php echo $department->cDepartment_ID; ?>&status=1&salesperson=%40All&leadTypeId=&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=%40All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  534. <?php else: ?>
  535. &nbsp;
  536. <?php endif ?>
  537. <?php $total += $data[$name][$department->Short_Desc]; ?>
  538. <?php else: ?>
  539. 0
  540. <?php endif ?>
  541. </td>
  542. <?php endforeach ?>
  543. <?php $html = ob_get_clean() ?>
  544. <td class="align-center bold">
  545. <?php if ($total > 0): ?>
  546. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=&status=1&salesperson=%40All&leadTypeId=&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=%40All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($total, 0); ?></a>
  547. <?php else: ?>
  548. &nbsp;
  549. <?php endif; ?>
  550. </td>
  551. <?php echo $html; ?>
  552. </tr>
  553. <?php $name = 'Internet Escalated'; $total = 0 ?>
  554. <tr>
  555. <td><?php echo $name; ?></td>
  556. <?php ob_start() ?>
  557. <?php foreach ($departments as $department): ?>
  558. <td class="align-center">
  559. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  560. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  561. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=<?php echo $department->cDepartment_ID; ?>&status=@AllActive&salesperson=@All&leadTypeId=3&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=@All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  562. <?php else: ?>
  563. &nbsp;
  564. <?php endif ?>
  565. <?php $total += $data[$name][$department->Short_Desc]; ?>
  566. <?php else: ?>
  567. 0
  568. <?php endif ?>
  569. </td>
  570. <?php endforeach ?>
  571. <?php $html = ob_get_clean() ?>
  572. <td class="align-center bold">
  573. <?php if ($total > 0): ?>
  574. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=&status=@AllActive&salesperson=@All&leadTypeId=3&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=@All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($total, 0); ?></a>
  575. <?php else: ?>
  576. &nbsp;
  577. <?php endif; ?>
  578. </td>
  579. <?php echo $html; ?>
  580. </tr>
  581. <tr><td colspan="<?php echo count($departments) + 2; ?>">&nbsp;</td></tr>
  582. <?php $name = "Lost >$lostDays day"; $total = 0 ?>
  583. <tr>
  584. <td><?php echo $name; ?></td>
  585. <?php ob_start() ?>
  586. <?php foreach ($departments as $department): ?>
  587. <td class="align-center">
  588. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  589. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  590. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=<?php echo $department->cDepartment_ID; ?>&status=11&salesperson=%40All&leadTypeId=&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=%40All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  591. <?php else: ?>
  592. &nbsp;
  593. <?php endif; ?>
  594. <?php $total += $data[$name][$department->Short_Desc]; ?>
  595. <?php else: ?>
  596. 0
  597. <?php endif ?>
  598. </td>
  599. <?php endforeach ?>
  600. <?php $html = ob_get_clean() ?>
  601. <td class="align-center bold">
  602. <?php if ($total > 0): ?>
  603. <a target="_blank" href="/p078_dealerd1/p108_Lead_Management/Diary/Diary_Log.php?department=&status=11&salesperson=%40All&leadTypeId=&category=&search=&deal=&publication=&mediaType=&campaign=&reminderOn=%40All&dataQ=&from_search=&refund_request=@All"><?php echo number_format($total, 0); ?></a>
  604. <?php else: ?>
  605. &nbsp;
  606. <?php endif ?>
  607. </td>
  608. <?php echo $html; ?>
  609. </tr>
  610. <tr><td colspan="<?php echo count($departments) + 2; ?>">&nbsp;</td></tr>
  611. <?php $name = 'Target Gross'; $total = 0 ?>
  612. <tr>
  613. <td><?php echo $name; ?></td>
  614. <?php ob_start() ?>
  615. <?php foreach ($departments as $department): ?>
  616. <td class="align-center">
  617. <?php if (isset($data[$name][$department->Short_Desc]) && $data[$name][$department->Short_Desc] > 0): ?>
  618. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Targets.php?month=<?php echo $_REQUEST['period']; ?>&department=<?php echo $department->DMS_DPT_Code; ?>">$<?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  619. <?php $total += $data[$name][$department->Short_Desc]; ?>
  620. <?php else: ?>
  621. $0
  622. <?php endif ?>
  623. </td>
  624. <?php endforeach ?>
  625. <?php $html = ob_get_clean() ?>
  626. <td class="align-center bold">
  627. <?php if ($total > 0): ?>
  628. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Targets.php?month=<?php echo $_REQUEST['period']; ?>&department=@All">$<?php echo number_format($total, 0); ?></a>
  629. <?php else: ?>
  630. $0
  631. <?php endif ?>
  632. </td>
  633. <?php echo $html; ?>
  634. </tr>
  635. <?php $name = 'Target Units'; $total = 0 ?>
  636. <tr>
  637. <td><?php echo $name; ?></td>
  638. <?php ob_start() ?>
  639. <?php foreach ($departments as $department): ?>
  640. <td class="align-center">
  641. <?php if (isset($data[$name][$department->Short_Desc]) && $data[$name][$department->Short_Desc] > 0): ?>
  642. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Targets.php?month=<?php echo $_REQUEST['period']; ?>&department=<?php echo $department->DMS_DPT_Code; ?>"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  643. <?php $total += $data[$name][$department->Short_Desc]; ?>
  644. <?php else: ?>
  645. 0
  646. <?php endif ?>
  647. </td>
  648. <?php endforeach ?>
  649. <?php $html = ob_get_clean() ?>
  650. <td class="align-center bold">
  651. <?php if ($total > 0): ?>
  652. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Targets.php?month=<?php echo $_REQUEST['period']; ?>&department=@All"><?php echo number_format($total, 0); ?></a>
  653. <?php else: ?>
  654. 0
  655. <?php endif ?>
  656. </td>
  657. <?php echo $html; ?>
  658. </tr>
  659. <?php $name = 'Weekly Dots Gross'; $total = 0 ?>
  660. <tr>
  661. <td><?php echo $name; ?></td>
  662. <?php ob_start() ?>
  663. <?php foreach ($departments as $department): ?>
  664. <td class="align-center">
  665. <?php if (isset($data[$name][$department->Short_Desc]) && $data[$name][$department->Short_Desc] > 0): ?>
  666. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Weekly_Targets.php?month=<?php echo $_REQUEST['period']; ?>">$<?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  667. <?php $total += $data[$name][$department->Short_Desc]; ?>
  668. <?php else: ?>
  669. $0
  670. <?php endif ?>
  671. </td>
  672. <?php endforeach ?>
  673. <?php $html = ob_get_clean() ?>
  674. <td class="align-center bold">
  675. <?php if ($total > 0): ?>
  676. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Weekly_Targets.php?month=<?php echo $_REQUEST['period']; ?>">$<?php echo number_format($total, 0); ?></a>
  677. <?php else: ?>
  678. $0
  679. <?php endif ?>
  680. </td>
  681. <?php echo $html; ?>
  682. </tr>
  683. <?php $name = 'Weekly Dots Units'; $total = 0 ?>
  684. <tr>
  685. <td><?php echo $name; ?></td>
  686. <?php ob_start() ?>
  687. <?php foreach ($departments as $department): ?>
  688. <td class="align-center">
  689. <?php if (isset($data[$name][$department->Short_Desc]) && $data[$name][$department->Short_Desc] > 0): ?>
  690. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Weekly_Targets.php?month=<?php echo $_REQUEST['period']; ?>"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  691. <?php $total += $data[$name][$department->Short_Desc]; ?>
  692. <?php else: ?>
  693. 0
  694. <?php endif ?>
  695. </td>
  696. <?php endforeach ?>
  697. <?php $html = ob_get_clean() ?>
  698. <td class="align-center bold">
  699. <?php if ($total > 0): ?>
  700. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Weekly_Targets.php?month=<?php echo $_REQUEST['period']; ?>"><?php echo number_format($total, 0); ?></a>
  701. <?php else: ?>
  702. 0
  703. <?php endif ?>
  704. </td>
  705. <?php echo $html; ?>
  706. </tr>
  707. <?php $name = 'ITU (Individual)'; $total = 0 ?>
  708. <tr>
  709. <td><?php echo $name; ?></td>
  710. <?php ob_start() ?>
  711. <?php foreach ($departments as $department): ?>
  712. <td class="align-center">
  713. <?php if (isset($data[$name][$department->Short_Desc]) && $data[$name][$department->Short_Desc] > 0): ?>
  714. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Targets.php?month=<?php echo $_REQUEST['period']; ?>&department=<?php echo $department->DMS_DPT_Code; ?>"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  715. <?php $total += $data[$name][$department->Short_Desc]; ?>
  716. <?php else: ?>
  717. 0
  718. <?php endif ?>
  719. </td>
  720. <?php endforeach ?>
  721. <?php $html = ob_get_clean() ?>
  722. <td class="align-center bold">
  723. <?php if ($total > 0): ?>
  724. <a target="blank" href="/p078_dealerd1/Dashboard1/Sales_Dashboard/Targets.php?month=<?php echo $_REQUEST['period']; ?>&department=@All"><?php echo number_format($total, 0); ?></a>
  725. <?php else: ?>
  726. 0
  727. <?php endif ?>
  728. </td>
  729. <?php echo $html; ?>
  730. </tr>
  731. <?php $name = 'GSM Dashboard'; $total = 0 ?>
  732. <tr>
  733. <td><?php echo $name; ?></td>
  734. <td class="align-center">
  735. [<a target="_blank" href="/p078_dealerd1/Dashboard1/GSM_Dashboard/index.php?month=<?php echo $_REQUEST['period']; ?>&department=@All">Dash</a>]
  736. </td>
  737. <?php foreach ($departments as $department): ?>
  738. <?php $departmentFilter = '@All'; ?>
  739. <?php if (!empty($department->Franchise)): ?>
  740. <?php $departmentFilter = '$Franchise-' . $department->Franchise; ?>
  741. <?php elseif ($department->Location_Group == 'Booval'): ?>
  742. <?php $departmentFilter = '@1' ?>
  743. <?php elseif ($department->Location_Group == 'Laidley'): ?>
  744. <?php $departmentFilter = '@2' ?>
  745. <?php endif ?>
  746. <td class="align-center">
  747. [<a target="_blank" href="/p078_dealerd1/Dashboard1/GSM_Dashboard/index.php?month=<?php echo $_REQUEST['period']; ?>&department=<?php echo $departmentFilter ?>">Dash</a>]
  748. </td>
  749. <?php endforeach ?>
  750. </tr>
  751. <?php $name = 'Deal Situation'; $total = 0 ?>
  752. <tr>
  753. <td><?php echo $name; ?></td>
  754. <?php ob_start() ?>
  755. <?php foreach ($departments as $department): ?>
  756. <td class="align-center">
  757. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  758. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  759. <a target="_blank" href="/p078_dealerd1/p077_DealLog1/PD_Main/Deal_Situation_Overview.php?month=<?php echo $_REQUEST['period']; ?>&category=@All&person=@All&fin_manager=@All&show_for=@All&department=<?php echo $department->DMS_DPT_Code; ?>&reference_no=@Stock"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  760. <?php else: ?>
  761. &nbsp;
  762. <?php endif; ?>
  763. <?php $total += $data[$name][$department->Short_Desc]; ?>
  764. <?php else: ?>
  765. &nbsp;
  766. <?php endif ?>
  767. </td>
  768. <?php endforeach ?>
  769. <?php $html = ob_get_clean() ?>
  770. <td class="align-center bold">
  771. <?php if ($total > 0): ?>
  772. <a target="_blank" href="/p078_dealerd1/p077_DealLog1/PD_Main/Deal_Situation_Overview.php?month=<?php echo $_REQUEST['period']; ?>&category=@All&reference_no=@Stock&person=@All&fin_manager=@All&show_for=@All&department=@All"><?php echo number_format($total, 0); ?></a>
  773. <?php else: ?>
  774. &nbsp;
  775. <?php endif ?>
  776. </td>
  777. <?php echo $html; ?>
  778. </tr>
  779. <tr><td colspan="<?php echo count($departments) + 2; ?>">&nbsp;</td></tr>
  780. <tr><td colspan="<?php echo count($departments) + 2; ?>">&nbsp;</td></tr>
  781. <tr><td colspan="<?php echo count($departments) + 2; ?>">&nbsp;</td></tr>
  782. <?php $name = 'Recon Cars'; $total = 0 ?>
  783. <tr>
  784. <td><?php echo $name; ?></td>
  785. <?php ob_start() ?>
  786. <?php foreach ($departments as $department): ?>
  787. <td class="align-center">
  788. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  789. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  790. <a target="_blank" href="/p078_dealerd1/p1xx/p133_Recon/p133_Recon_Overview.php?view=@All&service_department=@All&stock_car=N&sale_department=<?php echo $department->DMS_DPT_Code; ?>"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  791. <?php else: ?>
  792. &nbsp;
  793. <?php endif ?>
  794. <?php $total += $data[$name][$department->Short_Desc]; ?>
  795. <?php else: ?>
  796. &nbsp;
  797. <?php endif ?>
  798. </td>
  799. <?php endforeach ?>
  800. <?php $html = ob_get_clean() ?>
  801. <td class="align-center bold">
  802. <?php if ($total > 0): ?>
  803. <a target="_blank" href="/p078_dealerd1/p1xx/p133_Recon/p133_Recon_Overview.php?view=@All&service_department=@All&stock_car=N&sale_department=@All"><?php echo number_format($total, 0); ?></a>
  804. <?php else: ?>
  805. &nbsp;
  806. <?php endif ?>
  807. </td>
  808. <?php echo $html; ?>
  809. </tr>
  810. <?php $name = 'Avg Sales Days'; $totals = array('Days' => 0, 'Count' => 0) ?>
  811. <tr>
  812. <td><?php echo $name; ?></td>
  813. <?php ob_start() ?>
  814. <?php foreach ($departments as $department): ?>
  815. <td class="align-center">
  816. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  817. <?php if ($data[$name][$department->Short_Desc]['Days'] > 0): ?>
  818. <a target="_blank" href="/p078_dealerd1/p1xx/p133_Recon/p133_Recon_Trend_days.php?service_department=&show=@All&stock_car=N&sale_department=<?php echo $department->DMS_DPT_Code; ?>"><?php echo number_format($data[$name][$department->Short_Desc]['Days'] / $data[$name][$department->Short_Desc]['Count'], 1); ?></a>
  819. <?php else: ?>
  820. &nbsp;
  821. <?php endif; ?>
  822. <?php $totals['Days'] += $data[$name][$department->Short_Desc]['Days']; $totals['Count'] += $data[$name][$department->Short_Desc]['Count'] ?>
  823. <?php else: ?>
  824. &nbsp;
  825. <?php endif ?>
  826. </td>
  827. <?php endforeach ?>
  828. <?php $html = ob_get_clean() ?>
  829. <td class="align-center bold">
  830. <?php if ($totals['Days'] > 0): ?>
  831. <a target="_blank" href="/p078_dealerd1/p1xx/p133_Recon/p133_Recon_Trend_days.php?service_department=&show=@All&stock_car=N&sale_department=@All"><?php echo number_format($totals['Days'] / $totals['Count'], 1); ?></a>
  832. <?php else: ?>
  833. &nbsp;
  834. <?php endif ?>
  835. </td>
  836. <?php echo $html; ?>
  837. </tr>
  838. <?php $name = 'Recon Current'; $total = 0 ?>
  839. <tr>
  840. <td><?php echo $name; ?></td>
  841. <?php ob_start() ?>
  842. <?php foreach ($departments as $department): ?>
  843. <td class="align-center">
  844. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  845. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  846. <a target="_blank" href="/p078_dealerd1/p1xx/p133_Recon/p133_Recon_Log.php?view=@All&recon_completed=<?php echo $_REQUEST['period']; ?>&recon_status=6&recon_sort=status&sale_department=<?php echo $department->DMS_DPT_Code; ?>&service_department=@All&stock_car=N"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  847. <?php else: ?>
  848. &nbsp;
  849. <?php endif ?>
  850. <?php $total += $data[$name][$department->Short_Desc] ?>
  851. <?php else: ?>
  852. &nbsp;
  853. <?php endif ?>
  854. </td>
  855. <?php endforeach ?>
  856. <?php $html = ob_get_clean() ?>
  857. <td class="align-center bold">
  858. <?php if ($total > 0): ?>
  859. <a target="_blank" href="/p078_dealerd1/p1xx/p133_Recon/p133_Recon_Log.php?view=@All&recon_completed=<?php echo $_REQUEST['period']; ?>&recon_status=6&recon_sort=status&sale_department=@All&service_department=@All&stock_car=N"><?php echo number_format($total, 0); ?></a>
  860. <?php else: ?>
  861. &nbsp;
  862. <?php endif ?>
  863. </td>
  864. <?php echo $html; ?>
  865. </tr>
  866. <?php $name = 'Stock Cars'; $total = 0 ?>
  867. <tr>
  868. <td><?php echo $name; ?></td>
  869. <?php ob_start() ?>
  870. <?php foreach ($departments as $department): ?>
  871. <td class="align-center">
  872. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  873. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  874. <a target="_blank" href="/p078_dealerd1/p1xx/p133_Recon/p133_Recon_Overview.php?view=@All&service_department=@All&stock_car=Y&sale_department=<?php echo $department->DMS_DPT_Code; ?>"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  875. <?php else: ?>
  876. &nbsp;
  877. <?php endif ?>
  878. <?php $total += $data[$name][$department->Short_Desc]; ?>
  879. <?php else: ?>
  880. &nbsp;
  881. <?php endif ?>
  882. </td>
  883. <?php endforeach ?>
  884. <?php $html = ob_get_clean() ?>
  885. <td class="align-center bold">
  886. <?php if ($total > 0): ?>
  887. <a target="_blank" href="/p078_dealerd1/p1xx/p133_Recon/p133_Recon_Overview.php?view=@All&service_department=@All&stock_car=Y&sale_department=@All"><?php echo number_format($total, 0); ?></a>
  888. <?php else: ?>
  889. &nbsp;
  890. <?php endif ?>
  891. </td>
  892. <?php echo $html; ?>
  893. </tr>
  894. <tr><td colspan="<?php echo count($departments) + 2; ?>">&nbsp;</td></tr>
  895. <?php $name = 'Wholesale < 10 Days'; $total = 0 ?>
  896. <tr>
  897. <td><?php echo $name; ?></td>
  898. <?php ob_start() ?>
  899. <?php foreach ($departments as $department): ?>
  900. <td class="align-center">
  901. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  902. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  903. <a target="_blank" href="/p078_dealerd1/p077_DealLog1/SC_Main/SC_Status_Reporting.php?srt=1&department=<?php echo $department->DMS_DPT_Code; ?>&frn=@All&range=@All&colour=@All&sort=1&location=@All&age=@All"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  904. <?php else: ?>
  905. &nbsp;
  906. <?php endif ?>
  907. <?php $total += $data[$name][$department->Short_Desc] ?>
  908. <?php else: ?>
  909. &nbsp;
  910. <?php endif ?>
  911. </td>
  912. <?php endforeach ?>
  913. <?php $html = ob_get_clean() ?>
  914. <td class="align-center bold">
  915. <?php if ($total > 0): ?>
  916. <a target="_blank" href="/p078_dealerd1/p077_DealLog1/SC_Main/SC_Status_Reporting.php?srt=1&department=@All&frn=@All&range=@All&colour=@All&sort=1&location=@All&age=@All"><?php echo number_format($total, 0); ?></a>
  917. <?php else: ?>
  918. &nbsp;
  919. <?php endif ?>
  920. </td>
  921. <?php echo $html; ?>
  922. </tr>
  923. <?php $name = 'Wholesale 11 - 20 Days'; $total = 0 ?>
  924. <tr>
  925. <td><?php echo $name; ?></td>
  926. <?php ob_start() ?>
  927. <?php foreach ($departments as $department): ?>
  928. <td class="align-center">
  929. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  930. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  931. <a target="_blank" href="/p078_dealerd1/p077_DealLog1/SC_Main/SC_Status_Reporting.php?srt=1&department=<?php echo $department->DMS_DPT_Code; ?>&frn=@All&range=@All&colour=@All&sort=1&location=@All&age=@All"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  932. <?php else: ?>
  933. &nbsp;
  934. <?php endif ?>
  935. <?php $total += $data[$name][$department->Short_Desc] ?>
  936. <?php else: ?>
  937. &nbsp;
  938. <?php endif ?>
  939. </td>
  940. <?php endforeach ?>
  941. <?php $html = ob_get_clean() ?>
  942. <td class="align-center bold">
  943. <?php if ($total > 0): ?>
  944. <a target="_blank" href="/p078_dealerd1/p077_DealLog1/SC_Main/SC_Status_Reporting.php?srt=1&department=@All&frn=@All&range=@All&colour=@All&sort=1&location=@All&age=@All"><?php echo number_format($total, 0); ?></a>
  945. <?php else: ?>
  946. &nbsp;
  947. <?php endif ?>
  948. </td>
  949. <?php echo $html; ?>
  950. </tr>
  951. <?php $name = 'Wholesale > 20 Days'; $total = 0 ?>
  952. <tr>
  953. <td><?php echo $name; ?></td>
  954. <?php ob_start() ?>
  955. <?php foreach ($departments as $department): ?>
  956. <td class="align-center">
  957. <?php if (isset($data[$name][$department->Short_Desc])): ?>
  958. <?php if ($data[$name][$department->Short_Desc] > 0): ?>
  959. <a target="_blank" href="/p078_dealerd1/p077_DealLog1/SC_Main/SC_Status_Reporting.php?srt=1&department=<?php echo $department->DMS_DPT_Code; ?>&frn=@All&range=@All&colour=@All&sort=1&location=@All&age=@All"><?php echo number_format($data[$name][$department->Short_Desc], 0); ?></a>
  960. <?php else: ?>
  961. &nbsp;
  962. <?php endif ?>
  963. <?php $total += $data[$name][$department->Short_Desc] ?>
  964. <?php else: ?>
  965. &nbsp;
  966. <?php endif ?>
  967. </td>
  968. <?php endforeach ?>
  969. <?php $html = ob_get_clean() ?>
  970. <td class="align-center bold">
  971. <?php if ($total > 0): ?>
  972. <a target="_blank" href="/p078_dealerd1/p077_DealLog1/SC_Main/SC_Status_Reporting.php?srt=1&department=<?php echo $department->DMS_DPT_Code; ?>&frn=@All&range=@All&colour=@All&sort=1&location=@All&age=@All"><?php echo number_format($total, 0); ?></a>
  973. <?php else: ?>
  974. &nbsp;
  975. <?php endif ?>
  976. </td>
  977. <?php echo $html; ?>
  978. </tr>
  979. <?php $name = 'Deliveries Today'; $totals = array('Today' => 0, 'Yesterday' => 0, 'DayBefore' => 0) ?>
  980. <tr>
  981. <td><?php echo $name; ?></td>
  982. <?php ob_start() ?>
  983. <?php foreach ($departments as $department): ?>
  984. <td class="align-center">
  985. <?php if (isset($data[$name][$department->Short_Desc])): ?>

Large files files are truncated, but you can click here to view the full file