sw_fac 0.3.45 → 0.3.51
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sw_fac/config.rb +1 -1
- data/lib/sw_fac/facturacion.rb +111 -50
- data/lib/sw_fac/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 699ee18fb43953f097473a8f8e02d13a4bb6009c74f8cc9940d1a5e6784e8236
|
4
|
+
data.tar.gz: '066639f25ab6a19abdd559e8c689c3abeee7aa511141ed77c7253f8779444b08'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8f26d41657377a1dc9295adf53c4c3cd390f6761cb14fea872f0eab24e2047ad3ba60c0a3a8545a87beb9761e19de7a272afddee3c20e2017abb8586a5890aa
|
7
|
+
data.tar.gz: 7305bbf0421ad07c2469677f104a0219c0850444483aae0a00dd6d781e3295f31c734c15dc03d10ebe20543b2c56872c6784fa962e3a0fb81a006c2916b2ff41
|
data/lib/sw_fac/config.rb
CHANGED
@@ -62,7 +62,7 @@ module SwFac
|
|
62
62
|
|
63
63
|
DocBase = %(<?xml version="1.0" encoding="utf-8"?><cfdi:Comprobante xsi:schemaLocation="http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd" Version="3.3" xmlns:cfdi="http://www.sat.gob.mx/cfd/3" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><cfdi:Emisor />
|
64
64
|
<cfdi:Receptor /><cfdi:Conceptos></cfdi:Conceptos>
|
65
|
-
<cfdi:Impuestos
|
65
|
+
<cfdi:Impuestos></cfdi:Impuestos></cfdi:Comprobante>)
|
66
66
|
|
67
67
|
Doc_concepto = %(<cfdi:Concepto ClaveProdServ="25172504" NoIdentificacion="COST37125R17" Cantidad="1" ClaveUnidad="H87" Unidad="Pieza" Descripcion="Producto de prueba" ValorUnitario="1000.00" Importe="1000.00"><cfdi:Impuestos><cfdi:Traslados><cfdi:Traslado Base="1000.00" Impuesto="002" TipoFactor="Tasa" TasaOCuota="0.160000" Importe="160.00" /></cfdi:Traslados></cfdi:Impuestos></cfdi:Concepto>)
|
68
68
|
|
data/lib/sw_fac/facturacion.rb
CHANGED
@@ -414,7 +414,6 @@ module SwFac
|
|
414
414
|
# receptor_rfc: '',
|
415
415
|
# uso_cfdi: 'G03',
|
416
416
|
# time: "%Y-%m-%dT%H:%M:%S",
|
417
|
-
# retencion_iva: false, <------ ######
|
418
417
|
# line_items: [
|
419
418
|
# {
|
420
419
|
# clave_prod_serv: '78181500',
|
@@ -426,8 +425,8 @@ module SwFac
|
|
426
425
|
# valor_unitario: 100.00,
|
427
426
|
# descuento: 0.00,
|
428
427
|
# tax_included: true,
|
428
|
+
# retencion_iva: 0, 6, 16
|
429
429
|
# # Optional parameters
|
430
|
-
# # tipo_impuesto: '002'
|
431
430
|
# },
|
432
431
|
# ]
|
433
432
|
|
@@ -461,8 +460,10 @@ module SwFac
|
|
461
460
|
receptor['Rfc'] = params.fetch(:receptor_rfc, '')
|
462
461
|
receptor['UsoCFDI'] = params.fetch(:uso_cfdi, 'G03')
|
463
462
|
|
463
|
+
# retencion_iva = params.fetch(:retencion_iva, 0)
|
464
|
+
|
464
465
|
impuestos = xml.at_xpath("//cfdi:Impuestos")
|
465
|
-
|
466
|
+
traslados = Nokogiri::XML::Node.new "cfdi:Traslados", xml
|
466
467
|
|
467
468
|
|
468
469
|
puts '--- sw_fac time -----'
|
@@ -476,36 +477,57 @@ module SwFac
|
|
476
477
|
suma_total = 0.00
|
477
478
|
subtotal = 0.00
|
478
479
|
suma_iva = 0.00
|
480
|
+
suma_ret = 0.00
|
481
|
+
|
482
|
+
|
479
483
|
|
480
484
|
line_items.each do |line|
|
481
|
-
|
485
|
+
ret_iva = line.fetch(:retencion_iva, 0)
|
486
|
+
puts ret_iva
|
487
|
+
|
482
488
|
|
489
|
+
## revisando si la linea tiene iva 0
|
483
490
|
if line[:tax_included] == true
|
484
|
-
if line[:tipo_impuesto] == '004'
|
485
|
-
|
486
|
-
else
|
487
|
-
|
488
|
-
|
491
|
+
# if line[:tipo_impuesto] == '004'
|
492
|
+
# valor_unitario = (line[:valor_unitario].to_f)
|
493
|
+
# else
|
494
|
+
# end
|
495
|
+
valor_unitario = ((line[:valor_unitario]).to_f) / 1.16
|
489
496
|
else
|
490
|
-
|
497
|
+
valor_unitario = (line[:valor_unitario].to_f)
|
491
498
|
end
|
492
499
|
|
493
500
|
cantidad = line[:cantidad].to_f
|
494
|
-
total_line = cantidad *
|
501
|
+
total_line = cantidad * valor_unitario
|
495
502
|
|
496
|
-
if line[:tipo_impuesto] == '004'
|
497
|
-
total_acumulator = cantidad *
|
498
|
-
else
|
499
|
-
total_acumulator = cantidad *
|
500
|
-
end
|
501
|
-
|
502
|
-
|
503
|
+
# if line[:tipo_impuesto] == '004'
|
504
|
+
# total_acumulator = cantidad * valor_unitario
|
505
|
+
# else
|
506
|
+
# total_acumulator = cantidad * valor_unitario * 1.16
|
507
|
+
# end
|
508
|
+
|
509
|
+
total_acumulator = cantidad * valor_unitario * 1.16
|
503
510
|
|
511
|
+
importe_iva = total_acumulator - total_line
|
504
512
|
subtotal += total_line
|
505
513
|
suma_iva += importe_iva
|
506
514
|
suma_total += total_acumulator
|
507
515
|
|
516
|
+
## calculando retencion de IVA en caso de tener
|
517
|
+
if ret_iva > 0
|
518
|
+
if ret_iva == 6
|
519
|
+
importe_ret_linea = (total_line * 1.06) - total_line
|
520
|
+
elsif ret_iva == 16
|
521
|
+
importe_ret_linea = importe_iva
|
522
|
+
end
|
523
|
+
else
|
524
|
+
importe_ret_linea = 0
|
525
|
+
end
|
526
|
+
puts "--- 01"
|
527
|
+
suma_ret += importe_ret_linea
|
528
|
+
|
508
529
|
|
530
|
+
## Creando y poblando CFDI:CONCEPTO
|
509
531
|
child_concepto = Nokogiri::XML::Node.new "cfdi:Concepto", xml
|
510
532
|
child_concepto['ClaveProdServ'] = line[:clave_prod_serv].to_s
|
511
533
|
child_concepto['NoIdentificacion'] = line[:sku].to_s
|
@@ -513,68 +535,107 @@ module SwFac
|
|
513
535
|
child_concepto['Unidad'] = line[:unidad].to_s
|
514
536
|
child_concepto['Descripcion'] = line[:descripcion].to_s
|
515
537
|
child_concepto['Cantidad'] = cantidad.to_s
|
516
|
-
child_concepto['ValorUnitario'] =
|
517
|
-
child_concepto['Importe'] = total_line.round(
|
538
|
+
child_concepto['ValorUnitario'] = valor_unitario.round(2).to_s
|
539
|
+
child_concepto['Importe'] = total_line.round(2).to_s
|
518
540
|
# child_concepto['Descuento'] = line.fetch(:descuento, 0.00).round(6).to_s
|
519
541
|
|
542
|
+
|
543
|
+
## Creando cdfi:Impuestos para cada linea
|
520
544
|
child_impuestos = Nokogiri::XML::Node.new "cfdi:Impuestos", xml
|
545
|
+
|
546
|
+
## Creando cfdi:Traslados para cada linea
|
521
547
|
child_traslados = Nokogiri::XML::Node.new "cfdi:Traslados", xml
|
522
548
|
child_traslado = Nokogiri::XML::Node.new "cfdi:Traslado", xml
|
523
|
-
child_traslado['Base'] = total_line.round(
|
549
|
+
child_traslado['Base'] = total_line.round(2).to_s
|
524
550
|
child_traslado['Impuesto'] = '002'
|
525
551
|
child_traslado['TipoFactor'] = "Tasa"
|
552
|
+
child_traslado['TasaOCuota'] = '0.160000'
|
553
|
+
child_traslado['Importe'] = importe_iva.round(2).to_s
|
526
554
|
|
527
|
-
if line[:tipo_impuesto] == '004'
|
528
|
-
|
529
|
-
else
|
530
|
-
|
531
|
-
end
|
555
|
+
# if line[:tipo_impuesto] == '004'
|
556
|
+
# child_traslado['TasaOCuota'] = '0.000000'
|
557
|
+
# else
|
558
|
+
# end
|
532
559
|
|
533
560
|
|
534
|
-
child_traslado['Importe'] = importe_iva.round(6).to_s
|
535
|
-
|
536
561
|
# Joining all up
|
537
562
|
child_traslados.add_child(child_traslado)
|
538
563
|
child_impuestos.add_child(child_traslados)
|
539
564
|
child_concepto.add_child(child_impuestos)
|
540
|
-
|
541
565
|
conceptos.add_child(child_concepto)
|
566
|
+
|
567
|
+
## Creando cfdi:Retenciones para cada linea en caso de tener
|
568
|
+
if ret_iva > 0
|
569
|
+
child_retenciones = Nokogiri::XML::Node.new "cfdi:Retenciones", xml
|
570
|
+
child_retencion = Nokogiri::XML::Node.new "cfdi:Retencion", xml
|
571
|
+
child_retencion['Base'] = total_line.round(2).to_s
|
572
|
+
child_retencion['Impuesto'] = '002'
|
573
|
+
child_retencion['TipoFactor'] = "Tasa"
|
542
574
|
|
543
|
-
|
575
|
+
if ret_iva == 6
|
576
|
+
child_retencion['TasaOCuota'] = "0.060000"
|
577
|
+
elsif ret_iva == 16
|
578
|
+
child_retencion['TasaOCuota'] = "0.160000"
|
579
|
+
end
|
580
|
+
|
581
|
+
child_retencion['Importe'] = importe_ret_linea.round(2).to_s
|
544
582
|
|
545
|
-
|
546
|
-
|
547
|
-
|
548
|
-
# puts "Suma iva = #{suma_iva}"
|
583
|
+
child_retenciones.add_child(child_retencion)
|
584
|
+
child_impuestos.add_child(child_retenciones)
|
585
|
+
end
|
549
586
|
|
550
587
|
|
588
|
+
|
589
|
+
end
|
590
|
+
|
591
|
+
puts '------ Totales -----'
|
592
|
+
puts "Total suma = #{suma_total.round(2)}"
|
593
|
+
puts "SubTotal suma = #{subtotal.round(2)}"
|
594
|
+
puts "Suma iva = #{suma_iva.round(2)}"
|
595
|
+
puts "Suma restenciones = #{suma_ret.round(2)}"
|
596
|
+
|
551
597
|
comprobante['Moneda'] = params.fetch(:moneda, 'MXN')
|
552
598
|
comprobante['SubTotal'] = subtotal.round(2).to_s
|
553
|
-
impuestos['TotalImpuestosTrasladados'] = suma_iva.round(2).to_s
|
554
599
|
|
555
600
|
|
556
|
-
|
557
|
-
if
|
558
|
-
|
559
|
-
retencion_child = Nokogiri::XML::Node.new "cfdi:Retencion", xml
|
601
|
+
## Poblanco cfdi:Impuestos
|
602
|
+
impuestos['TotalImpuestosRetenidos'] = suma_ret.round(2).to_s if suma_ret > 0
|
603
|
+
impuestos['TotalImpuestosTrasladados'] = suma_iva.round(2).to_s
|
560
604
|
|
561
|
-
|
605
|
+
## filling default retencion info
|
606
|
+
if suma_ret > 0
|
607
|
+
retenciones = Nokogiri::XML::Node.new "cfdi:Retenciones", xml
|
608
|
+
retencion_child = Nokogiri::XML::Node.new "cfdi:Retencion", xml
|
562
609
|
retencion_child['Impuesto'] = "002"
|
563
|
-
retencion_child['Importe'] =
|
610
|
+
retencion_child['Importe'] = suma_ret.round(2).to_s
|
611
|
+
# retencion_child['TipoFactor'] = "Tasa"
|
564
612
|
|
565
|
-
|
566
|
-
impuestos
|
567
|
-
|
568
|
-
|
569
|
-
retencion.add_child(retencion_child)
|
570
|
-
impuestos.add_child(retencion)
|
613
|
+
retenciones.add_child(retencion_child)
|
614
|
+
impuestos.add_child(retenciones)
|
615
|
+
comprobante['Total'] = (suma_total - suma_ret).round(2).to_s
|
571
616
|
else
|
572
617
|
comprobante['Total'] = suma_total.round(2).to_s
|
573
618
|
end
|
574
|
-
|
575
|
-
# comprobante['Total'] = suma_total.round(2).to_s
|
576
619
|
|
577
|
-
|
620
|
+
|
621
|
+
## filling traslado info
|
622
|
+
traslado_child = Nokogiri::XML::Node.new "cfdi:Traslado", xml
|
623
|
+
traslado_child['Impuesto'] = '002'
|
624
|
+
traslado_child['TipoFactor'] = 'Tasa'
|
625
|
+
traslado_child['TasaOCuota'] = '0.160000'
|
626
|
+
traslado_child['Importe'] = suma_iva.round(2).to_s
|
627
|
+
traslados.add_child(traslado_child)
|
628
|
+
impuestos.add_child(traslados)
|
629
|
+
|
630
|
+
|
631
|
+
|
632
|
+
# puts '------ Totales -----'
|
633
|
+
# puts "Total suma = #{comprobante['Total']}"
|
634
|
+
# puts "SubTotal suma = #{subtotal}"
|
635
|
+
# puts "Suma iva = #{suma_iva}"
|
636
|
+
# puts "Suma retenciones = #{impuestos['TotalImpuestosRetenidos']}" if suma_ret > 0
|
637
|
+
|
638
|
+
|
578
639
|
|
579
640
|
path = File.join(File.dirname(__FILE__), *%w[.. tmp])
|
580
641
|
id = SecureRandom.hex
|
data/lib/sw_fac/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sw_fac
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.51
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Angel Padilla
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -58,14 +58,14 @@ dependencies:
|
|
58
58
|
requirements:
|
59
59
|
- - '='
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: 1.8
|
61
|
+
version: 1.10.8
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
66
|
- - '='
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: 1.8
|
68
|
+
version: 1.10.8
|
69
69
|
description: Gem used to fetch the Smarter Web API for the mexican billing system
|
70
70
|
(SAT), this gem was builted and is currently used by the team at www.mfactura.ml
|
71
71
|
email:
|