Feature: Recording the nutritional and ice cream related values in the database

This commit is contained in:
2023-12-25 10:57:44 +05:30
parent efaaf9d431
commit cd6a5e129f
14 changed files with 391 additions and 8 deletions

View File

@ -1,10 +1,14 @@
export class ProductGroup {
id: string | undefined;
name: string;
nutritional: boolean;
iceCream: boolean;
isFixture: boolean;
public constructor(init?: Partial<ProductGroup>) {
this.name = '';
this.nutritional = false;
this.iceCream = false;
this.isFixture = false;
Object.assign(this, init);
}

View File

@ -30,6 +30,21 @@ export class Product {
isSold: boolean;
productGroup?: ProductGroup;
protein: number;
carbohydrate: number;
totalSugar: number;
addedSugar: number;
totalFat: number;
saturatedFat: number;
transFat: number;
cholestrol: number;
sodium: number;
msnf: number;
otherSolids: number;
totalSolids: number;
water: number;
public constructor(init?: Partial<Product>) {
this.code = 0;
this.name = '';
@ -39,6 +54,22 @@ export class Product {
this.isFixture = false;
this.isPurchased = true;
this.isSold = false;
this.protein = 0;
this.carbohydrate = 0;
this.totalSugar = 0;
this.addedSugar = 0;
this.totalFat = 0;
this.saturatedFat = 0;
this.transFat = 0;
this.cholestrol = 0;
this.sodium = 0;
this.msnf = 0;
this.otherSolids = 0;
this.totalSolids = 0;
this.water = 0;
Object.assign(this, init);
}
}

View File

@ -10,6 +10,10 @@
<input matInput #nameElement formControlName="name" (keyup.enter)="save()" />
</mat-form-field>
</div>
<div class="flex flex-row justify-around content-start items-start">
<mat-checkbox formControlName="nutritional" class="flex-auto mr-5">Nutritional Information?</mat-checkbox>
<mat-checkbox formControlName="iceCream" class="flex-auto">Ice Cream?</mat-checkbox>
</div>
</form>
</mat-card-content>
<mat-card-actions>

View File

@ -15,6 +15,8 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
@ViewChild('nameElement', { static: true }) nameElement?: ElementRef;
form: FormGroup<{
name: FormControl<string | null>;
nutritional: FormControl<boolean>;
iceCream: FormControl<boolean>;
}>;
item: ProductGroup = new ProductGroup();
@ -27,6 +29,8 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
) {
this.form = new FormGroup({
name: new FormControl<string | null>(null),
nutritional: new FormControl<boolean>(false, { nonNullable: true }),
iceCream: new FormControl<boolean>(false, { nonNullable: true }),
});
}
@ -42,6 +46,8 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
this.item = item;
this.form.setValue({
name: this.item.name,
nutritional: this.item.nutritional,
iceCream: this.item.iceCream,
});
}
@ -68,6 +74,8 @@ export class ProductGroupDetailComponent implements OnInit, AfterViewInit {
getItem(): ProductGroup {
const formModel = this.form.value;
this.item.name = formModel.name ?? '';
this.item.nutritional = formModel.nutritional ?? false;
this.item.iceCream = formModel.iceCream ?? false;
return this.item;
}
}

View File

@ -4,6 +4,7 @@ import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatCardModule } from '@angular/material/card';
import { MatCheckboxModule } from '@angular/material/checkbox';
import { MatIconModule } from '@angular/material/icon';
import { MatInputModule } from '@angular/material/input';
import { MatPaginatorModule } from '@angular/material/paginator';
@ -23,6 +24,7 @@ import { ProductGroupRoutingModule } from './product-group-routing.module';
MatPaginatorModule,
MatSortModule,
MatCardModule,
MatCheckboxModule,
MatProgressSpinnerModule,
MatInputModule,
MatButtonModule,

View File

@ -28,13 +28,74 @@
<div class="flex flex-row justify-around content-start items-start">
<mat-form-field class="flex-auto">
<mat-label>Product Type</mat-label>
<mat-select formControlName="productGroup">
<mat-select formControlName="productGroup" (selectionChange)="updatePG($event.value)">
<mat-option *ngFor="let pg of productGroups" [value]="pg.id">
{{ pg.name }}
</mat-option>
</mat-select>
</mat-form-field>
</div>
<h2 *ngIf="item.productGroup?.nutritional ?? false">Nutritional Information</h2>
<div
class="flex flex-row justify-around content-start items-start"
*ngIf="item.productGroup?.nutritional ?? false"
>
<mat-form-field class="flex-auto mr-5">
<mat-label>Protein</mat-label>
<input matInput formControlName="protein" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Carbohydrate</mat-label>
<input matInput formControlName="carbohydrate" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Total Sugar</mat-label>
<input matInput formControlName="totalSugar" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Added Sugar</mat-label>
<input matInput formControlName="addedSugar" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Total Fat</mat-label>
<input matInput formControlName="totalFat" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Saturated Fat</mat-label>
<input matInput formControlName="saturatedFat" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Trans Fat</mat-label>
<input matInput formControlName="transFat" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Cholestrol</mat-label>
<input matInput formControlName="cholestrol" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Sodium</mat-label>
<input matInput formControlName="sodium" />
</mat-form-field>
</div>
<h2 *ngIf="item.productGroup?.iceCream ?? false">Ice Cream Information</h2>
<div class="flex flex-row justify-around content-start items-start" *ngIf="item.productGroup?.iceCream ?? false">
<mat-form-field class="flex-auto mr-5">
<mat-label>MSNF</mat-label>
<input matInput formControlName="msnf" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Other Solids</mat-label>
<input matInput formControlName="otherSolids" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Total Solids</mat-label>
<input matInput formControlName="totalSolids" />
</mat-form-field>
<mat-form-field class="flex-auto mr-5">
<mat-label>Water</mat-label>
<input matInput formControlName="water" />
</mat-form-field>
</div>
<h2>Stock Keeping Units</h2>
<div
formGroupName="addRow"

