Explorar el Código

[Administration] Documents > Bons de livraison & factures : correctif filtres 'facture' et 'payé'

feature/rotating_product
Guillaume Bourgeois hace 3 meses
padre
commit
985f879d8a
Se han modificado 4 ficheros con 69 adiciones y 29 borrados
  1. +2
    -2
      backend/views/invoice/index.php
  2. +35
    -0
      common/components/ActiveDataProvider.php
  3. +14
    -11
      domain/Document/DeliveryNote/DeliveryNoteSearch.php
  4. +18
    -16
      domain/Document/Invoice/InvoiceSearch.php

+ 2
- 2
backend/views/invoice/index.php Ver fichero

@@ -117,7 +117,7 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
}
],
[
'attribute' => 'paid',
'attribute' => 'is_paid',
'label' => 'Payée',
'filter' => [
0 => 'Non',
@@ -127,7 +127,7 @@ $this->addButton(['label' => 'Nouvelle facture <span class="glyphicon glyphicon-
'headerOptions' => ['class' => 'column-hide-on-mobile'],
'filterOptions' => ['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)) {
return '<span class="label label-success">Oui</span>';
}

+ 35
- 0
common/components/ActiveDataProvider.php Ver fichero

@@ -0,0 +1,35 @@
<?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);
}
}
}

+ 14
- 11
domain/Document/DeliveryNote/DeliveryNoteSearch.php Ver fichero

@@ -38,8 +38,8 @@

namespace domain\Document\DeliveryNote;

use common\components\ActiveDataProvider;
use common\helpers\GlobalParam;
use yii\data\ActiveDataProvider;

class DeliveryNoteSearch extends DeliveryNote
{
@@ -109,18 +109,21 @@ class DeliveryNoteSearch extends DeliveryNote
$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;
}

+ 18
- 16
domain/Document/Invoice/InvoiceSearch.php Ver fichero

@@ -38,20 +38,20 @@

namespace domain\Document\Invoice;

use common\components\ActiveDataProvider;
use common\helpers\GlobalParam;
use yii\data\ActiveDataProvider;
use yii\data\Sort;

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

public function rules()
{
return [
[['paid'], 'safe'],
[['is_sent'], 'boolean'],
[[], 'safe'],
[['is_sent', 'is_paid'], 'boolean'],
[['comment', 'address', 'status', 'username', 'date'], 'string'],
[['name', 'reference', 'username'], 'string', 'max' => 255],
];
@@ -84,7 +84,6 @@ class InvoiceSearch extends Invoice
->with($optionsSearch['with'])
->joinWith($optionsSearch['join_with'])
->where(['invoice.id_producer' => GlobalParam::getCurrentProducerId()])
//->orderBy('invoice.status ASC, invoice.reference DESC')
->orderBy($sort->orders)
->groupBy('invoice.id');

@@ -116,7 +115,7 @@ class InvoiceSearch extends Invoice
}

// filtre envoyé
if(!is_null($this->is_sent) && is_numeric($this->is_sent)) {
if(is_numeric($this->is_sent)) {
if($this->is_sent) {
$query->andWhere(['invoice.is_sent' => 1]);
}
@@ -125,18 +124,21 @@ class InvoiceSearch extends Invoice
}
}

// 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;
}

Cargando…
Cancelar
Guardar