Class: Cpro::Entities::Facture

Inherits:
Base
  • Object
show all
Defined in:
lib/cpro/entities/facture.rb

Constant Summary collapse

STATUTS =
%w[
  DEPOSEE RECUE_DE_LA_PLATEFORME REFUSEE PAIEMENT_TRANSMIS ENCAISSEE REJETEE ANNULEE
  EMISE_PAR_LA_PLATEFORME MISE_A_DISPOSITION PRISE_EN_CHARGE APPROUVEE APPROUVEE_PARTIELLEMENT
  EN_LITIGE SUSPENDUE COMPLETEE VISEE ERREUR_ROUTAGE DEMANDE_DE_PAIEMENT_DIRECT
  CHANGEMENT_DE_COMPTE_A_PAYER NON_AFFACTUREE AFFACTUREE AFFACTUREE_CONFIDENTIEL
].freeze
CHAMPS =
{
  uid: "uidFacture",
  numero: "numeroFacture",
  code_type: "codeTypeFacture",
  devise: "codeDeviseFacture",
  objet: "idObjetFacture",
  type_processus_metier: "typeProcessusMetier",
  numero_facture_anterieure: "numeroFactureAnterieure",
  raison_sociale_vendeur: "raisonSocialeVendeur",
  siren_vendeur: "sirenVendeur",
  siret_vendeur: "siretVendeur",
  raison_sociale_agent_vendeur: "raisonSocialeAgentVendeur",
  siren_agent_vendeur: "sirenAgentVendeur",
  siret_agent_vendeur: "siretAgentVendeur",
  raison_sociale_acheteur: "raisonSocialeAcheteur",
  siren_acheteur: "sirenAcheteur",
  siret_acheteur: "siretAcheteur",
  id_adressage_acheteur: "idAdressageAcheteur",
  siren_tiers_facturant: "sirenTiersFacturant",
  siret_tiers_facturant: "siretTiersFacturant",
  statut: "statutFacture",
  nom_flux: "nomFlux",
  uid_facture_principale: "uidFacturePrincipale"
}.freeze
MONTANTS =
{
  montant_total: "montantTotal",
  montant_total_hors_tva: "montantTotalHorsTVA",
  montant_tva: "montantTVA",
  montant_paye: "montantPaye",
  montant_a_payer: "montantAPayer"
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#payload

Instance Method Summary collapse

Methods inherited from Base

#==, #hash, #to_h

Constructor Details

#initialize(payload = nil, historique: nil) ⇒ Facture

Returns a new instance of Facture.



50
51
52
53
# File 'lib/cpro/entities/facture.rb', line 50

def initialize(payload = nil, historique: nil)
  super(payload)
  @historique_payload = historique
end

Instance Method Details

#date_echeanceObject



59
60
61
# File 'lib/cpro/entities/facture.rb', line 59

def date_echeance
  @date_echeance ||= parse_date(payload["dateEcheanceFacture"])
end

#date_emissionObject



55
56
57
# File 'lib/cpro/entities/facture.rb', line 55

def date_emission
  @date_emission ||= parse_date(payload["dateEmissionFacture"])
end

#date_statutObject



63
64
65
# File 'lib/cpro/entities/facture.rb', line 63

def date_statut
  @date_statut ||= parse_time(payload["dateStatutFacture"])
end

#historiqueObject

Renseigné par Factures#find seulement : la recherche ne retourne pas l'historique.



72
73
74
# File 'lib/cpro/entities/facture.rb', line 72

def historique
  @historique ||= Array(@historique_payload).map { |changement| ChangementStatut.new(changement) }
end

#motifs_rejetObject



76
77
78
# File 'lib/cpro/entities/facture.rb', line 76

def motifs_rejet
  historique.flat_map(&:motifs_rejet)
end

#multivendeurs?Boolean

Returns:

  • (Boolean)


67
68
69
# File 'lib/cpro/entities/facture.rb', line 67

def multivendeurs?
  payload["factureMultivendeurs"]
end

#to_sObject



80
81
82
# File 'lib/cpro/entities/facture.rb', line 80

def to_s
  [numero, statut].compact.join(" ")
end