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

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