activated_my == $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::where('_id', $d['customer_id'])->first(); $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $customer->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::where('_id', $d['customer_id'])->first(); $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $customer->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::where('_id', $c['customer_id'])->first(); $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $final[] = array( 'index' => $c['formT'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activation' => $c['activated_dt'], 'name' => $customer->name, 'address' => $address, 'package' => $c['package'], 'retail_price' => 'RM '.$c['retail_price'], 'incentives1' => '', 'incentives2' => '', 'total' => '', 'claim' => $c['claim_dt'], ); } } return $final; } /** Get Claim B **/ public function returnDataB(array $dataBB, $year,$month){ $dataCB = $dataBB; $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){ 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"){ $countD24_2[] = $dc; }else if($dc->contract == "24" && $dc->package == "500"){ $countD24_3[] = $dc; }else if($dc->contract == "24" && $dc->package == "1"){ $countD24_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_2 = 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 = ''; $addRM24_2 = $c->comm; }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 = ''; $addRM24_3 = $c->comm; }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 = ''; $addRM24_4 = $c->comm; }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[1])){ if(strpos($c->comm, 'RM') !== false) { $comm24_1 = '+ ' .$c->comm; $commV24_1 = ''; $addRM24_1 = $c->comm; }else { $comms = explode("RM", $c->comm); if(isset($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){ $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(isset($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; } } } } } } /*** 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::where('_id', $d['customer_id'])->first(); $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $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' => $customer->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::where('_id', $d['customer_id'])->first(); $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $total = ''; if($commV24_1 == ''){ $total = $addRM24_1; }else { $total = number_format($d['retail_price']*$commV24_1,2); } $final[] = array( 'index' => $d['formT'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activated_dt'], 'name' => $customer->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::where('_id', $d['customer_id'])->first(); $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $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' => $customer->name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm12_2, 'incentives2' => $addRM12_2, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } foreach ($data24_2 as $key => $d) { $customer = Subscriber::where('_id', $d['customer_id'])->first(); $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $total = ''; if($commV24_2 == ''){ $total = $addRM24_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' => $customer->name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm24_2, 'incentives2' => $addRM24_2, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } // Category 500 foreach ($data12_3 as $key => $d) { $customer = Subscriber::where('_id', $d['customer_id'])->first(); $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $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' => $customer->name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm12_3, 'incentives2' => $addRM12_3, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } foreach ($data24_3 as $key => $d) { $customer = Subscriber::where('_id', $d['customer_id'])->first(); $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $total = ''; if($commV24_3 == ''){ $total = $addRM24_3; }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' => $customer->name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm24_3, 'incentives2' => $addRM24_3, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } // Category 1 foreach ($data12_4 as $key => $d) { $customer = Subscriber::where('_id', $d['customer_id'])->first(); $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $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' => $customer->name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm12_4, 'incentives2' => $addRM12_4, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } foreach ($data24_4 as $key => $d) { $customer = Subscriber::where('_id', $d['customer_id'])->first(); $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $total = ''; if($commV24_4 == ''){ $total = $addRM24_4; }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' => $customer->name, 'address' => $address, 'package' => $d['package'], 'retail_price' => 'RM '.$d['retail_price'], 'incentives1' => $comm24_4, 'incentives2' => $addRM24_4, 'total' => 'RM '.$total, 'claim' => $c['claim_dt'], ); } }else { foreach ($dataCB as $c){ $customer = Subscriber::where('_id', $c['customer_id'])->first(); $address = $customer->company_name.', '.$customer->address.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $final[] = array( 'index' => $c['formT'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activation' => $c['activated_dt'], 'name' => $customer->name, 'address' => $address, 'package' => $c['package'], 'retail_price' => 'RM '.$c['retail_price'], 'incentives1' => '', 'incentives2' => '', 'total' => '', 'claim' => $c['claim_dt'], ); } } return $final; } //Show claim list by company public function mClaimList($company) { $id = Auth::guard('ms')->id(); $user = Staff::with('StaffDetail')->find($id); $dealer_claimAll = DealerClaim::where('dealer',$company)->get(); $dealer_claimR = DealerClaim::where('formT','R')->where('dealer',$company)->get()->toArray(); $dealer_claimB = DealerClaim::where('formT','B')->where('dealer',$company)->get()->toArray(); foreach ($dealer_claimAll as $c){ $customer = Subscriber::where('_id', $c['customer_id'])->first(); $address = $customer->unit_no.', '.$customer->building.', '.$customer->street.', '.$customer->postcode.', '.$customer->city.', '.$customer->state; $final[] = array( 'index' => $c['formT'], 'contract' => $c['contract'], 'wo' => $c['wo'], 'activation' => $c['activated_dt'], 'name' => $customer->name, 'address' => $address, 'package' => $c['package'], 'retail_price' => 'RM '.$c['retail_price'], 'incentives1' => '', 'incentives2' => '', 'total' => '', 'claim' => $c['claim_dt'], ); } dd($dealer_claimR); $dataR = $this->returnDataR($dealer_claimR, 'null','null'); $dataB = $this->returnDataB($dealer_claimB, 'null','null'); $combineData = array(); foreach($dataR as $r){ $combineData[] = $r; } foreach($dataB as $b){ $combineData[] = $b; } dd($dataR); $i = 0; $nested_data = array(); if(!empty($combineData)){ foreach ($combineData as $c){ $i++; array_push($nested_data, array( 'index' => $i.$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'], 'claim' => $c['claim'], )); } } return \DataTables::of($nested_data)->make(true); } }