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

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910
  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. {
  26. $id = Auth::guard('ds')->id();
  27. $user = Staff::with('StaffDetail')->find($id);
  28. return view('dealer.index', compact('user'));
  29. }
  30. /***
  31. / Agent list
  32. ***/
  33. public function gAgentList()
  34. {
  35. $id = Auth::guard('ds')->id();
  36. $user = Staff::find($id);
  37. $email = $user->email;
  38. $userDetails = StaffDetail::where('email', $email)->first();
  39. $all = StaffDetail::where('company_id', $userDetails->company_id)->orderBy('created_at', 'desc')->get();
  40. $curr = Carbon::now()->getTimestamp();
  41. $i = 0;
  42. $nested_data = array();
  43. if (!empty($all)) {
  44. foreach ($all as $a) {
  45. $i++;
  46. $y = '';
  47. $n1 = '';
  48. if ($userDetails->_id == $a->_id) {
  49. $y = $a->name . "-You";
  50. } else {
  51. $y = $a->name;
  52. }
  53. $reg_time = $a->created_at;
  54. $expiry_date = $reg_time->addDays(3);
  55. $expiry_date = $expiry_date->getTimestamp();
  56. if ($curr < $expiry_date) {
  57. $n1 = "New/";
  58. }
  59. array_push($nested_data, array(
  60. 'index' => $i,
  61. 'image' => $a->user_pic,
  62. 'name' => $n1 . $y,
  63. 'ic' => $a->ic,
  64. 'phone' => $a->phone,
  65. 'email' => $a->email,
  66. 'action' => $a->_id
  67. ));
  68. }
  69. }
  70. return \DataTables::of($nested_data)->make(true);
  71. }
  72. /***
  73. / Application Form List
  74. ***/
  75. public function viewAppList()
  76. {
  77. $id = Auth::guard('ds')->id();
  78. $user = Staff::with('StaffDetail')->find($id);
  79. return view('dealer.application-form-list', compact('user'));
  80. }
  81. /***
  82. / Get Application Form List
  83. ***/
  84. public function getSubscribers($dealerCompany)
  85. {
  86. $data = array();
  87. $curr = Carbon::now()->getTimestamp();
  88. $subscriber = Subscriber::where('dealer_company', $dealerCompany)->get();
  89. foreach ($subscriber as $key => $s) {
  90. $n1 = '';
  91. $reg_time = Carbon::createFromTimestamp($s->reg_time);
  92. $expiry_date = $reg_time->addDays(3);
  93. $expiry_date = $expiry_date->getTimestamp();
  94. $agentName = StaffDetail::where('_id', $s->dealer)->first();
  95. $build = Coverage::where('address', $s->building)->first();
  96. if ($s->street == '') {
  97. $street = $build->street;
  98. } else {
  99. $street = $s->street;
  100. }
  101. if ($curr < $expiry_date) {
  102. $n1 = "New/";
  103. }
  104. $data[] = array(
  105. 'formT' => 'R',
  106. 'wo' => $s->wo,
  107. 'name' => $n1 . $s->name,
  108. 'no' => $s->phone1,
  109. 'unit' => $s->unit_no,
  110. 'building' => $s->building,
  111. 'street' => $street,
  112. 'postcode' => $s->postcode,
  113. 'city' => $s->city,
  114. 'sales' => $agentName->name,
  115. 'created_at' => $s->reg_time,
  116. 'action' => $s->_id,
  117. );
  118. }
  119. return $data;
  120. }
  121. public function getBusiness($dealerCompany)
  122. {
  123. $data = array();
  124. $curr = Carbon::now()->getTimestamp();
  125. $business = Subscriber::where('dealer_company', $dealerCompany)->get();
  126. foreach ($business as $key => $s) {
  127. $n1 = '';
  128. $reg_time = Carbon::createFromTimestamp($s->reg_time);
  129. $expiry_date = $reg_time->addDays(3);
  130. $expiry_date = $expiry_date->getTimestamp();
  131. if ($curr < $expiry_date) {
  132. $n1 = "New/";
  133. }
  134. $agentName = StaffDetail::where('_id', $s->dealer)->first();
  135. $data[] = array(
  136. 'formT' => 'B',
  137. 'wo' => $s->wo,
  138. 'name' => $n1 . $s->name,
  139. 'no' => $s->phone1,
  140. 'unit' => '-',
  141. 'building' => '-',
  142. 'street' => $s->address,
  143. 'postcode' => $s->postcode,
  144. 'city' => $s->city,
  145. 'sales' => $agentName->name,
  146. 'created_at' => $s->reg_time,
  147. 'action' => $s->_id,
  148. );
  149. }
  150. return $data;
  151. }
  152. public function getOrderHistory($id)
  153. {
  154. $data = array();
  155. $order_history = FormStatus::where('form_id', $id)->get();
  156. foreach ($order_history as $oh) {
  157. $utcdatetime = new \MongoDB\BSON\UTCDateTime((string) $oh->date);
  158. $datetime = $utcdatetime->toDateTime();
  159. $time = $datetime->format(DATE_RSS);
  160. $time = strtotime($time . ' UTC');
  161. $dateInLocal = date("d/m/Y h:i a", $time);
  162. $data[] = array(
  163. 'date' => $dateInLocal,
  164. 'status' => $oh->status,
  165. 'desc' => $oh->desc
  166. );
  167. }
  168. $json = json_encode($data);
  169. return $json;
  170. }
  171. public function gApplicationList1()
  172. {
  173. $id = Auth::guard('ds')->id();
  174. $user = Staff::with('StaffDetail')->find($id);
  175. $fm = Form::with('Subscriber')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
  176. $nested_data = array();
  177. $i = 0;
  178. foreach ($fm as $f) {
  179. $dname = "";
  180. $wo = WorkOrder::where('_id', $f->_id)->first();
  181. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  182. if (!empty($dealer)) {
  183. $dname = $dealer->name;
  184. }
  185. $address = '';
  186. $name = '';
  187. if ($f->type_application == 'R') {
  188. if (!empty($f->Subscriber->building_name)) {
  189. $address = $f->Subscriber->building_name;
  190. $name = $f->Subscriber->name;
  191. }
  192. } else if ($f->type_application == 'B') {
  193. $address = '-';
  194. $name = $f->Subscriber->company_name;
  195. }
  196. if (empty($wo) && !empty($f->Subscriber)) {
  197. $i++;
  198. array_push($nested_data, array(
  199. 'index' => $i . $f->type_application,
  200. 'name' => $name,
  201. 'phone' => $f->Subscriber->phone1,
  202. 'unit' => $f->Subscriber->unit_no,
  203. 'building' => $address,
  204. 'street' => $f->Subscriber->street,
  205. 'postcode' => $f->Subscriber->postcode,
  206. 'city' => $f->Subscriber->city,
  207. 'sales' => $dname,
  208. 'action' => $f->_id
  209. ));
  210. }
  211. }
  212. return \DataTables::of($nested_data)->make(true);
  213. }
  214. public function gApplicationList2()
  215. {
  216. $id = Auth::guard('ds')->id();
  217. $user = Staff::with('StaffDetail')->find($id);
  218. $fm = Form::with('Subscriber')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
  219. $nested_data = array();
  220. $i = 0;
  221. foreach ($fm as $f) {
  222. $dname = "";
  223. $wo = WorkOrder::where('_id', $f->_id)->first();
  224. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  225. if (!empty($dealer)) {
  226. $dname = $dealer->name;
  227. }
  228. $address = '';
  229. $name = '';
  230. if ($f->type_application == 'R') {
  231. if (!empty($f->Subscriber->building_name)) {
  232. $address = $f->Subscriber->building_name;
  233. $name = $f->Subscriber->name;
  234. }
  235. } else if ($f->type_application == 'B') {
  236. $address = '-';
  237. $name = $f->Subscriber->company_name;
  238. }
  239. if (!empty($wo) && $wo->status != 'Completed') {
  240. $i++;
  241. array_push($nested_data, array(
  242. 'index' => $i . $f->type_application,
  243. 'name' => $name,
  244. 'phone' => $f->Subscriber->phone1,
  245. 'unit' => $f->Subscriber->unit_no,
  246. 'building' => $address,
  247. 'street' => $f->Subscriber->street,
  248. 'postcode' => $f->Subscriber->postcode,
  249. 'city' => $f->Subscriber->city,
  250. 'sales' => $dname,
  251. 'action' => $f->_id
  252. ));
  253. }
  254. }
  255. return \DataTables::of($nested_data)->make(true);
  256. }
  257. public function getCompletedList($year, $month)
  258. {
  259. $id = Auth::guard('ds')->id();
  260. $user = Staff::find($id);
  261. $email = $user->email;
  262. $userDetails = StaffDetail::where('email', $email)->first();
  263. $subs = $this->getSubscribers($userDetails->company_id);
  264. $buss = $this->getBusiness($userDetails->company_id);
  265. // Combine
  266. $cdata = array();
  267. foreach ($subs as $key => $s) {
  268. $cdata[] = $s;
  269. }
  270. foreach ($buss as $key => $b) {
  271. $cdata[] = $b;
  272. }
  273. // Sort based on TimeStamp
  274. $sort = array();
  275. foreach ($cdata as $key => $r) {
  276. $sort[$key] = $r['created_at'];
  277. }
  278. array_multisort($sort, SORT_DESC, $cdata);
  279. $wK = WorkDetail::get();
  280. $curr = Carbon::now()->getTimestamp();
  281. $mY = '';
  282. if ($year != 'null' && $month != 'null') {
  283. $mY = $year . '/' . $month;
  284. }
  285. $final = array();
  286. $filter = array();
  287. $dW = array();
  288. foreach ($cdata as $c) {
  289. if ($c['wo'] != '') {
  290. foreach ($wK as $key => $w) {
  291. if ($c['wo'] == $w->wo && $w->status == 'Completed') {
  292. $dW[] = $c;
  293. }
  294. }
  295. }
  296. }
  297. foreach ($dW as $d) {
  298. if ($mY != '') {
  299. $docket = Docket::where('work_order_id', $d['wo'])->first();
  300. $cDate = date('Y/m', strtotime($docket->end_job));;
  301. if ($mY == $cDate) {
  302. $filter[] = $d;
  303. }
  304. } else {
  305. $filter[] = $d;
  306. }
  307. }
  308. foreach ($filter as $c) {
  309. $do = Docket::where('work_order_id', $c['wo'])->first();
  310. $n1 = '';
  311. $reg_time = Carbon::createFromTimestamp(strtotime($do->end_job));
  312. $expiry_date = $reg_time->addDays(3);
  313. $expiry_date = $expiry_date->getTimestamp();
  314. if ($curr < $expiry_date) {
  315. $n1 = "New/";
  316. }
  317. $final[] = array(
  318. 'formT' => $c['formT'],
  319. 'wo' => $c['wo'],
  320. 'do' => $do->docket_id,
  321. 'activated' => $do->end_job,
  322. 'name' => $n1 . str_replace("New/", "", $c['name']),
  323. 'no' => $c['no'],
  324. 'unit' => $c['unit'],
  325. 'building' => $c['building'],
  326. 'street' => $c['street'],
  327. 'postcode' => $c['postcode'],
  328. 'city' => $c['city'],
  329. 'sales' => $c['sales'],
  330. 'created_at' => $c['created_at'],
  331. 'action' => $c['action'],
  332. );
  333. }
  334. return $final;
  335. }
  336. public function gApplicationList3($year, $month)
  337. {
  338. $id = Auth::guard('ds')->id();
  339. $user = Staff::with('StaffDetail')->find($id);
  340. $mY = '';
  341. if ($year != 'null' && $month != 'null') {
  342. $mY = $month . '/' . $year;
  343. }
  344. $fm = Form::with('Subscriber', 'WorkOrder')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
  345. $nested_data = array();
  346. $i = 0;
  347. foreach ($fm as $f) {
  348. if (!empty($f->WorkOrder)) {
  349. if ($f->WorkOrder->status == 'Completed') {
  350. $wo = WorkOrder::with('Docket')->where('wo', $f->WorkOrder->wo)->first();
  351. $dealer = StaffDetail::where('_id', $f->dealer_id)->withTrashed()->first();
  352. $i++;
  353. $address = '';
  354. $name = '';
  355. if ($f->type_application == 'R') {
  356. if (!empty($f->Subscriber->building_name)) {
  357. $address = $f->Subscriber->building_name;
  358. $name = $f->Subscriber->name;
  359. }
  360. } else if ($f->type_application == 'B') {
  361. $address = '-';
  362. $name = $f->Subscriber->company_name;
  363. }
  364. if (!empty($wo->Docket)) {
  365. $end = date('m/Y', strtotime($wo->Docket->end_job));
  366. if ($mY == '') {
  367. array_push($nested_data, array(
  368. 'index' => $i . $f->type_application,
  369. 'wo' => $wo->wo,
  370. 'do' => $f->WorkOrder->docket_id,
  371. 'name' => $name,
  372. 'phone' => $f->Subscriber->phone1,
  373. 'unit' => $f->Subscriber->unit_no,
  374. 'building' => $address,
  375. 'street' => $f->Subscriber->street,
  376. 'postcode' => $f->Subscriber->postcode,
  377. 'city' => $f->Subscriber->city,
  378. 'sales' => $dealer->name,
  379. 'action' => $f->_id
  380. ));
  381. } else if ($mY == $end) {
  382. array_push($nested_data, array(
  383. 'index' => $i . $f->type_application,
  384. 'wo' => $wo->wo,
  385. 'do' => $f->WorkOrder->docket_id,
  386. 'name' => $name,
  387. 'phone' => $f->Subscriber->phone1,
  388. 'unit' => $f->Subscriber->unit_no,
  389. 'building' => $address,
  390. 'street' => $f->Subscriber->street,
  391. 'postcode' => $f->Subscriber->postcode,
  392. 'city' => $f->Subscriber->city,
  393. 'sales' => $dealer->name,
  394. 'action' => $f->_id
  395. ));
  396. }
  397. }
  398. }
  399. }
  400. }
  401. return \DataTables::of($nested_data)->make(true);
  402. }
  403. /***
  404. / Claim All
  405. ***/
  406. public function claimAll()
  407. {
  408. $id = Auth::guard('ds')->id();
  409. $user = Staff::with('StaffDetail')->find($id);
  410. return view('dealer.claim-all', compact('user'));
  411. }
  412. /***
  413. / Convert To PDF
  414. ***/
  415. public function exportPDF1()
  416. {
  417. return view('pdf.agent-claim');
  418. }
  419. public function exportPDF($company, $year, $month, $app)
  420. {
  421. $final = array();
  422. $id = Auth::guard('ds')->id();
  423. $user = Staff::with('StaffDetail')->find($id);
  424. $com = Company::where('_id', $user->StaffDetail->company_id)->first();
  425. $i = 0;
  426. $dataR = array();
  427. $dataB = array();
  428. $combineData = array();
  429. $count_cyberjaya = array();
  430. $count_jasin = array();
  431. $count_ayerKeroh = array();
  432. $count_alorGajah = array();
  433. $count_menglembu = array();
  434. $count_ipoh = array();
  435. $extra = 0;
  436. $basic_total = 0;
  437. $totals = 0;
  438. if ($year != 'null' && $month != 'null' && $app != 'null') {
  439. if ($app == 'Residential') {
  440. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  441. $q->with('Form');
  442. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  443. if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
  444. foreach ($dataClaim as $key => $d) {
  445. if (
  446. date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  447. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
  448. ) {
  449. if (strpos($d['address'], 'Cyberjaya') !== false) {
  450. $count_cyberjaya[] = $d;
  451. }
  452. if (strpos($d['address'], 'Jasin') !== false) {
  453. $count_jasin[] = $d;
  454. }
  455. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  456. $count_ayerKeroh[] = $d;
  457. }
  458. if (strpos($d['address'], 'Alor Gajah') !== false) {
  459. $count_alorGajah[] = $d;
  460. }
  461. if (strpos($d['address'], 'Menglembu') !== false) {
  462. $count_menglembu[] = $d;
  463. }
  464. if (strpos($d['address'], 'Ipoh') !== false) {
  465. $count_ipoh[] = $d;
  466. }
  467. }
  468. }
  469. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  470. foreach ($dataClaim as $key => $d) {
  471. if (
  472. date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  473. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
  474. ) {
  475. if (strpos($d['address'], 'Cyberjaya') !== false) {
  476. $count_cyberjaya[] = $d;
  477. }
  478. if (strpos($d['address'], 'Jasin') !== false) {
  479. $count_jasin[] = $d;
  480. }
  481. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  482. $count_ayerKeroh[] = $d;
  483. }
  484. if (strpos($d['address'], 'Alor Gajah') !== false) {
  485. $count_alorGajah[] = $d;
  486. }
  487. if (strpos($d['address'], 'Menglembu') !== false) {
  488. $count_menglembu[] = $d;
  489. }
  490. if (strpos($d['address'], 'Ipoh') !== false) {
  491. $count_ipoh[] = $d;
  492. }
  493. }
  494. }
  495. }
  496. } else if ($app == 'Business') {
  497. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  498. $q->with('Form');
  499. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  500. }
  501. }
  502. if (!empty($dataClaim)) {
  503. foreach ($dataClaim as $c) {
  504. $address = '';
  505. $name = '';
  506. if ($c->Subscriber->Form->type_application == 'R') {
  507. if ($c->Subscriber->street != '') {
  508. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  509. } else {
  510. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  511. }
  512. $name = $c->Subscriber->name;
  513. } else if ($c->Subscriber->Form->type_application == 'B') {
  514. if ($c->Subscriber->unit_no != '') {
  515. $unit = $c->Subscriber->unit_no;
  516. } else {
  517. $unit = ' ';
  518. }
  519. if ($c->Subscriber->building_name == null) {
  520. $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  521. } else {
  522. $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  523. }
  524. $name = $c->Subscriber->company_name;
  525. }
  526. $i++;
  527. array_push($final, array(
  528. 'index' => $c->formT,
  529. 'contract' => $c->contract,
  530. 'wo' => $c->wo,
  531. 'do' => $c->docket,
  532. 'activated_dt' => $c->activated_dt,
  533. 'name' => $name,
  534. 'address' => $address,
  535. 'package' => $c->package,
  536. 'retail_price' => 'RM ' . $c->retail_price,
  537. 'incentives1' => $c->incentives1,
  538. 'incentives2' => $c->incentives2,
  539. 'total' => 'RM' . $c->total_claim,
  540. 'claimed' => $c->claim_dt,
  541. ));
  542. }
  543. $project_type = '';
  544. $invoice_no = '';
  545. foreach ($dataClaim as $f) {
  546. $basic_total += $f->total_claim;
  547. }
  548. // Calculate extra incentves
  549. if ($month == '01' && $year == '2020') {
  550. if (count($count_cyberjaya) > 50) {
  551. $balance = count($count_cyberjaya) - 50;
  552. $extra += $balance * 50;
  553. }
  554. if (count($count_ayerKeroh) > 50) {
  555. $balance = count($count_ayerKeroh) - 50;
  556. $extra += $balance * 50;
  557. }
  558. if (count($count_alorGajah) > 50) {
  559. $balance = count($count_alorGajah) - 50;
  560. $extra += $balance * 50;
  561. }
  562. if (count($count_menglembu) > 50) {
  563. $balance = count($count_menglembu) - 50;
  564. $extra += $balance * 50;
  565. }
  566. if (count($count_ipoh) > 50) {
  567. $balance = count($count_ipoh) - 50;
  568. $extra += $balance * 50;
  569. }
  570. if (count($count_jasin) > 10) {
  571. $balance = count($count_jasin) - 10;
  572. $extra += $balance * 50;
  573. }
  574. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  575. if (count($count_cyberjaya) > 50) {
  576. $balance = count($count_cyberjaya) - 50;
  577. $extra += $balance * 50;
  578. }
  579. if (count($count_ayerKeroh) > 50) {
  580. $balance = count($count_ayerKeroh) - 50;
  581. $extra += $balance * 50;
  582. }
  583. if (count($count_alorGajah) > 50) {
  584. $balance = count($count_alorGajah) - 50;
  585. $extra += $balance * 50;
  586. }
  587. if (count($count_menglembu) > 50) {
  588. $balance = count($count_menglembu) - 50;
  589. $extra += $balance * 50;
  590. }
  591. if (count($count_ipoh) > 50) {
  592. $balance = count($count_ipoh) - 50;
  593. $extra += $balance * 50;
  594. }
  595. if (count($count_jasin) > 20) {
  596. $balance = count($count_jasin) - 20;
  597. $extra += $balance * 50;
  598. }
  599. } else {
  600. $extra = 0;
  601. }
  602. $totals = $basic_total + $extra;
  603. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year', 'com', 'basic_total', 'extra', 'totals', 'invoice_no', 'project_type'));
  604. $pdf->setPaper('A4', 'landscape');
  605. $pdfName = preg_replace('/\s+/', '-', $com->name) . '-' . $month . '-' . $year . '.pdf';
  606. return $pdf->download($pdfName);
  607. }
  608. }
  609. /***
  610. / Encrypt Password
  611. ***/
  612. public function encryptPassword($action, $string)
  613. {
  614. $output = false;
  615. $encrypt_method = "AES-256-CBC";
  616. $secret_key = '28472B4B6250655368566D5970337336';
  617. $secret_iv = md5(md5($string)); //'This is my secret iv';
  618. // hash
  619. $key = hash('sha256', $secret_key);
  620. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  621. if ($action == 'encrypt') {
  622. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  623. $output = base64_encode($output);
  624. } else if ($action == 'decrypt') {
  625. $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  626. }
  627. return $output;
  628. }
  629. /***
  630. / Agent Form
  631. ***/
  632. public function showAgentForm()
  633. {
  634. $id = Auth::guard('ds')->id();
  635. $user = Staff::with('StaffDetail')->find($id);
  636. return view('dealer.add_agent', compact('user'));
  637. }
  638. /***
  639. / Add Agent
  640. ***/
  641. public function requestAddAgent(Request $request)
  642. {
  643. $validator = Validator::make($request->all(), [
  644. 'password' => 'min:8|confirmed',
  645. ]);
  646. if ($validator->fails()) {
  647. return redirect()->back()->withInput()->withErrors($validator);
  648. }
  649. $user = Staff::where('email', $request->get('email'))->first();
  650. if (empty($user)) {
  651. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  652. $dealerD = new StaffDetail;
  653. $dealerD->name = $request->get('aname');
  654. $dealerD->ic = $request->get('ic');
  655. $dealerD->email = $request->get('email');
  656. $dealerD->phone = $request->get('phone');
  657. $dealerD->company_id = $request->get('company_id');
  658. $dealerD->color = '';
  659. $dealerD->position = 'Sales';
  660. $dealerD->password = $pass;
  661. $dealerD->user_pic = 'assets/avatar/user.png';
  662. // Save Login Dealer
  663. $loginD = new Staff;
  664. $loginD->email = $request->get('email');
  665. $loginD->password = $pass;
  666. $loginD->roles_access = 'Sales';
  667. $loginD->company_id = $request->get('company_id');
  668. $loginD->last_login_at = '';
  669. $loginD->last_login_ip = '';
  670. // $loginData = [
  671. // 'email' => $request->get('email'),
  672. // 'password' => $pass,
  673. // 'roles_access' => 'Sales',
  674. // 'last_login_at' => '',
  675. // 'last_login_ip' => '',
  676. // ];
  677. $company = Company::where('_id', $request->get('company_id'))->first();
  678. $company->staff()->save($loginD);
  679. // $dealer = DealerLaravel::create($loginData);
  680. $loginD->staffdetail()->save($dealerD);
  681. return redirect()->back()->with('success_msg', '<strong>Success!</strong> register <strong>' . $request->get('email') . '</strong>');
  682. } else {
  683. return redirect()->back()->withInput()->withErrors('Email already exist!');
  684. }
  685. }
  686. public function editAgentDealer($agent_id)
  687. {
  688. $id = Auth::guard('ds')->id();
  689. $user = Staff::find($id);
  690. $email = $user->email;
  691. $userDetails = StaffDetail::where('email', $email)->first();
  692. $person = StaffDetail::where('_id', $agent_id)->first();
  693. return view('dealer.edit_agent', compact('person', 'userDetails', 'user'));
  694. }
  695. public function deleteAgent(Request $request)
  696. {
  697. $agent = Staff::where('_id', $request->id)->first();
  698. $agentdetail = $agent->staffdetail()->first();
  699. if (!empty($agentdetail) && !empty($agent)) {
  700. $agent->delete();
  701. $agentdetail->delete();
  702. return 'true';
  703. } else {
  704. return 'false';
  705. }
  706. }
  707. //Show claim list by company
  708. public function mClaimListAll($company)
  709. {
  710. $id = Auth::guard('ds')->id();
  711. $user = Staff::with('StaffDetail')->find($id);
  712. $dealer_claimAll = DealerClaim::where('dealer', $company)->orderBy('activated_dt', 'desc')->get();
  713. $i = 0;
  714. $nested_data = array();
  715. foreach ($dealer_claimAll as $c) {
  716. $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first();
  717. $address = '';
  718. if ($customer->Form->type_application == 'R') {
  719. if ($customer->street != '') {
  720. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  721. } else {
  722. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  723. }
  724. } else if ($customer->Form->type_application == 'B') {
  725. if ($customer->unit_no != '') {
  726. $unit = $customer->unit_no;
  727. } else {
  728. $unit = ' ';
  729. }
  730. if ($customer->building_name == null) {
  731. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  732. } else {
  733. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  734. }
  735. }
  736. $i++;
  737. array_push($nested_data, array(
  738. 'index' => $c->formT,
  739. 'contract' => $c->contract,
  740. 'wo' => $c->wo,
  741. 'activated_dt' => $c->activated_dt,
  742. 'name' => $customer->name,
  743. 'address' => $address,
  744. 'package' => $c->package,
  745. 'retail_price' => 'RM ' . $c->retail_price,
  746. 'incentives1' => '',
  747. 'incentives2' => '',
  748. 'total' => '',
  749. 'claimed' => $c->laim_dt,
  750. 'action' => 'null',
  751. ));
  752. }
  753. return \DataTables::of($nested_data)->make(true);
  754. }
  755. // Get Dealer Claim Residential
  756. public function returnDataR($company, $year, $month)
  757. {
  758. $dataCR = DealerClaim::where('formT', 'R')->where('dealer', $company)->get();
  759. $final = array();
  760. // Month & Year
  761. $mY = '';
  762. if ($year != 'null' && $month != 'null') {
  763. $mY = $month . '/' . $year;
  764. }
  765. if ($mY != '') {
  766. $data12 = array();
  767. $data24 = array();
  768. $countD12 = 0;
  769. $countD24 = 0;
  770. foreach ($dataCR as $dc) {
  771. if ($dc->activated_my == $mY || $dc->activated_my == '0' . $mY) {
  772. if ($dc->contract == "12") {
  773. $data12[] = $dc;
  774. } else if ($dc->contract == "24") {
  775. $data24[] = $dc;
  776. }
  777. }
  778. }
  779. $countD24 = count($data24);
  780. $countD12 = count($data12);
  781. $comm = Commission::where('formT', 'R')->get();
  782. $commV12 = 0;
  783. $commV24 = 0;
  784. $comm12 = '';
  785. $comm24 = '';
  786. $addRM24 = '';
  787. foreach ($comm as $c) {
  788. if ($c->contract == '12') {
  789. if (strpos($c->ranges, '>') !== false) {
  790. $pieces = explode(">", $c->ranges);
  791. if ($countD12 >= intval($pieces[1])) {
  792. $commV12 = floatval($c->comm) / 100;
  793. $comm12 = $c->comm . '%';
  794. }
  795. }
  796. if (strpos($c->ranges, '-') !== false) {
  797. $pieces = explode("-", $c->ranges);
  798. if ($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])) {
  799. $commV12 = floatval($c->comm) / 100;
  800. $comm12 = $c->comm . '%';
  801. }
  802. }
  803. } else if ($c->contract == '24') {
  804. // Contract => 24
  805. if ($countD24 != 0) {
  806. if (strpos($c->ranges, '>') !== false) {
  807. $pieces = explode(">", $c->ranges);
  808. if ($countD24 >= intval($pieces[1])) {
  809. if (strpos($c->comm, 'RM') !== false) {
  810. $comm24 = '+ ' . $c->comm;
  811. $commV24 = '';
  812. $addRM24 = $c->comm;
  813. } else {
  814. $comms = explode("RM", $c->comm);
  815. if (!empty($comms[1])) {
  816. $comm24 = 'RM ' . $comms[1];
  817. $commV24 = floatval($comms[1]);
  818. } else {
  819. if ($comms[0] != '') {
  820. $comm24 = $comms[0] . '%';
  821. $commV24 = floatval($comms[0]) / 100;
  822. }
  823. }
  824. }
  825. }
  826. }
  827. if (strpos($c->ranges, '-') !== false) {
  828. $pieces = explode("-", $c->ranges);
  829. if ($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])) {
  830. if (strpos($c->comm, 'RM') !== false) {
  831. $comms = explode(" + RM ", $c->comm);
  832. $comm24 = $comms[0] . '%';
  833. $commV24 = floatval($comms[0]) / 100;
  834. $addRM24 = floatval($comms[1]);
  835. } else {
  836. $comms = explode("RM", $c->comm);
  837. if (!empty($comms[1])) {
  838. $comm24 = 'RM ' . $comms[1];
  839. $commV24 = floatval($comms[1]);
  840. } else {
  841. if ($comms[0] != '') {
  842. $comm24 = $comms[0] . '%';
  843. $commV24 = floatval($comms[0]) / 100;
  844. }
  845. }
  846. }
  847. }
  848. }
  849. }
  850. }
  851. }
  852. foreach ($data12 as $key => $d) {
  853. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  854. $address = '';
  855. $name = '';
  856. if ($customer->Form->type_application == 'R') {
  857. if ($customer->street != '') {
  858. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $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. $unit = $customer->unit_no;
  866. } else {
  867. $unit = ' ';
  868. }
  869. if ($customer->building_name == null) {
  870. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  871. } else {
  872. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  873. }
  874. $name = $customer->company_name;
  875. }
  876. $final[] = array(
  877. 'index' => $d['formT'],
  878. 'contract' => $d['contract'],
  879. 'wo' => $d['wo'],
  880. 'submission' => $d['submission_dt'],
  881. 'activation' => $d['activated_dt'],
  882. 'name' => $name,
  883. 'address' => $address,
  884. 'package' => $d['package'],
  885. 'retail_price' => 'RM ' . $d['retail_price'],
  886. 'incentives1' => $comm12,
  887. 'incentives2' => '',
  888. 'total' => 'RM ' . number_format($d['retail_price'] * $commV12, 2),
  889. 'claim' => $d['claim_dt'],
  890. );
  891. }
  892. foreach ($data24 as $key => $d) {
  893. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  894. $address = '';
  895. $name = '';
  896. if ($customer->Form->type_application == 'R') {
  897. if ($customer->street != '') {
  898. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  899. } else {
  900. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  901. }
  902. $name = $customer->name;
  903. } else if ($customer->Form->type_application == 'B') {
  904. if ($customer->unit_no != '') {
  905. $unit = $customer->unit_no;
  906. } else {
  907. $unit = ' ';
  908. }
  909. if ($customer->building_name == null) {
  910. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  911. } else {
  912. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  913. }
  914. $name = $customer->company_name;
  915. }
  916. $total = '';
  917. if ($commV24 == '') {
  918. $total = $addRM24;
  919. } else {
  920. $total = number_format(($d['retail_price'] * $commV24) + floatval($addRM24), 2);
  921. }
  922. $final[] = array(
  923. 'index' => $d['formT'],
  924. 'contract' => $d['contract'],
  925. 'wo' => $d['wo'],
  926. 'submission' => $d['submission_dt'],
  927. 'activation' => $d['activated_dt'],
  928. 'name' => $name,
  929. 'address' => $address,
  930. 'package' => $d['package'],
  931. 'retail_price' => 'RM ' . $d['retail_price'],
  932. 'incentives1' => $comm24,
  933. 'incentives2' => $addRM24,
  934. 'total' => $total,
  935. 'claim' => $d['claim_dt'],
  936. );
  937. }
  938. } else {
  939. foreach ($dataCR as $c) {
  940. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  941. $address = '';
  942. $name = '';
  943. if ($customer->Form->type_application == 'R') {
  944. if ($customer->street != '') {
  945. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  946. } else {
  947. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  948. }
  949. $name = $customer->name;
  950. } else if ($customer->Form->type_application == 'B') {
  951. if ($customer->unit_no != '') {
  952. $unit = $customer->unit_no;
  953. } else {
  954. $unit = ' ';
  955. }
  956. if ($customer->building_name == null) {
  957. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  958. } else {
  959. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  960. }
  961. $name = $customer->company_name;
  962. }
  963. $final[] = array(
  964. 'index' => $c['formT'],
  965. 'contract' => $c['contract'],
  966. 'wo' => $c['wo'],
  967. 'submission' => $d['submission_dt'],
  968. 'activation' => $c['activated_dt'],
  969. 'name' => $name,
  970. 'address' => $address,
  971. 'package' => $c['package'],
  972. 'retail_price' => 'RM ' . $c['retail_price'],
  973. 'incentives1' => '',
  974. 'incentives2' => '',
  975. 'total' => '',
  976. 'claim' => $c['claim_dt'],
  977. );
  978. }
  979. }
  980. return $final;
  981. }
  982. // Get Claim Business
  983. public function returnDataB($company, $year, $month)
  984. {
  985. $dataCB = DealerClaim::where('formT', 'B')->where('dealer', $company)->get();
  986. $final = array();
  987. // Month & Year
  988. $mY = '';
  989. if ($year != 'null' && $month != 'null') {
  990. $mY = $month . '/' . $year;
  991. }
  992. if ($mY != '') {
  993. /** Contract 12
  994. // 1=>10-100 2=>300 3=>500 4=>1
  995. **/
  996. $data12_1 = array();
  997. $data12_2 = array();
  998. $data12_3 = array();
  999. $data12_4 = array();
  1000. $countD12_1 = 0;
  1001. $countD12_2 = 0;
  1002. $countD12_3 = 0;
  1003. $countD12_4 = 0;
  1004. /** Contract 24
  1005. // 1=>10-100 2=>300 3=>500 4=>1
  1006. **/
  1007. $data24_1 = array();
  1008. $data24_2 = array();
  1009. $data24_3 = array();
  1010. $data24_4 = array();
  1011. $countD24_1 = 0;
  1012. $countD24_2 = 0;
  1013. $countD24_3 = 0;
  1014. $countD24_4 = 0;
  1015. foreach ($dataCB as $dc) {
  1016. if ($dc->activated_my == $mY || $dc->activated_my == '0' . $mY) {
  1017. if ($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")) {
  1018. $data12_1[] = $dc;
  1019. } else if ($dc->contract == "12" && $dc->package == "300") {
  1020. $data12_2[] = $dc;
  1021. } else if ($dc->contract == "12" && $dc->package == "500") {
  1022. $data12_3[] = $dc;
  1023. } else if ($dc->contract == "12" && $dc->package == "1") {
  1024. $data12_4[] = $dc;
  1025. } else if ($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")) {
  1026. $data24_1[] = $dc;
  1027. } else if ($dc->contract == "24" && $dc->package == "300") {
  1028. $data24_2[] = $dc;
  1029. } else if ($dc->contract == "24" && $dc->package == "500") {
  1030. $data24_3[] = $dc;
  1031. } else if ($dc->contract == "24" && $dc->package == "1") {
  1032. $data24_4[] = $dc;
  1033. }
  1034. }
  1035. }
  1036. $countD12_1 = count($data12_1);
  1037. $countD12_2 = count($data12_2);
  1038. $countD12_3 = count($data12_3);
  1039. $countD12_4 = count($data12_4);
  1040. $countD24_1 = count($data24_1);
  1041. $countD24_2 = count($data24_2);
  1042. $countD24_3 = count($data24_3);
  1043. $countD24_4 = count($data24_4);
  1044. $comm = Commission::where('formT', 'B')->get();
  1045. $commV12_1 = 0;
  1046. $commV12_2 = 0;
  1047. $commV12_3 = 0;
  1048. $commV12_4 = 0;
  1049. $commV24_1 = 0;
  1050. $commV24_2 = 0;
  1051. $commV24_3 = 0;
  1052. $commV24_4 = 0;
  1053. $comm12_1 = '';
  1054. $comm12_2 = '';
  1055. $comm12_3 = '';
  1056. $comm12_4 = '';
  1057. $comm24_1 = '';
  1058. $comm24_2 = '';
  1059. $comm24_3 = '';
  1060. $comm24_4 = '';
  1061. $addRM12_1 = '';
  1062. $addRM12_2 = '';
  1063. $addRM12_3 = '';
  1064. $addRM12_4 = '';
  1065. $addRM24_1 = '';
  1066. $addRM24_2 = '';
  1067. $addRM24_3 = '';
  1068. $addRM24_4 = '';
  1069. foreach ($comm as $c) {
  1070. /*** Contract 24 **/
  1071. if ($c->contract == '24' && $c->packageR == "300") {
  1072. if (strpos($c->ranges, '-') !== false) {
  1073. $pieces = explode("-", $c->ranges);
  1074. if ($countD24_2 >= intval($pieces[0]) && $countD24_2 <= intval($pieces[1])) {
  1075. if (strpos($c->comm, 'RM') !== false) {
  1076. $comm24_2 = '+ ' . $c->comm;
  1077. $commV24_2 = '';
  1078. $addRM24_2 = $c->comm;
  1079. } else {
  1080. $comms = explode("RM", $c->comm);
  1081. if (!empty($comms[1])) {
  1082. $comm24_2 = 'RM ' . $comms[1];
  1083. $commV24_2 = floatval($comms[1]);
  1084. } else {
  1085. if ($comms[0] != '') {
  1086. $comm24_2 = $comms[0] . '%';
  1087. $commV24_2 = floatval($comms[0]) / 100;
  1088. }
  1089. }
  1090. }
  1091. }
  1092. }
  1093. if (strpos($c->ranges, '>') !== false) {
  1094. $pieces = explode(">", $c->ranges);
  1095. if ($countD24_2 >= intval($pieces[1])) {
  1096. if (strpos($c->comm, 'RM') !== false) {
  1097. $comm24_2 = '+ ' . $c->comm;
  1098. $commV24_2 = '';
  1099. $addRM24_2 = $c->comm;
  1100. } else {
  1101. $comms = explode("RM", $c->comm);
  1102. if (!empty($comms[1])) {
  1103. $comm24_2 = 'RM ' . $comms[1];
  1104. $commV24_2 = floatval($comms[1]);
  1105. } else {
  1106. if ($comms[0] != '') {
  1107. $comm24_2 = $comms[0] . '%';
  1108. $commV24_2 = floatval($comms[0]) / 100;
  1109. }
  1110. }
  1111. }
  1112. }
  1113. }
  1114. } else if ($c->contract == '24' && $c->packageR == "500") {
  1115. if (strpos($c->ranges, '-') !== false) {
  1116. $pieces = explode("-", $c->ranges);
  1117. if ($countD24_3 >= intval($pieces[0]) && $countD24_3 <= intval($pieces[1])) {
  1118. if (strpos($c->comm, 'RM') !== false) {
  1119. $comm24_3 = '+ ' . $c->comm;
  1120. $commV24_3 = '';
  1121. $addRM24_3 = $c->comm;
  1122. } else {
  1123. $comms = explode("RM", $c->comm);
  1124. if (!empty($comms[1])) {
  1125. $comm24_3 = 'RM ' . $comms[1];
  1126. $commV24_3 = floatval($comms[1]);
  1127. } else {
  1128. if ($comms[0] != '') {
  1129. $comm24_3 = $comms[0] . '%';
  1130. $commV24_3 = floatval($comms[0]) / 100;
  1131. }
  1132. }
  1133. }
  1134. }
  1135. }
  1136. if (strpos($c->ranges, '>') !== false) {
  1137. $pieces = explode(">", $c->ranges);
  1138. if ($countD24_3 >= intval($pieces[1])) {
  1139. if (strpos($c->comm, 'RM') !== false) {
  1140. $comm24_3 = '+ ' . $c->comm;
  1141. $commV24_3 = '';
  1142. $addRM24_3 = $c->comm;
  1143. } else {
  1144. $comms = explode("RM", $c->comm);
  1145. if (isset($comms[1])) {
  1146. $comm24_3 = 'RM ' . $comms[1];
  1147. $commV24_3 = floatval($comms[1]);
  1148. } else {
  1149. if ($comms[0] != '') {
  1150. $comm24_3 = $comms[0] . '%';
  1151. $commV24_3 = floatval($comms[0]) / 100;
  1152. }
  1153. }
  1154. }
  1155. }
  1156. }
  1157. } else if ($c->contract == '24' && $c->packageR == "1") {
  1158. if (strpos($c->ranges, '-') !== false) {
  1159. $pieces = explode("-", $c->ranges);
  1160. if ($countD24_4 >= intval($pieces[0]) && $countD24_4 <= intval($pieces[1])) {
  1161. if (strpos($c->comm, 'RM') !== false) {
  1162. $comm24_4 = '+ ' . $c->comm;
  1163. $commV24_4 = '';
  1164. $addRM24_4 = $c->comm;
  1165. } else {
  1166. $comms = explode("RM", $c->comm);
  1167. if (!empty($comms[1])) {
  1168. $comm24_4 = 'RM ' . $comms[1];
  1169. $commV24_4 = floatval($comms[1]);
  1170. } else {
  1171. if ($comms[0] != '') {
  1172. $comm24_4 = $comms[0] . '%';
  1173. $commV24_4 = floatval($comms[0]) / 100;
  1174. }
  1175. }
  1176. }
  1177. }
  1178. }
  1179. if (strpos($c->ranges, '>') !== false) {
  1180. $pieces = explode(">", $c->ranges);
  1181. if ($countD24_4 >= intval($pieces[1])) {
  1182. if (strpos($c->comm, 'RM') !== false) {
  1183. $comm24_4 = '+ ' . $c->comm;
  1184. $commV24_4 = '';
  1185. $addRM24_4 = $c->comm;
  1186. } else {
  1187. $comms = explode("RM", $c->comm);
  1188. if (isset($comms[1])) {
  1189. $comm24_4 = 'RM ' . $comms[1];
  1190. $commV24_4 = floatval($comms[1]);
  1191. } else {
  1192. if ($comms[0] != '') {
  1193. $comm24_4 = $comms[0] . '%';
  1194. $commV24_4 = floatval($comms[0]) / 100;
  1195. }
  1196. }
  1197. }
  1198. }
  1199. }
  1200. } else if ($c->contract == '24' && $c->packageR == "10,30,50,100") {
  1201. if (strpos($c->ranges, '-') !== false) {
  1202. $pieces = explode("-", $c->ranges);
  1203. if ($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])) {
  1204. if (strpos($c->comm, 'RM') !== false) {
  1205. $comm24_1 = '+ ' . $c->comm;
  1206. $commV24_1 = '';
  1207. $addRM24_1 = $c->comm;
  1208. } else {
  1209. $comms = explode("RM", $c->comm);
  1210. if (!empty($comms[1])) {
  1211. $comm24_1 = 'RM ' . $comms[1];
  1212. $commV24_1 = floatval($comms[1]);
  1213. } else {
  1214. if ($comms[0] != '') {
  1215. $comm24_1 = $comms[0] . '%';
  1216. $commV24_1 = floatval($comms[0]) / 100;
  1217. }
  1218. }
  1219. }
  1220. }
  1221. }
  1222. if (strpos($c->ranges, '>') !== false) {
  1223. $pieces1 = explode(">", $c->ranges);
  1224. if ($countD24_1 >= intval($pieces1[1])) {
  1225. if (strpos($c->comm, "RM") === true) {
  1226. $comm24_1 = '+ ' . $c->comm;
  1227. $commV24_1 = '';
  1228. $addRM24_1 = $c->comm;
  1229. } else {
  1230. $comms = explode("RM", $c->comm);
  1231. if (empty($comms[1])) {
  1232. $comm24_1 = 'RM ' . $comms[1];
  1233. $commV24_1 = floatval($comms[1]);
  1234. } else {
  1235. if ($comms[0] != '') {
  1236. $comm24_1 = str_replace('+ ', '', $comms[0]) . '%';
  1237. $commV24_1 = floatval($comms[0]) / 100;
  1238. $addRM24_1 = $comms[1];
  1239. }
  1240. }
  1241. }
  1242. }
  1243. }
  1244. }
  1245. /*** Contract 12 **/
  1246. else if ($c->contract == '12' && $c->packageR == "10,30,50,100") {
  1247. if (strpos($c->ranges, '>') !== false) {
  1248. $pieces = explode(">", $c->ranges);
  1249. if ($countD12_1 >= intval($pieces[1])) {
  1250. if (strpos($c->comm, 'RM') !== false) {
  1251. $comm12_1 = '+ ' . $c->comm;
  1252. $commV12_1 = '';
  1253. $addRM12_1 = $c->comm;
  1254. } else {
  1255. $comms = explode("RM", $c->comm);
  1256. if (isset($comms[1])) {
  1257. $comm12_1 = 'RM ' . $comms[1];
  1258. $commV12_1 = floatval($comms[1]);
  1259. } else {
  1260. if ($comms[0] != '') {
  1261. $comm12_1 = $comms[0] . '%';
  1262. $commV12_1 = floatval($comms[0]) / 100;
  1263. }
  1264. }
  1265. }
  1266. }
  1267. }
  1268. if (strpos($c->ranges, '-') !== false) {
  1269. $pieces = explode("-", $c->ranges);
  1270. if ($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])) {
  1271. if (strpos($c->comm, 'RM') !== false) {
  1272. $comm12_1 = '+ ' . $c->comm;
  1273. $commV12_1 = '';
  1274. $addRM12_1 = $c->comm;
  1275. } else {
  1276. $comms = explode("RM", $c->comm);
  1277. if (isset($comms[1])) {
  1278. $comm12_1 = 'RM ' . $comms[1];
  1279. $commV12_1 = floatval($comms[1]);
  1280. } else {
  1281. if ($comms[0] != '') {
  1282. $comm12_1 = $comms[0] . '%';
  1283. $commV12_1 = floatval($comms[0]) / 100;
  1284. }
  1285. }
  1286. }
  1287. }
  1288. }
  1289. } else if ($c->contract == '12' && $c->packageR == "300") {
  1290. if (strpos($c->ranges, '>') !== false) {
  1291. $pieces = explode(">", $c->ranges);
  1292. if ($countD12_2 >= intval($pieces[1])) {
  1293. if (strpos($c->comm, 'RM') !== false) {
  1294. $comm12_2 = '+ ' . $c->comm;
  1295. $commV12_2 = '';
  1296. $addRM12_2 = $c->comm;
  1297. } else {
  1298. $comms = explode("RM", $c->comm);
  1299. if (isset($comms[1])) {
  1300. $comm12_2 = 'RM ' . $comms[1];
  1301. $commV12_2 = floatval($comms[1]);
  1302. } else {
  1303. if ($comms[0] != '') {
  1304. $comm12_2 = $comms[0] . '%';
  1305. $commV12_2 = floatval($comms[0]) / 100;
  1306. }
  1307. }
  1308. }
  1309. }
  1310. }
  1311. } else if ($c->contract == '12' && $c->packageR == "500") {
  1312. if (strpos($c->ranges, '>') !== false) {
  1313. $pieces = explode(">", $c->ranges);
  1314. if ($countD12_3 >= intval($pieces[1])) {
  1315. if (strpos($c->comm, 'RM') !== false) {
  1316. $comm12_3 = '+ ' . $c->comm;
  1317. $commV12_3 = '';
  1318. $addRM12_3 = $c->comm;
  1319. } else {
  1320. $comms = explode("RM", $c->comm);
  1321. if (isset($comms[1])) {
  1322. $comm12_3 = 'RM ' . $comms[1];
  1323. $commV12_3 = floatval($comms[1]);
  1324. } else {
  1325. if ($comms[0] != '') {
  1326. $comm12_3 = $comms[0] . '%';
  1327. $commV12_3 = floatval($comms[0]) / 100;
  1328. }
  1329. }
  1330. }
  1331. }
  1332. }
  1333. } else if ($c->contract == '12' && $c->packageR == "1") {
  1334. if (strpos($c->ranges, '>') !== false) {
  1335. $pieces = explode(">", $c->ranges);
  1336. if ($countD12_4 >= intval($pieces[1])) {
  1337. if (strpos($c->comm, 'RM') !== false) {
  1338. $comm12_4 = '+ ' . $c->comm;
  1339. $commV12_4 = '';
  1340. $addRM12_4 = $c->comm;
  1341. } else {
  1342. $comms = explode("RM", $c->comm);
  1343. if (isset($comms[1])) {
  1344. $comm12_4 = 'RM ' . $comms[1];
  1345. $commV12_4 = floatval($comms[1]);
  1346. } else {
  1347. if ($comms[0] != '') {
  1348. $comm12_4 = $comms[0] . '%';
  1349. $commV12_4 = floatval($comms[0]) / 100;
  1350. }
  1351. }
  1352. }
  1353. }
  1354. }
  1355. }
  1356. }
  1357. // Category 10,30,50,100
  1358. foreach ($data12_1 as $key => $d) {
  1359. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1360. $address = '';
  1361. $name = '';
  1362. if ($customer->Form->type_application == 'R') {
  1363. if ($customer->street != '') {
  1364. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1365. } else {
  1366. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1367. }
  1368. $name = $customer->name;
  1369. } else if ($customer->Form->type_application == 'B') {
  1370. if ($customer->unit_no != '') {
  1371. $unit = $customer->unit_no;
  1372. } else {
  1373. $unit = ' ';
  1374. }
  1375. if ($customer->building_name == null) {
  1376. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1377. } else {
  1378. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1379. }
  1380. $name = $customer->company_name;
  1381. }
  1382. $total = '';
  1383. if ($commV12_1 == '') {
  1384. $total = $addRM12_1;
  1385. } else {
  1386. $total = number_format($d['retail_price'] * $commV12_1, 2);
  1387. }
  1388. $final[] = array(
  1389. 'index' => $d['formT'],
  1390. 'contract' => $d['contract'],
  1391. 'wo' => $d['wo'],
  1392. 'submission' => $d['submission_dt'],
  1393. 'activation' => $d['activated_dt'],
  1394. 'name' => $name,
  1395. 'address' => $address,
  1396. 'package' => $d['package'],
  1397. 'retail_price' => 'RM ' . $d['retail_price'],
  1398. 'incentives1' => $comm12_1,
  1399. 'incentives2' => $addRM12_1,
  1400. 'total' => 'RM ' . $total,
  1401. 'claim' => $c['claim_dt'],
  1402. );
  1403. }
  1404. foreach ($data24_1 as $key => $d) {
  1405. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1406. $address = '';
  1407. $name = '';
  1408. if ($customer->Form->type_application == 'R') {
  1409. if ($customer->street != '') {
  1410. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1411. } else {
  1412. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1413. }
  1414. $name = $customer->name;
  1415. } else if ($customer->Form->type_application == 'B') {
  1416. if ($customer->unit_no != '') {
  1417. $unit = $customer->unit_no;
  1418. } else {
  1419. $unit = ' ';
  1420. }
  1421. if ($customer->building_name == null) {
  1422. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1423. } else {
  1424. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1425. }
  1426. $name = $customer->company_name;
  1427. }
  1428. $total = '';
  1429. if ($commV24_1 == '') {
  1430. $total = $addRM24_1;
  1431. } else {
  1432. $total = number_format(($d['retail_price'] * $commV24_1) + floatval($addRM24_1), 2);
  1433. }
  1434. $final[] = array(
  1435. 'index' => $d['formT'],
  1436. 'contract' => $d['contract'],
  1437. 'wo' => $d['wo'],
  1438. 'submission' => $d['submission_dt'],
  1439. 'activation' => $d['activated_dt'],
  1440. 'name' => $name,
  1441. 'address' => $address,
  1442. 'package' => $d['package'],
  1443. 'retail_price' => 'RM ' . $d['retail_price'],
  1444. 'incentives1' => $comm24_1,
  1445. 'incentives2' => $addRM24_1,
  1446. 'total' => 'RM ' . $total,
  1447. 'claim' => $c['claim_dt'],
  1448. );
  1449. }
  1450. // Category 300
  1451. foreach ($data12_2 as $key => $d) {
  1452. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1453. $address = '';
  1454. $name = '';
  1455. if ($customer->Form->type_application == 'R') {
  1456. if ($customer->street != '') {
  1457. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1458. } else {
  1459. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1460. }
  1461. $name = $customer->name;
  1462. } else if ($customer->Form->type_application == 'B') {
  1463. if ($customer->unit_no != '') {
  1464. $unit = $customer->unit_no;
  1465. } else {
  1466. $unit = ' ';
  1467. }
  1468. if ($customer->building_name == null) {
  1469. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1470. } else {
  1471. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1472. }
  1473. $name = $customer->company_name;
  1474. }
  1475. $total = '';
  1476. if ($commV12_2 == '') {
  1477. $total = $addRM12_2;
  1478. } else {
  1479. $total = number_format($d['retail_price'] * $commV12_2, 2);
  1480. }
  1481. $final[] = array(
  1482. 'index' => $d['formT'],
  1483. 'contract' => $d['contract'],
  1484. 'wo' => $d['wo'],
  1485. 'submission' => $d['submission_dt'],
  1486. 'activation' => $d['activated_dt'],
  1487. 'name' => $name,
  1488. 'address' => $address,
  1489. 'package' => $d['package'],
  1490. 'retail_price' => 'RM ' . $d['retail_price'],
  1491. 'incentives1' => $comm12_2,
  1492. 'incentives2' => $addRM12_2,
  1493. 'total' => 'RM ' . $total,
  1494. 'claim' => $c['claim_dt'],
  1495. );
  1496. }
  1497. foreach ($data24_2 as $key => $d) {
  1498. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1499. $address = '';
  1500. $name = '';
  1501. if ($customer->Form->type_application == 'R') {
  1502. if ($customer->street != '') {
  1503. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1504. } else {
  1505. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1506. }
  1507. $name = $customer->name;
  1508. } else if ($customer->Form->type_application == 'B') {
  1509. if ($customer->unit_no != '') {
  1510. $unit = $customer->unit_no;
  1511. } else {
  1512. $unit = ' ';
  1513. }
  1514. if ($customer->building_name == null) {
  1515. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1516. } else {
  1517. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1518. }
  1519. $name = $customer->company_name;
  1520. }
  1521. $total = '';
  1522. if ($commV24_2 == '') {
  1523. $total = $addRM24_2;
  1524. } else {
  1525. $total = number_format($d['retail_price'] * $commV24_2, 2);
  1526. }
  1527. $final[] = array(
  1528. 'index' => $d['formT'],
  1529. 'contract' => $d['contract'],
  1530. 'wo' => $d['wo'],
  1531. 'submission' => $d['submission_dt'],
  1532. 'activation' => $d['activated_dt'],
  1533. 'name' => $name,
  1534. 'address' => $address,
  1535. 'package' => $d['package'],
  1536. 'retail_price' => 'RM ' . $d['retail_price'],
  1537. 'incentives1' => $comm24_2,
  1538. 'incentives2' => $addRM24_2,
  1539. 'total' => 'RM ' . $total,
  1540. 'claim' => $c['claim_dt'],
  1541. );
  1542. }
  1543. // Category 500
  1544. foreach ($data12_3 as $key => $d) {
  1545. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1546. $address = '';
  1547. $name = $customer->name;
  1548. if ($customer->Form->type_application == 'R') {
  1549. if ($customer->street != '') {
  1550. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1551. } else {
  1552. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1553. }
  1554. } else if ($customer->Form->type_application == 'B') {
  1555. if ($customer->unit_no != '') {
  1556. $unit = $customer->unit_no;
  1557. } else {
  1558. $unit = ' ';
  1559. }
  1560. if ($customer->building_name == null) {
  1561. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1562. } else {
  1563. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1564. }
  1565. $name = $customer->company_name;
  1566. }
  1567. $total = '';
  1568. if ($commV12_3 == '') {
  1569. $total = $addRM12_3;
  1570. } else {
  1571. $total = number_format($d['retail_price'] * $commV12_3, 2);
  1572. }
  1573. $final[] = array(
  1574. 'index' => $d['formT'],
  1575. 'contract' => $d['contract'],
  1576. 'wo' => $d['wo'],
  1577. 'submission' => $d['submission_dt'],
  1578. 'activation' => $d['activated_dt'],
  1579. 'name' => $name,
  1580. 'address' => $address,
  1581. 'package' => $d['package'],
  1582. 'retail_price' => 'RM ' . $d['retail_price'],
  1583. 'incentives1' => $comm12_3,
  1584. 'incentives2' => $addRM12_3,
  1585. 'total' => 'RM ' . $total,
  1586. 'claim' => $c['claim_dt'],
  1587. );
  1588. }
  1589. foreach ($data24_3 as $key => $d) {
  1590. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1591. $address = '';
  1592. $name = '';
  1593. if ($customer->Form->type_application == 'R') {
  1594. if ($customer->street != '') {
  1595. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1596. } else {
  1597. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1598. }
  1599. $name = $customer->name;
  1600. } else if ($customer->Form->type_application == 'B') {
  1601. if ($customer->unit_no != '') {
  1602. $unit = $customer->unit_no;
  1603. } else {
  1604. $unit = ' ';
  1605. }
  1606. if ($customer->building_name == null) {
  1607. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1608. } else {
  1609. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1610. }
  1611. $name = $customer->company_name;
  1612. }
  1613. $total = '';
  1614. if ($commV24_3 == '') {
  1615. $total = $addRM24_3;
  1616. } else {
  1617. $total = number_format($d['retail_price'] * $commV24_3, 2);
  1618. }
  1619. $final[] = array(
  1620. 'index' => $d['formT'],
  1621. 'contract' => $d['contract'],
  1622. 'wo' => $d['wo'],
  1623. 'submission' => $d['submission_dt'],
  1624. 'activation' => $d['activated_dt'],
  1625. 'name' => $name,
  1626. 'address' => $address,
  1627. 'package' => $d['package'],
  1628. 'retail_price' => 'RM ' . $d['retail_price'],
  1629. 'incentives1' => $comm24_3,
  1630. 'incentives2' => $addRM24_3,
  1631. 'total' => 'RM ' . $total,
  1632. 'claim' => $c['claim_dt'],
  1633. );
  1634. }
  1635. // Category 1
  1636. foreach ($data12_4 as $key => $d) {
  1637. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1638. $address = '';
  1639. $name = '';
  1640. if ($customer->Form->type_application == 'R') {
  1641. if ($customer->street != '') {
  1642. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1643. } else {
  1644. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1645. }
  1646. $name = $customer->name;
  1647. } else if ($customer->Form->type_application == 'B') {
  1648. if ($customer->unit_no != '') {
  1649. $unit = $customer->unit_no;
  1650. } else {
  1651. $unit = ' ';
  1652. }
  1653. if ($customer->building_name == null) {
  1654. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1655. } else {
  1656. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1657. }
  1658. $name = $customer->company_name;
  1659. }
  1660. $total = '';
  1661. if ($commV12_4 == '') {
  1662. $total = $addRM12_4;
  1663. } else {
  1664. $total = number_format($d['retail_price'] * $commV12_4, 2);
  1665. }
  1666. $final[] = array(
  1667. 'index' => $d['formT'],
  1668. 'contract' => $d['contract'],
  1669. 'wo' => $d['wo'],
  1670. 'submission' => $d['submission_dt'],
  1671. 'activation' => $d['activated_dt'],
  1672. 'name' => $name,
  1673. 'address' => $address,
  1674. 'package' => $d['package'],
  1675. 'retail_price' => 'RM ' . $d['retail_price'],
  1676. 'incentives1' => $comm12_4,
  1677. 'incentives2' => $addRM12_4,
  1678. 'total' => 'RM ' . $total,
  1679. 'claim' => $c['claim_dt'],
  1680. );
  1681. }
  1682. foreach ($data24_4 as $key => $d) {
  1683. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1684. $address = '';
  1685. $name = '';
  1686. if ($customer->Form->type_application == 'R') {
  1687. if ($customer->street != '') {
  1688. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1689. } else {
  1690. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1691. }
  1692. $name = $customer->name;
  1693. } else if ($customer->Form->type_application == 'B') {
  1694. if ($customer->unit_no != '') {
  1695. $unit = $customer->unit_no;
  1696. } else {
  1697. $unit = ' ';
  1698. }
  1699. if ($customer->building_name == null) {
  1700. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1701. } else {
  1702. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1703. }
  1704. $name = $customer->company_name;
  1705. }
  1706. $total = '';
  1707. if ($commV24_4 == '') {
  1708. $total = $addRM24_4;
  1709. } else {
  1710. $total = number_format($d['retail_price'] * $commV24_4, 2);
  1711. }
  1712. $final[] = array(
  1713. 'index' => $d['formT'],
  1714. 'contract' => $d['contract'],
  1715. 'wo' => $d['wo'],
  1716. 'submission' => $d['submission_dt'],
  1717. 'activation' => $d['activated_dt'],
  1718. 'name' => $name,
  1719. 'address' => $address,
  1720. 'package' => $d['package'],
  1721. 'retail_price' => 'RM ' . $d['retail_price'],
  1722. 'incentives1' => $comm24_4,
  1723. 'incentives2' => $addRM24_4,
  1724. 'total' => 'RM ' . $total,
  1725. 'claim' => $c['claim_dt'],
  1726. );
  1727. }
  1728. } else {
  1729. foreach ($dataCB as $c) {
  1730. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1731. $address = '';
  1732. $name = '';
  1733. if ($customer->Form->type_application == 'R') {
  1734. if ($customer->street != '') {
  1735. $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1736. } else {
  1737. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1738. }
  1739. $name = $customer->name;
  1740. } else if ($customer->Form->type_application == 'B') {
  1741. if ($customer->unit_no != '') {
  1742. $unit = $customer->unit_no;
  1743. } else {
  1744. $unit = ' ';
  1745. }
  1746. if ($customer->building_name == null) {
  1747. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1748. } else {
  1749. $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1750. }
  1751. $name = $customer->company_name;
  1752. }
  1753. $final[] = array(
  1754. 'index' => $c['formT'],
  1755. 'contract' => $c['contract'],
  1756. 'wo' => $c['wo'],
  1757. 'submission' => $d['submission_dt'],
  1758. 'activation' => $c['activated_dt'],
  1759. 'name' => $name,
  1760. 'address' => $address,
  1761. 'package' => $c['package'],
  1762. 'retail_price' => 'RM ' . $c['retail_price'],
  1763. 'incentives1' => '',
  1764. 'incentives2' => '',
  1765. 'total' => '',
  1766. 'claim' => $c['claim_dt'],
  1767. );
  1768. }
  1769. }
  1770. return $final;
  1771. }
  1772. /***
  1773. / Return Claim & Combined Business && Resident
  1774. ***/
  1775. public function getClaimRB($company, $year, $month, $app)
  1776. {
  1777. $dataR = array();
  1778. $dataB = array();
  1779. $combineData = array();
  1780. if ($month == 'null' && $year == 'null' && $app == 'null') {
  1781. return $this->mClaimListAll($company);
  1782. } else if ($year != 'null' && $month != 'null' && $app == 'null') {
  1783. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1784. $q->with('Form');
  1785. }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  1786. if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
  1787. foreach ($dataClaim as $key => $d) {
  1788. if (
  1789. date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  1790. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
  1791. ) {
  1792. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1793. $count_cyberjaya[] = $d;
  1794. }
  1795. if (strpos($d['address'], 'Jasin') !== false) {
  1796. $count_jasin[] = $d;
  1797. }
  1798. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1799. $count_ayerKeroh[] = $d;
  1800. }
  1801. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1802. $count_alorGajah[] = $d;
  1803. }
  1804. if (strpos($d['address'], 'Menglembu') !== false) {
  1805. $count_menglembu[] = $d;
  1806. }
  1807. if (strpos($d['address'], 'Ipoh') !== false) {
  1808. $count_ipoh[] = $d;
  1809. }
  1810. }
  1811. }
  1812. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  1813. foreach ($dataClaim as $key => $d) {
  1814. if (
  1815. date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  1816. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
  1817. ) {
  1818. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1819. $count_cyberjaya[] = $d;
  1820. }
  1821. if (strpos($d['address'], 'Jasin') !== false) {
  1822. $count_jasin[] = $d;
  1823. }
  1824. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1825. $count_ayerKeroh[] = $d;
  1826. }
  1827. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1828. $count_alorGajah[] = $d;
  1829. }
  1830. if (strpos($d['address'], 'Menglembu') !== false) {
  1831. $count_menglembu[] = $d;
  1832. }
  1833. if (strpos($d['address'], 'Ipoh') !== false) {
  1834. $count_ipoh[] = $d;
  1835. }
  1836. }
  1837. }
  1838. }
  1839. } else if ($year == 'null' && $month == 'null' && $app != 'null') {
  1840. if ($app == 'Residential') {
  1841. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1842. $q->with('Form');
  1843. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->orderBy('activated_dt', 'DESC')->get();
  1844. } else if ($app == 'Business') {
  1845. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1846. $q->with('Form');
  1847. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->orderBy('activated_dt', 'DESC')->get();
  1848. }
  1849. } else if ($year != 'null' && $month != 'null' && $app != 'null') {
  1850. if ($app == 'Residential') {
  1851. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1852. $q->with('Form');
  1853. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  1854. if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
  1855. foreach ($dataClaim as $key => $d) {
  1856. if (
  1857. date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  1858. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
  1859. ) {
  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. }
  1880. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  1881. foreach ($dataClaim as $key => $d) {
  1882. if (
  1883. date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  1884. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
  1885. ) {
  1886. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1887. $count_cyberjaya[] = $d;
  1888. }
  1889. if (strpos($d['address'], 'Jasin') !== false) {
  1890. $count_jasin[] = $d;
  1891. }
  1892. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1893. $count_ayerKeroh[] = $d;
  1894. }
  1895. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1896. $count_alorGajah[] = $d;
  1897. }
  1898. if (strpos($d['address'], 'Menglembu') !== false) {
  1899. $count_menglembu[] = $d;
  1900. }
  1901. if (strpos($d['address'], 'Ipoh') !== false) {
  1902. $count_ipoh[] = $d;
  1903. }
  1904. }
  1905. }
  1906. }
  1907. } else if ($app == 'Business') {
  1908. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  1909. $q->with('Form');
  1910. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  1911. }
  1912. }
  1913. $i = 0;
  1914. $nested_data = array();
  1915. if (!empty($dataClaim)) {
  1916. foreach ($dataClaim as $c) {
  1917. $address = '';
  1918. $name = '';
  1919. if ($c->Subscriber->Form->type_application == 'R') {
  1920. if ($c->Subscriber->street != '') {
  1921. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1922. } else {
  1923. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1924. }
  1925. $name = $c->Subscriber->name;
  1926. } else if ($c->Subscriber->Form->type_application == 'B') {
  1927. if ($c->Subscriber->unit_no != '') {
  1928. $unit = $c->Subscriber->unit_no;
  1929. } else {
  1930. $unit = ' ';
  1931. }
  1932. if ($c->Subscriber->building_name == null) {
  1933. $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1934. } else {
  1935. $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  1936. }
  1937. $name = $c->Subscriber->company_name;
  1938. }
  1939. $i++;
  1940. array_push($nested_data, array(
  1941. 'index' => $c->formT,
  1942. 'contract' => $c->contract,
  1943. 'wo' => $c->wo,
  1944. 'activated_dt' => $c->activated_dt,
  1945. 'name' => $name,
  1946. 'address' => $address,
  1947. 'package' => $c->package,
  1948. 'retail_price' => 'RM ' . $c->retail_price,
  1949. 'incentives1' => $c->incentives1,
  1950. 'incentives2' => $c->incentives2,
  1951. 'total' => 'RM ' . $c->total_claim,
  1952. 'claimed' => $c->claim_dt,
  1953. ));
  1954. }
  1955. }
  1956. return \DataTables::of($nested_data)->make(true);
  1957. }
  1958. public function updateAgent(Request $request)
  1959. {
  1960. $user = Staff::where('_id', $request->agent_id)->first();
  1961. $validate = Staff::where('email', $request->email)->first();
  1962. $detail = $user->staffdetail()->first();
  1963. $getpass = $request->get('password');
  1964. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  1965. if (empty($validate)) {
  1966. $detail->name = $request->get('aname');
  1967. $detail->ic = $request->get('ic');
  1968. $detail->email = $request->get('email');
  1969. $detail->phone = $request->get('phone');
  1970. $detail->company_id = $request->get('vendor');
  1971. $user->email = $request->get('email');
  1972. $user->company_id = $request->get('vendor');
  1973. if (!empty($getpass)) {
  1974. $validator = Validator::make($request->all(), [
  1975. 'password' => 'min:8|confirmed',
  1976. ]);
  1977. if ($validator->fails()) {
  1978. return redirect()->back()->withInput()->withErrors($validator);
  1979. }
  1980. $detail->password = $pass;
  1981. $user->password = $pass;
  1982. $detail->save();
  1983. $user->save();
  1984. } else {
  1985. $detail->save();
  1986. $user->save();
  1987. }
  1988. return redirect()->route('dHome')->with('success_msg', 'message');
  1989. } else {
  1990. if ($user->email == $request->email) {
  1991. echo "" . $request->get('password');
  1992. $detail->name = $request->get('aname');
  1993. $detail->ic = $request->get('ic');
  1994. $detail->email = $request->get('email');
  1995. $detail->phone = $request->get('phone');
  1996. $detail->company_id = $request->get('vendor');
  1997. $detail->save();
  1998. $user->email = $request->get('email');
  1999. if (!empty($getpass)) {
  2000. $validator = Validator::make($request->all(), [
  2001. 'password' => 'min:8|confirmed',
  2002. ]);
  2003. if ($validator->fails()) {
  2004. return redirect()->back()->withInput()->withErrors($validator);
  2005. }
  2006. $detail->password = $pass;
  2007. $user->password = $pass;
  2008. $detail->save();
  2009. $user->save();
  2010. } else {
  2011. $detail->save();
  2012. $user->save();
  2013. }
  2014. return redirect()->route('dHome')->with('success_msg', 'message');
  2015. } else {
  2016. echo "email is used";
  2017. return redirect()->back()->withInput()->withErrors('Email already exist!');
  2018. }
  2019. }
  2020. }
  2021. /***
  2022. / Application Form
  2023. ***/
  2024. public function showResidentialForm()
  2025. {
  2026. $id = Auth::guard('ds')->id();
  2027. $user = Staff::find($id);
  2028. $email = $user->email;
  2029. $userDetails = StaffDetail::where('email', $email)->first();
  2030. return view('dealer.residential-form', compact('userDetails', 'user'));
  2031. }
  2032. public function showBusinessForm()
  2033. {
  2034. $id = Auth::guard('ds')->id();
  2035. $user = Staff::find($id);
  2036. $email = $user->email;
  2037. $userDetails = StaffDetail::where('email', $email)->first();
  2038. return view('dealer.business-form', compact('userDetails', 'user'));
  2039. }
  2040. public function exportDealerJson(Request $request)
  2041. {
  2042. $final = array();
  2043. $id = Auth::guard('ds')->id();
  2044. // $user = Staff::with('StaffDetail')->find($id);
  2045. // $com = Company::where('_id',$user->StaffDetail->company_id)->first();
  2046. $dataR = array();
  2047. $dataB = array();
  2048. $combineData = array();
  2049. $extra = 0;
  2050. $year = $request->year;
  2051. $month = $request->month;
  2052. $app = $request->app;
  2053. $company = $request->company;
  2054. if ($year != 'null' && $month != 'null' && $app == 'null') {
  2055. $count_cyberjaya = array();
  2056. $count_jasin = array();
  2057. $count_ayerKeroh = array();
  2058. $count_alorGajah = array();
  2059. $count_menglembu = array();
  2060. $count_ipoh = array();
  2061. $extra = 0;
  2062. $basic_total = 0;
  2063. $countAugustR = array();
  2064. $countAugustB = array();
  2065. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  2066. // $dataDis = $this->returnDataR($company,'2019','12');
  2067. // $dataJan = $this->returnDataR($company,'2020','1');
  2068. if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  2069. $dataApril = $this->returnDataR($company, '2020', '4');
  2070. $dataMay = $this->returnDataR($company, '2020', '5');
  2071. $dataJune = $this->returnDataR($company, '2020', '6');
  2072. $dataJuly = $this->returnDataR($company, '2020', '7');
  2073. foreach ($dataApril as $key => $d) {
  2074. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  2075. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2076. // $count_cyberjaya[] = $d;
  2077. // }
  2078. // if (strpos($d['address'], 'Jasin') !== false) {
  2079. // $count_jasin[] = $d;
  2080. // }
  2081. // }
  2082. // // else
  2083. if (date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020') {
  2084. if (strpos($d['address'], 'Cyberjaya') !== false) {
  2085. $count_cyberjaya[] = $d;
  2086. }
  2087. if (strpos($d['address'], 'Jasin') !== false) {
  2088. $count_jasin[] = $d;
  2089. }
  2090. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  2091. $count_ayerKeroh[] = $d;
  2092. }
  2093. if (strpos($d['address'], 'Alor Gajah') !== false) {
  2094. $count_alorGajah[] = $d;
  2095. }
  2096. if (strpos($d['address'], 'Menglembu') !== false) {
  2097. $count_menglembu[] = $d;
  2098. }
  2099. if (strpos($d['address'], 'Ipoh') !== false) {
  2100. $count_ipoh[] = $d;
  2101. }
  2102. } else {
  2103. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2104. $combineData[] = $d;
  2105. }
  2106. }
  2107. }
  2108. foreach ($dataMay as $key => $d) {
  2109. if (strpos($d['address'], 'Cyberjaya') !== false) {
  2110. $count_cyberjaya[] = $d;
  2111. }
  2112. if (strpos($d['address'], 'Jasin') !== false) {
  2113. $count_jasin[] = $d;
  2114. }
  2115. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  2116. $count_ayerKeroh[] = $d;
  2117. }
  2118. if (strpos($d['address'], 'Alor Gajah') !== false) {
  2119. $count_alorGajah[] = $d;
  2120. }
  2121. if (strpos($d['address'], 'Menglembu') !== false) {
  2122. $count_menglembu[] = $d;
  2123. }
  2124. if (strpos($d['address'], 'Ipoh') !== false) {
  2125. $count_ipoh[] = $d;
  2126. }
  2127. }
  2128. foreach ($dataJune as $key => $d) {
  2129. if (strpos($d['address'], 'Cyberjaya') !== false) {
  2130. $count_cyberjaya[] = $d;
  2131. }
  2132. if (strpos($d['address'], 'Jasin') !== false) {
  2133. $count_jasin[] = $d;
  2134. }
  2135. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  2136. $count_ayerKeroh[] = $d;
  2137. }
  2138. if (strpos($d['address'], 'Alor Gajah') !== false) {
  2139. $count_alorGajah[] = $d;
  2140. }
  2141. if (strpos($d['address'], 'Menglembu') !== false) {
  2142. $count_menglembu[] = $d;
  2143. }
  2144. if (strpos($d['address'], 'Ipoh') !== false) {
  2145. $count_ipoh[] = $d;
  2146. }
  2147. }
  2148. foreach ($dataJuly as $key => $d) {
  2149. if (strpos($d['address'], 'Cyberjaya') !== false) {
  2150. $count_cyberjaya[] = $d;
  2151. }
  2152. if (strpos($d['address'], 'Jasin') !== false) {
  2153. $count_jasin[] = $d;
  2154. }
  2155. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  2156. $count_ayerKeroh[] = $d;
  2157. }
  2158. if (strpos($d['address'], 'Alor Gajah') !== false) {
  2159. $count_alorGajah[] = $d;
  2160. }
  2161. if (strpos($d['address'], 'Menglembu') !== false) {
  2162. $count_menglembu[] = $d;
  2163. }
  2164. if (strpos($d['address'], 'Ipoh') !== false) {
  2165. $count_ipoh[] = $d;
  2166. }
  2167. }
  2168. // Store to combineData New Incentives Cyberjaya
  2169. foreach ($count_cyberjaya as $key => $d) {
  2170. if (count($count_cyberjaya) > 50) {
  2171. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2172. if ($d['contract'] == '12') {
  2173. array_push($combineData, array(
  2174. 'index' => $d['index'],
  2175. 'contract' => $d['contract'],
  2176. 'wo' => $d['wo'],
  2177. 'activation' => $d['activation'],
  2178. 'name' => $d['name'],
  2179. 'address' => $d['address'],
  2180. 'package' => $d['package'],
  2181. 'retail_price' => $d['retail_price'],
  2182. 'incentives1' => $d['incentives1'],
  2183. 'incentives2' => $d['incentives2'],
  2184. 'total' => $d['total'],
  2185. 'claim' => $d['claim'],
  2186. ));
  2187. } else {
  2188. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2189. array_push($combineData, array(
  2190. 'index' => $d['index'],
  2191. 'contract' => $d['contract'],
  2192. 'wo' => $d['wo'],
  2193. 'activation' => $d['activation'],
  2194. 'name' => $d['name'],
  2195. 'address' => $d['address'],
  2196. 'package' => $d['package'],
  2197. 'retail_price' => $d['retail_price'],
  2198. 'incentives1' => '230%',
  2199. 'incentives2' => $d['incentives2'],
  2200. 'total' => 'RM ' . $total,
  2201. 'claim' => $d['claim'],
  2202. ));
  2203. }
  2204. }
  2205. } else if (count($count_cyberjaya) < 50) {
  2206. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2207. array_push($combineData, array(
  2208. 'index' => $d['index'],
  2209. 'contract' => $d['contract'],
  2210. 'wo' => $d['wo'],
  2211. 'activation' => $d['activation'],
  2212. 'name' => $d['name'],
  2213. 'address' => $d['address'],
  2214. 'package' => $d['package'],
  2215. 'retail_price' => $d['retail_price'],
  2216. 'incentives1' => $d['incentives1'],
  2217. 'incentives2' => $d['incentives2'],
  2218. 'total' => $d['total'],
  2219. 'claim' => $d['claim'],
  2220. ));
  2221. }
  2222. }
  2223. }
  2224. // Store to combineData New Incentives Menglembu
  2225. foreach ($count_menglembu as $key => $d) {
  2226. if (count($count_menglembu) > 50) {
  2227. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2228. if ($d['contract'] == '12') {
  2229. array_push($combineData, array(
  2230. 'index' => $d['index'],
  2231. 'contract' => $d['contract'],
  2232. 'wo' => $d['wo'],
  2233. 'activation' => $d['activation'],
  2234. 'name' => $d['name'],
  2235. 'address' => $d['address'],
  2236. 'package' => $d['package'],
  2237. 'retail_price' => $d['retail_price'],
  2238. 'incentives1' => $d['incentives1'],
  2239. 'incentives2' => $d['incentives2'],
  2240. 'total' => $d['total'],
  2241. 'claim' => $d['claim'],
  2242. ));
  2243. } else {
  2244. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2245. array_push($combineData, array(
  2246. 'index' => $d['index'],
  2247. 'contract' => $d['contract'],
  2248. 'wo' => $d['wo'],
  2249. 'activation' => $d['activation'],
  2250. 'name' => $d['name'],
  2251. 'address' => $d['address'],
  2252. 'package' => $d['package'],
  2253. 'retail_price' => $d['retail_price'],
  2254. 'incentives1' => '230%',
  2255. 'incentives2' => $d['incentives2'],
  2256. 'total' => 'RM ' . $total,
  2257. 'claim' => $d['claim'],
  2258. ));
  2259. }
  2260. }
  2261. } else if (count($count_menglembu) < 50) {
  2262. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2263. array_push($combineData, array(
  2264. 'index' => $d['index'],
  2265. 'contract' => $d['contract'],
  2266. 'wo' => $d['wo'],
  2267. 'activation' => $d['activation'],
  2268. 'name' => $d['name'],
  2269. 'address' => $d['address'],
  2270. 'package' => $d['package'],
  2271. 'retail_price' => $d['retail_price'],
  2272. 'incentives1' => $d['incentives1'],
  2273. 'incentives2' => $d['incentives2'],
  2274. 'total' => $d['total'],
  2275. 'claim' => $d['claim'],
  2276. ));
  2277. }
  2278. }
  2279. }
  2280. // Store to combineData New Incentives Ipoh
  2281. foreach ($count_ipoh as $key => $d) {
  2282. if (count($count_ipoh) > 50) {
  2283. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2284. if ($d['contract'] == '12') {
  2285. array_push($combineData, array(
  2286. 'index' => $d['index'],
  2287. 'contract' => $d['contract'],
  2288. 'wo' => $d['wo'],
  2289. 'activation' => $d['activation'],
  2290. 'name' => $d['name'],
  2291. 'address' => $d['address'],
  2292. 'package' => $d['package'],
  2293. 'retail_price' => $d['retail_price'],
  2294. 'incentives1' => $d['incentives1'],
  2295. 'incentives2' => $d['incentives2'],
  2296. 'total' => $d['total'],
  2297. 'claim' => $d['claim'],
  2298. ));
  2299. } else {
  2300. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2301. array_push($combineData, array(
  2302. 'index' => $d['index'],
  2303. 'contract' => $d['contract'],
  2304. 'wo' => $d['wo'],
  2305. 'activation' => $d['activation'],
  2306. 'name' => $d['name'],
  2307. 'address' => $d['address'],
  2308. 'package' => $d['package'],
  2309. 'retail_price' => $d['retail_price'],
  2310. 'incentives1' => '230%',
  2311. 'incentives2' => $d['incentives2'],
  2312. 'total' => 'RM ' . $total,
  2313. 'claim' => $d['claim'],
  2314. ));
  2315. }
  2316. }
  2317. } else if (count($count_ipoh) < 50) {
  2318. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2319. array_push($combineData, array(
  2320. 'index' => $d['index'],
  2321. 'contract' => $d['contract'],
  2322. 'wo' => $d['wo'],
  2323. 'activation' => $d['activation'],
  2324. 'name' => $d['name'],
  2325. 'address' => $d['address'],
  2326. 'package' => $d['package'],
  2327. 'retail_price' => $d['retail_price'],
  2328. 'incentives1' => $d['incentives1'],
  2329. 'incentives2' => $d['incentives2'],
  2330. 'total' => $d['total'],
  2331. 'claim' => $d['claim'],
  2332. ));
  2333. }
  2334. }
  2335. }
  2336. // Store to combineData New Incentives Ayer Keroh
  2337. foreach ($count_ayerKeroh as $key => $d) {
  2338. if (count($count_ayerKeroh) > 50) {
  2339. if ($d['contract'] == '12') {
  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' => $d['incentives1'],
  2350. 'incentives2' => $d['incentives2'],
  2351. 'total' => $d['total'],
  2352. 'claim' => $d['claim'],
  2353. ));
  2354. } else {
  2355. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2356. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2357. array_push($combineData, array(
  2358. 'index' => $d['index'],
  2359. 'contract' => $d['contract'],
  2360. 'wo' => $d['wo'],
  2361. 'activation' => $d['activation'],
  2362. 'name' => $d['name'],
  2363. 'address' => $d['address'],
  2364. 'package' => $d['package'],
  2365. 'retail_price' => $d['retail_price'],
  2366. 'incentives1' => '230%',
  2367. 'incentives2' => $d['incentives2'],
  2368. 'total' => 'RM ' . $total,
  2369. 'claim' => $d['claim'],
  2370. ));
  2371. }
  2372. }
  2373. } else if (count($count_ayerKeroh) < 50) {
  2374. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2375. array_push($combineData, array(
  2376. 'index' => $d['index'],
  2377. 'contract' => $d['contract'],
  2378. 'wo' => $d['wo'],
  2379. 'activation' => $d['activation'],
  2380. 'name' => $d['name'],
  2381. 'address' => $d['address'],
  2382. 'package' => $d['package'],
  2383. 'retail_price' => $d['retail_price'],
  2384. 'incentives1' => $d['incentives1'],
  2385. 'incentives2' => $d['incentives2'],
  2386. 'total' => $d['total'],
  2387. 'claim' => $d['claim'],
  2388. ));
  2389. }
  2390. }
  2391. }
  2392. // Store to combineData New Incentives Alor Gajah
  2393. foreach ($count_alorGajah as $key => $d) {
  2394. if (count($count_alorGajah) > 50) {
  2395. if ($d['contract'] == '12') {
  2396. array_push($combineData, array(
  2397. 'index' => $d['index'],
  2398. 'contract' => $d['contract'],
  2399. 'wo' => $d['wo'],
  2400. 'activation' => $d['activation'],
  2401. 'name' => $d['name'],
  2402. 'address' => $d['address'],
  2403. 'package' => $d['package'],
  2404. 'retail_price' => $d['retail_price'],
  2405. 'incentives1' => $d['incentives1'],
  2406. 'incentives2' => $d['incentives2'],
  2407. 'total' => $d['total'],
  2408. 'claim' => $d['claim'],
  2409. ));
  2410. } else {
  2411. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2412. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2413. array_push($combineData, array(
  2414. 'index' => $d['index'],
  2415. 'contract' => $d['contract'],
  2416. 'wo' => $d['wo'],
  2417. 'activation' => $d['activation'],
  2418. 'name' => $d['name'],
  2419. 'address' => $d['address'],
  2420. 'package' => $d['package'],
  2421. 'retail_price' => $d['retail_price'],
  2422. 'incentives1' => '230%',
  2423. 'incentives2' => $d['incentives2'],
  2424. 'total' => 'RM ' . $total,
  2425. 'claim' => $d['claim'],
  2426. ));
  2427. }
  2428. }
  2429. } else if (count($count_alorGajah) < 50) {
  2430. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2431. array_push($combineData, array(
  2432. 'index' => $d['index'],
  2433. 'contract' => $d['contract'],
  2434. 'wo' => $d['wo'],
  2435. 'activation' => $d['activation'],
  2436. 'name' => $d['name'],
  2437. 'address' => $d['address'],
  2438. 'package' => $d['package'],
  2439. 'retail_price' => $d['retail_price'],
  2440. 'incentives1' => $d['incentives1'],
  2441. 'incentives2' => $d['incentives2'],
  2442. 'total' => $d['total'],
  2443. 'claim' => $d['claim'],
  2444. ));
  2445. }
  2446. }
  2447. }
  2448. // Store to combineData New Incentives Jasin
  2449. foreach ($count_jasin as $key => $d) {
  2450. if (count($count_jasin) > 20) {
  2451. if ($d['contract'] == '12') {
  2452. array_push($combineData, array(
  2453. 'index' => $d['index'],
  2454. 'contract' => $d['contract'],
  2455. 'wo' => $d['wo'],
  2456. 'activation' => $d['activation'],
  2457. 'name' => $d['name'],
  2458. 'address' => $d['address'],
  2459. 'package' => $d['package'],
  2460. 'retail_price' => $d['retail_price'],
  2461. 'incentives1' => $d['incentives1'],
  2462. 'incentives2' => $d['incentives2'],
  2463. 'total' => $d['total'],
  2464. 'claim' => $d['claim'],
  2465. ));
  2466. } else {
  2467. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2468. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
  2469. array_push($combineData, array(
  2470. 'index' => $d['index'],
  2471. 'contract' => $d['contract'],
  2472. 'wo' => $d['wo'],
  2473. 'activation' => $d['activation'],
  2474. 'name' => $d['name'],
  2475. 'address' => $d['address'],
  2476. 'package' => $d['package'],
  2477. 'retail_price' => $d['retail_price'],
  2478. 'incentives1' => '230%',
  2479. 'incentives2' => $d['incentives2'],
  2480. 'total' => 'RM ' . $total,
  2481. 'claim' => $d['claim'],
  2482. ));
  2483. }
  2484. }
  2485. } else if (count($count_jasin) < 20) {
  2486. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2487. array_push($combineData, array(
  2488. 'index' => $d['index'],
  2489. 'contract' => $d['contract'],
  2490. 'wo' => $d['wo'],
  2491. 'activation' => $d['activation'],
  2492. 'name' => $d['name'],
  2493. 'address' => $d['address'],
  2494. 'package' => $d['package'],
  2495. 'retail_price' => $d['retail_price'],
  2496. 'incentives1' => $d['incentives1'],
  2497. 'incentives2' => $d['incentives2'],
  2498. 'total' => $d['total'],
  2499. 'claim' => $d['claim'],
  2500. ));
  2501. }
  2502. }
  2503. }
  2504. } else if ($year == '2020' && ($month == '08' || $month == '09' || $month == '10')) {
  2505. $dataAugustR = $this->returnDataR($company, '2020', '8');
  2506. $dataAugustB = $this->returnDataB($company, '2020', '8');
  2507. $dataSeptemberR = $this->returnDataR($company, '2020', '9');
  2508. $dataSeptemberB = $this->returnDataB($company, '2020', '9');
  2509. $dataOctoberR = $this->returnDataR($company, '2020', '10');
  2510. $dataOctoberB = $this->returnDataB($company, '2020', '10');
  2511. foreach ($dataAugustR as $key => $d) {
  2512. if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') {
  2513. if ($d['contract'] == '24') {
  2514. if ($d['package'] == 50) {
  2515. $d['retail_price'] = 69;
  2516. } elseif ($d['package'] == 100) {
  2517. $d['retail_price'] = 89;
  2518. } elseif ($d['package'] == 500) {
  2519. $d['retail_price'] = 129;
  2520. }
  2521. }
  2522. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  2523. $countAugustR[] = $d;
  2524. }
  2525. } else {
  2526. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  2527. $countAugustR[] = $d;
  2528. } else {
  2529. $combineData[] = $d;
  2530. }
  2531. }
  2532. }
  2533. // Store to combineData New Incentive August
  2534. foreach ($countAugustR as $key => $d) {
  2535. if (count($dataAugustR) >= 50) {
  2536. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2537. if ($d['contract'] == '12') {
  2538. array_push($combineData, array(
  2539. 'index' => $d['index'],
  2540. 'contract' => $d['contract'],
  2541. 'wo' => $d['wo'],
  2542. 'activation' => $d['activation'],
  2543. 'name' => $d['name'],
  2544. 'address' => $d['address'],
  2545. 'package' => $d['package'],
  2546. 'retail_price' => $d['retail_price'],
  2547. 'incentives1' => $d['incentives1'],
  2548. 'incentives2' => $d['incentives2'],
  2549. 'total' => $d['total'],
  2550. 'claim' => $d['claim'],
  2551. ));
  2552. } else {
  2553. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2554. array_push($combineData, array(
  2555. 'index' => $d['index'],
  2556. 'contract' => $d['contract'],
  2557. 'wo' => $d['wo'],
  2558. 'activation' => $d['activation'],
  2559. 'name' => $d['name'],
  2560. 'address' => $d['address'],
  2561. 'package' => $d['package'],
  2562. 'retail_price' => $d['retail_price'],
  2563. 'incentives1' => '250% + RM50',
  2564. 'incentives2' => $d['incentives2'],
  2565. 'total' => 'RM ' . $total,
  2566. 'claim' => $d['claim'],
  2567. ));
  2568. }
  2569. }
  2570. } else if (count($dataAugustR) < 50) {
  2571. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2572. if ($d['contract'] == '12') {
  2573. array_push($combineData, array(
  2574. 'index' => $d['index'],
  2575. 'contract' => $d['contract'],
  2576. 'wo' => $d['wo'],
  2577. 'activation' => $d['activation'],
  2578. 'name' => $d['name'],
  2579. 'address' => $d['address'],
  2580. 'package' => $d['package'],
  2581. 'retail_price' => $d['retail_price'],
  2582. 'incentives1' => $d['incentives1'],
  2583. 'incentives2' => $d['incentives2'],
  2584. 'total' => $d['total'],
  2585. 'claim' => $d['claim'],
  2586. ));
  2587. } else {
  2588. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2589. array_push($combineData, array(
  2590. 'index' => $d['index'],
  2591. 'contract' => $d['contract'],
  2592. 'wo' => $d['wo'],
  2593. 'activation' => $d['activation'],
  2594. 'name' => $d['name'],
  2595. 'address' => $d['address'],
  2596. 'package' => $d['package'],
  2597. 'retail_price' => $d['retail_price'],
  2598. 'incentives1' => '250%',
  2599. 'incentives2' => $d['incentives2'],
  2600. 'total' => 'RM ' . $total,
  2601. 'claim' => $d['claim'],
  2602. ));
  2603. }
  2604. }
  2605. }
  2606. }
  2607. foreach ($dataAugustB as $key => $d) {
  2608. if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') {
  2609. if ($d['contract'] == '24') {
  2610. if ($d['package'] == 50) {
  2611. $d['retail_price'] = 89;
  2612. } elseif ($d['package'] == 100) {
  2613. $d['retail_price'] = 119;
  2614. } elseif ($d['package'] == 300) {
  2615. $d['retail_price'] = 179;
  2616. } elseif ($d['package'] == 500) {
  2617. $d['retail_price'] = 249;
  2618. }
  2619. }
  2620. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  2621. $countAugustB[] = $d;
  2622. }
  2623. } else {
  2624. if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
  2625. $countAugustB[] = $d;
  2626. } else {
  2627. $combineData[] = $d;
  2628. }
  2629. }
  2630. }
  2631. // Store to combineData New Incentive August
  2632. foreach ($countAugustB as $key => $d) {
  2633. if (count($dataAugustB) >= 50) {
  2634. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2635. if ($d['contract'] == '12') {
  2636. array_push($combineData, array(
  2637. 'index' => $d['index'],
  2638. 'contract' => $d['contract'],
  2639. 'wo' => $d['wo'],
  2640. 'activation' => $d['activation'],
  2641. 'name' => $d['name'],
  2642. 'address' => $d['address'],
  2643. 'package' => $d['package'],
  2644. 'retail_price' => $d['retail_price'],
  2645. 'incentives1' => $d['incentives1'],
  2646. 'incentives2' => $d['incentives2'],
  2647. 'total' => $d['total'],
  2648. 'claim' => $d['claim'],
  2649. ));
  2650. } else {
  2651. if ($d['package'] == 1) {
  2652. $total = 1500;
  2653. } else {
  2654. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2655. }
  2656. array_push($combineData, array(
  2657. 'index' => $d['index'],
  2658. 'contract' => $d['contract'],
  2659. 'wo' => $d['wo'],
  2660. 'activation' => $d['activation'],
  2661. 'name' => $d['name'],
  2662. 'address' => $d['address'],
  2663. 'package' => $d['package'],
  2664. 'retail_price' => $d['retail_price'],
  2665. 'incentives1' => '250% + RM50',
  2666. 'incentives2' => '',
  2667. 'total' => 'RM ' . $total,
  2668. 'claim' => $d['claim'],
  2669. ));
  2670. }
  2671. }
  2672. } else if (count($dataAugustB) < 50) {
  2673. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2674. if ($d['contract'] == '12') {
  2675. array_push($combineData, array(
  2676. 'index' => $d['index'],
  2677. 'contract' => $d['contract'],
  2678. 'wo' => $d['wo'],
  2679. 'activation' => $d['activation'],
  2680. 'name' => $d['name'],
  2681. 'address' => $d['address'],
  2682. 'package' => $d['package'],
  2683. 'retail_price' => $d['retail_price'],
  2684. 'incentives1' => $d['incentives1'],
  2685. 'incentives2' => $d['incentives2'],
  2686. 'total' => $d['total'],
  2687. 'claim' => $d['claim'],
  2688. ));
  2689. } else {
  2690. if ($d['package'] == 1) {
  2691. $total = 1500;
  2692. } else {
  2693. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2694. }
  2695. array_push($combineData, array(
  2696. 'index' => $d['index'],
  2697. 'contract' => $d['contract'],
  2698. 'wo' => $d['wo'],
  2699. 'activation' => $d['activation'],
  2700. 'name' => $d['name'],
  2701. 'address' => $d['address'],
  2702. 'package' => $d['package'],
  2703. 'retail_price' => $d['retail_price'],
  2704. 'incentives1' => '250%',
  2705. 'incentives2' => '',
  2706. 'total' => 'RM ' . $total,
  2707. 'claim' => $d['claim'],
  2708. ));
  2709. }
  2710. }
  2711. }
  2712. }
  2713. foreach ($dataSeptemberR as $key => $d) {
  2714. 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)) {
  2715. if ($d['contract'] == '24') {
  2716. if ($d['package'] == 50) {
  2717. $d['retail_price'] = 69;
  2718. } elseif ($d['package'] == 100) {
  2719. $d['retail_price'] = 89;
  2720. } elseif ($d['package'] == 500) {
  2721. $d['retail_price'] = 129;
  2722. }
  2723. }
  2724. }
  2725. if (count($dataSeptemberR) >= 50) {
  2726. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2727. if ($d['contract'] == '12') {
  2728. array_push($combineData, array(
  2729. 'index' => $d['index'],
  2730. 'contract' => $d['contract'],
  2731. 'wo' => $d['wo'],
  2732. 'activation' => $d['activation'],
  2733. 'name' => $d['name'],
  2734. 'address' => $d['address'],
  2735. 'package' => $d['package'],
  2736. 'retail_price' => $d['retail_price'],
  2737. 'incentives1' => $d['incentives1'],
  2738. 'incentives2' => $d['incentives2'],
  2739. 'total' => $d['total'],
  2740. 'claim' => $d['claim'],
  2741. ));
  2742. } else {
  2743. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2744. array_push($combineData, array(
  2745. 'index' => $d['index'],
  2746. 'contract' => $d['contract'],
  2747. 'wo' => $d['wo'],
  2748. 'activation' => $d['activation'],
  2749. 'name' => $d['name'],
  2750. 'address' => $d['address'],
  2751. 'package' => $d['package'],
  2752. 'retail_price' => $d['retail_price'],
  2753. 'incentives1' => '250% + RM50',
  2754. 'incentives2' => $d['incentives2'],
  2755. 'total' => 'RM ' . $total,
  2756. 'claim' => $d['claim'],
  2757. ));
  2758. }
  2759. }
  2760. } else if (count($dataSeptemberR) < 50) {
  2761. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2762. if ($d['contract'] == '12') {
  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' => $d['incentives1'],
  2773. 'incentives2' => $d['incentives2'],
  2774. 'total' => $d['total'],
  2775. 'claim' => $d['claim'],
  2776. ));
  2777. } else {
  2778. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2779. array_push($combineData, array(
  2780. 'index' => $d['index'],
  2781. 'contract' => $d['contract'],
  2782. 'wo' => $d['wo'],
  2783. 'activation' => $d['activation'],
  2784. 'name' => $d['name'],
  2785. 'address' => $d['address'],
  2786. 'package' => $d['package'],
  2787. 'retail_price' => $d['retail_price'],
  2788. 'incentives1' => '250%',
  2789. 'incentives2' => $d['incentives2'],
  2790. 'total' => 'RM ' . $total,
  2791. 'claim' => $d['claim'],
  2792. ));
  2793. }
  2794. }
  2795. }
  2796. }
  2797. foreach ($dataSeptemberB as $key => $d) {
  2798. 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)) {
  2799. if ($d['contract'] == '24') {
  2800. if ($d['package'] == 50) {
  2801. $d['retail_price'] = 89;
  2802. } elseif ($d['package'] == 100) {
  2803. $d['retail_price'] = 119;
  2804. } elseif ($d['package'] == 300) {
  2805. $d['retail_price'] = 179;
  2806. } elseif ($d['package'] == 500) {
  2807. $d['retail_price'] = 249;
  2808. }
  2809. }
  2810. }
  2811. if (count($dataSeptemberB) >= 50) {
  2812. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2813. if ($d['contract'] == '12') {
  2814. array_push($combineData, array(
  2815. 'index' => $d['index'],
  2816. 'contract' => $d['contract'],
  2817. 'wo' => $d['wo'],
  2818. 'activation' => $d['activation'],
  2819. 'name' => $d['name'],
  2820. 'address' => $d['address'],
  2821. 'package' => $d['package'],
  2822. 'retail_price' => $d['retail_price'],
  2823. 'incentives1' => $d['incentives1'],
  2824. 'incentives2' => $d['incentives2'],
  2825. 'total' => $d['total'],
  2826. 'claim' => $d['claim'],
  2827. ));
  2828. } else {
  2829. if ($d['package'] == 1) {
  2830. $total = 1500;
  2831. } else {
  2832. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2833. }
  2834. array_push($combineData, array(
  2835. 'index' => $d['index'],
  2836. 'contract' => $d['contract'],
  2837. 'wo' => $d['wo'],
  2838. 'activation' => $d['activation'],
  2839. 'name' => $d['name'],
  2840. 'address' => $d['address'],
  2841. 'package' => $d['package'],
  2842. 'retail_price' => $d['retail_price'],
  2843. 'incentives1' => '250% + RM50',
  2844. 'incentives2' => '',
  2845. 'total' => 'RM ' . $total,
  2846. 'claim' => $d['claim'],
  2847. ));
  2848. }
  2849. }
  2850. } else if (count($dataSeptemberB) < 50) {
  2851. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2852. if ($d['contract'] == '12') {
  2853. array_push($combineData, array(
  2854. 'index' => $d['index'],
  2855. 'contract' => $d['contract'],
  2856. 'wo' => $d['wo'],
  2857. 'activation' => $d['activation'],
  2858. 'name' => $d['name'],
  2859. 'address' => $d['address'],
  2860. 'package' => $d['package'],
  2861. 'retail_price' => $d['retail_price'],
  2862. 'incentives1' => $d['incentives1'],
  2863. 'incentives2' => $d['incentives2'],
  2864. 'total' => $d['total'],
  2865. 'claim' => $d['claim'],
  2866. ));
  2867. } else {
  2868. if ($d['package'] == 1) {
  2869. $total = 1500;
  2870. } else {
  2871. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2872. }
  2873. array_push($combineData, array(
  2874. 'index' => $d['index'],
  2875. 'contract' => $d['contract'],
  2876. 'wo' => $d['wo'],
  2877. 'activation' => $d['activation'],
  2878. 'name' => $d['name'],
  2879. 'address' => $d['address'],
  2880. 'package' => $d['package'],
  2881. 'retail_price' => $d['retail_price'],
  2882. 'incentives1' => '250%',
  2883. 'incentives2' => '',
  2884. 'total' => 'RM ' . $total,
  2885. 'claim' => $d['claim'],
  2886. ));
  2887. }
  2888. }
  2889. }
  2890. }
  2891. foreach ($dataOctoberR as $key => $d) {
  2892. 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) || (date('m/Y', strtotime($d['submission'])) == '09/2020')) {
  2893. if ($d['contract'] == '24') {
  2894. if ($d['package'] == 50) {
  2895. $d['retail_price'] = 69;
  2896. } elseif ($d['package'] == 100) {
  2897. $d['retail_price'] = 89;
  2898. } elseif ($d['package'] == 500) {
  2899. $d['retail_price'] = 129;
  2900. }
  2901. }
  2902. }
  2903. if (count($dataOctoberR) >= 50) {
  2904. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2905. if ($d['contract'] == '12') {
  2906. array_push($combineData, array(
  2907. 'index' => $d['index'],
  2908. 'contract' => $d['contract'],
  2909. 'wo' => $d['wo'],
  2910. 'activation' => $d['activation'],
  2911. 'name' => $d['name'],
  2912. 'address' => $d['address'],
  2913. 'package' => $d['package'],
  2914. 'retail_price' => $d['retail_price'],
  2915. 'incentives1' => $d['incentives1'],
  2916. 'incentives2' => $d['incentives2'],
  2917. 'total' => $d['total'],
  2918. 'claim' => $d['claim'],
  2919. ));
  2920. } else {
  2921. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  2922. array_push($combineData, array(
  2923. 'index' => $d['index'],
  2924. 'contract' => $d['contract'],
  2925. 'wo' => $d['wo'],
  2926. 'activation' => $d['activation'],
  2927. 'name' => $d['name'],
  2928. 'address' => $d['address'],
  2929. 'package' => $d['package'],
  2930. 'retail_price' => $d['retail_price'],
  2931. 'incentives1' => '250% + RM50',
  2932. 'incentives2' => $d['incentives2'],
  2933. 'total' => 'RM ' . $total,
  2934. 'claim' => $d['claim'],
  2935. ));
  2936. }
  2937. }
  2938. } else if (count($dataOctoberR) < 50) {
  2939. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2940. if ($d['contract'] == '12') {
  2941. array_push($combineData, array(
  2942. 'index' => $d['index'],
  2943. 'contract' => $d['contract'],
  2944. 'wo' => $d['wo'],
  2945. 'activation' => $d['activation'],
  2946. 'name' => $d['name'],
  2947. 'address' => $d['address'],
  2948. 'package' => $d['package'],
  2949. 'retail_price' => $d['retail_price'],
  2950. 'incentives1' => $d['incentives1'],
  2951. 'incentives2' => $d['incentives2'],
  2952. 'total' => $d['total'],
  2953. 'claim' => $d['claim'],
  2954. ));
  2955. } else {
  2956. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  2957. array_push($combineData, array(
  2958. 'index' => $d['index'],
  2959. 'contract' => $d['contract'],
  2960. 'wo' => $d['wo'],
  2961. 'activation' => $d['activation'],
  2962. 'name' => $d['name'],
  2963. 'address' => $d['address'],
  2964. 'package' => $d['package'],
  2965. 'retail_price' => $d['retail_price'],
  2966. 'incentives1' => '250%',
  2967. 'incentives2' => $d['incentives2'],
  2968. 'total' => 'RM ' . $total,
  2969. 'claim' => $d['claim'],
  2970. ));
  2971. }
  2972. }
  2973. }
  2974. }
  2975. foreach ($dataOctoberB as $key => $d) {
  2976. 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) || (date('m/Y', strtotime($d['submission'])) == '09/2020')) {
  2977. if ($d['contract'] == '24') {
  2978. if ($d['package'] == 50) {
  2979. $d['retail_price'] = 89;
  2980. } elseif ($d['package'] == 100) {
  2981. $d['retail_price'] = 119;
  2982. } elseif ($d['package'] == 300) {
  2983. $d['retail_price'] = 179;
  2984. } elseif ($d['package'] == 500) {
  2985. $d['retail_price'] = 249;
  2986. }
  2987. }
  2988. }
  2989. if (count($dataOctoberB) >= 50) {
  2990. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  2991. if ($d['contract'] == '12') {
  2992. array_push($combineData, array(
  2993. 'index' => $d['index'],
  2994. 'contract' => $d['contract'],
  2995. 'wo' => $d['wo'],
  2996. 'activation' => $d['activation'],
  2997. 'name' => $d['name'],
  2998. 'address' => $d['address'],
  2999. 'package' => $d['package'],
  3000. 'retail_price' => $d['retail_price'],
  3001. 'incentives1' => $d['incentives1'],
  3002. 'incentives2' => $d['incentives2'],
  3003. 'total' => $d['total'],
  3004. 'claim' => $d['claim'],
  3005. ));
  3006. } else {
  3007. if ($d['package'] == 1) {
  3008. $total = 1500;
  3009. } else {
  3010. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
  3011. }
  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' => '250% + RM50',
  3022. 'incentives2' => '',
  3023. 'total' => 'RM ' . $total,
  3024. 'claim' => $d['claim'],
  3025. ));
  3026. }
  3027. }
  3028. } else if (count($dataOctoberB) < 50) {
  3029. if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
  3030. if ($d['contract'] == '12') {
  3031. array_push($combineData, array(
  3032. 'index' => $d['index'],
  3033. 'contract' => $d['contract'],
  3034. 'wo' => $d['wo'],
  3035. 'activation' => $d['activation'],
  3036. 'name' => $d['name'],
  3037. 'address' => $d['address'],
  3038. 'package' => $d['package'],
  3039. 'retail_price' => $d['retail_price'],
  3040. 'incentives1' => $d['incentives1'],
  3041. 'incentives2' => $d['incentives2'],
  3042. 'total' => $d['total'],
  3043. 'claim' => $d['claim'],
  3044. ));
  3045. } else {
  3046. if ($d['package'] == 1) {
  3047. $total = 1500;
  3048. } else {
  3049. $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
  3050. }
  3051. array_push($combineData, array(
  3052. 'index' => $d['index'],
  3053. 'contract' => $d['contract'],
  3054. 'wo' => $d['wo'],
  3055. 'activation' => $d['activation'],
  3056. 'name' => $d['name'],
  3057. 'address' => $d['address'],
  3058. 'package' => $d['package'],
  3059. 'retail_price' => $d['retail_price'],
  3060. 'incentives1' => '250%',
  3061. 'incentives2' => '',
  3062. 'total' => 'RM ' . $total,
  3063. 'claim' => $d['claim'],
  3064. ));
  3065. }
  3066. }
  3067. }
  3068. }
  3069. } else if ($year == '2020' && ($month == '12')) {
  3070. $dataDecemberR = $this->returnDataR($company, '2020', '12');
  3071. foreach ($dataDecemberR as $r) {
  3072. $combineData[] = $r;
  3073. }
  3074. $dataDecemberB = $this->returnDataB($company, '2020', '12');
  3075. foreach ($dataDecemberB as $b) {
  3076. if ((date('m/Y', strtotime($b['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($b['submission'])) >= '21/12/2020') {
  3077. if (strpos($b['address'], 'CYBERJAYA') !== false && $b['contract'] == '24' && $b['package'] == 1) {
  3078. $b['retail_price'] = 999;
  3079. }
  3080. $count_businessCyber[] = $b;
  3081. } else {
  3082. $combineData[] = $b;
  3083. }
  3084. }
  3085. if(!empty($count_businessCyber)){
  3086. for ($i=0;$i<count($count_businessCyber);$i++){
  3087. for($j=0;$j<51;$j++){
  3088. $total = number_format(floatval(str_replace("RM ", "", $count_businessCyber[$j]['retail_price'])) * 2.0, 2);
  3089. array_push($combineData, array(
  3090. 'index' => $count_businessCyber[$j]['index'],
  3091. 'contract' => $count_businessCyber[$j]['contract'],
  3092. 'wo' => $count_businessCyber[$j]['wo'],
  3093. 'activation' => $count_businessCyber[$j]['activation'],
  3094. 'name' => $count_businessCyber[$j]['name'],
  3095. 'address' => $count_businessCyber[$j]['address'],
  3096. 'package' => $count_businessCyber[$j]['package'],
  3097. 'retail_price' => $count_businessCyber[$j]['retail_price'],
  3098. 'incentives1' => '200%',
  3099. 'incentives2' => $count_businessCyber[$j]['incentives2'],
  3100. 'total' => 'RM ' . $total,
  3101. 'claim' => $count_businessCyber[$j]['claim'],
  3102. ));
  3103. }
  3104. for($j=51;$j>=51;$j++){
  3105. $total = number_format(floatval(str_replace("RM ", "", $count_businessCyber[$j]['retail_price'])) * 2.5, 2);
  3106. array_push($combineData, array(
  3107. 'index' => $count_businessCyber[$j]['index'],
  3108. 'contract' => $count_businessCyber[$j]['contract'],
  3109. 'wo' => $count_businessCyber[$j]['wo'],
  3110. 'activation' => $count_businessCyber[$j]['activation'],
  3111. 'name' => $count_businessCyber[$j]['name'],
  3112. 'address' => $count_businessCyber[$j]['address'],
  3113. 'package' => $count_businessCyber[$j]['package'],
  3114. 'retail_price' => $count_businessCyber[$j]['retail_price'],
  3115. 'incentives1' => '250%',
  3116. 'incentives2' => $count_businessCyber[$j]['incentives2'],
  3117. 'total' => 'RM ' . $total,
  3118. 'claim' => $count_businessCyber[$j]['claim'],
  3119. ));
  3120. }
  3121. }
  3122. }
  3123. } else {
  3124. $dataR = $this->returnDataR($company, $year, $month);
  3125. foreach ($dataR as $r) {
  3126. $combineData[] = $r;
  3127. }
  3128. $dataB = $this->returnDataB($company, $year, $month);
  3129. foreach ($dataB as $b) {
  3130. $combineData[] = $b;
  3131. }
  3132. }
  3133. $i = 0;
  3134. $nested_data = array();
  3135. if (!empty($combineData)) {
  3136. foreach ($combineData as $c) {
  3137. $update_dealer = DealerClaim::where('wo', $c['wo'])->first();
  3138. if (!empty($update_dealer)) {
  3139. $update_dealer->incentives1 = $c['incentives1'];
  3140. $update_dealer->incentives2 = $c['incentives2'];
  3141. $update_dealer->retail_price = $c['retail_price'];
  3142. $update_dealer->total_claim = $c['total'];
  3143. $update_dealer->save();
  3144. }
  3145. }
  3146. }
  3147. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3148. $q->with('Form');
  3149. }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->get();
  3150. if (!empty($dataClaim)) {
  3151. foreach ($dataClaim as $c) {
  3152. $address = '';
  3153. $name = '';
  3154. if ($c->Subscriber->Form->type_application == 'R') {
  3155. if ($c->Subscriber->street != '') {
  3156. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3157. } else {
  3158. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3159. }
  3160. $name = $c->Subscriber->name;
  3161. } else if ($c->Subscriber->Form->type_application == 'B') {
  3162. if ($c->Subscriber->unit_no != '') {
  3163. $unit = $c->Subscriber->unit_no;
  3164. } else {
  3165. $unit = ' ';
  3166. }
  3167. if ($c->Subscriber->building_name == null) {
  3168. $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3169. } else {
  3170. $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3171. }
  3172. $name = $c->Subscriber->company_name;
  3173. }
  3174. $i++;
  3175. array_push($final, array(
  3176. 'index' => $c->formT,
  3177. 'contract' => $c->contract,
  3178. 'wo' => $c->wo,
  3179. 'activated_dt' => $c->activated_dt,
  3180. 'name' => $name,
  3181. 'address' => $address,
  3182. 'package' => $c->package,
  3183. 'retail_price' => $c->retail_price,
  3184. 'incentives1' => $c->incentives1,
  3185. 'incentives2' => $c->incentives2,
  3186. 'total' => $c->total_claim,
  3187. 'claimed' => $c->claim_dt,
  3188. ));
  3189. }
  3190. }
  3191. foreach ($final as $f) {
  3192. $basic_total += floatval(str_replace('RM ', '', $f['total']));
  3193. }
  3194. // Calculate extra incentves
  3195. // if($month == '1' && $year == '2020'){
  3196. // if(count($count_cyberjaya) > 50){
  3197. // $balance = count($count_cyberjaya) - 50;
  3198. // $extra += $balance * 50;
  3199. // }
  3200. // if(count($count_jasin) > 10){
  3201. // $balance = count($count_jasin) - 10;
  3202. // $extra += $balance * 50;
  3203. // }
  3204. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  3205. // if(count($count_cyberjaya) > 50){
  3206. // $balance = count($count_cyberjaya) - 50;
  3207. // $extra += $balance * 50;
  3208. // }
  3209. // if(count($count_jasin) > 20){
  3210. // $balance = count($count_jasin) - 10;
  3211. // $extra += $balance * 50;
  3212. // }
  3213. // }else {
  3214. // $extra = 0;
  3215. // }
  3216. $extra = 0;
  3217. $totals = $basic_total + $extra;
  3218. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  3219. // $pdf->setPaper('A4', 'landscape');
  3220. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  3221. // return $pdf->download( $pdfName );
  3222. return $final;
  3223. }
  3224. // else if($year!='null' && $month!='null' && $app!='null'){
  3225. // $count_cyberjaya = array(); $count_jasin = array();
  3226. // $extra = 0; $basic_total = 0; $totals = 0;
  3227. // if($app == 'Residential'){
  3228. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  3229. // $dataDis = $this->returnDataR($company,'2019','12');
  3230. // $dataJan = $this->returnDataR($company,'2020','1');
  3231. // foreach ($dataDis as $key => $d) {
  3232. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  3233. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  3234. // $count_cyberjaya[] = $d;
  3235. // }
  3236. // if (strpos($d['address'], 'Jasin') !== false) {
  3237. // $count_jasin[] = $d;
  3238. // }
  3239. // }else if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020' && date('d/m/Y', strtotime($d['activation'])) <= '31/7/2020'){
  3240. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  3241. // $count_cyberjaya[] = $d;
  3242. // }
  3243. // if (strpos($d['address'], 'Jasin') !== false) {
  3244. // $count_jasin[] = $d;
  3245. // }
  3246. // }else {
  3247. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3248. // $combineData[] = $d;
  3249. // }
  3250. // }
  3251. // }
  3252. // foreach ($dataJan as $key => $d) {
  3253. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  3254. // $count_cyberjaya[] = $d;
  3255. // }
  3256. // if (strpos($d['address'], 'Jasin') !== false) {
  3257. // $count_jasin[] = $d;
  3258. // }
  3259. // }
  3260. // // Store to combineData New Incentives Cyberjaya
  3261. // foreach ($count_cyberjaya as $key => $d) {
  3262. // if(count($count_cyberjaya) > 50){
  3263. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3264. // if($d['contract'] == '12'){
  3265. // array_push($combineData, array(
  3266. // 'index' => $d['index'],
  3267. // 'contract' => $d['contract'],
  3268. // 'wo' => $d['wo'],
  3269. // 'activation' => $d['activation'],
  3270. // 'name' => $d['name'],
  3271. // 'address' => $d['address'],
  3272. // 'package' => $d['package'],
  3273. // 'retail_price' => $d['retail_price'],
  3274. // 'incentives1' => $d['incentives1'],
  3275. // 'incentives2' => $d['incentives2'],
  3276. // 'total' => $d['total'],
  3277. // 'claim' => $d['claim'],
  3278. // ));
  3279. // }else {
  3280. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  3281. // array_push($combineData, array(
  3282. // 'index' => $d['index'],
  3283. // 'contract' => $d['contract'],
  3284. // 'wo' => $d['wo'],
  3285. // 'activation' => $d['activation'],
  3286. // 'name' => $d['name'],
  3287. // 'address' => $d['address'],
  3288. // 'package' => $d['package'],
  3289. // 'retail_price' => $d['retail_price'],
  3290. // 'incentives1' => '230%',
  3291. // 'incentives2' => $d['incentives2'],
  3292. // 'total' => 'RM '.$total,
  3293. // 'claim' => $d['claim'],
  3294. // ));
  3295. // }
  3296. // }
  3297. // }else if(count($count_cyberjaya) < 50){
  3298. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3299. // array_push($combineData, array(
  3300. // 'index' => $d['index'],
  3301. // 'contract' => $d['contract'],
  3302. // 'wo' => $d['wo'],
  3303. // 'activation' => $d['activation'],
  3304. // 'name' => $d['name'],
  3305. // 'address' => $d['address'],
  3306. // 'package' => $d['package'],
  3307. // 'retail_price' => $d['retail_price'],
  3308. // 'incentives1' => $d['incentives1'],
  3309. // 'incentives2' => $d['incentives2'],
  3310. // 'total' => $d['total'],
  3311. // 'claim' => $d['claim'],
  3312. // ));
  3313. // }
  3314. // }
  3315. // }
  3316. // // Store to combineData New Incentives Jasin
  3317. // foreach ($count_jasin as $key => $d) {
  3318. // if(count($count_jasin) > 10){
  3319. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3320. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  3321. // array_push($combineData, array(
  3322. // 'index' => $d['index'],
  3323. // 'contract' => $d['contract'],
  3324. // 'wo' => $d['wo'],
  3325. // 'activation' => $d['activation'],
  3326. // 'name' => $d['name'],
  3327. // 'address' => $d['address'],
  3328. // 'package' => $d['package'],
  3329. // 'retail_price' => $d['retail_price'],
  3330. // 'incentives1' => '230%',
  3331. // 'incentives2' => $d['incentives2'],
  3332. // 'total' => 'RM '.$total,
  3333. // 'claim' => $d['claim'],
  3334. // ));
  3335. // }
  3336. // }else if(count($count_jasin) < 10){
  3337. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3338. // array_push($combineData, array(
  3339. // 'index' => $d['index'],
  3340. // 'contract' => $d['contract'],
  3341. // 'wo' => $d['wo'],
  3342. // 'activation' => $d['activation'],
  3343. // 'name' => $d['name'],
  3344. // 'address' => $d['address'],
  3345. // 'package' => $d['package'],
  3346. // 'retail_price' => $d['retail_price'],
  3347. // 'incentives1' => $d['incentives1'],
  3348. // 'incentives2' => $d['incentives2'],
  3349. // 'total' => $d['total'],
  3350. // 'claim' => $d['claim'],
  3351. // ));
  3352. // }
  3353. // }
  3354. // }
  3355. // }else {
  3356. // $dataR = $this->returnDataR($company,$year,$month);
  3357. // foreach($dataR as $r){
  3358. // $combineData[] = $r;
  3359. // }
  3360. // }
  3361. // }else if($app == 'Business'){
  3362. // $dataB = $this->returnDataB($company,$year,$month);
  3363. // }
  3364. // foreach($dataB as $b){
  3365. // $combineData[] = $b;
  3366. // }
  3367. // $i = 0;
  3368. // $nested_data = array();
  3369. // if(!empty($combineData)){
  3370. // foreach ($combineData as $c){
  3371. // $i++;
  3372. // array_push($final, array(
  3373. // 'index' => $c['index'],
  3374. // 'contract' => $c['contract'],
  3375. // 'wo' => $c['wo'],
  3376. // 'activated_dt' => $c['activation'],
  3377. // 'name' => $c['name'],
  3378. // 'address' => $c['address'],
  3379. // 'package' => $c['package'],
  3380. // 'retail_price' => $c['retail_price'],
  3381. // 'incentives1' => $c['incentives1'],
  3382. // 'incentives2' => $c['incentives2'],
  3383. // 'total' => $c['total'],
  3384. // 'claimed' => $c['claim'],
  3385. // ));
  3386. // }
  3387. // }
  3388. // foreach($final as $f){
  3389. // $basic_total += floatval(str_replace('RM ', '', $f['total']));
  3390. // }
  3391. // //Calculate extra incentves
  3392. // if($month == '1' && $year == '2020'){
  3393. // if(count($count_cyberjaya) > 50){
  3394. // $balance = count($count_cyberjaya) - 50;
  3395. // $extra += $balance * 50;
  3396. // }
  3397. // if(count($count_jasin) > 10){
  3398. // $balance = count($count_jasin) - 10;
  3399. // $extra += $balance * 50;
  3400. // }
  3401. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  3402. // if(count($count_cyberjaya) > 50){
  3403. // $balance = count($count_cyberjaya) - 50;
  3404. // $extra += $balance * 50;
  3405. // }
  3406. // if(count($count_jasin) > 20){
  3407. // $balance = count($count_jasin) - 10;
  3408. // $extra += $balance * 50;
  3409. // }
  3410. // }else {
  3411. // $extra = 0;
  3412. // }
  3413. // $totals = $basic_total + $extra;
  3414. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  3415. // $pdf->setPaper('A4', 'landscape');
  3416. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  3417. // return $pdf->download( $pdfName );
  3418. // }
  3419. }
  3420. public function update_total_claim()
  3421. {
  3422. $dealer = DealerClaim::all();
  3423. foreach ($dealer as $key => $d) {
  3424. $claim = str_replace("RM ", "", $d->total_claim);
  3425. $price = str_replace("RM ", "", $d->retail_price);
  3426. $d->total_claim = floatval($claim);
  3427. $d->retail_price = floatval($price);
  3428. $d->save();
  3429. }
  3430. }
  3431. }