Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

DealerController.php 91KB

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