PageRenderTime 64ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/p078_dealerd1/p077_DealLog1/GM_Main/GM_Dashboard/ajax/Sale_Departments_Table.php

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

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