|
|
@@ -0,0 +1,94 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+
|
|
|
+namespace App\Filters;
|
|
|
+
|
|
|
+use App\Order;
|
|
|
+use Illuminate\Http\Request;
|
|
|
+use phpDocumentor\Reflection\Types\Boolean;
|
|
|
+
|
|
|
+class OrderPackageFilters
|
|
|
+{
|
|
|
+ protected $request;
|
|
|
+ protected $queryBuilder;
|
|
|
+ protected $filters = ['logistic_number', 'status', 'received_at_start',
|
|
|
+ 'received_at_end', 'is_weighed', 'logistic_id', 'owner_id', 'sent_at_start', 'sent_at_end', 'is_exception'];
|
|
|
+
|
|
|
+ public function __construct(Request $request)
|
|
|
+ {
|
|
|
+ $this->request = $request;
|
|
|
+ }
|
|
|
+
|
|
|
+ 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;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private function logistic_number($logistic_number)
|
|
|
+ {
|
|
|
+ $this->queryBuilder->where('logistic_number', $logistic_number);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function status($status)
|
|
|
+ {
|
|
|
+ $this->queryBuilder->where('status', $status);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function received_at_start($received_at_start)
|
|
|
+ {
|
|
|
+ $this->queryBuilder->where('received_at', '>=', $received_at_start);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function received_at_end($received_at_end)
|
|
|
+ {
|
|
|
+ $this->queryBuilder->where('received_at', '<=', $received_at_end);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function is_weighed($is_weighed)
|
|
|
+ {
|
|
|
+ if ($is_weighed == 'true') {
|
|
|
+ $this->queryBuilder->whereNotNull('weighed_at');
|
|
|
+ } else {
|
|
|
+ $this->queryBuilder->whereNull('weighed_at');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private function logistic_id($logistic_id)
|
|
|
+ {
|
|
|
+ $logistic_ids = array_filter(preg_split('/[,, ]+/is', $logistic_id));
|
|
|
+ $this->queryBuilder->whereIn('order_id',function($query)use($logistic_ids){
|
|
|
+ $query->from('orders')->select('id')->whereIn('logistic_id',$logistic_ids);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private function owner_id($owner_id)
|
|
|
+ {
|
|
|
+ $owner_ids = array_filter(preg_split('/[,, ]+/is', $owner_id));
|
|
|
+ $this->queryBuilder->whereIn('order_id',function($query)use($owner_ids){
|
|
|
+ $query->from('orders')->select('id')->whereIn('owner_id',$owner_ids);
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sent_at_start($sent_at_start)
|
|
|
+ {
|
|
|
+ $this->queryBuilder->where('sent_at', '>=', $sent_at_start);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function sent_at_end($sent_at_end)
|
|
|
+ {
|
|
|
+ $this->queryBuilder->where('sent_at', '<=', $sent_at_end);
|
|
|
+ }
|
|
|
+
|
|
|
+ private function is_exception($is_exception)
|
|
|
+ {
|
|
|
+ $this->queryBuilder->where('exception', $is_exception);
|
|
|
+ }
|
|
|
+}
|