Feature: Tax Analysis

This commit is contained in:
Amritanshu
2019-08-21 08:32:12 +05:30
parent abc29844d3
commit 241568622e
20 changed files with 430 additions and 20 deletions

2
.gitignore vendored
View File

@ -5,7 +5,7 @@ env
*/__pycache__/
.idea/
*.egg-info/
DB/*.sql
DB/Data/*.sql
barker/static/
build/
dist/

View File

@ -358,8 +358,8 @@ def includeme(config):
config.add_route("v1_checkout_blank", "/v1/checkout")
config.add_route("v1_sa_sale", "/v1/sale-analysis/sale")
config.add_route("v1_sa_settlements", "/v1_sale-analysis/settlements")
config.add_route("v1_sa_tax", "/v1_sale-analysis/tax")
config.add_route("v1_sa_settlements", "/v1/sale-analysis/settlements")
config.add_route("v1_sa_tax", "/v1/sale-analysis/tax")
config.add_route("v1_sale_analysis", "/v1/sale-analysis")
# Done till here

View File

@ -138,29 +138,18 @@ def get_settlements(start_date, finish_date, dbsession):
permission=("Tax Analysis", "Sales Analysis"),
)
def get_tax_view(request):
start_date = request.GET.get("s", None)
if not start_date:
start_date = datetime.today().replace(hour=7, minute=0)
else:
start_date = datetime.strptime(start_date, "%d-%b-%Y").replace(hour=7, minute=0)
finish_date = request.GET.get("f", None)
if not finish_date:
finish_date = datetime.today().replace(hour=7, minute=0) + timedelta(days=1)
else:
finish_date = datetime.strptime(finish_date, "%d-%b-%Y").replace(
hour=7, minute=0
) + timedelta(days=1)
start_date = get_start_date(request.GET.get("s", None))
finish_date = get_finish_date(request.GET.get("f", None))
if (
datetime.date().today() - start_date.date()
datetime.today() - start_date.replace(hour=0)
).days > 5 and "Accounts Audit" not in request.effective_principals:
raise ValidationError("Accounts Audit")
return {
"startDate": start_date.date().strftime("%d-%b-%Y"),
"finishDate": (finish_date - timedelta(days=1)).date().strftime("%d-%b-%Y"),
"amounts": get_settlements(start_date, finish_date, request.dbsession),
"amounts": get_tax(start_date, finish_date, request.dbsession),
}
@ -188,7 +177,7 @@ def get_tax(start_date, finish_date, dbsession):
{
"name": "{0} - {1:.2%}".format(i[0], i[1]),
"taxRate": i[1],
"netSale": i[2],
"saleAmount": i[2],
"amount": i[3],
}
for i in amounts

View File

@ -69,6 +69,10 @@ const routes: Routes = [
path: 'taxes',
loadChildren: () => import('./taxes/taxes.module').then(mod => mod.TaxesModule)
},
{
path: 'tax-analysis',
loadChildren: () => import('./tax-analysis/tax-analysis.module').then(mod => mod.TaxAnalysisModule)
},
{
path: 'users',
loadChildren: () => import('./users/users.module').then(mod => mod.UsersModule)

View File

@ -17,6 +17,9 @@
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Sales Analysis')" [routerLink]="['/', 'sale-analysis']">
<h3 class="item-name">Sale Analysis</h3>
</mat-card>
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Tax Analysis')" [routerLink]="['/', 'tax-analysis']">
<h3 class="item-name">Tax Analysis</h3>
</mat-card>
<mat-card fxLayout="column" class="square-button" matRipple *ngIf="auth.hasPermission('Tables')" [routerLink]="['/', 'tables']">
<h3 class="item-name">Tables</h3>
</mat-card>

View File

@ -30,7 +30,7 @@ export class SaleAnalysisService {
}
return <Observable<SaleAnalysis>>this.http.get<SaleAnalysis>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'list'))
catchError(this.log.handleError(serviceName, 'get'))
);
}
}

View File

@ -0,0 +1,18 @@
import { DataSource } from '@angular/cdk/collections';
import { Observable, of as observableOf } from 'rxjs';
import { TaxAnalysisItem } from './tax-analysis';
export class TaxAnalysisDataSource extends DataSource<TaxAnalysisItem> {
constructor(public data: TaxAnalysisItem[]) {
super();
}
connect(): Observable<TaxAnalysisItem[]> {
return observableOf(this.data);
}
disconnect() {
}
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {TaxAnalysisResolver} from './tax-analysis-resolver.service';
describe('TaxAnalysisResolver', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [TaxAnalysisResolver]
});
});
it('should be created', inject([TaxAnalysisResolver], (service: TaxAnalysisResolver) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,20 @@
import {Injectable} from '@angular/core';
import {ActivatedRouteSnapshot, Resolve, RouterStateSnapshot} from '@angular/router';
import {Observable} from 'rxjs/internal/Observable';
import {TaxAnalysis} from './tax-analysis';
import {TaxAnalysisService} from './tax-analysis.service';
@Injectable({
providedIn: 'root'
})
export class TaxAnalysisResolver implements Resolve<TaxAnalysis> {
constructor(private ser: TaxAnalysisService) {
}
resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<TaxAnalysis> {
const startDate = route.queryParamMap.get('startDate') || null;
const finishDate = route.queryParamMap.get('finishDate') || null;
return this.ser.get(startDate, finishDate);
}
}

View File

@ -0,0 +1,13 @@
import {TaxAnalysisRoutingModule} from './tax-analysis-routing.module';
describe('TaxAnalysisRoutingModule', () => {
let taxAnalysisRoutingModule: TaxAnalysisRoutingModule;
beforeEach(() => {
taxAnalysisRoutingModule = new TaxAnalysisRoutingModule();
});
it('should create an instance', () => {
expect(taxAnalysisRoutingModule).toBeTruthy();
});
});

View File

@ -0,0 +1,37 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { RouterModule, Routes } from '@angular/router';
import { TaxAnalysisResolver } from './tax-analysis-resolver.service';
import { AuthGuard } from '../auth/auth-guard.service';
import { TaxAnalysisComponent } from './tax-analysis.component';
const TaxAnalysisRoutes: Routes = [
{
path: '',
component: TaxAnalysisComponent,
canActivate: [AuthGuard],
data: {
permission: 'Tax Analysis'
},
resolve: {
info: TaxAnalysisResolver
},
runGuardsAndResolvers: 'always'
}
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(TaxAnalysisRoutes)
],
exports: [
RouterModule
],
providers: [
TaxAnalysisResolver
]
})
export class TaxAnalysisRoutingModule {
}

View File

@ -0,0 +1,4 @@
.right {
display: flex;
justify-content: flex-end;
}

View File

@ -0,0 +1,57 @@
<mat-card>
<mat-card-title-group>
<mat-card-title>Tax Analysis</mat-card-title>
<button mat-button mat-icon-button (click)="exportCsv()">
<mat-icon>save_alt</mat-icon>
</button>
</mat-card-title-group>
<mat-card-content>
<form [formGroup]="form" fxLayout="column">
<div fxLayout="row" fxLayout.lt-md="column" fxLayoutGap="20px" fxLayoutGap.lt-md="0px"
fxLayoutAlign="space-around start">
<mat-form-field fxFlex="40">
<input matInput [matDatepicker]="startDate" (focus)="startDate.open()" placeholder="Start Date"
formControlName="startDate" autocomplete="off">
<mat-datepicker-toggle matSuffix [for]="startDate"></mat-datepicker-toggle>
<mat-datepicker #startDate></mat-datepicker>
</mat-form-field>
<mat-form-field fxFlex="40">
<input matInput [matDatepicker]="finishDate" (focus)="finishDate.open()" placeholder="Finish Date"
formControlName="finishDate" autocomplete="off">
<mat-datepicker-toggle matSuffix [for]="finishDate"></mat-datepicker-toggle>
<mat-datepicker #finishDate></mat-datepicker>
</mat-form-field>
<button fxFlex="20" mat-raised-button color="primary" (click)="show()">Show</button>
</div>
</form>
<mat-table #table [dataSource]="dataSource" aria-label="Elements">
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.name}}</mat-cell>
</ng-container>
<!-- Tax Rate Column -->
<ng-container matColumnDef="taxRate">
<mat-header-cell *matHeaderCellDef class="right">Rate</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.taxRate | percent:'1.2-2'}}</mat-cell>
</ng-container>
<!-- Sale Amount Column -->
<ng-container matColumnDef="saleAmount">
<mat-header-cell *matHeaderCellDef class="right">Sale</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.saleAmount | currency:'INR'}}</mat-cell>
</ng-container>
<!-- Tax Amount Column -->
<ng-container matColumnDef="taxAmount">
<mat-header-cell *matHeaderCellDef class="right">Tax</mat-header-cell>
<mat-cell *matCellDef="let row" class="right">{{row.amount | currency:'INR'}}</mat-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
</mat-table>
</mat-card-content>
</mat-card>

View File

@ -0,0 +1,25 @@
import {async, ComponentFixture, TestBed} from '@angular/core/testing';
import {TaxAnalysisComponent} from './tax-analysis.component';
describe('TaxAnalysisComponent', () => {
let component: TaxAnalysisComponent;
let fixture: ComponentFixture<TaxAnalysisComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [TaxAnalysisComponent]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(TaxAnalysisComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,90 @@
import { Component, OnInit } from '@angular/core';
import { FormBuilder, FormGroup } from '@angular/forms';
import { ActivatedRoute, Router } from '@angular/router';
import * as moment from 'moment';
import { TaxAnalysisDataSource } from './tax-analysis-datasource';
import { TaxAnalysis } from './tax-analysis';
import { ToCsvService } from '../shared/to-csv.service';
@Component({
selector: 'app-tax-analysis',
templateUrl: './tax-analysis.component.html',
styleUrls: ['./tax-analysis.component.css']
})
export class TaxAnalysisComponent implements OnInit {
dataSource: TaxAnalysisDataSource;
form: FormGroup;
info: TaxAnalysis;
/** Columns displayed in the table. Columns IDs can be added, removed, or reordered. */
displayedColumns = ['name', 'taxRate', 'saleAmount', 'taxAmount'];
constructor(
private route: ActivatedRoute,
private router: Router,
private fb: FormBuilder,
private toCsv: ToCsvService
) {
this.createForm();
}
ngOnInit() {
this.route.data
.subscribe((data: { info: TaxAnalysis }) => {
this.info = data.info;
this.form.setValue({
startDate: moment(this.info.startDate, 'DD-MMM-YYYY').toDate(),
finishDate: moment(this.info.finishDate, 'DD-MMM-YYYY').toDate()
});
this.dataSource = new TaxAnalysisDataSource(this.info.amounts);
});
}
show() {
const info = this.getInfo();
this.router.navigate(['tax-analysis'], {
queryParams: {
startDate: info.startDate,
finishDate: info.finishDate
}
});
}
createForm() {
this.form = this.fb.group({
startDate: '',
finishDate: ''
});
}
getInfo(): TaxAnalysis {
const formModel = this.form.value;
return {
startDate: moment(formModel.startDate).format('DD-MMM-YYYY'),
finishDate: moment(formModel.finishDate).format('DD-MMM-YYYY')
};
}
exportCsv() {
const headers = {
Date: 'date',
Name: 'name',
Type: 'type',
Narration: 'narration',
Debit: 'debit',
Credit: 'credit',
Running: 'running',
Posted: 'posted'
};
const csvData = new Blob([this.toCsv.toCsv(headers, this.dataSource.data)], {type: 'text/csv;charset=utf-8;'});
const link = document.createElement('a');
link.href = window.URL.createObjectURL(csvData);
link.setAttribute('download', 'tax-analysis.csv');
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
}
}

