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 facture (oui / non) $models = $dataProvider->getModels(); foreach($models as $index => $deliveryNote) { if(!is_null($this->with_invoice) && is_numeric($this->with_invoice)) { $invoice = $deliveryNoteModule->getSolver()->getInvoice($deliveryNote); if(($this->with_invoice && !$invoice) || (!$this->with_invoice && $invoice)) { unset($models[$index]); } } } $dataProvider->setModels($models); return $dataProvider; } }