sw_fac 0.3.45 → 0.3.55

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2eea41bdba37ef2f3ce75347eb8b3ebd00cc43d1f567ef8eb303f967c966493d
4
- data.tar.gz: 2f17be162ce59e857ffb6d3d96a35a16f8aefd9e1407330d2572211477feb792
3
+ metadata.gz: 876b881e7fc870771dd0217a9ba092c0c5b488548b4ae17fb7ee54f2c41da3ea
4
+ data.tar.gz: 07f02855d6c1cfd38401cce9f07e5b2eddd4929caa2572b1001c177f45a6f1c7
5
5
  SHA512:
6
- metadata.gz: 57232fff97ecfeea4de8b6a0dac722f90330a38bfee01c86f4df10aa420cad7e620f83b6e63ce2f6072cb54aa98678d2d39d749b6e26dd2ed32271cc3a01bf00
7
- data.tar.gz: 0fcd1ac24871aecb53a5c95e2b34a52cd2555754e0f82acc51386ec857a88ef56183493a154da11cee1d27e8f48bdf54e6522d0ed157c90cd65d28e151669d4d
6
+ metadata.gz: f6e9ec4a4b6c140c855b972b1f1ec122aaf5d892ec1ff2450d73fd384140a10cddec9bbf8bf06f239397b0201047540f7a60314d142d82d82adbc34120a430e7
7
+ data.tar.gz: '08b029ec32d8d132f42bfabd32a1686fc6f8556843bc1af2504ea2e886be107f1b6345374a33fd8d90bdd9eba0b156dacb7cbecda72b6ec2bc4150ae7dae099b'
@@ -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><cfdi:Traslados><cfdi:Traslado Impuesto="002" TipoFactor="Tasa" TasaOCuota="0.160000" /></cfdi:Traslados></cfdi:Impuestos></cfdi:Comprobante>)
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
 
@@ -79,7 +79,7 @@ module SwFac
79
79
  child_pago['MonedaP'] = params.fetch(:moneda, 'MXN')
80
80
  child_pago['Monto'] = params[:total].round(2).to_s
81
81
 
82
- saldo_anterior = params[:total].to_f
82
+ saldo_anterior = params[:total].to_s
83
83
 
84
84
  params[:line_items].each_with_index do |line, index|
85
85
  monto = line[:monto].to_f
@@ -89,9 +89,9 @@ module SwFac
89
89
  child_pago_relacionado['MetodoDePagoDR'] = 'PPD'
90
90
  child_pago_relacionado['NumParcialidad'] = (index + 1).to_s
91
91
 
92
- child_pago_relacionado['ImpSaldoAnt'] = (saldo_anterior).to_s
92
+ child_pago_relacionado['ImpSaldoAnt'] = (saldo_anterior).round(2).to_s
93
93
  child_pago_relacionado['ImpPagado'] = monto.round(2).to_s
94
- child_pago_relacionado['ImpSaldoInsoluto'] = (saldo_anterior - monto).to_s
94
+ child_pago_relacionado['ImpSaldoInsoluto'] = (saldo_anterior - monto).round(2).to_s
95
95
  saldo_anterior -= monto
96
96
 
97
97
  child_pago.add_child(child_pago_relacionado)
@@ -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
- traslado = xml.at_xpath("//cfdi:Traslado")
466
+ traslados = Nokogiri::XML::Node.new "cfdi:Traslados", xml
466
467
 
467
468
 
468
469
  puts '--- sw_fac time -----'
@@ -476,36 +477,58 @@ 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
- descuento = line.fetch(:descuento, 0.00).to_f
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
- unitario = (line[:valor_unitario].to_f) - descuento
486
- else
487
- unitario = ((line[:valor_unitario]).to_f - descuento) / 1.16
488
- end
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
- unitario = (line[:valor_unitario].to_f) - descuento
497
+ valor_unitario = (line[:valor_unitario].to_f)
491
498
  end
492
499
 
493
500
  cantidad = line[:cantidad].to_f
494
- total_line = cantidad * unitario
501
+ total_line = cantidad * valor_unitario
495
502
 
