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

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