Skip to content

Commit

Permalink
Merge 14ffce7 into b4db8cb
Browse files Browse the repository at this point in the history
  • Loading branch information
JackNeto committed Aug 11, 2019
2 parents b4db8cb + 14ffce7 commit 11d010e
Show file tree
Hide file tree
Showing 15 changed files with 1,764 additions and 1,633 deletions.
8 changes: 4 additions & 4 deletions src/core/Accounts/Transactions/TransactionDialog.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,6 @@ export const TransactionDialogComponent = ({
label="Amount"
inputProps={{
'aria-label': 'Amount',
maxLength: 10,
min: Number.MIN_SAFE_INTEGER,
max: Number.MAX_SAFE_INTEGER,
step: 0.01
}}
className={classes.input}
Expand Down Expand Up @@ -236,11 +233,14 @@ export default compose(
},
validationSchema: Yup.object().shape({
description: Yup.string()
.required('Please enter a description for this transaction')
.max(256, 'Too Long!'),
categoryId: Yup.object()
.nullable(),
amount: Yup.number()
.required('Please enter an amount'),
.required('Please enter an amount')
.min(-999999999.99)
.max(999999999.99),
createdAt: Yup.date()
.required('Please select the date of this transaction')
}),
Expand Down
46 changes: 28 additions & 18 deletions src/core/Accounts/form.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ const styles = theme => ({
const mapStateToProps = (state, ownProps) => ({
settings: state.settings,
accountInstitutions: Object.keys(state.accounts.byInstitution),
account: state.accounts.byId[ownProps.accountId]
account: state.accounts.byId[ownProps.accountId],
accounts: state.accounts
})

export class AccountFormComponent extends React.Component {
Expand Down Expand Up @@ -297,23 +298,32 @@ export default compose(
}
}
},
validationSchema: Yup.object().shape({
name: Yup.string()
.max(100, 'Too Long!')
.required('Please enter a name for this account'),
institution: Yup.object()
.required('Please select an institution')
.nullable(),
openingBalance: Yup.number()
.required('Please enter an opening balance')
.min(Number.MIN_SAFE_INTEGER)
.max(Number.MAX_SAFE_INTEGER),
openingBalanceDate: Yup.date()
.required('Please select the date of the opening balance'),
currency: Yup.object()
.required('Please select the currency of this account')
.nullable()
}),
validationSchema: (props) => {
return Yup.lazy((values) => {
const accountNames = Object.values(props.accounts.byId).filter(
account => account.institution === values.institution.value
).map(account => account.name)
console.log(accountNames, values)
return Yup.object().shape({
name: Yup.string()
.max(50, 'Too Long!')
.required('Please enter a name for this account')
.notOneOf(accountNames, `There's already an account with this name in ${values.institution.value}`),
institution: Yup.object()
.required('Please select an institution')
.nullable(accountNames),
openingBalance: Yup.number()
.required('Please enter an opening balance')
.min(-999999999.99)
.max(999999999.99),
openingBalanceDate: Yup.date()
.required('Please select the date of the opening balance'),
currency: Yup.object()
.required('Please select the currency of this account')
.nullable()
})
})
},
handleSubmit: async (values, { props, setSubmitting }) => {
setSubmitting(true)
await props.handleSave({
Expand Down
28 changes: 18 additions & 10 deletions src/core/Budget/BudgetChart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@ const BudgetChart = () => {

}))

const usedCategories = [...new Set(Object.values(budget.rules).map(rules => (
budget.categoriesById[rules.categoryId]
)))]
// Used categories except Income
const usedCategories = [
...new Set(
Object.values(budget.rules)
.map(rules => budget.categoriesById[rules.categoryId])
)
].filter(category => !budget.categoriesById[category.parentId].isIncome)

const initialState = usedCategories.reduce(
(res, cat) => ({ ...res, [cat]: 1 }),
{}
Expand All @@ -40,14 +45,17 @@ const BudgetChart = () => {
transactions.list.forEach((transaction) => {
const dateKey = startOfMonth(transaction.createdAt).getTime()
if (transaction.categoryId !== undefined) {
const categoryName = budget.categoriesById[transaction.categoryId].name
if (byMonth[dateKey] === undefined) {
byMonth[dateKey] = usedCategories.reduce((res, cat) => ({ ...res, [cat.name]: 0 }), {})
}
if (byMonth[dateKey][categoryName] === undefined) {
byMonth[dateKey][categoryName] = 0
const category = budget.categoriesById[transaction.categoryId]
const group = budget.categoriesById[category.parentId]
if (!group.isIncome) {
if (byMonth[dateKey] === undefined) {
byMonth[dateKey] = usedCategories.reduce((res, cat) => ({ ...res, [cat.name]: 0 }), {})
}
if (byMonth[dateKey][category.name] === undefined) {
byMonth[dateKey][category.name] = 0
}
byMonth[dateKey][category.name] += Math.abs(transaction.amount)
}
byMonth[dateKey][categoryName] += Math.abs(transaction.amount)
}
})
const data = Object.keys(byMonth).sort((a, b) => a - b).map(date => ({
Expand Down

0 comments on commit 11d010e

Please sign in to comment.