} | } | ||||
], | ], | ||||
[ | [ | ||||
'attribute' => 'paid', | |||||
'attribute' => 'is_paid', | |||||
'label' => 'Payée', | 'label' => 'Payée', | ||||
'filter' => [ | 'filter' => [ | ||||
0 => 'Non', | 0 => 'Non', | ||||
'headerOptions' => ['class' => 'column-hide-on-mobile'], | 'headerOptions' => ['class' => 'column-hide-on-mobile'], | ||||
'filterOptions' => ['class' => 'column-hide-on-mobile'], | 'filterOptions' => ['class' => 'column-hide-on-mobile'], | ||||
'contentOptions' => ['class' => 'column-hide-on-mobile'], | 'contentOptions' => ['class' => 'column-hide-on-mobile'], | ||||
'value' => function ($invoice) use ( $invoiceModule) { | |||||
'value' => function ($invoice) use ($invoiceModule) { | |||||
if($invoiceModule->isInvoicePaid($invoice)) { | if($invoiceModule->isInvoicePaid($invoice)) { | ||||
return '<span class="label label-success">Oui</span>'; | return '<span class="label label-success">Oui</span>'; | ||||
} | } |
<?php | |||||
namespace common\components; | |||||
class ActiveDataProvider extends \yii\data\ActiveDataProvider | |||||
{ | |||||
public function filterByCallback($callback) | |||||
{ | |||||
$filtered_models = $filtered_keys = []; | |||||
// la pagination ne fonctionne pas avec ce système de filtre : solution alternative sans pagination | |||||
// @TODO : faire en sorte que la pagination fonctionne avec les filtres par callback | |||||
$this->pagination = false; | |||||
$have_been_filtered = false; | |||||
$this->prepare(true); // force read of next page | |||||
$non_filtered_models = $this->getModels(); | |||||
foreach($non_filtered_models as $model) { | |||||
$filterModel = $callback($model); | |||||
if($filterModel) { | |||||
$have_been_filtered = true; | |||||
$this->setTotalCount($this->getTotalCount() - 1); | |||||
} | |||||
else { | |||||
$filtered_models[] = $model; | |||||
$filtered_keys[] = $model->id; | |||||
} | |||||
} | |||||
if($have_been_filtered) { | |||||
$this->setModels($filtered_models); | |||||
$this->setKeys($filtered_keys); | |||||
} | |||||
} | |||||
} |
namespace domain\Document\DeliveryNote; | namespace domain\Document\DeliveryNote; | ||||
use common\components\ActiveDataProvider; | |||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use yii\data\ActiveDataProvider; | |||||
class DeliveryNoteSearch extends DeliveryNote | class DeliveryNoteSearch extends DeliveryNote | ||||
{ | { | ||||
$query->andFilterWhere(['like', 'distribution.date', date('Y-m-d', strtotime(str_replace('/', '-', $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]); | |||||
// 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; | |||||
}); | |||||
} | } | ||||
$dataProvider->setModels($models); | |||||
return $dataProvider; | return $dataProvider; | ||||
} | } |
namespace domain\Document\Invoice; | namespace domain\Document\Invoice; | ||||
use common\components\ActiveDataProvider; | |||||
use common\helpers\GlobalParam; | use common\helpers\GlobalParam; | ||||
use yii\data\ActiveDataProvider; | |||||
use yii\data\Sort; | use yii\data\Sort; | ||||
class InvoiceSearch extends Invoice | class InvoiceSearch extends Invoice | ||||
{ | { | ||||
var $paid = null; | |||||
var $is_paid; | |||||
var $username; | var $username; | ||||
public function rules() | public function rules() | ||||
{ | { | ||||
return [ | return [ | ||||
[['paid'], 'safe'], | |||||
[['is_sent'], 'boolean'], | |||||
[[], 'safe'], | |||||
[['is_sent', 'is_paid'], 'boolean'], | |||||
[['comment', 'address', 'status', 'username', 'date'], 'string'], | [['comment', 'address', 'status', 'username', 'date'], 'string'], | ||||
[['name', 'reference', 'username'], 'string', 'max' => 255], | [['name', 'reference', 'username'], 'string', 'max' => 255], | ||||
]; | ]; | ||||
->with($optionsSearch['with']) | ->with($optionsSearch['with']) | ||||
->joinWith($optionsSearch['join_with']) | ->joinWith($optionsSearch['join_with']) | ||||
->where(['invoice.id_producer' => GlobalParam::getCurrentProducerId()]) | ->where(['invoice.id_producer' => GlobalParam::getCurrentProducerId()]) | ||||
//->orderBy('invoice.status ASC, invoice.reference DESC') | |||||
->orderBy($sort->orders) | ->orderBy($sort->orders) | ||||
->groupBy('invoice.id'); | ->groupBy('invoice.id'); | ||||
} | } | ||||
// filtre envoyé | // filtre envoyé | ||||
if(!is_null($this->is_sent) && is_numeric($this->is_sent)) { | |||||
if(is_numeric($this->is_sent)) { | |||||
if($this->is_sent) { | if($this->is_sent) { | ||||
$query->andWhere(['invoice.is_sent' => 1]); | $query->andWhere(['invoice.is_sent' => 1]); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
// filter payé / non payé | |||||
// @TODO : comprendre pourquoi la pagination ne suit pas | |||||
$models = $dataProvider->getModels(); | |||||
foreach($models as $index => $invoice) { | |||||
if(!is_null($this->paid) && is_numeric($this->paid)) { | |||||
$isInvoicePaid = $invoiceModule->getSolver()->isInvoicePaid($invoice); | |||||
if(($this->paid && !$isInvoicePaid) || (!$this->paid && $isInvoicePaid)) { | |||||
unset($models[$index]); | |||||
// filtre payé / non payé | |||||
$isPaid = $this->is_paid; | |||||
if(is_numeric($isPaid)) { | |||||
$dataProvider->filterByCallback(function($model) use ($isPaid) { | |||||
$filterModel = false; | |||||
$invoiceModule = InvoiceModule::getInstance(); | |||||
if(is_numeric($isPaid)) { | |||||
$isInvoicePaid = $invoiceModule->getSolver()->isInvoicePaid($model); | |||||
if(($isPaid && !$isInvoicePaid) || (!$isPaid && $isInvoicePaid)) { | |||||
$filterModel = true; | |||||
} | |||||
} | } | ||||
} | |||||
return $filterModel; | |||||
}); | |||||
} | } | ||||
$dataProvider->setModels($models); | |||||
return $dataProvider; | return $dataProvider; | ||||
} | } |