Moved from tslint to eslint as tslint was depreciated.
Added prettier and also prettied all the typescript files using prettier ESLint is using the AirBnB rules which are the most strict to lint the files.
This commit is contained in:
1 parent
40e79ff949
commit
1350870f9e
545 files changed
+8455
-7036
No files matched your search
@@ -22,7 +22,7 @@ import { Hotkey, HotkeysService } from 'angular2-hotkeys';
|
||||
@Component({
|
||||
selector: 'app-journal',
|
||||
templateUrl: './journal.component.html',
|
||||
styleUrls: ['./journal.component.css']
|
||||
styleUrls: ['./journal.component.css'],
|
||||
})
|
||||
export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
@ViewChild('accountElement', { static: true }) accountElement: ElementRef;
|
||||
@@ -47,7 +47,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
private toaster: ToasterService,
|
||||
private auth: AuthService,
|
||||
private ser: VoucherService,
|
||||
private accountSer: AccountService
|
||||
private accountSer: AccountService,
|
||||
) {
|
||||
this.account = null;
|
||||
this.createForm();
|
||||
@@ -55,28 +55,49 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
this.route.data
|
||||
.subscribe((data: { voucher: Voucher }) => {
|
||||
this.loadVoucher(data.voucher);
|
||||
});
|
||||
this.hotkeys.add(new Hotkey('f2', (event: KeyboardEvent): boolean => {
|
||||
setTimeout(() => {
|
||||
this.dateElement.nativeElement.focus();
|
||||
}, 0);
|
||||
return false; // Prevent bubbling
|
||||
}, ['INPUT', 'SELECT', 'TEXTAREA']));
|
||||
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
|
||||
if (this.canSave()) {
|
||||
this.save();
|
||||
}
|
||||
return false; // Prevent bubbling
|
||||
}, ['INPUT', 'SELECT', 'TEXTAREA']));
|
||||
this.hotkeys.add(new Hotkey('ctrl+p', (event: KeyboardEvent): boolean => {
|
||||
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('post-vouchers') !== -1) {
|
||||
this.post();
|
||||
}
|
||||
return false; // Prevent bubbling
|
||||
}, ['INPUT', 'SELECT', 'TEXTAREA']));
|
||||
this.route.data.subscribe((data: { voucher: Voucher }) => {
|
||||
this.loadVoucher(data.voucher);
|
||||
});
|
||||
this.hotkeys.add(
|
||||
new Hotkey(
|
||||
'f2',
|
||||
(event: KeyboardEvent): boolean => {
|
||||
setTimeout(() => {
|
||||
this.dateElement.nativeElement.focus();
|
||||
}, 0);
|
||||
return false; // Prevent bubbling
|
||||
},
|
||||
['INPUT', 'SELECT', 'TEXTAREA'],
|
||||
),
|
||||
);
|
||||
this.hotkeys.add(
|
||||
new Hotkey(
|
||||
'ctrl+s',
|
||||
(event: KeyboardEvent): boolean => {
|
||||
if (this.canSave()) {
|
||||
this.save();
|
||||
}
|
||||
return false; // Prevent bubbling
|
||||
},
|
||||
['INPUT', 'SELECT', 'TEXTAREA'],
|
||||
),
|
||||
);
|
||||
this.hotkeys.add(
|
||||
new Hotkey(
|
||||
'ctrl+p',
|
||||
(event: KeyboardEvent): boolean => {
|
||||
if (
|
||||
this.voucher.id &&
|
||||
!this.voucher.posted &&
|
||||
this.auth.user.perms.indexOf('post-vouchers') !== -1
|
||||
) {
|
||||
this.post();
|
||||
}
|
||||
return false; // Prevent bubbling
|
||||
},
|
||||
['INPUT', 'SELECT', 'TEXTAREA'],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
@@ -94,9 +115,9 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
addRow: {
|
||||
debit: '1',
|
||||
account: '',
|
||||
amount: 0
|
||||
amount: 0,
|
||||
},
|
||||
narration: this.voucher.narration
|
||||
narration: this.voucher.narration,
|
||||
});
|
||||
this.dataSource = new JournalDataSource(this.journalObservable);
|
||||
this.journalObservable.next(this.voucher.journals);
|
||||
@@ -117,8 +138,8 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
const oldFiltered = this.voucher.journals.filter((x) => x.account.id === this.account.id);
|
||||
const old = oldFiltered.length ? oldFiltered[0] : null;
|
||||
if (old) {
|
||||
const a = (old.debit * old.amount) + (amount.debit * amount.amount);
|
||||
old.debit = (a < 0) ? -1 : 1;
|
||||
const a = old.debit * old.amount + amount.debit * amount.amount;
|
||||
old.debit = a < 0 ? -1 : 1;
|
||||
old.amount = Math.abs(a);
|
||||
} else {
|
||||
this.voucher.journals.push({
|
||||
@@ -126,7 +147,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
debit: amount.debit,
|
||||
amount: amount.amount,
|
||||
account: this.account,
|
||||
costCentre: null
|
||||
costCentre: null,
|
||||
});
|
||||
}
|
||||
this.journalObservable.next(this.voucher.journals);
|
||||
@@ -135,24 +156,26 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
rowAmount(amount: string = '', debit: number): any {
|
||||
try {
|
||||
amount = amount.replace(new RegExp('(₹[\s]*)|(,)|(\s)', 'g'), '');
|
||||
amount = amount.replace(new RegExp('(₹[s]*)|(,)|(s)', 'g'), '');
|
||||
const val = evaluate(amount);
|
||||
if (val < 0) {
|
||||
debit *= -1;
|
||||
}
|
||||
return {debit: debit, amount: Math.abs(val)};
|
||||
return { debit: debit, amount: Math.abs(val) };
|
||||
} catch {
|
||||
return {debit: debit, amount: 0};
|
||||
return { debit: debit, amount: 0 };
|
||||
}
|
||||
}
|
||||
|
||||
resetAddRow() {
|
||||
const amount = Math.abs(this.voucher.journals.map((x) => x.debit * x.amount).reduce((p, c) => p + c));
|
||||
const amount = Math.abs(
|
||||
this.voucher.journals.map((x) => x.debit * x.amount).reduce((p, c) => p + c),
|
||||
);
|
||||
const debit = this.form.get('addRow').value.debit;
|
||||
this.form.get('addRow').reset({
|
||||
debit: debit,
|
||||
account: null,
|
||||
amount: '' + amount
|
||||
amount: '' + amount,
|
||||
});
|
||||
this.account = null;
|
||||
this.accBal = null;
|
||||
@@ -164,7 +187,10 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
editRow(row: Journal) {
|
||||
const dialogRef = this.dialog.open(JournalDialogComponent, {
|
||||
width: '750px',
|
||||
data: {journal: Object.assign({}, row), date: moment(this.form.get('date').value).format('DD-MMM-YYYY')}
|
||||
data: {
|
||||
journal: Object.assign({}, row),
|
||||
date: moment(this.form.get('date').value).format('DD-MMM-YYYY'),
|
||||
},
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean | Journal) => {
|
||||
@@ -172,7 +198,10 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
return;
|
||||
}
|
||||
const j = result as Journal;
|
||||
if (j.account.id !== row.account.id && this.voucher.journals.filter((x) => x.account.id === j.account.id).length) {
|
||||
if (
|
||||
j.account.id !== row.account.id &&
|
||||
this.voucher.journals.filter((x) => x.account.id === j.account.id).length
|
||||
) {
|
||||
return;
|
||||
}
|
||||
Object.assign(row, j);
|
||||
@@ -184,9 +213,11 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
deleteRow(row: Journal) {
|
||||
this.voucher.journals.splice(this.voucher.journals.indexOf(row), 1);
|
||||
this.journalObservable.next(this.voucher.journals);
|
||||
const amount = Math.abs(this.voucher.journals.map((x) => x.debit * x.amount).reduce((p, c) => p + c, 0));
|
||||
const amount = Math.abs(
|
||||
this.voucher.journals.map((x) => x.debit * x.amount).reduce((p, c) => p + c, 0),
|
||||
);
|
||||
this.form.get('addRow').patchValue({
|
||||
amount: amount
|
||||
amount: amount,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -196,9 +227,9 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
addRow: this.fb.group({
|
||||
debit: '1',
|
||||
account: '',
|
||||
amount: ''
|
||||
amount: '',
|
||||
}),
|
||||
narration: ''
|
||||
narration: '',
|
||||
});
|
||||
this.accBal = null;
|
||||
}
|
||||
@@ -209,39 +240,40 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
} else if (this.voucher.posted && this.auth.user.perms.indexOf('edit-posted-vouchers') !== -1) {
|
||||
return true;
|
||||
} else {
|
||||
return this.voucher.user.id === this.auth.user.id || this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1;
|
||||
return (
|
||||
this.voucher.user.id === this.auth.user.id ||
|
||||
this.auth.user.perms.indexOf("edit-other-user's-vouchers") !== -1
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
post() {
|
||||
this.ser.post(this.voucher.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.loadVoucher(result);
|
||||
this.toaster.show('Success', 'Voucher Posted');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.post(this.voucher.id).subscribe(
|
||||
(result) => {
|
||||
this.loadVoucher(result);
|
||||
this.toaster.show('Success', 'Voucher Posted');
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
save() {
|
||||
const voucher: Voucher = this.getVoucher();
|
||||
this.ser.saveOrUpdate(voucher)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
if (voucher.id === result.id) {
|
||||
this.loadVoucher(result);
|
||||
} else {
|
||||
this.ser.saveOrUpdate(voucher).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
if (voucher.id === result.id) {
|
||||
this.loadVoucher(result);
|
||||
} else {
|
||||
this.router.navigate(['/journal', result.id]);
|
||||
}
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
getVoucher(): Voucher {
|
||||
@@ -252,22 +284,21 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
delete() {
|
||||
this.ser.delete(this.voucher.id)
|
||||
.subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/journal'], {replaceUrl: true});
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
}
|
||||
);
|
||||
this.ser.delete(this.voucher.id).subscribe(
|
||||
(result) => {
|
||||
this.toaster.show('Success', '');
|
||||
this.router.navigate(['/journal'], { replaceUrl: true });
|
||||
},
|
||||
(error) => {
|
||||
this.toaster.show('Danger', error);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
confirmDelete(): void {
|
||||
const dialogRef = this.dialog.open(ConfirmDialogComponent, {
|
||||
width: '250px',
|
||||
data: {title: 'Delete Voucher?', content: 'Are you sure? This cannot be undone.'}
|
||||
data: { title: 'Delete Voucher?', content: 'Are you sure? This cannot be undone.' },
|
||||
});
|
||||
|
||||
dialogRef.afterClosed().subscribe((result: boolean) => {
|
||||
@@ -279,15 +310,13 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
setupAccountAutocomplete(): void {
|
||||
const control = this.form.get('addRow').get('account');
|
||||
this.accounts = control.valueChanges
|
||||
.pipe(
|
||||
startWith(null),
|
||||
map(x => (x !== null && x.length >= 1) ? x : null),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap(x => (x === null) ? observableOf([]) : this.accountSer.autocomplete(x))
|
||||
);
|
||||
|
||||
this.accounts = control.valueChanges.pipe(
|
||||
startWith(null),
|
||||
map((x) => (x !== null && x.length >= 1 ? x : null)),
|
||||
debounceTime(150),
|
||||
distinctUntilChanged(),
|
||||
switchMap((x) => (x === null ? observableOf([]) : this.accountSer.autocomplete(x))),
|
||||
);
|
||||
}
|
||||
|
||||
displayAccount(account?: Account): string | undefined {
|
||||
@@ -305,7 +334,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
zoomImage(file: DbFile) {
|
||||
this.dialog.open(ImageDialogComponent, {
|
||||
width: '750px',
|
||||
data: file.resized
|
||||
data: file.resized,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -320,11 +349,12 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
for (const file of files) {
|
||||
const reader = new FileReader();
|
||||
reader.onload = (e: any) => {
|
||||
zip(observableOf(e.target.result),
|
||||
zip(
|
||||
observableOf(e.target.result),
|
||||
this.resizeImage(e.target.result, 100, 150),
|
||||
this.resizeImage(e.target.result, 825, 1170)
|
||||
).subscribe(
|
||||
val => this.voucher.files.push({id: null, thumbnail: val[1], resized: val[2]})
|
||||
this.resizeImage(e.target.result, 825, 1170),
|
||||
).subscribe((val) =>
|
||||
this.voucher.files.push({ id: null, thumbnail: val[1], resized: val[2] }),
|
||||
);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
@@ -353,7 +383,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
|
||||
canvas.height = height;
|
||||
ctx.drawImage(img, 0, 0, width, height);
|
||||
return canvas.toDataURL('image/jpeg', 0.95);
|
||||
})
|
||||
}),
|
||||
);
|
||||
img.src = image;
|
||||
return ex;
|
||||
|
||||
Reference in new issue
Block a user