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

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