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

DealerController.php 78KB

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