496
- if line[:tipo_impuesto] == '004'
497
- total_acumulator = cantidad * unitario
498
- else
499
- total_acumulator = cantidad * unitario * 1.16
500
- end
501
-
502
- importe_iva = total_acumulator - total_line
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
+ puts "--- 01"
517
+ ## calculando retencion de IVA en caso de tener
518
+ if ret_iva > 0
519
+ if ret_iva == 6
520
+ importe_ret_linea = (total_line * 1.06) - total_line
521
+ elsif ret_iva == 16
522
+ importe_ret_linea = importe_iva
523
+ end
524
+ else
525
+ importe_ret_linea = 0
526
+ end
527
+ puts "--- 02"
528
+ suma_ret += importe_ret_linea
529
+
508
530
 
531
+ ## Creando y poblando CFDI:CONCEPTO
509
532
  child_concepto = Nokogiri::XML::Node.new "cfdi:Concepto", xml
510
533
  child_concepto['ClaveProdServ'] = line[:clave_prod_serv].to_s
511
534
  child_concepto['NoIdentificacion'] = line[:sku].to_s
@@ -513,68 +536,107 @@ module SwFac
513
536
  child_concepto['Unidad'] = line[:unidad].to_s
514
537
  child_concepto['Descripcion'] = line[:descripcion].to_s
515
538
  child_concepto['Cantidad'] = cantidad.to_s
516
- child_concepto['ValorUnitario'] = unitario.round(6).to_s
517
- child_concepto['Importe'] = total_line.round(6).to_s
539
+ child_concepto['ValorUnitario'] = valor_unitario.round(4).to_s
540
+ child_concepto['Importe'] = total_line.round(4).to_s
518
541
  # child_concepto['Descuento'] = line.fetch(:descuento, 0.00).round(6).to_s
519
542
 
543
+
544
+ ## Creando cdfi:Impuestos para cada linea
520
545
  child_impuestos = Nokogiri::XML::Node.new "cfdi:Impuestos", xml
546
+
547
+ ## Creando cfdi:Traslados para cada linea
521
548
  child_traslados = Nokogiri::XML::Node.new "cfdi:Traslados", xml
522
549
  child_traslado = Nokogiri::XML::Node.new "cfdi:Traslado", xml
523
- child_traslado['Base'] = total_line.round(6).to_s
550
+ child_traslado['Base'] = total_line.round(4).to_s
524
551
  child_traslado['Impuesto'] = '002'
525
552
  child_traslado['TipoFactor'] = "Tasa"
553
+ child_traslado['TasaOCuota'] = '0.160000'
554
+ child_traslado['Importe'] = importe_iva.round(4).to_s
526
555
 
527
- if line[:tipo_impuesto] == '004'
528
- child_traslado['TasaOCuota'] = '0.000000'
529
- else
530
- child_traslado['TasaOCuota'] = '0.160000'
531
- end
556
+ # if line[:tipo_impuesto] == '004'
557
+ # child_traslado['TasaOCuota'] = '0.000000'
558
+ # else
559
+ # end
532
560
 
533
561
 
534
- child_traslado['Importe'] = importe_iva.round(6).to_s
535
-
536
562
  # Joining all up
537
563
  child_traslados.add_child(child_traslado)
538
564
  child_impuestos.add_child(child_traslados)
539
565
  child_concepto.add_child(child_impuestos)
540
-
541
566
  conceptos.add_child(child_concepto)
567
+
568
+ ## Creando cfdi:Retenciones para cada linea en caso de tener
569
+ if ret_iva > 0
570
+ child_retenciones = Nokogiri::XML::Node.new "cfdi:Retenciones", xml
571
+ child_retencion = Nokogiri::XML::Node.new "cfdi:Retencion", xml
572
+ child_retencion['Base'] = total_line.round(4).to_s
573
+ child_retencion['Impuesto'] = '002'
574
+ child_retencion['TipoFactor'] = "Tasa"
542
575
 
543
- end
576
+ if ret_iva == 6
577
+ child_retencion['TasaOCuota'] = "0.060000"
578
+ elsif ret_iva == 16
579
+ child_retencion['TasaOCuota'] = "0.160000"
580
+ end
581
+
582
+ child_retencion['Importe'] = importe_ret_linea.round(4).to_s
544
583
 