View File

@ -35,6 +35,21 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
isSold: FormControl<boolean>;
isActive: FormControl<boolean>;
productGroup: FormControl<string | null>;
protein: FormControl<number>;
carbohydrate: FormControl<number>;
totalSugar: FormControl<number>;
addedSugar: FormControl<number>;
totalFat: FormControl<number>;
saturatedFat: FormControl<number>;
transFat: FormControl<number>;
cholestrol: FormControl<number>;
sodium: FormControl<number>;
msnf: FormControl<number>;
otherSolids: FormControl<number>;
totalSolids: FormControl<number>;
water: FormControl<number>;
}>;
productGroups: ProductGroup[] = [];
@ -66,6 +81,21 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
isSold: new FormControl<boolean>(true, { nonNullable: true }),
isActive: new FormControl<boolean>(true, { nonNullable: true }),
productGroup: new FormControl<string | null>(null),
protein: new FormControl<number>(0, { nonNullable: true }),
carbohydrate: new FormControl<number>(0, { nonNullable: true }),
totalSugar: new FormControl<number>(0, { nonNullable: true }),
addedSugar: new FormControl<number>(0, { nonNullable: true }),
totalFat: new FormControl<number>(0, { nonNullable: true }),
saturatedFat: new FormControl<number>(0, { nonNullable: true }),
transFat: new FormControl<number>(0, { nonNullable: true }),
cholestrol: new FormControl<number>(0, { nonNullable: true }),
sodium: new FormControl<number>(0, { nonNullable: true }),
msnf: new FormControl<number>(0, { nonNullable: true }),
otherSolids: new FormControl<number>(0, { nonNullable: true }),
totalSolids: new FormControl<number>(0, { nonNullable: true }),
water: new FormControl<number>(0, { nonNullable: true }),
});
}
@ -81,6 +111,7 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
}
showItem(item: Product) {
item.productGroup = this.productGroups.find((x) => x.id === item.productGroup?.id);
this.item = item;
this.form.setValue({
code: this.item.code || '(Auto)',
@ -97,6 +128,21 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
isSold: this.item.isSold,
isActive: this.item.isActive,
productGroup: this.item.productGroup ? this.item.productGroup.id ?? '' : '',
protein: this.item.protein,
carbohydrate: this.item.carbohydrate,
totalSugar: this.item.totalSugar,
addedSugar: this.item.addedSugar,
totalFat: this.item.totalFat,
saturatedFat: this.item.saturatedFat,
transFat: this.item.transFat,
cholestrol: this.item.cholestrol,
sodium: this.item.sodium,
msnf: this.item.msnf,
otherSolids: this.item.otherSolids,
totalSolids: this.item.totalSolids,
water: this.item.water,
});
}
@ -108,6 +154,10 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
}, 0);
}
updatePG(id: string) {
this.item.productGroup = this.productGroups.find((x) => x.id == id);
}
addRow() {
const formValue = this.form.value.addRow;
if (formValue === undefined) {
@ -220,10 +270,22 @@ export class ProductDetailComponent implements OnInit, AfterViewInit {
this.item.isPurchased = formModel.isPurchased ?? true;
this.item.isSold = formModel.isSold ?? false;
this.item.isActive = formModel.isActive ?? true;
if (this.item.productGroup === null || this.item.productGroup === undefined) {
this.item.productGroup = new ProductGroup();
}
this.item.productGroup.id = formModel.productGroup ?? '';
this.item.protein = formModel.protein ?? 0;
this.item.carbohydrate = formModel.carbohydrate ?? 0;
this.item.totalSugar = formModel.totalSugar ?? 0;
this.item.addedSugar = formModel.addedSugar ?? 0;
this.item.totalFat = formModel.totalFat ?? 0;
this.item.saturatedFat = formModel.saturatedFat ?? 0;
this.item.transFat = formModel.transFat ?? 0;
this.item.cholestrol = formModel.cholestrol ?? 0;
this.item.sodium = formModel.sodium ?? 0;
this.item.msnf = formModel.msnf ?? 0;
this.item.otherSolids = formModel.otherSolids ?? 0;
this.item.totalSolids = formModel.totalSolids ?? 0;
this.item.water = formModel.water ?? 0;
return this.item;
}
}