work on the submission

This commit is contained in:
Nickiel12 2024-03-03 20:21:25 -08:00
parent 00a697d1a6
commit 1b352b5ee1
4 changed files with 121 additions and 92 deletions

21
api.go
View file

@ -62,16 +62,17 @@ func getTransactions(w http.ResponseWriter, req *http.Request) {
} }
} }
func newTransaction(w http.ResponseWriter, req *http.Request) { func HandleNewTransaction(w http.ResponseWriter, req *http.Request) {
decoder := json.NewDecoder(req.Body) log.Fatal().Msg("TODO: new transaction functionality not implemented yet");
var t types.Transaction // decoder := json.NewDecoder(req.Body)
err := decoder.Decode(&t) // var t types.Transaction
if err != nil { // err := decoder.Decode(&t)
log.Fatal(). // if err != nil {
Err(err). // log.Fatal().
Msg("Could not decode incoming post data") // Err(err).
} // Msg("Could not decode incoming post data")
// }
//fmt.Fprintf(w, "New transaction created for Account: %d, with an Amount of: %s", //fmt.Fprintf(w, "New transaction created for Account: %d, with an Amount of: %s",
// t.Account, t.Amount) // t.Account, t.Amount)
db.NewTransaction(t) // db.NewTransaction(t)
} }

View file

@ -34,6 +34,7 @@ func WebRouter() http.Handler {
r := chi.NewRouter() r := chi.NewRouter()
r.Get("/", getDashboard) r.Get("/", getDashboard)
r.Get("/transactions", getTransactionsPage) r.Get("/transactions", getTransactionsPage)
r.Post("/submitTransaction", HandleNewTransaction);
r.Get("/components/account_summaries", GetAccountSummaries) r.Get("/components/account_summaries", GetAccountSummaries)

View file

@ -95,7 +95,9 @@ function add_new_breakdown() {
document.getElementById("breakdown-tbody").appendChild(source); 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; if (document.getElementById("tax-input")) return;
let source = document.importNode(document.getElementById("breakdown-template-row").content, true); let source = document.importNode(document.getElementById("breakdown-template-row").content, true);
source.querySelector("input[type='text']").value = "Tax"; source.querySelector("input[type='text']").value = "Tax";
@ -103,13 +105,36 @@ function insert_tax() {
let table_body = document.getElementById("breakdown-tbody"); let table_body = document.getElementById("breakdown-tbody");
table_body.insertBefore(source, table_body.firstChild); 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() { function register_breakdown_handlers() {
document.getElementById("amount-entry").addEventListener("input", on_input); document.getElementById("amount-entry").addEventListener("input", on_input);
document.getElementById("new-breakdown-btn").addEventListener("click", add_new_breakdown); document.getElementById("new-breakdown-btn").addEventListener("click", add_new_breakdown);
document.getElementById("tax-breakdown-btn").addEventListener("click", insert_tax); 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} export {open_new_transaction_pane, close_new_transaction_pane, register_breakdown_handlers}

View file

@ -20,6 +20,7 @@ templ NewTransactionPane(entry_types *[]types.QuickTransactionType, acnts *[]typ
</tr> </tr>
</template> </template>
<div id="new-transaction-pane" style="opacity: 0;" class="cr-all c-base d-flex-col" data-rcnt-taxrate="0.095"> <div id="new-transaction-pane" style="opacity: 0;" class="cr-all c-base d-flex-col" data-rcnt-taxrate="0.095">
<form method="POST" id="new-transaction-form">
<div class="my-2 d-flex"> <div class="my-2 d-flex">
<h2 class="ms-5">New Transaction</h2> <h2 class="ms-5">New Transaction</h2>
<button class="ms-auto me-4 my-auto exit-btn" id="close-transaction-pane"> <button class="ms-auto me-4 my-auto exit-btn" id="close-transaction-pane">
@ -35,7 +36,7 @@ templ NewTransactionPane(entry_types *[]types.QuickTransactionType, acnts *[]typ
} }
</div> </div>
<div class="d-flex" style="width:10%"> <div class="d-flex" style="width:10%">
<button class="btn-sm my-auto ms-auto me-4 d-flex invert c-green"> <button type="submit" class="btn-sm my-auto ms-auto me-4 d-flex invert c-green">
<i class="my-2" data-feather="save"></i> <i class="my-2" data-feather="save"></i>
<span class="my-auto ms-2">Save</span> <span class="my-auto ms-2">Save</span>
</button> </button>
@ -82,11 +83,11 @@ templ NewTransactionPane(entry_types *[]types.QuickTransactionType, acnts *[]typ
<div class="row"> <div class="row">
<div class="ms-5 d-flex"> <div class="ms-5 d-flex">
<h2 class="my-3">Breakdown</h2> <h2 class="my-3">Breakdown</h2>
<button class="btn-sm ms-5 my-auto c-green invert" id="new-breakdown-btn"> <button type="button" class="btn-sm ms-5 my-auto c-green invert" id="new-breakdown-btn">
<i class="" data-feather="plus"></i> <i class="" data-feather="plus"></i>
<span class="my-auto pe-2">New</span> <span class="my-auto pe-2">New</span>
</button> </button>
<button class="btn-sm ms-5 my-auto c-green invert" id="tax-breakdown-btn"> <button type="button" class="btn-sm ms-5 my-auto c-green invert" id="tax-breakdown-btn">
<i class="" data-feather="plus"></i> <i class="" data-feather="plus"></i>
<span class="my-auto pe-2">Tax</span> <span class="my-auto pe-2">Tax</span>
</button> </button>
@ -108,6 +109,7 @@ templ NewTransactionPane(entry_types *[]types.QuickTransactionType, acnts *[]typ
</table> </table>
</div> </div>
</div> </div>
</form>
</div> </div>
} }