Interrogation des écritures (API)

De Wiki1000

Cet exemple montre comment récupérer les écritures en utilisant l'API SData.

Sommaire

Utilisation de la classe des écritures

Dans cet exemple, nous interrogeons la classe des écritures.

http://localhost:8080/sdata/gentiers/tecriture?select=edate&where=(edate ge "2015-01-01")&orderBy=eDate&count=1
{
    "$baseUrl": "http://localhost:8080/sdata/cptmouvement/",
    "$title": "TEcriture - -",
    "$updated": "2021-01-28T10:58:09.438Z",
    "$resources": [
        {
            "$url": "TEcriture('1B28EFFFF1C300020133000000130E2F')",
            "$title": "18650 - Pièce:AN2012/01-000001",
            "$updated": "2013-04-16T09:12:52.000Z",
            "$etag": "1B28EFFFF1C300020133000000130E2F-000004640000306F",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "1B28EFFFF1C300020133000000130E2F",
            "stamp": "000004640000306F",
            "eDate": "2014-12-31T23:00:00.000Z"
        }
    ],
    "$nextUrl": "http://localhost:8080/sdata/cptmouvement/tecriture?select=edate&where=(edate ge \"2015-01-01\") &orderBy=edate&count=1&startKey='1B28EFFFF1C300020133000000130E2F'&keyDirection=gt"
}

Utilisation d'une vue sur les écritures

Dans cet exemple, nous interrogeons la classe des écritures en définissant un alias sur l'attribut retourné.

Le fait d'utiliser un alias provoque l'utilisation d'une vue.

http://localhost:8080/sdata/gentiers/tecriture?select=date as edate&where=(date ge "2015-01-01")&orderBy=date&count=1
{
    "$baseUrl": "http://localhost:8080/sdata/cptmouvement/",
    "$title": "TEcriture - -",
    "$updated": "2021-01-28T11:00:38.671Z",
    "$resources": [
        {
            "$url": "TEcriture('1B28EFFFF1C300020133000000130E2F')",
            "$title": "1B28EFFFF1C300020133000000130E2F",
            "$updated": "2013-04-16T09:12:52.000Z",
            "$etag": "1B28EFFFF1C300020133000000130E2F-000004640000306F",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "1B28EFFFF1C300020133000000130E2F",
            "stamp": "000004640000306F",
            "date": "2014-12-31T23:00:00.000Z"
        }
    ],
    "$nextUrl": "http://localhost:8080/sdata/cptmouvement/tecriture?select=date as edate&where=(date ge \"2015-01-01\")&orderBy=date&count=1&startKey='1B28EFFFF1C300020133000000130E2F'&keyDirection=gt"
}

Notez la définition du filtre utilisant l'alias de l'attribut dans la requête.

Utilisation d'une vue standard sur les écritures

Dans cet exemple, nous interrogeons une vue standard des écritures :

http://localhost:8080/sdata/gentiers/tvueecriture?select=dateEcriture,montant&where=(dateEcriture ge "2015-01-01") &orderBy=dateEcriture&count=1
{
    "$baseUrl": "http://localhost:8080/sdata/cptmouvement/",
    "$title": "TVueEcriture - -",
    "$updated": "2021-01-28T10:59:29.269Z",
    "$resources": [
        {
            "$url": "TVueEcriture('1B28EFFFF1C300020133000000130E2F')",
            "$title": "1B28EFFFF1C300020133000000130E2F",
            "$updated": "2013-04-16T09:12:52.000Z",
            "$etag": "1B28EFFFF1C300020133000000130E2F-000004640000306F",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "1B28EFFFF1C300020133000000130E2F",
            "stamp": "000004640000306F",
            "dateEcriture": "2014-12-31T23:00:00.000Z",
            "montant": {
                "value": 360000,
                "CodeDevise": "EUR",
                "Date": "2014-12-31T23:00:00.000Z",
                "TCConv": "",
                "TCValue": 360000,
                "RPConv": "",
                "RPValue": 323676
            }
        }
    ],
    "$nextUrl": "http://localhost:8080/sdata/cptmouvement/tvueecriture?select=dateEcriture,montant&where=(dateEcriture ge \"2015-01-01\") &orderBy=dateEcriture&count=1&startKey='1B28EFFFF1C300020133000000130E2F'&keyDirection=gt"
}
Tip-20px.png Tip : Il peut être intéressant de forcer l'utilisation d'une vue même quand les colonnes retournées sont dans la classe de base. En effet, la vue ne va pas exécuter les règles métiers AfterLoad de la classe de base et peut dans certain cas être plus performante. Par exemple le chargement d'une écriture comptable provoque l'exécution de 3 requêtes alors que le chargement d'une vue d'une écritures une seule. Ansi si votre interrogation retourne 100 écritures, elle génère 1 + 100*2 requêtes avec la classe des écritures mais une seule avec une vue sur les écritures.

