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

EephrController.php 61KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958
  1. <?php
  2. namespace App\Http\Controllers\EEP;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Carbon\Carbon;
  7. use Validator;
  8. use PDF;
  9. use App\Staff;
  10. use App\Model\StaffDetail;
  11. use App\Model\Coverage;
  12. use App\Model\DealerClaim;
  13. use App\Model\DealerClaim2;
  14. use App\Model\Commission;
  15. use App\Model\Company;
  16. use App\Model\Form;
  17. use App\Model\FormStatus;
  18. use App\Model\Subscriber;
  19. use App\Model\PackageDetail;
  20. use App\Model\WorkOrder;
  21. use App\Model\Docket;
  22. class EephrController extends Controller
  23. {
  24. public function dashboard()
  25. {
  26. $id = Auth::guard('eephr')->id();
  27. $user = Staff::with('StaffDetail')->find($id);
  28. $finalD1 = array();
  29. $finalD2 = array();
  30. $finalD3 = array();
  31. $finalD4 = array();
  32. $finalD5 = array();
  33. $finalD6 = array();
  34. $jan = array();
  35. $feb = array();
  36. $mac = array();
  37. $april = array();
  38. $may = array();
  39. $jun = array();
  40. $july = array();
  41. $august = array();
  42. $sep = array();
  43. $oct = array();
  44. $nov = array();
  45. $dec = array();
  46. $jan1 = array();
  47. $feb1 = array();
  48. $mac1 = array();
  49. $april1 = array();
  50. $may1 = array();
  51. $jun1 = array();
  52. $july1 = array();
  53. $august1 = array();
  54. $sep1 = array();
  55. $oct1 = array();
  56. $nov1 = array();
  57. $dec1 = array();
  58. $de = Form::all();
  59. foreach ($de as $key => $d) {
  60. if (!empty($d->dealer_id)) {
  61. $finalD1[] = $d;
  62. $mY = Carbon::parse($d->created_at)->format('m/Y');
  63. if ($mY == '01/2019') {
  64. $jan[] = $d;
  65. } else if ($mY == '02/2019') {
  66. $feb[] = $d;
  67. } else if ($mY == '03/2019') {
  68. $mac[] = $d;
  69. } else if ($mY == '04/2019') {
  70. $april[] = $d;
  71. } else if ($mY == '05/2019') {
  72. $may[] = $d;
  73. } else if ($mY == '06/2019') {
  74. $jun[] = $d;
  75. } else if ($mY == '07/2019') {
  76. $july[] = $d;
  77. } else if ($mY == '08/2019') {
  78. $august[] = $d;
  79. } else if ($mY == '09/2019') {
  80. $sep[] = $d;
  81. } else if ($mY == '10/2019') {
  82. $oct[] = $d;
  83. } else if ($mY == '11/2019') {
  84. $nov[] = $d;
  85. } else if ($mY == '12/2019') {
  86. $dec[] = $d;
  87. }
  88. $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)];
  89. } else if (empty($d->dealer_id)) {
  90. $mY = Carbon::parse($d->created_at)->format('m/Y');
  91. if ($mY == '01/2019') {
  92. $jan1[] = $d;
  93. } else if ($mY == '02/2019') {
  94. $feb1[] = $d;
  95. } else if ($mY == '03/2019') {
  96. $mac1[] = $d;
  97. } else if ($mY == '04/2019') {
  98. $april1[] = $d;
  99. } else if ($mY == '05/2019') {
  100. $may1[] = $d;
  101. } else if ($mY == '06/2019') {
  102. $jun1[] = $d;
  103. } else if ($mY == '07/2019') {
  104. $july1[] = $d;
  105. } else if ($mY == '08/2019') {
  106. $august1[] = $d;
  107. } else if ($mY == '09/2019') {
  108. $sep1[] = $d;
  109. } else if ($mY == '10/2019') {
  110. $oct1[] = $d;
  111. } else if ($mY == '11/2019') {
  112. $nov1[] = $d;
  113. } else if ($mY == '12/2019') {
  114. $dec1[] = $d;
  115. }
  116. $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)];
  117. if ($d->type_service != 'Rectification') {
  118. $finalD2[] = $d;
  119. $finalD4[] = $d;
  120. }
  121. }
  122. if ($d->type_service == 'Rectification') {
  123. $finalD3[] = $d;
  124. }
  125. }
  126. $total = count($finalD4);
  127. $dealer = count($finalD1);
  128. $normal = count($finalD2);
  129. $rec = count($finalD3);
  130. $rejected = count(Form::onlyTrashed()->get());
  131. return view('eep-hr.dashboard', compact('user', 'total', 'rec', 'dealer', 'normal', 'rejected', 'finalD5', 'finalD6'));
  132. }
  133. public function viewList()
  134. {
  135. $id = Auth::guard('eephr')->id();
  136. $user = Staff::with('StaffDetail')->find($id);
  137. return view('eep-hr.index', compact('user'));
  138. }
  139. /***
  140. / Application Form List
  141. ***/
  142. public function viewAppList()
  143. {
  144. $id = Auth::guard('ds')->id();
  145. $user = Staff::with('StaffDetail')->find($id);
  146. return view('dealer.application-form-list', compact('user'));
  147. }
  148. /***
  149. / Get Application Form List
  150. ***/
  151. public function getOrderHistory($id)
  152. {
  153. $data = array();
  154. $order_history = FormStatus::where('form_id', $id)->get();
  155. foreach ($order_history as $oh) {
  156. $utcdatetime = new \MongoDB\BSON\UTCDateTime((string) $oh->date);
  157. $datetime = $utcdatetime->toDateTime();
  158. $time = $datetime->format(DATE_RSS);
  159. $time = strtotime($time . ' UTC');
  160. $dateInLocal = date("d/m/Y h:i a", $time);
  161. $data[] = array(
  162. 'date' => $dateInLocal,
  163. 'status' => $oh->status,
  164. 'desc' => $oh->desc
  165. );
  166. }
  167. $json = json_encode($data);
  168. return $json;
  169. }
  170. public function gApplicationList2()
  171. {
  172. $id = Auth::guard('eephr')->id();
  173. $user = Staff::with('StaffDetail')->find($id);
  174. $fm = Form::with('Subscriber')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
  175. $nested_data = array();
  176. $i = 0;
  177. foreach ($fm as $f) {
  178. $dname = "";
  179. $wo = WorkOrder::where('_id', $f->_id)->first();
  180. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  181. if (!empty($dealer)) {
  182. $dname = $dealer->name;
  183. }
  184. $address = '';
  185. $name = '';
  186. if ($f->type_application == 'R') {
  187. if (!empty($f->Subscriber->building_name)) {
  188. $address = $f->Subscriber->building_name;
  189. $name = $f->Subscriber->name;
  190. }
  191. } else if ($f->type_application == 'B') {
  192. $address = '-';
  193. $name = $f->Subscriber->company_name;
  194. }
  195. if (!empty($wo) && $wo->status != 'Completed') {
  196. $i++;
  197. array_push($nested_data, array(
  198. 'index' => $i . $f->type_application,
  199. 'name' => $name,
  200. 'phone' => $f->Subscriber->phone1,
  201. 'unit' => $f->Subscriber->unit_no,
  202. 'building' => $address,
  203. 'street' => $f->Subscriber->street,
  204. 'postcode' => $f->Subscriber->postcode,
  205. 'city' => $f->Subscriber->city,
  206. 'sales' => $dname,
  207. 'action' => $f->_id
  208. ));
  209. }
  210. }
  211. return \DataTables::of($nested_data)->make(true);
  212. }
  213. public function getCompletedList($year, $month)
  214. {
  215. $id = Auth::guard('ds')->id();
  216. $user = Staff::find($id);
  217. $email = $user->email;
  218. $userDetails = StaffDetail::where('email', $email)->first();
  219. $subs = $this->getSubscribers($userDetails->company_id);
  220. $buss = $this->getBusiness($userDetails->company_id);
  221. // Combine
  222. $cdata = array();
  223. foreach ($subs as $key => $s) {
  224. $cdata[] = $s;
  225. }
  226. foreach ($buss as $key => $b) {
  227. $cdata[] = $b;
  228. }
  229. // Sort based on TimeStamp
  230. $sort = array();
  231. foreach ($cdata as $key => $r) {
  232. $sort[$key] = $r['created_at'];
  233. }
  234. array_multisort($sort, SORT_DESC, $cdata);
  235. $wK = WorkDetail::get();
  236. $curr = Carbon::now()->getTimestamp();
  237. $mY = '';
  238. if ($year != 'null' && $month != 'null') {
  239. $mY = $year . '/' . $month;
  240. }
  241. $final = array();
  242. $filter = array();
  243. $dW = array();
  244. foreach ($cdata as $c) {
  245. if ($c['wo'] != '') {
  246. foreach ($wK as $key => $w) {
  247. if ($c['wo'] == $w->wo && $w->status == 'Completed') {
  248. $dW[] = $c;
  249. }
  250. }
  251. }
  252. }
  253. foreach ($dW as $d) {
  254. if ($mY != '') {
  255. $docket = Docket::where('work_order_id', $d['wo'])->first();
  256. $cDate = date('Y/m', strtotime($docket->end_job));;
  257. if ($mY == $cDate) {
  258. $filter[] = $d;
  259. }
  260. } else {
  261. $filter[] = $d;
  262. }
  263. }
  264. foreach ($filter as $c) {
  265. $do = Docket::where('work_order_id', $c['wo'])->first();
  266. $n1 = '';
  267. $reg_time = Carbon::createFromTimestamp(strtotime($do->end_job));
  268. $expiry_date = $reg_time->addDays(3);
  269. $expiry_date = $expiry_date->getTimestamp();
  270. if ($curr < $expiry_date) {
  271. $n1 = "New/";
  272. }
  273. $final[] = array(
  274. 'formT' => $c['formT'],
  275. 'wo' => $c['wo'],
  276. 'do' => $do->docket_id,
  277. 'activated' => $do->end_job,
  278. 'name' => $n1 . str_replace("New/", "", $c['name']),
  279. 'no' => $c['no'],
  280. 'unit' => $c['unit'],
  281. 'building' => $c['building'],
  282. 'street' => $c['street'],
  283. 'postcode' => $c['postcode'],
  284. 'city' => $c['city'],
  285. 'sales' => $c['sales'],
  286. 'created_at' => $c['created_at'],
  287. 'action' => $c['action'],
  288. );
  289. }
  290. return $final;
  291. }
  292. public function gApplicationList3($year, $month)
  293. {
  294. $id = Auth::guard('ds')->id();
  295. $user = Staff::with('StaffDetail')->find($id);
  296. $mY = '';
  297. if ($year != 'null' && $month != 'null') {
  298. $mY = $month . '/' . $year;
  299. }
  300. $fm = Form::with('Subscriber', 'WorkOrder')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
  301. $nested_data = array();
  302. $i = 0;
  303. foreach ($fm as $f) {
  304. if (!empty($f->WorkOrder)) {
  305. if ($f->WorkOrder->status == 'Completed') {
  306. $wo = WorkOrder::with('Docket')->where('wo', $f->WorkOrder->wo)->first();
  307. $dealer = StaffDetail::where('_id', $f->dealer_id)->withTrashed()->first();
  308. $i++;
  309. $address = '';
  310. $name = '';
  311. if ($f->type_application == 'R') {
  312. if (!empty($f->Subscriber->building_name)) {
  313. $address = $f->Subscriber->building_name;
  314. $name = $f->Subscriber->name;
  315. }
  316. } else if ($f->type_application == 'B') {
  317. $address = '-';
  318. $name = $f->Subscriber->company_name;
  319. }
  320. if (!empty($wo->Docket)) {
  321. $end = date('m/Y', strtotime($wo->Docket->end_job));
  322. if ($mY == '') {
  323. array_push($nested_data, array(
  324. 'index' => $i . $f->type_application,
  325. 'wo' => $wo->wo,
  326. 'do' => $f->WorkOrder->docket_id,
  327. 'name' => $name,
  328. 'phone' => $f->Subscriber->phone1,
  329. 'unit' => $f->Subscriber->unit_no,
  330. 'building' => $address,
  331. 'street' => $f->Subscriber->street,
  332. 'postcode' => $f->Subscriber->postcode,
  333. 'city' => $f->Subscriber->city,
  334. 'sales' => $dealer->name,
  335. 'action' => $f->_id
  336. ));
  337. } else if ($mY == $end) {
  338. array_push($nested_data, array(
  339. 'index' => $i . $f->type_application,
  340. 'wo' => $wo->wo,
  341. 'do' => $f->WorkOrder->docket_id,
  342. 'name' => $name,
  343. 'phone' => $f->Subscriber->phone1,
  344. 'unit' => $f->Subscriber->unit_no,
  345. 'building' => $address,
  346. 'street' => $f->Subscriber->street,
  347. 'postcode' => $f->Subscriber->postcode,
  348. 'city' => $f->Subscriber->city,
  349. 'sales' => $dealer->name,
  350. 'action' => $f->_id
  351. ));
  352. }
  353. }
  354. }
  355. }
  356. }
  357. return \DataTables::of($nested_data)->make(true);
  358. }
  359. /***
  360. / Encrypt Password
  361. ***/
  362. public function encryptPassword($action, $string)
  363. {
  364. $output = false;
  365. $encrypt_method = "AES-256-CBC";
  366. $secret_key = '28472B4B6250655368566D5970337336';
  367. $secret_iv = md5(md5($string)); //'This is my secret iv';
  368. // hash
  369. $key = hash('sha256', $secret_key);
  370. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  371. if ($action == 'encrypt') {
  372. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  373. $output = base64_encode($output);
  374. } else if ($action == 'decrypt') {
  375. $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  376. }
  377. return $output;
  378. }
  379. /***
  380. / Application Form
  381. ***/
  382. public function showResidentialForm()
  383. {
  384. $id = Auth::guard('eephr')->id();
  385. $user = Staff::find($id);
  386. $email = $user->email;
  387. $userDetails = StaffDetail::where('email', $email)->first();
  388. return view('eep-hr.residential-form', compact('userDetails', 'user'));
  389. }
  390. public function exportDealerJson(Request $request)
  391. {
  392. $final = array();
  393. $id = Auth::guard('ds')->id();
  394. // $user = Staff::with('StaffDetail')->find($id);
  395. // $com = Company::where('_id',$user->StaffDetail->company_id)->first();
  396. $dataR = array();
  397. $dataB = array();
  398. $combineData = array();
  399. $extra = 0;
  400. $year = $request->year;
  401. $month = $request->month;
  402. $app = $request->app;
  403. $company = $request->company;
  404. if ($year != 'null' && $month != 'null' && $app == 'null') {
  405. $count_cyberjaya = array();
  406. $count_jasin = array();
  407. $count_ayerKeroh = array();
  408. $count_alorGajah = array();
  409. $count_menglembu = array();
  410. $count_ipoh = array();
  411. $extra = 0;
  412. $basic_total = 0;
  413. $countAugustR = array();
  414. $countAugustB = array();
  415. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  416. // $dataDis = $this->returnDataR($company,'2019','12');
  417. // $dataJan = $this->returnDataR($company,'2020','1');
  418. if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  419. $dataApril = $this->returnDataR($company, '2020', '4');
  420. $dataMay = $this->returnDataR($company, '2020', '5');
  421. $dataJune = $this->returnDataR($company, '2020', '6');
  422. $dataJuly = $this->returnDataR($company, '2020', '7');
  423. foreach ($dataApril as $key => $d) {
  424. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  425. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  426. // $count_cyberjaya[] = $d;
  427. // }
  428. // if (strpos($d['address'], 'Jasin') !== false) {
  429. // $count_jasin[] = $d;
  430. // }
  431. // }
  432. // // else
  433. if (date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020') {
  434. if (strpos($d['address'], 'Cyberjaya') !== false) {
  435. $count_cyberjaya[] = $d;
  436. }
  437. if (strpos($d['address'], 'Jasin') !== false) {
  438. $count_jasin[] = $d;
  439. }
  440. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  441. $count_ayerKeroh[] = $d;
  442. }
  443. if (strpos($d['address'], 'Alor Gajah') !== false) {
  444. $count_alorGajah[] = $d;
  445. }
  446. if (strpos($d['address'], 'Menglembu') !== false) {
  447. $count_menglembu[] = $d;
  448. }
  449. if (strpos($d['address'], 'Ipoh') !== false) {
  450. $count_ipoh[] = $d;
  451. }
  452. } else {
  453. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  454. $combineData[] = $d;
  455. }
  456. }
  457. }
  458. foreach ($dataMay as $key => $d) {
  459. if (strpos($d['address'], 'Cyberjaya') !== false) {
  460. $count_cyberjaya[] = $d;
  461. }
  462. if (strpos($d['address'], 'Jasin') !== false) {
  463. $count_jasin[] = $d;
  464. }
  465. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  466. $count_ayerKeroh[] = $d;
  467. }
  468. if (strpos($d['address'], 'Alor Gajah') !== false) {
  469. $count_alorGajah[] = $d;
  470. }
  471. if (strpos($d['address'], 'Menglembu') !== false) {
  472. $count_menglembu[] = $d;
  473. }
  474. if (strpos($d['address'], 'Ipoh') !== false) {
  475. $count_ipoh[] = $d;
  476. }
  477. }
  478. foreach ($dataJune as $key => $d) {
  479. if (strpos($d['address'], 'Cyberjaya') !== false) {
  480. $count_cyberjaya[] = $d;
  481. }
  482. if (strpos($d['address'], 'Jasin') !== false) {
  483. $count_jasin[] = $d;
  484. }
  485. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  486. $count_ayerKeroh[] = $d;
  487. }
  488. if (strpos($d['address'], 'Alor Gajah') !== false) {
  489. $count_alorGajah[] = $d;
  490. }
  491. if (strpos($d['address'], 'Menglembu') !== false) {
  492. $count_menglembu[] = $d;
  493. }
  494. if (strpos($d['address'], 'Ipoh') !== false) {
  495. $count_ipoh[] = $d;
  496. }
  497. }
  498. foreach ($dataJuly as $key => $d) {
  499. if (strpos($d['address'], 'Cyberjaya') !== false) {
  500. $count_cyberjaya[] = $d;
  501. }
  502. if (strpos($d['address'], 'Jasin') !== false) {
  503. $count_jasin[] = $d;
  504. }
  505. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  506. $count_ayerKeroh[] = $d;
  507. }
  508. if (strpos($d['address'], 'Alor Gajah') !== false) {
  509. $count_alorGajah[] = $d;
  510. }
  511. if (strpos($d['address'], 'Menglembu') !== false) {
  512. $count_menglembu[] = $d;
  513. }
  514. if (strpos($d['address'], 'Ipoh') !== false) {
  515. $count_ipoh[] = $d;
  516. }
  517. }
  518. // Store to combineData New Incentives Cyberjaya
  519. foreach ($count_cyberjaya as $key => $d) {
  520. if (count($count_cyberjaya) > 50) {
  521. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  522. if ($d['contract'] == '12') {
  523. array_push($combineData, array(
  524. 'index' => $d['index'],
  525. 'contract' => $d['contract'],
  526. 'wo' => $d['wo'],
  527. 'activation' => $d['activation'],
  528. 'name' => $d['name'],
  529. 'address' => $d['address'],
  530. 'package' => $d['package'],
  531. 'retail_price' => $d['retail_price'],
  532. 'incentives1' => $d['incentives1'],
  533. 'incentives2' => $d['incentives2'],
  534. 'total' => $d['total'],
  535. 'claim' => $d['claim'],
  536. ));
  537. } else {
  538. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  539. array_push($combineData, array(
  540. 'index' => $d['index'],
  541. 'contract' => $d['contract'],
  542. 'wo' => $d['wo'],
  543. 'activation' => $d['activation'],
  544. 'name' => $d['name'],
  545. 'address' => $d['address'],
  546. 'package' => $d['package'],
  547. 'retail_price' => $d['retail_price'],
  548. 'incentives1' => '230%',
  549. 'incentives2' => $d['incentives2'],
  550. 'total' => 'RM ' . $total,
  551. 'claim' => $d['claim'],
  552. ));
  553. }
  554. }
  555. } else if (count($count_cyberjaya) < 50) {
  556. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  557. array_push($combineData, array(
  558. 'index' => $d['index'],
  559. 'contract' => $d['contract'],
  560. 'wo' => $d['wo'],
  561. 'activation' => $d['activation'],
  562. 'name' => $d['name'],
  563. 'address' => $d['address'],
  564. 'package' => $d['package'],
  565. 'retail_price' => $d['retail_price'],
  566. 'incentives1' => $d['incentives1'],
  567. 'incentives2' => $d['incentives2'],
  568. 'total' => $d['total'],
  569. 'claim' => $d['claim'],
  570. ));
  571. }
  572. }
  573. }
  574. // Store to combineData New Incentives Menglembu
  575. foreach ($count_menglembu as $key => $d) {
  576. if (count($count_menglembu) > 50) {
  577. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  578. if ($d['contract'] == '12') {
  579. array_push($combineData, array(
  580. 'index' => $d['index'],
  581. 'contract' => $d['contract'],
  582. 'wo' => $d['wo'],
  583. 'activation' => $d['activation'],
  584. 'name' => $d['name'],
  585. 'address' => $d['address'],
  586. 'package' => $d['package'],
  587. 'retail_price' => $d['retail_price'],
  588. 'incentives1' => $d['incentives1'],
  589. 'incentives2' => $d['incentives2'],
  590. 'total' => $d['total'],
  591. 'claim' => $d['claim'],
  592. ));
  593. } else {
  594. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  595. array_push($combineData, array(
  596. 'index' => $d['index'],
  597. 'contract' => $d['contract'],
  598. 'wo' => $d['wo'],
  599. 'activation' => $d['activation'],
  600. 'name' => $d['name'],
  601. 'address' => $d['address'],
  602. 'package' => $d['package'],
  603. 'retail_price' => $d['retail_price'],
  604. 'incentives1' => '230%',
  605. 'incentives2' => $d['incentives2'],
  606. 'total' => 'RM ' . $total,
  607. 'claim' => $d['claim'],
  608. ));
  609. }
  610. }
  611. } else if (count($count_menglembu) < 50) {
  612. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  613. array_push($combineData, array(
  614. 'index' => $d['index'],
  615. 'contract' => $d['contract'],
  616. 'wo' => $d['wo'],
  617. 'activation' => $d['activation'],
  618. 'name' => $d['name'],
  619. 'address' => $d['address'],
  620. 'package' => $d['package'],
  621. 'retail_price' => $d['retail_price'],
  622. 'incentives1' => $d['incentives1'],
  623. 'incentives2' => $d['incentives2'],
  624. 'total' => $d['total'],
  625. 'claim' => $d['claim'],
  626. ));
  627. }
  628. }
  629. }
  630. // Store to combineData New Incentives Ipoh
  631. foreach ($count_ipoh as $key => $d) {
  632. if (count($count_ipoh) > 50) {
  633. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  634. if ($d['contract'] == '12') {
  635. array_push($combineData, array(
  636. 'index' => $d['index'],
  637. 'contract' => $d['contract'],
  638. 'wo' => $d['wo'],
  639. 'activation' => $d['activation'],
  640. 'name' => $d['name'],
  641. 'address' => $d['address'],
  642. 'package' => $d['package'],
  643. 'retail_price' => $d['retail_price'],
  644. 'incentives1' => $d['incentives1'],
  645. 'incentives2' => $d['incentives2'],
  646. 'total' => $d['total'],
  647. 'claim' => $d['claim'],
  648. ));
  649. } else {
  650. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  651. array_push($combineData, array(
  652. 'index' => $d['index'],
  653. 'contract' => $d['contract'],
  654. 'wo' => $d['wo'],
  655. 'activation' => $d['activation'],
  656. 'name' => $d['name'],
  657. 'address' => $d['address'],
  658. 'package' => $d['package'],
  659. 'retail_price' => $d['retail_price'],
  660. 'incentives1' => '230%',
  661. 'incentives2' => $d['incentives2'],
  662. 'total' => 'RM ' . $total,
  663. 'claim' => $d['claim'],
  664. ));
  665. }
  666. }
  667. } else if (count($count_ipoh) < 50) {
  668. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  669. array_push($combineData, array(
  670. 'index' => $d['index'],
  671. 'contract' => $d['contract'],
  672. 'wo' => $d['wo'],
  673. 'activation' => $d['activation'],
  674. 'name' => $d['name'],
  675. 'address' => $d['address'],
  676. 'package' => $d['package'],
  677. 'retail_price' => $d['retail_price'],
  678. 'incentives1' => $d['incentives1'],
  679. 'incentives2' => $d['incentives2'],
  680. 'total' => $d['total'],
  681. 'claim' => $d['claim'],
  682. ));
  683. }
  684. }
  685. }
  686. // Store to combineData New Incentives Ayer Keroh
  687. foreach ($count_ayerKeroh as $key => $d) {
  688. if (count($count_ayerKeroh) > 50) {
  689. if ($d['contract'] == '12') {
  690. array_push($combineData, array(
  691. 'index' => $d['index'],
  692. 'contract' => $d['contract'],
  693. 'wo' => $d['wo'],
  694. 'activation' => $d['activation'],
  695. 'name' => $d['name'],
  696. 'address' => $d['address'],
  697. 'package' => $d['package'],
  698. 'retail_price' => $d['retail_price'],
  699. 'incentives1' => $d['incentives1'],
  700. 'incentives2' => $d['incentives2'],
  701. 'total' => $d['total'],
  702. 'claim' => $d['claim'],
  703. ));
  704. } else {
  705. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  706. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  707. array_push($combineData, array(
  708. 'index' => $d['index'],
  709. 'contract' => $d['contract'],
  710. 'wo' => $d['wo'],
  711. 'activation' => $d['activation'],
  712. 'name' => $d['name'],
  713. 'address' => $d['address'],
  714. 'package' => $d['package'],
  715. 'retail_price' => $d['retail_price'],
  716. 'incentives1' => '230%',
  717. 'incentives2' => $d['incentives2'],
  718. 'total' => 'RM ' . $total,
  719. 'claim' => $d['claim'],
  720. ));
  721. }
  722. }
  723. } else if (count($count_ayerKeroh) < 50) {
  724. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  725. array_push($combineData, array(
  726. 'index' => $d['index'],
  727. 'contract' => $d['contract'],
  728. 'wo' => $d['wo'],
  729. 'activation' => $d['activation'],
  730. 'name' => $d['name'],
  731. 'address' => $d['address'],
  732. 'package' => $d['package'],
  733. 'retail_price' => $d['retail_price'],
  734. 'incentives1' => $d['incentives1'],
  735. 'incentives2' => $d['incentives2'],
  736. 'total' => $d['total'],
  737. 'claim' => $d['claim'],
  738. ));
  739. }
  740. }
  741. }
  742. // Store to combineData New Incentives Alor Gajah
  743. foreach ($count_alorGajah as $key => $d) {
  744. if (count($count_alorGajah) > 50) {
  745. if ($d['contract'] == '12') {
  746. array_push($combineData, array(
  747. 'index' => $d['index'],
  748. 'contract' => $d['contract'],
  749. 'wo' => $d['wo'],
  750. 'activation' => $d['activation'],
  751. 'name' => $d['name'],
  752. 'address' => $d['address'],
  753. 'package' => $d['package'],
  754. 'retail_price' => $d['retail_price'],
  755. 'incentives1' => $d['incentives1'],
  756. 'incentives2' => $d['incentives2'],
  757. 'total' => $d['total'],
  758. 'claim' => $d['claim'],
  759. ));
  760. } else {
  761. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  762. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  763. array_push($combineData, array(
  764. 'index' => $d['index'],
  765. 'contract' => $d['contract'],
  766. 'wo' => $d['wo'],
  767. 'activation' => $d['activation'],
  768. 'name' => $d['name'],
  769. 'address' => $d['address'],
  770. 'package' => $d['package'],
  771. 'retail_price' => $d['retail_price'],
  772. 'incentives1' => '230%',
  773. 'incentives2' => $d['incentives2'],
  774. 'total' => 'RM ' . $total,
  775. 'claim' => $d['claim'],
  776. ));
  777. }
  778. }
  779. } else if (count($count_alorGajah) < 50) {
  780. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  781. array_push($combineData, array(
  782. 'index' => $d['index'],
  783. 'contract' => $d['contract'],
  784. 'wo' => $d['wo'],
  785. 'activation' => $d['activation'],
  786. 'name' => $d['name'],
  787. 'address' => $d['address'],
  788. 'package' => $d['package'],
  789. 'retail_price' => $d['retail_price'],
  790. 'incentives1' => $d['incentives1'],
  791. 'incentives2' => $d['incentives2'],
  792. 'total' => $d['total'],
  793. 'claim' => $d['claim'],
  794. ));
  795. }
  796. }
  797. }
  798. // Store to combineData New Incentives Jasin
  799. foreach ($count_jasin as $key => $d) {
  800. if (count($count_jasin) > 20) {
  801. if ($d['contract'] == '12') {
  802. array_push($combineData, array(
  803. 'index' => $d['index'],
  804. 'contract' => $d['contract'],
  805. 'wo' => $d['wo'],
  806. 'activation' => $d['activation'],
  807. 'name' => $d['name'],
  808. 'address' => $d['address'],
  809. 'package' => $d['package'],
  810. 'retail_price' => $d['retail_price'],
  811. 'incentives1' => $d['incentives1'],
  812. 'incentives2' => $d['incentives2'],
  813. 'total' => $d['total'],
  814. 'claim' => $d['claim'],
  815. ));
  816. } else {
  817. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  818. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  819. array_push($combineData, array(
  820. 'index' => $d['index'],
  821. 'contract' => $d['contract'],
  822. 'wo' => $d['wo'],
  823. 'activation' => $d['activation'],
  824. 'name' => $d['name'],
  825. 'address' => $d['address'],
  826. 'package' => $d['package'],
  827. 'retail_price' => $d['retail_price'],
  828. 'incentives1' => '230%',
  829. 'incentives2' => $d['incentives2'],
  830. 'total' => 'RM ' . $total,
  831. 'claim' => $d['claim'],
  832. ));
  833. }
  834. }
  835. } else if (count($count_jasin) < 20) {
  836. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  837. array_push($combineData, array(
  838. 'index' => $d['index'],
  839. 'contract' => $d['contract'],
  840. 'wo' => $d['wo'],
  841. 'activation' => $d['activation'],
  842. 'name' => $d['name'],
  843. 'address' => $d['address'],
  844. 'package' => $d['package'],
  845. 'retail_price' => $d['retail_price'],
  846. 'incentives1' => $d['incentives1'],
  847. 'incentives2' => $d['incentives2'],
  848. 'total' => $d['total'],
  849. 'claim' => $d['claim'],
  850. ));
  851. }
  852. }
  853. }
  854. } else if ($year == '2020' && ($month == '08' || $month == '09' || $month == '10')) {
  855. $dataAugustR = $this->returnDataR($company, '2020', '8');
  856. $dataAugustB = $this->returnDataB($company, '2020', '8');
  857. $dataSeptemberR = $this->returnDataR($company, '2020', '9');
  858. $dataSeptemberB = $this->returnDataB($company, '2020', '9');
  859. $dataOctoberR = $this->returnDataR($company, '2020', '10');
  860. $dataOctoberB = $this->returnDataB($company, '2020', '10');
  861. foreach ($dataAugustR as $key => $d) {
  862. if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') {
  863. if ($d['contract'] == '24') {
  864. if ($d['package'] == 50) {
  865. $d['retail_price'] = 69;
  866. } elseif ($d['package'] == 100) {
  867. $d['retail_price'] = 89;
  868. } elseif ($d['package'] == 500) {
  869. $d['retail_price'] = 129;
  870. }
  871. }
  872. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  873. $countAugustR[] = $d;
  874. }
  875. } else {
  876. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  877. $countAugustR[] = $d;
  878. } else {
  879. $combineData[] = $d;
  880. }
  881. }
  882. }
  883. // Store to combineData New Incentive August
  884. foreach ($countAugustR as $key => $d) {
  885. if (count($dataAugustR) >= 50) {
  886. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  887. if ($d['contract'] == '12') {
  888. array_push($combineData, array(
  889. 'index' => $d['index'],
  890. 'contract' => $d['contract'],
  891. 'wo' => $d['wo'],
  892. 'activation' => $d['activation'],
  893. 'name' => $d['name'],
  894. 'address' => $d['address'],
  895. 'package' => $d['package'],
  896. 'retail_price' => $d['retail_price'],
  897. 'incentives1' => $d['incentives1'],
  898. 'incentives2' => $d['incentives2'],
  899. 'total' => $d['total'],
  900. 'claim' => $d['claim'],
  901. ));
  902. } else {
  903. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  904. array_push($combineData, array(
  905. 'index' => $d['index'],
  906. 'contract' => $d['contract'],
  907. 'wo' => $d['wo'],
  908. 'activation' => $d['activation'],
  909. 'name' => $d['name'],
  910. 'address' => $d['address'],
  911. 'package' => $d['package'],
  912. 'retail_price' => $d['retail_price'],
  913. 'incentives1' => '250% + RM50',
  914. 'incentives2' => $d['incentives2'],
  915. 'total' => 'RM ' . $total,
  916. 'claim' => $d['claim'],
  917. ));
  918. }
  919. }
  920. } else if (count($dataAugustR) < 50) {
  921. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  922. if ($d['contract'] == '12') {
  923. array_push($combineData, array(
  924. 'index' => $d['index'],
  925. 'contract' => $d['contract'],
  926. 'wo' => $d['wo'],
  927. 'activation' => $d['activation'],
  928. 'name' => $d['name'],
  929. 'address' => $d['address'],
  930. 'package' => $d['package'],
  931. 'retail_price' => $d['retail_price'],
  932. 'incentives1' => $d['incentives1'],
  933. 'incentives2' => $d['incentives2'],
  934. 'total' => $d['total'],
  935. 'claim' => $d['claim'],
  936. ));
  937. } else {
  938. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  939. array_push($combineData, array(
  940. 'index' => $d['index'],
  941. 'contract' => $d['contract'],
  942. 'wo' => $d['wo'],
  943. 'activation' => $d['activation'],
  944. 'name' => $d['name'],
  945. 'address' => $d['address'],
  946. 'package' => $d['package'],
  947. 'retail_price' => $d['retail_price'],
  948. 'incentives1' => '250%',
  949. 'incentives2' => $d['incentives2'],
  950. 'total' => 'RM ' . $total,
  951. 'claim' => $d['claim'],
  952. ));
  953. }
  954. }
  955. }
  956. }
  957. foreach ($dataAugustB as $key => $d) {
  958. if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') {
  959. if ($d['contract'] == '24') {
  960. if ($d['package'] == 50) {
  961. $d['retail_price'] = 89;
  962. } elseif ($d['package'] == 100) {
  963. $d['retail_price'] = 119;
  964. } elseif ($d['package'] == 300) {
  965. $d['retail_price'] = 179;
  966. } elseif ($d['package'] == 500) {
  967. $d['retail_price'] = 249;
  968. }
  969. }
  970. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  971. $countAugustB[] = $d;
  972. }
  973. } else {
  974. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  975. $countAugustB[] = $d;
  976. } else {
  977. $combineData[] = $d;
  978. }
  979. }
  980. }
  981. // Store to combineData New Incentive August
  982. foreach ($countAugustB as $key => $d) {
  983. if (count($dataAugustB) >= 50) {
  984. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  985. if ($d['contract'] == '12') {
  986. array_push($combineData, array(
  987. 'index' => $d['index'],
  988. 'contract' => $d['contract'],
  989. 'wo' => $d['wo'],
  990. 'activation' => $d['activation'],
  991. 'name' => $d['name'],
  992. 'address' => $d['address'],
  993. 'package' => $d['package'],
  994. 'retail_price' => $d['retail_price'],
  995. 'incentives1' => $d['incentives1'],
  996. 'incentives2' => $d['incentives2'],
  997. 'total' => $d['total'],
  998. 'claim' => $d['claim'],
  999. ));
  1000. } else {
  1001. if ($d['package'] == 1) {
  1002. $total = 1500;
  1003. } else {
  1004. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  1005. }
  1006. array_push($combineData, array(
  1007. 'index' => $d['index'],
  1008. 'contract' => $d['contract'],
  1009. 'wo' => $d['wo'],
  1010. 'activation' => $d['activation'],
  1011. 'name' => $d['name'],
  1012. 'address' => $d['address'],
  1013. 'package' => $d['package'],
  1014. 'retail_price' => $d['retail_price'],
  1015. 'incentives1' => '250% + RM50',
  1016. 'incentives2' => '',
  1017. 'total' => 'RM ' . $total,
  1018. 'claim' => $d['claim'],
  1019. ));
  1020. }
  1021. }
  1022. } else if (count($dataAugustB) < 50) {
  1023. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1024. if ($d['contract'] == '12') {
  1025. array_push($combineData, array(
  1026. 'index' => $d['index'],
  1027. 'contract' => $d['contract'],
  1028. 'wo' => $d['wo'],
  1029. 'activation' => $d['activation'],
  1030. 'name' => $d['name'],
  1031. 'address' => $d['address'],
  1032. 'package' => $d['package'],
  1033. 'retail_price' => $d['retail_price'],
  1034. 'incentives1' => $d['incentives1'],
  1035. 'incentives2' => $d['incentives2'],
  1036. 'total' => $d['total'],
  1037. 'claim' => $d['claim'],
  1038. ));
  1039. } else {
  1040. if ($d['package'] == 1) {
  1041. $total = 1500;
  1042. } else {
  1043. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  1044. }
  1045. array_push($combineData, array(
  1046. 'index' => $d['index'],
  1047. 'contract' => $d['contract'],
  1048. 'wo' => $d['wo'],
  1049. 'activation' => $d['activation'],
  1050. 'name' => $d['name'],
  1051. 'address' => $d['address'],
  1052. 'package' => $d['package'],
  1053. 'retail_price' => $d['retail_price'],
  1054. 'incentives1' => '250%',
  1055. 'incentives2' => '',
  1056. 'total' => 'RM ' . $total,
  1057. 'claim' => $d['claim'],
  1058. ));
  1059. }
  1060. }
  1061. }
  1062. }
  1063. foreach ($dataSeptemberR as $key => $d) {
  1064. 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)) {
  1065. if ($d['contract'] == '24') {
  1066. if ($d['package'] == 50) {
  1067. $d['retail_price'] = 69;
  1068. } elseif ($d['package'] == 100) {
  1069. $d['retail_price'] = 89;
  1070. } elseif ($d['package'] == 500) {
  1071. $d['retail_price'] = 129;
  1072. }
  1073. }
  1074. }
  1075. if (count($dataSeptemberR) >= 50) {
  1076. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1077. if ($d['contract'] == '12') {
  1078. array_push($combineData, array(
  1079. 'index' => $d['index'],
  1080. 'contract' => $d['contract'],
  1081. 'wo' => $d['wo'],
  1082. 'activation' => $d['activation'],
  1083. 'name' => $d['name'],
  1084. 'address' => $d['address'],
  1085. 'package' => $d['package'],
  1086. 'retail_price' => $d['retail_price'],
  1087. 'incentives1' => $d['incentives1'],
  1088. 'incentives2' => $d['incentives2'],
  1089. 'total' => $d['total'],
  1090. 'claim' => $d['claim'],
  1091. ));
  1092. } else {
  1093. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  1094. array_push($combineData, array(
  1095. 'index' => $d['index'],
  1096. 'contract' => $d['contract'],
  1097. 'wo' => $d['wo'],
  1098. 'activation' => $d['activation'],
  1099. 'name' => $d['name'],
  1100. 'address' => $d['address'],
  1101. 'package' => $d['package'],
  1102. 'retail_price' => $d['retail_price'],
  1103. 'incentives1' => '250% + RM50',
  1104. 'incentives2' => $d['incentives2'],
  1105. 'total' => 'RM ' . $total,
  1106. 'claim' => $d['claim'],
  1107. ));
  1108. }
  1109. }
  1110. } else if (count($dataSeptemberR) < 50) {
  1111. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1112. if ($d['contract'] == '12') {
  1113. array_push($combineData, array(
  1114. 'index' => $d['index'],
  1115. 'contract' => $d['contract'],
  1116. 'wo' => $d['wo'],
  1117. 'activation' => $d['activation'],
  1118. 'name' => $d['name'],
  1119. 'address' => $d['address'],
  1120. 'package' => $d['package'],
  1121. 'retail_price' => $d['retail_price'],
  1122. 'incentives1' => $d['incentives1'],
  1123. 'incentives2' => $d['incentives2'],
  1124. 'total' => $d['total'],
  1125. 'claim' => $d['claim'],
  1126. ));
  1127. } else {
  1128. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  1129. array_push($combineData, array(
  1130. 'index' => $d['index'],
  1131. 'contract' => $d['contract'],
  1132. 'wo' => $d['wo'],
  1133. 'activation' => $d['activation'],
  1134. 'name' => $d['name'],
  1135. 'address' => $d['address'],
  1136. 'package' => $d['package'],
  1137. 'retail_price' => $d['retail_price'],
  1138. 'incentives1' => '250%',
  1139. 'incentives2' => $d['incentives2'],
  1140. 'total' => 'RM ' . $total,
  1141. 'claim' => $d['claim'],
  1142. ));
  1143. }
  1144. }
  1145. }
  1146. }
  1147. foreach ($dataSeptemberB as $key => $d) {
  1148. 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)) {
  1149. if ($d['contract'] == '24') {
  1150. if ($d['package'] == 50) {
  1151. $d['retail_price'] = 89;
  1152. } elseif ($d['package'] == 100) {
  1153. $d['retail_price'] = 119;
  1154. } elseif ($d['package'] == 300) {
  1155. $d['retail_price'] = 179;
  1156. } elseif ($d['package'] == 500) {
  1157. $d['retail_price'] = 249;
  1158. }
  1159. }
  1160. }
  1161. if (count($dataSeptemberB) >= 50) {
  1162. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1163. if ($d['contract'] == '12') {
  1164. array_push($combineData, array(
  1165. 'index' => $d['index'],
  1166. 'contract' => $d['contract'],
  1167. 'wo' => $d['wo'],
  1168. 'activation' => $d['activation'],
  1169. 'name' => $d['name'],
  1170. 'address' => $d['address'],
  1171. 'package' => $d['package'],
  1172. 'retail_price' => $d['retail_price'],
  1173. 'incentives1' => $d['incentives1'],
  1174. 'incentives2' => $d['incentives2'],
  1175. 'total' => $d['total'],
  1176. 'claim' => $d['claim'],
  1177. ));
  1178. } else {
  1179. if ($d['package'] == 1) {
  1180. $total = 1500;
  1181. } else {
  1182. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  1183. }
  1184. array_push($combineData, array(
  1185. 'index' => $d['index'],
  1186. 'contract' => $d['contract'],
  1187. 'wo' => $d['wo'],
  1188. 'activation' => $d['activation'],
  1189. 'name' => $d['name'],
  1190. 'address' => $d['address'],
  1191. 'package' => $d['package'],
  1192. 'retail_price' => $d['retail_price'],
  1193. 'incentives1' => '250% + RM50',
  1194. 'incentives2' => '',
  1195. 'total' => 'RM ' . $total,
  1196. 'claim' => $d['claim'],
  1197. ));
  1198. }
  1199. }
  1200. } else if (count($dataSeptemberB) < 50) {
  1201. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1202. if ($d['contract'] == '12') {
  1203. array_push($combineData, array(
  1204. 'index' => $d['index'],
  1205. 'contract' => $d['contract'],
  1206. 'wo' => $d['wo'],
  1207. 'activation' => $d['activation'],
  1208. 'name' => $d['name'],
  1209. 'address' => $d['address'],
  1210. 'package' => $d['package'],
  1211. 'retail_price' => $d['retail_price'],
  1212. 'incentives1' => $d['incentives1'],
  1213. 'incentives2' => $d['incentives2'],
  1214. 'total' => $d['total'],
  1215. 'claim' => $d['claim'],
  1216. ));
  1217. } else {
  1218. if ($d['package'] == 1) {
  1219. $total = 1500;
  1220. } else {
  1221. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  1222. }
  1223. array_push($combineData, array(
  1224. 'index' => $d['index'],
  1225. 'contract' => $d['contract'],
  1226. 'wo' => $d['wo'],
  1227. 'activation' => $d['activation'],
  1228. 'name' => $d['name'],
  1229. 'address' => $d['address'],
  1230. 'package' => $d['package'],
  1231. 'retail_price' => $d['retail_price'],
  1232. 'incentives1' => '250%',
  1233. 'incentives2' => '',
  1234. 'total' => 'RM ' . $total,
  1235. 'claim' => $d['claim'],
  1236. ));
  1237. }
  1238. }
  1239. }
  1240. }
  1241. foreach ($dataOctoberR as $key => $d) {
  1242. 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')) {
  1243. if ($d['contract'] == '24') {
  1244. if ($d['package'] == 50) {
  1245. $d['retail_price'] = 69;
  1246. } elseif ($d['package'] == 100) {
  1247. $d['retail_price'] = 89;
  1248. } elseif ($d['package'] == 500) {
  1249. $d['retail_price'] = 129;
  1250. }
  1251. }
  1252. }
  1253. if (count($dataOctoberR) >= 50) {
  1254. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1255. if ($d['contract'] == '12') {
  1256. array_push($combineData, array(
  1257. 'index' => $d['index'],
  1258. 'contract' => $d['contract'],
  1259. 'wo' => $d['wo'],
  1260. 'activation' => $d['activation'],
  1261. 'name' => $d['name'],
  1262. 'address' => $d['address'],
  1263. 'package' => $d['package'],
  1264. 'retail_price' => $d['retail_price'],
  1265. 'incentives1' => $d['incentives1'],
  1266. 'incentives2' => $d['incentives2'],
  1267. 'total' => $d['total'],
  1268. 'claim' => $d['claim'],
  1269. ));
  1270. } else {
  1271. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  1272. array_push($combineData, array(
  1273. 'index' => $d['index'],
  1274. 'contract' => $d['contract'],
  1275. 'wo' => $d['wo'],
  1276. 'activation' => $d['activation'],
  1277. 'name' => $d['name'],
  1278. 'address' => $d['address'],
  1279. 'package' => $d['package'],
  1280. 'retail_price' => $d['retail_price'],
  1281. 'incentives1' => '250% + RM50',
  1282. 'incentives2' => $d['incentives2'],
  1283. 'total' => 'RM ' . $total,
  1284. 'claim' => $d['claim'],
  1285. ));
  1286. }
  1287. }
  1288. } else if (count($dataOctoberR) < 50) {
  1289. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1290. if ($d['contract'] == '12') {
  1291. array_push($combineData, array(
  1292. 'index' => $d['index'],
  1293. 'contract' => $d['contract'],
  1294. 'wo' => $d['wo'],
  1295. 'activation' => $d['activation'],
  1296. 'name' => $d['name'],
  1297. 'address' => $d['address'],
  1298. 'package' => $d['package'],
  1299. 'retail_price' => $d['retail_price'],
  1300. 'incentives1' => $d['incentives1'],
  1301. 'incentives2' => $d['incentives2'],
  1302. 'total' => $d['total'],
  1303. 'claim' => $d['claim'],
  1304. ));
  1305. } else {
  1306. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  1307. array_push($combineData, array(
  1308. 'index' => $d['index'],
  1309. 'contract' => $d['contract'],
  1310. 'wo' => $d['wo'],
  1311. 'activation' => $d['activation'],
  1312. 'name' => $d['name'],
  1313. 'address' => $d['address'],
  1314. 'package' => $d['package'],
  1315. 'retail_price' => $d['retail_price'],
  1316. 'incentives1' => '250%',
  1317. 'incentives2' => $d['incentives2'],
  1318. 'total' => 'RM ' . $total,
  1319. 'claim' => $d['claim'],
  1320. ));
  1321. }
  1322. }
  1323. }
  1324. }
  1325. foreach ($dataOctoberB as $key => $d) {
  1326. 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')) {
  1327. if ($d['contract'] == '24') {
  1328. if ($d['package'] == 50) {
  1329. $d['retail_price'] = 89;
  1330. } elseif ($d['package'] == 100) {
  1331. $d['retail_price'] = 119;
  1332. } elseif ($d['package'] == 300) {
  1333. $d['retail_price'] = 179;
  1334. } elseif ($d['package'] == 500) {
  1335. $d['retail_price'] = 249;
  1336. }
  1337. }
  1338. }
  1339. if (count($dataOctoberB) >= 50) {
  1340. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1341. if ($d['contract'] == '12') {
  1342. array_push($combineData, array(
  1343. 'index' => $d['index'],
  1344. 'contract' => $d['contract'],
  1345. 'wo' => $d['wo'],
  1346. 'activation' => $d['activation'],
  1347. 'name' => $d['name'],
  1348. 'address' => $d['address'],
  1349. 'package' => $d['package'],
  1350. 'retail_price' => $d['retail_price'],
  1351. 'incentives1' => $d['incentives1'],
  1352. 'incentives2' => $d['incentives2'],
  1353. 'total' => $d['total'],
  1354. 'claim' => $d['claim'],
  1355. ));
  1356. } else {
  1357. if ($d['package'] == 1) {
  1358. $total = 1500;
  1359. } else {
  1360. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  1361. }
  1362. array_push($combineData, array(
  1363. 'index' => $d['index'],
  1364. 'contract' => $d['contract'],
  1365. 'wo' => $d['wo'],
  1366. 'activation' => $d['activation'],
  1367. 'name' => $d['name'],
  1368. 'address' => $d['address'],
  1369. 'package' => $d['package'],
  1370. 'retail_price' => $d['retail_price'],
  1371. 'incentives1' => '250% + RM50',
  1372. 'incentives2' => '',
  1373. 'total' => 'RM ' . $total,
  1374. 'claim' => $d['claim'],
  1375. ));
  1376. }
  1377. }
  1378. } else if (count($dataOctoberB) < 50) {
  1379. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1380. if ($d['contract'] == '12') {
  1381. array_push($combineData, array(
  1382. 'index' => $d['index'],
  1383. 'contract' => $d['contract'],
  1384. 'wo' => $d['wo'],
  1385. 'activation' => $d['activation'],
  1386. 'name' => $d['name'],
  1387. 'address' => $d['address'],
  1388. 'package' => $d['package'],
  1389. 'retail_price' => $d['retail_price'],
  1390. 'incentives1' => $d['incentives1'],
  1391. 'incentives2' => $d['incentives2'],
  1392. 'total' => $d['total'],
  1393. 'claim' => $d['claim'],
  1394. ));
  1395. } else {
  1396. if ($d['package'] == 1) {
  1397. $total = 1500;
  1398. } else {
  1399. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  1400. }
  1401. array_push($combineData, array(
  1402. 'index' => $d['index'],
  1403. 'contract' => $d['contract'],
  1404. 'wo' => $d['wo'],
  1405. 'activation' => $d['activation'],
  1406. 'name' => $d['name'],
  1407. 'address' => $d['address'],
  1408. 'package' => $d['package'],
  1409. 'retail_price' => $d['retail_price'],
  1410. 'incentives1' => '250%',
  1411. 'incentives2' => '',
  1412. 'total' => 'RM ' . $total,
  1413. 'claim' => $d['claim'],
  1414. ));
  1415. }
  1416. }
  1417. }
  1418. }
  1419. } else if ($year == '2020' && ($month == '12')) {
  1420. $dataDecemberR = $this->returnDataR($company, '2020', '12');
  1421. foreach ($dataDecemberR as $r) {
  1422. $combineData[] = $r;
  1423. }
  1424. $dataDecemberB = $this->returnDataB($company, '2020', '12');
  1425. foreach ($dataDecemberB as $b) {
  1426. if ((date('m/Y', strtotime($b['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($b['submission'])) >= '21/12/2020') {
  1427. if (strpos($b['address'], 'CYBERJAYA') !== false && $b['contract'] == '24' && $b['package'] == 1) {
  1428. $b['retail_price'] = 999;
  1429. $count_businessCyber[] = $b;
  1430. }
  1431. else {
  1432. $combineData[] = $b;
  1433. }
  1434. } else {
  1435. $combineData[] = $b;
  1436. }
  1437. }
  1438. if(!empty($count_businessCyber)){
  1439. for ($i=0;$i<count($count_businessCyber);$i++){
  1440. info('i' . $i);
  1441. for($j=0; ($j<count($count_businessCyber)&&$j<51);$j++){
  1442. info('j' . $j);
  1443. $total = number_format(floatval(str_replace("RM ", "", $count_businessCyber[$j]['retail_price'])) * 2.0, 2);
  1444. array_push($combineData, array(
  1445. 'index' => $count_businessCyber[$j]['index'],
  1446. 'contract' => $count_businessCyber[$j]['contract'],
  1447. 'wo' => $count_businessCyber[$j]['wo'],
  1448. 'activation' => $count_businessCyber[$j]['activation'],
  1449. 'name' => $count_businessCyber[$j]['name'],
  1450. 'address' => $count_businessCyber[$j]['address'],
  1451. 'package' => $count_businessCyber[$j]['package'],
  1452. 'retail_price' => $count_businessCyber[$j]['retail_price'],
  1453. 'incentives1' => '200%',
  1454. 'incentives2' => $count_businessCyber[$j]['incentives2'],
  1455. 'total' => 'RM ' . $total,
  1456. 'claim' => $count_businessCyber[$j]['claim'],
  1457. ));
  1458. }
  1459. for($j=51; ($j < count($count_businessCyber) && $j>=51);$j++){
  1460. $total = number_format(floatval(str_replace("RM ", "", $count_businessCyber[$j]['retail_price'])) * 2.5, 2);
  1461. array_push($combineData, array(
  1462. 'index' => $count_businessCyber[$j]['index'],
  1463. 'contract' => $count_businessCyber[$j]['contract'],
  1464. 'wo' => $count_businessCyber[$j]['wo'],
  1465. 'activation' => $count_businessCyber[$j]['activation'],
  1466. 'name' => $count_businessCyber[$j]['name'],
  1467. 'address' => $count_businessCyber[$j]['address'],
  1468. 'package' => $count_businessCyber[$j]['package'],
  1469. 'retail_price' => $count_businessCyber[$j]['retail_price'],
  1470. 'incentives1' => '250%',
  1471. 'incentives2' => $count_businessCyber[$j]['incentives2'],
  1472. 'total' => 'RM ' . $total,
  1473. 'claim' => $count_businessCyber[$j]['claim'],
  1474. ));
  1475. }
  1476. }
  1477. }
  1478. } else {
  1479. $dataR = $this->returnDataR($company, $year, $month);
  1480. foreach ($dataR as $r) {
  1481. $combineData[] = $r;
  1482. }
  1483. $dataB = $this->returnDataB($company, $year, $month);
  1484. foreach ($dataB as $b) {
  1485. $combineData[] = $b;
  1486. }
  1487. }
  1488. $i = 0;
  1489. $nested_data = array();
  1490. if (!empty($combineData)) {
  1491. foreach ($combineData as $c) {
  1492. $update_dealer = DealerClaim::where('wo', $c['wo'])->first();
  1493. if (!empty($update_dealer)) {
  1494. $update_dealer->incentives1 = $c['incentives1'];
  1495. $update_dealer->incentives2 = $c['incentives2'];
  1496. $update_dealer->retail_price = $c['retail_price'];
  1497. $update_dealer->total_claim = $c['total'];
  1498. $update_dealer->save();
  1499. }
  1500. }
  1501. }
  1502. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1503. $q->with('Form');
  1504. }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->get();
  1505. if (!empty($dataClaim)) {
  1506. foreach ($dataClaim as $c) {
  1507. $address = '';
  1508. $name = '';
  1509. if ($c->Subscriber->Form->type_application == 'R') {
  1510. if ($c->Subscriber->street != '') {
  1511. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1512. } else {
  1513. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1514. }
  1515. $name = $c->Subscriber->name;
  1516. } else if ($c->Subscriber->Form->type_application == 'B') {
  1517. if ($c->Subscriber->unit_no != '') {
  1518. $unit = $c->Subscriber->unit_no;
  1519. } else {
  1520. $unit = ' ';
  1521. }
  1522. if ($c->Subscriber->building_name == null) {
  1523. $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1524. } else {
  1525. $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1526. }
  1527. $name = $c->Subscriber->company_name;
  1528. }
  1529. $i++;
  1530. array_push($final, array(
  1531. 'index' => $c->formT,
  1532. 'contract' => $c->contract,
  1533. 'wo' => $c->wo,
  1534. 'activated_dt' => $c->activated_dt,
  1535. 'name' => $name,
  1536. 'address' => $address,
  1537. 'package' => $c->package,
  1538. 'retail_price' => $c->retail_price,
  1539. 'incentives1' => $c->incentives1,
  1540. 'incentives2' => $c->incentives2,
  1541. 'total' => $c->total_claim,
  1542. 'claimed' => $c->claim_dt,
  1543. ));
  1544. }
  1545. }
  1546. foreach ($final as $f) {
  1547. $basic_total += floatval(str_replace('RM ', '', $f['total']));
  1548. }
  1549. // Calculate extra incentves
  1550. // if($month == '1' && $year == '2020'){
  1551. // if(count($count_cyberjaya) > 50){
  1552. // $balance = count($count_cyberjaya) - 50;
  1553. // $extra += $balance * 50;
  1554. // }
  1555. // if(count($count_jasin) > 10){
  1556. // $balance = count($count_jasin) - 10;
  1557. // $extra += $balance * 50;
  1558. // }
  1559. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  1560. // if(count($count_cyberjaya) > 50){
  1561. // $balance = count($count_cyberjaya) - 50;
  1562. // $extra += $balance * 50;
  1563. // }
  1564. // if(count($count_jasin) > 20){
  1565. // $balance = count($count_jasin) - 10;
  1566. // $extra += $balance * 50;
  1567. // }
  1568. // }else {
  1569. // $extra = 0;
  1570. // }
  1571. $extra = 0;
  1572. $totals = $basic_total + $extra;
  1573. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  1574. // $pdf->setPaper('A4', 'landscape');
  1575. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  1576. // return $pdf->download( $pdfName );
  1577. return $final;
  1578. }
  1579. // else if($year!='null' && $month!='null' && $app!='null'){
  1580. // $count_cyberjaya = array(); $count_jasin = array();
  1581. // $extra = 0; $basic_total = 0; $totals = 0;
  1582. // if($app == 'Residential'){
  1583. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  1584. // $dataDis = $this->returnDataR($company,'2019','12');
  1585. // $dataJan = $this->returnDataR($company,'2020','1');
  1586. // foreach ($dataDis as $key => $d) {
  1587. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  1588. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  1589. // $count_cyberjaya[] = $d;
  1590. // }
  1591. // if (strpos($d['address'], 'Jasin') !== false) {
  1592. // $count_jasin[] = $d;
  1593. // }
  1594. // }else if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020' && date('d/m/Y', strtotime($d['activation'])) <= '31/7/2020'){
  1595. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  1596. // $count_cyberjaya[] = $d;
  1597. // }
  1598. // if (strpos($d['address'], 'Jasin') !== false) {
  1599. // $count_jasin[] = $d;
  1600. // }
  1601. // }else {
  1602. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1603. // $combineData[] = $d;
  1604. // }
  1605. // }
  1606. // }
  1607. // foreach ($dataJan as $key => $d) {
  1608. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  1609. // $count_cyberjaya[] = $d;
  1610. // }
  1611. // if (strpos($d['address'], 'Jasin') !== false) {
  1612. // $count_jasin[] = $d;
  1613. // }
  1614. // }
  1615. // // Store to combineData New Incentives Cyberjaya
  1616. // foreach ($count_cyberjaya as $key => $d) {
  1617. // if(count($count_cyberjaya) > 50){
  1618. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1619. // if($d['contract'] == '12'){
  1620. // array_push($combineData, array(
  1621. // 'index' => $d['index'],
  1622. // 'contract' => $d['contract'],
  1623. // 'wo' => $d['wo'],
  1624. // 'activation' => $d['activation'],
  1625. // 'name' => $d['name'],
  1626. // 'address' => $d['address'],
  1627. // 'package' => $d['package'],
  1628. // 'retail_price' => $d['retail_price'],
  1629. // 'incentives1' => $d['incentives1'],
  1630. // 'incentives2' => $d['incentives2'],
  1631. // 'total' => $d['total'],
  1632. // 'claim' => $d['claim'],
  1633. // ));
  1634. // }else {
  1635. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1636. // array_push($combineData, array(
  1637. // 'index' => $d['index'],
  1638. // 'contract' => $d['contract'],
  1639. // 'wo' => $d['wo'],
  1640. // 'activation' => $d['activation'],
  1641. // 'name' => $d['name'],
  1642. // 'address' => $d['address'],
  1643. // 'package' => $d['package'],
  1644. // 'retail_price' => $d['retail_price'],
  1645. // 'incentives1' => '230%',
  1646. // 'incentives2' => $d['incentives2'],
  1647. // 'total' => 'RM '.$total,
  1648. // 'claim' => $d['claim'],
  1649. // ));
  1650. // }
  1651. // }
  1652. // }else if(count($count_cyberjaya) < 50){
  1653. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1654. // array_push($combineData, array(
  1655. // 'index' => $d['index'],
  1656. // 'contract' => $d['contract'],
  1657. // 'wo' => $d['wo'],
  1658. // 'activation' => $d['activation'],
  1659. // 'name' => $d['name'],
  1660. // 'address' => $d['address'],
  1661. // 'package' => $d['package'],
  1662. // 'retail_price' => $d['retail_price'],
  1663. // 'incentives1' => $d['incentives1'],
  1664. // 'incentives2' => $d['incentives2'],
  1665. // 'total' => $d['total'],
  1666. // 'claim' => $d['claim'],
  1667. // ));
  1668. // }
  1669. // }
  1670. // }
  1671. // // Store to combineData New Incentives Jasin
  1672. // foreach ($count_jasin as $key => $d) {
  1673. // if(count($count_jasin) > 10){
  1674. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1675. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1676. // array_push($combineData, array(
  1677. // 'index' => $d['index'],
  1678. // 'contract' => $d['contract'],
  1679. // 'wo' => $d['wo'],
  1680. // 'activation' => $d['activation'],
  1681. // 'name' => $d['name'],
  1682. // 'address' => $d['address'],
  1683. // 'package' => $d['package'],
  1684. // 'retail_price' => $d['retail_price'],
  1685. // 'incentives1' => '230%',
  1686. // 'incentives2' => $d['incentives2'],
  1687. // 'total' => 'RM '.$total,
  1688. // 'claim' => $d['claim'],
  1689. // ));
  1690. // }
  1691. // }else if(count($count_jasin) < 10){
  1692. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1693. // array_push($combineData, array(
  1694. // 'index' => $d['index'],
  1695. // 'contract' => $d['contract'],
  1696. // 'wo' => $d['wo'],
  1697. // 'activation' => $d['activation'],
  1698. // 'name' => $d['name'],
  1699. // 'address' => $d['address'],
  1700. // 'package' => $d['package'],
  1701. // 'retail_price' => $d['retail_price'],
  1702. // 'incentives1' => $d['incentives1'],
  1703. // 'incentives2' => $d['incentives2'],
  1704. // 'total' => $d['total'],
  1705. // 'claim' => $d['claim'],
  1706. // ));
  1707. // }
  1708. // }
  1709. // }
  1710. // }else {
  1711. // $dataR = $this->returnDataR($company,$year,$month);
  1712. // foreach($dataR as $r){
  1713. // $combineData[] = $r;
  1714. // }
  1715. // }
  1716. // }else if($app == 'Business'){
  1717. // $dataB = $this->returnDataB($company,$year,$month);
  1718. // }
  1719. // foreach($dataB as $b){
  1720. // $combineData[] = $b;
  1721. // }
  1722. // $i = 0;
  1723. // $nested_data = array();
  1724. // if(!empty($combineData)){
  1725. // foreach ($combineData as $c){
  1726. // $i++;
  1727. // array_push($final, array(
  1728. // 'index' => $c['index'],
  1729. // 'contract' => $c['contract'],
  1730. // 'wo' => $c['wo'],
  1731. // 'activated_dt' => $c['activation'],
  1732. // 'name' => $c['name'],
  1733. // 'address' => $c['address'],
  1734. // 'package' => $c['package'],
  1735. // 'retail_price' => $c['retail_price'],
  1736. // 'incentives1' => $c['incentives1'],
  1737. // 'incentives2' => $c['incentives2'],
  1738. // 'total' => $c['total'],
  1739. // 'claimed' => $c['claim'],
  1740. // ));
  1741. // }
  1742. // }
  1743. // foreach($final as $f){
  1744. // $basic_total += floatval(str_replace('RM ', '', $f['total']));
  1745. // }
  1746. // //Calculate extra incentves
  1747. // if($month == '1' && $year == '2020'){
  1748. // if(count($count_cyberjaya) > 50){
  1749. // $balance = count($count_cyberjaya) - 50;
  1750. // $extra += $balance * 50;
  1751. // }
  1752. // if(count($count_jasin) > 10){
  1753. // $balance = count($count_jasin) - 10;
  1754. // $extra += $balance * 50;
  1755. // }
  1756. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  1757. // if(count($count_cyberjaya) > 50){
  1758. // $balance = count($count_cyberjaya) - 50;
  1759. // $extra += $balance * 50;
  1760. // }
  1761. // if(count($count_jasin) > 20){
  1762. // $balance = count($count_jasin) - 10;
  1763. // $extra += $balance * 50;
  1764. // }
  1765. // }else {
  1766. // $extra = 0;
  1767. // }
  1768. // $totals = $basic_total + $extra;
  1769. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  1770. // $pdf->setPaper('A4', 'landscape');
  1771. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  1772. // return $pdf->download( $pdfName );
  1773. // }
  1774. }
  1775. }