Blacked and isorted the python files

Prettied and eslinted the typescript/html files
This commit is contained in:
2020-10-11 10:56:29 +05:30
parent b31db593c2
commit d677cfb1ea
505 changed files with 7560 additions and 5650 deletions

View File

@ -1,16 +1,14 @@
import { DataSource } from '@angular/cdk/collections';
import { Observable, of as observableOf } from 'rxjs';
export class ReceivePaymentDatasource extends DataSource<{name: string, discount: number}> {
constructor(private data: {name: string, discount: number}[]) {
export class ReceivePaymentDatasource extends DataSource<{ name: string; discount: number }> {
constructor(private data: { name: string; discount: number }[]) {
super();
}
connect(): Observable<{name: string, discount: number}[]> {
connect(): Observable<{ name: string; discount: number }[]> {
return observableOf(this.data);
}
disconnect() {
}
disconnect() {}
}

View File

@ -2,27 +2,30 @@
<mat-dialog-content>
<form [formGroup]="form" fxLayout="column">
<mat-table #table [dataSource]="dataSource" formArrayName="amounts">
<!-- Name Column -->
<ng-container matColumnDef="name">
<mat-header-cell *matHeaderCellDef class="bold">Amount</mat-header-cell>
<mat-cell *matCellDef="let row">{{row.name}}</mat-cell>
<mat-cell *matCellDef="let row">{{ row.name }}</mat-cell>
<mat-footer-cell *matFooterCellDef class="bold">Balance</mat-footer-cell>
</ng-container>
<!-- Discount Column -->
<ng-container matColumnDef="amount">
<mat-header-cell *matHeaderCellDef class="center bold" fxFlex>{{ amount | currency:'INR'}}</mat-header-cell>
<mat-header-cell *matHeaderCellDef class="center bold" fxFlex>{{
amount | currency: 'INR'
}}</mat-header-cell>
<mat-cell *matCellDef="let row; let i = index" class="center" [formGroupName]="i" fxFlex>
<mat-form-field>
<input matInput type="number" formControlName="amount" autocomplete="off">
<input matInput type="number" formControlName="amount" autocomplete="off" />
</mat-form-field>
</mat-cell>
<mat-footer-cell *matFooterCellDef class="bold">{{ balance | currency:'INR' }}</mat-footer-cell>
<mat-footer-cell *matFooterCellDef class="bold">{{
balance | currency: 'INR'
}}</mat-footer-cell>
</ng-container>
<mat-header-row *matHeaderRowDef="displayedColumns"></mat-header-row>
<mat-row *matRowDef="let row; columns: displayedColumns;"></mat-row>
<mat-row *matRowDef="let row; columns: displayedColumns"></mat-row>
<mat-footer-row *matFooterRowDef="displayedColumns"></mat-footer-row>
</mat-table>
</form>

View File

@ -8,9 +8,8 @@ describe('ReceivePaymentComponent', () => {
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ ReceivePaymentComponent ]
})
.compileComponents();
declarations: [ReceivePaymentComponent],
}).compileComponents();
}));
beforeEach(() => {

View File

@ -1,14 +1,16 @@
import { Component, Inject } from '@angular/core';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { FormArray, FormBuilder, FormGroup } from '@angular/forms';
import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog';
import { distinctUntilChanged } from 'rxjs/operators';
import { PrintType } from '../bills/print-type';
import { ReceivePaymentDatasource } from './receive-payment-datasource';
import { PrintType } from '../bills/bill';
@Component({
selector: 'app-receive-payment',
templateUrl: './receive-payment.component.html',
styleUrls: ['./receive-payment.component.css']
styleUrls: ['./receive-payment.component.css'],
})
export class ReceivePaymentComponent {
choices = {
@ -16,40 +18,40 @@ export class ReceivePaymentComponent {
{
id: 2,
name: 'Cash',
amount: 0
amount: 0,
},
{
id: 3,
name: 'Credit Card',
amount: 0
amount: 0,
},
{
id: 5,
name: 'Bill To Company',
amount: 0
amount: 0,
},
{
id: 6,
name: 'Tip',
amount: 0
}
]
,
amount: 0,
},
],
NO_CHARGE: [
{
id: 4,
name: 'No Charge',
amount: 0
}
amount: 0,
},
],
STAFF: [
{
id: 10,
name: 'Staff Account',
amount: 0
}
]
amount: 0,
},
],
};
type: PrintType;
amount: number;
balance: number;
@ -61,43 +63,44 @@ export class ReceivePaymentComponent {
constructor(
public dialogRef: MatDialogRef<ReceivePaymentComponent>,
private fb: FormBuilder,
@Inject(MAT_DIALOG_DATA) public data: {type: PrintType, amount: number}
@Inject(MAT_DIALOG_DATA) public data: { type: PrintType; amount: number },
) {
this.createForm();
this.type = data.type;
this.amount = data.amount;
this.balance = data.amount;
this.form.setControl('amounts', this.fb.array(
this.choices[this.type].map(
x => this.fb.group({
name: [x.name],
amount: ['']
})
)
));
this.form.setControl(
'amounts',
this.fb.array(
this.choices[this.type].map((x) =>
this.fb.group({
name: [x.name],
amount: [''],
}),
),
),
);
this.dataSource = new ReceivePaymentDatasource(this.choices[this.type]);
this.listenToAmountChange();
}
createForm() {
this.form = this.fb.group({
amounts: ''
amounts: '',
});
}
listenToAmountChange() {
const array = this.form.get('amounts') as FormArray;
this.choices[this.type].forEach(
(z, i) => array.controls[i].valueChanges.pipe(
distinctUntilChanged()
).subscribe(x => {
this.choices[this.type].find(s => s.name === x.name).amount = (x.amount === '' ? 0 : parseInt(x.amount, 10));
this.choices[this.type].forEach((z, i) =>
array.controls[i].valueChanges.pipe(distinctUntilChanged()).subscribe((x) => {
this.choices[this.type].find((s) => s.name === x.name).amount =
x.amount === '' ? 0 : parseInt(x.amount, 10);
this.balance = this.amount - this.choices[this.type].reduce((a, c) => a + c.amount, 0);
})
}),
);
}
accept(): void {
this.dialogRef.close(this.choices[this.type]);
}