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

DealerController.php 116KB

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