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