Refactored customer discount and choose discount. They were using the same schema unnecessarily which was leading to confusion.
This commit is contained in:
@ -1,12 +1,14 @@
|
||||
export class CustomerDiscount {
|
||||
id: string;
|
||||
name: string;
|
||||
discount: number | null;
|
||||
discount: number;
|
||||
limit: number;
|
||||
|
||||
public constructor(init?: Partial<CustomerDiscount>) {
|
||||
this.id = '';
|
||||
this.name = '';
|
||||
this.discount = null;
|
||||
this.discount = 0;
|
||||
this.limit = 1;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -39,6 +39,7 @@
|
||||
<mat-label>Discount on {{ r.name }}</mat-label>
|
||||
<input matInput formControlName="discount" />
|
||||
<span matSuffix>%</span>
|
||||
<mat-hint>Max {{ r.limit | percent : '1.2-2' }}</mat-hint>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -131,7 +131,7 @@ export class CustomerDetailComponent implements OnInit, AfterViewInit {
|
||||
if (array_item && array_item?.discount) {
|
||||
item.discount = Math.max(Math.min(round(array_item.discount / 100, 5), 100), 0);
|
||||
} else {
|
||||
item.discount = null;
|
||||
item.discount = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -106,7 +106,7 @@ export class ChooseCustomerComponent {
|
||||
if (array_item && array_item?.discount) {
|
||||
item.discount = Math.max(Math.min(round(array_item.discount / 100, 5), 100), 0);
|
||||
} else {
|
||||
item.discount = null;
|
||||
item.discount = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -3,8 +3,9 @@ import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { catchError } from 'rxjs/operators';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
import { DiscountItem } from '../sales/discount/discount-item';
|
||||
import { ErrorLoggerService } from '../../core/error-logger.service';
|
||||
|
||||
import { DiscountItem } from './discount-item';
|
||||
|
||||
const url = '/api/customer-discounts';
|
||||
const serviceName = 'CustomerService';
|
||||
@ -2,15 +2,15 @@ export class DiscountItem {
|
||||
id: string;
|
||||
name: string;
|
||||
discount: number;
|
||||
discountLimit: number;
|
||||
customerDiscount: number;
|
||||
limit: number;
|
||||
customer: number;
|
||||
|
||||
public constructor(init?: Partial<DiscountItem>) {
|
||||
this.id = '';
|
||||
this.name = '';
|
||||
this.discount = 0;
|
||||
this.discountLimit = 0;
|
||||
this.customerDiscount = 0;
|
||||
this.limit = 0;
|
||||
this.customer = 0;
|
||||
Object.assign(this, init);
|
||||
}
|
||||
}
|
||||
|
||||
@ -22,8 +22,8 @@
|
||||
<mat-form-field class="flex-auto">
|
||||
<input matInput type="number" formControlName="discount" autocomplete="off" />
|
||||
<span matSuffix>%</span>
|
||||
<mat-hint>Cust: {{ row.customerDiscount | percent : '1.2-2' }}</mat-hint>
|
||||
<mat-hint align="end">Max: {{ row.discountLimit | percent : '1.2-2' }}</mat-hint>
|
||||
<mat-hint>Cust: {{ row.customer | percent : '1.2-2' }}</mat-hint>
|
||||
<mat-hint align="end">Max: {{ row.limit | percent : '1.2-2' }}</mat-hint>
|
||||
</mat-form-field>
|
||||
</mat-cell>
|
||||
</ng-container>
|
||||
|
||||
@ -50,7 +50,7 @@ export class DiscountComponent {
|
||||
new FormGroup({
|
||||
name: new FormControl(x.name, { nonNullable: true }),
|
||||
discount: new FormControl(x.discount * 100, {
|
||||
validators: [Validators.min(0), Validators.max(x.discountLimit * 100)],
|
||||
validators: [Validators.min(0), Validators.max(x.limit * 100)],
|
||||
nonNullable: true,
|
||||
}),
|
||||
}),
|
||||
@ -68,7 +68,7 @@ export class DiscountComponent {
|
||||
if (control.pristine && control.value === 0) {
|
||||
this.list.splice(i, 1);
|
||||
} else {
|
||||
item.discount = Math.max(Math.min(round(control.value / 100, 5), item.discountLimit), 0);
|
||||
item.discount = Math.max(Math.min(round(control.value / 100, 5), item.limit), 0);
|
||||
}
|
||||
}
|
||||
this.dialogRef.close(this.list);
|
||||
|
||||
@ -8,7 +8,6 @@ import { AuthService } from '../../auth/auth.service';
|
||||
import { ReceivePaymentItem } from '../../core/receive-payment-item';
|
||||
import { Table } from '../../core/table';
|
||||
import { ToasterService } from '../../core/toaster.service';
|
||||
import { CustomerDiscountsService } from '../../customers/customer-discounts.service';
|
||||
import { SaleCategoryService } from '../../sale-category/sale-category.service';
|
||||
import { ConfirmDialogComponent } from '../../shared/confirm-dialog/confirm-dialog.component';
|
||||
import { TableService } from '../../tables/table.service';
|
||||
@ -16,6 +15,7 @@ import { BillTypeComponent } from '../bill-type/bill-type.component';
|
||||
import { BillService } from '../bill.service';
|
||||
import { BillSelectionItem } from '../bills/bill-selection-item';
|
||||
import { VoucherType } from '../bills/voucher-type';
|
||||
import { CustomerDiscountsService } from '../discount/customer-discounts.service';
|
||||
import { DiscountComponent } from '../discount/discount.component';
|
||||
import { ReasonComponent } from '../reason/reason.component';
|
||||
import { ReceivePaymentComponent } from '../receive-payment/receive-payment.component';
|
||||
|
||||
Reference in New Issue
Block a user