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

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