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

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