-
Notifications
You must be signed in to change notification settings - Fork 286
Tarea #2144 - Añadir filtros al agrupar documentos. #1339
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 8 commits
968c89a
bdbfc4a
cb046d9
89f048c
9b9606b
e1d42be
d9a8d70
81d7a4d
8d30f83
6339c1b
fddc975
90c4d37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,10 +22,13 @@ | |
| use FacturaScripts\Core\Base\Controller; | ||
| use FacturaScripts\Core\Base\ControllerPermissions; | ||
| use FacturaScripts\Core\Base\DataBase\DataBaseWhere; | ||
| use FacturaScripts\Core\DataSrc\FormasPago; | ||
| use FacturaScripts\Core\Model\Base\BusinessDocumentLine; | ||
| use FacturaScripts\Core\Model\Base\TransformerDocument; | ||
| use FacturaScripts\Core\Tools; | ||
| use FacturaScripts\Dinamic\Lib\BusinessDocumentGenerator; | ||
| use FacturaScripts\Dinamic\Lib\ListFilter\PeriodFilter; | ||
| use FacturaScripts\Dinamic\Lib\ListFilter\SelectFilter; | ||
| use FacturaScripts\Dinamic\Model\CodeModel; | ||
| use FacturaScripts\Dinamic\Model\EstadoDocumento; | ||
| use FacturaScripts\Dinamic\Model\User; | ||
|
|
@@ -36,6 +39,7 @@ | |
| * | ||
| * @author Carlos García Gómez <carlos@facturascripts.com> | ||
| * @author Francesc Pineda Segarra <francesc.pineda.segarra@gmail.com> | ||
| * @author Daniel Fernández Giménez <hola@danielfg.es> | ||
| */ | ||
| class DocumentStitcher extends Controller | ||
| { | ||
|
|
@@ -47,12 +51,18 @@ class DocumentStitcher extends Controller | |
| /** @var TransformerDocument[] */ | ||
| public $documents = []; | ||
|
|
||
| /** @var array */ | ||
| public $filters = []; | ||
|
|
||
| /** @var string */ | ||
| public $modelName; | ||
|
|
||
| /** @var TransformerDocument[] */ | ||
| public $moreDocuments = []; | ||
|
|
||
| /** @var array */ | ||
| public $where = []; | ||
|
|
||
| public function getAvailableStatus(): array | ||
| { | ||
| $status = []; | ||
|
|
@@ -94,6 +104,7 @@ public function getSeries(): array | |
| public function privateCore(&$response, $user, $permissions) | ||
| { | ||
| parent::privateCore($response, $user, $permissions); | ||
| $action = $this->request->request->get('action', ''); | ||
|
|
||
| $this->codes = $this->getCodes(); | ||
| $this->modelName = $this->getModelName(); | ||
|
|
@@ -105,6 +116,11 @@ public function privateCore(&$response, $user, $permissions) | |
| } | ||
|
|
||
| $this->loadDocuments(); | ||
| $this->addFilters(); | ||
| if ('search' === $action) { | ||
daniel89fg marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $this->processFormDataLoad(); | ||
| } | ||
|
|
||
| $this->loadMoreDocuments(); | ||
|
|
||
| $statusCode = $this->request->request->get('status', ''); | ||
|
|
@@ -124,6 +140,16 @@ public function privateCore(&$response, $user, $permissions) | |
| } | ||
| } | ||
|
|
||
| protected function addFilters() | ||
| { | ||
| $payMethods = FormasPago::codeModel(true, $this->documents[0]->idempresa); | ||
| if (count($payMethods) > 2) { | ||
| $this->filters['codpago'] = new SelectFilter('codpago', 'codpago', 'payment-method', $payMethods); | ||
daniel89fg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| $this->filters['fecha'] = new PeriodFilter('fecha', 'fecha', 'date'); | ||
| } | ||
|
|
||
| /** | ||
| * @param array $newLines | ||
| * @param TransformerDocument $doc | ||
|
|
@@ -175,6 +201,7 @@ protected function addInfoLine(array &$newLines, $doc): void | |
| 'mostrar_cantidad' => false, | ||
| 'mostrar_precio' => false | ||
| ]); | ||
|
|
||
| $this->pipe('addInfoLine', $infoLine); | ||
| $newLines[] = $infoLine; | ||
| } | ||
|
|
@@ -408,21 +435,30 @@ protected function loadMoreDocuments(): void | |
|
|
||
| $modelClass = self::MODEL_NAMESPACE . $this->modelName; | ||
| $model = new $modelClass(); | ||
| $where = [ | ||
| new DataBaseWhere('codalmacen', $this->documents[0]->codalmacen), | ||
| new DataBaseWhere('coddivisa', $this->documents[0]->coddivisa), | ||
| new DataBaseWhere('codserie', $this->documents[0]->codserie), | ||
| new DataBaseWhere('dtopor1', $this->documents[0]->dtopor1), | ||
| new DataBaseWhere('dtopor2', $this->documents[0]->dtopor2), | ||
| new DataBaseWhere('editable', true), | ||
| new DataBaseWhere('idempresa', $this->documents[0]->idempresa), | ||
| new DataBaseWhere($model->subjectColumn(), $this->documents[0]->subjectColumnValue()) | ||
| ]; | ||
| $this->where[] = new DataBaseWhere('codalmacen', $this->documents[0]->codalmacen); | ||
| $this->where[] = new DataBaseWhere('coddivisa', $this->documents[0]->coddivisa); | ||
| $this->where[] = new DataBaseWhere('codserie', $this->documents[0]->codserie); | ||
| $this->where[] = new DataBaseWhere('dtopor1', $this->documents[0]->dtopor1); | ||
| $this->where[] = new DataBaseWhere('dtopor2', $this->documents[0]->dtopor2); | ||
| $this->where[] = new DataBaseWhere('editable', true); | ||
| $this->where[] = new DataBaseWhere('idempresa', $this->documents[0]->idempresa); | ||
| $this->where[] = new DataBaseWhere($model->subjectColumn(), $this->documents[0]->subjectColumnValue()); | ||
| $orderBy = ['fecha' => 'ASC', 'hora' => 'ASC']; | ||
| foreach ($model->all($where, $orderBy, 0, 0) as $doc) { | ||
| foreach ($model->all($this->where, $orderBy, 0, 0) as $doc) { | ||
| if (false === in_array($doc->primaryColumnValue(), $this->getCodes())) { | ||
| $this->moreDocuments[] = $doc; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| protected function processFormDataLoad() | ||
| { | ||
| // filters | ||
| foreach ($this->filters as $filter) { | ||
| $filter->setValueFromRequest($this->request); | ||
| if ($filter->getDataBaseWhere($this->where)) { | ||
| $this->showFilters = true; | ||
|
||
| } | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -118,24 +118,48 @@ | |||||||||
| </div> | ||||||||||
| </form> | ||||||||||
|
|
||||||||||
| {% if fsc.moreDocuments %} | ||||||||||
| {% if fsc.moreDocuments or fsc.showFilters is same as(true) %} | ||||||||||
| <div class="container-fluid"> | ||||||||||
| <div class="row"> | ||||||||||
| <div class="col mt-3"> | ||||||||||
| <form action="{{ fsc.url() }}" method="post" onsubmit="animateSpinner('add')"> | ||||||||||
| {{ formToken() }} | ||||||||||
| <input type="hidden" name="model" value="{{ fsc.modelName }}"> | ||||||||||
| <input type="hidden" name="codes" value="{{ fsc.codes | join(',') }}"> | ||||||||||
| <div class="card border-success shadow mb-2"> | ||||||||||
| <div class="card-body p-2"> | ||||||||||
| <button class="btn btn-spin-action btn-sm btn-outline-success" type="button" | ||||||||||
| data-toggle="collapse" data-target="#moreDocsCollapse" aria-expanded="false"> | ||||||||||
| <i class="fas fa-plus-square fa-fw" aria-hidden="true"></i> | ||||||||||
| {{ trans('more') }} | ||||||||||
| </button> | ||||||||||
| {{ trans('group-more-docs-p') }} | ||||||||||
| <div class="card border-success shadow mb-2"> | ||||||||||
| <div class="card-body p-2"> | ||||||||||
| <button class="btn btn-sm btn-outline-success" type="button" data-toggle="collapse" | ||||||||||
| data-target="#moreDocsCollapse" aria-expanded="{{ fsc.showFilters is same as(true) ? 'true' : 'false' }}"> | ||||||||||
|
||||||||||
| <button class="btn btn-sm btn-outline-success" type="button" data-toggle="collapse" | |
| data-target="#moreDocsCollapse" aria-expanded="{{ fsc.showFilters is same as(true) ? 'true' : 'false' }}"> | |
| <button class="btn btn-sm btn-outline-success" type="button" data-bs-toggle="collapse" | |
| data-bs-target="#moreDocsCollapse" aria-expanded="{{ fsc.showFilters is same as(true) ? 'true' : 'false' }}"> |
daniel89fg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
daniel89fg marked this conversation as resolved.
Show resolved
Hide resolved
daniel89fg marked this conversation as resolved.
Show resolved
Hide resolved
daniel89fg marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
Copilot
AI
Feb 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new forms for search (line 136) and add (line 159) are missing CSRF protection tokens. These forms should include the formToken() call to prevent CSRF attacks, similar to the main form on line 25. Add {{ formToken() }} after each form opening tag.
Uh oh!
There was an error while loading. Please reload this page.