Skip to content

Commit ceb8507

Browse files
committed
Add invoice tabs
1 parent acb863e commit ceb8507

1 file changed

Lines changed: 90 additions & 4 deletions

File tree

Controller/EditRegularizacionImpuesto.php

Lines changed: 90 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,15 @@
2020

2121
use Exception;
2222
use FacturaScripts\Core\Base\DataBase\DataBaseWhere;
23+
use FacturaScripts\Core\DataSrc\Impuestos;
24+
use FacturaScripts\Core\DataSrc\Series;
2325
use FacturaScripts\Core\Lib\ExtendedController\BaseView;
2426
use FacturaScripts\Core\Lib\ExtendedController\EditController;
27+
use FacturaScripts\Core\Lib\SubAccountTools;
2528
use FacturaScripts\Core\Tools;
2629
use FacturaScripts\Dinamic\Model\RegularizacionImpuesto;
2730
use FacturaScripts\Dinamic\Lib\Accounting\VatRegularizationToAccounting;
28-
use FacturaScripts\Dinamic\Lib\Modelo303;
31+
use FacturaScripts\Plugins\Modelo303\Lib\Modelo303;
2932

3033
/**
3134
* Controller to list the items in the RegularizacionImpuesto model
@@ -60,6 +63,11 @@ public function getPageData(): array
6063
return $data;
6164
}
6265

66+
/**
67+
* Create accounting entry action procedure.
68+
*
69+
* @return void
70+
*/
6371
protected function createAccountingEntryAction(): void
6472
{
6573
$reg = new RegularizacionImpuesto();
@@ -100,6 +108,8 @@ protected function createViews(): void
100108

101109
$this->createViewsTaxSummary();
102110
$this->createViewsTaxDetail();
111+
$this->createViewsTaxLine('ListPartidaImpuesto-1', 'purchases', 'fas fa-sign-in-alt');
112+
$this->createViewsTaxLine('ListPartidaImpuesto-2', 'sales', 'fas fa-sign-out-alt');
103113
$this->createViewsEntryLine();
104114
}
105115

@@ -124,7 +134,26 @@ protected function createViewsEntryLine(string $viewName = 'ListPartida'): void
124134
protected function createViewsTaxDetail(string $viewName = 'ListPartidaImpuestoResumen'): void
125135
{
126136
$this->addListView($viewName, 'Join\PartidaImpuestoResumen', 'tax-detail');
127-
$this->disableButtons($viewName, true);
137+
$this->disableButtons($viewName, false);
138+
}
139+
140+
/**
141+
* Add invoices view for tax lines.
142+
*
143+
* @param string $viewName
144+
* @param string $caption
145+
* @param string $icon
146+
* @return void
147+
*/
148+
protected function createViewsTaxLine(string $viewName, string $caption, string $icon): void
149+
{
150+
$this->addListView($viewName, 'Join\PartidaImpuesto', $caption, $icon)
151+
->addSearchFields(['partidas.concepto'])
152+
->addFilterPeriod('date', 'date', 'fecha')
153+
->addFilterSelect('iva', 'vat', 'partidas.iva', Impuestos::codeModel())
154+
->addFilterSelect('codserie', 'serie', 'partidas.codserie', Series::codeModel());
155+
156+
$this->disableButtons($viewName);
128157
}
129158

130159
/**
@@ -207,6 +236,14 @@ protected function loadData($viewName, $view): void
207236
case 'ListPartida':
208237
$this->getListPartida($view);
209238
break;
239+
240+
case 'ListPartidaImpuesto-1':
241+
$this->getListPartidaImpuesto($view, SubAccountTools::SPECIAL_GROUP_TAX_INPUT);
242+
break;
243+
244+
case 'ListPartidaImpuesto-2':
245+
$this->getListPartidaImpuesto($view, SubAccountTools::SPECIAL_GROUP_TAX_OUTPUT);
246+
break;
210247
}
211248
}
212249

@@ -222,7 +259,8 @@ private function disableButtons(string $viewName, bool $clickable = false): void
222259
$this->setSettings($viewName, 'btnDelete', false)
223260
->setSettings('btnNew', false)
224261
->setSettings('checkBoxes', false)
225-
->setSettings('clickable', $clickable);
262+
->setSettings('clickable', $clickable)
263+
->setSettings('btnPrint', true);
226264
}
227265

228266
/**
@@ -239,6 +277,54 @@ private function getListPartida(BaseView $view): void
239277
}
240278
}
241279

280+
/**
281+
* Load data into invoices view for tax lines.
282+
*
283+
* @param BaseView $view
284+
* @param int $group
285+
* @return void
286+
*/
287+
private function getListPartidaImpuesto(BaseView $view, int $group): void
288+
{
289+
$id = $this->getModel()->idregiva;
290+
if (empty($id)) {
291+
return;
292+
}
293+
294+
$where = $this->getPartidaImpuestoWhere($group);
295+
$orderBy = ['asientos.fecha' => 'ASC', 'partidas.codserie' => 'ASC', 'partidas.factura' => 'ASC'];
296+
$view->loadData(false, $where, $orderBy);
297+
}
298+
299+
/**
300+
* Get DataBaseWhere filter for tax group
301+
*
302+
* @param int $group
303+
* @return DataBaseWhere[]
304+
*/
305+
private function getPartidaImpuestoWhere(int $group): array
306+
{
307+
// obtenemos todos los ids de los asientos de las regularizaciones
308+
$ids = [];
309+
foreach (RegularizacionImpuesto::all() as $reg) {
310+
if ($reg->idasiento) {
311+
$ids[] = $reg->idasiento;
312+
}
313+
}
314+
315+
$subAccountTools = new SubAccountTools();
316+
return [
317+
new DataBaseWhere('asientos.idasiento', implode(',', $ids), 'NOT IN'),
318+
new DataBaseWhere('asientos.codejercicio', $this->getModel()->codejercicio),
319+
new DataBaseWhere('asientos.fecha', $this->getModel()->fechainicio, '>='),
320+
new DataBaseWhere('asientos.fecha', $this->getModel()->fechafin, '<='),
321+
new DataBaseWhere('COALESCE(series.siniva, 0)', 0),
322+
new DataBaseWhere('partidas.baseimponible', 0, '!='),
323+
new DataBaseWhere('COALESCE(partidas.iva, 0)', 0, '>', 'OR'),
324+
$subAccountTools->whereForSpecialAccounts('COALESCE(subcuentas.codcuentaesp, cuentas.codcuentaesp)', $group)
325+
];
326+
}
327+
242328
/**
243329
* Settings for main view.
244330
*
@@ -262,4 +348,4 @@ private function settingsMainView(): void
262348
]);
263349
}
264350
}
265-
}
351+
}

0 commit comments

Comments
 (0)