Interrogation d'agrégat d'écritures

Dans cet exemple, nous interrogeons une vue standard des écritures en utilisant un opérateur "somme" sur l'attribut montant et en filtrant sur une tranche de date.

L'utilisation d'un opérateur provoque l'utilisation d'une vue sur la vue standard.

http://localhost:8080/sdata/gentiers/tvueecriture?select=sum(montant)&where=(dateEcriture ge "2015-01-01") and (dateEcriture le "2015-12-31")&count=4
{
    "$baseUrl": "http://localhost:8080/sdata/cptmouvement/",
    "$title": "TVueEcriture - -",
    "$updated": "2021-01-28T11:03:14.490Z",
    "$resources": [
        {
            "$url": "TVueEcriture('FFFFFFFFFFFFEEEE0000627300000035')",
            "$title": "FFFFFFFFFFFFEEEE0000627300000035",
            "$updated": "1899-12-30T00:00:00.000Z",
            "$etag": "FFFFFFFFFFFFEEEE0000627300000035-0000022C00000005",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "FFFFFFFFFFFFEEEE0000627300000035",
            "stamp": "0000022C00000005",
            "montant": {
                "value": 800000000,
                "CodeDevise": "PTE",
                "Date": "2021-01-27T23:00:00.000Z",
                "TCConv": "",
                "TCValue": 3990383.16,
                "RPConv": "",
                "RPValue": 3551441.04
            }
        },
        {
            "$url": "TVueEcriture('FFFFFFFFFFFFEEEE0000627300000038')",
            "$title": "FFFFFFFFFFFFEEEE0000627300000038",
            "$updated": "1899-12-30T00:00:00.000Z",
            "$etag": "FFFFFFFFFFFFEEEE0000627300000038-0000022C00000005",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "FFFFFFFFFFFFEEEE0000627300000038",
            "stamp": "0000022C00000005",
            "montant": {
                "value": 4000000,
                "CodeDevise": "GBP",
                "Date": "2021-01-27T23:00:00.000Z",
                "TCConv": "",
                "TCValue": 6939625.28,
                "RPConv": "",
                "RPValue": 4000000
            }
        },
        {
            "$url": "TVueEcriture('FFFFFFFFFFFFEEEE000062730000003B')",
            "$title": "FFFFFFFFFFFFEEEE000062730000003B",
            "$updated": "1899-12-30T00:00:00.000Z",
            "$etag": "FFFFFFFFFFFFEEEE000062730000003B-0000022C00000005",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "FFFFFFFFFFFFEEEE000062730000003B",
            "stamp": "0000022C00000005",
            "montant": {
                "value": 3686300.24,
                "CodeDevise": "USD",
                "Date": "2021-01-27T23:00:00.000Z",
                "TCConv": "",
                "TCValue": 4662106.56,
                "RPConv": "",
                "RPValue": 2929478.68
            }
        },
        {
            "$url": "TVueEcriture('FFFFFFFFFFFFEEEE000062730000003E')",
            "$title": "FFFFFFFFFFFFEEEE000062730000003E",
            "$updated": "1899-12-30T00:00:00.000Z",
            "$etag": "FFFFFFFFFFFFEEEE000062730000003E-0000022C00000005",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "FFFFFFFFFFFFEEEE000062730000003E",
            "stamp": "0000022C00000005",
            "montant": {
                "value": 1455011361.6,
                "CodeDevise": "EUR",
                "Date": "2021-01-27T23:00:00.000Z",
                "TCConv": "",
                "TCValue": 1455011361.6,
                "RPConv": "",
                "RPValue": 1303787971.66
            }
        }
    ],
    "$nextUrl": "http://localhost:8080/sdata/cptmouvement/tvueecriture?select=sum(montant)&where=(dateEcriture ge \"2015-01-01\") and (dateEcriture le \"2015-12-31\")&count=4&startKey='FFFFFFFFFFFFEEEE000062730000003E'&keyDirection=gt"
}

