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