orderBy('activated_dt','desc')->get(); foreach ($dealer_claimAll as $c){ $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $i++; array_push($nested_data, array( 'index' => $c->formT, 'contract' => $c->contract, 'wo' => $c->wo, 'activated_dt' => $c->activated_dt, 'name' => $name, 'address' => $address, 'package' => $c->package, 'retail_price' => 'RM '.$c->retail_price, 'incentives1' => '', 'incentives2' => '', 'total' => '', 'claimed' => $c->laim_dt, 'action' => 'null', )); } return \DataTables::of($nested_data)->make(true); } /* * Get Claim resident * * @return json */ public function returnDataR($company,$year,$month) { $final = array(); $dataCR = DealerClaim::where('formT','R')->where('dealer',$company)->get(); // Month & Year $mY = ''; if($year != 'null' && $month != 'null'){ $mY = $month.'/'.$year; } if($mY != ''){ $data12 = array(); $data24 = array(); $countD12 = 0; $countD24 = 0; foreach($dataCR as $dc){ if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){ if($dc->contract == "12"){ $data12[] = $dc; }else if($dc->contract == "24"){ $data24[] = $dc; } } } $countD24 = count($data24); $countD12 = count($data12); $comm = Commission::where('formT','R')->get(); $commV12 = 0; $commV24 = 0; $comm12 = ''; $comm24 = ''; foreach($comm as $c){ if($c->contract =='12'){ if(strpos($c->ranges, '>') !== false) { $pieces = explode(">", $c->ranges); if($countD12 >= intval($pieces[1])){ $commV12 = floatval($c->comm)/100; $comm12 = $c->comm.'%'; } } if(strpos($c->ranges,'-') !== false){ $pieces = explode("-", $c->ranges); if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){ $commV12 = floatval($c->comm)/100; $comm12 = $c->comm.'%'; } } }else if($c->contract =='24'){ // Contract => 24 if($countD24 != 0){ if(strpos($c->ranges, '>') !== false) { $pieces = explode(">", $c->ranges); if($countD24 > intval($pieces[1])){ $commV24 = floatval($c->comm)/100; $comm24 = $c->comm.'%'; } } if(strpos($c->ranges,'-') !== false){ $pieces = explode("-", $c->ranges); if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){ $commV24 = floatval($c->comm)/100; $comm24 = $c->comm.'%'; } } } } } foreach ($data12 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm12, 'incentives2' => '', 'total' => 'RM '.number_format($d['retail_price']*$commV12,2), 'claim' => $d['claim_dt'], ); } foreach ($data24 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm24, 'incentives2' => '', 'total' => 'RM '.number_format($d['retail_price']*$commV24,2), 'claim' => $d['claim_dt'], ); } }else { foreach ($dataCR as $c){ $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $final[] = array( 'index' => $c['formT'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activation' => $c['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $c['package'], 'retail_price' => 'RM '.$c['retail_price'], 'incentives1' => '', 'incentives2' => '', 'total' => '', 'claim' => $c['claim_dt'], ); } } return $final; } // Get Claim Business public function returnDataB($company,$year,$month){ $dataCB = DealerClaim::where('formT','B')->where('dealer',$company)->get(); $final = array(); // Month & Year $mY = ''; if($year != 'null' && $month != 'null'){ $mY = $month.'/'.$year; } if($mY != ''){ /** Contract 12 // 1=>10-100 2=>300 3=>500 4=>1 **/ $data12_1 = array(); $data12_2 = array(); $data12_3 = array(); $data12_4 = array(); $countD12_1 = 0; $countD12_2 = 0; $countD12_3 = 0; $countD12_4 = 0; /** Contract 24 // 1=>10-100 2=>300 3=>500 4=>1 **/ $data24_1 = array(); $data24_2 = array(); $data24_3 = array(); $data24_4 = array(); $countD24_1 = 0; $countD24_2 = 0; $countD24_3 = 0; $countD24_4 = 0; foreach($dataCB as $dc){ if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY){ if($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){ $data12_1[] = $dc; }else if($dc->contract == "12" && $dc->package == "300"){ $data12_2[] = $dc; }else if($dc->contract == "12" && $dc->package == "500"){ $data12_3[] = $dc; }else if($dc->contract == "12" && $dc->package == "1"){ $data12_4[] = $dc; }else if($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){ $data24_1[] = $dc; }else if($dc->contract == "24" && $dc->package == "300"){ $data24_2[] = $dc; }else if($dc->contract == "24" && $dc->package == "500"){ $data24_3[] = $dc; }else if($dc->contract == "24" && $dc->package == "1"){ $data24_4[] = $dc; } } } $countD12_1 = count($data12_1); $countD12_2 = count($data12_2); $countD12_3 = count($data12_3); $countD12_4 = count($data12_4); $countD24_1 = count($data24_1); $countD24_2 = count($data24_2); $countD24_3 = count($data24_3); $countD24_4 = count($data24_4); $comm = Commission::where('formT','B')->get(); $commV12_1 = 0; $commV12_2 = 0; $commV12_3 = 0; $commV12_4 = 0; $commV24_1 = 0; $commV24_2 = 0; $commV24_3 = 0; $commV24_4 = 0; $comm12_1 = ''; $comm12_2 = ''; $comm12_3 = ''; $comm12_4 = ''; $comm24_1 = ''; $comm24_2 = ''; $comm24_3 = ''; $comm24_4 = ''; $addRM12_1 = ''; $addRM12_2 = ''; $addRM12_3 = ''; $addRM12_4 = ''; $addRM24_1 = ''; $addRM24_2 = ''; $addRM24_3 = ''; $addRM24_4 = ''; foreach($comm as $c){ /*** Contract 24 **/ if($c->contract =='24' && $c->packageR == "300"){ if(strpos($c->ranges, '>') !== false) { $pieces = explode(">", $c->ranges); if($countD24_2 >= intval($pieces[1])){ if(strpos($c->comm, 'RM') !== false) { $comm24_2 = '+ ' .$c->comm; $commV24_2 = ''; $comms = explode("RM", $c->comm); $addRM24_2 = floatval($comms[1]); }else { $comms = explode("RM", $c->comm); if(isset($comms[1])){ $comm24_2 = 'RM '.$comms[1]; $commV24_2 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm24_2 = $comms[0].'%'; $commV24_2 = floatval($comms[0])/100; } } } } } }else if($c->contract =='24' && $c->packageR == "500"){ if(strpos($c->ranges, '>') !== false) { $pieces = explode(">", $c->ranges); if($countD24_3 >= intval($pieces[1])){ if(strpos($c->comm, 'RM') !== false) { $comm24_3 = '+ ' .$c->comm; $commV24_3 = ''; $comms = explode("RM", $c->comm); $addRM24_3 = floatval($comms[1]); }else { $comms = explode("RM", $c->comm); if(isset($comms[1])){ $comm24_3 = 'RM '.$comms[1]; $commV24_3 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm24_3 = $comms[0].'%'; $commV24_3 = floatval($comms[0])/100; } } } } } }else if($c->contract =='24' && $c->packageR == "1"){ if(strpos($c->ranges, '>') !== false) { $pieces = explode(">", $c->ranges); if($countD24_4 >= intval($pieces[1])){ if(strpos($c->comm, 'RM') !== false) { $comm24_4 = '+ ' .$c->comm; $commV24_4 = ''; $comms = explode("RM", $c->comm); $addRM24_4 = floatval($comms[1]); }else { $comms = explode("RM", $c->comm); if(isset($comms[1])){ $comm24_4 = 'RM '.$comms[1]; $commV24_4 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm24_4 = $comms[0].'%'; $commV24_4 = floatval($comms[0])/100; } } } } } }else if($c->contract =='24' && $c->packageR == "10,30,50,100"){ if(strpos($c->ranges,'-') !== false){ $pieces = explode("-", $c->ranges); if($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])){ if(strpos($c->comm, 'RM') !== false) { $comm24_1 = '+ ' .$c->comm; $commV24_1 = ''; $addRM24_1 = $c->comm; }else { $comms = explode("RM", $c->comm); if(!empty($comms[1])){ $comm24_1 = 'RM '.$comms[1]; $commV24_1 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm24_1 = $comms[0].'%'; $commV24_1 = floatval($comms[0])/100; } } } } } if(strpos($c->ranges, '>') !== false) { $pieces1 = explode(">", $c->ranges); if($countD24_1 >= intval($pieces1[1])){ if(strpos($c->comm, "RM") === true) { $comm24_1 = '+ ' .$c->comm; $commV24_1 = ''; $addRM24_1 = $c->comm; }else { $comms = explode("RM", $c->comm); if(empty($comms[1])){ $comm24_1 = 'RM '.$comms[1]; $commV24_1 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm24_1 = str_replace ('+ ','',$comms[0]).'%'; $commV24_1 = floatval($comms[0])/100; $addRM24_1 = $comms[1]; } } } } } } /*** Contract 12 **/ else if($c->contract =='12' && $c->packageR == "10,30,50,100"){ if(strpos($c->ranges, '>') !== false) { $pieces = explode(">", $c->ranges); if($countD12_1 >= intval($pieces[1])){ if(strpos($c->comm, 'RM') !== false) { $comm12_1 = '+ ' .$c->comm; $commV12_1 = ''; $addRM12_1 = $c->comm; }else { $comms = explode("RM", $c->comm); if(isset($comms[1])){ $comm12_1 = 'RM '.$comms[1]; $commV12_1 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm12_1 = $comms[0].'%'; $commV12_1 = floatval($comms[0])/100; } } } } } if(strpos($c->ranges,'-') !== false){ $pieces = explode("-", $c->ranges); if($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])){ if(strpos($c->comm, 'RM') !== false) { $comm12_1 = '+ ' .$c->comm; $commV12_1 = ''; $addRM12_1 = $c->comm; }else { $comms = explode("RM", $c->comm); if(isset($comms[1])){ $comm12_1 = 'RM '.$comms[1]; $commV12_1 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm12_1 = $comms[0].'%'; $commV12_1 = floatval($comms[0])/100; } } } } } }else if($c->contract =='12' && $c->packageR == "300"){ if(strpos($c->ranges, '>') !== false) { $pieces = explode(">", $c->ranges); if($countD12_2 >= intval($pieces[1])){ if(strpos($c->comm, 'RM') !== false) { $comm12_2 = '+ ' .$c->comm; $commV12_2 = ''; $addRM12_2 = $c->comm; }else { $comms = explode("RM", $c->comm); if(isset($comms[1])){ $comm12_2 = 'RM '.$comms[1]; $commV12_2 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm12_2 = $comms[0].'%'; $commV12_2 = floatval($comms[0])/100; } } } } } }else if($c->contract =='12' && $c->packageR == "500"){ if(strpos($c->ranges, '>') !== false) { $pieces = explode(">", $c->ranges); if($countD12_3 >= intval($pieces[1])){ if(strpos($c->comm, 'RM') !== false) { $comm12_3 = '+ ' .$c->comm; $commV12_3 = ''; $addRM12_3 = $c->comm; }else { $comms = explode("RM", $c->comm); if(isset($comms[1])){ $comm12_3 = 'RM '.$comms[1]; $commV12_3 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm12_3 = $comms[0].'%'; $commV12_3 = floatval($comms[0])/100; } } } } } }else if($c->contract =='12' && $c->packageR == "1"){ if(strpos($c->ranges, '>') !== false) { $pieces = explode(">", $c->ranges); if($countD12_4 >= intval($pieces[1])){ if(strpos($c->comm, 'RM') !== false) { $comm12_4 = '+ ' .$c->comm; $commV12_4 = ''; $addRM12_4 = $c->comm; }else { $comms = explode("RM", $c->comm); if(isset($comms[1])){ $comm12_4 = 'RM '.$comms[1]; $commV12_4 = floatval($comms[1]); }else { if($comms[0] != ''){ $comm12_4 = $comms[0].'%'; $commV12_4 = floatval($comms[0])/100; } } } } } } } // Category 10,30,50,100 foreach ($data12_1 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $total = ''; if($commV12_1 == ''){ $total = $addRM12_1; }else { $total = number_format($d['retail_price']*$commV12_1,2); } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm12_1, 'incentives2' => $addRM12_1, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } foreach ($data24_1 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $total = ''; if($commV24_1 == ''){ $total = $addRM24_1; }else { $total = number_format(($d['retail_price']*$commV24_1) + floatval($addRM24_1),2); } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm24_1, 'incentives2' => $addRM24_1, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } // Category 300 foreach ($data12_2 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $total = ''; if($commV12_2 == ''){ $total = $addRM12_2; }else { $total = number_format($d['retail_price']*$commV12_2,2); } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $commV12_2, 'incentives2' => $addRM12_2, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } foreach ($data24_2 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $total = ''; if($commV24_2 == ''){ $total = $addRM24_2;//number_format($d['retail_price']+$addRM24_2,2); }else { $total = number_format($d['retail_price']*$commV24_2,2); } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $commV24_2, 'incentives2' => $comm24_2, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } // Category 500 foreach ($data12_3 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $total = ''; if($commV12_3 == ''){ $total = $addRM12_3; }else { $total = number_format($d['retail_price']*$commV12_3,2); } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $commV12_3, 'incentives2' => $addRM12_3, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } foreach ($data24_3 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $total = ''; if($commV24_3 == ''){ $total = $addRM24_3; //number_format($d['retail_price']+$addRM24_3,2); }else { $total = number_format($d['retail_price']*$commV24_3,2); } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $commV24_3, 'incentives2' => $comm24_3, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } // Category 1 foreach ($data12_4 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $total = ''; if($commV12_4 == ''){ $total = $addRM12_4; }else { $total = number_format($d['retail_price']*$commV12_4,2); } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $commV12_4, 'incentives2' => $addRM12_4, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } foreach ($data24_4 as $key => $d) { $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $total = ''; if($commV24_4 == ''){ $total = $addRM24_4; //number_format($d['retail_price']+$addRM24_4,2); }else { $total = number_format($d['retail_price']*$commV24_4,2); } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $commV24_4, 'incentives2' => $comm24_4, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } }else { foreach ($dataCB as $c){ $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first(); $address = ''; $name = ''; if($customer->Form->type_application == 'R'){ if($customer->street != ''){ $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->name; }else if($customer->Form->type_application == 'B'){ if($customer->unit_no != ''){ $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; }else { $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state; } $name = $customer->company_name; } $final[] = array( 'index' => $c['formT'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activation' => $c['activated_dt'], 'name' => $name, 'address' => $address, 'package' => $c['package'], 'retail_price' => 'RM '.$c['retail_price'], 'incentives1' => '', 'incentives2' => '', 'total' => '', 'claim' => $c['claim_dt'], ); } } return $final; } public function filterclaim($company,$year,$month,$app) { $dataR = array(); $dataB = array(); $combineData = array(); $nested_data = array(); if($year!='null' && $month!='null' && $app=='null'){ $dataR = $this->returnDataR($company,$year,$month); $dataB = $this->returnDataB($company,$year,$month); foreach($dataR as $r){ $combineData[] = $r; } foreach($dataB as $b){ $combineData[] = $b; } $i = 0; if(!empty($combineData)){ foreach ($combineData as $c){ $i++; array_push($nested_data, array( 'index' => $c['index'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activated_dt' => $c['activation'], 'name' => $c['name'], 'address' => $c['address'], 'package' => $c['package'], 'retail_price' => $c['retail_price'], 'incentives1' => $c['incentives1'], 'incentives2' => $c['incentives2'], 'total' => $c['total'], 'claimed' => $c['claim'], )); } } }else if($year=='null' && $month=='null' && $app!='null'){ if($app == 'Residential'){ $dataR = $this->returnDataR($company,$year,$month); }else if($app == 'Business'){ $dataB = $this->returnDataB($company,$year,$month); } foreach($dataR as $r){ $combineData[] = $r; } foreach($dataB as $b){ $combineData[] = $b; } $i = 0; if(!empty($combineData)){ foreach ($combineData as $c){ $i++; array_push($nested_data, array( 'index' => $c['index'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activated_dt' => $c['activation'], 'name' => $c['name'], 'address' => $c['address'], 'package' => $c['package'], 'retail_price' => $c['retail_price'], 'incentives1' => $c['incentives1'], 'incentives2' => $c['incentives2'], 'total' => $c['total'], 'claimed' => $c['claim'], )); } } }else if($year!='null' && $month!='null' && $app!='null'){ if($app == 'Residential'){ $dataR = $this->returnDataR($company,$year,$month); }else if($app == 'Business'){ $dataB = $this->returnDataB($company,$year,$month); } foreach($dataR as $r){ $combineData[] = $r; } foreach($dataB as $b){ $combineData[] = $b; } $i = 0; if(!empty($combineData)){ foreach ($combineData as $c){ $i++; array_push($nested_data, array( 'index' => $c['index'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activated_dt' => $c['activation'], 'name' => $c['name'], 'address' => $c['address'], 'package' => $c['package'], 'retail_price' => $c['retail_price'], 'incentives1' => $c['incentives1'], 'incentives2' => $c['incentives2'], 'total' => $c['total'], 'claimed' => $c['claim'], )); } } } return \DataTables::of($nested_data)->make(true); } public function exportPDFClaim($company,$year,$month,$app) { $final = array(); $com = Company::where('_id',$company)->first(); $dataR = array(); $dataB = array(); $combineData = array(); if($year!='null' && $month!='null' && $app=='null'){ $dataR = $this->returnDataR($company,$year,$month); $dataB = $this->returnDataB($company,$year,$month); foreach($dataR as $r){ $combineData[] = $r; } foreach($dataB as $b){ $combineData[] = $b; } $i = 0; $nested_data = array(); if(!empty($combineData)){ foreach ($combineData as $c){ $i++; array_push($final, array( 'index' => $c['index'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activated_dt' => $c['activation'], 'name' => $c['name'], 'address' => $c['address'], 'package' => $c['package'], 'retail_price' => $c['retail_price'], 'incentives1' => $c['incentives1'], 'incentives2' => $c['incentives2'], 'total' => $c['total'], 'claimed' => $c['claim'], )); } } $totals = 0; foreach($final as $f){ $totals += floatval(str_replace('RM ', '', $f['total'])); } $pdf = PDF::loadView('v3.pdf.agent-claim', compact('final', 'month', 'year','com','totals')); $pdf->setPaper('A4', 'landscape'); $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf'; return $pdf->download( $pdfName ); }else if($year!='null' && $month!='null' && $app!='null'){ if($app == 'Residential'){ $dataR = $this->returnDataR($company,$year,$month); }else if($app == 'Business'){ $dataB = $this->returnDataB($company,$year,$month); } foreach($dataR as $r){ $combineData[] = $r; } foreach($dataB as $b){ $combineData[] = $b; } $i = 0; $nested_data = array(); if(!empty($combineData)){ foreach ($combineData as $c){ $i++; array_push($final, array( 'index' => $c['index'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activated_dt' => $c['activation'], 'name' => $c['name'], 'address' => $c['address'], 'package' => $c['package'], 'retail_price' => $c['retail_price'], 'incentives1' => $c['incentives1'], 'incentives2' => $c['incentives2'], 'total' => $c['total'], 'claimed' => $c['claim'], )); } } $totals = 0; foreach($final as $f){ $totals += floatval(str_replace('RM ', '', $f['total'])); } $pdf = PDF::loadView('v3.pdf.agent-claim', compact('final', 'month', 'year','com','totals')); $pdf->setPaper('A4', 'landscape'); $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf'; return $pdf->download( $pdfName ); } } }