diff --git a/app/controllers/chips_controller.rb b/app/controllers/chips_controller.rb index c1c6add..e2a03d1 100644 --- a/app/controllers/chips_controller.rb +++ b/app/controllers/chips_controller.rb @@ -22,7 +22,7 @@ class ChipsController < ApplicationController name: 'Euro', symbol: '€', code: 'EUR', - scale: 3, + scale: 2, prefixed: false } ] diff --git a/app/controllers/homies_controller.rb b/app/controllers/homies_controller.rb index ff64f42..8d5770c 100644 --- a/app/controllers/homies_controller.rb +++ b/app/controllers/homies_controller.rb @@ -35,7 +35,8 @@ class HomiesController < ApplicationController homie = Homie.find(homie_id) if homie.settle(amount) - info + money_moves = MoneyMove.where(homie_id: params[:homie_id].to_i).all.order(created_at: :desc) + json_response money_moves else error_response :bad_request end diff --git a/client/src/App.js b/client/src/App.js index 8f50db0..81566dd 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -79,7 +79,7 @@ const App = (props) => { const navbarLogoWithGang = (
- GKS + GKS { const [homiesCash, setHomiesCash] = useState([]); @@ -25,25 +23,11 @@ const Cash = (props) => { getCashForHomies(); }, []); - const settleFlowForHomie = async (id, amountToSettle) => { - try { - const response = await axios.post(`/api/gangs/${gang.id}/homies/${id}/settle`, { amount: amountToSettle }); - if (response.status === 200 && response.data) { - M.toast({ html: 'Settled' }); - setHomiesCash(response.data); - }else{ - errorToast(); - } - } catch(e) { - errorToast(); - } - } - const cashTableBody = homiesCash.map( (homieLine) => { return ( - { homieLine.homie.name } + {homieLine.homie.name} { formatTime(homieLine.work) } @@ -52,15 +36,6 @@ const Cash = (props) => { { formatMoney(homieLine.amount, gang) } - [ - settleFlowForHomie(homieLine.homie.id, settleAmount)} - triggerNode={Settle} - /> - ] ); diff --git a/client/src/common/InputModal.js b/client/src/common/InputModal.js index 48df526..dae5eaf 100644 --- a/client/src/common/InputModal.js +++ b/client/src/common/InputModal.js @@ -40,7 +40,7 @@ const InputModal = (props) => {

{body}


- +
diff --git a/client/src/homies/CashFlow.js b/client/src/homies/CashFlow.js index c71a229..8c924a4 100644 --- a/client/src/homies/CashFlow.js +++ b/client/src/homies/CashFlow.js @@ -4,19 +4,28 @@ import axios from "axios"; import './Flow.css'; import { formatMoney, timestampToDate } from "../common/formatting"; import {errorToast} from "../common/errorHelpers"; +import InputModal from "../common/InputModal"; +import M from "materialize-css"; +import { Button } from 'react-materialize'; const CashFlow = (props) => { const { homie_id } = useParams(); const gang = props.gang; const [cashFlow, setCashFlow] = useState([]); + const [totalCashFlowAmount, setTotalCashFlowAmount] = useState(0); + + const updateData = (data) => { + setCashFlow(data); + setTotalCashFlowAmount(data.reduce((sum, record) => sum + parseInt(record.amount), 0)); + } useEffect( () => { (async () => { try { const response = await axios.get(`/api/money_moves?homie_id=${parseInt(homie_id)}`); if (response.status === 200 && response.data){ - setCashFlow(response.data); + updateData(response.data); } } catch (e) { errorToast(); @@ -45,7 +54,6 @@ const CashFlow = (props) => { const totalCount = cashFlow.length; const firstFlowRow = totalCount > 0 ? cashFlow[0] : undefined; const lastFlowRow = totalCount > 0 ? cashFlow[cashFlow.length - 1] : undefined; - const totalFlow = cashFlow.reduce((sum, record) => sum + parseInt(record.amount), 0); const fromDate = lastFlowRow ? timestampToDate(lastFlowRow['created_at']) : ''; const toDate = firstFlowRow ? timestampToDate(firstFlowRow['created_at']) : ''; @@ -58,19 +66,43 @@ const CashFlow = (props) => { {`${totalCount} Records`}{` • ${fromDate} - ${toDate}`}
- Total cash flow: {formatMoney(totalFlow, gang)} + Total cash flow: {formatMoney(totalCashFlowAmount, gang)}
) } + const settleFlowForHomie = async (id, amountToSettle) => { + try { + const response = await axios.post(`/api/gangs/${gang.id}/homies/${id}/settle`, { amount: amountToSettle }); + if (response.status === 200 && response.data) { + M.toast({ html: 'Settled' }); + updateData(response.data); + }else{ + errorToast(); + } + } catch(e) { + errorToast(); + } + } + return (
{ totalStats() } + +
+ + settleFlowForHomie(homie_id, settleAmount)} + triggerNode={} + />
); }