You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

DealerController.php 100KB

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