選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DealerClaimController.php 38KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290
  1. <?php
  2. namespace App\Http\Controllers\v3\Api;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\v3\Api\BaseController;
  5. use File;
  6. use Carbon\Carbon;
  7. use PDF;
  8. use App\LatestModel\Staff;
  9. use App\LatestModel\StaffDetail;
  10. use App\LatestModel\Dealer;
  11. use App\LatestModel\DealerDetail;
  12. use App\LatestModel\Module\Form;
  13. use App\LatestModel\Module\FormStatus;
  14. use App\LatestModel\Module\Subscriber;
  15. use App\LatestModel\Module\WorkOrder;
  16. use App\LatestModel\Module\Docket;
  17. use App\LatestModel\Module\PackageDetail;
  18. use App\LatestModel\Module\Company;
  19. use App\LatestModel\Module\Coverage;
  20. use App\LatestModel\Module\Product;
  21. use App\LatestModel\Module\DealerClaim;
  22. use App\LatestModel\Module\Commission;
  23. class DealerClaimController extends BaseController
  24. {
  25. /**
  26. * Display all claim list
  27. *
  28. * @return json
  29. */
  30. public function mClaimListAll($dealer)
  31. {
  32. $i = 0;
  33. $nested_data = array();
  34. $dealer_claimAll = DealerClaim::where('dealer',$dealer)->orderBy('activated_dt','desc')->get();
  35. foreach ($dealer_claimAll as $c){
  36. $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first();
  37. $address = ''; $name = '';
  38. if($customer->Form->type_application == 'R'){
  39. if($customer->street != ''){
  40. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  41. }else {
  42. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  43. }
  44. $name = $customer->name;
  45. }else if($customer->Form->type_application == 'B'){
  46. if($customer->unit_no != ''){
  47. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  48. }else {
  49. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  50. }
  51. $name = $customer->company_name;
  52. }
  53. $i++;
  54. array_push($nested_data, array(
  55. 'index' => $c->formT,
  56. 'contract' => $c->contract,
  57. 'wo' => $c->wo,
  58. 'activated_dt' => $c->activated_dt,
  59. 'name' => $name,
  60. 'address' => $address,
  61. 'package' => $c->package,
  62. 'retail_price' => 'RM '.$c->retail_price,
  63. 'incentives1' => '',
  64. 'incentives2' => '',
  65. 'total' => '',
  66. 'claimed' => $c->laim_dt,
  67. 'action' => 'null',
  68. ));
  69. }
  70. return \DataTables::of($nested_data)->make(true);
  71. }
  72. /*
  73. * Get Claim resident
  74. *
  75. * @return json
  76. */
  77. public function returnDataR($company,$year,$month)
  78. {
  79. $final = array();
  80. $dataCR = DealerClaim::where('formT','R')->where('dealer',$company)->get();
  81. // Month & Year
  82. $mY = '';
  83. if($year != 'null' && $month != 'null'){
  84. $mY = $month.'/'.$year;
  85. }
  86. if($mY != ''){
  87. $data12 = array(); $data24 = array();
  88. $countD12 = 0; $countD24 = 0;
  89. foreach($dataCR as $dc){
  90. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  91. if($dc->contract == "12"){
  92. $data12[] = $dc;
  93. }else if($dc->contract == "24"){
  94. $data24[] = $dc;
  95. }
  96. }
  97. }
  98. $countD24 = count($data24);
  99. $countD12 = count($data12);
  100. $comm = Commission::where('formT','R')->get();
  101. $commV12 = 0; $commV24 = 0;
  102. $comm12 = ''; $comm24 = '';
  103. foreach($comm as $c){
  104. if($c->contract =='12'){
  105. if(strpos($c->ranges, '>') !== false) {
  106. $pieces = explode(">", $c->ranges);
  107. if($countD12 >= intval($pieces[1])){
  108. $commV12 = floatval($c->comm)/100;
  109. $comm12 = $c->comm.'%';
  110. }
  111. }
  112. if(strpos($c->ranges,'-') !== false){
  113. $pieces = explode("-", $c->ranges);
  114. if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){
  115. $commV12 = floatval($c->comm)/100;
  116. $comm12 = $c->comm.'%';
  117. }
  118. }
  119. }else if($c->contract =='24'){
  120. // Contract => 24
  121. if($countD24 != 0){
  122. if(strpos($c->ranges, '>') !== false) {
  123. $pieces = explode(">", $c->ranges);
  124. if($countD24 > intval($pieces[1])){
  125. $commV24 = floatval($c->comm)/100;
  126. $comm24 = $c->comm.'%';
  127. }
  128. }
  129. if(strpos($c->ranges,'-') !== false){
  130. $pieces = explode("-", $c->ranges);
  131. if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){
  132. $commV24 = floatval($c->comm)/100;
  133. $comm24 = $c->comm.'%';
  134. }
  135. }
  136. }
  137. }
  138. }
  139. foreach ($data12 as $key => $d) {
  140. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  141. $address = ''; $name = '';
  142. if($customer->Form->type_application == 'R'){
  143. if($customer->street != ''){
  144. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  145. }else {
  146. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  147. }
  148. $name = $customer->name;
  149. }else if($customer->Form->type_application == 'B'){
  150. if($customer->unit_no != ''){
  151. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  152. }else {
  153. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  154. }
  155. $name = $customer->company_name;
  156. }
  157. $final[] = array(
  158. 'index' => $d['formT'],
  159. 'contract' => $d['contract'],
  160. 'wo' => $d['wo'],
  161. 'activation' => $d['activated_dt'],
  162. 'name' => $name,
  163. 'address' => $address,
  164. 'package' => $d['package'],
  165. 'retail_price' => 'RM '.$d['retail_price'],
  166. 'incentives1' => $comm12,
  167. 'incentives2' => '',
  168. 'total' => 'RM '.number_format($d['retail_price']*$commV12,2),
  169. 'claim' => $d['claim_dt'],
  170. );
  171. }
  172. foreach ($data24 as $key => $d) {
  173. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  174. $address = ''; $name = '';
  175. if($customer->Form->type_application == 'R'){
  176. if($customer->street != ''){
  177. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  178. }else {
  179. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  180. }
  181. $name = $customer->name;
  182. }else if($customer->Form->type_application == 'B'){
  183. if($customer->unit_no != ''){
  184. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  185. }else {
  186. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  187. }
  188. $name = $customer->company_name;
  189. }
  190. $final[] = array(
  191. 'index' => $d['formT'],
  192. 'contract' => $d['contract'],
  193. 'wo' => $d['wo'],
  194. 'activation' => $d['activated_dt'],
  195. 'name' => $name,
  196. 'address' => $address,
  197. 'package' => $d['package'],
  198. 'retail_price' => 'RM '.$d['retail_price'],
  199. 'incentives1' => $comm24,
  200. 'incentives2' => '',
  201. 'total' => 'RM '.number_format($d['retail_price']*$commV24,2),
  202. 'claim' => $d['claim_dt'],
  203. );
  204. }
  205. }else {
  206. foreach ($dataCR as $c){
  207. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  208. $address = ''; $name = '';
  209. if($customer->Form->type_application == 'R'){
  210. if($customer->street != ''){
  211. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  212. }else {
  213. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  214. }
  215. $name = $customer->name;
  216. }else if($customer->Form->type_application == 'B'){
  217. if($customer->unit_no != ''){
  218. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  219. }else {
  220. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  221. }
  222. $name = $customer->company_name;
  223. }
  224. $final[] = array(
  225. 'index' => $c['formT'],
  226. 'contract' => $c['contract'],
  227. 'wo' => $c['wo'],
  228. 'activation' => $c['activated_dt'],
  229. 'name' => $name,
  230. 'address' => $address,
  231. 'package' => $c['package'],
  232. 'retail_price' => 'RM '.$c['retail_price'],
  233. 'incentives1' => '',
  234. 'incentives2' => '',
  235. 'total' => '',
  236. 'claim' => $c['claim_dt'],
  237. );
  238. }
  239. }
  240. return $final;
  241. }
  242. // Get Claim Business
  243. public function returnDataB($company,$year,$month){
  244. $dataCB = DealerClaim::where('formT','B')->where('dealer',$company)->get();
  245. $final = array();
  246. // Month & Year
  247. $mY = '';
  248. if($year != 'null' && $month != 'null'){
  249. $mY = $month.'/'.$year;
  250. }
  251. if($mY != ''){
  252. /** Contract 12
  253. // 1=>10-100 2=>300 3=>500 4=>1
  254. **/
  255. $data12_1 = array(); $data12_2 = array();
  256. $data12_3 = array(); $data12_4 = array();
  257. $countD12_1 = 0; $countD12_2 = 0;
  258. $countD12_3 = 0; $countD12_4 = 0;
  259. /** Contract 24
  260. // 1=>10-100 2=>300 3=>500 4=>1
  261. **/
  262. $data24_1 = array(); $data24_2 = array();
  263. $data24_3 = array(); $data24_4 = array();
  264. $countD24_1 = 0; $countD24_2 = 0;
  265. $countD24_3 = 0; $countD24_4 = 0;
  266. foreach($dataCB as $dc){
  267. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY){
  268. if($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  269. $data12_1[] = $dc;
  270. }else if($dc->contract == "12" && $dc->package == "300"){
  271. $data12_2[] = $dc;
  272. }else if($dc->contract == "12" && $dc->package == "500"){
  273. $data12_3[] = $dc;
  274. }else if($dc->contract == "12" && $dc->package == "1"){
  275. $data12_4[] = $dc;
  276. }else if($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  277. $data24_1[] = $dc;
  278. }else if($dc->contract == "24" && $dc->package == "300"){
  279. $data24_2[] = $dc;
  280. }else if($dc->contract == "24" && $dc->package == "500"){
  281. $data24_3[] = $dc;
  282. }else if($dc->contract == "24" && $dc->package == "1"){
  283. $data24_4[] = $dc;
  284. }
  285. }
  286. }
  287. $countD12_1 = count($data12_1); $countD12_2 = count($data12_2);
  288. $countD12_3 = count($data12_3); $countD12_4 = count($data12_4);
  289. $countD24_1 = count($data24_1); $countD24_2 = count($data24_2);
  290. $countD24_3 = count($data24_3); $countD24_4 = count($data24_4);
  291. $comm = Commission::where('formT','B')->get();
  292. $commV12_1 = 0; $commV12_2 = 0;
  293. $commV12_3 = 0; $commV12_4 = 0;
  294. $commV24_1 = 0; $commV24_2 = 0;
  295. $commV24_3 = 0; $commV24_4 = 0;
  296. $comm12_1 = ''; $comm12_2 = '';
  297. $comm12_3 = ''; $comm12_4 = '';
  298. $comm24_1 = ''; $comm24_2 = '';
  299. $comm24_3 = ''; $comm24_4 = '';
  300. $addRM12_1 = ''; $addRM12_2 = '';
  301. $addRM12_3 = ''; $addRM12_4 = '';
  302. $addRM24_1 = ''; $addRM24_2 = '';
  303. $addRM24_3 = ''; $addRM24_4 = '';
  304. foreach($comm as $c){
  305. /*** Contract 24 **/
  306. if($c->contract =='24' && $c->packageR == "300"){
  307. if(strpos($c->ranges, '>') !== false) {
  308. $pieces = explode(">", $c->ranges);
  309. if($countD24_2 >= intval($pieces[1])){
  310. if(strpos($c->comm, 'RM') !== false) {
  311. $comm24_2 = '+ ' .$c->comm;
  312. $commV24_2 = '';
  313. $comms = explode("RM", $c->comm);
  314. $addRM24_2 = floatval($comms[1]);
  315. }else {
  316. $comms = explode("RM", $c->comm);
  317. if(isset($comms[1])){
  318. $comm24_2 = 'RM '.$comms[1];
  319. $commV24_2 = floatval($comms[1]);
  320. }else {
  321. if($comms[0] != ''){
  322. $comm24_2 = $comms[0].'%';
  323. $commV24_2 = floatval($comms[0])/100;
  324. }
  325. }
  326. }
  327. }
  328. }
  329. }else if($c->contract =='24' && $c->packageR == "500"){
  330. if(strpos($c->ranges, '>') !== false) {
  331. $pieces = explode(">", $c->ranges);
  332. if($countD24_3 >= intval($pieces[1])){
  333. if(strpos($c->comm, 'RM') !== false) {
  334. $comm24_3 = '+ ' .$c->comm;
  335. $commV24_3 = '';
  336. $comms = explode("RM", $c->comm);
  337. $addRM24_3 = floatval($comms[1]);
  338. }else {
  339. $comms = explode("RM", $c->comm);
  340. if(isset($comms[1])){
  341. $comm24_3 = 'RM '.$comms[1];
  342. $commV24_3 = floatval($comms[1]);
  343. }else {
  344. if($comms[0] != ''){
  345. $comm24_3 = $comms[0].'%';
  346. $commV24_3 = floatval($comms[0])/100;
  347. }
  348. }
  349. }
  350. }
  351. }
  352. }else if($c->contract =='24' && $c->packageR == "1"){
  353. if(strpos($c->ranges, '>') !== false) {
  354. $pieces = explode(">", $c->ranges);
  355. if($countD24_4 >= intval($pieces[1])){
  356. if(strpos($c->comm, 'RM') !== false) {
  357. $comm24_4 = '+ ' .$c->comm;
  358. $commV24_4 = '';
  359. $comms = explode("RM", $c->comm);
  360. $addRM24_4 = floatval($comms[1]);
  361. }else {
  362. $comms = explode("RM", $c->comm);
  363. if(isset($comms[1])){
  364. $comm24_4 = 'RM '.$comms[1];
  365. $commV24_4 = floatval($comms[1]);
  366. }else {
  367. if($comms[0] != ''){
  368. $comm24_4 = $comms[0].'%';
  369. $commV24_4 = floatval($comms[0])/100;
  370. }
  371. }
  372. }
  373. }
  374. }
  375. }else if($c->contract =='24' && $c->packageR == "10,30,50,100"){
  376. if(strpos($c->ranges,'-') !== false){
  377. $pieces = explode("-", $c->ranges);
  378. if($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])){
  379. if(strpos($c->comm, 'RM') !== false) {
  380. $comm24_1 = '+ ' .$c->comm;
  381. $commV24_1 = '';
  382. $addRM24_1 = $c->comm;
  383. }else {
  384. $comms = explode("RM", $c->comm);
  385. if(!empty($comms[1])){
  386. $comm24_1 = 'RM '.$comms[1];
  387. $commV24_1 = floatval($comms[1]);
  388. }else {
  389. if($comms[0] != ''){
  390. $comm24_1 = $comms[0].'%';
  391. $commV24_1 = floatval($comms[0])/100;
  392. }
  393. }
  394. }
  395. }
  396. }
  397. if(strpos($c->ranges, '>') !== false) {
  398. $pieces1 = explode(">", $c->ranges);
  399. if($countD24_1 >= intval($pieces1[1])){
  400. if(strpos($c->comm, "RM") === true) {
  401. $comm24_1 = '+ ' .$c->comm;
  402. $commV24_1 = '';
  403. $addRM24_1 = $c->comm;
  404. }else {
  405. $comms = explode("RM", $c->comm);
  406. if(empty($comms[1])){
  407. $comm24_1 = 'RM '.$comms[1];
  408. $commV24_1 = floatval($comms[1]);
  409. }else {
  410. if($comms[0] != ''){
  411. $comm24_1 = str_replace ('+ ','',$comms[0]).'%';
  412. $commV24_1 = floatval($comms[0])/100;
  413. $addRM24_1 = $comms[1];
  414. }
  415. }
  416. }
  417. }
  418. }
  419. }
  420. /*** Contract 12 **/
  421. else if($c->contract =='12' && $c->packageR == "10,30,50,100"){
  422. if(strpos($c->ranges, '>') !== false) {
  423. $pieces = explode(">", $c->ranges);
  424. if($countD12_1 >= intval($pieces[1])){
  425. if(strpos($c->comm, 'RM') !== false) {
  426. $comm12_1 = '+ ' .$c->comm;
  427. $commV12_1 = '';
  428. $addRM12_1 = $c->comm;
  429. }else {
  430. $comms = explode("RM", $c->comm);
  431. if(isset($comms[1])){
  432. $comm12_1 = 'RM '.$comms[1];
  433. $commV12_1 = floatval($comms[1]);
  434. }else {
  435. if($comms[0] != ''){
  436. $comm12_1 = $comms[0].'%';
  437. $commV12_1 = floatval($comms[0])/100;
  438. }
  439. }
  440. }
  441. }
  442. }
  443. if(strpos($c->ranges,'-') !== false){
  444. $pieces = explode("-", $c->ranges);
  445. if($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])){
  446. if(strpos($c->comm, 'RM') !== false) {
  447. $comm12_1 = '+ ' .$c->comm;
  448. $commV12_1 = '';
  449. $addRM12_1 = $c->comm;
  450. }else {
  451. $comms = explode("RM", $c->comm);
  452. if(isset($comms[1])){
  453. $comm12_1 = 'RM '.$comms[1];
  454. $commV12_1 = floatval($comms[1]);
  455. }else {
  456. if($comms[0] != ''){
  457. $comm12_1 = $comms[0].'%';
  458. $commV12_1 = floatval($comms[0])/100;
  459. }
  460. }
  461. }
  462. }
  463. }
  464. }else if($c->contract =='12' && $c->packageR == "300"){
  465. if(strpos($c->ranges, '>') !== false) {
  466. $pieces = explode(">", $c->ranges);
  467. if($countD12_2 >= intval($pieces[1])){
  468. if(strpos($c->comm, 'RM') !== false) {
  469. $comm12_2 = '+ ' .$c->comm;
  470. $commV12_2 = '';
  471. $addRM12_2 = $c->comm;
  472. }else {
  473. $comms = explode("RM", $c->comm);
  474. if(isset($comms[1])){
  475. $comm12_2 = 'RM '.$comms[1];
  476. $commV12_2 = floatval($comms[1]);
  477. }else {
  478. if($comms[0] != ''){
  479. $comm12_2 = $comms[0].'%';
  480. $commV12_2 = floatval($comms[0])/100;
  481. }
  482. }
  483. }
  484. }
  485. }
  486. }else if($c->contract =='12' && $c->packageR == "500"){
  487. if(strpos($c->ranges, '>') !== false) {
  488. $pieces = explode(">", $c->ranges);
  489. if($countD12_3 >= intval($pieces[1])){
  490. if(strpos($c->comm, 'RM') !== false) {
  491. $comm12_3 = '+ ' .$c->comm;
  492. $commV12_3 = '';
  493. $addRM12_3 = $c->comm;
  494. }else {
  495. $comms = explode("RM", $c->comm);
  496. if(isset($comms[1])){
  497. $comm12_3 = 'RM '.$comms[1];
  498. $commV12_3 = floatval($comms[1]);
  499. }else {
  500. if($comms[0] != ''){
  501. $comm12_3 = $comms[0].'%';
  502. $commV12_3 = floatval($comms[0])/100;
  503. }
  504. }
  505. }
  506. }
  507. }
  508. }else if($c->contract =='12' && $c->packageR == "1"){
  509. if(strpos($c->ranges, '>') !== false) {
  510. $pieces = explode(">", $c->ranges);
  511. if($countD12_4 >= intval($pieces[1])){
  512. if(strpos($c->comm, 'RM') !== false) {
  513. $comm12_4 = '+ ' .$c->comm;
  514. $commV12_4 = '';
  515. $addRM12_4 = $c->comm;
  516. }else {
  517. $comms = explode("RM", $c->comm);
  518. if(isset($comms[1])){
  519. $comm12_4 = 'RM '.$comms[1];
  520. $commV12_4 = floatval($comms[1]);
  521. }else {
  522. if($comms[0] != ''){
  523. $comm12_4 = $comms[0].'%';
  524. $commV12_4 = floatval($comms[0])/100;
  525. }
  526. }
  527. }
  528. }
  529. }
  530. }
  531. }
  532. // Category 10,30,50,100
  533. foreach ($data12_1 as $key => $d) {
  534. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  535. $address = ''; $name = '';
  536. if($customer->Form->type_application == 'R'){
  537. if($customer->street != ''){
  538. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  539. }else {
  540. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  541. }
  542. $name = $customer->name;
  543. }else if($customer->Form->type_application == 'B'){
  544. if($customer->unit_no != ''){
  545. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  546. }else {
  547. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  548. }
  549. $name = $customer->company_name;
  550. }
  551. $total = '';
  552. if($commV12_1 == ''){
  553. $total = $addRM12_1;
  554. }else {
  555. $total = number_format($d['retail_price']*$commV12_1,2);
  556. }
  557. $final[] = array(
  558. 'index' => $d['formT'],
  559. 'contract' => $d['contract'],
  560. 'wo' => $d['wo'],
  561. 'activation' => $d['activated_dt'],
  562. 'name' => $name,
  563. 'address' => $address,
  564. 'package' => $d['package'],
  565. 'retail_price' => 'RM '.$d['retail_price'],
  566. 'incentives1' => $comm12_1,
  567. 'incentives2' => $addRM12_1,
  568. 'total' => 'RM '.$total,
  569. 'claim' => $c['claim_dt'],
  570. );
  571. }
  572. foreach ($data24_1 as $key => $d) {
  573. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  574. $address = ''; $name = '';
  575. if($customer->Form->type_application == 'R'){
  576. if($customer->street != ''){
  577. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  578. }else {
  579. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  580. }
  581. $name = $customer->name;
  582. }else if($customer->Form->type_application == 'B'){
  583. if($customer->unit_no != ''){
  584. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  585. }else {
  586. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  587. }
  588. $name = $customer->company_name;
  589. }
  590. $total = '';
  591. if($commV24_1 == ''){
  592. $total = $addRM24_1;
  593. }else {
  594. $total = number_format(($d['retail_price']*$commV24_1) + floatval($addRM24_1),2);
  595. }
  596. $final[] = array(
  597. 'index' => $d['formT'],
  598. 'contract' => $d['contract'],
  599. 'wo' => $d['wo'],
  600. 'activation' => $d['activated_dt'],
  601. 'name' => $name,
  602. 'address' => $address,
  603. 'package' => $d['package'],
  604. 'retail_price' => 'RM '.$d['retail_price'],
  605. 'incentives1' => $comm24_1,
  606. 'incentives2' => $addRM24_1,
  607. 'total' => 'RM '.$total,
  608. 'claim' => $c['claim_dt'],
  609. );
  610. }
  611. // Category 300
  612. foreach ($data12_2 as $key => $d) {
  613. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  614. $address = ''; $name = '';
  615. if($customer->Form->type_application == 'R'){
  616. if($customer->street != ''){
  617. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  618. }else {
  619. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  620. }
  621. $name = $customer->name;
  622. }else if($customer->Form->type_application == 'B'){
  623. if($customer->unit_no != ''){
  624. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  625. }else {
  626. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  627. }
  628. $name = $customer->company_name;
  629. }
  630. $total = '';
  631. if($commV12_2 == ''){
  632. $total = $addRM12_2;
  633. }else {
  634. $total = number_format($d['retail_price']*$commV12_2,2);
  635. }
  636. $final[] = array(
  637. 'index' => $d['formT'],
  638. 'contract' => $d['contract'],
  639. 'wo' => $d['wo'],
  640. 'activation' => $d['activated_dt'],
  641. 'name' => $name,
  642. 'address' => $address,
  643. 'package' => $d['package'],
  644. 'retail_price' => 'RM '.$d['retail_price'],
  645. 'incentives1' => $commV12_2,
  646. 'incentives2' => $addRM12_2,
  647. 'total' => 'RM '.$total,
  648. 'claim' => $c['claim_dt'],
  649. );
  650. }
  651. foreach ($data24_2 as $key => $d) {
  652. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  653. $address = ''; $name = '';
  654. if($customer->Form->type_application == 'R'){
  655. if($customer->street != ''){
  656. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  657. }else {
  658. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  659. }
  660. $name = $customer->name;
  661. }else if($customer->Form->type_application == 'B'){
  662. if($customer->unit_no != ''){
  663. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  664. }else {
  665. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  666. }
  667. $name = $customer->company_name;
  668. }
  669. $total = '';
  670. if($commV24_2 == ''){
  671. $total = $addRM24_2;//number_format($d['retail_price']+$addRM24_2,2);
  672. }else {
  673. $total = number_format($d['retail_price']*$commV24_2,2);
  674. }
  675. $final[] = array(
  676. 'index' => $d['formT'],
  677. 'contract' => $d['contract'],
  678. 'wo' => $d['wo'],
  679. 'activation' => $d['activated_dt'],
  680. 'name' => $name,
  681. 'address' => $address,
  682. 'package' => $d['package'],
  683. 'retail_price' => 'RM '.$d['retail_price'],
  684. 'incentives1' => $commV24_2,
  685. 'incentives2' => $comm24_2,
  686. 'total' => 'RM '.$total,
  687. 'claim' => $c['claim_dt'],
  688. );
  689. }
  690. // Category 500
  691. foreach ($data12_3 as $key => $d) {
  692. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  693. $address = ''; $name = '';
  694. if($customer->Form->type_application == 'R'){
  695. if($customer->street != ''){
  696. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  697. }else {
  698. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  699. }
  700. $name = $customer->name;
  701. }else if($customer->Form->type_application == 'B'){
  702. if($customer->unit_no != ''){
  703. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  704. }else {
  705. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  706. }
  707. $name = $customer->company_name;
  708. }
  709. $total = '';
  710. if($commV12_3 == ''){
  711. $total = $addRM12_3;
  712. }else {
  713. $total = number_format($d['retail_price']*$commV12_3,2);
  714. }
  715. $final[] = array(
  716. 'index' => $d['formT'],
  717. 'contract' => $d['contract'],
  718. 'wo' => $d['wo'],
  719. 'activation' => $d['activated_dt'],
  720. 'name' => $name,
  721. 'address' => $address,
  722. 'package' => $d['package'],
  723. 'retail_price' => 'RM '.$d['retail_price'],
  724. 'incentives1' => $commV12_3,
  725. 'incentives2' => $addRM12_3,
  726. 'total' => 'RM '.$total,
  727. 'claim' => $c['claim_dt'],
  728. );
  729. }
  730. foreach ($data24_3 as $key => $d) {
  731. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  732. $address = ''; $name = '';
  733. if($customer->Form->type_application == 'R'){
  734. if($customer->street != ''){
  735. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  736. }else {
  737. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  738. }
  739. $name = $customer->name;
  740. }else if($customer->Form->type_application == 'B'){
  741. if($customer->unit_no != ''){
  742. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  743. }else {
  744. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  745. }
  746. $name = $customer->company_name;
  747. }
  748. $total = '';
  749. if($commV24_3 == ''){
  750. $total = $addRM24_3; //number_format($d['retail_price']+$addRM24_3,2);
  751. }else {
  752. $total = number_format($d['retail_price']*$commV24_3,2);
  753. }
  754. $final[] = array(
  755. 'index' => $d['formT'],
  756. 'contract' => $d['contract'],
  757. 'wo' => $d['wo'],
  758. 'activation' => $d['activated_dt'],
  759. 'name' => $name,
  760. 'address' => $address,
  761. 'package' => $d['package'],
  762. 'retail_price' => 'RM '.$d['retail_price'],
  763. 'incentives1' => $commV24_3,
  764. 'incentives2' => $comm24_3,
  765. 'total' => 'RM '.$total,
  766. 'claim' => $c['claim_dt'],
  767. );
  768. }
  769. // Category 1
  770. foreach ($data12_4 as $key => $d) {
  771. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  772. $address = ''; $name = '';
  773. if($customer->Form->type_application == 'R'){
  774. if($customer->street != ''){
  775. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  776. }else {
  777. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  778. }
  779. $name = $customer->name;
  780. }else if($customer->Form->type_application == 'B'){
  781. if($customer->unit_no != ''){
  782. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  783. }else {
  784. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  785. }
  786. $name = $customer->company_name;
  787. }
  788. $total = '';
  789. if($commV12_4 == ''){
  790. $total = $addRM12_4;
  791. }else {
  792. $total = number_format($d['retail_price']*$commV12_4,2);
  793. }
  794. $final[] = array(
  795. 'index' => $d['formT'],
  796. 'contract' => $d['contract'],
  797. 'wo' => $d['wo'],
  798. 'activation' => $d['activated_dt'],
  799. 'name' => $name,
  800. 'address' => $address,
  801. 'package' => $d['package'],
  802. 'retail_price' => 'RM '.$d['retail_price'],
  803. 'incentives1' => $commV12_4,
  804. 'incentives2' => $addRM12_4,
  805. 'total' => 'RM '.$total,
  806. 'claim' => $c['claim_dt'],
  807. );
  808. }
  809. foreach ($data24_4 as $key => $d) {
  810. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  811. $address = ''; $name = '';
  812. if($customer->Form->type_application == 'R'){
  813. if($customer->street != ''){
  814. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  815. }else {
  816. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  817. }
  818. $name = $customer->name;
  819. }else if($customer->Form->type_application == 'B'){
  820. if($customer->unit_no != ''){
  821. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  822. }else {
  823. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  824. }
  825. $name = $customer->company_name;
  826. }
  827. $total = '';
  828. if($commV24_4 == ''){
  829. $total = $addRM24_4; //number_format($d['retail_price']+$addRM24_4,2);
  830. }else {
  831. $total = number_format($d['retail_price']*$commV24_4,2);
  832. }
  833. $final[] = array(
  834. 'index' => $d['formT'],
  835. 'contract' => $d['contract'],
  836. 'wo' => $d['wo'],
  837. 'activation' => $d['activated_dt'],
  838. 'name' => $name,
  839. 'address' => $address,
  840. 'package' => $d['package'],
  841. 'retail_price' => 'RM '.$d['retail_price'],
  842. 'incentives1' => $commV24_4,
  843. 'incentives2' => $comm24_4,
  844. 'total' => 'RM '.$total,
  845. 'claim' => $c['claim_dt'],
  846. );
  847. }
  848. }else {
  849. foreach ($dataCB as $c){
  850. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  851. $address = ''; $name = '';
  852. if($customer->Form->type_application == 'R'){
  853. if($customer->street != ''){
  854. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  855. }else {
  856. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  857. }
  858. $name = $customer->name;
  859. }else if($customer->Form->type_application == 'B'){
  860. if($customer->unit_no != ''){
  861. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  862. }else {
  863. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  864. }
  865. $name = $customer->company_name;
  866. }
  867. $final[] = array(
  868. 'index' => $c['formT'],
  869. 'contract' => $c['contract'],
  870. 'wo' => $c['wo'],
  871. 'activation' => $c['activated_dt'],
  872. 'name' => $name,
  873. 'address' => $address,
  874. 'package' => $c['package'],
  875. 'retail_price' => 'RM '.$c['retail_price'],
  876. 'incentives1' => '',
  877. 'incentives2' => '',
  878. 'total' => '',
  879. 'claim' => $c['claim_dt'],
  880. );
  881. }
  882. }
  883. return $final;
  884. }
  885. public function filterclaim($company,$year,$month,$app)
  886. {
  887. $dataR = array(); $dataB = array(); $combineData = array();
  888. $nested_data = array();
  889. if($year!='null' && $month!='null' && $app=='null'){
  890. $dataR = $this->returnDataR($company,$year,$month);
  891. $dataB = $this->returnDataB($company,$year,$month);
  892. foreach($dataR as $r){
  893. $combineData[] = $r;
  894. }
  895. foreach($dataB as $b){
  896. $combineData[] = $b;
  897. }
  898. $i = 0;
  899. if(!empty($combineData)){
  900. foreach ($combineData as $c){
  901. $i++;
  902. array_push($nested_data, array(
  903. 'index' => $c['index'],
  904. 'contract' => $c['contract'],
  905. 'wo' => $c['wo'],
  906. 'activated_dt' => $c['activation'],
  907. 'name' => $c['name'],
  908. 'address' => $c['address'],
  909. 'package' => $c['package'],
  910. 'retail_price' => $c['retail_price'],
  911. 'incentives1' => $c['incentives1'],
  912. 'incentives2' => $c['incentives2'],
  913. 'total' => $c['total'],
  914. 'claimed' => $c['claim'],
  915. ));
  916. }
  917. }
  918. }else if($year=='null' && $month=='null' && $app!='null'){
  919. if($app == 'Residential'){
  920. $dataR = $this->returnDataR($company,$year,$month);
  921. }else if($app == 'Business'){
  922. $dataB = $this->returnDataB($company,$year,$month);
  923. }
  924. foreach($dataR as $r){
  925. $combineData[] = $r;
  926. }
  927. foreach($dataB as $b){
  928. $combineData[] = $b;
  929. }
  930. $i = 0;
  931. if(!empty($combineData)){
  932. foreach ($combineData as $c){
  933. $i++;
  934. array_push($nested_data, array(
  935. 'index' => $c['index'],
  936. 'contract' => $c['contract'],
  937. 'wo' => $c['wo'],
  938. 'activated_dt' => $c['activation'],
  939. 'name' => $c['name'],
  940. 'address' => $c['address'],
  941. 'package' => $c['package'],
  942. 'retail_price' => $c['retail_price'],
  943. 'incentives1' => $c['incentives1'],
  944. 'incentives2' => $c['incentives2'],
  945. 'total' => $c['total'],
  946. 'claimed' => $c['claim'],
  947. ));
  948. }
  949. }
  950. }else if($year!='null' && $month!='null' && $app!='null'){
  951. if($app == 'Residential'){
  952. $dataR = $this->returnDataR($company,$year,$month);
  953. }else if($app == 'Business'){
  954. $dataB = $this->returnDataB($company,$year,$month);
  955. }
  956. foreach($dataR as $r){
  957. $combineData[] = $r;
  958. }
  959. foreach($dataB as $b){
  960. $combineData[] = $b;
  961. }
  962. $i = 0;
  963. if(!empty($combineData)){
  964. foreach ($combineData as $c){
  965. $i++;
  966. array_push($nested_data, array(
  967. 'index' => $c['index'],
  968. 'contract' => $c['contract'],
  969. 'wo' => $c['wo'],
  970. 'activated_dt' => $c['activation'],
  971. 'name' => $c['name'],
  972. 'address' => $c['address'],
  973. 'package' => $c['package'],
  974. 'retail_price' => $c['retail_price'],
  975. 'incentives1' => $c['incentives1'],
  976. 'incentives2' => $c['incentives2'],
  977. 'total' => $c['total'],
  978. 'claimed' => $c['claim'],
  979. ));
  980. }
  981. }
  982. }
  983. return \DataTables::of($nested_data)->make(true);
  984. }
  985. public function exportPDFClaim($company,$year,$month,$app) {
  986. $final = array();
  987. $com = Company::where('_id',$company)->first();
  988. $dataR = array(); $dataB = array(); $combineData = array();
  989. if($year!='null' && $month!='null' && $app=='null'){
  990. $dataR = $this->returnDataR($company,$year,$month);
  991. $dataB = $this->returnDataB($company,$year,$month);
  992. foreach($dataR as $r){
  993. $combineData[] = $r;
  994. }
  995. foreach($dataB as $b){
  996. $combineData[] = $b;
  997. }
  998. $i = 0;
  999. $nested_data = array();
  1000. if(!empty($combineData)){
  1001. foreach ($combineData as $c){
  1002. $i++;
  1003. array_push($final, array(
  1004. 'index' => $c['index'],
  1005. 'contract' => $c['contract'],
  1006. 'wo' => $c['wo'],
  1007. 'activated_dt' => $c['activation'],
  1008. 'name' => $c['name'],
  1009. 'address' => $c['address'],
  1010. 'package' => $c['package'],
  1011. 'retail_price' => $c['retail_price'],
  1012. 'incentives1' => $c['incentives1'],
  1013. 'incentives2' => $c['incentives2'],
  1014. 'total' => $c['total'],
  1015. 'claimed' => $c['claim'],
  1016. ));
  1017. }
  1018. }
  1019. $totals = 0;
  1020. foreach($final as $f){
  1021. $totals += floatval(str_replace('RM ', '', $f['total']));
  1022. }
  1023. $pdf = PDF::loadView('v3.pdf.agent-claim', compact('final', 'month', 'year','com','totals'));
  1024. $pdf->setPaper('A4', 'landscape');
  1025. $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  1026. return $pdf->download( $pdfName );
  1027. }else if($year!='null' && $month!='null' && $app!='null'){
  1028. if($app == 'Residential'){
  1029. $dataR = $this->returnDataR($company,$year,$month);
  1030. }else if($app == 'Business'){
  1031. $dataB = $this->returnDataB($company,$year,$month);
  1032. }
  1033. foreach($dataR as $r){
  1034. $combineData[] = $r;
  1035. }
  1036. foreach($dataB as $b){
  1037. $combineData[] = $b;
  1038. }
  1039. $i = 0;
  1040. $nested_data = array();
  1041. if(!empty($combineData)){
  1042. foreach ($combineData as $c){
  1043. $i++;
  1044. array_push($final, array(
  1045. 'index' => $c['index'],
  1046. 'contract' => $c['contract'],
  1047. 'wo' => $c['wo'],
  1048. 'activated_dt' => $c['activation'],
  1049. 'name' => $c['name'],
  1050. 'address' => $c['address'],
  1051. 'package' => $c['package'],
  1052. 'retail_price' => $c['retail_price'],
  1053. 'incentives1' => $c['incentives1'],
  1054. 'incentives2' => $c['incentives2'],
  1055. 'total' => $c['total'],
  1056. 'claimed' => $c['claim'],
  1057. ));
  1058. }
  1059. }
  1060. $totals = 0;
  1061. foreach($final as $f){
  1062. $totals += floatval(str_replace('RM ', '', $f['total']));
  1063. }
  1064. $pdf = PDF::loadView('v3.pdf.agent-claim', compact('final', 'month', 'year','com','totals'));
  1065. $pdf->setPaper('A4', 'landscape');
  1066. $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  1067. return $pdf->download( $pdfName );
  1068. }
  1069. }
  1070. }