├── .gitignore
├── .gitlab-ci.yml
├── CONTRIBUTING.md
├── COPYING
├── Cask
├── README.md
├── elbank-boobank.el
├── elbank-budget.el
├── elbank-common.el
├── elbank-compat.el
├── elbank-overview.el
├── elbank-progressbar.el
├── elbank-report.el
├── elbank-transaction.el
├── elbank.el
├── features
├── elbank-budget.feature
├── elbank-report.feature
├── step-definitions
│ └── elbank-steps.el
└── support
│ ├── env.el
│ └── test-helper.el
├── run-tests.sh
├── screenshots
├── budget-report.png
├── overview.png
├── report-example.png
└── transaction-details.png
└── test
├── elbank-boobank-test.el
├── elbank-common-test.el
├── elbank-report-test.el
└── test-helper.el
/.gitignore:
--------------------------------------------------------------------------------
1 | .cask
2 |
--------------------------------------------------------------------------------
/.gitlab-ci.yml:
--------------------------------------------------------------------------------
1 | image: nicolaspetton/emacs-docker
2 |
3 | before_script:
4 | - cask install
5 | - emacs --version
6 |
7 | test:
8 | script:
9 | - ./run-tests.sh
10 |
11 |
--------------------------------------------------------------------------------
/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | Contributions are welcome. If you discover bugs or issues, or have ideas for
4 | improvements or new features, please file a report on the issue tracker for this
5 | repository. Follow the guidelines below to make sure everything goes smoothly.
6 |
7 | ## Issue reporting
8 |
9 | - Check that the issue has not already been reported
10 | - Check that the issue has not already been fixed in the latest code
11 | - Open an issue with a clear title
12 | - Write as grammatically correct as you can in the description.
13 |
14 | ## Pull requests
15 |
16 | - Perform all changes on a topic branch for easier merging
17 | - Follow the coding conventions already in use
18 | - Verify Emacs Lisp code with `checkdoc`
19 | - Add unit tests whenever possible
20 | - Open a [pull request](https://help.github.com/articles/using-pull-requests)
21 | relating to a single issue.
22 |
23 | ## Coding Conventions
24 |
25 | ### Naming
26 |
27 | - Use a `elbank-` prefix for all public names.
28 | - Use a `elbank--` prefix for all internal names.
29 |
30 | ### Docstrings
31 |
32 | Write meaningful docstrings for all functions and vars.
33 |
34 | - Document all functions and variables as directed by `checkdoc`.
35 | - Consider using [Flycheck](https://github.com/flycheck/flycheck) to automate
36 | `checkdoc` while you're editing.
37 |
38 | ### Libraries
39 |
40 | - Use `seq` and `map` for manipulating collections.
41 | - Use `cl-lib`, which adds prefixes to all cl function names
42 | - Use [noflet](https://github.com/nicferrier/emacs-noflet) instead of `flet`
43 | when you need to dynamically rebind functions.
44 |
--------------------------------------------------------------------------------
/COPYING:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/Cask:
--------------------------------------------------------------------------------
1 | (source melpa)
2 |
3 | (package-file "elbank.el")
4 |
5 | (development
6 | (depends-on "ecukes")
7 | (depends-on "espuds")
8 | (depends-on "buttercup")
9 | (depends-on "flycheck")
10 | (depends-on "flycheck-cask")
11 | (depends-on "f")
12 | (depends-on "ert-runner")
13 | (depends-on "el-mock")
14 | (depends-on "cask-package-toolset")
15 | (depends-on "undercover")
16 | (depends-on "package-lint"))
17 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Elbank
2 | [](https://gitlab.petton.fr/nico/elbank/commits/master)
3 | [](https://www.gnu.org/software/emacs/)
4 |
5 | ## Summary
6 |
7 | **I'm not actively maintaining this project anymore**.
8 |
9 | Elbank is a personal finances reporting tool for Emacs. It uses
10 | [Weboob](https://weboob.org) for scraping data from bank websites.
11 |
12 | ## Screenshots
13 |
14 | ##### Overview buffer
15 |
16 | 
17 |
18 | ##### Report example (by category)
19 |
20 | 
21 |
22 | #### Budget reports
23 |
24 | 
25 |
26 | ##### Transaction details
27 |
28 | 
29 |
30 | ## Installing
31 |
32 | You will need Emacs 25+.
33 |
34 | - [Install Weboob](http://weboob.org/install) and run `boobank` configure your
35 | bank accounts;
36 |
37 | - Install Elbank from [MELPA](http://melpa.org/#/elbank).
38 |
39 | - Run `M-x elbank-overview`.
40 |
41 | Note: Make sure to enter your username and password (or an automated script)
42 | during the `boobank` setup, so that `boobank` can retrieve transactions without
43 | asking for them. This is currently required as Elbank will not interactively
44 | ask for usernames or passwords.
45 |
46 | ### Weboob and passwords
47 |
48 | If you do not want to store your passwords in Weboob, it is also possible to use
49 | a password manager like [pass](https://www.passwordstore.org/). During the setup
50 | of boobank, you can set the password to run an external command like:
51 |
52 | ```
53 | pass bank_website
54 | ```
55 |
56 | ## Usage
57 |
58 | ### Data file
59 |
60 | Data is stored as JSON in `elbank-data-file` which defaults to
61 | `$HOME/.emacs.d/elbank-data.json`.
62 |
63 | You might want to customize that variable or make sure to **exclude it from your
64 | `.emacs.d` git repository**.
65 |
66 | ### Entry point
67 |
68 | The command `elbank-overview` is the entry point of Elbank. You might want to
69 | bind it to a global key like the following:
70 |
71 | ```emacs-lisp
72 | (global-set-key (kbd "C-c e") #'elbank-overview)
73 | ```
74 |
75 | Otherwise just do `M-x elbank-overview RET` to get started. The overview buffer
76 | lists all bank accounts with their current balance and a link to each account
77 | statements report.
78 |
79 | From the overview buffer, press `r` to create a new report.
80 |
81 | ### Importing data
82 |
83 | Before using Elbank, make sure that `weboob` is correctly configured. You can
84 | make sure of it by evaluating `$ boobank ls` and see if your bank accounts are
85 | correctly outputted.
86 |
87 | When opening the overview buffer for the first time, Elbank will scrap data
88 | using weboob. Press `u` to update data from weboob.
89 |
90 | Note: Many bank website only store data for a short period of time (usually just
91 | a few months), so make sure to **import on a regular basis**, otherwise there
92 | will be gaps in the list of transactions.
93 |
94 | ### Categorizing transactions
95 |
96 | Categorizing transactions is important when reporting with Elbank. It makes it
97 | easy to group or filter transactions based on their categories.
98 |
99 | Transactions are automatically categorized when reporting, using
100 | `elbank-categories`, an association list of the form:
101 |
102 | ```emacs-lisp
103 | '(("category1" . ("regexp1" "regexp2"))
104 | (("category2" . ("regexp")))
105 | ```
106 |
107 | Where a category key can be any string. Category regexps are matched against
108 | transaction labels or raw text.
109 |
110 | For convenience when filtering transactions by categories, it is recommended to
111 | create categories with subcategories using ":" as a separator in category keys,
112 | like in the following example:
113 |
114 | ```emacs-lisp
115 | (setq elbank-categories
116 | '(("Expenses:Food" . ("^supermarket"
117 | "^restaurant"
118 | "Local store XXX"
119 | "Bakery XXX"))
120 | ("Expenses:Rent" . ("Real Estate Agency XXX"))
121 | ("Income:Salary" . ("Bank transfer from Company XXX"))))
122 | ```
123 |
124 | Note that it is not currently possible to manually add a category to a specific
125 | transaction, you always have to rely on `elbank-categories` to categorize
126 | transactions.
127 |
128 | ### Categorizing single transactions
129 |
130 | To set a custom category to a specific transaction, go to a transaction row in
131 | any report and press `c`.
132 |
133 | Transactions with a custom category will override any matching category from
134 | `elbank-categories`.
135 |
136 | ### Customizing reports
137 |
138 | Many report options can be customized from within a report buffer.
139 |
140 | - `f c`: Filter transactions by category, or a prefix of a category.
141 | - `f p`: Filter transactions by a period (leave empty for no period).
142 | - `f a`: Only show transactions for a specific account.
143 | - `S`: Select the sort column.
144 | - `s`: Reverse the sorting order.
145 | - `G`: Group transactions by a property (leave empty for no grouping).
146 | - `M-n`: Move forward by one period.
147 | - `M-p`: Move backward by one period.
148 |
149 | You can customize `elbank-saved-monthly reports` and
150 | `elbank-saved-yearly-reports` to get a quick list of commonly used reports from
151 | the overview buffer.
152 |
153 | ### Example reports
154 |
155 | Here are some example reports:
156 |
157 | - All transactions with default columns (date, label, category and amount)
158 | ```elisp
159 | (elbank-report)
160 | ```
161 |
162 | - All transactions with raw text
163 | ```elisp
164 | (elbank-report :columns '(date label raw amount))
165 | ```
166 | - Monthly income statement by category
167 | ```elisp
168 | (elbank-report :sort-by 'amount
169 | :group-by 'category
170 | :columns '(date label amount)
171 | :period `(month ,@(last (elbank-transaction-months))))
172 | ```
173 | - Daily expenses of the current month
174 | ```elisp
175 | (elbank-report :sort-by 'date
176 | :group-by 'date
177 | :columns '(label category amount)
178 | :period `(month ,@(last (elbank-transaction-months))))
179 | ```
180 |
181 | ## Budgeting
182 |
183 | Monthly Budgets are specified with `elbank-budget`, an assocation list of the form:
184 |
185 | ```elisp
186 | '(("category1" . amount)
187 | ("category2" . amount))
188 | ```
189 |
190 | To open a budget report, press `b` from the overview buffer or `M-x elbank-budget-report`.
191 |
192 | ## Contributing
193 |
194 | Yes, please do! See [CONTRIBUTING][] for guidelines.
195 |
196 | ## License
197 |
198 | See [COPYING][]. Copyright (c) 2017-2018 Nicolas Petton.
199 |
200 |
201 | [CONTRIBUTING]: ./CONTRIBUTING.md
202 | [COPYING]: ./COPYING
203 |
--------------------------------------------------------------------------------
/elbank-boobank.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-boobank.el --- Elbank functions for importing from Boobank -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 |
7 | ;; This program is free software; you can redistribute it and/or modify
8 | ;; it under the terms of the GNU General Public License as published by
9 | ;; the Free Software Foundation, either version 3 of the License, or
10 | ;; (at your option) any later version.
11 |
12 | ;; This program is distributed in the hope that it will be useful,
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ;; GNU General Public License for more details.
16 |
17 | ;; You should have received a copy of the GNU General Public License
18 | ;; along with this program. If not, see .
19 |
20 | ;;; Commentary:
21 |
22 | ;;
23 |
24 | ;;; Code:
25 |
26 | (require 'seq)
27 | (require 'map)
28 | (require 'json)
29 | (require 'cl-lib)
30 | (require 'subr-x)
31 |
32 | (require 'elbank-common)
33 |
34 | ;;;###autoload
35 | (defgroup elbank-boobank nil
36 | "Elbank boobank settings."
37 | :group 'elbank)
38 |
39 | ;;;###autoload
40 | (defcustom elbank-boobank-executable "boobank"
41 | "Boobank executable."
42 | :type '(file))
43 |
44 | (defun elbank-boobank-update (&optional callback)
45 | "Update `elbank-data' from boobank and save it on file.
46 | When CALLBACK is non-nil, evaluate it when data is updated."
47 | (elbank-boobank--update-accounts
48 | (lambda ()
49 | (elbank-boobank--update-transactions
50 | (lambda ()
51 | (elbank-write-data)
52 | (when callback (funcall callback)))))))
53 |
54 | (defun elbank-boobank--update-accounts (callback)
55 | "Update the accounts data from boobank.
56 | Evaluate CALLBACK when data is updated."
57 | (elbank-boobank--fetch-then-merge
58 | #'elbank-boobank--fetch-accounts
59 | #'elbank-boobank--merge-accounts
60 | (lambda (accounts)
61 | (map-put elbank-data 'accounts accounts)
62 | (funcall callback))))
63 |
64 | (defun elbank-boobank--update-transactions (callback)
65 | "Update the transactions data from boobank.
66 | Evaluate CALLBACK when data is updated."
67 | (elbank-boobank--fetch-then-merge
68 | #'elbank-boobank--fetch-transactions
69 | #'elbank-boobank--merge-transactions
70 | (lambda (transactions)
71 | (map-put elbank-data 'transactions transactions)
72 | (funcall callback))))
73 |
74 | (defun elbank-boobank--fetch-accounts (callback)
75 | "Execute CALLBACK with all fetched accounts from boobank."
76 | (let ((command (format "%s -f json ls 2>/dev/null" (elbank-boobank--find-executable))))
77 | (message "Elbank: fetching accounts...")
78 | (elbank-boobank--shell-command command callback)))
79 |
80 | (defun elbank-boobank--fetch-transactions (callback &optional accounts acc)
81 | "Fetch all transactions from all ACCOUNTS and evaluate CALLBACK.
82 | If ACCOUNTS is nil, use all accounts from `elbank-data'.
83 |
84 | CALLBACK is called with all fetched transactions.
85 |
86 | ACC is used in recursive calls to accumulate fetched transactions."
87 | (let* ((since "1970") ; the current strategy is to always fetch all data. If
88 | ; needed, this can be optimized later on.
89 | (accounts (or accounts (map-elt elbank-data 'accounts)))
90 | (account (car accounts))
91 | (id (map-elt account 'id))
92 | ;; The backend might not support listing transactions for some
93 | ;; accounts, ignore errors.
94 | (command (format "%s -f json history %s %s 2> /dev/null"
95 | (elbank-boobank--find-executable)
96 | id
97 | since)))
98 | (message "Elbank: fetching transactions for account %s..." id)
99 | (elbank-boobank--shell-command
100 | command
101 | (lambda (data)
102 | (let* ((transactions (seq-map (lambda (datum)
103 | (elbank-boobank--make-transaction datum account))
104 | data))
105 | (all (seq-concatenate 'list acc transactions)))
106 | (if (cdr accounts)
107 | (elbank-boobank--fetch-transactions callback (cdr accounts) all)
108 | (funcall callback all)))))))
109 |
110 | (defun elbank-boobank--make-transaction (data account)
111 | "Return a transaction alist from DATA with its account set to ACCOUNT."
112 | (unless (seq-contains (map-elt elbank-data 'accounts)
113 | account
114 | #'eq)
115 | (error "Account %s not in the Elbank database" account))
116 | (let ((transaction (map-copy data)))
117 | ;; Some banks add a category to transactions, which conflicts with elbank's
118 | ;; categories, so put the category in `bank-category' instead.
119 | (map-put transaction 'bank-category (map-elt data 'category))
120 | (map-put transaction 'category nil)
121 | (map-put transaction 'account account)))
122 |
123 | (defun elbank-boobank--merge-accounts (accounts)
124 | "Merge ACCOUNTS with existing ones in `elbank-data'.
125 | Data from existing accounts are updated with new data from ACCOUNTS."
126 | (elbank-boobank--update-existing-accounts accounts)
127 | (let ((existing-accounts (map-elt elbank-data 'accounts)))
128 | (let ((new-accounts (elbank-boobank--find-new-accounts accounts)))
129 | (seq-concatenate 'list existing-accounts new-accounts))))
130 |
131 | (defun elbank-boobank--find-new-accounts (accounts)
132 | "Return accounts in ACCOUNTS that are not present in `elbank-data'."
133 | (seq-remove (lambda (acc)
134 | (elbank-account-with-id (map-elt acc 'id)))
135 | accounts))
136 |
137 | (defun elbank-boobank--update-existing-accounts (new-accounts)
138 | "Update existing accounts in `elbank-data' with the data from NEW-ACCOUNTS'.
139 | No new account is created, only existing account values are updated."
140 | (seq-do (lambda (new-acc)
141 | (when-let ((acc (elbank-account-with-id (map-elt new-acc 'id))))
142 | (map-apply (lambda (key val)
143 | (map-put acc key val))
144 | new-acc)))
145 | new-accounts))
146 |
147 | (defun elbank-boobank--merge-transactions (transactions)
148 | "Merge the transaction list from `elbank-data' and TRANSACTIONS."
149 | (let* ((existing-transactions (map-elt elbank-data 'transactions))
150 | (new-transactions (elbank-boobank--find-new-transactions transactions)))
151 | (seq-concatenate 'list existing-transactions new-transactions)))
152 |
153 | (defun elbank-boobank--find-new-transactions (transactions)
154 | "Return all transactions from TRANSACTIONS not present in `elbank-data'.
155 | When comparing transactions, ignore (manually set) categories."
156 | (apply #'seq-concatenate 'list
157 | (seq-map (lambda (trans)
158 | (let ((n (- (elbank-boobank--count-transactions-like
159 | trans transactions)
160 | (elbank-boobank--count-transactions-like
161 | trans (elbank-all-transactions t)))))
162 | (when (> n 0)
163 | (let ((result))
164 | (dotimes (_ n)
165 | (setq result (cons trans result)))
166 | result))))
167 | (seq-uniq transactions))))
168 |
169 | (defun elbank-boobank--count-transactions-like (transaction transactions)
170 | "Return the number of transactions like TRANSACTION in TRANSACTIONS."
171 | (seq-length (elbank-filter-transactions
172 | transactions
173 | :raw (map-elt transaction 'raw)
174 | :account (map-elt transaction 'account)
175 | :amount (map-elt transaction 'amount)
176 | :date (map-elt transaction 'date)
177 | :vdate (map-elt transaction 'vdate)
178 | :rdate (map-elt transaction 'rdate)
179 | :label (map-elt transaction 'label))))
180 |
181 | (defun elbank-boobank--shell-command (command callback)
182 | "Start a subprocess for COMMAND, and evaluate CALLBACK with its output."
183 | (let ((bufname "*boobank process*"))
184 | (when-let ((buf (get-buffer bufname)))
185 | (with-current-buffer buf
186 | (erase-buffer)))
187 | (make-process :name "boobank"
188 | :buffer bufname
189 | :sentinel (lambda (process event)
190 | (if (eq (process-status process) 'exit)
191 | (let ((json-array-type 'list))
192 | (with-current-buffer (process-buffer process)
193 | (goto-char (point-min))
194 | (funcall callback (json-read))))
195 | (error "Boobank fetch failed! %s" event)))
196 | :command (list shell-file-name
197 | shell-command-switch
198 | command))))
199 |
200 | (defun elbank-boobank--find-executable ()
201 | "Return the boobank executable.
202 | Signal an error if the boobank executable cannot be found."
203 | (let ((executable (executable-find elbank-boobank-executable)))
204 | (unless executable
205 | (user-error "Cannot find boobank executable (%s) in PATH" elbank-boobank-executable))
206 | executable))
207 |
208 | (defun elbank-boobank--fetch-then-merge (fetch-fn merge-fn callback)
209 | "Evaluate MERGE-FN with the result of the evaluation of FETCH-FN.
210 |
211 | FETCH-FN is an asynchronous function that take a callback
212 | function as argument.
213 |
214 | Evaluate CALLBACK with the result of the merge."
215 | (funcall fetch-fn
216 | (lambda (data)
217 | (let ((merged (funcall merge-fn data)))
218 | (funcall callback merged)))))
219 |
220 |
221 |
222 | (provide 'elbank-boobank)
223 | ;;; elbank-boobank.el ends here
224 |
--------------------------------------------------------------------------------
/elbank-budget.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-budget.el --- Elbank budgeting functionality -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 |
7 | ;; This program is free software; you can redistribute it and/or modify
8 | ;; it under the terms of the GNU General Public License as published by
9 | ;; the Free Software Foundation, either version 3 of the License, or
10 | ;; (at your option) any later version.
11 |
12 | ;; This program is distributed in the hope that it will be useful,
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ;; GNU General Public License for more details.
16 |
17 | ;; You should have received a copy of the GNU General Public License
18 | ;; along with this program. If not, see .
19 |
20 | ;;; Commentary:
21 |
22 | ;;
23 |
24 | ;;; Code:
25 |
26 | (require 'seq)
27 | (require 'map)
28 | (require 'cl-lib)
29 |
30 | (require 'elbank-common)
31 | (require 'elbank-progressbar)
32 |
33 | (declare-function elbank-report "elbank-report.el")
34 |
35 | ;;;###autoload
36 | (defgroup elbank-budget nil
37 | "Elbank budget settings"
38 | :group 'elbank)
39 |
40 | ;;;###autoload
41 | (defcustom elbank-budget nil
42 | "Monthly budget by category of transactions.
43 |
44 | Keys are category names as defined in `elbank-categories'."
45 | :type '(alist :key-type (string :tag "Category name")
46 | :value-type (number :tag "Monthly budget")))
47 |
48 | (defvar elbank-budget-mode-map
49 | (copy-keymap elbank-base-report-mode-map)
50 | "Keymap for `elbank-budget-mode'.")
51 |
52 | (define-derived-mode elbank-budget-mode elbank-base-report-mode "Elbank Budget"
53 | "Major mode for viewing a monthly budget.
54 |
55 | \\{elbank-budget-mode-map}"
56 | (add-hook 'elbank-base-report-refresh-hook 'elbank-budget-refresh nil t))
57 |
58 | ;;;###autoload
59 | (defun elbank-budget-report ()
60 | "Build a budget report for the last month.
61 |
62 | Return the report buffer."
63 | (interactive)
64 | (let ((buf (get-buffer-create "*elbank budget report*")))
65 | (pop-to-buffer buf)
66 | (elbank-budget-mode)
67 | (setq elbank-report-period
68 | `(month ,(car (last (elbank-transaction-months)))))
69 | (elbank-budget-refresh)
70 | buf))
71 |
72 | (defun elbank-budget-refresh ()
73 | "Update the budget report."
74 | (let ((inhibit-read-only t)
75 | (elbank-budget-data (elbank-budget--get-data)))
76 | (erase-buffer)
77 | (elbank-budget--insert-header)
78 | (elbank-budget--insert-customize-link)
79 | (seq-do #'elbank-budget--insert-line
80 | (seq-sort (lambda (a b)
81 | (string< (car a) (car b)))
82 | elbank-budget-data))
83 | (elbank-budget--insert-footer elbank-budget-data)))
84 |
85 | (defun elbank-budget--insert-header ()
86 | "Insert the header for the budget buffer."
87 | (insert (format "Budget report for %s"
88 | (elbank-format-period elbank-report-period)))
89 | (put-text-property (point-at-bol) (point)
90 | 'face 'elbank-header-face)
91 | (insert "\n\n"))
92 |
93 | (defun elbank-budget--insert-footer (data)
94 | "Insert the footer with a summary of the budget DATA."
95 | (insert "\n")
96 | (insert " Total: ")
97 | (let ((beg (point)))
98 | (insert (format "%.2f"
99 | (seq-reduce #'+
100 | (seq-map #'cadr data)
101 | 0)))
102 | (put-text-property beg (point) 'face 'bold))
103 | (insert " of ")
104 | (let ((beg (point)))
105 | (insert (format "%.2f"
106 | (seq-reduce #'+
107 | (seq-map #'cl-caddr data)
108 | 0)))
109 | (put-text-property beg (point) 'face 'bold))
110 | (insert " budgeted."))
111 |
112 | (defun elbank-budget--insert-customize-link ()
113 | "Insert a button to customize `elbank-budget'."
114 | (insert "[Customize budgets]")
115 | (make-text-button (point-at-bol) (point)
116 | 'follow-link t
117 | 'action (lambda (&rest _)
118 | (customize-variable 'elbank-budget)))
119 | (insert "\n\n"))
120 |
121 | (defun elbank-budget--insert-line (budget-entry)
122 | "Insert the value for BUDGET-ENTRY with a progress bar."
123 | (let* ((label (car budget-entry))
124 | (spent (cadr budget-entry))
125 | (budgeted (cl-caddr budget-entry))
126 | (percentage (if (zerop budgeted)
127 | 100
128 | (round (* 100 (/ spent budgeted))))))
129 | (elbank-budget--insert-line-header label)
130 | (elbank-insert-progressbar percentage 40)
131 | (insert (format " %.2f of %.2f budgeted" spent budgeted))
132 | (insert "\n\n")))
133 |
134 | (defun elbank-budget--insert-line-header (label)
135 | "Insert a header with LABEL for a budget category."
136 | (let ((width (1+ (seq-reduce (lambda (acc cat)
137 | (max (seq-length (car cat)) acc))
138 | elbank-budget
139 | 0))))
140 | (dotimes (_ (- width (seq-length label)))
141 | (insert " "))
142 | (let ((beg (point)))
143 | (insert (format "%s" label))
144 | (make-text-button beg (point)
145 | 'follow-link t
146 | 'action (lambda (&rest _)
147 | (elbank-report :period elbank-report-period
148 | :category label))))
149 | (insert " ")))
150 |
151 | (defun elbank-budget--get-data ()
152 | "Return an assocation list of budget data.
153 |
154 | Keys are budgeted categories.
155 | Values are lists of spent amounts and budgeted amounts for a category."
156 | (let ((data (map-apply (lambda (key val)
157 | `(,key ,(- (elbank-sum-transactions val))
158 | ,(map-elt elbank-budget key)))
159 | (elbank-budget--transactions-by-budget))))
160 | ;; Add budgeted categories without transaction.
161 | (seq-do (lambda (budget)
162 | (unless (map-elt data (car budget))
163 | (map-put data (car budget) `(0 ,(cdr budget)))))
164 | elbank-budget)
165 | data))
166 |
167 |
168 | (defun elbank-budget--transactions-by-budget ()
169 | "Return an assocation list of all transactions grouped by budget category."
170 | (seq-filter
171 | (lambda (elt)
172 | (not (null (car elt))))
173 | (seq-group-by
174 | (lambda (trans)
175 | (seq-some
176 | (lambda (cat)
177 | (when (elbank-transaction-in-category-p trans cat)
178 | cat))
179 | (seq-map #'car elbank-budget)))
180 | (elbank-filter-transactions (elbank-all-transactions)
181 | :period elbank-report-period))))
182 |
183 | (provide 'elbank-budget)
184 | ;;; elbank-budget.el ends here
185 |
--------------------------------------------------------------------------------
/elbank-common.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-common.el --- Elbank common use functions and variables -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 |
7 | ;; This program is free software; you can redistribute it and/or modify
8 | ;; it under the terms of the GNU General Public License as published by
9 | ;; the Free Software Foundation, either version 3 of the License, or
10 | ;; (at your option) any later version.
11 |
12 | ;; This program is distributed in the hope that it will be useful,
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ;; GNU General Public License for more details.
16 |
17 | ;; You should have received a copy of the GNU General Public License
18 | ;; along with this program. If not, see .
19 |
20 | ;;; Commentary:
21 |
22 | ;; This file defines common data structures, variables and functions used in
23 | ;; Elbank.
24 |
25 | ;;; Code:
26 |
27 | (require 'map)
28 | (require 'seq)
29 | (require 'json)
30 | (require 'subr-x)
31 | (eval-and-compile (require 'cl-lib))
32 |
33 | ;;;###autoload
34 | (defgroup elbank nil
35 | "Elbank"
36 | :prefix "elbank-"
37 | :group 'tools)
38 |
39 | ;;;###autoload
40 | (defcustom elbank-data-file (locate-user-emacs-file "elbank-data.el")
41 | "Location of the file used to store elbank data."
42 | :type '(file))
43 |
44 | ;;;###autoload
45 | (defcustom elbank-categories nil
46 | "Alist of categories of transactions.
47 |
48 | Each category has an associated list of regular expressions.
49 | A transaction's category is found by testing each regexp in order.
50 |
51 | Example of categories
52 |
53 | (setq elbank-categories
54 | \\='((\"Expenses:Groceries\" . (\"walmart\" \"city market\"))
55 | (\"Income:Salary\" . (\"paycheck\"))))"
56 | :type '(alist :key-type (string :tag "Category name")
57 | :value-type (repeat (string :tag "Regexp"))))
58 |
59 | (defface elbank-header-face '((t . (:inherit font-lock-keyword-face
60 | :height 1.3)))
61 | "Face for displaying header in elbank."
62 | :group 'elbank)
63 |
64 | (defface elbank-subheader-face '((t . (:weight bold
65 | :height 1.1)))
66 | "Face for displaying sub headers in elbank."
67 | :group 'elbank)
68 |
69 | (defface elbank-positive-amount-face '((t . (:inherit success :weight normal)))
70 | "Face for displaying positive amounts."
71 | :group 'elbank)
72 |
73 | (defface elbank-negative-amount-face '((t . (:inherit error :weight normal)))
74 | "Face for displaying positive amounts."
75 | :group 'elbank)
76 |
77 | (defface elbank-entry-face '((t . ()))
78 | "Face for displaying entries in elbank."
79 | :group 'elbank)
80 |
81 | (defvar elbank-data nil
82 | "Alist of all accounts and transactions.")
83 |
84 | (defvar elbank-report-available-columns '(date rdate label raw category account amount)
85 | "List of all available columns in reports.")
86 |
87 |
88 | (defun elbank-read-data ()
89 | "Return an alist of boobank data read from `elbank-data-file'.
90 | Data is cached to `elbank-data'."
91 | (let ((file (expand-file-name elbank-data-file)))
92 | (when (file-exists-p file)
93 | (load file t))))
94 |
95 | (defun elbank-write-data ()
96 | "Write `elbank-data' to `elbank-data-file'."
97 | (let ((print-circle t)
98 | (print-level nil)
99 | (print-length nil))
100 | (with-temp-file (expand-file-name elbank-data-file)
101 | (emacs-lisp-mode)
102 | (insert ";; This file is automatically generated by Indium.")
103 | (newline)
104 | (insert (format "(setq %s '%S)" "elbank-data" elbank-data)))))
105 |
106 | (defun elbank-account-with-id (id)
107 | "Return the account with ID, or nil."
108 | (seq-find (lambda (acc)
109 | (string= (map-elt acc 'id)
110 | id))
111 | (map-elt elbank-data 'accounts)))
112 |
113 | (defun elbank-account-name (account)
114 | "Return a human-readable name for ACCOUNT."
115 | (format "%s@%s"
116 | (elbank-account-group account)
117 | (map-elt account 'label)))
118 |
119 | (defun elbank-account-group (account)
120 | "Return the group into which ACCOUNT is classified."
121 | (cadr (split-string (map-elt account 'id) "@")))
122 |
123 | (cl-defgeneric elbank-transaction-elt (transaction key &optional default)
124 | "Return the value of TRANSACTION at KEY.
125 |
126 | If the result is nil, return DEFAULT."
127 | (map-elt transaction key default))
128 |
129 | (cl-defmethod elbank-transaction-elt (transaction (key (eql account)) &optional default)
130 | "Return the account of TRANSACTION.
131 |
132 | If TRANSACTION is a split transaction, return the account of its parent transaction."
133 | (if (elbank-sub-transaction-p transaction)
134 | (elbank-transaction-elt (elbank-transaction-elt transaction 'split-from) 'account)
135 | (cl-call-next-method transaction key default)))
136 |
137 | (cl-defmethod elbank-transaction-elt (transaction (_key (eql category)) &optional default)
138 | "Return the category of TRANSACTION.
139 |
140 | Split transactions (that hold an list of (CATEGORY . AMOUNT)
141 | elements as category) have no category.
142 |
143 | If the result is nil, return DEFAULT."
144 | (let ((case-fold-search t)
145 | (custom-category (map-elt transaction 'category)))
146 | (cond ((or (null custom-category)
147 | (and (stringp custom-category)
148 | (string-empty-p custom-category)))
149 | (seq-find #'identity
150 | (map-apply
151 | (lambda (key category)
152 | (when (seq-find
153 | (lambda (regexp)
154 | (string-match-p
155 | regexp
156 | (map-elt transaction 'raw)))
157 | category)
158 | key))
159 | elbank-categories)
160 | default))
161 | ((stringp custom-category) custom-category)
162 | (t default))))
163 |
164 | (cl-defgeneric (setf elbank-transaction-elt) (store transaction key)
165 | (if (map-contains-key transaction key)
166 | (setf (map-elt transaction key) store)
167 | ;; Always mutate transactions in place.
168 | (nconc transaction (list (cons key store)))))
169 |
170 | (defun elbank-transaction-split-p (transaction)
171 | "Return non-nil if TRANSACTION is split.
172 | Split transactions have an alist of (CATEGORY-NAME . AMOUNT) as
173 | category."
174 | (let ((category (map-elt transaction 'category)))
175 | (and (not (null category))
176 | (listp category))))
177 |
178 | (defun elbank-sub-transaction-p (transaction)
179 | "Return non-nil if TRANSACTION is a sub transaction.
180 |
181 | Sub transactions are built dynamically from
182 | `elbank-all-transactions' from split transactions."
183 | (not (null (elbank-transaction-elt transaction 'split-from))))
184 |
185 | (defmacro elbank-filter-transactions (collection &rest query)
186 | "Returned all transactions in COLLECTION that match QUERY.
187 |
188 | QUERY is a plist of the form (:KEY1 VAL1 :KEY2 VAL2...) where
189 | keys are keywords matching transaction keys.
190 |
191 | Special keys in QUERY:
192 |
193 | - `:category': Match transactions within the category name, using
194 | `elbank-transaction-in-category-p'.
195 |
196 | - `:period': The value must be a list of the form (TYPE TIME),
197 | where TYPE is either year or month.
198 |
199 | - `:account-id': Lookup an account with the queried id and match
200 | transactions for that account."
201 | (let* ((sym (make-symbol "transaction"))
202 | (query (elbank--make-queries sym query)))
203 | `(seq-filter (lambda (,sym) ,query) ,collection)))
204 |
205 | (defun elbank--make-queries (transaction queries)
206 | "Return a form for filtering TRANSACTION with QUERIES."
207 | (let ((filters (seq-map (lambda (query)
208 | (elbank--make-query transaction
209 | (car query)
210 | (cadr query)))
211 | (seq-partition queries 2))))
212 | `(and ,@filters)))
213 |
214 | (cl-defgeneric elbank--make-query (transaction key val)
215 | (unless (keywordp key)
216 | (error "Query KEY must be a keyword"))
217 | `(or (null ,val)
218 | (equal (elbank-transaction-elt ,transaction
219 | ',(intern (seq-drop (symbol-name key) 1)))
220 | ,val)))
221 |
222 | (cl-defmethod elbank--make-query (transaction (_key (eql :category)) val)
223 | `(elbank-transaction-in-category-p ,transaction ,val))
224 |
225 | (cl-defmethod elbank--make-query (transaction (_key (eql :account-id)) val)
226 | (elbank--make-query transaction :account `(elbank-account-with-id ,val)))
227 |
228 | (cl-defmethod elbank--make-query (transaction (_key (eql :period)) period)
229 | "Return a period query for TRANSACTION.
230 |
231 | PERIOD is a list of the form `(type time)', with `type' a
232 | symbol (`month' or `year'), and `time' an encoded time."
233 | (let ((period-var (make-symbol "period")))
234 | `(let ((,period-var ,period))
235 | (pcase (car ,period-var)
236 | (`year (elbank--make-period-query-format ,transaction
237 | (cadr ,period-var)
238 | "%Y"))
239 | (`month (elbank--make-period-query-format ,transaction
240 | (cadr ,period-var)
241 | "%Y-%m"))
242 | (`nil t)
243 | (_ (error "Invalid period type %S" (car ,period-var)))))))
244 |
245 | (defun elbank--make-period-query-format (transaction time format)
246 | "Return a period query for TRANSACTION and TIME.
247 | Comparison is done by formatting times using FORMAT."
248 | (string= (format-time-string format time)
249 | (format-time-string format (elbank--transaction-time transaction))))
250 |
251 | (defun elbank--transaction-time (transaction)
252 | "Return the encoded time for TRANSACTION."
253 | (apply #'encode-time
254 | (seq-map (lambda (el)
255 | (or el 0))
256 | (parse-time-string (elbank-transaction-elt transaction 'date)))))
257 |
258 | (defun elbank-transaction-in-category-p (transaction category)
259 | "Return non-nil if TRANSACTION belongs to CATEGORY."
260 | (or (null category)
261 | (string-prefix-p category (elbank-transaction-elt transaction 'category "") t)))
262 |
263 | (defun elbank-sum-transactions (transactions)
264 | "Return the sum of all TRANSACTIONS.
265 | TRANSACTIONS are expected to all use the same currency."
266 | (seq-reduce (lambda (acc transaction)
267 | (+ acc
268 | (string-to-number (elbank-transaction-elt transaction 'amount))))
269 | transactions
270 | 0))
271 |
272 | (defun elbank-transaction-years ()
273 | "Return all years for which there is a transaction."
274 | (seq-sort #'time-less-p
275 | (seq-uniq
276 | (seq-map (lambda (transaction)
277 | (encode-time 0 0 0 1 1
278 | (seq-elt (decode-time
279 | (elbank--transaction-time transaction))
280 | 5)))
281 | (elbank-all-transactions)))))
282 |
283 | (defun elbank-transaction-months ()
284 | "Return all months for which there is a transaction."
285 | (seq-sort #'time-less-p
286 | (seq-uniq
287 | (seq-map (lambda (transaction)
288 | (let ((time (decode-time
289 | (elbank--transaction-time transaction))))
290 | (encode-time 0 0 0 1 (seq-elt time 4) (seq-elt time 5))))
291 | (elbank-all-transactions)))))
292 |
293 | (defun elbank-all-transactions (&optional nosplit)
294 | "Return all transactions for all accounts.
295 |
296 | When NOSPLIT is nil, split transactions that have multiple
297 | categories into multiple transactions."
298 | (if nosplit
299 | (map-elt elbank-data 'transactions)
300 | (seq-mapcat (lambda (transaction)
301 | (if (elbank-transaction-split-p transaction)
302 | (seq-map (lambda (cat)
303 | (let ((sub-trans (copy-alist transaction)))
304 | (map-put sub-trans 'amount (cdr cat))
305 | (map-put sub-trans 'category (car cat))
306 | (map-put sub-trans 'label
307 | (format "[split] %s"
308 | (elbank-transaction-elt
309 | transaction
310 | 'label)))
311 | (map-put sub-trans 'split-from transaction)
312 | sub-trans))
313 | (map-elt transaction 'category))
314 | (list transaction)))
315 | (elbank-all-transactions t))))
316 |
317 | (defun elbank--longest-account-label ()
318 | "Return the longest account label from all accounts."
319 | (seq-reduce (lambda (label1 label2)
320 | (if (> (seq-length label1)
321 | (seq-length label2))
322 | label1
323 | label2))
324 | (seq-map (lambda (account)
325 | (map-elt account 'label))
326 | (map-elt elbank-data 'accounts))
327 | ""))
328 |
329 | (defun elbank--insert-amount (amount &optional currency)
330 | "Insert AMOUNT as a float with a precision of 2 decimals.
331 | When CURRENCY is non-nil, append it to the inserted text.
332 | AMOUNT is fontified based on whether it is negative or positive."
333 | (let ((beg (point))
334 | (number (if (numberp amount)
335 | amount
336 | (string-to-number amount))))
337 | (insert (format "%.2f %s" number (or currency "")))
338 | (put-text-property beg (point)
339 | 'face
340 | (if (< number 0)
341 | 'elbank-negative-amount-face
342 | 'elbank-positive-amount-face))))
343 |
344 | (defun elbank--propertize-amount (amount &optional currency)
345 | "Fontify AMOUNT based on whether it is positive or not.
346 | When CURRENCY is non-nil, append it to the inserted text."
347 | (with-temp-buffer
348 | (elbank--insert-amount amount currency)
349 | (buffer-string)))
350 |
351 | (defun elbank-format-period (period)
352 | "Return the string representation of PERIOD."
353 | (pcase (car period)
354 | (`year (format-time-string "Year %Y" (cadr period)))
355 | (`month (format-time-string "%B %Y" (cadr period)))
356 | (`nil "")
357 | (`_ "Invalid period")))
358 |
359 | (defun elbank-quit ()
360 | "Kill the current buffer."
361 | (interactive)
362 | (quit-window t))
363 |
364 | ;;;
365 | ;;; Common major-mode for reports
366 | ;;;
367 |
368 | (defvar elbank-report-update-hook nil
369 | "Hook run when a report update is requested.")
370 |
371 | (defvar elbank-report-period nil
372 | "Period filter used in a report buffer.")
373 | (make-variable-buffer-local 'elbank-report-period)
374 |
375 | (defvar elbank-base-report-mode-map
376 | (let ((map (make-sparse-keymap)))
377 | (define-key map (kbd "q") #'elbank-quit)
378 | (define-key map (kbd "n") #'forward-button)
379 | (define-key map (kbd "p") #'backward-button)
380 | (define-key map [tab] #'forward-button)
381 | (define-key map [backtab] #'backward-button)
382 | (define-key map (kbd "M-n") #'elbank-base-report-forward-period)
383 | (define-key map (kbd "M-p") #'elbank-base-report-backward-period)
384 | (define-key map (kbd "g") #'elbank-base-report-refresh)
385 | map)
386 | "Keymap for `elbank-base-report-mode'.")
387 |
388 | (define-derived-mode elbank-base-report-mode nil "Base elbank reports"
389 | "Base major mode for viewing a report.
390 |
391 | \\{elbank-base-report-mode-map}"
392 | (setq-local truncate-lines nil)
393 | (read-only-mode))
394 |
395 | (defun elbank-base-report-refresh ()
396 | "Request an update of the current report."
397 | (interactive)
398 | (run-hooks 'elbank-base-report-refresh-hook))
399 |
400 | (defun elbank-base-report-forward-period (&optional n)
401 | "Select the next N period and update the current report.
402 | If there is no period filter, signal an error."
403 | (interactive "p")
404 | (unless elbank-report-period
405 | (user-error "No period filter for the current report"))
406 | (let* ((periods (pcase (car elbank-report-period)
407 | (`year (elbank-transaction-years))
408 | (`month (elbank-transaction-months))))
409 | (cur-index (seq-position periods (cadr elbank-report-period)))
410 | (new-index (+ n cur-index))
411 | (period (seq-elt periods new-index)))
412 | (if period
413 | (progn
414 | (setq elbank-report-period (list (car elbank-report-period)
415 | period))
416 | (elbank-base-report-refresh))
417 | (user-error "No more periods"))))
418 |
419 | (defun elbank-base-report-backward-period (&optional n)
420 | "Select the previous N period and update the current report.
421 | If there is no period filter, signal an error."
422 | (interactive "p")
423 | (elbank-base-report-forward-period (- n)))
424 |
425 | (provide 'elbank-common)
426 | ;;; elbank-common.el ends here
427 |
--------------------------------------------------------------------------------
/elbank-compat.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-compat.el --- Backward compatibility functions for elbank -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 | ;; Keywords:
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 | ;;
24 |
25 | ;;; Code:
26 |
27 |
28 | ;; HACK: In Emacs 25.1, an older version of seq.el is provided, which can be
29 | ;; loaded before indium or even package.el. If this happens, the feature `seq'
30 | ;; being already provided, the correct version of seq.el won't get loaded.
31 | (require 'seq)
32 | (if (fboundp 'seq-map-indexed)
33 | (defalias 'elbank-seq-map-indexed #'seq-map-indexed)
34 | (defun elbank-seq-map-indexed (function sequence)
35 | "Return the result of applying FUNCTION to each element of SEQUENCE.
36 | Unlike `seq-map', FUNCTION takes two arguments: the element of
37 | the sequence, and its index within the sequence."
38 | (let ((index 0))
39 | (seq-map (lambda (elt)
40 | (prog1
41 | (funcall function elt index)
42 | (setq index (1+ index))))
43 | sequence))))
44 |
45 | (provide 'elbank-compat)
46 | ;;; elbank-compat.el ends here
47 |
--------------------------------------------------------------------------------
/elbank-overview.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-overview.el --- Elbank overview buffer -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 |
7 | ;; This program is free software; you can redistribute it and/or modify
8 | ;; it under the terms of the GNU General Public License as published by
9 | ;; the Free Software Foundation, either version 3 of the License, or
10 | ;; (at your option) any later version.
11 |
12 | ;; This program is distributed in the hope that it will be useful,
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ;; GNU General Public License for more details.
16 |
17 | ;; You should have received a copy of the GNU General Public License
18 | ;; along with this program. If not, see .
19 |
20 | ;;; Commentary:
21 |
22 | ;;
23 |
24 | ;;; Code:
25 |
26 | (require 'button)
27 | (require 'seq)
28 | (require 'map)
29 | (require 'subr-x)
30 |
31 | (require 'elbank-common)
32 | (require 'elbank-boobank)
33 | (require 'elbank-report)
34 | (require 'elbank-budget)
35 |
36 | (defvar elbank-overview-buffer-name "*elbank overview*"
37 | "Name of the elbank overview buffer.")
38 |
39 | (defvar elbank-overview-mode-map
40 | (let ((map (make-sparse-keymap)))
41 | (define-key map (kbd "g") #'elbank-overview-update-buffer)
42 | (define-key map (kbd "u") #'elbank-overview-update-data)
43 | (define-key map (kbd "r") #'elbank-report)
44 | (define-key map (kbd "b") #'elbank-budget-report)
45 | (define-key map (kbd "n") #'forward-button)
46 | (define-key map (kbd "p") #'backward-button)
47 | (define-key map [tab] #'forward-button)
48 | (define-key map [backtab] #'backward-button)
49 | (define-key map (kbd "q") #'elbank-quit)
50 | map)
51 | "Keymap for `elbank-overview-mode'.")
52 |
53 | (define-derived-mode elbank-overview-mode nil "Elbank Overview"
54 | "Major mode for Elbank overview.
55 |
56 | \\{elbank-overview-mode-map}"
57 | (read-only-mode)
58 | (setq imenu-prev-index-position-function #'elbank-overview--imenu-prev-index-position-function)
59 | (setq imenu-extract-index-name-function #'elbank-overview--imenu-extract-index-name-function))
60 |
61 | (defun elbank-overview-account-at-point (&optional point)
62 | "Return account at POINT, nil if none.
63 | If POINT is nil, use current point."
64 | (get-text-property (or point (point)) 'elbank-account))
65 |
66 | (defun elbank-overview--imenu-prev-index-position-function ()
67 | "Move point to previous button in current buffer.
68 | This function is used as a value for
69 | `imenu-prev-index-position-function'."
70 | (ignore-errors (backward-button 1)))
71 |
72 | (defun elbank-overview--imenu-extract-index-name-function ()
73 | "Return imenu name for line at point.
74 | This function is used as a value for
75 | `imenu-extract-index-name-function'. Point should be at the
76 | beginning of an account line.
77 | If nothing important is at point, return nil."
78 | (get-text-property (point) 'imenu-name))
79 |
80 | ;;;###autoload
81 | (defun elbank-overview ()
82 | "Show an overview of all accounts."
83 | (interactive)
84 | (elbank-read-data)
85 | (unless elbank-data
86 | (when (yes-or-no-p "No data found, import from weboob?")
87 | (elbank-overview-update-data)))
88 | (if-let ((buf (get-buffer elbank-overview-buffer-name)))
89 | (progn
90 | (switch-to-buffer buf)
91 | (elbank-overview-update-buffer))
92 | (let ((buf (get-buffer-create elbank-overview-buffer-name)))
93 | (pop-to-buffer buf)
94 | (elbank-overview-mode)
95 | (elbank-overview-update-buffer))))
96 |
97 | ;;;###autoload
98 | (defun elbank-overview-update-buffer ()
99 | "Update the overview buffer with the latest data."
100 | (interactive)
101 | (let ((inhibit-read-only t))
102 | (erase-buffer)
103 | (remove-overlays (point-min) (point-max))
104 | (insert "Bank accounts overview")
105 | (put-text-property (point-at-bol) (point)
106 | 'face 'elbank-header-face)
107 | (insert "\n\n")
108 | (elbank-overview--insert-accounts)
109 | (elbank-overview--insert-hr)
110 | (insert "\n\n")
111 | (insert "Custom reports")
112 | (put-text-property (point-at-bol) (point)
113 | 'face 'elbank-header-face)
114 | (insert " ")
115 | (let ((beg (point)))
116 | (insert "[Customize]")
117 | (make-text-button beg (point)
118 | 'follow-link t
119 | 'action (lambda (&rest _)
120 | (customize-group 'elbank-report))))
121 | (insert "\n\n")
122 | (elbank-overview--insert-saved-reports)
123 | (insert "\n")
124 | (insert "Budget report")
125 | (put-text-property (point-at-bol) (point)
126 | 'face 'elbank-header-face)
127 | (insert "\n- ")
128 | (let ((beg (point))
129 | (name (format "Budget report of %s"
130 | (elbank-format-period
131 | `(month ,(car (last (elbank-transaction-months))))))))
132 | (insert name)
133 | (make-text-button beg (point)
134 | 'follow-link t
135 | 'action (lambda (&rest _)
136 | (elbank-budget-report)))
137 | (put-text-property (point-at-bol) (point-at-eol) 'imenu-name name))
138 | (insert "\n")
139 | (goto-char (point-min))))
140 |
141 | (defun elbank-overview-update-data ()
142 | "Read new data from boobank and update the buffer."
143 | (interactive)
144 | (message "Elbank: updating...")
145 | (elbank-boobank-update
146 | (lambda ()
147 | (message "Elbank: done!")
148 | (with-current-buffer elbank-overview-buffer-name
149 | (elbank-overview-update-buffer)))))
150 |
151 | (defun elbank-overview--insert-hr ()
152 | "Insert a horizontal rule."
153 | ;; End line
154 | (let ((p (1+ (point))))
155 | (insert "\n\n")
156 | (put-text-property p (1+ p) 'face '(:underline t :inherit border))
157 | (overlay-put (make-overlay p (1+ p))
158 | 'before-string
159 | (propertize "\n" 'face '(:underline t)
160 | 'display '(space :align-to 999)))))
161 |
162 | (defun elbank-overview--insert-accounts ()
163 | "Insert all accounts informations in the current buffer."
164 | (seq-do (lambda (group)
165 | (elbank-overview--insert-bank (car group))
166 | (seq-map #'elbank-overview--insert-account
167 | (cdr group))
168 | (insert "\n"))
169 | (seq-group-by #'elbank-account-group (map-elt elbank-data 'accounts))))
170 |
171 | (defun elbank-overview--insert-bank (bankname)
172 | "Insert BANKNAME into the current buffer as a header."
173 | (insert (format "%s" bankname))
174 | (put-text-property (point-at-bol) (point)
175 | 'face
176 | 'elbank-subheader-face)
177 | (insert "\n"))
178 |
179 | (defun elbank-overview--insert-account (account)
180 | "Insert ACCOUNT informations in the current buffer."
181 | (insert "- ")
182 | (let ((beg (point)))
183 | (insert (format "%s" (map-elt account 'label)))
184 | (make-text-button beg (point)
185 | 'follow-link t
186 | 'action (lambda (&rest _)
187 | (elbank-overview--list-transactions account))))
188 | (let* ((balance (format "%s"
189 | (map-elt account 'balance)))
190 | (fill-width (+ (- (seq-length (elbank--longest-account-label))
191 | (current-column))
192 | (- 25 (seq-length balance)))))
193 | (dotimes (_ fill-width)
194 | (insert " "))
195 | (elbank--insert-amount balance (map-elt account 'currency))
196 | (put-text-property (point-at-bol) (point-at-eol) 'elbank-account account)
197 | (put-text-property (point-at-bol) (point-at-eol) 'imenu-name (elbank-account-name account))
198 | (insert "\n")))
199 |
200 | (defun elbank-overview--insert-saved-reports ()
201 | "Insert links to saved monthly and yearly reports."
202 | (seq-doseq (type '(month year))
203 | (elbank-overview--insert-saved-reports-type type)
204 | (insert "\n")))
205 |
206 | (defun elbank-overview--insert-saved-reports-type (type)
207 | "Insert links to saved reports of period TYPE."
208 | (let (label reports)
209 | (pcase type
210 | (`month (setq label "Monthly reports")
211 | (setq reports elbank-saved-monthly-reports))
212 | (`year (setq label "Yearly reports")
213 | (setq reports elbank-saved-yearly-reports)))
214 | (when reports
215 | (insert label)
216 | (put-text-property (point-at-bol) (point)
217 | 'face 'elbank-subheader-face)
218 | (insert " ")
219 | (insert "\n")
220 | (seq-doseq (report (seq-sort (lambda (a b)
221 | (string< (car a) (car b)))
222 | reports))
223 | (insert "- ")
224 | (let ((beg (point)))
225 | (insert (car report))
226 | (make-text-button beg (point)
227 | 'action
228 | (lambda (&rest _)
229 | (elbank-report--open-saved-report report type)))
230 | (put-text-property beg (point) 'imenu-name (car report))
231 | (insert "\n"))))))
232 |
233 | (defun elbank-overview--list-transactions (account)
234 | "Display the list of transactions for ACCOUNT."
235 | (elbank-report :account-id (map-elt account 'id)
236 | :reverse-sort t))
237 |
238 | (provide 'elbank-overview)
239 | ;;; elbank-overview.el ends here
240 |
--------------------------------------------------------------------------------
/elbank-progressbar.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-progressbar.el --- Progressbar widget used by elbank -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 |
7 | ;; This program is free software; you can redistribute it and/or modify
8 | ;; it under the terms of the GNU General Public License as published by
9 | ;; the Free Software Foundation, either version 3 of the License, or
10 | ;; (at your option) any later version.
11 |
12 | ;; This program is distributed in the hope that it will be useful,
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ;; GNU General Public License for more details.
16 |
17 | ;; You should have received a copy of the GNU General Public License
18 | ;; along with this program. If not, see .
19 |
20 | ;;; Commentary:
21 |
22 | ;;
23 |
24 | ;;; Code:
25 |
26 | (require 'seq)
27 |
28 | (require 'elbank-common)
29 |
30 | (defgroup elbank-progressbar nil
31 | "Elbank progressbar."
32 | :group 'elbank)
33 |
34 | (defface elbank-progressbar-box-face '((t . (:box 1)))
35 | "Face used to represent the progressbar."
36 | :group 'elbank-progressbar)
37 |
38 | (defface elbank-progressbar-fill-face '((t . (:background "dark green" :weight bold)))
39 | "Face used to fill the progressbar."
40 | :group 'elbank-progressbar)
41 |
42 | (defface elbank-progressbar-overflow-face '((t . (:background "firebrick" :weight bold)))
43 | "Face used as a warning for overflowing progressbars."
44 | :group 'elbank-progressbar)
45 |
46 | (defun elbank-insert-progressbar (percent &optional width)
47 | "Insert a progressbar at point with PERCENT filled.
48 | The of the progressbar is set by WIDTH and default to 50.
49 |
50 | If PERCENT is greater than 100, fill the progressbar in red."
51 | (let* ((width (or width 50))
52 | (filled-width (min width (* width (/ percent 100.0))))
53 | (label (format "%s%%" percent))
54 | (label-padding (/ (- filled-width (seq-length label)) 2.0))
55 | (beg (point))
56 | (col (current-column)))
57 | (dotimes (_ label-padding)
58 | (insert " "))
59 | (insert label)
60 | (dotimes (_ (min label-padding
61 | (- width (- (current-column) col))))
62 | (insert " "))
63 | (when (not (zerop percent))
64 | (put-text-property beg (point)
65 | 'face (if (> percent 100)
66 | 'elbank-progressbar-overflow-face
67 | 'elbank-progressbar-fill-face)))
68 | (dotimes (_ (- width (- (current-column) col)))
69 | (insert " "))
70 | (let ((box (make-overlay beg (point))))
71 | (overlay-put box 'face 'elbank-progressbar-box-face))))
72 |
73 | (provide 'elbank-progressbar)
74 | ;;; elbank-progressbar.el ends here
75 |
--------------------------------------------------------------------------------
/elbank-report.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-report.el --- Elbank report functionality -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 |
7 | ;; This program is free software; you can redistribute it and/or modify
8 | ;; it under the terms of the GNU General Public License as published by
9 | ;; the Free Software Foundation, either version 3 of the License, or
10 | ;; (at your option) any later version.
11 |
12 | ;; This program is distributed in the hope that it will be useful,
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ;; GNU General Public License for more details.
16 |
17 | ;; You should have received a copy of the GNU General Public License
18 | ;; along with this program. If not, see .
19 |
20 | ;;; Commentary:
21 |
22 | ;;
23 |
24 | ;;; Code:
25 |
26 | (require 'seq)
27 | (require 'map)
28 | (require 'subr-x)
29 | (require 'cl-lib)
30 |
31 | (require 'button)
32 |
33 | (require 'elbank-common)
34 | (require 'elbank-transaction)
35 | (require 'elbank-compat)
36 |
37 | ;;;###autoload
38 | (defgroup elbank-report nil
39 | "Elbank report settings"
40 | :prefix "elbank-report-"
41 | :group 'elbank)
42 |
43 | ;;;###autoload
44 | (defcustom elbank-report-columns '(date label category amount)
45 | "List of transaction columns to print in reports."
46 | :type '(repeat (symbol :tag "Key")))
47 |
48 | ;;;###autoload
49 | (defcustom elbank-saved-monthly-reports nil
50 | "Saved report filters for monthly reports.
51 |
52 | \"Group by\" can be either one of the available columns or nil.
53 |
54 | \"Sort by\" can be either one of the available columns or nil.
55 | When nil, transactions are sorted using the first column of the
56 | report.
57 |
58 | \"Category\" can be any string (or empty for no category filter).
59 |
60 | Available columns:
61 | - `date'
62 | - `rdate' (real date)
63 | - `label'
64 | - `raw' (raw transaction text)
65 | - `category'
66 | - `account'
67 | - `amount'."
68 | :type `(repeat (list (string :tag "Name")
69 | (string :tag "Category")
70 | (symbol :tag "Group by")
71 | (symbol :tag "Sort by" :value date)
72 | (repeat :tag "Columns"
73 | :value ,elbank-report-columns
74 | (symbol :tag "Column"))
75 | (boolean :tag "Reverse sort"))))
76 |
77 | ;;;###autoload
78 | (defcustom elbank-saved-yearly-reports nil
79 | "Saved report filters for yearly reports.
80 |
81 | \"Group by\" can be either one of the available columns or nil.
82 |
83 | \"Sort by\" can be either one of the available columns or nil.
84 | When nil, transactions are sorted using the first column of the
85 | report.
86 |
87 | \"Category\" can be any string (or empty for no category filter).
88 |
89 | Available columns:
90 | - `date'
91 | - `rdate' (real date)
92 | - `label'
93 | - `raw' (raw transaction text)
94 | - `category'
95 | - `amount'."
96 | :type `(repeat (list (string :tag "Name")
97 | (string :tag "Category")
98 | (symbol :tag "Group by")
99 | (symbol :tag "Sort by" :value date)
100 | (repeat :tag "Columns"
101 | :value ,elbank-report-columns
102 | (symbol :tag "Column"))
103 | (boolean :tag "Reverse sort"))))
104 |
105 | (defvar elbank-report-mode-map
106 | (let ((map (copy-keymap elbank-base-report-mode-map)))
107 | (define-key map (kbd "f c") #'elbank-report-filter-category)
108 | (define-key map (kbd "f a") #'elbank-report-filter-account)
109 | (define-key map (kbd "f p") #'elbank-report-filter-period)
110 | (define-key map (kbd "G") #'elbank-report-group-by)
111 | (define-key map (kbd "S") #'elbank-report-sort-by)
112 | (define-key map (kbd "s") #'elbank-report-sort-reverse)
113 | (define-key map (kbd "c") #'elbank-report-set-category)
114 | (define-key map (kbd "l") #'elbank-report-set-custom-label)
115 | (define-key map (kbd "+") #'elbank-report-split-transaction)
116 | (define-key map (kbd "-") #'elbank-report-unsplit-transaction)
117 | map)
118 | "Keymap for `elbank-report-mode'.")
119 |
120 | (define-derived-mode elbank-report-mode elbank-base-report-mode "Elbank Report"
121 | "Major mode for viewing a report.
122 |
123 | \\{elbank-report-mode-map}"
124 | (setq-local revert-buffer-function #'elbank-report-refresh)
125 | (setq-local truncate-lines t)
126 | (add-hook 'elbank-base-report-refresh-hook 'elbank-report-refresh nil t))
127 |
128 | (defvar elbank-report-amount-columns '(amount)
129 | "List of columns for which values are numbers.")
130 | (make-variable-buffer-local 'elbank-report-amount-columns)
131 |
132 | (defvar elbank-report-max-column-width 40
133 | "Maximum width a report column can take.")
134 |
135 | (defvar elbank-report-group-by nil
136 | "Column by which transactions are grouped.")
137 | (make-variable-buffer-local 'elbank-report-group-by)
138 |
139 | (defvar elbank-report-sort-by nil
140 | "Column uses for sorting transactions.")
141 | (make-variable-buffer-local 'elbank-report-sort-by)
142 |
143 | (defvar elbank-report-sort-reversed nil
144 | "Reverse the sorting order when non-nil.")
145 | (make-variable-buffer-local 'elbank-report-sort-reversed)
146 |
147 | (defvar elbank-report-column-widths nil
148 | "List of column widths required to correctly display a report.")
149 | (make-variable-buffer-local 'elbank-report-widths)
150 |
151 | (defvar elbank-report-account-id nil
152 | "Account filter used in a report buffer.")
153 | (make-variable-buffer-local 'elbank-report-account-id)
154 |
155 | (defvar elbank-report-category nil
156 | "Category filter used in a report buffer.")
157 | (make-variable-buffer-local 'elbank-report-category)
158 |
159 | (defvar elbank-report-inhibit-update nil
160 | "When non-nil, do not perform a report update after setting a filter.")
161 |
162 | ;;;###autoload
163 | (cl-defun elbank-report (&key account-id period category group-by sort-by reverse-sort columns)
164 | "Build a report for transactions matching ACCOUNT-ID PERIOD and CATEGORY.
165 |
166 | When called interactively, prompt for ACCOUNT-ID, PERIOD and CATEGORY.
167 |
168 | Build the report for COLUMNS when non-nil,
169 | `elbank-report-columns' otherwise.
170 |
171 | Transactions are grouped by the GROUP-BY column when non-nil.
172 |
173 | Transactions are sorted by the SORT-BY column, or by the first
174 | column if nil.
175 |
176 | When a PERIOD is provided, append a sum row to the report.
177 |
178 | Return the report buffer."
179 | (interactive)
180 | (let ((buf (generate-new-buffer "*elbank report*")))
181 | (pop-to-buffer buf)
182 | (elbank-report-mode)
183 | (setq elbank-report-category category)
184 | (setq elbank-report-period period)
185 | (setq elbank-report-account-id account-id)
186 | (setq elbank-report-group-by group-by)
187 | (setq elbank-report-sort-by sort-by)
188 | (setq elbank-report-sort-reversed reverse-sort)
189 | (when columns
190 | (setq-local elbank-report-columns columns))
191 | (when (called-interactively-p 'interactive)
192 | (let ((elbank-report-inhibit-update t))
193 | (elbank-report-filter-account)
194 | (elbank-report-filter-period)
195 | (elbank-report-filter-category)))
196 | (elbank-report-refresh)
197 | buf))
198 |
199 | (defun elbank-report--all-saved-reports ()
200 | "Return a list of all saved reports, monthly and yearly."
201 | (append elbank-saved-monthly-reports elbank-saved-yearly-reports))
202 |
203 | (defun elbank-report--open-saved-report (report period-type)
204 | "Open a buffer presenting REPORT.
205 | PERIOD-TYPE is either `month' or `year'."
206 | (let ((time (if (eq period-type 'month)
207 | (car (last (elbank-transaction-months)))
208 | (car (last (elbank-transaction-years))))))
209 | (elbank-report :category (seq-elt report 1)
210 | :group-by (seq-elt report 2)
211 | :sort-by (seq-elt report 3)
212 | :columns (seq-elt report 4)
213 | :reverse-sort (seq-elt report 5)
214 | :period (list period-type time))))
215 |
216 | ;;;###autoload
217 | (defun elbank-report-open-by-name (name)
218 | "Open report named NAME."
219 | (interactive (list (completing-read
220 | "Report: "
221 | (seq-map (lambda (report) (seq-elt report 0))
222 | (elbank-report--all-saved-reports)))))
223 | (when-let* ((report (seq-find
224 | (lambda (report) (string= (seq-elt report 0) name))
225 | (elbank-report--all-saved-reports)))
226 | (type (if (seq-contains elbank-saved-monthly-reports report)
227 | 'month
228 | 'year)))
229 | (elbank-report--open-saved-report report type)))
230 |
231 | (defun elbank-report-filter-category ()
232 | "Prompt for a category and update the report buffer."
233 | (interactive)
234 | (setq elbank-report-category
235 | (completing-read "Category: " (map-keys elbank-categories)
236 | nil
237 | nil
238 | (or elbank-report-category "")))
239 | (elbank-report-refresh))
240 |
241 | (defun elbank-report-filter-account ()
242 | "Prompt for an account and update the report buffer."
243 | (interactive)
244 | (let* ((accounts (map-elt elbank-data 'accounts))
245 | (labels (seq-map (lambda (account)
246 | (map-elt account 'label))
247 | accounts))
248 | (label (completing-read "Select account: " labels)))
249 | (setq elbank-report-account-id
250 | (when-let ((position (seq-position labels label)))
251 | (map-elt (seq-elt accounts position) 'id))))
252 | (elbank-report-refresh))
253 |
254 | (defun elbank-report-filter-period ()
255 | "Prompt for a period to select for the current report."
256 | (interactive)
257 | (let ((type (completing-read "Period type: " '(month year))))
258 | (pcase type
259 | ("year" (elbank-report-filter-year))
260 | ("month" (elbank-report-filter-month))
261 | (_ (setq elbank-report-period nil)
262 | (elbank-report-refresh)))))
263 |
264 | (defun elbank-report-filter-year ()
265 | "Prompt for a year to select for the current report."
266 | (interactive)
267 | (let* ((years (seq-reverse (elbank-transaction-years)))
268 | (labels (seq-map (lambda (year)
269 | (format-time-string "%Y" year))
270 | years))
271 | (label (completing-read "Select year: " labels)))
272 | (setq elbank-report-period
273 | (when-let ((position (seq-position labels label)))
274 | `(year ,(seq-elt years position))))
275 | (elbank-report-refresh)))
276 |
277 | (defun elbank-report-filter-month ()
278 | "Prompt for a month to select for the current report."
279 | (interactive)
280 | (let* ((months (seq-reverse (elbank-transaction-months)))
281 | (labels (seq-map (lambda (month)
282 | (format-time-string "%B %Y" month))
283 | months))
284 | (label (completing-read "Select month: " labels)))
285 | (setq elbank-report-period
286 | (when-let ((position (seq-position labels label)))
287 | (setq elbank-report-period `(month ,(seq-elt months position)))))
288 | (elbank-report-refresh)))
289 |
290 | (defun elbank-report-group-by (column-name)
291 | "Prompt for a COLUMN-NAME to group transactions."
292 | (interactive (list (completing-read "Group by: "
293 | elbank-report-available-columns)))
294 | (setq-local elbank-report-group-by
295 | (if (string-empty-p column-name)
296 | nil
297 | (intern column-name)))
298 | (elbank-report-refresh))
299 |
300 | (defun elbank-report-sort-by (column-name)
301 | "Prompt for a COLUMN-NAME to sort the current report."
302 | (interactive (list (completing-read "Sort by: "
303 | elbank-report-available-columns)))
304 | (setq-local elbank-report-sort-by
305 | (if (string-empty-p column-name)
306 | nil
307 | (intern column-name)))
308 | (elbank-report-refresh))
309 |
310 | (defun elbank-report-sort-reverse ()
311 | "Reverse the sort order of the current report."
312 | (interactive)
313 | (setq-local elbank-report-sort-reversed
314 | (not elbank-report-sort-reversed))
315 | (elbank-report-refresh))
316 |
317 | (defun elbank-report-refresh (&rest _)
318 | "Update the report in the current buffer.
319 | When `elbank-report-inhibit-update' is non-nil, do not update."
320 | (unless elbank-report-inhibit-update
321 | (let ((inhibit-read-only t)
322 | (transactions (elbank-filter-transactions
323 | (elbank-all-transactions)
324 | :account-id elbank-report-account-id
325 | :period elbank-report-period
326 | :category elbank-report-category))
327 | (inhibit-read-only t))
328 | (let ((pos (point)))
329 | (erase-buffer)
330 | (elbank-report--update-column-widths transactions)
331 | (elbank-report--insert-preambule)
332 | (elbank-report--insert-column-titles)
333 | (elbank-report--insert-separator "═")
334 | (if elbank-report-group-by
335 | (elbank-report--insert-groups transactions)
336 | (elbank-report--insert-transactions transactions))
337 | (elbank-report--insert-separator "═")
338 | (elbank-report--insert-sum transactions)
339 | (goto-char (min (point-max) pos))))))
340 |
341 | (defun elbank-report-set-category (category &optional transaction)
342 | "Update the CATEGORY of TRANSACTION.
343 | When called interactively, prompt for the category.
344 |
345 | If TRANSACTION is nil, set the category of the transaction at
346 | point."
347 | (interactive (list (completing-read "Category: "
348 | (map-keys elbank-categories))))
349 | (unless transaction
350 | (setq transaction (elbank-report--transaction-at-point)))
351 | (setf (elbank-transaction-elt transaction 'category)
352 | category)
353 | (elbank-write-data)
354 | (elbank-report-refresh))
355 |
356 | (defun elbank-report-set-custom-label (label &optional transaction)
357 | "Set a custom LABEL for TRANSACTION.
358 | When called interactively, prompt for the label.
359 |
360 | If LABEL is an empty string, set nil as the custom label.
361 |
362 | If TRANSACTION is nil, set the custom label of the transaction at
363 | point."
364 | (interactive (list (read-from-minibuffer "Custom label: ")))
365 | (unless transaction
366 | (setq transaction (elbank-report--transaction-at-point)))
367 | (setf (elbank-transaction-elt transaction 'custom-label)
368 | (if (string-empty-p label)
369 | nil
370 | label))
371 | (elbank-write-data)
372 | (elbank-report-refresh))
373 |
374 | (defun elbank-report--split-amount (amount)
375 | "Split amount into a list of (CATEGORY-NAME . AMOUNT)."
376 | (let ((amount-left amount)
377 | (categories (list)))
378 | (while (not (zerop amount-left))
379 | (let ((sub-label (completing-read "Category: "
380 | (map-keys elbank-categories)))
381 | (sub-amount (read-from-minibuffer
382 | (format "Amount (%s left): " amount-left)
383 | (number-to-string amount-left))))
384 | (push (cons sub-label sub-amount) categories)
385 | (setq amount-left (/ (round (* 100 (- amount-left
386 | (string-to-number sub-amount))))
387 | 100.0))))
388 | categories))
389 |
390 | (defun elbank-report-split-transaction (&optional transaction)
391 | "Split TRANSACTION, transaction at point if nil.
392 |
393 | Splitting is done by assigning multiple categories to
394 | transaction, each one with an amount."
395 | (interactive)
396 | (let* ((trans (or transaction (elbank-report--transaction-at-point)))
397 | (amount (elbank-transaction-elt trans 'amount)))
398 | (if (elbank-sub-transaction-p trans)
399 | (let* ((main-transaction (elbank-transaction-elt trans 'split-from))
400 | (sub-category (map-elt trans 'category))
401 | (all-categories (map-elt main-transaction 'category))
402 | (other-categories (cl-remove (cons sub-category amount) all-categories :count 1 :test #'equal))
403 | (new-sub-categories (elbank-report--split-amount (string-to-number amount))))
404 | (elbank-report-set-category (append other-categories new-sub-categories) main-transaction))
405 | (elbank-report-set-category (elbank-report--split-amount (string-to-number amount)) trans))))
406 |
407 | (defun elbank-report-unsplit-transaction ()
408 | "Unsplit the parent of the sub transaction at point.
409 |
410 | Combining the parent is done by setting its category to nil."
411 | (interactive)
412 | (let ((trans (elbank-report--transaction-at-point)))
413 | (unless (elbank-sub-transaction-p trans)
414 | (user-error "Cannot combine transaction"))
415 | (elbank-report-set-category nil (elbank-transaction-elt trans 'split-from))))
416 |
417 | (defun elbank-report--transaction-at-point ()
418 | "Return the transaction at point.
419 |
420 | Signal an error if there is no transaction at point."
421 | (let ((tr (get-text-property (point) 'transaction)))
422 | (unless tr (user-error "No transaction at point"))
423 | tr))
424 |
425 | (defun elbank-report--insert-preambule ()
426 | "Display the report filters in the current buffer."
427 | (if (or elbank-report-account-id
428 | elbank-report-period
429 | elbank-report-category)
430 | (progn
431 | (seq-do (lambda (filter)
432 | (when (cdr filter)
433 | (insert (car filter))
434 | (put-text-property (point-at-bol) (point)
435 | 'face 'elbank-subheader-face)
436 | (insert " ")
437 | (insert (format "%s" (cdr filter)))
438 | (insert "\n")))
439 | `(("Account:" . ,(and elbank-report-account-id
440 | (map-elt (elbank-account-with-id
441 | elbank-report-account-id)
442 | 'label)))
443 | ("Period:" . ,(and elbank-report-period
444 | (elbank-format-period elbank-report-period)))
445 | ("Category:" . ,elbank-report-category))))
446 | (progn
447 | (insert "All transactions")
448 | (put-text-property (point-at-bol) (point)
449 | 'face 'elbank-subheader-face)
450 | (insert "\n")))
451 | (insert "\n"))
452 |
453 | (defun elbank-report--update-column-widths (transactions)
454 | "Locally set report columns widths needed to print TRANSACTIONS."
455 | (setq elbank-report-column-widths
456 | (elbank-seq-map-indexed
457 | (lambda (col index)
458 | (let ((row-max-width
459 | (seq-reduce (lambda (acc trans)
460 | (max acc
461 | (seq-length
462 | (elbank-report--cell trans col))))
463 | transactions
464 | 0)))
465 | (min (+ 2 (max row-max-width
466 | (seq-length (symbol-name
467 | (seq-elt elbank-report-columns
468 | index)))))
469 | elbank-report-max-column-width)))
470 | elbank-report-columns)))
471 |
472 | (cl-defgeneric elbank-report--cell (transaction column)
473 | "Return the text for the cell for TRANSACTION at COLUMN."
474 | (let ((str (elbank-transaction-elt transaction column "")))
475 | (elbank-report--truncate str)))
476 |
477 | (cl-defmethod elbank-report--cell (transaction (_column (eql label)))
478 | "Return a button text with the label of TRANSACTION.
479 | When clicking the button, jump to the transaction."
480 | (with-temp-buffer
481 | (insert (or (elbank-transaction-elt transaction 'custom-label)
482 | (elbank-transaction-elt transaction 'label)
483 | (elbank-transaction-elt transaction 'raw)
484 | ""))
485 | (make-text-button (point-at-bol) (point)
486 | 'follow-link t
487 | 'action
488 | (lambda (&rest _)
489 | (elbank-show-transaction transaction)))
490 | (elbank-report--truncate (buffer-string))))
491 |
492 | (cl-defmethod elbank-report--cell (transaction (_column (eql account)))
493 | "Return the label of the account associated with TRANSACTION."
494 | (elbank-report--truncate (elbank-account-name (elbank-transaction-elt transaction 'account))))
495 |
496 | (defun elbank-report--truncate (str)
497 | "Truncate STR to `elbank-report-max-column-width'.
498 | If STR overflows, add an ellipsis."
499 | (if (> (seq-length str) elbank-report-max-column-width)
500 | (format "%s…" (seq-take str (- elbank-report-max-column-width 1)))
501 | str))
502 |
503 | (defun elbank-report--insert-column-titles ()
504 | "Insert the report headers into the current buffer."
505 | (elbank-report--insert-title-row
506 | (seq-map (lambda (col) (capitalize (symbol-name col)))
507 | elbank-report-columns)))
508 |
509 | (defun elbank-report--insert-transactions (transactions)
510 | "Insert TRANSACTIONS rows the current buffer."
511 | (seq-do (lambda (trans)
512 | (let ((beg (point)))
513 | (elbank-report--insert-row
514 | (seq-map (lambda (col)
515 | (format "%s"
516 | (elbank-report--cell trans col)))
517 | elbank-report-columns)
518 | t)
519 | (put-text-property beg (point) 'transaction trans)))
520 | (elbank-report--sort-transactions transactions)))
521 |
522 | (defun elbank-report--insert-groups (transactions)
523 | "Insert TRANSACTIONS grouped by a property.
524 | The grouping property is defined by `elbank-report-group-by'."
525 | (seq-do (lambda (group)
526 | (elbank-report--insert-separator " ")
527 | (elbank-report--insert-title-row (list (or (car group) "None")))
528 | (elbank-report--insert-separator)
529 | (elbank-report--insert-transactions (cdr group))
530 | (elbank-report--insert-separator)
531 | (elbank-report--insert-sum (cdr group)))
532 | (elbank-report--sort-groups
533 | (seq-group-by (lambda (trans)
534 | (elbank-transaction-elt trans elbank-report-group-by ""))
535 | transactions))))
536 |
537 | (defun elbank-report--insert-sum (transactions)
538 | "Insert the sum row for TRANSACTIONS the current buffer."
539 | (elbank-report--insert-row
540 | (seq-map (lambda (col)
541 | (if (seq-contains elbank-report-amount-columns col)
542 | (elbank--propertize-amount (elbank-sum-transactions transactions))
543 | ""))
544 | elbank-report-columns)))
545 |
546 | (defun elbank-report--insert-row (row &optional propertize-amounts spacer)
547 | "Insert each element of ROW in the current buffer.
548 |
549 | When PROPERTIZE-AMOUNTS is non-nil, insert amounts using
550 | `elbank--propertize-amount'. SPACER is used for padding if
551 | non-nil."
552 | (let ((spacer (or spacer " ")))
553 | (elbank-seq-map-indexed
554 | (lambda (col index)
555 | (let* ((amount (seq-contains elbank-report-amount-columns col))
556 | (raw-item (or (seq-elt row index) ""))
557 | (item (if (and amount propertize-amounts)
558 | (elbank--propertize-amount raw-item)
559 | raw-item))
560 | (width (seq-elt elbank-report-column-widths index))
561 | (padding (- width (seq-length item))))
562 | (unless amount
563 | (insert (format "%s%s%s" spacer item spacer)))
564 | (dotimes (_ padding)
565 | (insert spacer))
566 | (when amount
567 | (insert (format "%s%s%s" spacer item spacer)))))
568 | elbank-report-columns))
569 | (insert "\n"))
570 |
571 | (defun elbank-report--insert-title-row (row)
572 | "Insert ROW as a title row.
573 |
574 | Unlike `elbank-report--insert-row', elements of ROW are displayed
575 | in bold."
576 | (let ((beg (point)))
577 | (elbank-report--insert-row row)
578 | (add-text-properties beg (point)
579 | '(face bold))))
580 |
581 | (defun elbank-report--insert-separator (&optional separator)
582 | "Insert a separator line in the current buffer.
583 | Use SEPARATOR if non-nil,\"─\" otherwise."
584 | (elbank-report--insert-row (seq-map (lambda (_) "") elbank-report-columns)
585 | nil
586 | (or separator "─")))
587 |
588 | (defun elbank-report--sort-transactions (transactions)
589 | "Sort TRANSACTIONS.
590 |
591 | Transactions are sorted by `elbank-report-sort-by' if
592 | non-nil, or by the first column if nil."
593 | (let ((sort-column (or elbank-report-sort-by
594 | (car elbank-report-columns))))
595 | (elbank-report--sort transactions
596 | (lambda (trans)
597 | (elbank-transaction-elt trans sort-column ""))
598 | (seq-contains elbank-report-amount-columns sort-column))))
599 |
600 | (defun elbank-report--sort-groups (groups)
601 | "Sort GROUPS.
602 |
603 | If the sorting column is an amount, GROUPS are sorted by summing
604 | their transactions."
605 | (let* ((sort-column (or elbank-report-sort-by
606 | (car elbank-report-columns)))
607 | (amounts (seq-contains elbank-report-amount-columns sort-column)))
608 | (elbank-report--sort
609 | groups
610 | (lambda (group)
611 | (if amounts
612 | (elbank-sum-transactions (cdr group))
613 | (car group)))
614 | amounts)))
615 |
616 | (defun elbank-report--sort (collection accessor &optional amounts)
617 | "Sort COLLECTION by ACCESSOR.
618 |
619 | If AMOUNTS is non-nil, the sort is done by comparing numeric
620 | values, converting items of collection to numbers if needed."
621 | (let ((sort-fn (if amounts
622 | (lambda (a b)
623 | (< (if (numberp a) a (string-to-number a))
624 | (if (numberp b) b (string-to-number b))))
625 | #'string-lessp)))
626 | (seq-sort (lambda (a b)
627 | (let ((sort (funcall sort-fn
628 | (funcall accessor a)
629 | (funcall accessor b))))
630 | (if elbank-report-sort-reversed
631 | (not sort)
632 | sort)))
633 | collection)))
634 |
635 | (provide 'elbank-report)
636 | ;;; elbank-report.el ends here
637 |
--------------------------------------------------------------------------------
/elbank-transaction.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-transaction.el --- Major mode for displaying a transaction -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 |
7 | ;; This program is free software; you can redistribute it and/or modify
8 | ;; it under the terms of the GNU General Public License as published by
9 | ;; the Free Software Foundation, either version 3 of the License, or
10 | ;; (at your option) any later version.
11 |
12 | ;; This program is distributed in the hope that it will be useful,
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ;; GNU General Public License for more details.
16 |
17 | ;; You should have received a copy of the GNU General Public License
18 | ;; along with this program. If not, see .
19 |
20 | ;;; Commentary:
21 |
22 | ;;
23 |
24 | ;;; Code:
25 |
26 | (require 'seq)
27 | (require 'map)
28 |
29 | (require 'elbank-common)
30 |
31 | (defvar elbank-transaction-mode-map
32 | (let ((map (make-sparse-keymap)))
33 | (define-key map (kbd "q") #'elbank-quit)
34 | map)
35 | "Keymap for `elbank-transaction-mode'.")
36 |
37 | (define-derived-mode elbank-transaction-mode nil "Elbank Transaction"
38 | "Major mode for viewing a single transaction.
39 |
40 | \\{elbank-transaction-mode-map}"
41 | (read-only-mode))
42 |
43 | ;;;###autoload
44 | (defun elbank-show-transaction (transaction)
45 | "Show the details of TRANSACTION in a separate buffer."
46 | (let ((buf (get-buffer-create "*Elbank transaction*")))
47 | (pop-to-buffer buf)
48 | (elbank-transaction-mode)
49 | (elbank-transaction--refresh transaction)))
50 |
51 | (cl-defgeneric elbank-transaction--field (transaction key)
52 | "Return the label of the KEY of TRANSACTION."
53 | (map-elt transaction key))
54 |
55 | (cl-defmethod elbank-transaction--field (transaction (_key (eql account)))
56 | (elbank-account-name (elbank-transaction-elt transaction 'account)))
57 |
58 | (defun elbank-transaction--refresh (transaction)
59 | "Populate the current buffer with the details of TRANSACTION."
60 | (let* ((inhibit-read-only t)
61 | (keys (map-keys transaction))
62 | (width (1+ (seq-reduce (lambda (acc elt)
63 | (max acc (seq-length (symbol-name elt))))
64 | keys
65 | 0))))
66 | (erase-buffer)
67 | (seq-doseq (key (seq-sort (lambda (k1 k2)
68 | (string-lessp (symbol-name k1)
69 | (symbol-name k2)))
70 | keys))
71 | (let ((label (capitalize (format "%s:" key))))
72 | (dotimes (_ (- width (seq-length label)))
73 | (insert " "))
74 | (insert label)
75 | (put-text-property (point-at-bol) (point)
76 | 'face
77 | 'font-lock-keyword-face)
78 | (insert " ")
79 | (insert (format "%s" (elbank-transaction--field transaction key)))
80 | (insert "\n")))))
81 |
82 | (provide 'elbank-transaction)
83 | ;;; elbank-transaction.el ends here
84 |
--------------------------------------------------------------------------------
/elbank.el:
--------------------------------------------------------------------------------
1 | ;;; elbank.el --- Personal finances reporting application -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 | ;; Version: 1.2
7 | ;; Keywords: tools, personal-finances
8 | ;; Package-Requires: ((emacs "25") (seq "2.16"))
9 |
10 | ;; This file is not part of GNU Emacs.
11 |
12 | ;; This program is free software: you can redistribute it and/or modify
13 | ;; it under the terms of the GNU General Public License as published by
14 | ;; the Free Software Foundation, either version 3 of the License, or
15 | ;; (at your option) any later version.
16 |
17 | ;; This program is distributed in the hope that it will be useful,
18 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 | ;; GNU General Public License for more details.
21 |
22 | ;; You should have received a copy of the GNU General Public License
23 | ;; along with this program. If not, see .
24 |
25 | ;;; Commentary:
26 |
27 | ;; Elbank is a personal finances reporting (and soon budgeting) application.
28 | ;; It uses Weboob (https://weboob.org) for scraping data.
29 | ;;
30 | ;; Data is stored as JSON in `elbank-data-file' which defaults to
31 | ;; `$HOME/.emacs.d/elbank-data.json'.
32 | ;;
33 | ;; Transactions are automatically categorized with `elbank-categories', an
34 | ;; association list of the form:
35 | ;;
36 | ;; '(("category1" . ("regexp1" "regexp2"))
37 | ;; (("category2" . ("regexp")))
38 |
39 | ;;; Code:
40 |
41 | (require 'button)
42 | (require 'tabulated-list)
43 | (eval-and-compile (require 'cl-lib))
44 |
45 | (require 'elbank-overview)
46 | (require 'elbank-transaction)
47 | (require 'elbank-report)
48 | (require 'elbank-budget)
49 | (require 'elbank-boobank)
50 |
51 | (provide 'elbank)
52 | ;;; elbank.el ends here
53 |
--------------------------------------------------------------------------------
/features/elbank-budget.feature:
--------------------------------------------------------------------------------
1 | Feature: Display reports
2 |
3 | Scenario: Budget reporting
4 | When I make a budget report
5 | Then I should see:
6 | """
7 | Budget report for November 2017
8 |
9 | [Customize budgets]
10 |
11 | Expenses:Food 53% 159.25 of 300.00 budgeted
12 |
13 | Expenses:Rent 100% 450.00 of 450.00 budgeted
14 |
15 |
16 | Total: 609.25 of 750.00 budgeted.
17 | """
18 |
--------------------------------------------------------------------------------
/features/elbank-report.feature:
--------------------------------------------------------------------------------
1 | Feature: Display reports
2 |
3 | Scenario: Reporting all transactions
4 | When I make a full report
5 | Then I should see:
6 | """
7 | Date Label Category Amount
8 | ══════════════════════════════════════════════════════════════
9 | 2017-11-01 Rent Expenses:Rent -450.00
10 | 2017-11-18 CB Restaurant Expenses:Food -31.00
11 | 2017-11-20 Paycheck Income:Salary 2300.00
12 | 2017-11-20 Bakery xxx Expenses:Food -4.25
13 | 2017-11-24 CB Supermarket 1 Expenses:Food -124.00
14 | """
15 |
16 | Scenario: Reporting all transactions within a month
17 | When I make a monthly report
18 | Then I should see:
19 | """
20 | Period: November 2017
21 |
22 | Date Label Category Amount
23 | ══════════════════════════════════════════════════════════════
24 | 2017-11-01 Rent Expenses:Rent -450.00
25 | 2017-11-18 CB Restaurant Expenses:Food -31.00
26 | 2017-11-20 Paycheck Income:Salary 2300.00
27 | 2017-11-20 Bakery xxx Expenses:Food -4.25
28 | 2017-11-24 CB Supermarket 1 Expenses:Food -124.00
29 | ══════════════════════════════════════════════════════════════
30 | 1690.75
31 | """
32 |
33 | Scenario: Sort column
34 | When I make a monthly report with ":sort-by amount"
35 | Then I should see:
36 | """
37 | Period: November 2017
38 |
39 | Date Label Category Amount
40 | ══════════════════════════════════════════════════════════════
41 | 2017-11-01 Rent Expenses:Rent -450.00
42 | 2017-11-24 CB Supermarket 1 Expenses:Food -124.00
43 | 2017-11-18 CB Restaurant Expenses:Food -31.00
44 | 2017-11-20 Bakery xxx Expenses:Food -4.25
45 | 2017-11-20 Paycheck Income:Salary 2300.00
46 | ══════════════════════════════════════════════════════════════
47 | 1690.75
48 | """
49 |
50 | Scenario: Reverting the sort order
51 | When I make a monthly report with ":sort-by amount"
52 | And I press "s"
53 | Then I should see:
54 | """
55 | Period: November 2017
56 |
57 | Date Label Category Amount
58 | ══════════════════════════════════════════════════════════════
59 | 2017-11-20 Paycheck Income:Salary 2300.00
60 | 2017-11-20 Bakery xxx Expenses:Food -4.25
61 | 2017-11-18 CB Restaurant Expenses:Food -31.00
62 | 2017-11-24 CB Supermarket 1 Expenses:Food -124.00
63 | 2017-11-01 Rent Expenses:Rent -450.00
64 | ══════════════════════════════════════════════════════════════
65 | 1690.75
66 | """
67 |
68 | Scenario: Grouping
69 | When I make a monthly report with ":group-by category"
70 | Then I should see:
71 | """
72 | Period: November 2017
73 |
74 | Date Label Category Amount
75 | ══════════════════════════════════════════════════════════════
76 |
77 | Expenses:Food
78 | ──────────────────────────────────────────────────────────────
79 | 2017-11-18 CB Restaurant Expenses:Food -31.00
80 | 2017-11-20 Bakery xxx Expenses:Food -4.25
81 | 2017-11-24 CB Supermarket 1 Expenses:Food -124.00
82 | ──────────────────────────────────────────────────────────────
83 | -159.25
84 |
85 | Expenses:Rent
86 | ──────────────────────────────────────────────────────────────
87 | 2017-11-01 Rent Expenses:Rent -450.00
88 | ──────────────────────────────────────────────────────────────
89 | -450.00
90 |
91 | Income:Salary
92 | ──────────────────────────────────────────────────────────────
93 | 2017-11-20 Paycheck Income:Salary 2300.00
94 | ──────────────────────────────────────────────────────────────
95 | 2300.00
96 | ══════════════════════════════════════════════════════════════
97 | 1690.75
98 | """
99 |
100 | Scenario: Grouping and sorting reports
101 | When I make a monthly report with ":group-by category :sort-by amount"
102 | Then I should see:
103 | """
104 | Period: November 2017
105 |
106 | Date Label Category Amount
107 | ══════════════════════════════════════════════════════════════
108 |
109 | Expenses:Rent
110 | ──────────────────────────────────────────────────────────────
111 | 2017-11-01 Rent Expenses:Rent -450.00
112 | ──────────────────────────────────────────────────────────────
113 | -450.00
114 |
115 | Expenses:Food
116 | ──────────────────────────────────────────────────────────────
117 | 2017-11-24 CB Supermarket 1 Expenses:Food -124.00
118 | 2017-11-18 CB Restaurant Expenses:Food -31.00
119 | 2017-11-20 Bakery xxx Expenses:Food -4.25
120 | ──────────────────────────────────────────────────────────────
121 | -159.25
122 |
123 | Income:Salary
124 | ──────────────────────────────────────────────────────────────
125 | 2017-11-20 Paycheck Income:Salary 2300.00
126 | ──────────────────────────────────────────────────────────────
127 | 2300.00
128 | ══════════════════════════════════════════════════════════════
129 | 1690.75
130 | """
131 |
132 | Scenario: Selecting columns
133 | When I make a monthly report with ":columns (date label amount)"
134 | Then I should see:
135 | """
136 | Period: November 2017
137 |
138 | Date Label Amount
139 | ═════════════════════════════════════════════
140 | 2017-11-01 Rent -450.00
141 | 2017-11-18 CB Restaurant -31.00
142 | 2017-11-20 Paycheck 2300.00
143 | 2017-11-20 Bakery xxx -4.25
144 | 2017-11-24 CB Supermarket 1 -124.00
145 | ═════════════════════════════════════════════
146 | 1690.75
147 | """
148 |
149 | Scenario: Filtering by category
150 | When I make a monthly report
151 | And I press "fcExpenses:Food"
152 | Then I should see:
153 | """
154 | Period: November 2017
155 | Category: Expenses:Food
156 |
157 | Date Label Category Amount
158 | ══════════════════════════════════════════════════════════════
159 | 2017-11-18 CB Restaurant Expenses:Food -31.00
160 | 2017-11-20 Bakery xxx Expenses:Food -4.25
161 | 2017-11-24 CB Supermarket 1 Expenses:Food -124.00
162 | ══════════════════════════════════════════════════════════════
163 | -159.25
164 | """
165 |
166 | Scenario: Filtering by category
167 | When I make a monthly report
168 | And I press "fcExpenses"
169 | Then I should see:
170 | """
171 | Period: November 2017
172 | Category: Expenses
173 |
174 | Date Label Category Amount
175 | ══════════════════════════════════════════════════════════════
176 | 2017-11-01 Rent Expenses:Rent -450.00
177 | 2017-11-18 CB Restaurant Expenses:Food -31.00
178 | 2017-11-20 Bakery xxx Expenses:Food -4.25
179 | 2017-11-24 CB Supermarket 1 Expenses:Food -124.00
180 | ══════════════════════════════════════════════════════════════
181 | -609.25
182 | """
183 |
--------------------------------------------------------------------------------
/features/step-definitions/elbank-steps.el:
--------------------------------------------------------------------------------
1 | ;; This file contains your project specific step definitions. All
2 | ;; files in this directory whose names end with "-steps.el" will be
3 | ;; loaded automatically by Ecukes.
4 |
5 | (When "^I make a full report$"
6 | (lambda ()
7 | (switch-to-buffer (elbank-report))))
8 |
9 | (When "^I make a monthly report$"
10 | (lambda ()
11 | (switch-to-buffer (elbank-report
12 | :period `(month ,@(last (elbank-transaction-months)))))))
13 |
14 | (When "^I make a monthly report with \"\\(.+\\)\"$"
15 | (lambda (options)
16 | (switch-to-buffer (apply #'elbank-report
17 | :period `(month ,@(last (elbank-transaction-months)))
18 | (read (format "(%s)" options))))))
19 |
20 | (When "^I make a budget report$"
21 | (lambda ()
22 | (switch-to-buffer (elbank-budget-report))))
23 |
24 | (Given "^I have \"\\(.+\\)\"$"
25 | (lambda (options)
26 | ))
27 |
28 | (When "^I have \"\\(.+\\)\"$"
29 | (lambda (something)
30 | ;; ...
31 | ))
32 |
33 | (Then "^I should have \"\\(.+\\)\"$"
34 | (lambda (something)
35 | ;; ...
36 | ))
37 |
38 | (And "^I have \"\\(.+\\)\"$"
39 | (lambda (something)
40 | ;; ...
41 | ))
42 |
43 | (But "^I should not have \"\\(.+\\)\"$"
44 | (lambda (something)
45 | ;; ...
46 | ))
47 |
--------------------------------------------------------------------------------
/features/support/env.el:
--------------------------------------------------------------------------------
1 | (require 'f)
2 | (require 'subr-x)
3 |
4 | (defvar elbank-support-path
5 | (f-dirname load-file-name))
6 |
7 | (defvar elbank-features-path
8 | (f-parent elbank-support-path))
9 |
10 | (defvar elbank-root-path
11 | (f-parent elbank-features-path))
12 |
13 | (add-to-list 'load-path elbank-root-path)
14 |
15 | ;; Ensure that we don't load old byte-compiled versions
16 | (let ((load-prefer-newer t))
17 | (require 'elbank)
18 | (require 'espuds)
19 | (require 'ert))
20 |
21 | (Setup
22 | ;; Before anything has run
23 | (setq real-elbank-data elbank-data)
24 | (setq elbank-data
25 | '((accounts . [#1=((id . "1234@fakebank")
26 | (label . "Fake account 1")
27 | (currency . "EUR")
28 | (iban . "1234")
29 | (type . 1)
30 | (balance . "400"))
31 |
32 | #2=((id . "1235@fakebank")
33 | (label . "Fake account 2")
34 | (currency . "EUR")
35 | (iban . "1235")
36 | (type . 1)
37 | (balance . "50"))])
38 | (transactions . (((id . "@fakebank")
39 | (date . "2017-11-24")
40 | (rdate . "2017-11-24")
41 | (type . 1)
42 | (raw . "CB Supermarket 1")
43 | (label . "CB Supermarket 1")
44 | (amount . "-124.00")
45 | (account . #1#))
46 | ((id . "@fakebank")
47 | (date . "2017-11-20")
48 | (rdate . "2017-11-20")
49 | (type . 1)
50 | (label . "Paycheck")
51 | (raw . "Transfer company XX paycheck")
52 | (amount . "2300.00")
53 | (account . #1#))
54 | ((id . "@fakebank")
55 | (date . "2017-11-20")
56 | (rdate . "2017-11-20")
57 | (type . 1)
58 | (raw . "Bakery xxx")
59 | (label . "Bakery xxx")
60 | (amount . "-4.25")
61 | (account . #1#))
62 | ((id . "@fakebank")
63 | (date . "2017-11-18")
64 | (rdate . "2017-11-18")
65 | (type . 1)
66 | (raw . "CB Restaurant")
67 | (label . "CB Restaurant")
68 | (amount . "-31.00")
69 | (account . #1#))
70 | ((id . "@fakebank")
71 | (date . "2017-11-01")
72 | (rdate . "2017-11-01")
73 | (type . 1)
74 | (label . "Rent")
75 | (raw . "Rent November 2017")
76 | (amount . "-450.00")
77 | (account . #1#))))))
78 |
79 | (setq real-elbank-categories elbank-categories)
80 | (setq elbank-categories '(("Expenses:Food" . ("supermarket"
81 | "restaurant"
82 | "Local store"
83 | "Bakery"))
84 | ("Expenses:Rent" . ("rent"))
85 | ("Income:Salary" . ("company xx"))))
86 |
87 | (setq real-elbank-budget elbank-budget)
88 | (setq elbank-budget '(("Expenses:Food" . 300)
89 | ("Expenses:Rent" . 450))))
90 |
91 | (Before
92 | ;; Before each scenario is run
93 | )
94 |
95 | (After
96 | ;; After each scenario is run
97 | )
98 |
99 | (Teardown
100 | ;; After when everything has been run
101 | (setq elbank-data real-elbank-data)
102 | (setq elbank-categories real-elbank-categories)
103 | (setq elbank-budget real-elbank-budget)
104 | (when-let ((buf (get-buffer "*elbank-report*")))
105 | (kill-buffer buf)))
106 |
--------------------------------------------------------------------------------
/features/support/test-helper.el:
--------------------------------------------------------------------------------
1 | ;; Temporary fix for https://github.com/ecukes/ecukes/issues/170
2 | (when (require 'cl-preloaded nil t)
3 | (setf (symbol-function 'cl--assertion-failed)
4 | (lambda (form &optional string sargs args)
5 | "Fake version"
6 | ;; (if debug-on-error
7 | ;; (apply debugger `(cl-assertion-failed ,form ,string ,@sargs))
8 | (if string
9 | (apply #'error string (append sargs args))
10 | (signal 'cl-assertion-failed `(,form ,@sargs))))))
11 |
--------------------------------------------------------------------------------
/run-tests.sh:
--------------------------------------------------------------------------------
1 | #!/bin/sh -e
2 | cask exec ecukes "$@"
3 | cask exec buttercup -l features/support/test-helper.el -L . "$@"
4 |
--------------------------------------------------------------------------------
/screenshots/budget-report.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicolasPetton/elbank/fa9bc7dec0a8fd489e90b9f178719344cc8d315a/screenshots/budget-report.png
--------------------------------------------------------------------------------
/screenshots/overview.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicolasPetton/elbank/fa9bc7dec0a8fd489e90b9f178719344cc8d315a/screenshots/overview.png
--------------------------------------------------------------------------------
/screenshots/report-example.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicolasPetton/elbank/fa9bc7dec0a8fd489e90b9f178719344cc8d315a/screenshots/report-example.png
--------------------------------------------------------------------------------
/screenshots/transaction-details.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/NicolasPetton/elbank/fa9bc7dec0a8fd489e90b9f178719344cc8d315a/screenshots/transaction-details.png
--------------------------------------------------------------------------------
/test/elbank-boobank-test.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-boobank-test.el --- Tests for elbank-boobank.el
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 |
7 | ;; This file is not part of GNU Emacs.
8 |
9 | ;; This program is free software: you can redistribute it and/or modify
10 | ;; it under the terms of the GNU General Public License as published by
11 | ;; the Free Software Foundation, either version 3 of the License, or
12 | ;; (at your option) any later version.
13 |
14 | ;; This program is distributed in the hope that it will be useful,
15 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | ;; GNU General Public License for more details.
18 |
19 | ;; You should have received a copy of the GNU General Public License
20 | ;; along with this program. If not, see .
21 |
22 | ;;; Commentary:
23 |
24 | ;; Tests for elbank-boobank.el
25 |
26 | ;;; Code:
27 |
28 | (require 'buttercup)
29 | (require 'map)
30 | (require 'seq)
31 | (require 'cl-lib)
32 | (require 'elbank-boobank)
33 |
34 | (describe "Merging data"
35 | (it "should append new transactions and keep old ones"
36 | (let* ((account '((id . "account1")
37 | (label . "account 1")))
38 | (elbank-data `((accounts . (,account))
39 | (transactions . (((label . "1") (account . ,account))
40 | ((label . "2") (account . ,account))
41 | ((label . "3") (account . ,account))))))
42 | (new-transactions `(((label . "4") (account . ,account))
43 | ((label . "5") (account . ,account))))
44 | (merged (elbank-boobank--merge-transactions new-transactions)))
45 | (expect (seq-map (lambda (tr) (map-elt tr 'label))
46 | merged)
47 | :to-equal '("1" "2" "3" "4" "5"))))
48 |
49 | (it "should keep existing accounts when merging accounts"
50 | (let* ((old-accounts '(((id . "1"))
51 | ((id . "2"))))
52 | (elbank-data `((accounts . ,old-accounts)))
53 | (new-accounts '(((id . "1"))
54 | ((id . "3"))))
55 | (merged (elbank-boobank--merge-accounts new-accounts)))
56 | (expect (seq-length merged) :to-be 3)
57 | (expect (car merged) :to-be (car old-accounts))
58 | (expect (cadr merged) :to-be (cadr old-accounts))
59 | (expect (cl-caddr merged) :to-be (cadr new-accounts))))
60 |
61 | (it "should not duplicate accounts when there are new fields"
62 | (let* ((old '(((id . "1") (foo "old"))))
63 | (new '(((id . "1") (foo "old") (bar "new"))))
64 | (elbank-data `((accounts . ,old)))
65 | (merged (elbank-boobank--merge-accounts new)))
66 | (expect (seq-length merged) :to-be 1)
67 | (expect (car merged) :to-be (car old))))
68 |
69 | (it "merging accounts should update current accounts values"
70 | (let* ((old '(((id . "1") (balance . "3000"))))
71 | (new '(((id . "1") (balance . "3500"))))
72 | (elbank-data `((accounts . ,old)))
73 | (merged (elbank-boobank--merge-accounts new)))
74 | (expect (seq-length merged) :to-be 1)
75 | (expect (map-elt (car merged) 'balance) :to-equal "3500")))
76 |
77 | (it "should deduplicate new transactions"
78 | (let* ((old '(((label . "1"))
79 | ((label . "2"))
80 | ((label . "3"))
81 | ((label . "3"))))
82 | (new '(((label . "2"))
83 | ((label . "3"))
84 | ((label . "3"))
85 | ((label . "3"))
86 | ((label . "3"))))
87 | (elbank-data `((transactions . ,old)))
88 | (merged (elbank-boobank--merge-transactions new)))
89 | (expect (seq-map (lambda (tr) (map-elt tr 'label))
90 | merged)
91 | :to-equal '("1" "2" "3" "3" "3" "3"))))
92 |
93 | (it "should ignore custom labels when deduplicating"
94 | (let* ((old '(((label . "1"))
95 | ((label . "2"))
96 | ((label . "3") (custom-label . "a"))
97 | ((label . "3") (custom-label . "b"))))
98 | (new '(((label . "2"))
99 | ((label . "3"))
100 | ((label . "3"))
101 | ((label . "3"))
102 | ((label . "3"))))
103 | (elbank-data `((transactions . ,old)))
104 | (merged (elbank-boobank--merge-transactions new)))
105 | (expect (seq-map (lambda (tr) (map-elt tr 'label))
106 | merged)
107 | :to-equal '("1" "2" "3" "3" "3" "3"))))
108 |
109 | (it "should ignore categories when deduplicating"
110 | (let* ((elbank-data `((accounts . (((id . "account1") (label . "account 1"))))
111 | (transactions . (((label . "1"))
112 | ((label . "2"))
113 | ((label . "3") (category . "foo"))
114 | ((label . "3") (category . "bar"))))))
115 | (new-transactions '(((label . "2"))
116 | ((label . "3"))
117 | ((label . "3"))
118 | ((label . "3"))
119 | ((label . "3"))))
120 | (merged (elbank-boobank--merge-transactions new-transactions)))
121 | (expect (seq-map (lambda (tr) (map-elt tr 'label))
122 | merged)
123 | :to-equal '("1" "2" "3" "3" "3" "3"))))
124 |
125 | (it "should ignore alist elements order deduplicating"
126 | (let* ((elbank-data `((transactions . (((label . "1") (amount . "10"))
127 | ((label . "2") (amount . "20"))
128 | ((amount . "15") (label . "3"))
129 | ((label . "3"))))))
130 | (new `((transactions . (((amount . "20") (label . "2"))
131 | ((amount . "15") (label . "3"))
132 | ((label . "3"))
133 | ((label . "3"))))))
134 | (merged (elbank-boobank--merge-transactions new)))
135 | (expect (seq-map (lambda (tr) (map-elt tr 'label))
136 | merged)
137 | :to-equal '("1" "2" "3" "3"))))
138 |
139 | (it "should fail to make transactions when the account is not in `elbank-data'"
140 | (let ((elbank-data '((accounts . '((id . "account1") (label . "account 1")))))
141 | (new-account '((id . "account1") (label . "account 1"))))
142 | (expect (elbank-boobank--make-transaction `((amount . "3000")) new-account) :to-throw))))
143 |
144 | (provide 'elbank-boobank-test)
145 | ;;; elbank-boobank-test.el ends here
146 |
--------------------------------------------------------------------------------
/test/elbank-common-test.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-common-test.el --- Unit tests for elbank-common.el -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 | ;; Keywords: test
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 | ;; Tests for elbank-common.el
24 |
25 | ;;; Code:
26 |
27 | (require 'buttercup)
28 | (require 'map)
29 | (require 'elbank-common)
30 |
31 | (describe "Transaction elements"
32 | (it "should access transactions element"
33 | (let ((tr '((amount . "2000")
34 | (category . "Expenses"))))
35 | (expect (elbank-transaction-elt tr 'amount) :to-equal "2000")
36 | (expect (elbank-transaction-elt tr 'category) :to-equal "Expenses")))
37 |
38 | (it "should set transactions element"
39 | (let ((tr '((amount . "2000")
40 | (category . "Expenses"))))
41 | (setf (elbank-transaction-elt tr 'amount) "-1500")
42 | (setf (elbank-transaction-elt tr 'category) "Income")
43 | (expect (elbank-transaction-elt tr 'amount) :to-equal "-1500")
44 | (expect (elbank-transaction-elt tr 'category) :to-equal "Income")))
45 |
46 | (it "should mutate transactions in place when adding new keys"
47 | (let* ((original '((amount . "2000")))
48 | (tr original))
49 | (setf (elbank-transaction-elt tr 'category) "Income")
50 | (expect (elbank-transaction-elt tr 'category) :to-equal "Income")
51 | (expect original :to-be tr)))
52 |
53 | (it "split transactions should have no category"
54 | (let ((tr '((category . (("foo" . 20) ("bar" . 10))))))
55 | (expect (elbank-transaction-elt tr 'category) :to-be nil)
56 | (expect (elbank-transaction-in-category-p tr "foo") :to-be nil)
57 | (expect (elbank-transaction-in-category-p tr "bar") :to-be nil)))
58 |
59 | (it "transactions with multiple categories should be split."
60 | (let ((tr1 '((category . (("foo" . 20) ("bar" . 10)))))
61 | (tr2 '((category . "foo"))))
62 | (expect (elbank-transaction-split-p tr1) :to-be-truthy)
63 | (expect (elbank-transaction-split-p tr2) :to-be nil)))
64 |
65 | (describe "when asked for label"
66 | (it "returns label if present"
67 | (let ((tr '((label . "foo"))))
68 | (expect (elbank-transaction-elt tr 'label) :to-equal "foo")))))
69 |
70 | (provide 'elbank-common-test)
71 | ;;; elbank-common-test.el ends here
72 |
--------------------------------------------------------------------------------
/test/elbank-report-test.el:
--------------------------------------------------------------------------------
1 | ;;; elbank-report-test.el --- Unit tests for elbank-report.el -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 | ;; Keywords: test
7 |
8 | ;; This program is free software; you can redistribute it and/or modify
9 | ;; it under the terms of the GNU General Public License as published by
10 | ;; the Free Software Foundation, either version 3 of the License, or
11 | ;; (at your option) any later version.
12 |
13 | ;; This program is distributed in the hope that it will be useful,
14 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 | ;; GNU General Public License for more details.
17 |
18 | ;; You should have received a copy of the GNU General Public License
19 | ;; along with this program. If not, see .
20 |
21 | ;;; Commentary:
22 |
23 | ;; Tests for elbank-report.el
24 |
25 | ;;; Code:
26 |
27 | (require 'buttercup)
28 | (require 'elbank-report)
29 |
30 | (describe "Splitting transaction"
31 | (spy-on 'elbank-report-set-category)
32 | (spy-on 'elbank-report--split-amount :and-return-value '(("foo" . "1500") ("bar" . "500")))
33 |
34 | (describe "should split a non-splitted transaction"
35 | (it "with a category"
36 | (let* ((transaction '((amount . "2000") (category . "Expenses"))))
37 | (elbank-report-split-transaction transaction)
38 | (expect 'elbank-report-set-category
39 | :to-have-been-called-with '(("foo" . "1500") ("bar" . "500")) transaction)))
40 |
41 | (it "with no category"
42 | (let* ((transaction '((amount . "2000"))))
43 | (elbank-report-split-transaction transaction)
44 | (expect 'elbank-report-set-category
45 | :to-have-been-called-with '(("foo" . "1500") ("bar" . "500")) transaction))))
46 |
47 | (describe "should split a sub-transaction"
48 | (it "with different categories"
49 | (let* ((main-transaction '((amount . "3000")
50 | (category . (("cat1" . "1000") ("cat2" . "2000")))))
51 | (sub-transaction `((amount . "2000")
52 | (category . "cat2")
53 | (split-from . ,main-transaction))))
54 | (elbank-report-split-transaction sub-transaction)
55 | (expect 'elbank-report-set-category
56 | :to-have-been-called-with '(("cat1" . "1000")
57 | ("foo" . "1500")
58 | ("bar" . "500")) main-transaction))))
59 |
60 | (it "with 2 identical sub-transactions"
61 | (let* ((main-transaction '((amount . "4000")
62 | (category . (("cat1" . "2000") ("cat1" . "2000")))))
63 | (sub-transaction `((amount . "2000")
64 | (category . "cat1")
65 | (split-from . ,main-transaction))))
66 | (elbank-report-split-transaction sub-transaction)
67 | (expect 'elbank-report-set-category
68 | :to-have-been-called-with '(("cat1" . "2000")
69 | ("foo" . "1500")
70 | ("bar" . "500")) main-transaction))))
71 | (describe "Representing transaction"
72 | (it "with a nil label"
73 | (expect (elbank-report--cell '((label)) 'label) :to-equal "")))
74 |
75 | (provide 'elbank-report-test)
76 | ;;; elbank-report-test.el ends here
77 |
--------------------------------------------------------------------------------
/test/test-helper.el:
--------------------------------------------------------------------------------
1 | ;;; test-helper.el --- Helper functions to test elbank -*- lexical-binding: t; -*-
2 |
3 | ;; Copyright (C) 2017-2018 Nicolas Petton
4 |
5 | ;; Author: Nicolas Petton
6 |
7 | ;; This program is free software; you can redistribute it and/or modify
8 | ;; it under the terms of the GNU General Public License as published by
9 | ;; the Free Software Foundation, either version 3 of the License, or
10 | ;; (at your option) any later version.
11 |
12 | ;; This program is distributed in the hope that it will be useful,
13 | ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | ;; GNU General Public License for more details.
16 |
17 | ;; You should have received a copy of the GNU General Public License
18 | ;; along with this program. If not, see .
19 |
20 | ;;; Commentary:
21 |
22 | ;;
23 |
24 | ;;; Code:
25 |
26 | (declare-function undercover "undercover")
27 |
28 | (when (require 'undercover nil t)
29 | (undercover "elbank.el"))
30 |
31 | ;;; test-helper.el ends here
32 |
--------------------------------------------------------------------------------