| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908 |
- <?php
-
- namespace App\Http\Controllers\DS;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\Auth;
-
- use Carbon\Carbon;
- use Validator;
- use PDF;
-
- use App\Staff;
- use App\Model\StaffDetail;
-
- use App\Model\Coverage;
- use App\Model\DealerClaim;
- use App\Model\DealerClaim2;
-
- use App\Model\Commission;
- use App\Model\Company;
-
- use App\Model\Form;
- use App\Model\FormStatus;
- use App\Model\Subscriber;
- use App\Model\PackageDetail;
- use App\Model\WorkOrder;
- use App\Model\Docket;
-
- class DealerController extends Controller
- {
-
- public function viewList()
- {
- $id = Auth::guard('ds')->id();
- $user = Staff::with('StaffDetail')->find($id);
- return view('dealer.index', compact('user'));
- }
-
- /***
- / Agent list
- ***/
- public function gAgentList()
- {
-
- $id = Auth::guard('ds')->id();
- $user = Staff::find($id);
- $email = $user->email;
-
- $userDetails = StaffDetail::where('email', $email)->first();
-
- $all = StaffDetail::where('company_id', $userDetails->company_id)->orderBy('created_at', 'desc')->get();
- $curr = Carbon::now()->getTimestamp();
-
- $i = 0;
- $nested_data = array();
- if (!empty($all)) {
- foreach ($all as $a) {
- $i++;
- $y = '';
- $n1 = '';
- if ($userDetails->_id == $a->_id) {
- $y = $a->name . "-You";
- } else {
- $y = $a->name;
- }
-
- $reg_time = $a->created_at;
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- array_push($nested_data, array(
- 'index' => $i,
- 'image' => $a->user_pic,
- 'name' => $n1 . $y,
- 'ic' => $a->ic,
- 'phone' => $a->phone,
- 'email' => $a->email,
- 'action' => $a->_id
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- /***
- / Application Form List
- ***/
- public function viewAppList()
- {
-
- $id = Auth::guard('ds')->id();
- $user = Staff::with('StaffDetail')->find($id);
- return view('dealer.application-form-list', compact('user'));
- }
-
- /***
- / Get Application Form List
- ***/
- public function getSubscribers($dealerCompany)
- {
- $data = array();
- $curr = Carbon::now()->getTimestamp();
- $subscriber = Subscriber::where('dealer_company', $dealerCompany)->get();
- foreach ($subscriber as $key => $s) {
-
- $n1 = '';
- $reg_time = Carbon::createFromTimestamp($s->reg_time);
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- $agentName = StaffDetail::where('_id', $s->dealer)->first();
- $build = Coverage::where('address', $s->building)->first();
- if ($s->street == '') {
- $street = $build->street;
- } else {
- $street = $s->street;
- }
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $data[] = array(
- 'formT' => 'R',
- 'wo' => $s->wo,
- 'name' => $n1 . $s->name,
- 'no' => $s->phone1,
- 'unit' => $s->unit_no,
- 'building' => $s->building,
- 'street' => $street,
- 'postcode' => $s->postcode,
- 'city' => $s->city,
- 'sales' => $agentName->name,
- 'created_at' => $s->reg_time,
- 'action' => $s->_id,
- );
- }
-
- return $data;
- }
-
- public function getBusiness($dealerCompany)
- {
-
- $data = array();
- $curr = Carbon::now()->getTimestamp();
- $business = Subscriber::where('dealer_company', $dealerCompany)->get();
-
- foreach ($business as $key => $s) {
-
- $n1 = '';
- $reg_time = Carbon::createFromTimestamp($s->reg_time);
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $agentName = StaffDetail::where('_id', $s->dealer)->first();
-
- $data[] = array(
- 'formT' => 'B',
- 'wo' => $s->wo,
- 'name' => $n1 . $s->name,
- 'no' => $s->phone1,
- 'unit' => '-',
- 'building' => '-',
- 'street' => $s->address,
- 'postcode' => $s->postcode,
- 'city' => $s->city,
- 'sales' => $agentName->name,
- 'created_at' => $s->reg_time,
- 'action' => $s->_id,
- );
- }
-
- return $data;
- }
-
- public function getOrderHistory($id)
- {
-
- $data = array();
- $order_history = FormStatus::where('form_id', $id)->get();
- foreach ($order_history as $oh) {
- $utcdatetime = new \MongoDB\BSON\UTCDateTime((string) $oh->date);
- $datetime = $utcdatetime->toDateTime();
- $time = $datetime->format(DATE_RSS);
- $time = strtotime($time . ' UTC');
- $dateInLocal = date("d/m/Y h:i a", $time);
- $data[] = array(
- 'date' => $dateInLocal,
- 'status' => $oh->status,
- 'desc' => $oh->desc
- );
- }
-
- $json = json_encode($data);
- return $json;
- }
-
- public function gApplicationList1()
- {
- $id = Auth::guard('ds')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $fm = Form::with('Subscriber')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
-
- $nested_data = array();
- $i = 0;
-
- foreach ($fm as $f) {
- $dname = "";
- $wo = WorkOrder::where('_id', $f->_id)->first();
- $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
-
- if (!empty($dealer)) {
- $dname = $dealer->name;
- }
-
- $address = '';
- $name = '';
- if ($f->type_application == 'R') {
- if (!empty($f->Subscriber->building_name)) {
- $address = $f->Subscriber->building_name;
- $name = $f->Subscriber->name;
- }
- } else if ($f->type_application == 'B') {
- $address = '-';
- $name = $f->Subscriber->company_name;
- }
-
- if (empty($wo) && !empty($f->Subscriber)) {
- $i++;
- array_push($nested_data, array(
- 'index' => $i . $f->type_application,
- 'name' => $name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $f->Subscriber->unit_no,
- 'building' => $address,
- 'street' => $f->Subscriber->street,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'sales' => $dname,
- 'action' => $f->_id
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function gApplicationList2()
- {
- $id = Auth::guard('ds')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $fm = Form::with('Subscriber')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
-
- $nested_data = array();
- $i = 0;
-
- foreach ($fm as $f) {
- $dname = "";
- $wo = WorkOrder::where('_id', $f->_id)->first();
- $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
-
- if (!empty($dealer)) {
- $dname = $dealer->name;
- }
-
- $address = '';
- $name = '';
- if ($f->type_application == 'R') {
- if (!empty($f->Subscriber->building_name)) {
- $address = $f->Subscriber->building_name;
- $name = $f->Subscriber->name;
- }
- } else if ($f->type_application == 'B') {
- $address = '-';
- $name = $f->Subscriber->company_name;
- }
-
-
- if (!empty($wo) && $wo->status != 'Completed') {
- $i++;
- array_push($nested_data, array(
- 'index' => $i . $f->type_application,
- 'name' => $name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $f->Subscriber->unit_no,
- 'building' => $address,
- 'street' => $f->Subscriber->street,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'sales' => $dname,
- 'action' => $f->_id
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function getCompletedList($year, $month)
- {
-
- $id = Auth::guard('ds')->id();
- $user = Staff::find($id);
- $email = $user->email;
-
- $userDetails = StaffDetail::where('email', $email)->first();
-
- $subs = $this->getSubscribers($userDetails->company_id);
- $buss = $this->getBusiness($userDetails->company_id);
-
- // Combine
- $cdata = array();
- foreach ($subs as $key => $s) {
- $cdata[] = $s;
- }
-
- foreach ($buss as $key => $b) {
- $cdata[] = $b;
- }
-
- // Sort based on TimeStamp
- $sort = array();
- foreach ($cdata as $key => $r) {
- $sort[$key] = $r['created_at'];
- }
- array_multisort($sort, SORT_DESC, $cdata);
-
- $wK = WorkDetail::get();
- $curr = Carbon::now()->getTimestamp();
-
- $mY = '';
- if ($year != 'null' && $month != 'null') {
- $mY = $year . '/' . $month;
- }
-
- $final = array();
- $filter = array();
- $dW = array();
-
- foreach ($cdata as $c) {
- if ($c['wo'] != '') {
- foreach ($wK as $key => $w) {
- if ($c['wo'] == $w->wo && $w->status == 'Completed') {
- $dW[] = $c;
- }
- }
- }
- }
-
- foreach ($dW as $d) {
- if ($mY != '') {
- $docket = Docket::where('work_order_id', $d['wo'])->first();
- $cDate = date('Y/m', strtotime($docket->end_job));;
- if ($mY == $cDate) {
- $filter[] = $d;
- }
- } else {
- $filter[] = $d;
- }
- }
-
- foreach ($filter as $c) {
- $do = Docket::where('work_order_id', $c['wo'])->first();
-
- $n1 = '';
- $reg_time = Carbon::createFromTimestamp(strtotime($do->end_job));
- $expiry_date = $reg_time->addDays(3);
- $expiry_date = $expiry_date->getTimestamp();
-
- if ($curr < $expiry_date) {
- $n1 = "New/";
- }
-
- $final[] = array(
- 'formT' => $c['formT'],
- 'wo' => $c['wo'],
- 'do' => $do->docket_id,
- 'activated' => $do->end_job,
- 'name' => $n1 . str_replace("New/", "", $c['name']),
- 'no' => $c['no'],
- 'unit' => $c['unit'],
- 'building' => $c['building'],
- 'street' => $c['street'],
- 'postcode' => $c['postcode'],
- 'city' => $c['city'],
- 'sales' => $c['sales'],
- 'created_at' => $c['created_at'],
- 'action' => $c['action'],
- );
- }
-
- return $final;
- }
- public function gApplicationList3($year, $month)
- {
- $id = Auth::guard('ds')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $mY = '';
- if ($year != 'null' && $month != 'null') {
- $mY = $month . '/' . $year;
- }
-
- $fm = Form::with('Subscriber', 'WorkOrder')->where('company_id', $user->StaffDetail->company_id)->orderBy('created_at', 'desc')->get();
-
- $nested_data = array();
- $i = 0;
- foreach ($fm as $f) {
- if (!empty($f->WorkOrder)) {
- if ($f->WorkOrder->status == 'Completed') {
-
- $wo = WorkOrder::with('Docket')->where('wo', $f->WorkOrder->wo)->first();
- $dealer = StaffDetail::where('_id', $f->dealer_id)->withTrashed()->first();
- $i++;
-
- $address = '';
- $name = '';
- if ($f->type_application == 'R') {
- if (!empty($f->Subscriber->building_name)) {
- $address = $f->Subscriber->building_name;
- $name = $f->Subscriber->name;
- }
- } else if ($f->type_application == 'B') {
- $address = '-';
- $name = $f->Subscriber->company_name;
- }
-
- if (!empty($wo->Docket)) {
- $end = date('m/Y', strtotime($wo->Docket->end_job));
-
- if ($mY == '') {
- array_push($nested_data, array(
- 'index' => $i . $f->type_application,
- 'wo' => $wo->wo,
- 'do' => $f->WorkOrder->docket_id,
- 'name' => $name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $f->Subscriber->unit_no,
- 'building' => $address,
- 'street' => $f->Subscriber->street,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'sales' => $dealer->name,
- 'action' => $f->_id
- ));
- } else if ($mY == $end) {
- array_push($nested_data, array(
- 'index' => $i . $f->type_application,
- 'wo' => $wo->wo,
- 'do' => $f->WorkOrder->docket_id,
- 'name' => $name,
- 'phone' => $f->Subscriber->phone1,
- 'unit' => $f->Subscriber->unit_no,
- 'building' => $address,
- 'street' => $f->Subscriber->street,
- 'postcode' => $f->Subscriber->postcode,
- 'city' => $f->Subscriber->city,
- 'sales' => $dealer->name,
- 'action' => $f->_id
- ));
- }
- }
- }
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- /***
- / Claim All
- ***/
- public function claimAll()
- {
-
- $id = Auth::guard('ds')->id();
- $user = Staff::with('StaffDetail')->find($id);
- return view('dealer.claim-all', compact('user'));
- }
-
- /***
- / Convert To PDF
- ***/
- public function exportPDF1()
- {
- return view('pdf.agent-claim');
- }
- public function exportPDF($company, $year, $month, $app)
- {
-
- $final = array();
-
- $id = Auth::guard('ds')->id();
- $user = Staff::with('StaffDetail')->find($id);
- $com = Company::where('_id', $user->StaffDetail->company_id)->first();
- $i = 0;
-
- $dataR = array();
- $dataB = array();
- $combineData = array();
-
- $count_cyberjaya = array();
- $count_jasin = array();
- $count_ayerKeroh = array();
- $count_alorGajah = array();
- $count_menglembu = array();
- $count_ipoh = array();
- $extra = 0;
- $basic_total = 0;
- $totals = 0;
-
- if ($year != 'null' && $month != 'null' && $app != 'null') {
-
- if ($app == 'Residential') {
- $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
- $q->with('Form');
- }], 'Staff')->where('formT', 'R')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
-
- if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
-
- foreach ($dataClaim as $key => $d) {
- if (
- date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
- date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
- ) {
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- }
- }
- } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
-
- foreach ($dataClaim as $key => $d) {
- if (
- date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
- date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
- ) {
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- }
- }
- }
- } else if ($app == 'Business') {
- $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
- $q->with('Form');
- }], 'Staff')->where('formT', 'B')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
- }
- }
-
- if (!empty($dataClaim)) {
- foreach ($dataClaim as $c) {
-
- $address = '';
- $name = '';
- if ($c->Subscriber->Form->type_application == 'R') {
-
- if ($c->Subscriber->street != '') {
- $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- } else {
- $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- }
-
- $name = $c->Subscriber->name;
- } else if ($c->Subscriber->Form->type_application == 'B') {
-
- if ($c->Subscriber->unit_no != '') {
- $unit = $c->Subscriber->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($c->Subscriber->building_name == null) {
- $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- } else {
- $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- }
-
- $name = $c->Subscriber->company_name;
- }
-
- $i++;
- array_push($final, array(
- 'index' => $c->formT,
- 'contract' => $c->contract,
- 'wo' => $c->wo,
- 'do' => $c->docket,
- 'activated_dt' => $c->activated_dt,
- 'name' => $name,
- 'address' => $address,
- 'package' => $c->package,
- 'retail_price' => 'RM ' . $c->retail_price,
- 'incentives1' => $c->incentives1,
- 'incentives2' => $c->incentives2,
- 'total' => 'RM' . $c->total_claim,
- 'claimed' => $c->claim_dt,
- ));
- }
-
- $project_type = '';
- $invoice_no = '';
-
- foreach ($dataClaim as $f) {
- $basic_total += $f->total_claim;
- }
-
- // Calculate extra incentves
- if ($month == '01' && $year == '2020') {
- if (count($count_cyberjaya) > 50) {
- $balance = count($count_cyberjaya) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_ayerKeroh) > 50) {
- $balance = count($count_ayerKeroh) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_alorGajah) > 50) {
- $balance = count($count_alorGajah) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_menglembu) > 50) {
- $balance = count($count_menglembu) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_ipoh) > 50) {
- $balance = count($count_ipoh) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_jasin) > 10) {
- $balance = count($count_jasin) - 10;
- $extra += $balance * 50;
- }
- } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
-
- if (count($count_cyberjaya) > 50) {
- $balance = count($count_cyberjaya) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_ayerKeroh) > 50) {
- $balance = count($count_ayerKeroh) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_alorGajah) > 50) {
- $balance = count($count_alorGajah) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_menglembu) > 50) {
- $balance = count($count_menglembu) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_ipoh) > 50) {
- $balance = count($count_ipoh) - 50;
- $extra += $balance * 50;
- }
-
- if (count($count_jasin) > 20) {
- $balance = count($count_jasin) - 20;
- $extra += $balance * 50;
- }
- } else {
- $extra = 0;
- }
-
- $totals = $basic_total + $extra;
-
- $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year', 'com', 'basic_total', 'extra', 'totals', 'invoice_no', 'project_type'));
- $pdf->setPaper('A4', 'landscape');
- $pdfName = preg_replace('/\s+/', '-', $com->name) . '-' . $month . '-' . $year . '.pdf';
-
- return $pdf->download($pdfName);
- }
- }
-
- /***
- / Encrypt Password
- ***/
- public function encryptPassword($action, $string)
- {
- $output = false;
- $encrypt_method = "AES-256-CBC";
- $secret_key = '28472B4B6250655368566D5970337336';
- $secret_iv = md5(md5($string)); //'This is my secret iv';
-
- // hash
- $key = hash('sha256', $secret_key);
-
- $iv = substr(hash('sha256', $secret_iv), 0, 16);
- if ($action == 'encrypt') {
- $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
- $output = base64_encode($output);
- } else if ($action == 'decrypt') {
- $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
- }
- return $output;
- }
-
- /***
- / Agent Form
- ***/
- public function showAgentForm()
- {
-
- $id = Auth::guard('ds')->id();
- $user = Staff::with('StaffDetail')->find($id);
- return view('dealer.add_agent', compact('user'));
- }
-
- /***
- / Add Agent
- ***/
- public function requestAddAgent(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'password' => 'min:8|confirmed',
- ]);
-
- if ($validator->fails()) {
- return redirect()->back()->withInput()->withErrors($validator);
- }
-
- $user = Staff::where('email', $request->get('email'))->first();
- if (empty($user)) {
-
- $pass = $this->encryptPassword('encrypt', $request->get('password'));
-
- $dealerD = new StaffDetail;
- $dealerD->name = $request->get('aname');
- $dealerD->ic = $request->get('ic');
- $dealerD->email = $request->get('email');
- $dealerD->phone = $request->get('phone');
- $dealerD->company_id = $request->get('company_id');
- $dealerD->color = '';
- $dealerD->position = 'Sales';
- $dealerD->password = $pass;
- $dealerD->user_pic = 'assets/avatar/user.png';
-
- // Save Login Dealer
- $loginD = new Staff;
- $loginD->email = $request->get('email');
- $loginD->password = $pass;
- $loginD->roles_access = 'Sales';
- $loginD->company_id = $request->get('company_id');
- $loginD->last_login_at = '';
- $loginD->last_login_ip = '';
-
- // $loginData = [
- // 'email' => $request->get('email'),
- // 'password' => $pass,
- // 'roles_access' => 'Sales',
- // 'last_login_at' => '',
- // 'last_login_ip' => '',
- // ];
-
- $company = Company::where('_id', $request->get('company_id'))->first();
- $company->staff()->save($loginD);
- // $dealer = DealerLaravel::create($loginData);
- $loginD->staffdetail()->save($dealerD);
-
- return redirect()->back()->with('success_msg', '<strong>Success!</strong> register <strong>' . $request->get('email') . '</strong>');
- } else {
- return redirect()->back()->withInput()->withErrors('Email already exist!');
- }
- }
-
- public function editAgentDealer($agent_id)
- {
- $id = Auth::guard('ds')->id();
- $user = Staff::find($id);
- $email = $user->email;
-
- $userDetails = StaffDetail::where('email', $email)->first();
-
- $person = StaffDetail::where('_id', $agent_id)->first();
- return view('dealer.edit_agent', compact('person', 'userDetails', 'user'));
- }
-
- public function deleteAgent(Request $request)
- {
- $agent = Staff::where('_id', $request->id)->first();
- $agentdetail = $agent->staffdetail()->first();
-
- if (!empty($agentdetail) && !empty($agent)) {
- $agent->delete();
- $agentdetail->delete();
- return 'true';
- } else {
- return 'false';
- }
- }
-
- //Show claim list by company
- public function mClaimListAll($company)
- {
- $id = Auth::guard('ds')->id();
- $user = Staff::with('StaffDetail')->find($id);
-
- $dealer_claimAll = DealerClaim::where('dealer', $company)->orderBy('activated_dt', 'desc')->get();
-
- $i = 0;
- $nested_data = array();
- foreach ($dealer_claimAll as $c) {
- $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first();
- $address = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- }
-
- $i++;
- array_push($nested_data, array(
- 'index' => $c->formT,
- 'contract' => $c->contract,
- 'wo' => $c->wo,
- 'activated_dt' => $c->activated_dt,
- 'name' => $customer->name,
- 'address' => $address,
- 'package' => $c->package,
- 'retail_price' => 'RM ' . $c->retail_price,
- 'incentives1' => '',
- 'incentives2' => '',
- 'total' => '',
- 'claimed' => $c->laim_dt,
- 'action' => 'null',
- ));
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- // Get Dealer Claim Residential
- public function returnDataR($company, $year, $month)
- {
-
- $dataCR = DealerClaim::where('formT', 'R')->where('dealer', $company)->get();
- $final = array();
-
- // Month & Year
- $mY = '';
- if ($year != 'null' && $month != 'null') {
- $mY = $month . '/' . $year;
- }
-
- if ($mY != '') {
-
- $data12 = array();
- $data24 = array();
- $countD12 = 0;
- $countD24 = 0;
-
- foreach ($dataCR as $dc) {
- if ($dc->activated_my == $mY || $dc->activated_my == '0' . $mY) {
- if ($dc->contract == "12") {
- $data12[] = $dc;
- } else if ($dc->contract == "24") {
- $data24[] = $dc;
- }
- }
- }
-
- $countD24 = count($data24);
- $countD12 = count($data12);
-
- $comm = Commission::where('formT', 'R')->get();
- $commV12 = 0;
- $commV24 = 0;
- $comm12 = '';
- $comm24 = '';
- $addRM24 = '';
-
- foreach ($comm as $c) {
- if ($c->contract == '12') {
- if (strpos($c->ranges, '>') !== false) {
-
- $pieces = explode(">", $c->ranges);
-
- if ($countD12 >= intval($pieces[1])) {
- $commV12 = floatval($c->comm) / 100;
- $comm12 = $c->comm . '%';
- }
- }
- if (strpos($c->ranges, '-') !== false) {
-
- $pieces = explode("-", $c->ranges);
-
- if ($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])) {
- $commV12 = floatval($c->comm) / 100;
- $comm12 = $c->comm . '%';
- }
- }
- } else if ($c->contract == '24') {
- // Contract => 24
- if ($countD24 != 0) {
- if (strpos($c->ranges, '>') !== false) {
-
- $pieces = explode(">", $c->ranges);
-
- if ($countD24 >= intval($pieces[1])) {
- if (strpos($c->comm, 'RM') !== false) {
- $comm24 = '+ ' . $c->comm;
- $commV24 = '';
- $addRM24 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (!empty($comms[1])) {
- $comm24 = 'RM ' . $comms[1];
- $commV24 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24 = $comms[0] . '%';
- $commV24 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
- if (strpos($c->ranges, '-') !== false) {
-
- $pieces = explode("-", $c->ranges);
-
- if ($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])) {
- if (strpos($c->comm, 'RM') !== false) {
- $comms = explode(" + RM ", $c->comm);
- $comm24 = $comms[0] . '%';
- $commV24 = floatval($comms[0]) / 100;
- $addRM24 = floatval($comms[1]);
- } else {
- $comms = explode("RM", $c->comm);
- if (!empty($comms[1])) {
- $comm24 = 'RM ' . $comms[1];
- $commV24 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24 = $comms[0] . '%';
- $commV24 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
- }
- }
- }
-
- foreach ($data12 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = '';
-
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm12,
- 'incentives2' => '',
- 'total' => 'RM ' . number_format($d['retail_price'] * $commV12, 2),
- 'claim' => $d['claim_dt'],
- );
- }
-
- foreach ($data24 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
-
- $total = '';
- if ($commV24 == '') {
- $total = $addRM24;
- } else {
- $total = number_format(($d['retail_price'] * $commV24) + floatval($addRM24), 2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm24,
- 'incentives2' => $addRM24,
- 'total' => $total,
- 'claim' => $d['claim_dt'],
- );
- }
- } else {
-
- foreach ($dataCR as $c) {
-
- $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
-
- $final[] = array(
- 'index' => $c['formT'],
- 'contract' => $c['contract'],
- 'wo' => $c['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $c['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $c['package'],
- 'retail_price' => 'RM ' . $c['retail_price'],
- 'incentives1' => '',
- 'incentives2' => '',
- 'total' => '',
- 'claim' => $c['claim_dt'],
- );
- }
- }
-
- return $final;
- }
-
-
- // Get Claim Business
- public function returnDataB($company, $year, $month)
- {
-
- $dataCB = DealerClaim::where('formT', 'B')->where('dealer', $company)->get();
- $final = array();
-
- // Month & Year
- $mY = '';
- if ($year != 'null' && $month != 'null') {
- $mY = $month . '/' . $year;
- }
-
- if ($mY != '') {
-
- /** Contract 12
- // 1=>10-100 2=>300 3=>500 4=>1
- **/
- $data12_1 = array();
- $data12_2 = array();
- $data12_3 = array();
- $data12_4 = array();
-
- $countD12_1 = 0;
- $countD12_2 = 0;
- $countD12_3 = 0;
- $countD12_4 = 0;
- /** Contract 24
- // 1=>10-100 2=>300 3=>500 4=>1
- **/
- $data24_1 = array();
- $data24_2 = array();
- $data24_3 = array();
- $data24_4 = array();
-
- $countD24_1 = 0;
- $countD24_2 = 0;
- $countD24_3 = 0;
- $countD24_4 = 0;
-
- foreach ($dataCB as $dc) {
- if ($dc->activated_my == $mY || $dc->activated_my == '0' . $mY) {
-
- if ($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")) {
- $data12_1[] = $dc;
- } else if ($dc->contract == "12" && $dc->package == "300") {
- $data12_2[] = $dc;
- } else if ($dc->contract == "12" && $dc->package == "500") {
- $data12_3[] = $dc;
- } else if ($dc->contract == "12" && $dc->package == "1") {
- $data12_4[] = $dc;
- } else if ($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")) {
- $data24_1[] = $dc;
- } else if ($dc->contract == "24" && $dc->package == "300") {
- $data24_2[] = $dc;
- } else if ($dc->contract == "24" && $dc->package == "500") {
- $data24_3[] = $dc;
- } else if ($dc->contract == "24" && $dc->package == "1") {
- $data24_4[] = $dc;
- }
- }
- }
-
- $countD12_1 = count($data12_1);
- $countD12_2 = count($data12_2);
- $countD12_3 = count($data12_3);
- $countD12_4 = count($data12_4);
-
- $countD24_1 = count($data24_1);
- $countD24_2 = count($data24_2);
- $countD24_3 = count($data24_3);
- $countD24_4 = count($data24_4);
-
- $comm = Commission::where('formT', 'B')->get();
-
- $commV12_1 = 0;
- $commV12_2 = 0;
- $commV12_3 = 0;
- $commV12_4 = 0;
-
- $commV24_1 = 0;
- $commV24_2 = 0;
- $commV24_3 = 0;
- $commV24_4 = 0;
-
- $comm12_1 = '';
- $comm12_2 = '';
- $comm12_3 = '';
- $comm12_4 = '';
-
- $comm24_1 = '';
- $comm24_2 = '';
- $comm24_3 = '';
- $comm24_4 = '';
-
- $addRM12_1 = '';
- $addRM12_2 = '';
- $addRM12_3 = '';
- $addRM12_4 = '';
-
- $addRM24_1 = '';
- $addRM24_2 = '';
- $addRM24_3 = '';
- $addRM24_4 = '';
-
- foreach ($comm as $c) {
-
- /*** Contract 24 **/
- if ($c->contract == '24' && $c->packageR == "300") {
-
- if (strpos($c->ranges, '-') !== false) {
-
- $pieces = explode("-", $c->ranges);
-
- if ($countD24_2 >= intval($pieces[0]) && $countD24_2 <= intval($pieces[1])) {
-
- if (strpos($c->comm, 'RM') !== false) {
- $comm24_2 = '+ ' . $c->comm;
- $commV24_2 = '';
- $addRM24_2 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (!empty($comms[1])) {
- $comm24_2 = 'RM ' . $comms[1];
- $commV24_2 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24_2 = $comms[0] . '%';
- $commV24_2 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
-
- if (strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if ($countD24_2 >= intval($pieces[1])) {
- if (strpos($c->comm, 'RM') !== false) {
- $comm24_2 = '+ ' . $c->comm;
- $commV24_2 = '';
- $addRM24_2 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (!empty($comms[1])) {
- $comm24_2 = 'RM ' . $comms[1];
- $commV24_2 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24_2 = $comms[0] . '%';
- $commV24_2 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
- } else if ($c->contract == '24' && $c->packageR == "500") {
-
-
- if (strpos($c->ranges, '-') !== false) {
-
- $pieces = explode("-", $c->ranges);
-
- if ($countD24_3 >= intval($pieces[0]) && $countD24_3 <= intval($pieces[1])) {
-
- if (strpos($c->comm, 'RM') !== false) {
- $comm24_3 = '+ ' . $c->comm;
- $commV24_3 = '';
- $addRM24_3 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (!empty($comms[1])) {
- $comm24_3 = 'RM ' . $comms[1];
- $commV24_3 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24_3 = $comms[0] . '%';
- $commV24_3 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
-
- if (strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if ($countD24_3 >= intval($pieces[1])) {
- if (strpos($c->comm, 'RM') !== false) {
- $comm24_3 = '+ ' . $c->comm;
- $commV24_3 = '';
- $addRM24_3 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (isset($comms[1])) {
- $comm24_3 = 'RM ' . $comms[1];
- $commV24_3 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24_3 = $comms[0] . '%';
- $commV24_3 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
- } else if ($c->contract == '24' && $c->packageR == "1") {
- if (strpos($c->ranges, '-') !== false) {
-
- $pieces = explode("-", $c->ranges);
-
- if ($countD24_4 >= intval($pieces[0]) && $countD24_4 <= intval($pieces[1])) {
-
- if (strpos($c->comm, 'RM') !== false) {
- $comm24_4 = '+ ' . $c->comm;
- $commV24_4 = '';
- $addRM24_4 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (!empty($comms[1])) {
- $comm24_4 = 'RM ' . $comms[1];
- $commV24_4 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24_4 = $comms[0] . '%';
- $commV24_4 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
-
- if (strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if ($countD24_4 >= intval($pieces[1])) {
- if (strpos($c->comm, 'RM') !== false) {
- $comm24_4 = '+ ' . $c->comm;
- $commV24_4 = '';
- $addRM24_4 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (isset($comms[1])) {
- $comm24_4 = 'RM ' . $comms[1];
- $commV24_4 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24_4 = $comms[0] . '%';
- $commV24_4 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
- } else if ($c->contract == '24' && $c->packageR == "10,30,50,100") {
-
- if (strpos($c->ranges, '-') !== false) {
-
- $pieces = explode("-", $c->ranges);
-
- if ($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])) {
-
- if (strpos($c->comm, 'RM') !== false) {
- $comm24_1 = '+ ' . $c->comm;
- $commV24_1 = '';
- $addRM24_1 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (!empty($comms[1])) {
- $comm24_1 = 'RM ' . $comms[1];
- $commV24_1 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24_1 = $comms[0] . '%';
- $commV24_1 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
-
- if (strpos($c->ranges, '>') !== false) {
- $pieces1 = explode(">", $c->ranges);
- if ($countD24_1 >= intval($pieces1[1])) {
- if (strpos($c->comm, "RM") === true) {
- $comm24_1 = '+ ' . $c->comm;
- $commV24_1 = '';
- $addRM24_1 = $c->comm;
- } else {
-
- $comms = explode("RM", $c->comm);
- if (empty($comms[1])) {
- $comm24_1 = 'RM ' . $comms[1];
- $commV24_1 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm24_1 = str_replace('+ ', '', $comms[0]) . '%';
- $commV24_1 = floatval($comms[0]) / 100;
- $addRM24_1 = $comms[1];
- }
- }
- }
- }
- }
- }
-
- /*** Contract 12 **/
- else if ($c->contract == '12' && $c->packageR == "10,30,50,100") {
-
- if (strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if ($countD12_1 >= intval($pieces[1])) {
-
- if (strpos($c->comm, 'RM') !== false) {
- $comm12_1 = '+ ' . $c->comm;
- $commV12_1 = '';
- $addRM12_1 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (isset($comms[1])) {
- $comm12_1 = 'RM ' . $comms[1];
- $commV12_1 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm12_1 = $comms[0] . '%';
- $commV12_1 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
-
- if (strpos($c->ranges, '-') !== false) {
-
- $pieces = explode("-", $c->ranges);
-
- if ($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])) {
-
- if (strpos($c->comm, 'RM') !== false) {
- $comm12_1 = '+ ' . $c->comm;
- $commV12_1 = '';
- $addRM12_1 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (isset($comms[1])) {
- $comm12_1 = 'RM ' . $comms[1];
- $commV12_1 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm12_1 = $comms[0] . '%';
- $commV12_1 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
- } else if ($c->contract == '12' && $c->packageR == "300") {
-
- if (strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if ($countD12_2 >= intval($pieces[1])) {
- if (strpos($c->comm, 'RM') !== false) {
- $comm12_2 = '+ ' . $c->comm;
- $commV12_2 = '';
- $addRM12_2 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (isset($comms[1])) {
- $comm12_2 = 'RM ' . $comms[1];
- $commV12_2 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm12_2 = $comms[0] . '%';
- $commV12_2 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
- } else if ($c->contract == '12' && $c->packageR == "500") {
-
- if (strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if ($countD12_3 >= intval($pieces[1])) {
- if (strpos($c->comm, 'RM') !== false) {
- $comm12_3 = '+ ' . $c->comm;
- $commV12_3 = '';
- $addRM12_3 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (isset($comms[1])) {
- $comm12_3 = 'RM ' . $comms[1];
- $commV12_3 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm12_3 = $comms[0] . '%';
- $commV12_3 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
- } else if ($c->contract == '12' && $c->packageR == "1") {
-
- if (strpos($c->ranges, '>') !== false) {
- $pieces = explode(">", $c->ranges);
-
- if ($countD12_4 >= intval($pieces[1])) {
- if (strpos($c->comm, 'RM') !== false) {
- $comm12_4 = '+ ' . $c->comm;
- $commV12_4 = '';
- $addRM12_4 = $c->comm;
- } else {
- $comms = explode("RM", $c->comm);
- if (isset($comms[1])) {
- $comm12_4 = 'RM ' . $comms[1];
- $commV12_4 = floatval($comms[1]);
- } else {
- if ($comms[0] != '') {
- $comm12_4 = $comms[0] . '%';
- $commV12_4 = floatval($comms[0]) / 100;
- }
- }
- }
- }
- }
- }
- }
-
- // Category 10,30,50,100
- foreach ($data12_1 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
-
- $total = '';
- if ($commV12_1 == '') {
- $total = $addRM12_1;
- } else {
- $total = number_format($d['retail_price'] * $commV12_1, 2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm12_1,
- 'incentives2' => $addRM12_1,
- 'total' => 'RM ' . $total,
- 'claim' => $c['claim_dt'],
- );
- }
-
- foreach ($data24_1 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
- $total = '';
- if ($commV24_1 == '') {
- $total = $addRM24_1;
- } else {
- $total = number_format(($d['retail_price'] * $commV24_1) + floatval($addRM24_1), 2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm24_1,
- 'incentives2' => $addRM24_1,
- 'total' => 'RM ' . $total,
- 'claim' => $c['claim_dt'],
- );
- }
-
- // Category 300
- foreach ($data12_2 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
- $total = '';
- if ($commV12_2 == '') {
- $total = $addRM12_2;
- } else {
- $total = number_format($d['retail_price'] * $commV12_2, 2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm12_2,
- 'incentives2' => $addRM12_2,
- 'total' => 'RM ' . $total,
- 'claim' => $c['claim_dt'],
- );
- }
-
- foreach ($data24_2 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
- $total = '';
- if ($commV24_2 == '') {
- $total = $addRM24_2;
- } else {
- $total = number_format($d['retail_price'] * $commV24_2, 2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm24_2,
- 'incentives2' => $addRM24_2,
- 'total' => 'RM ' . $total,
- 'claim' => $c['claim_dt'],
- );
- }
-
- // Category 500
- foreach ($data12_3 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = $customer->name;
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
- $total = '';
- if ($commV12_3 == '') {
- $total = $addRM12_3;
- } else {
- $total = number_format($d['retail_price'] * $commV12_3, 2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm12_3,
- 'incentives2' => $addRM12_3,
- 'total' => 'RM ' . $total,
- 'claim' => $c['claim_dt'],
- );
- }
-
- foreach ($data24_3 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
- $total = '';
- if ($commV24_3 == '') {
- $total = $addRM24_3;
- } else {
- $total = number_format($d['retail_price'] * $commV24_3, 2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm24_3,
- 'incentives2' => $addRM24_3,
- 'total' => 'RM ' . $total,
- 'claim' => $c['claim_dt'],
- );
- }
-
- // Category 1
- foreach ($data12_4 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
- $total = '';
- if ($commV12_4 == '') {
- $total = $addRM12_4;
- } else {
- $total = number_format($d['retail_price'] * $commV12_4, 2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm12_4,
- 'incentives2' => $addRM12_4,
- 'total' => 'RM ' . $total,
- 'claim' => $c['claim_dt'],
- );
- }
-
- foreach ($data24_4 as $key => $d) {
-
- $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
- $total = '';
- if ($commV24_4 == '') {
- $total = $addRM24_4;
- } else {
- $total = number_format($d['retail_price'] * $commV24_4, 2);
- }
-
- $final[] = array(
- 'index' => $d['formT'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $d['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $d['package'],
- 'retail_price' => 'RM ' . $d['retail_price'],
- 'incentives1' => $comm24_4,
- 'incentives2' => $addRM24_4,
- 'total' => 'RM ' . $total,
- 'claim' => $c['claim_dt'],
- );
- }
- } else {
-
- foreach ($dataCB as $c) {
-
- $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
- $address = '';
- $name = '';
- if ($customer->Form->type_application == 'R') {
- if ($customer->street != '') {
- $address = $customer->unit_no . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $customer->unit_no . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->name;
- } else if ($customer->Form->type_application == 'B') {
-
- if ($customer->unit_no != '') {
- $unit = $customer->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($customer->building_name == null) {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- } else {
- $address = $unit . ' , ' . $customer->street . ' , ' . $customer->building_name . ' , ' . $customer->postcode . ' , ' . $customer->city . ' , ' . $customer->state;
- }
- $name = $customer->company_name;
- }
-
- $final[] = array(
- 'index' => $c['formT'],
- 'contract' => $c['contract'],
- 'wo' => $c['wo'],
- 'submission' => $d['submission_dt'],
- 'activation' => $c['activated_dt'],
- 'name' => $name,
- 'address' => $address,
- 'package' => $c['package'],
- 'retail_price' => 'RM ' . $c['retail_price'],
- 'incentives1' => '',
- 'incentives2' => '',
- 'total' => '',
- 'claim' => $c['claim_dt'],
- );
- }
- }
-
- return $final;
- }
-
- /***
- / Return Claim & Combined Business && Resident
- ***/
- public function getClaimRB($company, $year, $month, $app)
- {
-
- $dataR = array();
- $dataB = array();
- $combineData = array();
-
- if ($month == 'null' && $year == 'null' && $app == 'null') {
- return $this->mClaimListAll($company);
- } else if ($year != 'null' && $month != 'null' && $app == 'null') {
-
- $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
- $q->with('Form');
- }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
-
- if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
-
- foreach ($dataClaim as $key => $d) {
- if (
- date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
- date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
- ) {
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- }
- }
- } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
-
- foreach ($dataClaim as $key => $d) {
- if (
- date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
- date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
- ) {
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- }
- }
- }
- } else if ($year == 'null' && $month == 'null' && $app != 'null') {
-
- if ($app == 'Residential') {
- $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
- $q->with('Form');
- }], 'Staff')->where('formT', 'R')->where('dealer', $company)->orderBy('activated_dt', 'DESC')->get();
- } else if ($app == 'Business') {
- $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
- $q->with('Form');
- }], 'Staff')->where('formT', 'B')->where('dealer', $company)->orderBy('activated_dt', 'DESC')->get();
- }
- } else if ($year != 'null' && $month != 'null' && $app != 'null') {
-
- if ($app == 'Residential') {
- $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
- $q->with('Form');
- }], 'Staff')->where('formT', 'R')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
-
- if (($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')) {
-
- foreach ($dataClaim as $key => $d) {
- if (
- date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
- date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'
- ) {
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- }
- }
- } else if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
-
- foreach ($dataClaim as $key => $d) {
- if (
- date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
- date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'
- ) {
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- }
- }
- }
- } else if ($app == 'Business') {
- $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
- $q->with('Form');
- }], 'Staff')->where('formT', 'B')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->orderBy('activated_dt', 'DESC')->get();
- }
- }
-
- $i = 0;
- $nested_data = array();
- if (!empty($dataClaim)) {
- foreach ($dataClaim as $c) {
-
- $address = '';
- $name = '';
- if ($c->Subscriber->Form->type_application == 'R') {
-
- if ($c->Subscriber->street != '') {
- $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- } else {
- $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- }
-
- $name = $c->Subscriber->name;
- } else if ($c->Subscriber->Form->type_application == 'B') {
-
- if ($c->Subscriber->unit_no != '') {
- $unit = $c->Subscriber->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($c->Subscriber->building_name == null) {
- $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- } else {
- $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- }
-
- $name = $c->Subscriber->company_name;
- }
-
- $i++;
- array_push($nested_data, array(
- 'index' => $c->formT,
- 'contract' => $c->contract,
- 'wo' => $c->wo,
- 'activated_dt' => $c->activated_dt,
- 'name' => $name,
- 'address' => $address,
- 'package' => $c->package,
- 'retail_price' => 'RM ' . $c->retail_price,
- 'incentives1' => $c->incentives1,
- 'incentives2' => $c->incentives2,
- 'total' => 'RM ' . $c->total_claim,
- 'claimed' => $c->claim_dt,
- ));
- }
- }
-
- return \DataTables::of($nested_data)->make(true);
- }
-
- public function updateAgent(Request $request)
- {
- $user = Staff::where('_id', $request->agent_id)->first();
- $validate = Staff::where('email', $request->email)->first();
-
- $detail = $user->staffdetail()->first();
- $getpass = $request->get('password');
-
- $pass = $this->encryptPassword('encrypt', $request->get('password'));
-
- if (empty($validate)) {
- $detail->name = $request->get('aname');
- $detail->ic = $request->get('ic');
- $detail->email = $request->get('email');
- $detail->phone = $request->get('phone');
- $detail->company_id = $request->get('vendor');
-
- $user->email = $request->get('email');
- $user->company_id = $request->get('vendor');
-
- if (!empty($getpass)) {
- $validator = Validator::make($request->all(), [
- 'password' => 'min:8|confirmed',
- ]);
-
- if ($validator->fails()) {
- return redirect()->back()->withInput()->withErrors($validator);
- }
-
- $detail->password = $pass;
- $user->password = $pass;
-
- $detail->save();
- $user->save();
- } else {
- $detail->save();
- $user->save();
- }
-
- return redirect()->route('dHome')->with('success_msg', 'message');
- } else {
- if ($user->email == $request->email) {
- echo "" . $request->get('password');
-
- $detail->name = $request->get('aname');
- $detail->ic = $request->get('ic');
- $detail->email = $request->get('email');
- $detail->phone = $request->get('phone');
- $detail->company_id = $request->get('vendor');
-
- $detail->save();
-
- $user->email = $request->get('email');
-
- if (!empty($getpass)) {
- $validator = Validator::make($request->all(), [
- 'password' => 'min:8|confirmed',
- ]);
-
- if ($validator->fails()) {
- return redirect()->back()->withInput()->withErrors($validator);
- }
-
- $detail->password = $pass;
- $user->password = $pass;
-
- $detail->save();
- $user->save();
- } else {
- $detail->save();
- $user->save();
- }
-
- return redirect()->route('dHome')->with('success_msg', 'message');
- } else {
- echo "email is used";
- return redirect()->back()->withInput()->withErrors('Email already exist!');
- }
- }
- }
-
-
-
- /***
- / Application Form
- ***/
- public function showResidentialForm()
- {
-
- $id = Auth::guard('ds')->id();
- $user = Staff::find($id);
- $email = $user->email;
-
- $userDetails = StaffDetail::where('email', $email)->first();
-
- return view('dealer.residential-form', compact('userDetails', 'user'));
- }
-
- public function showBusinessForm()
- {
-
- $id = Auth::guard('ds')->id();
- $user = Staff::find($id);
- $email = $user->email;
-
- $userDetails = StaffDetail::where('email', $email)->first();
-
- return view('dealer.business-form', compact('userDetails', 'user'));
- }
-
-
- public function exportDealerJson(Request $request)
- {
-
- $final = array();
-
- $id = Auth::guard('ds')->id();
- // $user = Staff::with('StaffDetail')->find($id);
- // $com = Company::where('_id',$user->StaffDetail->company_id)->first();
-
- $dataR = array();
- $dataB = array();
- $combineData = array();
- $extra = 0;
-
- $year = $request->year;
- $month = $request->month;
- $app = $request->app;
- $company = $request->company;
-
- if ($year != 'null' && $month != 'null' && $app == 'null') {
-
- $count_cyberjaya = array();
- $count_jasin = array();
- $count_ayerKeroh = array();
- $count_alorGajah = array();
- $count_menglembu = array();
- $count_ipoh = array();
- $extra = 0;
- $basic_total = 0;
- $countAugustR = array();
- $countAugustB = array();
-
- // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
- // $dataDis = $this->returnDataR($company,'2019','12');
- // $dataJan = $this->returnDataR($company,'2020','1');
- if ($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')) {
- $dataApril = $this->returnDataR($company, '2020', '4');
- $dataMay = $this->returnDataR($company, '2020', '5');
- $dataJune = $this->returnDataR($company, '2020', '6');
- $dataJuly = $this->returnDataR($company, '2020', '7');
-
- foreach ($dataApril as $key => $d) {
- // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
- // if (strpos($d['address'], 'Cyberjaya') !== false) {
- // $count_cyberjaya[] = $d;
- // }
-
- // if (strpos($d['address'], 'Jasin') !== false) {
- // $count_jasin[] = $d;
- // }
-
- // }
- // // else
- if (date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020') {
-
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- } else {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- $combineData[] = $d;
- }
- }
- }
-
- foreach ($dataMay as $key => $d) {
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- }
-
- foreach ($dataJune as $key => $d) {
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- }
-
- foreach ($dataJuly as $key => $d) {
- if (strpos($d['address'], 'Cyberjaya') !== false) {
- $count_cyberjaya[] = $d;
- }
-
- if (strpos($d['address'], 'Jasin') !== false) {
- $count_jasin[] = $d;
- }
-
- if (strpos($d['address'], 'Ayer Keroh') !== false) {
- $count_ayerKeroh[] = $d;
- }
-
- if (strpos($d['address'], 'Alor Gajah') !== false) {
- $count_alorGajah[] = $d;
- }
-
- if (strpos($d['address'], 'Menglembu') !== false) {
- $count_menglembu[] = $d;
- }
-
- if (strpos($d['address'], 'Ipoh') !== false) {
- $count_ipoh[] = $d;
- }
- }
-
- // Store to combineData New Incentives Cyberjaya
- foreach ($count_cyberjaya as $key => $d) {
- if (count($count_cyberjaya) > 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
-
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
-
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '230%',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($count_cyberjaya) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- }
- }
- }
-
- // Store to combineData New Incentives Menglembu
- foreach ($count_menglembu as $key => $d) {
- if (count($count_menglembu) > 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
-
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
-
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '230%',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($count_menglembu) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- }
- }
- }
-
- // Store to combineData New Incentives Ipoh
- foreach ($count_ipoh as $key => $d) {
- if (count($count_ipoh) > 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
-
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
-
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '230%',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($count_ipoh) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- // Store to combineData New Incentives Ayer Keroh
- foreach ($count_ayerKeroh as $key => $d) {
- if (count($count_ayerKeroh) > 50) {
-
- if ($d['contract'] == '12') {
-
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
-
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '230%',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($count_ayerKeroh) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- // Store to combineData New Incentives Alor Gajah
- foreach ($count_alorGajah as $key => $d) {
- if (count($count_alorGajah) > 50) {
-
- if ($d['contract'] == '12') {
-
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
-
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '230%',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($count_alorGajah) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- // Store to combineData New Incentives Jasin
- foreach ($count_jasin as $key => $d) {
- if (count($count_jasin) > 20) {
-
- if ($d['contract'] == '12') {
-
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
-
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.3, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '230%',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($count_jasin) < 20) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- } else if ($year == '2020' && ($month == '08' || $month == '09' || $month == '10')) {
- $dataAugustR = $this->returnDataR($company, '2020', '8');
- $dataAugustB = $this->returnDataB($company, '2020', '8');
- $dataSeptemberR = $this->returnDataR($company, '2020', '9');
- $dataSeptemberB = $this->returnDataB($company, '2020', '9');
- $dataOctoberR = $this->returnDataR($company, '2020', '10');
- $dataOctoberB = $this->returnDataB($company, '2020', '10');
-
- foreach ($dataAugustR as $key => $d) {
- if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') {
- if ($d['contract'] == '24') {
- if ($d['package'] == 50) {
- $d['retail_price'] = 69;
- } elseif ($d['package'] == 100) {
- $d['retail_price'] = 89;
- } elseif ($d['package'] == 500) {
- $d['retail_price'] = 129;
- }
- }
-
- if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
- $countAugustR[] = $d;
- }
- } else {
- if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
- $countAugustR[] = $d;
- } else {
- $combineData[] = $d;
- }
- }
- }
- // Store to combineData New Incentive August
- foreach ($countAugustR as $key => $d) {
- if (count($dataAugustR) >= 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250% + RM50',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($dataAugustR) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250%',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- }
-
- foreach ($dataAugustB as $key => $d) {
- if ((date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020') {
- if ($d['contract'] == '24') {
- if ($d['package'] == 50) {
- $d['retail_price'] = 89;
- } elseif ($d['package'] == 100) {
- $d['retail_price'] = 119;
- } elseif ($d['package'] == 300) {
- $d['retail_price'] = 179;
- } elseif ($d['package'] == 500) {
- $d['retail_price'] = 249;
- }
- }
-
- if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
- $countAugustB[] = $d;
- }
- } else {
- if (date('d/m/Y', strtotime($d['activation'])) >= '11/8/2020') {
- $countAugustB[] = $d;
- } else {
- $combineData[] = $d;
- }
- }
- }
- // Store to combineData New Incentive August
- foreach ($countAugustB as $key => $d) {
- if (count($dataAugustB) >= 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- if ($d['package'] == 1) {
- $total = 1500;
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
- }
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250% + RM50',
- 'incentives2' => '',
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($dataAugustB) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- if ($d['package'] == 1) {
- $total = 1500;
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
- }
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250%',
- 'incentives2' => '',
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- }
-
- foreach ($dataSeptemberR as $key => $d) {
- if (((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month . '/' . $year)) {
- if ($d['contract'] == '24') {
- if ($d['package'] == 50) {
- $d['retail_price'] = 69;
- } elseif ($d['package'] == 100) {
- $d['retail_price'] = 89;
- } elseif ($d['package'] == 500) {
- $d['retail_price'] = 129;
- }
- }
- }
-
- if (count($dataSeptemberR) >= 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250% + RM50',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($dataSeptemberR) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250%',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- }
-
- foreach ($dataSeptemberB as $key => $d) {
- if (((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month . '/' . $year)) {
- if ($d['contract'] == '24') {
- if ($d['package'] == 50) {
- $d['retail_price'] = 89;
- } elseif ($d['package'] == 100) {
- $d['retail_price'] = 119;
- } elseif ($d['package'] == 300) {
- $d['retail_price'] = 179;
- } elseif ($d['package'] == 500) {
- $d['retail_price'] = 249;
- }
- }
- }
-
- if (count($dataSeptemberB) >= 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- if ($d['package'] == 1) {
- $total = 1500;
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
- }
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250% + RM50',
- 'incentives2' => '',
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($dataSeptemberB) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- if ($d['package'] == 1) {
- $total = 1500;
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
- }
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250%',
- 'incentives2' => '',
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- }
-
- foreach ($dataOctoberR as $key => $d) {
- if (((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) || (date('m/Y', strtotime($d['submission'])) == '09/2020')) {
- if ($d['contract'] == '24') {
- if ($d['package'] == 50) {
- $d['retail_price'] = 69;
- } elseif ($d['package'] == 100) {
- $d['retail_price'] = 89;
- } elseif ($d['package'] == 500) {
- $d['retail_price'] = 129;
- }
- }
- }
-
- if (count($dataOctoberR) >= 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250% + RM50',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($dataOctoberR) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250%',
- 'incentives2' => $d['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- }
-
- foreach ($dataOctoberB as $key => $d) {
- if (((date('m/Y', strtotime($d['submission'])) == '08/2020') && (date('d/m/Y', strtotime($d['submission'])) >= '11/8/2020')) || (date('m/Y', strtotime($d['submission'])) == $month . '/' . $year) || (date('m/Y', strtotime($d['submission'])) == '09/2020')) {
- if ($d['contract'] == '24') {
- if ($d['package'] == 50) {
- $d['retail_price'] = 89;
- } elseif ($d['package'] == 100) {
- $d['retail_price'] = 119;
- } elseif ($d['package'] == 300) {
- $d['retail_price'] = 179;
- } elseif ($d['package'] == 500) {
- $d['retail_price'] = 249;
- }
- }
- }
-
- if (count($dataOctoberB) >= 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- if ($d['package'] == 1) {
- $total = 1500;
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5 + 50, 2);
- }
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250% + RM50',
- 'incentives2' => '',
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- } else if (count($dataOctoberB) < 50) {
- if (date('m/Y', strtotime($d['activation'])) == $month . '/' . $year) {
- if ($d['contract'] == '12') {
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => $d['incentives1'],
- 'incentives2' => $d['incentives2'],
- 'total' => $d['total'],
- 'claim' => $d['claim'],
- ));
- } else {
- if ($d['package'] == 1) {
- $total = 1500;
- } else {
- $total = number_format(floatval(str_replace("RM ", "", $d['retail_price'])) * 2.5, 2);
- }
- array_push($combineData, array(
- 'index' => $d['index'],
- 'contract' => $d['contract'],
- 'wo' => $d['wo'],
- 'activation' => $d['activation'],
- 'name' => $d['name'],
- 'address' => $d['address'],
- 'package' => $d['package'],
- 'retail_price' => $d['retail_price'],
- 'incentives1' => '250%',
- 'incentives2' => '',
- 'total' => 'RM ' . $total,
- 'claim' => $d['claim'],
- ));
- }
- }
- }
- }
- } else if ($year == '2020' && ($month == '12')) {
- $dataDecemberR = $this->returnDataR($company, '2020', '12');
- foreach ($dataDecemberR as $r) {
- $combineData[] = $r;
- }
-
- $dataDecemberB = $this->returnDataB($company, '2020', '12');
- foreach ($dataDecemberB as $b) {
- if ((date('m/Y', strtotime($b['submission'])) == $month . '/' . $year) && date('d/m/Y', strtotime($b['submission'])) >= '21/12/2020') {
- if (strpos($b['address'], 'CYBERJAYA') !== false && $b['contract'] == '24' && $b['package'] == 1) {
- $b['retail_price'] = 999;
- }
- $count_businessCyber[] = $b;
- } else {
- $combineData[] = $b;
- }
- }
-
- for ($i=0;$i<count($count_businessCyber);$i++){
- for($j=0;$j<51;$j++){
- $total = number_format(floatval(str_replace("RM ", "", $count_businessCyber[$j]['retail_price'])) * 2.0, 2);
- array_push($combineData, array(
- 'index' => $count_businessCyber[$j]['index'],
- 'contract' => $count_businessCyber[$j]['contract'],
- 'wo' => $count_businessCyber[$j]['wo'],
- 'activation' => $count_businessCyber[$j]['activation'],
- 'name' => $count_businessCyber[$j]['name'],
- 'address' => $count_businessCyber[$j]['address'],
- 'package' => $count_businessCyber[$j]['package'],
- 'retail_price' => $count_businessCyber[$j]['retail_price'],
- 'incentives1' => '200%',
- 'incentives2' => $count_businessCyber[$j]['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $count_businessCyber[$j]['claim'],
- ));
- }
- for($j=51;$j>=51;$j++){
- $total = number_format(floatval(str_replace("RM ", "", $count_businessCyber[$j]['retail_price'])) * 2.5, 2);
- array_push($combineData, array(
- 'index' => $count_businessCyber[$j]['index'],
- 'contract' => $count_businessCyber[$j]['contract'],
- 'wo' => $count_businessCyber[$j]['wo'],
- 'activation' => $count_businessCyber[$j]['activation'],
- 'name' => $count_businessCyber[$j]['name'],
- 'address' => $count_businessCyber[$j]['address'],
- 'package' => $count_businessCyber[$j]['package'],
- 'retail_price' => $count_businessCyber[$j]['retail_price'],
- 'incentives1' => '250%',
- 'incentives2' => $count_businessCyber[$j]['incentives2'],
- 'total' => 'RM ' . $total,
- 'claim' => $count_businessCyber[$j]['claim'],
- ));
- }
- }
-
- } else {
- $dataR = $this->returnDataR($company, $year, $month);
- foreach ($dataR as $r) {
- $combineData[] = $r;
- }
-
- $dataB = $this->returnDataB($company, $year, $month);
-
- foreach ($dataB as $b) {
- $combineData[] = $b;
- }
- }
-
- $i = 0;
- $nested_data = array();
- if (!empty($combineData)) {
- foreach ($combineData as $c) {
- $update_dealer = DealerClaim::where('wo', $c['wo'])->first();
- if (!empty($update_dealer)) {
- $update_dealer->incentives1 = $c['incentives1'];
- $update_dealer->incentives2 = $c['incentives2'];
- $update_dealer->retail_price = $c['retail_price'];
- $update_dealer->total_claim = $c['total'];
- $update_dealer->save();
- }
- }
- }
-
- $dataClaim = DealerClaim::with(['Subscriber' => function ($q) {
- $q->with('Form');
- }], 'Staff')->where('dealer', $company)->where('activated_my', $month . '/' . $year)->get();
-
- if (!empty($dataClaim)) {
- foreach ($dataClaim as $c) {
-
- $address = '';
- $name = '';
- if ($c->Subscriber->Form->type_application == 'R') {
-
- if ($c->Subscriber->street != '') {
- $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- } else {
- $address = $c->Subscriber->unit_no . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- }
-
- $name = $c->Subscriber->name;
- } else if ($c->Subscriber->Form->type_application == 'B') {
-
- if ($c->Subscriber->unit_no != '') {
- $unit = $c->Subscriber->unit_no;
- } else {
- $unit = ' ';
- }
-
- if ($c->Subscriber->building_name == null) {
- $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- } else {
- $address = $unit . ' , ' . $c->Subscriber->street . ' , ' . $c->Subscriber->building_name . ' , ' . $c->Subscriber->postcode . ' , ' . $c->Subscriber->city . ' , ' . $c->Subscriber->state;
- }
-
- $name = $c->Subscriber->company_name;
- }
-
- $i++;
- array_push($final, array(
- 'index' => $c->formT,
- 'contract' => $c->contract,
- 'wo' => $c->wo,
- 'activated_dt' => $c->activated_dt,
- 'name' => $name,
- 'address' => $address,
- 'package' => $c->package,
- 'retail_price' => $c->retail_price,
- 'incentives1' => $c->incentives1,
- 'incentives2' => $c->incentives2,
- 'total' => $c->total_claim,
- 'claimed' => $c->claim_dt,
- ));
- }
- }
-
- foreach ($final as $f) {
- $basic_total += floatval(str_replace('RM ', '', $f['total']));
- }
-
- // Calculate extra incentves
- // if($month == '1' && $year == '2020'){
- // if(count($count_cyberjaya) > 50){
- // $balance = count($count_cyberjaya) - 50;
- // $extra += $balance * 50;
- // }
-
- // if(count($count_jasin) > 10){
- // $balance = count($count_jasin) - 10;
- // $extra += $balance * 50;
- // }
- // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
- // if(count($count_cyberjaya) > 50){
- // $balance = count($count_cyberjaya) - 50;
- // $extra += $balance * 50;
- // }
-
- // if(count($count_jasin) > 20){
- // $balance = count($count_jasin) - 10;
- // $extra += $balance * 50;
- // }
- // }else {
- // $extra = 0;
- // }
-
- $extra = 0;
- $totals = $basic_total + $extra;
-
- // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
- // $pdf->setPaper('A4', 'landscape');
- // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
-
- // return $pdf->download( $pdfName );
-
- return $final;
- }
- // else if($year!='null' && $month!='null' && $app!='null'){
-
- // $count_cyberjaya = array(); $count_jasin = array();
- // $extra = 0; $basic_total = 0; $totals = 0;
-
- // if($app == 'Residential'){
-
- // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
- // $dataDis = $this->returnDataR($company,'2019','12');
- // $dataJan = $this->returnDataR($company,'2020','1');
-
- // foreach ($dataDis as $key => $d) {
- // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
- // if (strpos($d['address'], 'Cyberjaya') !== false) {
- // $count_cyberjaya[] = $d;
- // }
-
- // if (strpos($d['address'], 'Jasin') !== false) {
- // $count_jasin[] = $d;
- // }
-
- // }else if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020' && date('d/m/Y', strtotime($d['activation'])) <= '31/7/2020'){
-
- // if (strpos($d['address'], 'Cyberjaya') !== false) {
- // $count_cyberjaya[] = $d;
- // }
-
- // if (strpos($d['address'], 'Jasin') !== false) {
- // $count_jasin[] = $d;
- // }
-
- // }else {
- // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
- // $combineData[] = $d;
- // }
- // }
- // }
-
- // foreach ($dataJan as $key => $d) {
- // if (strpos($d['address'], 'Cyberjaya') !== false) {
- // $count_cyberjaya[] = $d;
- // }
-
- // if (strpos($d['address'], 'Jasin') !== false) {
- // $count_jasin[] = $d;
- // }
- // }
-
- // // Store to combineData New Incentives Cyberjaya
- // foreach ($count_cyberjaya as $key => $d) {
- // if(count($count_cyberjaya) > 50){
- // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
- // if($d['contract'] == '12'){
- // array_push($combineData, array(
- // 'index' => $d['index'],
- // 'contract' => $d['contract'],
- // 'wo' => $d['wo'],
- // 'activation' => $d['activation'],
- // 'name' => $d['name'],
- // 'address' => $d['address'],
- // 'package' => $d['package'],
- // 'retail_price' => $d['retail_price'],
- // 'incentives1' => $d['incentives1'],
- // 'incentives2' => $d['incentives2'],
- // 'total' => $d['total'],
- // 'claim' => $d['claim'],
- // ));
- // }else {
- // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
- // array_push($combineData, array(
- // 'index' => $d['index'],
- // 'contract' => $d['contract'],
- // 'wo' => $d['wo'],
- // 'activation' => $d['activation'],
- // 'name' => $d['name'],
- // 'address' => $d['address'],
- // 'package' => $d['package'],
- // 'retail_price' => $d['retail_price'],
- // 'incentives1' => '230%',
- // 'incentives2' => $d['incentives2'],
- // 'total' => 'RM '.$total,
- // 'claim' => $d['claim'],
- // ));
- // }
- // }
-
- // }else if(count($count_cyberjaya) < 50){
- // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
- // array_push($combineData, array(
- // 'index' => $d['index'],
- // 'contract' => $d['contract'],
- // 'wo' => $d['wo'],
- // 'activation' => $d['activation'],
- // 'name' => $d['name'],
- // 'address' => $d['address'],
- // 'package' => $d['package'],
- // 'retail_price' => $d['retail_price'],
- // 'incentives1' => $d['incentives1'],
- // 'incentives2' => $d['incentives2'],
- // 'total' => $d['total'],
- // 'claim' => $d['claim'],
- // ));
- // }
- // }
- // }
-
- // // Store to combineData New Incentives Jasin
- // foreach ($count_jasin as $key => $d) {
- // if(count($count_jasin) > 10){
- // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
- // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
- // array_push($combineData, array(
- // 'index' => $d['index'],
- // 'contract' => $d['contract'],
- // 'wo' => $d['wo'],
- // 'activation' => $d['activation'],
- // 'name' => $d['name'],
- // 'address' => $d['address'],
- // 'package' => $d['package'],
- // 'retail_price' => $d['retail_price'],
- // 'incentives1' => '230%',
- // 'incentives2' => $d['incentives2'],
- // 'total' => 'RM '.$total,
- // 'claim' => $d['claim'],
- // ));
- // }
-
- // }else if(count($count_jasin) < 10){
- // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
- // array_push($combineData, array(
- // 'index' => $d['index'],
- // 'contract' => $d['contract'],
- // 'wo' => $d['wo'],
- // 'activation' => $d['activation'],
- // 'name' => $d['name'],
- // 'address' => $d['address'],
- // 'package' => $d['package'],
- // 'retail_price' => $d['retail_price'],
- // 'incentives1' => $d['incentives1'],
- // 'incentives2' => $d['incentives2'],
- // 'total' => $d['total'],
- // 'claim' => $d['claim'],
- // ));
- // }
- // }
- // }
-
- // }else {
- // $dataR = $this->returnDataR($company,$year,$month);
- // foreach($dataR as $r){
- // $combineData[] = $r;
- // }
- // }
-
- // }else if($app == 'Business'){
- // $dataB = $this->returnDataB($company,$year,$month);
- // }
-
- // foreach($dataB as $b){
- // $combineData[] = $b;
- // }
-
- // $i = 0;
- // $nested_data = array();
- // if(!empty($combineData)){
- // foreach ($combineData as $c){
- // $i++;
- // array_push($final, array(
- // 'index' => $c['index'],
- // 'contract' => $c['contract'],
- // 'wo' => $c['wo'],
- // 'activated_dt' => $c['activation'],
- // 'name' => $c['name'],
- // 'address' => $c['address'],
- // 'package' => $c['package'],
- // 'retail_price' => $c['retail_price'],
- // 'incentives1' => $c['incentives1'],
- // 'incentives2' => $c['incentives2'],
- // 'total' => $c['total'],
- // 'claimed' => $c['claim'],
- // ));
- // }
- // }
-
- // foreach($final as $f){
- // $basic_total += floatval(str_replace('RM ', '', $f['total']));
- // }
-
- // //Calculate extra incentves
- // if($month == '1' && $year == '2020'){
- // if(count($count_cyberjaya) > 50){
- // $balance = count($count_cyberjaya) - 50;
- // $extra += $balance * 50;
- // }
-
- // if(count($count_jasin) > 10){
- // $balance = count($count_jasin) - 10;
- // $extra += $balance * 50;
- // }
- // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
- // if(count($count_cyberjaya) > 50){
- // $balance = count($count_cyberjaya) - 50;
- // $extra += $balance * 50;
- // }
-
- // if(count($count_jasin) > 20){
- // $balance = count($count_jasin) - 10;
- // $extra += $balance * 50;
- // }
- // }else {
- // $extra = 0;
- // }
-
- // $totals = $basic_total + $extra;
-
- // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
- // $pdf->setPaper('A4', 'landscape');
- // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
-
- // return $pdf->download( $pdfName );
- // }
- }
-
- public function update_total_claim()
- {
- $dealer = DealerClaim::all();
-
- foreach ($dealer as $key => $d) {
- $claim = str_replace("RM ", "", $d->total_claim);
- $price = str_replace("RM ", "", $d->retail_price);
- $d->total_claim = floatval($claim);
- $d->retail_price = floatval($price);
- $d->save();
- }
- }
- }
|