您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DealerController.php 105KB

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