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

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