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