您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DealerController.php 110KB

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