選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DealerController.php 73KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540
  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 {
  426. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  427. $combineData[] = $d;
  428. }
  429. }
  430. }
  431. foreach ($dataJan as $key => $d) {
  432. if (strpos($d['address'], 'Cyberjaya') !== false) {
  433. $count_cyberjaya[] = $d;
  434. }
  435. if (strpos($d['address'], 'Jasin') !== false) {
  436. $count_jasin[] = $d;
  437. }
  438. }
  439. // Store to combineData New Incentives Cyberjaya
  440. foreach ($count_cyberjaya as $key => $d) {
  441. if(count($count_cyberjaya) > 50){
  442. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  443. if($d['contract'] == '12'){
  444. array_push($combineData, array(
  445. 'index' => $d['index'],
  446. 'contract' => $d['contract'],
  447. 'wo' => $d['wo'],
  448. 'activation' => $d['activation'],
  449. 'name' => $d['name'],
  450. 'address' => $d['address'],
  451. 'package' => $d['package'],
  452. 'retail_price' => $d['retail_price'],
  453. 'incentives1' => $d['incentives1'],
  454. 'incentives2' => $d['incentives2'],
  455. 'total' => $d['total'],
  456. 'claim' => $d['claim'],
  457. ));
  458. }else {
  459. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  460. array_push($combineData, array(
  461. 'index' => $d['index'],
  462. 'contract' => $d['contract'],
  463. 'wo' => $d['wo'],
  464. 'activation' => $d['activation'],
  465. 'name' => $d['name'],
  466. 'address' => $d['address'],
  467. 'package' => $d['package'],
  468. 'retail_price' => $d['retail_price'],
  469. 'incentives1' => '230%',
  470. 'incentives2' => $d['incentives2'],
  471. 'total' => 'RM '.$total,
  472. 'claim' => $d['claim'],
  473. ));
  474. }
  475. }
  476. }else if(count($count_cyberjaya) < 50){
  477. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  478. array_push($combineData, array(
  479. 'index' => $d['index'],
  480. 'contract' => $d['contract'],
  481. 'wo' => $d['wo'],
  482. 'activation' => $d['activation'],
  483. 'name' => $d['name'],
  484. 'address' => $d['address'],
  485. 'package' => $d['package'],
  486. 'retail_price' => $d['retail_price'],
  487. 'incentives1' => $d['incentives1'],
  488. 'incentives2' => $d['incentives2'],
  489. 'total' => $d['total'],
  490. 'claim' => $d['claim'],
  491. ));
  492. }
  493. }
  494. }
  495. // Store to combineData New Incentives Jasin
  496. foreach ($count_jasin as $key => $d) {
  497. if(count($count_jasin) > 10){
  498. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  499. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  500. array_push($combineData, array(
  501. 'index' => $d['index'],
  502. 'contract' => $d['contract'],
  503. 'wo' => $d['wo'],
  504. 'activation' => $d['activation'],
  505. 'name' => $d['name'],
  506. 'address' => $d['address'],
  507. 'package' => $d['package'],
  508. 'retail_price' => $d['retail_price'],
  509. 'incentives1' => '230%',
  510. 'incentives2' => $d['incentives2'],
  511. 'total' => 'RM '.$total,
  512. 'claim' => $d['claim'],
  513. ));
  514. }
  515. }else if(count($count_jasin) < 10){
  516. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  517. array_push($combineData, array(
  518. 'index' => $d['index'],
  519. 'contract' => $d['contract'],
  520. 'wo' => $d['wo'],
  521. 'activation' => $d['activation'],
  522. 'name' => $d['name'],
  523. 'address' => $d['address'],
  524. 'package' => $d['package'],
  525. 'retail_price' => $d['retail_price'],
  526. 'incentives1' => $d['incentives1'],
  527. 'incentives2' => $d['incentives2'],
  528. 'total' => $d['total'],
  529. 'claim' => $d['claim'],
  530. ));
  531. }
  532. }
  533. }
  534. }else {
  535. $dataR = $this->returnDataR($company,$year,$month);
  536. foreach($dataR as $r){
  537. $combineData[] = $r;
  538. }
  539. }
  540. $dataB = $this->returnDataB($company,$year,$month);
  541. foreach($dataB as $b){
  542. $combineData[] = $b;
  543. }
  544. $i = 0;
  545. $nested_data = array();
  546. if(!empty($combineData)){
  547. foreach ($combineData as $c){
  548. $i++;
  549. array_push($final, array(
  550. 'index' => $c['index'],
  551. 'contract' => $c['contract'],
  552. 'wo' => $c['wo'],
  553. 'activated_dt' => $c['activation'],
  554. 'name' => $c['name'],
  555. 'address' => $c['address'],
  556. 'package' => $c['package'],
  557. 'retail_price' => $c['retail_price'],
  558. 'incentives1' => $c['incentives1'],
  559. 'incentives2' => $c['incentives2'],
  560. 'total' => $c['total'],
  561. 'claimed' => $c['claim'],
  562. ));
  563. }
  564. }
  565. foreach($final as $f){
  566. $basic_total += floatval(str_replace('RM ', '', $f['total']));
  567. }
  568. // Calculate extra incentves
  569. if($month == '1' && $year == '2020'){
  570. if(count($count_cyberjaya) > 50){
  571. $balance = count($count_cyberjaya) - 50;
  572. $extra += $balance * 50;
  573. }
  574. if(count($count_jasin) > 10){
  575. $balance = count($count_jasin) - 10;
  576. $extra += $balance * 50;
  577. }
  578. }else {
  579. $extra = 0;
  580. }
  581. $totals = $basic_total + $extra;
  582. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  583. $pdf->setPaper('A4', 'landscape');
  584. $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  585. return $pdf->download( $pdfName );
  586. }else if($year!='null' && $month!='null' && $app!='null'){
  587. $count_cyberjaya = array(); $count_jasin = array();
  588. $extra = 0; $basic_total = 0; $totals = 0;
  589. if($app == 'Residential'){
  590. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  591. $dataDis = $this->returnDataR($company,'2019','12');
  592. $dataJan = $this->returnDataR($company,'2020','1');
  593. foreach ($dataDis as $key => $d) {
  594. if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  595. if (strpos($d['address'], 'Cyberjaya') !== false) {
  596. $count_cyberjaya[] = $d;
  597. }
  598. if (strpos($d['address'], 'Jasin') !== false) {
  599. $count_jasin[] = $d;
  600. }
  601. }else {
  602. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  603. $combineData[] = $d;
  604. }
  605. }
  606. }
  607. foreach ($dataJan as $key => $d) {
  608. if (strpos($d['address'], 'Cyberjaya') !== false) {
  609. $count_cyberjaya[] = $d;
  610. }
  611. if (strpos($d['address'], 'Jasin') !== false) {
  612. $count_jasin[] = $d;
  613. }
  614. }
  615. // Store to combineData New Incentives Cyberjaya
  616. foreach ($count_cyberjaya as $key => $d) {
  617. if(count($count_cyberjaya) > 50){
  618. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  619. if($d['contract'] == '12'){
  620. array_push($combineData, array(
  621. 'index' => $d['index'],
  622. 'contract' => $d['contract'],
  623. 'wo' => $d['wo'],
  624. 'activation' => $d['activation'],
  625. 'name' => $d['name'],
  626. 'address' => $d['address'],
  627. 'package' => $d['package'],
  628. 'retail_price' => $d['retail_price'],
  629. 'incentives1' => $d['incentives1'],
  630. 'incentives2' => $d['incentives2'],
  631. 'total' => $d['total'],
  632. 'claim' => $d['claim'],
  633. ));
  634. }else {
  635. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  636. array_push($combineData, array(
  637. 'index' => $d['index'],
  638. 'contract' => $d['contract'],
  639. 'wo' => $d['wo'],
  640. 'activation' => $d['activation'],
  641. 'name' => $d['name'],
  642. 'address' => $d['address'],
  643. 'package' => $d['package'],
  644. 'retail_price' => $d['retail_price'],
  645. 'incentives1' => '230%',
  646. 'incentives2' => $d['incentives2'],
  647. 'total' => 'RM '.$total,
  648. 'claim' => $d['claim'],
  649. ));
  650. }
  651. }
  652. }else if(count($count_cyberjaya) < 50){
  653. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  654. array_push($combineData, array(
  655. 'index' => $d['index'],
  656. 'contract' => $d['contract'],
  657. 'wo' => $d['wo'],
  658. 'activation' => $d['activation'],
  659. 'name' => $d['name'],
  660. 'address' => $d['address'],
  661. 'package' => $d['package'],
  662. 'retail_price' => $d['retail_price'],
  663. 'incentives1' => $d['incentives1'],
  664. 'incentives2' => $d['incentives2'],
  665. 'total' => $d['total'],
  666. 'claim' => $d['claim'],
  667. ));
  668. }
  669. }
  670. }
  671. // Store to combineData New Incentives Jasin
  672. foreach ($count_jasin as $key => $d) {
  673. if(count($count_jasin) > 10){
  674. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  675. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  676. array_push($combineData, array(
  677. 'index' => $d['index'],
  678. 'contract' => $d['contract'],
  679. 'wo' => $d['wo'],
  680. 'activation' => $d['activation'],
  681. 'name' => $d['name'],
  682. 'address' => $d['address'],
  683. 'package' => $d['package'],
  684. 'retail_price' => $d['retail_price'],
  685. 'incentives1' => '230%',
  686. 'incentives2' => $d['incentives2'],
  687. 'total' => 'RM '.$total,
  688. 'claim' => $d['claim'],
  689. ));
  690. }
  691. }else if(count($count_jasin) < 10){
  692. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  693. array_push($combineData, array(
  694. 'index' => $d['index'],
  695. 'contract' => $d['contract'],
  696. 'wo' => $d['wo'],
  697. 'activation' => $d['activation'],
  698. 'name' => $d['name'],
  699. 'address' => $d['address'],
  700. 'package' => $d['package'],
  701. 'retail_price' => $d['retail_price'],
  702. 'incentives1' => $d['incentives1'],
  703. 'incentives2' => $d['incentives2'],
  704. 'total' => $d['total'],
  705. 'claim' => $d['claim'],
  706. ));
  707. }
  708. }
  709. }
  710. }else {
  711. $dataR = $this->returnDataR($company,$year,$month);
  712. foreach($dataR as $r){
  713. $combineData[] = $r;
  714. }
  715. }
  716. }else if($app == 'Business'){
  717. $dataB = $this->returnDataB($company,$year,$month);
  718. }
  719. foreach($dataB as $b){
  720. $combineData[] = $b;
  721. }
  722. $i = 0;
  723. $nested_data = array();
  724. if(!empty($combineData)){
  725. foreach ($combineData as $c){
  726. $i++;
  727. array_push($final, array(
  728. 'index' => $c['index'],
  729. 'contract' => $c['contract'],
  730. 'wo' => $c['wo'],
  731. 'activated_dt' => $c['activation'],
  732. 'name' => $c['name'],
  733. 'address' => $c['address'],
  734. 'package' => $c['package'],
  735. 'retail_price' => $c['retail_price'],
  736. 'incentives1' => $c['incentives1'],
  737. 'incentives2' => $c['incentives2'],
  738. 'total' => $c['total'],
  739. 'claimed' => $c['claim'],
  740. ));
  741. }
  742. }
  743. foreach($final as $f){
  744. $basic_total += floatval(str_replace('RM ', '', $f['total']));
  745. }
  746. //Calculate extra incentves
  747. if($month == '1' && $year == '2020'){
  748. if(count($count_cyberjaya) > 50){
  749. $balance = count($count_cyberjaya) - 50;
  750. $extra += $balance * 50;
  751. }
  752. if(count($count_jasin) > 10){
  753. $balance = count($count_jasin) - 10;
  754. $extra += $balance * 50;
  755. }
  756. }else {
  757. $extra = 0;
  758. }
  759. $totals = $basic_total + $extra;
  760. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  761. $pdf->setPaper('A4', 'landscape');
  762. $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  763. return $pdf->download( $pdfName );
  764. }
  765. }
  766. /***
  767. / Encrypt Password
  768. ***/
  769. public function encryptPassword($action, $string) {
  770. $output = false;
  771. $encrypt_method = "AES-256-CBC";
  772. $secret_key = '28472B4B6250655368566D5970337336';
  773. $secret_iv = md5(md5($string)); //'This is my secret iv';
  774. // hash
  775. $key = hash('sha256', $secret_key);
  776. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  777. if ( $action == 'encrypt' ) {
  778. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  779. $output = base64_encode($output);
  780. } else if( $action == 'decrypt' ) {
  781. $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  782. }
  783. return $output;
  784. }
  785. /***
  786. / Agent Form
  787. ***/
  788. public function showAgentForm(){
  789. $id = Auth::guard('ds')->id();
  790. $user = Staff::with('StaffDetail')->find($id);
  791. return view('dealer.add_agent',compact('user'));
  792. }
  793. /***
  794. / Add Agent
  795. ***/
  796. public function requestAddAgent(Request $request)
  797. {
  798. $validator = Validator::make($request->all(), [
  799. 'password' => 'min:8|confirmed',
  800. ]);
  801. if ($validator->fails()) {
  802. return redirect()->back()->withInput()->withErrors($validator);
  803. }
  804. $user = Staff::where('email', $request->get('email'))->first();
  805. if (empty($user)) {
  806. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  807. $dealerD = new StaffDetail;
  808. $dealerD->name = $request->get('aname');
  809. $dealerD->ic = $request->get('ic');
  810. $dealerD->email = $request->get('email');
  811. $dealerD->phone = $request->get('phone');
  812. $dealerD->company_id = $request->get('company_id');
  813. $dealerD->color = '';
  814. $dealerD->position = 'Sales';
  815. $dealerD->password = $pass;
  816. $dealerD->user_pic = 'assets/avatar/user.png';
  817. // Save Login Dealer
  818. $loginD = new Staff;
  819. $loginD->email = $request->get('email');
  820. $loginD->password = $pass;
  821. $loginD->roles_access = 'Sales';
  822. $loginD->company_id = $request->get('company_id');
  823. $loginD->last_login_at = '';
  824. $loginD->last_login_ip = '';
  825. // $loginData = [
  826. // 'email' => $request->get('email'),
  827. // 'password' => $pass,
  828. // 'roles_access' => 'Sales',
  829. // 'last_login_at' => '',
  830. // 'last_login_ip' => '',
  831. // ];
  832. $company = Company::where('_id',$request->get('company_id'))->first();
  833. $company->staff()->save($loginD);
  834. // $dealer = DealerLaravel::create($loginData);
  835. $loginD->staffdetail()->save($dealerD);
  836. return redirect()->back()->with('success_msg', '<strong>Success!</strong> register <strong>'.$request->get('email').'</strong>');
  837. }
  838. else
  839. {
  840. return redirect()->back()->withInput()->withErrors('Email already exist!');
  841. }
  842. }
  843. public function editAgentDealer($agent_id)
  844. {
  845. $id = Auth::guard('ds')->id();
  846. $user = Staff::find($id);
  847. $email = $user->email;
  848. $userDetails = StaffDetail::where('email',$email)->first();
  849. $person = StaffDetail::where('_id', $agent_id)->first();
  850. return view('dealer.edit_agent', compact('person','userDetails','user'));
  851. }
  852. public function deleteAgent(Request $request)
  853. {
  854. $agent = Staff::where('_id',$request->id)->first();
  855. $agentdetail = $agent->staffdetail()->first();
  856. if(!empty($agentdetail) && !empty($agent))
  857. {
  858. $agent->delete();
  859. $agentdetail->delete();
  860. return 'true';
  861. }
  862. else
  863. {
  864. return 'false';
  865. }
  866. }
  867. //Show claim list by company
  868. public function mClaimListAll($company)
  869. {
  870. $id = Auth::guard('ds')->id();
  871. $user = Staff::with('StaffDetail')->find($id);
  872. $dealer_claimAll = DealerClaim::where('dealer',$company)->orderBy('activated_dt','desc')->get();
  873. $i = 0;
  874. $nested_data = array();
  875. foreach ($dealer_claimAll as $c){
  876. $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first();
  877. $address = '';
  878. if($customer->Form->type_application == 'R'){
  879. if($customer->street != ''){
  880. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  881. }else {
  882. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  883. }
  884. }else if($customer->Form->type_application == 'B'){
  885. if($customer->unit_no != ''){
  886. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  887. }else {
  888. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  889. }
  890. }
  891. $i++;
  892. array_push($nested_data, array(
  893. 'index' => $c->formT,
  894. 'contract' => $c->contract,
  895. 'wo' => $c->wo,
  896. 'activated_dt' => $c->activated_dt,
  897. 'name' => $customer->name,
  898. 'address' => $address,
  899. 'package' => $c->package,
  900. 'retail_price' => 'RM '.$c->retail_price,
  901. 'incentives1' => '',
  902. 'incentives2' => '',
  903. 'total' => '',
  904. 'claimed' => $c->laim_dt,
  905. 'action' => 'null',
  906. ));
  907. }
  908. return \DataTables::of($nested_data)->make(true);
  909. }
  910. // Get Dealer Claim Residential
  911. public function returnDataR($company,$year,$month){
  912. $dataCR = DealerClaim::where('formT','R')->where('dealer',$company)->get();
  913. $final = array();
  914. // Month & Year
  915. $mY = '';
  916. if($year != 'null' && $month != 'null'){
  917. $mY = $month.'/'.$year;
  918. }
  919. if($mY != ''){
  920. $data12 = array(); $data24 = array();
  921. $countD12 = 0; $countD24 = 0;
  922. foreach($dataCR as $dc){
  923. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  924. if($dc->contract == "12"){
  925. $data12[] = $dc;
  926. }else if($dc->contract == "24"){
  927. $data24[] = $dc;
  928. }
  929. }
  930. }
  931. $countD24 = count($data24);
  932. $countD12 = count($data12);
  933. $comm = Commission::where('formT','R')->get();
  934. $commV12 = 0; $commV24 = 0;
  935. $comm12 = ''; $comm24 = '';
  936. foreach($comm as $c){
  937. if($c->contract =='12'){
  938. if(strpos($c->ranges, '>') !== false) {
  939. $pieces = explode(">", $c->ranges);
  940. if($countD12 >= intval($pieces[1])){
  941. $commV12 = floatval($c->comm)/100;
  942. $comm12 = $c->comm.'%';
  943. }
  944. }
  945. if(strpos($c->ranges,'-') !== false){
  946. $pieces = explode("-", $c->ranges);
  947. if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){
  948. $commV12 = floatval($c->comm)/100;
  949. $comm12 = $c->comm.'%';
  950. }
  951. }
  952. }else if($c->contract =='24'){
  953. // Contract => 24
  954. if($countD24 != 0){
  955. if(strpos($c->ranges, '>') !== false) {
  956. $pieces = explode(">", $c->ranges);
  957. if($countD24 > intval($pieces[1])){
  958. $commV24 = floatval($c->comm)/100;
  959. $comm24 = $c->comm.'%';
  960. }
  961. }
  962. if(strpos($c->ranges,'-') !== false){
  963. $pieces = explode("-", $c->ranges);
  964. if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){
  965. $commV24 = floatval($c->comm)/100;
  966. $comm24 = $c->comm.'%';
  967. }
  968. }
  969. }
  970. }
  971. }
  972. foreach ($data12 as $key => $d) {
  973. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  974. $address = ''; $name = '';
  975. if($customer->Form->type_application == 'R'){
  976. if($customer->street != ''){
  977. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  978. }else {
  979. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  980. }
  981. $name = $customer->name;
  982. }else if($customer->Form->type_application == 'B'){
  983. if($customer->unit_no != ''){
  984. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  985. }else {
  986. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  987. }
  988. $name = $customer->company_name;
  989. }
  990. $final[] = array(
  991. 'index' => $d['formT'],
  992. 'contract' => $d['contract'],
  993. 'wo' => $d['wo'],
  994. 'activation' => $d['activated_dt'],
  995. 'name' => $name,
  996. 'address' => $address,
  997. 'package' => $d['package'],
  998. 'retail_price' => 'RM '.$d['retail_price'],
  999. 'incentives1' => $comm12,
  1000. 'incentives2' => '',
  1001. 'total' => 'RM '.number_format($d['retail_price']*$commV12,2),
  1002. 'claim' => $d['claim_dt'],
  1003. );
  1004. }
  1005. foreach ($data24 as $key => $d) {
  1006. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1007. $address = ''; $name = '';
  1008. if($customer->Form->type_application == 'R'){
  1009. if($customer->street != ''){
  1010. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1011. }else {
  1012. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1013. }
  1014. $name = $customer->name;
  1015. }else if($customer->Form->type_application == 'B'){
  1016. if($customer->unit_no != ''){
  1017. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1018. }else {
  1019. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1020. }
  1021. $name = $customer->company_name;
  1022. }
  1023. $final[] = array(
  1024. 'index' => $d['formT'],
  1025. 'contract' => $d['contract'],
  1026. 'wo' => $d['wo'],
  1027. 'activation' => $d['activated_dt'],
  1028. 'name' => $name,
  1029. 'address' => $address,
  1030. 'package' => $d['package'],
  1031. 'retail_price' => 'RM '.$d['retail_price'],
  1032. 'incentives1' => $comm24,
  1033. 'incentives2' => '',
  1034. 'total' => 'RM '.number_format($d['retail_price']*$commV24,2),
  1035. 'claim' => $d['claim_dt'],
  1036. );
  1037. }
  1038. }else {
  1039. foreach ($dataCR as $c){
  1040. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1041. $address = ''; $name = '';
  1042. if($customer->Form->type_application == 'R'){
  1043. if($customer->street != ''){
  1044. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1045. }else {
  1046. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1047. }
  1048. $name = $customer->name;
  1049. }else if($customer->Form->type_application == 'B'){
  1050. if($customer->unit_no != ''){
  1051. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1052. }else {
  1053. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1054. }
  1055. $name = $customer->company_name;
  1056. }
  1057. $final[] = array(
  1058. 'index' => $c['formT'],
  1059. 'contract' => $c['contract'],
  1060. 'wo' => $c['wo'],
  1061. 'activation' => $c['activated_dt'],
  1062. 'name' => $name,
  1063. 'address' => $address,
  1064. 'package' => $c['package'],
  1065. 'retail_price' => 'RM '.$c['retail_price'],
  1066. 'incentives1' => '',
  1067. 'incentives2' => '',
  1068. 'total' => '',
  1069. 'claim' => $c['claim_dt'],
  1070. );
  1071. }
  1072. }
  1073. return $final;
  1074. }
  1075. // Get Claim Business
  1076. public function returnDataB($company,$year,$month){
  1077. $dataCB = DealerClaim::where('formT','B')->where('dealer',$company)->get();
  1078. $final = array();
  1079. // Month & Year
  1080. $mY = '';
  1081. if($year != 'null' && $month != 'null'){
  1082. $mY = $month.'/'.$year;
  1083. }
  1084. if($mY != ''){
  1085. /** Contract 12
  1086. // 1=>10-100 2=>300 3=>500 4=>1
  1087. **/
  1088. $data12_1 = array(); $data12_2 = array();
  1089. $data12_3 = array(); $data12_4 = array();
  1090. $countD12_1 = 0; $countD12_2 = 0;
  1091. $countD12_3 = 0; $countD12_4 = 0;
  1092. /** Contract 24
  1093. // 1=>10-100 2=>300 3=>500 4=>1
  1094. **/
  1095. $data24_1 = array(); $data24_2 = array();
  1096. $data24_3 = array(); $data24_4 = array();
  1097. $countD24_1 = 0; $countD24_2 = 0;
  1098. $countD24_3 = 0; $countD24_4 = 0;
  1099. foreach($dataCB as $dc){
  1100. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  1101. if($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  1102. $data12_1[] = $dc;
  1103. }else if($dc->contract == "12" && $dc->package == "300"){
  1104. $data12_2[] = $dc;
  1105. }else if($dc->contract == "12" && $dc->package == "500"){
  1106. $data12_3[] = $dc;
  1107. }else if($dc->contract == "12" && $dc->package == "1"){
  1108. $data12_4[] = $dc;
  1109. }else if($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  1110. $data24_1[] = $dc;
  1111. }else if($dc->contract == "24" && $dc->package == "300"){
  1112. $data24_2[] = $dc;
  1113. }else if($dc->contract == "24" && $dc->package == "500"){
  1114. $data24_3[] = $dc;
  1115. }else if($dc->contract == "24" && $dc->package == "1"){
  1116. $data24_4[] = $dc;
  1117. }
  1118. }
  1119. }
  1120. $countD12_1 = count($data12_1); $countD12_2 = count($data12_2);
  1121. $countD12_3 = count($data12_3); $countD12_4 = count($data12_4);
  1122. $countD24_1 = count($data24_1); $countD24_2 = count($data24_2);
  1123. $countD24_3 = count($data24_3); $countD24_4 = count($data24_4);
  1124. $comm = Commission::where('formT','B')->get();
  1125. $commV12_1 = 0; $commV12_2 = 0;
  1126. $commV12_3 = 0; $commV12_4 = 0;
  1127. $commV24_1 = 0; $commV24_2 = 0;
  1128. $commV24_3 = 0; $commV24_4 = 0;
  1129. $comm12_1 = ''; $comm12_2 = '';
  1130. $comm12_3 = ''; $comm12_4 = '';
  1131. $comm24_1 = ''; $comm24_2 = '';
  1132. $comm24_3 = ''; $comm24_4 = '';
  1133. $addRM12_1 = ''; $addRM12_2 = '';
  1134. $addRM12_3 = ''; $addRM12_4 = '';
  1135. $addRM24_1 = ''; $addRM24_2 = '';
  1136. $addRM24_3 = ''; $addRM24_4 = '';
  1137. foreach($comm as $c){
  1138. /*** Contract 24 **/
  1139. if($c->contract =='24' && $c->packageR == "300"){
  1140. if(strpos($c->ranges, '>') !== false) {
  1141. $pieces = explode(">", $c->ranges);
  1142. if($countD24_2 >= intval($pieces[1])){
  1143. if(strpos($c->comm, 'RM') !== false) {
  1144. $comm24_2 = '+ ' .$c->comm;
  1145. $commV24_2 = '';
  1146. $addRM24_2 = $c->comm;
  1147. }else {
  1148. $comms = explode("RM", $c->comm);
  1149. if(!empty($comms[1])){
  1150. $comm24_2 = 'RM '.$comms[1];
  1151. $commV24_2 = floatval($comms[1]);
  1152. }else {
  1153. if($comms[0] != ''){
  1154. $comm24_2 = $comms[0].'%';
  1155. $commV24_2 = floatval($comms[0])/100;
  1156. }
  1157. }
  1158. }
  1159. }
  1160. }
  1161. }else if($c->contract =='24' && $c->packageR == "500"){
  1162. if(strpos($c->ranges, '>') !== false) {
  1163. $pieces = explode(">", $c->ranges);
  1164. if($countD24_3 >= intval($pieces[1])){
  1165. if(strpos($c->comm, 'RM') !== false) {
  1166. $comm24_3 = '+ ' .$c->comm;
  1167. $commV24_3 = '';
  1168. $addRM24_3 = $c->comm;
  1169. }else {
  1170. $comms = explode("RM", $c->comm);
  1171. if(isset($comms[1])){
  1172. $comm24_3 = 'RM '.$comms[1];
  1173. $commV24_3 = floatval($comms[1]);
  1174. }else {
  1175. if($comms[0] != ''){
  1176. $comm24_3 = $comms[0].'%';
  1177. $commV24_3 = floatval($comms[0])/100;
  1178. }
  1179. }
  1180. }
  1181. }
  1182. }
  1183. }else if($c->contract =='24' && $c->packageR == "1"){
  1184. if(strpos($c->ranges, '>') !== false) {
  1185. $pieces = explode(">", $c->ranges);
  1186. if($countD24_4 >= intval($pieces[1])){
  1187. if(strpos($c->comm, 'RM') !== false) {
  1188. $comm24_4 = '+ ' .$c->comm;
  1189. $commV24_4 = '';
  1190. $addRM24_4 = $c->comm;
  1191. }else {
  1192. $comms = explode("RM", $c->comm);
  1193. if(isset($comms[1])){
  1194. $comm24_4 = 'RM '.$comms[1];
  1195. $commV24_4 = floatval($comms[1]);
  1196. }else {
  1197. if($comms[0] != ''){
  1198. $comm24_4 = $comms[0].'%';
  1199. $commV24_4 = floatval($comms[0])/100;
  1200. }
  1201. }
  1202. }
  1203. }
  1204. }
  1205. }else if($c->contract =='24' && $c->packageR == "10,30,50,100"){
  1206. if(strpos($c->ranges,'-') !== false){
  1207. $pieces = explode("-", $c->ranges);
  1208. if($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])){
  1209. if(strpos($c->comm, 'RM') !== false) {
  1210. $comm24_1 = '+ ' .$c->comm;
  1211. $commV24_1 = '';
  1212. $addRM24_1 = $c->comm;
  1213. }else {
  1214. $comms = explode("RM", $c->comm);
  1215. if(!empty($comms[1])){
  1216. $comm24_1 = 'RM '.$comms[1];
  1217. $commV24_1 = floatval($comms[1]);
  1218. }else {
  1219. if($comms[0] != ''){
  1220. $comm24_1 = $comms[0].'%';
  1221. $commV24_1 = floatval($comms[0])/100;
  1222. }
  1223. }
  1224. }
  1225. }
  1226. }
  1227. if(strpos($c->ranges, '>') !== false) {
  1228. $pieces1 = explode(">", $c->ranges);
  1229. if($countD24_1 >= intval($pieces1[1])){
  1230. if(strpos($c->comm, "RM") === true) {
  1231. $comm24_1 = '+ ' .$c->comm;
  1232. $commV24_1 = '';
  1233. $addRM24_1 = $c->comm;
  1234. }else {
  1235. $comms = explode("RM", $c->comm);
  1236. if(empty($comms[1])){
  1237. $comm24_1 = 'RM '.$comms[1];
  1238. $commV24_1 = floatval($comms[1]);
  1239. }else {
  1240. if($comms[0] != ''){
  1241. $comm24_1 = str_replace ('+ ','',$comms[0]).'%';
  1242. $commV24_1 = floatval($comms[0])/100;
  1243. $addRM24_1 = $comms[1];
  1244. }
  1245. }
  1246. }
  1247. }
  1248. }
  1249. }
  1250. /*** Contract 12 **/
  1251. else if($c->contract =='12' && $c->packageR == "10,30,50,100"){
  1252. if(strpos($c->ranges, '>') !== false) {
  1253. $pieces = explode(">", $c->ranges);
  1254. if($countD12_1 >= intval($pieces[1])){
  1255. if(strpos($c->comm, 'RM') !== false) {
  1256. $comm12_1 = '+ ' .$c->comm;
  1257. $commV12_1 = '';
  1258. $addRM12_1 = $c->comm;
  1259. }else {
  1260. $comms = explode("RM", $c->comm);
  1261. if(isset($comms[1])){
  1262. $comm12_1 = 'RM '.$comms[1];
  1263. $commV12_1 = floatval($comms[1]);
  1264. }else {
  1265. if($comms[0] != ''){
  1266. $comm12_1 = $comms[0].'%';
  1267. $commV12_1 = floatval($comms[0])/100;
  1268. }
  1269. }
  1270. }
  1271. }
  1272. }
  1273. if(strpos($c->ranges,'-') !== false){
  1274. $pieces = explode("-", $c->ranges);
  1275. if($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])){
  1276. if(strpos($c->comm, 'RM') !== false) {
  1277. $comm12_1 = '+ ' .$c->comm;
  1278. $commV12_1 = '';
  1279. $addRM12_1 = $c->comm;
  1280. }else {
  1281. $comms = explode("RM", $c->comm);
  1282. if(isset($comms[1])){
  1283. $comm12_1 = 'RM '.$comms[1];
  1284. $commV12_1 = floatval($comms[1]);
  1285. }else {
  1286. if($comms[0] != ''){
  1287. $comm12_1 = $comms[0].'%';
  1288. $commV12_1 = floatval($comms[0])/100;
  1289. }
  1290. }
  1291. }
  1292. }
  1293. }
  1294. }else if($c->contract =='12' && $c->packageR == "300"){
  1295. if(strpos($c->ranges, '>') !== false) {
  1296. $pieces = explode(">", $c->ranges);
  1297. if($countD12_2 >= intval($pieces[1])){
  1298. if(strpos($c->comm, 'RM') !== false) {
  1299. $comm12_2 = '+ ' .$c->comm;
  1300. $commV12_2 = '';
  1301. $addRM12_2 = $c->comm;
  1302. }else {
  1303. $comms = explode("RM", $c->comm);
  1304. if(isset($comms[1])){
  1305. $comm12_2 = 'RM '.$comms[1];
  1306. $commV12_2 = floatval($comms[1]);
  1307. }else {
  1308. if($comms[0] != ''){
  1309. $comm12_2 = $comms[0].'%';
  1310. $commV12_2 = floatval($comms[0])/100;
  1311. }
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }else if($c->contract =='12' && $c->packageR == "500"){
  1317. if(strpos($c->ranges, '>') !== false) {
  1318. $pieces = explode(">", $c->ranges);
  1319. if($countD12_3 >= intval($pieces[1])){
  1320. if(strpos($c->comm, 'RM') !== false) {
  1321. $comm12_3 = '+ ' .$c->comm;
  1322. $commV12_3 = '';
  1323. $addRM12_3 = $c->comm;
  1324. }else {
  1325. $comms = explode("RM", $c->comm);
  1326. if(isset($comms[1])){
  1327. $comm12_3 = 'RM '.$comms[1];
  1328. $commV12_3 = floatval($comms[1]);
  1329. }else {
  1330. if($comms[0] != ''){
  1331. $comm12_3 = $comms[0].'%';
  1332. $commV12_3 = floatval($comms[0])/100;
  1333. }
  1334. }
  1335. }
  1336. }
  1337. }
  1338. }else if($c->contract =='12' && $c->packageR == "1"){
  1339. if(strpos($c->ranges, '>') !== false) {
  1340. $pieces = explode(">", $c->ranges);
  1341. if($countD12_4 >= intval($pieces[1])){
  1342. if(strpos($c->comm, 'RM') !== false) {
  1343. $comm12_4 = '+ ' .$c->comm;
  1344. $commV12_4 = '';
  1345. $addRM12_4 = $c->comm;
  1346. }else {
  1347. $comms = explode("RM", $c->comm);
  1348. if(isset($comms[1])){
  1349. $comm12_4 = 'RM '.$comms[1];
  1350. $commV12_4 = floatval($comms[1]);
  1351. }else {
  1352. if($comms[0] != ''){
  1353. $comm12_4 = $comms[0].'%';
  1354. $commV12_4 = floatval($comms[0])/100;
  1355. }
  1356. }
  1357. }
  1358. }
  1359. }
  1360. }
  1361. }
  1362. // Category 10,30,50,100
  1363. foreach ($data12_1 as $key => $d) {
  1364. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1365. $address = ''; $name = '';
  1366. if($customer->Form->type_application == 'R'){
  1367. if($customer->street != ''){
  1368. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1369. }else {
  1370. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1371. }
  1372. $name = $customer->name;
  1373. }else if($customer->Form->type_application == 'B'){
  1374. if($customer->unit_no != ''){
  1375. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1376. }else {
  1377. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1378. }
  1379. $name = $customer->company_name;
  1380. }
  1381. $total = '';
  1382. if($commV12_1 == ''){
  1383. $total = $addRM12_1;
  1384. }else {
  1385. $total = number_format($d['retail_price']*$commV12_1,2);
  1386. }
  1387. $final[] = array(
  1388. 'index' => $d['formT'],
  1389. 'contract' => $d['contract'],
  1390. 'wo' => $d['wo'],
  1391. 'activation' => $d['activated_dt'],
  1392. 'name' => $name,
  1393. 'address' => $address,
  1394. 'package' => $d['package'],
  1395. 'retail_price' => 'RM '.$d['retail_price'],
  1396. 'incentives1' => $comm12_1,
  1397. 'incentives2' => $addRM12_1,
  1398. 'total' => 'RM '.$total,
  1399. 'claim' => $c['claim_dt'],
  1400. );
  1401. }
  1402. foreach ($data24_1 as $key => $d) {
  1403. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1404. $address = ''; $name = '';
  1405. if($customer->Form->type_application == 'R'){
  1406. if($customer->street != ''){
  1407. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1408. }else {
  1409. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1410. }
  1411. $name = $customer->name;
  1412. }else if($customer->Form->type_application == 'B'){
  1413. if($customer->unit_no != ''){
  1414. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1415. }else {
  1416. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1417. }
  1418. $name = $customer->company_name;
  1419. }
  1420. $total = '';
  1421. if($commV24_1 == ''){
  1422. $total = $addRM24_1;
  1423. }else {
  1424. $total = number_format(($d['retail_price']*$commV24_1) + floatval($addRM24_1),2);
  1425. }
  1426. $final[] = array(
  1427. 'index' => $d['formT'],
  1428. 'contract' => $d['contract'],
  1429. 'wo' => $d['wo'],
  1430. 'activation' => $d['activated_dt'],
  1431. 'name' => $name,
  1432. 'address' => $address,
  1433. 'package' => $d['package'],
  1434. 'retail_price' => 'RM '.$d['retail_price'],
  1435. 'incentives1' => $comm24_1,
  1436. 'incentives2' => $addRM24_1,
  1437. 'total' => 'RM '.$total,
  1438. 'claim' => $c['claim_dt'],
  1439. );
  1440. }
  1441. // Category 300
  1442. foreach ($data12_2 as $key => $d) {
  1443. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1444. $address = ''; $name = '';
  1445. if($customer->Form->type_application == 'R'){
  1446. if($customer->street != ''){
  1447. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1448. }else {
  1449. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1450. }
  1451. $name = $customer->name;
  1452. }else if($customer->Form->type_application == 'B'){
  1453. if($customer->unit_no != ''){
  1454. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1455. }else {
  1456. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1457. }
  1458. $name = $customer->company_name;
  1459. }
  1460. $total = '';
  1461. if($commV12_2 == ''){
  1462. $total = $addRM12_2;
  1463. }else {
  1464. $total = number_format($d['retail_price']*$commV12_2,2);
  1465. }
  1466. $final[] = array(
  1467. 'index' => $d['formT'],
  1468. 'contract' => $d['contract'],
  1469. 'wo' => $d['wo'],
  1470. 'activation' => $d['activated_dt'],
  1471. 'name' => $name,
  1472. 'address' => $address,
  1473. 'package' => $d['package'],
  1474. 'retail_price' => 'RM '.$d['retail_price'],
  1475. 'incentives1' => $comm12_2,
  1476. 'incentives2' => $addRM12_2,
  1477. 'total' => 'RM '.$total,
  1478. 'claim' => $c['claim_dt'],
  1479. );
  1480. }
  1481. foreach ($data24_2 as $key => $d) {
  1482. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1483. $address = ''; $name = '';
  1484. if($customer->Form->type_application == 'R'){
  1485. if($customer->street != ''){
  1486. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1487. }else {
  1488. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1489. }
  1490. $name = $customer->name;
  1491. }else if($customer->Form->type_application == 'B'){
  1492. if($customer->unit_no != ''){
  1493. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1494. }else {
  1495. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1496. }
  1497. $name = $customer->company_name;
  1498. }
  1499. $total = '';
  1500. if($commV24_2 == ''){
  1501. $total = $addRM24_2;
  1502. }else {
  1503. $total = number_format($d['retail_price']*$commV24_2,2);
  1504. }
  1505. $final[] = array(
  1506. 'index' => $d['formT'],
  1507. 'contract' => $d['contract'],
  1508. 'wo' => $d['wo'],
  1509. 'activation' => $d['activated_dt'],
  1510. 'name' => $name,
  1511. 'address' => $address,
  1512. 'package' => $d['package'],
  1513. 'retail_price' => 'RM '.$d['retail_price'],
  1514. 'incentives1' => $comm24_2,
  1515. 'incentives2' => $addRM24_2,
  1516. 'total' => 'RM '.$total,
  1517. 'claim' => $c['claim_dt'],
  1518. );
  1519. }
  1520. // Category 500
  1521. foreach ($data12_3 as $key => $d) {
  1522. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1523. $address = ''; $name = $customer->name;
  1524. if($customer->Form->type_application == 'R'){
  1525. if($customer->street != ''){
  1526. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1527. }else {
  1528. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1529. }
  1530. }else if($customer->Form->type_application == 'B'){
  1531. if($customer->unit_no != ''){
  1532. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1533. }else {
  1534. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1535. }
  1536. $name = $customer->company_name;
  1537. }
  1538. $total = '';
  1539. if($commV12_3 == ''){
  1540. $total = $addRM12_3;
  1541. }else {
  1542. $total = number_format($d['retail_price']*$commV12_3,2);
  1543. }
  1544. $final[] = array(
  1545. 'index' => $d['formT'],
  1546. 'contract' => $d['contract'],
  1547. 'wo' => $d['wo'],
  1548. 'activation' => $d['activated_dt'],
  1549. 'name' => $name,
  1550. 'address' => $address,
  1551. 'package' => $d['package'],
  1552. 'retail_price' => 'RM '.$d['retail_price'],
  1553. 'incentives1' => $comm12_3,
  1554. 'incentives2' => $addRM12_3,
  1555. 'total' => 'RM '.$total,
  1556. 'claim' => $c['claim_dt'],
  1557. );
  1558. }
  1559. foreach ($data24_3 as $key => $d) {
  1560. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1561. $address = ''; $name = '';
  1562. if($customer->Form->type_application == 'R'){
  1563. if($customer->street != ''){
  1564. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1565. }else {
  1566. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1567. }
  1568. $name = $customer->name;
  1569. }else if($customer->Form->type_application == 'B'){
  1570. if($customer->unit_no != ''){
  1571. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1572. }else {
  1573. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1574. }
  1575. $name = $customer->company_name;
  1576. }
  1577. $total = '';
  1578. if($commV24_3 == ''){
  1579. $total = $addRM24_3;
  1580. }else {
  1581. $total = number_format($d['retail_price']*$commV24_3,2);
  1582. }
  1583. $final[] = array(
  1584. 'index' => $d['formT'],
  1585. 'contract' => $d['contract'],
  1586. 'wo' => $d['wo'],
  1587. 'activation' => $d['activated_dt'],
  1588. 'name' => $name,
  1589. 'address' => $address,
  1590. 'package' => $d['package'],
  1591. 'retail_price' => 'RM '.$d['retail_price'],
  1592. 'incentives1' => $comm24_3,
  1593. 'incentives2' => $addRM24_3,
  1594. 'total' => 'RM '.$total,
  1595. 'claim' => $c['claim_dt'],
  1596. );
  1597. }
  1598. // Category 1
  1599. foreach ($data12_4 as $key => $d) {
  1600. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1601. $address = ''; $name = '';
  1602. if($customer->Form->type_application == 'R'){
  1603. if($customer->street != ''){
  1604. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1605. }else {
  1606. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1607. }
  1608. $name = $customer->name;
  1609. }else if($customer->Form->type_application == 'B'){
  1610. if($customer->unit_no != ''){
  1611. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1612. }else {
  1613. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1614. }
  1615. $name = $customer->company_name;
  1616. }
  1617. $total = '';
  1618. if($commV12_4 == ''){
  1619. $total = $addRM12_4;
  1620. }else {
  1621. $total = number_format($d['retail_price']*$commV12_4,2);
  1622. }
  1623. $final[] = array(
  1624. 'index' => $d['formT'],
  1625. 'contract' => $d['contract'],
  1626. 'wo' => $d['wo'],
  1627. 'activation' => $d['activated_dt'],
  1628. 'name' => $name,
  1629. 'address' => $address,
  1630. 'package' => $d['package'],
  1631. 'retail_price' => 'RM '.$d['retail_price'],
  1632. 'incentives1' => $comm12_4,
  1633. 'incentives2' => $addRM12_4,
  1634. 'total' => 'RM '.$total,
  1635. 'claim' => $c['claim_dt'],
  1636. );
  1637. }
  1638. foreach ($data24_4 as $key => $d) {
  1639. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1640. $address = ''; $name = '';
  1641. if($customer->Form->type_application == 'R'){
  1642. if($customer->street != ''){
  1643. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1644. }else {
  1645. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1646. }
  1647. $name = $customer->name;
  1648. }else if($customer->Form->type_application == 'B'){
  1649. if($customer->unit_no != ''){
  1650. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1651. }else {
  1652. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1653. }
  1654. $name = $customer->company_name;
  1655. }
  1656. $total = '';
  1657. if($commV24_4 == ''){
  1658. $total = $addRM24_4;
  1659. }else {
  1660. $total = number_format($d['retail_price']*$commV24_4,2);
  1661. }
  1662. $final[] = array(
  1663. 'index' => $d['formT'],
  1664. 'contract' => $d['contract'],
  1665. 'wo' => $d['wo'],
  1666. 'activation' => $d['activated_dt'],
  1667. 'name' => $name,
  1668. 'address' => $address,
  1669. 'package' => $d['package'],
  1670. 'retail_price' => 'RM '.$d['retail_price'],
  1671. 'incentives1' => $comm24_4,
  1672. 'incentives2' => $addRM24_4,
  1673. 'total' => 'RM '.$total,
  1674. 'claim' => $c['claim_dt'],
  1675. );
  1676. }
  1677. }else {
  1678. foreach ($dataCB as $c){
  1679. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1680. $address = ''; $name = '';
  1681. if($customer->Form->type_application == 'R'){
  1682. if($customer->street != ''){
  1683. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1684. }else {
  1685. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1686. }
  1687. $name = $customer->name;
  1688. }else if($customer->Form->type_application == 'B'){
  1689. if($customer->unit_no != ''){
  1690. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1691. }else {
  1692. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1693. }
  1694. $name = $customer->company_name;
  1695. }
  1696. $final[] = array(
  1697. 'index' => $c['formT'],
  1698. 'contract' => $c['contract'],
  1699. 'wo' => $c['wo'],
  1700. 'activation' => $c['activated_dt'],
  1701. 'name' => $name,
  1702. 'address' => $address,
  1703. 'package' => $c['package'],
  1704. 'retail_price' => 'RM '.$c['retail_price'],
  1705. 'incentives1' => '',
  1706. 'incentives2' => '',
  1707. 'total' => '',
  1708. 'claim' => $c['claim_dt'],
  1709. );
  1710. }
  1711. }
  1712. return $final;
  1713. }
  1714. /***
  1715. / Return Claim & Combined Business && Resident
  1716. ***/
  1717. public function getClaimRB($company,$year,$month,$app) {
  1718. $dataR = array(); $dataB = array(); $combineData = array();
  1719. if($month=='null' && $year=='null' && $app=='null'){
  1720. return $this->mClaimListAll($company);
  1721. }else if($year!='null' && $month!='null' && $app=='null'){
  1722. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  1723. $dataDis = $this->returnDataR($company,'2019','12');
  1724. $dataJan = $this->returnDataR($company,'2020','1');
  1725. $count_cyberjaya = array(); $count_jasin = array();
  1726. foreach ($dataDis as $key => $d) {
  1727. if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  1728. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1729. $count_cyberjaya[] = $d;
  1730. }
  1731. if (strpos($d['address'], 'Jasin') !== false) {
  1732. $count_jasin[] = $d;
  1733. }
  1734. }else {
  1735. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1736. $combineData[] = $d;
  1737. }
  1738. }
  1739. }
  1740. foreach ($dataJan as $key => $d) {
  1741. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1742. $count_cyberjaya[] = $d;
  1743. }
  1744. if (strpos($d['address'], 'Jasin') !== false) {
  1745. $count_jasin[] = $d;
  1746. }
  1747. }
  1748. // Store to combineData New Incentives Cyberjaya
  1749. foreach ($count_cyberjaya as $key => $d) {
  1750. if(count($count_cyberjaya) > 50){
  1751. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1752. if($d['contract'] == '12'){
  1753. array_push($combineData, array(
  1754. 'index' => $d['index'],
  1755. 'contract' => $d['contract'],
  1756. 'wo' => $d['wo'],
  1757. 'activation' => $d['activation'],
  1758. 'name' => $d['name'],
  1759. 'address' => $d['address'],
  1760. 'package' => $d['package'],
  1761. 'retail_price' => $d['retail_price'],
  1762. 'incentives1' => $d['incentives1'],
  1763. 'incentives2' => $d['incentives2'],
  1764. 'total' => $d['total'],
  1765. 'claim' => $d['claim'],
  1766. ));
  1767. }else {
  1768. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1769. array_push($combineData, array(
  1770. 'index' => $d['index'],
  1771. 'contract' => $d['contract'],
  1772. 'wo' => $d['wo'],
  1773. 'activation' => $d['activation'],
  1774. 'name' => $d['name'],
  1775. 'address' => $d['address'],
  1776. 'package' => $d['package'],
  1777. 'retail_price' => $d['retail_price'],
  1778. 'incentives1' => '230%',
  1779. 'incentives2' => $d['incentives2'],
  1780. 'total' => 'RM '.$total,
  1781. 'claim' => $d['claim'],
  1782. ));
  1783. }
  1784. }
  1785. }else if(count($count_cyberjaya) < 50){
  1786. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1787. array_push($combineData, array(
  1788. 'index' => $d['index'],
  1789. 'contract' => $d['contract'],
  1790. 'wo' => $d['wo'],
  1791. 'activation' => $d['activation'],
  1792. 'name' => $d['name'],
  1793. 'address' => $d['address'],
  1794. 'package' => $d['package'],
  1795. 'retail_price' => $d['retail_price'],
  1796. 'incentives1' => $d['incentives1'],
  1797. 'incentives2' => $d['incentives2'],
  1798. 'total' => $d['total'],
  1799. 'claim' => $d['claim'],
  1800. ));
  1801. }
  1802. }
  1803. }
  1804. // Store to combineData New Incentives Jasin
  1805. foreach ($count_jasin as $key => $d) {
  1806. if(count($count_jasin) > 10){
  1807. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1808. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1809. array_push($combineData, array(
  1810. 'index' => $d['index'],
  1811. 'contract' => $d['contract'],
  1812. 'wo' => $d['wo'],
  1813. 'activation' => $d['activation'],
  1814. 'name' => $d['name'],
  1815. 'address' => $d['address'],
  1816. 'package' => $d['package'],
  1817. 'retail_price' => $d['retail_price'],
  1818. 'incentives1' => '230%',
  1819. 'incentives2' => $d['incentives2'],
  1820. 'total' => 'RM '.$total,
  1821. 'claim' => $d['claim'],
  1822. ));
  1823. }
  1824. }else if(count($count_jasin) < 10){
  1825. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1826. array_push($combineData, array(
  1827. 'index' => $d['index'],
  1828. 'contract' => $d['contract'],
  1829. 'wo' => $d['wo'],
  1830. 'activation' => $d['activation'],
  1831. 'name' => $d['name'],
  1832. 'address' => $d['address'],
  1833. 'package' => $d['package'],
  1834. 'retail_price' => $d['retail_price'],
  1835. 'incentives1' => $d['incentives1'],
  1836. 'incentives2' => $d['incentives2'],
  1837. 'total' => $d['total'],
  1838. 'claim' => $d['claim'],
  1839. ));
  1840. }
  1841. }
  1842. }
  1843. }else {
  1844. $dataR = $this->returnDataR($company,$year,$month);
  1845. foreach($dataR as $r){
  1846. $combineData[] = $r;
  1847. }
  1848. }
  1849. $dataB = $this->returnDataB($company,$year,$month);
  1850. foreach($dataB as $b){
  1851. $combineData[] = $b;
  1852. }
  1853. $i = 0;
  1854. $nested_data = array();
  1855. if(!empty($combineData)){
  1856. foreach ($combineData as $c){
  1857. $i++;
  1858. array_push($nested_data, array(
  1859. 'index' => $c['index'],
  1860. 'contract' => $c['contract'],
  1861. 'wo' => $c['wo'],
  1862. 'activated_dt' => $c['activation'],
  1863. 'name' => $c['name'],
  1864. 'address' => $c['address'],
  1865. 'package' => $c['package'],
  1866. 'retail_price' => $c['retail_price'],
  1867. 'incentives1' => $c['incentives1'],
  1868. 'incentives2' => $c['incentives2'],
  1869. 'total' => $c['total'],
  1870. 'claimed' => $c['claim'],
  1871. ));
  1872. }
  1873. }
  1874. return \DataTables::of($nested_data)->make(true);
  1875. }else if($year=='null' && $month=='null' && $app!='null'){
  1876. if($app == 'Residential'){
  1877. $dataR = $this->returnDataR($company,$year,$month);
  1878. }else if($app == 'Business'){
  1879. $dataB = $this->returnDataB($company,$year,$month);
  1880. }
  1881. foreach($dataR as $r){
  1882. $combineData[] = $r;
  1883. }
  1884. foreach($dataB as $b){
  1885. $combineData[] = $b;
  1886. }
  1887. $i = 0;
  1888. $nested_data = array();
  1889. if(!empty($combineData)){
  1890. foreach ($combineData as $c){
  1891. $i++;
  1892. array_push($nested_data, array(
  1893. 'index' => $c['index'],
  1894. 'contract' => $c['contract'],
  1895. 'wo' => $c['wo'],
  1896. 'activated_dt' => $c['activation'],
  1897. 'name' => $c['name'],
  1898. 'address' => $c['address'],
  1899. 'package' => $c['package'],
  1900. 'retail_price' => $c['retail_price'],
  1901. 'incentives1' => $c['incentives1'],
  1902. 'incentives2' => $c['incentives2'],
  1903. 'total' => $c['total'],
  1904. 'claimed' => $c['claim'],
  1905. ));
  1906. }
  1907. }
  1908. return \DataTables::of($nested_data)->make(true);
  1909. }else if($year!='null' && $month!='null' && $app!='null'){
  1910. if($app == 'Residential'){
  1911. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  1912. $dataDis = $this->returnDataR($company,'2019','12');
  1913. $dataJan = $this->returnDataR($company,'2020','1');
  1914. $count_cyberjaya = array(); $count_jasin = array();
  1915. foreach ($dataDis as $key => $d) {
  1916. if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  1917. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1918. $count_cyberjaya[] = $d;
  1919. }
  1920. if (strpos($d['address'], 'Jasin') !== false) {
  1921. $count_jasin[] = $d;
  1922. }
  1923. }else {
  1924. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1925. $combineData[] = $d;
  1926. }
  1927. }
  1928. }
  1929. foreach ($dataJan as $key => $d) {
  1930. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1931. $count_cyberjaya[] = $d;
  1932. }
  1933. if (strpos($d['address'], 'Jasin') !== false) {
  1934. $count_jasin[] = $d;
  1935. }
  1936. }
  1937. // Store to combineData New Incentives Cyberjaya
  1938. foreach ($count_cyberjaya as $key => $d) {
  1939. if(count($count_cyberjaya) > 50){
  1940. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1941. if($d['contract'] == '12'){
  1942. array_push($combineData, array(
  1943. 'index' => $d['index'],
  1944. 'contract' => $d['contract'],
  1945. 'wo' => $d['wo'],
  1946. 'activation' => $d['activation'],
  1947. 'name' => $d['name'],
  1948. 'address' => $d['address'],
  1949. 'package' => $d['package'],
  1950. 'retail_price' => $d['retail_price'],
  1951. 'incentives1' => $d['incentives1'],
  1952. 'incentives2' => $d['incentives2'],
  1953. 'total' => $d['total'],
  1954. 'claim' => $d['claim'],
  1955. ));
  1956. }else {
  1957. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1958. array_push($combineData, array(
  1959. 'index' => $d['index'],
  1960. 'contract' => $d['contract'],
  1961. 'wo' => $d['wo'],
  1962. 'activation' => $d['activation'],
  1963. 'name' => $d['name'],
  1964. 'address' => $d['address'],
  1965. 'package' => $d['package'],
  1966. 'retail_price' => $d['retail_price'],
  1967. 'incentives1' => '230%',
  1968. 'incentives2' => $d['incentives2'],
  1969. 'total' => 'RM '.$total,
  1970. 'claim' => $d['claim'],
  1971. ));
  1972. }
  1973. }
  1974. }else if(count($count_cyberjaya) < 50){
  1975. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1976. array_push($combineData, array(
  1977. 'index' => $d['index'],
  1978. 'contract' => $d['contract'],
  1979. 'wo' => $d['wo'],
  1980. 'activation' => $d['activation'],
  1981. 'name' => $d['name'],
  1982. 'address' => $d['address'],
  1983. 'package' => $d['package'],
  1984. 'retail_price' => $d['retail_price'],
  1985. 'incentives1' => $d['incentives1'],
  1986. 'incentives2' => $d['incentives2'],
  1987. 'total' => $d['total'],
  1988. 'claim' => $d['claim'],
  1989. ));
  1990. }
  1991. }
  1992. }
  1993. // Store to combineData New Incentives Jasin
  1994. foreach ($count_jasin as $key => $d) {
  1995. if(count($count_jasin) > 10){
  1996. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1997. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1998. array_push($combineData, array(
  1999. 'index' => $d['index'],
  2000. 'contract' => $d['contract'],
  2001. 'wo' => $d['wo'],
  2002. 'activation' => $d['activation'],
  2003. 'name' => $d['name'],
  2004. 'address' => $d['address'],
  2005. 'package' => $d['package'],
  2006. 'retail_price' => $d['retail_price'],
  2007. 'incentives1' => '230%',
  2008. 'incentives2' => $d['incentives2'],
  2009. 'total' => 'RM '.$total,
  2010. 'claim' => $d['claim'],
  2011. ));
  2012. }
  2013. }else if(count($count_jasin) < 10){
  2014. if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2015. array_push($combineData, array(
  2016. 'index' => $d['index'],
  2017. 'contract' => $d['contract'],
  2018. 'wo' => $d['wo'],
  2019. 'activation' => $d['activation'],
  2020. 'name' => $d['name'],
  2021. 'address' => $d['address'],
  2022. 'package' => $d['package'],
  2023. 'retail_price' => $d['retail_price'],
  2024. 'incentives1' => $d['incentives1'],
  2025. 'incentives2' => $d['incentives2'],
  2026. 'total' => $d['total'],
  2027. 'claim' => $d['claim'],
  2028. ));
  2029. }
  2030. }
  2031. }
  2032. }else {
  2033. $dataR = $this->returnDataR($company,$year,$month);
  2034. foreach($dataR as $r){
  2035. $combineData[] = $r;
  2036. }
  2037. }
  2038. }else if($app == 'Business'){
  2039. $dataB = $this->returnDataB($company,$year,$month);
  2040. }
  2041. foreach($dataB as $b){
  2042. $combineData[] = $b;
  2043. }
  2044. $i = 0;
  2045. $nested_data = array();
  2046. if(!empty($combineData)){
  2047. foreach ($combineData as $c){
  2048. $i++;
  2049. array_push($nested_data, array(
  2050. 'index' => $c['index'],
  2051. 'contract' => $c['contract'],
  2052. 'wo' => $c['wo'],
  2053. 'activated_dt' => $c['activation'],
  2054. 'name' => $c['name'],
  2055. 'address' => $c['address'],
  2056. 'package' => $c['package'],
  2057. 'retail_price' => $c['retail_price'],
  2058. 'incentives1' => $c['incentives1'],
  2059. 'incentives2' => $c['incentives2'],
  2060. 'total' => $c['total'],
  2061. 'claimed' => $c['claim'],
  2062. ));
  2063. }
  2064. }
  2065. return \DataTables::of($nested_data)->make(true);
  2066. }
  2067. }
  2068. public function updateAgent(Request $request)
  2069. {
  2070. $user = Staff::where('_id', $request->agent_id)->first();
  2071. $validate = Staff::where('email', $request->email)->first();
  2072. $detail = $user->staffdetail()->first();
  2073. $getpass = $request->get('password');
  2074. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  2075. if(empty($validate))
  2076. {
  2077. $detail->name = $request->get('aname');
  2078. $detail->ic = $request->get('ic');
  2079. $detail->email = $request->get('email');
  2080. $detail->phone = $request->get('phone');
  2081. $detail->company_id = $request->get('vendor');
  2082. $user->email = $request->get('email');
  2083. $user->company_id = $request->get('vendor');
  2084. if(!empty($getpass))
  2085. {
  2086. $validator = Validator::make($request->all(), [
  2087. 'password' => 'min:8|confirmed',
  2088. ]);
  2089. if ($validator->fails())
  2090. {
  2091. return redirect()->back()->withInput()->withErrors($validator);
  2092. }
  2093. $detail->password = $pass;
  2094. $user->password = $pass;
  2095. $detail->save();
  2096. $user->save();
  2097. }
  2098. else
  2099. {
  2100. $detail->save();
  2101. $user->save();
  2102. }
  2103. return redirect()->route('dHome')->with('success_msg', 'message');
  2104. }
  2105. else
  2106. {
  2107. if($user->email == $request->email)
  2108. {
  2109. echo "".$request->get('password');
  2110. $detail->name = $request->get('aname');
  2111. $detail->ic = $request->get('ic');
  2112. $detail->email = $request->get('email');
  2113. $detail->phone = $request->get('phone');
  2114. $detail->company_id = $request->get('vendor');
  2115. $detail->save();
  2116. $user->email = $request->get('email');
  2117. if(!empty($getpass))
  2118. {
  2119. $validator = Validator::make($request->all(), [
  2120. 'password' => 'min:8|confirmed',
  2121. ]);
  2122. if ($validator->fails())
  2123. {
  2124. return redirect()->back()->withInput()->withErrors($validator);
  2125. }
  2126. $detail->password = $pass;
  2127. $user->password = $pass;
  2128. $detail->save();
  2129. $user->save();
  2130. }
  2131. else
  2132. {
  2133. $detail->save();
  2134. $user->save();
  2135. }
  2136. return redirect()->route('dHome')->with('success_msg', 'message');
  2137. }
  2138. else
  2139. {
  2140. echo "email is used";
  2141. return redirect()->back()->withInput()->withErrors('Email already exist!');
  2142. }
  2143. }
  2144. }
  2145. /***
  2146. / Application Form
  2147. ***/
  2148. public function showResidentialForm(){
  2149. $id = Auth::guard('ds')->id();
  2150. $user = Staff::find($id);
  2151. $email = $user->email;
  2152. $userDetails = StaffDetail::where('email',$email)->first();
  2153. return view('dealer.residential-form',compact('userDetails','user'));
  2154. }
  2155. public function showBusinessForm(){
  2156. $id = Auth::guard('ds')->id();
  2157. $user = Staff::find($id);
  2158. $email = $user->email;
  2159. $userDetails = StaffDetail::where('email',$email)->first();
  2160. return view('dealer.business-form',compact('userDetails','user'));
  2161. }
  2162. }