Skip to content

Commit

Permalink
Adding new income frequencies; bumping up version
Browse files Browse the repository at this point in the history
  • Loading branch information
reZach committed May 26, 2019
1 parent 975f8c6 commit edc3075
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 38 deletions.
10 changes: 6 additions & 4 deletions app/actions/incomeRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@ export const INCOME_RECORDS_FREQUENCY_MAP = {
"1": "every week",
"2": "every 2 weeks",
"3": "first business day of the month",
"4": "last business day of the month"
"4": "last business day of the month",
"5": "every \"{0}\" {1}"
}

const add_income_record = function(day: number, month: number, year: number, income: number, frequency: string, note: string){
const add_income_record = function(day: number, month: number, year: number, income: number, frequency: string, xdays: number, note: string){
return {
type: ADD_INCOME_RECORD,
payload: {
Expand All @@ -40,6 +41,7 @@ const add_income_record = function(day: number, month: number, year: number, inc
startYear: year,
income,
frequency,
xdays,
note
}
};
Expand Down Expand Up @@ -122,9 +124,9 @@ const entry_income_records = function(incomeRecords: array){
};
}

export function addIncomeRecord(day: number, month: number, year: number, income: number, frequency: string, note: string){
export function addIncomeRecord(day: number, month: number, year: number, income: number, frequency: string, xdays: number, note: string){
return (dispatch: Dispatch) => {
dispatch(add_income_record(day, month, year, income, frequency, note));
dispatch(add_income_record(day, month, year, income, frequency, xdays, note));
}
}

Expand Down
87 changes: 76 additions & 11 deletions app/components/Income/Income.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,15 @@ class Income extends Component<Props>{
date: "",
income: 0,
frequency: "0",
xdays: "1",
note: ""
};

this.toggleModal = this.toggleModal.bind(this);
this.changeIncome = this.changeIncome.bind(this);
this.changeDate = this.changeDate.bind(this);
this.changeFrequency = this.changeFrequency.bind(this);
this.changeXDays = this.changeXDays.bind(this);
this.changeNote = this.changeNote.bind(this);
this.addNewIncomeRecord = this.addNewIncomeRecord.bind(this);
this.addIncomeRecordIsValid = this.addIncomeRecordIsValid.bind(this);
Expand Down Expand Up @@ -71,7 +73,14 @@ class Income extends Component<Props>{

changeFrequency(event){
this.setState({
frequency: event.target.value
frequency: event.target.value,
xdays: event.target.value === "5" ? "1" : "0" // reset if not picking "x" days frequency
});
}

changeXDays(event){
this.setState({
xdays: event.target.value
});
}

Expand Down Expand Up @@ -109,7 +118,7 @@ class Income extends Component<Props>{
}

addNewIncomeRecord(){
this.props.addIncomeRecord(this.state.day, this.state.month, this.state.year, this.state.income, this.state.frequency, this.state.note);
this.props.addIncomeRecord(this.state.day, this.state.month, this.state.year, this.state.income, this.state.frequency, this.state.xdays, this.state.note);

this.setState({
day: 0,
Expand Down Expand Up @@ -156,10 +165,18 @@ class Income extends Component<Props>{
}

addIncomeRecordIsValid(){
return (this.state.day !== 0 &&
if (this.state.frequency === "5"){
return (this.state.day !== 0 &&
this.state.month !== 0 &&
this.state.year !== 0 &&
this.state.income !== 0 &&
parseInt(this.state.xdays) > 0);
} else {
return (this.state.day !== 0 &&
this.state.month !== 0 &&
this.state.year !== 0 &&
this.state.income !== 0);
}
}

toggleModal(){
Expand Down Expand Up @@ -218,7 +235,7 @@ class Income extends Component<Props>{
cash += parseFloat(validIncomeRecords[i].income);
} else {

var firstBusinessDay = new Date(startDate.getFullYear(), startDate.getMonth(), 1);
let firstBusinessDay = new Date(startDate.getFullYear(), startDate.getMonth(), 1);

// Land on a weekday (0 == sunday, 6 == saturday)
while(firstBusinessDay > 0 && firstBusinessDay < 6){
Expand All @@ -238,10 +255,43 @@ class Income extends Component<Props>{
}
break;
}
case "4":
case "4": {
// last business day of every month

break;
let greaterThanAMonth = false;
while (startDate <= today){

if (today.getFullYear() > startDate.getFullYear()){
cash += parseFloat(validIncomeRecords[i].income);
} else if (today.getMonth() - startDate.getMonth() > 0){
cash += parseFloat(validIncomeRecords[i].income);
} else {
let firstBusinessDay = new Date(startDate.getFullYear(), startDate.getMonth() + 1, 0);

// Land on a weekday (0 == sunday, 6 == saturday)
while(firstBusinessDay > 0 && firstBusinessDay < 6){
firstBusinessDay.setDate(firstBusinessDay.getDate() - 1);
}

if ((today >= firstBusinessDay && greaterThanAMonth) ||
startDate.getTime() === firstBusinessDay.getTime()){
cash += parseFloat(validIncomeRecords[i].income);
}
}

// set to next month
startDate.setDate(1);
startDate.setMonth(startDate.getMonth() + 1);
greaterThanAMonth = true;
}
break;
}
case "5":
// every "x" days
while (startDate <= today){
cash += parseFloat(validIncomeRecords[i].income);
startDate.setDate(startDate.getDate() + validIncomeRecords[i].xdays);
}
break;
default:
break;
}
Expand Down Expand Up @@ -304,10 +354,9 @@ class Income extends Component<Props>{
</div>
);
}
return (
<span className="label label-success">${data.amount}</span>
);

return (
<span className="label label-success">${data.amount}</span>
);
}

frequencyDropDown(){
Expand All @@ -327,6 +376,14 @@ class Income extends Component<Props>{
{
value: "3",
text: "first business day of the month"
},
{
value: "4",
text: "last business day of the month"
},
{
value: "5",
text: "every x days"
}
];

Expand Down Expand Up @@ -414,6 +471,14 @@ class Income extends Component<Props>{
</select>
</div>
</div>
{this.state.frequency !== "5" ? <React.Fragment></React.Fragment> : <div className="form-group">
<div className="column col-3">
<label className="form-label" htmlFor="income-xdays-input">{"\"X\" days"}</label>
</div>
<div className="column col-9">
<input className="form-input" id="income-xdays-input" type="number" value={this.state.xdays} onChange={this.changeXDays} placeholder={"\"x\" days"} />
</div>
</div> }
<div className="form-group">
<div className="column col-3">
<label className="form-label" htmlFor="income-note-input">Note</label>
Expand Down
42 changes: 22 additions & 20 deletions app/reducers/incomeRecords.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,34 @@ export default function incomeRecords(state: array = [], action: Action){
startYear: action.payload.startYear,
income: action.payload.income,
frequency: action.payload.frequency,
frequencyName: INCOME_RECORDS_FREQUENCY_MAP[action.payload.frequency],
frequencyName: action.payload.frequency !== "5" ? INCOME_RECORDS_FREQUENCY_MAP[action.payload.frequency] : (parseInt(action.payload.xdays) > 1 ? INCOME_RECORDS_FREQUENCY_MAP[action.payload.frequency].replace("{0}", action.payload.xdays).replace("{1}", "days") : INCOME_RECORDS_FREQUENCY_MAP[action.payload.frequency].replace("{0}", action.payload.xdays).replace("{1}", "day")),
xdays: parseInt(action.payload.xdays),
note: action.payload.note
}]
);
}
return update(state,
[{
id: (state.reduce((accumulator, current) => {
const id = parseInt(current.id);
return update(state,
[{
id: (state.reduce((accumulator, current) => {
const id = parseInt(current.id);

if (id > accumulator) {
return id;
}
if (id > accumulator) {
return id;
}

// Should never get into this, but still
return accumulator;
}, 0) + 1).toString(),
startDay: action.payload.startDay,
startMonth: action.payload.startMonth,
startYear: action.payload.startYear,
income: action.payload.income,
frequency: action.payload.frequency,
frequencyName: INCOME_RECORDS_FREQUENCY_MAP[action.payload.frequency],
note: action.payload.note
}]
);
// Should never get into this, but still
return accumulator;
}, 0) + 1).toString(),
startDay: action.payload.startDay,
startMonth: action.payload.startMonth,
startYear: action.payload.startYear,
income: action.payload.income,
frequency: action.payload.frequency,
frequencyName: action.payload.frequency !== "5" ? INCOME_RECORDS_FREQUENCY_MAP[action.payload.frequency] : (parseInt(action.payload.xdays) > 1 ? INCOME_RECORDS_FREQUENCY_MAP[action.payload.frequency].replace("{0}", action.payload.xdays).replace("{1}", "days") : INCOME_RECORDS_FREQUENCY_MAP[action.payload.frequency].replace("{0}", action.payload.xdays).replace("{1}", "day")),
xdays: action.payload.xdays,
note: action.payload.note
}]
);

case MODIFY_INCOME_RECORD_START_DAY:
return update([],
Expand Down
4 changes: 2 additions & 2 deletions docs/_layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ <h1>{{ site.title | default: site.github.repository_name }}</h1>
<div class="downloads">
<span>Downloads:</span>
<ul>
<li><a href="https://github.com/reZach/my-budget/releases/download/v3.1.1-beta/my-budget-3.1.1-beta.msi" class="button">Windows</a></li>
<li><a href="https://github.com/reZach/my-budget/releases/download/v3.1.1-beta/my-budget-3.1.1-beta.dmg" class="button">Mac</a></li>
<li><a href="https://github.com/reZach/my-budget/releases/download/v3.2.0-beta/my-budget-3.2.0-beta.msi" class="button">Windows</a></li>
<li><a href="https://github.com/reZach/my-budget/releases/download/v3.2.0-beta/my-budget-3.2.0-beta.dmg" class="button">Mac</a></li>
<li><a href="https://github.com/reZach/my-budget/releases/latest" class="button">Linux</a></li>
</ul>
</div>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "my-budget",
"productName": "MyBudget",
"version": "3.1.1-beta",
"version": "3.2.0-beta",
"description": "Free, open source offline cross-platform budgeting solution built with Electron.",
"scripts": {
"build": "concurrently \"yarn build-main\" \"yarn build-renderer\"",
Expand Down

0 comments on commit edc3075

Please sign in to comment.