@@ -65,8 +65,9 @@ discard block |
||
| 65 | 65 | public static function write($code, $msg = null, $severity = LOG_ERR) |
| 66 | 66 | { |
| 67 | 67 | // si no existe la bitácora para la gravedad se crea |
| 68 | - if (!isset(self::$bitacora[$severity])) |
|
| 69 | - self::$bitacora[$severity] = []; |
|
| 68 | + if (!isset(self::$bitacora[$severity])) { |
|
| 69 | + self::$bitacora[$severity] = []; |
|
| 70 | + } |
|
| 70 | 71 | // si el código es un string se copia a msg |
| 71 | 72 | if (is_string($code)) { |
| 72 | 73 | $msg = $code; |
@@ -97,8 +98,9 @@ discard block |
||
| 97 | 98 | */ |
| 98 | 99 | public static function read($severity = LOG_ERR) |
| 99 | 100 | { |
| 100 | - if (!isset(self::$bitacora[$severity])) |
|
| 101 | - return false; |
|
| 101 | + if (!isset(self::$bitacora[$severity])) { |
|
| 102 | + return false; |
|
| 103 | + } |
|
| 102 | 104 | return array_pop(self::$bitacora[$severity]); |
| 103 | 105 | } |
| 104 | 106 | |
@@ -112,11 +114,13 @@ discard block |
||
| 112 | 114 | */ |
| 113 | 115 | public static function readAll($severity = LOG_ERR, $new_first = true) |
| 114 | 116 | { |
| 115 | - if (!isset(self::$bitacora[$severity])) |
|
| 116 | - return []; |
|
| 117 | + if (!isset(self::$bitacora[$severity])) { |
|
| 118 | + return []; |
|
| 119 | + } |
|
| 117 | 120 | $bitacora = self::$bitacora[$severity]; |
| 118 | - if ($new_first) |
|
| 119 | - krsort($bitacora); |
|
| 121 | + if ($new_first) { |
|
| 122 | + krsort($bitacora); |
|
| 123 | + } |
|
| 120 | 124 | self::$bitacora[$severity] = []; |
| 121 | 125 | return $bitacora; |
| 122 | 126 | } |
@@ -163,8 +167,9 @@ discard block |
||
| 163 | 167 | public function __toString() |
| 164 | 168 | { |
| 165 | 169 | $msg = $this->msg ? $this->msg : 'Error código '.$this->code; |
| 166 | - if (!$this->file) |
|
| 167 | - return $msg; |
|
| 170 | + if (!$this->file) { |
|
| 171 | + return $msg; |
|
| 172 | + } |
|
| 168 | 173 | return $msg.' (by '.$this->class.$this->type.$this->function.'() in '.$this->file.' on line '.$this->line.')'; |
| 169 | 174 | } |
| 170 | 175 | |
@@ -98,8 +98,9 @@ discard block |
||
| 98 | 98 | public function generar() |
| 99 | 99 | { |
| 100 | 100 | // si ya se había generado se entrega directamente |
| 101 | - if ($this->xml_data) |
|
| 102 | - return $this->xml_data; |
|
| 101 | + if ($this->xml_data) { |
|
| 102 | + return $this->xml_data; |
|
| 103 | + } |
|
| 103 | 104 | // si no hay respuestas para generar entregar falso |
| 104 | 105 | if (!isset($this->recibos[0])) { |
| 105 | 106 | \sasco\LibreDTE\Log::write( |
@@ -173,8 +174,9 @@ discard block |
||
| 173 | 174 | } |
| 174 | 175 | // crear recibos a partir del arreglo |
| 175 | 176 | $Recibos = $this->arreglo['EnvioRecibos']['SetRecibos']['Recibo']; |
| 176 | - if (!isset($Recibos[0])) |
|
| 177 | - $Recibos = [$Recibos]; |
|
| 177 | + if (!isset($Recibos[0])) { |
|
| 178 | + $Recibos = [$Recibos]; |
|
| 179 | + } |
|
| 178 | 180 | foreach ($Recibos as $Recibo) { |
| 179 | 181 | $this->recibos[] = $Recibo; |
| 180 | 182 | } |
@@ -40,8 +40,9 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | public function agregar(array $detalle, $normalizar = true) |
| 42 | 42 | { |
| 43 | - if ($normalizar) |
|
| 44 | - $this->normalizarDetalle($detalle); |
|
| 43 | + if ($normalizar) { |
|
| 44 | + $this->normalizarDetalle($detalle); |
|
| 45 | + } |
|
| 45 | 46 | $this->detalles[] = $detalle; |
| 46 | 47 | return true; |
| 47 | 48 | } |
@@ -138,8 +139,9 @@ discard block |
||
| 138 | 139 | 'TipoEnvio' => 'TOTAL', |
| 139 | 140 | 'FolioNotificacion' => null, |
| 140 | 141 | ], $caratula); |
| 141 | - if ($this->caratula['TipoEnvio']=='ESPECIAL') |
|
| 142 | - $this->caratula['FolioNotificacion'] = null; |
|
| 142 | + if ($this->caratula['TipoEnvio']=='ESPECIAL') { |
|
| 143 | + $this->caratula['FolioNotificacion'] = null; |
|
| 144 | + } |
|
| 143 | 145 | $this->id = 'LibreDTE_LIBRO_GUIA_'.str_replace('-', '', $this->caratula['RutEmisorLibro']).'_'.str_replace('-', '', $this->caratula['PeriodoTributario']).'_'.date('U'); |
| 144 | 146 | } |
| 145 | 147 | |
@@ -153,8 +155,9 @@ discard block |
||
| 153 | 155 | public function generar($incluirDetalle = true) |
| 154 | 156 | { |
| 155 | 157 | // si ya se había generado se entrega directamente |
| 156 | - if ($this->xml_data) |
|
| 157 | - return $this->xml_data; |
|
| 158 | + if ($this->xml_data) { |
|
| 159 | + return $this->xml_data; |
|
| 160 | + } |
|
| 158 | 161 | // generar XML del envío |
| 159 | 162 | $xmlEnvio = (new \sasco\LibreDTE\XML())->generate([ |
| 160 | 163 | 'LibroGuia' => [ |
@@ -79,11 +79,11 @@ discard block |
||
| 79 | 79 | } |
| 80 | 80 | // calcular valores que no se hayan entregado |
| 81 | 81 | if (!$detalle['IVA'] and $detalle['TasaImp'] and $detalle['MntNeto']) { |
| 82 | - $detalle['IVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
| 82 | + $detalle['IVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp'] / 100)); |
|
| 83 | 83 | } |
| 84 | 84 | // calcular monto total si no se especificó |
| 85 | 85 | if ($detalle['MntTotal']===false) { |
| 86 | - $detalle['MntTotal'] = $detalle['MntNeto'] + $detalle['IVA']; |
|
| 86 | + $detalle['MntTotal'] = $detalle['MntNeto']+$detalle['IVA']; |
|
| 87 | 87 | } |
| 88 | 88 | } |
| 89 | 89 | |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | $data = \sasco\LibreDTE\CSV::read($archivo); |
| 101 | 101 | $n_data = count($data); |
| 102 | 102 | $detalles = []; |
| 103 | - for ($i=1; $i<$n_data; $i++) { |
|
| 103 | + for ($i = 1; $i<$n_data; $i++) { |
|
| 104 | 104 | // detalle genérico |
| 105 | 105 | $detalle = [ |
| 106 | 106 | 'Folio' => $data[$i][0], |
@@ -203,17 +203,17 @@ discard block |
||
| 203 | 203 | // se contabiliza si la guía está anulada |
| 204 | 204 | if ($d['Anulado']==1 or $d['Anulado']==2) { |
| 205 | 205 | if ($d['Anulado']==1) { |
| 206 | - $ResumenPeriodo['TotFolAnulado'] = (int)$ResumenPeriodo['TotFolAnulado'] + 1; |
|
| 206 | + $ResumenPeriodo['TotFolAnulado'] = (int)$ResumenPeriodo['TotFolAnulado']+1; |
|
| 207 | 207 | } else { |
| 208 | - $ResumenPeriodo['TotGuiaAnulada'] = (int)$ResumenPeriodo['TotGuiaAnulada'] + 1; |
|
| 208 | + $ResumenPeriodo['TotGuiaAnulada'] = (int)$ResumenPeriodo['TotGuiaAnulada']+1; |
|
| 209 | 209 | } |
| 210 | 210 | } |
| 211 | 211 | // si no está anulado |
| 212 | 212 | else { |
| 213 | 213 | // si es de venta |
| 214 | 214 | if ($d['TpoOper']==1) { |
| 215 | - $ResumenPeriodo['TotGuiaVenta'] = (int)$ResumenPeriodo['TotGuiaVenta'] + 1; |
|
| 216 | - $ResumenPeriodo['TotMntGuiaVta'] = (int)$ResumenPeriodo['TotMntGuiaVta'] + $d['MntTotal']; |
|
| 215 | + $ResumenPeriodo['TotGuiaVenta'] = (int)$ResumenPeriodo['TotGuiaVenta']+1; |
|
| 216 | + $ResumenPeriodo['TotMntGuiaVta'] = (int)$ResumenPeriodo['TotMntGuiaVta']+$d['MntTotal']; |
|
| 217 | 217 | } |
| 218 | 218 | // si no es de venta |
| 219 | 219 | else { |
@@ -84,8 +84,9 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | private static function getTokenRequest($seed, $Firma = []) |
| 86 | 86 | { |
| 87 | - if (is_array($Firma)) |
|
| 88 | - $Firma = new \sasco\LibreDTE\FirmaElectronica($Firma); |
|
| 87 | + if (is_array($Firma)) { |
|
| 88 | + $Firma = new \sasco\LibreDTE\FirmaElectronica($Firma); |
|
| 89 | + } |
|
| 89 | 90 | $seedSigned = $Firma->signXML( |
| 90 | 91 | (new \sasco\LibreDTE\XML())->generate([ |
| 91 | 92 | 'getToken' => [ |
@@ -119,11 +120,17 @@ discard block |
||
| 119 | 120 | */ |
| 120 | 121 | public static function getToken($Firma = []) |
| 121 | 122 | { |
| 122 | - if (!$Firma) return false; |
|
| 123 | + if (!$Firma) { |
|
| 124 | + return false; |
|
| 125 | + } |
|
| 123 | 126 | $semilla = self::getSeed(); |
| 124 | - if (!$semilla) return false; |
|
| 127 | + if (!$semilla) { |
|
| 128 | + return false; |
|
| 129 | + } |
|
| 125 | 130 | $requestFirmado = self::getTokenRequest($semilla, $Firma); |
| 126 | - if (!$requestFirmado) return false; |
|
| 131 | + if (!$requestFirmado) { |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 127 | 134 | $xml = \sasco\LibreDTE\Sii::request('GetTokenFromSeed', 'getToken', $requestFirmado); |
| 128 | 135 | if ($xml===false or (string)$xml->xpath('/SII:RESPUESTA/SII:RESP_HDR/ESTADO')[0]!=='00') { |
| 129 | 136 | \sasco\LibreDTE\Log::write( |
@@ -73,10 +73,12 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | public function agregarRespuestaEnvio(array $datos) |
| 75 | 75 | { |
| 76 | - if (isset($this->respuesta_documentos[0])) |
|
| 77 | - return false; |
|
| 78 | - if (isset($this->respuesta_envios[$this->config['respuesta_envios_max']-1])) |
|
| 79 | - return false; |
|
| 76 | + if (isset($this->respuesta_documentos[0])) { |
|
| 77 | + return false; |
|
| 78 | + } |
|
| 79 | + if (isset($this->respuesta_envios[$this->config['respuesta_envios_max']-1])) { |
|
| 80 | + return false; |
|
| 81 | + } |
|
| 80 | 82 | $this->respuesta_envios[] = array_merge([ |
| 81 | 83 | 'NmbEnvio' => false, |
| 82 | 84 | 'FchRecep' => date('Y-m-d\TH:i:s'), |
@@ -102,10 +104,12 @@ discard block |
||
| 102 | 104 | */ |
| 103 | 105 | public function agregarRespuestaDocumento(array $datos) |
| 104 | 106 | { |
| 105 | - if (isset($this->respuesta_envios[0])) |
|
| 106 | - return false; |
|
| 107 | - if (isset($this->respuesta_documentos[$this->config['respuesta_documentos_max']-1])) |
|
| 108 | - return false; |
|
| 107 | + if (isset($this->respuesta_envios[0])) { |
|
| 108 | + return false; |
|
| 109 | + } |
|
| 110 | + if (isset($this->respuesta_documentos[$this->config['respuesta_documentos_max']-1])) { |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 109 | 113 | $this->respuesta_documentos[] = array_merge([ |
| 110 | 114 | 'TipoDTE' => false, |
| 111 | 115 | 'Folio' => false, |
@@ -156,8 +160,9 @@ discard block |
||
| 156 | 160 | public function generar() |
| 157 | 161 | { |
| 158 | 162 | // si ya se había generado se entrega directamente |
| 159 | - if ($this->xml_data) |
|
| 160 | - return $this->xml_data; |
|
| 163 | + if ($this->xml_data) { |
|
| 164 | + return $this->xml_data; |
|
| 165 | + } |
|
| 161 | 166 | // si no hay respuestas para generar entregar falso |
| 162 | 167 | if (!isset($this->respuesta_envios[0]) and !isset($this->respuesta_documentos[0])) { |
| 163 | 168 | \sasco\LibreDTE\Log::write( |
@@ -230,8 +235,9 @@ discard block |
||
| 230 | 235 | */ |
| 231 | 236 | public function getRecepciones() |
| 232 | 237 | { |
| 233 | - if (!$this->esRecepcionEnvio()) |
|
| 234 | - return false; |
|
| 238 | + if (!$this->esRecepcionEnvio()) { |
|
| 239 | + return false; |
|
| 240 | + } |
|
| 235 | 241 | // si no hay respustas se deben crear |
| 236 | 242 | if (!$this->respuesta_envios) { |
| 237 | 243 | // si no está creado el arrelgo con los datos error |
@@ -242,8 +248,9 @@ discard block |
||
| 242 | 248 | if (isset($this->arreglo['RespuestaDTE']['Resultado']['RecepcionEnvio']['RecepcionDTE'])) { |
| 243 | 249 | // crear repuestas a partir del arreglo |
| 244 | 250 | $Recepciones = $this->arreglo['RespuestaDTE']['Resultado']['RecepcionEnvio']['RecepcionDTE']; |
| 245 | - if (!isset($Recepciones[0])) |
|
| 246 | - $Recepciones = [$Recepciones]; |
|
| 251 | + if (!isset($Recepciones[0])) { |
|
| 252 | + $Recepciones = [$Recepciones]; |
|
| 253 | + } |
|
| 247 | 254 | foreach ($Recepciones as $Recepcion) { |
| 248 | 255 | $this->respuesta_envios[] = $Recepcion; |
| 249 | 256 | } |
@@ -260,8 +267,9 @@ discard block |
||
| 260 | 267 | */ |
| 261 | 268 | public function getResultados() |
| 262 | 269 | { |
| 263 | - if (!$this->esResultadoDTE()) |
|
| 264 | - return false; |
|
| 270 | + if (!$this->esResultadoDTE()) { |
|
| 271 | + return false; |
|
| 272 | + } |
|
| 265 | 273 | // si no hay respustas se deben crear |
| 266 | 274 | if (!$this->respuesta_documentos) { |
| 267 | 275 | // si no está creado el arrelgo con los datos error |
@@ -270,8 +278,9 @@ discard block |
||
| 270 | 278 | } |
| 271 | 279 | // crear repuestas a partir del arreglo |
| 272 | 280 | $Resultados = $this->arreglo['RespuestaDTE']['Resultado']['ResultadoDTE']; |
| 273 | - if (!isset($Resultados[0])) |
|
| 274 | - $Resultados = [$Resultados]; |
|
| 281 | + if (!isset($Resultados[0])) { |
|
| 282 | + $Resultados = [$Resultados]; |
|
| 283 | + } |
|
| 275 | 284 | foreach ($Resultados as $Resultado) { |
| 276 | 285 | $this->respuesta_documentos[] = $Resultado; |
| 277 | 286 | } |
@@ -162,8 +162,9 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | public static function getTipo($codigo) |
| 164 | 164 | { |
| 165 | - if (isset(self::$impuestos[$codigo])) |
|
| 166 | - return self::$impuestos[$codigo]['tipo']; |
|
| 165 | + if (isset(self::$impuestos[$codigo])) { |
|
| 166 | + return self::$impuestos[$codigo]['tipo']; |
|
| 167 | + } |
|
| 167 | 168 | return false; |
| 168 | 169 | } |
| 169 | 170 | |
@@ -175,8 +176,9 @@ discard block |
||
| 175 | 176 | */ |
| 176 | 177 | public static function getGlosa($codigo) |
| 177 | 178 | { |
| 178 | - if (isset(self::$impuestos[$codigo])) |
|
| 179 | - return self::$impuestos[$codigo]['glosa']; |
|
| 179 | + if (isset(self::$impuestos[$codigo])) { |
|
| 180 | + return self::$impuestos[$codigo]['glosa']; |
|
| 181 | + } |
|
| 180 | 182 | return 'Impto. cód. '.$codigo; |
| 181 | 183 | } |
| 182 | 184 | |
@@ -188,8 +190,9 @@ discard block |
||
| 188 | 190 | */ |
| 189 | 191 | public static function getTasa($codigo) |
| 190 | 192 | { |
| 191 | - if (isset(self::$impuestos[$codigo]['tasa'])) |
|
| 192 | - return self::$impuestos[$codigo]['tasa']; |
|
| 193 | + if (isset(self::$impuestos[$codigo]['tasa'])) { |
|
| 194 | + return self::$impuestos[$codigo]['tasa']; |
|
| 195 | + } |
|
| 193 | 196 | return false; |
| 194 | 197 | } |
| 195 | 198 | |
@@ -76,12 +76,12 @@ |
||
| 76 | 76 | if (!self::$formatos) { |
| 77 | 77 | $dir = dirname(__FILE__).'/Formatos'; |
| 78 | 78 | $formatos = scandir($dir); |
| 79 | - foreach($formatos as &$formato) { |
|
| 79 | + foreach ($formatos as &$formato) { |
|
| 80 | 80 | if ($formato[0]=='.') |
| 81 | 81 | continue; |
| 82 | 82 | if (is_dir($dir.'/'.$formato)) { |
| 83 | 83 | $subformatos = scandir($dir.'/'.$formato); |
| 84 | - foreach($subformatos as &$subformato) { |
|
| 84 | + foreach ($subformatos as &$subformato) { |
|
| 85 | 85 | if ($subformato[0]=='.') |
| 86 | 86 | continue; |
| 87 | 87 | self::$formatos[] = $formato.'.'.substr($subformato, 0, -4); |
@@ -77,13 +77,15 @@ |
||
| 77 | 77 | $dir = dirname(__FILE__).'/Formatos'; |
| 78 | 78 | $formatos = scandir($dir); |
| 79 | 79 | foreach($formatos as &$formato) { |
| 80 | - if ($formato[0]=='.') |
|
| 81 | - continue; |
|
| 80 | + if ($formato[0]=='.') { |
|
| 81 | + continue; |
|
| 82 | + } |
|
| 82 | 83 | if (is_dir($dir.'/'.$formato)) { |
| 83 | 84 | $subformatos = scandir($dir.'/'.$formato); |
| 84 | 85 | foreach($subformatos as &$subformato) { |
| 85 | - if ($subformato[0]=='.') |
|
| 86 | - continue; |
|
| 86 | + if ($subformato[0]=='.') { |
|
| 87 | + continue; |
|
| 88 | + } |
|
| 87 | 89 | self::$formatos[] = $formato.'.'.substr($subformato, 0, -4); |
| 88 | 90 | } |
| 89 | 91 | } else { |
@@ -47,12 +47,13 @@ |
||
| 47 | 47 | if (!isset($datos['DTE'])) { |
| 48 | 48 | throw new \Exception('El nodo raíz del string XML debe ser el tag DTE'); |
| 49 | 49 | } |
| 50 | - if (isset($datos['DTE']['Documento'])) |
|
| 51 | - $dte = $datos['DTE']['Documento']; |
|
| 52 | - else if (isset($datos['DTE']['Exportaciones'])) |
|
| 53 | - $dte = $datos['DTE']['Exportaciones']; |
|
| 54 | - else if (isset($datos['DTE']['Liquidacion'])) |
|
| 55 | - $dte = $datos['DTE']['Liquidacion']; |
|
| 50 | + if (isset($datos['DTE']['Documento'])) { |
|
| 51 | + $dte = $datos['DTE']['Documento']; |
|
| 52 | + } else if (isset($datos['DTE']['Exportaciones'])) { |
|
| 53 | + $dte = $datos['DTE']['Exportaciones']; |
|
| 54 | + } else if (isset($datos['DTE']['Liquidacion'])) { |
|
| 55 | + $dte = $datos['DTE']['Liquidacion']; |
|
| 56 | + } |
|
| 56 | 57 | unset($dte['@attributes']); |
| 57 | 58 | return $dte; |
| 58 | 59 | } |
@@ -194,8 +194,9 @@ |
||
| 194 | 194 | return false; |
| 195 | 195 | } |
| 196 | 196 | $this->xml = new \sasco\LibreDTE\XML(); |
| 197 | - if (!$this->xml->loadXML($xml) or !$this->schemaValidate()) |
|
| 198 | - return false; |
|
| 197 | + if (!$this->xml->loadXML($xml) or !$this->schemaValidate()) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 199 | 200 | return true; |
| 200 | 201 | } |
| 201 | 202 | |