Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DealerController.php 114KB

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