diff --git a/src/javascript/app/App/Components/Form/CompositeCalendar/composite-calendar.jsx b/src/javascript/app/App/Components/Form/CompositeCalendar/composite-calendar.jsx index 193b9ba00201..c49d2c17eb7e 100644 --- a/src/javascript/app/App/Components/Form/CompositeCalendar/composite-calendar.jsx +++ b/src/javascript/app/App/Components/Form/CompositeCalendar/composite-calendar.jsx @@ -19,7 +19,7 @@ class CompositeCalendar extends React.PureComponent { this.state = { show_to : false, show_from : false, - selected_to_date : props.to ? props.to : date.unix(), + selected_to_date : props.to ? props.to : date.clone().startOf('day').add(1, 'd').subtract(1, 's').unix(), selected_from_date: props.from ? props.from : null, list : [ { children: localize('All time'), onClick: () => this.selectDateRange(0), duration: 0, is_active: true }, @@ -36,7 +36,7 @@ class CompositeCalendar extends React.PureComponent { selectDateRange (from) { this.setState({ - selected_from_date: from ? toMoment().startOf('day').subtract(from, 'day').unix() : null, + selected_from_date: from ? toMoment().startOf('day').subtract(from, 'day').add(1, 's').unix() : null, selected_to_date : toMoment().startOf('day').unix(), }, () => { this.setActiveList(); @@ -113,7 +113,7 @@ class CompositeCalendar extends React.PureComponent { } setToDate (date) { - this.updateState('selected_to_date', date); + this.updateState('selected_to_date', epochToMoment(date).startOf('day').add(1, 'd').subtract(1, 's').unix()); } setFromDate(date) { diff --git a/src/javascript/app/Stores/Modules/Profit/Helpers/format-request.js b/src/javascript/app/Stores/Modules/Profit/Helpers/format-request.js index ddd723dd0a16..62b6003516d7 100644 --- a/src/javascript/app/Stores/Modules/Profit/Helpers/format-request.js +++ b/src/javascript/app/Stores/Modules/Profit/Helpers/format-request.js @@ -4,7 +4,13 @@ import { } from 'Utils/Date'; const getDateTo = (partial_fetch_time, date_to) => { - if (partial_fetch_time) { + const today = toMoment().startOf('day').unix(); + if (date_to && today > date_to) { + return epochToMoment(date_to) + .add(1, 'd') + .subtract(1, 's') + .unix(); + } else if (partial_fetch_time) { return toMoment().endOf('day').unix(); } else if (date_to) { return epochToMoment(date_to) @@ -15,13 +21,18 @@ const getDateTo = (partial_fetch_time, date_to) => { return toMoment().endOf('day').unix(); }; -const getDateFrom = (should_load_partially, partial_fetch_time, date_from) => - should_load_partially && partial_fetch_time ? partial_fetch_time : date_from; +const getDateFrom = (should_load_partially, partial_fetch_time, date_from, date_to) => { + const today = toMoment().startOf('day').unix(); + if (today > date_to) { + return date_from; + } + return should_load_partially && partial_fetch_time ? partial_fetch_time : date_from; +}; const getDateBoundaries = (date_from, date_to, partial_fetch_time, should_load_partially = false) => ( { // eslint-disable-next-line max-len - ...(date_from || should_load_partially) && { date_from: getDateFrom(should_load_partially, partial_fetch_time, date_from) }, + ...(date_from || should_load_partially) && { date_from: getDateFrom(should_load_partially, partial_fetch_time, date_from, date_to) }, ...(date_to || should_load_partially) && { date_to: getDateTo(partial_fetch_time, date_to) }, } ); diff --git a/src/javascript/app/Stores/Modules/Profit/profit-store.js b/src/javascript/app/Stores/Modules/Profit/profit-store.js index ab37cb8e6e47..7be7a3d2e751 100644 --- a/src/javascript/app/Stores/Modules/Profit/profit-store.js +++ b/src/javascript/app/Stores/Modules/Profit/profit-store.js @@ -45,9 +45,16 @@ export default class ProfitTableStore extends BaseStore { return !!(this.date_from || this.date_to); } + shouldFetchNextBatch(should_load_partially) { + if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return false; + const today = toMoment().startOf('day').add(1, 'd').subtract(1, 's').unix(); + if (should_load_partially && this.date_to && this.date_to < today) return false; + return true; + } + @action.bound async fetchNextBatch(should_load_partially = false) { - if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return; + if (!this.shouldFetchNextBatch(should_load_partially)) return; this.is_loading = true; const response = await WS.profitTable( @@ -159,9 +166,7 @@ export default class ProfitTableStore extends BaseStore { @action.bound handleDateChange(date_values) { Object.keys(date_values).forEach(key => { - if (date_values[key]) { - this[`date_${key}`] = date_values[key]; - } + this[`date_${key}`] = date_values[key]; }); this.clearTable(); this.fetchNextBatch(); diff --git a/src/javascript/app/Stores/Modules/Statement/statement-store.js b/src/javascript/app/Stores/Modules/Statement/statement-store.js index 9a1bf1c6f93d..29a56a06b88d 100644 --- a/src/javascript/app/Stores/Modules/Statement/statement-store.js +++ b/src/javascript/app/Stores/Modules/Statement/statement-store.js @@ -49,9 +49,16 @@ export default class StatementStore extends BaseStore { this.date_to = 0; } + shouldFetchNextBatch(should_load_partially) { + if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return false; + const today = toMoment().startOf('day').add(1, 'd').subtract(1, 's').unix(); + if (should_load_partially && this.date_to && this.date_to < today) return false; + return true; + } + @action.bound async fetchNextBatch(should_load_partially = false) { - if (!should_load_partially && (this.has_loaded_all || this.is_loading)) return; + if (!this.shouldFetchNextBatch(should_load_partially)) return; this.is_loading = true; const response = await WS.statement( @@ -92,9 +99,7 @@ export default class StatementStore extends BaseStore { @action.bound handleDateChange(date_values) { Object.keys(date_values).forEach(key => { - if (date_values[key]) { - this[`date_${key}`] = date_values[key]; - } + this[`date_${key}`] = date_values[key]; }); this.clearTable(); this.fetchNextBatch();