Browse Source

[Administration] Factures & bons de livraisons > Liste : amélioration des filtres de recherche

feature/rotating_product
Guillaume Bourgeois 5 months ago
parent
commit
830f2be22d
2 changed files with 44 additions and 7 deletions
  1. +13
    -3
      backend/views/invoice/index.php
  2. +31
    -4
      domain/Document/Invoice/InvoiceSearch.php

+ 13
- 3
backend/views/invoice/index.php View File

[ [
'attribute' => 'date', 'attribute' => 'date',
'header' => 'Date', 'header' => 'Date',
'filter' => \yii\jui\DatePicker::widget([
'language' => 'fr',
'dateFormat' => 'dd/MM/yyyy',
'model' => $searchModel,
'attribute' => 'date',
'options' => ['class' => 'form-control']
]),
'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'],
[ [
'attribute' => 'paid', 'attribute' => 'paid',
'label' => 'Payée', 'label' => 'Payée',
/*'filter' => [
'filter' => [
0 => 'Non', 0 => 'Non',
1 => 'Oui', 1 => 'Oui',
],*/
'filter' => false,
],
'format' => 'raw', 'format' => 'raw',
'headerOptions' => ['class' => 'column-hide-on-mobile'], 'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'], 'filterOptions' => ['class' => 'column-hide-on-mobile'],
[ [
'attribute' => 'is_sent', 'attribute' => 'is_sent',
'header' => 'Envoyée', 'header' => 'Envoyée',
'filter' => [
0 => 'Non',
1 => 'Oui',
],
'format' => 'raw', 'format' => 'raw',
'headerOptions' => ['class' => 'column-hide-on-mobile'], 'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'], 'filterOptions' => ['class' => 'column-hide-on-mobile'],

+ 31
- 4
domain/Document/Invoice/InvoiceSearch.php View File



class InvoiceSearch extends Invoice class InvoiceSearch extends Invoice
{ {
var $paid;
var $paid = null;
var $username; var $username;


public function rules() public function rules()
{ {
return [ return [
[['paid'], 'safe'], [['paid'], 'safe'],
[['comment', 'address', 'status', 'username'], 'string'],
[['is_sent'], 'boolean'],
[['comment', 'address', 'status', 'username', 'date'], 'string'],
[['name', 'reference', 'username'], 'string', 'max' => 255], [['name', 'reference', 'username'], 'string', 'max' => 255],
]; ];
} }


public function search($params) public function search($params)
{ {
$invoiceRepository = InvoiceRepository::getInstance();
$invoiceModule = InvoiceModule::getInstance();
$invoiceRepository = $invoiceModule->getRepository();
$optionsSearch = $invoiceRepository->getDefaultOptionsSearch(); $optionsSearch = $invoiceRepository->getDefaultOptionsSearch();


$sort = new Sort([ $sort = new Sort([
$query->andFilterWhere(['like', 'invoice.name', $this->name]); $query->andFilterWhere(['like', 'invoice.name', $this->name]);
$query->andFilterWhere(['like', 'invoice.reference', $this->reference]); $query->andFilterWhere(['like', 'invoice.reference', $this->reference]);
$query->andFilterWhere(['like', 'invoice.status', $this->status]); $query->andFilterWhere(['like', 'invoice.status', $this->status]);

$query->andFilterWhere([ $query->andFilterWhere([
'or', 'or',
['like', 'user_invoice.lastname', $this->username], ['like', 'user_invoice.lastname', $this->username],
['like', 'user_invoice.name_legal_person', $this->username], ['like', 'user_invoice.name_legal_person', $this->username],
]); ]);


if ($this->date && strlen($this->date)) {
$query->andFilterWhere(['like', 'invoice.date', date('Y-m-d', strtotime(str_replace('/', '-', $this->date)))]);
}

if(!is_null($this->is_sent) && is_numeric($this->is_sent)) {
if($this->is_sent) {
$query->andWhere(['invoice.is_sent' => 1]);
}
else {
$query->andWhere('invoice.is_sent IS NULL OR invoice.is_sent = 0');
}
}

// filter payé / non payé
// @TODO : comprendre pourquoi la pagination ne suit pas
$models = $dataProvider->getModels();
foreach($models as $index => $product) {
if(!is_null($this->paid) && is_numeric($this->paid)) {
$isInvoicePaid = $invoiceModule->getSolver()->isInvoicePaid($product);
if(($this->paid && !$isInvoicePaid) || (!$this->paid && $isInvoicePaid)) {
unset($models[$index]);
}
}
}
$dataProvider->setModels($models);

return $dataProvider; return $dataProvider;
} }
} }

Loading…
Cancel
Save