You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DealerController.php 111KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647
  1. <?php
  2. namespace App\Http\Controllers\DS;
  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 DealerController extends Controller
  23. {
  24. public function viewList()
  25. {
  26. $id = Auth::guard('ds')->id();
  27. $user = Staff::with('StaffDetail')->find($id);
  28. return view('dealer.index', compact('user'));
  29. }
  30. /***
  31. / Agent list
  32. ***/
  33. public function gAgentList()
  34. {
  35. $id = Auth::guard('ds')->id();
  36. $user = Staff::find($id);
  37. $email = $user->email;
  38. $userDetails = StaffDetail::where('email', $email)->first();
  39. $all = StaffDetail::where('company_id', $userDetails->company_id)->orderBy('created_at', 'desc')->get();
  40. $curr = Carbon::now()->getTimestamp();
  41. $i = 0;
  42. $nested_data = array();
  43. if (!empty($all)) {
  44. foreach ($all as $a) {
  45. $i++;
  46. $y = '';
  47. $n1 = '';
  48. if ($userDetails->_id == $a->_id) {
  49. $y = $a->name . "-You";
  50. } else {
  51. $y = $a->name;
  52. }
  53. $reg_time = $a->created_at;
  54. $expiry_date = $reg_time->addDays(3);
  55. $expiry_date = $expiry_date->getTimestamp();
  56. if ($curr < $expiry_date) {
  57. $n1 = "New/";
  58. }
  59. array_push($nested_data, array(
  60. 'index' => $i,
  61. 'image' => $a->user_pic,
  62. 'name' => $n1 . $y,
  63. 'ic' => $a->ic,
  64. 'phone' => $a->phone,
  65. 'email' => $a->email,
  66. 'action' => $a->_id
  67. ));
  68. }
  69. }
  70. return \DataTables::of($nested_data)->make(true);
  71. }
  72. /***
  73. / Application Form List
  74. ***/
  75. public function viewAppList()
  76. {
  77. $id = Auth::guard('ds')->id();
  78. $user = Staff::with('StaffDetail')->find($id);
  79. return view('dealer.application-form-list', compact('user'));
  80. }
  81. /***
  82. / Get Application Form List
  83. ***/
  84. public function getSubscribers($dealerCompany)
  85. {
  86. $data = array();
  87. $curr = Carbon::now()->getTimestamp();
  88. $subscriber = Subscriber::where('dealer_company', $dealerCompany)->get();
  89. foreach ($subscriber as $key => $s) {
  90. $n1 = '';
  91. $reg_time = Carbon::createFromTimestamp($s->reg_time);
  92. $expiry_date = $reg_time->addDays(3);
  93. $expiry_date = $expiry_date->getTimestamp();
  94. $agentName = StaffDetail::where('_id', $s->dealer)->first();
  95. $build = Coverage::where('address', $s->building)->first();
  96. if ($s->street == '') {
  97. $street = $build->street;
  98. } else {
  99. $street = $s->street;
  100. }
  101. if ($curr < $expiry_date) {
  102. $n1 = "New/";
  103. }
  104. $data[] = array(
  105. 'formT' => 'R',
  106. 'wo' => $s->wo,
  107. 'name' => $n1 . $s->name,
  108. 'no' => $s->phone1,
  109. 'unit' => $s->unit_no,
  110. 'building' => $s->building,
  111. 'street' => $street,
  112. 'postcode' => $s->postcode,
  113. 'city' => $s->city,
  114. 'sales' => $agentName->name,
  115. 'created_at' => $s->reg_time,
  116. 'action' => $s->_id,
  117. );
  118. }
  119. return $data;
  120. }
  121. public function getBusiness($dealerCompany)
  122. {
  123. $data = array();
  124. $curr = Carbon::now()->getTimestamp();
  125. $business = Subscriber::where('dealer_company', $dealerCompany)->get();
  126. foreach ($business as $key => $s) {
  127. $n1 = '';
  128. $reg_time = Carbon::createFromTimestamp($s->reg_time);
  129. $expiry_date = $reg_time->addDays(3);
  130. $expiry_date = $expiry_date->getTimestamp();
  131. if ($curr < $expiry_date) {
  132. $n1 = "New/";
  133. }
  134. $agentName = StaffDetail::where('_id', $s->dealer)->first();
  135. $data[] = array(
  136. 'formT' => 'B',
  137. 'wo' => $s->wo,
  138. 'name' => $n1 . $s->name,
  139. 'no' => $s->phone1,
  140. 'unit' => '-',
  141. 'building' => '-',
  142. 'street' => $s->address,
  143. 'postcode' => $s->postcode,
  144. 'city' => $s->city,
  145. 'sales' => $agentName->name,
  146. 'created_at' => $s->reg_time,
  147. 'action' => $s->_id,
  148. );
  149. }
  150. return $data;
  151. }
  152. public function getOrderHistory($id)
  153. {
  154. $data = array();
  155. $order_history = FormStatus::where('form_id', $id)->get();
  156. foreach ($order_history as $oh) {
  157. $utcdatetime = new \MongoDB\BSON\UTCDateTime((string) $oh->date);
  158. $datetime = $utcdatetime->toDateTime();
  159. $time = $datetime->format(DATE_RSS);
  160. $time = strtotime($time . ' UTC');
  161. $dateInLocal = date("d/m/Y h:i a", $time);
  162. $data[] = array(
  163. 'date' => $dateInLocal,
  164. 'status' => $oh->status,
  165. 'desc' => $oh->desc
  166. );
  167. }
  168. $json = json_encode($data);
  169. return $json;
  170. }
  171. public function gApplicationList1()
  172. {
  173. $id = Auth::guard('ds')->id();
  174. $user = Staff::with('StaffDetail')->find($id);
  175. $fm = Form::with('Subscriber')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
  176. $nested_data = array();
  177. $i = 0;
  178. foreach ($fm as $f) {
  179. $dname = "";
  180. $wo = WorkOrder::where('_id', $f->_id)->first();
  181. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  182. if (!empty($dealer)) {
  183. $dname = $dealer->name;
  184. }
  185. $address = '';
  186. $name = '';
  187. if ($f->type_application == 'R') {
  188. if (!empty($f->Subscriber->building_name)) {
  189. $address = $f->Subscriber->building_name;
  190. $name = $f->Subscriber->name;
  191. }
  192. } else if ($f->type_application == 'B') {
  193. $address = '-';
  194. $name = $f->Subscriber->company_name;
  195. }
  196. if (empty($wo) && !empty($f->Subscriber)) {
  197. $i++;
  198. array_push($nested_data, array(
  199. 'index' => $i . $f->type_application,
  200. 'name' => $name,
  201. 'phone' => $f->Subscriber->phone1,
  202. 'unit' => $f->Subscriber->unit_no,
  203. 'building' => $address,
  204. 'street' => $f->Subscriber->street,
  205. 'postcode' => $f->Subscriber->postcode,
  206. 'city' => $f->Subscriber->city,
  207. 'sales' => $dname,
  208. 'action' => $f->_id
  209. ));
  210. }
  211. }
  212. return \DataTables::of($nested_data)->make(true);
  213. }
  214. public function gApplicationList2()
  215. {
  216. $id = Auth::guard('ds')->id();
  217. $user = Staff::with('StaffDetail')->find($id);
  218. $fm = Form::with('Subscriber')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
  219. $nested_data = array();
  220. $i = 0;
  221. foreach ($fm as $f) {
  222. $dname = "";
  223. $wo = WorkOrder::where('_id', $f->_id)->first();
  224. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  225. if (!empty($dealer)) {
  226. $dname = $dealer->name;
  227. }
  228. $address = '';
  229. $name = '';
  230. if ($f->type_application == 'R') {
  231. if (!empty($f->Subscriber->building_name)) {
  232. $address = $f->Subscriber->building_name;
  233. $name = $f->Subscriber->name;
  234. }
  235. } else if ($f->type_application == 'B') {
  236. $address = '-';
  237. $name = $f->Subscriber->company_name;
  238. }
  239. if (!empty($wo) && $wo->status != 'Completed') {
  240. $i++;
  241. array_push($nested_data, array(
  242. 'index' => $i . $f->type_application,
  243. 'name' => $name,
  244. 'phone' => $f->Subscriber->phone1,
  245. 'unit' => $f->Subscriber->unit_no,
  246. 'building' => $address,
  247. 'street' => $f->Subscriber->street,
  248. 'postcode' => $f->Subscriber->postcode,
  249. 'city' => $f->Subscriber->city,
  250. 'sales' => $dname,
  251. 'action' => $f->_id
  252. ));
  253. }
  254. }
  255. return \DataTables::of($nested_data)->make(true);
  256. }
  257. public function getCompletedList($year, $month)
  258. {
  259. $id = Auth::guard('ds')->id();
  260. $user = Staff::find($id);
  261. $email = $user->email;
  262. $userDetails = StaffDetail::where('email', $email)->first();
  263. $subs = $this->getSubscribers($userDetails->company_id);
  264. $buss = $this->getBusiness($userDetails->company_id);
  265. // Combine
  266. $cdata = array();
  267. foreach ($subs as $key => $s) {
  268. $cdata[] = $s;
  269. }
  270. foreach ($buss as $key => $b) {
  271. $cdata[] = $b;
  272. }
  273. // Sort based on TimeStamp
  274. $sort = array();
  275. foreach ($cdata as $key => $r) {
  276. $sort[$key] = $r['created_at'];
  277. }
  278. array_multisort($sort, SORT_DESC, $cdata);
  279. $wK = WorkDetail::get();
  280. $curr = Carbon::now()->getTimestamp();
  281. $mY = '';
  282. if ($year != 'null' && $month != 'null') {
  283. $mY = $year . '/' . $month;
  284. }
  285. $final = array();
  286. $filter = array();
  287. $dW = array();
  288. foreach ($cdata as $c) {
  289. if ($c['wo'] != '') {
  290. foreach ($wK as $key => $w) {
  291. if ($c['wo'] == $w->wo && $w->status == 'Completed') {
  292. $dW[] = $c;
  293. }
  294. }
  295. }
  296. }
  297. foreach ($dW as $d) {
  298. if ($mY != '') {
  299. $docket = Docket::where('work_order_id', $d['wo'])->first();
  300. $cDate = date('Y/m', strtotime($docket->end_job));;
  301. if ($mY == $cDate) {
  302. $filter[] = $d;
  303. }
  304. } else {
  305. $filter[] = $d;
  306. }
  307. }
  308. foreach ($filter as $c) {
  309. $do = Docket::where('work_order_id', $c['wo'])->first();
  310. $n1 = '';
  311. $reg_time = Carbon::createFromTimestamp(strtotime($do->end_job));
  312. $expiry_date = $reg_time->addDays(3);
  313. $expiry_date = $expiry_date->getTimestamp();
  314. if ($curr < $expiry_date) {
  315. $n1 = "New/";
  316. }
  317. $final[] = array(
  318. 'formT' => $c['formT'],
  319. 'wo' => $c['wo'],
  320. 'do' => $do->docket_id,
  321. 'activated' => $do->end_job,
  322. 'name' => $n1 . str_replace("New/", "", $c['name']),
  323. 'no' => $c['no'],
  324. 'unit' => $c['unit'],
  325. 'building' => $c['building'],
  326. 'street' => $c['street'],
  327. 'postcode' => $c['postcode'],
  328. 'city' => $c['city'],
  329. 'sales' => $c['sales'],
  330. 'created_at' => $c['created_at'],
  331. 'action' => $c['action'],
  332. );
  333. }
  334. return $final;
  335. }
  336. public function gApplicationList3($year, $month)
  337. {
  338. $id = Auth::guard('ds')->id();
  339. $user = Staff::with('StaffDetail')->find($id);
  340. $mY = '';
  341. if ($year != 'null' && $month != 'null') {
  342. $mY = $month . '/' . $year;
  343. }
  344. $fm = Form::with('Subscriber', 'WorkOrder')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
  345. $nested_data = array();
  346. $i = 0;
  347. foreach ($fm as $f) {
  348. if (!empty($f->WorkOrder)) {
  349. if ($f->WorkOrder->status == 'Completed') {
  350. $wo = WorkOrder::with('Docket')->where('wo', $f->WorkOrder->wo)->first();
  351. $dealer = StaffDetail::where('_id', $f->dealer_id)->withTrashed()->first();
  352. $i++;
  353. $address = '';
  354. $name = '';
  355. if ($f->type_application == 'R') {
  356. if (!empty($f->Subscriber->building_name)) {
  357. $address = $f->Subscriber->building_name;
  358. $name = $f->Subscriber->name;
  359. }
  360. } else if ($f->type_application == 'B') {
  361. $address = '-';
  362. $name = $f->Subscriber->company_name;
  363. }
  364. if (!empty($wo->Docket)) {
  365. $end = date('m/Y', strtotime($wo->Docket->end_job));
  366. if ($mY == '') {
  367. array_push($nested_data, array(
  368. 'index' => $i . $f->type_application,
  369. 'wo' => $wo->wo,
  370. 'do' => $f->WorkOrder->docket_id,
  371. 'name' => $name,
  372. 'phone' => $f->Subscriber->phone1,
  373. 'unit' => $f->Subscriber->unit_no,
  374. 'building' => $address,
  375. 'street' => $f->Subscriber->street,
  376. 'postcode' => $f->Subscriber->postcode,
  377. 'city' => $f->Subscriber->city,
  378. 'sales' => $dealer->name,
  379. 'action' => $f->_id
  380. ));
  381. } else if ($mY == $end) {
  382. array_push($nested_data, array(
  383. 'index' => $i . $f->type_application,
  384. 'wo' => $wo->wo,
  385. 'do' => $f->WorkOrder->docket_id,
  386. 'name' => $name,
  387. 'phone' => $f->Subscriber->phone1,
  388. 'unit' => $f->Subscriber->unit_no,
  389. 'building' => $address,
  390. 'street' => $f->Subscriber->street,
  391. 'postcode' => $f->Subscriber->postcode,
  392. 'city' => $f->Subscriber->city,
  393. 'sales' => $dealer->name,
  394. 'action' => $f->_id
  395. ));
  396. }
  397. }
  398. }
  399. }
  400. }
  401. return \DataTables::of($nested_data)->make(true);
  402. }
  403. /***
  404. / Claim All
  405. ***/
  406. public function claimAll()
  407. {
  408. $id = Auth::guard('ds')->id();
  409. $user = Staff::with('StaffDetail')->find($id);
  410. return view('dealer.claim-all', compact('user'));
  411. }
  412. /***
  413. / Convert To PDF
  414. ***/
  415. public function exportPDF1()
  416. {
  417. return view('pdf.agent-claim');
  418. }
  419. public function exportPDF($company, $year, $month, $app)
  420. {
  421. $final = array();
  422. $id = Auth::guard('ds')->id();
  423. $user = Staff::with('StaffDetail')->find($id);
  424. $com = Company::where('_id', $user->StaffDetail->company_id)->first();
  425. $i = 0;
  426. $dataR = array();
  427. $dataB = array();
  428. $combineData = array();
  429. $count_cyberjaya = array();
  430. $count_jasin = array();
  431. $count_ayerKeroh = array();
  432. $count_alorGajah = array();
  433. $count_menglembu = array();
  434. $count_ipoh = array();
  435. $extra = 0;
  436. $basic_total = 0;
  437. $totals = 0;
  438. if ($year != 'null' && $month != 'null' && $app != 'null') {
  439. if ($app == 'Residential') {
  440. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  441. $q->with('Form');
  442. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  443. if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
  444. foreach ($dataClaim as $key => $d) {
  445. if (
  446. date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  447. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
  448. ) {
  449. if (strpos($d['address'], 'Cyberjaya') !== false) {
  450. $count_cyberjaya[] = $d;
  451. }
  452. if (strpos($d['address'], 'Jasin') !== false) {
  453. $count_jasin[] = $d;
  454. }
  455. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  456. $count_ayerKeroh[] = $d;
  457. }
  458. if (strpos($d['address'], 'Alor Gajah') !== false) {
  459. $count_alorGajah[] = $d;
  460. }
  461. if (strpos($d['address'], 'Menglembu') !== false) {
  462. $count_menglembu[] = $d;
  463. }
  464. if (strpos($d['address'], 'Ipoh') !== false) {
  465. $count_ipoh[] = $d;
  466. }
  467. }
  468. }
  469. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  470. foreach ($dataClaim as $key => $d) {
  471. if (
  472. date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  473. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
  474. ) {
  475. if (strpos($d['address'], 'Cyberjaya') !== false) {
  476. $count_cyberjaya[] = $d;
  477. }
  478. if (strpos($d['address'], 'Jasin') !== false) {
  479. $count_jasin[] = $d;
  480. }
  481. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  482. $count_ayerKeroh[] = $d;
  483. }
  484. if (strpos($d['address'], 'Alor Gajah') !== false) {
  485. $count_alorGajah[] = $d;
  486. }
  487. if (strpos($d['address'], 'Menglembu') !== false) {
  488. $count_menglembu[] = $d;
  489. }
  490. if (strpos($d['address'], 'Ipoh') !== false) {
  491. $count_ipoh[] = $d;
  492. }
  493. }
  494. }
  495. }
  496. } else if ($app == 'Business') {
  497. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  498. $q->with('Form');
  499. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  500. }
  501. }
  502. if (!empty($dataClaim)) {
  503. foreach ($dataClaim as $c) {
  504. $address = '';
  505. $name = '';
  506. if ($c->Subscriber->Form->type_application == 'R') {
  507. if ($c->Subscriber->street != '') {
  508. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  509. } else {
  510. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  511. }
  512. $name = $c->Subscriber->name;
  513. } else if ($c->Subscriber->Form->type_application == 'B') {
  514. if ($c->Subscriber->unit_no != '') {
  515. $address = $c->Subscriber->unit_no . ', ' . $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  516. } else {
  517. $address = $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  518. }
  519. $name = $c->Subscriber->company_name;
  520. }
  521. $i++;
  522. array_push($final, array(
  523. 'index' => $c->formT,
  524. 'contract' => $c->contract,
  525. 'wo' => $c->wo,
  526. 'activated_dt' => $c->activated_dt,
  527. 'name' => $name,
  528. 'address' => $address,
  529. 'package' => $c->package,
  530. 'retail_price' => 'RM ' . $c->retail_price,
  531. 'incentives1' => $c->incentives1,
  532. 'incentives2' => $c->incentives2,
  533. 'total' => 'RM' . $c->total_claim,
  534. 'claimed' => $c->claim_dt,
  535. ));
  536. }
  537. foreach ($dataClaim as $f) {
  538. $basic_total += $f->total_claim;
  539. $invoice_no = '';
  540. if (!empty($f->invoice_no)) {
  541. $invoice_no = $f->invoice_no;
  542. }
  543. }
  544. // Calculate extra incentves
  545. if ($month == '01' && $year == '2020') {
  546. if (count($count_cyberjaya) > 50) {
  547. $balance = count($count_cyberjaya) - 50;
  548. $extra += $balance * 50;
  549. }
  550. if (count($count_ayerKeroh) > 50) {
  551. $balance = count($count_ayerKeroh) - 50;
  552. $extra += $balance * 50;
  553. }
  554. if (count($count_alorGajah) > 50) {
  555. $balance = count($count_alorGajah) - 50;
  556. $extra += $balance * 50;
  557. }
  558. if (count($count_menglembu) > 50) {
  559. $balance = count($count_menglembu) - 50;
  560. $extra += $balance * 50;
  561. }
  562. if (count($count_ipoh) > 50) {
  563. $balance = count($count_ipoh) - 50;
  564. $extra += $balance * 50;
  565. }
  566. if (count($count_jasin) > 10) {
  567. $balance = count($count_jasin) - 10;
  568. $extra += $balance * 50;
  569. }
  570. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  571. if (count($count_cyberjaya) > 50) {
  572. $balance = count($count_cyberjaya) - 50;
  573. $extra += $balance * 50;
  574. }
  575. if (count($count_ayerKeroh) > 50) {
  576. $balance = count($count_ayerKeroh) - 50;
  577. $extra += $balance * 50;
  578. }
  579. if (count($count_alorGajah) > 50) {
  580. $balance = count($count_alorGajah) - 50;
  581. $extra += $balance * 50;
  582. }
  583. if (count($count_menglembu) > 50) {
  584. $balance = count($count_menglembu) - 50;
  585. $extra += $balance * 50;
  586. }
  587. if (count($count_ipoh) > 50) {
  588. $balance = count($count_ipoh) - 50;
  589. $extra += $balance * 50;
  590. }
  591. if (count($count_jasin) > 20) {
  592. $balance = count($count_jasin) - 20;
  593. $extra += $balance * 50;
  594. }
  595. } else {
  596. $extra = 0;
  597. }
  598. $totals = $basic_total + $extra;
  599. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year', 'com', 'basic_total', 'extra', 'totals', 'invoice_no'));
  600. $pdf->setPaper('A4', 'landscape');
  601. $pdfName = preg_replace('/\s+/', '-', $com->name) . '-' . $month . '-' . $year . '.pdf';
  602. return $pdf->download($pdfName);
  603. }
  604. }
  605. /***
  606. / Encrypt Password
  607. ***/
  608. public function encryptPassword($action, $string)
  609. {
  610. $output = false;
  611. $encrypt_method = "AES-256-CBC";
  612. $secret_key = '28472B4B6250655368566D5970337336';
  613. $secret_iv = md5(md5($string)); //'This is my secret iv';
  614. // hash
  615. $key = hash('sha256', $secret_key);
  616. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  617. if ($action == 'encrypt') {
  618. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  619. $output = base64_encode($output);
  620. } else if ($action == 'decrypt') {
  621. $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  622. }
  623. return $output;
  624. }
  625. /***
  626. / Agent Form
  627. ***/
  628. public function showAgentForm()
  629. {
  630. $id = Auth::guard('ds')->id();
  631. $user = Staff::with('StaffDetail')->find($id);
  632. return view('dealer.add_agent', compact('user'));
  633. }
  634. /***
  635. / Add Agent
  636. ***/
  637. public function requestAddAgent(Request $request)
  638. {
  639. $validator = Validator::make($request->all(), [
  640. 'password' => 'min:8|confirmed',
  641. ]);
  642. if ($validator->fails()) {
  643. return redirect()->back()->withInput()->withErrors($validator);
  644. }
  645. $user = Staff::where('email', $request->get('email'))->first();
  646. if (empty($user)) {
  647. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  648. $dealerD = new StaffDetail;
  649. $dealerD->name = $request->get('aname');
  650. $dealerD->ic = $request->get('ic');
  651. $dealerD->email = $request->get('email');
  652. $dealerD->phone = $request->get('phone');
  653. $dealerD->company_id = $request->get('company_id');
  654. $dealerD->color = '';
  655. $dealerD->position = 'Sales';
  656. $dealerD->password = $pass;
  657. $dealerD->user_pic = 'assets/avatar/user.png';
  658. // Save Login Dealer
  659. $loginD = new Staff;
  660. $loginD->email = $request->get('email');
  661. $loginD->password = $pass;
  662. $loginD->roles_access = 'Sales';
  663. $loginD->company_id = $request->get('company_id');
  664. $loginD->last_login_at = '';
  665. $loginD->last_login_ip = '';
  666. // $loginData = [
  667. // 'email' => $request->get('email'),
  668. // 'password' => $pass,
  669. // 'roles_access' => 'Sales',
  670. // 'last_login_at' => '',
  671. // 'last_login_ip' => '',
  672. // ];
  673. $company = Company::where('_id', $request->get('company_id'))->first();
  674. $company->staff()->save($loginD);
  675. // $dealer = DealerLaravel::create($loginData);
  676. $loginD->staffdetail()->save($dealerD);
  677. return redirect()->back()->with('success_msg', '<strong>Success!</strong> register <strong>' . $request->get('email') . '</strong>');
  678. } else {
  679. return redirect()->back()->withInput()->withErrors('Email already exist!');
  680. }
  681. }
  682. public function editAgentDealer($agent_id)
  683. {
  684. $id = Auth::guard('ds')->id();
  685. $user = Staff::find($id);
  686. $email = $user->email;
  687. $userDetails = StaffDetail::where('email', $email)->first();
  688. $person = StaffDetail::where('_id', $agent_id)->first();
  689. return view('dealer.edit_agent', compact('person', 'userDetails', 'user'));
  690. }
  691. public function deleteAgent(Request $request)
  692. {
  693. $agent = Staff::where('_id', $request->id)->first();
  694. $agentdetail = $agent->staffdetail()->first();
  695. if (!empty($agentdetail) && !empty($agent)) {
  696. $agent->delete();
  697. $agentdetail->delete();
  698. return 'true';
  699. } else {
  700. return 'false';
  701. }
  702. }
  703. //Show claim list by company
  704. public function mClaimListAll($company)
  705. {
  706. $id = Auth::guard('ds')->id();
  707. $user = Staff::with('StaffDetail')->find($id);
  708. $dealer_claimAll = DealerClaim::where('dealer', $company)->orderBy('activated_dt', 'desc')->get();
  709. $i = 0;
  710. $nested_data = array();
  711. foreach ($dealer_claimAll as $c) {
  712. $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first();
  713. $address = '';
  714. if ($customer->Form->type_application == 'R') {
  715. if ($customer->street != '') {
  716. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  717. } else {
  718. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  719. }
  720. } else if ($customer->Form->type_application == 'B') {
  721. if ($customer->unit_no != '') {
  722. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  723. } else {
  724. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  725. }
  726. }
  727. $i++;
  728. array_push($nested_data, array(
  729. 'index' => $c->formT,
  730. 'contract' => $c->contract,
  731. 'wo' => $c->wo,
  732. 'activated_dt' => $c->activated_dt,
  733. 'name' => $customer->name,
  734. 'address' => $address,
  735. 'package' => $c->package,
  736. 'retail_price' => 'RM ' . $c->retail_price,
  737. 'incentives1' => '',
  738. 'incentives2' => '',
  739. 'total' => '',
  740. 'claimed' => $c->laim_dt,
  741. 'action' => 'null',
  742. ));
  743. }
  744. return \DataTables::of($nested_data)->make(true);
  745. }
  746. // Get Dealer Claim Residential
  747. public function returnDataR($company, $year, $month)
  748. {
  749. $dataCR = DealerClaim::where('formT', 'R')->where('dealer', $company)->get();
  750. $final = array();
  751. // Month & Year
  752. $mY = '';
  753. if ($year != 'null' && $month != 'null') {
  754. $mY = $month . '/' . $year;
  755. }
  756. if ($mY != '') {
  757. $data12 = array();
  758. $data24 = array();
  759. $countD12 = 0;
  760. $countD24 = 0;
  761. foreach ($dataCR as $dc) {
  762. if ($dc->activated_my == $mY || $dc->activated_my == '0' . $mY) {
  763. if ($dc->contract == "12") {
  764. $data12[] = $dc;
  765. } else if ($dc->contract == "24") {
  766. $data24[] = $dc;
  767. }
  768. }
  769. }
  770. $countD24 = count($data24);
  771. $countD12 = count($data12);
  772. $comm = Commission::where('formT', 'R')->get();
  773. $commV12 = 0;
  774. $commV24 = 0;
  775. $comm12 = '';
  776. $comm24 = '';
  777. foreach ($comm as $c) {
  778. if ($c->contract == '12') {
  779. if (strpos($c->ranges, '>') !== false) {
  780. $pieces = explode(">", $c->ranges);
  781. if ($countD12 >= intval($pieces[1])) {
  782. $commV12 = floatval($c->comm) / 100;
  783. $comm12 = $c->comm . '%';
  784. }
  785. }
  786. if (strpos($c->ranges, '-') !== false) {
  787. $pieces = explode("-", $c->ranges);
  788. if ($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])) {
  789. $commV12 = floatval($c->comm) / 100;
  790. $comm12 = $c->comm . '%';
  791. }
  792. }
  793. } else if ($c->contract == '24') {
  794. // Contract => 24
  795. if ($countD24 != 0) {
  796. if (strpos($c->ranges, '>') !== false) {
  797. $pieces = explode(">", $c->ranges);
  798. if ($countD24 > intval($pieces[1])) {
  799. $commV24 = floatval($c->comm) / 100;
  800. $comm24 = $c->comm . '%';
  801. }
  802. }
  803. if (strpos($c->ranges, '-') !== false) {
  804. $pieces = explode("-", $c->ranges);
  805. if ($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])) {
  806. $commV24 = floatval($c->comm) / 100;
  807. $comm24 = $c->comm . '%';
  808. }
  809. }
  810. }
  811. }
  812. }
  813. foreach ($data12 as $key => $d) {
  814. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  815. $address = '';
  816. $name = '';
  817. if ($customer->Form->type_application == 'R') {
  818. if ($customer->street != '') {
  819. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  820. } else {
  821. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  822. }
  823. $name = $customer->name;
  824. } else if ($customer->Form->type_application == 'B') {
  825. if ($customer->unit_no != '') {
  826. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  827. } else {
  828. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  829. }
  830. $name = $customer->company_name;
  831. }
  832. $final[] = array(
  833. 'index' => $d['formT'],
  834. 'contract' => $d['contract'],
  835. 'wo' => $d['wo'],
  836. 'submission' => $d['submission_dt'],
  837. 'activation' => $d['activated_dt'],
  838. 'name' => $name,
  839. 'address' => $address,
  840. 'package' => $d['package'],
  841. 'retail_price' => 'RM ' . $d['retail_price'],
  842. 'incentives1' => $comm12,
  843. 'incentives2' => '',
  844. 'total' => 'RM ' . number_format($d['retail_price'] * $commV12, 2),
  845. 'claim' => $d['claim_dt'],
  846. );
  847. }
  848. foreach ($data24 as $key => $d) {
  849. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  850. $address = '';
  851. $name = '';
  852. if ($customer->Form->type_application == 'R') {
  853. if ($customer->street != '') {
  854. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  855. } else {
  856. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  857. }
  858. $name = $customer->name;
  859. } else if ($customer->Form->type_application == 'B') {
  860. if ($customer->unit_no != '') {
  861. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  862. } else {
  863. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  864. }
  865. $name = $customer->company_name;
  866. }
  867. $final[] = array(
  868. 'index' => $d['formT'],
  869. 'contract' => $d['contract'],
  870. 'wo' => $d['wo'],
  871. 'submission' => $d['submission_dt'],
  872. 'activation' => $d['activated_dt'],
  873. 'name' => $name,
  874. 'address' => $address,
  875. 'package' => $d['package'],
  876. 'retail_price' => 'RM ' . $d['retail_price'],
  877. 'incentives1' => $comm24,
  878. 'incentives2' => '',
  879. 'total' => 'RM ' . number_format($d['retail_price'] * $commV24, 2),
  880. 'claim' => $d['claim_dt'],
  881. );
  882. }
  883. } else {
  884. foreach ($dataCR as $c) {
  885. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  886. $address = '';
  887. $name = '';
  888. if ($customer->Form->type_application == 'R') {
  889. if ($customer->street != '') {
  890. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  891. } else {
  892. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  893. }
  894. $name = $customer->name;
  895. } else if ($customer->Form->type_application == 'B') {
  896. if ($customer->unit_no != '') {
  897. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  898. } else {
  899. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  900. }
  901. $name = $customer->company_name;
  902. }
  903. $final[] = array(
  904. 'index' => $c['formT'],
  905. 'contract' => $c['contract'],
  906. 'wo' => $c['wo'],
  907. 'submission' => $d['submission_dt'],
  908. 'activation' => $c['activated_dt'],
  909. 'name' => $name,
  910. 'address' => $address,
  911. 'package' => $c['package'],
  912. 'retail_price' => 'RM ' . $c['retail_price'],
  913. 'incentives1' => '',
  914. 'incentives2' => '',
  915. 'total' => '',
  916. 'claim' => $c['claim_dt'],
  917. );
  918. }
  919. }
  920. return $final;
  921. }
  922. // Get Claim Business
  923. public function returnDataB($company, $year, $month)
  924. {
  925. $dataCB = DealerClaim::where('formT', 'B')->where('dealer', $company)->get();
  926. $final = array();
  927. // Month & Year
  928. $mY = '';
  929. if ($year != 'null' && $month != 'null') {
  930. $mY = $month . '/' . $year;
  931. }
  932. if ($mY != '') {
  933. /** Contract 12
  934. // 1=>10-100 2=>300 3=>500 4=>1
  935. **/
  936. $data12_1 = array();
  937. $data12_2 = array();
  938. $data12_3 = array();
  939. $data12_4 = array();
  940. $countD12_1 = 0;
  941. $countD12_2 = 0;
  942. $countD12_3 = 0;
  943. $countD12_4 = 0;
  944. /** Contract 24
  945. // 1=>10-100 2=>300 3=>500 4=>1
  946. **/
  947. $data24_1 = array();
  948. $data24_2 = array();
  949. $data24_3 = array();
  950. $data24_4 = array();
  951. $countD24_1 = 0;
  952. $countD24_2 = 0;
  953. $countD24_3 = 0;
  954. $countD24_4 = 0;
  955. foreach ($dataCB as $dc) {
  956. if ($dc->activated_my == $mY || $dc->activated_my == '0' . $mY) {
  957. if ($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")) {
  958. $data12_1[] = $dc;
  959. } else if ($dc->contract == "12" && $dc->package == "300") {
  960. $data12_2[] = $dc;
  961. } else if ($dc->contract == "12" && $dc->package == "500") {
  962. $data12_3[] = $dc;
  963. } else if ($dc->contract == "12" && $dc->package == "1") {
  964. $data12_4[] = $dc;
  965. } else if ($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")) {
  966. $data24_1[] = $dc;
  967. } else if ($dc->contract == "24" && $dc->package == "300") {
  968. $data24_2[] = $dc;
  969. } else if ($dc->contract == "24" && $dc->package == "500") {
  970. $data24_3[] = $dc;
  971. } else if ($dc->contract == "24" && $dc->package == "1") {
  972. $data24_4[] = $dc;
  973. }
  974. }
  975. }
  976. $countD12_1 = count($data12_1);
  977. $countD12_2 = count($data12_2);
  978. $countD12_3 = count($data12_3);
  979. $countD12_4 = count($data12_4);
  980. $countD24_1 = count($data24_1);
  981. $countD24_2 = count($data24_2);
  982. $countD24_3 = count($data24_3);
  983. $countD24_4 = count($data24_4);
  984. $comm = Commission::where('formT', 'B')->get();
  985. $commV12_1 = 0;
  986. $commV12_2 = 0;
  987. $commV12_3 = 0;
  988. $commV12_4 = 0;
  989. $commV24_1 = 0;
  990. $commV24_2 = 0;
  991. $commV24_3 = 0;
  992. $commV24_4 = 0;
  993. $comm12_1 = '';
  994. $comm12_2 = '';
  995. $comm12_3 = '';
  996. $comm12_4 = '';
  997. $comm24_1 = '';
  998. $comm24_2 = '';
  999. $comm24_3 = '';
  1000. $comm24_4 = '';
  1001. $addRM12_1 = '';
  1002. $addRM12_2 = '';
  1003. $addRM12_3 = '';
  1004. $addRM12_4 = '';
  1005. $addRM24_1 = '';
  1006. $addRM24_2 = '';
  1007. $addRM24_3 = '';
  1008. $addRM24_4 = '';
  1009. foreach ($comm as $c) {
  1010. /*** Contract 24 **/
  1011. if ($c->contract == '24' && $c->packageR == "300") {
  1012. if (strpos($c->ranges, '>') !== false) {
  1013. $pieces = explode(">", $c->ranges);
  1014. if ($countD24_2 >= intval($pieces[1])) {
  1015. if (strpos($c->comm, 'RM') !== false) {
  1016. $comm24_2 = '+ ' . $c->comm;
  1017. $commV24_2 = '';
  1018. $addRM24_2 = $c->comm;
  1019. } else {
  1020. $comms = explode("RM", $c->comm);
  1021. if (!empty($comms[1])) {
  1022. $comm24_2 = 'RM ' . $comms[1];
  1023. $commV24_2 = floatval($comms[1]);
  1024. } else {
  1025. if ($comms[0] != '') {
  1026. $comm24_2 = $comms[0] . '%';
  1027. $commV24_2 = floatval($comms[0]) / 100;
  1028. }
  1029. }
  1030. }
  1031. }
  1032. }
  1033. } else if ($c->contract == '24' && $c->packageR == "500") {
  1034. if (strpos($c->ranges, '>') !== false) {
  1035. $pieces = explode(">", $c->ranges);
  1036. if ($countD24_3 >= intval($pieces[1])) {
  1037. if (strpos($c->comm, 'RM') !== false) {
  1038. $comm24_3 = '+ ' . $c->comm;
  1039. $commV24_3 = '';
  1040. $addRM24_3 = $c->comm;
  1041. } else {
  1042. $comms = explode("RM", $c->comm);
  1043. if (isset($comms[1])) {
  1044. $comm24_3 = 'RM ' . $comms[1];
  1045. $commV24_3 = floatval($comms[1]);
  1046. } else {
  1047. if ($comms[0] != '') {
  1048. $comm24_3 = $comms[0] . '%';
  1049. $commV24_3 = floatval($comms[0]) / 100;
  1050. }
  1051. }
  1052. }
  1053. }
  1054. }
  1055. } else if ($c->contract == '24' && $c->packageR == "1") {
  1056. if (strpos($c->ranges, '>') !== false) {
  1057. $pieces = explode(">", $c->ranges);
  1058. if ($countD24_4 >= intval($pieces[1])) {
  1059. if (strpos($c->comm, 'RM') !== false) {
  1060. $comm24_4 = '+ ' . $c->comm;
  1061. $commV24_4 = '';
  1062. $addRM24_4 = $c->comm;
  1063. } else {
  1064. $comms = explode("RM", $c->comm);
  1065. if (isset($comms[1])) {
  1066. $comm24_4 = 'RM ' . $comms[1];
  1067. $commV24_4 = floatval($comms[1]);
  1068. } else {
  1069. if ($comms[0] != '') {
  1070. $comm24_4 = $comms[0] . '%';
  1071. $commV24_4 = floatval($comms[0]) / 100;
  1072. }
  1073. }
  1074. }
  1075. }
  1076. }
  1077. } else if ($c->contract == '24' && $c->packageR == "10,30,50,100") {
  1078. if (strpos($c->ranges, '-') !== false) {
  1079. $pieces = explode("-", $c->ranges);
  1080. if ($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])) {
  1081. if (strpos($c->comm, 'RM') !== false) {
  1082. $comm24_1 = '+ ' . $c->comm;
  1083. $commV24_1 = '';
  1084. $addRM24_1 = $c->comm;
  1085. } else {
  1086. $comms = explode("RM", $c->comm);
  1087. if (!empty($comms[1])) {
  1088. $comm24_1 = 'RM ' . $comms[1];
  1089. $commV24_1 = floatval($comms[1]);
  1090. } else {
  1091. if ($comms[0] != '') {
  1092. $comm24_1 = $comms[0] . '%';
  1093. $commV24_1 = floatval($comms[0]) / 100;
  1094. }
  1095. }
  1096. }
  1097. }
  1098. }
  1099. if (strpos($c->ranges, '>') !== false) {
  1100. $pieces1 = explode(">", $c->ranges);
  1101. if ($countD24_1 >= intval($pieces1[1])) {
  1102. if (strpos($c->comm, "RM") === true) {
  1103. $comm24_1 = '+ ' . $c->comm;
  1104. $commV24_1 = '';
  1105. $addRM24_1 = $c->comm;
  1106. } else {
  1107. $comms = explode("RM", $c->comm);
  1108. if (empty($comms[1])) {
  1109. $comm24_1 = 'RM ' . $comms[1];
  1110. $commV24_1 = floatval($comms[1]);
  1111. } else {
  1112. if ($comms[0] != '') {
  1113. $comm24_1 = str_replace('+ ', '', $comms[0]) . '%';
  1114. $commV24_1 = floatval($comms[0]) / 100;
  1115. $addRM24_1 = $comms[1];
  1116. }
  1117. }
  1118. }
  1119. }
  1120. }
  1121. }
  1122. /*** Contract 12 **/
  1123. else if ($c->contract == '12' && $c->packageR == "10,30,50,100") {
  1124. if (strpos($c->ranges, '>') !== false) {
  1125. $pieces = explode(">", $c->ranges);
  1126. if ($countD12_1 >= intval($pieces[1])) {
  1127. if (strpos($c->comm, 'RM') !== false) {
  1128. $comm12_1 = '+ ' . $c->comm;
  1129. $commV12_1 = '';
  1130. $addRM12_1 = $c->comm;
  1131. } else {
  1132. $comms = explode("RM", $c->comm);
  1133. if (isset($comms[1])) {
  1134. $comm12_1 = 'RM ' . $comms[1];
  1135. $commV12_1 = floatval($comms[1]);
  1136. } else {
  1137. if ($comms[0] != '') {
  1138. $comm12_1 = $comms[0] . '%';
  1139. $commV12_1 = floatval($comms[0]) / 100;
  1140. }
  1141. }
  1142. }
  1143. }
  1144. }
  1145. if (strpos($c->ranges, '-') !== false) {
  1146. $pieces = explode("-", $c->ranges);
  1147. if ($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])) {
  1148. if (strpos($c->comm, 'RM') !== false) {
  1149. $comm12_1 = '+ ' . $c->comm;
  1150. $commV12_1 = '';
  1151. $addRM12_1 = $c->comm;
  1152. } else {
  1153. $comms = explode("RM", $c->comm);
  1154. if (isset($comms[1])) {
  1155. $comm12_1 = 'RM ' . $comms[1];
  1156. $commV12_1 = floatval($comms[1]);
  1157. } else {
  1158. if ($comms[0] != '') {
  1159. $comm12_1 = $comms[0] . '%';
  1160. $commV12_1 = floatval($comms[0]) / 100;
  1161. }
  1162. }
  1163. }
  1164. }
  1165. }
  1166. } else if ($c->contract == '12' && $c->packageR == "300") {
  1167. if (strpos($c->ranges, '>') !== false) {
  1168. $pieces = explode(">", $c->ranges);
  1169. if ($countD12_2 >= intval($pieces[1])) {
  1170. if (strpos($c->comm, 'RM') !== false) {
  1171. $comm12_2 = '+ ' . $c->comm;
  1172. $commV12_2 = '';
  1173. $addRM12_2 = $c->comm;
  1174. } else {
  1175. $comms = explode("RM", $c->comm);
  1176. if (isset($comms[1])) {
  1177. $comm12_2 = 'RM ' . $comms[1];
  1178. $commV12_2 = floatval($comms[1]);
  1179. } else {
  1180. if ($comms[0] != '') {
  1181. $comm12_2 = $comms[0] . '%';
  1182. $commV12_2 = floatval($comms[0]) / 100;
  1183. }
  1184. }
  1185. }
  1186. }
  1187. }
  1188. } else if ($c->contract == '12' && $c->packageR == "500") {
  1189. if (strpos($c->ranges, '>') !== false) {
  1190. $pieces = explode(">", $c->ranges);
  1191. if ($countD12_3 >= intval($pieces[1])) {
  1192. if (strpos($c->comm, 'RM') !== false) {
  1193. $comm12_3 = '+ ' . $c->comm;
  1194. $commV12_3 = '';
  1195. $addRM12_3 = $c->comm;
  1196. } else {
  1197. $comms = explode("RM", $c->comm);
  1198. if (isset($comms[1])) {
  1199. $comm12_3 = 'RM ' . $comms[1];
  1200. $commV12_3 = floatval($comms[1]);
  1201. } else {
  1202. if ($comms[0] != '') {
  1203. $comm12_3 = $comms[0] . '%';
  1204. $commV12_3 = floatval($comms[0]) / 100;
  1205. }
  1206. }
  1207. }
  1208. }
  1209. }
  1210. } else if ($c->contract == '12' && $c->packageR == "1") {
  1211. if (strpos($c->ranges, '>') !== false) {
  1212. $pieces = explode(">", $c->ranges);
  1213. if ($countD12_4 >= intval($pieces[1])) {
  1214. if (strpos($c->comm, 'RM') !== false) {
  1215. $comm12_4 = '+ ' . $c->comm;
  1216. $commV12_4 = '';
  1217. $addRM12_4 = $c->comm;
  1218. } else {
  1219. $comms = explode("RM", $c->comm);
  1220. if (isset($comms[1])) {
  1221. $comm12_4 = 'RM ' . $comms[1];
  1222. $commV12_4 = floatval($comms[1]);
  1223. } else {
  1224. if ($comms[0] != '') {
  1225. $comm12_4 = $comms[0] . '%';
  1226. $commV12_4 = floatval($comms[0]) / 100;
  1227. }
  1228. }
  1229. }
  1230. }
  1231. }
  1232. }
  1233. }
  1234. // Category 10,30,50,100
  1235. foreach ($data12_1 as $key => $d) {
  1236. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1237. $address = '';
  1238. $name = '';
  1239. if ($customer->Form->type_application == 'R') {
  1240. if ($customer->street != '') {
  1241. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1242. } else {
  1243. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1244. }
  1245. $name = $customer->name;
  1246. } else if ($customer->Form->type_application == 'B') {
  1247. if ($customer->unit_no != '') {
  1248. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1249. } else {
  1250. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1251. }
  1252. $name = $customer->company_name;
  1253. }
  1254. $total = '';
  1255. if ($commV12_1 == '') {
  1256. $total = $addRM12_1;
  1257. } else {
  1258. $total = number_format($d['retail_price'] * $commV12_1, 2);
  1259. }
  1260. $final[] = array(
  1261. 'index' => $d['formT'],
  1262. 'contract' => $d['contract'],
  1263. 'wo' => $d['wo'],
  1264. 'submission' => $d['submission_dt'],
  1265. 'activation' => $d['activated_dt'],
  1266. 'name' => $name,
  1267. 'address' => $address,
  1268. 'package' => $d['package'],
  1269. 'retail_price' => 'RM ' . $d['retail_price'],
  1270. 'incentives1' => $comm12_1,
  1271. 'incentives2' => $addRM12_1,
  1272. 'total' => 'RM ' . $total,
  1273. 'claim' => $c['claim_dt'],
  1274. );
  1275. }
  1276. foreach ($data24_1 as $key => $d) {
  1277. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1278. $address = '';
  1279. $name = '';
  1280. if ($customer->Form->type_application == 'R') {
  1281. if ($customer->street != '') {
  1282. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1283. } else {
  1284. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1285. }
  1286. $name = $customer->name;
  1287. } else if ($customer->Form->type_application == 'B') {
  1288. if ($customer->unit_no != '') {
  1289. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1290. } else {
  1291. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1292. }
  1293. $name = $customer->company_name;
  1294. }
  1295. $total = '';
  1296. if ($commV24_1 == '') {
  1297. $total = $addRM24_1;
  1298. } else {
  1299. $total = number_format(($d['retail_price'] * $commV24_1) + floatval($addRM24_1), 2);
  1300. }
  1301. $final[] = array(
  1302. 'index' => $d['formT'],
  1303. 'contract' => $d['contract'],
  1304. 'wo' => $d['wo'],
  1305. 'submission' => $d['submission_dt'],
  1306. 'activation' => $d['activated_dt'],
  1307. 'name' => $name,
  1308. 'address' => $address,
  1309. 'package' => $d['package'],
  1310. 'retail_price' => 'RM ' . $d['retail_price'],
  1311. 'incentives1' => $comm24_1,
  1312. 'incentives2' => $addRM24_1,
  1313. 'total' => 'RM ' . $total,
  1314. 'claim' => $c['claim_dt'],
  1315. );
  1316. }
  1317. // Category 300
  1318. foreach ($data12_2 as $key => $d) {
  1319. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1320. $address = '';
  1321. $name = '';
  1322. if ($customer->Form->type_application == 'R') {
  1323. if ($customer->street != '') {
  1324. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1325. } else {
  1326. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1327. }
  1328. $name = $customer->name;
  1329. } else if ($customer->Form->type_application == 'B') {
  1330. if ($customer->unit_no != '') {
  1331. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1332. } else {
  1333. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1334. }
  1335. $name = $customer->company_name;
  1336. }
  1337. $total = '';
  1338. if ($commV12_2 == '') {
  1339. $total = $addRM12_2;
  1340. } else {
  1341. $total = number_format($d['retail_price'] * $commV12_2, 2);
  1342. }
  1343. $final[] = array(
  1344. 'index' => $d['formT'],
  1345. 'contract' => $d['contract'],
  1346. 'wo' => $d['wo'],
  1347. 'submission' => $d['submission_dt'],
  1348. 'activation' => $d['activated_dt'],
  1349. 'name' => $name,
  1350. 'address' => $address,
  1351. 'package' => $d['package'],
  1352. 'retail_price' => 'RM ' . $d['retail_price'],
  1353. 'incentives1' => $comm12_2,
  1354. 'incentives2' => $addRM12_2,
  1355. 'total' => 'RM ' . $total,
  1356. 'claim' => $c['claim_dt'],
  1357. );
  1358. }
  1359. foreach ($data24_2 as $key => $d) {
  1360. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1361. $address = '';
  1362. $name = '';
  1363. if ($customer->Form->type_application == 'R') {
  1364. if ($customer->street != '') {
  1365. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1366. } else {
  1367. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1368. }
  1369. $name = $customer->name;
  1370. } else if ($customer->Form->type_application == 'B') {
  1371. if ($customer->unit_no != '') {
  1372. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1373. } else {
  1374. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1375. }
  1376. $name = $customer->company_name;
  1377. }
  1378. $total = '';
  1379. if ($commV24_2 == '') {
  1380. $total = $addRM24_2;
  1381. } else {
  1382. $total = number_format($d['retail_price'] * $commV24_2, 2);
  1383. }
  1384. $final[] = array(
  1385. 'index' => $d['formT'],
  1386. 'contract' => $d['contract'],
  1387. 'wo' => $d['wo'],
  1388. 'submission' => $d['submission_dt'],
  1389. 'activation' => $d['activated_dt'],
  1390. 'name' => $name,
  1391. 'address' => $address,
  1392. 'package' => $d['package'],
  1393. 'retail_price' => 'RM ' . $d['retail_price'],
  1394. 'incentives1' => $comm24_2,
  1395. 'incentives2' => $addRM24_2,
  1396. 'total' => 'RM ' . $total,
  1397. 'claim' => $c['claim_dt'],
  1398. );
  1399. }
  1400. // Category 500
  1401. foreach ($data12_3 as $key => $d) {
  1402. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1403. $address = '';
  1404. $name = $customer->name;
  1405. if ($customer->Form->type_application == 'R') {
  1406. if ($customer->street != '') {
  1407. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1408. } else {
  1409. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1410. }
  1411. } else if ($customer->Form->type_application == 'B') {
  1412. if ($customer->unit_no != '') {
  1413. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1414. } else {
  1415. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1416. }
  1417. $name = $customer->company_name;
  1418. }
  1419. $total = '';
  1420. if ($commV12_3 == '') {
  1421. $total = $addRM12_3;
  1422. } else {
  1423. $total = number_format($d['retail_price'] * $commV12_3, 2);
  1424. }
  1425. $final[] = array(
  1426. 'index' => $d['formT'],
  1427. 'contract' => $d['contract'],
  1428. 'wo' => $d['wo'],
  1429. 'submission' => $d['submission_dt'],
  1430. 'activation' => $d['activated_dt'],
  1431. 'name' => $name,
  1432. 'address' => $address,
  1433. 'package' => $d['package'],
  1434. 'retail_price' => 'RM ' . $d['retail_price'],
  1435. 'incentives1' => $comm12_3,
  1436. 'incentives2' => $addRM12_3,
  1437. 'total' => 'RM ' . $total,
  1438. 'claim' => $c['claim_dt'],
  1439. );
  1440. }
  1441. foreach ($data24_3 as $key => $d) {
  1442. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1443. $address = '';
  1444. $name = '';
  1445. if ($customer->Form->type_application == 'R') {
  1446. if ($customer->street != '') {
  1447. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1448. } else {
  1449. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1450. }
  1451. $name = $customer->name;
  1452. } else if ($customer->Form->type_application == 'B') {
  1453. if ($customer->unit_no != '') {
  1454. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1455. } else {
  1456. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1457. }
  1458. $name = $customer->company_name;
  1459. }
  1460. $total = '';
  1461. if ($commV24_3 == '') {
  1462. $total = $addRM24_3;
  1463. } else {
  1464. $total = number_format($d['retail_price'] * $commV24_3, 2);
  1465. }
  1466. $final[] = array(
  1467. 'index' => $d['formT'],
  1468. 'contract' => $d['contract'],
  1469. 'wo' => $d['wo'],
  1470. 'submission' => $d['submission_dt'],
  1471. 'activation' => $d['activated_dt'],
  1472. 'name' => $name,
  1473. 'address' => $address,
  1474. 'package' => $d['package'],
  1475. 'retail_price' => 'RM ' . $d['retail_price'],
  1476. 'incentives1' => $comm24_3,
  1477. 'incentives2' => $addRM24_3,
  1478. 'total' => 'RM ' . $total,
  1479. 'claim' => $c['claim_dt'],
  1480. );
  1481. }
  1482. // Category 1
  1483. foreach ($data12_4 as $key => $d) {
  1484. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1485. $address = '';
  1486. $name = '';
  1487. if ($customer->Form->type_application == 'R') {
  1488. if ($customer->street != '') {
  1489. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1490. } else {
  1491. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1492. }
  1493. $name = $customer->name;
  1494. } else if ($customer->Form->type_application == 'B') {
  1495. if ($customer->unit_no != '') {
  1496. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1497. } else {
  1498. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1499. }
  1500. $name = $customer->company_name;
  1501. }
  1502. $total = '';
  1503. if ($commV12_4 == '') {
  1504. $total = $addRM12_4;
  1505. } else {
  1506. $total = number_format($d['retail_price'] * $commV12_4, 2);
  1507. }
  1508. $final[] = array(
  1509. 'index' => $d['formT'],
  1510. 'contract' => $d['contract'],
  1511. 'wo' => $d['wo'],
  1512. 'submission' => $d['submission_dt'],
  1513. 'activation' => $d['activated_dt'],
  1514. 'name' => $name,
  1515. 'address' => $address,
  1516. 'package' => $d['package'],
  1517. 'retail_price' => 'RM ' . $d['retail_price'],
  1518. 'incentives1' => $comm12_4,
  1519. 'incentives2' => $addRM12_4,
  1520. 'total' => 'RM ' . $total,
  1521. 'claim' => $c['claim_dt'],
  1522. );
  1523. }
  1524. foreach ($data24_4 as $key => $d) {
  1525. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1526. $address = '';
  1527. $name = '';
  1528. if ($customer->Form->type_application == 'R') {
  1529. if ($customer->street != '') {
  1530. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1531. } else {
  1532. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1533. }
  1534. $name = $customer->name;
  1535. } else if ($customer->Form->type_application == 'B') {
  1536. if ($customer->unit_no != '') {
  1537. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1538. } else {
  1539. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1540. }
  1541. $name = $customer->company_name;
  1542. }
  1543. $total = '';
  1544. if ($commV24_4 == '') {
  1545. $total = $addRM24_4;
  1546. } else {
  1547. $total = number_format($d['retail_price'] * $commV24_4, 2);
  1548. }
  1549. $final[] = array(
  1550. 'index' => $d['formT'],
  1551. 'contract' => $d['contract'],
  1552. 'wo' => $d['wo'],
  1553. 'submission' => $d['submission_dt'],
  1554. 'activation' => $d['activated_dt'],
  1555. 'name' => $name,
  1556. 'address' => $address,
  1557. 'package' => $d['package'],
  1558. 'retail_price' => 'RM ' . $d['retail_price'],
  1559. 'incentives1' => $comm24_4,
  1560. 'incentives2' => $addRM24_4,
  1561. 'total' => 'RM ' . $total,
  1562. 'claim' => $c['claim_dt'],
  1563. );
  1564. }
  1565. } else {
  1566. foreach ($dataCB as $c) {
  1567. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1568. $address = '';
  1569. $name = '';
  1570. if ($customer->Form->type_application == 'R') {
  1571. if ($customer->street != '') {
  1572. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1573. } else {
  1574. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1575. }
  1576. $name = $customer->name;
  1577. } else if ($customer->Form->type_application == 'B') {
  1578. if ($customer->unit_no != '') {
  1579. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1580. } else {
  1581. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1582. }
  1583. $name = $customer->company_name;
  1584. }
  1585. $final[] = array(
  1586. 'index' => $c['formT'],
  1587. 'contract' => $c['contract'],
  1588. 'wo' => $c['wo'],
  1589. 'submission' => $d['submission_dt'],
  1590. 'activation' => $c['activated_dt'],
  1591. 'name' => $name,
  1592. 'address' => $address,
  1593. 'package' => $c['package'],
  1594. 'retail_price' => 'RM ' . $c['retail_price'],
  1595. 'incentives1' => '',
  1596. 'incentives2' => '',
  1597. 'total' => '',
  1598. 'claim' => $c['claim_dt'],
  1599. );
  1600. }
  1601. }
  1602. return $final;
  1603. }
  1604. /***
  1605. / Return Claim & Combined Business && Resident
  1606. ***/
  1607. public function getClaimRB($company, $year, $month, $app)
  1608. {
  1609. $dataR = array();
  1610. $dataB = array();
  1611. $combineData = array();
  1612. if ($month == 'null' && $year == 'null' && $app == 'null') {
  1613. return $this->mClaimListAll($company);
  1614. } else if ($year != 'null' && $month != 'null' && $app == 'null') {
  1615. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1616. $q->with('Form');
  1617. }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  1618. if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
  1619. foreach ($dataClaim as $key => $d) {
  1620. if (
  1621. date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  1622. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
  1623. ) {
  1624. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1625. $count_cyberjaya[] = $d;
  1626. }
  1627. if (strpos($d['address'], 'Jasin') !== false) {
  1628. $count_jasin[] = $d;
  1629. }
  1630. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1631. $count_ayerKeroh[] = $d;
  1632. }
  1633. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1634. $count_alorGajah[] = $d;
  1635. }
  1636. if (strpos($d['address'], 'Menglembu') !== false) {
  1637. $count_menglembu[] = $d;
  1638. }
  1639. if (strpos($d['address'], 'Ipoh') !== false) {
  1640. $count_ipoh[] = $d;
  1641. }
  1642. }
  1643. }
  1644. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  1645. foreach ($dataClaim as $key => $d) {
  1646. if (
  1647. date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  1648. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
  1649. ) {
  1650. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1651. $count_cyberjaya[] = $d;
  1652. }
  1653. if (strpos($d['address'], 'Jasin') !== false) {
  1654. $count_jasin[] = $d;
  1655. }
  1656. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1657. $count_ayerKeroh[] = $d;
  1658. }
  1659. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1660. $count_alorGajah[] = $d;
  1661. }
  1662. if (strpos($d['address'], 'Menglembu') !== false) {
  1663. $count_menglembu[] = $d;
  1664. }
  1665. if (strpos($d['address'], 'Ipoh') !== false) {
  1666. $count_ipoh[] = $d;
  1667. }
  1668. }
  1669. }
  1670. }
  1671. } else if ($year == 'null' && $month == 'null' && $app != 'null') {
  1672. if ($app == 'Residential') {
  1673. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1674. $q->with('Form');
  1675. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->orderBy('activated_dt', 'DESC')->get();
  1676. } else if ($app == 'Business') {
  1677. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1678. $q->with('Form');
  1679. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->orderBy('activated_dt', 'DESC')->get();
  1680. }
  1681. } else if ($year != 'null' && $month != 'null' && $app != 'null') {
  1682. if ($app == 'Residential') {
  1683. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1684. $q->with('Form');
  1685. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  1686. if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
  1687. foreach ($dataClaim as $key => $d) {
  1688. if (
  1689. date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  1690. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
  1691. ) {
  1692. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1693. $count_cyberjaya[] = $d;
  1694. }
  1695. if (strpos($d['address'], 'Jasin') !== false) {
  1696. $count_jasin[] = $d;
  1697. }
  1698. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1699. $count_ayerKeroh[] = $d;
  1700. }
  1701. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1702. $count_alorGajah[] = $d;
  1703. }
  1704. if (strpos($d['address'], 'Menglembu') !== false) {
  1705. $count_menglembu[] = $d;
  1706. }
  1707. if (strpos($d['address'], 'Ipoh') !== false) {
  1708. $count_ipoh[] = $d;
  1709. }
  1710. }
  1711. }
  1712. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  1713. foreach ($dataClaim as $key => $d) {
  1714. if (
  1715. date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  1716. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
  1717. ) {
  1718. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1719. $count_cyberjaya[] = $d;
  1720. }
  1721. if (strpos($d['address'], 'Jasin') !== false) {
  1722. $count_jasin[] = $d;
  1723. }
  1724. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1725. $count_ayerKeroh[] = $d;
  1726. }
  1727. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1728. $count_alorGajah[] = $d;
  1729. }
  1730. if (strpos($d['address'], 'Menglembu') !== false) {
  1731. $count_menglembu[] = $d;
  1732. }
  1733. if (strpos($d['address'], 'Ipoh') !== false) {
  1734. $count_ipoh[] = $d;
  1735. }
  1736. }
  1737. }
  1738. }
  1739. } else if ($app == 'Business') {
  1740. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1741. $q->with('Form');
  1742. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  1743. }
  1744. }
  1745. $i = 0;
  1746. $nested_data = array();
  1747. if (!empty($dataClaim)) {
  1748. foreach ($dataClaim as $c) {
  1749. $address = '';
  1750. $name = '';
  1751. if ($c->Subscriber->Form->type_application == 'R') {
  1752. if ($c->Subscriber->street != '') {
  1753. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1754. } else {
  1755. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1756. }
  1757. $name = $c->Subscriber->name;
  1758. } else if ($c->Subscriber->Form->type_application == 'B') {
  1759. if ($c->Subscriber->unit_no != '') {
  1760. $address = $c->Subscriber->unit_no . ', ' . $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1761. } else {
  1762. $address = $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1763. }
  1764. $name = $c->Subscriber->company_name;
  1765. }
  1766. $i++;
  1767. array_push($nested_data, array(
  1768. 'index' => $c->formT,
  1769. 'contract' => $c->contract,
  1770. 'wo' => $c->wo,
  1771. 'activated_dt' => $c->activated_dt,
  1772. 'name' => $name,
  1773. 'address' => $address,
  1774. 'package' => $c->package,
  1775. 'retail_price' => 'RM ' . $c->retail_price,
  1776. 'incentives1' => $c->incentives1,
  1777. 'incentives2' => $c->incentives2,
  1778. 'total' => 'RM ' . $c->total_claim,
  1779. 'claimed' => $c->claim_dt,
  1780. ));
  1781. }
  1782. }
  1783. return \DataTables::of($nested_data)->make(true);
  1784. }
  1785. public function updateAgent(Request $request)
  1786. {
  1787. $user = Staff::where('_id', $request->agent_id)->first();
  1788. $validate = Staff::where('email', $request->email)->first();
  1789. $detail = $user->staffdetail()->first();
  1790. $getpass = $request->get('password');
  1791. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  1792. if (empty($validate)) {
  1793. $detail->name = $request->get('aname');
  1794. $detail->ic = $request->get('ic');
  1795. $detail->email = $request->get('email');
  1796. $detail->phone = $request->get('phone');
  1797. $detail->company_id = $request->get('vendor');
  1798. $user->email = $request->get('email');
  1799. $user->company_id = $request->get('vendor');
  1800. if (!empty($getpass)) {
  1801. $validator = Validator::make($request->all(), [
  1802. 'password' => 'min:8|confirmed',
  1803. ]);
  1804. if ($validator->fails()) {
  1805. return redirect()->back()->withInput()->withErrors($validator);
  1806. }
  1807. $detail->password = $pass;
  1808. $user->password = $pass;
  1809. $detail->save();
  1810. $user->save();
  1811. } else {
  1812. $detail->save();
  1813. $user->save();
  1814. }
  1815. return redirect()->route('dHome')->with('success_msg', 'message');
  1816. } else {
  1817. if ($user->email == $request->email) {
  1818. echo "" . $request->get('password');
  1819. $detail->name = $request->get('aname');
  1820. $detail->ic = $request->get('ic');
  1821. $detail->email = $request->get('email');
  1822. $detail->phone = $request->get('phone');
  1823. $detail->company_id = $request->get('vendor');
  1824. $detail->save();
  1825. $user->email = $request->get('email');
  1826. if (!empty($getpass)) {
  1827. $validator = Validator::make($request->all(), [
  1828. 'password' => 'min:8|confirmed',
  1829. ]);
  1830. if ($validator->fails()) {
  1831. return redirect()->back()->withInput()->withErrors($validator);
  1832. }
  1833. $detail->password = $pass;
  1834. $user->password = $pass;
  1835. $detail->save();
  1836. $user->save();
  1837. } else {
  1838. $detail->save();
  1839. $user->save();
  1840. }
  1841. return redirect()->route('dHome')->with('success_msg', 'message');
  1842. } else {
  1843. echo "email is used";
  1844. return redirect()->back()->withInput()->withErrors('Email already exist!');
  1845. }
  1846. }
  1847. }
  1848. /***
  1849. / Application Form
  1850. ***/
  1851. public function showResidentialForm()
  1852. {
  1853. $id = Auth::guard('ds')->id();
  1854. $user = Staff::find($id);
  1855. $email = $user->email;
  1856. $userDetails = StaffDetail::where('email', $email)->first();
  1857. return view('dealer.residential-form', compact('userDetails', 'user'));
  1858. }
  1859. public function showBusinessForm()
  1860. {
  1861. $id = Auth::guard('ds')->id();
  1862. $user = Staff::find($id);
  1863. $email = $user->email;
  1864. $userDetails = StaffDetail::where('email', $email)->first();
  1865. return view('dealer.business-form', compact('userDetails', 'user'));
  1866. }
  1867. public function exportDealerJson(Request $request)
  1868. {
  1869. $final = array();
  1870. $id = Auth::guard('ds')->id();
  1871. // $user = Staff::with('StaffDetail')->find($id);
  1872. // $com = Company::where('_id',$user->StaffDetail->company_id)->first();
  1873. $dataR = array();
  1874. $dataB = array();
  1875. $combineData = array();
  1876. $extra = 0;
  1877. $year = $request->year;
  1878. $month = $request->month;
  1879. $app = $request->app;
  1880. $company = $request->company;
  1881. if ($year != 'null' && $month != 'null' && $app == 'null') {
  1882. $count_cyberjaya = array();
  1883. $count_jasin = array();
  1884. $count_ayerKeroh = array();
  1885. $count_alorGajah = array();
  1886. $count_menglembu = array();
  1887. $count_ipoh = array();
  1888. $extra = 0;
  1889. $basic_total = 0;
  1890. $countAugustR = array();
  1891. $countAugustB = array();
  1892. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  1893. // $dataDis = $this->returnDataR($company,'2019','12');
  1894. // $dataJan = $this->returnDataR($company,'2020','1');
  1895. if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  1896. $dataApril = $this->returnDataR($company, '2020', '4');
  1897. $dataMay = $this->returnDataR($company, '2020', '5');
  1898. $dataJune = $this->returnDataR($company, '2020', '6');
  1899. $dataJuly = $this->returnDataR($company, '2020', '7');
  1900. foreach ($dataApril as $key => $d) {
  1901. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  1902. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  1903. // $count_cyberjaya[] = $d;
  1904. // }
  1905. // if (strpos($d['address'], 'Jasin') !== false) {
  1906. // $count_jasin[] = $d;
  1907. // }
  1908. // }
  1909. // // else
  1910. if (date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020') {
  1911. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1912. $count_cyberjaya[] = $d;
  1913. }
  1914. if (strpos($d['address'], 'Jasin') !== false) {
  1915. $count_jasin[] = $d;
  1916. }
  1917. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1918. $count_ayerKeroh[] = $d;
  1919. }
  1920. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1921. $count_alorGajah[] = $d;
  1922. }
  1923. if (strpos($d['address'], 'Menglembu') !== false) {
  1924. $count_menglembu[] = $d;
  1925. }
  1926. if (strpos($d['address'], 'Ipoh') !== false) {
  1927. $count_ipoh[] = $d;
  1928. }
  1929. } else {
  1930. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1931. $combineData[] = $d;
  1932. }
  1933. }
  1934. }
  1935. foreach ($dataMay as $key => $d) {
  1936. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1937. $count_cyberjaya[] = $d;
  1938. }
  1939. if (strpos($d['address'], 'Jasin') !== false) {
  1940. $count_jasin[] = $d;
  1941. }
  1942. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1943. $count_ayerKeroh[] = $d;
  1944. }
  1945. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1946. $count_alorGajah[] = $d;
  1947. }
  1948. if (strpos($d['address'], 'Menglembu') !== false) {
  1949. $count_menglembu[] = $d;
  1950. }
  1951. if (strpos($d['address'], 'Ipoh') !== false) {
  1952. $count_ipoh[] = $d;
  1953. }
  1954. }
  1955. foreach ($dataJune as $key => $d) {
  1956. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1957. $count_cyberjaya[] = $d;
  1958. }
  1959. if (strpos($d['address'], 'Jasin') !== false) {
  1960. $count_jasin[] = $d;
  1961. }
  1962. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1963. $count_ayerKeroh[] = $d;
  1964. }
  1965. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1966. $count_alorGajah[] = $d;
  1967. }
  1968. if (strpos($d['address'], 'Menglembu') !== false) {
  1969. $count_menglembu[] = $d;
  1970. }
  1971. if (strpos($d['address'], 'Ipoh') !== false) {
  1972. $count_ipoh[] = $d;
  1973. }
  1974. }
  1975. foreach ($dataJuly as $key => $d) {
  1976. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1977. $count_cyberjaya[] = $d;
  1978. }
  1979. if (strpos($d['address'], 'Jasin') !== false) {
  1980. $count_jasin[] = $d;
  1981. }
  1982. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1983. $count_ayerKeroh[] = $d;
  1984. }
  1985. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1986. $count_alorGajah[] = $d;
  1987. }
  1988. if (strpos($d['address'], 'Menglembu') !== false) {
  1989. $count_menglembu[] = $d;
  1990. }
  1991. if (strpos($d['address'], 'Ipoh') !== false) {
  1992. $count_ipoh[] = $d;
  1993. }
  1994. }
  1995. // Store to combineData New Incentives Cyberjaya
  1996. foreach ($count_cyberjaya as $key => $d) {
  1997. if (count($count_cyberjaya) > 50) {
  1998. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  1999. if ($d['contract'] == '12') {
  2000. array_push($combineData, array(
  2001. 'index' => $d['index'],
  2002. 'contract' => $d['contract'],
  2003. 'wo' => $d['wo'],
  2004. 'activation' => $d['activation'],
  2005. 'name' => $d['name'],
  2006. 'address' => $d['address'],
  2007. 'package' => $d['package'],
  2008. 'retail_price' => $d['retail_price'],
  2009. 'incentives1' => $d['incentives1'],
  2010. 'incentives2' => $d['incentives2'],
  2011. 'total' => $d['total'],
  2012. 'claim' => $d['claim'],
  2013. ));
  2014. } else {
  2015. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2016. array_push($combineData, array(
  2017. 'index' => $d['index'],
  2018. 'contract' => $d['contract'],
  2019. 'wo' => $d['wo'],
  2020. 'activation' => $d['activation'],
  2021. 'name' => $d['name'],
  2022. 'address' => $d['address'],
  2023. 'package' => $d['package'],
  2024. 'retail_price' => $d['retail_price'],
  2025. 'incentives1' => '230%',
  2026. 'incentives2' => $d['incentives2'],
  2027. 'total' => 'RM ' . $total,
  2028. 'claim' => $d['claim'],
  2029. ));
  2030. }
  2031. }
  2032. } else if (count($count_cyberjaya) < 50) {
  2033. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2034. array_push($combineData, array(
  2035. 'index' => $d['index'],
  2036. 'contract' => $d['contract'],
  2037. 'wo' => $d['wo'],
  2038. 'activation' => $d['activation'],
  2039. 'name' => $d['name'],
  2040. 'address' => $d['address'],
  2041. 'package' => $d['package'],
  2042. 'retail_price' => $d['retail_price'],
  2043. 'incentives1' => $d['incentives1'],
  2044. 'incentives2' => $d['incentives2'],
  2045. 'total' => $d['total'],
  2046. 'claim' => $d['claim'],
  2047. ));
  2048. }
  2049. }
  2050. }
  2051. // Store to combineData New Incentives Menglembu
  2052. foreach ($count_menglembu as $key => $d) {
  2053. if (count($count_menglembu) > 50) {
  2054. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2055. if ($d['contract'] == '12') {
  2056. array_push($combineData, array(
  2057. 'index' => $d['index'],
  2058. 'contract' => $d['contract'],
  2059. 'wo' => $d['wo'],
  2060. 'activation' => $d['activation'],
  2061. 'name' => $d['name'],
  2062. 'address' => $d['address'],
  2063. 'package' => $d['package'],
  2064. 'retail_price' => $d['retail_price'],
  2065. 'incentives1' => $d['incentives1'],
  2066. 'incentives2' => $d['incentives2'],
  2067. 'total' => $d['total'],
  2068. 'claim' => $d['claim'],
  2069. ));
  2070. } else {
  2071. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2072. array_push($combineData, array(
  2073. 'index' => $d['index'],
  2074. 'contract' => $d['contract'],
  2075. 'wo' => $d['wo'],
  2076. 'activation' => $d['activation'],
  2077. 'name' => $d['name'],
  2078. 'address' => $d['address'],
  2079. 'package' => $d['package'],
  2080. 'retail_price' => $d['retail_price'],
  2081. 'incentives1' => '230%',
  2082. 'incentives2' => $d['incentives2'],
  2083. 'total' => 'RM ' . $total,
  2084. 'claim' => $d['claim'],
  2085. ));
  2086. }
  2087. }
  2088. } else if (count($count_menglembu) < 50) {
  2089. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2090. array_push($combineData, array(
  2091. 'index' => $d['index'],
  2092. 'contract' => $d['contract'],
  2093. 'wo' => $d['wo'],
  2094. 'activation' => $d['activation'],
  2095. 'name' => $d['name'],
  2096. 'address' => $d['address'],
  2097. 'package' => $d['package'],
  2098. 'retail_price' => $d['retail_price'],
  2099. 'incentives1' => $d['incentives1'],
  2100. 'incentives2' => $d['incentives2'],
  2101. 'total' => $d['total'],
  2102. 'claim' => $d['claim'],
  2103. ));
  2104. }
  2105. }
  2106. }
  2107. // Store to combineData New Incentives Ipoh
  2108. foreach ($count_ipoh as $key => $d) {
  2109. if (count($count_ipoh) > 50) {
  2110. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2111. if ($d['contract'] == '12') {
  2112. array_push($combineData, array(
  2113. 'index' => $d['index'],
  2114. 'contract' => $d['contract'],
  2115. 'wo' => $d['wo'],
  2116. 'activation' => $d['activation'],
  2117. 'name' => $d['name'],
  2118. 'address' => $d['address'],
  2119. 'package' => $d['package'],
  2120. 'retail_price' => $d['retail_price'],
  2121. 'incentives1' => $d['incentives1'],
  2122. 'incentives2' => $d['incentives2'],
  2123. 'total' => $d['total'],
  2124. 'claim' => $d['claim'],
  2125. ));
  2126. } else {
  2127. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2128. array_push($combineData, array(
  2129. 'index' => $d['index'],
  2130. 'contract' => $d['contract'],
  2131. 'wo' => $d['wo'],
  2132. 'activation' => $d['activation'],
  2133. 'name' => $d['name'],
  2134. 'address' => $d['address'],
  2135. 'package' => $d['package'],
  2136. 'retail_price' => $d['retail_price'],
  2137. 'incentives1' => '230%',
  2138. 'incentives2' => $d['incentives2'],
  2139. 'total' => 'RM ' . $total,
  2140. 'claim' => $d['claim'],
  2141. ));
  2142. }
  2143. }
  2144. } else if (count($count_ipoh) < 50) {
  2145. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2146. array_push($combineData, array(
  2147. 'index' => $d['index'],
  2148. 'contract' => $d['contract'],
  2149. 'wo' => $d['wo'],
  2150. 'activation' => $d['activation'],
  2151. 'name' => $d['name'],
  2152. 'address' => $d['address'],
  2153. 'package' => $d['package'],
  2154. 'retail_price' => $d['retail_price'],
  2155. 'incentives1' => $d['incentives1'],
  2156. 'incentives2' => $d['incentives2'],
  2157. 'total' => $d['total'],
  2158. 'claim' => $d['claim'],
  2159. ));
  2160. }
  2161. }
  2162. }
  2163. // Store to combineData New Incentives Ayer Keroh
  2164. foreach ($count_ayerKeroh as $key => $d) {
  2165. if (count($count_ayerKeroh) > 50) {
  2166. if ($d['contract'] == '12') {
  2167. array_push($combineData, array(
  2168. 'index' => $d['index'],
  2169. 'contract' => $d['contract'],
  2170. 'wo' => $d['wo'],
  2171. 'activation' => $d['activation'],
  2172. 'name' => $d['name'],
  2173. 'address' => $d['address'],
  2174. 'package' => $d['package'],
  2175. 'retail_price' => $d['retail_price'],
  2176. 'incentives1' => $d['incentives1'],
  2177. 'incentives2' => $d['incentives2'],
  2178. 'total' => $d['total'],
  2179. 'claim' => $d['claim'],
  2180. ));
  2181. } else {
  2182. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2183. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2184. array_push($combineData, array(
  2185. 'index' => $d['index'],
  2186. 'contract' => $d['contract'],
  2187. 'wo' => $d['wo'],
  2188. 'activation' => $d['activation'],
  2189. 'name' => $d['name'],
  2190. 'address' => $d['address'],
  2191. 'package' => $d['package'],
  2192. 'retail_price' => $d['retail_price'],
  2193. 'incentives1' => '230%',
  2194. 'incentives2' => $d['incentives2'],
  2195. 'total' => 'RM ' . $total,
  2196. 'claim' => $d['claim'],
  2197. ));
  2198. }
  2199. }
  2200. } else if (count($count_ayerKeroh) < 50) {
  2201. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2202. array_push($combineData, array(
  2203. 'index' => $d['index'],
  2204. 'contract' => $d['contract'],
  2205. 'wo' => $d['wo'],
  2206. 'activation' => $d['activation'],
  2207. 'name' => $d['name'],
  2208. 'address' => $d['address'],
  2209. 'package' => $d['package'],
  2210. 'retail_price' => $d['retail_price'],
  2211. 'incentives1' => $d['incentives1'],
  2212. 'incentives2' => $d['incentives2'],
  2213. 'total' => $d['total'],
  2214. 'claim' => $d['claim'],
  2215. ));
  2216. }
  2217. }
  2218. }
  2219. // Store to combineData New Incentives Alor Gajah
  2220. foreach ($count_alorGajah as $key => $d) {
  2221. if (count($count_alorGajah) > 50) {
  2222. if ($d['contract'] == '12') {
  2223. array_push($combineData, array(
  2224. 'index' => $d['index'],
  2225. 'contract' => $d['contract'],
  2226. 'wo' => $d['wo'],
  2227. 'activation' => $d['activation'],
  2228. 'name' => $d['name'],
  2229. 'address' => $d['address'],
  2230. 'package' => $d['package'],
  2231. 'retail_price' => $d['retail_price'],
  2232. 'incentives1' => $d['incentives1'],
  2233. 'incentives2' => $d['incentives2'],
  2234. 'total' => $d['total'],
  2235. 'claim' => $d['claim'],
  2236. ));
  2237. } else {
  2238. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2239. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2240. array_push($combineData, array(
  2241. 'index' => $d['index'],
  2242. 'contract' => $d['contract'],
  2243. 'wo' => $d['wo'],
  2244. 'activation' => $d['activation'],
  2245. 'name' => $d['name'],
  2246. 'address' => $d['address'],
  2247. 'package' => $d['package'],
  2248. 'retail_price' => $d['retail_price'],
  2249. 'incentives1' => '230%',
  2250. 'incentives2' => $d['incentives2'],
  2251. 'total' => 'RM ' . $total,
  2252. 'claim' => $d['claim'],
  2253. ));
  2254. }
  2255. }
  2256. } else if (count($count_alorGajah) < 50) {
  2257. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2258. array_push($combineData, array(
  2259. 'index' => $d['index'],
  2260. 'contract' => $d['contract'],
  2261. 'wo' => $d['wo'],
  2262. 'activation' => $d['activation'],
  2263. 'name' => $d['name'],
  2264. 'address' => $d['address'],
  2265. 'package' => $d['package'],
  2266. 'retail_price' => $d['retail_price'],
  2267. 'incentives1' => $d['incentives1'],
  2268. 'incentives2' => $d['incentives2'],
  2269. 'total' => $d['total'],
  2270. 'claim' => $d['claim'],
  2271. ));
  2272. }
  2273. }
  2274. }
  2275. // Store to combineData New Incentives Jasin
  2276. foreach ($count_jasin as $key => $d) {
  2277. if (count($count_jasin) > 20) {
  2278. if ($d['contract'] == '12') {
  2279. array_push($combineData, array(
  2280. 'index' => $d['index'],
  2281. 'contract' => $d['contract'],
  2282. 'wo' => $d['wo'],
  2283. 'activation' => $d['activation'],
  2284. 'name' => $d['name'],
  2285. 'address' => $d['address'],
  2286. 'package' => $d['package'],
  2287. 'retail_price' => $d['retail_price'],
  2288. 'incentives1' => $d['incentives1'],
  2289. 'incentives2' => $d['incentives2'],
  2290. 'total' => $d['total'],
  2291. 'claim' => $d['claim'],
  2292. ));
  2293. } else {
  2294. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2295. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2296. array_push($combineData, array(
  2297. 'index' => $d['index'],
  2298. 'contract' => $d['contract'],
  2299. 'wo' => $d['wo'],
  2300. 'activation' => $d['activation'],
  2301. 'name' => $d['name'],
  2302. 'address' => $d['address'],
  2303. 'package' => $d['package'],
  2304. 'retail_price' => $d['retail_price'],
  2305. 'incentives1' => '230%',
  2306. 'incentives2' => $d['incentives2'],
  2307. 'total' => 'RM ' . $total,
  2308. 'claim' => $d['claim'],
  2309. ));
  2310. }
  2311. }
  2312. } else if (count($count_jasin) < 20) {
  2313. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2314. array_push($combineData, array(
  2315. 'index' => $d['index'],
  2316. 'contract' => $d['contract'],
  2317. 'wo' => $d['wo'],
  2318. 'activation' => $d['activation'],
  2319. 'name' => $d['name'],
  2320. 'address' => $d['address'],
  2321. 'package' => $d['package'],
  2322. 'retail_price' => $d['retail_price'],
  2323. 'incentives1' => $d['incentives1'],
  2324. 'incentives2' => $d['incentives2'],
  2325. 'total' => $d['total'],
  2326. 'claim' => $d['claim'],
  2327. ));
  2328. }
  2329. }
  2330. }
  2331. } else if ($year == '2020' && ($month == '08' || $month == '09' || $month == '10')) {
  2332. $dataAugustR = $this->returnDataR($company, '2020', '8');
  2333. $dataAugustB = $this->returnDataB($company, '2020', '8');
  2334. $dataSeptemberR = $this->returnDataR($company, '2020', '9');
  2335. $dataSeptemberB = $this->returnDataB($company, '2020', '9');
  2336. $dataOctoberR = $this->returnDataR($company, '2020', '10');
  2337. $dataOctoberB = $this->returnDataB($company, '2020', '10');
  2338. foreach ($dataAugustR as $key => $d) {
  2339. if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') {
  2340. if ($d['contract'] == '24') {
  2341. if ($d['package'] == 50) {
  2342. $d['retail_price'] = 69;
  2343. } elseif ($d['package'] == 100) {
  2344. $d['retail_price'] = 89;
  2345. } elseif ($d['package'] == 500) {
  2346. $d['retail_price'] = 129;
  2347. }
  2348. }
  2349. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  2350. $countAugustR[] = $d;
  2351. }
  2352. } else {
  2353. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  2354. $countAugustR[] = $d;
  2355. } else {
  2356. $combineData[] = $d;
  2357. }
  2358. }
  2359. }
  2360. // Store to combineData New Incentive August
  2361. foreach ($countAugustR as $key => $d) {
  2362. if (count($dataAugustR) >= 50) {
  2363. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2364. if ($d['contract'] == '12') {
  2365. array_push($combineData, array(
  2366. 'index' => $d['index'],
  2367. 'contract' => $d['contract'],
  2368. 'wo' => $d['wo'],
  2369. 'activation' => $d['activation'],
  2370. 'name' => $d['name'],
  2371. 'address' => $d['address'],
  2372. 'package' => $d['package'],
  2373. 'retail_price' => $d['retail_price'],
  2374. 'incentives1' => $d['incentives1'],
  2375. 'incentives2' => $d['incentives2'],
  2376. 'total' => $d['total'],
  2377. 'claim' => $d['claim'],
  2378. ));
  2379. } else {
  2380. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2381. array_push($combineData, array(
  2382. 'index' => $d['index'],
  2383. 'contract' => $d['contract'],
  2384. 'wo' => $d['wo'],
  2385. 'activation' => $d['activation'],
  2386. 'name' => $d['name'],
  2387. 'address' => $d['address'],
  2388. 'package' => $d['package'],
  2389. 'retail_price' => $d['retail_price'],
  2390. 'incentives1' => '250% + RM50',
  2391. 'incentives2' => $d['incentives2'],
  2392. 'total' => 'RM ' . $total,
  2393. 'claim' => $d['claim'],
  2394. ));
  2395. }
  2396. }
  2397. } else if (count($dataAugustR) < 50) {
  2398. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2399. if ($d['contract'] == '12') {
  2400. array_push($combineData, array(
  2401. 'index' => $d['index'],
  2402. 'contract' => $d['contract'],
  2403. 'wo' => $d['wo'],
  2404. 'activation' => $d['activation'],
  2405. 'name' => $d['name'],
  2406. 'address' => $d['address'],
  2407. 'package' => $d['package'],
  2408. 'retail_price' => $d['retail_price'],
  2409. 'incentives1' => $d['incentives1'],
  2410. 'incentives2' => $d['incentives2'],
  2411. 'total' => $d['total'],
  2412. 'claim' => $d['claim'],
  2413. ));
  2414. } else {
  2415. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2416. array_push($combineData, array(
  2417. 'index' => $d['index'],
  2418. 'contract' => $d['contract'],
  2419. 'wo' => $d['wo'],
  2420. 'activation' => $d['activation'],
  2421. 'name' => $d['name'],
  2422. 'address' => $d['address'],
  2423. 'package' => $d['package'],
  2424. 'retail_price' => $d['retail_price'],
  2425. 'incentives1' => '250%',
  2426. 'incentives2' => $d['incentives2'],
  2427. 'total' => 'RM ' . $total,
  2428. 'claim' => $d['claim'],
  2429. ));
  2430. }
  2431. }
  2432. }
  2433. }
  2434. foreach ($dataAugustB as $key => $d) {
  2435. if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') {
  2436. if ($d['contract'] == '24') {
  2437. if ($d['package'] == 50) {
  2438. $d['retail_price'] = 89;
  2439. } elseif ($d['package'] == 100) {
  2440. $d['retail_price'] = 119;
  2441. } elseif ($d['package'] == 300) {
  2442. $d['retail_price'] = 179;
  2443. } elseif ($d['package'] == 500) {
  2444. $d['retail_price'] = 249;
  2445. }
  2446. }
  2447. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  2448. $countAugustB[] = $d;
  2449. }
  2450. } else {
  2451. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  2452. $countAugustB[] = $d;
  2453. } else {
  2454. $combineData[] = $d;
  2455. }
  2456. }
  2457. }
  2458. // Store to combineData New Incentive August
  2459. foreach ($countAugustB as $key => $d) {
  2460. if (count($dataAugustB) >= 50) {
  2461. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2462. if ($d['contract'] == '12') {
  2463. array_push($combineData, array(
  2464. 'index' => $d['index'],
  2465. 'contract' => $d['contract'],
  2466. 'wo' => $d['wo'],
  2467. 'activation' => $d['activation'],
  2468. 'name' => $d['name'],
  2469. 'address' => $d['address'],
  2470. 'package' => $d['package'],
  2471. 'retail_price' => $d['retail_price'],
  2472. 'incentives1' => $d['incentives1'],
  2473. 'incentives2' => $d['incentives2'],
  2474. 'total' => $d['total'],
  2475. 'claim' => $d['claim'],
  2476. ));
  2477. } else {
  2478. if ($d['package'] == 1) {
  2479. $total = 1500;
  2480. } else {
  2481. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2482. }
  2483. array_push($combineData, array(
  2484. 'index' => $d['index'],
  2485. 'contract' => $d['contract'],
  2486. 'wo' => $d['wo'],
  2487. 'activation' => $d['activation'],
  2488. 'name' => $d['name'],
  2489. 'address' => $d['address'],
  2490. 'package' => $d['package'],
  2491. 'retail_price' => $d['retail_price'],
  2492. 'incentives1' => '250% + RM50',
  2493. 'incentives2' => '',
  2494. 'total' => 'RM ' . $total,
  2495. 'claim' => $d['claim'],
  2496. ));
  2497. }
  2498. }
  2499. } else if (count($dataAugustB) < 50) {
  2500. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2501. if ($d['contract'] == '12') {
  2502. array_push($combineData, array(
  2503. 'index' => $d['index'],
  2504. 'contract' => $d['contract'],
  2505. 'wo' => $d['wo'],
  2506. 'activation' => $d['activation'],
  2507. 'name' => $d['name'],
  2508. 'address' => $d['address'],
  2509. 'package' => $d['package'],
  2510. 'retail_price' => $d['retail_price'],
  2511. 'incentives1' => $d['incentives1'],
  2512. 'incentives2' => $d['incentives2'],
  2513. 'total' => $d['total'],
  2514. 'claim' => $d['claim'],
  2515. ));
  2516. } else {
  2517. if ($d['package'] == 1) {
  2518. $total = 1500;
  2519. } else {
  2520. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2521. }
  2522. array_push($combineData, array(
  2523. 'index' => $d['index'],
  2524. 'contract' => $d['contract'],
  2525. 'wo' => $d['wo'],
  2526. 'activation' => $d['activation'],
  2527. 'name' => $d['name'],
  2528. 'address' => $d['address'],
  2529. 'package' => $d['package'],
  2530. 'retail_price' => $d['retail_price'],
  2531. 'incentives1' => '250%',
  2532. 'incentives2' => '',
  2533. 'total' => 'RM ' . $total,
  2534. 'claim' => $d['claim'],
  2535. ));
  2536. }
  2537. }
  2538. }
  2539. }
  2540. foreach ($dataSeptemberR as $key => $d) {
  2541. 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)) {
  2542. if ($d['contract'] == '24') {
  2543. if ($d['package'] == 50) {
  2544. $d['retail_price'] = 69;
  2545. } elseif ($d['package'] == 100) {
  2546. $d['retail_price'] = 89;
  2547. } elseif ($d['package'] == 500) {
  2548. $d['retail_price'] = 129;
  2549. }
  2550. }
  2551. }
  2552. if (count($dataSeptemberR) >= 50) {
  2553. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2554. if ($d['contract'] == '12') {
  2555. array_push($combineData, array(
  2556. 'index' => $d['index'],
  2557. 'contract' => $d['contract'],
  2558. 'wo' => $d['wo'],
  2559. 'activation' => $d['activation'],
  2560. 'name' => $d['name'],
  2561. 'address' => $d['address'],
  2562. 'package' => $d['package'],
  2563. 'retail_price' => $d['retail_price'],
  2564. 'incentives1' => $d['incentives1'],
  2565. 'incentives2' => $d['incentives2'],
  2566. 'total' => $d['total'],
  2567. 'claim' => $d['claim'],
  2568. ));
  2569. } else {
  2570. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2571. array_push($combineData, array(
  2572. 'index' => $d['index'],
  2573. 'contract' => $d['contract'],
  2574. 'wo' => $d['wo'],
  2575. 'activation' => $d['activation'],
  2576. 'name' => $d['name'],
  2577. 'address' => $d['address'],
  2578. 'package' => $d['package'],
  2579. 'retail_price' => $d['retail_price'],
  2580. 'incentives1' => '250% + RM50',
  2581. 'incentives2' => $d['incentives2'],
  2582. 'total' => 'RM ' . $total,
  2583. 'claim' => $d['claim'],
  2584. ));
  2585. }
  2586. }
  2587. } else if (count($dataSeptemberR) < 50) {
  2588. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2589. if ($d['contract'] == '12') {
  2590. array_push($combineData, array(
  2591. 'index' => $d['index'],
  2592. 'contract' => $d['contract'],
  2593. 'wo' => $d['wo'],
  2594. 'activation' => $d['activation'],
  2595. 'name' => $d['name'],
  2596. 'address' => $d['address'],
  2597. 'package' => $d['package'],
  2598. 'retail_price' => $d['retail_price'],
  2599. 'incentives1' => $d['incentives1'],
  2600. 'incentives2' => $d['incentives2'],
  2601. 'total' => $d['total'],
  2602. 'claim' => $d['claim'],
  2603. ));
  2604. } else {
  2605. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2606. array_push($combineData, array(
  2607. 'index' => $d['index'],
  2608. 'contract' => $d['contract'],
  2609. 'wo' => $d['wo'],
  2610. 'activation' => $d['activation'],
  2611. 'name' => $d['name'],
  2612. 'address' => $d['address'],
  2613. 'package' => $d['package'],
  2614. 'retail_price' => $d['retail_price'],
  2615. 'incentives1' => '250%',
  2616. 'incentives2' => $d['incentives2'],
  2617. 'total' => 'RM ' . $total,
  2618. 'claim' => $d['claim'],
  2619. ));
  2620. }
  2621. }
  2622. }
  2623. }
  2624. foreach ($dataSeptemberB as $key => $d) {
  2625. 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)) {
  2626. if ($d['contract'] == '24') {
  2627. if ($d['package'] == 50) {
  2628. $d['retail_price'] = 89;
  2629. } elseif ($d['package'] == 100) {
  2630. $d['retail_price'] = 119;
  2631. } elseif ($d['package'] == 300) {
  2632. $d['retail_price'] = 179;
  2633. } elseif ($d['package'] == 500) {
  2634. $d['retail_price'] = 249;
  2635. }
  2636. }
  2637. }
  2638. if (count($dataSeptemberB) >= 50) {
  2639. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2640. if ($d['contract'] == '12') {
  2641. array_push($combineData, array(
  2642. 'index' => $d['index'],
  2643. 'contract' => $d['contract'],
  2644. 'wo' => $d['wo'],
  2645. 'activation' => $d['activation'],
  2646. 'name' => $d['name'],
  2647. 'address' => $d['address'],
  2648. 'package' => $d['package'],
  2649. 'retail_price' => $d['retail_price'],
  2650. 'incentives1' => $d['incentives1'],
  2651. 'incentives2' => $d['incentives2'],
  2652. 'total' => $d['total'],
  2653. 'claim' => $d['claim'],
  2654. ));
  2655. } else {
  2656. if ($d['package'] == 1) {
  2657. $total = 1500;
  2658. } else {
  2659. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2660. }
  2661. array_push($combineData, array(
  2662. 'index' => $d['index'],
  2663. 'contract' => $d['contract'],
  2664. 'wo' => $d['wo'],
  2665. 'activation' => $d['activation'],
  2666. 'name' => $d['name'],
  2667. 'address' => $d['address'],
  2668. 'package' => $d['package'],
  2669. 'retail_price' => $d['retail_price'],
  2670. 'incentives1' => '250% + RM50',
  2671. 'incentives2' => '',
  2672. 'total' => 'RM ' . $total,
  2673. 'claim' => $d['claim'],
  2674. ));
  2675. }
  2676. }
  2677. } else if (count($dataSeptemberB) < 50) {
  2678. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2679. if ($d['contract'] == '12') {
  2680. array_push($combineData, array(
  2681. 'index' => $d['index'],
  2682. 'contract' => $d['contract'],
  2683. 'wo' => $d['wo'],
  2684. 'activation' => $d['activation'],
  2685. 'name' => $d['name'],
  2686. 'address' => $d['address'],
  2687. 'package' => $d['package'],
  2688. 'retail_price' => $d['retail_price'],
  2689. 'incentives1' => $d['incentives1'],
  2690. 'incentives2' => $d['incentives2'],
  2691. 'total' => $d['total'],
  2692. 'claim' => $d['claim'],
  2693. ));
  2694. } else {
  2695. if ($d['package'] == 1) {
  2696. $total = 1500;
  2697. } else {
  2698. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2699. }
  2700. array_push($combineData, array(
  2701. 'index' => $d['index'],
  2702. 'contract' => $d['contract'],
  2703. 'wo' => $d['wo'],
  2704. 'activation' => $d['activation'],
  2705. 'name' => $d['name'],
  2706. 'address' => $d['address'],
  2707. 'package' => $d['package'],
  2708. 'retail_price' => $d['retail_price'],
  2709. 'incentives1' => '250%',
  2710. 'incentives2' => '',
  2711. 'total' => 'RM ' . $total,
  2712. 'claim' => $d['claim'],
  2713. ));
  2714. }
  2715. }
  2716. }
  2717. }
  2718. foreach ($dataOctoberR as $key => $d) {
  2719. 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')) {
  2720. if ($d['contract'] == '24') {
  2721. if ($d['package'] == 50) {
  2722. $d['retail_price'] = 69;
  2723. } elseif ($d['package'] == 100) {
  2724. $d['retail_price'] = 89;
  2725. } elseif ($d['package'] == 500) {
  2726. $d['retail_price'] = 129;
  2727. }
  2728. }
  2729. }
  2730. if (count($dataOctoberR) >= 50) {
  2731. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2732. if ($d['contract'] == '12') {
  2733. array_push($combineData, array(
  2734. 'index' => $d['index'],
  2735. 'contract' => $d['contract'],
  2736. 'wo' => $d['wo'],
  2737. 'activation' => $d['activation'],
  2738. 'name' => $d['name'],
  2739. 'address' => $d['address'],
  2740. 'package' => $d['package'],
  2741. 'retail_price' => $d['retail_price'],
  2742. 'incentives1' => $d['incentives1'],
  2743. 'incentives2' => $d['incentives2'],
  2744. 'total' => $d['total'],
  2745. 'claim' => $d['claim'],
  2746. ));
  2747. } else {
  2748. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2749. array_push($combineData, array(
  2750. 'index' => $d['index'],
  2751. 'contract' => $d['contract'],
  2752. 'wo' => $d['wo'],
  2753. 'activation' => $d['activation'],
  2754. 'name' => $d['name'],
  2755. 'address' => $d['address'],
  2756. 'package' => $d['package'],
  2757. 'retail_price' => $d['retail_price'],
  2758. 'incentives1' => '250% + RM50',
  2759. 'incentives2' => $d['incentives2'],
  2760. 'total' => 'RM ' . $total,
  2761. 'claim' => $d['claim'],
  2762. ));
  2763. }
  2764. }
  2765. } else if (count($dataOctoberR) < 50) {
  2766. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2767. if ($d['contract'] == '12') {
  2768. array_push($combineData, array(
  2769. 'index' => $d['index'],
  2770. 'contract' => $d['contract'],
  2771. 'wo' => $d['wo'],
  2772. 'activation' => $d['activation'],
  2773. 'name' => $d['name'],
  2774. 'address' => $d['address'],
  2775. 'package' => $d['package'],
  2776. 'retail_price' => $d['retail_price'],
  2777. 'incentives1' => $d['incentives1'],
  2778. 'incentives2' => $d['incentives2'],
  2779. 'total' => $d['total'],
  2780. 'claim' => $d['claim'],
  2781. ));
  2782. } else {
  2783. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2784. array_push($combineData, array(
  2785. 'index' => $d['index'],
  2786. 'contract' => $d['contract'],
  2787. 'wo' => $d['wo'],
  2788. 'activation' => $d['activation'],
  2789. 'name' => $d['name'],
  2790. 'address' => $d['address'],
  2791. 'package' => $d['package'],
  2792. 'retail_price' => $d['retail_price'],
  2793. 'incentives1' => '250%',
  2794. 'incentives2' => $d['incentives2'],
  2795. 'total' => 'RM ' . $total,
  2796. 'claim' => $d['claim'],
  2797. ));
  2798. }
  2799. }
  2800. }
  2801. }
  2802. foreach ($dataOctoberB as $key => $d) {
  2803. 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')) {
  2804. if ($d['contract'] == '24') {
  2805. if ($d['package'] == 50) {
  2806. $d['retail_price'] = 89;
  2807. } elseif ($d['package'] == 100) {
  2808. $d['retail_price'] = 119;
  2809. } elseif ($d['package'] == 300) {
  2810. $d['retail_price'] = 179;
  2811. } elseif ($d['package'] == 500) {
  2812. $d['retail_price'] = 249;
  2813. }
  2814. }
  2815. }
  2816. if (count($dataOctoberB) >= 50) {
  2817. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2818. if ($d['contract'] == '12') {
  2819. array_push($combineData, array(
  2820. 'index' => $d['index'],
  2821. 'contract' => $d['contract'],
  2822. 'wo' => $d['wo'],
  2823. 'activation' => $d['activation'],
  2824. 'name' => $d['name'],
  2825. 'address' => $d['address'],
  2826. 'package' => $d['package'],
  2827. 'retail_price' => $d['retail_price'],
  2828. 'incentives1' => $d['incentives1'],
  2829. 'incentives2' => $d['incentives2'],
  2830. 'total' => $d['total'],
  2831. 'claim' => $d['claim'],
  2832. ));
  2833. } else {
  2834. if ($d['package'] == 1) {
  2835. $total = 1500;
  2836. } else {
  2837. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2838. }
  2839. array_push($combineData, array(
  2840. 'index' => $d['index'],
  2841. 'contract' => $d['contract'],
  2842. 'wo' => $d['wo'],
  2843. 'activation' => $d['activation'],
  2844. 'name' => $d['name'],
  2845. 'address' => $d['address'],
  2846. 'package' => $d['package'],
  2847. 'retail_price' => $d['retail_price'],
  2848. 'incentives1' => '250% + RM50',
  2849. 'incentives2' => '',
  2850. 'total' => 'RM ' . $total,
  2851. 'claim' => $d['claim'],
  2852. ));
  2853. }
  2854. }
  2855. } else if (count($dataOctoberB) < 50) {
  2856. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2857. if ($d['contract'] == '12') {
  2858. array_push($combineData, array(
  2859. 'index' => $d['index'],
  2860. 'contract' => $d['contract'],
  2861. 'wo' => $d['wo'],
  2862. 'activation' => $d['activation'],
  2863. 'name' => $d['name'],
  2864. 'address' => $d['address'],
  2865. 'package' => $d['package'],
  2866. 'retail_price' => $d['retail_price'],
  2867. 'incentives1' => $d['incentives1'],
  2868. 'incentives2' => $d['incentives2'],
  2869. 'total' => $d['total'],
  2870. 'claim' => $d['claim'],
  2871. ));
  2872. } else {
  2873. if ($d['package'] == 1) {
  2874. $total = 1500;
  2875. } else {
  2876. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2877. }
  2878. array_push($combineData, array(
  2879. 'index' => $d['index'],
  2880. 'contract' => $d['contract'],
  2881. 'wo' => $d['wo'],
  2882. 'activation' => $d['activation'],
  2883. 'name' => $d['name'],
  2884. 'address' => $d['address'],
  2885. 'package' => $d['package'],
  2886. 'retail_price' => $d['retail_price'],
  2887. 'incentives1' => '250%',
  2888. 'incentives2' => '',
  2889. 'total' => 'RM ' . $total,
  2890. 'claim' => $d['claim'],
  2891. ));
  2892. }
  2893. }
  2894. }
  2895. }
  2896. } else {
  2897. $dataR = $this->returnDataR($company, $year, $month);
  2898. foreach ($dataR as $r) {
  2899. $combineData[] = $r;
  2900. }
  2901. $dataB = $this->returnDataB($company, $year, $month);
  2902. foreach ($dataB as $b) {
  2903. $combineData[] = $b;
  2904. }
  2905. }
  2906. $i = 0;
  2907. $nested_data = array();
  2908. if (!empty($combineData)) {
  2909. foreach ($combineData as $c) {
  2910. $update_dealer = DealerClaim::where('wo', $c['wo'])->first();
  2911. if (!empty($update_dealer)) {
  2912. $update_dealer->incentives1 = $c['incentives1'];
  2913. $update_dealer->incentives2 = $c['incentives2'];
  2914. $update_dealer->retail_price = $c['retail_price'];
  2915. $update_dealer->total_claim = $c['total'];
  2916. $update_dealer->save();
  2917. }
  2918. }
  2919. }
  2920. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  2921. $q->with('Form');
  2922. }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->get();
  2923. if (!empty($dataClaim)) {
  2924. foreach ($dataClaim as $c) {
  2925. $address = '';
  2926. $name = '';
  2927. if ($c->Subscriber->Form->type_application == 'R') {
  2928. if ($c->Subscriber->street != '') {
  2929. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  2930. } else {
  2931. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  2932. }
  2933. $name = $c->Subscriber->name;
  2934. } else if ($c->Subscriber->Form->type_application == 'B') {
  2935. if ($c->Subscriber->unit_no != '') {
  2936. $address = $c->Subscriber->unit_no . ', ' . $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  2937. } else {
  2938. $address = $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  2939. }
  2940. $name = $c->Subscriber->company_name;
  2941. }
  2942. $i++;
  2943. array_push($final, array(
  2944. 'index' => $c->formT,
  2945. 'contract' => $c->contract,
  2946. 'wo' => $c->wo,
  2947. 'activated_dt' => $c->activated_dt,
  2948. 'name' => $name,
  2949. 'address' => $address,
  2950. 'package' => $c->package,
  2951. 'retail_price' => $c->retail_price,
  2952. 'incentives1' => $c->incentives1,
  2953. 'incentives2' => $c->incentives2,
  2954. 'total' => $c->total_claim,
  2955. 'claimed' => $c->claim_dt,
  2956. ));
  2957. }
  2958. }
  2959. foreach ($final as $f) {
  2960. $basic_total += floatval(str_replace('RM ', '', $f['total']));
  2961. }
  2962. // Calculate extra incentves
  2963. // if($month == '1' && $year == '2020'){
  2964. // if(count($count_cyberjaya) > 50){
  2965. // $balance = count($count_cyberjaya) - 50;
  2966. // $extra += $balance * 50;
  2967. // }
  2968. // if(count($count_jasin) > 10){
  2969. // $balance = count($count_jasin) - 10;
  2970. // $extra += $balance * 50;
  2971. // }
  2972. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  2973. // if(count($count_cyberjaya) > 50){
  2974. // $balance = count($count_cyberjaya) - 50;
  2975. // $extra += $balance * 50;
  2976. // }
  2977. // if(count($count_jasin) > 20){
  2978. // $balance = count($count_jasin) - 10;
  2979. // $extra += $balance * 50;
  2980. // }
  2981. // }else {
  2982. // $extra = 0;
  2983. // }
  2984. $extra = 0;
  2985. $totals = $basic_total + $extra;
  2986. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  2987. // $pdf->setPaper('A4', 'landscape');
  2988. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  2989. // return $pdf->download( $pdfName );
  2990. return $final;
  2991. }
  2992. // else if($year!='null' && $month!='null' && $app!='null'){
  2993. // $count_cyberjaya = array(); $count_jasin = array();
  2994. // $extra = 0; $basic_total = 0; $totals = 0;
  2995. // if($app == 'Residential'){
  2996. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  2997. // $dataDis = $this->returnDataR($company,'2019','12');
  2998. // $dataJan = $this->returnDataR($company,'2020','1');
  2999. // foreach ($dataDis as $key => $d) {
  3000. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  3001. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  3002. // $count_cyberjaya[] = $d;
  3003. // }
  3004. // if (strpos($d['address'], 'Jasin') !== false) {
  3005. // $count_jasin[] = $d;
  3006. // }
  3007. // }else if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020' && date('d/m/Y', strtotime($d['activation'])) <= '31/7/2020'){
  3008. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  3009. // $count_cyberjaya[] = $d;
  3010. // }
  3011. // if (strpos($d['address'], 'Jasin') !== false) {
  3012. // $count_jasin[] = $d;
  3013. // }
  3014. // }else {
  3015. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3016. // $combineData[] = $d;
  3017. // }
  3018. // }
  3019. // }
  3020. // foreach ($dataJan as $key => $d) {
  3021. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  3022. // $count_cyberjaya[] = $d;
  3023. // }
  3024. // if (strpos($d['address'], 'Jasin') !== false) {
  3025. // $count_jasin[] = $d;
  3026. // }
  3027. // }
  3028. // // Store to combineData New Incentives Cyberjaya
  3029. // foreach ($count_cyberjaya as $key => $d) {
  3030. // if(count($count_cyberjaya) > 50){
  3031. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3032. // if($d['contract'] == '12'){
  3033. // array_push($combineData, array(
  3034. // 'index' => $d['index'],
  3035. // 'contract' => $d['contract'],
  3036. // 'wo' => $d['wo'],
  3037. // 'activation' => $d['activation'],
  3038. // 'name' => $d['name'],
  3039. // 'address' => $d['address'],
  3040. // 'package' => $d['package'],
  3041. // 'retail_price' => $d['retail_price'],
  3042. // 'incentives1' => $d['incentives1'],
  3043. // 'incentives2' => $d['incentives2'],
  3044. // 'total' => $d['total'],
  3045. // 'claim' => $d['claim'],
  3046. // ));
  3047. // }else {
  3048. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  3049. // array_push($combineData, array(
  3050. // 'index' => $d['index'],
  3051. // 'contract' => $d['contract'],
  3052. // 'wo' => $d['wo'],
  3053. // 'activation' => $d['activation'],
  3054. // 'name' => $d['name'],
  3055. // 'address' => $d['address'],
  3056. // 'package' => $d['package'],
  3057. // 'retail_price' => $d['retail_price'],
  3058. // 'incentives1' => '230%',
  3059. // 'incentives2' => $d['incentives2'],
  3060. // 'total' => 'RM '.$total,
  3061. // 'claim' => $d['claim'],
  3062. // ));
  3063. // }
  3064. // }
  3065. // }else if(count($count_cyberjaya) < 50){
  3066. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3067. // array_push($combineData, array(
  3068. // 'index' => $d['index'],
  3069. // 'contract' => $d['contract'],
  3070. // 'wo' => $d['wo'],
  3071. // 'activation' => $d['activation'],
  3072. // 'name' => $d['name'],
  3073. // 'address' => $d['address'],
  3074. // 'package' => $d['package'],
  3075. // 'retail_price' => $d['retail_price'],
  3076. // 'incentives1' => $d['incentives1'],
  3077. // 'incentives2' => $d['incentives2'],
  3078. // 'total' => $d['total'],
  3079. // 'claim' => $d['claim'],
  3080. // ));
  3081. // }
  3082. // }
  3083. // }
  3084. // // Store to combineData New Incentives Jasin
  3085. // foreach ($count_jasin as $key => $d) {
  3086. // if(count($count_jasin) > 10){
  3087. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3088. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  3089. // array_push($combineData, array(
  3090. // 'index' => $d['index'],
  3091. // 'contract' => $d['contract'],
  3092. // 'wo' => $d['wo'],
  3093. // 'activation' => $d['activation'],
  3094. // 'name' => $d['name'],
  3095. // 'address' => $d['address'],
  3096. // 'package' => $d['package'],
  3097. // 'retail_price' => $d['retail_price'],
  3098. // 'incentives1' => '230%',
  3099. // 'incentives2' => $d['incentives2'],
  3100. // 'total' => 'RM '.$total,
  3101. // 'claim' => $d['claim'],
  3102. // ));
  3103. // }
  3104. // }else if(count($count_jasin) < 10){
  3105. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3106. // array_push($combineData, array(
  3107. // 'index' => $d['index'],
  3108. // 'contract' => $d['contract'],
  3109. // 'wo' => $d['wo'],
  3110. // 'activation' => $d['activation'],
  3111. // 'name' => $d['name'],
  3112. // 'address' => $d['address'],
  3113. // 'package' => $d['package'],
  3114. // 'retail_price' => $d['retail_price'],
  3115. // 'incentives1' => $d['incentives1'],
  3116. // 'incentives2' => $d['incentives2'],
  3117. // 'total' => $d['total'],
  3118. // 'claim' => $d['claim'],
  3119. // ));
  3120. // }
  3121. // }
  3122. // }
  3123. // }else {
  3124. // $dataR = $this->returnDataR($company,$year,$month);
  3125. // foreach($dataR as $r){
  3126. // $combineData[] = $r;
  3127. // }
  3128. // }
  3129. // }else if($app == 'Business'){
  3130. // $dataB = $this->returnDataB($company,$year,$month);
  3131. // }
  3132. // foreach($dataB as $b){
  3133. // $combineData[] = $b;
  3134. // }
  3135. // $i = 0;
  3136. // $nested_data = array();
  3137. // if(!empty($combineData)){
  3138. // foreach ($combineData as $c){
  3139. // $i++;
  3140. // array_push($final, array(
  3141. // 'index' => $c['index'],
  3142. // 'contract' => $c['contract'],
  3143. // 'wo' => $c['wo'],
  3144. // 'activated_dt' => $c['activation'],
  3145. // 'name' => $c['name'],
  3146. // 'address' => $c['address'],
  3147. // 'package' => $c['package'],
  3148. // 'retail_price' => $c['retail_price'],
  3149. // 'incentives1' => $c['incentives1'],
  3150. // 'incentives2' => $c['incentives2'],
  3151. // 'total' => $c['total'],
  3152. // 'claimed' => $c['claim'],
  3153. // ));
  3154. // }
  3155. // }
  3156. // foreach($final as $f){
  3157. // $basic_total += floatval(str_replace('RM ', '', $f['total']));
  3158. // }
  3159. // //Calculate extra incentves
  3160. // if($month == '1' && $year == '2020'){
  3161. // if(count($count_cyberjaya) > 50){
  3162. // $balance = count($count_cyberjaya) - 50;
  3163. // $extra += $balance * 50;
  3164. // }
  3165. // if(count($count_jasin) > 10){
  3166. // $balance = count($count_jasin) - 10;
  3167. // $extra += $balance * 50;
  3168. // }
  3169. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  3170. // if(count($count_cyberjaya) > 50){
  3171. // $balance = count($count_cyberjaya) - 50;
  3172. // $extra += $balance * 50;
  3173. // }
  3174. // if(count($count_jasin) > 20){
  3175. // $balance = count($count_jasin) - 10;
  3176. // $extra += $balance * 50;
  3177. // }
  3178. // }else {
  3179. // $extra = 0;
  3180. // }
  3181. // $totals = $basic_total + $extra;
  3182. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  3183. // $pdf->setPaper('A4', 'landscape');
  3184. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  3185. // return $pdf->download( $pdfName );
  3186. // }
  3187. }
  3188. public function update_total_claim()
  3189. {
  3190. $dealer = DealerClaim::all();
  3191. foreach ($dealer as $key => $d) {
  3192. $claim = str_replace("RM ", "", $d->total_claim);
  3193. $price = str_replace("RM ", "", $d->retail_price);
  3194. $d->total_claim = floatval($claim);
  3195. $d->retail_price = floatval($price);
  3196. $d->save();
  3197. }
  3198. }
  3199. }