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

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