View File

@ -0,0 +1,13 @@
import {TaxAnalysisModule} from './tax-analysis.module';
describe('TaxAnalysisModule', () => {
let taxAnalysisModule: TaxAnalysisModule;
beforeEach(() => {
taxAnalysisModule = new TaxAnalysisModule();
});
it('should create an instance', () => {
expect(taxAnalysisModule).toBeTruthy();
});
});

View File

@ -0,0 +1,61 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { MatAutocompleteModule } from '@angular/material/autocomplete';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { DateAdapter, MAT_DATE_FORMATS, MAT_DATE_LOCALE, MatNativeDateModule } from '@angular/material/core';
import { MatDatepickerModule } from '@angular/material/datepicker';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatTableModule } from '@angular/material/table';
import { SharedModule} from '../shared/shared.module';
import { ReactiveFormsModule } from '@angular/forms';
import { CdkTableModule } from '@angular/cdk/table';
import { TaxAnalysisRoutingModule } from './tax-analysis-routing.module';
import { TaxAnalysisComponent } from './tax-analysis.component';
import { MomentDateAdapter } from '@angular/material-moment-adapter';
import { A11yModule } from '@angular/cdk/a11y';
import { FlexLayoutModule } from '@angular/flex-layout';
export const MY_FORMATS = {
parse: {
dateInput: 'DD-MMM-YYYY',
},
display: {
dateInput: 'DD-MMM-YYYY',
monthYearLabel: 'MMM YYYY',
dateA11yLabel: 'DD-MMM-YYYY',
monthYearA11yLabel: 'MMM YYYY',
},
};
@NgModule({
imports: [
A11yModule,
CommonModule,
CdkTableModule,
FlexLayoutModule,
MatAutocompleteModule,
MatButtonModule,
MatCardModule,
MatDatepickerModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatNativeDateModule,
MatTableModule,
ReactiveFormsModule,
SharedModule,
TaxAnalysisRoutingModule
],
declarations: [
TaxAnalysisComponent
],
providers: [
{provide: DateAdapter, useClass: MomentDateAdapter, deps: [MAT_DATE_LOCALE]},
{provide: MAT_DATE_FORMATS, useValue: MY_FORMATS},
]
})
export class TaxAnalysisModule {
}

