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 113KB

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