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

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