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

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