Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DealerController.php 74KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580
  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\Commission;
  14. use App\Model\Company;
  15. use App\Model\Form;
  16. use App\Model\FormStatus;
  17. use App\Model\Subscriber;
  18. use App\Model\PackageDetail;
  19. use App\Model\WorkOrder;
  20. use App\Model\Docket;
  21. class DealerController extends Controller
  22. {
  23. public function viewList(){
  24. $id = Auth::guard('ds')->id();
  25. $user = Staff::with('StaffDetail')->find($id);
  26. return view('dealer.index',compact('user'));
  27. }
  28. /***
  29. / Agent list
  30. ***/
  31. public function gAgentList(){
  32. $id = Auth::guard('ds')->id();
  33. $user = Staff::find($id);
  34. $email = $user->email;
  35. $userDetails = StaffDetail::where('email',$email)->first();
  36. $all = StaffDetail::where('company_id',$userDetails->company_id)->orderBy('created_at','desc')->get();
  37. $curr = Carbon::now()->getTimestamp();
  38. $i = 0;
  39. $nested_data = array();
  40. if(!empty($all)){
  41. foreach ($all as $a){
  42. $i++; $y = ''; $n1 = '';
  43. if($userDetails->_id == $a->_id){
  44. $y = $a->name."-You";
  45. }else {
  46. $y = $a->name;
  47. }
  48. $reg_time = $a->created_at;
  49. $expiry_date = $reg_time->addDays(3);
  50. $expiry_date = $expiry_date->getTimestamp();
  51. if($curr < $expiry_date) {
  52. $n1 = "New/";
  53. }
  54. array_push($nested_data, array(
  55. 'index' => $i,
  56. 'image' => $a->user_pic,
  57. 'name' => $n1.$y,
  58. 'ic' => $a->ic,
  59. 'phone' => $a->phone,
  60. 'email' => $a->email,
  61. 'action' => $a->_id
  62. ));
  63. }
  64. }
  65. return \DataTables::of($nested_data)->make(true);
  66. }
  67. /***
  68. / Application Form List
  69. ***/
  70. public function viewAppList(){
  71. $id = Auth::guard('ds')->id();
  72. $user = Staff::with('StaffDetail')->find($id);
  73. return view('dealer.application-form-list',compact('user'));
  74. }
  75. /***
  76. / Get Application Form List
  77. ***/
  78. public function getSubscribers($dealerCompany)
  79. {
  80. $data = array();
  81. $curr = Carbon::now()->getTimestamp();
  82. $subscriber = Subscriber::where('dealer_company', $dealerCompany)->get();
  83. foreach ($subscriber as $key => $s) {
  84. $n1 = '';
  85. $reg_time = Carbon::createFromTimestamp($s->reg_time);
  86. $expiry_date = $reg_time->addDays(3);
  87. $expiry_date = $expiry_date->getTimestamp();
  88. $agentName = StaffDetail::where('_id',$s->dealer)->first();
  89. $build = Coverage::where('address',$s->building)->first();
  90. if($s->street == ''){
  91. $street = $build->street;
  92. }else {
  93. $street = $s->street;
  94. }
  95. if($curr < $expiry_date) {
  96. $n1 = "New/";
  97. }
  98. $data[] = array(
  99. 'formT' => 'R',
  100. 'wo' => $s->wo,
  101. 'name' => $n1.$s->name,
  102. 'no' => $s->phone1,
  103. 'unit' => $s->unit_no,
  104. 'building' => $s->building,
  105. 'street' => $street,
  106. 'postcode' => $s->postcode,
  107. 'city' => $s->city,
  108. 'sales' => $agentName->name,
  109. 'created_at' => $s->reg_time,
  110. 'action' => $s->_id,
  111. );
  112. }
  113. return $data;
  114. }
  115. public function getBusiness($dealerCompany){
  116. $data = array();
  117. $curr = Carbon::now()->getTimestamp();
  118. $business = Subscriber::where('dealer_company', $dealerCompany)->get();
  119. foreach ($business as $key => $s) {
  120. $n1 = '';
  121. $reg_time = Carbon::createFromTimestamp($s->reg_time);
  122. $expiry_date = $reg_time->addDays(3);
  123. $expiry_date = $expiry_date->getTimestamp();
  124. if($curr < $expiry_date) {
  125. $n1 = "New/";
  126. }
  127. $agentName = StaffDetail::where('_id',$s->dealer)->first();
  128. $data[] = array(
  129. 'formT' => 'B',
  130. 'wo' => $s->wo,
  131. 'name' => $n1.$s->name,
  132. 'no' => $s->phone1,
  133. 'unit' => '-',
  134. 'building' => '-',
  135. 'street' => $s->address,
  136. 'postcode' => $s->postcode,
  137. 'city' => $s->city,
  138. 'sales' => $agentName->name,
  139. 'created_at' => $s->reg_time,
  140. 'action' => $s->_id,
  141. );
  142. }
  143. return $data;
  144. }
  145. public function getOrderHistory($id){
  146. $data = array();
  147. $order_history = FormStatus::where('form_id', $id)->get();
  148. foreach($order_history as $oh){
  149. $utcdatetime = new \MongoDB\BSON\UTCDateTime((string) $oh->date);
  150. $datetime = $utcdatetime->toDateTime();
  151. $time = $datetime->format(DATE_RSS);
  152. $time = strtotime($time.' UTC');
  153. $dateInLocal = date("d/m/Y h:i a", $time);
  154. $data[] = array(
  155. 'date' => $dateInLocal,
  156. 'status' => $oh->status,
  157. 'desc' => $oh->desc
  158. );
  159. }
  160. $json = json_encode($data);
  161. return $json;
  162. }
  163. public function gApplicationList1()
  164. {
  165. $id = Auth::guard('ds')->id();
  166. $user = Staff::with('StaffDetail')->find($id);
  167. $fm = Form::with('Subscriber')->where('company_id',$user->StaffDetail->company_id)->orderBy('created_at','desc')->get();
  168. $nested_data = array();
  169. $i=0;
  170. foreach($fm as $f)
  171. {
  172. $dname="";
  173. $wo = WorkOrder::where('_id', $f->_id)->first();
  174. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  175. if(!empty($dealer)){
  176. $dname=$dealer->name;
  177. }
  178. $address = ''; $name = '';
  179. if($f->type_application == 'R'){
  180. $address = $f->Subscriber->building_name;
  181. $name = $f->Subscriber->name;
  182. }else if($f->type_application == 'B'){
  183. $address = '-';
  184. $name = $f->Subscriber->company_name;
  185. }
  186. if(empty($wo) && !empty($f->Subscriber))
  187. {
  188. $i++;
  189. array_push($nested_data, array(
  190. 'index' => $i.$f->type_application,
  191. 'name' => $name,
  192. 'phone' => $f->Subscriber->phone1,
  193. 'unit' => $f->Subscriber->unit_no,
  194. 'building' => $address,
  195. 'street' => $f->Subscriber->street,
  196. 'postcode' => $f->Subscriber->postcode,
  197. 'city' => $f->Subscriber->city,
  198. 'sales' => $dname,
  199. 'action' => $f->_id
  200. ));
  201. }
  202. }
  203. return \DataTables::of($nested_data)->make(true);
  204. }
  205. public function gApplicationList2()
  206. {
  207. $id = Auth::guard('ds')->id();
  208. $user = Staff::with('StaffDetail')->find($id);
  209. $fm = Form::with('Subscriber')->where('company_id',$user->StaffDetail->company_id)->orderBy('created_at','desc')->get();
  210. $nested_data = array();
  211. $i=0;
  212. foreach($fm as $f)
  213. {
  214. $dname="";
  215. $wo = WorkOrder::where('_id', $f->_id)->first();
  216. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  217. if(!empty($dealer)){
  218. $dname=$dealer->name;
  219. }
  220. $address = ''; $name = '';
  221. if($f->type_application == 'R'){
  222. $address = $f->Subscriber->building_name;
  223. $name = $f->Subscriber->name;
  224. }else if($f->type_application == 'B'){
  225. $address = '-';
  226. $name = $f->Subscriber->company_name;
  227. }
  228. if(!empty($wo) && $wo->status!='Completed')
  229. {
  230. $i++;
  231. array_push($nested_data, array(
  232. 'index' => $i.$f->type_application,
  233. 'name' => $name,
  234. 'phone' => $f->Subscriber->phone1,
  235. 'unit' => $f->Subscriber->unit_no,
  236. 'building' => $address,
  237. 'street' => $f->Subscriber->street,
  238. 'postcode' => $f->Subscriber->postcode,
  239. 'city' => $f->Subscriber->city,
  240. 'sales' => $dname,
  241. 'action' => $f->_id
  242. ));
  243. }
  244. }
  245. return \DataTables::of($nested_data)->make(true);
  246. }
  247. public function getCompletedList($year, $month)
  248. {
  249. $id = Auth::guard('ds')->id();
  250. $user = Staff::find($id);
  251. $email = $user->email;
  252. $userDetails = StaffDetail::where('email',$email)->first();
  253. $subs = $this->getSubscribers($userDetails->company_id);
  254. $buss = $this->getBusiness($userDetails->company_id);
  255. // Combine
  256. $cdata = array();
  257. foreach ($subs as $key => $s) {
  258. $cdata[] = $s;
  259. }
  260. foreach ($buss as $key => $b) {
  261. $cdata[] = $b;
  262. }
  263. // Sort based on TimeStamp
  264. $sort = array();
  265. foreach ($cdata as $key => $r) {
  266. $sort[$key] = $r['created_at'];
  267. }
  268. array_multisort($sort, SORT_DESC, $cdata);
  269. $wK = WorkDetail::get();
  270. $curr = Carbon::now()->getTimestamp();
  271. $mY = '';
  272. if($year != 'null' && $month != 'null'){
  273. $mY = $year.'/'.$month;
  274. }
  275. $final = array(); $filter = array();
  276. $dW = array();
  277. foreach ($cdata as $c){
  278. if($c['wo'] != ''){
  279. foreach ($wK as $key => $w) {
  280. if($c['wo'] == $w->wo && $w->status == 'Completed'){
  281. $dW[] = $c;
  282. }
  283. }
  284. }
  285. }
  286. foreach($dW as $d){
  287. if($mY != ''){
  288. $docket = Docket::where('work_order_id', $d['wo'])->first();
  289. $cDate = date('Y/m', strtotime($docket->end_job));;
  290. if($mY == $cDate){
  291. $filter[] = $d;
  292. }
  293. }else {
  294. $filter[] = $d;
  295. }
  296. }
  297. foreach ($filter as $c){
  298. $do = Docket::where('work_order_id', $c['wo'])->first();
  299. $n1 = '';
  300. $reg_time = Carbon::createFromTimestamp(strtotime($do->end_job));
  301. $expiry_date = $reg_time->addDays(3);
  302. $expiry_date = $expiry_date->getTimestamp();
  303. if($curr < $expiry_date) {
  304. $n1 = "New/";
  305. }
  306. $final[] = array(
  307. 'formT' => $c['formT'],
  308. 'wo' => $c['wo'],
  309. 'do' => $do->docket_id,
  310. 'activated' => $do->end_job,
  311. 'name' => $n1.str_replace("New/","",$c['name']),
  312. 'no' => $c['no'],
  313. 'unit' => $c['unit'],
  314. 'building' => $c['building'],
  315. 'street' => $c['street'],
  316. 'postcode' => $c['postcode'],
  317. 'city' => $c['city'],
  318. 'sales' => $c['sales'],
  319. 'created_at' => $c['created_at'],
  320. 'action' => $c['action'],
  321. );
  322. }
  323. return $final;
  324. }
  325. public function gApplicationList3($year,$month)
  326. {
  327. $id = Auth::guard('ds')->id();
  328. $user = Staff::with('StaffDetail')->find($id);
  329. $mY = '';
  330. if($year!='null' && $month!='null'){
  331. $mY = $month.'/'.$year;
  332. }
  333. $fm = Form::with('Subscriber','WorkOrder')->where('company_id',$user->StaffDetail->company_id)->orderBy('created_at','desc')->get();
  334. $nested_data = array();
  335. $i=0;
  336. foreach($fm as $f)
  337. {
  338. if(!empty($f->WorkOrder)){
  339. if($f->WorkOrder->status == 'Completed'){
  340. $wo = WorkOrder::with('Docket')->where('wo', $f->WorkOrder->wo)->first();
  341. $dealer = StaffDetail::where('_id', $f->dealer_id)->withTrashed()->first();
  342. $i++;
  343. $address = ''; $name = '';
  344. if($f->type_application == 'R'){
  345. $address = $f->Subscriber->building_name;
  346. $name = $f->Subscriber->name;
  347. }else if($f->type_application == 'B'){
  348. $address = '-';
  349. $name = $f->Subscriber->company_name;
  350. }
  351. if(!empty($wo->Docket)){
  352. $end = date('m/Y',strtotime($wo->Docket->end_job));
  353. if($mY == ''){
  354. array_push($nested_data, array(
  355. 'index' => $i.$f->type_application,
  356. 'wo' => $wo->wo,
  357. 'do' => $f->WorkOrder->docket_id,
  358. 'name' => $name,
  359. 'phone' => $f->Subscriber->phone1,
  360. 'unit' => $f->Subscriber->unit_no,
  361. 'building' => $address,
  362. 'street' => $f->Subscriber->street,
  363. 'postcode' => $f->Subscriber->postcode,
  364. 'city' => $f->Subscriber->city,
  365. 'sales' => $dealer->name,
  366. 'action' => $f->_id
  367. ));
  368. }else if($mY == $end){
  369. array_push($nested_data, array(
  370. 'index' => $i.$f->type_application,
  371. 'wo' => $wo->wo,
  372. 'do' => $f->WorkOrder->docket_id,
  373. 'name' => $name,
  374. 'phone' => $f->Subscriber->phone1,
  375. 'unit' => $f->Subscriber->unit_no,
  376. 'building' => $address,
  377. 'street' => $f->Subscriber->street,
  378. 'postcode' => $f->Subscriber->postcode,
  379. 'city' => $f->Subscriber->city,
  380. 'sales' => $dealer->name,
  381. 'action' => $f->_id
  382. ));
  383. }
  384. }
  385. }
  386. }
  387. }
  388. return \DataTables::of($nested_data)->make(true);
  389. }
  390. /***
  391. / Claim All
  392. ***/
  393. public function claimAll() {
  394. $id = Auth::guard('ds')->id();
  395. $user = Staff::with('StaffDetail')->find($id);
  396. return view('dealer.claim-all',compact('user'));
  397. }
  398. /***
  399. / Convert To PDF
  400. ***/
  401. public function exportPDF1() {
  402. return view('pdf.agent-claim');
  403. }
  404. public function exportPDF($company,$year,$month,$app) {
  405. $final = array();
  406. $id = Auth::guard('ds')->id();
  407. $user = Staff::with('StaffDetail')->find($id);
  408. $com = Company::where('_id',$user->StaffDetail->company_id)->first();
  409. $dataR = array(); $dataB = array(); $combineData = array();
  410. $extra = 0;
  411. if($year!='null' && $month!='null' && $app=='null'){
  412. $count_cyberjaya = array(); $count_jasin = array();
  413. $extra = 0; $basic_total = 0; $totals = 0;
  414. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  415. $dataDis = $this->returnDataR($company,'2019','12');
  416. $dataJan = $this->returnDataR($company,'2020','1');
  417. foreach ($dataDis as $key => $d) {
  418. if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  419. if (strpos($d['address'], 'Cyberjaya') !== false) {
  420. $count_cyberjaya[] = $d;
  421. }
  422. if (strpos($d['address'], 'Jasin') !== false) {
  423. $count_jasin[] = $d;
  424. }
  425. }else if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020' && date('d/m/Y', strtotime($d['activation'])) <= '31/7/2020'){
  426. if (strpos($d['address'], 'Cyberjaya') !== false) {
  427. $count_cyberjaya[] = $d;
  428. }
  429. if (strpos($d['address'], 'Jasin') !== false) {
  430. $count_jasin[] = $d;
  431. }
  432. }else {
  433. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  434. $combineData[] = $d;
  435. }
  436. }
  437. }
  438. foreach ($dataJan as $key => $d) {
  439. if (strpos($d['address'], 'Cyberjaya') !== false) {
  440. $count_cyberjaya[] = $d;
  441. }
  442. if (strpos($d['address'], 'Jasin') !== false) {
  443. $count_jasin[] = $d;
  444. }
  445. }
  446. // Store to combineData New Incentives Cyberjaya
  447. foreach ($count_cyberjaya as $key => $d) {
  448. if(count($count_cyberjaya) > 50){
  449. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  450. if($d['contract'] == '12'){
  451. array_push($combineData, array(
  452. 'index' => $d['index'],
  453. 'contract' => $d['contract'],
  454. 'wo' => $d['wo'],
  455. 'activation' => $d['activation'],
  456. 'name' => $d['name'],
  457. 'address' => $d['address'],
  458. 'package' => $d['package'],
  459. 'retail_price' => $d['retail_price'],
  460. 'incentives1' => $d['incentives1'],
  461. 'incentives2' => $d['incentives2'],
  462. 'total' => $d['total'],
  463. 'claim' => $d['claim'],
  464. ));
  465. }else {
  466. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  467. array_push($combineData, array(
  468. 'index' => $d['index'],
  469. 'contract' => $d['contract'],
  470. 'wo' => $d['wo'],
  471. 'activation' => $d['activation'],
  472. 'name' => $d['name'],
  473. 'address' => $d['address'],
  474. 'package' => $d['package'],
  475. 'retail_price' => $d['retail_price'],
  476. 'incentives1' => '230%',
  477. 'incentives2' => $d['incentives2'],
  478. 'total' => 'RM '.$total,
  479. 'claim' => $d['claim'],
  480. ));
  481. }
  482. }
  483. }else if(count($count_cyberjaya) < 50){
  484. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  485. array_push($combineData, array(
  486. 'index' => $d['index'],
  487. 'contract' => $d['contract'],
  488. 'wo' => $d['wo'],
  489. 'activation' => $d['activation'],
  490. 'name' => $d['name'],
  491. 'address' => $d['address'],
  492. 'package' => $d['package'],
  493. 'retail_price' => $d['retail_price'],
  494. 'incentives1' => $d['incentives1'],
  495. 'incentives2' => $d['incentives2'],
  496. 'total' => $d['total'],
  497. 'claim' => $d['claim'],
  498. ));
  499. }
  500. }
  501. }
  502. // Store to combineData New Incentives Jasin
  503. foreach ($count_jasin as $key => $d) {
  504. if(count($count_jasin) > 10){
  505. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  506. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  507. array_push($combineData, array(
  508. 'index' => $d['index'],
  509. 'contract' => $d['contract'],
  510. 'wo' => $d['wo'],
  511. 'activation' => $d['activation'],
  512. 'name' => $d['name'],
  513. 'address' => $d['address'],
  514. 'package' => $d['package'],
  515. 'retail_price' => $d['retail_price'],
  516. 'incentives1' => '230%',
  517. 'incentives2' => $d['incentives2'],
  518. 'total' => 'RM '.$total,
  519. 'claim' => $d['claim'],
  520. ));
  521. }
  522. }else if(count($count_jasin) < 10){
  523. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  524. array_push($combineData, array(
  525. 'index' => $d['index'],
  526. 'contract' => $d['contract'],
  527. 'wo' => $d['wo'],
  528. 'activation' => $d['activation'],
  529. 'name' => $d['name'],
  530. 'address' => $d['address'],
  531. 'package' => $d['package'],
  532. 'retail_price' => $d['retail_price'],
  533. 'incentives1' => $d['incentives1'],
  534. 'incentives2' => $d['incentives2'],
  535. 'total' => $d['total'],
  536. 'claim' => $d['claim'],
  537. ));
  538. }
  539. }
  540. }
  541. }else {
  542. $dataR = $this->returnDataR($company,$year,$month);
  543. foreach($dataR as $r){
  544. $combineData[] = $r;
  545. }
  546. }
  547. $dataB = $this->returnDataB($company,$year,$month);
  548. foreach($dataB as $b){
  549. $combineData[] = $b;
  550. }
  551. $i = 0;
  552. $nested_data = array();
  553. if(!empty($combineData)){
  554. foreach ($combineData as $c){
  555. $i++;
  556. array_push($final, array(
  557. 'index' => $c['index'],
  558. 'contract' => $c['contract'],
  559. 'wo' => $c['wo'],
  560. 'activated_dt' => $c['activation'],
  561. 'name' => $c['name'],
  562. 'address' => $c['address'],
  563. 'package' => $c['package'],
  564. 'retail_price' => $c['retail_price'],
  565. 'incentives1' => $c['incentives1'],
  566. 'incentives2' => $c['incentives2'],
  567. 'total' => $c['total'],
  568. 'claimed' => $c['claim'],
  569. ));
  570. }
  571. }
  572. foreach($final as $f){
  573. $basic_total += floatval(str_replace('RM ', '', $f['total']));
  574. }
  575. // Calculate extra incentves
  576. if($month == '1' && $year == '2020'){
  577. if(count($count_cyberjaya) > 50){
  578. $balance = count($count_cyberjaya) - 50;
  579. $extra += $balance * 50;
  580. }
  581. if(count($count_jasin) > 10){
  582. $balance = count($count_jasin) - 10;
  583. $extra += $balance * 50;
  584. }
  585. }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  586. if(count($count_cyberjaya) > 50){
  587. $balance = count($count_cyberjaya) - 50;
  588. $extra += $balance * 50;
  589. }
  590. if(count($count_jasin) > 20){
  591. $balance = count($count_jasin) - 10;
  592. $extra += $balance * 50;
  593. }
  594. }else {
  595. $extra = 0;
  596. }
  597. $totals = $basic_total + $extra;
  598. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  599. $pdf->setPaper('A4', 'landscape');
  600. $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  601. return $pdf->download( $pdfName );
  602. }else if($year!='null' && $month!='null' && $app!='null'){
  603. $count_cyberjaya = array(); $count_jasin = array();
  604. $extra = 0; $basic_total = 0; $totals = 0;
  605. if($app == 'Residential'){
  606. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  607. $dataDis = $this->returnDataR($company,'2019','12');
  608. $dataJan = $this->returnDataR($company,'2020','1');
  609. foreach ($dataDis as $key => $d) {
  610. if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  611. if (strpos($d['address'], 'Cyberjaya') !== false) {
  612. $count_cyberjaya[] = $d;
  613. }
  614. if (strpos($d['address'], 'Jasin') !== false) {
  615. $count_jasin[] = $d;
  616. }
  617. }else if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020' && date('d/m/Y', strtotime($d['activation'])) <= '31/7/2020'){
  618. if (strpos($d['address'], 'Cyberjaya') !== false) {
  619. $count_cyberjaya[] = $d;
  620. }
  621. if (strpos($d['address'], 'Jasin') !== false) {
  622. $count_jasin[] = $d;
  623. }
  624. }else {
  625. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  626. $combineData[] = $d;
  627. }
  628. }
  629. }
  630. foreach ($dataJan as $key => $d) {
  631. if (strpos($d['address'], 'Cyberjaya') !== false) {
  632. $count_cyberjaya[] = $d;
  633. }
  634. if (strpos($d['address'], 'Jasin') !== false) {
  635. $count_jasin[] = $d;
  636. }
  637. }
  638. // Store to combineData New Incentives Cyberjaya
  639. foreach ($count_cyberjaya as $key => $d) {
  640. if(count($count_cyberjaya) > 50){
  641. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  642. if($d['contract'] == '12'){
  643. array_push($combineData, array(
  644. 'index' => $d['index'],
  645. 'contract' => $d['contract'],
  646. 'wo' => $d['wo'],
  647. 'activation' => $d['activation'],
  648. 'name' => $d['name'],
  649. 'address' => $d['address'],
  650. 'package' => $d['package'],
  651. 'retail_price' => $d['retail_price'],
  652. 'incentives1' => $d['incentives1'],
  653. 'incentives2' => $d['incentives2'],
  654. 'total' => $d['total'],
  655. 'claim' => $d['claim'],
  656. ));
  657. }else {
  658. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  659. array_push($combineData, array(
  660. 'index' => $d['index'],
  661. 'contract' => $d['contract'],
  662. 'wo' => $d['wo'],
  663. 'activation' => $d['activation'],
  664. 'name' => $d['name'],
  665. 'address' => $d['address'],
  666. 'package' => $d['package'],
  667. 'retail_price' => $d['retail_price'],
  668. 'incentives1' => '230%',
  669. 'incentives2' => $d['incentives2'],
  670. 'total' => 'RM '.$total,
  671. 'claim' => $d['claim'],
  672. ));
  673. }
  674. }
  675. }else if(count($count_cyberjaya) < 50){
  676. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  677. array_push($combineData, array(
  678. 'index' => $d['index'],
  679. 'contract' => $d['contract'],
  680. 'wo' => $d['wo'],
  681. 'activation' => $d['activation'],
  682. 'name' => $d['name'],
  683. 'address' => $d['address'],
  684. 'package' => $d['package'],
  685. 'retail_price' => $d['retail_price'],
  686. 'incentives1' => $d['incentives1'],
  687. 'incentives2' => $d['incentives2'],
  688. 'total' => $d['total'],
  689. 'claim' => $d['claim'],
  690. ));
  691. }
  692. }
  693. }
  694. // Store to combineData New Incentives Jasin
  695. foreach ($count_jasin as $key => $d) {
  696. if(count($count_jasin) > 10){
  697. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  698. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  699. array_push($combineData, array(
  700. 'index' => $d['index'],
  701. 'contract' => $d['contract'],
  702. 'wo' => $d['wo'],
  703. 'activation' => $d['activation'],
  704. 'name' => $d['name'],
  705. 'address' => $d['address'],
  706. 'package' => $d['package'],
  707. 'retail_price' => $d['retail_price'],
  708. 'incentives1' => '230%',
  709. 'incentives2' => $d['incentives2'],
  710. 'total' => 'RM '.$total,
  711. 'claim' => $d['claim'],
  712. ));
  713. }
  714. }else if(count($count_jasin) < 10){
  715. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  716. array_push($combineData, array(
  717. 'index' => $d['index'],
  718. 'contract' => $d['contract'],
  719. 'wo' => $d['wo'],
  720. 'activation' => $d['activation'],
  721. 'name' => $d['name'],
  722. 'address' => $d['address'],
  723. 'package' => $d['package'],
  724. 'retail_price' => $d['retail_price'],
  725. 'incentives1' => $d['incentives1'],
  726. 'incentives2' => $d['incentives2'],
  727. 'total' => $d['total'],
  728. 'claim' => $d['claim'],
  729. ));
  730. }
  731. }
  732. }
  733. }else {
  734. $dataR = $this->returnDataR($company,$year,$month);
  735. foreach($dataR as $r){
  736. $combineData[] = $r;
  737. }
  738. }
  739. }else if($app == 'Business'){
  740. $dataB = $this->returnDataB($company,$year,$month);
  741. }
  742. foreach($dataB as $b){
  743. $combineData[] = $b;
  744. }
  745. $i = 0;
  746. $nested_data = array();
  747. if(!empty($combineData)){
  748. foreach ($combineData as $c){
  749. $i++;
  750. array_push($final, array(
  751. 'index' => $c['index'],
  752. 'contract' => $c['contract'],
  753. 'wo' => $c['wo'],
  754. 'activated_dt' => $c['activation'],
  755. 'name' => $c['name'],
  756. 'address' => $c['address'],
  757. 'package' => $c['package'],
  758. 'retail_price' => $c['retail_price'],
  759. 'incentives1' => $c['incentives1'],
  760. 'incentives2' => $c['incentives2'],
  761. 'total' => $c['total'],
  762. 'claimed' => $c['claim'],
  763. ));
  764. }
  765. }
  766. foreach($final as $f){
  767. $basic_total += floatval(str_replace('RM ', '', $f['total']));
  768. }
  769. //Calculate extra incentves
  770. if($month == '1' && $year == '2020'){
  771. if(count($count_cyberjaya) > 50){
  772. $balance = count($count_cyberjaya) - 50;
  773. $extra += $balance * 50;
  774. }
  775. if(count($count_jasin) > 10){
  776. $balance = count($count_jasin) - 10;
  777. $extra += $balance * 50;
  778. }
  779. }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  780. if(count($count_cyberjaya) > 50){
  781. $balance = count($count_cyberjaya) - 50;
  782. $extra += $balance * 50;
  783. }
  784. if(count($count_jasin) > 20){
  785. $balance = count($count_jasin) - 10;
  786. $extra += $balance * 50;
  787. }
  788. }else {
  789. $extra = 0;
  790. }
  791. $totals = $basic_total + $extra;
  792. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  793. $pdf->setPaper('A4', 'landscape');
  794. $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  795. return $pdf->download( $pdfName );
  796. }
  797. }
  798. /***
  799. / Encrypt Password
  800. ***/
  801. public function encryptPassword($action, $string) {
  802. $output = false;
  803. $encrypt_method = "AES-256-CBC";
  804. $secret_key = '28472B4B6250655368566D5970337336';
  805. $secret_iv = md5(md5($string)); //'This is my secret iv';
  806. // hash
  807. $key = hash('sha256', $secret_key);
  808. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  809. if ( $action == 'encrypt' ) {
  810. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  811. $output = base64_encode($output);
  812. } else if( $action == 'decrypt' ) {
  813. $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  814. }
  815. return $output;
  816. }
  817. /***
  818. / Agent Form
  819. ***/
  820. public function showAgentForm(){
  821. $id = Auth::guard('ds')->id();
  822. $user = Staff::with('StaffDetail')->find($id);
  823. return view('dealer.add_agent',compact('user'));
  824. }
  825. /***
  826. / Add Agent
  827. ***/
  828. public function requestAddAgent(Request $request)
  829. {
  830. $validator = Validator::make($request->all(), [
  831. 'password' => 'min:8|confirmed',
  832. ]);
  833. if ($validator->fails()) {
  834. return redirect()->back()->withInput()->withErrors($validator);
  835. }
  836. $user = Staff::where('email', $request->get('email'))->first();
  837. if (empty($user)) {
  838. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  839. $dealerD = new StaffDetail;
  840. $dealerD->name = $request->get('aname');
  841. $dealerD->ic = $request->get('ic');
  842. $dealerD->email = $request->get('email');
  843. $dealerD->phone = $request->get('phone');
  844. $dealerD->company_id = $request->get('company_id');
  845. $dealerD->color = '';
  846. $dealerD->position = 'Sales';
  847. $dealerD->password = $pass;
  848. $dealerD->user_pic = 'assets/avatar/user.png';
  849. // Save Login Dealer
  850. $loginD = new Staff;
  851. $loginD->email = $request->get('email');
  852. $loginD->password = $pass;
  853. $loginD->roles_access = 'Sales';
  854. $loginD->company_id = $request->get('company_id');
  855. $loginD->last_login_at = '';
  856. $loginD->last_login_ip = '';
  857. // $loginData = [
  858. // 'email' => $request->get('email'),
  859. // 'password' => $pass,
  860. // 'roles_access' => 'Sales',
  861. // 'last_login_at' => '',
  862. // 'last_login_ip' => '',
  863. // ];
  864. $company = Company::where('_id',$request->get('company_id'))->first();
  865. $company->staff()->save($loginD);
  866. // $dealer = DealerLaravel::create($loginData);
  867. $loginD->staffdetail()->save($dealerD);
  868. return redirect()->back()->with('success_msg', '<strong>Success!</strong> register <strong>'.$request->get('email').'</strong>');
  869. }
  870. else
  871. {
  872. return redirect()->back()->withInput()->withErrors('Email already exist!');
  873. }
  874. }
  875. public function editAgentDealer($agent_id)
  876. {
  877. $id = Auth::guard('ds')->id();
  878. $user = Staff::find($id);
  879. $email = $user->email;
  880. $userDetails = StaffDetail::where('email',$email)->first();
  881. $person = StaffDetail::where('_id', $agent_id)->first();
  882. return view('dealer.edit_agent', compact('person','userDetails','user'));
  883. }
  884. public function deleteAgent(Request $request)
  885. {
  886. $agent = Staff::where('_id',$request->id)->first();
  887. $agentdetail = $agent->staffdetail()->first();
  888. if(!empty($agentdetail) && !empty($agent))
  889. {
  890. $agent->delete();
  891. $agentdetail->delete();
  892. return 'true';
  893. }
  894. else
  895. {
  896. return 'false';
  897. }
  898. }
  899. //Show claim list by company
  900. public function mClaimListAll($company)
  901. {
  902. $id = Auth::guard('ds')->id();
  903. $user = Staff::with('StaffDetail')->find($id);
  904. $dealer_claimAll = DealerClaim::where('dealer',$company)->orderBy('activated_dt','desc')->get();
  905. $i = 0;
  906. $nested_data = array();
  907. foreach ($dealer_claimAll as $c){
  908. $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first();
  909. $address = '';
  910. if($customer->Form->type_application == 'R'){
  911. if($customer->street != ''){
  912. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  913. }else {
  914. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  915. }
  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. }
  923. $i++;
  924. array_push($nested_data, array(
  925. 'index' => $c->formT,
  926. 'contract' => $c->contract,
  927. 'wo' => $c->wo,
  928. 'activated_dt' => $c->activated_dt,
  929. 'name' => $customer->name,
  930. 'address' => $address,
  931. 'package' => $c->package,
  932. 'retail_price' => 'RM '.$c->retail_price,
  933. 'incentives1' => '',
  934. 'incentives2' => '',
  935. 'total' => '',
  936. 'claimed' => $c->laim_dt,
  937. 'action' => 'null',
  938. ));
  939. }
  940. return \DataTables::of($nested_data)->make(true);
  941. }
  942. // Get Dealer Claim Residential
  943. public function returnDataR($company,$year,$month){
  944. $dataCR = DealerClaim::where('formT','R')->where('dealer',$company)->get();
  945. $final = array();
  946. // Month & Year
  947. $mY = '';
  948. if($year != 'null' && $month != 'null'){
  949. $mY = $month.'/'.$year;
  950. }
  951. if($mY != ''){
  952. $data12 = array(); $data24 = array();
  953. $countD12 = 0; $countD24 = 0;
  954. foreach($dataCR as $dc){
  955. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  956. if($dc->contract == "12"){
  957. $data12[] = $dc;
  958. }else if($dc->contract == "24"){
  959. $data24[] = $dc;
  960. }
  961. }
  962. }
  963. $countD24 = count($data24);
  964. $countD12 = count($data12);
  965. $comm = Commission::where('formT','R')->get();
  966. $commV12 = 0; $commV24 = 0;
  967. $comm12 = ''; $comm24 = '';
  968. foreach($comm as $c){
  969. if($c->contract =='12'){
  970. if(strpos($c->ranges, '>') !== false) {
  971. $pieces = explode(">", $c->ranges);
  972. if($countD12 >= intval($pieces[1])){
  973. $commV12 = floatval($c->comm)/100;
  974. $comm12 = $c->comm.'%';
  975. }
  976. }
  977. if(strpos($c->ranges,'-') !== false){
  978. $pieces = explode("-", $c->ranges);
  979. if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){
  980. $commV12 = floatval($c->comm)/100;
  981. $comm12 = $c->comm.'%';
  982. }
  983. }
  984. }else if($c->contract =='24'){
  985. // Contract => 24
  986. if($countD24 != 0){
  987. if(strpos($c->ranges, '>') !== false) {
  988. $pieces = explode(">", $c->ranges);
  989. if($countD24 > intval($pieces[1])){
  990. $commV24 = floatval($c->comm)/100;
  991. $comm24 = $c->comm.'%';
  992. }
  993. }
  994. if(strpos($c->ranges,'-') !== false){
  995. $pieces = explode("-", $c->ranges);
  996. if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){
  997. $commV24 = floatval($c->comm)/100;
  998. $comm24 = $c->comm.'%';
  999. }
  1000. }
  1001. }
  1002. }
  1003. }
  1004. foreach ($data12 as $key => $d) {
  1005. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1006. $address = ''; $name = '';
  1007. if($customer->Form->type_application == 'R'){
  1008. if($customer->street != ''){
  1009. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1010. }else {
  1011. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1012. }
  1013. $name = $customer->name;
  1014. }else if($customer->Form->type_application == 'B'){
  1015. if($customer->unit_no != ''){
  1016. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1017. }else {
  1018. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1019. }
  1020. $name = $customer->company_name;
  1021. }
  1022. $final[] = array(
  1023. 'index' => $d['formT'],
  1024. 'contract' => $d['contract'],
  1025. 'wo' => $d['wo'],
  1026. 'activation' => $d['activated_dt'],
  1027. 'name' => $name,
  1028. 'address' => $address,
  1029. 'package' => $d['package'],
  1030. 'retail_price' => 'RM '.$d['retail_price'],
  1031. 'incentives1' => $comm12,
  1032. 'incentives2' => '',
  1033. 'total' => 'RM '.number_format($d['retail_price']*$commV12,2),
  1034. 'claim' => $d['claim_dt'],
  1035. );
  1036. }
  1037. foreach ($data24 as $key => $d) {
  1038. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1039. $address = ''; $name = '';
  1040. if($customer->Form->type_application == 'R'){
  1041. if($customer->street != ''){
  1042. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1043. }else {
  1044. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1045. }
  1046. $name = $customer->name;
  1047. }else if($customer->Form->type_application == 'B'){
  1048. if($customer->unit_no != ''){
  1049. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1050. }else {
  1051. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1052. }
  1053. $name = $customer->company_name;
  1054. }
  1055. $final[] = array(
  1056. 'index' => $d['formT'],
  1057. 'contract' => $d['contract'],
  1058. 'wo' => $d['wo'],
  1059. 'activation' => $d['activated_dt'],
  1060. 'name' => $name,
  1061. 'address' => $address,
  1062. 'package' => $d['package'],
  1063. 'retail_price' => 'RM '.$d['retail_price'],
  1064. 'incentives1' => $comm24,
  1065. 'incentives2' => '',
  1066. 'total' => 'RM '.number_format($d['retail_price']*$commV24,2),
  1067. 'claim' => $d['claim_dt'],
  1068. );
  1069. }
  1070. }else {
  1071. foreach ($dataCR as $c){
  1072. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1073. $address = ''; $name = '';
  1074. if($customer->Form->type_application == 'R'){
  1075. if($customer->street != ''){
  1076. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1077. }else {
  1078. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1079. }
  1080. $name = $customer->name;
  1081. }else if($customer->Form->type_application == 'B'){
  1082. if($customer->unit_no != ''){
  1083. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1084. }else {
  1085. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1086. }
  1087. $name = $customer->company_name;
  1088. }
  1089. $final[] = array(
  1090. 'index' => $c['formT'],
  1091. 'contract' => $c['contract'],
  1092. 'wo' => $c['wo'],
  1093. 'activation' => $c['activated_dt'],
  1094. 'name' => $name,
  1095. 'address' => $address,
  1096. 'package' => $c['package'],
  1097. 'retail_price' => 'RM '.$c['retail_price'],
  1098. 'incentives1' => '',
  1099. 'incentives2' => '',
  1100. 'total' => '',
  1101. 'claim' => $c['claim_dt'],
  1102. );
  1103. }
  1104. }
  1105. return $final;
  1106. }
  1107. // Get Claim Business
  1108. public function returnDataB($company,$year,$month){
  1109. $dataCB = DealerClaim::where('formT','B')->where('dealer',$company)->get();
  1110. $final = array();
  1111. // Month & Year
  1112. $mY = '';
  1113. if($year != 'null' && $month != 'null'){
  1114. $mY = $month.'/'.$year;
  1115. }
  1116. if($mY != ''){
  1117. /** Contract 12
  1118. // 1=>10-100 2=>300 3=>500 4=>1
  1119. **/
  1120. $data12_1 = array(); $data12_2 = array();
  1121. $data12_3 = array(); $data12_4 = array();
  1122. $countD12_1 = 0; $countD12_2 = 0;
  1123. $countD12_3 = 0; $countD12_4 = 0;
  1124. /** Contract 24
  1125. // 1=>10-100 2=>300 3=>500 4=>1
  1126. **/
  1127. $data24_1 = array(); $data24_2 = array();
  1128. $data24_3 = array(); $data24_4 = array();
  1129. $countD24_1 = 0; $countD24_2 = 0;
  1130. $countD24_3 = 0; $countD24_4 = 0;
  1131. foreach($dataCB as $dc){
  1132. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  1133. if($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  1134. $data12_1[] = $dc;
  1135. }else if($dc->contract == "12" && $dc->package == "300"){
  1136. $data12_2[] = $dc;
  1137. }else if($dc->contract == "12" && $dc->package == "500"){
  1138. $data12_3[] = $dc;
  1139. }else if($dc->contract == "12" && $dc->package == "1"){
  1140. $data12_4[] = $dc;
  1141. }else if($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  1142. $data24_1[] = $dc;
  1143. }else if($dc->contract == "24" && $dc->package == "300"){
  1144. $data24_2[] = $dc;
  1145. }else if($dc->contract == "24" && $dc->package == "500"){
  1146. $data24_3[] = $dc;
  1147. }else if($dc->contract == "24" && $dc->package == "1"){
  1148. $data24_4[] = $dc;
  1149. }
  1150. }
  1151. }
  1152. $countD12_1 = count($data12_1); $countD12_2 = count($data12_2);
  1153. $countD12_3 = count($data12_3); $countD12_4 = count($data12_4);
  1154. $countD24_1 = count($data24_1); $countD24_2 = count($data24_2);
  1155. $countD24_3 = count($data24_3); $countD24_4 = count($data24_4);
  1156. $comm = Commission::where('formT','B')->get();
  1157. $commV12_1 = 0; $commV12_2 = 0;
  1158. $commV12_3 = 0; $commV12_4 = 0;
  1159. $commV24_1 = 0; $commV24_2 = 0;
  1160. $commV24_3 = 0; $commV24_4 = 0;
  1161. $comm12_1 = ''; $comm12_2 = '';
  1162. $comm12_3 = ''; $comm12_4 = '';
  1163. $comm24_1 = ''; $comm24_2 = '';
  1164. $comm24_3 = ''; $comm24_4 = '';
  1165. $addRM12_1 = ''; $addRM12_2 = '';
  1166. $addRM12_3 = ''; $addRM12_4 = '';
  1167. $addRM24_1 = ''; $addRM24_2 = '';
  1168. $addRM24_3 = ''; $addRM24_4 = '';
  1169. foreach($comm as $c){
  1170. /*** Contract 24 **/
  1171. if($c->contract =='24' && $c->packageR == "300"){
  1172. if(strpos($c->ranges, '>') !== false) {
  1173. $pieces = explode(">", $c->ranges);
  1174. if($countD24_2 >= intval($pieces[1])){
  1175. if(strpos($c->comm, 'RM') !== false) {
  1176. $comm24_2 = '+ ' .$c->comm;
  1177. $commV24_2 = '';
  1178. $addRM24_2 = $c->comm;
  1179. }else {
  1180. $comms = explode("RM", $c->comm);
  1181. if(!empty($comms[1])){
  1182. $comm24_2 = 'RM '.$comms[1];
  1183. $commV24_2 = floatval($comms[1]);
  1184. }else {
  1185. if($comms[0] != ''){
  1186. $comm24_2 = $comms[0].'%';
  1187. $commV24_2 = floatval($comms[0])/100;
  1188. }
  1189. }
  1190. }
  1191. }
  1192. }
  1193. }else if($c->contract =='24' && $c->packageR == "500"){
  1194. if(strpos($c->ranges, '>') !== false) {
  1195. $pieces = explode(">", $c->ranges);
  1196. if($countD24_3 >= intval($pieces[1])){
  1197. if(strpos($c->comm, 'RM') !== false) {
  1198. $comm24_3 = '+ ' .$c->comm;
  1199. $commV24_3 = '';
  1200. $addRM24_3 = $c->comm;
  1201. }else {
  1202. $comms = explode("RM", $c->comm);
  1203. if(isset($comms[1])){
  1204. $comm24_3 = 'RM '.$comms[1];
  1205. $commV24_3 = floatval($comms[1]);
  1206. }else {
  1207. if($comms[0] != ''){
  1208. $comm24_3 = $comms[0].'%';
  1209. $commV24_3 = floatval($comms[0])/100;
  1210. }
  1211. }
  1212. }
  1213. }
  1214. }
  1215. }else if($c->contract =='24' && $c->packageR == "1"){
  1216. if(strpos($c->ranges, '>') !== false) {
  1217. $pieces = explode(">", $c->ranges);
  1218. if($countD24_4 >= intval($pieces[1])){
  1219. if(strpos($c->comm, 'RM') !== false) {
  1220. $comm24_4 = '+ ' .$c->comm;
  1221. $commV24_4 = '';
  1222. $addRM24_4 = $c->comm;
  1223. }else {
  1224. $comms = explode("RM", $c->comm);
  1225. if(isset($comms[1])){
  1226. $comm24_4 = 'RM '.$comms[1];
  1227. $commV24_4 = floatval($comms[1]);
  1228. }else {
  1229. if($comms[0] != ''){
  1230. $comm24_4 = $comms[0].'%';
  1231. $commV24_4 = floatval($comms[0])/100;
  1232. }
  1233. }
  1234. }
  1235. }
  1236. }
  1237. }else if($c->contract =='24' && $c->packageR == "10,30,50,100"){
  1238. if(strpos($c->ranges,'-') !== false){
  1239. $pieces = explode("-", $c->ranges);
  1240. if($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])){
  1241. if(strpos($c->comm, 'RM') !== false) {
  1242. $comm24_1 = '+ ' .$c->comm;
  1243. $commV24_1 = '';
  1244. $addRM24_1 = $c->comm;
  1245. }else {
  1246. $comms = explode("RM", $c->comm);
  1247. if(!empty($comms[1])){
  1248. $comm24_1 = 'RM '.$comms[1];
  1249. $commV24_1 = floatval($comms[1]);
  1250. }else {
  1251. if($comms[0] != ''){
  1252. $comm24_1 = $comms[0].'%';
  1253. $commV24_1 = floatval($comms[0])/100;
  1254. }
  1255. }
  1256. }
  1257. }
  1258. }
  1259. if(strpos($c->ranges, '>') !== false) {
  1260. $pieces1 = explode(">", $c->ranges);
  1261. if($countD24_1 >= intval($pieces1[1])){
  1262. if(strpos($c->comm, "RM") === true) {
  1263. $comm24_1 = '+ ' .$c->comm;
  1264. $commV24_1 = '';
  1265. $addRM24_1 = $c->comm;
  1266. }else {
  1267. $comms = explode("RM", $c->comm);
  1268. if(empty($comms[1])){
  1269. $comm24_1 = 'RM '.$comms[1];
  1270. $commV24_1 = floatval($comms[1]);
  1271. }else {
  1272. if($comms[0] != ''){
  1273. $comm24_1 = str_replace ('+ ','',$comms[0]).'%';
  1274. $commV24_1 = floatval($comms[0])/100;
  1275. $addRM24_1 = $comms[1];
  1276. }
  1277. }
  1278. }
  1279. }
  1280. }
  1281. }
  1282. /*** Contract 12 **/
  1283. else if($c->contract =='12' && $c->packageR == "10,30,50,100"){
  1284. if(strpos($c->ranges, '>') !== false) {
  1285. $pieces = explode(">", $c->ranges);
  1286. if($countD12_1 >= intval($pieces[1])){
  1287. if(strpos($c->comm, 'RM') !== false) {
  1288. $comm12_1 = '+ ' .$c->comm;
  1289. $commV12_1 = '';
  1290. $addRM12_1 = $c->comm;
  1291. }else {
  1292. $comms = explode("RM", $c->comm);
  1293. if(isset($comms[1])){
  1294. $comm12_1 = 'RM '.$comms[1];
  1295. $commV12_1 = floatval($comms[1]);
  1296. }else {
  1297. if($comms[0] != ''){
  1298. $comm12_1 = $comms[0].'%';
  1299. $commV12_1 = floatval($comms[0])/100;
  1300. }
  1301. }
  1302. }
  1303. }
  1304. }
  1305. if(strpos($c->ranges,'-') !== false){
  1306. $pieces = explode("-", $c->ranges);
  1307. if($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])){
  1308. if(strpos($c->comm, 'RM') !== false) {
  1309. $comm12_1 = '+ ' .$c->comm;
  1310. $commV12_1 = '';
  1311. $addRM12_1 = $c->comm;
  1312. }else {
  1313. $comms = explode("RM", $c->comm);
  1314. if(isset($comms[1])){
  1315. $comm12_1 = 'RM '.$comms[1];
  1316. $commV12_1 = floatval($comms[1]);
  1317. }else {
  1318. if($comms[0] != ''){
  1319. $comm12_1 = $comms[0].'%';
  1320. $commV12_1 = floatval($comms[0])/100;
  1321. }
  1322. }
  1323. }
  1324. }
  1325. }
  1326. }else if($c->contract =='12' && $c->packageR == "300"){
  1327. if(strpos($c->ranges, '>') !== false) {
  1328. $pieces = explode(">", $c->ranges);
  1329. if($countD12_2 >= intval($pieces[1])){
  1330. if(strpos($c->comm, 'RM') !== false) {
  1331. $comm12_2 = '+ ' .$c->comm;
  1332. $commV12_2 = '';
  1333. $addRM12_2 = $c->comm;
  1334. }else {
  1335. $comms = explode("RM", $c->comm);
  1336. if(isset($comms[1])){
  1337. $comm12_2 = 'RM '.$comms[1];
  1338. $commV12_2 = floatval($comms[1]);
  1339. }else {
  1340. if($comms[0] != ''){
  1341. $comm12_2 = $comms[0].'%';
  1342. $commV12_2 = floatval($comms[0])/100;
  1343. }
  1344. }
  1345. }
  1346. }
  1347. }
  1348. }else if($c->contract =='12' && $c->packageR == "500"){
  1349. if(strpos($c->ranges, '>') !== false) {
  1350. $pieces = explode(">", $c->ranges);
  1351. if($countD12_3 >= intval($pieces[1])){
  1352. if(strpos($c->comm, 'RM') !== false) {
  1353. $comm12_3 = '+ ' .$c->comm;
  1354. $commV12_3 = '';
  1355. $addRM12_3 = $c->comm;
  1356. }else {
  1357. $comms = explode("RM", $c->comm);
  1358. if(isset($comms[1])){
  1359. $comm12_3 = 'RM '.$comms[1];
  1360. $commV12_3 = floatval($comms[1]);
  1361. }else {
  1362. if($comms[0] != ''){
  1363. $comm12_3 = $comms[0].'%';
  1364. $commV12_3 = floatval($comms[0])/100;
  1365. }
  1366. }
  1367. }
  1368. }
  1369. }
  1370. }else if($c->contract =='12' && $c->packageR == "1"){
  1371. if(strpos($c->ranges, '>') !== false) {
  1372. $pieces = explode(">", $c->ranges);
  1373. if($countD12_4 >= intval($pieces[1])){
  1374. if(strpos($c->comm, 'RM') !== false) {
  1375. $comm12_4 = '+ ' .$c->comm;
  1376. $commV12_4 = '';
  1377. $addRM12_4 = $c->comm;
  1378. }else {
  1379. $comms = explode("RM", $c->comm);
  1380. if(isset($comms[1])){
  1381. $comm12_4 = 'RM '.$comms[1];
  1382. $commV12_4 = floatval($comms[1]);
  1383. }else {
  1384. if($comms[0] != ''){
  1385. $comm12_4 = $comms[0].'%';
  1386. $commV12_4 = floatval($comms[0])/100;
  1387. }
  1388. }
  1389. }
  1390. }
  1391. }
  1392. }
  1393. }
  1394. // Category 10,30,50,100
  1395. foreach ($data12_1 as $key => $d) {
  1396. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1397. $address = ''; $name = '';
  1398. if($customer->Form->type_application == 'R'){
  1399. if($customer->street != ''){
  1400. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1401. }else {
  1402. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1403. }
  1404. $name = $customer->name;
  1405. }else if($customer->Form->type_application == 'B'){
  1406. if($customer->unit_no != ''){
  1407. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1408. }else {
  1409. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1410. }
  1411. $name = $customer->company_name;
  1412. }
  1413. $total = '';
  1414. if($commV12_1 == ''){
  1415. $total = $addRM12_1;
  1416. }else {
  1417. $total = number_format($d['retail_price']*$commV12_1,2);
  1418. }
  1419. $final[] = array(
  1420. 'index' => $d['formT'],
  1421. 'contract' => $d['contract'],
  1422. 'wo' => $d['wo'],
  1423. 'activation' => $d['activated_dt'],
  1424. 'name' => $name,
  1425. 'address' => $address,
  1426. 'package' => $d['package'],
  1427. 'retail_price' => 'RM '.$d['retail_price'],
  1428. 'incentives1' => $comm12_1,
  1429. 'incentives2' => $addRM12_1,
  1430. 'total' => 'RM '.$total,
  1431. 'claim' => $c['claim_dt'],
  1432. );
  1433. }
  1434. foreach ($data24_1 as $key => $d) {
  1435. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1436. $address = ''; $name = '';
  1437. if($customer->Form->type_application == 'R'){
  1438. if($customer->street != ''){
  1439. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1440. }else {
  1441. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1442. }
  1443. $name = $customer->name;
  1444. }else if($customer->Form->type_application == 'B'){
  1445. if($customer->unit_no != ''){
  1446. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1447. }else {
  1448. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1449. }
  1450. $name = $customer->company_name;
  1451. }
  1452. $total = '';
  1453. if($commV24_1 == ''){
  1454. $total = $addRM24_1;
  1455. }else {
  1456. $total = number_format(($d['retail_price']*$commV24_1) + floatval($addRM24_1),2);
  1457. }
  1458. $final[] = array(
  1459. 'index' => $d['formT'],
  1460. 'contract' => $d['contract'],
  1461. 'wo' => $d['wo'],
  1462. 'activation' => $d['activated_dt'],
  1463. 'name' => $name,
  1464. 'address' => $address,
  1465. 'package' => $d['package'],
  1466. 'retail_price' => 'RM '.$d['retail_price'],
  1467. 'incentives1' => $comm24_1,
  1468. 'incentives2' => $addRM24_1,
  1469. 'total' => 'RM '.$total,
  1470. 'claim' => $c['claim_dt'],
  1471. );
  1472. }
  1473. // Category 300
  1474. foreach ($data12_2 as $key => $d) {
  1475. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1476. $address = ''; $name = '';
  1477. if($customer->Form->type_application == 'R'){
  1478. if($customer->street != ''){
  1479. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1480. }else {
  1481. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1482. }
  1483. $name = $customer->name;
  1484. }else if($customer->Form->type_application == 'B'){
  1485. if($customer->unit_no != ''){
  1486. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1487. }else {
  1488. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1489. }
  1490. $name = $customer->company_name;
  1491. }
  1492. $total = '';
  1493. if($commV12_2 == ''){
  1494. $total = $addRM12_2;
  1495. }else {
  1496. $total = number_format($d['retail_price']*$commV12_2,2);
  1497. }
  1498. $final[] = array(
  1499. 'index' => $d['formT'],
  1500. 'contract' => $d['contract'],
  1501. 'wo' => $d['wo'],
  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_2,
  1508. 'incentives2' => $addRM12_2,
  1509. 'total' => 'RM '.$total,
  1510. 'claim' => $c['claim_dt'],
  1511. );
  1512. }
  1513. foreach ($data24_2 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_2 == ''){
  1533. $total = $addRM24_2;
  1534. }else {
  1535. $total = number_format($d['retail_price']*$commV24_2,2);
  1536. }
  1537. $final[] = array(
  1538. 'index' => $d['formT'],
  1539. 'contract' => $d['contract'],
  1540. 'wo' => $d['wo'],
  1541. 'activation' => $d['activated_dt'],
  1542. 'name' => $name,
  1543. 'address' => $address,
  1544. 'package' => $d['package'],
  1545. 'retail_price' => 'RM '.$d['retail_price'],
  1546. 'incentives1' => $comm24_2,
  1547. 'incentives2' => $addRM24_2,
  1548. 'total' => 'RM '.$total,
  1549. 'claim' => $c['claim_dt'],
  1550. );
  1551. }
  1552. // Category 500
  1553. foreach ($data12_3 as $key => $d) {
  1554. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1555. $address = ''; $name = $customer->name;
  1556. if($customer->Form->type_application == 'R'){
  1557. if($customer->street != ''){
  1558. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1559. }else {
  1560. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1561. }
  1562. }else if($customer->Form->type_application == 'B'){
  1563. if($customer->unit_no != ''){
  1564. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1565. }else {
  1566. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1567. }
  1568. $name = $customer->company_name;
  1569. }
  1570. $total = '';
  1571. if($commV12_3 == ''){
  1572. $total = $addRM12_3;
  1573. }else {
  1574. $total = number_format($d['retail_price']*$commV12_3,2);
  1575. }
  1576. $final[] = array(
  1577. 'index' => $d['formT'],
  1578. 'contract' => $d['contract'],
  1579. 'wo' => $d['wo'],
  1580. 'activation' => $d['activated_dt'],
  1581. 'name' => $name,
  1582. 'address' => $address,
  1583. 'package' => $d['package'],
  1584. 'retail_price' => 'RM '.$d['retail_price'],
  1585. 'incentives1' => $comm12_3,
  1586. 'incentives2' => $addRM12_3,
  1587. 'total' => 'RM '.$total,
  1588. 'claim' => $c['claim_dt'],
  1589. );
  1590. }
  1591. foreach ($data24_3 as $key => $d) {
  1592. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1593. $address = ''; $name = '';
  1594. if($customer->Form->type_application == 'R'){
  1595. if($customer->street != ''){
  1596. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1597. }else {
  1598. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1599. }
  1600. $name = $customer->name;
  1601. }else if($customer->Form->type_application == 'B'){
  1602. if($customer->unit_no != ''){
  1603. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1604. }else {
  1605. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1606. }
  1607. $name = $customer->company_name;
  1608. }
  1609. $total = '';
  1610. if($commV24_3 == ''){
  1611. $total = $addRM24_3;
  1612. }else {
  1613. $total = number_format($d['retail_price']*$commV24_3,2);
  1614. }
  1615. $final[] = array(
  1616. 'index' => $d['formT'],
  1617. 'contract' => $d['contract'],
  1618. 'wo' => $d['wo'],
  1619. 'activation' => $d['activated_dt'],
  1620. 'name' => $name,
  1621. 'address' => $address,
  1622. 'package' => $d['package'],
  1623. 'retail_price' => 'RM '.$d['retail_price'],
  1624. 'incentives1' => $comm24_3,
  1625. 'incentives2' => $addRM24_3,
  1626. 'total' => 'RM '.$total,
  1627. 'claim' => $c['claim_dt'],
  1628. );
  1629. }
  1630. // Category 1
  1631. foreach ($data12_4 as $key => $d) {
  1632. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1633. $address = ''; $name = '';
  1634. if($customer->Form->type_application == 'R'){
  1635. if($customer->street != ''){
  1636. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1637. }else {
  1638. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1639. }
  1640. $name = $customer->name;
  1641. }else if($customer->Form->type_application == 'B'){
  1642. if($customer->unit_no != ''){
  1643. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1644. }else {
  1645. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1646. }
  1647. $name = $customer->company_name;
  1648. }
  1649. $total = '';
  1650. if($commV12_4 == ''){
  1651. $total = $addRM12_4;
  1652. }else {
  1653. $total = number_format($d['retail_price']*$commV12_4,2);
  1654. }
  1655. $final[] = array(
  1656. 'index' => $d['formT'],
  1657. 'contract' => $d['contract'],
  1658. 'wo' => $d['wo'],
  1659. 'activation' => $d['activated_dt'],
  1660. 'name' => $name,
  1661. 'address' => $address,
  1662. 'package' => $d['package'],
  1663. 'retail_price' => 'RM '.$d['retail_price'],
  1664. 'incentives1' => $comm12_4,
  1665. 'incentives2' => $addRM12_4,
  1666. 'total' => 'RM '.$total,
  1667. 'claim' => $c['claim_dt'],
  1668. );
  1669. }
  1670. foreach ($data24_4 as $key => $d) {
  1671. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1672. $address = ''; $name = '';
  1673. if($customer->Form->type_application == 'R'){
  1674. if($customer->street != ''){
  1675. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1676. }else {
  1677. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1678. }
  1679. $name = $customer->name;
  1680. }else if($customer->Form->type_application == 'B'){
  1681. if($customer->unit_no != ''){
  1682. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1683. }else {
  1684. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1685. }
  1686. $name = $customer->company_name;
  1687. }
  1688. $total = '';
  1689. if($commV24_4 == ''){
  1690. $total = $addRM24_4;
  1691. }else {
  1692. $total = number_format($d['retail_price']*$commV24_4,2);
  1693. }
  1694. $final[] = array(
  1695. 'index' => $d['formT'],
  1696. 'contract' => $d['contract'],
  1697. 'wo' => $d['wo'],
  1698. 'activation' => $d['activated_dt'],
  1699. 'name' => $name,
  1700. 'address' => $address,
  1701. 'package' => $d['package'],
  1702. 'retail_price' => 'RM '.$d['retail_price'],
  1703. 'incentives1' => $comm24_4,
  1704. 'incentives2' => $addRM24_4,
  1705. 'total' => 'RM '.$total,
  1706. 'claim' => $c['claim_dt'],
  1707. );
  1708. }
  1709. }else {
  1710. foreach ($dataCB as $c){
  1711. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1712. $address = ''; $name = '';
  1713. if($customer->Form->type_application == 'R'){
  1714. if($customer->street != ''){
  1715. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1716. }else {
  1717. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1718. }
  1719. $name = $customer->name;
  1720. }else if($customer->Form->type_application == 'B'){
  1721. if($customer->unit_no != ''){
  1722. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1723. }else {
  1724. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1725. }
  1726. $name = $customer->company_name;
  1727. }
  1728. $final[] = array(
  1729. 'index' => $c['formT'],
  1730. 'contract' => $c['contract'],
  1731. 'wo' => $c['wo'],
  1732. 'activation' => $c['activated_dt'],
  1733. 'name' => $name,
  1734. 'address' => $address,
  1735. 'package' => $c['package'],
  1736. 'retail_price' => 'RM '.$c['retail_price'],
  1737. 'incentives1' => '',
  1738. 'incentives2' => '',
  1739. 'total' => '',
  1740. 'claim' => $c['claim_dt'],
  1741. );
  1742. }
  1743. }
  1744. return $final;
  1745. }
  1746. /***
  1747. / Return Claim & Combined Business && Resident
  1748. ***/
  1749. public function getClaimRB($company,$year,$month,$app) {
  1750. $dataR = array(); $dataB = array(); $combineData = array();
  1751. if($month=='null' && $year=='null' && $app=='null'){
  1752. return $this->mClaimListAll($company);
  1753. }else if($year!='null' && $month!='null' && $app=='null'){
  1754. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  1755. $dataDis = $this->returnDataR($company,'2019','12');
  1756. $dataJan = $this->returnDataR($company,'2020','1');
  1757. $count_cyberjaya = array(); $count_jasin = array();
  1758. foreach ($dataDis as $key => $d) {
  1759. if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  1760. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1761. $count_cyberjaya[] = $d;
  1762. }
  1763. if (strpos($d['address'], 'Jasin') !== false) {
  1764. $count_jasin[] = $d;
  1765. }
  1766. }else {
  1767. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1768. $combineData[] = $d;
  1769. }
  1770. }
  1771. }
  1772. foreach ($dataJan as $key => $d) {
  1773. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1774. $count_cyberjaya[] = $d;
  1775. }
  1776. if (strpos($d['address'], 'Jasin') !== false) {
  1777. $count_jasin[] = $d;
  1778. }
  1779. }
  1780. // Store to combineData New Incentives Cyberjaya
  1781. foreach ($count_cyberjaya as $key => $d) {
  1782. if(count($count_cyberjaya) > 50){
  1783. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1784. if($d['contract'] == '12'){
  1785. array_push($combineData, array(
  1786. 'index' => $d['index'],
  1787. 'contract' => $d['contract'],
  1788. 'wo' => $d['wo'],
  1789. 'activation' => $d['activation'],
  1790. 'name' => $d['name'],
  1791. 'address' => $d['address'],
  1792. 'package' => $d['package'],
  1793. 'retail_price' => $d['retail_price'],
  1794. 'incentives1' => $d['incentives1'],
  1795. 'incentives2' => $d['incentives2'],
  1796. 'total' => $d['total'],
  1797. 'claim' => $d['claim'],
  1798. ));
  1799. }else {
  1800. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1801. array_push($combineData, array(
  1802. 'index' => $d['index'],
  1803. 'contract' => $d['contract'],
  1804. 'wo' => $d['wo'],
  1805. 'activation' => $d['activation'],
  1806. 'name' => $d['name'],
  1807. 'address' => $d['address'],
  1808. 'package' => $d['package'],
  1809. 'retail_price' => $d['retail_price'],
  1810. 'incentives1' => '230%',
  1811. 'incentives2' => $d['incentives2'],
  1812. 'total' => 'RM '.$total,
  1813. 'claim' => $d['claim'],
  1814. ));
  1815. }
  1816. }
  1817. }else if(count($count_cyberjaya) < 50){
  1818. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1819. array_push($combineData, array(
  1820. 'index' => $d['index'],
  1821. 'contract' => $d['contract'],
  1822. 'wo' => $d['wo'],
  1823. 'activation' => $d['activation'],
  1824. 'name' => $d['name'],
  1825. 'address' => $d['address'],
  1826. 'package' => $d['package'],
  1827. 'retail_price' => $d['retail_price'],
  1828. 'incentives1' => $d['incentives1'],
  1829. 'incentives2' => $d['incentives2'],
  1830. 'total' => $d['total'],
  1831. 'claim' => $d['claim'],
  1832. ));
  1833. }
  1834. }
  1835. }
  1836. // Store to combineData New Incentives Jasin
  1837. foreach ($count_jasin as $key => $d) {
  1838. if(count($count_jasin) > 10){
  1839. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1840. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1841. array_push($combineData, array(
  1842. 'index' => $d['index'],
  1843. 'contract' => $d['contract'],
  1844. 'wo' => $d['wo'],
  1845. 'activation' => $d['activation'],
  1846. 'name' => $d['name'],
  1847. 'address' => $d['address'],
  1848. 'package' => $d['package'],
  1849. 'retail_price' => $d['retail_price'],
  1850. 'incentives1' => '230%',
  1851. 'incentives2' => $d['incentives2'],
  1852. 'total' => 'RM '.$total,
  1853. 'claim' => $d['claim'],
  1854. ));
  1855. }
  1856. }else if(count($count_jasin) < 10){
  1857. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1858. array_push($combineData, array(
  1859. 'index' => $d['index'],
  1860. 'contract' => $d['contract'],
  1861. 'wo' => $d['wo'],
  1862. 'activation' => $d['activation'],
  1863. 'name' => $d['name'],
  1864. 'address' => $d['address'],
  1865. 'package' => $d['package'],
  1866. 'retail_price' => $d['retail_price'],
  1867. 'incentives1' => $d['incentives1'],
  1868. 'incentives2' => $d['incentives2'],
  1869. 'total' => $d['total'],
  1870. 'claim' => $d['claim'],
  1871. ));
  1872. }
  1873. }
  1874. }
  1875. }else {
  1876. $dataR = $this->returnDataR($company,$year,$month);
  1877. foreach($dataR as $r){
  1878. $combineData[] = $r;
  1879. }
  1880. }
  1881. $dataB = $this->returnDataB($company,$year,$month);
  1882. foreach($dataB as $b){
  1883. $combineData[] = $b;
  1884. }
  1885. $i = 0;
  1886. $nested_data = array();
  1887. if(!empty($combineData)){
  1888. foreach ($combineData as $c){
  1889. $i++;
  1890. array_push($nested_data, array(
  1891. 'index' => $c['index'],
  1892. 'contract' => $c['contract'],
  1893. 'wo' => $c['wo'],
  1894. 'activated_dt' => $c['activation'],
  1895. 'name' => $c['name'],
  1896. 'address' => $c['address'],
  1897. 'package' => $c['package'],
  1898. 'retail_price' => $c['retail_price'],
  1899. 'incentives1' => $c['incentives1'],
  1900. 'incentives2' => $c['incentives2'],
  1901. 'total' => $c['total'],
  1902. 'claimed' => $c['claim'],
  1903. ));
  1904. }
  1905. }
  1906. return \DataTables::of($nested_data)->make(true);
  1907. }else if($year=='null' && $month=='null' && $app!='null'){
  1908. if($app == 'Residential'){
  1909. $dataR = $this->returnDataR($company,$year,$month);
  1910. }else if($app == 'Business'){
  1911. $dataB = $this->returnDataB($company,$year,$month);
  1912. }
  1913. foreach($dataR as $r){
  1914. $combineData[] = $r;
  1915. }
  1916. foreach($dataB as $b){
  1917. $combineData[] = $b;
  1918. }
  1919. $i = 0;
  1920. $nested_data = array();
  1921. if(!empty($combineData)){
  1922. foreach ($combineData as $c){
  1923. $i++;
  1924. array_push($nested_data, array(
  1925. 'index' => $c['index'],
  1926. 'contract' => $c['contract'],
  1927. 'wo' => $c['wo'],
  1928. 'activated_dt' => $c['activation'],
  1929. 'name' => $c['name'],
  1930. 'address' => $c['address'],
  1931. 'package' => $c['package'],
  1932. 'retail_price' => $c['retail_price'],
  1933. 'incentives1' => $c['incentives1'],
  1934. 'incentives2' => $c['incentives2'],
  1935. 'total' => $c['total'],
  1936. 'claimed' => $c['claim'],
  1937. ));
  1938. }
  1939. }
  1940. return \DataTables::of($nested_data)->make(true);
  1941. }else if($year!='null' && $month!='null' && $app!='null'){
  1942. if($app == 'Residential'){
  1943. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  1944. $dataDis = $this->returnDataR($company,'2019','12');
  1945. $dataJan = $this->returnDataR($company,'2020','1');
  1946. $count_cyberjaya = array(); $count_jasin = array();
  1947. foreach ($dataDis as $key => $d) {
  1948. if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  1949. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1950. $count_cyberjaya[] = $d;
  1951. }
  1952. if (strpos($d['address'], 'Jasin') !== false) {
  1953. $count_jasin[] = $d;
  1954. }
  1955. }else {
  1956. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1957. $combineData[] = $d;
  1958. }
  1959. }
  1960. }
  1961. foreach ($dataJan as $key => $d) {
  1962. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1963. $count_cyberjaya[] = $d;
  1964. }
  1965. if (strpos($d['address'], 'Jasin') !== false) {
  1966. $count_jasin[] = $d;
  1967. }
  1968. }
  1969. // Store to combineData New Incentives Cyberjaya
  1970. foreach ($count_cyberjaya as $key => $d) {
  1971. if(count($count_cyberjaya) > 50){
  1972. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1973. if($d['contract'] == '12'){
  1974. array_push($combineData, array(
  1975. 'index' => $d['index'],
  1976. 'contract' => $d['contract'],
  1977. 'wo' => $d['wo'],
  1978. 'activation' => $d['activation'],
  1979. 'name' => $d['name'],
  1980. 'address' => $d['address'],
  1981. 'package' => $d['package'],
  1982. 'retail_price' => $d['retail_price'],
  1983. 'incentives1' => $d['incentives1'],
  1984. 'incentives2' => $d['incentives2'],
  1985. 'total' => $d['total'],
  1986. 'claim' => $d['claim'],
  1987. ));
  1988. }else {
  1989. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1990. array_push($combineData, array(
  1991. 'index' => $d['index'],
  1992. 'contract' => $d['contract'],
  1993. 'wo' => $d['wo'],
  1994. 'activation' => $d['activation'],
  1995. 'name' => $d['name'],
  1996. 'address' => $d['address'],
  1997. 'package' => $d['package'],
  1998. 'retail_price' => $d['retail_price'],
  1999. 'incentives1' => '230%',
  2000. 'incentives2' => $d['incentives2'],
  2001. 'total' => 'RM '.$total,
  2002. 'claim' => $d['claim'],
  2003. ));
  2004. }
  2005. }
  2006. }else if(count($count_cyberjaya) < 50){
  2007. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2008. array_push($combineData, array(
  2009. 'index' => $d['index'],
  2010. 'contract' => $d['contract'],
  2011. 'wo' => $d['wo'],
  2012. 'activation' => $d['activation'],
  2013. 'name' => $d['name'],
  2014. 'address' => $d['address'],
  2015. 'package' => $d['package'],
  2016. 'retail_price' => $d['retail_price'],
  2017. 'incentives1' => $d['incentives1'],
  2018. 'incentives2' => $d['incentives2'],
  2019. 'total' => $d['total'],
  2020. 'claim' => $d['claim'],
  2021. ));
  2022. }
  2023. }
  2024. }
  2025. // Store to combineData New Incentives Jasin
  2026. foreach ($count_jasin as $key => $d) {
  2027. if(count($count_jasin) > 10){
  2028. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2029. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2030. array_push($combineData, array(
  2031. 'index' => $d['index'],
  2032. 'contract' => $d['contract'],
  2033. 'wo' => $d['wo'],
  2034. 'activation' => $d['activation'],
  2035. 'name' => $d['name'],
  2036. 'address' => $d['address'],
  2037. 'package' => $d['package'],
  2038. 'retail_price' => $d['retail_price'],
  2039. 'incentives1' => '230%',
  2040. 'incentives2' => $d['incentives2'],
  2041. 'total' => 'RM '.$total,
  2042. 'claim' => $d['claim'],
  2043. ));
  2044. }
  2045. }else if(count($count_jasin) < 10){
  2046. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2047. array_push($combineData, array(
  2048. 'index' => $d['index'],
  2049. 'contract' => $d['contract'],
  2050. 'wo' => $d['wo'],
  2051. 'activation' => $d['activation'],
  2052. 'name' => $d['name'],
  2053. 'address' => $d['address'],
  2054. 'package' => $d['package'],
  2055. 'retail_price' => $d['retail_price'],
  2056. 'incentives1' => $d['incentives1'],
  2057. 'incentives2' => $d['incentives2'],
  2058. 'total' => $d['total'],
  2059. 'claim' => $d['claim'],
  2060. ));
  2061. }
  2062. }
  2063. }
  2064. }else {
  2065. $dataR = $this->returnDataR($company,$year,$month);
  2066. foreach($dataR as $r){
  2067. $combineData[] = $r;
  2068. }
  2069. }
  2070. }else if($app == 'Business'){
  2071. $dataB = $this->returnDataB($company,$year,$month);
  2072. }
  2073. foreach($dataB as $b){
  2074. $combineData[] = $b;
  2075. }
  2076. $i = 0;
  2077. $nested_data = array();
  2078. if(!empty($combineData)){
  2079. foreach ($combineData as $c){
  2080. $i++;
  2081. array_push($nested_data, array(
  2082. 'index' => $c['index'],
  2083. 'contract' => $c['contract'],
  2084. 'wo' => $c['wo'],
  2085. 'activated_dt' => $c['activation'],
  2086. 'name' => $c['name'],
  2087. 'address' => $c['address'],
  2088. 'package' => $c['package'],
  2089. 'retail_price' => $c['retail_price'],
  2090. 'incentives1' => $c['incentives1'],
  2091. 'incentives2' => $c['incentives2'],
  2092. 'total' => $c['total'],
  2093. 'claimed' => $c['claim'],
  2094. ));
  2095. }
  2096. }
  2097. return \DataTables::of($nested_data)->make(true);
  2098. }
  2099. }
  2100. public function updateAgent(Request $request)
  2101. {
  2102. $user = Staff::where('_id', $request->agent_id)->first();
  2103. $validate = Staff::where('email', $request->email)->first();
  2104. $detail = $user->staffdetail()->first();
  2105. $getpass = $request->get('password');
  2106. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  2107. if(empty($validate))
  2108. {
  2109. $detail->name = $request->get('aname');
  2110. $detail->ic = $request->get('ic');
  2111. $detail->email = $request->get('email');
  2112. $detail->phone = $request->get('phone');
  2113. $detail->company_id = $request->get('vendor');
  2114. $user->email = $request->get('email');
  2115. $user->company_id = $request->get('vendor');
  2116. if(!empty($getpass))
  2117. {
  2118. $validator = Validator::make($request->all(), [
  2119. 'password' => 'min:8|confirmed',
  2120. ]);
  2121. if ($validator->fails())
  2122. {
  2123. return redirect()->back()->withInput()->withErrors($validator);
  2124. }
  2125. $detail->password = $pass;
  2126. $user->password = $pass;
  2127. $detail->save();
  2128. $user->save();
  2129. }
  2130. else
  2131. {
  2132. $detail->save();
  2133. $user->save();
  2134. }
  2135. return redirect()->route('dHome')->with('success_msg', 'message');
  2136. }
  2137. else
  2138. {
  2139. if($user->email == $request->email)
  2140. {
  2141. echo "".$request->get('password');
  2142. $detail->name = $request->get('aname');
  2143. $detail->ic = $request->get('ic');
  2144. $detail->email = $request->get('email');
  2145. $detail->phone = $request->get('phone');
  2146. $detail->company_id = $request->get('vendor');
  2147. $detail->save();
  2148. $user->email = $request->get('email');
  2149. if(!empty($getpass))
  2150. {
  2151. $validator = Validator::make($request->all(), [
  2152. 'password' => 'min:8|confirmed',
  2153. ]);
  2154. if ($validator->fails())
  2155. {
  2156. return redirect()->back()->withInput()->withErrors($validator);
  2157. }
  2158. $detail->password = $pass;
  2159. $user->password = $pass;
  2160. $detail->save();
  2161. $user->save();
  2162. }
  2163. else
  2164. {
  2165. $detail->save();
  2166. $user->save();
  2167. }
  2168. return redirect()->route('dHome')->with('success_msg', 'message');
  2169. }
  2170. else
  2171. {
  2172. echo "email is used";
  2173. return redirect()->back()->withInput()->withErrors('Email already exist!');
  2174. }
  2175. }
  2176. }
  2177. /***
  2178. / Application Form
  2179. ***/
  2180. public function showResidentialForm(){
  2181. $id = Auth::guard('ds')->id();
  2182. $user = Staff::find($id);
  2183. $email = $user->email;
  2184. $userDetails = StaffDetail::where('email',$email)->first();
  2185. return view('dealer.residential-form',compact('userDetails','user'));
  2186. }
  2187. public function showBusinessForm(){
  2188. $id = Auth::guard('ds')->id();
  2189. $user = Staff::find($id);
  2190. $email = $user->email;
  2191. $userDetails = StaffDetail::where('email',$email)->first();
  2192. return view('dealer.business-form',compact('userDetails','user'));
  2193. }
  2194. }