Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

DealerController.php 114KB

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