id(); $user = Staff::with('StaffDetail')->find($id); $finalD1 = array(); $finalD2 = array(); $finalD3 = array(); $finalD4 = array(); $finalD5 = array(); $finalD6 = array(); $jan = array(); $feb = array(); $mac = array(); $april = array(); $may = array(); $jun = array(); $july = array(); $august = array(); $sep = array(); $oct = array(); $nov = array(); $dec = array(); $jan1 = array(); $feb1 = array(); $mac1 = array(); $april1 = array(); $may1 = array(); $jun1 = array(); $july1 = array(); $august1 = array(); $sep1 = array(); $oct1 = array(); $nov1 = array(); $dec1 = array(); $de = Form::all(); foreach ($de as $key => $d) { if (!empty($d->dealer_id)) { $finalD1[] = $d; $mY = Carbon::parse($d->created_at)->format('m/Y'); if ($mY == '01/2019') { $jan[] = $d; } else if ($mY == '02/2019') { $feb[] = $d; } else if ($mY == '03/2019') { $mac[] = $d; } else if ($mY == '04/2019') { $april[] = $d; } else if ($mY == '05/2019') { $may[] = $d; } else if ($mY == '06/2019') { $jun[] = $d; } else if ($mY == '07/2019') { $july[] = $d; } else if ($mY == '08/2019') { $august[] = $d; } else if ($mY == '09/2019') { $sep[] = $d; } else if ($mY == '10/2019') { $oct[] = $d; } else if ($mY == '11/2019') { $nov[] = $d; } else if ($mY == '12/2019') { $dec[] = $d; } $finalD6 = [count($jan), count($feb), count($mac), count($april), count($may), count($jun), count($july), count($august), count($sep), count($oct), count($nov), count($dec)]; } else if (empty($d->dealer_id)) { $mY = Carbon::parse($d->created_at)->format('m/Y'); if ($mY == '01/2019') { $jan1[] = $d; } else if ($mY == '02/2019') { $feb1[] = $d; } else if ($mY == '03/2019') { $mac1[] = $d; } else if ($mY == '04/2019') { $april1[] = $d; } else if ($mY == '05/2019') { $may1[] = $d; } else if ($mY == '06/2019') { $jun1[] = $d; } else if ($mY == '07/2019') { $july1[] = $d; } else if ($mY == '08/2019') { $august1[] = $d; } else if ($mY == '09/2019') { $sep1[] = $d; } else if ($mY == '10/2019') { $oct1[] = $d; } else if ($mY == '11/2019') { $nov1[] = $d; } else if ($mY == '12/2019') { $dec1[] = $d; } $finalD5 = [count($jan1), count($feb1), count($mac1), count($april1), count($may1), count($jun1), count($july1), count($august1), count($sep1), count($oct1), count($nov1), count($dec1)]; if ($d->type_service != 'Rectification') { $finalD2[] = $d; $finalD4[] = $d; } } if ($d->type_service == 'Rectification') { $finalD3[] = $d; } } $total = count($finalD4); $dealer = count($finalD1); $normal = count($finalD2); $rec = count($finalD3); $rejected = count(Form::onlyTrashed()->get()); return view('eep-hr.dashboard', compact('user', 'total', 'rec', 'dealer', 'normal', 'rejected', 'finalD5', 'finalD6')); } public function viewList() { $id = Auth::guard('eephr')->id(); $user = Staff::with('StaffDetail')->find($id); return view('eep-hr.index', compact('user')); } /*** / Application Form List ***/ public function viewAppList() { $id = Auth::guard('ds')->id(); $user = Staff::with('StaffDetail')->find($id); return view('dealer.application-form-list', compact('user')); } /*** / Get Application Form List ***/ public function getOrderHistory($id) { $data = array(); $order_history = FormStatus::where('form_id', $id)->get(); foreach ($order_history as $oh) { $utcdatetime = new \MongoDB\BSON\UTCDateTime((string) $oh->date); $datetime = $utcdatetime->toDateTime(); $time = $datetime->format(DATE_RSS); $time = strtotime($time . ' UTC'); $dateInLocal = date("d/m/Y h:i a", $time); $data[] = array( 'date' => $dateInLocal, 'status' => $oh->status, 'desc' => $oh->desc ); } $json = json_encode($data); return $json; } public function gApplicationList2() { $id = Auth::guard('eephr')->id(); $user = Staff::with('StaffDetail')->find($id); $fm = Form::with('Subscriber')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get(); $nested_data = array(); $i = 0; foreach ($fm as $f) { $dname = ""; $wo = WorkOrder::where('_id', $f->_id)->first(); $dealer = StaffDetail::where('_id', $f->dealer_id)->first(); if (!empty($dealer)) { $dname = $dealer->name; } $address = ''; $name = ''; if ($f->type_application == 'R') { if (!empty($f->Subscriber->building_name)) { $address = $f->Subscriber->building_name; $name = $f->Subscriber->name; } } else if ($f->type_application == 'B') { $address = '-'; $name = $f->Subscriber->company_name; } if (!empty($wo) && $wo->status != 'Completed') { $i++; array_push($nested_data, array( 'index' => $i . $f->type_application, 'name' => $name, 'phone' => $f->Subscriber->phone1, 'unit' => $f->Subscriber->unit_no, 'building' => $address, 'street' => $f->Subscriber->street, 'postcode' => $f->Subscriber->postcode, 'city' => $f->Subscriber->city, 'sales' => $dname, 'action' => $f->_id )); } } return \DataTables::of($nested_data)->make(true); } public function getCompletedList($year, $month) { $id = Auth::guard('ds')->id(); $user = Staff::find($id); $email = $user->email; $userDetails = StaffDetail::where('email', $email)->first(); $subs = $this->getSubscribers($userDetails->company_id); $buss = $this->getBusiness($userDetails->company_id); // Combine $cdata = array(); foreach ($subs as $key => $s) { $cdata[] = $s; } foreach ($buss as $key => $b) { $cdata[] = $b; } // Sort based on TimeStamp $sort = array(); foreach ($cdata as $key => $r) { $sort[$key] = $r['created_at']; } array_multisort($sort, SORT_DESC, $cdata); $wK = WorkDetail::get(); $curr = Carbon::now()->getTimestamp(); $mY = ''; if ($year != 'null' && $month != 'null') { $mY = $year . '/' . $month; } $final = array(); $filter = array(); $dW = array(); foreach ($cdata as $c) { if ($c['wo'] != '') { foreach ($wK as $key => $w) { if ($c['wo'] == $w->wo && $w->status == 'Completed') { $dW[] = $c; } } } } foreach ($dW as $d) { if ($mY != '') { $docket = Docket::where('work_order_id', $d['wo'])->first(); $cDate = date('Y/m', strtotime($docket->end_job));; if ($mY == $cDate) { $filter[] = $d; } } else { $filter[] = $d; } } foreach ($filter as $c) { $do = Docket::where('work_order_id', $c['wo'])->first(); $n1 = ''; $reg_time = Carbon::createFromTimestamp(strtotime($do->end_job)); $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if ($curr < $expiry_date) { $n1 = "New/"; } $final[] = array( 'formT' => $c['formT'], 'wo' => $c['wo'], 'do' => $do->docket_id, 'activated' => $do->end_job, 'name' => $n1 . str_replace("New/", "", $c['name']), 'no' => $c['no'], 'unit' => $c['unit'], 'building' => $c['building'], 'street' => $c['street'], 'postcode' => $c['postcode'], 'city' => $c['city'], 'sales' => $c['sales'], 'created_at' => $c['created_at'], 'action' => $c['action'], ); } return $final; } public function gApplicationList3($year, $month) { $id = Auth::guard('ds')->id(); $user = Staff::with('StaffDetail')->find($id); $mY = ''; if ($year != 'null' && $month != 'null') { $mY = $month . '/' . $year; } $fm = Form::with('Subscriber', 'WorkOrder')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get(); $nested_data = array(); $i = 0; foreach ($fm as $f) { if (!empty($f->WorkOrder)) { if ($f->WorkOrder->status == 'Completed') { $wo = WorkOrder::with('Docket')->where('wo', $f->WorkOrder->wo)->first(); $dealer = StaffDetail::where('_id', $f->dealer_id)->withTrashed()->first(); $i++; $address = ''; $name = ''; if ($f->type_application == 'R') { if (!empty($f->Subscriber->building_name)) { $address = $f->Subscriber->building_name; $name = $f->Subscriber->name; } } else if ($f->type_application == 'B') { $address = '-'; $name = $f->Subscriber->company_name; } if (!empty($wo->Docket)) { $end = date('m/Y', strtotime($wo->Docket->end_job)); if ($mY == '') { array_push($nested_data, array( 'index' => $i . $f->type_application, 'wo' => $wo->wo, 'do' => $f->WorkOrder->docket_id, 'name' => $name, 'phone' => $f->Subscriber->phone1, 'unit' => $f->Subscriber->unit_no, 'building' => $address, 'street' => $f->Subscriber->street, 'postcode' => $f->Subscriber->postcode, 'city' => $f->Subscriber->city, 'sales' => $dealer->name, 'action' => $f->_id )); } else if ($mY == $end) { array_push($nested_data, array( 'index' => $i . $f->type_application, 'wo' => $wo->wo, 'do' => $f->WorkOrder->docket_id, 'name' => $name, 'phone' => $f->Subscriber->phone1, 'unit' => $f->Subscriber->unit_no, 'building' => $address, 'street' => $f->Subscriber->street, 'postcode' => $f->Subscriber->postcode, 'city' => $f->Subscriber->city, 'sales' => $dealer->name, 'action' => $f->_id )); } } } } } return \DataTables::of($nested_data)->make(true); } /*** / Encrypt Password ***/ public function encryptPassword($action, $string) { $output = false; $encrypt_method = "AES-256-CBC"; $secret_key = '28472B4B6250655368566D5970337336'; $secret_iv = md5(md5($string)); //'This is my secret iv'; // hash $key = hash('sha256', $secret_key); $iv = substr(hash('sha256', $secret_iv), 0, 16); if ($action == 'encrypt') { $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv); $output = base64_encode($output); } else if ($action == 'decrypt') { $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv); } return $output; } /*** / Application Form ***/ public function showResidentialForm() { $id = Auth::guard('eephr')->id(); $user = Staff::find($id); $email = $user->email; $userDetails = StaffDetail::where('email', $email)->first(); return view('eep-hr.residential-form', compact('userDetails', 'user')); } public function exportDealerJson(Request $request) { $final = array(); $id = Auth::guard('ds')->id(); // $user = Staff::with('StaffDetail')->find($id); // $com = Company::where('_id',$user->StaffDetail->company_id)->first(); $dataR = array(); $dataB = array(); $combineData = array(); $extra = 0; $year = $request->year; $month = $request->month; $app = $request->app; $company = $request->company; if ($year != 'null' && $month != 'null' && $app == 'null') { $count_cyberjaya = array(); $count_jasin = array(); $count_ayerKeroh = array(); $count_alorGajah = array(); $count_menglembu = array(); $count_ipoh = array(); $extra = 0; $basic_total = 0; $countAugustR = array(); $countAugustB = array(); // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){ // $dataDis = $this->returnDataR($company,'2019','12'); // $dataJan = $this->returnDataR($company,'2020','1'); if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) { $dataApril = $this->returnDataR($company, '2020', '4'); $dataMay = $this->returnDataR($company, '2020', '5'); $dataJune = $this->returnDataR($company, '2020', '6'); $dataJuly = $this->returnDataR($company, '2020', '7'); foreach ($dataApril as $key => $d) { // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){ // if (strpos($d['address'], 'Cyberjaya') !== false) { // $count_cyberjaya[] = $d; // } // if (strpos($d['address'], 'Jasin') !== false) { // $count_jasin[] = $d; // } // } // // else if (date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020') { if (strpos($d['address'], 'Cyberjaya') !== false) { $count_cyberjaya[] = $d; } if (strpos($d['address'], 'Jasin') !== false) { $count_jasin[] = $d; } if (strpos($d['address'], 'Ayer Keroh') !== false) { $count_ayerKeroh[] = $d; } if (strpos($d['address'], 'Alor Gajah') !== false) { $count_alorGajah[] = $d; } if (strpos($d['address'], 'Menglembu') !== false) { $count_menglembu[] = $d; } if (strpos($d['address'], 'Ipoh') !== false) { $count_ipoh[] = $d; } } else { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { $combineData[] = $d; } } } foreach ($dataMay as $key => $d) { if (strpos($d['address'], 'Cyberjaya') !== false) { $count_cyberjaya[] = $d; } if (strpos($d['address'], 'Jasin') !== false) { $count_jasin[] = $d; } if (strpos($d['address'], 'Ayer Keroh') !== false) { $count_ayerKeroh[] = $d; } if (strpos($d['address'], 'Alor Gajah') !== false) { $count_alorGajah[] = $d; } if (strpos($d['address'], 'Menglembu') !== false) { $count_menglembu[] = $d; } if (strpos($d['address'], 'Ipoh') !== false) { $count_ipoh[] = $d; } } foreach ($dataJune as $key => $d) { if (strpos($d['address'], 'Cyberjaya') !== false) { $count_cyberjaya[] = $d; } if (strpos($d['address'], 'Jasin') !== false) { $count_jasin[] = $d; } if (strpos($d['address'], 'Ayer Keroh') !== false) { $count_ayerKeroh[] = $d; } if (strpos($d['address'], 'Alor Gajah') !== false) { $count_alorGajah[] = $d; } if (strpos($d['address'], 'Menglembu') !== false) { $count_menglembu[] = $d; } if (strpos($d['address'], 'Ipoh') !== false) { $count_ipoh[] = $d; } } foreach ($dataJuly as $key => $d) { if (strpos($d['address'], 'Cyberjaya') !== false) { $count_cyberjaya[] = $d; } if (strpos($d['address'], 'Jasin') !== false) { $count_jasin[] = $d; } if (strpos($d['address'], 'Ayer Keroh') !== false) { $count_ayerKeroh[] = $d; } if (strpos($d['address'], 'Alor Gajah') !== false) { $count_alorGajah[] = $d; } if (strpos($d['address'], 'Menglembu') !== false) { $count_menglembu[] = $d; } if (strpos($d['address'], 'Ipoh') !== false) { $count_ipoh[] = $d; } } // Store to combineData New Incentives Cyberjaya foreach ($count_cyberjaya as $key => $d) { if (count($count_cyberjaya) > 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '230%', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($count_cyberjaya) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } } } // Store to combineData New Incentives Menglembu foreach ($count_menglembu as $key => $d) { if (count($count_menglembu) > 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '230%', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($count_menglembu) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } } } // Store to combineData New Incentives Ipoh foreach ($count_ipoh as $key => $d) { if (count($count_ipoh) > 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '230%', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($count_ipoh) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } } } // Store to combineData New Incentives Ayer Keroh foreach ($count_ayerKeroh as $key => $d) { if (count($count_ayerKeroh) > 50) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '230%', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($count_ayerKeroh) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } } } // Store to combineData New Incentives Alor Gajah foreach ($count_alorGajah as $key => $d) { if (count($count_alorGajah) > 50) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '230%', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($count_alorGajah) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } } } // Store to combineData New Incentives Jasin foreach ($count_jasin as $key => $d) { if (count($count_jasin) > 20) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '230%', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($count_jasin) < 20) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } } } } else if ($year == '2020' && ($month == '08' || $month == '09' || $month == '10')) { $dataAugustR = $this->returnDataR($company, '2020', '8'); $dataAugustB = $this->returnDataB($company, '2020', '8'); $dataSeptemberR = $this->returnDataR($company, '2020', '9'); $dataSeptemberB = $this->returnDataB($company, '2020', '9'); $dataOctoberR = $this->returnDataR($company, '2020', '10'); $dataOctoberB = $this->returnDataB($company, '2020', '10'); foreach ($dataAugustR as $key => $d) { if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') { if ($d['contract'] == '24') { if ($d['package'] == 50) { $d['retail_price'] = 69; } elseif ($d['package'] == 100) { $d['retail_price'] = 89; } elseif ($d['package'] == 500) { $d['retail_price'] = 129; } } if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') { $countAugustR[] = $d; } } else { if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') { $countAugustR[] = $d; } else { $combineData[] = $d; } } } // Store to combineData New Incentive August foreach ($countAugustR as $key => $d) { if (count($dataAugustR) >= 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250% + RM50', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($dataAugustR) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250%', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } } foreach ($dataAugustB as $key => $d) { if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') { if ($d['contract'] == '24') { if ($d['package'] == 50) { $d['retail_price'] = 89; } elseif ($d['package'] == 100) { $d['retail_price'] = 119; } elseif ($d['package'] == 300) { $d['retail_price'] = 179; } elseif ($d['package'] == 500) { $d['retail_price'] = 249; } } if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') { $countAugustB[] = $d; } } else { if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') { $countAugustB[] = $d; } else { $combineData[] = $d; } } } // Store to combineData New Incentive August foreach ($countAugustB as $key => $d) { if (count($dataAugustB) >= 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { if ($d['package'] == 1) { $total = 1500; } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2); } array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250% + RM50', 'incentives2' => '', 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($dataAugustB) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { if ($d['package'] == 1) { $total = 1500; } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2); } array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250%', 'incentives2' => '', 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } } foreach ($dataSeptemberR as $key => $d) { if (((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month . '/' . $year)) { if ($d['contract'] == '24') { if ($d['package'] == 50) { $d['retail_price'] = 69; } elseif ($d['package'] == 100) { $d['retail_price'] = 89; } elseif ($d['package'] == 500) { $d['retail_price'] = 129; } } } if (count($dataSeptemberR) >= 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250% + RM50', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($dataSeptemberR) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250%', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } } foreach ($dataSeptemberB as $key => $d) { if (((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month . '/' . $year)) { if ($d['contract'] == '24') { if ($d['package'] == 50) { $d['retail_price'] = 89; } elseif ($d['package'] == 100) { $d['retail_price'] = 119; } elseif ($d['package'] == 300) { $d['retail_price'] = 179; } elseif ($d['package'] == 500) { $d['retail_price'] = 249; } } } if (count($dataSeptemberB) >= 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { if ($d['package'] == 1) { $total = 1500; } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2); } array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250% + RM50', 'incentives2' => '', 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($dataSeptemberB) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { if ($d['package'] == 1) { $total = 1500; } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2); } array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250%', 'incentives2' => '', 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } } foreach ($dataOctoberR as $key => $d) { if (((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) || (date('m/Y', strtotime($d['submission'])) == '09/2020')) { if ($d['contract'] == '24') { if ($d['package'] == 50) { $d['retail_price'] = 69; } elseif ($d['package'] == 100) { $d['retail_price'] = 89; } elseif ($d['package'] == 500) { $d['retail_price'] = 129; } } } if (count($dataOctoberR) >= 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250% + RM50', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($dataOctoberR) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2); array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250%', 'incentives2' => $d['incentives2'], 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } } foreach ($dataOctoberB as $key => $d) { if (((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) || (date('m/Y', strtotime($d['submission'])) == '09/2020')) { if ($d['contract'] == '24') { if ($d['package'] == 50) { $d['retail_price'] = 89; } elseif ($d['package'] == 100) { $d['retail_price'] = 119; } elseif ($d['package'] == 300) { $d['retail_price'] = 179; } elseif ($d['package'] == 500) { $d['retail_price'] = 249; } } } if (count($dataOctoberB) >= 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { if ($d['package'] == 1) { $total = 1500; } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2); } array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250% + RM50', 'incentives2' => '', 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } else if (count($dataOctoberB) < 50) { if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) { if ($d['contract'] == '12') { array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => $d['incentives1'], 'incentives2' => $d['incentives2'], 'total' => $d['total'], 'claim' => $d['claim'], )); } else { if ($d['package'] == 1) { $total = 1500; } else { $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2); } array_push($combineData, array( 'index' => $d['index'], 'contract' => $d['contract'], 'wo' => $d['wo'], 'activation' => $d['activation'], 'name' => $d['name'], 'address' => $d['address'], 'package' => $d['package'], 'retail_price' => $d['retail_price'], 'incentives1' => '250%', 'incentives2' => '', 'total' => 'RM ' . $total, 'claim' => $d['claim'], )); } } } } } else if ($year == '2020' && ($month == '12')) { $dataDecemberR = $this->returnDataR($company, '2020', '12'); foreach ($dataDecemberR as $r) { $combineData[] = $r; } $dataDecemberB = $this->returnDataB($company, '2020', '12'); foreach ($dataDecemberB as $b) { if ((date('m/Y', strtotime($b['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($b['submission'])) >= '21/12/2020') { if (strpos($b['address'], 'CYBERJAYA') !== false && $b['contract'] == '24' && $b['package'] == 1) { $b['retail_price'] = 999; $count_businessCyber[] = $b; } else { $combineData[] = $b; } } else { $combineData[] = $b; } } if(!empty($count_businessCyber)){ for ($i=0;$i $count_businessCyber[$j]['index'], 'contract' => $count_businessCyber[$j]['contract'], 'wo' => $count_businessCyber[$j]['wo'], 'activation' => $count_businessCyber[$j]['activation'], 'name' => $count_businessCyber[$j]['name'], 'address' => $count_businessCyber[$j]['address'], 'package' => $count_businessCyber[$j]['package'], 'retail_price' => $count_businessCyber[$j]['retail_price'], 'incentives1' => '200%', 'incentives2' => $count_businessCyber[$j]['incentives2'], 'total' => 'RM ' . $total, 'claim' => $count_businessCyber[$j]['claim'], )); } for($j=51; ($j < count($count_businessCyber) && $j>=51);$j++){ $total = number_format(floatval(str_replace("RM ", "", $count_businessCyber[$j]['retail_price'])) * 2.5, 2); array_push($combineData, array( 'index' => $count_businessCyber[$j]['index'], 'contract' => $count_businessCyber[$j]['contract'], 'wo' => $count_businessCyber[$j]['wo'], 'activation' => $count_businessCyber[$j]['activation'], 'name' => $count_businessCyber[$j]['name'], 'address' => $count_businessCyber[$j]['address'], 'package' => $count_businessCyber[$j]['package'], 'retail_price' => $count_businessCyber[$j]['retail_price'], 'incentives1' => '250%', 'incentives2' => $count_businessCyber[$j]['incentives2'], 'total' => 'RM ' . $total, 'claim' => $count_businessCyber[$j]['claim'], )); } } } } else { $dataR = $this->returnDataR($company, $year, $month); foreach ($dataR as $r) { $combineData[] = $r; } $dataB = $this->returnDataB($company, $year, $month); foreach ($dataB as $b) { $combineData[] = $b; } } $i = 0; $nested_data = array(); if (!empty($combineData)) { foreach ($combineData as $c) { $update_dealer = DealerClaim::where('wo', $c['wo'])->first(); if (!empty($update_dealer)) { $update_dealer->incentives1 = $c['incentives1']; $update_dealer->incentives2 = $c['incentives2']; $update_dealer->retail_price = $c['retail_price']; $update_dealer->total_claim = $c['total']; $update_dealer->save(); } } } $dataClaim = DealerClaim::with(['Subscriber' => function ($q) { $q->with('Form'); }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->get(); if (!empty($dataClaim)) { foreach ($dataClaim as $c) { $address = ''; $name = ''; if ($c->Subscriber->Form->type_application == 'R') { if ($c->Subscriber->street != '') { $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state; } else { $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state; } $name = $c->Subscriber->name; } else if ($c->Subscriber->Form->type_application == 'B') { if ($c->Subscriber->unit_no != '') { $unit = $c->Subscriber->unit_no; } else { $unit = ' '; } if ($c->Subscriber->building_name == null) { $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state; } else { $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state; } $name = $c->Subscriber->company_name; } $i++; array_push($final, array( 'index' => $c->formT, 'contract' => $c->contract, 'wo' => $c->wo, 'activated_dt' => $c->activated_dt, 'name' => $name, 'address' => $address, 'package' => $c->package, 'retail_price' => $c->retail_price, 'incentives1' => $c->incentives1, 'incentives2' => $c->incentives2, 'total' => $c->total_claim, 'claimed' => $c->claim_dt, )); } } foreach ($final as $f) { $basic_total += floatval(str_replace('RM ', '', $f['total'])); } // Calculate extra incentves // if($month == '1' && $year == '2020'){ // if(count($count_cyberjaya) > 50){ // $balance = count($count_cyberjaya) - 50; // $extra += $balance * 50; // } // if(count($count_jasin) > 10){ // $balance = count($count_jasin) - 10; // $extra += $balance * 50; // } // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){ // if(count($count_cyberjaya) > 50){ // $balance = count($count_cyberjaya) - 50; // $extra += $balance * 50; // } // if(count($count_jasin) > 20){ // $balance = count($count_jasin) - 10; // $extra += $balance * 50; // } // }else { // $extra = 0; // } $extra = 0; $totals = $basic_total + $extra; // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals')); // $pdf->setPaper('A4', 'landscape'); // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf'; // return $pdf->download( $pdfName ); return $final; } // else if($year!='null' && $month!='null' && $app!='null'){ // $count_cyberjaya = array(); $count_jasin = array(); // $extra = 0; $basic_total = 0; $totals = 0; // if($app == 'Residential'){ // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){ // $dataDis = $this->returnDataR($company,'2019','12'); // $dataJan = $this->returnDataR($company,'2020','1'); // foreach ($dataDis as $key => $d) { // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){ // if (strpos($d['address'], 'Cyberjaya') !== false) { // $count_cyberjaya[] = $d; // } // if (strpos($d['address'], 'Jasin') !== false) { // $count_jasin[] = $d; // } // }else if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020' && date('d/m/Y', strtotime($d['activation'])) <= '31/7/2020'){ // if (strpos($d['address'], 'Cyberjaya') !== false) { // $count_cyberjaya[] = $d; // } // if (strpos($d['address'], 'Jasin') !== false) { // $count_jasin[] = $d; // } // }else { // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){ // $combineData[] = $d; // } // } // } // foreach ($dataJan as $key => $d) { // if (strpos($d['address'], 'Cyberjaya') !== false) { // $count_cyberjaya[] = $d; // } // if (strpos($d['address'], 'Jasin') !== false) { // $count_jasin[] = $d; // } // } // // Store to combineData New Incentives Cyberjaya // foreach ($count_cyberjaya as $key => $d) { // if(count($count_cyberjaya) > 50){ // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){ // if($d['contract'] == '12'){ // array_push($combineData, array( // 'index' => $d['index'], // 'contract' => $d['contract'], // 'wo' => $d['wo'], // 'activation' => $d['activation'], // 'name' => $d['name'], // 'address' => $d['address'], // 'package' => $d['package'], // 'retail_price' => $d['retail_price'], // 'incentives1' => $d['incentives1'], // 'incentives2' => $d['incentives2'], // 'total' => $d['total'], // 'claim' => $d['claim'], // )); // }else { // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2); // array_push($combineData, array( // 'index' => $d['index'], // 'contract' => $d['contract'], // 'wo' => $d['wo'], // 'activation' => $d['activation'], // 'name' => $d['name'], // 'address' => $d['address'], // 'package' => $d['package'], // 'retail_price' => $d['retail_price'], // 'incentives1' => '230%', // 'incentives2' => $d['incentives2'], // 'total' => 'RM '.$total, // 'claim' => $d['claim'], // )); // } // } // }else if(count($count_cyberjaya) < 50){ // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){ // array_push($combineData, array( // 'index' => $d['index'], // 'contract' => $d['contract'], // 'wo' => $d['wo'], // 'activation' => $d['activation'], // 'name' => $d['name'], // 'address' => $d['address'], // 'package' => $d['package'], // 'retail_price' => $d['retail_price'], // 'incentives1' => $d['incentives1'], // 'incentives2' => $d['incentives2'], // 'total' => $d['total'], // 'claim' => $d['claim'], // )); // } // } // } // // Store to combineData New Incentives Jasin // foreach ($count_jasin as $key => $d) { // if(count($count_jasin) > 10){ // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){ // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2); // array_push($combineData, array( // 'index' => $d['index'], // 'contract' => $d['contract'], // 'wo' => $d['wo'], // 'activation' => $d['activation'], // 'name' => $d['name'], // 'address' => $d['address'], // 'package' => $d['package'], // 'retail_price' => $d['retail_price'], // 'incentives1' => '230%', // 'incentives2' => $d['incentives2'], // 'total' => 'RM '.$total, // 'claim' => $d['claim'], // )); // } // }else if(count($count_jasin) < 10){ // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){ // array_push($combineData, array( // 'index' => $d['index'], // 'contract' => $d['contract'], // 'wo' => $d['wo'], // 'activation' => $d['activation'], // 'name' => $d['name'], // 'address' => $d['address'], // 'package' => $d['package'], // 'retail_price' => $d['retail_price'], // 'incentives1' => $d['incentives1'], // 'incentives2' => $d['incentives2'], // 'total' => $d['total'], // 'claim' => $d['claim'], // )); // } // } // } // }else { // $dataR = $this->returnDataR($company,$year,$month); // foreach($dataR as $r){ // $combineData[] = $r; // } // } // }else if($app == 'Business'){ // $dataB = $this->returnDataB($company,$year,$month); // } // 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'], // )); // } // } // foreach($final as $f){ // $basic_total += floatval(str_replace('RM ', '', $f['total'])); // } // //Calculate extra incentves // if($month == '1' && $year == '2020'){ // if(count($count_cyberjaya) > 50){ // $balance = count($count_cyberjaya) - 50; // $extra += $balance * 50; // } // if(count($count_jasin) > 10){ // $balance = count($count_jasin) - 10; // $extra += $balance * 50; // } // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){ // if(count($count_cyberjaya) > 50){ // $balance = count($count_cyberjaya) - 50; // $extra += $balance * 50; // } // if(count($count_jasin) > 20){ // $balance = count($count_jasin) - 10; // $extra += $balance * 50; // } // }else { // $extra = 0; // } // $totals = $basic_total + $extra; // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals')); // $pdf->setPaper('A4', 'landscape'); // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf'; // return $pdf->download( $pdfName ); // } } }