545
- # puts '------ Line -----'
546
- # puts "Total suma = #{suma_total}"
547
- # puts "SubTotal suma = #{subtotal}"
548
- # puts "Suma iva = #{suma_iva}"
584
+ child_retenciones.add_child(child_retencion)
585
+ child_impuestos.add_child(child_retenciones)
586
+ end
549
587
 
550
588
 
589
+
590
+ end
591
+
592
+ puts '------ Totales -----'
593
+ puts "Total suma = #{suma_total.round(2)}"
594
+ puts "SubTotal suma = #{subtotal.round(2)}"
595
+ puts "Suma iva = #{suma_iva.round(2)}"
596
+ puts "Suma restenciones = #{suma_ret.round(2)}"
597
+
551
598
  comprobante['Moneda'] = params.fetch(:moneda, 'MXN')
552
599
  comprobante['SubTotal'] = subtotal.round(2).to_s
553
- impuestos['TotalImpuestosTrasladados'] = suma_iva.round(2).to_s
554
600
 
555
601
 
556
- ### en caso de retencion de IVA
557
- if params[:retencion_iva]
558
- retencion = Nokogiri::XML::Node.new "cfdi:Retenciones", xml
559
- retencion_child = Nokogiri::XML::Node.new "cfdi:Retencion", xml
602
+ ## Poblanco cfdi:Impuestos
603
+ impuestos['TotalImpuestosRetenidos'] = suma_ret.round(2).to_s if suma_ret > 0
604
+ impuestos['TotalImpuestosTrasladados'] = suma_iva.round(2).to_s
560
605
 
561
- # retencion = xml.at_xpath("//cfdi:Retencion")
606
+ ## filling default retencion info
607
+ if suma_ret > 0
608
+ retenciones = Nokogiri::XML::Node.new "cfdi:Retenciones", xml
609
+ retencion_child = Nokogiri::XML::Node.new "cfdi:Retencion", xml
562
610
  retencion_child['Impuesto'] = "002"
563
- retencion_child['Importe'] = suma_iva.round(2).to_s
611
+ retencion_child['Importe'] = suma_ret.round(2).to_s
612
+ # retencion_child['TipoFactor'] = "Tasa"
564
613
 
565
- comprobante['Total'] = subtotal.round(2).to_s
566
- impuestos['TotalImpuestosRetenidos'] = suma_iva.round(2).to_s
567
-
568
-
569
- retencion.add_child(retencion_child)
570
- impuestos.add_child(retencion)
614
+ retenciones.add_child(retencion_child)
615
+ impuestos.add_child(retenciones)
616
+ comprobante['Total'] = (suma_total - suma_ret).round(2).to_s
571
617
  else
572
618
  comprobante['Total'] = suma_total.round(2).to_s
573
619
  end
574
-
575
- # comprobante['Total'] = suma_total.round(2).to_s
576
620
 
577
- traslado['Importe'] = suma_iva.round(2).to_s
621
+
622
+ ## filling traslado info
623
+ traslado_child = Nokogiri::XML::Node.new "cfdi:Traslado", xml
624
+ traslado_child['Impuesto'] = '002'
625
+ traslado_child['TipoFactor'] = 'Tasa'
626
+ traslado_child['TasaOCuota'] = '0.160000'
627
+ traslado_child['Importe'] = suma_iva.round(2).to_s
628
+ traslados.add_child(traslado_child)
629
+ impuestos.add_child(traslados)
630
+
631
+
632
+
633
+ # puts '------ Totales -----'
634
+ # puts "Total suma = #{comprobante['Total']}"
635
+ # puts "SubTotal suma = #{subtotal}"
636
+ # puts "Suma iva = #{suma_iva}"
637
+ # puts "Suma retenciones = #{impuestos['TotalImpuestosRetenidos']}" if suma_ret > 0
638
+
639
+
578
640
 
579
641
  path = File.join(File.dirname(__FILE__), *%w[.. tmp])
580
642
  id = SecureRandom.hex
@@ -1,3 +1,3 @@
1
1
  module SwFac
2
- VERSION = "0.3.45"
2
+ VERSION = "0.3.55"
3
3
  end
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.45
4
+ version: 0.3.55
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angel Padilla
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-07-05 00:00:00.000000000 Z
11
+ date: 2020-07-30 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.2
61
+ version: 1.10.9
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.2
68
+ version: 1.10.9
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: