@@ -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 { |
@@ -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 | |
@@ -138,7 +138,7 @@ |
||
| 138 | 138 | ]; |
| 139 | 139 | // agregar otros impuestos adicionales |
| 140 | 140 | if ($n_OtrosImp>1) { |
| 141 | - for ($i=1; $i<$n_OtrosImp; $i++) { |
|
| 141 | + for ($i = 1; $i<$n_OtrosImp; $i++) { |
|
| 142 | 142 | $detalle[] = [ |
| 143 | 143 | '', |
| 144 | 144 | '', |
@@ -57,8 +57,9 @@ discard block |
||
| 57 | 57 | { |
| 58 | 58 | $this->startPageGroup(); |
| 59 | 59 | $this->AddPage(); |
| 60 | - if (isset($libro['LibroCompraVenta'])) |
|
| 61 | - $libro = $libro['LibroCompraVenta']; |
|
| 60 | + if (isset($libro['LibroCompraVenta'])) { |
|
| 61 | + $libro = $libro['LibroCompraVenta']; |
|
| 62 | + } |
|
| 62 | 63 | // título del libro |
| 63 | 64 | $this->SetFont('helvetica', 'B', 16); |
| 64 | 65 | $this->Texto('Libro de '.ucfirst(strtolower($libro['EnvioLibro']['Caratula']['TipoOperacion'])), null, null, 'C'); |
@@ -109,8 +110,7 @@ discard block |
||
| 109 | 110 | $total_resumen['TotIVARetTotal'] += !empty($total['TotIVARetTotal']) ? $total['TotIVARetTotal'] : 0; |
| 110 | 111 | $total_resumen['TotIVANoRetenido'] += !empty($total['TotIVANoRetenido']) ? $total['TotIVANoRetenido'] : 0; |
| 111 | 112 | $total_resumen['TotMntTotal'] += $total['TotMntTotal']; |
| 112 | - } |
|
| 113 | - else if (in_array($total['TpoDoc'], $this->dte_tipo_operacion['resta'])) { |
|
| 113 | + } else if (in_array($total['TpoDoc'], $this->dte_tipo_operacion['resta'])) { |
|
| 114 | 114 | $total_resumen['TotMntExe'] -= !empty($total['TotMntExe']) ? $total['TotMntExe'] : 0; |
| 115 | 115 | $total_resumen['TotMntNeto'] -= !empty($total['TotMntNeto']) ? $total['TotMntNeto'] : 0; |
| 116 | 116 | $total_resumen['TotMntIVA'] -= !empty($total['TotMntIVA']) ? $total['TotMntIVA'] : 0; |
@@ -171,10 +171,13 @@ discard block |
||
| 171 | 171 | foreach ($libro['EnvioLibro']['Detalle'] as $d) { |
| 172 | 172 | // impuesto adicional |
| 173 | 173 | if (!empty($d['OtrosImp'])) { |
| 174 | - if (!isset($d['OtrosImp'][0])) |
|
| 175 | - $d['OtrosImp'] = [$d['OtrosImp']]; |
|
| 174 | + if (!isset($d['OtrosImp'][0])) { |
|
| 175 | + $d['OtrosImp'] = [$d['OtrosImp']]; |
|
| 176 | + } |
|
| 176 | 177 | $n_OtrosImp = count($d['OtrosImp']); |
| 177 | - } else $n_OtrosImp = 0; |
|
| 178 | + } else { |
|
| 179 | + $n_OtrosImp = 0; |
|
| 180 | + } |
|
| 178 | 181 | // se agrega detalle |
| 179 | 182 | $detalle[] = [ |
| 180 | 183 | $d['TpoDoc'], |
@@ -40,8 +40,9 @@ discard block |
||
| 40 | 40 | public function enviar() |
| 41 | 41 | { |
| 42 | 42 | // generar XML que se enviará |
| 43 | - if (!$this->xml_data) |
|
| 44 | - $this->xml_data = $this->generar(); |
|
| 43 | + if (!$this->xml_data) { |
|
| 44 | + $this->xml_data = $this->generar(); |
|
| 45 | + } |
|
| 45 | 46 | if (!$this->xml_data) { |
| 46 | 47 | \sasco\LibreDTE\Log::write( |
| 47 | 48 | \sasco\LibreDTE\Estado::DOCUMENTO_ERROR_GENERAR_XML, |
@@ -53,20 +54,24 @@ discard block |
||
| 53 | 54 | return false; |
| 54 | 55 | } |
| 55 | 56 | // validar schema del documento antes de enviar |
| 56 | - if (!$this->schemaValidate()) |
|
| 57 | - return false; |
|
| 57 | + if (!$this->schemaValidate()) { |
|
| 58 | + return false; |
|
| 59 | + } |
|
| 58 | 60 | // solicitar token |
| 59 | 61 | $token = \sasco\LibreDTE\Sii\Autenticacion::getToken($this->Firma); |
| 60 | - if (!$token) |
|
| 61 | - return false; |
|
| 62 | + if (!$token) { |
|
| 63 | + return false; |
|
| 64 | + } |
|
| 62 | 65 | // enviar DTE |
| 63 | 66 | $envia = $this->caratula['RutEnvia']; |
| 64 | 67 | $emisor = !empty($this->caratula['RutEmisor']) ? $this->caratula['RutEmisor'] : $this->caratula['RutEmisorLibro']; |
| 65 | 68 | $result = \sasco\LibreDTE\Sii::enviar($envia, $emisor, $this->xml_data, $token); |
| 66 | - if ($result===false) |
|
| 67 | - return false; |
|
| 68 | - if (!is_numeric((string)$result->TRACKID)) |
|
| 69 | - return false; |
|
| 69 | + if ($result===false) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + if (!is_numeric((string)$result->TRACKID)) { |
|
| 73 | + return false; |
|
| 74 | + } |
|
| 70 | 75 | return (int)(string)$result->TRACKID; |
| 71 | 76 | } |
| 72 | 77 | |
@@ -813,8 +813,9 @@ discard block |
||
| 813 | 813 | */ |
| 814 | 814 | public static function getGlosa($tag) |
| 815 | 815 | { |
| 816 | - if (!isset(self::$tablas[$tag])) |
|
| 817 | - return false; |
|
| 816 | + if (!isset(self::$tablas[$tag])) { |
|
| 817 | + return false; |
|
| 818 | + } |
|
| 818 | 819 | return is_array(self::$tablas[$tag]) ? self::$tablas[$tag]['glosa'] : self::$tablas[$tag]; |
| 819 | 820 | } |
| 820 | 821 | |
@@ -825,10 +826,12 @@ discard block |
||
| 825 | 826 | */ |
| 826 | 827 | public static function getValor($tag, $codigo) |
| 827 | 828 | { |
| 828 | - if (!isset(self::$tablas[$tag])) |
|
| 829 | - return false; |
|
| 830 | - if (!is_array(self::$tablas[$tag])) |
|
| 831 | - return $codigo; |
|
| 829 | + if (!isset(self::$tablas[$tag])) { |
|
| 830 | + return false; |
|
| 831 | + } |
|
| 832 | + if (!is_array(self::$tablas[$tag])) { |
|
| 833 | + return $codigo; |
|
| 834 | + } |
|
| 832 | 835 | $tabla = isset(self::$tablas[$tag]['valor']) ? self::$tablas[$tag]['valor'] : self::$tablas[self::$tablas[$tag]['tabla']]; |
| 833 | 836 | if ($tag=='TipoBultos') { |
| 834 | 837 | $valor = isset($tabla[$codigo['CodTpoBultos']]) ? $tabla[$codigo['CodTpoBultos']] : $codigo['CodTpoBultos']; |
@@ -868,8 +871,9 @@ discard block |
||
| 868 | 871 | { |
| 869 | 872 | self::$tablasInvertidas = []; |
| 870 | 873 | foreach (self::$tablas as $tag => $info) { |
| 871 | - if (is_string($info) or (!isset($info['valor']) and !isset($info['tabla']))) |
|
| 872 | - continue; |
|
| 874 | + if (is_string($info) or (!isset($info['valor']) and !isset($info['tabla']))) { |
|
| 875 | + continue; |
|
| 876 | + } |
|
| 873 | 877 | $tabla = isset($info['valor']) ? $info['valor'] : self::$tablas[$info['tabla']]; |
| 874 | 878 | foreach ($tabla as &$val) { |
| 875 | 879 | $val = str_replace( |
@@ -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 | } |
@@ -167,9 +167,9 @@ discard block |
||
| 167 | 167 | // calcular valores que no se hayan entregado |
| 168 | 168 | if (isset($detalle['FctProp'])) { |
| 169 | 169 | if ($detalle['IVAUsoComun']===false) |
| 170 | - $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
| 170 | + $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp'] / 100)); |
|
| 171 | 171 | } else if (!$detalle['MntIVA'] and !is_array($detalle['IVANoRec']) and $detalle['TasaImp'] and $detalle['MntNeto']) { |
| 172 | - $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
| 172 | + $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp'] / 100)); |
|
| 173 | 173 | } |
| 174 | 174 | // si el monto total es 0 pero no se asigno neto ni exento se coloca |
| 175 | 175 | if ($detalle['MntExe']===false and $detalle['MntNeto']===false and $detalle['MntTotal']===0) { |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | $MntIVANoRec = explode(',', $detalle['IVANoRec'][0]['MntIVANoRec']); |
| 186 | 186 | $detalle['IVANoRec'] = []; |
| 187 | 187 | $n_inr = count($CodIVANoRec); |
| 188 | - for ($i=0; $i<$n_inr; $i++) { |
|
| 188 | + for ($i = 0; $i<$n_inr; $i++) { |
|
| 189 | 189 | $detalle['IVANoRec'][] = [ |
| 190 | 190 | 'CodIVANoRec' => $CodIVANoRec[$i], |
| 191 | 191 | 'MntIVANoRec' => $MntIVANoRec[$i], |
@@ -204,7 +204,7 @@ discard block |
||
| 204 | 204 | $MntImp = explode(',', $detalle['OtrosImp'][0]['MntImp']); |
| 205 | 205 | $detalle['OtrosImp'] = []; |
| 206 | 206 | $n_impuestos = count($CodImp); |
| 207 | - for ($i=0; $i<$n_impuestos; $i++) { |
|
| 207 | + for ($i = 0; $i<$n_impuestos; $i++) { |
|
| 208 | 208 | $detalle['OtrosImp'][] = [ |
| 209 | 209 | 'CodImp' => $CodImp[$i], |
| 210 | 210 | 'TasaImp' => !empty($TasaImp[$i]) ? $TasaImp[$i] : false, |
@@ -216,20 +216,20 @@ discard block |
||
| 216 | 216 | $retenido = ImpuestosAdicionales::getRetenido($detalle['OtrosImp']); |
| 217 | 217 | if ($retenido) { |
| 218 | 218 | // si el iva retenido es total |
| 219 | - if ($retenido == $detalle['MntIVA']) { |
|
| 219 | + if ($retenido==$detalle['MntIVA']) { |
|
| 220 | 220 | $detalle['IVARetTotal'] = $retenido; |
| 221 | 221 | } |
| 222 | 222 | // si el iva retenido es parcial |
| 223 | 223 | else { |
| 224 | 224 | $detalle['IVARetParcial'] = $retenido; |
| 225 | - $detalle['IVANoRetenido'] = $detalle['MntIVA'] - $retenido; |
|
| 225 | + $detalle['IVANoRetenido'] = $detalle['MntIVA']-$retenido; |
|
| 226 | 226 | } |
| 227 | 227 | } |
| 228 | 228 | } |
| 229 | 229 | // calcular monto total si no se especificó |
| 230 | 230 | if ($detalle['MntTotal']===false) { |
| 231 | 231 | // calcular monto total inicial |
| 232 | - $detalle['MntTotal'] = $detalle['MntExe'] + $detalle['MntNeto'] + (int)$detalle['MntIVA']; |
|
| 232 | + $detalle['MntTotal'] = $detalle['MntExe']+$detalle['MntNeto']+(int)$detalle['MntIVA']; |
|
| 233 | 233 | // agregar iva no recuperable al monto total |
| 234 | 234 | if (!empty($detalle['IVANoRec'])) { |
| 235 | 235 | foreach ($detalle['IVANoRec'] as $IVANoRec) { |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | } |
| 250 | 250 | } |
| 251 | 251 | // agregar otro montos e impuestos al total |
| 252 | - $detalle['MntTotal'] += (int)$detalle['MntSinCred'] + (int)$detalle['TabPuros'] + (int)$detalle['TabCigarrillos'] + (int)$detalle['TabElaborado'] + (int)$detalle['ImpVehiculo']; |
|
| 252 | + $detalle['MntTotal'] += (int)$detalle['MntSinCred']+(int)$detalle['TabPuros']+(int)$detalle['TabCigarrillos']+(int)$detalle['TabElaborado']+(int)$detalle['ImpVehiculo']; |
|
| 253 | 253 | } |
| 254 | 254 | // si no hay no hay monto neto, no se crean campos para IVA |
| 255 | 255 | if ($detalle['MntNeto']===false) { |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | $data = \sasco\LibreDTE\CSV::read($archivo); |
| 310 | 310 | $n_data = count($data); |
| 311 | 311 | $detalles = []; |
| 312 | - for ($i=1; $i<$n_data; $i++) { |
|
| 312 | + for ($i = 1; $i<$n_data; $i++) { |
|
| 313 | 313 | // detalle genérico |
| 314 | 314 | $detalle = [ |
| 315 | 315 | 'TpoDoc' => $data[$i][0], |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | if (!empty($data[$i][11])) { |
| 345 | 345 | $detalle['IVANoRec'] = [ |
| 346 | 346 | 'CodIVANoRec' => $data[$i][11], |
| 347 | - 'MntIVANoRec' => !empty($data[$i][12]) ? $data[$i][12] : round($detalle['MntNeto'] * ($detalle['TasaImp']/100)), |
|
| 347 | + 'MntIVANoRec' => !empty($data[$i][12]) ? $data[$i][12] : round($detalle['MntNeto'] * ($detalle['TasaImp'] / 100)), |
|
| 348 | 348 | ]; |
| 349 | 349 | } |
| 350 | 350 | // agregar código y monto de otros impuestos |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | $detalle['OtrosImp'] = [ |
| 353 | 353 | 'CodImp' => $data[$i][14], |
| 354 | 354 | 'TasaImp' => !empty($data[$i][15]) ? $data[$i][15] : 0, |
| 355 | - 'MntImp' => !empty($data[$i][16]) ? $data[$i][16] : round($detalle['MntNeto'] * ($data[$i][15]/100)), |
|
| 355 | + 'MntImp' => !empty($data[$i][16]) ? $data[$i][16] : round($detalle['MntNeto'] * ($data[$i][15] / 100)), |
|
| 356 | 356 | ]; |
| 357 | 357 | } |
| 358 | 358 | // si hay monto total se agrega |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | $data = \sasco\LibreDTE\CSV::read($archivo); |
| 428 | 428 | $n_data = count($data); |
| 429 | 429 | $detalles = []; |
| 430 | - for ($i=1; $i<$n_data; $i++) { |
|
| 430 | + for ($i = 1; $i<$n_data; $i++) { |
|
| 431 | 431 | // detalle genérico |
| 432 | 432 | $detalle = [ |
| 433 | 433 | 'TpoDoc' => $data[$i][0], |
@@ -466,7 +466,7 @@ discard block |
||
| 466 | 466 | $detalle['OtrosImp'] = [ |
| 467 | 467 | 'CodImp' => $data[$i][11], |
| 468 | 468 | 'TasaImp' => !empty($data[$i][12]) ? $data[$i][12] : false, |
| 469 | - 'MntImp' => !empty($data[$i][13]) ? $data[$i][13] : round($detalle['MntNeto'] * ($data[$i][12]/100)), |
|
| 469 | + 'MntImp' => !empty($data[$i][13]) ? $data[$i][13] : round($detalle['MntNeto'] * ($data[$i][12] / 100)), |
|
| 470 | 470 | ]; |
| 471 | 471 | } |
| 472 | 472 | // agregar datos extranjeros |
@@ -628,8 +628,8 @@ discard block |
||
| 628 | 628 | // si hay IVA de uso común se contabiliza |
| 629 | 629 | if (!empty($d['FctProp'])) { |
| 630 | 630 | $totales[$d['TpoDoc']]['TotIVAUsoComun'] += $d['IVAUsoComun']; |
| 631 | - $totales[$d['TpoDoc']]['FctProp'] = $d['FctProp']/100; |
|
| 632 | - $totales[$d['TpoDoc']]['TotCredIVAUsoComun'] += round($d['IVAUsoComun'] * ($d['FctProp']/100)); |
|
| 631 | + $totales[$d['TpoDoc']]['FctProp'] = $d['FctProp'] / 100; |
|
| 632 | + $totales[$d['TpoDoc']]['TotCredIVAUsoComun'] += round($d['IVAUsoComun'] * ($d['FctProp'] / 100)); |
|
| 633 | 633 | unset($d['FctProp']); // se quita el factor de proporcionalidad del detalle ya que no es parte del XML |
| 634 | 634 | } |
| 635 | 635 | // contabilizar IVA fuera de plazo |
@@ -102,10 +102,12 @@ discard block |
||
| 102 | 102 | */ |
| 103 | 103 | public function agregar(array $detalle, $normalizar = true) |
| 104 | 104 | { |
| 105 | - if ($normalizar) |
|
| 106 | - $this->normalizarDetalle($detalle); |
|
| 107 | - if (!$detalle['TpoDoc']) |
|
| 108 | - return false; |
|
| 105 | + if ($normalizar) { |
|
| 106 | + $this->normalizarDetalle($detalle); |
|
| 107 | + } |
|
| 108 | + if (!$detalle['TpoDoc']) { |
|
| 109 | + return false; |
|
| 110 | + } |
|
| 109 | 111 | $this->detalles[] = $detalle; |
| 110 | 112 | return true; |
| 111 | 113 | } |
@@ -183,8 +185,9 @@ discard block |
||
| 183 | 185 | } |
| 184 | 186 | // calcular valores que no se hayan entregado |
| 185 | 187 | if (isset($detalle['FctProp'])) { |
| 186 | - if ($detalle['IVAUsoComun']===false) |
|
| 187 | - $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
| 188 | + if ($detalle['IVAUsoComun']===false) { |
|
| 189 | + $detalle['IVAUsoComun'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
|
| 190 | + } |
|
| 188 | 191 | } else if (!$detalle['MntIVA'] and !is_array($detalle['IVANoRec']) and $detalle['TasaImp'] and $detalle['MntNeto']) { |
| 189 | 192 | $detalle['MntIVA'] = round($detalle['MntNeto'] * ($detalle['TasaImp']/100)); |
| 190 | 193 | } |
@@ -194,8 +197,9 @@ discard block |
||
| 194 | 197 | } |
| 195 | 198 | // normalizar IVA no recuperable |
| 196 | 199 | if (!empty($detalle['IVANoRec'])) { |
| 197 | - if (!isset($detalle['IVANoRec'][0])) |
|
| 198 | - $detalle['IVANoRec'] = [$detalle['IVANoRec']]; |
|
| 200 | + if (!isset($detalle['IVANoRec'][0])) { |
|
| 201 | + $detalle['IVANoRec'] = [$detalle['IVANoRec']]; |
|
| 202 | + } |
|
| 199 | 203 | // si son múltiples iva no recuperable se arma arreglo real |
| 200 | 204 | if (strpos($detalle['IVANoRec'][0]['CodIVANoRec'], ',')) { |
| 201 | 205 | $CodIVANoRec = explode(',', $detalle['IVANoRec'][0]['CodIVANoRec']); |
@@ -212,8 +216,9 @@ discard block |
||
| 212 | 216 | } |
| 213 | 217 | // normalizar otros impuestos |
| 214 | 218 | if (!empty($detalle['OtrosImp'])) { |
| 215 | - if (!isset($detalle['OtrosImp'][0])) |
|
| 216 | - $detalle['OtrosImp'] = [$detalle['OtrosImp']]; |
|
| 219 | + if (!isset($detalle['OtrosImp'][0])) { |
|
| 220 | + $detalle['OtrosImp'] = [$detalle['OtrosImp']]; |
|
| 221 | + } |
|
| 217 | 222 | // si son múltiples impuestos se arma arreglo real |
| 218 | 223 | if (strpos($detalle['OtrosImp'][0]['CodImp'], ',')) { |
| 219 | 224 | $CodImp = explode(',', $detalle['OtrosImp'][0]['CodImp']); |
@@ -531,8 +536,9 @@ discard block |
||
| 531 | 536 | 'TipoEnvio' => 'TOTAL', |
| 532 | 537 | 'FolioNotificacion' => false, |
| 533 | 538 | ], $caratula); |
| 534 | - if ($this->caratula['TipoEnvio']=='ESPECIAL') |
|
| 535 | - $this->caratula['FolioNotificacion'] = null; |
|
| 539 | + if ($this->caratula['TipoEnvio']=='ESPECIAL') { |
|
| 540 | + $this->caratula['FolioNotificacion'] = null; |
|
| 541 | + } |
|
| 536 | 542 | $this->id = 'LibreDTE_LIBRO_'.$this->caratula['TipoOperacion'].'_'.str_replace('-', '', $this->caratula['RutEmisorLibro']).'_'.str_replace('-', '', $this->caratula['PeriodoTributario']).'_'.date('U'); |
| 537 | 543 | } |
| 538 | 544 | |
@@ -546,8 +552,9 @@ discard block |
||
| 546 | 552 | public function generar($incluirDetalle = true) |
| 547 | 553 | { |
| 548 | 554 | // si ya se había generado se entrega directamente |
| 549 | - if ($this->xml_data) |
|
| 550 | - return $this->xml_data; |
|
| 555 | + if ($this->xml_data) { |
|
| 556 | + return $this->xml_data; |
|
| 557 | + } |
|
| 551 | 558 | // generar totales de DTE y sus montos |
| 552 | 559 | $TotalesPeriodo = $this->getResumen(); |
| 553 | 560 | $ResumenPeriodo = $TotalesPeriodo ? ['TotalesPeriodo'=>$TotalesPeriodo] : false; |
@@ -712,8 +719,9 @@ discard block |
||
| 712 | 719 | $manual = []; |
| 713 | 720 | if (isset($this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo'])) { |
| 714 | 721 | $totales = $this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo']; |
| 715 | - if (!isset($totales[0])) |
|
| 716 | - $totales = [$totales]; |
|
| 722 | + if (!isset($totales[0])) { |
|
| 723 | + $totales = [$totales]; |
|
| 724 | + } |
|
| 717 | 725 | foreach ($totales as $total) { |
| 718 | 726 | if (isset($total['TpoDoc']) and in_array($total['TpoDoc'], [35, 38, 48])) { |
| 719 | 727 | $manual[$total['TpoDoc']] = array_merge($this->total_default, $total); |
@@ -733,8 +741,9 @@ discard block |
||
| 733 | 741 | $manual = []; |
| 734 | 742 | if (isset($this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo'])) { |
| 735 | 743 | $totales = $this->toArray()['LibroCompraVenta']['EnvioLibro']['ResumenPeriodo']['TotalesPeriodo']; |
| 736 | - if (!isset($totales[0])) |
|
| 737 | - $totales = [$totales]; |
|
| 744 | + if (!isset($totales[0])) { |
|
| 745 | + $totales = [$totales]; |
|
| 746 | + } |
|
| 738 | 747 | foreach ($totales as $total) { |
| 739 | 748 | if (in_array($total['TpoDoc'], [39, 41])) { |
| 740 | 749 | $manual[$total['TpoDoc']] = array_merge($this->total_default, $total); |