Add Cash
This commit is contained in:
parent
8a25a5fa82
commit
18814f18e0
5 changed files with 127 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
|||
use leptos::prelude::*;
|
||||
use bkbh_lib::commands::*;
|
||||
use leptos::task::spawn_local;
|
||||
use leptos::web_sys::FormData;
|
||||
use leptos::form::FromFormData;
|
||||
use std::collections::HashMap;
|
||||
|
||||
use bkbh_lib::types::*;
|
||||
|
||||
|
@ -54,6 +57,58 @@ fn StoreInput(store: Store) -> impl IntoView {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
struct Cash(i64);
|
||||
|
||||
impl std::str::FromStr for Cash {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
let split: Vec<&str> = s.split(".").collect();
|
||||
let i = i64::from_str(split.get(0).ok_or(())?)
|
||||
.map_err(|e| println!("{:?}", e))?;
|
||||
let f = match split.get(1) {
|
||||
None => 0,
|
||||
Some(fs) => i64::from_str(
|
||||
&format!("00{}", fs)[0..2]
|
||||
)
|
||||
.map_err(|e| println!("{:?}", e))?,
|
||||
};
|
||||
Ok(Cash(i*100+f))
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn CashInput(value: RwSignal<String>) -> impl IntoView {
|
||||
let txt = "cash";
|
||||
view! {
|
||||
<div
|
||||
class="labelled-input"
|
||||
>
|
||||
<label
|
||||
for=txt.clone()
|
||||
>
|
||||
<img
|
||||
src="assets/cash.svg"
|
||||
class="logo"
|
||||
alt="Bargeld"
|
||||
/>
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
name=txt.clone()
|
||||
id=txt.clone()
|
||||
min=0
|
||||
step=0.01
|
||||
bind:value=value
|
||||
on:change=move |_| {
|
||||
println!("{:?}", value.get());
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn AccRadio(acc: Account) -> impl IntoView {
|
||||
let txt = format!("{}", Into::<String>::into(&acc));
|
||||
|
@ -80,9 +135,28 @@ fn AccRadio(acc: Account) -> impl IntoView {
|
|||
}
|
||||
|
||||
#[component]
|
||||
fn InvForm() -> impl IntoView {
|
||||
fn SubmitButton() -> impl IntoView {
|
||||
view! {
|
||||
<form>
|
||||
<button
|
||||
type="submit"
|
||||
class="shout"
|
||||
>
|
||||
"Senden"
|
||||
</button>
|
||||
}
|
||||
}
|
||||
|
||||
#[component]
|
||||
fn InvForm() -> impl IntoView {
|
||||
let cash = RwSignal::new(String::from("0.00"));
|
||||
view! {
|
||||
<form
|
||||
on:submit=move |ev| {
|
||||
ev.prevent_default();
|
||||
let data = FromFormData::from_event(ev.as_ref()).unwrap();
|
||||
spawn_local(async move {inventory(data).await;});
|
||||
}
|
||||
>
|
||||
<AccRadio acc=Account::Sumpf />
|
||||
<AccRadio acc=Account::Heinersyndikat />
|
||||
<StoreInput store=Store::Aldi />
|
||||
|
@ -90,6 +164,8 @@ fn InvForm() -> impl IntoView {
|
|||
<StoreInput store=Store::Lidl />
|
||||
<StoreInput store=Store::Rewe />
|
||||
<StoreInput store=Store::Tegut />
|
||||
<CashInput value=cash />
|
||||
<SubmitButton />
|
||||
</form>
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
use tauri_sys::Error;
|
||||
use tauri_sys::core::invoke;
|
||||
use crate::types::*;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct Swap {
|
||||
|
@ -11,3 +12,12 @@ pub async fn swap(store: Store, acc: i64) -> Result<(), Error> {
|
|||
let args = Swap { store, acc };
|
||||
invoke("swap", &args).await
|
||||
}
|
||||
|
||||
#[derive(serde::Serialize)]
|
||||
pub struct Inventory {
|
||||
data: HashMap<String, String>,
|
||||
}
|
||||
pub async fn inventory(data: HashMap<String, String>) -> Result<(), Error> {
|
||||
let args = Inventory { data };
|
||||
invoke("inventory", &args).await
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ pub async fn inventory(
|
|||
data: HashMap<String, String>,
|
||||
state: State<'_, Mutex<AppState>>,
|
||||
) -> Result<(), ()> {
|
||||
println!("{:?}", data);
|
||||
let now = Utc::now().timestamp();
|
||||
let state = state.lock().await;
|
||||
let inv = parse_inventory(data)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue