joenilson /
fsRepublicaDominicana
| 1 | <?php |
||
| 2 | /* |
||
| 3 | * Copyright (C) 2019 joenilson. |
||
| 4 | * |
||
| 5 | * This library is free software; you can redistribute it and/or |
||
| 6 | * modify it under the terms of the GNU Lesser General Public |
||
| 7 | * License as published by the Free Software Foundation; either |
||
| 8 | * version 3 of the License, or (at your option) any later version. |
||
| 9 | * |
||
| 10 | * This library is distributed in the hope that it will be useful, |
||
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
||
| 13 | * Lesser General Public License for more details. |
||
| 14 | * |
||
| 15 | * You should have received a copy of the GNU Lesser General Public |
||
| 16 | * License along with this library; if not, write to the Free Software |
||
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
||
| 18 | * MA 02110-1301 USA |
||
| 19 | */ |
||
| 20 | |||
| 21 | namespace FacturaScripts\Plugins\fsRepublicaDominicana\Controller; |
||
| 22 | |||
| 23 | use FacturaScripts\Core\Base\DataBase\DataBaseWhere; |
||
|
0 ignored issues
–
show
|
|||
| 24 | use FacturaScripts\Core\Base\MyFilesToken; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Core\Base\MyFilesToken was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 25 | use FacturaScripts\Core\DataSrc\Almacenes; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Core\DataSrc\Almacenes was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 26 | use FacturaScripts\Core\Lib\ExtendedController\BaseView; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Core\Lib\...ndedController\BaseView was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 27 | use FacturaScripts\Core\Lib\ExtendedController\ListController; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Core\Lib\...ntroller\ListController was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 28 | use FacturaScripts\Core\Lib\ListFilter\PeriodTools; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Core\Lib\ListFilter\PeriodTools was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 29 | use FacturaScripts\Core\Tools; |
||
| 30 | |||
| 31 | use FacturaScripts\Dinamic\Model\LineaFacturaCliente; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Dinamic\Model\LineaFacturaCliente was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||
| 32 | use FacturaScripts\Plugins\fsRepublicaDominicana\Lib\CommonFunctionsDominicanRepublic; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Description of FiscalReports |
||
| 36 | * |
||
| 37 | * @author joenilson |
||
| 38 | */ |
||
| 39 | class FiscalReports extends ListController |
||
| 40 | { |
||
| 41 | /** |
||
| 42 | * @return array |
||
| 43 | */ |
||
| 44 | public function getPageData(): array |
||
| 45 | { |
||
| 46 | $data = parent::getPageData(); |
||
| 47 | $data['menu'] = 'reports'; |
||
| 48 | $data['submenu'] = 'dominican-republic'; |
||
| 49 | $data['icon'] = 'fa-solid fa-hand-holding-usd'; |
||
| 50 | $data['title'] = 'rd-fiscal-reports'; |
||
| 51 | return $data; |
||
| 52 | } |
||
| 53 | |||
| 54 | protected function createViews(): void |
||
| 55 | { |
||
| 56 | // needed dependencies |
||
| 57 | new LineaFacturaCliente(); |
||
| 58 | $this->createViewsFiscalReportsConsolidated(); |
||
| 59 | $this->createViewsFiscalReports606(); |
||
| 60 | $this->createViewsFiscalReports607(); |
||
| 61 | $this->createViewsFiscalReports608(); |
||
| 62 | $this->exportManager::addOption('dgii', 'txt-export', 'fa-solid fa-file-alt'); |
||
| 63 | } |
||
| 64 | |||
| 65 | public function execAfterAction($action) |
||
| 66 | { |
||
| 67 | parent::execAfterAction($action); |
||
| 68 | $periodStartDate = \date('Y-m-01'); |
||
| 69 | $periodEndDate = \date('Y-m-d'); |
||
| 70 | if ($this->request->request->get('filterfecha') !== null) { |
||
| 71 | PeriodTools::applyPeriod($this->request->request->get('filterfecha'), $periodStartDate, $periodEndDate); |
||
| 72 | } |
||
| 73 | $startDate = (($this->request->request->get('filterstartfecha') !== null) === true) |
||
| 74 | ? $this->request->request->get('filterstartfecha') |
||
| 75 | : $periodStartDate; |
||
| 76 | $endDate = (($this->request->request->get('filterstartfecha') !== null) === true) |
||
| 77 | ? $this->request->request->get('filterendfecha') |
||
| 78 | : $periodEndDate; |
||
| 79 | |||
| 80 | $commonFunctions = new CommonFunctionsDominicanRepublic(); |
||
| 81 | |||
| 82 | [$year, $month] = $commonFunctions->checkDateFormat($startDate); |
||
| 83 | |||
| 84 | $option = $this->request->get('option'); |
||
| 85 | $actualTab = $this->request->get('activetab'); |
||
| 86 | switch ($actualTab) { |
||
| 87 | case "FiscalReport606": |
||
| 88 | $whereReport = [ |
||
| 89 | new DataBaseWhere('facturasprov.fecha', $startDate, '>='), |
||
| 90 | new DataBaseWhere('facturasprov.fecha', $endDate, '<='), |
||
| 91 | ]; |
||
| 92 | $reportCode = 606; |
||
| 93 | break; |
||
| 94 | case "FiscalReport607": |
||
| 95 | $whereReport = [ |
||
| 96 | new DataBaseWhere('facturascli.fecha', $startDate, '>='), |
||
| 97 | new DataBaseWhere('facturascli.fecha', $endDate, '<='), |
||
| 98 | ]; |
||
| 99 | $reportCode = 607; |
||
| 100 | break; |
||
| 101 | case "FiscalReport608": |
||
| 102 | $whereReport = [ |
||
| 103 | new DataBaseWhere('facturascli.fecha', $startDate, '>='), |
||
| 104 | new DataBaseWhere('facturascli.fecha', $endDate, '<='), |
||
| 105 | ]; |
||
| 106 | $reportCode = 608; |
||
| 107 | break; |
||
| 108 | default: |
||
| 109 | $whereReport = [ |
||
| 110 | new DataBaseWhere('facturascli.fecha', $startDate, '>='), |
||
| 111 | new DataBaseWhere('facturascli.fecha', $endDate, '<='), |
||
| 112 | ]; |
||
| 113 | $reportCode = ''; |
||
| 114 | break; |
||
| 115 | } |
||
| 116 | if ($action === 'export' && $option === 'dgii' && $reportCode !== '') { |
||
| 117 | $this->setTemplate(false); |
||
| 118 | $fileName = 'MyFiles/DGII_F_'.$reportCode.'_'.$this->empresa->cifnif.'_'.$year.'_'.$month.'.TXT'; |
||
| 119 | $commonFunctions->exportTXT($reportCode, $fileName, $this->empresa->cifnif, $year, $month, $whereReport); |
||
| 120 | $this->response->headers->set('Content-type', 'text/plain'); |
||
| 121 | $this->response->headers->set('Content-Disposition', 'attachment;filename=' . $fileName); |
||
| 122 | $this->response->setContent( |
||
| 123 | file_get_contents( |
||
| 124 | \FS_FOLDER |
||
|
0 ignored issues
–
show
|
|||
| 125 | . DIRECTORY_SEPARATOR |
||
| 126 | . $fileName |
||
| 127 | // . '?myft=' |
||
| 128 | // . MyFilesToken::get( |
||
| 129 | // $fileName, |
||
| 130 | // false, |
||
| 131 | // \date('Y-m-d', strtotime('+1 days')) |
||
| 132 | // ) |
||
| 133 | ) |
||
| 134 | ); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | /** |
||
| 139 | * @param string $viewName |
||
| 140 | */ |
||
| 141 | protected function createViewsFiscalReportsConsolidated(string $viewName = 'FiscalReports-consolidated') |
||
| 142 | { |
||
| 143 | $this->addView( |
||
| 144 | $viewName, |
||
| 145 | 'Join\FiscalReports', |
||
| 146 | 'rd-fiscal-reports-consolidated', |
||
| 147 | 'fa-solid fa-shipping-fast' |
||
| 148 | ); |
||
| 149 | $this->addOrderBy($viewName, ['ncf'], 'ncf'); |
||
| 150 | $this->addFilterPeriod($viewName, 'fecha', 'date', 'facturascli.fecha'); |
||
| 151 | $this->addCommonSearchFields($viewName); |
||
| 152 | $this->disableButtons($viewName); |
||
| 153 | } |
||
| 154 | |||
| 155 | /** |
||
| 156 | * @param string $viewName |
||
| 157 | */ |
||
| 158 | protected function createViewsFiscalReports608(string $viewName = 'FiscalReport608') |
||
| 159 | { |
||
| 160 | $this->addView( |
||
| 161 | $viewName, |
||
| 162 | 'Join\FiscalReport608', |
||
| 163 | 'rd-fiscal-reports-608', |
||
| 164 | 'fa-solid fa-shopping-cart' |
||
| 165 | ); |
||
| 166 | $this->addFilterPeriod($viewName, 'fecha', 'date', 'facturascli.fecha'); |
||
| 167 | $this->addCommonSearchFields($viewName); |
||
| 168 | $this->disableButtons($viewName); |
||
| 169 | } |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @param string $viewName |
||
| 173 | */ |
||
| 174 | protected function createViewsFiscalReports607(string $viewName = 'FiscalReport607') |
||
| 175 | { |
||
| 176 | $this->addView($viewName, 'Join\FiscalReport607', 'rd-fiscal-reports-607', 'fa-solid fa-copy'); |
||
| 177 | $this->addFilterPeriod($viewName, 'fecha', 'date', 'facturascli.fecha'); |
||
| 178 | $this->addCommonSearchFields($viewName); |
||
| 179 | $this->disableButtons($viewName); |
||
| 180 | } |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @param string $viewName |
||
| 184 | */ |
||
| 185 | protected function createViewsFiscalReports606(string $viewName = 'FiscalReport606') |
||
| 186 | { |
||
| 187 | $this->addView($viewName, 'Join\FiscalReport606', 'rd-fiscal-reports-606', 'fa-solid fa-copy'); |
||
| 188 | $this->addFilterPeriod($viewName, 'fecha', 'date', 'facturasprov.fecha'); |
||
| 189 | $this->addSearchFields($viewName, ['numero2', 'cifnif', 'fecha', 'estado'], 'fecha'); |
||
| 190 | $this->addOrderBy($viewName, ['facturasprov.fecha'], 'fecha'); |
||
| 191 | $this->addOrderBy($viewName, ['facturasprov.numproveedor'], 'ncf'); |
||
| 192 | $this->addOrderBy($viewName, ['cifnif'], 'cifnif'); |
||
| 193 | $this->disableButtons($viewName); |
||
| 194 | } |
||
| 195 | |||
| 196 | /** |
||
| 197 | * @param string $viewName |
||
| 198 | */ |
||
| 199 | private function addCommonSearchFields(string $viewName) |
||
| 200 | { |
||
| 201 | $this->addSearchFields($viewName, ['numero2', 'cifnif', 'fecha', 'estado'], 'fecha'); |
||
| 202 | $this->addOrderBy($viewName, ['facturascli.fecha'], 'fecha'); |
||
| 203 | $this->addOrderBy($viewName, ['facturascli.numero2'], 'ncf'); |
||
| 204 | $this->addOrderBy($viewName, ['cifnif'], 'cifnif'); |
||
| 205 | } |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @param string $viewName |
||
| 209 | */ |
||
| 210 | private function disableButtons(string $viewName) |
||
| 211 | { |
||
| 212 | $this->setSettings($viewName, 'btnDelete', false); |
||
| 213 | $this->setSettings($viewName, 'btnNew', false); |
||
| 214 | $this->setSettings($viewName, 'checkBoxes', false); |
||
| 215 | $this->setSettings($viewName, 'clickable', false); |
||
| 216 | } |
||
| 217 | |||
| 218 | /** |
||
| 219 | * |
||
| 220 | * @param string $viewName |
||
| 221 | * @param BaseView $view |
||
| 222 | */ |
||
| 223 | protected function loadData($viewName, $view) |
||
| 224 | { |
||
| 225 | $periodStartDate = \date('Y-m-01'); |
||
| 226 | $periodEndDate = \date('Y-m-d'); |
||
| 227 | PeriodTools::applyPeriod('last-month', $periodStartDate, $periodEndDate); |
||
| 228 | if (in_array($this->request->request->get('filterfecha'), ['',null], true) === false) { |
||
| 229 | PeriodTools::applyPeriod($this->request->request->get('filterfecha'), $periodStartDate, $periodEndDate); |
||
| 230 | } else { |
||
| 231 | $periodStartDate = $this->request->request->get('filterstartfecha') ?? $periodStartDate; |
||
| 232 | $periodEndDate = $this->request->request->get('filterendfecha') ?? $periodEndDate; |
||
| 233 | } |
||
| 234 | switch ($viewName) { |
||
| 235 | case 'FiscalReport606': |
||
| 236 | $where = [ |
||
| 237 | new DataBaseWhere('facturasprov.fecha', $periodStartDate, '>='), |
||
| 238 | new DataBaseWhere('facturasprov.fecha', $periodEndDate, '<='), |
||
| 239 | ]; |
||
| 240 | $view->loadData('', $where); |
||
| 241 | break; |
||
| 242 | case 'FiscalReport607': |
||
| 243 | case 'FiscalReport608': |
||
| 244 | case 'FiscalReports-consolidated': |
||
| 245 | $where = [ |
||
| 246 | new DataBaseWhere('facturascli.fecha', $periodStartDate, '>='), |
||
| 247 | new DataBaseWhere('facturascli.fecha', $periodEndDate, '<='), |
||
| 248 | ]; |
||
| 249 | $view->loadData('', $where); |
||
| 250 | break; |
||
| 251 | default: |
||
| 252 | parent::loadData($viewName, $view); |
||
| 253 | break; |
||
| 254 | } |
||
| 255 | } |
||
| 256 | } |
||
| 257 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths