Merge branch 'add-money-move-soft-delete' into 'master'
Add money move soft delete See merge request saburly/gangsta/roraccounting!30
This commit was merged in pull request #30.
This commit is contained in:
@@ -22,6 +22,14 @@ class MoneyMovesController < ApplicationController
|
|||||||
error_response(:bad_request)
|
error_response(:bad_request)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
money_move = MoneyMove.find(params[:id])
|
||||||
|
money_move.update!(deleted_at: DateTime.now)
|
||||||
|
index
|
||||||
|
rescue StandardError
|
||||||
|
error_response :bad_request
|
||||||
|
end
|
||||||
|
|
||||||
def money_move_params
|
def money_move_params
|
||||||
params.require(:money_move).permit(
|
params.require(:money_move).permit(
|
||||||
:description,
|
:description,
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ class Homie < ApplicationRecord
|
|||||||
def self.info(importance, gang)
|
def self.info(importance, gang)
|
||||||
# TODO: This can be improved
|
# TODO: This can be improved
|
||||||
|
|
||||||
cash_totals = Homie.all.joins(:money_moves).group(:id).order(:id).sum(:amount)
|
cash_totals = Homie.all.joins(:money_moves).where(money_moves: { deleted_at: nil}).group(:id).order(:id).sum(:amount)
|
||||||
work_totals = Homie.all.joins(:work).group(:id).order(:id).sum(:amount)
|
work_totals = Homie.all.joins(:work).group(:id).order(:id).sum(:amount)
|
||||||
|
|
||||||
Homie.where(['importance > ? and gang_id = ?', importance, gang]).map do |homie|
|
Homie.where(['importance > ? and gang_id = ?', importance, gang]).map do |homie|
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import {errorToast} from "../common/errorHelpers";
|
|||||||
import InputModal from "../common/InputModal";
|
import InputModal from "../common/InputModal";
|
||||||
import M from "materialize-css";
|
import M from "materialize-css";
|
||||||
import { Button } from 'react-materialize';
|
import { Button } from 'react-materialize';
|
||||||
|
import YesNoModal from "../common/YesNoModal";
|
||||||
|
|
||||||
const CashFlow = (props) => {
|
const CashFlow = (props) => {
|
||||||
const { homie_id } = useParams();
|
const { homie_id } = useParams();
|
||||||
@@ -17,13 +18,16 @@ const CashFlow = (props) => {
|
|||||||
|
|
||||||
const updateData = (data) => {
|
const updateData = (data) => {
|
||||||
setCashFlow(data);
|
setCashFlow(data);
|
||||||
setTotalCashFlowAmount(data.reduce((sum, record) => sum + parseInt(record.amount), 0));
|
setTotalCashFlowAmount(data.reduce((sum, record) => {
|
||||||
|
const amountToAdd = record.deleted_at ? 0 : parseInt(record.amount);
|
||||||
|
return sum + amountToAdd;
|
||||||
|
}, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect( () => {
|
useEffect( () => {
|
||||||
(async () => {
|
(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.get(`/api/money_moves?homie_id=${parseInt(homie_id)}`);
|
const response = await axios.get(`/api/gangs/${gang.id}/homies/${homie_id}/money_moves`);
|
||||||
if (response.status === 200 && response.data){
|
if (response.status === 200 && response.data){
|
||||||
updateData(response.data);
|
updateData(response.data);
|
||||||
}
|
}
|
||||||
@@ -33,37 +37,65 @@ const CashFlow = (props) => {
|
|||||||
})();
|
})();
|
||||||
}, [homie_id]);
|
}, [homie_id]);
|
||||||
|
|
||||||
const dateBlock = (timestamp) => <span className="grey-text">{ timestampToDate(timestamp) }</span>
|
const softDeleteMoneyMove = async (moneyMove) => {
|
||||||
|
try {
|
||||||
|
const response = await axios.delete(`/api/gangs/${gang.id}/homies/${homie_id}/money_moves/${moneyMove.id}`);
|
||||||
|
if (response.status === 200 && response.data){
|
||||||
|
updateData(response.data);
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
errorToast();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const flowData = cashFlow.map( (singleFlowData, index) => (
|
const flowData = cashFlow.map((singleFlowData, index) => {
|
||||||
<li key={index}>
|
const deleted = !!singleFlowData.deleted_at;
|
||||||
<div className="collapsible-header record">
|
const description = deleted ? <del>{singleFlowData.description}</del> : singleFlowData.description;
|
||||||
<div className="flex-row opposite-sides-content">
|
const formattedCreatedAtDate = timestampToDate(singleFlowData['created_at']);
|
||||||
<div className="flex-col">
|
const formattedDeletedAtDate = deleted ? timestampToDate(singleFlowData['deleted_at']) : null;
|
||||||
<div>{ singleFlowData.description }</div>
|
const dateDescription = deleted ?
|
||||||
<div>{ dateBlock(singleFlowData['created_at']) }</div>
|
`${formattedCreatedAtDate} • deleted at ${formattedDeletedAtDate}` : `${formattedCreatedAtDate}`;
|
||||||
|
|
||||||
|
const recordClass = deleted ? 'deleted-record' : 'record';
|
||||||
|
|
||||||
|
return (
|
||||||
|
<li key={index}>
|
||||||
|
<div className={`collapsible-header ${recordClass}`}>
|
||||||
|
<div className="flex-row opposite-sides-content">
|
||||||
|
<div className="flex-col">
|
||||||
|
<div>{description}</div>
|
||||||
|
<div><span className="grey-text">{dateDescription}</span></div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className={`push flex-center ${singleFlowData.amount > 0 ? 'amount-green' : ''}`}>{ formatMoney(singleFlowData.amount, gang) }</div>
|
||||||
|
|
||||||
|
<YesNoModal
|
||||||
|
body={"Maan, y'a sure about this?"}
|
||||||
|
yesAction={() => softDeleteMoneyMove(singleFlowData)}
|
||||||
|
triggerNode={<Button disabled={deleted} className="flex-center" flat node="button" icon="remove_circle" />} />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className={`flex-center ${singleFlowData.amount > 0 ? 'amount-green' : ''}`}>{ formatMoney(singleFlowData.amount, gang) }</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</li>
|
||||||
</li>
|
)
|
||||||
));
|
});
|
||||||
|
|
||||||
const totalStats = () => {
|
const totalStats = () => {
|
||||||
const totalCount = cashFlow.length;
|
const totalNonDeletedCount = cashFlow.filter(record => !record.deleted_at).length;
|
||||||
const firstFlowRow = totalCount > 0 ? cashFlow[0] : undefined;
|
|
||||||
const lastFlowRow = totalCount > 0 ? cashFlow[cashFlow.length - 1] : undefined;
|
const firstFlowRow = totalNonDeletedCount > 0 ? cashFlow[0] : undefined;
|
||||||
|
const lastFlowRow = totalNonDeletedCount > 0 ? cashFlow[cashFlow.length - 1] : undefined;
|
||||||
|
|
||||||
const fromDate = lastFlowRow ? timestampToDate(lastFlowRow['created_at']) : '';
|
const fromDate = lastFlowRow ? timestampToDate(lastFlowRow['created_at']) : '';
|
||||||
const toDate = firstFlowRow ? timestampToDate(firstFlowRow['created_at']) : '';
|
const toDate = firstFlowRow ? timestampToDate(firstFlowRow['created_at']) : '';
|
||||||
|
|
||||||
|
const dateRange = firstFlowRow && lastFlowRow ? ` • ${fromDate} - ${toDate}` : '';
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<br />
|
<br />
|
||||||
<div className="row">
|
<div className="row">
|
||||||
<div className="col s6">
|
<div className="col s6">
|
||||||
<strong>{`${totalCount} Records`}</strong><span className="grey-text">{` • ${fromDate} - ${toDate}`}</span>
|
<strong>{`${totalNonDeletedCount} Records`}</strong><span className="grey-text">{dateRange}</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="col s6 right-align">
|
<div className="col s6 right-align">
|
||||||
<span className="grey-text">Total cash flow:</span> <strong>{formatMoney(totalCashFlowAmount, gang)}</strong>
|
<span className="grey-text">Total cash flow:</span> <strong>{formatMoney(totalCashFlowAmount, gang)}</strong>
|
||||||
|
|||||||
@@ -33,6 +33,12 @@
|
|||||||
padding-left: 11px;
|
padding-left: 11px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.deleted-record:hover {
|
||||||
|
border-left: rgb(85, 85, 85) solid 4px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
padding-left: 11px;
|
||||||
|
}
|
||||||
|
|
||||||
.switch-box {
|
.switch-box {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
margin-bottom: 20px;
|
margin-bottom: 20px;
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ const MoveMoney = (props) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const submitResponse = await axios.post('/api/money_moves', moneyMoveRequest);
|
const submitResponse = await axios.post(`/api/gangs/${gang.id}/homies/${homie_id}/money_moves`, moneyMoveRequest);
|
||||||
|
|
||||||
if (submitResponse && submitResponse.status === 200 && submitResponse.data === true) {
|
if (submitResponse && submitResponse.status === 200 && submitResponse.data === true) {
|
||||||
M.toast({html: "Money lounde...moved"});
|
M.toast({html: "Money lounde...moved"});
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ Rails.application.routes.draw do
|
|||||||
end
|
end
|
||||||
member do
|
member do
|
||||||
post 'settle'
|
post 'settle'
|
||||||
|
resources :money_moves
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :money_moves
|
|
||||||
resources :work
|
resources :work
|
||||||
resources :chips, only: %i[index create destroy]
|
resources :chips, only: %i[index create destroy]
|
||||||
resources :chip_values, only: %i[create update destroy]
|
resources :chip_values, only: %i[create update destroy]
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
class AddDeletedAtToMoneyMoves < ActiveRecord::Migration[5.2]
|
||||||
|
def change
|
||||||
|
add_column :money_moves, :deleted_at, :timestamp
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2020_10_07_213411) do
|
ActiveRecord::Schema.define(version: 2020_10_09_114126) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
@@ -63,6 +63,7 @@ ActiveRecord::Schema.define(version: 2020_10_07_213411) do
|
|||||||
t.integer "homie_id", null: false
|
t.integer "homie_id", null: false
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
t.datetime "deleted_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "work", force: :cascade do |t|
|
create_table "work", force: :cascade do |t|
|
||||||
|
|||||||
Reference in New Issue
Block a user