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 111KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715
  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. info($c->customer_id);
  743. $address = '';
  744. if($customer->Form->type_application == 'R'){
  745. if($customer->street != ''){
  746. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  747. }else {
  748. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  749. }
  750. }else if($customer->Form->type_application == 'B'){
  751. if($customer->unit_no != ''){
  752. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  753. }else {
  754. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  755. }
  756. }
  757. $i++;
  758. array_push($nested_data, array(
  759. 'index' => $c->formT,
  760. 'contract' => $c->contract,
  761. 'wo' => $c->wo,
  762. 'activated_dt' => $c->activated_dt,
  763. 'name' => $customer->name,
  764. 'address' => $address,
  765. 'package' => $c->package,
  766. 'retail_price' => 'RM '.$c->retail_price,
  767. 'incentives1' => '',
  768. 'incentives2' => '',
  769. 'total' => '',
  770. 'claimed' => $c->laim_dt,
  771. 'action' => 'null',
  772. ));
  773. }
  774. return \DataTables::of($nested_data)->make(true);
  775. }
  776. // Get Dealer Claim Residential
  777. public function returnDataR($company,$year,$month){
  778. $dataCR = DealerClaim::where('formT','R')->where('dealer',$company)->get();
  779. $final = array();
  780. // Month & Year
  781. $mY = '';
  782. if($year != 'null' && $month != 'null'){
  783. $mY = $month.'/'.$year;
  784. }
  785. if($mY != ''){
  786. $data12 = array(); $data24 = array();
  787. $countD12 = 0; $countD24 = 0;
  788. foreach($dataCR as $dc){
  789. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  790. if($dc->contract == "12"){
  791. $data12[] = $dc;
  792. }else if($dc->contract == "24"){
  793. $data24[] = $dc;
  794. }
  795. }
  796. }
  797. $countD24 = count($data24);
  798. $countD12 = count($data12);
  799. $comm = Commission::where('formT','R')->get();
  800. $commV12 = 0; $commV24 = 0;
  801. $comm12 = ''; $comm24 = '';
  802. foreach($comm as $c){
  803. if($c->contract =='12'){
  804. if(strpos($c->ranges, '>') !== false) {
  805. $pieces = explode(">", $c->ranges);
  806. if($countD12 >= intval($pieces[1])){
  807. $commV12 = floatval($c->comm)/100;
  808. $comm12 = $c->comm.'%';
  809. }
  810. }
  811. if(strpos($c->ranges,'-') !== false){
  812. $pieces = explode("-", $c->ranges);
  813. if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){
  814. $commV12 = floatval($c->comm)/100;
  815. $comm12 = $c->comm.'%';
  816. }
  817. }
  818. }else if($c->contract =='24'){
  819. // Contract => 24
  820. if($countD24 != 0){
  821. if(strpos($c->ranges, '>') !== false) {
  822. $pieces = explode(">", $c->ranges);
  823. if($countD24 > intval($pieces[1])){
  824. $commV24 = floatval($c->comm)/100;
  825. $comm24 = $c->comm.'%';
  826. }
  827. }
  828. if(strpos($c->ranges,'-') !== false){
  829. $pieces = explode("-", $c->ranges);
  830. if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){
  831. $commV24 = floatval($c->comm)/100;
  832. $comm24 = $c->comm.'%';
  833. }
  834. }
  835. }
  836. }
  837. }
  838. foreach ($data12 as $key => $d) {
  839. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  840. $address = ''; $name = '';
  841. if($customer->Form->type_application == 'R'){
  842. if($customer->street != ''){
  843. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  844. }else {
  845. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  846. }
  847. $name = $customer->name;
  848. }else if($customer->Form->type_application == 'B'){
  849. if($customer->unit_no != ''){
  850. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  851. }else {
  852. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  853. }
  854. $name = $customer->company_name;
  855. }
  856. $final[] = array(
  857. 'index' => $d['formT'],
  858. 'contract' => $d['contract'],
  859. 'wo' => $d['wo'],
  860. 'submission' => $d['submission_dt'],
  861. 'activation' => $d['activated_dt'],
  862. 'name' => $name,
  863. 'address' => $address,
  864. 'package' => $d['package'],
  865. 'retail_price' => 'RM '.$d['retail_price'],
  866. 'incentives1' => $comm12,
  867. 'incentives2' => '',
  868. 'total' => 'RM '.number_format($d['retail_price']*$commV12,2),
  869. 'claim' => $d['claim_dt'],
  870. );
  871. }
  872. foreach ($data24 as $key => $d) {
  873. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  874. $address = ''; $name = '';
  875. if($customer->Form->type_application == 'R'){
  876. if($customer->street != ''){
  877. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  878. }else {
  879. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  880. }
  881. $name = $customer->name;
  882. }else if($customer->Form->type_application == 'B'){
  883. if($customer->unit_no != ''){
  884. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  885. }else {
  886. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  887. }
  888. $name = $customer->company_name;
  889. }
  890. $final[] = array(
  891. 'index' => $d['formT'],
  892. 'contract' => $d['contract'],
  893. 'wo' => $d['wo'],
  894. 'submission' => $d['submission_dt'],
  895. 'activation' => $d['activated_dt'],
  896. 'name' => $name,
  897. 'address' => $address,
  898. 'package' => $d['package'],
  899. 'retail_price' => 'RM '.$d['retail_price'],
  900. 'incentives1' => $comm24,
  901. 'incentives2' => '',
  902. 'total' => 'RM '.number_format($d['retail_price']*$commV24,2),
  903. 'claim' => $d['claim_dt'],
  904. );
  905. }
  906. }else {
  907. foreach ($dataCR as $c){
  908. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  909. $address = ''; $name = '';
  910. if($customer->Form->type_application == 'R'){
  911. if($customer->street != ''){
  912. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  913. }else {
  914. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  915. }
  916. $name = $customer->name;
  917. }else if($customer->Form->type_application == 'B'){
  918. if($customer->unit_no != ''){
  919. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  920. }else {
  921. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  922. }
  923. $name = $customer->company_name;
  924. }
  925. $final[] = array(
  926. 'index' => $c['formT'],
  927. 'contract' => $c['contract'],
  928. 'wo' => $c['wo'],
  929. 'submission' => $d['submission_dt'],
  930. 'activation' => $c['activated_dt'],
  931. 'name' => $name,
  932. 'address' => $address,
  933. 'package' => $c['package'],
  934. 'retail_price' => 'RM '.$c['retail_price'],
  935. 'incentives1' => '',
  936. 'incentives2' => '',
  937. 'total' => '',
  938. 'claim' => $c['claim_dt'],
  939. );
  940. }
  941. }
  942. return $final;
  943. }
  944. // Get Claim Business
  945. public function returnDataB($company,$year,$month){
  946. $dataCB = DealerClaim::where('formT','B')->where('dealer',$company)->get();
  947. $final = array();
  948. // Month & Year
  949. $mY = '';
  950. if($year != 'null' && $month != 'null'){
  951. $mY = $month.'/'.$year;
  952. }
  953. if($mY != ''){
  954. /** Contract 12
  955. // 1=>10-100 2=>300 3=>500 4=>1
  956. **/
  957. $data12_1 = array(); $data12_2 = array();
  958. $data12_3 = array(); $data12_4 = array();
  959. $countD12_1 = 0; $countD12_2 = 0;
  960. $countD12_3 = 0; $countD12_4 = 0;
  961. /** Contract 24
  962. // 1=>10-100 2=>300 3=>500 4=>1
  963. **/
  964. $data24_1 = array(); $data24_2 = array();
  965. $data24_3 = array(); $data24_4 = array();
  966. $countD24_1 = 0; $countD24_2 = 0;
  967. $countD24_3 = 0; $countD24_4 = 0;
  968. foreach($dataCB as $dc){
  969. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  970. if($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  971. $data12_1[] = $dc;
  972. }else if($dc->contract == "12" && $dc->package == "300"){
  973. $data12_2[] = $dc;
  974. }else if($dc->contract == "12" && $dc->package == "500"){
  975. $data12_3[] = $dc;
  976. }else if($dc->contract == "12" && $dc->package == "1"){
  977. $data12_4[] = $dc;
  978. }else if($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  979. $data24_1[] = $dc;
  980. }else if($dc->contract == "24" && $dc->package == "300"){
  981. $data24_2[] = $dc;
  982. }else if($dc->contract == "24" && $dc->package == "500"){
  983. $data24_3[] = $dc;
  984. }else if($dc->contract == "24" && $dc->package == "1"){
  985. $data24_4[] = $dc;
  986. }
  987. }
  988. }
  989. $countD12_1 = count($data12_1); $countD12_2 = count($data12_2);
  990. $countD12_3 = count($data12_3); $countD12_4 = count($data12_4);
  991. $countD24_1 = count($data24_1); $countD24_2 = count($data24_2);
  992. $countD24_3 = count($data24_3); $countD24_4 = count($data24_4);
  993. $comm = Commission::where('formT','B')->get();
  994. $commV12_1 = 0; $commV12_2 = 0;
  995. $commV12_3 = 0; $commV12_4 = 0;
  996. $commV24_1 = 0; $commV24_2 = 0;
  997. $commV24_3 = 0; $commV24_4 = 0;
  998. $comm12_1 = ''; $comm12_2 = '';
  999. $comm12_3 = ''; $comm12_4 = '';
  1000. $comm24_1 = ''; $comm24_2 = '';
  1001. $comm24_3 = ''; $comm24_4 = '';
  1002. $addRM12_1 = ''; $addRM12_2 = '';
  1003. $addRM12_3 = ''; $addRM12_4 = '';
  1004. $addRM24_1 = ''; $addRM24_2 = '';
  1005. $addRM24_3 = ''; $addRM24_4 = '';
  1006. foreach($comm as $c){
  1007. /*** Contract 24 **/
  1008. if($c->contract =='24' && $c->packageR == "300"){
  1009. if(strpos($c->ranges, '>') !== false) {
  1010. $pieces = explode(">", $c->ranges);
  1011. if($countD24_2 >= intval($pieces[1])){
  1012. if(strpos($c->comm, 'RM') !== false) {
  1013. $comm24_2 = '+ ' .$c->comm;
  1014. $commV24_2 = '';
  1015. $addRM24_2 = $c->comm;
  1016. }else {
  1017. $comms = explode("RM", $c->comm);
  1018. if(!empty($comms[1])){
  1019. $comm24_2 = 'RM '.$comms[1];
  1020. $commV24_2 = floatval($comms[1]);
  1021. }else {
  1022. if($comms[0] != ''){
  1023. $comm24_2 = $comms[0].'%';
  1024. $commV24_2 = floatval($comms[0])/100;
  1025. }
  1026. }
  1027. }
  1028. }
  1029. }
  1030. }else if($c->contract =='24' && $c->packageR == "500"){
  1031. if(strpos($c->ranges, '>') !== false) {
  1032. $pieces = explode(">", $c->ranges);
  1033. if($countD24_3 >= intval($pieces[1])){
  1034. if(strpos($c->comm, 'RM') !== false) {
  1035. $comm24_3 = '+ ' .$c->comm;
  1036. $commV24_3 = '';
  1037. $addRM24_3 = $c->comm;
  1038. }else {
  1039. $comms = explode("RM", $c->comm);
  1040. if(isset($comms[1])){
  1041. $comm24_3 = 'RM '.$comms[1];
  1042. $commV24_3 = floatval($comms[1]);
  1043. }else {
  1044. if($comms[0] != ''){
  1045. $comm24_3 = $comms[0].'%';
  1046. $commV24_3 = floatval($comms[0])/100;
  1047. }
  1048. }
  1049. }
  1050. }
  1051. }
  1052. }else if($c->contract =='24' && $c->packageR == "1"){
  1053. if(strpos($c->ranges, '>') !== false) {
  1054. $pieces = explode(">", $c->ranges);
  1055. if($countD24_4 >= intval($pieces[1])){
  1056. if(strpos($c->comm, 'RM') !== false) {
  1057. $comm24_4 = '+ ' .$c->comm;
  1058. $commV24_4 = '';
  1059. $addRM24_4 = $c->comm;
  1060. }else {
  1061. $comms = explode("RM", $c->comm);
  1062. if(isset($comms[1])){
  1063. $comm24_4 = 'RM '.$comms[1];
  1064. $commV24_4 = floatval($comms[1]);
  1065. }else {
  1066. if($comms[0] != ''){
  1067. $comm24_4 = $comms[0].'%';
  1068. $commV24_4 = floatval($comms[0])/100;
  1069. }
  1070. }
  1071. }
  1072. }
  1073. }
  1074. }else if($c->contract =='24' && $c->packageR == "10,30,50,100"){
  1075. if(strpos($c->ranges,'-') !== false){
  1076. $pieces = explode("-", $c->ranges);
  1077. if($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])){
  1078. if(strpos($c->comm, 'RM') !== false) {
  1079. $comm24_1 = '+ ' .$c->comm;
  1080. $commV24_1 = '';
  1081. $addRM24_1 = $c->comm;
  1082. }else {
  1083. $comms = explode("RM", $c->comm);
  1084. if(!empty($comms[1])){
  1085. $comm24_1 = 'RM '.$comms[1];
  1086. $commV24_1 = floatval($comms[1]);
  1087. }else {
  1088. if($comms[0] != ''){
  1089. $comm24_1 = $comms[0].'%';
  1090. $commV24_1 = floatval($comms[0])/100;
  1091. }
  1092. }
  1093. }
  1094. }
  1095. }
  1096. if(strpos($c->ranges, '>') !== false) {
  1097. $pieces1 = explode(">", $c->ranges);
  1098. if($countD24_1 >= intval($pieces1[1])){
  1099. if(strpos($c->comm, "RM") === true) {
  1100. $comm24_1 = '+ ' .$c->comm;
  1101. $commV24_1 = '';
  1102. $addRM24_1 = $c->comm;
  1103. }else {
  1104. $comms = explode("RM", $c->comm);
  1105. if(empty($comms[1])){
  1106. $comm24_1 = 'RM '.$comms[1];
  1107. $commV24_1 = floatval($comms[1]);
  1108. }else {
  1109. if($comms[0] != ''){
  1110. $comm24_1 = str_replace ('+ ','',$comms[0]).'%';
  1111. $commV24_1 = floatval($comms[0])/100;
  1112. $addRM24_1 = $comms[1];
  1113. }
  1114. }
  1115. }
  1116. }
  1117. }
  1118. }
  1119. /*** Contract 12 **/
  1120. else if($c->contract =='12' && $c->packageR == "10,30,50,100"){
  1121. if(strpos($c->ranges, '>') !== false) {
  1122. $pieces = explode(">", $c->ranges);
  1123. if($countD12_1 >= intval($pieces[1])){
  1124. if(strpos($c->comm, 'RM') !== false) {
  1125. $comm12_1 = '+ ' .$c->comm;
  1126. $commV12_1 = '';
  1127. $addRM12_1 = $c->comm;
  1128. }else {
  1129. $comms = explode("RM", $c->comm);
  1130. if(isset($comms[1])){
  1131. $comm12_1 = 'RM '.$comms[1];
  1132. $commV12_1 = floatval($comms[1]);
  1133. }else {
  1134. if($comms[0] != ''){
  1135. $comm12_1 = $comms[0].'%';
  1136. $commV12_1 = floatval($comms[0])/100;
  1137. }
  1138. }
  1139. }
  1140. }
  1141. }
  1142. if(strpos($c->ranges,'-') !== false){
  1143. $pieces = explode("-", $c->ranges);
  1144. if($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])){
  1145. if(strpos($c->comm, 'RM') !== false) {
  1146. $comm12_1 = '+ ' .$c->comm;
  1147. $commV12_1 = '';
  1148. $addRM12_1 = $c->comm;
  1149. }else {
  1150. $comms = explode("RM", $c->comm);
  1151. if(isset($comms[1])){
  1152. $comm12_1 = 'RM '.$comms[1];
  1153. $commV12_1 = floatval($comms[1]);
  1154. }else {
  1155. if($comms[0] != ''){
  1156. $comm12_1 = $comms[0].'%';
  1157. $commV12_1 = floatval($comms[0])/100;
  1158. }
  1159. }
  1160. }
  1161. }
  1162. }
  1163. }else if($c->contract =='12' && $c->packageR == "300"){
  1164. if(strpos($c->ranges, '>') !== false) {
  1165. $pieces = explode(">", $c->ranges);
  1166. if($countD12_2 >= intval($pieces[1])){
  1167. if(strpos($c->comm, 'RM') !== false) {
  1168. $comm12_2 = '+ ' .$c->comm;
  1169. $commV12_2 = '';
  1170. $addRM12_2 = $c->comm;
  1171. }else {
  1172. $comms = explode("RM", $c->comm);
  1173. if(isset($comms[1])){
  1174. $comm12_2 = 'RM '.$comms[1];
  1175. $commV12_2 = floatval($comms[1]);
  1176. }else {
  1177. if($comms[0] != ''){
  1178. $comm12_2 = $comms[0].'%';
  1179. $commV12_2 = floatval($comms[0])/100;
  1180. }
  1181. }
  1182. }
  1183. }
  1184. }
  1185. }else if($c->contract =='12' && $c->packageR == "500"){
  1186. if(strpos($c->ranges, '>') !== false) {
  1187. $pieces = explode(">", $c->ranges);
  1188. if($countD12_3 >= intval($pieces[1])){
  1189. if(strpos($c->comm, 'RM') !== false) {
  1190. $comm12_3 = '+ ' .$c->comm;
  1191. $commV12_3 = '';
  1192. $addRM12_3 = $c->comm;
  1193. }else {
  1194. $comms = explode("RM", $c->comm);
  1195. if(isset($comms[1])){
  1196. $comm12_3 = 'RM '.$comms[1];
  1197. $commV12_3 = floatval($comms[1]);
  1198. }else {
  1199. if($comms[0] != ''){
  1200. $comm12_3 = $comms[0].'%';
  1201. $commV12_3 = floatval($comms[0])/100;
  1202. }
  1203. }
  1204. }
  1205. }
  1206. }
  1207. }else if($c->contract =='12' && $c->packageR == "1"){
  1208. if(strpos($c->ranges, '>') !== false) {
  1209. $pieces = explode(">", $c->ranges);
  1210. if($countD12_4 >= intval($pieces[1])){
  1211. if(strpos($c->comm, 'RM') !== false) {
  1212. $comm12_4 = '+ ' .$c->comm;
  1213. $commV12_4 = '';
  1214. $addRM12_4 = $c->comm;
  1215. }else {
  1216. $comms = explode("RM", $c->comm);
  1217. if(isset($comms[1])){
  1218. $comm12_4 = 'RM '.$comms[1];
  1219. $commV12_4 = floatval($comms[1]);
  1220. }else {
  1221. if($comms[0] != ''){
  1222. $comm12_4 = $comms[0].'%';
  1223. $commV12_4 = floatval($comms[0])/100;
  1224. }
  1225. }
  1226. }
  1227. }
  1228. }
  1229. }
  1230. }
  1231. // Category 10,30,50,100
  1232. foreach ($data12_1 as $key => $d) {
  1233. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1234. $address = ''; $name = '';
  1235. if($customer->Form->type_application == 'R'){
  1236. if($customer->street != ''){
  1237. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1238. }else {
  1239. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1240. }
  1241. $name = $customer->name;
  1242. }else if($customer->Form->type_application == 'B'){
  1243. if($customer->unit_no != ''){
  1244. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1245. }else {
  1246. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1247. }
  1248. $name = $customer->company_name;
  1249. }
  1250. $total = '';
  1251. if($commV12_1 == ''){
  1252. $total = $addRM12_1;
  1253. }else {
  1254. $total = number_format($d['retail_price']*$commV12_1,2);
  1255. }
  1256. $final[] = array(
  1257. 'index' => $d['formT'],
  1258. 'contract' => $d['contract'],
  1259. 'wo' => $d['wo'],
  1260. 'submission' => $d['submission_dt'],
  1261. 'activation' => $d['activated_dt'],
  1262. 'name' => $name,
  1263. 'address' => $address,
  1264. 'package' => $d['package'],
  1265. 'retail_price' => 'RM '.$d['retail_price'],
  1266. 'incentives1' => $comm12_1,
  1267. 'incentives2' => $addRM12_1,
  1268. 'total' => 'RM '.$total,
  1269. 'claim' => $c['claim_dt'],
  1270. );
  1271. }
  1272. foreach ($data24_1 as $key => $d) {
  1273. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1274. $address = ''; $name = '';
  1275. if($customer->Form->type_application == 'R'){
  1276. if($customer->street != ''){
  1277. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1278. }else {
  1279. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1280. }
  1281. $name = $customer->name;
  1282. }else if($customer->Form->type_application == 'B'){
  1283. if($customer->unit_no != ''){
  1284. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1285. }else {
  1286. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1287. }
  1288. $name = $customer->company_name;
  1289. }
  1290. $total = '';
  1291. if($commV24_1 == ''){
  1292. $total = $addRM24_1;
  1293. }else {
  1294. $total = number_format(($d['retail_price']*$commV24_1) + floatval($addRM24_1),2);
  1295. }
  1296. $final[] = array(
  1297. 'index' => $d['formT'],
  1298. 'contract' => $d['contract'],
  1299. 'wo' => $d['wo'],
  1300. 'submission' => $d['submission_dt'],
  1301. 'activation' => $d['activated_dt'],
  1302. 'name' => $name,
  1303. 'address' => $address,
  1304. 'package' => $d['package'],
  1305. 'retail_price' => 'RM '.$d['retail_price'],
  1306. 'incentives1' => $comm24_1,
  1307. 'incentives2' => $addRM24_1,
  1308. 'total' => 'RM '.$total,
  1309. 'claim' => $c['claim_dt'],
  1310. );
  1311. }
  1312. // Category 300
  1313. foreach ($data12_2 as $key => $d) {
  1314. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1315. $address = ''; $name = '';
  1316. if($customer->Form->type_application == 'R'){
  1317. if($customer->street != ''){
  1318. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1319. }else {
  1320. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1321. }
  1322. $name = $customer->name;
  1323. }else if($customer->Form->type_application == 'B'){
  1324. if($customer->unit_no != ''){
  1325. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1326. }else {
  1327. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1328. }
  1329. $name = $customer->company_name;
  1330. }
  1331. $total = '';
  1332. if($commV12_2 == ''){
  1333. $total = $addRM12_2;
  1334. }else {
  1335. $total = number_format($d['retail_price']*$commV12_2,2);
  1336. }
  1337. $final[] = array(
  1338. 'index' => $d['formT'],
  1339. 'contract' => $d['contract'],
  1340. 'wo' => $d['wo'],
  1341. 'submission' => $d['submission_dt'],
  1342. 'activation' => $d['activated_dt'],
  1343. 'name' => $name,
  1344. 'address' => $address,
  1345. 'package' => $d['package'],
  1346. 'retail_price' => 'RM '.$d['retail_price'],
  1347. 'incentives1' => $comm12_2,
  1348. 'incentives2' => $addRM12_2,
  1349. 'total' => 'RM '.$total,
  1350. 'claim' => $c['claim_dt'],
  1351. );
  1352. }
  1353. foreach ($data24_2 as $key => $d) {
  1354. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1355. $address = ''; $name = '';
  1356. if($customer->Form->type_application == 'R'){
  1357. if($customer->street != ''){
  1358. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1359. }else {
  1360. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1361. }
  1362. $name = $customer->name;
  1363. }else if($customer->Form->type_application == 'B'){
  1364. if($customer->unit_no != ''){
  1365. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1366. }else {
  1367. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1368. }
  1369. $name = $customer->company_name;
  1370. }
  1371. $total = '';
  1372. if($commV24_2 == ''){
  1373. $total = $addRM24_2;
  1374. }else {
  1375. $total = number_format($d['retail_price']*$commV24_2,2);
  1376. }
  1377. $final[] = array(
  1378. 'index' => $d['formT'],
  1379. 'contract' => $d['contract'],
  1380. 'wo' => $d['wo'],
  1381. 'submission' => $d['submission_dt'],
  1382. 'activation' => $d['activated_dt'],
  1383. 'name' => $name,
  1384. 'address' => $address,
  1385. 'package' => $d['package'],
  1386. 'retail_price' => 'RM '.$d['retail_price'],
  1387. 'incentives1' => $comm24_2,
  1388. 'incentives2' => $addRM24_2,
  1389. 'total' => 'RM '.$total,
  1390. 'claim' => $c['claim_dt'],
  1391. );
  1392. }
  1393. // Category 500
  1394. foreach ($data12_3 as $key => $d) {
  1395. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1396. $address = ''; $name = $customer->name;
  1397. if($customer->Form->type_application == 'R'){
  1398. if($customer->street != ''){
  1399. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1400. }else {
  1401. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1402. }
  1403. }else if($customer->Form->type_application == 'B'){
  1404. if($customer->unit_no != ''){
  1405. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1406. }else {
  1407. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1408. }
  1409. $name = $customer->company_name;
  1410. }
  1411. $total = '';
  1412. if($commV12_3 == ''){
  1413. $total = $addRM12_3;
  1414. }else {
  1415. $total = number_format($d['retail_price']*$commV12_3,2);
  1416. }
  1417. $final[] = array(
  1418. 'index' => $d['formT'],
  1419. 'contract' => $d['contract'],
  1420. 'wo' => $d['wo'],
  1421. 'submission' => $d['submission_dt'],
  1422. 'activation' => $d['activated_dt'],
  1423. 'name' => $name,
  1424. 'address' => $address,
  1425. 'package' => $d['package'],
  1426. 'retail_price' => 'RM '.$d['retail_price'],
  1427. 'incentives1' => $comm12_3,
  1428. 'incentives2' => $addRM12_3,
  1429. 'total' => 'RM '.$total,
  1430. 'claim' => $c['claim_dt'],
  1431. );
  1432. }
  1433. foreach ($data24_3 as $key => $d) {
  1434. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1435. $address = ''; $name = '';
  1436. if($customer->Form->type_application == 'R'){
  1437. if($customer->street != ''){
  1438. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1439. }else {
  1440. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1441. }
  1442. $name = $customer->name;
  1443. }else if($customer->Form->type_application == 'B'){
  1444. if($customer->unit_no != ''){
  1445. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1446. }else {
  1447. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1448. }
  1449. $name = $customer->company_name;
  1450. }
  1451. $total = '';
  1452. if($commV24_3 == ''){
  1453. $total = $addRM24_3;
  1454. }else {
  1455. $total = number_format($d['retail_price']*$commV24_3,2);
  1456. }
  1457. $final[] = array(
  1458. 'index' => $d['formT'],
  1459. 'contract' => $d['contract'],
  1460. 'wo' => $d['wo'],
  1461. 'submission' => $d['submission_dt'],
  1462. 'activation' => $d['activated_dt'],
  1463. 'name' => $name,
  1464. 'address' => $address,
  1465. 'package' => $d['package'],
  1466. 'retail_price' => 'RM '.$d['retail_price'],
  1467. 'incentives1' => $comm24_3,
  1468. 'incentives2' => $addRM24_3,
  1469. 'total' => 'RM '.$total,
  1470. 'claim' => $c['claim_dt'],
  1471. );
  1472. }
  1473. // Category 1
  1474. foreach ($data12_4 as $key => $d) {
  1475. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1476. $address = ''; $name = '';
  1477. if($customer->Form->type_application == 'R'){
  1478. if($customer->street != ''){
  1479. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1480. }else {
  1481. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1482. }
  1483. $name = $customer->name;
  1484. }else if($customer->Form->type_application == 'B'){
  1485. if($customer->unit_no != ''){
  1486. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1487. }else {
  1488. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1489. }
  1490. $name = $customer->company_name;
  1491. }
  1492. $total = '';
  1493. if($commV12_4 == ''){
  1494. $total = $addRM12_4;
  1495. }else {
  1496. $total = number_format($d['retail_price']*$commV12_4,2);
  1497. }
  1498. $final[] = array(
  1499. 'index' => $d['formT'],
  1500. 'contract' => $d['contract'],
  1501. 'wo' => $d['wo'],
  1502. 'submission' => $d['submission_dt'],
  1503. 'activation' => $d['activated_dt'],
  1504. 'name' => $name,
  1505. 'address' => $address,
  1506. 'package' => $d['package'],
  1507. 'retail_price' => 'RM '.$d['retail_price'],
  1508. 'incentives1' => $comm12_4,
  1509. 'incentives2' => $addRM12_4,
  1510. 'total' => 'RM '.$total,
  1511. 'claim' => $c['claim_dt'],
  1512. );
  1513. }
  1514. foreach ($data24_4 as $key => $d) {
  1515. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1516. $address = ''; $name = '';
  1517. if($customer->Form->type_application == 'R'){
  1518. if($customer->street != ''){
  1519. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1520. }else {
  1521. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1522. }
  1523. $name = $customer->name;
  1524. }else if($customer->Form->type_application == 'B'){
  1525. if($customer->unit_no != ''){
  1526. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1527. }else {
  1528. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1529. }
  1530. $name = $customer->company_name;
  1531. }
  1532. $total = '';
  1533. if($commV24_4 == ''){
  1534. $total = $addRM24_4;
  1535. }else {
  1536. $total = number_format($d['retail_price']*$commV24_4,2);
  1537. }
  1538. $final[] = array(
  1539. 'index' => $d['formT'],
  1540. 'contract' => $d['contract'],
  1541. 'wo' => $d['wo'],
  1542. 'submission' => $d['submission_dt'],
  1543. 'activation' => $d['activated_dt'],
  1544. 'name' => $name,
  1545. 'address' => $address,
  1546. 'package' => $d['package'],
  1547. 'retail_price' => 'RM '.$d['retail_price'],
  1548. 'incentives1' => $comm24_4,
  1549. 'incentives2' => $addRM24_4,
  1550. 'total' => 'RM '.$total,
  1551. 'claim' => $c['claim_dt'],
  1552. );
  1553. }
  1554. }else {
  1555. foreach ($dataCB as $c){
  1556. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1557. $address = ''; $name = '';
  1558. if($customer->Form->type_application == 'R'){
  1559. if($customer->street != ''){
  1560. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1561. }else {
  1562. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1563. }
  1564. $name = $customer->name;
  1565. }else if($customer->Form->type_application == 'B'){
  1566. if($customer->unit_no != ''){
  1567. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1568. }else {
  1569. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1570. }
  1571. $name = $customer->company_name;
  1572. }
  1573. $final[] = array(
  1574. 'index' => $c['formT'],
  1575. 'contract' => $c['contract'],
  1576. 'wo' => $c['wo'],
  1577. 'submission' => $d['submission_dt'],
  1578. 'activation' => $c['activated_dt'],
  1579. 'name' => $name,
  1580. 'address' => $address,
  1581. 'package' => $c['package'],
  1582. 'retail_price' => 'RM '.$c['retail_price'],
  1583. 'incentives1' => '',
  1584. 'incentives2' => '',
  1585. 'total' => '',
  1586. 'claim' => $c['claim_dt'],
  1587. );
  1588. }
  1589. }
  1590. return $final;
  1591. }
  1592. /***
  1593. / Return Claim & Combined Business && Resident
  1594. ***/
  1595. public function getClaimRB($company,$year,$month,$app) {
  1596. $dataR = array(); $dataB = array(); $combineData = array();
  1597. if($month=='null' && $year=='null' && $app=='null'){
  1598. return $this->mClaimListAll($company);
  1599. }else if($year!='null' && $month!='null' && $app=='null'){
  1600. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1601. $q->with('Form');
  1602. }],'Staff')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1603. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  1604. foreach ($dataClaim as $key => $d) {
  1605. if(date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  1606. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'){
  1607. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1608. $count_cyberjaya[] = $d;
  1609. }
  1610. if (strpos($d['address'], 'Jasin') !== false) {
  1611. $count_jasin[] = $d;
  1612. }
  1613. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1614. $count_ayerKeroh[] = $d;
  1615. }
  1616. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1617. $count_alorGajah[] = $d;
  1618. }
  1619. if (strpos($d['address'], 'Menglembu') !== false) {
  1620. $count_menglembu[] = $d;
  1621. }
  1622. if (strpos($d['address'], 'Ipoh') !== false) {
  1623. $count_ipoh[] = $d;
  1624. }
  1625. }
  1626. }
  1627. }else if($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')){
  1628. foreach ($dataClaim as $key => $d) {
  1629. if(date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  1630. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'){
  1631. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1632. $count_cyberjaya[] = $d;
  1633. }
  1634. if (strpos($d['address'], 'Jasin') !== false) {
  1635. $count_jasin[] = $d;
  1636. }
  1637. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1638. $count_ayerKeroh[] = $d;
  1639. }
  1640. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1641. $count_alorGajah[] = $d;
  1642. }
  1643. if (strpos($d['address'], 'Menglembu') !== false) {
  1644. $count_menglembu[] = $d;
  1645. }
  1646. if (strpos($d['address'], 'Ipoh') !== false) {
  1647. $count_ipoh[] = $d;
  1648. }
  1649. }
  1650. }
  1651. }
  1652. }else if($year=='null' && $month=='null' && $app!='null'){
  1653. // if($app == 'Residential'){
  1654. // $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1655. // $q->with('Form');
  1656. // }],'Staff')->where('formT', 'R')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1657. // }else if($app == 'Business'){
  1658. // $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1659. // $q->with('Form');
  1660. // }],'Staff')->where('formT', 'B')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1661. // }
  1662. }else if($year!='null' && $month!='null' && $app!='null'){
  1663. if($app == 'Residential'){
  1664. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1665. $q->with('Form');
  1666. }],'Staff')->where('formT', 'R')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1667. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  1668. foreach ($dataClaim as $key => $d) {
  1669. if(date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  1670. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'){
  1671. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1672. $count_cyberjaya[] = $d;
  1673. }
  1674. if (strpos($d['address'], 'Jasin') !== false) {
  1675. $count_jasin[] = $d;
  1676. }
  1677. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1678. $count_ayerKeroh[] = $d;
  1679. }
  1680. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1681. $count_alorGajah[] = $d;
  1682. }
  1683. if (strpos($d['address'], 'Menglembu') !== false) {
  1684. $count_menglembu[] = $d;
  1685. }
  1686. if (strpos($d['address'], 'Ipoh') !== false) {
  1687. $count_ipoh[] = $d;
  1688. }
  1689. }
  1690. }
  1691. }else if($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')){
  1692. foreach ($dataClaim as $key => $d) {
  1693. if(date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  1694. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'){
  1695. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1696. $count_cyberjaya[] = $d;
  1697. }
  1698. if (strpos($d['address'], 'Jasin') !== false) {
  1699. $count_jasin[] = $d;
  1700. }
  1701. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1702. $count_ayerKeroh[] = $d;
  1703. }
  1704. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1705. $count_alorGajah[] = $d;
  1706. }
  1707. if (strpos($d['address'], 'Menglembu') !== false) {
  1708. $count_menglembu[] = $d;
  1709. }
  1710. if (strpos($d['address'], 'Ipoh') !== false) {
  1711. $count_ipoh[] = $d;
  1712. }
  1713. }
  1714. }
  1715. }
  1716. }else if($app == 'Business'){
  1717. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1718. $q->with('Form');
  1719. }],'Staff')->where('formT', 'B')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1720. }
  1721. }
  1722. $i = 0;
  1723. $nested_data = array();
  1724. if(!empty($dataClaim)){
  1725. foreach ($dataClaim as $c){
  1726. $address = ''; $name = '';
  1727. info($c->Subscriber->_id);
  1728. if($c->Subscriber->Form->type_application == 'R'){
  1729. if($c->Subscriber->street != ''){
  1730. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  1731. }else {
  1732. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  1733. }
  1734. $name = $c->Subscriber->name;
  1735. }else if($c->Subscriber->Form->type_application == 'B'){
  1736. if($c->Subscriber->unit_no != ''){
  1737. $address = $c->Subscriber->unit_no. ', '.$c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  1738. }else {
  1739. $address = $c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  1740. }
  1741. $name = $c->Subscriber->company_name;
  1742. }
  1743. $i++;
  1744. array_push($nested_data, array(
  1745. 'index' => $c->formT,
  1746. 'contract' => $c->contract,
  1747. 'wo' => $c->wo,
  1748. 'activated_dt' => $c->activated_dt,
  1749. 'name' => $name,
  1750. 'address' => $address,
  1751. 'package' => $c->package,
  1752. 'retail_price' => 'RM '.$c->retail_price,
  1753. 'incentives1' => $c->incentives1,
  1754. 'incentives2' => $c->incentives2,
  1755. 'total' => 'RM '.$c->total_claim,
  1756. 'claimed' => $c->claim_dt,
  1757. ));
  1758. }
  1759. }
  1760. return \DataTables::of($nested_data)->make(true);
  1761. }
  1762. public function updateAgent(Request $request)
  1763. {
  1764. $user = Staff::where('_id', $request->agent_id)->first();
  1765. $validate = Staff::where('email', $request->email)->first();
  1766. $detail = $user->staffdetail()->first();
  1767. $getpass = $request->get('password');
  1768. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  1769. if(empty($validate))
  1770. {
  1771. $detail->name = $request->get('aname');
  1772. $detail->ic = $request->get('ic');
  1773. $detail->email = $request->get('email');
  1774. $detail->phone = $request->get('phone');
  1775. $detail->company_id = $request->get('vendor');
  1776. $user->email = $request->get('email');
  1777. $user->company_id = $request->get('vendor');
  1778. if(!empty($getpass))
  1779. {
  1780. $validator = Validator::make($request->all(), [
  1781. 'password' => 'min:8|confirmed',
  1782. ]);
  1783. if ($validator->fails())
  1784. {
  1785. return redirect()->back()->withInput()->withErrors($validator);
  1786. }
  1787. $detail->password = $pass;
  1788. $user->password = $pass;
  1789. $detail->save();
  1790. $user->save();
  1791. }
  1792. else
  1793. {
  1794. $detail->save();
  1795. $user->save();
  1796. }
  1797. return redirect()->route('dHome')->with('success_msg', 'message');
  1798. }
  1799. else
  1800. {
  1801. if($user->email == $request->email)
  1802. {
  1803. echo "".$request->get('password');
  1804. $detail->name = $request->get('aname');
  1805. $detail->ic = $request->get('ic');
  1806. $detail->email = $request->get('email');
  1807. $detail->phone = $request->get('phone');
  1808. $detail->company_id = $request->get('vendor');
  1809. $detail->save();
  1810. $user->email = $request->get('email');
  1811. if(!empty($getpass))
  1812. {
  1813. $validator = Validator::make($request->all(), [
  1814. 'password' => 'min:8|confirmed',
  1815. ]);
  1816. if ($validator->fails())
  1817. {
  1818. return redirect()->back()->withInput()->withErrors($validator);
  1819. }
  1820. $detail->password = $pass;
  1821. $user->password = $pass;
  1822. $detail->save();
  1823. $user->save();
  1824. }
  1825. else
  1826. {
  1827. $detail->save();
  1828. $user->save();
  1829. }
  1830. return redirect()->route('dHome')->with('success_msg', 'message');
  1831. }
  1832. else
  1833. {
  1834. echo "email is used";
  1835. return redirect()->back()->withInput()->withErrors('Email already exist!');
  1836. }
  1837. }
  1838. }
  1839. /***
  1840. / Application Form
  1841. ***/
  1842. public function showResidentialForm(){
  1843. $id = Auth::guard('ds')->id();
  1844. $user = Staff::find($id);
  1845. $email = $user->email;
  1846. $userDetails = StaffDetail::where('email',$email)->first();
  1847. return view('dealer.residential-form',compact('userDetails','user'));
  1848. }
  1849. public function showBusinessForm(){
  1850. $id = Auth::guard('ds')->id();
  1851. $user = Staff::find($id);
  1852. $email = $user->email;
  1853. $userDetails = StaffDetail::where('email',$email)->first();
  1854. return view('dealer.business-form',compact('userDetails','user'));
  1855. }
  1856. public function exportDealerJson(Request $request) {
  1857. $final = array();
  1858. $id = Auth::guard('ds')->id();
  1859. // $user = Staff::with('StaffDetail')->find($id);
  1860. // $com = Company::where('_id',$user->StaffDetail->company_id)->first();
  1861. $dataR = array(); $dataB = array(); $combineData = array();
  1862. $extra = 0;
  1863. $year = $request->year;
  1864. $month = $request->month;
  1865. $app = $request->app;
  1866. $company = $request->company;
  1867. if($year!='null' && $month!='null' && $app=='null'){
  1868. $count_cyberjaya = array(); $count_jasin = array(); $count_ayerKeroh = array(); $count_alorGajah = array(); $count_menglembu = array(); $count_ipoh = array();
  1869. $extra = 0; $basic_total = 0; $countAugustR = array(); $countAugustB = array();
  1870. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  1871. // $dataDis = $this->returnDataR($company,'2019','12');
  1872. // $dataJan = $this->returnDataR($company,'2020','1');
  1873. if($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')){
  1874. $dataApril = $this->returnDataR($company,'2020','4');
  1875. $dataMay = $this->returnDataR($company,'2020','5');
  1876. $dataJune = $this->returnDataR($company,'2020','6');
  1877. $dataJuly = $this->returnDataR($company,'2020','7');
  1878. foreach ($dataApril as $key => $d) {
  1879. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  1880. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  1881. // $count_cyberjaya[] = $d;
  1882. // }
  1883. // if (strpos($d['address'], 'Jasin') !== false) {
  1884. // $count_jasin[] = $d;
  1885. // }
  1886. // }
  1887. // // else
  1888. if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020'){
  1889. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1890. $count_cyberjaya[] = $d;
  1891. }
  1892. if (strpos($d['address'], 'Jasin') !== false) {
  1893. $count_jasin[] = $d;
  1894. }
  1895. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1896. $count_ayerKeroh[] = $d;
  1897. }
  1898. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1899. $count_alorGajah[] = $d;
  1900. }
  1901. if (strpos($d['address'], 'Menglembu') !== false) {
  1902. $count_menglembu[] = $d;
  1903. }
  1904. if (strpos($d['address'], 'Ipoh') !== false) {
  1905. $count_ipoh[] = $d;
  1906. }
  1907. }
  1908. else {
  1909. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1910. $combineData[] = $d;
  1911. }
  1912. }
  1913. }
  1914. foreach ($dataMay as $key => $d) {
  1915. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1916. $count_cyberjaya[] = $d;
  1917. }
  1918. if (strpos($d['address'], 'Jasin') !== false) {
  1919. $count_jasin[] = $d;
  1920. }
  1921. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1922. $count_ayerKeroh[] = $d;
  1923. }
  1924. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1925. $count_alorGajah[] = $d;
  1926. }
  1927. if (strpos($d['address'], 'Menglembu') !== false) {
  1928. $count_menglembu[] = $d;
  1929. }
  1930. if (strpos($d['address'], 'Ipoh') !== false) {
  1931. $count_ipoh[] = $d;
  1932. }
  1933. }
  1934. foreach ($dataJune as $key => $d) {
  1935. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1936. $count_cyberjaya[] = $d;
  1937. }
  1938. if (strpos($d['address'], 'Jasin') !== false) {
  1939. $count_jasin[] = $d;
  1940. }
  1941. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1942. $count_ayerKeroh[] = $d;
  1943. }
  1944. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1945. $count_alorGajah[] = $d;
  1946. }
  1947. if (strpos($d['address'], 'Menglembu') !== false) {
  1948. $count_menglembu[] = $d;
  1949. }
  1950. if (strpos($d['address'], 'Ipoh') !== false) {
  1951. $count_ipoh[] = $d;
  1952. }
  1953. }
  1954. foreach ($dataJuly as $key => $d) {
  1955. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1956. $count_cyberjaya[] = $d;
  1957. }
  1958. if (strpos($d['address'], 'Jasin') !== false) {
  1959. $count_jasin[] = $d;
  1960. }
  1961. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1962. $count_ayerKeroh[] = $d;
  1963. }
  1964. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1965. $count_alorGajah[] = $d;
  1966. }
  1967. if (strpos($d['address'], 'Menglembu') !== false) {
  1968. $count_menglembu[] = $d;
  1969. }
  1970. if (strpos($d['address'], 'Ipoh') !== false) {
  1971. $count_ipoh[] = $d;
  1972. }
  1973. }
  1974. // Store to combineData New Incentives Cyberjaya
  1975. foreach ($count_cyberjaya as $key => $d) {
  1976. if(count($count_cyberjaya) > 50){
  1977. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1978. if($d['contract'] == '12'){
  1979. array_push($combineData, array(
  1980. 'index' => $d['index'],
  1981. 'contract' => $d['contract'],
  1982. 'wo' => $d['wo'],
  1983. 'activation' => $d['activation'],
  1984. 'name' => $d['name'],
  1985. 'address' => $d['address'],
  1986. 'package' => $d['package'],
  1987. 'retail_price' => $d['retail_price'],
  1988. 'incentives1' => $d['incentives1'],
  1989. 'incentives2' => $d['incentives2'],
  1990. 'total' => $d['total'],
  1991. 'claim' => $d['claim'],
  1992. ));
  1993. }else {
  1994. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1995. array_push($combineData, array(
  1996. 'index' => $d['index'],
  1997. 'contract' => $d['contract'],
  1998. 'wo' => $d['wo'],
  1999. 'activation' => $d['activation'],
  2000. 'name' => $d['name'],
  2001. 'address' => $d['address'],
  2002. 'package' => $d['package'],
  2003. 'retail_price' => $d['retail_price'],
  2004. 'incentives1' => '230%',
  2005. 'incentives2' => $d['incentives2'],
  2006. 'total' => 'RM '.$total,
  2007. 'claim' => $d['claim'],
  2008. ));
  2009. }
  2010. }
  2011. }else if(count($count_cyberjaya) < 50){
  2012. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2013. array_push($combineData, array(
  2014. 'index' => $d['index'],
  2015. 'contract' => $d['contract'],
  2016. 'wo' => $d['wo'],
  2017. 'activation' => $d['activation'],
  2018. 'name' => $d['name'],
  2019. 'address' => $d['address'],
  2020. 'package' => $d['package'],
  2021. 'retail_price' => $d['retail_price'],
  2022. 'incentives1' => $d['incentives1'],
  2023. 'incentives2' => $d['incentives2'],
  2024. 'total' => $d['total'],
  2025. 'claim' => $d['claim'],
  2026. ));
  2027. }
  2028. }
  2029. }
  2030. // Store to combineData New Incentives Menglembu
  2031. foreach ($count_menglembu as $key => $d) {
  2032. if(count($count_menglembu) > 50){
  2033. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2034. if($d['contract'] == '12'){
  2035. array_push($combineData, array(
  2036. 'index' => $d['index'],
  2037. 'contract' => $d['contract'],
  2038. 'wo' => $d['wo'],
  2039. 'activation' => $d['activation'],
  2040. 'name' => $d['name'],
  2041. 'address' => $d['address'],
  2042. 'package' => $d['package'],
  2043. 'retail_price' => $d['retail_price'],
  2044. 'incentives1' => $d['incentives1'],
  2045. 'incentives2' => $d['incentives2'],
  2046. 'total' => $d['total'],
  2047. 'claim' => $d['claim'],
  2048. ));
  2049. }else {
  2050. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2051. array_push($combineData, array(
  2052. 'index' => $d['index'],
  2053. 'contract' => $d['contract'],
  2054. 'wo' => $d['wo'],
  2055. 'activation' => $d['activation'],
  2056. 'name' => $d['name'],
  2057. 'address' => $d['address'],
  2058. 'package' => $d['package'],
  2059. 'retail_price' => $d['retail_price'],
  2060. 'incentives1' => '230%',
  2061. 'incentives2' => $d['incentives2'],
  2062. 'total' => 'RM '.$total,
  2063. 'claim' => $d['claim'],
  2064. ));
  2065. }
  2066. }
  2067. }else if(count($count_menglembu) < 50){
  2068. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2069. array_push($combineData, array(
  2070. 'index' => $d['index'],
  2071. 'contract' => $d['contract'],
  2072. 'wo' => $d['wo'],
  2073. 'activation' => $d['activation'],
  2074. 'name' => $d['name'],
  2075. 'address' => $d['address'],
  2076. 'package' => $d['package'],
  2077. 'retail_price' => $d['retail_price'],
  2078. 'incentives1' => $d['incentives1'],
  2079. 'incentives2' => $d['incentives2'],
  2080. 'total' => $d['total'],
  2081. 'claim' => $d['claim'],
  2082. ));
  2083. }
  2084. }
  2085. }
  2086. // Store to combineData New Incentives Ipoh
  2087. foreach ($count_ipoh as $key => $d) {
  2088. if(count($count_ipoh) > 50){
  2089. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2090. if($d['contract'] == '12'){
  2091. array_push($combineData, array(
  2092. 'index' => $d['index'],
  2093. 'contract' => $d['contract'],
  2094. 'wo' => $d['wo'],
  2095. 'activation' => $d['activation'],
  2096. 'name' => $d['name'],
  2097. 'address' => $d['address'],
  2098. 'package' => $d['package'],
  2099. 'retail_price' => $d['retail_price'],
  2100. 'incentives1' => $d['incentives1'],
  2101. 'incentives2' => $d['incentives2'],
  2102. 'total' => $d['total'],
  2103. 'claim' => $d['claim'],
  2104. ));
  2105. }else {
  2106. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2107. array_push($combineData, array(
  2108. 'index' => $d['index'],
  2109. 'contract' => $d['contract'],
  2110. 'wo' => $d['wo'],
  2111. 'activation' => $d['activation'],
  2112. 'name' => $d['name'],
  2113. 'address' => $d['address'],
  2114. 'package' => $d['package'],
  2115. 'retail_price' => $d['retail_price'],
  2116. 'incentives1' => '230%',
  2117. 'incentives2' => $d['incentives2'],
  2118. 'total' => 'RM '.$total,
  2119. 'claim' => $d['claim'],
  2120. ));
  2121. }
  2122. }
  2123. }else if(count($count_ipoh) < 50){
  2124. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2125. array_push($combineData, array(
  2126. 'index' => $d['index'],
  2127. 'contract' => $d['contract'],
  2128. 'wo' => $d['wo'],
  2129. 'activation' => $d['activation'],
  2130. 'name' => $d['name'],
  2131. 'address' => $d['address'],
  2132. 'package' => $d['package'],
  2133. 'retail_price' => $d['retail_price'],
  2134. 'incentives1' => $d['incentives1'],
  2135. 'incentives2' => $d['incentives2'],
  2136. 'total' => $d['total'],
  2137. 'claim' => $d['claim'],
  2138. ));
  2139. }
  2140. }
  2141. }
  2142. // Store to combineData New Incentives Ayer Keroh
  2143. foreach ($count_ayerKeroh as $key => $d) {
  2144. if(count($count_ayerKeroh) > 50){
  2145. if($d['contract'] == '12'){
  2146. array_push($combineData, array(
  2147. 'index' => $d['index'],
  2148. 'contract' => $d['contract'],
  2149. 'wo' => $d['wo'],
  2150. 'activation' => $d['activation'],
  2151. 'name' => $d['name'],
  2152. 'address' => $d['address'],
  2153. 'package' => $d['package'],
  2154. 'retail_price' => $d['retail_price'],
  2155. 'incentives1' => $d['incentives1'],
  2156. 'incentives2' => $d['incentives2'],
  2157. 'total' => $d['total'],
  2158. 'claim' => $d['claim'],
  2159. ));
  2160. }else {
  2161. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2162. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2163. array_push($combineData, array(
  2164. 'index' => $d['index'],
  2165. 'contract' => $d['contract'],
  2166. 'wo' => $d['wo'],
  2167. 'activation' => $d['activation'],
  2168. 'name' => $d['name'],
  2169. 'address' => $d['address'],
  2170. 'package' => $d['package'],
  2171. 'retail_price' => $d['retail_price'],
  2172. 'incentives1' => '230%',
  2173. 'incentives2' => $d['incentives2'],
  2174. 'total' => 'RM '.$total,
  2175. 'claim' => $d['claim'],
  2176. ));
  2177. }
  2178. }
  2179. }else if(count($count_ayerKeroh) < 50){
  2180. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2181. array_push($combineData, array(
  2182. 'index' => $d['index'],
  2183. 'contract' => $d['contract'],
  2184. 'wo' => $d['wo'],
  2185. 'activation' => $d['activation'],
  2186. 'name' => $d['name'],
  2187. 'address' => $d['address'],
  2188. 'package' => $d['package'],
  2189. 'retail_price' => $d['retail_price'],
  2190. 'incentives1' => $d['incentives1'],
  2191. 'incentives2' => $d['incentives2'],
  2192. 'total' => $d['total'],
  2193. 'claim' => $d['claim'],
  2194. ));
  2195. }
  2196. }
  2197. }
  2198. // Store to combineData New Incentives Alor Gajah
  2199. foreach ($count_alorGajah as $key => $d) {
  2200. if(count($count_alorGajah) > 50){
  2201. if($d['contract'] == '12'){
  2202. array_push($combineData, array(
  2203. 'index' => $d['index'],
  2204. 'contract' => $d['contract'],
  2205. 'wo' => $d['wo'],
  2206. 'activation' => $d['activation'],
  2207. 'name' => $d['name'],
  2208. 'address' => $d['address'],
  2209. 'package' => $d['package'],
  2210. 'retail_price' => $d['retail_price'],
  2211. 'incentives1' => $d['incentives1'],
  2212. 'incentives2' => $d['incentives2'],
  2213. 'total' => $d['total'],
  2214. 'claim' => $d['claim'],
  2215. ));
  2216. }else {
  2217. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2218. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2219. array_push($combineData, array(
  2220. 'index' => $d['index'],
  2221. 'contract' => $d['contract'],
  2222. 'wo' => $d['wo'],
  2223. 'activation' => $d['activation'],
  2224. 'name' => $d['name'],
  2225. 'address' => $d['address'],
  2226. 'package' => $d['package'],
  2227. 'retail_price' => $d['retail_price'],
  2228. 'incentives1' => '230%',
  2229. 'incentives2' => $d['incentives2'],
  2230. 'total' => 'RM '.$total,
  2231. 'claim' => $d['claim'],
  2232. ));
  2233. }
  2234. }
  2235. }else if(count($count_alorGajah) < 50){
  2236. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2237. array_push($combineData, array(
  2238. 'index' => $d['index'],
  2239. 'contract' => $d['contract'],
  2240. 'wo' => $d['wo'],
  2241. 'activation' => $d['activation'],
  2242. 'name' => $d['name'],
  2243. 'address' => $d['address'],
  2244. 'package' => $d['package'],
  2245. 'retail_price' => $d['retail_price'],
  2246. 'incentives1' => $d['incentives1'],
  2247. 'incentives2' => $d['incentives2'],
  2248. 'total' => $d['total'],
  2249. 'claim' => $d['claim'],
  2250. ));
  2251. }
  2252. }
  2253. }
  2254. // Store to combineData New Incentives Jasin
  2255. foreach ($count_jasin as $key => $d) {
  2256. if(count($count_jasin) > 20){
  2257. if($d['contract'] == '12'){
  2258. array_push($combineData, array(
  2259. 'index' => $d['index'],
  2260. 'contract' => $d['contract'],
  2261. 'wo' => $d['wo'],
  2262. 'activation' => $d['activation'],
  2263. 'name' => $d['name'],
  2264. 'address' => $d['address'],
  2265. 'package' => $d['package'],
  2266. 'retail_price' => $d['retail_price'],
  2267. 'incentives1' => $d['incentives1'],
  2268. 'incentives2' => $d['incentives2'],
  2269. 'total' => $d['total'],
  2270. 'claim' => $d['claim'],
  2271. ));
  2272. }else {
  2273. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2274. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2275. array_push($combineData, array(
  2276. 'index' => $d['index'],
  2277. 'contract' => $d['contract'],
  2278. 'wo' => $d['wo'],
  2279. 'activation' => $d['activation'],
  2280. 'name' => $d['name'],
  2281. 'address' => $d['address'],
  2282. 'package' => $d['package'],
  2283. 'retail_price' => $d['retail_price'],
  2284. 'incentives1' => '230%',
  2285. 'incentives2' => $d['incentives2'],
  2286. 'total' => 'RM '.$total,
  2287. 'claim' => $d['claim'],
  2288. ));
  2289. }
  2290. }
  2291. }else if(count($count_jasin) < 20){
  2292. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2293. array_push($combineData, array(
  2294. 'index' => $d['index'],
  2295. 'contract' => $d['contract'],
  2296. 'wo' => $d['wo'],
  2297. 'activation' => $d['activation'],
  2298. 'name' => $d['name'],
  2299. 'address' => $d['address'],
  2300. 'package' => $d['package'],
  2301. 'retail_price' => $d['retail_price'],
  2302. 'incentives1' => $d['incentives1'],
  2303. 'incentives2' => $d['incentives2'],
  2304. 'total' => $d['total'],
  2305. 'claim' => $d['claim'],
  2306. ));
  2307. }
  2308. }
  2309. }
  2310. }else if($year == '2020' && ($month == '08' || $month == '09' || $month == '10')){
  2311. $dataAugustR = $this->returnDataR($company,'2020','8');
  2312. $dataAugustB = $this->returnDataB($company,'2020','8');
  2313. $dataSeptemberR = $this->returnDataR($company,'2020','9');
  2314. $dataSeptemberB = $this->returnDataB($company,'2020','9');
  2315. $dataOctoberR = $this->returnDataR($company,'2020','10');
  2316. $dataOctoberB = $this->returnDataB($company,'2020','10');
  2317. foreach ($dataAugustR as $key => $d) {
  2318. if((date('m/Y', strtotime($d['submission'])) == $month.'/'.$year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020'){
  2319. if($d['contract'] == '24'){
  2320. if ($d['package']== 50){
  2321. $d['retail_price'] = 69;
  2322. } elseif ($d['package']== 100){
  2323. $d['retail_price'] = 89;
  2324. } elseif ($d['package']== 500){
  2325. $d['retail_price'] = 129;
  2326. }
  2327. }
  2328. if(date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020'){
  2329. $countAugustR[] = $d;
  2330. }
  2331. }else {
  2332. if(date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020'){
  2333. $countAugustR[] = $d;
  2334. }else {
  2335. $combineData[] = $d;
  2336. }
  2337. }
  2338. }
  2339. // Store to combineData New Incentive August
  2340. foreach ($countAugustR as $key => $d) {
  2341. if(count($dataAugustR) >= 50){
  2342. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2343. if($d['contract'] == '12'){
  2344. array_push($combineData, array(
  2345. 'index' => $d['index'],
  2346. 'contract' => $d['contract'],
  2347. 'wo' => $d['wo'],
  2348. 'activation' => $d['activation'],
  2349. 'name' => $d['name'],
  2350. 'address' => $d['address'],
  2351. 'package' => $d['package'],
  2352. 'retail_price' => $d['retail_price'],
  2353. 'incentives1' => $d['incentives1'],
  2354. 'incentives2' => $d['incentives2'],
  2355. 'total' => $d['total'],
  2356. 'claim' => $d['claim'],
  2357. ));
  2358. }else {
  2359. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5 + 50, 2);
  2360. array_push($combineData, array(
  2361. 'index' => $d['index'],
  2362. 'contract' => $d['contract'],
  2363. 'wo' => $d['wo'],
  2364. 'activation' => $d['activation'],
  2365. 'name' => $d['name'],
  2366. 'address' => $d['address'],
  2367. 'package' => $d['package'],
  2368. 'retail_price' => $d['retail_price'],
  2369. 'incentives1' => '250% + RM50',
  2370. 'incentives2' => $d['incentives2'],
  2371. 'total' => 'RM '.$total,
  2372. 'claim' => $d['claim'],
  2373. ));
  2374. }
  2375. }
  2376. }else if(count($dataAugustR) < 50){
  2377. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2378. if($d['contract'] == '12'){
  2379. array_push($combineData, array(
  2380. 'index' => $d['index'],
  2381. 'contract' => $d['contract'],
  2382. 'wo' => $d['wo'],
  2383. 'activation' => $d['activation'],
  2384. 'name' => $d['name'],
  2385. 'address' => $d['address'],
  2386. 'package' => $d['package'],
  2387. 'retail_price' => $d['retail_price'],
  2388. 'incentives1' => $d['incentives1'],
  2389. 'incentives2' => $d['incentives2'],
  2390. 'total' => $d['total'],
  2391. 'claim' => $d['claim'],
  2392. ));
  2393. }else {
  2394. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5, 2);
  2395. array_push($combineData, array(
  2396. 'index' => $d['index'],
  2397. 'contract' => $d['contract'],
  2398. 'wo' => $d['wo'],
  2399. 'activation' => $d['activation'],
  2400. 'name' => $d['name'],
  2401. 'address' => $d['address'],
  2402. 'package' => $d['package'],
  2403. 'retail_price' => $d['retail_price'],
  2404. 'incentives1' => '250%',
  2405. 'incentives2' => $d['incentives2'],
  2406. 'total' => 'RM '.$total,
  2407. 'claim' => $d['claim'],
  2408. ));
  2409. }
  2410. }
  2411. }
  2412. }
  2413. foreach ($dataAugustB as $key => $d) {
  2414. if((date('m/Y', strtotime($d['submission'])) == $month.'/'.$year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020'){
  2415. if($d['contract'] == '24'){
  2416. if ($d['package']== 50){
  2417. $d['retail_price'] = 89;
  2418. } elseif ($d['package']== 100){
  2419. $d['retail_price'] = 119;
  2420. } elseif ($d['package']== 300){
  2421. $d['retail_price'] = 179;
  2422. } elseif ($d['package']== 500){
  2423. $d['retail_price'] = 249;
  2424. }
  2425. }
  2426. if(date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020'){
  2427. $countAugustB[] = $d;
  2428. }
  2429. }else {
  2430. if(date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020'){
  2431. $countAugustB[] = $d;
  2432. }else {
  2433. $combineData[] = $d;
  2434. }
  2435. }
  2436. }
  2437. // Store to combineData New Incentive August
  2438. foreach ($countAugustB as $key => $d) {
  2439. if(count($dataAugustB) >= 50){
  2440. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2441. if($d['contract'] == '12'){
  2442. array_push($combineData, array(
  2443. 'index' => $d['index'],
  2444. 'contract' => $d['contract'],
  2445. 'wo' => $d['wo'],
  2446. 'activation' => $d['activation'],
  2447. 'name' => $d['name'],
  2448. 'address' => $d['address'],
  2449. 'package' => $d['package'],
  2450. 'retail_price' => $d['retail_price'],
  2451. 'incentives1' => $d['incentives1'],
  2452. 'incentives2' => $d['incentives2'],
  2453. 'total' => $d['total'],
  2454. 'claim' => $d['claim'],
  2455. ));
  2456. }else {
  2457. if ($d['package']== 1){
  2458. $total = 1500;
  2459. } else{
  2460. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5 + 50, 2);
  2461. }
  2462. array_push($combineData, array(
  2463. 'index' => $d['index'],
  2464. 'contract' => $d['contract'],
  2465. 'wo' => $d['wo'],
  2466. 'activation' => $d['activation'],
  2467. 'name' => $d['name'],
  2468. 'address' => $d['address'],
  2469. 'package' => $d['package'],
  2470. 'retail_price' => $d['retail_price'],
  2471. 'incentives1' => '250% + RM50',
  2472. 'incentives2' => '',
  2473. 'total' => 'RM '.$total,
  2474. 'claim' => $d['claim'],
  2475. ));
  2476. }
  2477. }
  2478. }else if(count($dataAugustB) < 50){
  2479. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2480. if($d['contract'] == '12'){
  2481. array_push($combineData, array(
  2482. 'index' => $d['index'],
  2483. 'contract' => $d['contract'],
  2484. 'wo' => $d['wo'],
  2485. 'activation' => $d['activation'],
  2486. 'name' => $d['name'],
  2487. 'address' => $d['address'],
  2488. 'package' => $d['package'],
  2489. 'retail_price' => $d['retail_price'],
  2490. 'incentives1' => $d['incentives1'],
  2491. 'incentives2' => $d['incentives2'],
  2492. 'total' => $d['total'],
  2493. 'claim' => $d['claim'],
  2494. ));
  2495. }else {
  2496. if ($d['package']== 1){
  2497. $total = 1500;
  2498. } else{
  2499. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5, 2);
  2500. }
  2501. array_push($combineData, array(
  2502. 'index' => $d['index'],
  2503. 'contract' => $d['contract'],
  2504. 'wo' => $d['wo'],
  2505. 'activation' => $d['activation'],
  2506. 'name' => $d['name'],
  2507. 'address' => $d['address'],
  2508. 'package' => $d['package'],
  2509. 'retail_price' => $d['retail_price'],
  2510. 'incentives1' => '250%',
  2511. 'incentives2' => '',
  2512. 'total' => 'RM '.$total,
  2513. 'claim' => $d['claim'],
  2514. ));
  2515. }
  2516. }
  2517. }
  2518. }
  2519. foreach ($dataSeptemberR as $key => $d) {
  2520. if(((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month.'/'.$year)){
  2521. if($d['contract'] == '24'){
  2522. if ($d['package']== 50){
  2523. $d['retail_price'] = 69;
  2524. } elseif ($d['package']== 100){
  2525. $d['retail_price'] = 89;
  2526. } elseif ($d['package']== 500){
  2527. $d['retail_price'] = 129;
  2528. }
  2529. }
  2530. }
  2531. if(count($dataSeptemberR) >= 50){
  2532. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2533. if($d['contract'] == '12'){
  2534. array_push($combineData, array(
  2535. 'index' => $d['index'],
  2536. 'contract' => $d['contract'],
  2537. 'wo' => $d['wo'],
  2538. 'activation' => $d['activation'],
  2539. 'name' => $d['name'],
  2540. 'address' => $d['address'],
  2541. 'package' => $d['package'],
  2542. 'retail_price' => $d['retail_price'],
  2543. 'incentives1' => $d['incentives1'],
  2544. 'incentives2' => $d['incentives2'],
  2545. 'total' => $d['total'],
  2546. 'claim' => $d['claim'],
  2547. ));
  2548. }else {
  2549. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5 + 50, 2);
  2550. array_push($combineData, array(
  2551. 'index' => $d['index'],
  2552. 'contract' => $d['contract'],
  2553. 'wo' => $d['wo'],
  2554. 'activation' => $d['activation'],
  2555. 'name' => $d['name'],
  2556. 'address' => $d['address'],
  2557. 'package' => $d['package'],
  2558. 'retail_price' => $d['retail_price'],
  2559. 'incentives1' => '250% + RM50',
  2560. 'incentives2' => $d['incentives2'],
  2561. 'total' => 'RM '.$total,
  2562. 'claim' => $d['claim'],
  2563. ));
  2564. }
  2565. }
  2566. }else if(count($dataSeptemberR) < 50){
  2567. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2568. if($d['contract'] == '12'){
  2569. array_push($combineData, array(
  2570. 'index' => $d['index'],
  2571. 'contract' => $d['contract'],
  2572. 'wo' => $d['wo'],
  2573. 'activation' => $d['activation'],
  2574. 'name' => $d['name'],
  2575. 'address' => $d['address'],
  2576. 'package' => $d['package'],
  2577. 'retail_price' => $d['retail_price'],
  2578. 'incentives1' => $d['incentives1'],
  2579. 'incentives2' => $d['incentives2'],
  2580. 'total' => $d['total'],
  2581. 'claim' => $d['claim'],
  2582. ));
  2583. }else {
  2584. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5, 2);
  2585. array_push($combineData, array(
  2586. 'index' => $d['index'],
  2587. 'contract' => $d['contract'],
  2588. 'wo' => $d['wo'],
  2589. 'activation' => $d['activation'],
  2590. 'name' => $d['name'],
  2591. 'address' => $d['address'],
  2592. 'package' => $d['package'],
  2593. 'retail_price' => $d['retail_price'],
  2594. 'incentives1' => '250%',
  2595. 'incentives2' => $d['incentives2'],
  2596. 'total' => 'RM '.$total,
  2597. 'claim' => $d['claim'],
  2598. ));
  2599. }
  2600. }
  2601. }
  2602. }
  2603. foreach ($dataSeptemberB as $key => $d) {
  2604. if(((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month.'/'.$year)){
  2605. if($d['contract'] == '24'){
  2606. if ($d['package']== 50){
  2607. $d['retail_price'] = 89;
  2608. } elseif ($d['package']== 100){
  2609. $d['retail_price'] = 119;
  2610. } elseif ($d['package']== 300){
  2611. $d['retail_price'] = 179;
  2612. } elseif ($d['package']== 500){
  2613. $d['retail_price'] = 249;
  2614. }
  2615. }
  2616. }
  2617. if(count($dataSeptemberB) >= 50){
  2618. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2619. if($d['contract'] == '12'){
  2620. array_push($combineData, array(
  2621. 'index' => $d['index'],
  2622. 'contract' => $d['contract'],
  2623. 'wo' => $d['wo'],
  2624. 'activation' => $d['activation'],
  2625. 'name' => $d['name'],
  2626. 'address' => $d['address'],
  2627. 'package' => $d['package'],
  2628. 'retail_price' => $d['retail_price'],
  2629. 'incentives1' => $d['incentives1'],
  2630. 'incentives2' => $d['incentives2'],
  2631. 'total' => $d['total'],
  2632. 'claim' => $d['claim'],
  2633. ));
  2634. }else {
  2635. if ($d['package']== 1){
  2636. $total = 1500;
  2637. } else{
  2638. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5 + 50, 2);
  2639. }
  2640. array_push($combineData, array(
  2641. 'index' => $d['index'],
  2642. 'contract' => $d['contract'],
  2643. 'wo' => $d['wo'],
  2644. 'activation' => $d['activation'],
  2645. 'name' => $d['name'],
  2646. 'address' => $d['address'],
  2647. 'package' => $d['package'],
  2648. 'retail_price' => $d['retail_price'],
  2649. 'incentives1' => '250% + RM50',
  2650. 'incentives2' => '',
  2651. 'total' => 'RM '.$total,
  2652. 'claim' => $d['claim'],
  2653. ));
  2654. }
  2655. }
  2656. }else if(count($dataSeptemberB) < 50){
  2657. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2658. if($d['contract'] == '12'){
  2659. array_push($combineData, array(
  2660. 'index' => $d['index'],
  2661. 'contract' => $d['contract'],
  2662. 'wo' => $d['wo'],
  2663. 'activation' => $d['activation'],
  2664. 'name' => $d['name'],
  2665. 'address' => $d['address'],
  2666. 'package' => $d['package'],
  2667. 'retail_price' => $d['retail_price'],
  2668. 'incentives1' => $d['incentives1'],
  2669. 'incentives2' => $d['incentives2'],
  2670. 'total' => $d['total'],
  2671. 'claim' => $d['claim'],
  2672. ));
  2673. }else {
  2674. if ($d['package']== 1){
  2675. $total = 1500;
  2676. } else{
  2677. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5, 2);
  2678. }
  2679. array_push($combineData, array(
  2680. 'index' => $d['index'],
  2681. 'contract' => $d['contract'],
  2682. 'wo' => $d['wo'],
  2683. 'activation' => $d['activation'],
  2684. 'name' => $d['name'],
  2685. 'address' => $d['address'],
  2686. 'package' => $d['package'],
  2687. 'retail_price' => $d['retail_price'],
  2688. 'incentives1' => '250%',
  2689. 'incentives2' => '',
  2690. 'total' => 'RM '.$total,
  2691. 'claim' => $d['claim'],
  2692. ));
  2693. }
  2694. }
  2695. }
  2696. }
  2697. foreach ($dataOctoberR as $key => $d) {
  2698. if(((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month.'/'.$year)){
  2699. if($d['contract'] == '24'){
  2700. if ($d['package']== 50){
  2701. $d['retail_price'] = 69;
  2702. } elseif ($d['package']== 100){
  2703. $d['retail_price'] = 89;
  2704. } elseif ($d['package']== 500){
  2705. $d['retail_price'] = 129;
  2706. }
  2707. }
  2708. }
  2709. if(count($dataOctoberR) >= 50){
  2710. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2711. if($d['contract'] == '12'){
  2712. array_push($combineData, array(
  2713. 'index' => $d['index'],
  2714. 'contract' => $d['contract'],
  2715. 'wo' => $d['wo'],
  2716. 'activation' => $d['activation'],
  2717. 'name' => $d['name'],
  2718. 'address' => $d['address'],
  2719. 'package' => $d['package'],
  2720. 'retail_price' => $d['retail_price'],
  2721. 'incentives1' => $d['incentives1'],
  2722. 'incentives2' => $d['incentives2'],
  2723. 'total' => $d['total'],
  2724. 'claim' => $d['claim'],
  2725. ));
  2726. }else {
  2727. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5 + 50, 2);
  2728. array_push($combineData, array(
  2729. 'index' => $d['index'],
  2730. 'contract' => $d['contract'],
  2731. 'wo' => $d['wo'],
  2732. 'activation' => $d['activation'],
  2733. 'name' => $d['name'],
  2734. 'address' => $d['address'],
  2735. 'package' => $d['package'],
  2736. 'retail_price' => $d['retail_price'],
  2737. 'incentives1' => '250% + RM50',
  2738. 'incentives2' => $d['incentives2'],
  2739. 'total' => 'RM '.$total,
  2740. 'claim' => $d['claim'],
  2741. ));
  2742. }
  2743. }
  2744. }else if(count($dataOctoberR) < 50){
  2745. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2746. if($d['contract'] == '12'){
  2747. array_push($combineData, array(
  2748. 'index' => $d['index'],
  2749. 'contract' => $d['contract'],
  2750. 'wo' => $d['wo'],
  2751. 'activation' => $d['activation'],
  2752. 'name' => $d['name'],
  2753. 'address' => $d['address'],
  2754. 'package' => $d['package'],
  2755. 'retail_price' => $d['retail_price'],
  2756. 'incentives1' => $d['incentives1'],
  2757. 'incentives2' => $d['incentives2'],
  2758. 'total' => $d['total'],
  2759. 'claim' => $d['claim'],
  2760. ));
  2761. }else {
  2762. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5, 2);
  2763. array_push($combineData, array(
  2764. 'index' => $d['index'],
  2765. 'contract' => $d['contract'],
  2766. 'wo' => $d['wo'],
  2767. 'activation' => $d['activation'],
  2768. 'name' => $d['name'],
  2769. 'address' => $d['address'],
  2770. 'package' => $d['package'],
  2771. 'retail_price' => $d['retail_price'],
  2772. 'incentives1' => '250%',
  2773. 'incentives2' => $d['incentives2'],
  2774. 'total' => 'RM '.$total,
  2775. 'claim' => $d['claim'],
  2776. ));
  2777. }
  2778. }
  2779. }
  2780. }
  2781. foreach ($dataOctoberB as $key => $d) {
  2782. if(((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month.'/'.$year)){
  2783. if($d['contract'] == '24'){
  2784. if ($d['package']== 50){
  2785. $d['retail_price'] = 89;
  2786. } elseif ($d['package']== 100){
  2787. $d['retail_price'] = 119;
  2788. } elseif ($d['package']== 300){
  2789. $d['retail_price'] = 179;
  2790. } elseif ($d['package']== 500){
  2791. $d['retail_price'] = 249;
  2792. }
  2793. }
  2794. }
  2795. if(count($dataOctoberB) >= 50){
  2796. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2797. if($d['contract'] == '12'){
  2798. array_push($combineData, array(
  2799. 'index' => $d['index'],
  2800. 'contract' => $d['contract'],
  2801. 'wo' => $d['wo'],
  2802. 'activation' => $d['activation'],
  2803. 'name' => $d['name'],
  2804. 'address' => $d['address'],
  2805. 'package' => $d['package'],
  2806. 'retail_price' => $d['retail_price'],
  2807. 'incentives1' => $d['incentives1'],
  2808. 'incentives2' => $d['incentives2'],
  2809. 'total' => $d['total'],
  2810. 'claim' => $d['claim'],
  2811. ));
  2812. }else {
  2813. if ($d['package']== 1){
  2814. $total = 1500;
  2815. } else{
  2816. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5 + 50, 2);
  2817. }
  2818. array_push($combineData, array(
  2819. 'index' => $d['index'],
  2820. 'contract' => $d['contract'],
  2821. 'wo' => $d['wo'],
  2822. 'activation' => $d['activation'],
  2823. 'name' => $d['name'],
  2824. 'address' => $d['address'],
  2825. 'package' => $d['package'],
  2826. 'retail_price' => $d['retail_price'],
  2827. 'incentives1' => '250% + RM50',
  2828. 'incentives2' => '',
  2829. 'total' => 'RM '.$total,
  2830. 'claim' => $d['claim'],
  2831. ));
  2832. }
  2833. }
  2834. }else if(count($dataOctoberB) < 50){
  2835. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2836. if($d['contract'] == '12'){
  2837. array_push($combineData, array(
  2838. 'index' => $d['index'],
  2839. 'contract' => $d['contract'],
  2840. 'wo' => $d['wo'],
  2841. 'activation' => $d['activation'],
  2842. 'name' => $d['name'],
  2843. 'address' => $d['address'],
  2844. 'package' => $d['package'],
  2845. 'retail_price' => $d['retail_price'],
  2846. 'incentives1' => $d['incentives1'],
  2847. 'incentives2' => $d['incentives2'],
  2848. 'total' => $d['total'],
  2849. 'claim' => $d['claim'],
  2850. ));
  2851. }else {
  2852. if ($d['package']== 1){
  2853. $total = 1500;
  2854. } else{
  2855. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.5, 2);
  2856. }
  2857. array_push($combineData, array(
  2858. 'index' => $d['index'],
  2859. 'contract' => $d['contract'],
  2860. 'wo' => $d['wo'],
  2861. 'activation' => $d['activation'],
  2862. 'name' => $d['name'],
  2863. 'address' => $d['address'],
  2864. 'package' => $d['package'],
  2865. 'retail_price' => $d['retail_price'],
  2866. 'incentives1' => '250%',
  2867. 'incentives2' => '',
  2868. 'total' => 'RM '.$total,
  2869. 'claim' => $d['claim'],
  2870. ));
  2871. }
  2872. }
  2873. }
  2874. }
  2875. }else{
  2876. $dataR = $this->returnDataR($company,$year,$month);
  2877. foreach($dataR as $r){
  2878. $combineData[] = $r;
  2879. }
  2880. $dataB = $this->returnDataB($company,$year,$month);
  2881. foreach($dataB as $b){
  2882. $combineData[] = $b;
  2883. }
  2884. }
  2885. $i = 0;
  2886. $nested_data = array();
  2887. if(!empty($combineData)){
  2888. foreach ($combineData as $c){
  2889. $update_dealer = DealerClaim::where('wo',$c['wo'])->first();
  2890. if(!empty($update_dealer)){
  2891. $update_dealer->incentives1 = $c['incentives1'];
  2892. $update_dealer->incentives2 = $c['incentives2'];
  2893. $update_dealer->retail_price = $c['retail_price'];
  2894. $update_dealer->total_claim = $c['total'];
  2895. $update_dealer->save();
  2896. }
  2897. }
  2898. }
  2899. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  2900. $q->with('Form');
  2901. }],'Staff')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->get();
  2902. if(!empty($dataClaim)){
  2903. foreach ($dataClaim as $c){
  2904. $address = ''; $name = '';
  2905. if($c->Subscriber->Form->type_application == 'R'){
  2906. if($c->Subscriber->street != ''){
  2907. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  2908. }else {
  2909. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  2910. }
  2911. $name = $c->Subscriber->name;
  2912. }else if($c->Subscriber->Form->type_application == 'B'){
  2913. if($c->Subscriber->unit_no != ''){
  2914. $address = $c->Subscriber->unit_no. ', '.$c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  2915. }else {
  2916. $address = $c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  2917. }
  2918. $name = $c->Subscriber->company_name;
  2919. }
  2920. $i++;
  2921. array_push($final, array(
  2922. 'index' => $c->formT,
  2923. 'contract' => $c->contract,
  2924. 'wo' => $c->wo,
  2925. 'activated_dt' => $c->activated_dt,
  2926. 'name' => $name,
  2927. 'address' => $address,
  2928. 'package' => $c->package,
  2929. 'retail_price' => $c->retail_price,
  2930. 'incentives1' => $c->incentives1,
  2931. 'incentives2' => $c->incentives2,
  2932. 'total' => $c->total_claim,
  2933. 'claimed' => $c->claim_dt,
  2934. ));
  2935. }
  2936. }
  2937. foreach($final as $f){
  2938. $basic_total += floatval(str_replace('RM ', '', $f['total']));
  2939. }
  2940. // Calculate extra incentves
  2941. // if($month == '1' && $year == '2020'){
  2942. // if(count($count_cyberjaya) > 50){
  2943. // $balance = count($count_cyberjaya) - 50;
  2944. // $extra += $balance * 50;
  2945. // }
  2946. // if(count($count_jasin) > 10){
  2947. // $balance = count($count_jasin) - 10;
  2948. // $extra += $balance * 50;
  2949. // }
  2950. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  2951. // if(count($count_cyberjaya) > 50){
  2952. // $balance = count($count_cyberjaya) - 50;
  2953. // $extra += $balance * 50;
  2954. // }
  2955. // if(count($count_jasin) > 20){
  2956. // $balance = count($count_jasin) - 10;
  2957. // $extra += $balance * 50;
  2958. // }
  2959. // }else {
  2960. // $extra = 0;
  2961. // }
  2962. $extra = 0;
  2963. $totals = $basic_total + $extra;
  2964. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  2965. // $pdf->setPaper('A4', 'landscape');
  2966. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  2967. // return $pdf->download( $pdfName );
  2968. return $final;
  2969. }
  2970. // else if($year!='null' && $month!='null' && $app!='null'){
  2971. // $count_cyberjaya = array(); $count_jasin = array();
  2972. // $extra = 0; $basic_total = 0; $totals = 0;
  2973. // if($app == 'Residential'){
  2974. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  2975. // $dataDis = $this->returnDataR($company,'2019','12');
  2976. // $dataJan = $this->returnDataR($company,'2020','1');
  2977. // foreach ($dataDis as $key => $d) {
  2978. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  2979. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2980. // $count_cyberjaya[] = $d;
  2981. // }
  2982. // if (strpos($d['address'], 'Jasin') !== false) {
  2983. // $count_jasin[] = $d;
  2984. // }
  2985. // }else if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020' && date('d/m/Y', strtotime($d['activation'])) <= '31/7/2020'){
  2986. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2987. // $count_cyberjaya[] = $d;
  2988. // }
  2989. // if (strpos($d['address'], 'Jasin') !== false) {
  2990. // $count_jasin[] = $d;
  2991. // }
  2992. // }else {
  2993. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2994. // $combineData[] = $d;
  2995. // }
  2996. // }
  2997. // }
  2998. // foreach ($dataJan as $key => $d) {
  2999. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  3000. // $count_cyberjaya[] = $d;
  3001. // }
  3002. // if (strpos($d['address'], 'Jasin') !== false) {
  3003. // $count_jasin[] = $d;
  3004. // }
  3005. // }
  3006. // // Store to combineData New Incentives Cyberjaya
  3007. // foreach ($count_cyberjaya as $key => $d) {
  3008. // if(count($count_cyberjaya) > 50){
  3009. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3010. // if($d['contract'] == '12'){
  3011. // array_push($combineData, array(
  3012. // 'index' => $d['index'],
  3013. // 'contract' => $d['contract'],
  3014. // 'wo' => $d['wo'],
  3015. // 'activation' => $d['activation'],
  3016. // 'name' => $d['name'],
  3017. // 'address' => $d['address'],
  3018. // 'package' => $d['package'],
  3019. // 'retail_price' => $d['retail_price'],
  3020. // 'incentives1' => $d['incentives1'],
  3021. // 'incentives2' => $d['incentives2'],
  3022. // 'total' => $d['total'],
  3023. // 'claim' => $d['claim'],
  3024. // ));
  3025. // }else {
  3026. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  3027. // array_push($combineData, array(
  3028. // 'index' => $d['index'],
  3029. // 'contract' => $d['contract'],
  3030. // 'wo' => $d['wo'],
  3031. // 'activation' => $d['activation'],
  3032. // 'name' => $d['name'],
  3033. // 'address' => $d['address'],
  3034. // 'package' => $d['package'],
  3035. // 'retail_price' => $d['retail_price'],
  3036. // 'incentives1' => '230%',
  3037. // 'incentives2' => $d['incentives2'],
  3038. // 'total' => 'RM '.$total,
  3039. // 'claim' => $d['claim'],
  3040. // ));
  3041. // }
  3042. // }
  3043. // }else if(count($count_cyberjaya) < 50){
  3044. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3045. // array_push($combineData, array(
  3046. // 'index' => $d['index'],
  3047. // 'contract' => $d['contract'],
  3048. // 'wo' => $d['wo'],
  3049. // 'activation' => $d['activation'],
  3050. // 'name' => $d['name'],
  3051. // 'address' => $d['address'],
  3052. // 'package' => $d['package'],
  3053. // 'retail_price' => $d['retail_price'],
  3054. // 'incentives1' => $d['incentives1'],
  3055. // 'incentives2' => $d['incentives2'],
  3056. // 'total' => $d['total'],
  3057. // 'claim' => $d['claim'],
  3058. // ));
  3059. // }
  3060. // }
  3061. // }
  3062. // // Store to combineData New Incentives Jasin
  3063. // foreach ($count_jasin as $key => $d) {
  3064. // if(count($count_jasin) > 10){
  3065. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3066. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  3067. // array_push($combineData, array(
  3068. // 'index' => $d['index'],
  3069. // 'contract' => $d['contract'],
  3070. // 'wo' => $d['wo'],
  3071. // 'activation' => $d['activation'],
  3072. // 'name' => $d['name'],
  3073. // 'address' => $d['address'],
  3074. // 'package' => $d['package'],
  3075. // 'retail_price' => $d['retail_price'],
  3076. // 'incentives1' => '230%',
  3077. // 'incentives2' => $d['incentives2'],
  3078. // 'total' => 'RM '.$total,
  3079. // 'claim' => $d['claim'],
  3080. // ));
  3081. // }
  3082. // }else if(count($count_jasin) < 10){
  3083. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3084. // array_push($combineData, array(
  3085. // 'index' => $d['index'],
  3086. // 'contract' => $d['contract'],
  3087. // 'wo' => $d['wo'],
  3088. // 'activation' => $d['activation'],
  3089. // 'name' => $d['name'],
  3090. // 'address' => $d['address'],
  3091. // 'package' => $d['package'],
  3092. // 'retail_price' => $d['retail_price'],
  3093. // 'incentives1' => $d['incentives1'],
  3094. // 'incentives2' => $d['incentives2'],
  3095. // 'total' => $d['total'],
  3096. // 'claim' => $d['claim'],
  3097. // ));
  3098. // }
  3099. // }
  3100. // }
  3101. // }else {
  3102. // $dataR = $this->returnDataR($company,$year,$month);
  3103. // foreach($dataR as $r){
  3104. // $combineData[] = $r;
  3105. // }
  3106. // }
  3107. // }else if($app == 'Business'){
  3108. // $dataB = $this->returnDataB($company,$year,$month);
  3109. // }
  3110. // foreach($dataB as $b){
  3111. // $combineData[] = $b;
  3112. // }
  3113. // $i = 0;
  3114. // $nested_data = array();
  3115. // if(!empty($combineData)){
  3116. // foreach ($combineData as $c){
  3117. // $i++;
  3118. // array_push($final, array(
  3119. // 'index' => $c['index'],
  3120. // 'contract' => $c['contract'],
  3121. // 'wo' => $c['wo'],
  3122. // 'activated_dt' => $c['activation'],
  3123. // 'name' => $c['name'],
  3124. // 'address' => $c['address'],
  3125. // 'package' => $c['package'],
  3126. // 'retail_price' => $c['retail_price'],
  3127. // 'incentives1' => $c['incentives1'],
  3128. // 'incentives2' => $c['incentives2'],
  3129. // 'total' => $c['total'],
  3130. // 'claimed' => $c['claim'],
  3131. // ));
  3132. // }
  3133. // }
  3134. // foreach($final as $f){
  3135. // $basic_total += floatval(str_replace('RM ', '', $f['total']));
  3136. // }
  3137. // //Calculate extra incentves
  3138. // if($month == '1' && $year == '2020'){
  3139. // if(count($count_cyberjaya) > 50){
  3140. // $balance = count($count_cyberjaya) - 50;
  3141. // $extra += $balance * 50;
  3142. // }
  3143. // if(count($count_jasin) > 10){
  3144. // $balance = count($count_jasin) - 10;
  3145. // $extra += $balance * 50;
  3146. // }
  3147. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  3148. // if(count($count_cyberjaya) > 50){
  3149. // $balance = count($count_cyberjaya) - 50;
  3150. // $extra += $balance * 50;
  3151. // }
  3152. // if(count($count_jasin) > 20){
  3153. // $balance = count($count_jasin) - 10;
  3154. // $extra += $balance * 50;
  3155. // }
  3156. // }else {
  3157. // $extra = 0;
  3158. // }
  3159. // $totals = $basic_total + $extra;
  3160. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  3161. // $pdf->setPaper('A4', 'landscape');
  3162. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  3163. // return $pdf->download( $pdfName );
  3164. // }
  3165. }
  3166. public function update_total_claim(){
  3167. $dealer = DealerClaim::all();
  3168. foreach ($dealer as $key => $d) {
  3169. $claim = str_replace("RM ","",$d->total_claim);
  3170. $price = str_replace("RM ","",$d->retail_price);
  3171. $d->total_claim = floatval($claim);
  3172. $d->retail_price = floatval($price);
  3173. $d->save();
  3174. }
  3175. }
  3176. }