diff --git a/choruspro.go b/choruspro.go index 8ee4cf4..d9f2ea7 100644 --- a/choruspro.go +++ b/choruspro.go @@ -220,19 +220,3 @@ func getOAuthToken(clientId, clientSecret string, authUrl *url.URL) (*oauth2.Tok return tok, nil } - -// Bool is a helper routine that allocates a new bool value -// to store v and returns a pointer to it. -func Bool(v bool) *bool { return &v } - -// Int is a helper routine that allocates a new int value -// to store v and returns a pointer to it. -func Int(v int) *int { return &v } - -// Int64 is a helper routine that allocates a new int64 value -// to store v and returns a pointer to it. -func Int64(v int64) *int64 { return &v } - -// String is a helper routine that allocates a new string value -// to store v and returns a pointer to it. -func String(v string) *string { return &v } diff --git a/choruspro_test.go b/choruspro_test.go index ab3da15..2568194 100644 --- a/choruspro_test.go +++ b/choruspro_test.go @@ -19,9 +19,10 @@ const ( ) var ( - defaultDate = time.Date(2023, 01, 01, 0, 0, 0, 0, time.UTC) - defaultDateStr = `"2023-01-01"` - defaultDateTimeStr = `"2023-01-01T00:00:00Z"` + defaultDate = time.Date(2023, 01, 01, 0, 0, 0, 0, time.UTC) + defaultDateStr = `"2023-01-01"` + defaultISODateTimeStr = `"2023-01-01T00:00:00Z"` + defaultDateTimeStr = `"2023-01-01 00:00"` ) func setup() (client *Client, mux *http.ServeMux, teardown func()) { diff --git a/date.go b/date.go index a010abf..d2b0bec 100644 --- a/date.go +++ b/date.go @@ -13,3 +13,13 @@ func (t *Date) UnmarshalJSON(data []byte) error { t.Time, err = time.Parse("\"2006-01-02\"", string(data)) return err } + +type Datetime struct { + time.Time +} + +func (t *Datetime) UnmarshalJSON(data []byte) error { + var err error + t.Time, err = time.Parse("\"2006-01-02 15:04\"", string(data)) + return err +} diff --git a/factures.go b/factures.go index 8771555..24d32fe 100644 --- a/factures.go +++ b/factures.go @@ -62,3 +62,24 @@ const ( TypeFactureAvoir TypeFacture = "AVOIR" TypeFactureAcompte TypeFacture = "ACOMPTE" ) + +type TypeTva string + +const ( + TypeTvaSurDebit TypeTva = "TVA_SUR_DEBIT" + TypeTvaSurEncaissement TypeTva = "TVA_SUR_ENCAISSEMENT" + TypeTvaExoneration TypeTva = "EXONERATION" + TypeTvaSansTva TypeTva = "SANS_TVA" +) + +type TypeIdentifiant string + +const ( + TypeIdentifiantSiret TypeIdentifiant = "SIRET" + TypeIdentifiantUEHorsFrance TypeIdentifiant = "UE_HORS_FRANCE" + TypeIdentifiantHorsUE TypeIdentifiant = "HORS_UE" + TypeIdentifiantRidet TypeIdentifiant = "RIDET" + TypeIdentifiantTahiti TypeIdentifiant = "TAHITI" + TypeIdentifiantAutre TypeIdentifiant = "AUTRE" + TypeIdentifiantParticulier TypeIdentifiant = "PARTICULIER" +) diff --git a/factures_consultations.go b/factures_consultations.go index 54c0276..cde4dfc 100644 --- a/factures_consultations.go +++ b/factures_consultations.go @@ -5,7 +5,7 @@ import ( "net/http" ) -type ConsulterFactureRecipiendaireOptions struct { +type ConsulterFactureOptions struct { CodeLangue CodeLangue `json:"codeLangue,omitempty"` IdUtilisateurCourant int `json:"idUtilisateurCourant,omitempty"` IdentifiantFactureCPP int `json:"identifiantFactureCPP,omitempty"` @@ -15,48 +15,48 @@ type ConsulterFactureRecipiendaireOptions struct { } type CadreDeFacturation struct { - Code CadreFac `json:"codeCadreFacturation,omitempty"` - CodeServiceMoa string `json:"codeServiceMoa,omitempty"` - CodeServiceMoe string `json:"codeServiceMoe,omitempty"` - CodeValideur1 string `json:"codeValideur1,omitempty"` - CodeValideur2 string `json:"codeValideur2,omitempty"` - DateValidation1 *Date `json:"dateValidation1,omitempty"` - DateValidation2 *Date `json:"dateValidation2,omitempty"` - DesignationMoa string `json:"designationMoa,omitempty"` - DesignationMoe string `json:"designationMoe,omitempty"` - DesignationValideur2 string `json:"designationValideur2,omitempty"` - IdMoa int64 `json:"idMoa,omitempty"` - IdMoe int64 `json:"idMoe,omitempty"` - IdServiceMoa int64 `json:"idServiceMoa,omitempty"` - IdServiceMoe int64 `json:"idServiceMoe,omitempty"` - IdValideur1 int64 `json:"idValideur1,omitempty"` - IdValideur2 int64 `json:"idValideur2,omitempty"` - IdentifiantMoa string `json:"identifiantMoa,omitempty"` - IdentifiantMoe string `json:"identifiantMoe,omitempty"` - NomMoe string `json:"nomMoe,omitempty"` - NomServiceMoa string `json:"nomServiceMoa,omitempty"` - NomServiceMoe string `json:"nomServiceMoe,omitempty"` - NomValideur1 string `json:"nomValideur1,omitempty"` - NomValideur2 string `json:"nomValideur2,omitempty"` - PrenomMoe string `json:"prenomMoe,omitempty"` - PrenomValideur1 string `json:"prenomValideur1,omitempty"` - PrenomValideur2 string `json:"prenomValideur2,omitempty"` - RaisonSocialeMoa string `json:"raisonSocialeMoa,omitempty"` - RaisonSocialeMoe string `json:"raisonSocialeMoe,omitempty"` - RaisonSocialeValideur1 string `json:"raisonSocialeValideur1,omitempty"` - RaisonSocialeValideur2 string `json:"raisonSocialeValideur2,omitempty"` - TypeIdentifiantMoa string `json:"typeIdentifiantMoa,omitempty"` - TypeIdentifiantMoe string `json:"typeIdentifiantMoe,omitempty"` - TypeIdentifiantValideur1 string `json:"typeIdentifiantValideur1,omitempty"` - TypeIdentifiantValideur2 string `json:"typeIdentifiantValideur2,omitempty"` + Code CadreFac `json:"codeCadreFacturation,omitempty"` + CodeServiceMoa string `json:"codeServiceMoa,omitempty"` + CodeServiceMoe string `json:"codeServiceMoe,omitempty"` + CodeValideur1 string `json:"codeValideur1,omitempty"` + CodeValideur2 string `json:"codeValideur2,omitempty"` + DateValidation1 *Date `json:"dateValidation1,omitempty"` + DateValidation2 *Date `json:"dateValidation2,omitempty"` + DesignationMoa string `json:"designationMoa,omitempty"` + DesignationMoe string `json:"designationMoe,omitempty"` + DesignationValideur2 string `json:"designationValideur2,omitempty"` + IdMoa int64 `json:"idMoa,omitempty"` + IdMoe int64 `json:"idMoe,omitempty"` + IdServiceMoa int64 `json:"idServiceMoa,omitempty"` + IdServiceMoe int64 `json:"idServiceMoe,omitempty"` + IdValideur1 int64 `json:"idValideur1,omitempty"` + IdValideur2 int64 `json:"idValideur2,omitempty"` + IdentifiantMoa string `json:"identifiantMoa,omitempty"` + IdentifiantMoe string `json:"identifiantMoe,omitempty"` + NomMoe string `json:"nomMoe,omitempty"` + NomServiceMoa string `json:"nomServiceMoa,omitempty"` + NomServiceMoe string `json:"nomServiceMoe,omitempty"` + NomValideur1 string `json:"nomValideur1,omitempty"` + NomValideur2 string `json:"nomValideur2,omitempty"` + PrenomMoe string `json:"prenomMoe,omitempty"` + PrenomValideur1 string `json:"prenomValideur1,omitempty"` + PrenomValideur2 string `json:"prenomValideur2,omitempty"` + RaisonSocialeMoa string `json:"raisonSocialeMoa,omitempty"` + RaisonSocialeMoe string `json:"raisonSocialeMoe,omitempty"` + RaisonSocialeValideur1 string `json:"raisonSocialeValideur1,omitempty"` + RaisonSocialeValideur2 string `json:"raisonSocialeValideur2,omitempty"` + TypeIdentifiantMoa TypeIdentifiant `json:"typeIdentifiantMoa,omitempty"` + TypeIdentifiantMoe TypeIdentifiant `json:"typeIdentifiantMoe,omitempty"` + TypeIdentifiantValideur1 TypeIdentifiant `json:"typeIdentifiantValideur1,omitempty"` + TypeIdentifiantValideur2 TypeIdentifiant `json:"typeIdentifiantValideur2,omitempty"` } type Affactureur struct { - Code string `json:"affactureurCode,omitempty"` - CodePays string `json:"affactureurCodePays,omitempty"` - Id int64 `json:"affactureurId,omitempty"` - RaisonSociale string `json:"affactureurRaisonSociale,omitempty"` - TypeIdentifiant string `json:"affactureurTypeIdentifiant,omitempty"` + Code string `json:"affactureurCode,omitempty"` + CodePays string `json:"affactureurCodePays,omitempty"` + Id int64 `json:"affactureurId,omitempty"` + RaisonSociale string `json:"affactureurRaisonSociale,omitempty"` + TypeIdentifiant TypeIdentifiant `json:"affactureurTypeIdentifiant,omitempty"` } type PieceJointeFacture struct { @@ -130,7 +130,7 @@ type PieceSuivante struct { type References struct { CodeDevise string `json:"codeDeviseFacture,omitempty"` - DateCreationFacture *Date `json:"dateCreationFacture,omitempty"` + DateCreationFacture *Datetime `json:"dateCreationFacture,omitempty"` DateDepot *Date `json:"dateDepot,omitempty"` DateEcheancePaiement *Date `json:"dateEcheancePaiement,omitempty"` DateFacture *Date `json:"dateFacture,omitempty"` @@ -145,7 +145,7 @@ type References struct { TailleTotalePiecesJointes float32 `json:"tailleTotalePiecesJointes,omitempty"` TypeFacture TypeFacture `json:"typeFacture,omitempty"` TypeFactureTravaux string `json:"typeFactureTravaux,omitempty"` - TypeTva string `json:"typeTva,omitempty"` + TypeTva TypeTva `json:"typeTva,omitempty"` } type Destinataire struct { @@ -167,33 +167,33 @@ type Destinataire struct { } type Fournisseur struct { - AdresseCodePays string `json:"adresseFournisseurCodePays,omitempty"` - AdresseCodePostal string `json:"adresseFournisseurCodePostal,omitempty"` - AdresseComplement1 string `json:"adresseFournisseurComplement1,omitempty"` - AdresseComplement2 string `json:"adresseFournisseurComplement2,omitempty"` - AdresseDetail string `json:"adresseFournisseurDetail,omitempty"` - AdresseId int64 `json:"adresseFournisseurId,omitempty"` - AdresseLibellePays string `json:"adresseFournisseurLibellePays,omitempty"` - AdresseVille string `json:"adresseFournisseurVille,omitempty"` - Affactureur Affactureur `json:"affactureur,omitempty"` - Code string `json:"codeFournisseur,omitempty"` - CodeService string `json:"codeServiceFournisseur,omitempty"` - CoordBancairesBicSwift string `json:"coordBancairesBicSwift,omitempty"` - CoordBancairesCodeGuichet string `json:"coordBancairesCodeGuichet,omitempty"` - CoordBancairesCleIban string `json:"coordBancairesFournisseurCleIban,omitempty"` - CoordBancairesCleRib string `json:"coordBancairesFournisseurCleRib,omitempty"` - CoordBancairesCodeBanque string `json:"coordBancairesFournisseurCodeBanque,omitempty"` - CoordBancairesCodePays string `json:"coordBancairesFournisseurCodePays,omitempty"` - CoordBancairesCompteBancaire string `json:"coordBancairesFournisseurCompteBancaire,omitempty"` - CoordBancairesId int64 `json:"coordBancairesFournisseurId,omitempty"` - CoordBancairesLibelle string `json:"coordBancairesFournisseurLibelle,omitempty"` - CoordBancairesType string `json:"coordBancairesFournisseurType,omitempty"` - Designation string `json:"designationFournisseur,omitempty"` - Id int64 `json:"idFournisseur,omitempty"` - IdService int64 `json:"idServiceFournisseur,omitempty"` - LibelleService string `json:"libelleServiceFournisseur,omitempty"` - NumeroRcs string `json:"numeroRcsFournisseur,omitempty"` - TypeIdentifiant string `json:"typeIdentifiantFournisseur,omitempty"` + AdresseCodePays string `json:"adresseFournisseurCodePays,omitempty"` + AdresseCodePostal string `json:"adresseFournisseurCodePostal,omitempty"` + AdresseComplement1 string `json:"adresseFournisseurComplement1,omitempty"` + AdresseComplement2 string `json:"adresseFournisseurComplement2,omitempty"` + AdresseDetail string `json:"adresseFournisseurDetail,omitempty"` + AdresseId int64 `json:"adresseFournisseurId,omitempty"` + AdresseLibellePays string `json:"adresseFournisseurLibellePays,omitempty"` + AdresseVille string `json:"adresseFournisseurVille,omitempty"` + Affactureur Affactureur `json:"affactureur,omitempty"` + Code string `json:"codeFournisseur,omitempty"` + CodeService string `json:"codeServiceFournisseur,omitempty"` + CoordBancairesBicSwift string `json:"coordBancairesBicSwift,omitempty"` + CoordBancairesCodeGuichet string `json:"coordBancairesCodeGuichet,omitempty"` + CoordBancairesCleIban string `json:"coordBancairesFournisseurCleIban,omitempty"` + CoordBancairesCleRib string `json:"coordBancairesFournisseurCleRib,omitempty"` + CoordBancairesCodeBanque string `json:"coordBancairesFournisseurCodeBanque,omitempty"` + CoordBancairesCodePays string `json:"coordBancairesFournisseurCodePays,omitempty"` + CoordBancairesCompteBancaire string `json:"coordBancairesFournisseurCompteBancaire,omitempty"` + CoordBancairesId int64 `json:"coordBancairesFournisseurId,omitempty"` + CoordBancairesLibelle string `json:"coordBancairesFournisseurLibelle,omitempty"` + CoordBancairesType string `json:"coordBancairesFournisseurType,omitempty"` + Designation string `json:"designationFournisseur,omitempty"` + Id int64 `json:"idFournisseur,omitempty"` + IdService int64 `json:"idServiceFournisseur,omitempty"` + LibelleService string `json:"libelleServiceFournisseur,omitempty"` + NumeroRcs string `json:"numeroRcsFournisseur,omitempty"` + TypeIdentifiant TypeIdentifiant `json:"typeIdentifiantFournisseur,omitempty"` } type ListeLignesDePoste struct { @@ -245,7 +245,7 @@ type ConsulterFactureResponse struct { Libelle string `json:"libelle,omitempty"` } -func (s *FacturesService) ConsulterFactureParRecipiendaire(ctx context.Context, opts ConsulterFactureRecipiendaireOptions) (*ConsulterFactureResponse, error) { +func (s *FacturesService) ConsulterFactureParRecipiendaire(ctx context.Context, opts ConsulterFactureOptions) (*ConsulterFactureResponse, error) { req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/consulter/recipiendaire", opts) if err != nil { return nil, err @@ -260,3 +260,139 @@ func (s *FacturesService) ConsulterFactureParRecipiendaire(ctx context.Context, return res, nil } + +func (s *FacturesService) ConsulterFactureParValideur(ctx context.Context, opts ConsulterFactureOptions) (*ConsulterFactureResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/consulter/valideur", opts) + if err != nil { + return nil, err + } + + res := new(ConsulterFactureResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} + +type ConsulterFactureFournisseurOptions struct { + CodeLangue CodeLangue `json:"codeLangue,omitempty"` + IdUtilisateurCourant int `json:"idUtilisateurCourant,omitempty"` + IdentifiantFactureCPP int `json:"identifiantFactureCPP,omitempty"` + PaginationLignesPoste *PaginationLignesPosteOptions `json:"pLignesPoste,omitempty"` + PaginationPiecesJointes *PaginationPiecesJointesOptions `json:"pListePiecesJointes,omitempty"` + PaginationLignesTVA *PaginationLignesRecapTVAOptions `json:"pLigneRecapTva,omitempty"` +} + +func (s *FacturesService) ConsulterFactureParFournisseur(ctx context.Context, opts ConsulterFactureFournisseurOptions) (*ConsulterFactureResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/consulter/fournisseur", opts) + if err != nil { + return nil, err + } + + res := new(ConsulterFactureResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} + +type ConsulterHistoriqueOptions struct { + IdEspace int64 `json:"idEspace"` + IdFacture int64 `json:"idFacture"` + IdUtilisateurCourant int64 `json:"idUtilisateurCourant"` + PaginationHistoActionsUtilisateurs *PaginationHistoActionsUtilisateursOptions `json:"paramRechercheHistoActionsUtilisateurs"` + PaginationHistoEvenementsComplementaires *PaginationHistoEvenementsComplementairesOptions `json:"paramRechercheHistoEvenementsComplementaires"` + PaginationHistoStatuts *PaginationHistoStatutsOptions `json:"paramRechercheHistoStatuts"` +} + +type DerniereAction struct { + Code string `json:"derniereActionCode"` + Id int64 `json:"derniereActionId"` +} + +type HistoAction struct { + Code string `json:"histoActionCode"` + DateHeure *Datetime `json:"histoActionDateHeure"` + Id int32 `json:"histoActionId"` + UtilisateurEmail string `json:"histoActionUtilisateurEmail"` + UtilisateurNom string `json:"histoActionUtilisateurNom"` + UtilisateurPrenom string `json:"histoActionUtilisateurPrenom"` + UtilisateurTelephone string `json:"histoActionUtilisateurTelephone"` +} + +type HistoriquesDesActionsUtilisateurs struct { + HistoAction []HistoAction `json:"histoAction"` + NbResultatsParPageHistoAction int32 `json:"nbResultatsParPageHistoAction"` + PageCouranteHistoAction int32 `json:"pageCouranteHistoAction"` + PagesHistoAction int32 `json:"pagesHistoAction"` + TotalHistoAction int32 `json:"totalHistoAction"` +} + +type Evenement struct { + EvenementDateHeure *Datetime `json:"evenementDateHeure"` + EvenementId int64 `json:"evenementId"` + EvenementLibelle string `json:"evenementLibelle"` + EvenementQui string `json:"evenementQui"` +} + +type HistoriquesDesEvenementsComplementaires struct { + Evenement []Evenement `json:"evenement"` + NbResultatsParPageEvenement int32 `json:"nbResultatsParPageEvenement"` + PageCouranteEvenement int32 `json:"pageCouranteEvenement"` + PagesEvenement int32 `json:"pagesEvenement"` + TotalEvenement int32 `json:"totalEvenement"` +} + +type HistoStatut struct { + Code string `json:"histoStatutCode"` + Commentaire string `json:"histoStatutCommentaire"` + DatePassage *Datetime `json:"histoStatutDatePassage"` + Id int32 `json:"histoStatutId"` + UtilisateurEmail string `json:"histoStatutUtilisateurEmail"` + UtilisateurNom string `json:"histoStatutUtilisateurNom"` + UtilisateurPrenom string `json:"histoStatutUtilisateurPrenom"` + UtilisateurTelephone string `json:"histoStatutUtilisateurTelephone"` +} + +type HistoriquesDesStatuts struct { + HistoStatut []HistoStatut `json:"histoStatut"` + NbResultatsParPageHistoStatut int32 `json:"nbResultatsParPageHistoStatut"` + PageCouranteHistoStatut int32 `json:"pageCouranteHistoStatut"` + PagesHistoStatut int32 `json:"pagesHistoStatut"` + TotalHistoStatut int32 `json:"totalHistoStatut"` +} + +type ConsulterHistoriqueResponse struct { + CodeRetour int32 `json:"codeRetour"` + DerniereAction *DerniereAction `json:"derniereAction"` + HistoriquesDesActionsUtilisateurs *HistoriquesDesActionsUtilisateurs `json:"historiquesDesActionsUtilisateurs"` + HistoriquesDesEvenementsComplementaires *HistoriquesDesEvenementsComplementaires `json:"historiquesDesEvenementsComplementaires"` + HistoriquesDesStatuts *HistoriquesDesStatuts `json:"historiquesDesStatuts"` + IdFacture int64 `json:"idFacture"` + Libelle string `json:"libelle"` + ModeDepot string `json:"modeDepot"` + NumeroFacture string `json:"numeroFacture"` + StatutCourantCode string `json:"statutCourantCode"` +} + +func (s *FacturesService) ConsulterHistorique(ctx context.Context, opts ConsulterHistoriqueOptions) (*ConsulterHistoriqueResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/consulter/historique", opts) + if err != nil { + return nil, err + } + + res := new(ConsulterHistoriqueResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} diff --git a/factures_consultations_test.go b/factures_consultations_test.go index cfe7371..d0d278b 100644 --- a/factures_consultations_test.go +++ b/factures_consultations_test.go @@ -13,7 +13,7 @@ func TestFacturesService_ConsulterFactureParRecipiendaire(t *testing.T) { defer teardown() mux.HandleFunc("/cpro/factures/v1/consulter/recipiendaire", func(w http.ResponseWriter, r *http.Request) { - v := new(ListeTypesPieceJointeOptions) + v := new(ConsulterFactureOptions) assertNilError(t, json.NewDecoder(r.Body).Decode(v)) testMethod(t, r, http.MethodPost) w.Write([]byte(`{ @@ -199,7 +199,7 @@ func TestFacturesService_ConsulterFactureParRecipiendaire(t *testing.T) { }, "references": { "codeDeviseFacture": "c", - "dateCreationFacture": ` + defaultDateStr + `, + "dateCreationFacture": ` + defaultDateTimeStr + `, "dateDepot": ` + defaultDateStr + `, "dateEcheancePaiement": ` + defaultDateStr + `, "dateFacture": ` + defaultDateStr + `, @@ -224,7 +224,7 @@ func TestFacturesService_ConsulterFactureParRecipiendaire(t *testing.T) { }) ctx := context.Background() - opt := ConsulterFactureRecipiendaireOptions{} + opt := ConsulterFactureOptions{} got, err := client.Factures.ConsulterFactureParRecipiendaire(ctx, opt) if err != nil { @@ -414,7 +414,7 @@ func TestFacturesService_ConsulterFactureParRecipiendaire(t *testing.T) { }, References: References{ CodeDevise: "c", - DateCreationFacture: &Date{defaultDate}, + DateCreationFacture: &Datetime{defaultDate}, DateDepot: &Date{defaultDate}, DateEcheancePaiement: &Date{defaultDate}, DateFacture: &Date{defaultDate}, @@ -444,3 +444,1029 @@ func TestFacturesService_ConsulterFactureParRecipiendaire(t *testing.T) { return err }) } + +func TestFacturesService_ConsulterFactureParValideur(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/consulter/valideur", func(w http.ResponseWriter, r *http.Request) { + v := new(ConsulterFactureOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "facture": { + "cadreDeFacturation": { + "codeCadreFacturation": "c", + "codeServiceMoa": "c", + "codeServiceMoe": "c", + "codeValideur1": "c", + "codeValideur2": "c", + "dateValidation1": ` + defaultDateStr + `, + "dateValidation2": ` + defaultDateStr + `, + "designationMoa": "d", + "designationMoe": "d", + "designationValideur2": "d", + "idMoa": 1, + "idMoe": 1, + "idServiceMoa": 1, + "idServiceMoe": 1, + "idValideur1": 1, + "idValideur2": 1, + "identifiantMoa": "i", + "identifiantMoe": "i", + "nomMoe": "n", + "nomServiceMoa": "n", + "nomServiceMoe": "n", + "nomValideur1": "n", + "nomValideur2": "n", + "prenomMoe": "p", + "prenomValideur1": "p", + "prenomValideur2": "p", + "raisonSocialeMoa": "r", + "raisonSocialeMoe": "r", + "raisonSocialeValideur1": "r", + "raisonSocialeValideur2": "r", + "typeIdentifiantMoa": "t", + "typeIdentifiantMoe": "t", + "typeIdentifiantValideur1": "t", + "typeIdentifiantValideur2": "t" + }, + "commentaire": "c", + "destinataire": { + "adresseDestinataireCodePays": "a", + "adresseDestinataireCodePostal": "a", + "adresseDestinataireComplement1": "a", + "adresseDestinataireComplement2": "a", + "adresseDestinataireDetail": "a", + "adresseDestinataireId": 1, + "adresseDestinataireLibellePays": "a", + "adresseDestinataireVille": "a", + "codeDestinataire": "c", + "codeServiceExecutant": "c", + "destinataireEtat": "d", + "idDestinataire": 1, + "idServiceExecutant": 1, + "libelleDestinataire": "l", + "libelleServiceExecutant": "l" + }, + "fournisseur": { + "adresseFournisseurCodePays": "a", + "adresseFournisseurCodePostal": "a", + "adresseFournisseurComplement1": "a", + "adresseFournisseurComplement2": "a", + "adresseFournisseurDetail": "a", + "adresseFournisseurId": 1, + "adresseFournisseurLibellePays": "a", + "adresseFournisseurVille": "a", + "affactureur": { + "affactureurCode": "a", + "affactureurCodePays": "a", + "affactureurId": 1, + "affactureurRaisonSociale": "a", + "affactureurTypeIdentifiant": "a" + }, + "codeFournisseur": "c", + "codeServiceFournisseur": "c", + "coordBancairesBicSwift": "c", + "coordBancairesCodeGuichet": "c", + "coordBancairesFournisseurCleIban": "c", + "coordBancairesFournisseurCleRib": "c", + "coordBancairesFournisseurCodeBanque": "c", + "coordBancairesFournisseurCodePays": "c", + "coordBancairesFournisseurCompteBancaire": "c", + "coordBancairesFournisseurId": 1, + "coordBancairesFournisseurLibelle": "c", + "coordBancairesFournisseurType": "c", + "designationFournisseur": "d", + "idFournisseur": 1, + "idServiceFournisseur": 1, + "libelleServiceFournisseur": "l", + "numeroRcsFournisseur": "n", + "typeIdentifiantFournisseur": "t" + }, + "identifiantFactureCPP": 1, + "lignesDePoste": { + "lignePoste": [ + { + "lignePosteDenomination": "l", + "lignePosteMontantHtApresRemise": 1, + "lignePosteMontantRemiseHT": 1, + "lignePosteMontantTtcApresRemise": 1, + "lignePosteMontantTva": 1, + "lignePosteMontantUnitaireHT": 1, + "lignePosteNumero": 1, + "lignePosteQuantite": 1, + "lignePosteReference": "r", + "lignePosteTauxTva": "t", + "lignePosteTauxTvaManuel": 1, + "lignePosteUniteCode": 1, + "lignePosteUniteLibelle": "u" + } + ], + "nbResultatsParPageLignesPoste": 1, + "pageCouranteLignesPoste": 1, + "pagesLignesPoste": 1, + "totalLignesPoste": 1 + }, + "listeDesPiecesJointes": { + "pieceJointe": [ + { + "pieceJointeDesignation": "p", + "pieceJointeExtension": "e", + "pieceJointeId": 1, + "pieceJointeIdLiaison": 1, + "pieceJointeNumeroLigneFacture": 1, + "pieceJointeTypeCode": "t", + "pieceJointeTypeLibelle": "t" + } + ], + "nbResultatsParPageListePiecesJointe": 1, + "pageCouranteListePiecesJointe": 1, + "pagesListePiecesJointe": 1, + "totalListePiecesJointe": 1 + }, + "modeDepot": "m", + "montantTotal": { + "montantAPayer": 1, + "montantHtTotal": 1, + "montantRemiseGlobaleTTC": 1, + "montantTVA": 1, + "montantTtcAvantRemiseGlobalTTC": 1, + "montantTtcTotal": 1, + "motifRemiseGlobaleTTC": "m" + }, + "numeroFacture": "n", + "pieceJointePrincipale": { + "idLiaisonPieceJointePrincipale": 1, + "idPieceJointePrincipale": 1 + }, + "piecePrecedente": { + "cadreFacturationPiecePrecedente": "c", + "codeServiceExecutantPiecePrecedente": "c", + "idDestinatairePiecePrecedente": 1, + "idPiecePrecedente": 1, + "idServiceExecutantPiecePrecedente": 1, + "identifiantDestinatairePiecePrecedente": "i", + "nomServiceExecutantPiecePrecedente": "n", + "numeroPiecePrecedente": "n", + "raisonSocialeDestinatairePiecePrecedente": "r" + }, + "pieceSuivante": { + "cadreFacturationPieceSuivante": "c", + "idPieceSuivante": 1, + "numeroPieceSuivante": "n" + }, + "recapitulatifDeTva": { + "ligneTva": [ + { + "ligneTvaMontantBaseHtParTaux": 1, + "ligneTvaMontantTvaParTaux": 1, + "ligneTvaTauxManuel": 1, + "ligneTvaTauxRefCode": "t", + "ligneTvaTauxRefId": 1, + "ligneTvaTauxRefLibelle": "t", + "ligneTvaTauxRefValeur": 1 + } + ], + "nbResultatsParPageLignesRecapitulativesTVA": 1, + "pageCouranteLignesRecapitulativesTVA": 1, + "pagesLignesRecapitulativesTVA": 1, + "totalLignesRecapitulativesTVA": 1 + }, + "references": { + "codeDeviseFacture": "c", + "dateCreationFacture": ` + defaultDateTimeStr + `, + "dateDepot": ` + defaultDateStr + `, + "dateEcheancePaiement": ` + defaultDateStr + `, + "dateFacture": ` + defaultDateStr + `, + "libelleDeviseFacture": "l", + "libelleMotifExonerationTva": "l", + "modePaiement": "m", + "motifExonerationTva": "m", + "numeroBonCommande": "n", + "numeroDpMandat": "n", + "numeroFactureOrigine": "n", + "numeroMarche": "n", + "tailleTotalePiecesJointes": 1, + "typeFacture": "t", + "typeFactureTravaux": "t", + "typeTva": "t" + }, + "statutFacture": "s" + }, + "libelle": "l" + } + `)) + }) + + ctx := context.Background() + opt := ConsulterFactureOptions{} + got, err := client.Factures.ConsulterFactureParValideur(ctx, opt) + + if err != nil { + t.Errorf("Factures.ConsulterFactureParValideur returned error : %v", err) + } + + want := &ConsulterFactureResponse{ + CodeRetour: 1, + Facture: Facture{ + CadreDeFacturation: CadreDeFacturation{ + Code: "c", + CodeServiceMoa: "c", + CodeServiceMoe: "c", + CodeValideur1: "c", + CodeValideur2: "c", + DateValidation1: &Date{defaultDate}, + DateValidation2: &Date{defaultDate}, + DesignationMoa: "d", + DesignationMoe: "d", + DesignationValideur2: "d", + IdMoa: 1, + IdMoe: 1, + IdServiceMoa: 1, + IdServiceMoe: 1, + IdValideur1: 1, + IdValideur2: 1, + IdentifiantMoa: "i", + IdentifiantMoe: "i", + NomMoe: "n", + NomServiceMoa: "n", + NomServiceMoe: "n", + NomValideur1: "n", + NomValideur2: "n", + PrenomMoe: "p", + PrenomValideur1: "p", + PrenomValideur2: "p", + RaisonSocialeMoa: "r", + RaisonSocialeMoe: "r", + RaisonSocialeValideur1: "r", + RaisonSocialeValideur2: "r", + TypeIdentifiantMoa: "t", + TypeIdentifiantMoe: "t", + TypeIdentifiantValideur1: "t", + TypeIdentifiantValideur2: "t", + }, + Commentaire: "c", + Destinataire: Destinataire{ + AdresseCodePays: "a", + AdresseCodePostal: "a", + AdresseComplement1: "a", + AdresseComplement2: "a", + AdresseDetail: "a", + AdresseId: 1, + AdresseLibellePays: "a", + AdresseVille: "a", + Code: "c", + CodeServiceExecutant: "c", + Etat: "d", + Id: 1, + IdServiceExecutant: 1, + Libelle: "l", + LibelleServiceExecutant: "l", + }, + Fournisseur: Fournisseur{ + AdresseCodePays: "a", + AdresseCodePostal: "a", + AdresseComplement1: "a", + AdresseComplement2: "a", + AdresseDetail: "a", + AdresseId: 1, + AdresseLibellePays: "a", + AdresseVille: "a", + Affactureur: Affactureur{ + Code: "a", + CodePays: "a", + Id: 1, + RaisonSociale: "a", + TypeIdentifiant: "a", + }, + Code: "c", + CodeService: "c", + CoordBancairesBicSwift: "c", + CoordBancairesCodeGuichet: "c", + CoordBancairesCleIban: "c", + CoordBancairesCleRib: "c", + CoordBancairesCodeBanque: "c", + CoordBancairesCodePays: "c", + CoordBancairesCompteBancaire: "c", + CoordBancairesId: 1, + CoordBancairesLibelle: "c", + CoordBancairesType: "c", + Designation: "d", + Id: 1, + IdService: 1, + LibelleService: "l", + NumeroRcs: "n", + TypeIdentifiant: "t", + }, + IdentifiantFactureCPP: 1, + LignesDePoste: &ListeLignesDePoste{ + Lignes: []LignePoste{ + { + Denomination: "l", + MontantHtApresRemise: 1, + MontantRemiseHT: 1, + MontantTtcApresRemise: 1, + MontantTva: 1, + MontantUnitaireHT: 1, + Numero: 1, + Quantite: 1, + Reference: "r", + TauxTva: "t", + TauxTvaManuel: 1, + UniteCode: 1, + UniteLibelle: "u", + }, + }, + NbResultatsParPage: 1, + PageCourante: 1, + Pages: 1, + Total: 1, + }, + ListeDesPiecesJointes: &ListePiecesJointesFacture{ + PiecesJointes: []PieceJointeFacture{ + { + Designation: "p", + Extension: "e", + Id: 1, + IdLiaison: 1, + NumeroLigneFacture: 1, + TypeCode: "t", + TypeLibelle: "t", + }, + }, + NbResultatsParPage: 1, + PageCourante: 1, + Pages: 1, + Total: 1, + }, + ModeDepot: "m", + MontantTotal: MontantTotal{ + MontantAPayer: 1, + MontantHtTotal: 1, + MontantRemiseGlobaleTTC: 1, + MontantTVA: 1, + MontantTtcAvantRemiseGlobalTTC: 1, + MontantTtcTotal: 1, + MotifRemiseGlobaleTTC: "m", + }, + NumeroFacture: "n", + PieceJointePrincipale: &PieceJointePrincipale{ + IdLiaison: 1, + Id: 1, + }, + PiecePrecedente: &PiecePrecedente{ + CadreFacturation: "c", + CodeServiceExecutant: "c", + IdDestinataire: 1, + Id: 1, + IdServiceExecutant: 1, + IdentifiantDestinataire: "i", + NomServiceExecutant: "n", + Numero: "n", + RaisonSocialeDestinataire: "r", + }, + PieceSuivante: &PieceSuivante{ + CadreFacturation: "c", + Id: 1, + Numero: "n", + }, + RecapitulatifDeTva: &ListeLignesRecapTVA{ + Lignes: []LigneTva{ + { + MontantBaseHtParTaux: 1, + MontantTvaParTaux: 1, + TauxManuel: 1, + TauxRefCode: "t", + TauxRefId: 1, + TauxRefLibelle: "t", + TauxRefValeur: 1, + }, + }, + NbResultatsParPage: 1, + PageCourante: 1, + Pages: 1, + Total: 1, + }, + References: References{ + CodeDevise: "c", + DateCreationFacture: &Datetime{defaultDate}, + DateDepot: &Date{defaultDate}, + DateEcheancePaiement: &Date{defaultDate}, + DateFacture: &Date{defaultDate}, + LibelleDevise: "l", + LibelleMotifExonerationTva: "l", + ModePaiement: "m", + MotifExonerationTva: "m", + NumeroBonCommande: "n", + NumeroDpMandat: "n", + NumeroFactureOrigine: "n", + NumeroMarche: "n", + TailleTotalePiecesJointes: 1, + TypeFacture: "t", + TypeFactureTravaux: "t", + TypeTva: "t", + }, + StatutFacture: "s", + }, + Libelle: "l", + } + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.ConsulterFactureParValideur returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "ConsulterFactureParValideur", client, func() error { + _, err := client.Factures.ConsulterFactureParValideur(ctx, opt) + return err + }) +} + +func TestFacturesService_ConsulterFactureParFournisseur(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/consulter/fournisseur", func(w http.ResponseWriter, r *http.Request) { + v := new(ConsulterFactureFournisseurOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "facture": { + "cadreDeFacturation": { + "codeCadreFacturation": "c", + "codeServiceMoa": "c", + "codeServiceMoe": "c", + "codeValideur1": "c", + "codeValideur2": "c", + "dateValidation1": ` + defaultDateStr + `, + "dateValidation2": ` + defaultDateStr + `, + "designationMoa": "d", + "designationMoe": "d", + "designationValideur2": "d", + "idMoa": 1, + "idMoe": 1, + "idServiceMoa": 1, + "idServiceMoe": 1, + "idValideur1": 1, + "idValideur2": 1, + "identifiantMoa": "i", + "identifiantMoe": "i", + "nomMoe": "n", + "nomServiceMoa": "n", + "nomServiceMoe": "n", + "nomValideur1": "n", + "nomValideur2": "n", + "prenomMoe": "p", + "prenomValideur1": "p", + "prenomValideur2": "p", + "raisonSocialeMoa": "r", + "raisonSocialeMoe": "r", + "raisonSocialeValideur1": "r", + "raisonSocialeValideur2": "r", + "typeIdentifiantMoa": "t", + "typeIdentifiantMoe": "t", + "typeIdentifiantValideur1": "t", + "typeIdentifiantValideur2": "t" + }, + "commentaire": "c", + "destinataire": { + "adresseDestinataireCodePays": "a", + "adresseDestinataireCodePostal": "a", + "adresseDestinataireComplement1": "a", + "adresseDestinataireComplement2": "a", + "adresseDestinataireDetail": "a", + "adresseDestinataireId": 1, + "adresseDestinataireLibellePays": "a", + "adresseDestinataireVille": "a", + "codeDestinataire": "c", + "codeServiceExecutant": "c", + "destinataireEtat": "d", + "idDestinataire": 1, + "idServiceExecutant": 1, + "libelleDestinataire": "l", + "libelleServiceExecutant": "l" + }, + "fournisseur": { + "adresseFournisseurCodePays": "a", + "adresseFournisseurCodePostal": "a", + "adresseFournisseurComplement1": "a", + "adresseFournisseurComplement2": "a", + "adresseFournisseurDetail": "a", + "adresseFournisseurId": 1, + "adresseFournisseurLibellePays": "a", + "adresseFournisseurVille": "a", + "affactureur": { + "affactureurCode": "a", + "affactureurCodePays": "a", + "affactureurId": 1, + "affactureurRaisonSociale": "a", + "affactureurTypeIdentifiant": "a" + }, + "codeFournisseur": "c", + "codeServiceFournisseur": "c", + "coordBancairesBicSwift": "c", + "coordBancairesCodeGuichet": "c", + "coordBancairesFournisseurCleIban": "c", + "coordBancairesFournisseurCleRib": "c", + "coordBancairesFournisseurCodeBanque": "c", + "coordBancairesFournisseurCodePays": "c", + "coordBancairesFournisseurCompteBancaire": "c", + "coordBancairesFournisseurId": 1, + "coordBancairesFournisseurLibelle": "c", + "coordBancairesFournisseurType": "c", + "designationFournisseur": "d", + "idFournisseur": 1, + "idServiceFournisseur": 1, + "libelleServiceFournisseur": "l", + "numeroRcsFournisseur": "n", + "typeIdentifiantFournisseur": "t" + }, + "identifiantFactureCPP": 1, + "lignesDePoste": { + "lignePoste": [ + { + "lignePosteDenomination": "l", + "lignePosteMontantHtApresRemise": 1, + "lignePosteMontantRemiseHT": 1, + "lignePosteMontantTtcApresRemise": 1, + "lignePosteMontantTva": 1, + "lignePosteMontantUnitaireHT": 1, + "lignePosteNumero": 1, + "lignePosteQuantite": 1, + "lignePosteReference": "r", + "lignePosteTauxTva": "t", + "lignePosteTauxTvaManuel": 1, + "lignePosteUniteCode": 1, + "lignePosteUniteLibelle": "u" + } + ], + "nbResultatsParPageLignesPoste": 1, + "pageCouranteLignesPoste": 1, + "pagesLignesPoste": 1, + "totalLignesPoste": 1 + }, + "listeDesPiecesJointes": { + "pieceJointe": [ + { + "pieceJointeDesignation": "p", + "pieceJointeExtension": "e", + "pieceJointeId": 1, + "pieceJointeIdLiaison": 1, + "pieceJointeNumeroLigneFacture": 1, + "pieceJointeTypeCode": "t", + "pieceJointeTypeLibelle": "t" + } + ], + "nbResultatsParPageListePiecesJointe": 1, + "pageCouranteListePiecesJointe": 1, + "pagesListePiecesJointe": 1, + "totalListePiecesJointe": 1 + }, + "modeDepot": "m", + "montantTotal": { + "montantAPayer": 1, + "montantHtTotal": 1, + "montantRemiseGlobaleTTC": 1, + "montantTVA": 1, + "montantTtcAvantRemiseGlobalTTC": 1, + "montantTtcTotal": 1, + "motifRemiseGlobaleTTC": "m" + }, + "numeroFacture": "n", + "pieceJointePrincipale": { + "idLiaisonPieceJointePrincipale": 1, + "idPieceJointePrincipale": 1 + }, + "piecePrecedente": { + "cadreFacturationPiecePrecedente": "c", + "codeServiceExecutantPiecePrecedente": "c", + "idDestinatairePiecePrecedente": 1, + "idPiecePrecedente": 1, + "idServiceExecutantPiecePrecedente": 1, + "identifiantDestinatairePiecePrecedente": "i", + "nomServiceExecutantPiecePrecedente": "n", + "numeroPiecePrecedente": "n", + "raisonSocialeDestinatairePiecePrecedente": "r" + }, + "pieceSuivante": { + "cadreFacturationPieceSuivante": "c", + "idPieceSuivante": 1, + "numeroPieceSuivante": "n" + }, + "recapitulatifDeTva": { + "ligneTva": [ + { + "ligneTvaMontantBaseHtParTaux": 1, + "ligneTvaMontantTvaParTaux": 1, + "ligneTvaTauxManuel": 1, + "ligneTvaTauxRefCode": "t", + "ligneTvaTauxRefId": 1, + "ligneTvaTauxRefLibelle": "t", + "ligneTvaTauxRefValeur": 1 + } + ], + "nbResultatsParPageLignesRecapitulativesTVA": 1, + "pageCouranteLignesRecapitulativesTVA": 1, + "pagesLignesRecapitulativesTVA": 1, + "totalLignesRecapitulativesTVA": 1 + }, + "references": { + "codeDeviseFacture": "c", + "dateCreationFacture": ` + defaultDateTimeStr + `, + "dateDepot": ` + defaultDateStr + `, + "dateEcheancePaiement": ` + defaultDateStr + `, + "dateFacture": ` + defaultDateStr + `, + "libelleDeviseFacture": "l", + "libelleMotifExonerationTva": "l", + "modePaiement": "m", + "motifExonerationTva": "m", + "numeroBonCommande": "n", + "numeroDpMandat": "n", + "numeroFactureOrigine": "n", + "numeroMarche": "n", + "tailleTotalePiecesJointes": 1, + "typeFacture": "t", + "typeFactureTravaux": "t", + "typeTva": "t" + }, + "statutFacture": "s" + }, + "libelle": "l" + } + `)) + }) + + ctx := context.Background() + opt := ConsulterFactureFournisseurOptions{} + got, err := client.Factures.ConsulterFactureParFournisseur(ctx, opt) + + if err != nil { + t.Errorf("Factures.ConsulterFactureParFournisseur returned error : %v", err) + } + + want := &ConsulterFactureResponse{ + CodeRetour: 1, + Facture: Facture{ + CadreDeFacturation: CadreDeFacturation{ + Code: "c", + CodeServiceMoa: "c", + CodeServiceMoe: "c", + CodeValideur1: "c", + CodeValideur2: "c", + DateValidation1: &Date{defaultDate}, + DateValidation2: &Date{defaultDate}, + DesignationMoa: "d", + DesignationMoe: "d", + DesignationValideur2: "d", + IdMoa: 1, + IdMoe: 1, + IdServiceMoa: 1, + IdServiceMoe: 1, + IdValideur1: 1, + IdValideur2: 1, + IdentifiantMoa: "i", + IdentifiantMoe: "i", + NomMoe: "n", + NomServiceMoa: "n", + NomServiceMoe: "n", + NomValideur1: "n", + NomValideur2: "n", + PrenomMoe: "p", + PrenomValideur1: "p", + PrenomValideur2: "p", + RaisonSocialeMoa: "r", + RaisonSocialeMoe: "r", + RaisonSocialeValideur1: "r", + RaisonSocialeValideur2: "r", + TypeIdentifiantMoa: "t", + TypeIdentifiantMoe: "t", + TypeIdentifiantValideur1: "t", + TypeIdentifiantValideur2: "t", + }, + Commentaire: "c", + Destinataire: Destinataire{ + AdresseCodePays: "a", + AdresseCodePostal: "a", + AdresseComplement1: "a", + AdresseComplement2: "a", + AdresseDetail: "a", + AdresseId: 1, + AdresseLibellePays: "a", + AdresseVille: "a", + Code: "c", + CodeServiceExecutant: "c", + Etat: "d", + Id: 1, + IdServiceExecutant: 1, + Libelle: "l", + LibelleServiceExecutant: "l", + }, + Fournisseur: Fournisseur{ + AdresseCodePays: "a", + AdresseCodePostal: "a", + AdresseComplement1: "a", + AdresseComplement2: "a", + AdresseDetail: "a", + AdresseId: 1, + AdresseLibellePays: "a", + AdresseVille: "a", + Affactureur: Affactureur{ + Code: "a", + CodePays: "a", + Id: 1, + RaisonSociale: "a", + TypeIdentifiant: "a", + }, + Code: "c", + CodeService: "c", + CoordBancairesBicSwift: "c", + CoordBancairesCodeGuichet: "c", + CoordBancairesCleIban: "c", + CoordBancairesCleRib: "c", + CoordBancairesCodeBanque: "c", + CoordBancairesCodePays: "c", + CoordBancairesCompteBancaire: "c", + CoordBancairesId: 1, + CoordBancairesLibelle: "c", + CoordBancairesType: "c", + Designation: "d", + Id: 1, + IdService: 1, + LibelleService: "l", + NumeroRcs: "n", + TypeIdentifiant: "t", + }, + IdentifiantFactureCPP: 1, + LignesDePoste: &ListeLignesDePoste{ + Lignes: []LignePoste{ + { + Denomination: "l", + MontantHtApresRemise: 1, + MontantRemiseHT: 1, + MontantTtcApresRemise: 1, + MontantTva: 1, + MontantUnitaireHT: 1, + Numero: 1, + Quantite: 1, + Reference: "r", + TauxTva: "t", + TauxTvaManuel: 1, + UniteCode: 1, + UniteLibelle: "u", + }, + }, + NbResultatsParPage: 1, + PageCourante: 1, + Pages: 1, + Total: 1, + }, + ListeDesPiecesJointes: &ListePiecesJointesFacture{ + PiecesJointes: []PieceJointeFacture{ + { + Designation: "p", + Extension: "e", + Id: 1, + IdLiaison: 1, + NumeroLigneFacture: 1, + TypeCode: "t", + TypeLibelle: "t", + }, + }, + NbResultatsParPage: 1, + PageCourante: 1, + Pages: 1, + Total: 1, + }, + ModeDepot: "m", + MontantTotal: MontantTotal{ + MontantAPayer: 1, + MontantHtTotal: 1, + MontantRemiseGlobaleTTC: 1, + MontantTVA: 1, + MontantTtcAvantRemiseGlobalTTC: 1, + MontantTtcTotal: 1, + MotifRemiseGlobaleTTC: "m", + }, + NumeroFacture: "n", + PieceJointePrincipale: &PieceJointePrincipale{ + IdLiaison: 1, + Id: 1, + }, + PiecePrecedente: &PiecePrecedente{ + CadreFacturation: "c", + CodeServiceExecutant: "c", + IdDestinataire: 1, + Id: 1, + IdServiceExecutant: 1, + IdentifiantDestinataire: "i", + NomServiceExecutant: "n", + Numero: "n", + RaisonSocialeDestinataire: "r", + }, + PieceSuivante: &PieceSuivante{ + CadreFacturation: "c", + Id: 1, + Numero: "n", + }, + RecapitulatifDeTva: &ListeLignesRecapTVA{ + Lignes: []LigneTva{ + { + MontantBaseHtParTaux: 1, + MontantTvaParTaux: 1, + TauxManuel: 1, + TauxRefCode: "t", + TauxRefId: 1, + TauxRefLibelle: "t", + TauxRefValeur: 1, + }, + }, + NbResultatsParPage: 1, + PageCourante: 1, + Pages: 1, + Total: 1, + }, + References: References{ + CodeDevise: "c", + DateCreationFacture: &Datetime{defaultDate}, + DateDepot: &Date{defaultDate}, + DateEcheancePaiement: &Date{defaultDate}, + DateFacture: &Date{defaultDate}, + LibelleDevise: "l", + LibelleMotifExonerationTva: "l", + ModePaiement: "m", + MotifExonerationTva: "m", + NumeroBonCommande: "n", + NumeroDpMandat: "n", + NumeroFactureOrigine: "n", + NumeroMarche: "n", + TailleTotalePiecesJointes: 1, + TypeFacture: "t", + TypeFactureTravaux: "t", + TypeTva: "t", + }, + StatutFacture: "s", + }, + Libelle: "l", + } + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.ConsulterFactureParFournisseur returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "ConsulterFactureParFournisseur", client, func() error { + _, err := client.Factures.ConsulterFactureParFournisseur(ctx, opt) + return err + }) +} + +func TestFacturesService_ConsulterHistorique(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/consulter/historique", func(w http.ResponseWriter, r *http.Request) { + v := new(ConsulterHistoriqueOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "derniereAction": { + "derniereActionCode": "c", + "derniereActionId": 1 + }, + "historiquesDesActionsUtilisateurs": { + "histoAction": [ + { + "histoActionCode": "c", + "histoActionDateHeure": ` + defaultDateTimeStr + `, + "histoActionId": 1, + "histoActionUtilisateurEmail": "e", + "histoActionUtilisateurNom": "n", + "histoActionUtilisateurPrenom": "p", + "histoActionUtilisateurTelephone": "t" + } + ], + "nbResultatsParPageHistoAction": 1, + "pageCouranteHistoAction": 1, + "pagesHistoAction": 1, + "totalHistoAction": 1 + }, + "historiquesDesEvenementsComplementaires": { + "evenement": [ + { + "evenementDateHeure": ` + defaultDateTimeStr + `, + "evenementId": 1, + "evenementLibelle": "l", + "evenementQui": "q" + } + ], + "nbResultatsParPageEvenement": 1, + "pageCouranteEvenement": 1, + "pagesEvenement": 1, + "totalEvenement": 1 + }, + "historiquesDesStatuts": { + "histoStatut": [ + { + "histoStatutCode": "c", + "histoStatutCommentaire": "c", + "histoStatutDatePassage": ` + defaultDateTimeStr + `, + "histoStatutId": 1, + "histoStatutUtilisateurEmail": "e", + "histoStatutUtilisateurNom": "n", + "histoStatutUtilisateurPrenom": "p", + "histoStatutUtilisateurTelephone": "t" + } + ], + "nbResultatsParPageHistoStatut": 1, + "pageCouranteHistoStatut": 1, + "pagesHistoStatut": 1, + "totalHistoStatut": 1 + }, + "idFacture": 1, + "libelle": "l", + "modeDepot": "m", + "numeroFacture": "n", + "statutCourantCode": "s" + } + `)) + }) + + ctx := context.Background() + opt := ConsulterHistoriqueOptions{} + got, err := client.Factures.ConsulterHistorique(ctx, opt) + + if err != nil { + t.Errorf("Factures.ConsulterHistorique returned error : %v", err) + } + + want := &ConsulterHistoriqueResponse{ + CodeRetour: 1, + DerniereAction: &DerniereAction{ + Code: "c", + Id: 1, + }, + HistoriquesDesActionsUtilisateurs: &HistoriquesDesActionsUtilisateurs{ + HistoAction: []HistoAction{ + { + Code: "c", + DateHeure: &Datetime{defaultDate}, + Id: 1, + UtilisateurEmail: "e", + UtilisateurNom: "n", + UtilisateurPrenom: "p", + UtilisateurTelephone: "t", + }, + }, + NbResultatsParPageHistoAction: 1, + PageCouranteHistoAction: 1, + PagesHistoAction: 1, + TotalHistoAction: 1, + }, + HistoriquesDesEvenementsComplementaires: &HistoriquesDesEvenementsComplementaires{ + Evenement: []Evenement{ + { + EvenementDateHeure: &Datetime{defaultDate}, + EvenementId: 1, + EvenementLibelle: "l", + EvenementQui: "q", + }, + }, + + NbResultatsParPageEvenement: 1, + PageCouranteEvenement: 1, + PagesEvenement: 1, + TotalEvenement: 1, + }, + HistoriquesDesStatuts: &HistoriquesDesStatuts{ + HistoStatut: []HistoStatut{ + { + Code: "c", + Commentaire: "c", + DatePassage: &Datetime{defaultDate}, + Id: 1, + UtilisateurEmail: "e", + UtilisateurNom: "n", + UtilisateurPrenom: "p", + UtilisateurTelephone: "t", + }, + }, + NbResultatsParPageHistoStatut: 1, + PageCouranteHistoStatut: 1, + PagesHistoStatut: 1, + TotalHistoStatut: 1, + }, + IdFacture: 1, + Libelle: "l", + ModeDepot: "m", + NumeroFacture: "n", + StatutCourantCode: "s", + } + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.ConsulterHistorique returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "ConsulterHistorique", client, func() error { + _, err := client.Factures.ConsulterHistorique(ctx, opt) + return err + }) +} diff --git a/factures_depots.go b/factures_depots.go index deb3f86..b8123b4 100644 --- a/factures_depots.go +++ b/factures_depots.go @@ -5,6 +5,70 @@ import ( "net/http" ) +type CompleterFactureOptions struct { + Commentaire string `json:"commentaire,omitempty"` + IdUtilisateurCourant int64 `json:"idUtilisateurCourant,omitempty"` + IdentifiantFactureCPP int64 `json:"identifiantFactureCPP,omitempty"` + PiecesJointesComplementaires []*PieceJointeComplementaire `json:"pieceJointeComplementaire,omitempty"` +} + +type CompleterFactureResponse struct { + CodeRetour int `json:"codeRetour,omitempty"` + DateTraitement *Date `json:"dateTraitement,omitempty"` + IdentifiantFactureCPP int64 `json:"identifiantFactureCPP,omitempty"` + Libelle string `json:"libelle,omitempty"` + NumeroFacture string `json:"numeroFacture,omitempty"` +} + +func (s *FacturesService) CompleterFacture(ctx context.Context, opts CompleterFactureOptions) (*CompleterFactureResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/completer", opts) + if err != nil { + return nil, err + } + + res := new(CompleterFactureResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} + +type RecyclerFactureOptions struct { + Commentaire string `json:"commentaire"` + Destinataire *SoumettreFactureDestinataire `json:"destinataire"` + IdUtilisateurCourant int `json:"idUtilisateurCourant"` + IdentifiantFactureCPP int `json:"identifiantFactureCPP"` + Reference *SoumettreFactureReferences `json:"reference"` +} + +type RecyclerFactureResponse struct { + CodeRetour int32 `json:"codeRetour"` + DateDepot *Date `json:"dateDepot"` + IdentifiantFactureCPP int32 `json:"identifiantFactureCPP"` + Libelle string `json:"libelle"` + NumeroFacture string `json:"numeroFacture"` + StatutFacture string `json:"statutFacture"` +} + +func (s *FacturesService) RecyclerFacture(ctx context.Context, opts RecyclerFactureOptions) (*RecyclerFactureResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/recycler", opts) + if err != nil { + return nil, err + } + + res := new(RecyclerFactureResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} + type SoumettreFactureOptions struct { CadreDeFacturation SoumettreFactureCadreDeFacturation `json:"cadreDeFacturation,omitempty"` Commentaire string `json:"commentaire,omitempty"` @@ -43,7 +107,7 @@ type SoumettreFactureLignePoste struct { Denomination string `json:"lignePosteDenomination,omitempty"` MontantRemiseHT float32 `json:"lignePosteMontantRemiseHT,omitempty"` MontantUnitaireHT float32 `json:"lignePosteMontantUnitaireHT,omitempty"` - Numero int `json:"lignePosteNumero,omitempty"` + Numero int32 `json:"lignePosteNumero,omitempty"` Quantite float32 `json:"lignePosteQuantite,omitempty"` Reference string `json:"lignePosteReference,omitempty"` TauxTva string `json:"lignePosteTauxTva,omitempty"` @@ -150,28 +214,26 @@ func (s *FacturesService) DeposerFlux(ctx context.Context, opts DeposerFluxFactu return res, nil } -type CompleterFactureOptions struct { - Commentaire string `json:"commentaire,omitempty"` - IdUtilisateurCourant int64 `json:"idUtilisateurCourant,omitempty"` - IdentifiantFactureCPP int64 `json:"identifiantFactureCPP,omitempty"` - PiecesJointesComplementaires []*PieceJointeComplementaire `json:"pieceJointeComplementaire,omitempty"` +type CorrigerValideurFactureOptions struct { + IdFacture int64 `json:"idFacture"` + IdStructure int64 `json:"idStructure"` + IdentifiantStructure string `json:"identifiantStructure"` + TypeIdentifiantStructure string `json:"typeIdentifiantStructure"` } -type CompleterFactureResponse struct { - CodeRetour int `json:"codeRetour,omitempty"` - DateTraitement *Date `json:"dateTraitement,omitempty"` - IdentifiantFactureCPP int64 `json:"identifiantFactureCPP,omitempty"` - Libelle string `json:"libelle,omitempty"` - NumeroFacture string `json:"numeroFacture,omitempty"` +type CorrigerValideurFactureResponse struct { + CodeRetour int32 `json:"codeRetour"` + IdFacture int64 `json:"idFacture"` + Libelle string `json:"libelle"` } -func (s *FacturesService) CompleterFacture(ctx context.Context, opts CompleterFactureOptions) (*CompleterFactureResponse, error) { - req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/completer", opts) +func (s *FacturesService) CorrigerValideurFacture(ctx context.Context, opts CorrigerValideurFactureOptions) (*CorrigerValideurFactureResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/corriger/valideur/facture", opts) if err != nil { return nil, err } - res := new(CompleterFactureResponse) + res := new(CorrigerValideurFactureResponse) err = s.client.doRequest(ctx, req, res) if err != nil { diff --git a/factures_depots_test.go b/factures_depots_test.go index bc267f4..2fa7743 100644 --- a/factures_depots_test.go +++ b/factures_depots_test.go @@ -8,6 +8,94 @@ import ( "testing" ) +func TestFacturesService_CompleterFacture(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/completer", func(w http.ResponseWriter, r *http.Request) { + v := new(CompleterFactureOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "dateTraitement": ` + defaultDateStr + `, + "identifiantFactureCPP": 1, + "libelle": "l", + "numeroFacture": "n" + }`)) + }) + + ctx := context.Background() + opt := CompleterFactureOptions{} + got, err := client.Factures.CompleterFacture(ctx, opt) + + if err != nil { + t.Errorf("Factures.CompleterFacture returned error : %v", err) + } + + want := &CompleterFactureResponse{ + CodeRetour: 1, + DateTraitement: &Date{defaultDate}, + IdentifiantFactureCPP: 1, + Libelle: "l", + NumeroFacture: "n", + } + + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.CompleterFacture returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "CompleterFacture", client, func() error { + _, err := client.Factures.CompleterFacture(ctx, opt) + return err + }) +} + +func TestFacturesService_RecyclerFacture(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/recycler", func(w http.ResponseWriter, r *http.Request) { + v := new(RecyclerFactureOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "dateDepot": ` + defaultDateStr + `, + "identifiantFactureCPP": 1, + "libelle": "l", + "numeroFacture": "n", + "statutFacture": "s" + }`)) + }) + + ctx := context.Background() + opt := RecyclerFactureOptions{} + got, err := client.Factures.RecyclerFacture(ctx, opt) + + if err != nil { + t.Errorf("Factures.RecyclerFacture returned error : %v", err) + } + + want := &RecyclerFactureResponse{ + CodeRetour: 1, + DateDepot: &Date{defaultDate}, + IdentifiantFactureCPP: 1, + Libelle: "l", + NumeroFacture: "n", + StatutFacture: "s", + } + + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.RecyclerFacture returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "RecyclerFacture", client, func() error { + _, err := client.Factures.RecyclerFacture(ctx, opt) + return err + }) +} + func TestFacturesService_SoumettreFacture(t *testing.T) { client, mux, teardown := setup() defer teardown() @@ -104,45 +192,41 @@ func TestFacturesService_DeposerFlux(t *testing.T) { }) } -func TestFacturesService_CompleterFacture(t *testing.T) { +func TestFacturesService_CorrigerValideurFacture(t *testing.T) { client, mux, teardown := setup() defer teardown() - mux.HandleFunc("/cpro/factures/v1/completer", func(w http.ResponseWriter, r *http.Request) { - v := new(CompleterFactureOptions) + mux.HandleFunc("/cpro/factures/v1/corriger/valideur/facture", func(w http.ResponseWriter, r *http.Request) { + v := new(CorrigerValideurFactureOptions) assertNilError(t, json.NewDecoder(r.Body).Decode(v)) testMethod(t, r, http.MethodPost) w.Write([]byte(`{ "codeRetour": 1, - "dateTraitement": ` + defaultDateStr + `, - "identifiantFactureCPP": 1, - "libelle": "l", - "numeroFacture": "n" + "idFacture": 1, + "libelle": "l" }`)) }) ctx := context.Background() - opt := CompleterFactureOptions{} - got, err := client.Factures.CompleterFacture(ctx, opt) + opt := CorrigerValideurFactureOptions{} + got, err := client.Factures.CorrigerValideurFacture(ctx, opt) if err != nil { - t.Errorf("Factures.CompleterFacture returned error : %v", err) + t.Errorf("Factures.CorrigerValideurFacture returned error : %v", err) } - want := &CompleterFactureResponse{ - CodeRetour: 1, - DateTraitement: &Date{defaultDate}, - IdentifiantFactureCPP: 1, - Libelle: "l", - NumeroFacture: "n", + want := &CorrigerValideurFactureResponse{ + CodeRetour: 1, + IdFacture: 1, + Libelle: "l", } if !reflect.DeepEqual(got, want) { - t.Errorf("Factures.CompleterFacture returned %+v, want %+v", got, want) + t.Errorf("Factures.CorrigerValideurFacture returned %+v, want %+v", got, want) } - testNewRequestAndDoRequestFailure(t, "CompleterFacture", client, func() error { - _, err := client.Factures.CompleterFacture(ctx, opt) + testNewRequestAndDoRequestFailure(t, "CorrigerValideurFacture", client, func() error { + _, err := client.Factures.CorrigerValideurFacture(ctx, opt) return err }) } diff --git a/factures_misc.go b/factures_misc.go index 8108122..87afd2a 100644 --- a/factures_misc.go +++ b/factures_misc.go @@ -35,3 +35,33 @@ func (s *FacturesService) TelechargerGroupe(ctx context.Context, opts TraiterFac return res, nil } + +type RecupererStatutsVisiblesParValideurOptions struct { + IdUtilisateurCourant int64 `json:"idUtilisateurCourant"` +} + +type StatutVisible struct { + CodeStatut string `json:"codeStatutFacture"` +} + +type RecupererStatutsVisiblesParValideurResponse struct { + CodeRetour int64 `json:"codeRetour"` + Libelle string `json:"libelle"` + ListeStatutFacture []StatutVisible `json:"listeStatutFacture"` +} + +func (s *FacturesService) RecupererStatutsVisiblesParValideur(ctx context.Context, opts RecupererStatutsVisiblesParValideurOptions) (*RecupererStatutsVisiblesParValideurResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/recuperer/statutsFactureVisibles/valideur", opts) + if err != nil { + return nil, err + } + + res := new(RecupererStatutsVisiblesParValideurResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} diff --git a/factures_misc_test.go b/factures_misc_test.go index 1063802..100d92f 100644 --- a/factures_misc_test.go +++ b/factures_misc_test.go @@ -46,3 +46,50 @@ func TestFacturesService_TelechargerGroupe(t *testing.T) { return err }) } + +func TestFacturesService_RecupererStatutsVisiblesParValideur(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/recuperer/statutsFactureVisibles/valideur", func(w http.ResponseWriter, r *http.Request) { + v := new(RecupererStatutsVisiblesParValideurOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "libelle": "l", + "listeStatutFacture": [ + { + "codeStatutFacture": "c" + } + ] + }`)) + }) + + ctx := context.Background() + opt := RecupererStatutsVisiblesParValideurOptions{} + got, err := client.Factures.RecupererStatutsVisiblesParValideur(ctx, opt) + + if err != nil { + t.Errorf("Factures.RecupererStatutsVisiblesParValideur returned error : %v", err) + } + + want := &RecupererStatutsVisiblesParValideurResponse{ + CodeRetour: 1, + Libelle: "l", + ListeStatutFacture: []StatutVisible{ + { + CodeStatut: "c", + }, + }, + } + + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.RecupererStatutsVisiblesParValideur returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "RecupererStatutsVisiblesParValideur", client, func() error { + _, err := client.Factures.RecupererStatutsVisiblesParValideur(ctx, opt) + return err + }) +} diff --git a/factures_recherches.go b/factures_recherches.go index a39eb49..a55e9c3 100644 --- a/factures_recherches.go +++ b/factures_recherches.go @@ -153,35 +153,35 @@ func (s *FacturesService) RechercherDemandePaiement(ctx context.Context, opts Re } type RechercherFactureRecipiendaireOptions struct { - CadreFacturation CadreFac `json:"cadreFacturation,omitempty"` - FactureTelechargeeParDestinataire bool `json:"factureTelechargeeParDestinataire,omitempty"` - IdDestinataire int64 `json:"idDestinataire,omitempty"` - IdServiceExecutant int64 `json:"idServiceExecutant,omitempty"` - IdStructureValideur int64 `json:"idStructureValideur,omitempty"` - IdUtilisateurCourant int64 `json:"idUtilisateurCourant,omitempty"` - ListeFournisseurs []*FournisseurParam `json:"listeFournisseurs,omitempty"` - ListeTypesFacture []string `json:"listeTypeFacture,omitempty"` - ListeTypesFactureTravaux []string `json:"listeTypeFactureTravaux,omitempty"` - MontantAPayerMax float32 `json:"montantApayerMax,omitempty"` - MontantAPayerMin float32 `json:"montantApayerMin,omitempty"` - MontantHTMax float32 `json:"montantHTMax,omitempty"` - MontantHTMin float32 `json:"montantHTMin,omitempty"` - MontantTTCMax float32 `json:"montantTTCMax,omitempty"` - MontantTTCMin float32 `json:"montantTTCMin,omitempty"` - NumeroBonCommande string `json:"numeroBonCommande,omitempty"` - NumeroFacture string `json:"numeroFacture,omitempty"` - NumeroMarche string `json:"numeroMarche,omitempty"` - Pagination *PaginationOptions `json:"paramRecherche,omitempty"` - PeriodeDateDepotAu *Date `json:"periodeDateDepotAu,omitempty"` - PeriodeDateDepotDu *Date `json:"periodeDateDepotDu,omitempty"` - PeriodeDateFactureAu *Date `json:"periodeDateFactureAu,omitempty"` - PeriodeDateFactureDu *Date `json:"periodeDateFactureDu,omitempty"` - PeriodeDateHeureEtatCourantAu *time.Time `json:"periodeDateHeureEtatCourantAu,omitempty"` - PeriodeDateHeureEtatCourantDu *time.Time `json:"periodeDateHeureEtatCourantDu,omitempty"` - RechercheSirenFournisseur bool `json:"rechercheSirenFournisseur,omitempty"` - RecupererTaille bool `json:"recupererTaille,omitempty"` - StatutCourant []string `json:"statutCourant,omitempty"` - TypeDemandePaiement string `json:"typeDemandePaiement,omitempty"` + CadreFacturation CadreFac `json:"cadreFacturation,omitempty"` + FactureTelechargeeParDestinataire bool `json:"factureTelechargeeParDestinataire,omitempty"` + IdDestinataire int64 `json:"idDestinataire,omitempty"` + IdServiceExecutant int64 `json:"idServiceExecutant,omitempty"` + IdStructureValideur int64 `json:"idStructureValideur,omitempty"` + IdUtilisateurCourant int64 `json:"idUtilisateurCourant,omitempty"` + ListeFournisseurs []FournisseurParam `json:"listeFournisseurs,omitempty"` + ListeTypesFacture []string `json:"listeTypeFacture,omitempty"` + ListeTypesFactureTravaux []string `json:"listeTypeFactureTravaux,omitempty"` + MontantAPayerMax float32 `json:"montantApayerMax,omitempty"` + MontantAPayerMin float32 `json:"montantApayerMin,omitempty"` + MontantHTMax float32 `json:"montantHTMax,omitempty"` + MontantHTMin float32 `json:"montantHTMin,omitempty"` + MontantTTCMax float32 `json:"montantTTCMax,omitempty"` + MontantTTCMin float32 `json:"montantTTCMin,omitempty"` + NumeroBonCommande string `json:"numeroBonCommande,omitempty"` + NumeroFacture string `json:"numeroFacture,omitempty"` + NumeroMarche string `json:"numeroMarche,omitempty"` + Pagination *PaginationOptions `json:"paramRecherche,omitempty"` + PeriodeDateDepotAu *Date `json:"periodeDateDepotAu,omitempty"` + PeriodeDateDepotDu *Date `json:"periodeDateDepotDu,omitempty"` + PeriodeDateFactureAu *Date `json:"periodeDateFactureAu,omitempty"` + PeriodeDateFactureDu *Date `json:"periodeDateFactureDu,omitempty"` + PeriodeDateHeureEtatCourantAu *time.Time `json:"periodeDateHeureEtatCourantAu,omitempty"` + PeriodeDateHeureEtatCourantDu *time.Time `json:"periodeDateHeureEtatCourantDu,omitempty"` + RechercheSirenFournisseur bool `json:"rechercheSirenFournisseur,omitempty"` + RecupererTaille bool `json:"recupererTaille,omitempty"` + StatutCourant []string `json:"statutCourant,omitempty"` + TypeDemandePaiement string `json:"typeDemandePaiement,omitempty"` } type FournisseurParam struct { @@ -189,61 +189,284 @@ type FournisseurParam struct { ListeIdService []int64 `json:"listeIdService,omitempty"` } -type RechercherFactureRecipiendaireResponse struct { - CodeRetour int `json:"codeRetour,omitempty"` - Libelle string `json:"libelle,omitempty"` - Factures *[]FactureRecherche `json:"listeFactures,omitempty"` - NbResultatsParPage int `json:"nbResultatsParPage,omitempty"` - PageCourante int `json:"pageCourante,omitempty"` - Pages int `json:"pages,omitempty"` - Total int `json:"total,omitempty"` -} - -type FactureRecherche struct { - CodeDestinataire string `json:"codeDestinataire,omitempty"` - CodeFournisseur string `json:"codeFournisseur,omitempty"` - CodeMOA string `json:"codeMOA,omitempty"` - CodeMOE string `json:"codeMOE,omitempty"` - CodeServiceExecutant string `json:"codeServiceExecutant,omitempty"` - CodeServiceFournisseur string `json:"codeServiceFournisseur,omitempty"` - CommentaireEtatCourant string `json:"commentaireEtatCourant,omitempty"` - DateDepot *Date `json:"dateDepot,omitempty"` - DateFacture *Date `json:"dateFacture,omitempty"` - DateHeureEtatCourant *time.Time `json:"dateHeureEtatCourant,omitempty"` - DesignationDestinataire string `json:"designationDestinataire,omitempty"` - DesignationFournisseur string `json:"designationFournisseur,omitempty"` - DesignationMOA string `json:"designationMOA,omitempty"` - DesignationMOE string `json:"designationMOE,omitempty"` - Devise string `json:"devise,omitempty"` - FactureTelechargeeParDestinataire bool `json:"factureTelechargeeParDestinataire,omitempty"` - IdDestinataire int64 `json:"idDestinataire,omitempty"` - IdFacture int64 `json:"idFacture,omitempty"` - IdServiceExecutant int64 `json:"idServiceExecutant,omitempty"` - MontantAPayer float32 `json:"montantAPayer,omitempty"` - MontantHT float32 `json:"montantHT,omitempty"` - MontantTTC float32 `json:"montantTTC,omitempty"` - NomServiceExecutant string `json:"nomServiceExecutant,omitempty"` - NomServiceFournisseur string `json:"nomServiceFournisseur,omitempty"` - NumeroBonCommande string `json:"numeroBonCommande,omitempty"` - NumeroFacture string `json:"numeroFacture,omitempty"` - NumeroMarche string `json:"numeroMarche,omitempty"` - Statut string `json:"statut,omitempty"` - Taille int64 `json:"taille,omitempty"` - TypeDemandePaiement string `json:"typeDemandePaiement,omitempty"` - TypeFacture TypeFacture `json:"typeFacture,omitempty"` - TypeFactureTravaux string `json:"typeFactureTravaux,omitempty"` - TypeIdentifiantFournisseur string `json:"typeIdentifiantFournisseur,omitempty"` - TypeIdentifiantMOA string `json:"typeIdentifiantMOA,omitempty"` - TypeIdentifiantMOE string `json:"typeIdentifiantMOE,omitempty"` -} - -func (s *FacturesService) RechercherFactureParRecipiendaire(ctx context.Context, opts RechercherFactureRecipiendaireOptions) (*RechercherFactureRecipiendaireResponse, error) { +type RechercherFactureParRecipiendaireResponse struct { + CodeRetour int `json:"codeRetour,omitempty"` + Libelle string `json:"libelle,omitempty"` + Factures *[]FactureRecipiendaireRecherche `json:"listeFactures,omitempty"` + NbResultatsParPage int `json:"nbResultatsParPage,omitempty"` + PageCourante int `json:"pageCourante,omitempty"` + Pages int `json:"pages,omitempty"` + Total int `json:"total,omitempty"` +} + +type FactureRecipiendaireRecherche struct { + CodeDestinataire string `json:"codeDestinataire,omitempty"` + CodeFournisseur string `json:"codeFournisseur,omitempty"` + CodeMOA string `json:"codeMOA,omitempty"` + CodeMOE string `json:"codeMOE,omitempty"` + CodeServiceExecutant string `json:"codeServiceExecutant,omitempty"` + CodeServiceFournisseur string `json:"codeServiceFournisseur,omitempty"` + CommentaireEtatCourant string `json:"commentaireEtatCourant,omitempty"` + DateDepot *Date `json:"dateDepot,omitempty"` + DateFacture *Date `json:"dateFacture,omitempty"` + DateHeureEtatCourant *time.Time `json:"dateHeureEtatCourant,omitempty"` + DesignationDestinataire string `json:"designationDestinataire,omitempty"` + DesignationFournisseur string `json:"designationFournisseur,omitempty"` + DesignationMOA string `json:"designationMOA,omitempty"` + DesignationMOE string `json:"designationMOE,omitempty"` + Devise string `json:"devise,omitempty"` + FactureTelechargeeParDestinataire bool `json:"factureTelechargeeParDestinataire,omitempty"` + IdDestinataire int64 `json:"idDestinataire,omitempty"` + IdFacture int64 `json:"idFacture,omitempty"` + IdServiceExecutant int64 `json:"idServiceExecutant,omitempty"` + MontantAPayer float32 `json:"montantAPayer,omitempty"` + MontantHT float32 `json:"montantHT,omitempty"` + MontantTTC float32 `json:"montantTTC,omitempty"` + NomServiceExecutant string `json:"nomServiceExecutant,omitempty"` + NomServiceFournisseur string `json:"nomServiceFournisseur,omitempty"` + NumeroBonCommande string `json:"numeroBonCommande,omitempty"` + NumeroFacture string `json:"numeroFacture,omitempty"` + NumeroMarche string `json:"numeroMarche,omitempty"` + Statut string `json:"statut,omitempty"` + Taille int64 `json:"taille,omitempty"` + TypeDemandePaiement string `json:"typeDemandePaiement,omitempty"` + TypeFacture TypeFacture `json:"typeFacture,omitempty"` + TypeFactureTravaux string `json:"typeFactureTravaux,omitempty"` + TypeIdentifiantFournisseur TypeIdentifiant `json:"typeIdentifiantFournisseur,omitempty"` + TypeIdentifiantMOA TypeIdentifiant `json:"typeIdentifiantMOA,omitempty"` + TypeIdentifiantMOE TypeIdentifiant `json:"typeIdentifiantMOE,omitempty"` +} + +func (s *FacturesService) RechercherFactureParRecipiendaire(ctx context.Context, opts RechercherFactureRecipiendaireOptions) (*RechercherFactureParRecipiendaireResponse, error) { req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/rechercher/recipiendaire", opts) if err != nil { return nil, err } - res := new(RechercherFactureRecipiendaireResponse) + res := new(RechercherFactureParRecipiendaireResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} + +type RechercherFactureParValideurOptions struct { + CadreFacturation CadreDeFacturation `json:"cadreFacturation"` + IdDestinataire int64 `json:"idDestinataire"` + IdFournisseur int64 `json:"idFournisseur"` + IdServiceExecutant int64 `json:"idServiceExecutant"` + IdServiceFournisseur int64 `json:"idServiceFournisseur"` + IdStructureMoa int64 `json:"idStructureMoa"` + IdStructureMoe int64 `json:"idStructureMoe"` + IdStructureValideur int64 `json:"idStructureValideur"` + IdUtilisateurCourant int64 `json:"idUtilisateurCourant"` + ListeTypeFacture []string `json:"listeTypeFacture"` + ListeTypeFactureTravaux []string `json:"listeTypeFactureTravaux"` + MontantAPayerMax float32 `json:"montantAPayerMax"` + MontantAPayerMin float32 `json:"montantAPayerMin"` + MontantHTMax float32 `json:"montantHTMax"` + MontantHTMin float32 `json:"montantHTMin"` + MontantTTCMax float32 `json:"montantTTCMax"` + MontantTTCMin float32 `json:"montantTTCMin"` + NumeroEngagement string `json:"numeroEngagement"` + NumeroFacture string `json:"numeroFacture"` + NumeroMarche string `json:"numeroMarche"` + Pagination *PaginationOptions `json:"pagination"` + PeriodeDateDepotAu *Date `json:"periodeDateDepotAu"` + PeriodeDateDepotDu *Date `json:"periodeDateDepotDu"` + PeriodeDateFactureAu *time.Time `json:"periodeDateFactureAu"` + PeriodeDateFactureDu *time.Time `json:"periodeDateFactureDu"` + RechercheSirenDestinataire bool `json:"rechercheSirenDestinataire"` + RechercheSirenFournisseur bool `json:"rechercheSirenFournisseur"` + StatutCourant []string `json:"statutCourant"` + TypeDemandePaiement string `json:"typeDemandePaiement"` +} + +type FactureValideurRecherche struct { + CodeServiceExecutant string `json:"codeServiceExecutant"` + CodeServiceFournisseur string `json:"codeServiceFournisseur"` + CodeServiceMoa string `json:"codeServiceMoa"` + CodeServiceMoe string `json:"codeServiceMoe"` + DateDepot *Date `json:"dateDepot"` + DateFacture *Date `json:"dateFacture"` + DesignationDestinataire string `json:"designationDestinataire"` + DesignationFournisseur string `json:"designationFournisseur"` + DesignationMoa string `json:"designationMoa"` + DesignationMoe string `json:"designationMoe"` + DesignationValideur string `json:"designationValideur"` + Devise string `json:"devise"` + IdDestinataire int64 `json:"idDestinataire"` + IdFacture int64 `json:"idFacture"` + IdFournisseur int64 `json:"idFournisseur"` + IdMoa int64 `json:"idMoa"` + IdMoe int64 `json:"idMoe"` + IdServiceExecutant int64 `json:"idServiceExecutant"` + IdServiceMoa int64 `json:"idServiceMoa"` + IdServiceMoe int64 `json:"idServiceMoe"` + IdValideur int64 `json:"idValideur"` + IdentifiantDestinataire string `json:"identifiantDestinataire"` + IdentifiantFournisseur string `json:"identifiantFournisseur"` + IdentifiantMoa string `json:"identifiantMoa"` + IdentifiantMoe string `json:"identifiantMoe"` + IdentifiantValideur string `json:"identifiantValideur"` + MontantAPayer float32 `json:"montantAPayer"` + MontantHT float32 `json:"montantHT"` + MontantTTC float32 `json:"montantTTC"` + NomServiceExecutant string `json:"nomServiceExecutant"` + NomServiceFournisseur string `json:"nomServiceFournisseur"` + NomServiceMoa string `json:"nomServiceMoa"` + NomServiceMoe string `json:"nomServiceMoe"` + NumeroEngagement string `json:"numeroEngagement"` + NumeroFacture string `json:"numeroFacture"` + NumeroMarche string `json:"numeroMarche"` + Statut string `json:"statut"` + TypeDemandePaiement string `json:"typeDemandePaiement"` + TypeFacture TypeFacture `json:"typeFacture"` + TypeFactureTravaux TypeIdentifiant `json:"typeFactureTravaux"` + TypeIdentifiantDestinataire TypeIdentifiant `json:"typeIdentifiantDestinataire"` + TypeIdentifiantFournisseur TypeIdentifiant `json:"typeIdentifiantFournisseur"` + TypeIdentifiantMoa TypeIdentifiant `json:"typeIdentifiantMoa"` + TypeIdentifiantMoe TypeIdentifiant `json:"typeIdentifiantMoe"` + TypeIdentifiantValideur TypeIdentifiant `json:"typeIdentifiantValideur"` +} + +type RechercherFactureParValideurResponse struct { + CodeRetour int32 `json:"codeRetour"` + Libelle string `json:"libelle"` + Factures []FactureValideurRecherche `json:"listeFactures"` + Pagination *PaginationResponse `json:"parametresRetour"` +} + +func (s *FacturesService) RechercherFactureParValideur(ctx context.Context, opts RechercherFactureParValideurOptions) (*RechercherFactureParValideurResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/rechercher/valideur", opts) + if err != nil { + return nil, err + } + + res := new(RechercherFactureParValideurResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} + +type DestinataireParam struct { + IdDestinataire int64 `json:"idDestinataire"` + ListeIdServiceExecutant []int64 `json:"listeIdServiceExecutant"` + RaisonSocialeStuctDmd string `json:"raisonSocialeStuctDmd"` +} + +type RechercherFactureParFournisseurOptions struct { + CadreFacturation CadreDeFacturation `json:"cadreFacturation"` + CoordonneeBancaire int64 `json:"coordonneeBancaire"` + IdFournisseur int64 `json:"idFournisseur"` + IdServiceFournisseur int64 `json:"idServiceFournisseur"` + IdStructureValideur int64 `json:"idStructureValideur"` + IdUtilisateurCourant int64 `json:"idUtilisateurCourant"` + IdUtilisateurCreateur []int64 `json:"idUtilisateurCreateur"` + ListeDestinataire []DestinataireParam `json:"listeDestinataire"` + ModeDepot string `json:"modeDepot"` + MontantAPayerMax float32 `json:"montantApayerMax"` + MontantAPayerMin float32 `json:"montantApayerMin"` + MontantHTMax float32 `json:"montantHTMax"` + MontantHTMin float32 `json:"montantHTMin"` + MontantTTCMax float32 `json:"montantTTCMax"` + MontantTTCMin float32 `json:"montantTTCMin"` + NumeroBonCommande string `json:"numeroBonCommande"` + NumeroFacture string `json:"numeroFacture"` + NumeroFactureOrigine string `json:"numeroFactureOrigine"` + NumeroFluxDepot string `json:"numeroFluxDepot"` + NumeroMarche string `json:"numeroMarche"` + PeriodeDateDepotAu string `json:"periodeDateDepotAu"` + PeriodeDateDepotDu string `json:"periodeDateDepotDu"` + PeriodeDateFactureAu *Date `json:"periodeDateFactureAu"` + PeriodeDateFactureDu *Date `json:"periodeDateFactureDu"` + PeriodeDateHeureEtatCourantAu *time.Time `json:"periodeDateHeureEtatCourantAu"` + PeriodeDateHeureEtatCourantDu *time.Time `json:"periodeDateHeureEtatCourantDu"` + RechercheFactureParFournisseur *PaginationOptions `json:"rechercheFactureParFournisseur"` + RechercheSirenDestinataire bool `json:"rechercheSirenDestinataire"` + RecupererTaille bool `json:"recupererTaille"` + RejetTraite bool `json:"rejetTraite"` + StatutCourant []string `json:"statutCourant"` + TypeFacture TypeFacture `json:"typeFacture"` +} + +type FactureFournisseurRecherche struct { + AffactureurCode string `json:"affactureurCode"` + AffactureurRaisonSociale string `json:"affactureurRaisonSociale"` + AffactureurTypeIdentifiant string `json:"affactureurTypeIdentifiant"` + CodeDestinataire string `json:"codeDestinataire"` + CodeFournisseur string `json:"codeFournisseur"` + CodeServiceExecutant string `json:"codeServiceExecutant"` + CodeServiceFournisseur string `json:"codeServiceFournisseur"` + CodeValideur1 string `json:"codeValideur1"` + CodeValideur2 string `json:"codeValideur2"` + CommentaireEtatCourant string `json:"commentaireEtatCourant"` + CoordBancairesFournisseurCleIban string `json:"coordBancairesFournisseurCleIban"` + CoordBancairesFournisseurCleRib string `json:"coordBancairesFournisseurCleRib"` + CoordBancairesFournisseurCodeBanque string `json:"coordBancairesFournisseurCodeBanque"` + CoordBancairesFournisseurCodePays string `json:"coordBancairesFournisseurCodePays"` + CoordBancairesFournisseurCompteBancaire string `json:"coordBancairesFournisseurCompteBancaire"` + CoordBancairesFournisseurNomCb string `json:"coordBancairesFournisseurNomCb"` + DateDepot *Date `json:"dateDepot"` + DateFacture *Date `json:"dateFacture"` + DateHeureEtatCourant *time.Time `json:"dateHeureEtatCourant"` + DateValidation1 *Date `json:"dateValidation1"` + DateValidation2 *Date `json:"dateValidation2"` + DesignationDestinataire string `json:"designationDestinataire"` + DesignationFournisseur string `json:"designationFournisseur"` + Devise string `json:"devise"` + IdDestinataire int64 `json:"idDestinataire"` + IdServiceExecutant int64 `json:"idServiceExecutant"` + IdentifiantFactureCPP int64 `json:"identifiantFactureCPP"` + ModeDepot string `json:"modeDepot"` + MontantAPayer float32 `json:"montantAPayer"` + MontantHT float32 `json:"montantHT"` + MontantTTC float32 `json:"montantTTC"` + NomPrenomUtilisateurCreateur string `json:"nomPrenomUtilisateurCreateur"` + NomServiceExecutant string `json:"nomServiceExecutant"` + NomServiceFournisseur string `json:"nomServiceFournisseur"` + NomValideur1 string `json:"nomValideur1"` + NomValideur2 string `json:"nomValideur2"` + NumeroBonCommande string `json:"numeroBonCommande"` + NumeroFacture string `json:"numeroFacture"` + NumeroFactureOrigine string `json:"numeroFactureOrigine"` + NumeroFluxDepot string `json:"numeroFluxDepot"` + NumeroMarche string `json:"numeroMarche"` + PrenomValideur1 string `json:"prenomValideur1"` + PrenomValideur2 string `json:"prenomValideur2"` + RaisonSocialeValideur1 string `json:"raisonSocialeValideur1"` + RaisonSocialeValideur2 string `json:"raisonSocialeValideur2"` + RejetTraite bool `json:"rejetTraite"` + Statut string `json:"statut"` + Taille int64 `json:"taille"` + TypeDemandePaiement string `json:"typeDemandePaiement"` + TypeFacture string `json:"typeFacture"` + TypeIdentifiantFournisseur TypeIdentifiant `json:"typeIdentifiantFournisseur"` + TypeIdentifiantValideur1 TypeIdentifiant `json:"typeIdentifiantValideur1"` + TypeIdentifiantValideur2 TypeIdentifiant `json:"typeIdentifiantValideur2"` +} + +type RechercherFactureParFournisseurResponse struct { + CodeRetour int32 `json:"codeRetour"` + Libelle string `json:"libelle"` + Factures []FactureFournisseurRecherche `json:"listeFactures"` + Pagination *PaginationResponse `json:"parametresRetour"` +} + +func (s *FacturesService) RechercherFactureParFournisseur(ctx context.Context, opts RechercherFactureParFournisseurOptions) (*RechercherFactureParFournisseurResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/rechercher/fournisseur", opts) + if err != nil { + return nil, err + } + + res := new(RechercherFactureParFournisseurResponse) err = s.client.doRequest(ctx, req, res) if err != nil { diff --git a/factures_recherches_test.go b/factures_recherches_test.go index e8bf61a..e86161c 100644 --- a/factures_recherches_test.go +++ b/factures_recherches_test.go @@ -28,7 +28,7 @@ func TestFacturesService_RechercherDemandePaiement(t *testing.T) { "commentaireEtatCourant": "c", "dateDepot": ` + defaultDateStr + `, "dateFournisseur": ` + defaultDateStr + `, - "dateHeureEtatCourant": ` + defaultDateTimeStr + `, + "dateHeureEtatCourant": ` + defaultISODateTimeStr + `, "dpOuDpArchive": "d", "etatCourant": "e", "idDemandePaiement": 1, @@ -165,7 +165,7 @@ func TestFacturesService_RechercherFactureParRecipiendaire(t *testing.T) { "commentaireEtatCourant": "c", "dateDepot": ` + defaultDateStr + `, "dateFacture": ` + defaultDateStr + `, - "dateHeureEtatCourant": ` + defaultDateTimeStr + `, + "dateHeureEtatCourant": ` + defaultISODateTimeStr + `, "designationDestinataire": "d", "designationFournisseur": "d", "designationMOA": "d", @@ -208,10 +208,10 @@ func TestFacturesService_RechercherFactureParRecipiendaire(t *testing.T) { t.Errorf("Factures.RechercherFactureParRecipiendaire returned error : %v", err) } - want := &RechercherFactureRecipiendaireResponse{ + want := &RechercherFactureParRecipiendaireResponse{ CodeRetour: 1, Libelle: "l", - Factures: &[]FactureRecherche{ + Factures: &[]FactureRecipiendaireRecherche{ { CodeDestinataire: "c", CodeFournisseur: "c", @@ -265,3 +265,311 @@ func TestFacturesService_RechercherFactureParRecipiendaire(t *testing.T) { return err }) } + +func TestFacturesService_RechercherFactureParValideur(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/rechercher/valideur", func(w http.ResponseWriter, r *http.Request) { + v := new(RechercherFactureParValideurOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "libelle": "l", + "listeFactures": [ + { + "codeServiceExecutant": "c", + "codeServiceFournisseur": "c", + "codeServiceMoa": "c", + "codeServiceMoe": "c", + "dateDepot": ` + defaultDateStr + `, + "dateFacture": ` + defaultDateStr + `, + "designationDestinataire": "d", + "designationFournisseur": "d", + "designationMoa": "d", + "designationMoe": "d", + "designationValideur": "d", + "devise": "d", + "idDestinataire": 1, + "idFacture": 1, + "idFournisseur": 1, + "idMoa": 1, + "idMoe": 1, + "idServiceExecutant": 1, + "idServiceMoa": 1, + "idServiceMoe": 1, + "idValideur": 1, + "identifiantDestinataire": "i", + "identifiantFournisseur": "i", + "identifiantMoa": "i", + "identifiantMoe": "i", + "identifiantValideur": "i", + "montantAPayer": 1, + "montantHT": 1, + "montantTTC": 1, + "nomServiceExecutant": "n", + "nomServiceFournisseur": "n", + "nomServiceMoa": "n", + "nomServiceMoe": "n", + "numeroEngagement": "n", + "numeroFacture": "n", + "numeroMarche": "n", + "statut": "s", + "typeDemandePaiement": "t", + "typeFacture": "t", + "typeFactureTravaux": "t", + "typeIdentifiantDestinataire": "t", + "typeIdentifiantFournisseur": "t", + "typeIdentifiantMoa": "t", + "typeIdentifiantMoe": "t", + "typeIdentifiantValideur": "t" + } + ], + "parametresRetour": { + "pageCourante": 1, + "pages": 1, + "nbResultatsParPage": 1, + "total": 1 + } + }`)) + }) + + ctx := context.Background() + opt := RechercherFactureParValideurOptions{} + got, err := client.Factures.RechercherFactureParValideur(ctx, opt) + + if err != nil { + t.Errorf("Factures.RechercherFactureParRecipiendaire returned error : %v", err) + } + + want := &RechercherFactureParValideurResponse{ + CodeRetour: 1, + Libelle: "l", + Factures: []FactureValideurRecherche{ + { + CodeServiceExecutant: "c", + CodeServiceFournisseur: "c", + CodeServiceMoa: "c", + CodeServiceMoe: "c", + DateDepot: &Date{defaultDate}, + DateFacture: &Date{defaultDate}, + DesignationDestinataire: "d", + DesignationFournisseur: "d", + DesignationMoa: "d", + DesignationMoe: "d", + DesignationValideur: "d", + Devise: "d", + IdDestinataire: 1, + IdFacture: 1, + IdFournisseur: 1, + IdMoa: 1, + IdMoe: 1, + IdServiceExecutant: 1, + IdServiceMoa: 1, + IdServiceMoe: 1, + IdValideur: 1, + IdentifiantDestinataire: "i", + IdentifiantFournisseur: "i", + IdentifiantMoa: "i", + IdentifiantMoe: "i", + IdentifiantValideur: "i", + MontantAPayer: 1, + MontantHT: 1, + MontantTTC: 1, + NomServiceExecutant: "n", + NomServiceFournisseur: "n", + NomServiceMoa: "n", + NomServiceMoe: "n", + NumeroEngagement: "n", + NumeroFacture: "n", + NumeroMarche: "n", + Statut: "s", + TypeDemandePaiement: "t", + TypeFacture: "t", + TypeFactureTravaux: "t", + TypeIdentifiantDestinataire: "t", + TypeIdentifiantFournisseur: "t", + TypeIdentifiantMoa: "t", + TypeIdentifiantMoe: "t", + TypeIdentifiantValideur: "t", + }, + }, + Pagination: &PaginationResponse{ + PageCourante: 1, + Pages: 1, + NbResultatsParPage: 1, + Total: 1, + }, + } + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.RechercherFactureParValideur returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "RechercherFactureParValideur", client, func() error { + _, err := client.Factures.RechercherFactureParValideur(ctx, opt) + return err + }) +} + +func TestFacturesService_RechercherFactureParFournisseur(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/rechercher/fournisseur", func(w http.ResponseWriter, r *http.Request) { + v := new(RechercherFactureParFournisseurOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "libelle": "l", + "listeFactures": [ + { + "affactureurCode": "a", + "affactureurRaisonSociale": "a", + "affactureurTypeIdentifiant": "a", + "codeDestinataire": "c", + "codeFournisseur": "c", + "codeServiceExecutant": "c", + "codeServiceFournisseur": "c", + "codeValideur1": "c", + "codeValideur2": "c", + "commentaireEtatCourant": "c", + "coordBancairesFournisseurCleIban": "c", + "coordBancairesFournisseurCleRib": "c", + "coordBancairesFournisseurCodeBanque": "c", + "coordBancairesFournisseurCodePays": "c", + "coordBancairesFournisseurCompteBancaire": "c", + "coordBancairesFournisseurNomCb": "c", + "dateDepot": ` + defaultDateStr + `, + "dateFacture": ` + defaultDateStr + `, + "dateHeureEtatCourant": ` + defaultISODateTimeStr + `, + "dateValidation1": ` + defaultDateStr + `, + "dateValidation2": ` + defaultDateStr + `, + "designationDestinataire": "d", + "designationFournisseur": "d", + "devise": "d", + "idDestinataire": 1, + "idServiceExecutant": 1, + "identifiantFactureCPP": 1, + "modeDepot": "m", + "montantAPayer": 1, + "montantHT": 1, + "montantTTC": 1, + "nomPrenomUtilisateurCreateur": "n", + "nomServiceExecutant": "n", + "nomServiceFournisseur": "n", + "nomValideur1": "n", + "nomValideur2": "n", + "numeroBonCommande": "n", + "numeroFacture": "n", + "numeroFactureOrigine": "n", + "numeroFluxDepot": "n", + "numeroMarche": "n", + "prenomValideur1": "p", + "prenomValideur2": "p", + "raisonSocialeValideur1": "r", + "raisonSocialeValideur2": "r", + "rejetTraite": true, + "statut": "s", + "taille": 1, + "typeDemandePaiement": "t", + "typeFacture": "t", + "typeIdentifiantFournisseur": "t", + "typeIdentifiantValideur1": "t", + "typeIdentifiantValideur2": "t" + } + ], + "parametresRetour": { + "pageCourante": 1, + "pages": 1, + "nbResultatsParPage": 1, + "total": 1 + } + }`)) + }) + + ctx := context.Background() + opt := RechercherFactureParFournisseurOptions{} + got, err := client.Factures.RechercherFactureParFournisseur(ctx, opt) + + if err != nil { + t.Errorf("Factures.RechercherFactureParFournisseur returned error : %v", err) + } + + want := &RechercherFactureParFournisseurResponse{ + CodeRetour: 1, + Libelle: "l", + Factures: []FactureFournisseurRecherche{ + { + AffactureurCode: "a", + AffactureurRaisonSociale: "a", + AffactureurTypeIdentifiant: "a", + CodeDestinataire: "c", + CodeFournisseur: "c", + CodeServiceExecutant: "c", + CodeServiceFournisseur: "c", + CodeValideur1: "c", + CodeValideur2: "c", + CommentaireEtatCourant: "c", + CoordBancairesFournisseurCleIban: "c", + CoordBancairesFournisseurCleRib: "c", + CoordBancairesFournisseurCodeBanque: "c", + CoordBancairesFournisseurCodePays: "c", + CoordBancairesFournisseurCompteBancaire: "c", + CoordBancairesFournisseurNomCb: "c", + DateDepot: &Date{defaultDate}, + DateFacture: &Date{defaultDate}, + DateHeureEtatCourant: &defaultDate, + DateValidation1: &Date{defaultDate}, + DateValidation2: &Date{defaultDate}, + DesignationDestinataire: "d", + DesignationFournisseur: "d", + Devise: "d", + IdDestinataire: 1, + IdServiceExecutant: 1, + IdentifiantFactureCPP: 1, + ModeDepot: "m", + MontantAPayer: 1, + MontantHT: 1, + MontantTTC: 1, + NomPrenomUtilisateurCreateur: "n", + NomServiceExecutant: "n", + NomServiceFournisseur: "n", + NomValideur1: "n", + NomValideur2: "n", + NumeroBonCommande: "n", + NumeroFacture: "n", + NumeroFactureOrigine: "n", + NumeroFluxDepot: "n", + NumeroMarche: "n", + PrenomValideur1: "p", + PrenomValideur2: "p", + RaisonSocialeValideur1: "r", + RaisonSocialeValideur2: "r", + RejetTraite: true, + Statut: "s", + Taille: 1, + TypeDemandePaiement: "t", + TypeFacture: "t", + TypeIdentifiantFournisseur: "t", + TypeIdentifiantValideur1: "t", + TypeIdentifiantValideur2: "t", + }, + }, + Pagination: &PaginationResponse{ + PageCourante: 1, + Pages: 1, + NbResultatsParPage: 1, + Total: 1, + }, + } + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.RechercherFactureParFournisseur returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "RechercherFactureParFournisseur", client, func() error { + _, err := client.Factures.RechercherFactureParFournisseur(ctx, opt) + return err + }) +} diff --git a/factures_traitements.go b/factures_traitements.go index 7f2173d..7330923 100644 --- a/factures_traitements.go +++ b/factures_traitements.go @@ -39,3 +39,67 @@ func (s *FacturesService) TraiterFactureAValider(ctx context.Context, opts Trait return res, nil } + +type TraiterFactureRecueOptions struct { + IdFacture int64 `json:"idFacture"` + IdUtilisateurCourant int64 `json:"idUtilisateurCourant"` + Motif string `json:"motif"` + NouveauStatut string `json:"nouveauStatut"` + NumeroDPMandat string `json:"numeroDPMandat"` +} + +type TraiterFactureRecueResponse struct { + CodeRetour int32 `json:"codeRetour"` + DateTraitement *Date `json:"dateTraitement"` + IdFacture int64 `json:"idFacture"` + Libelle string `json:"libelle"` + NouveauStatut string `json:"nouveauStatut"` + NumeroFacture string `json:"numeroFacture"` +} + +func (s *FacturesService) TraiterFactureRecue(ctx context.Context, opts TraiterFactureRecueOptions) (*TraiterFactureRecueResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/traiter/recue", opts) + if err != nil { + return nil, err + } + + res := new(TraiterFactureRecueResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} + +type DemandePaiementParam struct { + IdDemandePaiement int64 `json:"idDemandePaiement"` +} + +type TraiterRejetOptions struct { + CpltInfos string `json:"cpltInfos"` + ListeDemandePaiement []DemandePaiementParam `json:"listeDemandePaiement"` + MotifRejet string `json:"motifRejet"` +} + +type TraiterRejetResponse struct { + CodeRetour int32 `json:"codeRetour"` + Libelle string `json:"libelle"` +} + +func (s *FacturesService) TraiterRejet(ctx context.Context, opts TraiterRejetOptions) (*TraiterRejetResponse, error) { + req, err := s.client.newRequest(ctx, http.MethodPost, "cpro/factures/v1/traiterRejet", opts) + if err != nil { + return nil, err + } + + res := new(TraiterRejetResponse) + + err = s.client.doRequest(ctx, req, res) + if err != nil { + return nil, err + } + + return res, nil +} diff --git a/factures_traitements_test.go b/factures_traitements_test.go index 1e6dd6e..99e5950 100644 --- a/factures_traitements_test.go +++ b/factures_traitements_test.go @@ -52,3 +52,85 @@ func TestFacturesService_TraiterFactureAValider(t *testing.T) { return err }) } + +func TestFacturesService_TraiterFactureRecue(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/traiter/recue", func(w http.ResponseWriter, r *http.Request) { + v := new(TraiterFactureRecueOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "dateTraitement": ` + defaultDateStr + `, + "idFacture": 1, + "libelle": "l", + "nouveauStatut": "n", + "numeroFacture": "n" + }`)) + }) + + ctx := context.Background() + opt := TraiterFactureRecueOptions{} + got, err := client.Factures.TraiterFactureRecue(ctx, opt) + + if err != nil { + t.Errorf("Factures.TraiterFactureRecue returned error : %v", err) + } + + want := &TraiterFactureRecueResponse{ + CodeRetour: 1, + DateTraitement: &Date{defaultDate}, + IdFacture: 1, + Libelle: "l", + NouveauStatut: "n", + NumeroFacture: "n", + } + + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.TraiterFactureRecue returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "TraiterFactureRecue", client, func() error { + _, err := client.Factures.TraiterFactureRecue(ctx, opt) + return err + }) +} + +func TestFacturesService_TraiterRejet(t *testing.T) { + client, mux, teardown := setup() + defer teardown() + + mux.HandleFunc("/cpro/factures/v1/traiterRejet", func(w http.ResponseWriter, r *http.Request) { + v := new(TraiterRejetOptions) + assertNilError(t, json.NewDecoder(r.Body).Decode(v)) + testMethod(t, r, http.MethodPost) + w.Write([]byte(`{ + "codeRetour": 1, + "libelle": "l" + }`)) + }) + + ctx := context.Background() + opt := TraiterRejetOptions{} + got, err := client.Factures.TraiterRejet(ctx, opt) + + if err != nil { + t.Errorf("Factures.TraiterRejet returned error : %v", err) + } + + want := &TraiterRejetResponse{ + CodeRetour: 1, + Libelle: "l", + } + + if !reflect.DeepEqual(got, want) { + t.Errorf("Factures.TraiterRejet returned %+v, want %+v", got, want) + } + + testNewRequestAndDoRequestFailure(t, "TraiterRejet", client, func() error { + _, err := client.Factures.TraiterRejet(ctx, opt) + return err + }) +} diff --git a/pagination.go b/pagination.go index bbea41b..e332dc1 100644 --- a/pagination.go +++ b/pagination.go @@ -41,3 +41,24 @@ type PaginationLignesRecapTVAOptions struct { TriColonne string `json:"triColonneListeRecapitulatifTVA,omitempty"` TriSens TriSens `json:"triSensListeRecapitulatifTVA,omitempty"` } + +type PaginationHistoActionsUtilisateursOptions struct { + NbResultatsParPageListeHistoAction int `json:"nbResultatsParPageListeHistoAction"` + PageResultatDemandeeListeHistoAction int `json:"pageResultatDemandeeListeHistoAction"` + TriColonneListeHistoAction string `json:"triColonneListeHistoAction"` + TriSensListeHistoAction string `json:"triSensListeHistoAction"` +} + +type PaginationHistoEvenementsComplementairesOptions struct { + NbResultatsParPageListeHistoEvenement int `json:"nbResultatsParPageListeHistoEvenement"` + PageResultatDemandeeListeHistoEvenement int `json:"pageResultatDemandeeListeHistoEvenement"` + TriColonneListeHistoEvenement string `json:"triColonneListeHistoEvenement"` + TriSensListeHistoEvenement string `json:"triSensListeHistoEvenement"` +} + +type PaginationHistoStatutsOptions struct { + NbResultatsParPageListeHistoStatut int `json:"nbResultatsParPageListeHistoStatut"` + PageResultatDemandeeListeHistoStatut int `json:"pageResultatDemandeeListeHistoStatut"` + TriColonneListeHistoStatut string `json:"triColonneListeHistoStatut"` + TriSensListeHistoStatut string `json:"triSensListeHistoStatut"` +}