Renamed "Salary Deduction" to "Employee Benefit"

Journal, Purchase and Purchase Return vouchers done!!

Changed the column type of "date" columns from "datetime" to better fit the data.
This commit is contained in:
tanshu
2020-05-21 13:11:47 +05:30
parent a0f27fe364
commit 98edca5f60
35 changed files with 977 additions and 894 deletions

View File

@ -3,7 +3,7 @@
<mat-menu #voucherMenu="matMenu">
<a mat-menu-item routerLink="/journal">Journal</a>
<a mat-menu-item routerLink="/purchase">Purchase</a>
<a mat-menu-item routerLink="/return">Purchase Return</a>
<a mat-menu-item routerLink="/purchase-return">Purchase Return</a>
<a mat-menu-item routerLink="/payment">Payment</a>
<a mat-menu-item routerLink="/receipt">Receipt</a>
<a mat-menu-item routerLink="/issue">Issue</a>

View File

@ -63,9 +63,16 @@ export class VoucherService {
);
}
save(voucher: Voucher): Observable<Voucher> {
saveOrUpdate(voucher: Voucher): Observable<Voucher> {
const endpoint = voucher.type.replace(/ /g, '-').toLowerCase();
if (!voucher.id) {
return this.save(voucher, endpoint);
} else {
return this.update(voucher, endpoint);
}
}
save(voucher: Voucher, endpoint: string): Observable<Voucher> {
const fd = new FormData();
voucher.files.filter(x => !x.id).forEach((file) => {
fd.append('i' , this.dataURLtoBlob(file.resized));
@ -73,10 +80,23 @@ export class VoucherService {
});
voucher.files = voucher.files.filter(x => x.id);
fd.append('data', JSON.stringify(voucher));
const saveUrl: string = (voucher.id === undefined || voucher.id === null) ? `${url}/${endpoint}` : `${url}/${endpoint}/${voucher.id}`;
return <Observable<Voucher>>this.http.post<Voucher>(saveUrl, fd)
return <Observable<Voucher>>this.http.post<Voucher>(`${url}/${endpoint}`, fd)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
catchError(this.log.handleError(serviceName, 'save'))
);
}
update(voucher: Voucher, endpoint: string): Observable<Voucher> {
const fd = new FormData();
voucher.files.filter(x => !x.id).forEach((file) => {
fd.append('i' , this.dataURLtoBlob(file.resized));
fd.append('t' , this.dataURLtoBlob(file.thumbnail));
});
voucher.files = voucher.files.filter(x => x.id);
fd.append('data', JSON.stringify(voucher));
return <Observable<Voucher>>this.http.put<Voucher>(`${url}/${endpoint}/${voucher.id}`, fd)
.pipe(
catchError(this.log.handleError(serviceName, 'update'))
);
}

View File

@ -10,6 +10,7 @@ export class Voucher {
posted: boolean;
narration: string;
incentive?: number;
vendor?: Account;
journals: Journal[];
inventories: Inventory[];
employeeBenefits: EmployeeBenefit[];

View File

@ -191,7 +191,7 @@ export class EmployeeBenefitsComponent implements OnInit, AfterViewInit {
}
save() {
this.ser.save(this.getVoucher())
this.ser.saveOrUpdate(this.getVoucher())
.subscribe(
(result) => {
this.toaster.show('Success', '');

View File

@ -141,7 +141,7 @@ export class IncentiveComponent implements OnInit {
}
save() {
this.ser.save(this.getVoucher())
this.ser.saveOrUpdate(this.getVoucher())
.subscribe(
(result) => {
this.toaster.show('Success', '');

View File

@ -223,7 +223,7 @@ export class IssueComponent implements OnInit, AfterViewInit, OnDestroy {
}
save() {
this.ser.save(this.getVoucher())
this.ser.saveOrUpdate(this.getVoucher())
.subscribe(
(result) => {
this.loadVoucher(result);

View File

@ -224,7 +224,7 @@ export class JournalComponent implements OnInit, AfterViewInit, OnDestroy {
}
save() {
this.ser.save(this.getVoucher())
this.ser.saveOrUpdate(this.getVoucher())
.subscribe(
(result) => {
this.loadVoucher(result);

View File

@ -228,7 +228,7 @@ export class PaymentComponent implements OnInit, AfterViewInit, OnDestroy {
}
save() {
this.ser.save(this.getVoucher())
this.ser.saveOrUpdate(this.getVoucher())
.subscribe(
(result) => {
this.loadVoucher(result);

View File

@ -8,7 +8,7 @@ import {PurchaseReturnDataSource} from './purchase-return-datasource';
import {Account} from '../core/account';
import {VoucherService} from '../core/voucher.service';
import {AccountService} from '../core/account.service';
import {Batch, DbFile, Inventory, Journal, Voucher} from '../core/voucher';
import {Batch, DbFile, Inventory, Voucher} from '../core/voucher';
import * as moment from 'moment';
import {AuthService} from '../auth/auth.service';
import {ConfirmDialogComponent} from '../shared/confirm-dialog/confirm-dialog.component';
@ -17,7 +17,7 @@ import {debounceTime, distinctUntilChanged, map, startWith, switchMap} from 'rxj
import {PurchaseReturnDialogComponent} from './purchase-return-dialog.component';
import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component';
import {BatchService} from '../core/batch.service';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
import {Hotkey, HotkeysService} from 'angular2-hotkeys';
@Component({
selector: 'app-purchase-return',
@ -31,9 +31,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
public inventoryObservable = new BehaviorSubject<Inventory[]>([]);
dataSource: PurchaseReturnDataSource;
form: FormGroup;
purchaseReturnJournal: Journal;
voucher: Voucher;
account: Account;
batch: Batch;
accBal: any;
@ -71,13 +69,15 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
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)
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('Post Vouchers') !== -1) {
this.post();
}
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
}
@ -92,11 +92,10 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
loadVoucher(voucher: Voucher) {
this.voucher = voucher;
this.purchaseReturnJournal = this.voucher.journals.filter(x => x.debit === 1)[0];
this.form.setValue({
date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(),
account: this.purchaseReturnJournal.account,
amount: this.purchaseReturnJournal.amount,
account: this.voucher.vendor,
amount: Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)),
addRow: {
batch: '',
quantity: ''
@ -152,8 +151,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
updateView() {
this.inventoryObservable.next(this.voucher.inventories);
this.purchaseReturnJournal.amount = Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0));
this.form.get('amount').setValue(this.purchaseReturnJournal.amount);
this.form.get('amount').setValue(Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)));
}
editRow(row: Inventory) {
@ -217,12 +215,12 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
}
save() {
this.ser.save(this.getVoucher())
this.ser.saveOrUpdate(this.getVoucher())
.subscribe(
(result) => {
this.loadVoucher(result);
this.toaster.show('Success', '');
this.router.navigate(['/return', result.id]);
this.router.navigate(['/purchase-return', result.id]);
},
(error) => {
this.toaster.show('Danger', error.error);
@ -233,7 +231,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
getVoucher(): Voucher {
const formModel = this.form.value;
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY');
this.purchaseReturnJournal.account = formModel.account;
this.voucher.vendor = formModel.account;
this.voucher.narration = formModel.narration;
return this.voucher;
}
@ -243,7 +241,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
.subscribe(
(result) => {
this.toaster.show('Success', '');
this.router.navigate(['/return'], {replaceUrl: true});
this.router.navigate(['/purchase-return'], {replaceUrl: true});
},
(error) => {
this.toaster.show('Danger', error.error);
@ -297,7 +295,7 @@ export class PurchaseReturnComponent implements OnInit, AfterViewInit, OnDestroy
}
accountSelected(event: MatAutocompleteSelectedEvent): void {
this.account = event.option.value;
this.form.get('account').setValue(event.option.value);
}
displayBatchName(batch?: Batch): string | undefined {

View File

@ -8,7 +8,7 @@ import {PurchaseDataSource} from './purchase-datasource';
import {Account} from '../core/account';
import {VoucherService} from '../core/voucher.service';
import {AccountService} from '../core/account.service';
import {DbFile, Inventory, Journal, Voucher} from '../core/voucher';
import {DbFile, Inventory, Voucher} from '../core/voucher';
import * as moment from 'moment';
import {AuthService} from '../auth/auth.service';
import {ConfirmDialogComponent} from '../shared/confirm-dialog/confirm-dialog.component';
@ -18,7 +18,7 @@ import {PurchaseDialogComponent} from './purchase-dialog.component';
import {ImageDialogComponent} from '../shared/image-dialog/image-dialog.component';
import {ProductService} from '../product/product.service';
import {Product} from '../core/product';
import {Hotkey, HotkeysService} from "angular2-hotkeys";
import {Hotkey, HotkeysService} from 'angular2-hotkeys';
@Component({
selector: 'app-purchase',
@ -32,9 +32,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
public inventoryObservable = new BehaviorSubject<Inventory[]>([]);
dataSource: PurchaseDataSource;
form: FormGroup;
purchaseJournal: Journal;
voucher: Voucher;
account: Account;
product: Product;
accBal: any;
@ -72,13 +70,15 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
this.hotkeys.add(new Hotkey('ctrl+s', (event: KeyboardEvent): boolean => {
if (this.canSave())
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)
if (this.voucher.id && !this.voucher.posted && this.auth.user.perms.indexOf('Post Vouchers') !== -1) {
this.post();
}
return false; // Prevent bubbling
}, ['INPUT', 'SELECT', 'TEXTAREA']));
}
@ -93,11 +93,10 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
loadVoucher(voucher) {
this.voucher = voucher;
this.purchaseJournal = this.voucher.journals.filter(x => x.debit === -1)[0];
this.form.setValue({
date: moment(this.voucher.date, 'DD-MMM-YYYY').toDate(),
account: this.purchaseJournal.account,
amount: this.purchaseJournal.amount,
account: this.voucher.vendor,
amount: Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)),
addRow: {
product: '',
quantity: '',
@ -161,8 +160,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
updateView() {
this.inventoryObservable.next(this.voucher.inventories);
this.purchaseJournal.amount = Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0));
this.form.get('amount').setValue(this.purchaseJournal.amount);
this.form.get('amount').setValue(Math.abs(this.voucher.inventories.map((x) => x.amount).reduce((p, c) => p + c, 0)));
}
editRow(row: Inventory) {
@ -230,7 +228,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
}
save() {
this.ser.save(this.getVoucher())
this.ser.saveOrUpdate(this.getVoucher())
.subscribe(
(result) => {
this.loadVoucher(result);
@ -246,7 +244,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
getVoucher(): Voucher {
const formModel = this.form.value;
this.voucher.date = moment(formModel.date).format('DD-MMM-YYYY');
this.purchaseJournal.account = formModel.account;
this.voucher.vendor = formModel.account;
this.voucher.narration = formModel.narration;
return this.voucher;
}
@ -306,7 +304,7 @@ export class PurchaseComponent implements OnInit, AfterViewInit, OnDestroy {
}
accountSelected(event: MatAutocompleteSelectedEvent): void {
this.account = event.option.value;
this.form.get('account').setValue(event.option.value);
}
displayProductName(product?: Product): string | undefined {

View File

@ -227,7 +227,7 @@ export class ReceiptComponent implements OnInit, AfterViewInit, OnDestroy {
}
save() {
this.ser.save(this.getVoucher())
this.ser.saveOrUpdate(this.getVoucher())
.subscribe(
(result) => {
this.loadVoucher(result);