emacs: Add inventory functions
This commit is contained in:
parent
d78b2785fe
commit
05fee51dc8
@ -333,7 +333,58 @@ Return nil if on a link url, markup, html, or references."
|
||||
;; '("\\.m$" . matlab-mode))
|
||||
;; (setq matlab-indent-function t)
|
||||
;; (setq matlab-shell-command "matlab")
|
||||
|
||||
(defun fd-inventory-transfer()
|
||||
(interactive)
|
||||
())
|
||||
#+end_src
|
||||
|
||||
** Inventory
|
||||
#+begin_src emacs-lisp :tangle yes
|
||||
(defun fd-inventory-transfer()
|
||||
(interactive)
|
||||
(fd-inventory-transfer-check-if-valid-table)
|
||||
(let ((location-from (string-trim (org-table-get 1 2)))
|
||||
(location-to (string-trim (org-table-get 1 3)))
|
||||
(item-name (string-trim (org-table-get-field 1))))
|
||||
(let (transfer-amount)
|
||||
(setq transfer-amount (read-number (concat "Transfer from " location-from " to " location-to ": ")))
|
||||
(fd-inventory-transfer-log-transfer transfer-amount item-name location-from location-to)
|
||||
(fd-inventory-transfer-do-transfer transfer-amount)
|
||||
(org-table-align)
|
||||
)))
|
||||
|
||||
(defun fd-inventory-transfer-check-if-valid-table ()
|
||||
(unless (org-at-table-p) (error "You are not inside a table"))
|
||||
(unless (and (string-match-p "^[[:blank:]]*-?[0-9]+[[:blank:]]*$" (org-table-get-field 2))
|
||||
(string-match-p "^[[:blank:]]*-?[0-9]+[[:blank:]]*$" (org-table-get-field 3)))
|
||||
(error "Amounts in table are not numbers"))
|
||||
(if (or (string= "" (org-table-get 1 2))
|
||||
(string= "" (org-table-get 1 3)))
|
||||
(error "No valid table header")))
|
||||
|
||||
(defun fd-inventory-transfer-do-transfer(amount)
|
||||
(let* ((amount-from-location (string-to-number (org-table-get-field 2)))
|
||||
(amount-to-location (string-to-number (org-table-get-field 3)))
|
||||
(amount-from-location-new (- amount-from-location amount))
|
||||
(amount-to-location-new (+ amount-to-location amount)))
|
||||
(progn (org-table-get-field 2 (number-to-string amount-from-location-new))
|
||||
(org-table-get-field 3 (number-to-string amount-to-location-new)))))
|
||||
|
||||
(defun fd-inventory-transfer-log-transfer(amount item-name from-location to-location)
|
||||
(save-excursion
|
||||
(let* ((log-heading-point (or (org-find-exact-headline-in-buffer "Transfer log" nil t)
|
||||
(progn (goto-char (org-table-end))
|
||||
(org-insert-heading)
|
||||
(insert "Transfer log")
|
||||
(point)))))
|
||||
(goto-char log-heading-point)
|
||||
(forward-line)
|
||||
(let ((message (concat "- " (format-time-string "%d.%m.%Y") ": *" (number-to-string amount) "* =" item-name "= from " from-location " to " to-location "\n")))
|
||||
(insert message))
|
||||
)))
|
||||
#+end_src
|
||||
|
||||
** Python
|
||||
#+begin_src emacs-lisp :tangle yes
|
||||
|
||||
|
@ -87,7 +87,7 @@
|
||||
:tools
|
||||
;;ansible
|
||||
biblio ; Writes a PhD for you (citation needed)
|
||||
;;debugger ; FIXME stepping through code, to help you add bugs
|
||||
(debugger +lsp) ; FIXME stepping through code, to help you add bugs
|
||||
;;direnv
|
||||
docker
|
||||
;;editorconfig ; let someone else argue about tabs vs spaces
|
||||
|
Loading…
x
Reference in New Issue
Block a user