Merge branch 'show-work-hours-on-dashboard' into 'master'
Show work hours on dashboard See merge request saburly/gangsta/roraccounting!20
This commit was merged in pull request #20.
This commit is contained in:
@@ -21,9 +21,9 @@ class HomiesController < ApplicationController
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def cash
|
def info
|
||||||
importance = params[:importance].present? ? params[:importance].to_i : -1
|
importance = params[:importance].present? ? params[:importance].to_i : -1
|
||||||
json_response(Homie.cash(importance))
|
json_response(Homie.info(importance))
|
||||||
end
|
end
|
||||||
|
|
||||||
def settle
|
def settle
|
||||||
@@ -32,7 +32,7 @@ class HomiesController < ApplicationController
|
|||||||
homie = Homie.find(homie_id)
|
homie = Homie.find(homie_id)
|
||||||
|
|
||||||
if homie.settle(amount)
|
if homie.settle(amount)
|
||||||
cash
|
info
|
||||||
else
|
else
|
||||||
error_response :bad_request
|
error_response :bad_request
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -3,12 +3,14 @@ class Homie < ApplicationRecord
|
|||||||
has_many :work
|
has_many :work
|
||||||
belongs_to :chip
|
belongs_to :chip
|
||||||
|
|
||||||
def self.cash(importance)
|
def self.info(importance)
|
||||||
totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount)
|
cash_totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount)
|
||||||
|
work_totals = Homie.all.joins(:work).group(:id).order(:id).sum(:amount)
|
||||||
|
|
||||||
Homie.where(["importance > ?", importance]).map do |homie|
|
Homie.where(["importance > ?", importance]).map do |homie|
|
||||||
total = totals.fetch(homie.id, 0)
|
cash_total = cash_totals.fetch(homie.id, 0)
|
||||||
{ homie: homie, amount: total }
|
work_total = work_totals.fetch(homie.id, 0)
|
||||||
|
{ homie: homie, amount: cash_total, work: work_total }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import './Cash.css';
|
|||||||
import axios from 'axios';
|
import axios from 'axios';
|
||||||
import { MAKE_MONEY_MOVE } from '../RouteNames';
|
import { MAKE_MONEY_MOVE } from '../RouteNames';
|
||||||
import { withRouter } from 'react-router-dom';
|
import { withRouter } from 'react-router-dom';
|
||||||
import { formatMoney } from '../common/formatting';
|
import { formatMoney, formatTime } from '../common/formatting';
|
||||||
import InputModal from "../common/InputModal";
|
import InputModal from "../common/InputModal";
|
||||||
import { errorToast } from "../common/errorHelpers";
|
import { errorToast } from "../common/errorHelpers";
|
||||||
import M from 'materialize-css';
|
import M from 'materialize-css';
|
||||||
@@ -16,7 +16,7 @@ const Cash = (props) => {
|
|||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
const getCashForHomies = async () => {
|
const getCashForHomies = async () => {
|
||||||
try {
|
try {
|
||||||
const cash = await axios.get(`/api/homies/cash`);
|
const cash = await axios.get(`/api/homies/info`);
|
||||||
setHomiesCash(cash.data);
|
setHomiesCash(cash.data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Error fetching", e);
|
console.log("Error fetching", e);
|
||||||
@@ -45,6 +45,9 @@ const Cash = (props) => {
|
|||||||
<td className="cash-cell-left">
|
<td className="cash-cell-left">
|
||||||
<a href={`/homie/${homieLine.homie.id}/flow`}>{ homieLine.homie.name }</a>
|
<a href={`/homie/${homieLine.homie.id}/flow`}>{ homieLine.homie.name }</a>
|
||||||
</td>
|
</td>
|
||||||
|
<td className="cash-cell-left">
|
||||||
|
{ formatTime(homieLine.work) }
|
||||||
|
</td>
|
||||||
<td className="cash-cell-right">
|
<td className="cash-cell-right">
|
||||||
{ formatMoney(homieLine.amount) }
|
{ formatMoney(homieLine.amount) }
|
||||||
</td>
|
</td>
|
||||||
@@ -71,6 +74,9 @@ const Cash = (props) => {
|
|||||||
<th>
|
<th>
|
||||||
Homie
|
Homie
|
||||||
</th>
|
</th>
|
||||||
|
<th>
|
||||||
|
Work
|
||||||
|
</th>
|
||||||
<th>
|
<th>
|
||||||
Cash
|
Cash
|
||||||
</th>
|
</th>
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ const MakeMoneyMove = (props) => {
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const getCashForHomies = async () => {
|
const getCashForHomies = async () => {
|
||||||
try {
|
try {
|
||||||
const cash = await axios.get(`/api/homies/cash`);
|
const cash = await axios.get(`/api/homies/info`);
|
||||||
setHomiesCash(cash.data);
|
setHomiesCash(cash.data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.log("Error fetching", e);
|
console.log("Error fetching", e);
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ Rails.application.routes.draw do
|
|||||||
resources :chip_values, only: %i[create update destroy]
|
resources :chip_values, only: %i[create update destroy]
|
||||||
resources :homies, param: :homie_id do
|
resources :homies, param: :homie_id do
|
||||||
collection do
|
collection do
|
||||||
get 'cash'
|
get 'info'
|
||||||
end
|
end
|
||||||
member do
|
member do
|
||||||
post 'settle'
|
post 'settle'
|
||||||
|
|||||||
Reference in New Issue
Block a user