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

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