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

DealerController.php 91KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126
  1. <?php
  2. namespace App\Http\Controllers\DS;
  3. use Illuminate\Http\Request;
  4. use App\Http\Controllers\Controller;
  5. use Illuminate\Support\Facades\Auth;
  6. use Carbon\Carbon;
  7. use Validator;
  8. use PDF;
  9. use App\Staff;
  10. use App\Model\StaffDetail;
  11. use App\Model\Coverage;
  12. use App\Model\DealerClaim;
  13. use App\Model\DealerClaim2;
  14. use App\Model\Commission;
  15. use App\Model\Company;
  16. use App\Model\Form;
  17. use App\Model\FormStatus;
  18. use App\Model\Subscriber;
  19. use App\Model\PackageDetail;
  20. use App\Model\WorkOrder;
  21. use App\Model\Docket;
  22. class DealerController extends Controller
  23. {
  24. public function viewList(){
  25. $id = Auth::guard('ds')->id();
  26. $user = Staff::with('StaffDetail')->find($id);
  27. return view('dealer.index',compact('user'));
  28. }
  29. /***
  30. / Agent list
  31. ***/
  32. public function gAgentList(){
  33. $id = Auth::guard('ds')->id();
  34. $user = Staff::find($id);
  35. $email = $user->email;
  36. $userDetails = StaffDetail::where('email',$email)->first();
  37. $all = StaffDetail::where('company_id',$userDetails->company_id)->orderBy('created_at','desc')->get();
  38. $curr = Carbon::now()->getTimestamp();
  39. $i = 0;
  40. $nested_data = array();
  41. if(!empty($all)){
  42. foreach ($all as $a){
  43. $i++; $y = ''; $n1 = '';
  44. if($userDetails->_id == $a->_id){
  45. $y = $a->name."-You";
  46. }else {
  47. $y = $a->name;
  48. }
  49. $reg_time = $a->created_at;
  50. $expiry_date = $reg_time->addDays(3);
  51. $expiry_date = $expiry_date->getTimestamp();
  52. if($curr < $expiry_date) {
  53. $n1 = "New/";
  54. }
  55. array_push($nested_data, array(
  56. 'index' => $i,
  57. 'image' => $a->user_pic,
  58. 'name' => $n1.$y,
  59. 'ic' => $a->ic,
  60. 'phone' => $a->phone,
  61. 'email' => $a->email,
  62. 'action' => $a->_id
  63. ));
  64. }
  65. }
  66. return \DataTables::of($nested_data)->make(true);
  67. }
  68. /***
  69. / Application Form List
  70. ***/
  71. public function viewAppList(){
  72. $id = Auth::guard('ds')->id();
  73. $user = Staff::with('StaffDetail')->find($id);
  74. return view('dealer.application-form-list',compact('user'));
  75. }
  76. /***
  77. / Get Application Form List
  78. ***/
  79. public function getSubscribers($dealerCompany)
  80. {
  81. $data = array();
  82. $curr = Carbon::now()->getTimestamp();
  83. $subscriber = Subscriber::where('dealer_company', $dealerCompany)->get();
  84. foreach ($subscriber as $key => $s) {
  85. $n1 = '';
  86. $reg_time = Carbon::createFromTimestamp($s->reg_time);
  87. $expiry_date = $reg_time->addDays(3);
  88. $expiry_date = $expiry_date->getTimestamp();
  89. $agentName = StaffDetail::where('_id',$s->dealer)->first();
  90. $build = Coverage::where('address',$s->building)->first();
  91. if($s->street == ''){
  92. $street = $build->street;
  93. }else {
  94. $street = $s->street;
  95. }
  96. if($curr < $expiry_date) {
  97. $n1 = "New/";
  98. }
  99. $data[] = array(
  100. 'formT' => 'R',
  101. 'wo' => $s->wo,
  102. 'name' => $n1.$s->name,
  103. 'no' => $s->phone1,
  104. 'unit' => $s->unit_no,
  105. 'building' => $s->building,
  106. 'street' => $street,
  107. 'postcode' => $s->postcode,
  108. 'city' => $s->city,
  109. 'sales' => $agentName->name,
  110. 'created_at' => $s->reg_time,
  111. 'action' => $s->_id,
  112. );
  113. }
  114. return $data;
  115. }
  116. public function getBusiness($dealerCompany){
  117. $data = array();
  118. $curr = Carbon::now()->getTimestamp();
  119. $business = Subscriber::where('dealer_company', $dealerCompany)->get();
  120. foreach ($business as $key => $s) {
  121. $n1 = '';
  122. $reg_time = Carbon::createFromTimestamp($s->reg_time);
  123. $expiry_date = $reg_time->addDays(3);
  124. $expiry_date = $expiry_date->getTimestamp();
  125. if($curr < $expiry_date) {
  126. $n1 = "New/";
  127. }
  128. $agentName = StaffDetail::where('_id',$s->dealer)->first();
  129. $data[] = array(
  130. 'formT' => 'B',
  131. 'wo' => $s->wo,
  132. 'name' => $n1.$s->name,
  133. 'no' => $s->phone1,
  134. 'unit' => '-',
  135. 'building' => '-',
  136. 'street' => $s->address,
  137. 'postcode' => $s->postcode,
  138. 'city' => $s->city,
  139. 'sales' => $agentName->name,
  140. 'created_at' => $s->reg_time,
  141. 'action' => $s->_id,
  142. );
  143. }
  144. return $data;
  145. }
  146. public function getOrderHistory($id){
  147. $data = array();
  148. $order_history = FormStatus::where('form_id', $id)->get();
  149. foreach($order_history as $oh){
  150. $utcdatetime = new \MongoDB\BSON\UTCDateTime((string) $oh->date);
  151. $datetime = $utcdatetime->toDateTime();
  152. $time = $datetime->format(DATE_RSS);
  153. $time = strtotime($time.' UTC');
  154. $dateInLocal = date("d/m/Y h:i a", $time);
  155. $data[] = array(
  156. 'date' => $dateInLocal,
  157. 'status' => $oh->status,
  158. 'desc' => $oh->desc
  159. );
  160. }
  161. $json = json_encode($data);
  162. return $json;
  163. }
  164. public function gApplicationList1()
  165. {
  166. $id = Auth::guard('ds')->id();
  167. $user = Staff::with('StaffDetail')->find($id);
  168. $fm = Form::with('Subscriber')->where('company_id',$user->StaffDetail->company_id)->orderBy('created_at','desc')->get();
  169. $nested_data = array();
  170. $i=0;
  171. foreach($fm as $f)
  172. {
  173. $dname="";
  174. $wo = WorkOrder::where('_id', $f->_id)->first();
  175. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  176. if(!empty($dealer)){
  177. $dname=$dealer->name;
  178. }
  179. $address = ''; $name = '';
  180. if($f->type_application == 'R'){
  181. if (!empty($f->Subscriber->building_name)){
  182. $address = $f->Subscriber->building_name;
  183. $name = $f->Subscriber->name;
  184. }
  185. }else if($f->type_application == 'B'){
  186. $address = '-';
  187. $name = $f->Subscriber->company_name;
  188. }
  189. if(empty($wo) && !empty($f->Subscriber))
  190. {
  191. $i++;
  192. array_push($nested_data, array(
  193. 'index' => $i.$f->type_application,
  194. 'name' => $name,
  195. 'phone' => $f->Subscriber->phone1,
  196. 'unit' => $f->Subscriber->unit_no,
  197. 'building' => $address,
  198. 'street' => $f->Subscriber->street,
  199. 'postcode' => $f->Subscriber->postcode,
  200. 'city' => $f->Subscriber->city,
  201. 'sales' => $dname,
  202. 'action' => $f->_id
  203. ));
  204. }
  205. }
  206. return \DataTables::of($nested_data)->make(true);
  207. }
  208. public function gApplicationList2()
  209. {
  210. $id = Auth::guard('ds')->id();
  211. $user = Staff::with('StaffDetail')->find($id);
  212. $fm = Form::with('Subscriber')->where('company_id',$user->StaffDetail->company_id)->orderBy('created_at','desc')->get();
  213. $nested_data = array();
  214. $i=0;
  215. foreach($fm as $f)
  216. {
  217. $dname="";
  218. $wo = WorkOrder::where('_id', $f->_id)->first();
  219. $dealer = StaffDetail::where('_id', $f->dealer_id)->first();
  220. if(!empty($dealer)){
  221. $dname=$dealer->name;
  222. }
  223. $address = ''; $name = '';
  224. if($f->type_application == 'R'){
  225. $address = $f->Subscriber->building_name;
  226. $name = $f->Subscriber->name;
  227. }else if($f->type_application == 'B'){
  228. $address = '-';
  229. $name = $f->Subscriber->company_name;
  230. }
  231. if(!empty($wo) && $wo->status!='Completed')
  232. {
  233. $i++;
  234. array_push($nested_data, array(
  235. 'index' => $i.$f->type_application,
  236. 'name' => $name,
  237. 'phone' => $f->Subscriber->phone1,
  238. 'unit' => $f->Subscriber->unit_no,
  239. 'building' => $address,
  240. 'street' => $f->Subscriber->street,
  241. 'postcode' => $f->Subscriber->postcode,
  242. 'city' => $f->Subscriber->city,
  243. 'sales' => $dname,
  244. 'action' => $f->_id
  245. ));
  246. }
  247. }
  248. return \DataTables::of($nested_data)->make(true);
  249. }
  250. public function getCompletedList($year, $month)
  251. {
  252. $id = Auth::guard('ds')->id();
  253. $user = Staff::find($id);
  254. $email = $user->email;
  255. $userDetails = StaffDetail::where('email',$email)->first();
  256. $subs = $this->getSubscribers($userDetails->company_id);
  257. $buss = $this->getBusiness($userDetails->company_id);
  258. // Combine
  259. $cdata = array();
  260. foreach ($subs as $key => $s) {
  261. $cdata[] = $s;
  262. }
  263. foreach ($buss as $key => $b) {
  264. $cdata[] = $b;
  265. }
  266. // Sort based on TimeStamp
  267. $sort = array();
  268. foreach ($cdata as $key => $r) {
  269. $sort[$key] = $r['created_at'];
  270. }
  271. array_multisort($sort, SORT_DESC, $cdata);
  272. $wK = WorkDetail::get();
  273. $curr = Carbon::now()->getTimestamp();
  274. $mY = '';
  275. if($year != 'null' && $month != 'null'){
  276. $mY = $year.'/'.$month;
  277. }
  278. $final = array(); $filter = array();
  279. $dW = array();
  280. foreach ($cdata as $c){
  281. if($c['wo'] != ''){
  282. foreach ($wK as $key => $w) {
  283. if($c['wo'] == $w->wo && $w->status == 'Completed'){
  284. $dW[] = $c;
  285. }
  286. }
  287. }
  288. }
  289. foreach($dW as $d){
  290. if($mY != ''){
  291. $docket = Docket::where('work_order_id', $d['wo'])->first();
  292. $cDate = date('Y/m', strtotime($docket->end_job));;
  293. if($mY == $cDate){
  294. $filter[] = $d;
  295. }
  296. }else {
  297. $filter[] = $d;
  298. }
  299. }
  300. foreach ($filter as $c){
  301. $do = Docket::where('work_order_id', $c['wo'])->first();
  302. $n1 = '';
  303. $reg_time = Carbon::createFromTimestamp(strtotime($do->end_job));
  304. $expiry_date = $reg_time->addDays(3);
  305. $expiry_date = $expiry_date->getTimestamp();
  306. if($curr < $expiry_date) {
  307. $n1 = "New/";
  308. }
  309. $final[] = array(
  310. 'formT' => $c['formT'],
  311. 'wo' => $c['wo'],
  312. 'do' => $do->docket_id,
  313. 'activated' => $do->end_job,
  314. 'name' => $n1.str_replace("New/","",$c['name']),
  315. 'no' => $c['no'],
  316. 'unit' => $c['unit'],
  317. 'building' => $c['building'],
  318. 'street' => $c['street'],
  319. 'postcode' => $c['postcode'],
  320. 'city' => $c['city'],
  321. 'sales' => $c['sales'],
  322. 'created_at' => $c['created_at'],
  323. 'action' => $c['action'],
  324. );
  325. }
  326. return $final;
  327. }
  328. public function gApplicationList3($year,$month)
  329. {
  330. $id = Auth::guard('ds')->id();
  331. $user = Staff::with('StaffDetail')->find($id);
  332. $mY = '';
  333. if($year!='null' && $month!='null'){
  334. $mY = $month.'/'.$year;
  335. }
  336. $fm = Form::with('Subscriber','WorkOrder')->where('company_id',$user->StaffDetail->company_id)->orderBy('created_at','desc')->get();
  337. $nested_data = array();
  338. $i=0;
  339. foreach($fm as $f)
  340. {
  341. if(!empty($f->WorkOrder)){
  342. if($f->WorkOrder->status == 'Completed'){
  343. $wo = WorkOrder::with('Docket')->where('wo', $f->WorkOrder->wo)->first();
  344. $dealer = StaffDetail::where('_id', $f->dealer_id)->withTrashed()->first();
  345. $i++;
  346. $address = ''; $name = '';
  347. if($f->type_application == 'R'){
  348. $address = $f->Subscriber->building_name;
  349. $name = $f->Subscriber->name;
  350. }else if($f->type_application == 'B'){
  351. $address = '-';
  352. $name = $f->Subscriber->company_name;
  353. }
  354. if(!empty($wo->Docket)){
  355. $end = date('m/Y',strtotime($wo->Docket->end_job));
  356. if($mY == ''){
  357. array_push($nested_data, array(
  358. 'index' => $i.$f->type_application,
  359. 'wo' => $wo->wo,
  360. 'do' => $f->WorkOrder->docket_id,
  361. 'name' => $name,
  362. 'phone' => $f->Subscriber->phone1,
  363. 'unit' => $f->Subscriber->unit_no,
  364. 'building' => $address,
  365. 'street' => $f->Subscriber->street,
  366. 'postcode' => $f->Subscriber->postcode,
  367. 'city' => $f->Subscriber->city,
  368. 'sales' => $dealer->name,
  369. 'action' => $f->_id
  370. ));
  371. }else if($mY == $end){
  372. array_push($nested_data, array(
  373. 'index' => $i.$f->type_application,
  374. 'wo' => $wo->wo,
  375. 'do' => $f->WorkOrder->docket_id,
  376. 'name' => $name,
  377. 'phone' => $f->Subscriber->phone1,
  378. 'unit' => $f->Subscriber->unit_no,
  379. 'building' => $address,
  380. 'street' => $f->Subscriber->street,
  381. 'postcode' => $f->Subscriber->postcode,
  382. 'city' => $f->Subscriber->city,
  383. 'sales' => $dealer->name,
  384. 'action' => $f->_id
  385. ));
  386. }
  387. }
  388. }
  389. }
  390. }
  391. return \DataTables::of($nested_data)->make(true);
  392. }
  393. /***
  394. / Claim All
  395. ***/
  396. public function claimAll() {
  397. $id = Auth::guard('ds')->id();
  398. $user = Staff::with('StaffDetail')->find($id);
  399. return view('dealer.claim-all',compact('user'));
  400. }
  401. /***
  402. / Convert To PDF
  403. ***/
  404. public function exportPDF1() {
  405. return view('pdf.agent-claim');
  406. }
  407. public function exportPDF($company,$year,$month,$app) {
  408. $final = array();
  409. $id = Auth::guard('ds')->id();
  410. $user = Staff::with('StaffDetail')->find($id);
  411. $com = Company::where('_id',$user->StaffDetail->company_id)->first();
  412. $i = 0;
  413. $dataR = array(); $dataB = array(); $combineData = array();
  414. $count_cyberjaya = array(); $count_jasin = array(); $count_ayerKeroh = array(); $count_alorGajah = array(); $count_menglembu = array(); $count_ipoh = array();
  415. $extra = 0; $basic_total = 0; $totals = 0;
  416. if($year!='null' && $month!='null' && $app=='null'){
  417. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  418. $q->with('Form');
  419. }],'Staff')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  420. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  421. foreach ($dataClaim as $key => $d) {
  422. if(date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  423. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'){
  424. if (strpos($d['address'], 'Cyberjaya') !== false) {
  425. $count_cyberjaya[] = $d;
  426. }
  427. if (strpos($d['address'], 'Jasin') !== false) {
  428. $count_jasin[] = $d;
  429. }
  430. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  431. $count_ayerKeroh[] = $d;
  432. }
  433. if (strpos($d['address'], 'Alor Gajah') !== false) {
  434. $count_alorGajah[] = $d;
  435. }
  436. if (strpos($d['address'], 'Menglembu') !== false) {
  437. $count_menglembu[] = $d;
  438. }
  439. if (strpos($d['address'], 'Ipoh') !== false) {
  440. $count_ipoh[] = $d;
  441. }
  442. }
  443. }
  444. }else if($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')){
  445. foreach ($dataClaim as $key => $d) {
  446. if(date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  447. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'){
  448. if (strpos($d['address'], 'Cyberjaya') !== false) {
  449. $count_cyberjaya[] = $d;
  450. }
  451. if (strpos($d['address'], 'Jasin') !== false) {
  452. $count_jasin[] = $d;
  453. }
  454. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  455. $count_ayerKeroh[] = $d;
  456. }
  457. if (strpos($d['address'], 'Alor Gajah') !== false) {
  458. $count_alorGajah[] = $d;
  459. }
  460. if (strpos($d['address'], 'Menglembu') !== false) {
  461. $count_menglembu[] = $d;
  462. }
  463. if (strpos($d['address'], 'Ipoh') !== false) {
  464. $count_ipoh[] = $d;
  465. }
  466. }
  467. }
  468. }
  469. }else if($year!='null' && $month!='null' && $app!='null'){
  470. if($app == 'Residential'){
  471. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  472. $q->with('Form');
  473. }],'Staff')->where('formT', 'R')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  474. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  475. foreach ($dataClaim as $key => $d) {
  476. if(date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  477. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'){
  478. if (strpos($d['address'], 'Cyberjaya') !== false) {
  479. $count_cyberjaya[] = $d;
  480. }
  481. if (strpos($d['address'], 'Jasin') !== false) {
  482. $count_jasin[] = $d;
  483. }
  484. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  485. $count_ayerKeroh[] = $d;
  486. }
  487. if (strpos($d['address'], 'Alor Gajah') !== false) {
  488. $count_alorGajah[] = $d;
  489. }
  490. if (strpos($d['address'], 'Menglembu') !== false) {
  491. $count_menglembu[] = $d;
  492. }
  493. if (strpos($d['address'], 'Ipoh') !== false) {
  494. $count_ipoh[] = $d;
  495. }
  496. }
  497. }
  498. }else if($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')){
  499. foreach ($dataClaim as $key => $d) {
  500. if(date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  501. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'){
  502. if (strpos($d['address'], 'Cyberjaya') !== false) {
  503. $count_cyberjaya[] = $d;
  504. }
  505. if (strpos($d['address'], 'Jasin') !== false) {
  506. $count_jasin[] = $d;
  507. }
  508. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  509. $count_ayerKeroh[] = $d;
  510. }
  511. if (strpos($d['address'], 'Alor Gajah') !== false) {
  512. $count_alorGajah[] = $d;
  513. }
  514. if (strpos($d['address'], 'Menglembu') !== false) {
  515. $count_menglembu[] = $d;
  516. }
  517. if (strpos($d['address'], 'Ipoh') !== false) {
  518. $count_ipoh[] = $d;
  519. }
  520. }
  521. }
  522. }
  523. }else if($app == 'Business'){
  524. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  525. $q->with('Form');
  526. }],'Staff')->where('formT', 'B')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  527. }
  528. }
  529. if(!empty($dataClaim)){
  530. foreach ($dataClaim as $c){
  531. $address = ''; $name = '';
  532. if($c->Subscriber->Form->type_application == 'R'){
  533. if($c->Subscriber->street != ''){
  534. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  535. }else {
  536. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  537. }
  538. $name = $c->Subscriber->name;
  539. }else if($c->Subscriber->Form->type_application == 'B'){
  540. if($c->Subscriber->unit_no != ''){
  541. $address = $c->Subscriber->unit_no. ', '.$c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  542. }else {
  543. $address = $c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  544. }
  545. $name = $c->Subscriber->company_name;
  546. }
  547. $i++;
  548. array_push($final, array(
  549. 'index' => $c->formT,
  550. 'contract' => $c->contract,
  551. 'wo' => $c->wo,
  552. 'activated_dt' => $c->activated_dt,
  553. 'name' => $name,
  554. 'address' => $address,
  555. 'package' => $c->package,
  556. 'retail_price' => 'RM '.$c->retail_price,
  557. 'incentives1' => $c->incentives1,
  558. 'incentives2' => $c->incentives2,
  559. 'total' => 'RM' .$c->total_claim,
  560. 'claimed' => $c->claim_dt,
  561. ));
  562. }
  563. foreach($dataClaim as $f){
  564. $basic_total += $f->total_claim;
  565. }
  566. // Calculate extra incentves
  567. if($month == '01' && $year == '2020'){
  568. if(count($count_cyberjaya) > 50){
  569. $balance = count($count_cyberjaya) - 50;
  570. $extra += $balance * 50;
  571. }
  572. if(count($count_ayerKeroh) > 50){
  573. $balance = count($count_ayerKeroh) - 50;
  574. $extra += $balance * 50;
  575. }
  576. if(count($count_alorGajah) > 50){
  577. $balance = count($count_alorGajah) - 50;
  578. $extra += $balance * 50;
  579. }
  580. if(count($count_menglembu) > 50){
  581. $balance = count($count_menglembu) - 50;
  582. $extra += $balance * 50;
  583. }
  584. if(count($count_ipoh) > 50){
  585. $balance = count($count_ipoh) - 50;
  586. $extra += $balance * 50;
  587. }
  588. if(count($count_jasin) > 10){
  589. $balance = count($count_jasin) - 10;
  590. $extra += $balance * 50;
  591. }
  592. }else if($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')){
  593. if(count($count_cyberjaya) > 50){
  594. $balance = count($count_cyberjaya) - 50;
  595. $extra += $balance * 50;
  596. }
  597. if(count($count_ayerKeroh) > 50){
  598. $balance = count($count_ayerKeroh) - 50;
  599. $extra += $balance * 50;
  600. }
  601. if(count($count_alorGajah) > 50){
  602. $balance = count($count_alorGajah) - 50;
  603. $extra += $balance * 50;
  604. }
  605. if(count($count_menglembu) > 50){
  606. $balance = count($count_menglembu) - 50;
  607. $extra += $balance * 50;
  608. }
  609. if(count($count_ipoh) > 50){
  610. $balance = count($count_ipoh) - 50;
  611. $extra += $balance * 50;
  612. }
  613. if(count($count_jasin) > 20){
  614. $balance = count($count_jasin) - 20;
  615. $extra += $balance * 50;
  616. }
  617. }else {
  618. $extra = 0;
  619. }
  620. $totals = $basic_total + $extra;
  621. $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  622. $pdf->setPaper('A4', 'landscape');
  623. $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  624. return $pdf->download( $pdfName );
  625. }
  626. }
  627. /***
  628. / Encrypt Password
  629. ***/
  630. public function encryptPassword($action, $string) {
  631. $output = false;
  632. $encrypt_method = "AES-256-CBC";
  633. $secret_key = '28472B4B6250655368566D5970337336';
  634. $secret_iv = md5(md5($string)); //'This is my secret iv';
  635. // hash
  636. $key = hash('sha256', $secret_key);
  637. $iv = substr(hash('sha256', $secret_iv), 0, 16);
  638. if ( $action == 'encrypt' ) {
  639. $output = openssl_encrypt($string, $encrypt_method, $key, 0, $iv);
  640. $output = base64_encode($output);
  641. } else if( $action == 'decrypt' ) {
  642. $output = openssl_decrypt(base64_decode($string), $encrypt_method, $key, 0, $iv);
  643. }
  644. return $output;
  645. }
  646. /***
  647. / Agent Form
  648. ***/
  649. public function showAgentForm(){
  650. $id = Auth::guard('ds')->id();
  651. $user = Staff::with('StaffDetail')->find($id);
  652. return view('dealer.add_agent',compact('user'));
  653. }
  654. /***
  655. / Add Agent
  656. ***/
  657. public function requestAddAgent(Request $request)
  658. {
  659. $validator = Validator::make($request->all(), [
  660. 'password' => 'min:8|confirmed',
  661. ]);
  662. if ($validator->fails()) {
  663. return redirect()->back()->withInput()->withErrors($validator);
  664. }
  665. $user = Staff::where('email', $request->get('email'))->first();
  666. if (empty($user)) {
  667. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  668. $dealerD = new StaffDetail;
  669. $dealerD->name = $request->get('aname');
  670. $dealerD->ic = $request->get('ic');
  671. $dealerD->email = $request->get('email');
  672. $dealerD->phone = $request->get('phone');
  673. $dealerD->company_id = $request->get('company_id');
  674. $dealerD->color = '';
  675. $dealerD->position = 'Sales';
  676. $dealerD->password = $pass;
  677. $dealerD->user_pic = 'assets/avatar/user.png';
  678. // Save Login Dealer
  679. $loginD = new Staff;
  680. $loginD->email = $request->get('email');
  681. $loginD->password = $pass;
  682. $loginD->roles_access = 'Sales';
  683. $loginD->company_id = $request->get('company_id');
  684. $loginD->last_login_at = '';
  685. $loginD->last_login_ip = '';
  686. // $loginData = [
  687. // 'email' => $request->get('email'),
  688. // 'password' => $pass,
  689. // 'roles_access' => 'Sales',
  690. // 'last_login_at' => '',
  691. // 'last_login_ip' => '',
  692. // ];
  693. $company = Company::where('_id',$request->get('company_id'))->first();
  694. $company->staff()->save($loginD);
  695. // $dealer = DealerLaravel::create($loginData);
  696. $loginD->staffdetail()->save($dealerD);
  697. return redirect()->back()->with('success_msg', '<strong>Success!</strong> register <strong>'.$request->get('email').'</strong>');
  698. }
  699. else
  700. {
  701. return redirect()->back()->withInput()->withErrors('Email already exist!');
  702. }
  703. }
  704. public function editAgentDealer($agent_id)
  705. {
  706. $id = Auth::guard('ds')->id();
  707. $user = Staff::find($id);
  708. $email = $user->email;
  709. $userDetails = StaffDetail::where('email',$email)->first();
  710. $person = StaffDetail::where('_id', $agent_id)->first();
  711. return view('dealer.edit_agent', compact('person','userDetails','user'));
  712. }
  713. public function deleteAgent(Request $request)
  714. {
  715. $agent = Staff::where('_id',$request->id)->first();
  716. $agentdetail = $agent->staffdetail()->first();
  717. if(!empty($agentdetail) && !empty($agent))
  718. {
  719. $agent->delete();
  720. $agentdetail->delete();
  721. return 'true';
  722. }
  723. else
  724. {
  725. return 'false';
  726. }
  727. }
  728. //Show claim list by company
  729. public function mClaimListAll($company)
  730. {
  731. $id = Auth::guard('ds')->id();
  732. $user = Staff::with('StaffDetail')->find($id);
  733. $dealer_claimAll = DealerClaim::where('dealer',$company)->orderBy('activated_dt','desc')->get();
  734. $i = 0;
  735. $nested_data = array();
  736. foreach ($dealer_claimAll as $c){
  737. $customer = Subscriber::with('Form')->where('_id', $c->customer_id)->first();
  738. $address = '';
  739. if($customer->Form->type_application == 'R'){
  740. if($customer->street != ''){
  741. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  742. }else {
  743. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  744. }
  745. }else if($customer->Form->type_application == 'B'){
  746. if($customer->unit_no != ''){
  747. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  748. }else {
  749. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  750. }
  751. }
  752. $i++;
  753. array_push($nested_data, array(
  754. 'index' => $c->formT,
  755. 'contract' => $c->contract,
  756. 'wo' => $c->wo,
  757. 'activated_dt' => $c->activated_dt,
  758. 'name' => $customer->name,
  759. 'address' => $address,
  760. 'package' => $c->package,
  761. 'retail_price' => 'RM '.$c->retail_price,
  762. 'incentives1' => '',
  763. 'incentives2' => '',
  764. 'total' => '',
  765. 'claimed' => $c->laim_dt,
  766. 'action' => 'null',
  767. ));
  768. }
  769. return \DataTables::of($nested_data)->make(true);
  770. }
  771. // Get Dealer Claim Residential
  772. public function returnDataR($company,$year,$month){
  773. $dataCR = DealerClaim::where('formT','R')->where('dealer',$company)->get();
  774. $final = array();
  775. // Month & Year
  776. $mY = '';
  777. if($year != 'null' && $month != 'null'){
  778. $mY = $month.'/'.$year;
  779. }
  780. if($mY != ''){
  781. $data12 = array(); $data24 = array();
  782. $countD12 = 0; $countD24 = 0;
  783. foreach($dataCR as $dc){
  784. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  785. if($dc->contract == "12"){
  786. $data12[] = $dc;
  787. }else if($dc->contract == "24"){
  788. $data24[] = $dc;
  789. }
  790. }
  791. }
  792. $countD24 = count($data24);
  793. $countD12 = count($data12);
  794. $comm = Commission::where('formT','R')->get();
  795. $commV12 = 0; $commV24 = 0;
  796. $comm12 = ''; $comm24 = '';
  797. foreach($comm as $c){
  798. if($c->contract =='12'){
  799. if(strpos($c->ranges, '>') !== false) {
  800. $pieces = explode(">", $c->ranges);
  801. if($countD12 >= intval($pieces[1])){
  802. $commV12 = floatval($c->comm)/100;
  803. $comm12 = $c->comm.'%';
  804. }
  805. }
  806. if(strpos($c->ranges,'-') !== false){
  807. $pieces = explode("-", $c->ranges);
  808. if($countD12 >= intval($pieces[0]) && $countD12 <= intval($pieces[1])){
  809. $commV12 = floatval($c->comm)/100;
  810. $comm12 = $c->comm.'%';
  811. }
  812. }
  813. }else if($c->contract =='24'){
  814. // Contract => 24
  815. if($countD24 != 0){
  816. if(strpos($c->ranges, '>') !== false) {
  817. $pieces = explode(">", $c->ranges);
  818. if($countD24 > intval($pieces[1])){
  819. $commV24 = floatval($c->comm)/100;
  820. $comm24 = $c->comm.'%';
  821. }
  822. }
  823. if(strpos($c->ranges,'-') !== false){
  824. $pieces = explode("-", $c->ranges);
  825. if($countD24 >= intval($pieces[0]) && $countD24 <= intval($pieces[1])){
  826. $commV24 = floatval($c->comm)/100;
  827. $comm24 = $c->comm.'%';
  828. }
  829. }
  830. }
  831. }
  832. }
  833. foreach ($data12 as $key => $d) {
  834. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  835. $address = ''; $name = '';
  836. if($customer->Form->type_application == 'R'){
  837. if($customer->street != ''){
  838. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  839. }else {
  840. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  841. }
  842. $name = $customer->name;
  843. }else if($customer->Form->type_application == 'B'){
  844. if($customer->unit_no != ''){
  845. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  846. }else {
  847. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  848. }
  849. $name = $customer->company_name;
  850. }
  851. $final[] = array(
  852. 'index' => $d['formT'],
  853. 'contract' => $d['contract'],
  854. 'wo' => $d['wo'],
  855. 'activation' => $d['activated_dt'],
  856. 'name' => $name,
  857. 'address' => $address,
  858. 'package' => $d['package'],
  859. 'retail_price' => 'RM '.$d['retail_price'],
  860. 'incentives1' => $comm12,
  861. 'incentives2' => '',
  862. 'total' => 'RM '.number_format($d['retail_price']*$commV12,2),
  863. 'claim' => $d['claim_dt'],
  864. );
  865. }
  866. foreach ($data24 as $key => $d) {
  867. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  868. $address = ''; $name = '';
  869. if($customer->Form->type_application == 'R'){
  870. if($customer->street != ''){
  871. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  872. }else {
  873. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  874. }
  875. $name = $customer->name;
  876. }else if($customer->Form->type_application == 'B'){
  877. if($customer->unit_no != ''){
  878. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  879. }else {
  880. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  881. }
  882. $name = $customer->company_name;
  883. }
  884. $final[] = array(
  885. 'index' => $d['formT'],
  886. 'contract' => $d['contract'],
  887. 'wo' => $d['wo'],
  888. 'activation' => $d['activated_dt'],
  889. 'name' => $name,
  890. 'address' => $address,
  891. 'package' => $d['package'],
  892. 'retail_price' => 'RM '.$d['retail_price'],
  893. 'incentives1' => $comm24,
  894. 'incentives2' => '',
  895. 'total' => 'RM '.number_format($d['retail_price']*$commV24,2),
  896. 'claim' => $d['claim_dt'],
  897. );
  898. }
  899. }else {
  900. foreach ($dataCR as $c){
  901. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  902. $address = ''; $name = '';
  903. if($customer->Form->type_application == 'R'){
  904. if($customer->street != ''){
  905. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  906. }else {
  907. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  908. }
  909. $name = $customer->name;
  910. }else if($customer->Form->type_application == 'B'){
  911. if($customer->unit_no != ''){
  912. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  913. }else {
  914. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  915. }
  916. $name = $customer->company_name;
  917. }
  918. $final[] = array(
  919. 'index' => $c['formT'],
  920. 'contract' => $c['contract'],
  921. 'wo' => $c['wo'],
  922. 'activation' => $c['activated_dt'],
  923. 'name' => $name,
  924. 'address' => $address,
  925. 'package' => $c['package'],
  926. 'retail_price' => 'RM '.$c['retail_price'],
  927. 'incentives1' => '',
  928. 'incentives2' => '',
  929. 'total' => '',
  930. 'claim' => $c['claim_dt'],
  931. );
  932. }
  933. }
  934. return $final;
  935. }
  936. // Get Claim Business
  937. public function returnDataB($company,$year,$month){
  938. $dataCB = DealerClaim::where('formT','B')->where('dealer',$company)->get();
  939. $final = array();
  940. // Month & Year
  941. $mY = '';
  942. if($year != 'null' && $month != 'null'){
  943. $mY = $month.'/'.$year;
  944. }
  945. if($mY != ''){
  946. /** Contract 12
  947. // 1=>10-100 2=>300 3=>500 4=>1
  948. **/
  949. $data12_1 = array(); $data12_2 = array();
  950. $data12_3 = array(); $data12_4 = array();
  951. $countD12_1 = 0; $countD12_2 = 0;
  952. $countD12_3 = 0; $countD12_4 = 0;
  953. /** Contract 24
  954. // 1=>10-100 2=>300 3=>500 4=>1
  955. **/
  956. $data24_1 = array(); $data24_2 = array();
  957. $data24_3 = array(); $data24_4 = array();
  958. $countD24_1 = 0; $countD24_2 = 0;
  959. $countD24_3 = 0; $countD24_4 = 0;
  960. foreach($dataCB as $dc){
  961. if($dc->activated_my == $mY || $dc->activated_my == '0'.$mY ){
  962. if($dc->contract == "12" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  963. $data12_1[] = $dc;
  964. }else if($dc->contract == "12" && $dc->package == "300"){
  965. $data12_2[] = $dc;
  966. }else if($dc->contract == "12" && $dc->package == "500"){
  967. $data12_3[] = $dc;
  968. }else if($dc->contract == "12" && $dc->package == "1"){
  969. $data12_4[] = $dc;
  970. }else if($dc->contract == "24" && ($dc->package == "10" || $dc->package == "30" || $dc->package == "50" || $dc->package == "100")){
  971. $data24_1[] = $dc;
  972. }else if($dc->contract == "24" && $dc->package == "300"){
  973. $data24_2[] = $dc;
  974. }else if($dc->contract == "24" && $dc->package == "500"){
  975. $data24_3[] = $dc;
  976. }else if($dc->contract == "24" && $dc->package == "1"){
  977. $data24_4[] = $dc;
  978. }
  979. }
  980. }
  981. $countD12_1 = count($data12_1); $countD12_2 = count($data12_2);
  982. $countD12_3 = count($data12_3); $countD12_4 = count($data12_4);
  983. $countD24_1 = count($data24_1); $countD24_2 = count($data24_2);
  984. $countD24_3 = count($data24_3); $countD24_4 = count($data24_4);
  985. $comm = Commission::where('formT','B')->get();
  986. $commV12_1 = 0; $commV12_2 = 0;
  987. $commV12_3 = 0; $commV12_4 = 0;
  988. $commV24_1 = 0; $commV24_2 = 0;
  989. $commV24_3 = 0; $commV24_4 = 0;
  990. $comm12_1 = ''; $comm12_2 = '';
  991. $comm12_3 = ''; $comm12_4 = '';
  992. $comm24_1 = ''; $comm24_2 = '';
  993. $comm24_3 = ''; $comm24_4 = '';
  994. $addRM12_1 = ''; $addRM12_2 = '';
  995. $addRM12_3 = ''; $addRM12_4 = '';
  996. $addRM24_1 = ''; $addRM24_2 = '';
  997. $addRM24_3 = ''; $addRM24_4 = '';
  998. foreach($comm as $c){
  999. /*** Contract 24 **/
  1000. if($c->contract =='24' && $c->packageR == "300"){
  1001. if(strpos($c->ranges, '>') !== false) {
  1002. $pieces = explode(">", $c->ranges);
  1003. if($countD24_2 >= intval($pieces[1])){
  1004. if(strpos($c->comm, 'RM') !== false) {
  1005. $comm24_2 = '+ ' .$c->comm;
  1006. $commV24_2 = '';
  1007. $addRM24_2 = $c->comm;
  1008. }else {
  1009. $comms = explode("RM", $c->comm);
  1010. if(!empty($comms[1])){
  1011. $comm24_2 = 'RM '.$comms[1];
  1012. $commV24_2 = floatval($comms[1]);
  1013. }else {
  1014. if($comms[0] != ''){
  1015. $comm24_2 = $comms[0].'%';
  1016. $commV24_2 = floatval($comms[0])/100;
  1017. }
  1018. }
  1019. }
  1020. }
  1021. }
  1022. }else if($c->contract =='24' && $c->packageR == "500"){
  1023. if(strpos($c->ranges, '>') !== false) {
  1024. $pieces = explode(">", $c->ranges);
  1025. if($countD24_3 >= intval($pieces[1])){
  1026. if(strpos($c->comm, 'RM') !== false) {
  1027. $comm24_3 = '+ ' .$c->comm;
  1028. $commV24_3 = '';
  1029. $addRM24_3 = $c->comm;
  1030. }else {
  1031. $comms = explode("RM", $c->comm);
  1032. if(isset($comms[1])){
  1033. $comm24_3 = 'RM '.$comms[1];
  1034. $commV24_3 = floatval($comms[1]);
  1035. }else {
  1036. if($comms[0] != ''){
  1037. $comm24_3 = $comms[0].'%';
  1038. $commV24_3 = floatval($comms[0])/100;
  1039. }
  1040. }
  1041. }
  1042. }
  1043. }
  1044. }else if($c->contract =='24' && $c->packageR == "1"){
  1045. if(strpos($c->ranges, '>') !== false) {
  1046. $pieces = explode(">", $c->ranges);
  1047. if($countD24_4 >= intval($pieces[1])){
  1048. if(strpos($c->comm, 'RM') !== false) {
  1049. $comm24_4 = '+ ' .$c->comm;
  1050. $commV24_4 = '';
  1051. $addRM24_4 = $c->comm;
  1052. }else {
  1053. $comms = explode("RM", $c->comm);
  1054. if(isset($comms[1])){
  1055. $comm24_4 = 'RM '.$comms[1];
  1056. $commV24_4 = floatval($comms[1]);
  1057. }else {
  1058. if($comms[0] != ''){
  1059. $comm24_4 = $comms[0].'%';
  1060. $commV24_4 = floatval($comms[0])/100;
  1061. }
  1062. }
  1063. }
  1064. }
  1065. }
  1066. }else if($c->contract =='24' && $c->packageR == "10,30,50,100"){
  1067. if(strpos($c->ranges,'-') !== false){
  1068. $pieces = explode("-", $c->ranges);
  1069. if($countD24_1 >= intval($pieces[0]) && $countD24_1 <= intval($pieces[1])){
  1070. if(strpos($c->comm, 'RM') !== false) {
  1071. $comm24_1 = '+ ' .$c->comm;
  1072. $commV24_1 = '';
  1073. $addRM24_1 = $c->comm;
  1074. }else {
  1075. $comms = explode("RM", $c->comm);
  1076. if(!empty($comms[1])){
  1077. $comm24_1 = 'RM '.$comms[1];
  1078. $commV24_1 = floatval($comms[1]);
  1079. }else {
  1080. if($comms[0] != ''){
  1081. $comm24_1 = $comms[0].'%';
  1082. $commV24_1 = floatval($comms[0])/100;
  1083. }
  1084. }
  1085. }
  1086. }
  1087. }
  1088. if(strpos($c->ranges, '>') !== false) {
  1089. $pieces1 = explode(">", $c->ranges);
  1090. if($countD24_1 >= intval($pieces1[1])){
  1091. if(strpos($c->comm, "RM") === true) {
  1092. $comm24_1 = '+ ' .$c->comm;
  1093. $commV24_1 = '';
  1094. $addRM24_1 = $c->comm;
  1095. }else {
  1096. $comms = explode("RM", $c->comm);
  1097. if(empty($comms[1])){
  1098. $comm24_1 = 'RM '.$comms[1];
  1099. $commV24_1 = floatval($comms[1]);
  1100. }else {
  1101. if($comms[0] != ''){
  1102. $comm24_1 = str_replace ('+ ','',$comms[0]).'%';
  1103. $commV24_1 = floatval($comms[0])/100;
  1104. $addRM24_1 = $comms[1];
  1105. }
  1106. }
  1107. }
  1108. }
  1109. }
  1110. }
  1111. /*** Contract 12 **/
  1112. else if($c->contract =='12' && $c->packageR == "10,30,50,100"){
  1113. if(strpos($c->ranges, '>') !== false) {
  1114. $pieces = explode(">", $c->ranges);
  1115. if($countD12_1 >= intval($pieces[1])){
  1116. if(strpos($c->comm, 'RM') !== false) {
  1117. $comm12_1 = '+ ' .$c->comm;
  1118. $commV12_1 = '';
  1119. $addRM12_1 = $c->comm;
  1120. }else {
  1121. $comms = explode("RM", $c->comm);
  1122. if(isset($comms[1])){
  1123. $comm12_1 = 'RM '.$comms[1];
  1124. $commV12_1 = floatval($comms[1]);
  1125. }else {
  1126. if($comms[0] != ''){
  1127. $comm12_1 = $comms[0].'%';
  1128. $commV12_1 = floatval($comms[0])/100;
  1129. }
  1130. }
  1131. }
  1132. }
  1133. }
  1134. if(strpos($c->ranges,'-') !== false){
  1135. $pieces = explode("-", $c->ranges);
  1136. if($countD12_1 >= intval($pieces[0]) && $countD12_1 <= intval($pieces[1])){
  1137. if(strpos($c->comm, 'RM') !== false) {
  1138. $comm12_1 = '+ ' .$c->comm;
  1139. $commV12_1 = '';
  1140. $addRM12_1 = $c->comm;
  1141. }else {
  1142. $comms = explode("RM", $c->comm);
  1143. if(isset($comms[1])){
  1144. $comm12_1 = 'RM '.$comms[1];
  1145. $commV12_1 = floatval($comms[1]);
  1146. }else {
  1147. if($comms[0] != ''){
  1148. $comm12_1 = $comms[0].'%';
  1149. $commV12_1 = floatval($comms[0])/100;
  1150. }
  1151. }
  1152. }
  1153. }
  1154. }
  1155. }else if($c->contract =='12' && $c->packageR == "300"){
  1156. if(strpos($c->ranges, '>') !== false) {
  1157. $pieces = explode(">", $c->ranges);
  1158. if($countD12_2 >= intval($pieces[1])){
  1159. if(strpos($c->comm, 'RM') !== false) {
  1160. $comm12_2 = '+ ' .$c->comm;
  1161. $commV12_2 = '';
  1162. $addRM12_2 = $c->comm;
  1163. }else {
  1164. $comms = explode("RM", $c->comm);
  1165. if(isset($comms[1])){
  1166. $comm12_2 = 'RM '.$comms[1];
  1167. $commV12_2 = floatval($comms[1]);
  1168. }else {
  1169. if($comms[0] != ''){
  1170. $comm12_2 = $comms[0].'%';
  1171. $commV12_2 = floatval($comms[0])/100;
  1172. }
  1173. }
  1174. }
  1175. }
  1176. }
  1177. }else if($c->contract =='12' && $c->packageR == "500"){
  1178. if(strpos($c->ranges, '>') !== false) {
  1179. $pieces = explode(">", $c->ranges);
  1180. if($countD12_3 >= intval($pieces[1])){
  1181. if(strpos($c->comm, 'RM') !== false) {
  1182. $comm12_3 = '+ ' .$c->comm;
  1183. $commV12_3 = '';
  1184. $addRM12_3 = $c->comm;
  1185. }else {
  1186. $comms = explode("RM", $c->comm);
  1187. if(isset($comms[1])){
  1188. $comm12_3 = 'RM '.$comms[1];
  1189. $commV12_3 = floatval($comms[1]);
  1190. }else {
  1191. if($comms[0] != ''){
  1192. $comm12_3 = $comms[0].'%';
  1193. $commV12_3 = floatval($comms[0])/100;
  1194. }
  1195. }
  1196. }
  1197. }
  1198. }
  1199. }else if($c->contract =='12' && $c->packageR == "1"){
  1200. if(strpos($c->ranges, '>') !== false) {
  1201. $pieces = explode(">", $c->ranges);
  1202. if($countD12_4 >= intval($pieces[1])){
  1203. if(strpos($c->comm, 'RM') !== false) {
  1204. $comm12_4 = '+ ' .$c->comm;
  1205. $commV12_4 = '';
  1206. $addRM12_4 = $c->comm;
  1207. }else {
  1208. $comms = explode("RM", $c->comm);
  1209. if(isset($comms[1])){
  1210. $comm12_4 = 'RM '.$comms[1];
  1211. $commV12_4 = floatval($comms[1]);
  1212. }else {
  1213. if($comms[0] != ''){
  1214. $comm12_4 = $comms[0].'%';
  1215. $commV12_4 = floatval($comms[0])/100;
  1216. }
  1217. }
  1218. }
  1219. }
  1220. }
  1221. }
  1222. }
  1223. // Category 10,30,50,100
  1224. foreach ($data12_1 as $key => $d) {
  1225. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1226. $address = ''; $name = '';
  1227. if($customer->Form->type_application == 'R'){
  1228. if($customer->street != ''){
  1229. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1230. }else {
  1231. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1232. }
  1233. $name = $customer->name;
  1234. }else if($customer->Form->type_application == 'B'){
  1235. if($customer->unit_no != ''){
  1236. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1237. }else {
  1238. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1239. }
  1240. $name = $customer->company_name;
  1241. }
  1242. $total = '';
  1243. if($commV12_1 == ''){
  1244. $total = $addRM12_1;
  1245. }else {
  1246. $total = number_format($d['retail_price']*$commV12_1,2);
  1247. }
  1248. $final[] = array(
  1249. 'index' => $d['formT'],
  1250. 'contract' => $d['contract'],
  1251. 'wo' => $d['wo'],
  1252. 'activation' => $d['activated_dt'],
  1253. 'name' => $name,
  1254. 'address' => $address,
  1255. 'package' => $d['package'],
  1256. 'retail_price' => 'RM '.$d['retail_price'],
  1257. 'incentives1' => $comm12_1,
  1258. 'incentives2' => $addRM12_1,
  1259. 'total' => 'RM '.$total,
  1260. 'claim' => $c['claim_dt'],
  1261. );
  1262. }
  1263. foreach ($data24_1 as $key => $d) {
  1264. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1265. $address = ''; $name = '';
  1266. if($customer->Form->type_application == 'R'){
  1267. if($customer->street != ''){
  1268. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1269. }else {
  1270. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1271. }
  1272. $name = $customer->name;
  1273. }else if($customer->Form->type_application == 'B'){
  1274. if($customer->unit_no != ''){
  1275. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1276. }else {
  1277. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1278. }
  1279. $name = $customer->company_name;
  1280. }
  1281. $total = '';
  1282. if($commV24_1 == ''){
  1283. $total = $addRM24_1;
  1284. }else {
  1285. $total = number_format(($d['retail_price']*$commV24_1) + floatval($addRM24_1),2);
  1286. }
  1287. $final[] = array(
  1288. 'index' => $d['formT'],
  1289. 'contract' => $d['contract'],
  1290. 'wo' => $d['wo'],
  1291. 'activation' => $d['activated_dt'],
  1292. 'name' => $name,
  1293. 'address' => $address,
  1294. 'package' => $d['package'],
  1295. 'retail_price' => 'RM '.$d['retail_price'],
  1296. 'incentives1' => $comm24_1,
  1297. 'incentives2' => $addRM24_1,
  1298. 'total' => 'RM '.$total,
  1299. 'claim' => $c['claim_dt'],
  1300. );
  1301. }
  1302. // Category 300
  1303. foreach ($data12_2 as $key => $d) {
  1304. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1305. $address = ''; $name = '';
  1306. if($customer->Form->type_application == 'R'){
  1307. if($customer->street != ''){
  1308. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1309. }else {
  1310. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1311. }
  1312. $name = $customer->name;
  1313. }else if($customer->Form->type_application == 'B'){
  1314. if($customer->unit_no != ''){
  1315. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1316. }else {
  1317. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1318. }
  1319. $name = $customer->company_name;
  1320. }
  1321. $total = '';
  1322. if($commV12_2 == ''){
  1323. $total = $addRM12_2;
  1324. }else {
  1325. $total = number_format($d['retail_price']*$commV12_2,2);
  1326. }
  1327. $final[] = array(
  1328. 'index' => $d['formT'],
  1329. 'contract' => $d['contract'],
  1330. 'wo' => $d['wo'],
  1331. 'activation' => $d['activated_dt'],
  1332. 'name' => $name,
  1333. 'address' => $address,
  1334. 'package' => $d['package'],
  1335. 'retail_price' => 'RM '.$d['retail_price'],
  1336. 'incentives1' => $comm12_2,
  1337. 'incentives2' => $addRM12_2,
  1338. 'total' => 'RM '.$total,
  1339. 'claim' => $c['claim_dt'],
  1340. );
  1341. }
  1342. foreach ($data24_2 as $key => $d) {
  1343. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1344. $address = ''; $name = '';
  1345. if($customer->Form->type_application == 'R'){
  1346. if($customer->street != ''){
  1347. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1348. }else {
  1349. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1350. }
  1351. $name = $customer->name;
  1352. }else if($customer->Form->type_application == 'B'){
  1353. if($customer->unit_no != ''){
  1354. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1355. }else {
  1356. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1357. }
  1358. $name = $customer->company_name;
  1359. }
  1360. $total = '';
  1361. if($commV24_2 == ''){
  1362. $total = $addRM24_2;
  1363. }else {
  1364. $total = number_format($d['retail_price']*$commV24_2,2);
  1365. }
  1366. $final[] = array(
  1367. 'index' => $d['formT'],
  1368. 'contract' => $d['contract'],
  1369. 'wo' => $d['wo'],
  1370. 'activation' => $d['activated_dt'],
  1371. 'name' => $name,
  1372. 'address' => $address,
  1373. 'package' => $d['package'],
  1374. 'retail_price' => 'RM '.$d['retail_price'],
  1375. 'incentives1' => $comm24_2,
  1376. 'incentives2' => $addRM24_2,
  1377. 'total' => 'RM '.$total,
  1378. 'claim' => $c['claim_dt'],
  1379. );
  1380. }
  1381. // Category 500
  1382. foreach ($data12_3 as $key => $d) {
  1383. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1384. $address = ''; $name = $customer->name;
  1385. if($customer->Form->type_application == 'R'){
  1386. if($customer->street != ''){
  1387. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1388. }else {
  1389. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1390. }
  1391. }else if($customer->Form->type_application == 'B'){
  1392. if($customer->unit_no != ''){
  1393. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1394. }else {
  1395. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1396. }
  1397. $name = $customer->company_name;
  1398. }
  1399. $total = '';
  1400. if($commV12_3 == ''){
  1401. $total = $addRM12_3;
  1402. }else {
  1403. $total = number_format($d['retail_price']*$commV12_3,2);
  1404. }
  1405. $final[] = array(
  1406. 'index' => $d['formT'],
  1407. 'contract' => $d['contract'],
  1408. 'wo' => $d['wo'],
  1409. 'activation' => $d['activated_dt'],
  1410. 'name' => $name,
  1411. 'address' => $address,
  1412. 'package' => $d['package'],
  1413. 'retail_price' => 'RM '.$d['retail_price'],
  1414. 'incentives1' => $comm12_3,
  1415. 'incentives2' => $addRM12_3,
  1416. 'total' => 'RM '.$total,
  1417. 'claim' => $c['claim_dt'],
  1418. );
  1419. }
  1420. foreach ($data24_3 as $key => $d) {
  1421. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1422. $address = ''; $name = '';
  1423. if($customer->Form->type_application == 'R'){
  1424. if($customer->street != ''){
  1425. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1426. }else {
  1427. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1428. }
  1429. $name = $customer->name;
  1430. }else if($customer->Form->type_application == 'B'){
  1431. if($customer->unit_no != ''){
  1432. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1433. }else {
  1434. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1435. }
  1436. $name = $customer->company_name;
  1437. }
  1438. $total = '';
  1439. if($commV24_3 == ''){
  1440. $total = $addRM24_3;
  1441. }else {
  1442. $total = number_format($d['retail_price']*$commV24_3,2);
  1443. }
  1444. $final[] = array(
  1445. 'index' => $d['formT'],
  1446. 'contract' => $d['contract'],
  1447. 'wo' => $d['wo'],
  1448. 'activation' => $d['activated_dt'],
  1449. 'name' => $name,
  1450. 'address' => $address,
  1451. 'package' => $d['package'],
  1452. 'retail_price' => 'RM '.$d['retail_price'],
  1453. 'incentives1' => $comm24_3,
  1454. 'incentives2' => $addRM24_3,
  1455. 'total' => 'RM '.$total,
  1456. 'claim' => $c['claim_dt'],
  1457. );
  1458. }
  1459. // Category 1
  1460. foreach ($data12_4 as $key => $d) {
  1461. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1462. $address = ''; $name = '';
  1463. if($customer->Form->type_application == 'R'){
  1464. if($customer->street != ''){
  1465. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1466. }else {
  1467. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1468. }
  1469. $name = $customer->name;
  1470. }else if($customer->Form->type_application == 'B'){
  1471. if($customer->unit_no != ''){
  1472. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1473. }else {
  1474. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1475. }
  1476. $name = $customer->company_name;
  1477. }
  1478. $total = '';
  1479. if($commV12_4 == ''){
  1480. $total = $addRM12_4;
  1481. }else {
  1482. $total = number_format($d['retail_price']*$commV12_4,2);
  1483. }
  1484. $final[] = array(
  1485. 'index' => $d['formT'],
  1486. 'contract' => $d['contract'],
  1487. 'wo' => $d['wo'],
  1488. 'activation' => $d['activated_dt'],
  1489. 'name' => $name,
  1490. 'address' => $address,
  1491. 'package' => $d['package'],
  1492. 'retail_price' => 'RM '.$d['retail_price'],
  1493. 'incentives1' => $comm12_4,
  1494. 'incentives2' => $addRM12_4,
  1495. 'total' => 'RM '.$total,
  1496. 'claim' => $c['claim_dt'],
  1497. );
  1498. }
  1499. foreach ($data24_4 as $key => $d) {
  1500. $customer = Subscriber::with('Form')->where('_id', $d['customer_id'])->first();
  1501. $address = ''; $name = '';
  1502. if($customer->Form->type_application == 'R'){
  1503. if($customer->street != ''){
  1504. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1505. }else {
  1506. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1507. }
  1508. $name = $customer->name;
  1509. }else if($customer->Form->type_application == 'B'){
  1510. if($customer->unit_no != ''){
  1511. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1512. }else {
  1513. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1514. }
  1515. $name = $customer->company_name;
  1516. }
  1517. $total = '';
  1518. if($commV24_4 == ''){
  1519. $total = $addRM24_4;
  1520. }else {
  1521. $total = number_format($d['retail_price']*$commV24_4,2);
  1522. }
  1523. $final[] = array(
  1524. 'index' => $d['formT'],
  1525. 'contract' => $d['contract'],
  1526. 'wo' => $d['wo'],
  1527. 'activation' => $d['activated_dt'],
  1528. 'name' => $name,
  1529. 'address' => $address,
  1530. 'package' => $d['package'],
  1531. 'retail_price' => 'RM '.$d['retail_price'],
  1532. 'incentives1' => $comm24_4,
  1533. 'incentives2' => $addRM24_4,
  1534. 'total' => 'RM '.$total,
  1535. 'claim' => $c['claim_dt'],
  1536. );
  1537. }
  1538. }else {
  1539. foreach ($dataCB as $c){
  1540. $customer = Subscriber::with('Form')->where('_id', $c['customer_id'])->first();
  1541. $address = ''; $name = '';
  1542. if($customer->Form->type_application == 'R'){
  1543. if($customer->street != ''){
  1544. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1545. }else {
  1546. $address = $customer->unit_no. ' , '.$customer->building_name. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1547. }
  1548. $name = $customer->name;
  1549. }else if($customer->Form->type_application == 'B'){
  1550. if($customer->unit_no != ''){
  1551. $address = $customer->unit_no. ', '.$customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1552. }else {
  1553. $address = $customer->company_name. ', '.$customer->street. ' , '.$customer->postcode. ' , '.$customer->city. ' , '.$customer->state;
  1554. }
  1555. $name = $customer->company_name;
  1556. }
  1557. $final[] = array(
  1558. 'index' => $c['formT'],
  1559. 'contract' => $c['contract'],
  1560. 'wo' => $c['wo'],
  1561. 'activation' => $c['activated_dt'],
  1562. 'name' => $name,
  1563. 'address' => $address,
  1564. 'package' => $c['package'],
  1565. 'retail_price' => 'RM '.$c['retail_price'],
  1566. 'incentives1' => '',
  1567. 'incentives2' => '',
  1568. 'total' => '',
  1569. 'claim' => $c['claim_dt'],
  1570. );
  1571. }
  1572. }
  1573. return $final;
  1574. }
  1575. /***
  1576. / Return Claim & Combined Business && Resident
  1577. ***/
  1578. public function getClaimRB($company,$year,$month,$app) {
  1579. $dataR = array(); $dataB = array(); $combineData = array();
  1580. if($month=='null' && $year=='null' && $app=='null'){
  1581. return $this->mClaimListAll($company);
  1582. }else if($year!='null' && $month!='null' && $app=='null'){
  1583. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1584. $q->with('Form');
  1585. }],'Staff')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1586. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  1587. foreach ($dataClaim as $key => $d) {
  1588. if(date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  1589. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'){
  1590. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1591. $count_cyberjaya[] = $d;
  1592. }
  1593. if (strpos($d['address'], 'Jasin') !== false) {
  1594. $count_jasin[] = $d;
  1595. }
  1596. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1597. $count_ayerKeroh[] = $d;
  1598. }
  1599. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1600. $count_alorGajah[] = $d;
  1601. }
  1602. if (strpos($d['address'], 'Menglembu') !== false) {
  1603. $count_menglembu[] = $d;
  1604. }
  1605. if (strpos($d['address'], 'Ipoh') !== false) {
  1606. $count_ipoh[] = $d;
  1607. }
  1608. }
  1609. }
  1610. }else if($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')){
  1611. foreach ($dataClaim as $key => $d) {
  1612. if(date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  1613. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'){
  1614. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1615. $count_cyberjaya[] = $d;
  1616. }
  1617. if (strpos($d['address'], 'Jasin') !== false) {
  1618. $count_jasin[] = $d;
  1619. }
  1620. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1621. $count_ayerKeroh[] = $d;
  1622. }
  1623. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1624. $count_alorGajah[] = $d;
  1625. }
  1626. if (strpos($d['address'], 'Menglembu') !== false) {
  1627. $count_menglembu[] = $d;
  1628. }
  1629. if (strpos($d['address'], 'Ipoh') !== false) {
  1630. $count_ipoh[] = $d;
  1631. }
  1632. }
  1633. }
  1634. }
  1635. }else if($year=='null' && $month=='null' && $app!='null'){
  1636. // if($app == 'Residential'){
  1637. // $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1638. // $q->with('Form');
  1639. // }],'Staff')->where('formT', 'R')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1640. // }else if($app == 'Business'){
  1641. // $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1642. // $q->with('Form');
  1643. // }],'Staff')->where('formT', 'B')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1644. // }
  1645. }else if($year!='null' && $month!='null' && $app!='null'){
  1646. if($app == 'Residential'){
  1647. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1648. $q->with('Form');
  1649. }],'Staff')->where('formT', 'R')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1650. if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  1651. foreach ($dataClaim as $key => $d) {
  1652. if(date('d/m/Y', strtotime($d->activated_dt)) >= '12/12/2019' &&
  1653. date('d/m/Y', strtotime($d->activated_dt)) <= '31/01/2020'){
  1654. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1655. $count_cyberjaya[] = $d;
  1656. }
  1657. if (strpos($d['address'], 'Jasin') !== false) {
  1658. $count_jasin[] = $d;
  1659. }
  1660. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1661. $count_ayerKeroh[] = $d;
  1662. }
  1663. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1664. $count_alorGajah[] = $d;
  1665. }
  1666. if (strpos($d['address'], 'Menglembu') !== false) {
  1667. $count_menglembu[] = $d;
  1668. }
  1669. if (strpos($d['address'], 'Ipoh') !== false) {
  1670. $count_ipoh[] = $d;
  1671. }
  1672. }
  1673. }
  1674. }else if($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')){
  1675. foreach ($dataClaim as $key => $d) {
  1676. if(date('d/m/Y', strtotime($d->activated_dt)) >= '27/04/2020' &&
  1677. date('d/m/Y', strtotime($d->activated_dt)) <= '31/07/2020'){
  1678. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1679. $count_cyberjaya[] = $d;
  1680. }
  1681. if (strpos($d['address'], 'Jasin') !== false) {
  1682. $count_jasin[] = $d;
  1683. }
  1684. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1685. $count_ayerKeroh[] = $d;
  1686. }
  1687. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1688. $count_alorGajah[] = $d;
  1689. }
  1690. if (strpos($d['address'], 'Menglembu') !== false) {
  1691. $count_menglembu[] = $d;
  1692. }
  1693. if (strpos($d['address'], 'Ipoh') !== false) {
  1694. $count_ipoh[] = $d;
  1695. }
  1696. }
  1697. }
  1698. }
  1699. }else if($app == 'Business'){
  1700. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  1701. $q->with('Form');
  1702. }],'Staff')->where('formT', 'B')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->orderBy('activated_dt','DESC')->get();
  1703. }
  1704. }
  1705. $i = 0;
  1706. $nested_data = array();
  1707. if(!empty($dataClaim)){
  1708. foreach ($dataClaim as $c){
  1709. $address = ''; $name = '';
  1710. if($c->Subscriber->Form->type_application == 'R'){
  1711. if($c->Subscriber->street != ''){
  1712. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  1713. }else {
  1714. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  1715. }
  1716. $name = $c->Subscriber->name;
  1717. }else if($c->Subscriber->Form->type_application == 'B'){
  1718. if($c->Subscriber->unit_no != ''){
  1719. $address = $c->Subscriber->unit_no. ', '.$c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  1720. }else {
  1721. $address = $c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  1722. }
  1723. $name = $c->Subscriber->company_name;
  1724. }
  1725. $i++;
  1726. array_push($nested_data, array(
  1727. 'index' => $c->formT,
  1728. 'contract' => $c->contract,
  1729. 'wo' => $c->wo,
  1730. 'activated_dt' => $c->activated_dt,
  1731. 'name' => $name,
  1732. 'address' => $address,
  1733. 'package' => $c->package,
  1734. 'retail_price' => 'RM '.$c->retail_price,
  1735. 'incentives1' => $c->incentives1,
  1736. 'incentives2' => $c->incentives2,
  1737. 'total' => 'RM '.$c->total_claim,
  1738. 'claimed' => $c->claim_dt,
  1739. ));
  1740. }
  1741. }
  1742. return \DataTables::of($nested_data)->make(true);
  1743. }
  1744. public function updateAgent(Request $request)
  1745. {
  1746. $user = Staff::where('_id', $request->agent_id)->first();
  1747. $validate = Staff::where('email', $request->email)->first();
  1748. $detail = $user->staffdetail()->first();
  1749. $getpass = $request->get('password');
  1750. $pass = $this->encryptPassword('encrypt', $request->get('password'));
  1751. if(empty($validate))
  1752. {
  1753. $detail->name = $request->get('aname');
  1754. $detail->ic = $request->get('ic');
  1755. $detail->email = $request->get('email');
  1756. $detail->phone = $request->get('phone');
  1757. $detail->company_id = $request->get('vendor');
  1758. $user->email = $request->get('email');
  1759. $user->company_id = $request->get('vendor');
  1760. if(!empty($getpass))
  1761. {
  1762. $validator = Validator::make($request->all(), [
  1763. 'password' => 'min:8|confirmed',
  1764. ]);
  1765. if ($validator->fails())
  1766. {
  1767. return redirect()->back()->withInput()->withErrors($validator);
  1768. }
  1769. $detail->password = $pass;
  1770. $user->password = $pass;
  1771. $detail->save();
  1772. $user->save();
  1773. }
  1774. else
  1775. {
  1776. $detail->save();
  1777. $user->save();
  1778. }
  1779. return redirect()->route('dHome')->with('success_msg', 'message');
  1780. }
  1781. else
  1782. {
  1783. if($user->email == $request->email)
  1784. {
  1785. echo "".$request->get('password');
  1786. $detail->name = $request->get('aname');
  1787. $detail->ic = $request->get('ic');
  1788. $detail->email = $request->get('email');
  1789. $detail->phone = $request->get('phone');
  1790. $detail->company_id = $request->get('vendor');
  1791. $detail->save();
  1792. $user->email = $request->get('email');
  1793. if(!empty($getpass))
  1794. {
  1795. $validator = Validator::make($request->all(), [
  1796. 'password' => 'min:8|confirmed',
  1797. ]);
  1798. if ($validator->fails())
  1799. {
  1800. return redirect()->back()->withInput()->withErrors($validator);
  1801. }
  1802. $detail->password = $pass;
  1803. $user->password = $pass;
  1804. $detail->save();
  1805. $user->save();
  1806. }
  1807. else
  1808. {
  1809. $detail->save();
  1810. $user->save();
  1811. }
  1812. return redirect()->route('dHome')->with('success_msg', 'message');
  1813. }
  1814. else
  1815. {
  1816. echo "email is used";
  1817. return redirect()->back()->withInput()->withErrors('Email already exist!');
  1818. }
  1819. }
  1820. }
  1821. /***
  1822. / Application Form
  1823. ***/
  1824. public function showResidentialForm(){
  1825. $id = Auth::guard('ds')->id();
  1826. $user = Staff::find($id);
  1827. $email = $user->email;
  1828. $userDetails = StaffDetail::where('email',$email)->first();
  1829. return view('dealer.residential-form',compact('userDetails','user'));
  1830. }
  1831. public function showBusinessForm(){
  1832. $id = Auth::guard('ds')->id();
  1833. $user = Staff::find($id);
  1834. $email = $user->email;
  1835. $userDetails = StaffDetail::where('email',$email)->first();
  1836. return view('dealer.business-form',compact('userDetails','user'));
  1837. }
  1838. public function exportDealerJson(Request $request) {
  1839. $final = array();
  1840. $id = Auth::guard('ds')->id();
  1841. // $user = Staff::with('StaffDetail')->find($id);
  1842. // $com = Company::where('_id',$user->StaffDetail->company_id)->first();
  1843. $dataR = array(); $dataB = array(); $combineData = array();
  1844. $extra = 0;
  1845. $year = $request->year;
  1846. $month = $request->month;
  1847. $app = $request->app;
  1848. $company = $request->company;
  1849. if($year!='null' && $month!='null' && $app=='null'){
  1850. $count_cyberjaya = array(); $count_jasin = array(); $count_ayerKeroh = array(); $count_alorGajah = array(); $count_menglembu = array(); $count_ipoh = array();
  1851. $extra = 0; $basic_total = 0; $totals = 0;
  1852. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '01')){
  1853. // $dataDis = $this->returnDataR($company,'2019','12');
  1854. // $dataJan = $this->returnDataR($company,'2020','1');
  1855. if($year == '2020' && ($month == '04' || $month == '05' || $month == '06' || $month == '07')){
  1856. $dataApril = $this->returnDataR($company,'2020','4');
  1857. $dataMay = $this->returnDataR($company,'2020','5');
  1858. $dataJune = $this->returnDataR($company,'2020','6');
  1859. $dataJuly = $this->returnDataR($company,'2020','7');
  1860. foreach ($dataApril as $key => $d) {
  1861. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  1862. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  1863. // $count_cyberjaya[] = $d;
  1864. // }
  1865. // if (strpos($d['address'], 'Jasin') !== false) {
  1866. // $count_jasin[] = $d;
  1867. // }
  1868. // }
  1869. // // else
  1870. if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020'){
  1871. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1872. $count_cyberjaya[] = $d;
  1873. }
  1874. if (strpos($d['address'], 'Jasin') !== false) {
  1875. $count_jasin[] = $d;
  1876. }
  1877. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1878. $count_ayerKeroh[] = $d;
  1879. }
  1880. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1881. $count_alorGajah[] = $d;
  1882. }
  1883. if (strpos($d['address'], 'Menglembu') !== false) {
  1884. $count_menglembu[] = $d;
  1885. }
  1886. if (strpos($d['address'], 'Ipoh') !== false) {
  1887. $count_ipoh[] = $d;
  1888. }
  1889. }
  1890. else {
  1891. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1892. $combineData[] = $d;
  1893. }
  1894. }
  1895. }
  1896. foreach ($dataMay as $key => $d) {
  1897. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1898. $count_cyberjaya[] = $d;
  1899. }
  1900. if (strpos($d['address'], 'Jasin') !== false) {
  1901. $count_jasin[] = $d;
  1902. }
  1903. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1904. $count_ayerKeroh[] = $d;
  1905. }
  1906. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1907. $count_alorGajah[] = $d;
  1908. }
  1909. if (strpos($d['address'], 'Menglembu') !== false) {
  1910. $count_menglembu[] = $d;
  1911. }
  1912. if (strpos($d['address'], 'Ipoh') !== false) {
  1913. $count_ipoh[] = $d;
  1914. }
  1915. }
  1916. foreach ($dataJune as $key => $d) {
  1917. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1918. $count_cyberjaya[] = $d;
  1919. }
  1920. if (strpos($d['address'], 'Jasin') !== false) {
  1921. $count_jasin[] = $d;
  1922. }
  1923. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1924. $count_ayerKeroh[] = $d;
  1925. }
  1926. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1927. $count_alorGajah[] = $d;
  1928. }
  1929. if (strpos($d['address'], 'Menglembu') !== false) {
  1930. $count_menglembu[] = $d;
  1931. }
  1932. if (strpos($d['address'], 'Ipoh') !== false) {
  1933. $count_ipoh[] = $d;
  1934. }
  1935. }
  1936. foreach ($dataJuly as $key => $d) {
  1937. if (strpos($d['address'], 'Cyberjaya') !== false) {
  1938. $count_cyberjaya[] = $d;
  1939. }
  1940. if (strpos($d['address'], 'Jasin') !== false) {
  1941. $count_jasin[] = $d;
  1942. }
  1943. if (strpos($d['address'], 'Ayer Keroh') !== false) {
  1944. $count_ayerKeroh[] = $d;
  1945. }
  1946. if (strpos($d['address'], 'Alor Gajah') !== false) {
  1947. $count_alorGajah[] = $d;
  1948. }
  1949. if (strpos($d['address'], 'Menglembu') !== false) {
  1950. $count_menglembu[] = $d;
  1951. }
  1952. if (strpos($d['address'], 'Ipoh') !== false) {
  1953. $count_ipoh[] = $d;
  1954. }
  1955. }
  1956. // Store to combineData New Incentives Cyberjaya
  1957. foreach ($count_cyberjaya as $key => $d) {
  1958. if(count($count_cyberjaya) > 50){
  1959. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1960. if($d['contract'] == '12'){
  1961. array_push($combineData, array(
  1962. 'index' => $d['index'],
  1963. 'contract' => $d['contract'],
  1964. 'wo' => $d['wo'],
  1965. 'activation' => $d['activation'],
  1966. 'name' => $d['name'],
  1967. 'address' => $d['address'],
  1968. 'package' => $d['package'],
  1969. 'retail_price' => $d['retail_price'],
  1970. 'incentives1' => $d['incentives1'],
  1971. 'incentives2' => $d['incentives2'],
  1972. 'total' => $d['total'],
  1973. 'claim' => $d['claim'],
  1974. ));
  1975. }else {
  1976. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  1977. array_push($combineData, array(
  1978. 'index' => $d['index'],
  1979. 'contract' => $d['contract'],
  1980. 'wo' => $d['wo'],
  1981. 'activation' => $d['activation'],
  1982. 'name' => $d['name'],
  1983. 'address' => $d['address'],
  1984. 'package' => $d['package'],
  1985. 'retail_price' => $d['retail_price'],
  1986. 'incentives1' => '230%',
  1987. 'incentives2' => $d['incentives2'],
  1988. 'total' => 'RM '.$total,
  1989. 'claim' => $d['claim'],
  1990. ));
  1991. }
  1992. }
  1993. }else if(count($count_cyberjaya) < 50){
  1994. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  1995. array_push($combineData, array(
  1996. 'index' => $d['index'],
  1997. 'contract' => $d['contract'],
  1998. 'wo' => $d['wo'],
  1999. 'activation' => $d['activation'],
  2000. 'name' => $d['name'],
  2001. 'address' => $d['address'],
  2002. 'package' => $d['package'],
  2003. 'retail_price' => $d['retail_price'],
  2004. 'incentives1' => $d['incentives1'],
  2005. 'incentives2' => $d['incentives2'],
  2006. 'total' => $d['total'],
  2007. 'claim' => $d['claim'],
  2008. ));
  2009. }
  2010. }
  2011. }
  2012. // Store to combineData New Incentives Menglembu
  2013. foreach ($count_menglembu as $key => $d) {
  2014. if(count($count_menglembu) > 50){
  2015. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2016. if($d['contract'] == '12'){
  2017. array_push($combineData, array(
  2018. 'index' => $d['index'],
  2019. 'contract' => $d['contract'],
  2020. 'wo' => $d['wo'],
  2021. 'activation' => $d['activation'],
  2022. 'name' => $d['name'],
  2023. 'address' => $d['address'],
  2024. 'package' => $d['package'],
  2025. 'retail_price' => $d['retail_price'],
  2026. 'incentives1' => $d['incentives1'],
  2027. 'incentives2' => $d['incentives2'],
  2028. 'total' => $d['total'],
  2029. 'claim' => $d['claim'],
  2030. ));
  2031. }else {
  2032. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2033. array_push($combineData, array(
  2034. 'index' => $d['index'],
  2035. 'contract' => $d['contract'],
  2036. 'wo' => $d['wo'],
  2037. 'activation' => $d['activation'],
  2038. 'name' => $d['name'],
  2039. 'address' => $d['address'],
  2040. 'package' => $d['package'],
  2041. 'retail_price' => $d['retail_price'],
  2042. 'incentives1' => '230%',
  2043. 'incentives2' => $d['incentives2'],
  2044. 'total' => 'RM '.$total,
  2045. 'claim' => $d['claim'],
  2046. ));
  2047. }
  2048. }
  2049. }else if(count($count_menglembu) < 50){
  2050. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2051. array_push($combineData, array(
  2052. 'index' => $d['index'],
  2053. 'contract' => $d['contract'],
  2054. 'wo' => $d['wo'],
  2055. 'activation' => $d['activation'],
  2056. 'name' => $d['name'],
  2057. 'address' => $d['address'],
  2058. 'package' => $d['package'],
  2059. 'retail_price' => $d['retail_price'],
  2060. 'incentives1' => $d['incentives1'],
  2061. 'incentives2' => $d['incentives2'],
  2062. 'total' => $d['total'],
  2063. 'claim' => $d['claim'],
  2064. ));
  2065. }
  2066. }
  2067. }
  2068. // Store to combineData New Incentives Ipoh
  2069. foreach ($count_ipoh as $key => $d) {
  2070. if(count($count_ipoh) > 50){
  2071. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2072. if($d['contract'] == '12'){
  2073. array_push($combineData, array(
  2074. 'index' => $d['index'],
  2075. 'contract' => $d['contract'],
  2076. 'wo' => $d['wo'],
  2077. 'activation' => $d['activation'],
  2078. 'name' => $d['name'],
  2079. 'address' => $d['address'],
  2080. 'package' => $d['package'],
  2081. 'retail_price' => $d['retail_price'],
  2082. 'incentives1' => $d['incentives1'],
  2083. 'incentives2' => $d['incentives2'],
  2084. 'total' => $d['total'],
  2085. 'claim' => $d['claim'],
  2086. ));
  2087. }else {
  2088. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2089. array_push($combineData, array(
  2090. 'index' => $d['index'],
  2091. 'contract' => $d['contract'],
  2092. 'wo' => $d['wo'],
  2093. 'activation' => $d['activation'],
  2094. 'name' => $d['name'],
  2095. 'address' => $d['address'],
  2096. 'package' => $d['package'],
  2097. 'retail_price' => $d['retail_price'],
  2098. 'incentives1' => '230%',
  2099. 'incentives2' => $d['incentives2'],
  2100. 'total' => 'RM '.$total,
  2101. 'claim' => $d['claim'],
  2102. ));
  2103. }
  2104. }
  2105. }else if(count($count_ipoh) < 50){
  2106. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2107. array_push($combineData, array(
  2108. 'index' => $d['index'],
  2109. 'contract' => $d['contract'],
  2110. 'wo' => $d['wo'],
  2111. 'activation' => $d['activation'],
  2112. 'name' => $d['name'],
  2113. 'address' => $d['address'],
  2114. 'package' => $d['package'],
  2115. 'retail_price' => $d['retail_price'],
  2116. 'incentives1' => $d['incentives1'],
  2117. 'incentives2' => $d['incentives2'],
  2118. 'total' => $d['total'],
  2119. 'claim' => $d['claim'],
  2120. ));
  2121. }
  2122. }
  2123. }
  2124. // Store to combineData New Incentives Ayer Keroh
  2125. foreach ($count_ayerKeroh as $key => $d) {
  2126. if(count($count_ayerKeroh) > 50){
  2127. if($d['contract'] == '12'){
  2128. array_push($combineData, array(
  2129. 'index' => $d['index'],
  2130. 'contract' => $d['contract'],
  2131. 'wo' => $d['wo'],
  2132. 'activation' => $d['activation'],
  2133. 'name' => $d['name'],
  2134. 'address' => $d['address'],
  2135. 'package' => $d['package'],
  2136. 'retail_price' => $d['retail_price'],
  2137. 'incentives1' => $d['incentives1'],
  2138. 'incentives2' => $d['incentives2'],
  2139. 'total' => $d['total'],
  2140. 'claim' => $d['claim'],
  2141. ));
  2142. }else {
  2143. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2144. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2145. array_push($combineData, array(
  2146. 'index' => $d['index'],
  2147. 'contract' => $d['contract'],
  2148. 'wo' => $d['wo'],
  2149. 'activation' => $d['activation'],
  2150. 'name' => $d['name'],
  2151. 'address' => $d['address'],
  2152. 'package' => $d['package'],
  2153. 'retail_price' => $d['retail_price'],
  2154. 'incentives1' => '230%',
  2155. 'incentives2' => $d['incentives2'],
  2156. 'total' => 'RM '.$total,
  2157. 'claim' => $d['claim'],
  2158. ));
  2159. }
  2160. }
  2161. }else if(count($count_ayerKeroh) < 50){
  2162. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2163. array_push($combineData, array(
  2164. 'index' => $d['index'],
  2165. 'contract' => $d['contract'],
  2166. 'wo' => $d['wo'],
  2167. 'activation' => $d['activation'],
  2168. 'name' => $d['name'],
  2169. 'address' => $d['address'],
  2170. 'package' => $d['package'],
  2171. 'retail_price' => $d['retail_price'],
  2172. 'incentives1' => $d['incentives1'],
  2173. 'incentives2' => $d['incentives2'],
  2174. 'total' => $d['total'],
  2175. 'claim' => $d['claim'],
  2176. ));
  2177. }
  2178. }
  2179. }
  2180. // Store to combineData New Incentives Alor Gajah
  2181. foreach ($count_alorGajah as $key => $d) {
  2182. if(count($count_alorGajah) > 50){
  2183. if($d['contract'] == '12'){
  2184. array_push($combineData, array(
  2185. 'index' => $d['index'],
  2186. 'contract' => $d['contract'],
  2187. 'wo' => $d['wo'],
  2188. 'activation' => $d['activation'],
  2189. 'name' => $d['name'],
  2190. 'address' => $d['address'],
  2191. 'package' => $d['package'],
  2192. 'retail_price' => $d['retail_price'],
  2193. 'incentives1' => $d['incentives1'],
  2194. 'incentives2' => $d['incentives2'],
  2195. 'total' => $d['total'],
  2196. 'claim' => $d['claim'],
  2197. ));
  2198. }else {
  2199. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2200. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2201. array_push($combineData, array(
  2202. 'index' => $d['index'],
  2203. 'contract' => $d['contract'],
  2204. 'wo' => $d['wo'],
  2205. 'activation' => $d['activation'],
  2206. 'name' => $d['name'],
  2207. 'address' => $d['address'],
  2208. 'package' => $d['package'],
  2209. 'retail_price' => $d['retail_price'],
  2210. 'incentives1' => '230%',
  2211. 'incentives2' => $d['incentives2'],
  2212. 'total' => 'RM '.$total,
  2213. 'claim' => $d['claim'],
  2214. ));
  2215. }
  2216. }
  2217. }else if(count($count_alorGajah) < 50){
  2218. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2219. array_push($combineData, array(
  2220. 'index' => $d['index'],
  2221. 'contract' => $d['contract'],
  2222. 'wo' => $d['wo'],
  2223. 'activation' => $d['activation'],
  2224. 'name' => $d['name'],
  2225. 'address' => $d['address'],
  2226. 'package' => $d['package'],
  2227. 'retail_price' => $d['retail_price'],
  2228. 'incentives1' => $d['incentives1'],
  2229. 'incentives2' => $d['incentives2'],
  2230. 'total' => $d['total'],
  2231. 'claim' => $d['claim'],
  2232. ));
  2233. }
  2234. }
  2235. }
  2236. // Store to combineData New Incentives Jasin
  2237. foreach ($count_jasin as $key => $d) {
  2238. if(count($count_jasin) > 20){
  2239. if($d['contract'] == '12'){
  2240. array_push($combineData, array(
  2241. 'index' => $d['index'],
  2242. 'contract' => $d['contract'],
  2243. 'wo' => $d['wo'],
  2244. 'activation' => $d['activation'],
  2245. 'name' => $d['name'],
  2246. 'address' => $d['address'],
  2247. 'package' => $d['package'],
  2248. 'retail_price' => $d['retail_price'],
  2249. 'incentives1' => $d['incentives1'],
  2250. 'incentives2' => $d['incentives2'],
  2251. 'total' => $d['total'],
  2252. 'claim' => $d['claim'],
  2253. ));
  2254. }else {
  2255. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2256. $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2257. array_push($combineData, array(
  2258. 'index' => $d['index'],
  2259. 'contract' => $d['contract'],
  2260. 'wo' => $d['wo'],
  2261. 'activation' => $d['activation'],
  2262. 'name' => $d['name'],
  2263. 'address' => $d['address'],
  2264. 'package' => $d['package'],
  2265. 'retail_price' => $d['retail_price'],
  2266. 'incentives1' => '230%',
  2267. 'incentives2' => $d['incentives2'],
  2268. 'total' => 'RM '.$total,
  2269. 'claim' => $d['claim'],
  2270. ));
  2271. }
  2272. }
  2273. }else if(count($count_jasin) < 20){
  2274. if(date('m/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2275. array_push($combineData, array(
  2276. 'index' => $d['index'],
  2277. 'contract' => $d['contract'],
  2278. 'wo' => $d['wo'],
  2279. 'activation' => $d['activation'],
  2280. 'name' => $d['name'],
  2281. 'address' => $d['address'],
  2282. 'package' => $d['package'],
  2283. 'retail_price' => $d['retail_price'],
  2284. 'incentives1' => $d['incentives1'],
  2285. 'incentives2' => $d['incentives2'],
  2286. 'total' => $d['total'],
  2287. 'claim' => $d['claim'],
  2288. ));
  2289. }
  2290. }
  2291. }
  2292. }
  2293. // $dataR = $this->returnDataR($company,$year,$month);
  2294. // foreach($dataR as $r){
  2295. // $combineData[] = $r;
  2296. // }
  2297. $dataB = $this->returnDataB($company,$year,$month);
  2298. foreach($dataB as $b){
  2299. $combineData[] = $b;
  2300. }
  2301. $i = 0;
  2302. $nested_data = array();
  2303. if(!empty($combineData)){
  2304. foreach ($combineData as $c){
  2305. $update_dealer = DealerClaim::where('wo',$c['wo'])->first();
  2306. if(!empty($update_dealer)){
  2307. $update_dealer->incentives1 = $c['incentives1'];
  2308. $update_dealer->incentives2 = $c['incentives2'];
  2309. $update_dealer->total_claim = $c['total'];
  2310. $update_dealer->save();
  2311. }
  2312. // $i++;
  2313. // array_push($final, array(
  2314. // 'index' => $c['index'],
  2315. // 'contract' => $c['contract'],
  2316. // 'wo' => $c['wo'],
  2317. // 'activated_dt' => $c['activation'],
  2318. // 'name' => $c['name'],
  2319. // 'address' => $c['address'],
  2320. // 'package' => $c['package'],
  2321. // 'retail_price' => $c['retail_price'],
  2322. // 'incentives1' => $c['incentives1'],
  2323. // 'incentives2' => $c['incentives2'],
  2324. // 'total' => $c['total'],
  2325. // 'claimed' => $c['claim'],
  2326. // ));
  2327. }
  2328. }
  2329. $dataClaim = DealerClaim::with(['Subscriber' => function($q) {
  2330. $q->with('Form');
  2331. }],'Staff')->where('dealer',$company)->where('activated_my',$month.'/'.$year)->get();
  2332. if(!empty($dataClaim)){
  2333. foreach ($dataClaim as $c){
  2334. $address = ''; $name = '';
  2335. if($c->Subscriber->Form->type_application == 'R'){
  2336. if($c->Subscriber->street != ''){
  2337. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  2338. }else {
  2339. $address = $c->Subscriber->unit_no. ' , '.$c->Subscriber->building_name. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  2340. }
  2341. $name = $c->Subscriber->name;
  2342. }else if($c->Subscriber->Form->type_application == 'B'){
  2343. if($c->Subscriber->unit_no != ''){
  2344. $address = $c->Subscriber->unit_no. ', '.$c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  2345. }else {
  2346. $address = $c->Subscriber->company_name. ', '.$c->Subscriber->street. ' , '.$c->Subscriber->postcode. ' , '.$c->Subscriber->city. ' , '.$c->Subscriber->state;
  2347. }
  2348. $name = $c->Subscriber->company_name;
  2349. }
  2350. $i++;
  2351. array_push($final, array(
  2352. 'index' => $c->formT,
  2353. 'contract' => $c->contract,
  2354. 'wo' => $c->wo,
  2355. 'activated_dt' => $c->activated_dt,
  2356. 'name' => $name,
  2357. 'address' => $address,
  2358. 'package' => $c->package,
  2359. 'retail_price' => 'RM '.$c->retail_price,
  2360. 'incentives1' => $c->incentives1,
  2361. 'incentives2' => $c->incentives2,
  2362. 'total' => $c->total_claim,
  2363. 'claimed' => $c->claim_dt,
  2364. ));
  2365. }
  2366. }
  2367. foreach($final as $f){
  2368. $basic_total += floatval(str_replace('RM ', '', $f['total']));
  2369. }
  2370. // Calculate extra incentves
  2371. // if($month == '1' && $year == '2020'){
  2372. // if(count($count_cyberjaya) > 50){
  2373. // $balance = count($count_cyberjaya) - 50;
  2374. // $extra += $balance * 50;
  2375. // }
  2376. // if(count($count_jasin) > 10){
  2377. // $balance = count($count_jasin) - 10;
  2378. // $extra += $balance * 50;
  2379. // }
  2380. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  2381. // if(count($count_cyberjaya) > 50){
  2382. // $balance = count($count_cyberjaya) - 50;
  2383. // $extra += $balance * 50;
  2384. // }
  2385. // if(count($count_jasin) > 20){
  2386. // $balance = count($count_jasin) - 10;
  2387. // $extra += $balance * 50;
  2388. // }
  2389. // }else {
  2390. // $extra = 0;
  2391. // }
  2392. $extra = 0;
  2393. $totals = $basic_total + $extra;
  2394. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  2395. // $pdf->setPaper('A4', 'landscape');
  2396. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  2397. // return $pdf->download( $pdfName );
  2398. return $final;
  2399. }
  2400. // else if($year!='null' && $month!='null' && $app!='null'){
  2401. // $count_cyberjaya = array(); $count_jasin = array();
  2402. // $extra = 0; $basic_total = 0; $totals = 0;
  2403. // if($app == 'Residential'){
  2404. // if(($year == '2019' || $year == '2020') && ($month == '12' || $month == '1')){
  2405. // $dataDis = $this->returnDataR($company,'2019','12');
  2406. // $dataJan = $this->returnDataR($company,'2020','1');
  2407. // foreach ($dataDis as $key => $d) {
  2408. // if(date('d/m/Y', strtotime($d['activation'])) >= '12/12/2019'){
  2409. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2410. // $count_cyberjaya[] = $d;
  2411. // }
  2412. // if (strpos($d['address'], 'Jasin') !== false) {
  2413. // $count_jasin[] = $d;
  2414. // }
  2415. // }else if(date('d/m/Y', strtotime($d['activation'])) >= '27/4/2020' && date('d/m/Y', strtotime($d['activation'])) <= '31/7/2020'){
  2416. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2417. // $count_cyberjaya[] = $d;
  2418. // }
  2419. // if (strpos($d['address'], 'Jasin') !== false) {
  2420. // $count_jasin[] = $d;
  2421. // }
  2422. // }else {
  2423. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2424. // $combineData[] = $d;
  2425. // }
  2426. // }
  2427. // }
  2428. // foreach ($dataJan as $key => $d) {
  2429. // if (strpos($d['address'], 'Cyberjaya') !== false) {
  2430. // $count_cyberjaya[] = $d;
  2431. // }
  2432. // if (strpos($d['address'], 'Jasin') !== false) {
  2433. // $count_jasin[] = $d;
  2434. // }
  2435. // }
  2436. // // Store to combineData New Incentives Cyberjaya
  2437. // foreach ($count_cyberjaya as $key => $d) {
  2438. // if(count($count_cyberjaya) > 50){
  2439. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2440. // if($d['contract'] == '12'){
  2441. // array_push($combineData, array(
  2442. // 'index' => $d['index'],
  2443. // 'contract' => $d['contract'],
  2444. // 'wo' => $d['wo'],
  2445. // 'activation' => $d['activation'],
  2446. // 'name' => $d['name'],
  2447. // 'address' => $d['address'],
  2448. // 'package' => $d['package'],
  2449. // 'retail_price' => $d['retail_price'],
  2450. // 'incentives1' => $d['incentives1'],
  2451. // 'incentives2' => $d['incentives2'],
  2452. // 'total' => $d['total'],
  2453. // 'claim' => $d['claim'],
  2454. // ));
  2455. // }else {
  2456. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2457. // array_push($combineData, array(
  2458. // 'index' => $d['index'],
  2459. // 'contract' => $d['contract'],
  2460. // 'wo' => $d['wo'],
  2461. // 'activation' => $d['activation'],
  2462. // 'name' => $d['name'],
  2463. // 'address' => $d['address'],
  2464. // 'package' => $d['package'],
  2465. // 'retail_price' => $d['retail_price'],
  2466. // 'incentives1' => '230%',
  2467. // 'incentives2' => $d['incentives2'],
  2468. // 'total' => 'RM '.$total,
  2469. // 'claim' => $d['claim'],
  2470. // ));
  2471. // }
  2472. // }
  2473. // }else if(count($count_cyberjaya) < 50){
  2474. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2475. // array_push($combineData, array(
  2476. // 'index' => $d['index'],
  2477. // 'contract' => $d['contract'],
  2478. // 'wo' => $d['wo'],
  2479. // 'activation' => $d['activation'],
  2480. // 'name' => $d['name'],
  2481. // 'address' => $d['address'],
  2482. // 'package' => $d['package'],
  2483. // 'retail_price' => $d['retail_price'],
  2484. // 'incentives1' => $d['incentives1'],
  2485. // 'incentives2' => $d['incentives2'],
  2486. // 'total' => $d['total'],
  2487. // 'claim' => $d['claim'],
  2488. // ));
  2489. // }
  2490. // }
  2491. // }
  2492. // // Store to combineData New Incentives Jasin
  2493. // foreach ($count_jasin as $key => $d) {
  2494. // if(count($count_jasin) > 10){
  2495. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2496. // $total = number_format(floatval(str_replace("RM ", "" , $d['retail_price'])) * 2.3, 2);
  2497. // array_push($combineData, array(
  2498. // 'index' => $d['index'],
  2499. // 'contract' => $d['contract'],
  2500. // 'wo' => $d['wo'],
  2501. // 'activation' => $d['activation'],
  2502. // 'name' => $d['name'],
  2503. // 'address' => $d['address'],
  2504. // 'package' => $d['package'],
  2505. // 'retail_price' => $d['retail_price'],
  2506. // 'incentives1' => '230%',
  2507. // 'incentives2' => $d['incentives2'],
  2508. // 'total' => 'RM '.$total,
  2509. // 'claim' => $d['claim'],
  2510. // ));
  2511. // }
  2512. // }else if(count($count_jasin) < 10){
  2513. // if(date('n/Y', strtotime($d['activation'])) == $month.'/'.$year){
  2514. // array_push($combineData, array(
  2515. // 'index' => $d['index'],
  2516. // 'contract' => $d['contract'],
  2517. // 'wo' => $d['wo'],
  2518. // 'activation' => $d['activation'],
  2519. // 'name' => $d['name'],
  2520. // 'address' => $d['address'],
  2521. // 'package' => $d['package'],
  2522. // 'retail_price' => $d['retail_price'],
  2523. // 'incentives1' => $d['incentives1'],
  2524. // 'incentives2' => $d['incentives2'],
  2525. // 'total' => $d['total'],
  2526. // 'claim' => $d['claim'],
  2527. // ));
  2528. // }
  2529. // }
  2530. // }
  2531. // }else {
  2532. // $dataR = $this->returnDataR($company,$year,$month);
  2533. // foreach($dataR as $r){
  2534. // $combineData[] = $r;
  2535. // }
  2536. // }
  2537. // }else if($app == 'Business'){
  2538. // $dataB = $this->returnDataB($company,$year,$month);
  2539. // }
  2540. // foreach($dataB as $b){
  2541. // $combineData[] = $b;
  2542. // }
  2543. // $i = 0;
  2544. // $nested_data = array();
  2545. // if(!empty($combineData)){
  2546. // foreach ($combineData as $c){
  2547. // $i++;
  2548. // array_push($final, array(
  2549. // 'index' => $c['index'],
  2550. // 'contract' => $c['contract'],
  2551. // 'wo' => $c['wo'],
  2552. // 'activated_dt' => $c['activation'],
  2553. // 'name' => $c['name'],
  2554. // 'address' => $c['address'],
  2555. // 'package' => $c['package'],
  2556. // 'retail_price' => $c['retail_price'],
  2557. // 'incentives1' => $c['incentives1'],
  2558. // 'incentives2' => $c['incentives2'],
  2559. // 'total' => $c['total'],
  2560. // 'claimed' => $c['claim'],
  2561. // ));
  2562. // }
  2563. // }
  2564. // foreach($final as $f){
  2565. // $basic_total += floatval(str_replace('RM ', '', $f['total']));
  2566. // }
  2567. // //Calculate extra incentves
  2568. // if($month == '1' && $year == '2020'){
  2569. // if(count($count_cyberjaya) > 50){
  2570. // $balance = count($count_cyberjaya) - 50;
  2571. // $extra += $balance * 50;
  2572. // }
  2573. // if(count($count_jasin) > 10){
  2574. // $balance = count($count_jasin) - 10;
  2575. // $extra += $balance * 50;
  2576. // }
  2577. // }else if(($month == '4' || $month == '5'|| $month == '6' || $month == '7') && $year == '2020'){
  2578. // if(count($count_cyberjaya) > 50){
  2579. // $balance = count($count_cyberjaya) - 50;
  2580. // $extra += $balance * 50;
  2581. // }
  2582. // if(count($count_jasin) > 20){
  2583. // $balance = count($count_jasin) - 10;
  2584. // $extra += $balance * 50;
  2585. // }
  2586. // }else {
  2587. // $extra = 0;
  2588. // }
  2589. // $totals = $basic_total + $extra;
  2590. // $pdf = PDF::loadView('pdf.agent-claim', compact('final', 'month', 'year','com','basic_total','extra','totals'));
  2591. // $pdf->setPaper('A4', 'landscape');
  2592. // $pdfName = preg_replace('/\s+/', '-', $com->name).'-'.$month.'-'.$year.'.pdf';
  2593. // return $pdf->download( $pdfName );
  2594. // }
  2595. }
  2596. public function update_total_claim(){
  2597. $dealer = DealerClaim::all();
  2598. foreach ($dealer as $key => $d) {
  2599. $claim = str_replace("RM ","",$d->total_claim);
  2600. $d->total_claim = floatval($claim);
  2601. $d->save();
  2602. }
  2603. }
  2604. }