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

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