選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

DealerController.php 114KB

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