fdis2 0.1.5 → 0.1.34

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: f08eca18abd4e122bd52b1872a23643e52799bdfe6e83ff5d7feffe064a77398
4
- data.tar.gz: 67e0dc7aca8ce98ba37a42d177ce889719cc305742d78586939f3939e3700f4e
3
+ metadata.gz: 98156d327de044116f8ecd1635cb108d647d4a7f21ef24a794f959e5f192dde5
4
+ data.tar.gz: 790237815643c6f4d69ede647f5a7d1932b476f4368dea0083ae65c2300fef58
5
5
  SHA512:
6
- metadata.gz: 7e2c2952b97571935be480f5c757d5a9f335014d3f12397f84422d4089fd9be35f4e39faeb48b70b7ab0e7eb43f861106d453c573c5f4fc0796aafb852f178b0
7
- data.tar.gz: b8be3af2c78dcd24b98e6871390f0154544f52ec10f5166f67c41f3179746a04b6d7d2e55b7cc717c0e07462024ae9bab4b54bb8eda8cacfcddac16905c3f63a
6
+ metadata.gz: 3d18820ba0ae74963e58f01c9964b4e66c6f2ef26c0e9c9c33c69de929eaca216e2d03467a2038810be0dd59ec9b863c5d0b4fe2f4bdbcab9d2cbe02f6a8c3e5
7
+ data.tar.gz: 80491a426bbcdb6ba76cbef09953dcb4e363cfca478c830accc6a16f4c727ea0f73c7d0a11634802e2d5902bd86450155401e3e5a767c17106463ccd23362d7c
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Fdis 0.1.5
1
+ # Fdis 0.1.34
2
2
 
3
- This is a ruby library that helps to interact with the the mexican billing system (SAT).
3
+ This is a ruby library that helps to interact with the Smarted Web API and the mexican billing system (SAT).
4
4
 
5
5
 
6
6
  ## Installation
@@ -8,7 +8,7 @@ This is a ruby library that helps to interact with the the mexican billing syste
8
8
  Add this line to your application's Gemfile:
9
9
 
10
10
  ```ruby
11
- gem 'fdis2'
11
+ gem 'fdis'
12
12
  ```
13
13
 
14
14
  And then execute:
@@ -37,7 +37,7 @@ Initialize a new object with your config arguments
37
37
  production = (Boolean) # environment, optional, default is -false-
38
38
 
39
39
  # The object
