;;; moneylog.el --- Provide a way to enter moneylog logs ;; Copyright (C) 2009 Leslie Harlley Watter ;; Author: Leslie Harlley Watter ;; Keywords: ;; This file is free software; you can redistribute it and/or modify ;; it under the terms of the GNU General Public License as published by ;; the Free Software Foundation; either version 3, or (at your option) ;; any later version. ;; This file is distributed in the hope that it will be useful, ;; but WITHOUT ANY WARRANTY; without even the implied warranty of ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ;; GNU General Public License for more details. ;; You should have received a copy of the GNU General Public License ;; along with GNU Emacs; see the file COPYING. If not, write to ;; the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, ;; Boston, MA 02110-1301, USA. ;;; Commentary: ;; This file should be used with moneylog (www.aurelio.net/moneylog) ;;; Code: (defun i-register (&optional tag) "Inserts/format an account record. It should be used with moneylog 2009.08.15 -29.00 bicicleta | Mesa para a bicicleta" (interactive) ;; pre-fills the today variable with today's date (setq today (format-time-string "%Y-%m-%d")) (setq rdata (read-string "Data (2009.06.15): " today )) (unless (equal rdata "") (setq rvalor (read-string "Valor (110.00 ou -110.00): ")) (unless (equal rvalor "") (setq rtags (read-string "Tags (poupanca,visa,ccred): " tag)) (setq rcomentario (read-string "Comentario: ")) (unless (equal rcomentario "") (insert (format "%s\t%s\t%s| %s\n" rdata rvalor rtags rcomentario )) ; )))) (defun i-reg-ccredit (&optional tag) "Inserts/format an account record. It should be used with moneylog 2009.08.15 -29.00 visa | Mesa para a bicicleta" (interactive) ;; pre-fills the today variable with today's date ;; fechamento is the date where the credit card closes it's bills (setq fechamento 7) (setq diaspgtoaposfechamento 10) (setq dia (string-to-number (format-time-string "%d"))) (if (<= dia fechamento) (setq mes (format-time-string "%m")) (setq mes (format "%02d" (% (+ (string-to-number (format-time-string "%m")) 1 ) 12 ))) ) (setq today (format "%s%s-%s" (format-time-string "%Y-") mes (+ fechamento diaspgtoaposfechamento) )) (setq rdata (read-string "Data Vencimento (2009.06.15): " today )) (unless (equal rdata "") (setq rvalor (read-string "Valor (110.00 ou -110.00): ")) (unless (equal rvalor "") (setq rtags (read-string "Tags (ccred): " tag)) (setq bdate (format-time-string "%m.%d")) (setq rdatacompra (read-string "Data compra (mm.dd): " bdate)) (unless (equal rdatacompra "") (setq rcomentario (read-string "Comentario: ")) (unless (equal rcomentario "") (setq atual (point)) (goto-char (point-max)) (goto-char (if (equal (search-backward rdata (point-min) t) nil) atual (search-backward rdata (point-min)) )) (beginning-of-line) (forward-line 2) (insert (format "%s\t%s\t%s| @%s %s\n" rdata rvalor rtags rdatacompra rcomentario )) ; ))))) (defun i-reg-gas () "Inserts/format a gas account record. It should be used with moneylog" (interactive) ;; prefills month variable to be concatenated to default tags (setq fechamento 7) (setq diaspgtoaposfechamento 10) (setq dia (string-to-number (format-time-string "%d"))) (if (<= dia fechamento) (setq mes (format-time-string "%m")) (setq mes (format "%02d" (% (+ (string-to-number (format-time-string "%m")) 1 ) 12 ))) ) ;; here starts the real gas function (setq tiporeg (read-string "tipo Registro (C|I) (Credito/Imediato): ")) (unless (equal tiporeg "") (if (equal tiporeg "C") (i-reg-ccredit (concat (concat "ccred" mes) ", posto, ")) (i-register (concat (concat "ccred" mes) ", posto, ")) ) (setq odomtotal (read-string "Odometro Total: ")) (unless (equal odomtotal "") (setq odomparc (read-string "Odometro Parcial: ")) (unless (equal odomparc "") (setq litabast (read-string "Litros Abastecidos: ")) (unless (equal litabast "") (setq precolitro (read-string "Preço por Litro: ")) (unless (equal precolitro "") (setq kmporlitro (number-to-string (/ (string-to-number odomparc)(string-to-number litabast)))) (setq tipogas (read-string "Tipo ( aditivada / comum ): ")) (unless (equal tipogas "") (backward-char 1) (insert (format " otot}%s} opar(%s) l{%s{ R/l$%s$ km/l _%s_ %s \n" odomtotal odomparc litabast precolitro (substring kmporlitro 0 6) tipogas )) ; ))))))) (defun i-atualiza-dados-dev () "Atualiza os dados no arquivo moneylog.txt em ../moneylog-dev/." (interactive) (goto-char (point-min)) (search-forward "## começo") ; grab the current line (beginning-of-line) (setq myStartPos (line-beginning-position)) (goto-char (point-min)) (search-forward "## fim") ; grab the current line (end-of-line) (setq myEndPos (line-end-position)) ; get the strings between start and end point (setq myStr (buffer-substring myStartPos myEndPos)) ;; (message "%s" myStr) (pop-to-buffer (find-file-noselect "../moneylog-dev/moneylog.txt")) (goto-char (point-min)) (search-forward "## começo") ; grab the current line (beginning-of-line) (setq myStartPos2 (line-beginning-position)) (goto-char (point-min)) (search-forward "## fim") ; grab the current line (end-of-line) (setq myEndPos2 (line-end-position)) ;; delete the region (delete-region myStartPos2 myEndPos2) (goto-char myStartPos2) (insert myStr) (basic-save-buffer) (message "Arquivo Atualizado" ) ) (provide 'moneylog) ;;; moneylog.el ends here