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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028
  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 ($a->Form->type_application == "R") {
  1024. $r++;
  1025. $n1 = 'R';
  1026. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1027. if (!empty($customer)) {
  1028. array_push($nested_data, array(
  1029. 'index' => $r . $n1,
  1030. 'nature_work' => $a->nature_work,
  1031. 'wo' => $a->wo,
  1032. 'customer_name' => $customer->name,
  1033. 'customer_phone' => $customer->phone1,
  1034. 'customer_unit' => $customer->unit_no,
  1035. 'customer_building' => $customer->building_name,
  1036. 'customer_postcode' => $customer->postcode,
  1037. 'customer_city' => $customer->city,
  1038. 'contractor_id' => $contractor->name,
  1039. 'installer_id' => $var1,
  1040. 'dateTimeEnd' => $a->dateTimeEnd,
  1041. 'status' => $a->status,
  1042. ));
  1043. }
  1044. }
  1045. if ($a->Form->type_application == "B") {
  1046. $b++;
  1047. $n1 = 'B';
  1048. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1049. if (!empty($customer)) {
  1050. array_push($nested_data, array(
  1051. 'index' => $b . $n1,
  1052. 'nature_work' => $a->nature_work,
  1053. 'wo' => $a->wo,
  1054. 'customer_name' => $customer->name,
  1055. 'customer_phone' => $customer->phone1,
  1056. 'customer_unit' => '-',
  1057. 'customer_building' => $customer->company_name,
  1058. 'customer_postcode' => $customer->postcode,
  1059. 'customer_city' => $customer->city,
  1060. 'contractor_id' => $contractor->name,
  1061. 'installer_id' => $var1,
  1062. 'dateTimeEnd' => $a->dateTimeEnd,
  1063. 'status' => $a->status,
  1064. ));
  1065. }
  1066. }
  1067. }
  1068. }
  1069. if ($year == 'null' && $month == 'null' & $status == 'null') {
  1070. $i = 0;
  1071. // $subDetail = Form::with('WorkOrder','Subscriber')->where('_id', $a->id)->first();
  1072. $wo = WorkOrder::with('Form')->orderBy('dateTimeStart', 'desc')->get();
  1073. foreach ($wo as $a) {
  1074. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1075. $contractor = Company::where('_id', $a->contractor_id)->first();
  1076. $installer = StaffDetail::where('_id', $a->installer_id)->withTrashed()->first();
  1077. $var1 = "";
  1078. if (!empty($installer)) {
  1079. $var1 = $installer->name;
  1080. }
  1081. if ($a->Form->type_application == "R") {
  1082. $r++;
  1083. $n1 = 'R';
  1084. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1085. if (!empty($customer)) {
  1086. array_push($nested_data, array(
  1087. 'index' => $r . $n1,
  1088. 'nature_work' => $a->nature_work,
  1089. 'wo' => $a->wo,
  1090. 'customer_name' => $customer->name,
  1091. 'customer_phone' => $customer->phone1,
  1092. 'customer_unit' => $customer->unit_no,
  1093. 'customer_building' => $customer->building_name,
  1094. 'customer_postcode' => $customer->postcode,
  1095. 'customer_city' => $customer->city,
  1096. 'contractor_id' => $contractor->name,
  1097. 'installer_id' => $var1,
  1098. 'dateTimeEnd' => $a->dateTimeEnd,
  1099. 'status' => $a->status,
  1100. ));
  1101. }
  1102. }
  1103. if ($a->Form->type_application == "B") {
  1104. $b++;
  1105. $n1 = 'B';
  1106. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1107. if (!empty($customer)) {
  1108. array_push($nested_data, array(
  1109. 'index' => $b . $n1,
  1110. 'nature_work' => $a->nature_work,
  1111. 'wo' => $a->wo,
  1112. 'customer_name' => $customer->name,
  1113. 'customer_phone' => $customer->phone1,
  1114. 'customer_unit' => '-',
  1115. 'customer_building' => $customer->company_name,
  1116. 'customer_postcode' => $customer->postcode,
  1117. 'customer_city' => $customer->city,
  1118. 'contractor_id' => $contractor->name,
  1119. 'installer_id' => $var1,
  1120. 'dateTimeEnd' => $a->dateTimeEnd,
  1121. 'status' => $a->status,
  1122. ));
  1123. }
  1124. }
  1125. }
  1126. }
  1127. if ($year != '' && $month != '' && $status != '') {
  1128. $start_month = $year . "-" . $month . "-01 00:00:00";
  1129. $end_month = $year . "-" . $month . "-32 23:59:59";
  1130. // $wo = WorkOrder::orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->where('status',$status)->get();
  1131. $i = 0;
  1132. // $subDetail = Form::with('WorkOrder','Subscriber')->where('_id', $a->id)->first();
  1133. $wo = WorkOrder::with('Form')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->where('status', $status)->get();
  1134. foreach ($wo as $a) {
  1135. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1136. $contractor = Company::where('_id', $a->contractor_id)->first();
  1137. $installer = StaffDetail::where('_id', $a->installer_id)->withTrashed()->first();
  1138. $var1 = "";
  1139. if (!empty($installer)) {
  1140. $var1 = $installer->name;
  1141. }
  1142. if ($a->Form->type_application == "R") {
  1143. $r++;
  1144. $n1 = 'R';
  1145. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1146. if (!empty($customer)) {
  1147. array_push($nested_data, array(
  1148. 'index' => $r . $n1,
  1149. 'nature_work' => $a->nature_work,
  1150. 'wo' => $a->wo,
  1151. 'customer_name' => $customer->name,
  1152. 'customer_phone' => $customer->phone1,
  1153. 'customer_unit' => $customer->unit_no,
  1154. 'customer_building' => $customer->building_name,
  1155. 'customer_postcode' => $customer->postcode,
  1156. 'customer_city' => $customer->city,
  1157. 'contractor_id' => $contractor->name,
  1158. 'installer_id' => $var1,
  1159. 'dateTimeEnd' => $a->dateTimeEnd,
  1160. 'status' => $a->status,
  1161. ));
  1162. }
  1163. }
  1164. if ($a->Form->type_application == "B") {
  1165. $b++;
  1166. $n1 = 'B';
  1167. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1168. if (!empty($customer)) {
  1169. array_push($nested_data, array(
  1170. 'index' => $b . $n1,
  1171. 'nature_work' => $a->nature_work,
  1172. 'wo' => $a->wo,
  1173. 'customer_name' => $customer->name,
  1174. 'customer_phone' => $customer->phone1,
  1175. 'customer_unit' => '-',
  1176. 'customer_building' => $customer->company_name,
  1177. 'customer_postcode' => $customer->postcode,
  1178. 'customer_city' => $customer->city,
  1179. 'contractor_id' => $contractor->name,
  1180. 'installer_id' => $var1,
  1181. 'dateTimeEnd' => $a->dateTimeEnd,
  1182. 'status' => $a->status,
  1183. ));
  1184. }
  1185. }
  1186. }
  1187. }
  1188. if ($year != '' && $month != '' && $status == 'null') {
  1189. $start_month = $year . "-" . $month . "-01 00:00:00";
  1190. $end_month = $year . "-" . $month . "-32 23:59:59";
  1191. $i = 0;
  1192. // $subDetail = Form::with('WorkOrder','Subscriber')->where('_id', $a->id)->first();
  1193. $wo = WorkOrder::with('Form')->orderBy('dateTimeStart', 'desc')->whereBetween('dateTimeStart', [$start_month, $end_month])->get();
  1194. foreach ($wo as $a) {
  1195. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1196. $contractor = Company::where('_id', $a->contractor_id)->first();
  1197. $installer = StaffDetail::where('_id', $a->installer_id)->withTrashed()->first();
  1198. $var1 = "";
  1199. if (!empty($installer)) {
  1200. $var1 = $installer->name;
  1201. }
  1202. if ($a->Form->type_application == "R") {
  1203. $r++;
  1204. $n1 = 'R';
  1205. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1206. if (!empty($customer)) {
  1207. array_push($nested_data, array(
  1208. 'index' => $r . $n1,
  1209. 'nature_work' => $a->nature_work,
  1210. 'wo' => $a->wo,
  1211. 'customer_name' => $customer->name,
  1212. 'customer_phone' => $customer->phone1,
  1213. 'customer_unit' => $customer->unit_no,
  1214. 'customer_building' => $customer->building_name,
  1215. 'customer_postcode' => $customer->postcode,
  1216. 'customer_city' => $customer->city,
  1217. 'contractor_id' => $contractor->name,
  1218. 'installer_id' => $var1,
  1219. 'dateTimeEnd' => $a->dateTimeEnd,
  1220. 'status' => $a->status,
  1221. ));
  1222. }
  1223. }
  1224. if ($a->Form->type_application == "B") {
  1225. $b++;
  1226. $n1 = 'B';
  1227. $customer = Subscriber::where('_id', $a->Form->_id)->first();
  1228. if (!empty($customer)) {
  1229. array_push($nested_data, array(
  1230. 'index' => $b . $n1,
  1231. 'nature_work' => $a->nature_work,
  1232. 'wo' => $a->wo,
  1233. 'customer_name' => $customer->name,
  1234. 'customer_phone' => $customer->phone1,
  1235. 'customer_unit' => '-',
  1236. 'customer_building' => $customer->company_name,
  1237. 'customer_postcode' => $customer->postcode,
  1238. 'customer_city' => $customer->city,
  1239. 'contractor_id' => $contractor->name,
  1240. 'installer_id' => $var1,
  1241. 'dateTimeEnd' => $a->dateTimeEnd,
  1242. 'status' => $a->status,
  1243. ));
  1244. }
  1245. }
  1246. }
  1247. }
  1248. return \DataTables::of($nested_data)->make(true);
  1249. }
  1250. /**
  1251. ALL DOWN HERE ARE FOR TESTING AND UTILITIES PURPOSES
  1252. **/
  1253. public function woToLaravel()
  1254. {
  1255. }
  1256. public function checktry()
  1257. {
  1258. $data = Subscriber::where('wo', '!=', '')->get();
  1259. $wo = WorkOrder::all()->toArray();
  1260. $adawork = array();
  1261. $newarr = array();
  1262. $hmm = array();
  1263. $i = 0;
  1264. foreach ($data as $d) {
  1265. if (array_search($d->wo, array_column($wo, 'wo')) !== False) { // search value in the array
  1266. // echo "FOUND";
  1267. } else {
  1268. $adawork[] = $d->wo;
  1269. $i++;
  1270. }
  1271. }
  1272. dd($adawork);
  1273. }
  1274. //Insert data into Commission_Laravel table
  1275. public function commissionlara()
  1276. {
  1277. $olddata = Commission::all();
  1278. foreach ($olddata as $od) {
  1279. $subsData = [
  1280. 'formT' => $od['formT'],
  1281. 'ranges' => $od['ranges'],
  1282. 'comm' => $od['comm'],
  1283. 'category' => $od['category'],
  1284. 'contract' => $od['contract'],
  1285. 'reg_time' => $od['reg_time'],
  1286. 'packageR' => $od['packageR'],
  1287. ];
  1288. Commission::create($subsData);
  1289. }
  1290. return "success";
  1291. }
  1292. //Insert data into Company_Laravel table
  1293. public function companylara()
  1294. {
  1295. $olddata = Company::all();
  1296. foreach ($olddata as $od) {
  1297. $subsData = [
  1298. 'name' => $od['name'],
  1299. 'address' => $od['address'],
  1300. 'city' => $od['city'],
  1301. 'state' => $od['state'],
  1302. 'postcode' => $od['postcode'],
  1303. 'color' => $od['color'],
  1304. 'team' => $od['team'],
  1305. 'status' => $od['status'],
  1306. 'reg_time' => $od['reg_time'],
  1307. ];
  1308. Company::create($subsData);
  1309. }
  1310. }
  1311. //Insert data into Claim_Laravel table
  1312. public function claimtolara()
  1313. {
  1314. $olddata = DealerClaim::all();
  1315. foreach ($olddata as $od) {
  1316. $subsData = [
  1317. '_id' => $od['_id'],
  1318. 'formT' => $od['formT'],
  1319. 'wo' => $od['wo'],
  1320. 'dateTimeStart' => $od['dateTimeEnd'],
  1321. 'customer_id' => $od['customer_id'],
  1322. 'contractor_id' => $od['contractor_id'],
  1323. 'installer_id' => $od['installer_id'],
  1324. 'nature_work' => $od['nature_work'],
  1325. 'sub_category' => $od['sub_category'],
  1326. 'img_url' => $od['img_url'],
  1327. 'docket' => $od['docket'],
  1328. 'status' => $od['status'],
  1329. 'remark' => $od['remark'],
  1330. 'remarks_inst' => $od['remarks_inst'],
  1331. 'customer_code' => $od['customer_code'],
  1332. 'package_bandwidth' => $od['package_bandwidth'],
  1333. 'subnet_mask' => $od['subnet_mask'],
  1334. 'login_id' => $od['login_id'],
  1335. 'password' => $od['password'],
  1336. 'wan_ip' => $od['wan_ip'],
  1337. 'lan_ip' => $od['lan_ip'],
  1338. 'gateway' => $od['getaway'],
  1339. 'service_id1' => $od['service_id2'],
  1340. 'ip_address_onu' => $od['ip_address_onu'],
  1341. 'gateway_onu' => $od['gateaway_onu'],
  1342. 'subnet_mask_onu' => $od['subnet_mask_onu'],
  1343. 'ip_address_srp' => $od['ip_address_srp'],
  1344. 'dectphone1' => $od['dectphone1'],
  1345. 'dectphone2' => $od['dectphone2'],
  1346. 'onu' => $od['onu'],
  1347. 'router' => $od['router'],
  1348. 'wifi_extender' => $od['wifi_extender'],
  1349. 'reg_time' => $od['reg_time'],
  1350. ];
  1351. DealerClaim::create($subsData);
  1352. }
  1353. }
  1354. //Add total form by month to Claim Laravel collection
  1355. public function claimaddtotal()
  1356. {
  1357. $getdata = DealerClaim::all();
  1358. $total = 0;
  1359. foreach ($getdata as $a) {
  1360. if ($a->activated_my == "2/2019") {
  1361. $total += 1;
  1362. }
  1363. }
  1364. $adddata = DealerClaim::all();
  1365. foreach ($adddata as $a) {
  1366. if ($a->activated_my == "2/2019") {
  1367. $a->total_form_by_month = $total;
  1368. $a->save();
  1369. }
  1370. }
  1371. }
  1372. public function generateWorkOrderPDF($wo)
  1373. {
  1374. $id = Auth::guard('ms')->id();
  1375. $user = Staff::with('StaffDetail')->find($id);
  1376. $wo = WorkOrder::where('wo', $wo)->first();
  1377. $form = Form::with('PackageDetail', 'Subscriber')->where('_id', $wo->_id)->first();
  1378. $product = Product::where('formT', $form->type_application)->where('speed', $form->PackageDetail->name)->first();
  1379. if (empty($form->customer_category)) {
  1380. $category = '';
  1381. } else {
  1382. $category = $form->customer_category;
  1383. }
  1384. if (empty($product)) {
  1385. $product = 'RMbps';
  1386. } else {
  1387. $product = $product->package_name;
  1388. }
  1389. $created_by = Staff::with('StaffDetail')->where("_id", $wo->created_by)->first();
  1390. if (empty($created_by)) {
  1391. $created_by = '';
  1392. }
  1393. $created_at = Carbon::parse($wo->created_at)->toDateTimeString();
  1394. $address = '';
  1395. if ($form->type_application == 'R') {
  1396. if ($form->Subscriber->street != '') {
  1397. $address = $form->Subscriber->unit_no . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1398. } else {
  1399. $address = $form->Subscriber->unit_no . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1400. }
  1401. } else if ($form->type_application == 'B') {
  1402. if ($form->Subscriber->unit_no != '') {
  1403. $address = $form->Subscriber->unit_no . ', ' . $form->Subscriber->company_name . ', ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1404. } else {
  1405. $address = $form->Subscriber->company_name . ', ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1406. }
  1407. }
  1408. $pdf = PDF::loadView('pdf.workorder-pdf', compact('wo', 'form', 'product', 'created_at', 'created_by', 'address', 'category'));
  1409. $pdf->setPaper('A4', 'potrait');
  1410. return $pdf->stream();
  1411. }
  1412. public function generateDocketPDF($do)
  1413. {
  1414. $id = Auth::guard('ms')->id();
  1415. $user = Staff::with('StaffDetail')->find($id);
  1416. $docket = Docket::with('WorkOrder')->where('docket_id', $do)->first();
  1417. if (!empty($docket)) {
  1418. $form = Form::with('Subscriber', 'PackageDetail')->where('_id', $docket->WorkOrder->_id)->first();
  1419. $address = '';
  1420. if ($form->type_application == 'R') {
  1421. if ($form->Subscriber->street != '') {
  1422. $address = $form->Subscriber->unit_no . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1423. } else {
  1424. $address = $form->Subscriber->unit_no . ' , ' . $form->Subscriber->building_name . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1425. }
  1426. } else if ($form->type_application == 'B') {
  1427. if ($form->Subscriber->unit_no != '') {
  1428. $address = $form->Subscriber->unit_no . ', ' . $form->Subscriber->company_name . ', ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1429. } else {
  1430. $address = $form->Subscriber->company_name . ', ' . $form->Subscriber->street . ' , ' . $form->Subscriber->postcode . ' , ' . $form->Subscriber->city . ' , ' . $form->Subscriber->state;
  1431. }
  1432. }
  1433. if (empty($form->customer_category)) {
  1434. $category = '';
  1435. } else {
  1436. $category = $form->customer_category;
  1437. }
  1438. $product = Product::where('formT', $form->type_application)->where('speed', $form->PackageDetail->name)->first();
  1439. $installer = Staff::with('StaffDetail')->where('_id', $docket->installer_id)->withTrashed()->first();
  1440. if (empty($product)) {
  1441. $product = 'RMbps';
  1442. } else {
  1443. $product = $product->package_name;
  1444. }
  1445. $dateTime = Carbon::parse($docket->WorkOrder->dateTimeStart)->toDateTimeString();
  1446. $edateTime = Carbon::parse($docket->end_job)->toDateTimeString();
  1447. $pdf = PDF::loadView('pdf.docket-pdf', compact('docket', 'form', 'address', 'product', 'installer', 'dateTime', 'edateTime', 'category'));
  1448. $pdf->setPaper('A4', 'potrait');
  1449. return $pdf->stream();
  1450. }
  1451. }
  1452. public function mClaimAll($agent_id)
  1453. {
  1454. $id = Auth::guard('ms')->id();
  1455. $user = Staff::with('StaffDetail')->find($id);
  1456. $getid = $agent_id;
  1457. $temp = StaffDetail::where('_id', $agent_id)->first();
  1458. $company = $temp->company_id;
  1459. return view('market.claim_list', compact('user', 'getid', 'company'));
  1460. }
  1461. //Show claim list by company
  1462. public function mClaimListAll($company)
  1463. {
  1464. $id = Auth::guard('ms')->id();
  1465. $user = Staff::with('StaffDetail')->find($id);
  1466. $dealer_claimAll = DealerClaim::where('dealer', $company)->orderBy('activated_dt', 'desc')->get();
  1467. $i = 0;
  1468. $nested_data = array();
  1469. foreach ($dealer_claimAll as $c) {
  1470. $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first();
  1471. $address = '';
  1472. $name = '';
  1473. if ($customer->Form->type_application == 'R') {
  1474. if ($customer->street != '') {
  1475. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1476. } else {
  1477. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1478. }
  1479. $name = $customer->name;
  1480. } else if ($customer->Form->type_application == 'B') {
  1481. if ($customer->unit_no != '') {
  1482. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1483. } else {
  1484. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1485. }
  1486. $name = $customer->company_name;
  1487. }
  1488. $i++;
  1489. array_push($nested_data, array(
  1490. 'index' => $c->formT,
  1491. 'contract' => $c->contract,
  1492. 'wo' => $c->wo,
  1493. 'activated_dt' => $c->activated_dt,
  1494. 'name' => $name,
  1495. 'address' => $address,
  1496. 'package' => $c->package,
  1497. 'retail_price' => 'RM ' . $c->retail_price,
  1498. 'incentives1' => '',
  1499. 'incentives2' => '',
  1500. 'total' => '',
  1501. 'claimed' => $c->laim_dt,
  1502. 'action' => 'null',
  1503. ));
  1504. }
  1505. return \DataTables::of($nested_data)->make(true);
  1506. }
  1507. // Get Dealer Claim Residential
  1508. public function returnDataR($company, $year, $month)
  1509. {
  1510. $dataCR = DealerClaim::where('formT', 'R')->where('dealer', $company)->orderBy('activated_dt', 'desc')->get();
  1511. $final = array();
  1512. // Month & Year
  1513. $mY = '';
  1514. if ($year != 'null' && $month != 'null') {
  1515. $mY = $month . '/' . $year;
  1516. }
  1517. if ($mY != '') {
  1518. $data12 = array();
  1519. $data24 = array();
  1520. $countD12 = 0;
  1521. $countD24 = 0;
  1522. foreach ($dataCR as $dc) {
  1523. if ($dc->activated_my == $mY || $dc->activated_my == '0' . $mY) {
  1524. if ($dc->contract == "12") {
  1525. $data12[] = $dc;
  1526. } else if ($dc->contract == "24") {
  1527. $data24[] = $dc;
  1528. }
  1529. }
  1530. }
  1531. $countD24 = count($data24);
  1532. $countD12 = count($data12);
  1533. $comm = Commission::where('formT', 'R')->get();
  1534. $commV12 = 0;
  1535. $commV24 = 0;
  1536. $comm12 = '';
  1537. $comm24 = '';
  1538. foreach ($comm as $c) {
  1539. if ($c->contract == '12') {
  1540. if (strpos($c->ranges, '>') !== false) {
  1541. $pieces = explode(">", $c->ranges);
  1542. if ($countD12 >= intval($pieces[1])) {
  1543. $commV12 = floatval($c->comm) / 100;
  1544. $comm12 = $c->comm . '%';
  1545. }
  1546. }
  1547. if (strpos($c->ranges, '-') !== false) {
  1548. $pieces = explode("-", $c->ranges);
  1549. if ($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])) {
  1550. $commV12 = floatval($c->comm) / 100;
  1551. $comm12 = $c->comm . '%';
  1552. }
  1553. }
  1554. } else if ($c->contract == '24') {
  1555. // Contract => 24
  1556. if ($countD24 != 0) {
  1557. if (strpos($c->ranges, '>') !== false) {
  1558. $pieces = explode(">", $c->ranges);
  1559. if ($countD24 > intval($pieces[1])) {
  1560. $commV24 = floatval($c->comm) / 100;
  1561. $comm24 = $c->comm . '%';
  1562. }
  1563. }
  1564. if (strpos($c->ranges, '-') !== false) {
  1565. $pieces = explode("-", $c->ranges);
  1566. if ($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])) {
  1567. $commV24 = floatval($c->comm) / 100;
  1568. $comm24 = $c->comm . '%';
  1569. }
  1570. }
  1571. }
  1572. }
  1573. }
  1574. foreach ($data12 as $key => $d) {
  1575. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1576. $address = '';
  1577. $name = '';
  1578. if ($customer->Form->type_application == 'R') {
  1579. if ($customer->street != '') {
  1580. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1581. } else {
  1582. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1583. }
  1584. $name = $customer->name;
  1585. } else if ($customer->Form->type_application == 'B') {
  1586. if ($customer->unit_no != '') {
  1587. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1588. } else {
  1589. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1590. }
  1591. $name = $customer->company_name;
  1592. }
  1593. $final[] = array(
  1594. 'index' => $d['formT'],
  1595. 'contract' => $d['contract'],
  1596. 'wo' => $d['wo'],
  1597. 'activation' => $d['activated_dt'],
  1598. 'name' => $name,
  1599. 'address' => $address,
  1600. 'package' => $d['package'],
  1601. 'retail_price' => 'RM ' . $d['retail_price'],
  1602. 'incentives1' => $comm12,
  1603. 'incentives2' => '',
  1604. 'total' => 'RM ' . number_format($d['retail_price'] * $commV12, 2),
  1605. 'claim' => $d['claim_dt'],
  1606. );
  1607. }
  1608. foreach ($data24 as $key => $d) {
  1609. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1610. $address = '';
  1611. $name = '';
  1612. if ($customer->Form->type_application == 'R') {
  1613. if ($customer->street != '') {
  1614. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1615. } else {
  1616. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1617. }
  1618. $name = $customer->name;
  1619. } else if ($customer->Form->type_application == 'B') {
  1620. if ($customer->unit_no != '') {
  1621. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1622. } else {
  1623. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1624. }
  1625. $name = $customer->company_name;
  1626. }
  1627. $final[] = array(
  1628. 'index' => $d['formT'],
  1629. 'contract' => $d['contract'],
  1630. 'wo' => $d['wo'],
  1631. 'activation' => $d['activated_dt'],
  1632. 'name' => $name,
  1633. 'address' => $address,
  1634. 'package' => $d['package'],
  1635. 'retail_price' => 'RM ' . $d['retail_price'],
  1636. 'incentives1' => $comm24,
  1637. 'incentives2' => '',
  1638. 'total' => 'RM ' . number_format($d['retail_price'] * $commV24, 2),
  1639. 'claim' => $d['claim_dt'],
  1640. );
  1641. }
  1642. } else {
  1643. foreach ($dataCR as $c) {
  1644. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1645. $address = '';
  1646. $name = '';
  1647. if ($customer->Form->type_application == 'R') {
  1648. if ($customer->street != '') {
  1649. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1650. } else {
  1651. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1652. }
  1653. $name = $customer->name;
  1654. } else if ($customer->Form->type_application == 'B') {
  1655. if ($customer->unit_no != '') {
  1656. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1657. } else {
  1658. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  1659. }
  1660. $name = $customer->company_name;
  1661. }
  1662. $final[] = array(
  1663. 'index' => $c['formT'],
  1664. 'contract' => $c['contract'],
  1665. 'wo' => $c['wo'],
  1666. 'activation' => $c['activated_dt'],
  1667. 'name' => $name,
  1668. 'address' => $address,
  1669. 'package' => $c['package'],
  1670. 'retail_price' => 'RM ' . $c['retail_price'],
  1671. 'incentives1' => '',
  1672. 'incentives2' => '',
  1673. 'total' => '',
  1674. 'claim' => $c['claim_dt'],
  1675. );
  1676. }
  1677. }
  1678. return $final;
  1679. }
  1680. // Get Claim Business
  1681. public function returnDataB($company, $year, $month)
  1682. {
  1683. $dataCB = DealerClaim::where('formT', 'B')->where('dealer', $company)->orderBy('activated_dt', 'desc')->get();
  1684. $final = array();
  1685. // Month & Year
  1686. $mY = '';
  1687. if ($year != 'null' && $month != 'null') {
  1688. $mY = $month . '/' . $year;
  1689. }
  1690. if ($mY != '') {
  1691. /** Contract 12
  1692. // 1=>10-100 2=>300 3=>500 4=>1
  1693. **/
  1694. $data12_1 = array();
  1695. $data12_2 = array();
  1696. $data12_3 = array();
  1697. $data12_4 = array();
  1698. $countD12_1 = 0;
  1699. $countD12_2 = 0;
  1700. $countD12_3 = 0;
  1701. $countD12_4 = 0;
  1702. /** Contract 24
  1703. // 1=>10-100 2=>300 3=>500 4=>1
  1704. **/
  1705. $data24_1 = array();
  1706. $data24_2 = array();
  1707. $data24_3 = array();
  1708. $data24_4 = array();
  1709. $countD24_1 = 0;
  1710. $countD24_2 = 0;
  1711. $countD24_3 = 0;
  1712. $countD24_4 = 0;
  1713. foreach ($dataCB as $dc) {
  1714. if ($dc->activated_my == $mY || $dc->activated_my == '0' . $mY) {
  1715. if ($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")) {
  1716. $data12_1[] = $dc;
  1717. } else if ($dc->contract == "12" && $dc->package == "300") {
  1718. $data12_2[] = $dc;
  1719. } else if ($dc->contract == "12" && $dc->package == "500") {
  1720. $data12_3[] = $dc;
  1721. } else if ($dc->contract == "12" && $dc->package == "1") {
  1722. $data12_4[] = $dc;
  1723. } else if ($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")) {
  1724. $data24_1[] = $dc;
  1725. } else if ($dc->contract == "24" && $dc->package == "300") {
  1726. $data24_2[] = $dc;
  1727. } else if ($dc->contract == "24" && $dc->package == "500") {
  1728. $data24_3[] = $dc;
  1729. } else if ($dc->contract == "24" && $dc->package == "1") {
  1730. $data24_4[] = $dc;
  1731. }
  1732. }
  1733. }
  1734. $countD12_1 = count($data12_1);
  1735. $countD12_2 = count($data12_2);
  1736. $countD12_3 = count($data12_3);
  1737. $countD12_4 = count($data12_4);
  1738. $countD24_1 = count($data24_1);
  1739. $countD24_2 = count($data24_2);
  1740. $countD24_3 = count($data24_3);
  1741. $countD24_4 = count($data24_4);
  1742. $comm = Commission::where('formT', 'B')->get();
  1743. $commV12_1 = 0;
  1744. $commV12_2 = 0;
  1745. $commV12_3 = 0;
  1746. $commV12_4 = 0;
  1747. $commV24_1 = 0;
  1748. $commV24_2 = 0;
  1749. $commV24_3 = 0;
  1750. $commV24_4 = 0;
  1751. $comm12_1 = '';
  1752. $comm12_2 = '';
  1753. $comm12_3 = '';
  1754. $comm12_4 = '';
  1755. $comm24_1 = '';
  1756. $comm24_2 = '';
  1757. $comm24_3 = '';
  1758. $comm24_4 = '';
  1759. $addRM12_1 = '';
  1760. $addRM12_2 = '';
  1761. $addRM12_3 = '';
  1762. $addRM12_4 = '';
  1763. $addRM24_1 = '';
  1764. $addRM24_2 = '';
  1765. $addRM24_3 = '';
  1766. $addRM24_4 = '';
  1767. foreach ($comm as $c) {
  1768. /*** Contract 24 **/
  1769. if ($c->contract == '24' && $c->packageR == "300") {
  1770. if (strpos($c->ranges, '>') !== false) {
  1771. $pieces = explode(">", $c->ranges);
  1772. if ($countD24_2 >= intval($pieces[1])) {
  1773. if (strpos($c->comm, 'RM') !== false) {
  1774. $comm24_2 = '+ ' . $c->comm;
  1775. $commV24_2 = '';
  1776. $comms = explode("RM", $c->comm);
  1777. $addRM24_2 = floatval($comms[1]);
  1778. } else {
  1779. $comms = explode("RM", $c->comm);
  1780. if (isset($comms[1])) {
  1781. $comm24_2 = 'RM ' . $comms[1];
  1782. $commV24_2 = floatval($comms[1]);
  1783. } else {
  1784. if ($comms[0] != '') {
  1785. $comm24_2 = $comms[0] . '%';
  1786. $commV24_2 = floatval($comms[0]) / 100;
  1787. }
  1788. }
  1789. }
  1790. }
  1791. }
  1792. } else if ($c->contract == '24' && $c->packageR == "500") {
  1793. if (strpos($c->ranges, '>') !== false) {
  1794. $pieces = explode(">", $c->ranges);
  1795. if ($countD24_3 >= intval($pieces[1])) {
  1796. if (strpos($c->comm, 'RM') !== false) {
  1797. $comm24_3 = '+ ' . $c->comm;
  1798. $commV24_3 = '';
  1799. $comms = explode("RM", $c->comm);
  1800. $addRM24_3 = floatval($comms[1]);
  1801. } else {
  1802. $comms = explode("RM", $c->comm);
  1803. if (isset($comms[1])) {
  1804. $comm24_3 = 'RM ' . $comms[1];
  1805. $commV24_3 = floatval($comms[1]);
  1806. } else {
  1807. if ($comms[0] != '') {
  1808. $comm24_3 = $comms[0] . '%';
  1809. $commV24_3 = floatval($comms[0]) / 100;
  1810. }
  1811. }
  1812. }
  1813. }
  1814. }
  1815. } else if ($c->contract == '24' && $c->packageR == "1") {
  1816. if (strpos($c->ranges, '>') !== false) {
  1817. $pieces = explode(">", $c->ranges);
  1818. if ($countD24_4 >= intval($pieces[1])) {
  1819. if (strpos($c->comm, 'RM') !== false) {
  1820. $comm24_4 = '+ ' . $c->comm;
  1821. $commV24_4 = '';
  1822. $comms = explode("RM", $c->comm);
  1823. $addRM24_4 = floatval($comms[1]);
  1824. } else {
  1825. $comms = explode("RM", $c->comm);
  1826. if (isset($comms[1])) {
  1827. $comm24_4 = 'RM ' . $comms[1];
  1828. $commV24_4 = floatval($comms[1]);
  1829. } else {
  1830. if ($comms[0] != '') {
  1831. $comm24_4 = $comms[0] . '%';
  1832. $commV24_4 = floatval($comms[0]) / 100;
  1833. }
  1834. }
  1835. }
  1836. }
  1837. }
  1838. } else if ($c->contract == '24' && $c->packageR == "10,30,50,100") {
  1839. if (strpos($c->ranges, '-') !== false) {
  1840. $pieces = explode("-", $c->ranges);
  1841. if ($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])) {
  1842. if (strpos($c->comm, 'RM') !== false) {
  1843. $comm24_1 = '+ ' . $c->comm;
  1844. $commV24_1 = '';
  1845. $addRM24_1 = $c->comm;
  1846. } else {
  1847. $comms = explode("RM", $c->comm);
  1848. if (!empty($comms[1])) {
  1849. $comm24_1 = 'RM ' . $comms[1];
  1850. $commV24_1 = floatval($comms[1]);
  1851. } else {
  1852. if ($comms[0] != '') {
  1853. $comm24_1 = $comms[0] . '%';
  1854. $commV24_1 = floatval($comms[0]) / 100;
  1855. }
  1856. }
  1857. }
  1858. }
  1859. }
  1860. if (strpos($c->ranges, '>') !== false) {
  1861. $pieces1 = explode(">", $c->ranges);
  1862. if ($countD24_1 >= intval($pieces1[1])) {
  1863. if (strpos($c->comm, "RM") === true) {
  1864. $comm24_1 = '+ ' . $c->comm;
  1865. $commV24_1 = '';
  1866. $addRM24_1 = $c->comm;
  1867. } else {
  1868. $comms = explode("RM", $c->comm);
  1869. if (empty($comms[1])) {
  1870. $comm24_1 = 'RM ' . $comms[1];
  1871. $commV24_1 = floatval($comms[1]);
  1872. } else {
  1873. if ($comms[0] != '') {
  1874. $comm24_1 = str_replace('+ ', '', $comms[0]) . '%';
  1875. $commV24_1 = floatval($comms[0]) / 100;
  1876. $addRM24_1 = $comms[1];
  1877. }
  1878. }
  1879. }
  1880. }
  1881. }
  1882. }
  1883. /*** Contract 12 **/
  1884. else if ($c->contract == '12' && $c->packageR == "10,30,50,100") {
  1885. if (strpos($c->ranges, '>') !== false) {
  1886. $pieces = explode(">", $c->ranges);
  1887. if ($countD12_1 >= intval($pieces[1])) {
  1888. if (strpos($c->comm, 'RM') !== false) {
  1889. $comm12_1 = '+ ' . $c->comm;
  1890. $commV12_1 = '';
  1891. $addRM12_1 = $c->comm;
  1892. } else {
  1893. $comms = explode("RM", $c->comm);
  1894. if (isset($comms[1])) {
  1895. $comm12_1 = 'RM ' . $comms[1];
  1896. $commV12_1 = floatval($comms[1]);
  1897. } else {
  1898. if ($comms[0] != '') {
  1899. $comm12_1 = $comms[0] . '%';
  1900. $commV12_1 = floatval($comms[0]) / 100;
  1901. }
  1902. }
  1903. }
  1904. }
  1905. }
  1906. if (strpos($c->ranges, '-') !== false) {
  1907. $pieces = explode("-", $c->ranges);
  1908. if ($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])) {
  1909. if (strpos($c->comm, 'RM') !== false) {
  1910. $comm12_1 = '+ ' . $c->comm;
  1911. $commV12_1 = '';
  1912. $addRM12_1 = $c->comm;
  1913. } else {
  1914. $comms = explode("RM", $c->comm);
  1915. if (isset($comms[1])) {
  1916. $comm12_1 = 'RM ' . $comms[1];
  1917. $commV12_1 = floatval($comms[1]);
  1918. } else {
  1919. if ($comms[0] != '') {
  1920. $comm12_1 = $comms[0] . '%';
  1921. $commV12_1 = floatval($comms[0]) / 100;
  1922. }
  1923. }
  1924. }
  1925. }
  1926. }
  1927. } else if ($c->contract == '12' && $c->packageR == "300") {
  1928. if (strpos($c->ranges, '>') !== false) {
  1929. $pieces = explode(">", $c->ranges);
  1930. if ($countD12_2 >= intval($pieces[1])) {
  1931. if (strpos($c->comm, 'RM') !== false) {
  1932. $comm12_2 = '+ ' . $c->comm;
  1933. $commV12_2 = '';
  1934. $addRM12_2 = $c->comm;
  1935. } else {
  1936. $comms = explode("RM", $c->comm);
  1937. if (isset($comms[1])) {
  1938. $comm12_2 = 'RM ' . $comms[1];
  1939. $commV12_2 = floatval($comms[1]);
  1940. } else {
  1941. if ($comms[0] != '') {
  1942. $comm12_2 = $comms[0] . '%';
  1943. $commV12_2 = floatval($comms[0]) / 100;
  1944. }
  1945. }
  1946. }
  1947. }
  1948. }
  1949. } else if ($c->contract == '12' && $c->packageR == "500") {
  1950. if (strpos($c->ranges, '>') !== false) {
  1951. $pieces = explode(">", $c->ranges);
  1952. if ($countD12_3 >= intval($pieces[1])) {
  1953. if (strpos($c->comm, 'RM') !== false) {
  1954. $comm12_3 = '+ ' . $c->comm;
  1955. $commV12_3 = '';
  1956. $addRM12_3 = $c->comm;
  1957. } else {
  1958. $comms = explode("RM", $c->comm);
  1959. if (isset($comms[1])) {
  1960. $comm12_3 = 'RM ' . $comms[1];
  1961. $commV12_3 = floatval($comms[1]);
  1962. } else {
  1963. if ($comms[0] != '') {
  1964. $comm12_3 = $comms[0] . '%';
  1965. $commV12_3 = floatval($comms[0]) / 100;
  1966. }
  1967. }
  1968. }
  1969. }
  1970. }
  1971. } else if ($c->contract == '12' && $c->packageR == "1") {
  1972. if (strpos($c->ranges, '>') !== false) {
  1973. $pieces = explode(">", $c->ranges);
  1974. if ($countD12_4 >= intval($pieces[1])) {
  1975. if (strpos($c->comm, 'RM') !== false) {
  1976. $comm12_4 = '+ ' . $c->comm;
  1977. $commV12_4 = '';
  1978. $addRM12_4 = $c->comm;
  1979. } else {
  1980. $comms = explode("RM", $c->comm);
  1981. if (isset($comms[1])) {
  1982. $comm12_4 = 'RM ' . $comms[1];
  1983. $commV12_4 = floatval($comms[1]);
  1984. } else {
  1985. if ($comms[0] != '') {
  1986. $comm12_4 = $comms[0] . '%';
  1987. $commV12_4 = floatval($comms[0]) / 100;
  1988. }
  1989. }
  1990. }
  1991. }
  1992. }
  1993. }
  1994. }
  1995. // Category 10,30,50,100
  1996. foreach ($data12_1 as $key => $d) {
  1997. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1998. $address = '';
  1999. $name = '';
  2000. if ($customer->Form->type_application == 'R') {
  2001. if ($customer->street != '') {
  2002. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2003. } else {
  2004. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2005. }
  2006. $name = $customer->name;
  2007. } else if ($customer->Form->type_application == 'B') {
  2008. if ($customer->unit_no != '') {
  2009. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2010. } else {
  2011. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2012. }
  2013. $name = $customer->company_name;
  2014. }
  2015. $total = '';
  2016. if ($commV12_1 == '') {
  2017. $total = $addRM12_1;
  2018. } else {
  2019. $total = number_format($d['retail_price'] * $commV12_1, 2);
  2020. }
  2021. $final[] = array(
  2022. 'index' => $d['formT'],
  2023. 'contract' => $d['contract'],
  2024. 'wo' => $d['wo'],
  2025. 'activation' => $d['activated_dt'],
  2026. 'name' => $name,
  2027. 'address' => $address,
  2028. 'package' => $d['package'],
  2029. 'retail_price' => 'RM ' . $d['retail_price'],
  2030. 'incentives1' => $comm12_1,
  2031. 'incentives2' => $addRM12_1,
  2032. 'total' => 'RM ' . $total,
  2033. 'claim' => $c['claim_dt'],
  2034. );
  2035. }
  2036. foreach ($data24_1 as $key => $d) {
  2037. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2038. $address = '';
  2039. $name = '';
  2040. if ($customer->Form->type_application == 'R') {
  2041. if ($customer->street != '') {
  2042. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2043. } else {
  2044. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2045. }
  2046. $name = $customer->name;
  2047. } else if ($customer->Form->type_application == 'B') {
  2048. if ($customer->unit_no != '') {
  2049. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2050. } else {
  2051. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2052. }
  2053. $name = $customer->company_name;
  2054. }
  2055. $total = '';
  2056. if ($commV24_1 == '') {
  2057. $total = $addRM24_1;
  2058. } else {
  2059. $total = number_format(($d['retail_price'] * $commV24_1) + floatval($addRM24_1), 2);
  2060. }
  2061. $final[] = array(
  2062. 'index' => $d['formT'],
  2063. 'contract' => $d['contract'],
  2064. 'wo' => $d['wo'],
  2065. 'activation' => $d['activated_dt'],
  2066. 'name' => $name,
  2067. 'address' => $address,
  2068. 'package' => $d['package'],
  2069. 'retail_price' => 'RM ' . $d['retail_price'],
  2070. 'incentives1' => $comm24_1,
  2071. 'incentives2' => $addRM24_1,
  2072. 'total' => 'RM ' . $total,
  2073. 'claim' => $c['claim_dt'],
  2074. );
  2075. }
  2076. // Category 300
  2077. foreach ($data12_2 as $key => $d) {
  2078. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2079. $address = '';
  2080. $name = '';
  2081. if ($customer->Form->type_application == 'R') {
  2082. if ($customer->street != '') {
  2083. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2084. } else {
  2085. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2086. }
  2087. $name = $customer->name;
  2088. } else if ($customer->Form->type_application == 'B') {
  2089. if ($customer->unit_no != '') {
  2090. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2091. } else {
  2092. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2093. }
  2094. $name = $customer->company_name;
  2095. }
  2096. $total = '';
  2097. if ($commV12_2 == '') {
  2098. $total = $addRM12_2;
  2099. } else {
  2100. $total = number_format($d['retail_price'] * $commV12_2, 2);
  2101. }
  2102. $final[] = array(
  2103. 'index' => $d['formT'],
  2104. 'contract' => $d['contract'],
  2105. 'wo' => $d['wo'],
  2106. 'activation' => $d['activated_dt'],
  2107. 'name' => $name,
  2108. 'address' => $address,
  2109. 'package' => $d['package'],
  2110. 'retail_price' => 'RM ' . $d['retail_price'],
  2111. 'incentives1' => $commV12_2,
  2112. 'incentives2' => $addRM12_2,
  2113. 'total' => 'RM ' . $total,
  2114. 'claim' => $c['claim_dt'],
  2115. );
  2116. }
  2117. foreach ($data24_2 as $key => $d) {
  2118. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2119. $address = '';
  2120. $name = '';
  2121. if ($customer->Form->type_application == 'R') {
  2122. if ($customer->street != '') {
  2123. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2124. } else {
  2125. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2126. }
  2127. $name = $customer->name;
  2128. } else if ($customer->Form->type_application == 'B') {
  2129. if ($customer->unit_no != '') {
  2130. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2131. } else {
  2132. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2133. }
  2134. $name = $customer->company_name;
  2135. }
  2136. $total = '';
  2137. if ($commV24_2 == '') {
  2138. $total = $addRM24_2; //number_format($d['retail_price']+$addRM24_2,2);
  2139. } else {
  2140. $total = number_format($d['retail_price'] * $commV24_2, 2);
  2141. }
  2142. $final[] = array(
  2143. 'index' => $d['formT'],
  2144. 'contract' => $d['contract'],
  2145. 'wo' => $d['wo'],
  2146. 'activation' => $d['activated_dt'],
  2147. 'name' => $name,
  2148. 'address' => $address,
  2149. 'package' => $d['package'],
  2150. 'retail_price' => 'RM ' . $d['retail_price'],
  2151. 'incentives1' => $commV24_2,
  2152. 'incentives2' => $comm24_2,
  2153. 'total' => 'RM ' . $total,
  2154. 'claim' => $c['claim_dt'],
  2155. );
  2156. }
  2157. // Category 500
  2158. foreach ($data12_3 as $key => $d) {
  2159. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2160. $address = '';
  2161. $name = '';
  2162. if ($customer->Form->type_application == 'R') {
  2163. if ($customer->street != '') {
  2164. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2165. } else {
  2166. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2167. }
  2168. $name = $customer->name;
  2169. } else if ($customer->Form->type_application == 'B') {
  2170. if ($customer->unit_no != '') {
  2171. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2172. } else {
  2173. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2174. }
  2175. $name = $customer->company_name;
  2176. }
  2177. $total = '';
  2178. if ($commV12_3 == '') {
  2179. $total = $addRM12_3;
  2180. } else {
  2181. $total = number_format($d['retail_price'] * $commV12_3, 2);
  2182. }
  2183. $final[] = array(
  2184. 'index' => $d['formT'],
  2185. 'contract' => $d['contract'],
  2186. 'wo' => $d['wo'],
  2187. 'activation' => $d['activated_dt'],
  2188. 'name' => $name,
  2189. 'address' => $address,
  2190. 'package' => $d['package'],
  2191. 'retail_price' => 'RM ' . $d['retail_price'],
  2192. 'incentives1' => $commV12_3,
  2193. 'incentives2' => $addRM12_3,
  2194. 'total' => 'RM ' . $total,
  2195. 'claim' => $c['claim_dt'],
  2196. );
  2197. }
  2198. foreach ($data24_3 as $key => $d) {
  2199. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2200. $address = '';
  2201. $name = '';
  2202. if ($customer->Form->type_application == 'R') {
  2203. if ($customer->street != '') {
  2204. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2205. } else {
  2206. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2207. }
  2208. $name = $customer->name;
  2209. } else if ($customer->Form->type_application == 'B') {
  2210. if ($customer->unit_no != '') {
  2211. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2212. } else {
  2213. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2214. }
  2215. $name = $customer->company_name;
  2216. }
  2217. $total = '';
  2218. if ($commV24_3 == '') {
  2219. $total = $addRM24_3; //number_format($d['retail_price']+$addRM24_3,2);
  2220. } else {
  2221. $total = number_format($d['retail_price'] * $commV24_3, 2);
  2222. }
  2223. $final[] = array(
  2224. 'index' => $d['formT'],
  2225. 'contract' => $d['contract'],
  2226. 'wo' => $d['wo'],
  2227. 'activation' => $d['activated_dt'],
  2228. 'name' => $name,
  2229. 'address' => $address,
  2230. 'package' => $d['package'],
  2231. 'retail_price' => 'RM ' . $d['retail_price'],
  2232. 'incentives1' => $commV24_3,
  2233. 'incentives2' => $comm24_3,
  2234. 'total' => 'RM ' . $total,
  2235. 'claim' => $c['claim_dt'],
  2236. );
  2237. }
  2238. // Category 1
  2239. foreach ($data12_4 as $key => $d) {
  2240. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2241. $address = '';
  2242. $name = '';
  2243. if ($customer->Form->type_application == 'R') {
  2244. if ($customer->street != '') {
  2245. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2246. } else {
  2247. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2248. }
  2249. $name = $customer->name;
  2250. } else if ($customer->Form->type_application == 'B') {
  2251. if ($customer->unit_no != '') {
  2252. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2253. } else {
  2254. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2255. }
  2256. $name = $customer->company_name;
  2257. }
  2258. $total = '';
  2259. if ($commV12_4 == '') {
  2260. $total = $addRM12_4;
  2261. } else {
  2262. $total = number_format($d['retail_price'] * $commV12_4, 2);
  2263. }
  2264. $final[] = array(
  2265. 'index' => $d['formT'],
  2266. 'contract' => $d['contract'],
  2267. 'wo' => $d['wo'],
  2268. 'activation' => $d['activated_dt'],
  2269. 'name' => $name,
  2270. 'address' => $address,
  2271. 'package' => $d['package'],
  2272. 'retail_price' => 'RM ' . $d['retail_price'],
  2273. 'incentives1' => $commV12_4,
  2274. 'incentives2' => $addRM12_4,
  2275. 'total' => 'RM ' . $total,
  2276. 'claim' => $c['claim_dt'],
  2277. );
  2278. }
  2279. foreach ($data24_4 as $key => $d) {
  2280. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  2281. $address = '';
  2282. $name = '';
  2283. if ($customer->Form->type_application == 'R') {
  2284. if ($customer->street != '') {
  2285. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2286. } else {
  2287. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2288. }
  2289. $name = $customer->name;
  2290. } else if ($customer->Form->type_application == 'B') {
  2291. if ($customer->unit_no != '') {
  2292. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2293. } else {
  2294. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2295. }
  2296. $name = $customer->company_name;
  2297. }
  2298. $total = '';
  2299. if ($commV24_4 == '') {
  2300. $total = $addRM24_4; //number_format($d['retail_price']+$addRM24_4,2);
  2301. } else {
  2302. $total = number_format($d['retail_price'] * $commV24_4, 2);
  2303. }
  2304. $final[] = array(
  2305. 'index' => $d['formT'],
  2306. 'contract' => $d['contract'],
  2307. 'wo' => $d['wo'],
  2308. 'activation' => $d['activated_dt'],
  2309. 'name' => $name,
  2310. 'address' => $address,
  2311. 'package' => $d['package'],
  2312. 'retail_price' => 'RM ' . $d['retail_price'],
  2313. 'incentives1' => $commV24_4,
  2314. 'incentives2' => $comm24_4,
  2315. 'total' => 'RM ' . $total,
  2316. 'claim' => $c['claim_dt'],
  2317. );
  2318. }
  2319. } else {
  2320. foreach ($dataCB as $c) {
  2321. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  2322. $address = '';
  2323. $name = '';
  2324. if ($customer->Form->type_application == 'R') {
  2325. if ($customer->street != '') {
  2326. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2327. } else {
  2328. $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2329. }
  2330. $name = $customer->name;
  2331. } else if ($customer->Form->type_application == 'B') {
  2332. if ($customer->unit_no != '') {
  2333. $address = $customer->unit_no . ', ' . $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2334. } else {
  2335. $address = $customer->company_name . ', ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
  2336. }
  2337. $name = $customer->company_name;
  2338. }
  2339. $final[] = array(
  2340. 'index' => $c['formT'],
  2341. 'contract' => $c['contract'],
  2342. 'wo' => $c['wo'],
  2343. 'activation' => $c['activated_dt'],
  2344. 'name' => $name,
  2345. 'address' => $address,
  2346. 'package' => $c['package'],
  2347. 'retail_price' => 'RM ' . $c['retail_price'],
  2348. 'incentives1' => '',
  2349. 'incentives2' => '',
  2350. 'total' => '',
  2351. 'claim' => $c['claim_dt'],
  2352. );
  2353. }
  2354. }
  2355. return $final;
  2356. }
  2357. // public function filterclaim($company,$year,$month,$app)
  2358. // {
  2359. // $id = Auth::guard('ms')->id();
  2360. // $user = Staff::with('StaffDetail')->find($id);
  2361. // $dataR = array(); $dataB = array(); $combineData = array();
  2362. // if($year!='null' && $month!='null' && $app=='null'){
  2363. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  2364. // $dataDis = $this->returnDataR($company,'2019','12');
  2365. // $dataJan = $this->returnDataR($company,'2020','1');
  2366. // $count_cyberjaya = array(); $count_jasin = array();
  2367. // foreach ($dataDis as $key => $d) {
  2368. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  2369. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2370. // $count_cyberjaya[] = $d;
  2371. // }
  2372. // if (strpos($d['address'], 'Jasin') !== false) {
  2373. // $count_jasin[] = $d;
  2374. // }
  2375. // }else {
  2376. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2377. // $combineData[] = $d;
  2378. // }
  2379. // }
  2380. // }
  2381. // foreach ($dataJan as $key => $d) {
  2382. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2383. // $count_cyberjaya[] = $d;
  2384. // }
  2385. // if (strpos($d['address'], 'Jasin') !== false) {
  2386. // $count_jasin[] = $d;
  2387. // }
  2388. // }
  2389. // // Store to combineData New Incentives Cyberjaya
  2390. // foreach ($count_cyberjaya as $key => $d) {
  2391. // if(count($count_cyberjaya) > 50){
  2392. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2393. // if($d['contract'] == '12'){
  2394. // array_push($combineData, array(
  2395. // 'index' => $d['index'],
  2396. // 'contract' => $d['contract'],
  2397. // 'wo' => $d['wo'],
  2398. // 'activation' => $d['activation'],
  2399. // 'name' => $d['name'],
  2400. // 'address' => $d['address'],
  2401. // 'package' => $d['package'],
  2402. // 'retail_price' => $d['retail_price'],
  2403. // 'incentives1' => $d['incentives1'],
  2404. // 'incentives2' => $d['incentives2'],
  2405. // 'total' => $d['total'],
  2406. // 'claim' => $d['claim'],
  2407. // ));
  2408. // }else {
  2409. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2410. // array_push($combineData, array(
  2411. // 'index' => $d['index'],
  2412. // 'contract' => $d['contract'],
  2413. // 'wo' => $d['wo'],
  2414. // 'activation' => $d['activation'],
  2415. // 'name' => $d['name'],
  2416. // 'address' => $d['address'],
  2417. // 'package' => $d['package'],
  2418. // 'retail_price' => $d['retail_price'],
  2419. // 'incentives1' => '230%',
  2420. // 'incentives2' => $d['incentives2'],
  2421. // 'total' => 'RM '.$total,
  2422. // 'claim' => $d['claim'],
  2423. // ));
  2424. // }
  2425. // }
  2426. // }else if(count($count_cyberjaya) < 50){
  2427. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2428. // array_push($combineData, array(
  2429. // 'index' => $d['index'],
  2430. // 'contract' => $d['contract'],
  2431. // 'wo' => $d['wo'],
  2432. // 'activation' => $d['activation'],
  2433. // 'name' => $d['name'],
  2434. // 'address' => $d['address'],
  2435. // 'package' => $d['package'],
  2436. // 'retail_price' => $d['retail_price'],
  2437. // 'incentives1' => $d['incentives1'],
  2438. // 'incentives2' => $d['incentives2'],
  2439. // 'total' => $d['total'],
  2440. // 'claim' => $d['claim'],
  2441. // ));
  2442. // }
  2443. // }
  2444. // }
  2445. // // Store to combineData New Incentives Jasin
  2446. // foreach ($count_jasin as $key => $d) {
  2447. // if(count($count_jasin) > 10){
  2448. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2449. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2450. // array_push($combineData, array(
  2451. // 'index' => $d['index'],
  2452. // 'contract' => $d['contract'],
  2453. // 'wo' => $d['wo'],
  2454. // 'activation' => $d['activation'],
  2455. // 'name' => $d['name'],
  2456. // 'address' => $d['address'],
  2457. // 'package' => $d['package'],
  2458. // 'retail_price' => $d['retail_price'],
  2459. // 'incentives1' => '230%',
  2460. // 'incentives2' => $d['incentives2'],
  2461. // 'total' => 'RM '.$total,
  2462. // 'claim' => $d['claim'],
  2463. // ));
  2464. // }
  2465. // }else if(count($count_jasin) < 10){
  2466. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2467. // array_push($combineData, array(
  2468. // 'index' => $d['index'],
  2469. // 'contract' => $d['contract'],
  2470. // 'wo' => $d['wo'],
  2471. // 'activation' => $d['activation'],
  2472. // 'name' => $d['name'],
  2473. // 'address' => $d['address'],
  2474. // 'package' => $d['package'],
  2475. // 'retail_price' => $d['retail_price'],
  2476. // 'incentives1' => $d['incentives1'],
  2477. // 'incentives2' => $d['incentives2'],
  2478. // 'total' => $d['total'],
  2479. // 'claim' => $d['claim'],
  2480. // ));
  2481. // }
  2482. // }
  2483. // }
  2484. // }else {
  2485. // $dataR = $this->returnDataR($company,$year,$month);
  2486. // foreach($dataR as $r){
  2487. // $combineData[] = $r;
  2488. // }
  2489. // }
  2490. // $dataB = $this->returnDataB($company,$year,$month);
  2491. // foreach($dataB as $b){
  2492. // $combineData[] = $b;
  2493. // }
  2494. // $i = 0;
  2495. // $nested_data = array();
  2496. // if(!empty($combineData)){
  2497. // foreach ($combineData as $c){
  2498. // $i++;
  2499. // array_push($nested_data, array(
  2500. // 'index' => $c['index'],
  2501. // 'contract' => $c['contract'],
  2502. // 'wo' => $c['wo'],
  2503. // 'activated_dt' => $c['activation'],
  2504. // 'name' => $c['name'],
  2505. // 'address' => $c['address'],
  2506. // 'package' => $c['package'],
  2507. // 'retail_price' => $c['retail_price'],
  2508. // 'incentives1' => $c['incentives1'],
  2509. // 'incentives2' => $c['incentives2'],
  2510. // 'total' => $c['total'],
  2511. // 'claimed' => $c['claim'],
  2512. // ));
  2513. // }
  2514. // }
  2515. // usort($nested_data, function ($a, $b) {
  2516. // $dateA = $a['activated_dt'];
  2517. // $dateB = $b['activated_dt'];
  2518. // // ascending ordering, use `<=` for descending
  2519. // return $dateA <= $dateB;
  2520. // });
  2521. // return \DataTables::of($nested_data)->make(true);
  2522. // }else if($year=='null' && $month=='null' && $app!='null'){
  2523. // if($app == 'Residential'){
  2524. // $dataR = $this->returnDataR($company,$year,$month);
  2525. // }else if($app == 'Business'){
  2526. // $dataB = $this->returnDataB($company,$year,$month);
  2527. // }
  2528. // foreach($dataR as $r){
  2529. // $combineData[] = $r;
  2530. // }
  2531. // foreach($dataB as $b){
  2532. // $combineData[] = $b;
  2533. // }
  2534. // $i = 0;
  2535. // $nested_data = array();
  2536. // if(!empty($combineData)){
  2537. // foreach ($combineData as $c){
  2538. // $i++;
  2539. // array_push($nested_data, array(
  2540. // 'index' => $c['index'],
  2541. // 'contract' => $c['contract'],
  2542. // 'wo' => $c['wo'],
  2543. // 'activated_dt' => $c['activation'],
  2544. // 'name' => $c['name'],
  2545. // 'address' => $c['address'],
  2546. // 'package' => $c['package'],
  2547. // 'retail_price' => $c['retail_price'],
  2548. // 'incentives1' => $c['incentives1'],
  2549. // 'incentives2' => $c['incentives2'],
  2550. // 'total' => $c['total'],
  2551. // 'claimed' => $c['claim'],
  2552. // ));
  2553. // }
  2554. // }
  2555. // usort($nested_data, function ($a, $b) {
  2556. // $dateA = $a['activated_dt'];
  2557. // $dateB = $b['activated_dt'];
  2558. // // ascending ordering, use `<=` for descending
  2559. // return $dateA <= $dateB;
  2560. // });
  2561. // return \DataTables::of($nested_data)->make(true);
  2562. // }else if($year!='null' && $month!='null' && $app!='null'){
  2563. // if($app == 'Residential'){
  2564. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  2565. // $dataDis = $this->returnDataR($company,'2019','12');
  2566. // $dataJan = $this->returnDataR($company,'2020','1');
  2567. // $count_cyberjaya = array(); $count_jasin = array();
  2568. // foreach ($dataDis as $key => $d) {
  2569. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  2570. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2571. // $count_cyberjaya[] = $d;
  2572. // }
  2573. // if (strpos($d['address'], 'Jasin') !== false) {
  2574. // $count_jasin[] = $d;
  2575. // }
  2576. // }else {
  2577. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2578. // $combineData[] = $d;
  2579. // }
  2580. // }
  2581. // }
  2582. // foreach ($dataJan as $key => $d) {
  2583. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2584. // $count_cyberjaya[] = $d;
  2585. // }
  2586. // if (strpos($d['address'], 'Jasin') !== false) {
  2587. // $count_jasin[] = $d;
  2588. // }
  2589. // }
  2590. // // Store to combineData New Incentives Cyberjaya
  2591. // foreach ($count_cyberjaya as $key => $d) {
  2592. // if(count($count_cyberjaya) > 50){
  2593. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2594. // if($d['contract'] == '12'){
  2595. // array_push($combineData, array(
  2596. // 'index' => $d['index'],
  2597. // 'contract' => $d['contract'],
  2598. // 'wo' => $d['wo'],
  2599. // 'activation' => $d['activation'],
  2600. // 'name' => $d['name'],
  2601. // 'address' => $d['address'],
  2602. // 'package' => $d['package'],
  2603. // 'retail_price' => $d['retail_price'],
  2604. // 'incentives1' => $d['incentives1'],
  2605. // 'incentives2' => $d['incentives2'],
  2606. // 'total' => $d['total'],
  2607. // 'claim' => $d['claim'],
  2608. // ));
  2609. // }else {
  2610. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2611. // array_push($combineData, array(
  2612. // 'index' => $d['index'],
  2613. // 'contract' => $d['contract'],
  2614. // 'wo' => $d['wo'],
  2615. // 'activation' => $d['activation'],
  2616. // 'name' => $d['name'],
  2617. // 'address' => $d['address'],
  2618. // 'package' => $d['package'],
  2619. // 'retail_price' => $d['retail_price'],
  2620. // 'incentives1' => '230%',
  2621. // 'incentives2' => $d['incentives2'],
  2622. // 'total' => 'RM '.$total,
  2623. // 'claim' => $d['claim'],
  2624. // ));
  2625. // }
  2626. // }
  2627. // }else if(count($count_cyberjaya) < 50){
  2628. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2629. // array_push($combineData, array(
  2630. // 'index' => $d['index'],
  2631. // 'contract' => $d['contract'],
  2632. // 'wo' => $d['wo'],
  2633. // 'activation' => $d['activation'],
  2634. // 'name' => $d['name'],
  2635. // 'address' => $d['address'],
  2636. // 'package' => $d['package'],
  2637. // 'retail_price' => $d['retail_price'],
  2638. // 'incentives1' => $d['incentives1'],
  2639. // 'incentives2' => $d['incentives2'],
  2640. // 'total' => $d['total'],
  2641. // 'claim' => $d['claim'],
  2642. // ));
  2643. // }
  2644. // }
  2645. // }
  2646. // // Store to combineData New Incentives Jasin
  2647. // foreach ($count_jasin as $key => $d) {
  2648. // if(count($count_jasin) > 10){
  2649. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2650. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2651. // array_push($combineData, array(
  2652. // 'index' => $d['index'],
  2653. // 'contract' => $d['contract'],
  2654. // 'wo' => $d['wo'],
  2655. // 'activation' => $d['activation'],
  2656. // 'name' => $d['name'],
  2657. // 'address' => $d['address'],
  2658. // 'package' => $d['package'],
  2659. // 'retail_price' => $d['retail_price'],
  2660. // 'incentives1' => '230%',
  2661. // 'incentives2' => $d['incentives2'],
  2662. // 'total' => 'RM '.$total,
  2663. // 'claim' => $d['claim'],
  2664. // ));
  2665. // }
  2666. // }else if(count($count_jasin) < 10){
  2667. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2668. // array_push($combineData, array(
  2669. // 'index' => $d['index'],
  2670. // 'contract' => $d['contract'],
  2671. // 'wo' => $d['wo'],
  2672. // 'activation' => $d['activation'],
  2673. // 'name' => $d['name'],
  2674. // 'address' => $d['address'],
  2675. // 'package' => $d['package'],
  2676. // 'retail_price' => $d['retail_price'],
  2677. // 'incentives1' => $d['incentives1'],
  2678. // 'incentives2' => $d['incentives2'],
  2679. // 'total' => $d['total'],
  2680. // 'claim' => $d['claim'],
  2681. // ));
  2682. // }
  2683. // }
  2684. // }
  2685. // }else {
  2686. // $dataR = $this->returnDataR($company,$year,$month);
  2687. // foreach($dataR as $r){
  2688. // $combineData[] = $r;
  2689. // }
  2690. // }
  2691. // }else if($app == 'Business'){
  2692. // $dataB = $this->returnDataB($company,$year,$month);
  2693. // }
  2694. // foreach($dataB as $b){
  2695. // $combineData[] = $b;
  2696. // }
  2697. // $i = 0;
  2698. // $nested_data = array();
  2699. // if(!empty($combineData)){
  2700. // foreach ($combineData as $c){
  2701. // $i++;
  2702. // array_push($nested_data, array(
  2703. // 'index' => $c['index'],
  2704. // 'contract' => $c['contract'],
  2705. // 'wo' => $c['wo'],
  2706. // 'activated_dt' => $c['activation'],
  2707. // 'name' => $c['name'],
  2708. // 'address' => $c['address'],
  2709. // 'package' => $c['package'],
  2710. // 'retail_price' => $c['retail_price'],
  2711. // 'incentives1' => $c['incentives1'],
  2712. // 'incentives2' => $c['incentives2'],
  2713. // 'total' => $c['total'],
  2714. // 'claimed' => $c['claim'],
  2715. // ));
  2716. // }
  2717. // }
  2718. // usort($nested_data, function ($a, $b) {
  2719. // $dateA = $a['activated_dt'];
  2720. // $dateB = $b['activated_dt'];
  2721. // // ascending ordering, use `<=` for descending
  2722. // return $dateA <= $dateB;
  2723. // });
  2724. // return \DataTables::of($nested_data)->make(true);
  2725. // }
  2726. // }
  2727. // public function exportPDFClaim($company,$year,$month,$app) {
  2728. // $final = array();
  2729. // $id = Auth::guard('ms')->id();
  2730. // $user = Staff::with('StaffDetail')->find($id);
  2731. // $com = Company::where('_id',$company)->first();
  2732. // $dataR = array(); $dataB = array(); $combineData = array();
  2733. // if($year!='null' && $month!='null' && $app=='null'){
  2734. // $count_cyberjaya = array(); $count_jasin = array();
  2735. // $extra = 0; $basic_total = 0; $totals = 0;
  2736. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  2737. // $dataDis = $this->returnDataR($company,'2019','12');
  2738. // $dataJan = $this->returnDataR($company,'2020','1');
  2739. // foreach ($dataDis as $key => $d) {
  2740. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  2741. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2742. // $count_cyberjaya[] = $d;
  2743. // }
  2744. // if (strpos($d['address'], 'Jasin') !== false) {
  2745. // $count_jasin[] = $d;
  2746. // }
  2747. // }else {
  2748. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2749. // $combineData[] = $d;
  2750. // }
  2751. // }
  2752. // }
  2753. // foreach ($dataJan as $key => $d) {
  2754. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2755. // $count_cyberjaya[] = $d;
  2756. // }
  2757. // if (strpos($d['address'], 'Jasin') !== false) {
  2758. // $count_jasin[] = $d;
  2759. // }
  2760. // }
  2761. // // Store to combineData New Incentives Cyberjaya
  2762. // foreach ($count_cyberjaya as $key => $d) {
  2763. // if(count($count_cyberjaya) > 50){
  2764. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2765. // if($d['contract'] == '12'){
  2766. // array_push($combineData, array(
  2767. // 'index' => $d['index'],
  2768. // 'contract' => $d['contract'],
  2769. // 'wo' => $d['wo'],
  2770. // 'activation' => $d['activation'],
  2771. // 'name' => $d['name'],
  2772. // 'address' => $d['address'],
  2773. // 'package' => $d['package'],
  2774. // 'retail_price' => $d['retail_price'],
  2775. // 'incentives1' => $d['incentives1'],
  2776. // 'incentives2' => $d['incentives2'],
  2777. // 'total' => $d['total'],
  2778. // 'claim' => $d['claim'],
  2779. // ));
  2780. // }else {
  2781. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2782. // array_push($combineData, array(
  2783. // 'index' => $d['index'],
  2784. // 'contract' => $d['contract'],
  2785. // 'wo' => $d['wo'],
  2786. // 'activation' => $d['activation'],
  2787. // 'name' => $d['name'],
  2788. // 'address' => $d['address'],
  2789. // 'package' => $d['package'],
  2790. // 'retail_price' => $d['retail_price'],
  2791. // 'incentives1' => '230%',
  2792. // 'incentives2' => $d['incentives2'],
  2793. // 'total' => 'RM '.$total,
  2794. // 'claim' => $d['claim'],
  2795. // ));
  2796. // }
  2797. // }
  2798. // }else if(count($count_cyberjaya) < 50){
  2799. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2800. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.1, 2);
  2801. // array_push($combineData, array(
  2802. // 'index' => $d['index'],
  2803. // 'contract' => $d['contract'],
  2804. // 'wo' => $d['wo'],
  2805. // 'activation' => $d['activation'],
  2806. // 'name' => $d['name'],
  2807. // 'address' => $d['address'],
  2808. // 'package' => $d['package'],
  2809. // 'retail_price' => $d['retail_price'],
  2810. // 'incentives1' => $d['incentives1'],
  2811. // 'incentives2' => $d['incentives2'],
  2812. // 'total' => $d['total'],
  2813. // 'claim' => $d['claim'],
  2814. // ));
  2815. // }
  2816. // }
  2817. // }
  2818. // // Store to combineData New Incentives Jasin
  2819. // foreach ($count_jasin as $key => $d) {
  2820. // if(count($count_jasin) > 10){
  2821. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2822. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2823. // array_push($combineData, array(
  2824. // 'index' => $d['index'],
  2825. // 'contract' => $d['contract'],
  2826. // 'wo' => $d['wo'],
  2827. // 'activation' => $d['activation'],
  2828. // 'name' => $d['name'],
  2829. // 'address' => $d['address'],
  2830. // 'package' => $d['package'],
  2831. // 'retail_price' => $d['retail_price'],
  2832. // 'incentives1' => '230%',
  2833. // 'incentives2' => $d['incentives2'],
  2834. // 'total' => 'RM '.$total,
  2835. // 'claim' => $d['claim'],
  2836. // ));
  2837. // }
  2838. // }else if(count($count_jasin) < 10){
  2839. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2840. // array_push($combineData, array(
  2841. // 'index' => $d['index'],
  2842. // 'contract' => $d['contract'],
  2843. // 'wo' => $d['wo'],
  2844. // 'activation' => $d['activation'],
  2845. // 'name' => $d['name'],
  2846. // 'address' => $d['address'],
  2847. // 'package' => $d['package'],
  2848. // 'retail_price' => $d['retail_price'],
  2849. // 'incentives1' => $d['incentives1'],
  2850. // 'incentives2' => $d['incentives2'],
  2851. // 'total' => $d['total'],
  2852. // 'claim' => $d['claim'],
  2853. // ));
  2854. // }
  2855. // }
  2856. // }
  2857. // }else {
  2858. // $dataR = $this->returnDataR($company,$year,$month);
  2859. // foreach($dataR as $r){
  2860. // $combineData[] = $r;
  2861. // }
  2862. // }
  2863. // $dataB = $this->returnDataB($company,$year,$month);
  2864. // foreach($dataB as $b){
  2865. // $combineData[] = $b;
  2866. // }
  2867. // $i = 0;
  2868. // $nested_data = array();
  2869. // if(!empty($combineData)){
  2870. // foreach ($combineData as $c){
  2871. // $i++;
  2872. // array_push($final, array(
  2873. // 'index' => $c['index'],
  2874. // 'contract' => $c['contract'],
  2875. // 'wo' => $c['wo'],
  2876. // 'activated_dt' => $c['activation'],
  2877. // 'name' => $c['name'],
  2878. // 'address' => $c['address'],
  2879. // 'package' => $c['package'],
  2880. // 'retail_price' => $c['retail_price'],
  2881. // 'incentives1' => $c['incentives1'],
  2882. // 'incentives2' => $c['incentives2'],
  2883. // 'total' => $c['total'],
  2884. // 'claimed' => $c['claim'],
  2885. // ));
  2886. // }
  2887. // }
  2888. // foreach($final as $f){
  2889. // $basic_total += floatval(str_replace('RM ', '', $f['total']));
  2890. // }
  2891. // // Calculate extra incentves
  2892. // if($month == '1' && $year == '2020'){
  2893. // if(count($count_cyberjaya) > 50){
  2894. // $balance = count($count_cyberjaya) - 50;
  2895. // $extra += $balance * 50;
  2896. // }
  2897. // if(count($count_jasin) > 10){
  2898. // $balance = count($count_jasin) - 10;
  2899. // $extra += $balance * 50;
  2900. // }
  2901. // }else {
  2902. // $extra = 0;
  2903. // }
  2904. // $totals = $basic_total + $extra;
  2905. // usort($final, function ($a, $b) {
  2906. // $dateA = $a['activated_dt'];
  2907. // $dateB = $b['activated_dt'];
  2908. // // ascending ordering, use `<=` for descending
  2909. // return $dateA <= $dateB;
  2910. // });
  2911. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  2912. // $pdf->setPaper('A4', 'landscape');
  2913. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  2914. // return $pdf->download( $pdfName );
  2915. // }else if($year!='null' && $month!='null' && $app!='null'){
  2916. // $count_cyberjaya = array(); $count_jasin = array();
  2917. // $extra = 0; $basic_total = 0; $totals = 0;
  2918. // if($app == 'Residential'){
  2919. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  2920. // $dataDis = $this->returnDataR($company,'2019','12');
  2921. // $dataJan = $this->returnDataR($company,'2020','1');
  2922. // foreach ($dataDis as $key => $d) {
  2923. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  2924. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2925. // $count_cyberjaya[] = $d;
  2926. // }
  2927. // if (strpos($d['address'], 'Jasin') !== false) {
  2928. // $count_jasin[] = $d;
  2929. // }
  2930. // }else {
  2931. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2932. // $combineData[] = $d;
  2933. // }
  2934. // }
  2935. // }
  2936. // foreach ($dataJan as $key => $d) {
  2937. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2938. // $count_cyberjaya[] = $d;
  2939. // }
  2940. // if (strpos($d['address'], 'Jasin') !== false) {
  2941. // $count_jasin[] = $d;
  2942. // }
  2943. // }
  2944. // // Store to combineData New Incentives Cyberjaya
  2945. // foreach ($count_cyberjaya as $key => $d) {
  2946. // if(count($count_cyberjaya) > 50){
  2947. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2948. // if($d['contract'] == '12'){
  2949. // array_push($combineData, array(
  2950. // 'index' => $d['index'],
  2951. // 'contract' => $d['contract'],
  2952. // 'wo' => $d['wo'],
  2953. // 'activation' => $d['activation'],
  2954. // 'name' => $d['name'],
  2955. // 'address' => $d['address'],
  2956. // 'package' => $d['package'],
  2957. // 'retail_price' => $d['retail_price'],
  2958. // 'incentives1' => $d['incentives1'],
  2959. // 'incentives2' => $d['incentives2'],
  2960. // 'total' => $d['total'],
  2961. // 'claim' => $d['claim'],
  2962. // ));
  2963. // }else {
  2964. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2965. // array_push($combineData, array(
  2966. // 'index' => $d['index'],
  2967. // 'contract' => $d['contract'],
  2968. // 'wo' => $d['wo'],
  2969. // 'activation' => $d['activation'],
  2970. // 'name' => $d['name'],
  2971. // 'address' => $d['address'],
  2972. // 'package' => $d['package'],
  2973. // 'retail_price' => $d['retail_price'],
  2974. // 'incentives1' => '230%',
  2975. // 'incentives2' => $d['incentives2'],
  2976. // 'total' => 'RM '.$total,
  2977. // 'claim' => $d['claim'],
  2978. // ));
  2979. // }
  2980. // }
  2981. // }else if(count($count_cyberjaya) < 50){
  2982. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2983. // array_push($combineData, array(
  2984. // 'index' => $d['index'],
  2985. // 'contract' => $d['contract'],
  2986. // 'wo' => $d['wo'],
  2987. // 'activation' => $d['activation'],
  2988. // 'name' => $d['name'],
  2989. // 'address' => $d['address'],
  2990. // 'package' => $d['package'],
  2991. // 'retail_price' => $d['retail_price'],
  2992. // 'incentives1' => $d['incentives1'],
  2993. // 'incentives2' => $d['incentives2'],
  2994. // 'total' => $d['total'],
  2995. // 'claim' => $d['claim'],
  2996. // ));
  2997. // }
  2998. // }
  2999. // }
  3000. // // Store to combineData New Incentives Jasin
  3001. // foreach ($count_jasin as $key => $d) {
  3002. // if(count($count_jasin) > 10){
  3003. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3004. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  3005. // array_push($combineData, array(
  3006. // 'index' => $d['index'],
  3007. // 'contract' => $d['contract'],
  3008. // 'wo' => $d['wo'],
  3009. // 'activation' => $d['activation'],
  3010. // 'name' => $d['name'],
  3011. // 'address' => $d['address'],
  3012. // 'package' => $d['package'],
  3013. // 'retail_price' => $d['retail_price'],
  3014. // 'incentives1' => '230%',
  3015. // 'incentives2' => $d['incentives2'],
  3016. // 'total' => 'RM '.$total,
  3017. // 'claim' => $d['claim'],
  3018. // ));
  3019. // }
  3020. // }else if(count($count_jasin) < 10){
  3021. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  3022. // array_push($combineData, array(
  3023. // 'index' => $d['index'],
  3024. // 'contract' => $d['contract'],
  3025. // 'wo' => $d['wo'],
  3026. // 'activation' => $d['activation'],
  3027. // 'name' => $d['name'],
  3028. // 'address' => $d['address'],
  3029. // 'package' => $d['package'],
  3030. // 'retail_price' => $d['retail_price'],
  3031. // 'incentives1' => $d['incentives1'],
  3032. // 'incentives2' => $d['incentives2'],
  3033. // 'total' => $d['total'],
  3034. // 'claim' => $d['claim'],
  3035. // ));
  3036. // }
  3037. // }
  3038. // }
  3039. // }else {
  3040. // $dataR = $this->returnDataR($company,$year,$month);
  3041. // foreach($dataR as $r){
  3042. // $combineData[] = $r;
  3043. // }
  3044. // }
  3045. // }else if($app == 'Business'){
  3046. // $dataB = $this->returnDataB($company,$year,$month);
  3047. // }
  3048. // foreach($dataB as $b){
  3049. // $combineData[] = $b;
  3050. // }
  3051. // $i = 0;
  3052. // $nested_data = array();
  3053. // if(!empty($combineData)){
  3054. // foreach ($combineData as $c){
  3055. // $i++;
  3056. // array_push($final, array(
  3057. // 'index' => $c['index'],
  3058. // 'contract' => $c['contract'],
  3059. // 'wo' => $c['wo'],
  3060. // 'activated_dt' => $c['activation'],
  3061. // 'name' => $c['name'],
  3062. // 'address' => $c['address'],
  3063. // 'package' => $c['package'],
  3064. // 'retail_price' => $c['retail_price'],
  3065. // 'incentives1' => $c['incentives1'],
  3066. // 'incentives2' => $c['incentives2'],
  3067. // 'total' => $c['total'],
  3068. // 'claimed' => $c['claim'],
  3069. // ));
  3070. // }
  3071. // }
  3072. // foreach($final as $f){
  3073. // $basic_total += floatval(str_replace('RM ', '', $f['total']));
  3074. // }
  3075. // //Calculate extra incentves
  3076. // if($month == '1' && $year == '2020'){
  3077. // if(count($count_cyberjaya) > 50){
  3078. // $balance = count($count_cyberjaya) - 50;
  3079. // $extra += $balance * 50;
  3080. // }
  3081. // if(count($count_jasin) > 10){
  3082. // $balance = count($count_jasin) - 10;
  3083. // $extra += $balance * 50;
  3084. // }
  3085. // }else {
  3086. // $extra = 0;
  3087. // }
  3088. // $totals = $basic_total + $extra;
  3089. // usort($final, function ($a, $b) {
  3090. // $dateA = $a['activated_dt'];
  3091. // $dateB = $b['activated_dt'];
  3092. // // ascending ordering, use `<=` for descending
  3093. // return $dateA <= $dateB;
  3094. // });
  3095. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  3096. // $pdf->setPaper('A4', 'landscape');
  3097. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  3098. // return $pdf->download( $pdfName );
  3099. // }
  3100. // }
  3101. public function filterclaim($company, $year, $month, $app, $ptype)
  3102. {
  3103. $id = Auth::guard('ms')->id();
  3104. $user = Staff::with('StaffDetail')->find($id);
  3105. if ($year != 'null' && $month != 'null' && $app == 'null' && $ptype == 'null') {
  3106. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3107. $q->with('Form');
  3108. }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  3109. } else if ($year == 'null' && $month == 'null' && $app != 'null' && $ptype == 'null') {
  3110. if ($app == 'Residential') {
  3111. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3112. $q->with('Form');
  3113. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->orderBy('activated_dt', 'DESC')->get();
  3114. } else if ($app == 'Business') {
  3115. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3116. $q->with('Form');
  3117. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->orderBy('activated_dt', 'DESC')->get();
  3118. }
  3119. } else if ($year != 'null' && $month != 'null' && $app != 'null' && $ptype == 'null') {
  3120. if ($app == 'Residential') {
  3121. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3122. $q->with('Form');
  3123. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  3124. } else if ($app == 'Business') {
  3125. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3126. $q->with('Form');
  3127. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  3128. }
  3129. } else if ($year != 'null' && $month != 'null' && $app == 'null' && $ptype != 'null') {
  3130. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3131. $q->with('Form');
  3132. }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->where('projectT', $ptype)->orderBy('activated_dt', 'DESC')->get();
  3133. } else if ($year == 'null' && $month == 'null' && $app == 'null' && $ptype != 'null') {
  3134. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3135. $q->with('Form');
  3136. }], 'Staff')->where('projectT', $ptype)->where('dealer', $company)->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)->where('activated_my', $month . '/' . $year)->where('projectT', $ptype)->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)->where('activated_my', $month . '/' . $year)->where('projectT', $ptype)->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('projectT', $ptype)->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('projectT', $ptype)->orderBy('activated_dt', 'DESC')->get();
  3156. }
  3157. }
  3158. $i = 0;
  3159. $nested_data = array();
  3160. if (!empty($dataClaim)) {
  3161. foreach ($dataClaim as $c) {
  3162. $address = '';
  3163. $name = '';
  3164. if ($c->Subscriber->Form->type_application == 'R') {
  3165. if ($c->Subscriber->street != '') {
  3166. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3167. } else {
  3168. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3169. }
  3170. $name = $c->Subscriber->name;
  3171. } else if ($c->Subscriber->Form->type_application == 'B') {
  3172. if ($c->Subscriber->unit_no != '') {
  3173. $address = $c->Subscriber->unit_no . ', ' . $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3174. } else {
  3175. $address = $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3176. }
  3177. $name = $c->Subscriber->company_name;
  3178. }
  3179. $i++;
  3180. array_push($nested_data, array(
  3181. 'index' => $c->formT,
  3182. 'contract' => $c->contract,
  3183. 'wo' => $c->wo,
  3184. 'activated_dt' => $c->activated_dt,
  3185. 'name' => $name,
  3186. 'address' => $address,
  3187. 'package' => $c->package,
  3188. 'retail_price' => 'RM ' . $c->retail_price,
  3189. 'incentives1' => $c->incentives1,
  3190. 'incentives2' => $c->incentives2,
  3191. 'total' => 'RM ' . $c->total_claim,
  3192. 'claimed' => $c->claim_dt,
  3193. ));
  3194. }
  3195. }
  3196. return \DataTables::of($nested_data)->make(true);
  3197. }
  3198. public function exportPDFClaim($company, $year, $month, $app, $ptype)
  3199. {
  3200. $final = array();
  3201. $id = Auth::guard('ms')->id();
  3202. $user = Staff::with('StaffDetail')->find($id);
  3203. $com = Company::where('_id', $company)->first();
  3204. $i = 0;
  3205. $dataR = array();
  3206. $dataB = array();
  3207. $combineData = array();
  3208. $count_cyberjaya = array();
  3209. $count_jasin = array();
  3210. $count_ayerKeroh = array();
  3211. $count_alorGajah = array();
  3212. $extra = 0;
  3213. $basic_total = 0;
  3214. $totals = 0;
  3215. if ($year != 'null' && $month != 'null' && $app != 'null' && $ptype == 'null') {
  3216. if ($app == 'Residential') {
  3217. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3218. $q->with('Form');
  3219. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  3220. if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
  3221. foreach ($dataClaim as $key => $d) {
  3222. if (
  3223. date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  3224. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
  3225. ) {
  3226. if (strpos($d['address'], 'Cyberjaya') !== false) {
  3227. $count_cyberjaya[] = $d;
  3228. }
  3229. if (strpos($d['address'], 'Jasin') !== false) {
  3230. $count_jasin[] = $d;
  3231. }
  3232. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  3233. $count_ayerKeroh[] = $d;
  3234. }
  3235. if (strpos($d['address'], 'Alor Gajah') !== false) {
  3236. $count_alorGajah[] = $d;
  3237. }
  3238. }
  3239. }
  3240. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  3241. foreach ($dataClaim as $key => $d) {
  3242. if (
  3243. date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  3244. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
  3245. ) {
  3246. if (strpos($d['address'], 'Cyberjaya') !== false) {
  3247. $count_cyberjaya[] = $d;
  3248. }
  3249. if (strpos($d['address'], 'Jasin') !== false) {
  3250. $count_jasin[] = $d;
  3251. }
  3252. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  3253. $count_ayerKeroh[] = $d;
  3254. }
  3255. if (strpos($d['address'], 'Alor Gajah') !== false) {
  3256. $count_alorGajah[] = $d;
  3257. }
  3258. }
  3259. }
  3260. }
  3261. } else if ($app == 'Business') {
  3262. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3263. $q->with('Form');
  3264. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
  3265. }
  3266. } else if ($year != 'null' && $month != 'null' && $app != 'null' && $ptype != 'null') {
  3267. if ($app == 'Residential') {
  3268. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3269. $q->with('Form');
  3270. }], 'Staff')->where('formT', 'R')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->where('projectT', $ptype)->orderBy('activated_dt', 'DESC')->get();
  3271. if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
  3272. foreach ($dataClaim as $key => $d) {
  3273. if (
  3274. date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  3275. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
  3276. ) {
  3277. if (strpos($d['address'], 'Cyberjaya') !== false) {
  3278. $count_cyberjaya[] = $d;
  3279. }
  3280. if (strpos($d['address'], 'Jasin') !== false) {
  3281. $count_jasin[] = $d;
  3282. }
  3283. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  3284. $count_ayerKeroh[] = $d;
  3285. }
  3286. if (strpos($d['address'], 'Alor Gajah') !== false) {
  3287. $count_alorGajah[] = $d;
  3288. }
  3289. }
  3290. }
  3291. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  3292. foreach ($dataClaim as $key => $d) {
  3293. if (
  3294. date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  3295. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
  3296. ) {
  3297. if (strpos($d['address'], 'Cyberjaya') !== false) {
  3298. $count_cyberjaya[] = $d;
  3299. }
  3300. if (strpos($d['address'], 'Jasin') !== false) {
  3301. $count_jasin[] = $d;
  3302. }
  3303. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  3304. $count_ayerKeroh[] = $d;
  3305. }
  3306. if (strpos($d['address'], 'Alor Gajah') !== false) {
  3307. $count_alorGajah[] = $d;
  3308. }
  3309. }
  3310. }
  3311. }
  3312. } else if ($app == 'Business') {
  3313. $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
  3314. $q->with('Form');
  3315. }], 'Staff')->where('formT', 'B')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->where('projectT', $ptype)->orderBy('activated_dt', 'DESC')->get();
  3316. }
  3317. }
  3318. if (!empty($dataClaim)) {
  3319. foreach ($dataClaim as $c) {
  3320. $address = '';
  3321. $name = '';
  3322. if ($c->Subscriber->Form->type_application == 'R') {
  3323. if ($c->Subscriber->street != '') {
  3324. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3325. } else {
  3326. $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3327. }
  3328. $name = $c->Subscriber->name;
  3329. } else if ($c->Subscriber->Form->type_application == 'B') {
  3330. if ($c->Subscriber->unit_no != '') {
  3331. $address = $c->Subscriber->unit_no . ', ' . $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3332. } else {
  3333. $address = $c->Subscriber->company_name . ', ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
  3334. }
  3335. $name = $c->Subscriber->company_name;
  3336. }
  3337. $i++;
  3338. array_push($final, array(
  3339. 'index' => $c->formT,
  3340. 'contract' => $c->contract,
  3341. 'wo' => $c->wo,
  3342. 'activated_dt' => $c->activated_dt,
  3343. 'name' => $name,
  3344. 'address' => $address,
  3345. 'package' => $c->package,
  3346. 'retail_price' => 'RM ' . $c->retail_price,
  3347. 'incentives1' => $c->incentives1,
  3348. 'incentives2' => $c->incentives2,
  3349. 'total' => 'RM' . $c->total_claim,
  3350. 'claimed' => $c->claim_dt,
  3351. ));
  3352. }
  3353. foreach ($dataClaim as $f) {
  3354. $basic_total += $f->total_claim;
  3355. $invoice_no = '';
  3356. if (!empty($f->invoice_no)) {
  3357. $invoice_no = $f->invoice_no;
  3358. }
  3359. }
  3360. // Calculate extra incentves
  3361. if ($month == '01' && $year == '2020') {
  3362. if (count($count_cyberjaya) > 50) {
  3363. $balance = count($count_cyberjaya) - 50;
  3364. $extra += $balance * 50;
  3365. }
  3366. if (count($count_jasin) > 10) {
  3367. $balance = count($count_jasin) - 10;
  3368. $extra += $balance * 50;
  3369. }
  3370. if (count($count_ayerKeroh) > 10) {
  3371. $balance = count($count_ayerKeroh) - 10;
  3372. $extra += $balance * 50;
  3373. }
  3374. if (count($count_alorGajah) > 10) {
  3375. $balance = count($count_alorGajah) - 10;
  3376. $extra += $balance * 50;
  3377. }
  3378. } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
  3379. if (count($count_cyberjaya) > 50) {
  3380. $balance = count($count_cyberjaya) - 50;
  3381. $extra += $balance * 50;
  3382. }
  3383. if (count($count_jasin) > 20) {
  3384. $balance = count($count_jasin) - 20;
  3385. $extra += $balance * 50;
  3386. }
  3387. if (count($count_ayerKeroh) > 20) {
  3388. $balance = count($count_ayerKeroh) - 20;
  3389. $extra += $balance * 50;
  3390. }
  3391. if (count($count_alorGajah) > 20) {
  3392. $balance = count($count_alorGajah) - 20;
  3393. $extra += $balance * 50;
  3394. }
  3395. } else {
  3396. $extra = 0;
  3397. }
  3398. $totals = $basic_total + $extra;
  3399. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year', 'com', 'basic_total', 'extra', 'totals', 'invoice_no'));
  3400. $pdf->setPaper('A4', 'landscape');
  3401. if ($ptype != null) {
  3402. $pdfName = preg_replace('/\s+/', '-', $com->name) . '-' . $app . '-' . $ptype . '-' . $month . '-' . $year . '.pdf';
  3403. } else {
  3404. $pdfName = preg_replace('/\s+/', '-', $com->name) . '-' . $app . '-' . $month . '-' . $year . '.pdf';
  3405. }
  3406. return $pdf->download($pdfName);
  3407. }
  3408. }
  3409. public function manualDate()
  3410. {
  3411. $final = array();
  3412. $com = Company::where('_id', '5bb2bc66ee0dc2271c6fedf6')->first();
  3413. $dataR = array();
  3414. $dataB = array();
  3415. $combineData = array();
  3416. $count_cyberjaya = array();
  3417. $count_jasin = array();
  3418. $count_ayerKeroh = array();
  3419. $count_alorGajah = array();
  3420. $extra = 0;
  3421. $basic_total = 0;
  3422. $totals = 0;
  3423. $dataDis = $this->returnDataR('5bb2bc66ee0dc2271c6fedf6', '2019', '12');
  3424. foreach ($dataDis as $key => $d) {
  3425. if (date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019') {
  3426. $combineData[] = $d;
  3427. }
  3428. }
  3429. $dataB = $this->returnDataB('5bb2bc66ee0dc2271c6fedf6', '2019', '12');
  3430. foreach ($dataB as $b) {
  3431. $combineData[] = $b;
  3432. }
  3433. $i = 0;
  3434. $nested_data = array();
  3435. if (!empty($combineData)) {
  3436. foreach ($combineData as $c) {
  3437. $i++;
  3438. array_push($final, array(
  3439. 'index' => $c['index'],
  3440. 'contract' => $c['contract'],
  3441. 'wo' => $c['wo'],
  3442. 'activated_dt' => $c['activation'],
  3443. 'name' => $c['name'],
  3444. 'address' => $c['address'],
  3445. 'package' => $c['package'],
  3446. 'retail_price' => $c['retail_price'],
  3447. 'incentives1' => $c['incentives1'],
  3448. 'incentives2' => $c['incentives2'],
  3449. 'total' => $c['total'],
  3450. 'claimed' => $c['claim'],
  3451. ));
  3452. }
  3453. }
  3454. usort($final, function ($a, $b) {
  3455. $dateA = $a['activated_dt'];
  3456. $dateB = $b['activated_dt'];
  3457. // ascending ordering, use `<=` for descending
  3458. return $dateA <= $dateB;
  3459. });
  3460. return json_encode($final);
  3461. }
  3462. }