Notez que lorsqu'un opérateur de regroupement est réalisé sur un montant, celui est regroupé par devise et la date du montant est la date du jour.

Exemple utilisant un opérateur à deux paramètres :

http://localhost:8080/sdata/gentiers/tvueecriture?select=diff as sumdiff(debit;credit)&where=(dateEcriture ge "2015-01-01") and (dateEcriture le "2015-12-31")&count=4
{
    "$baseUrl": "http://localhost:8080/sdata/cptmouvement/",
    "$title": "TVueEcriture - -",
    "$updated": "2021-01-28T17:08:11.573Z",
    "$resources": [
        {
            "$url": "TVueEcriture('FFFFFFFFFFFFEEEE0000968D00000002')",
            "$title": "FFFFFFFFFFFFEEEE0000968D00000002",
            "$updated": "1899-12-30T00:00:00.000Z",
            "$etag": "FFFFFFFFFFFFEEEE0000968D00000002-0000022E00000001",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "FFFFFFFFFFFFEEEE0000968D00000002",
            "stamp": "0000022E00000001",
            "diff": {
                "value": 0,
                "CodeDevise": "PTE",
                "Date": "2021-01-27T23:00:00.000Z",
                "TCConv": "",
                "TCValue": 0,
                "RPConv": "",
                "RPValue": 0
            }
        },
        {
            "$url": "TVueEcriture('FFFFFFFFFFFFEEEE0000968D00000005')",
            "$title": "FFFFFFFFFFFFEEEE0000968D00000005",
            "$updated": "1899-12-30T00:00:00.000Z",
            "$etag": "FFFFFFFFFFFFEEEE0000968D00000005-0000022E00000001",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "FFFFFFFFFFFFEEEE0000968D00000005",
            "stamp": "0000022E00000001",
            "diff": {
                "value": 0,
                "CodeDevise": "GBP",
                "Date": "2021-01-27T23:00:00.000Z",
                "TCConv": "",
                "TCValue": 0,
                "RPConv": "",
                "RPValue": 0
            }
        },
        {
            "$url": "TVueEcriture('FFFFFFFFFFFFEEEE0000968D00000008')",
            "$title": "FFFFFFFFFFFFEEEE0000968D00000008",
            "$updated": "1899-12-30T00:00:00.000Z",
            "$etag": "FFFFFFFFFFFFEEEE0000968D00000008-0000022E00000001",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "FFFFFFFFFFFFEEEE0000968D00000008",
            "stamp": "0000022E00000001",
            "diff": {
                "value": 0,
                "CodeDevise": "USD",
                "Date": "2021-01-27T23:00:00.000Z",
                "TCConv": "",
                "TCValue": 0,
                "RPConv": "",
                "RPValue": 0
            }
        },
        {
            "$url": "TVueEcriture('FFFFFFFFFFFFEEEE0000968D0000000B')",
            "$title": "FFFFFFFFFFFFEEEE0000968D0000000B",
            "$updated": "1899-12-30T00:00:00.000Z",
            "$etag": "FFFFFFFFFFFFEEEE0000968D0000000B-0000022E00000001",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "FFFFFFFFFFFFEEEE0000968D0000000B",
            "stamp": "0000022E00000001",
            "diff": {
                "value": 0,
                "CodeDevise": "EUR",
                "Date": "2021-01-27T23:00:00.000Z",
                "TCConv": "",
                "TCValue": 0,
                "RPConv": "",
                "RPValue": 0
            }
        }
    ],
    "$nextUrl": "http://localhost:8080/sdata/cptmouvement/tvueecriture?select=diff as sumdiff(debit;credit)&where=(dateEcriture ge \"2015-01-01\") and (dateEcriture le \"2015-12-31\")&count=4&startKey='FFFFFFFFFFFFEEEE0000968D0000000B'&keyDirection=gt"
}

