Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

DealerController.php 118KB

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