255], ]; } public function search($params) { $deliveryNoteModule = DeliveryNoteModule::getInstance(); $deliveryNoteRepository = $deliveryNoteModule->getRepository(); $optionsSearch = $deliveryNoteRepository->getDefaultOptionsSearch(); if(isset($params['DeliveryNoteSearch']['id_point_sale'])) { $optionsSearch['join_with'][] = 'orders'; } $query = DeliveryNote::find() ->with($optionsSearch['with']) ->joinWith($optionsSearch['join_with']) ->where(['delivery_note.id_producer' => GlobalParam::getCurrentProducerId()]) ->orderBy('delivery_note.status ASC, delivery_note.reference DESC') ->groupBy('delivery_note.id'); $dataProvider = new ActiveDataProvider([ 'query' => $query, 'sort' => ['attributes' => ['name', 'reference', 'date']], 'pagination' => [ 'pageSize' => 20, ], ]); $this->load($params); if (!$this->validate()) { return $dataProvider; } $query->andFilterWhere(['like', 'delivery_note.name', $this->name]); $query->andFilterWhere(['like', 'delivery_note.reference', $this->reference]); $query->andFilterWhere(['like', 'delivery_note.status', $this->status]); if ($this->id_point_sale) { $query->andWhere(['order.id_point_sale' => $this->id_point_sale]); } if(!is_null($this->is_sent) && is_numeric($this->is_sent)) { if($this->is_sent) { $query->andWhere(['delivery_note.is_sent' => 1]); } else { $query->andWhere('delivery_note.is_sent IS NULL OR delivery_note.is_sent = 0'); } } if ($this->date_distribution && strlen($this->date_distribution)) { $query->andFilterWhere(['like', 'distribution.date', date('Y-m-d', strtotime(str_replace('/', '-', $this->date_distribution)))]); } // filtre avec ou sans facture $withInvoice = $this->with_invoice; if(is_numeric($withInvoice)) { $dataProvider->filterByCallback(function($model) use ($withInvoice) { $deliveryNoteModule = DeliveryNoteModule::getInstance(); $filterModel = false; if(is_numeric($withInvoice)) { $invoice = $deliveryNoteModule->getSolver()->getInvoice($model); if(($withInvoice && !$invoice) || (!$withInvoice && $invoice)) { $filterModel = true; } } return $filterModel; }); } return $dataProvider; } }