loustwo 4 лет назад
Родитель
Сommit
1dd5ef7d09
1 измененных файлов с 81 добавлено и 0 удалено
  1. 81 0
      app/Filters/ReceivingTaskFilters.php

+ 81 - 0
app/Filters/ReceivingTaskFilters.php

@@ -0,0 +1,81 @@
+<?php
+
+
+namespace App\Filters;
+
+use App\DeliveryAppointmentCar;
+use App\Traits\ModelSearchWay;
+use Illuminate\Database\Eloquent\Builder;
+use Illuminate\Http\Request;
+
+class ReceivingTaskFilters{
+    use ModelSearchWay;
+
+
+    protected $request;
+    protected $queryBuilder;
+    protected $deliveryAppointmentCarQuery;
+    protected $receiving;
+    protected $filters = [
+        'id','owner_id','warehouse_id','appointment_number','created_at_start','created_at_end','number'
+    ];
+    protected $params = [];
+
+    public function __construct(Request $request)
+    {
+        $this->request = $request;
+        $this->params = $request->all();
+    }
+
+    public function apply($builder)
+    {
+        $this->queryBuilder = $builder;
+        $filters = array_filter($this->request->only($this->filters));
+
+        foreach ($filters as $filter => $value) {
+            if (method_exists($this, $filter)) {
+                $this->$filter($value, $this->queryBuilder);
+            }
+        }
+        return $this->queryBuilder;
+    }
+
+    public function getDeliveryAppointmentCarQuery(): Builder
+    {
+        if (!$this->deliveryAppointmentCarQuery){
+            $this->deliveryAppointmentCarQuery = DeliveryAppointmentCar::query()->select('id');
+        }
+        return $this->deliveryAppointmentCarQuery;
+    }
+
+    public function id($ids){
+        $this->searchWay($this->queryBuilder,$ids,'id');
+    }
+
+    public function owner_id($owner_id){
+        $this->searchWay($this->queryBuilder,$owner_id,'owner_id');
+    }
+
+    public function warehouse_id($warehouse_id){
+        $this->searchWay($this->queryBuilder,$warehouse_id,'warehouse_id');
+    }
+
+    public function appointment_number($appointment_number){
+        $this->searchWay($this->getDeliveryAppointmentCarQuery(),$appointment_number,'appointment_number');
+    }
+
+    public function number($number){
+        $this->searchWay($this->queryBuilder,$number,'number');
+    }
+
+    public function created_at_start($created_at_start){
+        $this->queryBuilder->where('created_at','>=',$created_at_start." 00:00:00");
+    }
+
+    public function created_at_end($created_at_end){
+        $this->queryBuilder->where('created_at','<=',$created_at_end." 23:59:59");
+    }
+
+
+
+}