40
- obj = Fdis2::Facturacion.new(production_token, development_token, rfc, razon_social, regimen, path_to_key, key_passphrase, path_to_cer, production)
40
+ obj = Fdis::Facturacion.new(production_token, development_token, rfc, razon_social, regimen, path_to_key, key_passphrase, path_to_cer, production)
41
41
  ```
42
42
 
43
43
  ## Development
@@ -1,4 +1,4 @@
1
- module Fdis2
1
+ module Fdis
2
2
  class Config
3
3
  attr_accessor :production_token, :dev_token, :doc_cer_path, :doc_key_path
4
4
  attr_reader :pem, :serial, :cadena, :key_pass, :pem_cadena
@@ -1,5 +1,5 @@
1
1
 
2
- module Fdis2
2
+ module Fdis
3
3
  class Facturacion < Config
4
4
 
5
5
  def comp_pago(params={})
@@ -30,17 +30,16 @@ module Fdis2
30
30
  # ]
31
31
  # }
32
32
 
33
- puts "----- Fdis: Facturacion::com_pago"
34
- puts "--- Fdis: Total venta: #{params[:total]}"
35
- puts "--- Fdis: Monto de pago a procesar: #{params[:monto_pago]}"
36
- puts "--- Fdis: Saldo insoluto anterior: #{params[:saldo_anterior]}"
37
- puts "--- Fdis: Line items: "
33
+ puts "----- Fdis::Facturacion::com_pago"
34
+ puts "--- Fdis:: Total venta: #{params[:total]}"
35
+ puts "--- Fdis:: Monto de pago a procesar: #{params[:monto_pago]}"
36
+ puts "--- Fdis:: Line items: "
38
37
  params[:line_items].each do |line|
39
38
  puts "-- #{line[:monto]}"
40
39
  end
41
40
  lines_total = params[:line_items].inject(0) {|sum, x| sum + x[:monto].to_f}
42
41
 
43
- puts "--- Fdis: Suma de lineas: #{lines_total}"
42
+ puts "--- Fdis::Suma de line_items: #{lines_total}"
44
43
 
45
44
  if (lines_total > params[:total].to_f)
46
45
  raise 'Error Fdis - la suma de los complementos de pago es mayor al total de la venta'
@@ -118,7 +117,7 @@ module Fdis2
118
117
 
119
118
 
120
119
  # totales
121
- total = params[:monto_pago].to_f.abs
120
+ total = params[:monto_pago].to_f
122
121
  iva_id = params.fetch(:tasa_iva, 16)
123
122
 
124
123
  pago_totales = xml.at_xpath("//pago20:Totales")
@@ -163,11 +162,11 @@ module Fdis2
163
162
  child_pago_relacionado['Folio'] = params[:folio]
164
163
  child_pago_relacionado['EquivalenciaDR'] = "1"
165
164
 
166
- saldo_anterior = params[:saldo_anterior].to_f.abs
165
+ saldo_anterior = params[:saldo_anterior].to_f
167
166
 
168
167
  child_pago_relacionado['ImpSaldoAnt'] = saldo_anterior.round(2).to_s
169
168
  child_pago_relacionado['ImpPagado'] = total.round(2).to_s
170
- child_pago_relacionado['ImpSaldoInsoluto'] = (saldo_anterior - total).round(2).abs.to_s
169
+ child_pago_relacionado['ImpSaldoInsoluto'] = (saldo_anterior - total).round(2).to_s
171
170
  child_pago_relacionado['ObjetoImpDR'] = '02'
172
171
 
173
172
  impuestos_dr = Nokogiri::XML::Node.new "pago20:ImpuestosDR", xml
@@ -181,13 +180,13 @@ module Fdis2
181
180
  traslado['TipoFactorDR'] = 'Tasa'
182
181
  traslado['ImpuestoDR'] = '002'
183
182
 
184
- traslado['BaseDR'] = subtotal.round(2).to_s #subtotal
185
- traslado['ImporteDR'] = iva.round(2).to_s # tax
183
+ traslado['BaseDR'] = subtotal.round(4).to_s #subtotal
184
+ traslado['ImporteDR'] = iva.round(4).to_s # tax
186
185
 
187
- traslado_p['BaseP'] = subtotal.round(2).to_s
186
+ traslado_p['BaseP'] = subtotal.round(4).to_s
188
187
  traslado_p['ImpuestoP'] = '002'
189
188
  traslado_p['TipoFactorP'] = 'Tasa'
190
- traslado_p['ImporteP'] = iva.round(2).to_s # tax
189
+ traslado_p['ImporteP'] = iva.round(4).to_s # tax
191
190
 
192
191
  if iva_id == 16
193
192
  traslado['TasaOCuotaDR'] = '0.160000'
@@ -236,7 +235,7 @@ module Fdis2
236
235
  base64_xml = Base64.encode64(xml.to_xml)
237
236
 
238
237
  # haciendo llamada a API
239
- uri = URI("#{Fdis2::UrlPro}/Timbrar40")
238
+ uri = URI("#{Fdis::UrlPro}/Timbrar40")
240
239
  request = Net::HTTP::Post.new(uri)
241
240
  # request.basic_auth(token, "")
242
241
  request.content_type = "application/json"
@@ -331,7 +330,7 @@ module Fdis2
331
330
  # }
332
331
 
333
332
 
334
- uri = URI(Fdis2::UrlCancel)
333
+ uri = URI(Fdis::UrlCancel)
335
334
  request = Net::HTTP::Post.new(uri)
336
335
  request.content_type = "application/json"
337
336
 
@@ -428,7 +427,7 @@ module Fdis2
428
427
  # descripcion: 'Servicio mano de obra',
429
428
  # valor_unitario: 100.00,
430
429
  # descuento: 0.00,
431
- # tax: 16.0 o 0.0,
430
+ # tax_included: true,
432
431
  # retencion_iva: 0, 6, 16
433
432
  # # Optional parameters
434
433
  # },
@@ -469,14 +468,8 @@ module Fdis2
469
468
  comprobante['Serie'] = params.fetch(:series, 'FA').to_s
470
469
  comprobante['Folio'] = params.fetch(:folio).to_s
471
470
  comprobante['Fecha'] = time.to_s
472
- comprobante['MetodoPago'] = params.fetch(:metodo_pago, 'PUE')
473
471
  comprobante['FormaPago'] = params.fetch(:forma_pago, '01')
474
-
475
- if comprobante['MetodoPago'] == 'PPD'
476
- comprobante['FormaPago'] = '99'
477
- end
478
-
479
-
472
+ comprobante['MetodoPago'] = params.fetch(:metodo_pago, 'PUE')
480
473
  comprobante['LugarExpedicion'] = params.fetch(:cp, '47180')
481
474
  comprobante['NoCertificado'] = @serial
482
475
  comprobante['Certificado'] = @cadena
@@ -520,10 +513,9 @@ module Fdis2
520
513
  suma_iva = 0.00
521
514
  suma_ret = 0.00
522
515
 
523
-
524
- line_items.each do |line|
525
- iva_id = line.fetch(:tax, 16.0)
516
+ iva_id = params.fetch(:tasa_iva, 16)
526
517
 
518
+ line_items.each do |line|
527
519
  ret_iva = line.fetch(:retencion_iva, 0)
528
520
 
529
521
  cantidad = line[:cantidad].to_f
@@ -540,23 +532,17 @@ module Fdis2
540
532
 
541
533
  total_acumulator = cantidad * line[:valor_unitario].to_f
542
534
 
543
- if iva_id > 0
544
- tax_factor = (iva_id / 100) + 1
545
- valor_unitario = (line[:valor_unitario].to_f) / tax_factor
535
+ if iva_id == 16
536
+ valor_unitario = (line[:valor_unitario].to_f) / 1.16
546
537
  else
547
538
  valor_unitario = line[:valor_unitario].to_f
548
539
  end
549
540
 
550
- # if iva_id == 16
551
- # valor_unitario = (line[:valor_unitario].to_f) / 1.16
552
- # else
553
- # valor_unitario = line[:valor_unitario].to_f
554
- # end
541
+ total_line = cantidad * valor_unitario
555
542
 
556
- subtotal_line = cantidad * valor_unitario
557
- importe_iva = total_acumulator - subtotal_line
543
+ importe_iva = total_acumulator - total_line
558
544
 
559
- subtotal += subtotal_line
545
+ subtotal += total_line
560
546
  suma_iva += importe_iva
561
547
  suma_total += total_acumulator
562
548
 
@@ -564,7 +550,7 @@ module Fdis2
564
550
  ## calculando retencion de IVA en caso de tener
565
551
  if ret_iva > 0
566
552
  if ret_iva == 6
567
- importe_ret_linea = (subtotal_line * 1.06) - subtotal_line
553
+ importe_ret_linea = (total_line * 1.06) - total_line
568
554
  elsif ret_iva == 16
569
555
  importe_ret_linea = importe_iva
570
556
  end
@@ -584,7 +570,7 @@ module Fdis2
584
570
  child_concepto['Descripcion'] = line[:descripcion].to_s
585
571
  child_concepto['Cantidad'] = cantidad.to_s
586
572
  child_concepto['ValorUnitario'] = valor_unitario.round(4).to_s
587
- child_concepto['Importe'] = subtotal_line.round(4).to_s
573
+ child_concepto['Importe'] = total_line.round(4).to_s
588
574
  child_concepto['ObjetoImp'] = '02'
589
575
 
590
576
 
@@ -598,15 +584,14 @@ module Fdis2
598
584
  child_traslado = Nokogiri::XML::Node.new "cfdi:Traslado", xml
599
585
  child_traslado['Impuesto'] = '002'
600
586
  child_traslado['TipoFactor'] = "Tasa"
601
- child_traslado['Base'] = subtotal_line.round(4).to_s
587
+ child_traslado['Base'] = total_line.round(4).to_s
602
588
 
603
- if iva_id > 0
604
- tasa_cuota = (iva_id / 100).round(6)
605
- child_traslado['Importe'] = importe_iva.round(4).to_s
606
- child_traslado['TasaOCuota'] = tasa_cuota.to_s
607
- else
589
+ if iva_id == 0
608
590
  child_traslado['Importe'] = "0.00"
609
591
  child_traslado['TasaOCuota'] = '0.000000'
592
+ else
593
+ child_traslado['Importe'] = importe_iva.round(4).to_s
594
+ child_traslado['TasaOCuota'] = '0.160000'
610
595
  end
611
596
 
612
597
 
@@ -620,7 +605,7 @@ module Fdis2
620
605
  if ret_iva > 0
621
606
  child_retenciones = Nokogiri::XML::Node.new "cfdi:Retenciones", xml
622
607
  child_retencion = Nokogiri::XML::Node.new "cfdi:Retencion", xml
623
- child_retencion['Base'] = subtotal_line.round(4).to_s
608
+ child_retencion['Base'] = total_line.round(4).to_s
624
609
  child_retencion['Impuesto'] = '002'
625
610
  child_retencion['TipoFactor'] = "Tasa"
626
611
 
@@ -649,13 +634,13 @@ module Fdis2
649
634
  comprobante['SubTotal'] = subtotal.round(2).to_s
650
635
 
651
636
 
652
- ## Poblando cfdi:Impuestos
637
+ ## Poblanco cfdi:Impuestos
653
638
  impuestos['TotalImpuestosRetenidos'] = suma_ret.round(2).to_s if suma_ret > 0
654
639
 
655
- if suma_iva > 0
656
- impuestos['TotalImpuestosTrasladados'] = suma_iva.round(2).to_s
657
- else
640
+ if iva_id == 0
658
641
  impuestos['TotalImpuestosTrasladados'] = "0.00"
642
+ else
643
+ impuestos['TotalImpuestosTrasladados'] = suma_iva.round(2).to_s
659
644
  end
660
645
 
661
646
 
@@ -681,12 +666,12 @@ module Fdis2
681
666
  traslado_child['TipoFactor'] = 'Tasa'
682
667
  traslado_child['Base'] = subtotal.round(2)
683
668
 
684
- if suma_iva > 0
685
- traslado_child['Importe'] = suma_iva.round(2).to_s
686
- traslado_child['TasaOCuota'] = '0.160000'
687
- else
669
+ if iva_id == 0
688
670
  traslado_child['Importe'] = "0.00"
689
671
  traslado_child['TasaOCuota'] = '0.000000'
672
+ else
673
+ traslado_child['Importe'] = suma_iva.round(2).to_s
674
+ traslado_child['TasaOCuota'] = '0.160000'
690
675
  end
691
676
 
692
677
  traslados.add_child(traslado_child)
@@ -717,7 +702,7 @@ module Fdis2
717
702
  base64_xml = Base64.encode64(xml.to_xml)
718
703
 
719
704
  # haciendo llamada a API
720
- uri = URI("#{Fdis2::UrlPro}/Timbrar40")
705
+ uri = URI("#{Fdis::UrlPro}/Timbrar40")
721
706
  request = Net::HTTP::Post.new(uri)
722
707
  request.content_type = "application/json"
723
708
  request.body = JSON.dump({
@@ -0,0 +1,3 @@
1
+ module Fdis
2
+ VERSION = "0.1.34"
3
+ end
@@ -1,6 +1,6 @@
1
- require "fdis2/version"
2
- require "fdis2/config"
3
- require "fdis2/facturacion"
1
+ require "fdis/version"
2
+ require "fdis/config"
3
+ require "fdis/facturacion"
4
4
 
5
5
  require 'openssl'
6
6
  require 'net/http'
@@ -12,6 +12,6 @@ require 'fileutils'
12
12
  # External gems
13
13
  require 'nokogiri'
14
14
 
15
- module Fdis2
15
+ module Fdis
16
16
 
17
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fdis2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.34
5
5
  platform: ruby
6
6
  authors:
7
7
  - Angel Padilla
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-11-23 00:00:00.000000000 Z
11
+ date: 2023-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,10 +113,10 @@ files:
113
113
  - lib/cadena/valesdedespensa.xslt
114
114
  - lib/cadena/vehiculousado.xslt
115
115
  - lib/cadena/ventavehiculos11.xslt
116
- - lib/fdis2.rb
117
- - lib/fdis2/config.rb
118
- - lib/fdis2/facturacion.rb
119
- - lib/fdis2/version.rb
116
+ - lib/fdis.rb
117
+ - lib/fdis/config.rb
118
+ - lib/fdis/facturacion.rb
119
+ - lib/fdis/version.rb
120
120
  homepage: https://github.com/angelpadilla/fdis2
121
121
  licenses:
122
122
  - MIT
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
139
  requirements: []
140
- rubygems_version: 3.1.6
140
+ rubygems_version: 3.4.6
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: Gem used to fetch the CFDIS Web API
data/lib/fdis2/version.rb DELETED
@@ -1,3 +0,0 @@
1
- module Fdis2
2
- VERSION = "0.1.5"
3
- end