Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DealerController.php 116KB

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