You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MarketingController.php 122KB

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