Feature: Tax Regimes are added so that different bills with different series can be printed for Different regimes such as VAT and GST

Chore: Model relationships updated to make them simpler
Chore: Bill printing majorly refactored for it

Due to the sheer depth of the changes. There can be showstoppers. Please test it carefully
This commit is contained in:
2023-03-05 23:50:41 +05:30
parent 802eded568
commit e46fe7f90e
141 changed files with 2197 additions and 892 deletions

View File

@ -1,7 +1,8 @@
import { Component, OnInit } from '@angular/core';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
import { FormControl, FormGroup } from '@angular/forms';
import { MatDialog } from '@angular/material/dialog';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
import { environment } from '../../environments/environment';
import { AuthService } from '../auth/auth.service';
@ -16,19 +17,28 @@ import { SettingsService } from './settings.service';
})
export class SettingsComponent implements OnInit {
prefillCustomerDiscount = true;
version: string;
maintenanceForm: FormGroup<{
startDate: FormControl<Date>;
finishDate: FormControl<Date>;
}>;
beerFile: File | null = null;
saleFile: File | null = null;
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: UntypedFormBuilder,
private dialog: MatDialog,
private toaster: ToasterService,
public auth: AuthService,
private ser: SettingsService,
) {
this.version = environment.version;
this.maintenanceForm = new FormGroup({
startDate: new FormControl(new Date(), { nonNullable: true }),
finishDate: new FormControl(new Date(), { nonNullable: true }),
});
}
ngOnInit() {
@ -46,4 +56,31 @@ export class SettingsComponent implements OnInit {
this.prefillCustomerDiscount = x;
});
}
detectBeer(event: Event) {
this.beerFile = ((event.target as HTMLInputElement).files as FileList)[0];
}
detectSale(event: Event) {
this.saleFile = ((event.target as HTMLInputElement).files as FileList)[0];
}
runMaintenance() {
const formModel = this.maintenanceForm.value;
const startDate = moment(formModel.startDate).format('DD-MMM-YYYY');
const finishDate = moment(formModel.finishDate).format('DD-MMM-YYYY');
if (!this.beerFile || !this.saleFile) {
this.toaster.show('Danger', 'Please choose both files first!');
return;
}
this.ser.runMaintenance(startDate, finishDate, this.beerFile, this.saleFile).subscribe(
() => {
this.toaster.show('Success', 'Maintenance done');
},
(error) => {
this.toaster.show('Danger', error);
},
);
}
}

View File

@ -26,4 +26,20 @@ export class SettingsService {
catchError(this.log.handleError(serviceName, 'setPrefillCustomerDiscount')),
) as Observable<boolean>;
}
runMaintenance(
startDate: string,
finishDate: string,
beerFile: File,
saleFile: File,
): Observable<boolean> {
const options = { params: new HttpParams().set('s', startDate).set('f', finishDate) };
const url = '/api/maintenance';
const fd = new FormData();
fd.append('beer_file', beerFile);
fd.append('sale_file', saleFile);
return this.http
.post<boolean>(url, fd, options)
.pipe(catchError(this.log.handleError(serviceName, 'runMaintenance'))) as Observable<boolean>;
}
}