Interrogation des cumuls

Dans cet exemple, nous interrogeons les cumuls période des compte généraux, pour la norme NAT, les période 2015 et les comptes 401*

http://localhost:8080/sdata/gentiers/tcumulperiodecompte?select=codeCompte as compteGeneral.codeCompte,dateDebut as periode.datedebut,dateFin as periode.dateFin,credit,debit&where=(codeCompte like "4011%25") and (normeComptable.code eq "NAT") and (datedebut ge "2015-01-01") and (dateFin le "2015-12-31")&orderby=codeCompte
{
    "$baseUrl": "http://localhost:8080/sdata/cptenvironnement/",
    "$title": "TCumulPeriodeCompte - -",
    "$updated": "2021-01-28T13:26:41.940Z",
    "$resources": [
        {
            "$url": "TCumulPeriodeCompte('1B28EFFFF1C30002025F000000164D19')",
            "$title": "1B28EFFFF1C30002025F000000164D19",
            "$updated": "2020-02-25T14:52:51.000Z",
            "$etag": "1B28EFFFF1C30002025F000000164D19-0000001300007390",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "1B28EFFFF1C30002025F000000164D19",
            "stamp": "0000001300007390",
            "codeCompte": "40110000",
            "credit": 0,
            "dateDebut": "2014-12-31T23:00:00.000Z",
            "dateFin": "2015-01-30T23:00:00.000Z",
            "debit": 0
        },
        {
            "$url": "TCumulPeriodeCompte('1B28EFFFF1C30002025F000000164D22')",
            "$title": "1B28EFFFF1C30002025F000000164D22",
            "$updated": "2020-02-25T14:52:51.000Z",
            "$etag": "1B28EFFFF1C30002025F000000164D22-0000001300007399",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "1B28EFFFF1C30002025F000000164D22",
            "stamp": "0000001300007399",
            "codeCompte": "40110000",
            "credit": 0,
            "dateDebut": "2014-12-31T23:00:00.000Z",
            "dateFin": "2015-01-30T23:00:00.000Z",
            "debit": 0
        },
        {
            "$url": "TCumulPeriodeCompte('1B28EFFFF1C30002025F000000164D2A')",
            "$title": "1B28EFFFF1C30002025F000000164D2A",
            "$updated": "2020-02-25T14:52:51.000Z",
            "$etag": "1B28EFFFF1C30002025F000000164D2A-00000013000073A1",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "1B28EFFFF1C30002025F000000164D2A",
            "stamp": "00000013000073A1",
            "codeCompte": "40110000",
            "credit": 0,
            "dateDebut": "2014-12-31T23:00:00.000Z",
            "dateFin": "2015-01-30T23:00:00.000Z",
            "debit": 0
        },
        {
            "$url": "TCumulPeriodeCompte('1B28EFFFF1C30002025F000000164D31')",
            "$title": "1B28EFFFF1C30002025F000000164D31",
            "$updated": "2020-02-25T14:52:51.000Z",
            "$etag": "1B28EFFFF1C30002025F000000164D31-00000013000073A8",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "1B28EFFFF1C30002025F000000164D31",
            "stamp": "00000013000073A8",
            "codeCompte": "40110000",
            "credit": 0,
            "dateDebut": "2014-12-31T23:00:00.000Z",
            "dateFin": "2015-01-30T23:00:00.000Z",
            "debit": 0
        },
        {
            "$url": "TCumulPeriodeCompte('1B28EFFFF1C30002025F000000164D3B')",
            "$title": "1B28EFFFF1C30002025F000000164D3B",
            "$updated": "2020-02-25T14:52:51.000Z",
            "$etag": "1B28EFFFF1C30002025F000000164D3B-00000013000073B2",
            "$shareId": "1B28EFFFF1C30002000300000003000B",
            "$shareInfo": "S1",
            "$shareLevel": 2,
            "$key": "1B28EFFFF1C30002025F000000164D3B",
            "stamp": "00000013000073B2",
            "codeCompte": "40112000",
            "credit": 0,
            "dateDebut": "2014-12-31T23:00:00.000Z",
            "dateFin": "2015-01-30T23:00:00.000Z",
            "debit": 0
        }
    ]
}
Outils personnels