You've already forked openaccounting-web
forked from cybercinch/openaccounting-web
wip
This commit is contained in:
16
package-lock.json
generated
16
package-lock.json
generated
@@ -595,6 +595,14 @@
|
||||
"@types/jasmine": "*"
|
||||
}
|
||||
},
|
||||
"@types/moment-timezone": {
|
||||
"version": "0.5.12",
|
||||
"resolved": "https://registry.npmjs.org/@types/moment-timezone/-/moment-timezone-0.5.12.tgz",
|
||||
"integrity": "sha512-hnHH2+Efg2vExr/dSz+IX860nSiyk9Sk4pJF2EmS11lRpMcNXeB4KBW5xcgw2QPsb9amTXdsVNEe5IoJXiT0uw==",
|
||||
"requires": {
|
||||
"moment": ">=2.14.0"
|
||||
}
|
||||
},
|
||||
"@types/node": {
|
||||
"version": "8.9.5",
|
||||
"resolved": "http://registry.npmjs.org/@types/node/-/node-8.9.5.tgz",
|
||||
@@ -6408,6 +6416,14 @@
|
||||
"minimist": "0.0.8"
|
||||
}
|
||||
},
|
||||
"moment-timezone": {
|
||||
"version": "0.5.25",
|
||||
"resolved": "https://registry.npmjs.org/moment-timezone/-/moment-timezone-0.5.25.tgz",
|
||||
"integrity": "sha512-DgEaTyN/z0HFaVcVbSyVCUU6HeFdnNC3vE4c9cgu2dgMTvjBUBdBzWfasTBmAW45u5OIMeCJtU8yNjM22DHucw==",
|
||||
"requires": {
|
||||
"moment": ">= 2.9.0"
|
||||
}
|
||||
},
|
||||
"move-concurrently": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/move-concurrently/-/move-concurrently-1.0.1.tgz",
|
||||
|
||||
@@ -28,8 +28,10 @@
|
||||
"@angular/platform-browser-dynamic": "^6.1.0",
|
||||
"@angular/router": "^6.1.0",
|
||||
"@ng-bootstrap/ng-bootstrap": "^3.3.1",
|
||||
"@types/moment-timezone": "^0.5.12",
|
||||
"bootstrap": "^4.1.3",
|
||||
"core-js": "^2.5.4",
|
||||
"moment-timezone": "^0.5.25",
|
||||
"rxjs": "~6.2.0",
|
||||
"rxjs-compat": "6.0.0",
|
||||
"zone.js": "~0.8.26"
|
||||
|
||||
@@ -63,7 +63,7 @@ export class BalanceSheetReport {
|
||||
}
|
||||
|
||||
this.form = fb.group({
|
||||
date: [Util.getLocalDateString(this.date), Validators.required],
|
||||
date: [Util.getLocalDateStringExcl(this.date), Validators.required],
|
||||
priceSource: [this.priceSource, Validators.required]
|
||||
});
|
||||
}
|
||||
@@ -133,7 +133,7 @@ export class BalanceSheetReport {
|
||||
this.treeSubscription.unsubscribe();
|
||||
//this.dataService.setLoading(true);
|
||||
this.showOptionsForm = false;
|
||||
this.date = Util.getDateFromLocalDateString(this.form.value.date);
|
||||
this.date = Util.getDateFromLocalDateStringExcl(this.form.value.date);
|
||||
this.priceSource = this.form.value.priceSource;
|
||||
|
||||
let reportData = this.configService.get('reportData');
|
||||
|
||||
@@ -45,10 +45,9 @@ export class IncomeReport {
|
||||
private configService: ConfigService,
|
||||
private sessionService: SessionService) {
|
||||
this.startDate = new Date();
|
||||
this.startDate.setDate(1);
|
||||
this.startDate.setHours(0, 0, 0, 0);
|
||||
this.endDate = new Date(this.startDate);
|
||||
this.endDate.setMonth(this.startDate.getMonth() + 1);
|
||||
Util.setFirstOfMonth(this.startDate);
|
||||
Util.setBeginOfDay(this.startDate);
|
||||
this.endDate = Util.getOneMonthLater(this.startDate);
|
||||
|
||||
let reportData = this.configService.get('reportData');
|
||||
|
||||
@@ -65,7 +64,7 @@ export class IncomeReport {
|
||||
|
||||
this.form = fb.group({
|
||||
startDate: [Util.getLocalDateString(this.startDate), Validators.required],
|
||||
endDate: [Util.getLocalDateString(new Date(this.endDate.getTime() - 1)), Validators.required]
|
||||
endDate: [Util.getLocalDateStringExcl(this.endDate), Validators.required]
|
||||
});
|
||||
}
|
||||
|
||||
@@ -92,8 +91,7 @@ export class IncomeReport {
|
||||
//this.dataService.setLoading(true);
|
||||
this.showDateForm = false;
|
||||
this.startDate = Util.getDateFromLocalDateString(this.form.value.startDate);
|
||||
this.endDate = Util.getDateFromLocalDateString(this.form.value.endDate);
|
||||
this.endDate.setDate(this.endDate.getDate() + 1);
|
||||
this.endDate = Util.getDateFromLocalDateStringExcl(this.form.value.endDate);
|
||||
|
||||
let reportData = this.configService.get('reportData');
|
||||
|
||||
|
||||
@@ -1,8 +1,15 @@
|
||||
//import * as moment from 'moment-timezone/builds/moment-timezone-with-data-2012-2022.min';
|
||||
import * as moment from 'moment-timezone';
|
||||
|
||||
const defaultTz = moment.tz.guess();
|
||||
|
||||
export class Util {
|
||||
static getLocalDateString(input: Date) {
|
||||
let year = input.getFullYear().toString();
|
||||
let month = (input.getMonth() + 1).toString();
|
||||
let date = input.getDate().toString();
|
||||
static getLocalDateString(input: Date, tz: string = defaultTz) {
|
||||
let m = moment(input).tz(tz);
|
||||
|
||||
let year = m.format('YYYY');
|
||||
let month = m.format('MM');
|
||||
let date = m.format('DD');
|
||||
|
||||
if(month.length < 2) {
|
||||
month = '0' + month;
|
||||
@@ -15,14 +22,112 @@ export class Util {
|
||||
return year + '-' + month + '-' + date;
|
||||
}
|
||||
|
||||
static getDateFromLocalDateString(input: string) {
|
||||
let parts = input.split('-');
|
||||
let date = new Date();
|
||||
date.setHours(0, 0, 0, 0);
|
||||
date.setFullYear(parseInt(parts[0]));
|
||||
date.setMonth(parseInt(parts[1]) - 1, parseInt(parts[2]));
|
||||
static getLocalDateStringExcl(input: Date, tz: string = defaultTz) {
|
||||
let m = moment(input.getTime() - 1).tz(tz);
|
||||
|
||||
return date;
|
||||
let year = m.format('YYYY');
|
||||
let month = m.format('MM');
|
||||
let date = m.format('DD');
|
||||
|
||||
if(month.length < 2) {
|
||||
month = '0' + month;
|
||||
}
|
||||
|
||||
if(date.length < 2) {
|
||||
date = '0' + date;
|
||||
}
|
||||
|
||||
return year + '-' + month + '-' + date;
|
||||
}
|
||||
|
||||
static getDateFromLocalDateString(input: string, tz: string = defaultTz) {
|
||||
let parts = input.split('-');
|
||||
|
||||
let m = moment().tz(tz);
|
||||
m.hours(0);
|
||||
m.minutes(0);
|
||||
m.seconds(0);
|
||||
m.milliseconds(0);
|
||||
m.year(parseInt(parts[0]));
|
||||
m.month(parseInt(parts[1]) - 1);
|
||||
m.date(parseInt(parts[2]));
|
||||
|
||||
return m.toDate();
|
||||
}
|
||||
|
||||
static getDateFromLocalDateStringExcl(input: string, tz: string = defaultTz) {
|
||||
let parts = input.split('-');
|
||||
|
||||
let m = moment().tz(tz);
|
||||
m.hours(0);
|
||||
m.minutes(0);
|
||||
m.seconds(0);
|
||||
m.milliseconds(0);
|
||||
m.year(parseInt(parts[0]));
|
||||
m.month(parseInt(parts[1]) - 1);
|
||||
m.date(parseInt(parts[2]) + 1);
|
||||
|
||||
return m.toDate();
|
||||
}
|
||||
|
||||
static setFirstOfMonth(input: Date, tz: string = defaultTz) {
|
||||
let m = moment(input).tz(tz);
|
||||
|
||||
m.date(1);
|
||||
input.setTime(m.valueOf());
|
||||
}
|
||||
|
||||
static setBeginOfDay(input: Date, tz: string = defaultTz) {
|
||||
let m = moment(input).tz(tz);
|
||||
|
||||
m.hours(0);
|
||||
m.minutes(0);
|
||||
m.seconds(0);
|
||||
m.milliseconds(0);
|
||||
input.setTime(m.valueOf());
|
||||
}
|
||||
|
||||
static setEndOfDay(input: Date, tz: string = defaultTz) {
|
||||
let m = moment(input).tz(tz);
|
||||
|
||||
m.hours(23);
|
||||
m.minutes(59);
|
||||
m.seconds(59);
|
||||
m.milliseconds(999);
|
||||
input.setTime(m.valueOf());
|
||||
}
|
||||
|
||||
static getOneMonthLater(input: Date, tz: string = defaultTz): Date {
|
||||
let m = moment(input).tz(tz);
|
||||
|
||||
m.month(m.month() + 1);
|
||||
|
||||
return m.toDate();
|
||||
}
|
||||
|
||||
static computeTransactionDate(formDate: Date, txDate: Date, tz: string = defaultTz): Date {
|
||||
if(!formDate || !formDate.getTime()) {
|
||||
return txDate;
|
||||
}
|
||||
|
||||
let formMoment = moment(formDate).tz(tz);
|
||||
let txMoment = moment(txDate).tz(tz);
|
||||
|
||||
// make the time be at the very end of the day
|
||||
formMoment.hours(23);
|
||||
formMoment.minutes(59);
|
||||
formMoment.seconds(59);
|
||||
formMoment.milliseconds(999);
|
||||
|
||||
let sameDay = formMoment.year() === txMoment.year() &&
|
||||
formMoment.month() === txMoment.month() &&
|
||||
formMoment.date() === txMoment.date();
|
||||
|
||||
if(!sameDay) {
|
||||
return formMoment.toDate();
|
||||
}
|
||||
|
||||
return txDate;
|
||||
}
|
||||
|
||||
static newGuid() {
|
||||
|
||||
@@ -624,7 +624,7 @@ export class TxListPage implements OnInit, AfterViewChecked {
|
||||
let date = item.tx.id ? item.tx.date : new Date();
|
||||
let formDate = Util.getDateFromLocalDateString(item.form.value.date);
|
||||
|
||||
date = this.computeTransactionDate(formDate, date);
|
||||
date = Util.computeTransactionDate(formDate, date);
|
||||
|
||||
let tx = new Transaction({
|
||||
id: item.tx.id,
|
||||
@@ -731,23 +731,6 @@ export class TxListPage implements OnInit, AfterViewChecked {
|
||||
}
|
||||
}
|
||||
|
||||
computeTransactionDate(formDate: Date, txDate: Date): Date {
|
||||
if(formDate.getTime()) {
|
||||
// make the time be at the very end of the day
|
||||
formDate.setHours(23, 59, 59, 999);
|
||||
}
|
||||
|
||||
let sameDay = formDate.getFullYear() === txDate.getFullYear() &&
|
||||
formDate.getMonth() === txDate.getMonth() &&
|
||||
formDate.getDate() === txDate.getDate();
|
||||
|
||||
if(formDate.getTime() && !sameDay) {
|
||||
txDate = formDate;
|
||||
}
|
||||
|
||||
return txDate;
|
||||
}
|
||||
|
||||
deleteTransaction(item) {
|
||||
this.modalService.open(this.confirmDeleteModal).result.then((result) => {
|
||||
this.log.debug('delete');
|
||||
@@ -846,7 +829,7 @@ export class TxListPage implements OnInit, AfterViewChecked {
|
||||
item.tx = new Transaction(
|
||||
{
|
||||
id: item.tx.id,
|
||||
date: this.computeTransactionDate(formDate, new Date()),
|
||||
date: Util.computeTransactionDate(formDate, new Date()),
|
||||
description: tx.description,
|
||||
splits: tx.splits
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user