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

DealerController.php 95KB

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