|
1 | 1 | <?php |
2 | 2 | /** |
3 | 3 | * This file is part of Modelo347 plugin for FacturaScripts |
4 | | - * Copyright (C) 2020-2025 Carlos Garcia Gomez <carlos@facturascripts.com> |
| 4 | + * Copyright (C) 2020-2026 Carlos Garcia Gomez <carlos@facturascripts.com> |
5 | 5 | * |
6 | 6 | * This program is free software: you can redistribute it and/or modify |
7 | 7 | * it under the terms of the GNU Lesser General Public License as |
|
20 | 20 | namespace FacturaScripts\Plugins\Modelo347\Controller; |
21 | 21 |
|
22 | 22 | use FacturaScripts\Core\Base\Controller; |
23 | | -use FacturaScripts\Core\Base\DataBase\DataBaseWhere; |
24 | 23 | use FacturaScripts\Core\DataSrc\Ejercicios; |
25 | 24 | use FacturaScripts\Core\DataSrc\Empresas; |
26 | 25 | use FacturaScripts\Core\Tools; |
| 26 | +use FacturaScripts\Core\Where; |
27 | 27 | use FacturaScripts\Dinamic\Lib\Export\XLSExport; |
28 | 28 | use FacturaScripts\Dinamic\Model\Cliente; |
29 | 29 | use FacturaScripts\Dinamic\Model\Cuenta; |
@@ -252,29 +252,25 @@ protected function downloadTxtAction(): void |
252 | 252 | $this->loadCustomersData(); |
253 | 253 | $this->loadSuppliersData(); |
254 | 254 |
|
255 | | - // creamos el archivo txt |
256 | | - $exportFile = FS_FOLDER . '/MyFiles/modelo_347_' . $this->codejercicio . '.347'; |
257 | | - if (false === file_put_contents($exportFile, Txt347Export::export($this->codejercicio, $this->customersData, $this->suppliersData))) { |
258 | | - Tools::log()->error('cant-save-file', ['%fileName%' => $exportFile]); |
259 | | - return; |
260 | | - } |
261 | | - |
262 | | - // descargamos el archivo |
263 | | - $this->response->headers->set('Content-Type', 'text/plain; charset=ISO-8859-1'); |
264 | | - $this->response->headers->set('Content-Disposition', 'attachment; filename="' . basename($exportFile) . '"'); |
265 | | - $this->response->headers->set('Pragma', 'no-cache'); |
266 | | - $this->response->headers->set('Expires', '0'); |
267 | | - $this->response->setContent(file_get_contents($exportFile)); |
268 | | - |
269 | | - // eliminamos el archivo |
270 | | - unlink($exportFile); |
| 255 | + // generamos el contenido del archivo |
| 256 | + $fileName = 'modelo_347_' . $this->codejercicio . '.347'; |
| 257 | + $content = Txt347Export::export($this->codejercicio, $this->customersData, $this->suppliersData); |
| 258 | + |
| 259 | + // devolvemos el archivo directamente |
| 260 | + $this->response |
| 261 | + ->header('Content-Type', 'text/plain; charset=ISO-8859-1') |
| 262 | + ->header('Content-Disposition', 'attachment; filename="' . $fileName . '"') |
| 263 | + ->header('Pragma', 'no-cache') |
| 264 | + ->header('Expires', '0') |
| 265 | + ->setContent($content); |
271 | 266 | } |
272 | 267 |
|
273 | 268 | protected function getAccountingInfo(Cuenta $cuenta, string $column): array |
274 | 269 | { |
275 | 270 | $ejercicio = Ejercicios::get($this->codejercicio); |
276 | 271 |
|
277 | | - if (strtolower(FS_DB_TYPE) == 'postgresql') { |
| 272 | + $dbType = Tools::config('db_type'); |
| 273 | + if (strtolower($dbType) == 'postgresql') { |
278 | 274 | $sql = "select idsubcuenta, codsubcuenta, to_char(fecha,'FMMM') as mes, sum(" . $column . ") as total from partidas p, asientos a" |
279 | 275 | . " where idsubcuenta IN (select idsubcuenta from subcuentas where idcuenta = " . $this->dataBase->var2str($cuenta->idcuenta) . ")" |
280 | 276 | . " and p.idasiento = a.idasiento" |
@@ -314,15 +310,15 @@ protected function getCustomersDataAccounting(): array |
314 | 310 | // buscamos las cuentas especiales de clientes de este ejercicio |
315 | 311 | $cuentaModel = new Cuenta(); |
316 | 312 | $where = [ |
317 | | - new DataBaseWhere('codejercicio', $this->codejercicio), |
318 | | - new DataBaseWhere('codcuentaesp', 'CLIENT') |
| 313 | + Where::eq('codejercicio', $this->codejercicio), |
| 314 | + Where::eq('codcuentaesp', 'CLIENT'), |
319 | 315 | ]; |
320 | 316 | foreach ($cuentaModel->all($where, [], 0, 0) as $cuenta) { |
321 | 317 | // buscamos las partidas de las subcuentas de esta cuenta |
322 | 318 | foreach ($this->getAccountingInfo($cuenta, 'debe') as $row) { |
323 | 319 | // buscamos el cliente de la subcuenta |
324 | 320 | $cliente = new Cliente(); |
325 | | - $where = [new DataBaseWhere('codsubcuenta', $row['codsubcuenta'])]; |
| 321 | + $where = [Where::eq('codsubcuenta', $row['codsubcuenta'])]; |
326 | 322 | if (false === $cliente->loadWhere($where)) { |
327 | 323 | // no se ha encontrado el cliente, saltamos |
328 | 324 | continue; |
@@ -448,15 +444,15 @@ protected function getSuppliersDataAccounting(): array |
448 | 444 | // buscamos las cuentas especiales de proveedores de este ejercicio |
449 | 445 | $cuentaModel = new Cuenta(); |
450 | 446 | $where = [ |
451 | | - new DataBaseWhere('codejercicio', $this->codejercicio), |
452 | | - new DataBaseWhere('codcuentaesp', 'PROVEE,ACREED', 'IN') |
| 447 | + Where::eq('codejercicio', $this->codejercicio), |
| 448 | + Where::in('codcuentaesp', ['PROVEE', 'ACREED']), |
453 | 449 | ]; |
454 | 450 | foreach ($cuentaModel->all($where, [], 0, 0) as $cuenta) { |
455 | 451 | // consultamos las partidas de cada subcuenta hija |
456 | 452 | foreach ($this->getAccountingInfo($cuenta, 'haber') as $row) { |
457 | 453 | // buscamos el proveedor de la subcuenta |
458 | 454 | $proveedor = new Proveedor(); |
459 | | - $where = [new DataBaseWhere('codsubcuenta', $row['codsubcuenta'])]; |
| 455 | + $where = [Where::eq('codsubcuenta', $row['codsubcuenta'])]; |
460 | 456 | if (false === $proveedor->loadWhere($where)) { |
461 | 457 | // no existe, saltamos |
462 | 458 | continue; |
|
0 commit comments