1 = Informatiser une comptabilité avec confiance
2 :author: git://git.autogeree.net/tool/hledger
3 :copyright: © 2014 (CC) BY Julien Moutinho <julm+hledger@autogeree.net>
8 :slidebackground: hledgersplash
9 :slidefontsizeadjust: -3
13 :scriptsdir: $PWD/javascripts
14 ifdef::backend-slidy2[:data-uri:]
16 ifdef::backend-slidy2[:slidebackground!:]
18 // a2x: --xsltproc-opts "--stringparam ulink.show 1"
19 // a2x: --xsltproc-opts "--stringparam ulink.footnotes 1"
20 // :source-highlighter: vim
23 == Le ++.ledger++ : un format de __Grand Livre__ ouvert.. et simple
27 2014/05/01 Stand manif
33 Achat:Impression:Tracts 7
38 ifdef::backend-slidy2[>>>]
41 Transparent:: Visibilité de _toutes_ les informations.
42 Pérenne:: Compréhensible sans peine.
43 Modifiable:: Pas d’interface protectrice.
44 Accès:: Pas de changement d’interface non-consenti.
45 Versionnable:: Suivi et fusion simples des modifications.
46 Écrit:: Langage pour s’exprimer clairement, par exemple pour discuter dans un courriel.
47 Hors-ligne:: Pas besoin de réseau.
49 Pas spécifique à un éditeur logiciel particulier
50 (sauf fonctionnalité expérimentale).
51 * http://ledger-cli.org/[]
52 * http://hledger.org/[]
53 * http://furius.ca/beancount/[]
54 * https://massysett.github.io/penny/[]
55 * https://github.com/hrj/abandon/[]
60 Mais pas moins que les autres logiciels
61 et à nuancer si couplé à un gestionnaires de versions,
62 et/ou avec signature cryptographiques.
66 % git tag --sign v2011 -m "Clôture de la comptabilité 2011"
67 % git tag --verify v2011
72 % gpg --sign $fichier.hledger
73 % gpg --verify-files $fichier.hledger.gpg
76 Textuel:: Préférable de bien savoir utiliser
77 un éditeur de texte structuré.
82 2102/03/21 Remise chq (1101804)
83 5.Finance:1.Etablissement:1.Valeur:2.Chèque_à_encaisser -145,00
84 5.Finance:1.Etablissement:2.Banque:001.Courant 145,00
90 == ++hledger++ : un outil libre.. et convivial
93 % hledger balance '^6' '^7' --depth 2 -f Paris.2011.hledger
97 55,25€ 2.Autre_service
101 -26,00€ 5.Autre_gestion_courante
106 ifdef::backend-slidy2[>>>]
113 Permises techniquement et légalement +
114 (« logiciel libre » sous ++GNU/GPLv3++)
117 Programmé en http://fr.wikipedia.org/wiki/Haskell[Haskell]
119 Fonctionnel pur;; Aucune mutation de données externes à une fonction (effet de bord).
120 Typage statique;; Vérification des erreurs de type avant l’exécution du programme.
121 Typage fort;; Aucune conversion implicite de types de données.
123 Portable:: GNU/Linux, Apple/MacOS, Microsoft/Windows
125 Support:: ~1 développeur à mi-temps
127 * Simon Michael <simon@joyful.com>
134 % hledger balance -f $fichier.hledger
140 % hledger-web --server -f $fichier.hledger
141 % firefox "http://localhost:5000"
147 % ghc hledger-fait-ce-que-je-veux.hs
148 % ./hledger-fait-ce-que-je-veux -f $fichier.hledger
151 ifdef::backend-slidy2[>>>]
157 == Installer `hledger`
159 * http://hledger.org/installing[]
164 % sudo apt-get install hledger hledger-web
167 ifdef::backend-slidy2[>>>]
169 * http://www.haskell.org/cabal/[]
174 % echo 'PATH="$HOME/.cabal/bin:$PATH"' >>~/.profile
175 # NOTE: rajoute dans le chemins des exécutables
176 # les exécutables installés par cabal
177 % exit # NOTE: recharge ~/.profile
179 % sudo apt-get install ghc cabal-install \
180 libncurses5-dev libtinfo-dev zlib1g-dev
182 % cabal install cabal # NOTE: met à jour cabal
183 % cabal install happy # NOTE: anticipe une dépendance exécutable
184 % cabal install hledger
185 % cabal install alex # NOTE: anticipe une dépendance exécutable
186 % cabal install warp-2.0.3.4 hledger-web
187 # NOTE: aide cabal à sélectionner un warp qui fonctionne
193 % cabal install --reinstall hledger hledger-web
196 ifdef::backend-slidy2[>>>]
197 ==== Version de développement
201 % git clone http://github.com/simonmichael/hledger.git ~/src/hledger
203 % cabal install --reinstall --force-reinstalls \
204 ./hledger-lib ./hledger ./hledger-web
207 == Écrire en +.ledger+
208 Un +.ledger+ est un fichier de texte brut respectant une syntaxe préçise
209 qui forme une succession d’écritures comptables, ordonnées librement.
211 ifdef::backend-slidy2[>>>]
215 ; Ceci est un exemple de livre comptable « ledger »
216 ; NOTE: fantaisiste comptablement parlant, mais syntaxiquement correct
218 2014/01/01 Libellé de l’écriture ; UN_TAG:, Autre_tag:Avec_Valeur
219 Compte:Sous-Compte -42 ; flux créditant
220 Autre_Compte:Sous-Compte:Sous-Sous-Compte 42 ; flux débitant
222 2014/01/01 Deuxième écriture le même jour
223 Vente:Âme -666 ; (tag de flux) Arnaque:
226 2014/01/02 Troisième écriture le jour suivant avec ventilation des flux
234 Compte:Crédité -1234,56
235 Compte:Débité ; 1234,56 (montant inféré)
237 2014/02/01 Écriture non ordonnée par date ; Ok, mais déconseillé
239 Compte:Crédité -1 ; Flux non ordonné par crédit/débit
240 ; c'est juste moins lisible...
247 [cols="a,a",options="header"]
248 |==================================
249 ^|Syntaxe (grammaire https://fr.wikipedia.org/wiki/Forme_de_Backus-Naur[BNF])
250 ^|Structure (signatures fonctionnelles)
253 -----------------------------------
254 livre ::= (écriture \| commentaire \| "⏎" \| "␣")*
255 -----------------------------------
259 **livre**:: latexmath:[$
260 :\>f:\textcolor{#D2691E}{\textbf{fichier}} →
261 \lbrack\textcolor{#D2691E}{\textbf{\acute{e}criture}}\rbrack$]
265 écriture ::= date "␣" "␣"* libellé commentaire "⏎"
267 date ::= (année "/")? mois "/" jour
268 libellé ::= (· - (";"\|"⏎"))*
273 **date**:: latexmath:[$
274 :\>e:\textcolor{#D2691E}{\textbf{\acute{e}criture}} →
275 (\textcolor{#083194}{\textbf{ann\acute{e}e}}:\textcolor{#D2691E}{\textbf{ℕ}},~
276 \textcolor{#083194}{\textbf{mois}}:\{\textcolor{#D2691E}{\textbf{01}},...,\textcolor{#D2691E}{\textbf{12}}\},~
277 \textcolor{#083194}{\textbf{jour}}:\{\textcolor{#D2691E}{\textbf{01}},...,\textcolor{#D2691E}{\textbf{31}}\})$]
278 **libellé**:: latexmath:[$
279 :\>e:\textcolor{#D2691E}{\textbf{\acute{e}criture}} →
280 \textcolor{#D2691E}{\textbf{texte}}$]
281 **commentaire**:: latexmath:[$
282 :\>e:\textcolor{#D2691E}{\textbf{\acute{e}criture}} →
283 \textcolor{#D2691E}{\textbf{texte}}$]
284 **tags**:: latexmath:[$
285 :\>e:\textcolor{#D2691E}{\textbf{\acute{e}criture}} →
286 \lbrack\textcolor{#D2691E}{\textbf{tag}}\rbrack
287 \ =\ \textbf{tags}~(\textbf{commentaire}~e)$]
288 **flux**:: latexmath:[$
289 :\>e:\textcolor{#D2691E}{\textbf{\acute{e}criture}} →
290 \lbrack\textcolor{#D2691E}{\textbf{flux}}\rbrack$]
294 flux ::= compte "␣␣" "␣"* ("-" crédit \| débit) ("␣"\|"⏎")* commentaire
295 compte ::= nom ( ":" nom )*
296 nom ::= (· - (":"\|"⏎")) (· - (":"\|"⏎"))*
303 **compte**:: latexmath:[$
304 :\>f:\textcolor{#D2691E}{\textbf{flux}} →
305 \lbrack\textcolor{#D2691E}{\textbf{nom}}\rbrack$]
308 :\>f:\textcolor{#D2691E}{\textbf{flux}} → \textcolor{#D2691E}{ℚ} = \displaystyle{
309 \left\{\begin{array}{ll} -~(\textbf{cr\acute{e}dit}~f) & \mathit{\mbox{si défini}} \\
310 (\textbf{d\acute{e}bit}~f) & \mathit{\mbox{sinon}}
312 **tags**:: latexmath:[$
313 :\>f:\textcolor{#D2691E}{\textbf{flux}} →
314 \lbrack\textcolor{#D2691E}{\textbf{tag}}\rbrack
315 \ =\ \textbf{tags}~(\textbf{commentaire}~f)$]
319 commentaire ::= ( ";" (tag ":" valeur? \| ·)* )
320 ( ("⏎"\|"␣")* ";" (tag ":" valeur? \| ·)* )*
325 **tags**:: latexmath:[$
326 :\>m:\textcolor{#D2691E}{\textbf{commentaire}} →
327 \lbrack\textcolor{#D2691E}{\textbf{tag}}\rbrack$]
328 **tag**:: latexmath:[$
329 :\>(\textcolor{#083194}{\textbf{tag}}:\textcolor{#D2691E}{\textbf{texte}},%
330 ~\textcolor{#083194}{\textbf{valeur}}:\textcolor{#D2691E}{\textbf{\mbox{texte}}\>?})$]
331 |==================================
333 NOTE: RTFM @ http://hledger.org/manual/[].
340 latexmath:[$:\>c : \textcolor{#D2691E}{\textbf{compte}} → \textcolor{#D2691E}{\textbf{compte}}\>?$] +
341 latexmath:[$=\>c_{\lbrack0,\cdots,|c|-2\rbrack}\ \mbox{si}\ |c| \ge 2$]
342 **hiérarchie_de_compte**::
343 latexmath:[$:\>\mathbb c : \textcolor{#D2691E}{\textbf{compte}} → \lbrack\textcolor{#D2691E}{\textbf{compte}}\rbrack$] +
344 latexmath:[$=\>\lbrack{\ c\ :\ \lbrack{\ c\ |\ c ← (\mathbf{compte\mbox{_}parent}\>{c})}\ \rbrack}\ \rbrack$]
346 latexmath:[$:\>\mathbb E : \lbrack\textcolor{#D2691E}{\textbf{\acute{e}criture}}\rbrack → \{\textcolor{#D2691E}{\textbf{compte}}\}$] +
347 latexmath:[$\{\ (\textbf{compte}\>f)\ |\ f ← (\textbf{flux}\>e)\ |\ e ← \mathbb E\ \}$]
349 latexmath:[$:\>\mathbb F : \lbrack\textcolor{#D2691E}{\textbf{flux}}\rbrack → ℚ$] +
350 latexmath:[$=\>{(\ m\ |\ m ← m + (\textbf{montant}\>f)\ |\ f ← \mathbb F\ |\ m ← 0\ )$] +
351 **solde_de_compte**::
352 latexmath:[$:\>\mathbb E : \lbrack\textcolor{#D2691E}{\textbf{\acute{e}criture}}\rbrack → c : \textcolor{#D2691E}{\textbf{compte}} → ℚ$] +
353 latexmath:[$=\>{\textbf{balance}\>\lbrack{\ f\ |\ f ← (\textbf{flux}\>e),\ c\>≼\>(\textbf{compte}\>f)\ |\ e ← \mathbb E\ }\rbrack$] +
354 // latexmath:[$=\>{\displaystyle{\sum_{e ← \mathbb E}}\left(\sum_{\stackrel{f ← (\textbf{flux}\>e),}{c\ ≼\ (\textbf{compte}\>f)}}(\textbf{montant}\>f})\right)$]
356 latexmath:[$:\>\mathbb E : \lbrack\textcolor{#D2691E}{\textbf{\acute{e}criture}}\rbrack →
357 \lbrack\textcolor{#D2691E}{\textbf{flux}}\rbrack$] +
358 latexmath:[$=\>\displaystyle{\left\lbrack
360 (\textcolor{#083194}{\textbf{compte}}=c´, \textcolor{#083194}{\textbf{montant}}=m) \\
361 |\ m ← (\mathbf{\mbox{solde_de_compte}}\,\mathbb E\,c´) \\
362 |\ c´ ← (\mathbf{hi\acute{e}rarchie\mbox{_}de\mbox{_}compte}\,c) \\
363 |\ c ← (\mathbf{comptes}\,\mathbb E)
364 \end{array}}\right\rbrack$]
367 === Utiliser un éditeur de texte structuré (`vim`)
369 Coloration syntaxique sur mesure::
375 autocmd BufNewFile,BufRead *.hledger,*.ledger setfiletype hledger
377 Complètement automatique des comptes (`<Tab>`)::
379 * https://github.com/Shougo/neocomplete.vim[]
380 * https://github.com/Shougo/neocomplcache.vim[]
385 autocmd Filetype hledger set iskeyword+=.,38,39,40,41,44,45,58 "
387 Alignement automatique des montants::
389 * https://github.com/junegunn/vim-easy-align[]
394 let g:easy_align_ignore_groups = ['Comment', 'String', 'hledgerTransaction']
397 ifdef::backend-slidy2[>>>]
398 ==== Suivre les modifications à plusieurs et/ou à distance (`git`)
401 == Commandes `hledger`
403 ifdef::backend-slidy2[>>>]
404 === Calculer des soldes (`balance`)
407 % hledger balance -f $fichier.ledger $filtre
413 % hledger balance -b 2012/02/01 -e 2012/04/30 --monthly -f $fichier.ledger >/tmp/bal.flow
414 % hledger balance -b 2012/02/01 -e 2012/04/30 --cumulative --monthly -f $fichier.ledger >/tmp/bal.cumulative
415 % hledger balance -b 2012/02/01 -e 2012/04/30 --historical --monthly -f $fichier.ledger >/tmp/bal.historical
416 % gvimdiff -o /tmp/bal.{cumulative,historical}
418 image::data/gvimdiff-cumulative-historical.png[]
420 ifdef::backend-slidy2[>>>]
421 === Filtrer des écritures (`print`)
424 ifdef::backend-slidy2[>>>]
425 === Suivre un compte (`register`)
428 ifdef::backend-slidy2[>>>]
429 === Observer des statistiques (`stats`, `activity`)
433 == Exercice comptable
435 ifdef::backend-slidy2[>>>]
436 === Plan comptable d’une association
438 * DOC : https://wiki.cyclocoop.org/Comptabilité/Document/Plan_comptable/[]
442 #include::data/Cyclofficine.Plan_comptable.hledger[]
445 === Comptabiliser en partie double
447 Solde nul de toute écriture::
449 Pour toute écriture;;
450 Tout ce qui est _débité_ (+++++) dans ses comptes +
451 est forcément _crédité_ (++-++) dans ses autres comptes.
453 * latexmath:[$\forall e : \textcolor{#D2691E}{\textbf{\acute{e}criture}},
454 \ \textbf{balance}\>(\textbf{flux}\>{e}) = 0$]
456 Relation de Chasles par écritures d’engagement et de paiement::
460 01/01 Écriture d’engagement
461 7.Produit:0.Vente:1.Produit_fini:1.Vélo -80
462 5.Finance:1.Etablissement:1.Valeur:2.Chèque_à_encaisser 80
464 01/02 Écriture de paiement
465 5.Finance:1.Etablissement:1.Valeur:2.Chèque_à_encaisser -80
466 5.Finance:1.Etablissement:2.Banque:001.Courant 80
469 NOTE: pour des espèces, transiter par : ++5.Finance:3.Caisse:1.Siège++
471 ==== Soldes nuls souhaitables
473 - Écritures des recettes
475 1. latexmath:[$\sum{\mbox{ventes}} + \sum{\mbox{dons}} = \sum{\mbox{espèces entrées en caisse}} + \sum{\mbox{Chèques à encaisser}}$] +
476 (Total des ventes + dons == Total d’espèces entrée en caisse + Chèques à encaisser (5112))
477 2. Total chèques à encaisser (5112) == Total remises de chèques à la banque (512) (+/- argent non déposé en banque)
478 3. Solde du compte caisse (531) == Total entrées espèces en caisse - Total des sorties (remises d’espèces en banque - sorties d’achats - erreur de caisse)
479 4. Solde compte caisse (531) == Total entrées en caisse - Dépôt espèce en banque - Achat en espèce
487 === Journaux (filtres)
493 hledger print -f $fichier.ledger '^5.Finance:1.Etablissement:2.Banque:'
499 hledger print -f $fichier.ledger '^(2.Immobilisation:1.Corporelle:|6.Charge:(0.Achat|1.Service|2.Autre_service):)'
505 hledger print -f $fichier.ledger '^7.Produit:0.Vente:'
511 hledger print -f $fichier.ledger '^5.Finance:3.Caisse:'
517 hledger print -f $fichier.ledger '6.Charge:(3.Impôt:(1.|3.):|4.Personnel:)'
523 hledger print -f $fichier.ledger tag:ANV
525 **Opération_Diverses**::
529 hledger print -f $fichier.ledger tag:OD
532 === Clôture / Ouverture (`equity`)
533 ++hledger-equity++ calcule une balance de comptes
534 et en fait deux écritures, respectivement :
536 de clôture:: pour les solder à zéro en fin d’exercice ;
537 d’ouverture:: pour les réinitialiser à leur solde du précédent exercice.
541 % hledger-equity -f $fichier.ledger $filtre
545 .Solde des compte de gestion
547 % hledger-equity '^6' '^7' -f Paris.2011.hledger
549 6.Charge:0.Achat:6.Non_stocké:8.Autre_Matière,Fourniture:1.Atelier -248,87€
550 6.Charge:1.Service:3.Location:2.Immobilière -441,46€
551 6.Charge:2.Autre_service:3.Communication:6.Catalogue,Imprimé -24,00€
552 6.Charge:2.Autre_service:7.Service_bancaire -31,25€
553 6.Charge:5.Gestion:8.Divers:6.Cotisation_(vie_statutaire) -25,00€
554 7.Produit:0.Vente:6.Prest'action 700,00€
555 7.Produit:5.Autre_gestion_courante:6.Cotisation 20,00€
556 7.Produit:5.Autre_gestion_courante:8.Divers 6,00€
557 equity:closing balances 44,58€
560 6.Charge:0.Achat:6.Non_stocké:8.Autre_Matière,Fourniture:1.Atelier 248,87€
561 6.Charge:1.Service:3.Location:2.Immobilière 441,46€
562 6.Charge:2.Autre_service:3.Communication:6.Catalogue,Imprimé 24,00€
563 6.Charge:2.Autre_service:7.Service_bancaire 31,25€
564 6.Charge:5.Gestion:8.Divers:6.Cotisation_(vie_statutaire) 25,00€
565 7.Produit:0.Vente:6.Prest'action -700,00€
566 7.Produit:5.Autre_gestion_courante:6.Cotisation -20,00€
567 7.Produit:5.Autre_gestion_courante:8.Divers -6,00€
568 equity:opening balances -44,58€
571 == Import et export avec `hledger`
573 * https://github.com/eval/total_recall[]
574 * https://github.com/quentinsf/icsv2ledger[]
576 === Feuilles de calculs des documents comptables
578 ifdef::backend-slidy2[>>>]
582 ifdef::backend-slidy2[>>>]
583 ==== Comptes de résultats
589 == (bonus) Scripter ++hledger++
592 ifdef::backend-slidy2[>>>]
593 === Installer un script ++hledger++
596 % echo 'PATH="$HOME/src/hledger/extra:$PATH"' >>~/.profile
597 % exit # NOTE: recharge ~/.profile
598 % ghc ~/src/hledger/extra/hledger-SCRIPT.hs
604 Chat:: <irc://irc.freenode.net#ledger>
605 Liste:: <hledger+subscribe@googlegroups.com>
609 ifdef::backend-slidy2[]
610 [hledgersplash,position: absolute; left: 50%; top: 10%;]
612 image::data/hledger.splash.png[hledgersplash]
614 endif::backend-slidy2[]