You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DealerController.php 118KB

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