diff --git a/api.go b/api.go
index c51b370..a5571fb 100644
--- a/api.go
+++ b/api.go
@@ -62,16 +62,17 @@ func getTransactions(w http.ResponseWriter, req *http.Request) {
}
}
-func newTransaction(w http.ResponseWriter, req *http.Request) {
- decoder := json.NewDecoder(req.Body)
- var t types.Transaction
- err := decoder.Decode(&t)
- if err != nil {
- log.Fatal().
- Err(err).
- Msg("Could not decode incoming post data")
- }
+func HandleNewTransaction(w http.ResponseWriter, req *http.Request) {
+ log.Fatal().Msg("TODO: new transaction functionality not implemented yet");
+ // decoder := json.NewDecoder(req.Body)
+ // var t types.Transaction
+ // err := decoder.Decode(&t)
+ // if err != nil {
+ // log.Fatal().
+ // Err(err).
+ // Msg("Could not decode incoming post data")
+ // }
//fmt.Fprintf(w, "New transaction created for Account: %d, with an Amount of: %s",
// t.Account, t.Amount)
- db.NewTransaction(t)
+ // db.NewTransaction(t)
}
diff --git a/web/router.go b/web/router.go
index b5e4462..a443972 100644
--- a/web/router.go
+++ b/web/router.go
@@ -34,6 +34,7 @@ func WebRouter() http.Handler {
r := chi.NewRouter()
r.Get("/", getDashboard)
r.Get("/transactions", getTransactionsPage)
+ r.Post("/submitTransaction", HandleNewTransaction);
r.Get("/components/account_summaries", GetAccountSummaries)
diff --git a/web/static/new_transactions.js b/web/static/new_transactions.js
index 54d501b..a10a81d 100644
--- a/web/static/new_transactions.js
+++ b/web/static/new_transactions.js
@@ -95,7 +95,9 @@ function add_new_breakdown() {
document.getElementById("breakdown-tbody").appendChild(source);
}
-function insert_tax() {
+function insert_tax(event) {
+ event.target.parentNode.classList.remove("c-green");
+ event.target.parentNode.classList.add("c-overlay2");
if (document.getElementById("tax-input")) return;
let source = document.importNode(document.getElementById("breakdown-template-row").content, true);
source.querySelector("input[type='text']").value = "Tax";
@@ -103,13 +105,36 @@ function insert_tax() {
let table_body = document.getElementById("breakdown-tbody");
table_body.insertBefore(source, table_body.firstChild);
- // on_input();
+
+ // calculate the the tax and final amount
+ on_input({target: {id: "amount-entry"}});
+}
+
+function submit_form(event) {
+ event.preventDefault(); // Prevent the default form submission
+
+ // Your custom submission handling code here
+
+ // For example, you might want to send the form data using AJAX
+ var formData = new FormData(this);
+ fetch('/submitTransaction', {
+ method: 'POST',
+ body: formData
+ })
+ .then(_ => {
+ alert("form submitted");
+ })
+ .catch(error => {
+ console.log("Form submission error:\n" + error);
+ alert("There was an issue submitting the form");
+ });
}
function register_breakdown_handlers() {
document.getElementById("amount-entry").addEventListener("input", on_input);
document.getElementById("new-breakdown-btn").addEventListener("click", add_new_breakdown);
document.getElementById("tax-breakdown-btn").addEventListener("click", insert_tax);
+ document.getElementById("new-transaction-form").addEventListener("submit", submit_form);
}
export {open_new_transaction_pane, close_new_transaction_pane, register_breakdown_handlers}
diff --git a/web/templates/new_transaction_pane.templ b/web/templates/new_transaction_pane.templ
index 7115ace..44f2cee 100644
--- a/web/templates/new_transaction_pane.templ
+++ b/web/templates/new_transaction_pane.templ
@@ -20,94 +20,96 @@ templ NewTransactionPane(entry_types *[]types.QuickTransactionType, acnts *[]typ
-
-
New Transaction
-
-
-
-
- for _, value := range *entry_types {
-
- }
-
-
-
-
-
-
-
+
+
+ for _, value := range *entry_types {
+
+ }
-
-
-
-
-
-
-
-
- Tag:
-
-
-
-
-
-
Breakdown
-
-
-
-
-
-
- |
- Bucket |
- Description |
- Amount |
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
-
-
+
+ Tag:
+
+
+
+
+
+
Breakdown
+
+
+ New
+
+
+
+ Tax
+
+
+
+
+
+
+
+ |
+ Bucket |
+ Description |
+ Amount |
+
+
+
+
+
+
+
-
+
}