| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- <?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);
- }
- }
- $this->afterApply();
- return $this->queryBuilder;
- }
- public function getDeliveryAppointmentCarQuery(): Builder
- {
- if (!$this->deliveryAppointmentCarQuery){
- $this->deliveryAppointmentCarQuery = DeliveryAppointmentCar::query()->select('id');
- }
- return $this->deliveryAppointmentCarQuery;
- }
- public function afterApply(){
- if ($this->deliveryAppointmentCarQuery){
- $this->queryBuilder->whereIn('delivery_appointment_car_id',$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");
- }
- }
|