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 123KB

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