You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MarketingDealerController.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. <?php
  2. namespace App\Http\Controllers\DS;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Carbon\Carbon;
  7. use Validator;
  8. use PDF;
  9. use App\Staff;
  10. use App\Model\StaffDetail;
  11. Use App\Model\Coverage;
  12. use App\Model\DealerClaim;
  13. use App\Model\Company;
  14. use App\Model\Commission;
  15. use App\Model\Form;
  16. use App\Model\Subscriber;
  17. use App\Model\PackageDetail;
  18. use App\Model\WorkOrder;
  19. use App\Model\Docket;
  20. class MarketingDealerController extends Controller {
  21. // Return view
  22. /**
  23. Calculate Claim R
  24. **/
  25. public function returnDataR(array $dataRR, $year,$month){
  26. $dataCR = $dataRR;
  27. $final = array();
  28. // Month & Year
  29. $mY = '';
  30. if($year != 'null' && $month != 'null'){
  31. $mY = $month.'/'.$year;
  32. }
  33. if($mY != ''){
  34. $data12 = array(); $data24 = array();
  35. $countD12 = 0; $countD24 = 0;
  36. foreach($dataCR as $dc){
  37. if($dc->activated_my == $mY){
  38. if($dc->contract == "12"){
  39. $data12[] = $dc;
  40. }else if($dc->contract == "24"){
  41. $data24[] = $dc;
  42. }
  43. }
  44. }
  45. $countD24 = count($data24);
  46. $countD12 = count($data12);
  47. $comm = Commission::where('formT','R')->get();
  48. $commV12 = 0; $commV24 = 0;
  49. $comm12 = ''; $comm24 = '';
  50. foreach($comm as $c){
  51. if($c->contract =='12'){
  52. if(strpos($c->ranges, '>') !== false) {
  53. $pieces = explode(">", $c->ranges);
  54. if($countD12 >= intval($pieces[1])){
  55. $commV12 = floatval($c->comm)/100;
  56. $comm12 = $c->comm.'%';
  57. }
  58. }
  59. if(strpos($c->ranges,'-') !== false){
  60. $pieces = explode("-", $c->ranges);
  61. if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){
  62. $commV12 = floatval($c->comm)/100;
  63. $comm12 = $c->comm.'%';
  64. }
  65. }
  66. }else if($c->contract =='24'){
  67. // Contract => 24
  68. if($countD24 != 0){
  69. if(strpos($c->ranges, '>') !== false) {
  70. $pieces = explode(">", $c->ranges);
  71. if($countD24 > intval($pieces[1])){
  72. $commV24 = floatval($c->comm)/100;
  73. $comm24 = $c->comm.'%';
  74. }
  75. }
  76. if(strpos($c->ranges,'-') !== false){
  77. $pieces = explode("-", $c->ranges);
  78. if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){
  79. $commV24 = floatval($c->comm)/100;
  80. $comm24 = $c->comm.'%';
  81. }
  82. }
  83. }
  84. }
  85. }
  86. foreach ($data12 as $key => $d) {
  87. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  88. $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  89. $final[] = array(
  90. 'index' => $d['formT'],
  91. 'contract' => $d['contract'],
  92. 'wo' => $d['wo'],
  93. 'activation' => $d['activated_dt'],
  94. 'name' => $customer->name,
  95. 'address' => $address,
  96. 'package' => $d['package'],
  97. 'retail_price' => 'RM '.$d['retail_price'],
  98. 'incentives1' => $comm12,
  99. 'incentives2' => '',
  100. 'total' => 'RM '.number_format($d['retail_price']*$commV12,2),
  101. 'claim' => $d['claim_dt'],
  102. );
  103. }
  104. foreach ($data24 as $key => $d) {
  105. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  106. $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  107. $final[] = array(
  108. 'index' => $d['formT'],
  109. 'contract' => $d['contract'],
  110. 'wo' => $d['wo'],
  111. 'activation' => $d['activated_dt'],
  112. 'name' => $customer->name,
  113. 'address' => $address,
  114. 'package' => $d['package'],
  115. 'retail_price' => 'RM '.$d['retail_price'],
  116. 'incentives1' => $comm24,
  117. 'incentives2' => '',
  118. 'total' => 'RM '.number_format($d['retail_price']*$commV24,2),
  119. 'claim' => $d['claim_dt'],
  120. );
  121. }
  122. }else {
  123. foreach ($dataCR as $c){
  124. $customer = Subscriber::where('_id', $c['customer_id'])->first();
  125. $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  126. $final[] = array(
  127. 'index' => $c['formT'],
  128. 'contract' => $c['contract'],
  129. 'wo' => $c['wo'],
  130. 'activation' => $c['activated_dt'],
  131. 'name' => $customer->name,
  132. 'address' => $address,
  133. 'package' => $c['package'],
  134. 'retail_price' => 'RM '.$c['retail_price'],
  135. 'incentives1' => '',
  136. 'incentives2' => '',
  137. 'total' => '',
  138. 'claim' => $c['claim_dt'],
  139. );
  140. }
  141. }
  142. return $final;
  143. }
  144. /**
  145. Get Claim B
  146. **/
  147. public function returnDataB(array $dataBB, $year,$month){
  148. $dataCB = $dataBB;
  149. $final = array();
  150. // Month & Year
  151. $mY = '';
  152. if($year != 'null' && $month != 'null'){
  153. $mY = $month.'/'.$year;
  154. }
  155. if($mY != ''){
  156. /** Contract 12
  157. // 1=>10-100 2=>300 3=>500 4=>1
  158. **/
  159. $data12_1 = array(); $data12_2 = array();
  160. $data12_3 = array(); $data12_4 = array();
  161. $countD12_1 = 0; $countD12_2 = 0;
  162. $countD12_3 = 0; $countD12_4 = 0;
  163. /** Contract 24
  164. // 1=>10-100 2=>300 3=>500 4=>1
  165. **/
  166. $data24_1 = array(); $data24_2 = array();
  167. $data24_3 = array(); $data24_4 = array();
  168. $countD24_1 = 0; $countD24_2 = 0;
  169. $countD24_3 = 0; $countD24_4 = 0;
  170. foreach($dataCB as $dc){
  171. if($dc->activated_my == $mY){
  172. if($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  173. $data12_1[] = $dc;
  174. }else if($dc->contract == "12" && $dc->package == "300"){
  175. $data12_2[] = $dc;
  176. }else if($dc->contract == "12" && $dc->package == "500"){
  177. $data12_3[] = $dc;
  178. }else if($dc->contract == "12" && $dc->package == "1"){
  179. $data12_4[] = $dc;
  180. }else if($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  181. $data24_1[] = $dc;
  182. }else if($dc->contract == "24" && $dc->package == "300"){
  183. $countD24_2[] = $dc;
  184. }else if($dc->contract == "24" && $dc->package == "500"){
  185. $countD24_3[] = $dc;
  186. }else if($dc->contract == "24" && $dc->package == "1"){
  187. $countD24_4[] = $dc;
  188. }
  189. }
  190. }
  191. $countD12_1 = count($data12_1); $countD12_2 = count($data12_2);
  192. $countD12_3 = count($data12_3); $countD12_4 = count($data12_4);
  193. $countD24_1 = count($data24_1); $countD24_2 = count($data24_2);
  194. $countD24_3 = count($data24_3); $countD24_4 = count($data24_4);
  195. $comm = Commission::where('formT','B')->get();
  196. $commV12_1 = 0; $commV12_2 = 0;
  197. $commV12_3 = 0; $commV12_4 = 0;
  198. $commV24_2 = 0; $commV24_2 = 0;
  199. $commV24_3 = 0; $commV24_4 = 0;
  200. $comm12_1 = ''; $comm12_2 = '';
  201. $comm12_3 = ''; $comm12_4 = '';
  202. $comm24_1 = ''; $comm24_2 = '';
  203. $comm24_3 = ''; $comm24_4 = '';
  204. $addRM12_1 = ''; $addRM12_2 = '';
  205. $addRM12_3 = ''; $addRM12_4 = '';
  206. $addRM24_1 = ''; $addRM24_2 = '';
  207. $addRM24_3 = ''; $addRM24_4 = '';
  208. foreach($comm as $c){
  209. /*** Contract 24 **/
  210. if($c->contract =='24' && $c->packageR == "300"){
  211. if(strpos($c->ranges, '>') !== false) {
  212. $pieces = explode(">", $c->ranges);
  213. if($countD24_2 >= intval($pieces[1])){
  214. if(strpos($c->comm, 'RM') !== false) {
  215. $comm24_2 = '+ ' .$c->comm;
  216. $commV24_2 = '';
  217. $addRM24_2 = $c->comm;
  218. }else {
  219. $comms = explode("RM", $c->comm);
  220. if(isset($comms[1])){
  221. $comm24_2 = 'RM '.$comms[1];
  222. $commV24_2 = floatval($comms[1]);
  223. }else {
  224. if($comms[0] != ''){
  225. $comm24_2 = $comms[0].'%';
  226. $commV24_2 = floatval($comms[0])/100;
  227. }
  228. }
  229. }
  230. }
  231. }
  232. }else if($c->contract =='24' && $c->packageR == "500"){
  233. if(strpos($c->ranges, '>') !== false) {
  234. $pieces = explode(">", $c->ranges);
  235. if($countD24_3 >= intval($pieces[1])){
  236. if(strpos($c->comm, 'RM') !== false) {
  237. $comm24_3 = '+ ' .$c->comm;
  238. $commV24_3 = '';
  239. $addRM24_3 = $c->comm;
  240. }else {
  241. $comms = explode("RM", $c->comm);
  242. if(isset($comms[1])){
  243. $comm24_3 = 'RM '.$comms[1];
  244. $commV24_3 = floatval($comms[1]);
  245. }else {
  246. if($comms[0] != ''){
  247. $comm24_3 = $comms[0].'%';
  248. $commV24_3 = floatval($comms[0])/100;
  249. }
  250. }
  251. }
  252. }
  253. }
  254. }else if($c->contract =='24' && $c->packageR == "1"){
  255. if(strpos($c->ranges, '>') !== false) {
  256. $pieces = explode(">", $c->ranges);
  257. if($countD24_4 >= intval($pieces[1])){
  258. if(strpos($c->comm, 'RM') !== false) {
  259. $comm24_4 = '+ ' .$c->comm;
  260. $commV24_4 = '';
  261. $addRM24_4 = $c->comm;
  262. }else {
  263. $comms = explode("RM", $c->comm);
  264. if(isset($comms[1])){
  265. $comm24_4 = 'RM '.$comms[1];
  266. $commV24_4 = floatval($comms[1]);
  267. }else {
  268. if($comms[0] != ''){
  269. $comm24_4 = $comms[0].'%';
  270. $commV24_4 = floatval($comms[0])/100;
  271. }
  272. }
  273. }
  274. }
  275. }
  276. }else if($c->contract =='24' && $c->packageR == "10,30,50,100"){
  277. if(strpos($c->ranges, '>') !== false) {
  278. $pieces = explode(">", $c->ranges);
  279. if($countD24_1 >= intval($pieces[1])){
  280. if(strpos($c->comm, 'RM') !== false) {
  281. $comm24_1 = '+ ' .$c->comm;
  282. $commV24_1 = '';
  283. $addRM24_1 = $c->comm;
  284. }else {
  285. $comms = explode("RM", $c->comm);
  286. if(isset($comms[1])){
  287. $comm24_1 = 'RM '.$comms[1];
  288. $commV24_1 = floatval($comms[1]);
  289. }else {
  290. if($comms[0] != ''){
  291. $comm24_1 = $comms[0].'%';
  292. $commV24_1 = floatval($comms[0])/100;
  293. }
  294. }
  295. }
  296. }
  297. }
  298. if(strpos($c->ranges,'-') !== false){
  299. $pieces = explode("-", $c->ranges);
  300. if($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])){
  301. if(strpos($c->comm, 'RM') !== false) {
  302. $comm24_1 = '+ ' .$c->comm;
  303. $commV24_1 = '';
  304. $addRM24_1 = $c->comm;
  305. }else {
  306. $comms = explode("RM", $c->comm);
  307. if(isset($comms[1])){
  308. $comm24_1 = 'RM '.$comms[1];
  309. $commV24_1 = floatval($comms[1]);
  310. }else {
  311. if($comms[0] != ''){
  312. $comm24_1 = $comms[0].'%';
  313. $commV24_1 = floatval($comms[0])/100;
  314. }
  315. }
  316. }
  317. }
  318. }
  319. }
  320. /*** Contract 12 **/
  321. else if($c->contract =='12' && $c->packageR == "10,30,50,100"){
  322. if(strpos($c->ranges, '>') !== false) {
  323. $pieces = explode(">", $c->ranges);
  324. if($countD12_1 >= intval($pieces[1])){
  325. if(strpos($c->comm, 'RM') !== false) {
  326. $comm12_1 = '+ ' .$c->comm;
  327. $commV12_1 = '';
  328. $addRM12_1 = $c->comm;
  329. }else {
  330. $comms = explode("RM", $c->comm);
  331. if(isset($comms[1])){
  332. $comm12_1 = 'RM '.$comms[1];
  333. $commV12_1 = floatval($comms[1]);
  334. }else {
  335. if($comms[0] != ''){
  336. $comm12_1 = $comms[0].'%';
  337. $commV12_1 = floatval($comms[0])/100;
  338. }
  339. }
  340. }
  341. }
  342. }
  343. if(strpos($c->ranges,'-') !== false){
  344. $pieces = explode("-", $c->ranges);
  345. if($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])){
  346. if(strpos($c->comm, 'RM') !== false) {
  347. $comm12_1 = '+ ' .$c->comm;
  348. $commV12_1 = '';
  349. $addRM12_1 = $c->comm;
  350. }else {
  351. $comms = explode("RM", $c->comm);
  352. if(isset($comms[1])){
  353. $comm12_1 = 'RM '.$comms[1];
  354. $commV12_1 = floatval($comms[1]);
  355. }else {
  356. if($comms[0] != ''){
  357. $comm12_1 = $comms[0].'%';
  358. $commV12_1 = floatval($comms[0])/100;
  359. }
  360. }
  361. }
  362. }
  363. }
  364. }else if($c->contract =='12' && $c->packageR == "300"){
  365. if(strpos($c->ranges, '>') !== false) {
  366. $pieces = explode(">", $c->ranges);
  367. if($countD12_2 >= intval($pieces[1])){
  368. if(strpos($c->comm, 'RM') !== false) {
  369. $comm12_2 = '+ ' .$c->comm;
  370. $commV12_2 = '';
  371. $addRM12_2 = $c->comm;
  372. }else {
  373. $comms = explode("RM", $c->comm);
  374. if(isset($comms[1])){
  375. $comm12_2 = 'RM '.$comms[1];
  376. $commV12_2 = floatval($comms[1]);
  377. }else {
  378. if($comms[0] != ''){
  379. $comm12_2 = $comms[0].'%';
  380. $commV12_2 = floatval($comms[0])/100;
  381. }
  382. }
  383. }
  384. }
  385. }
  386. }else if($c->contract =='12' && $c->packageR == "500"){
  387. if(strpos($c->ranges, '>') !== false) {
  388. $pieces = explode(">", $c->ranges);
  389. if($countD12_3 >= intval($pieces[1])){
  390. if(strpos($c->comm, 'RM') !== false) {
  391. $comm12_3 = '+ ' .$c->comm;
  392. $commV12_3 = '';
  393. $addRM12_3 = $c->comm;
  394. }else {
  395. $comms = explode("RM", $c->comm);
  396. if(isset($comms[1])){
  397. $comm12_3 = 'RM '.$comms[1];
  398. $commV12_3 = floatval($comms[1]);
  399. }else {
  400. if($comms[0] != ''){
  401. $comm12_3 = $comms[0].'%';
  402. $commV12_3 = floatval($comms[0])/100;
  403. }
  404. }
  405. }
  406. }
  407. }
  408. }else if($c->contract =='12' && $c->packageR == "1"){
  409. if(strpos($c->ranges, '>') !== false) {
  410. $pieces = explode(">", $c->ranges);
  411. if($countD12_4 >= intval($pieces[1])){
  412. if(strpos($c->comm, 'RM') !== false) {
  413. $comm12_4 = '+ ' .$c->comm;
  414. $commV12_4 = '';
  415. $addRM12_4 = $c->comm;
  416. }else {
  417. $comms = explode("RM", $c->comm);
  418. if(isset($comms[1])){
  419. $comm12_4 = 'RM '.$comms[1];
  420. $commV12_4 = floatval($comms[1]);
  421. }else {
  422. if($comms[0] != ''){
  423. $comm12_4 = $comms[0].'%';
  424. $commV12_4 = floatval($comms[0])/100;
  425. }
  426. }
  427. }
  428. }
  429. }
  430. }
  431. }
  432. // Category 10,30,50,100
  433. foreach ($data12_1 as $key => $d) {
  434. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  435. $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  436. $total = '';
  437. if($commV12_1 == ''){
  438. $total = $addRM12_1;
  439. }else {
  440. $total = number_format($d['retail_price']*$commV12_1,2);
  441. }
  442. $final[] = array(
  443. 'index' => $d['formT'],
  444. 'contract' => $d['contract'],
  445. 'wo' => $d['wo'],
  446. 'activation' => $d['activated_dt'],
  447. 'name' => $customer->name,
  448. 'address' => $address,
  449. 'package' => $d['package'],
  450. 'retail_price' => 'RM '.$d['retail_price'],
  451. 'incentives1' => $comm12_1,
  452. 'incentives2' => $addRM12_1,
  453. 'total' => 'RM '.$total,
  454. 'claim' => $c['claim_dt'],
  455. );
  456. }
  457. foreach ($data24_1 as $key => $d) {
  458. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  459. $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  460. $total = '';
  461. if($commV24_1 == ''){
  462. $total = $addRM24_1;
  463. }else {
  464. $total = number_format($d['retail_price']*$commV24_1,2);
  465. }
  466. $final[] = array(
  467. 'index' => $d['formT'],
  468. 'contract' => $d['contract'],
  469. 'wo' => $d['wo'],
  470. 'activation' => $d['activated_dt'],
  471. 'name' => $customer->name,
  472. 'address' => $address,
  473. 'package' => $d['package'],
  474. 'retail_price' => 'RM '.$d['retail_price'],
  475. 'incentives1' => $comm24_1,
  476. 'incentives2' => $addRM24_1,
  477. 'total' => 'RM '.$total,
  478. 'claim' => $c['claim_dt'],
  479. );
  480. }
  481. // Category 300
  482. foreach ($data12_2 as $key => $d) {
  483. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  484. $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  485. $total = '';
  486. if($commV12_2 == ''){
  487. $total = $addRM12_2;
  488. }else {
  489. $total = number_format($d['retail_price']*$commV12_2,2);
  490. }
  491. $final[] = array(
  492. 'index' => $d['formT'],
  493. 'contract' => $d['contract'],
  494. 'wo' => $d['wo'],
  495. 'activation' => $d['activated_dt'],
  496. 'name' => $customer->name,
  497. 'address' => $address,
  498. 'package' => $d['package'],
  499. 'retail_price' => 'RM '.$d['retail_price'],
  500. 'incentives1' => $comm12_2,
  501. 'incentives2' => $addRM12_2,
  502. 'total' => 'RM '.$total,
  503. 'claim' => $c['claim_dt'],
  504. );
  505. }
  506. foreach ($data24_2 as $key => $d) {
  507. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  508. $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  509. $total = '';
  510. if($commV24_2 == ''){
  511. $total = $addRM24_2;
  512. }else {
  513. $total = number_format($d['retail_price']*$commV24_2,2);
  514. }
  515. $final[] = array(
  516. 'index' => $d['formT'],
  517. 'contract' => $d['contract'],
  518. 'wo' => $d['wo'],
  519. 'activation' => $d['activated_dt'],
  520. 'name' => $customer->name,
  521. 'address' => $address,
  522. 'package' => $d['package'],
  523. 'retail_price' => 'RM '.$d['retail_price'],
  524. 'incentives1' => $comm24_2,
  525. 'incentives2' => $addRM24_2,
  526. 'total' => 'RM '.$total,
  527. 'claim' => $c['claim_dt'],
  528. );
  529. }
  530. // Category 500
  531. foreach ($data12_3 as $key => $d) {
  532. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  533. $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  534. $total = '';
  535. if($commV12_3 == ''){
  536. $total = $addRM12_3;
  537. }else {
  538. $total = number_format($d['retail_price']*$commV12_3,2);
  539. }
  540. $final[] = array(
  541. 'index' => $d['formT'],
  542. 'contract' => $d['contract'],
  543. 'wo' => $d['wo'],
  544. 'activation' => $d['activated_dt'],
  545. 'name' => $customer->name,
  546. 'address' => $address,
  547. 'package' => $d['package'],
  548. 'retail_price' => 'RM '.$d['retail_price'],
  549. 'incentives1' => $comm12_3,
  550. 'incentives2' => $addRM12_3,
  551. 'total' => 'RM '.$total,
  552. 'claim' => $c['claim_dt'],
  553. );
  554. }
  555. foreach ($data24_3 as $key => $d) {
  556. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  557. $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  558. $total = '';
  559. if($commV24_3 == ''){
  560. $total = $addRM24_3;
  561. }else {
  562. $total = number_format($d['retail_price']*$commV24_3,2);
  563. }
  564. $final[] = array(
  565. 'index' => $d['formT'],
  566. 'contract' => $d['contract'],
  567. 'wo' => $d['wo'],
  568. 'activation' => $d['activated_dt'],
  569. 'name' => $customer->name,
  570. 'address' => $address,
  571. 'package' => $d['package'],
  572. 'retail_price' => 'RM '.$d['retail_price'],
  573. 'incentives1' => $comm24_3,
  574. 'incentives2' => $addRM24_3,
  575. 'total' => 'RM '.$total,
  576. 'claim' => $c['claim_dt'],
  577. );
  578. }
  579. // Category 1
  580. foreach ($data12_4 as $key => $d) {
  581. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  582. $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  583. $total = '';
  584. if($commV12_4 == ''){
  585. $total = $addRM12_4;
  586. }else {
  587. $total = number_format($d['retail_price']*$commV12_4,2);
  588. }
  589. $final[] = array(
  590. 'index' => $d['formT'],
  591. 'contract' => $d['contract'],
  592. 'wo' => $d['wo'],
  593. 'activation' => $d['activated_dt'],
  594. 'name' => $customer->name,
  595. 'address' => $address,
  596. 'package' => $d['package'],
  597. 'retail_price' => 'RM '.$d['retail_price'],
  598. 'incentives1' => $comm12_4,
  599. 'incentives2' => $addRM12_4,
  600. 'total' => 'RM '.$total,
  601. 'claim' => $c['claim_dt'],
  602. );
  603. }
  604. foreach ($data24_4 as $key => $d) {
  605. $customer = Subscriber::where('_id', $d['customer_id'])->first();
  606. $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  607. $total = '';
  608. if($commV24_4 == ''){
  609. $total = $addRM24_4;
  610. }else {
  611. $total = number_format($d['retail_price']*$commV24_4,2);
  612. }
  613. $final[] = array(
  614. 'index' => $d['formT'],
  615. 'contract' => $d['contract'],
  616. 'wo' => $d['wo'],
  617. 'activation' => $d['activated_dt'],
  618. 'name' => $customer->name,
  619. 'address' => $address,
  620. 'package' => $d['package'],
  621. 'retail_price' => 'RM '.$d['retail_price'],
  622. 'incentives1' => $comm24_4,
  623. 'incentives2' => $addRM24_4,
  624. 'total' => 'RM '.$total,
  625. 'claim' => $c['claim_dt'],
  626. );
  627. }
  628. }else {
  629. foreach ($dataCB as $c){
  630. $customer = Subscriber::where('_id', $c['customer_id'])->first();
  631. $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  632. $final[] = array(
  633. 'index' => $c['formT'],
  634. 'contract' => $c['contract'],
  635. 'wo' => $c['wo'],
  636. 'activation' => $c['activated_dt'],
  637. 'name' => $customer->name,
  638. 'address' => $address,
  639. 'package' => $c['package'],
  640. 'retail_price' => 'RM '.$c['retail_price'],
  641. 'incentives1' => '',
  642. 'incentives2' => '',
  643. 'total' => '',
  644. 'claim' => $c['claim_dt'],
  645. );
  646. }
  647. }
  648. return $final;
  649. }
  650. //Show claim list by company
  651. public function mClaimList($company)
  652. {
  653. $id = Auth::guard('ms')->id();
  654. $user = Staff::with('StaffDetail')->find($id);
  655. $dealer_claimAll = DealerClaim::where('dealer',$company)->get();
  656. $dealer_claimR = DealerClaim::where('formT','R')->where('dealer',$company)->get()->toArray();
  657. $dealer_claimB = DealerClaim::where('formT','B')->where('dealer',$company)->get()->toArray();
  658. foreach ($dealer_claimAll as $c){
  659. $customer = Subscriber::where('_id', $c['customer_id'])->first();
  660. $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state;
  661. $final[] = array(
  662. 'index' => $c['formT'],
  663. 'contract' => $c['contract'],
  664. 'wo' => $c['wo'],
  665. 'activation' => $c['activated_dt'],
  666. 'name' => $customer->name,
  667. 'address' => $address,
  668. 'package' => $c['package'],
  669. 'retail_price' => 'RM '.$c['retail_price'],
  670. 'incentives1' => '',
  671. 'incentives2' => '',
  672. 'total' => '',
  673. 'claim' => $c['claim_dt'],
  674. );
  675. }
  676. dd($dealer_claimR);
  677. $dataR = $this->returnDataR($dealer_claimR, 'null','null');
  678. $dataB = $this->returnDataB($dealer_claimB, 'null','null');
  679. $combineData = array();
  680. foreach($dataR as $r){
  681. $combineData[] = $r;
  682. }
  683. foreach($dataB as $b){
  684. $combineData[] = $b;
  685. }
  686. dd($dataR);
  687. $i = 0;
  688. $nested_data = array();
  689. if(!empty($combineData)){
  690. foreach ($combineData as $c){
  691. $i++;
  692. array_push($nested_data, array(
  693. 'index' => $i.$c['index'],
  694. 'contract' => $c['contract'],
  695. 'wo' => $c['wo'],
  696. 'activated_dt' => $c['activation'],
  697. 'name' => $c['name'],
  698. 'address' => $c['address'],
  699. 'package' => $c['package'],
  700. 'retail_price' => $c['retail_price'],
  701. 'incentives1' => $c['incentives1'],
  702. 'incentives2' => $c['incentives2'],
  703. 'total' => $c['total'],
  704. 'claim' => $c['claim'],
  705. ));
  706. }
  707. }
  708. return \DataTables::of($nested_data)->make(true);
  709. }
  710. }