incentive and closing stock fixed
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
<mat-label>Department</mat-label>
|
<mat-label>Department</mat-label>
|
||||||
<mat-select [formField]="form.costCentre">
|
<mat-select [formField]="form.costCentre">
|
||||||
@for (at of costCentres(); track at) {
|
@for (at of costCentres(); track at) {
|
||||||
<mat-option [value]="at.id">
|
<mat-option [value]="at">
|
||||||
{{ at.name }}
|
{{ at.name }}
|
||||||
</mat-option>
|
</mat-option>
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { CurrencyPipe, DecimalPipe } from '@angular/common';
|
import { CurrencyPipe, DecimalPipe } from '@angular/common';
|
||||||
import { Component, inject, computed, input, linkedSignal, signal, afterNextRender } from '@angular/core';
|
import { Component, inject, computed, input, linkedSignal, signal, afterNextRender } from '@angular/core';
|
||||||
import { form as createForm, FormField, FormRoot } from '@angular/forms/signals';
|
import { form as createForm, FormField, FormRoot, required } from '@angular/forms/signals';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatOptionModule } from '@angular/material/core';
|
import { MatOptionModule } from '@angular/material/core';
|
||||||
import { MatDatepickerModule } from '@angular/material/datepicker';
|
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||||
@@ -94,7 +94,10 @@ export class ClosingStockComponent {
|
|||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
form = createForm(this.model);
|
form = createForm(this.model, (f) => {
|
||||||
|
required(f.costCentre);
|
||||||
|
required(f.date);
|
||||||
|
});
|
||||||
|
|
||||||
sortedList = computed(() => {
|
sortedList = computed(() => {
|
||||||
const data = this.info().items ?? [];
|
const data = this.info().items ?? [];
|
||||||
@@ -144,6 +147,9 @@ export class ClosingStockComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
show() {
|
show() {
|
||||||
|
if (this.form().invalid()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const info = this.getInfo();
|
const info = this.getInfo();
|
||||||
this.router.navigate(['closing-stock', info.date], {
|
this.router.navigate(['closing-stock', info.date], {
|
||||||
queryParams: {
|
queryParams: {
|
||||||
@@ -180,7 +186,7 @@ export class ClosingStockComponent {
|
|||||||
|
|
||||||
return new ClosingStock({
|
return new ClosingStock({
|
||||||
date: moment(formModel.date).format('DD-MMM-YYYY'),
|
date: moment(formModel.date).format('DD-MMM-YYYY'),
|
||||||
costCentre: new CostCentre({ id: formModel.costCentre?.id ?? '' }),
|
costCentre: formModel.costCentre ?? new CostCentre(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,10 +73,6 @@ export class VoucherService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
getIncentive(date: Signal<string>): ResourceRef<Voucher | undefined> {
|
|
||||||
return httpResource<Voucher>(() => `${url}/incentive?d=${date()}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
post(id: string): Observable<Voucher> {
|
post(id: string): Observable<Voucher> {
|
||||||
return this.http
|
return this.http
|
||||||
.post<Voucher>(`${url}/post-voucher/${id}`, {})
|
.post<Voucher>(`${url}/post-voucher/${id}`, {})
|
||||||
|
|||||||
@@ -21,7 +21,7 @@
|
|||||||
<strong>{{ totalPoints() | number: '1.2-2' }}</strong> Point Value:
|
<strong>{{ totalPoints() | number: '1.2-2' }}</strong> Point Value:
|
||||||
<strong>{{ pointValue() | number: '1.2-2' }}</strong>
|
<strong>{{ pointValue() | number: '1.2-2' }}</strong>
|
||||||
</div>
|
</div>
|
||||||
<mat-table #table [dataSource]="incentives()">
|
<mat-table #table [dataSource]="model().incentives">
|
||||||
<!-- Name Column -->
|
<!-- Name Column -->
|
||||||
<ng-container matColumnDef="name">
|
<ng-container matColumnDef="name">
|
||||||
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
<mat-header-cell *matHeaderCellDef>Name</mat-header-cell>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { CurrencyPipe, DecimalPipe } from '@angular/common';
|
import { CurrencyPipe, DecimalPipe } from '@angular/common';
|
||||||
import { signal, Component, inject, input, computed, linkedSignal } from '@angular/core';
|
import { signal, Component, inject, input, computed, linkedSignal, effect } from '@angular/core';
|
||||||
import { form as createForm, FormField, FormRoot } from '@angular/forms/signals';
|
import { form as createForm, FormField, FormRoot } from '@angular/forms/signals';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
import { MatDatepickerModule } from '@angular/material/datepicker';
|
import { MatDatepickerModule } from '@angular/material/datepicker';
|
||||||
@@ -23,8 +23,8 @@ import { ConfirmDialogComponent } from '../shared/confirm-dialog/confirm-dialog.
|
|||||||
import { LocalTimePipe } from '../shared/local-time.pipe';
|
import { LocalTimePipe } from '../shared/local-time.pipe';
|
||||||
|
|
||||||
export interface IncentiveFormData {
|
export interface IncentiveFormData {
|
||||||
date: Date;
|
date: moment.Moment;
|
||||||
incentives: { points: number }[];
|
incentives: Incentive[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
@@ -55,19 +55,28 @@ export class IncentiveComponent {
|
|||||||
auth = inject(AuthService);
|
auth = inject(AuthService);
|
||||||
private ser = inject(VoucherService);
|
private ser = inject(VoucherService);
|
||||||
id = input(null, { transform: (v: string | null | undefined) => v ?? null });
|
id = input(null, { transform: (v: string | null | undefined) => v ?? null });
|
||||||
voucherResource = this.ser.getVoucher(this.id, signal('Incentive'), signal(null), signal(null));
|
d = input(null, { transform: (v: string | null | undefined): string | null => v ?? null });
|
||||||
voucher = computed(() => this.voucherResource.value() ?? new Voucher());
|
voucherResource = this.ser.getVoucher(this.id, signal('Incentive'), signal(null), this.d);
|
||||||
|
voucher = computed(() => this.voucherResource.value() ?? new Voucher({ date: this.d() as string }));
|
||||||
|
|
||||||
model = linkedSignal({
|
model = linkedSignal({
|
||||||
source: this.voucher,
|
source: this.voucher,
|
||||||
computation: (v): IncentiveFormData => ({
|
computation: (v): IncentiveFormData => ({
|
||||||
date: moment(v.date, 'DD-MMM-YYYY').toDate(),
|
date: v.date ? moment(v.date, 'DD-MMM-YYYY') : moment(new Date()),
|
||||||
incentives: v.incentives.map((x) => ({ points: x.points })),
|
incentives: v.incentives.map((x) => new Incentive({ ...x })),
|
||||||
}),
|
}),
|
||||||
});
|
});
|
||||||
|
|
||||||
form = createForm(this.model);
|
form = createForm(this.model);
|
||||||
|
|
||||||
incentives = linkedSignal(() => this.voucher().incentives);
|
constructor() {
|
||||||
|
effect(async () => {
|
||||||
|
const date = this.form.date().value().format('DD-MMM-YYYY');
|
||||||
|
if (date !== this.d() && !this.id()) {
|
||||||
|
this.router.navigate(['/incentive'], { queryParams: { d: date }, replaceUrl: true });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
account: Account = new Account();
|
account: Account = new Account();
|
||||||
accBal: AccountBalance | null = null;
|
accBal: AccountBalance | null = null;
|
||||||
@@ -80,9 +89,10 @@ export class IncentiveComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
totalPoints = computed(() => {
|
totalPoints = computed(() => {
|
||||||
return this.incentives()
|
return this.model().incentives.reduce(
|
||||||
.map((item: Incentive, i: number) => item.daysWorked * (this.model().incentives[i]?.points ?? 0))
|
(sum: number, item: Incentive) => sum + item.daysWorked * (item.points ?? 0),
|
||||||
.reduce((sum: number, item: number) => sum + item, 0);
|
0,
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
pointValue = computed(() => {
|
pointValue = computed(() => {
|
||||||
@@ -97,7 +107,7 @@ export class IncentiveComponent {
|
|||||||
this.model.update((m) => {
|
this.model.update((m) => {
|
||||||
const arr = [...m.incentives];
|
const arr = [...m.incentives];
|
||||||
if (arr[i]) {
|
if (arr[i]) {
|
||||||
arr[i] = { ...arr[i], points: currentPoints - 1 };
|
arr[i] = new Incentive({ ...arr[i], points: currentPoints - 1 });
|
||||||
}
|
}
|
||||||
return { ...m, incentives: arr };
|
return { ...m, incentives: arr };
|
||||||
});
|
});
|
||||||
@@ -109,7 +119,7 @@ export class IncentiveComponent {
|
|||||||
this.model.update((m) => {
|
this.model.update((m) => {
|
||||||
const arr = [...m.incentives];
|
const arr = [...m.incentives];
|
||||||
if (arr[i]) {
|
if (arr[i]) {
|
||||||
arr[i] = { ...arr[i], points: currentPoints + 1 };
|
arr[i] = new Incentive({ ...arr[i], points: currentPoints + 1 });
|
||||||
}
|
}
|
||||||
return { ...m, incentives: arr };
|
return { ...m, incentives: arr };
|
||||||
});
|
});
|
||||||
@@ -158,11 +168,7 @@ export class IncentiveComponent {
|
|||||||
const formModel = this.model();
|
const formModel = this.model();
|
||||||
const v = this.voucher();
|
const v = this.voucher();
|
||||||
v.date = moment(formModel.date).format('DD-MMM-YYYY');
|
v.date = moment(formModel.date).format('DD-MMM-YYYY');
|
||||||
const array = formModel.incentives;
|
v.incentives = formModel.incentives;
|
||||||
|
|
||||||
v.incentives.forEach((item: Incentive, index: number) => {
|
|
||||||
item.points = array[index]?.points ?? 0;
|
|
||||||
});
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user