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

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