View File

@ -0,0 +1,15 @@
import {inject, TestBed} from '@angular/core/testing';
import {TaxAnalysisService} from './tax-analysis.service';
describe('TaxAnalysisService', () => {
beforeEach(() => {
TestBed.configureTestingModule({
providers: [TaxAnalysisService]
});
});
it('should be created', inject([TaxAnalysisService], (service: TaxAnalysisService) => {
expect(service).toBeTruthy();
}));
});

View File

@ -0,0 +1,36 @@
import { Injectable } from '@angular/core';
import { catchError } from 'rxjs/operators';
import { Observable } from 'rxjs/internal/Observable';
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
import { TaxAnalysis } from './tax-analysis';
import { ErrorLoggerService } from '../core/error-logger.service';
const httpOptions = {
headers: new HttpHeaders({'Content-Type': 'application/json'})
};
const url = '/v1/sale-analysis/tax';
const serviceName = 'TaxAnalysisService';
@Injectable({
providedIn: 'root'
})
export class TaxAnalysisService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {
}
get(startDate: string, finishDate): Observable<TaxAnalysis> {
const options = {params: new HttpParams()};
if (startDate !== null) {
options.params = options.params.set('s', startDate);
}
if (finishDate !== null) {
options.params = options.params.set('f', finishDate);
}
return <Observable<TaxAnalysis>>this.http.get<TaxAnalysis>(url, options)
.pipe(
catchError(this.log.handleError(serviceName, 'get'))
);
}
}

View File

@ -0,0 +1,10 @@
export class TaxAnalysisItem {
name: string;
amount: number;
}
export class TaxAnalysis {
startDate: string;
finishDate: string;
amounts?: TaxAnalysisItem[];
}