Browse Source

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

feature/rotating_product
Guillaume Bourgeois 6 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

@@ -92,6 +92,13 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
[
'attribute' => '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'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
'contentOptions' => ['class' => 'column-hide-on-mobile'],
@@ -110,11 +117,10 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
[
'attribute' => 'paid',
'label' => 'Payée',
/*'filter' => [
'filter' => [
0 => 'Non',
1 => 'Oui',
],*/
'filter' => false,
],
'format' => 'raw',
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],
@@ -130,6 +136,10 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
[
'attribute' => 'is_sent',
'header' => 'Envoyée',
'filter' => [
0 => 'Non',
1 => 'Oui',
],
'format' => 'raw',
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['class' => 'column-hide-on-mobile'],

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

@@ -44,21 +44,23 @@ use yii\data\Sort;

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

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

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

$sort = new Sort([
@@ -102,7 +104,6 @@ class InvoiceSearch extends Invoice
$query->andFilterWhere(['like', 'invoice.name', $this->name]);
$query->andFilterWhere(['like', 'invoice.reference', $this->reference]);
$query->andFilterWhere(['like', 'invoice.status', $this->status]);

$query->andFilterWhere([
'or',
['like', 'user_invoice.lastname', $this->username],
@@ -110,6 +111,32 @@ class InvoiceSearch extends Invoice
['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;
}
}

Loading…
Cancel
Save