joenilson /
fsRepublicaDominicana
| 1 | <?php |
||
| 2 | /* |
||
| 3 | * Copyright (C) 2023-2024 Joe Nilson <[email protected]> |
||
| 4 | * |
||
| 5 | * This program is free software: you can redistribute it and/or modify |
||
| 6 | * it under the terms of the GNU Lesser General Public License as |
||
| 7 | * published by the Free Software Foundation, either version 3 of the |
||
| 8 | * License, or (at your option) any later version. |
||
| 9 | * |
||
| 10 | * This program 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 |
||
| 13 | * GNU Lesser General Public License for more details. |
||
| 14 | * You should have received a copy of the GNU Lesser General Public License |
||
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
||
| 16 | */ |
||
| 17 | |||
| 18 | namespace FacturaScripts\Plugins\fsRepublicaDominicana\Lib\Tickets; |
||
| 19 | |||
| 20 | use FacturaScripts\Core\Template\ModelClass; |
||
|
0 ignored issues
–
show
|
|||
| 21 | use FacturaScripts\Core\Tools; |
||
| 22 | use FacturaScripts\Dinamic\Lib\Tickets\BaseTicket; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Dinamic\Lib\Tickets\BaseTicket 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...
|
|||
| 23 | use FacturaScripts\Dinamic\Model\Agente; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Dinamic\Model\Agente 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...
|
|||
| 24 | use FacturaScripts\Dinamic\Model\Ticket; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Dinamic\Model\Ticket 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\Dinamic\Model\TicketPrinter; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Dinamic\Model\TicketPrinter 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\Dinamic\Model\User; |
||
|
0 ignored issues
–
show
The type
FacturaScripts\Dinamic\Model\User 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 Mike42\Escpos\Printer; |
||
|
0 ignored issues
–
show
The type
Mike42\Escpos\Printer 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 | |||
| 29 | class RepDominicana extends BaseTicket |
||
| 30 | { |
||
| 31 | public static function print(ModelClass $model, TicketPrinter $printer, User $user, Agente $agent = null): bool |
||
| 32 | { |
||
| 33 | static::init(); |
||
| 34 | |||
| 35 | $ticket = new Ticket(); |
||
| 36 | $ticket->idprinter = $printer->id; |
||
| 37 | $ticket->nick = $user->nick; |
||
| 38 | $ticket->title = $model->codigo; |
||
| 39 | |||
| 40 | static::setHeader($model, $printer, $ticket->title); |
||
| 41 | static::setBody($model, $printer); |
||
| 42 | static::setFooter($model, $printer); |
||
| 43 | $ticket->body = static::getBody(); |
||
| 44 | $ticket->base64 = true; |
||
| 45 | $ticket->appversion = 1; |
||
| 46 | |||
| 47 | if ($agent) { |
||
| 48 | $ticket->codagente = $agent->codagente; |
||
| 49 | } |
||
| 50 | |||
| 51 | return $ticket->save(); |
||
| 52 | } |
||
| 53 | |||
| 54 | protected static function setHeader(ModelClass $model, TicketPrinter $printer, string $title): void |
||
| 55 | { |
||
| 56 | if ($printer->print_stored_logo) { |
||
| 57 | static::$escpos->setJustification(Printer::JUSTIFY_CENTER); |
||
| 58 | // imprimimos el logotipo almacenado en la impresora |
||
| 59 | static::$connector->write("\x1Cp\x01\x00\x00"); |
||
| 60 | static::$escpos->feed(); |
||
| 61 | } |
||
| 62 | |||
| 63 | // obtenemos los datos de la empresa |
||
| 64 | $company = $model->getCompany(); |
||
| 65 | |||
| 66 | // establecemos el tamaño de la fuente |
||
| 67 | static::$escpos->setTextSize($printer->title_font_size, $printer->title_font_size); |
||
| 68 | |||
| 69 | // imprimimos el nombre corto de la empresa |
||
| 70 | if ($printer->print_comp_shortname) { |
||
| 71 | static::$escpos->text(static::sanitize($company->nombrecorto) . "\n"); |
||
| 72 | static::$escpos->setTextSize($printer->head_font_size, $printer->head_font_size); |
||
| 73 | |||
| 74 | // imprimimos el nombre de la empresa |
||
| 75 | static::$escpos->text(static::sanitize($company->nombre) . "\n"); |
||
| 76 | } else { |
||
| 77 | // imprimimos el nombre de la empresa |
||
| 78 | static::$escpos->text(static::sanitize($company->nombre) . "\n"); |
||
| 79 | static::$escpos->setTextSize($printer->head_font_size, $printer->head_font_size); |
||
| 80 | } |
||
| 81 | |||
| 82 | static::$escpos->setJustification(); |
||
| 83 | |||
| 84 | // imprimimos la dirección de la empresa |
||
| 85 | static::$escpos->text(static::sanitize($company->direccion) . "\n"); |
||
| 86 | static::$escpos->text(static::sanitize("CP: " . $company->codpostal . ', ' . $company->ciudad) . "\n"); |
||
| 87 | static::$escpos->text(static::sanitize($company->tipoidfiscal . ': ' . $company->cifnif) . "\n\n"); |
||
| 88 | |||
| 89 | if ($printer->print_comp_tlf) { |
||
| 90 | if (false === empty($company->telefono1) && false === empty($company->telefono2)) { |
||
| 91 | static::$escpos->text(static::sanitize($company->telefono1 . ' / ' . $company->telefono2) . "\n"); |
||
| 92 | } elseif (false === empty($company->telefono1)) { |
||
| 93 | static::$escpos->text(static::sanitize($company->telefono1) . "\n"); |
||
| 94 | } elseif (false === empty($company->telefono2)) { |
||
| 95 | static::$escpos->text(static::sanitize($company->telefono2) . "\n"); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | // imprimimos el título del documento |
||
| 100 | static::$escpos->text(static::sanitize($title) . "\n"); |
||
| 101 | |||
| 102 | static::setHeaderTPV($model, $printer); |
||
| 103 | |||
| 104 | // si es un documento de venta |
||
| 105 | // imprimimos la fecha y el cliente |
||
| 106 | if ( |
||
| 107 | in_array( |
||
| 108 | $model->modelClassName(), |
||
| 109 | [ |
||
| 110 | 'PresupuestoCliente', |
||
| 111 | 'PedidoCliente', |
||
| 112 | 'AlbaranCliente', |
||
| 113 | 'FacturaCliente' |
||
| 114 | ] |
||
| 115 | ) |
||
| 116 | ) { |
||
| 117 | static::$escpos->text(static::sanitize( |
||
| 118 | static::$i18n->trans('date') . ': ' . $model->fecha . ' ' . $model->hora |
||
| 119 | ) . "\n"); |
||
| 120 | static::$escpos->text(static::sanitize( |
||
| 121 | static::$i18n->trans('customer') . ': ' . $model->nombrecliente |
||
| 122 | ) . "\n"); |
||
| 123 | if(strlen($model->cifnif) == 9) { |
||
| 124 | static::$escpos->text(static::sanitize( |
||
| 125 | static::$i18n->trans('title-cifnif-rnc') . ': ' . $model->cifnif |
||
| 126 | ) . "\n\n"); |
||
| 127 | } else { |
||
| 128 | static::$escpos->text(static::sanitize( |
||
| 129 | static::$i18n->trans('title-cifnif-ci') . ': ' . $model->cifnif |
||
| 130 | ) . "\n\n"); |
||
| 131 | } |
||
| 132 | |||
| 133 | |||
| 134 | if ($model->modelClassName() === 'FacturaCliente') { |
||
| 135 | |||
| 136 | if (property_exists($model, 'tipocomprobante') && $model->tipocomprobante) { |
||
| 137 | static::$escpos->text(static::sanitize( |
||
| 138 | static::$i18n->trans('tipo_comprobante') . ': ' . |
||
| 139 | $model->descripcionTipoComprobante() |
||
| 140 | ). "\n"); |
||
| 141 | } |
||
| 142 | |||
| 143 | if (property_exists($model, 'numeroncf') && $model->numeroncf) { |
||
| 144 | static::$escpos->text(static::sanitize( |
||
| 145 | static::$i18n->trans('ncf-number') . ': ' . $model->numeroncf |
||
| 146 | ). "\n"); |
||
| 147 | } |
||
| 148 | |||
| 149 | if (property_exists($model, 'ncffechavencimiento') && $model->ncffechavencimiento) { |
||
| 150 | static::$escpos->text(static::sanitize( |
||
| 151 | static::$i18n->trans('due-date') . ': ' . $model->ncffechavencimiento |
||
| 152 | ). "\n\n"); |
||
| 153 | } else { |
||
| 154 | static::$escpos->text("\n\n"); |
||
| 155 | } |
||
| 156 | } |
||
| 157 | } |
||
| 158 | |||
| 159 | // añadimos la cabecera |
||
| 160 | if ($printer->head) { |
||
| 161 | static::$escpos->setJustification(Printer::JUSTIFY_CENTER); |
||
| 162 | static::$escpos->text(static::sanitize($printer->head) . "\n\n"); |
||
| 163 | static::$escpos->setJustification(); |
||
| 164 | } |
||
| 165 | } |
||
| 166 | |||
| 167 | protected static function getTipoComprobanteRD(string $numero): string |
||
| 168 | { |
||
| 169 | switch ($numero) { |
||
| 170 | case '01': |
||
| 171 | return static::$i18n->trans('desc-ncf-type-01'); |
||
| 172 | |||
| 173 | case '02': |
||
| 174 | return static::$i18n->trans('desc-ncf-type-02'); |
||
| 175 | |||
| 176 | case '03': |
||
| 177 | return static::$i18n->trans('desc-ncf-type-03'); |
||
| 178 | |||
| 179 | case '04': |
||
| 180 | return static::$i18n->trans('desc-ncf-type-04'); |
||
| 181 | |||
| 182 | case '11': |
||
| 183 | return static::$i18n->trans('desc-ncf-type-11'); |
||
| 184 | |||
| 185 | case '12': |
||
| 186 | return static::$i18n->trans('desc-ncf-type-12'); |
||
| 187 | |||
| 188 | case '13': |
||
| 189 | return static::$i18n->trans('desc-ncf-type-13'); |
||
| 190 | |||
| 191 | case '14': |
||
| 192 | return static::$i18n->trans('desc-ncf-type-14'); |
||
| 193 | |||
| 194 | case '15': |
||
| 195 | return static::$i18n->trans('desc-ncf-type-15'); |
||
| 196 | |||
| 197 | case '16': |
||
| 198 | return static::$i18n->trans('desc-ncf-type-16'); |
||
| 199 | |||
| 200 | case '17': |
||
| 201 | return static::$i18n->trans('desc-ncf-type-17'); |
||
| 202 | |||
| 203 | default: |
||
| 204 | return ''; |
||
| 205 | } |
||
| 206 | } |
||
| 207 | } |
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