| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252 |
- <?php
-
- namespace App\Http\Controllers\v3\Api;
-
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Carbon\Carbon;
-
- use App\LatestModel\Staff;
- use App\LatestModel\StaffDetail;
- use App\LatestModel\Dealer;
- use App\LatestModel\DealerDetail;
- use App\LatestModel\Module\Form;
- use App\LatestModel\Module\FormStatus;
- use App\LatestModel\Module\Subscriber;
- use App\LatestModel\Module\WorkOrder;
- use App\LatestModel\Module\Docket;
- use App\LatestModel\Module\PackageDetail;
- use App\LatestModel\Module\Company;
- use App\LatestModel\Module\Coverage;
- use App\LatestModel\Module\Product;
-
- use App\Http\Resources\FormResource;
-
- class FormResourceController extends BaseController
- {
- /**
- * @var ServiceCategory
- */
- protected $form;
-
- /**
- * ServiceController constructor.
- *
- * @param ServiceCategory $ServiceCategory
- */
- public function __construct(Form $form)
- {
- $this->form = $form;
- }
-
- public function filterByTypeADate($type, $startdate, $enddate){
-
- if($type == 'All' && $startdate == ''){
- $form = Form::where('type_service', '!=', '');
- return $form;
- }else if($type == 'All' && $startdate != ''){
-
- $dateS = Carbon::createFromFormat('Y-m-d', $startdate);
- $start = $dateS->copy()->startOfDay();
-
- $dateE = Carbon::createFromFormat('Y-m-d', $enddate);
- $end = $dateE->copy()->endOfDay();
-
- $form = Form::whereBetween('created_at', array($start, $end));
- return $form;
-
- }else if($type != 'All' && $startdate == ''){
- $form = Form::where('type_service', $type);
- return $form;
- }else if($type != 'All' && $startdate != ''){
-
- $dateS = Carbon::createFromFormat('Y-m-d', $startdate);
- $start = $dateS->copy()->startOfDay();
-
- $dateE = Carbon::createFromFormat('Y-m-d', $enddate);
- $end = $dateE->copy()->endOfDay();
-
- $form = Form::where('type_service', $type)->whereBetween('created_at', array($start, $end));
- return $form;
-
- }
- }
-
- public function filterByPackage($type, $startdate, $enddate, $application){
- $form = $this->filterByTypeADate($type, $startdate, $enddate);
- if($application == 'All'){
- return $form;
- }else{
- $form = $form->where('type_application', $application);
- return $form;
- }
- }
-
- public function filterByCompany($type, $startdate, $enddate, $application, $company){
- $form = $this->filterByPackage($type, $startdate, $enddate, $application);
- if($company == 'All'){
- return $form;
- }else{
- $form = $form->where('company_id', $company);
- return $form;
- }
- }
-
- public function filterBySubscriber($type, $startdate, $enddate, $application, $company, $subcriber){
- $form = $this->filterByCompany($type, $startdate, $enddate, $application, $company);
- $form = $form->with(['Subscriber' => function($q) use($subcriber){
- $q->where('subscriber_id', 'LIKE', $subcriber);
- }],'PackageDetail','WorkOrder');
- return $form;
- }
-
- public function filterByName($type, $startdate, $enddate, $application, $company, $name){
- $form = $this->filterByCompany($type, $startdate, $enddate, $application, $company);
- $form = $form->with(['Subscriber' => function($q) use($name){
- $q->where('name', 'LIKE', "%{$name}%")->orWhere('company_name', 'LIKE', "%{$name}%");
- }],'PackageDetail','WorkOrder');
- return $form;
- }
-
- public function filterByUnit($type, $startdate, $enddate, $application, $company, $unit){
- $form = $this->filterByCompany($type, $startdate, $enddate, $application, $company);
- $form = $form->with(['Subscriber' => function($q) use($unit){
- $q->where('unit_no', $unit);
- }],'PackageDetail','WorkOrder');
- return $form;
- }
-
- public function filterByBuilding($type, $startdate, $enddate, $application, $company, $building){
- $form = $this->filterByCompany($type, $startdate, $enddate, $application, $company);
- $form = $form->with(['Subscriber' => function($q) use($building){
- $q->where('building_name', $building);
- }],'PackageDetail','WorkOrder');
- return $form;
- }
-
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index(Request $request)
- {
- $type = $request->fbtype;
- $application = $request->fbpackage;
- $company = $request->fbdealer;
-
- $startdate = $request->startdate;
- $enddate = $request->enddate;
-
- $subcriber = $request->subcriber_id;
- $name = $request->name;
- $unit = $request->unit_no;
- $building = $request->building;
-
- $status = $request->status;
-
- $nested_data = array();
-
- if($subcriber != '') {
- $form = $this->filterBySubscriber($type, $startdate, $enddate, $application, $company, $subcriber);
- $form = $form->orderBy('created_at','ASC')->get();
- }else if($name == ''){
- $form = $this->filterByName($type, $startdate, $enddate, $application, $company, $name);
- $form = $form->orderBy('created_at','ASC')->get();
- }else if($unit == ''){
- $form = $this->filterByUnit($type, $startdate, $enddate, $application, $company, $unit);
- $form = $form->orderBy('created_at','ASC')->get();
- }else if($building == ''){
- $form = $this->filterByBuilding($type, $startdate, $enddate, $application, $company, $building);
- $form = $form->orderBy('created_at','ASC')->get();
- }else{
- $form = $this->filterByCompany($type, $startdate, $enddate, $application, $company);
- $form = $form->with('Subscriber','PackageDetail','WorkOrder')->orderBy('created_at','ASC')->get();
- }
-
- if($status == 'new'){
- foreach ($form as $key => $f) {
- if(!empty($f->Subscriber) && !empty($f->PackageDetail) && empty($f->WorkOrder)){
- $nested_data[] = $f;
- }
- }
- }
-
- // return $compound;
- return \DataTables::of($nested_data)->addIndexColumn()
- ->addColumn('index', function($row) {
- $curr = Carbon::now();
- $dtC = Carbon::parse($row['created_at'])->setTimezone('Asia/Kuala_Lumpur');
- if($curr->diffInDays($dtC) <= 3){
- $html = 'New';
- }else{ $html = ''; }
- return $html;
- })->rawColumns(['index'])->make(true);
- }
-
- /**
- * Show the form for creating a new resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function create()
- {
- //
- }
-
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(Request $request)
- {
- //
- }
-
- /**
- * Display the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function show($id)
- {
- //
- }
-
- /**
- * Show the form for editing the specified resource.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function edit($id)
- {
- //
- }
-
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function update(Request $request, $id)
- {
- //
- }
-
- /**
- * Remove the specified resource from storage.
- *
- * @param int $id
- * @return \Illuminate\Http\Response
- */
- public function destroy($id)
- {
- //
- }
- }
|