You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

MarketingController.php 124KB

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