Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

MarketingController.php 122KB

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