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,94 +20,96 @@ 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">
<div class="my-2 d-flex"> <form method="POST" id="new-transaction-form">
<h2 class="ms-5">New Transaction</h2> <div class="my-2 d-flex">
<button class="ms-auto me-4 my-auto exit-btn" id="close-transaction-pane"> <h2 class="ms-5">New Transaction</h2>
<i class="my-auto" data-feather="x"></i> <button class="ms-auto me-4 my-auto exit-btn" id="close-transaction-pane">
</button> <i class="my-auto" data-feather="x"></i>
</div>
<div class="d-flex">
<div class="d-flex ms-5" style="overflow-x: scroll; width: 90%;">
for _, value := range *entry_types {
<button class="borderless-btn btn-sm mx-3">
{value.DisplayName}
</button>
}
</div>
<div class="d-flex" style="width:10%">
<button class="btn-sm my-auto ms-auto me-4 d-flex invert c-green">
<i class="my-2" data-feather="save"></i>
<span class="my-auto ms-2">Save</span>
</button> </button>
</div> </div>
</div> <div class="d-flex">
<div class="c-mantle cr-all m-5 container" style="height: 85%;"> <div class="d-flex ms-5" style="overflow-x: scroll; width: 90%;">
<div class="row mt-5"> for _, value := range *entry_types {
<div class="p-5 mx-auto"> <button class="borderless-btn btn-sm mx-3">
<label for="acnt-entry-selection" id="acnt-entry-label"> {value.DisplayName}
Account: </button>
</label> }
<select class="ms-2 select border" id="acnt-entry-selection">
for _, value := range *acnts {
<option value={strconv.Itoa(value.Id)}>{value.DisplayName.String}</option>
}
</select>
</div> </div>
<div class="p-5 mx-auto" style="height: fit-content;"> <div class="d-flex" style="width:10%">
<label> <button type="submit" class="btn-sm my-auto ms-auto me-4 d-flex invert c-green">
Date: <i class="my-2" data-feather="save"></i>
<input class="input" id="date-entry" type="date" /> <span class="my-auto ms-2">Save</span>
</label>
</div>
<div class="p-5 mx-auto" style="height: fit-content;">
<label>
Amount:
<input class="input" id="amount-entry" type="number" step="any" />
</label>
</div>
<div class="d-flex p-5 mx-auto">
<span class="my-auto">Tag: </span>
<label class="input-sizer">
<input
size="4"
class="input"
id="trans-tab-entry"
type="text"
/>
<span class="d-flex"> <i class="my-auto" style="transform: scale(-1,1);" data-feather="tag"></i> </span>
</label>
</div>
</div>
<div class="row">
<div class="ms-5 d-flex">
<h2 class="my-3">Breakdown</h2>
<button class="btn-sm ms-5 my-auto c-green invert" id="new-breakdown-btn">
<i class="" data-feather="plus"></i>
<span class="my-auto pe-2">New</span>
</button>
<button class="btn-sm ms-5 my-auto c-green invert" id="tax-breakdown-btn">
<i class="" data-feather="plus"></i>
<span class="my-auto pe-2">Tax</span>
</button> </button>
</div> </div>
</div> </div>
<div class="row" style="flex-grow: 1"> <div class="c-mantle cr-all m-5 container" style="height: 85%;">
<table class="table table-striped cr-all" style="width: 100%; border: solid 1px black;"> <div class="row mt-5">
<thead> <div class="p-5 mx-auto">
<tr> <label for="acnt-entry-selection" id="acnt-entry-label">
<td></td> Account:
<td class="py-2">Bucket</td> </label>
<td>Description</td> <select class="ms-2 select border" id="acnt-entry-selection">
<td>Amount</td> for _, value := range *acnts {
</tr> <option value={strconv.Itoa(value.Id)}>{value.DisplayName.String}</option>
</thead> }
<tbody id="breakdown-tbody"> </select>
</div>
<div class="p-5 mx-auto" style="height: fit-content;">
<label>
Date:
<input class="input" id="date-entry" type="date" />
</label>
</div>
<div class="p-5 mx-auto" style="height: fit-content;">
<label>
Amount:
<input class="input" id="amount-entry" type="number" step="any" />
</label>
</div>
</tbody> <div class="d-flex p-5 mx-auto">
</table> <span class="my-auto">Tag: </span>
<label class="input-sizer">
<input
size="4"
class="input"
id="trans-tab-entry"
type="text"
/>
<span class="d-flex"> <i class="my-auto" style="transform: scale(-1,1);" data-feather="tag"></i> </span>
</label>
</div>
</div>
<div class="row">
<div class="ms-5 d-flex">
<h2 class="my-3">Breakdown</h2>
<button type="button" class="btn-sm ms-5 my-auto c-green invert" id="new-breakdown-btn">
<i class="" data-feather="plus"></i>
<span class="my-auto pe-2">New</span>
</button>
<button type="button" class="btn-sm ms-5 my-auto c-green invert" id="tax-breakdown-btn">
<i class="" data-feather="plus"></i>
<span class="my-auto pe-2">Tax</span>
</button>
</div>
</div>
<div class="row" style="flex-grow: 1">
<table class="table table-striped cr-all" style="width: 100%; border: solid 1px black;">
<thead>
<tr>
<td></td>
<td class="py-2">Bucket</td>
<td>Description</td>
<td>Amount</td>
</tr>
</thead>
<tbody id="breakdown-tbody">
</tbody>
</table>
</div>
</div> </div>
</div> </form>
</div> </div>
} }