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\Model\Base\ModelClass; |
||
|
0 ignored issues
–
show
|
|||
| 21 | 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...
|
|||
| 22 | 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...
|
|||
| 23 | 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...
|
|||
| 24 | 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...
|
|||
| 25 | 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...
|
|||
| 26 | 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...
|
|||
| 27 | |||
| 28 | class RepDominicana extends BaseTicket |
||
| 29 | { |
||
| 30 | public static function print(ModelClass $model, TicketPrinter $printer, User $user, Agente $agent = null): bool |
||
| 31 | { |
||
| 32 | static::init(); |
||
| 33 | |||
| 34 | $ticket = new Ticket(); |
||
| 35 | $ticket->idprinter = $printer->id; |
||
| 36 | $ticket->nick = $user->nick; |
||
| 37 | $ticket->title = self::$i18n->trans($model->modelClassName() . '-min') . ' RepDominicana.php' . $model->codigo; |
||
| 38 | |||
| 39 | static::setHeader($model, $printer, $ticket->title); |
||
| 40 | static::setBody($model, $printer); |
||
| 41 | static::setFooter($model, $printer); |
||
| 42 | $ticket->body = static::getBody(); |
||
| 43 | $ticket->base64 = true; |
||
| 44 | $ticket->appversion = 1; |
||
| 45 | |||
| 46 | if ($agent) { |
||
| 47 | $ticket->codagente = $agent->codagente; |
||
| 48 | } |
||
| 49 | |||
| 50 | return $ticket->save(); |
||
| 51 | } |
||
| 52 | |||
| 53 | protected static function setHeader(ModelClass $model, TicketPrinter $printer, string $title): void |
||
| 54 | { |
||
| 55 | if ($printer->print_stored_logo) { |
||
| 56 | static::$escpos->setJustification(Printer::JUSTIFY_CENTER); |
||
| 57 | // imprimimos el logotipo almacenado en la impresora |
||
| 58 | static::$connector->write("\x1Cp\x01\x00\x00"); |
||
| 59 | static::$escpos->feed(); |
||
| 60 | } |
||
| 61 | |||
| 62 | // obtenemos los datos de la empresa |
||
| 63 | $company = $model->getCompany(); |
||
| 64 | |||
| 65 | // establecemos el tamaño de la fuente |
||
| 66 | static::$escpos->setTextSize($printer->title_font_size, $printer->title_font_size); |
||
| 67 | |||
| 68 | // imprimimos el nombre corto de la empresa |
||
| 69 | if ($printer->print_comp_shortname) { |
||
| 70 | static::$escpos->text(static::sanitize($company->nombrecorto) . "\n"); |
||
| 71 | static::$escpos->setTextSize($printer->head_font_size, $printer->head_font_size); |
||
| 72 | |||
| 73 | // imprimimos el nombre de la empresa |
||
| 74 | static::$escpos->text(static::sanitize($company->nombre) . "\n"); |
||
| 75 | } else { |
||
| 76 | // imprimimos el nombre de la empresa |
||
| 77 | static::$escpos->text(static::sanitize($company->nombre) . "\n"); |
||
| 78 | static::$escpos->setTextSize($printer->head_font_size, $printer->head_font_size); |
||
| 79 | } |
||
| 80 | |||
| 81 | static::$escpos->setJustification(); |
||
| 82 | |||
| 83 | // imprimimos la dirección de la empresa |
||
| 84 | static::$escpos->text(static::sanitize($company->direccion) . "\n"); |
||
| 85 | static::$escpos->text(static::sanitize("CP: " . $company->codpostal . ', ' . $company->ciudad) . "\n"); |
||
| 86 | static::$escpos->text(static::sanitize($company->tipoidfiscal . ': ' . $company->cifnif) . "\n\n"); |
||
| 87 | |||
| 88 | if ($printer->print_comp_tlf) { |
||
| 89 | if (false === empty($company->telefono1) && false === empty($company->telefono2)) { |
||
| 90 | static::$escpos->text(static::sanitize($company->telefono1 . ' / ' . $company->telefono2) . "\n"); |
||
| 91 | } elseif (false === empty($company->telefono1)) { |
||
| 92 | static::$escpos->text(static::sanitize($company->telefono1) . "\n"); |
||
| 93 | } elseif (false === empty($company->telefono2)) { |
||
| 94 | static::$escpos->text(static::sanitize($company->telefono2) . "\n"); |
||
| 95 | } |
||
| 96 | } |
||
| 97 | |||
| 98 | // imprimimos el título del documento |
||
| 99 | static::$escpos->text(static::sanitize($title) . "\n"); |
||
| 100 | |||
| 101 | static::setHeaderTPV($model, $printer); |
||
| 102 | |||
| 103 | // si es un documento de venta |
||
| 104 | // imprimimos la fecha y el cliente |
||
| 105 | if (in_array($model->modelClassName(), ['PresupuestoCliente', 'PedidoCliente', 'AlbaranCliente', 'FacturaCliente'])) { |
||
| 106 | static::$escpos->text(static::sanitize(static::$i18n->trans('date') . ': ' . $model->fecha . ' ' . $model->hora) . "\n"); |
||
| 107 | static::$escpos->text(static::sanitize(static::$i18n->trans('customer') . ': ' . $model->nombrecliente) . "\n\n"); |
||
| 108 | |||
| 109 | if ($model->modelClassName() == 'FacturaCliente') { |
||
| 110 | if (property_exists($model, 'numeroncf') && $model->numeroncf) { |
||
| 111 | static::$escpos->text(static::sanitize(static::$i18n->trans('ncf-number') . ': ' . $model->numeroncf)) . "\n"; |
||
| 112 | } |
||
| 113 | if (property_exists($model, 'tipocomprobante') && $model->tipocomprobante) { |
||
| 114 | static::$escpos->text(static::sanitize(static::$i18n->trans('tipo_comprobante') . ': ' . static::getTipoComprobanteRD($model->tipocomprobante))) . "\n"; |
||
| 115 | } |
||
| 116 | if (property_exists($model, 'ncffechavencimiento') && $model->ncffechavencimiento) { |
||
| 117 | static::$escpos->text(static::sanitize(static::$i18n->trans('due-date') . ': ' . $model->ncffechavencimiento)) . "\n"; |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } |
||
| 121 | |||
| 122 | // añadimos la cabecera |
||
| 123 | if ($printer->head) { |
||
| 124 | static::$escpos->setJustification(Printer::JUSTIFY_CENTER); |
||
| 125 | static::$escpos->text(static::sanitize($printer->head) . "\n\n"); |
||
| 126 | static::$escpos->setJustification(); |
||
| 127 | } |
||
| 128 | } |
||
| 129 | |||
| 130 | protected static function getTipoComprobanteRD(string $numero): string |
||
| 131 | { |
||
| 132 | switch ($numero) { |
||
| 133 | case '01': |
||
| 134 | return static::$i18n->trans('desc-ncf-type-01'); |
||
| 135 | |||
| 136 | case '02': |
||
| 137 | return static::$i18n->trans('desc-ncf-type-02'); |
||
| 138 | |||
| 139 | case '03': |
||
| 140 | return static::$i18n->trans('desc-ncf-type-03'); |
||
| 141 | |||
| 142 | case '04': |
||
| 143 | return static::$i18n->trans('desc-ncf-type-04'); |
||
| 144 | |||
| 145 | case '11': |
||
| 146 | return static::$i18n->trans('desc-ncf-type-11'); |
||
| 147 | |||
| 148 | case '12': |
||
| 149 | return static::$i18n->trans('desc-ncf-type-12'); |
||
| 150 | |||
| 151 | case '13': |
||
| 152 | return static::$i18n->trans('desc-ncf-type-13'); |
||
| 153 | |||
| 154 | case '14': |
||
| 155 | return static::$i18n->trans('desc-ncf-type-14'); |
||
| 156 | |||
| 157 | case '15': |
||
| 158 | return static::$i18n->trans('desc-ncf-type-15'); |
||
| 159 | |||
| 160 | case '16': |
||
| 161 | return static::$i18n->trans('desc-ncf-type-16'); |
||
| 162 | |||
| 163 | case '17': |
||
| 164 | return static::$i18n->trans('desc-ncf-type-17'); |
||
| 165 | |||
| 166 | default: |
||
| 167 | return ''; |
||
| 168 | } |
||
| 169 | } |
||
| 170 | } |
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