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

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