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

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