Import d'écritures (API)

De Wiki1000
(Redirigé depuis Import d'écriture (API))

Ce exemple montre comment importer des écritures en utilisant l'API SData.

Pour réaliser l'import d'écriture on utilise le processus d'import des écritures basée sur des sessions d'import.

Pour cela il faut :

  1. Créer une session d'import (TSessionImport)
  2. Créer les écritures d'import (TEcritureImport) rattachées à cette session
  3. Exécuter le processus d'exécution de session d'import (TProcessusPlanifImport)
POST https://localhost/sdata/S1/$batch
{
    "$": {"$transaction":["atomic"]},
    "$resources": [
        {
            "$httpMethod":"POST",
            "$url":"cptimport/tsessionimport",
            "$uuid":"session",
            "Caption":"Session import par API - 4",
            "CompteEquilibre":{"$url":"TCompteGeneral(codeCompte eq '10500000')"},
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "SessionImport":{"$uuid":"session"},
            "codeJournal": "ACH",
            "compteAuxiliaire": "F-ABI 007",
            "compteGeneral": "40110000",
            "dateEcheance": "2019-01-30T23:00:00.000Z",
            "datePiece": "2018-12-31T23:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "modePaiement": "LCR",
            "montant": 1200,
            "montantEnDevise": 1200,
            "numeroPiece": "AC2009/01-000147",
            "sens": "C",
            "typeCompte": "X",
            "typeEcriture": "Brouillard",
            "typePiece": "AF"
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "codeJournal": "ACH",
            "compteGeneral": "60114000",
            "dateEcheance": "1899-12-30T00:00:00.000Z",
            "datePiece": "2018-12-31T23:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "montant": 1200,
            "montantEnDevise": 1200,
            "numeroPiece": "AC2009/01-000147",
            "sens": "D",
            "typeEcriture": "Brouillard",
            "typePiece": "AF"
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "SessionImport":{"$uuid":"session"},
            "codeJournal": "ACH",
            "compteGeneral": "47100000",
            "dateEcheance": "1899-12-30T00:00:00.000Z",
            "datePiece": "2018-12-31T23:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "montant": 1000,
            "montantEnDevise": 1000,
            "numeroPiece": "AC2009/01-000148",
            "sens": "C",
            "typeEcriture": "Brouillard",
            "typePiece": "AF"
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "SessionImport":{"$uuid":"session"},
            "codeJournal": "ACH",
            "compteGeneral": "60114000",
            "dateEcheance": "1899-12-30T00:00:00.000Z",
            "datePiece": "2018-12-31T23:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "montant": 1000,
            "montantEnDevise": 1000,
            "numeroPiece": "AC2009/01-000148",
            "sens": "D",
            "typeEcriture": "Brouillard",
            "typePiece": "AF"
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "SessionImport":{"$uuid":"session"},
            "codeJournal": "ACH",
            "compteAuxiliaire": "F-BARRES",
            "compteGeneral": "40110000",
            "dateEcheance": "2019-01-30T23:00:00.000Z",
            "datePiece": "2018-12-31T23:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "modePaiement": "LCR",
            "montant": 1000,
            "montantEnDevise": 1000,
            "numeroPiece": "AC2009/01-000149",
            "sens": "C",
            "typeCompte": "X",
            "typeEcriture": "Brouillard",
            "typePiece": "AF"
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "SessionImport":{"$uuid":"session"},
            "codeJournal": "ACH",
            "compteGeneral": "60114000",
            "dateEcheance": "1899-12-30T00:00:00.000Z",
            "datePiece": "2018-12-31T23:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "montant": 1000,
            "montantEnDevise": 1000,
            "numeroPiece": "AC2009/01-000149",
            "sens": "D",
            "typeEcriture": "Brouillard",
            "typePiece": "AF"
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "SessionImport":{"$uuid":"session"},
            "codeJournal": "ACH",
            "compteGeneral": "47100000",
            "dateEcheance": "1899-12-30T00:00:00.000Z",
            "datePiece": "2018-12-31T23:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "montant": 100,
            "montantEnDevise": 100,
            "numeroPiece": "AC2009/01-000150",
            "sens": "C",
            "typeEcriture": "Brouillard",
            "typePiece": "AF"
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "SessionImport":{"$uuid":"session"},
            "codeJournal": "ACH",
            "compteGeneral": "60114000",
            "dateEcheance": "1899-12-30T00:00:00.000Z",
            "datePiece": "2018-12-31T23:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "montant": 100,
            "montantEnDevise": 100,
            "numeroPiece": "AC2009/01-000150",
            "sens": "D",
            "typeEcriture": "Brouillard",
            "typePiece": "AF"
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "SessionImport":{"$uuid":"session"},
            "codeJournal": "ACH",
            "compteAuxiliaire": "F-BARRES",
            "compteGeneral": "40110000",
            "dateEcheance": "2019-07-30T22:00:00.000Z",
            "datePiece": "2019-06-15T22:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "libelleEcriture": "libellé",
            "modePaiement": "LCR",
            "montant": 100,
            "montantEnDevise": 100,
            "numeroPiece": "AC2009/06-000001",
            "sens": "C",
            "typeCompte": "X",
            "typeEcriture": "Brouillard",
            "typePiece": "FF"
        },
        {
            "$httpMethod":"POST",
            "$url":"cptimport/timportecritures",
            "SessionImport":{"$uuid":"session"},
            "codeJournal": "ACH",
            "compteGeneral": "47100000",
            "dateEcheance": "1899-12-30T00:00:00.000Z",
            "datePiece": "2019-06-15T22:00:00.000Z",
            "deviseEcriture": "EUR",
            "deviseTenueCompte": "EUR",
            "etablissement": "ETS1-S01",
            "libelleEcriture": "libellé",
            "montant": 100,
            "montantEnDevise": 100,
            "numeroPiece": "AC2009/06-000001",
            "sens": "D",
            "typeEcriture": "Brouillard",
            "typePiece": "FF"
        },
        {
            "$": {"$transaction":["commit"]},
            "$httpMethod":"EXEC",
            "$url":"cptimportmouvement/TProcessusPlanifImport/Executer",
            "$uuid":"processus",
            "$resource" : {
                "codeSessionInf":"Session import par API - 4",
                "codeSessionSup":"Session import par API - 4",
                "importerExterne":true,
            }
        },
    ]
}
Tip-20px.png Tip : Notez l'utilisation de $transaction "commit" dans l'exécution du processus TProcessusPlanifImport, cette directive termine la transaction ouverte par le batch car ce processus ne fonctionne pas si une transaction longue est ouverte avant l'exécution.

Le résultat de l'exécution :

{
    "$baseUrl": "http://localhost:8080/sdata/l1000/-/-/",
    "$title": "$batch - -",
    "$resources": [
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C300020413000002450001-000001CF00000001",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TSessionImport('1B28EFFFF1C300020413000002450001')",
            "$milliseconds": "129,1544"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C300020308000002450002-000001CF00000002",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C300020308000002450002')",
            "$milliseconds": "2,6776"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C300020308000002450003-000001CF00000003",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C300020308000002450003')",
            "$milliseconds": "0,9213"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C300020308000002450004-000001CF00000004",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C300020308000002450004')",
            "$milliseconds": "1,0709"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C300020308000002450005-000001CF00000005",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C300020308000002450005')",
            "$milliseconds": "1,1676"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C300020308000002450006-000001CF00000006",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C300020308000002450006')",
            "$milliseconds": "0,9573"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C300020308000002450007-000001CF00000007",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C300020308000002450007')",
            "$milliseconds": "1,1896"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C300020308000002450008-000001CF00000008",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C300020308000002450008')",
            "$milliseconds": "2,8675"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C300020308000002450009-000001CF00000009",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C300020308000002450009')",
            "$milliseconds": "2,0515"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C30002030800000245000A-000001CF0000000A",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C30002030800000245000A')",
            "$milliseconds": "1,2315"
        },
        {
            "$httpStatus": 201,
            "$httpMethod": "POST",
            "$httpMessage": "Created",
            "$etag": "1B28EFFFF1C30002030800000245000B-000001CF0000000B",
            "$location": "http://localhost:8080/sdata/l1000/cptimport/-/TImportEcritures('1B28EFFFF1C30002030800000245000B')",
            "$milliseconds": "1,1972"
        },
        {
            "$httpStatus": 200,
            "$httpMethod": "EXEC",
            "$httpMessage": "Executed",
            "$url": "cptimportmouvement/TProcessusPlanifImport/Executer",
            "$uuid": "processus",
            "result": 0,
            "$milliseconds": "2044,6074",
            "$messages": [
                "Importation de la session \"Session import par API - 13\"",
                "Erreur d'importation : lignes 1-:1",
                "Le solde de la pièce AC2019/01-000186 doit être nul en devise de tenue , de reporting et en devise de transaction (Lot n°251).",
                "Enregistrement pièce n° AC2019/01-000187",
                "Enregistrement pièce n° AC2019/01-000188",
                "Enregistrement pièce n° AC2019/01-000189",
                "Enregistrement pièce n° AC2019/06-000046",
                "Traitement terminé."
            ]  
        }
    ],
    "$batch": {
        "$httpStatus": 200,
        "$httpMessage": "OK",
        "$milliseconds": "2344,0533"
    }
}
Outils personnels