feat: update environment configurations and add gold price management module with related components and services

This commit is contained in:
2026-05-23 19:57:28 +03:30
parent 6ad1a73c16
commit 7f07bf53c2
14 changed files with 507 additions and 89 deletions
@@ -0,0 +1,9 @@
<app-card-data cardTitle="قیمت پیش‌فرض هر گرم طلا" class="w-full">
<p-message variant="text" severity="info" icon="pi pi-info-circle">
در این بخش می‌توانید قیمت پیش‌فرض هر گرم طلا را وارد کنید.
</p-message>
<form [formGroup]="form" class="mt-6" (submit)="submit()">
<field-unit-price [control]="form.controls.price" />
<app-form-footer-actions (onCancel)="close()" />
</form>
</app-card-data>
@@ -0,0 +1,55 @@
import { AbstractForm } from '@/shared/abstractClasses';
import { AppCardComponent, UnitPriceComponent } from '@/shared/components';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { fieldControl } from '@/shared/constants';
import { Component, inject, signal } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { Message } from 'primeng/message';
import { IPosConfigGoldPricePayload, IPosConfigGoldPriceResponse } from './models';
import { PosConfigGoldPriceService } from './services/main.service';
@Component({
selector: 'pos-config-gold-price-form',
templateUrl: 'form.component.html',
imports: [
ReactiveFormsModule,
FormFooterActionsComponent,
AppCardComponent,
Message,
UnitPriceComponent,
],
})
export class PosConfigGoldPriceFormComponent extends AbstractForm<
IPosConfigGoldPricePayload,
IPosConfigGoldPriceResponse
> {
private readonly service = inject(PosConfigGoldPriceService);
loading = signal(true);
initForm = () => {
const form = this.fb.group({
price: fieldControl.unit_price(),
});
return form;
};
form = this.initForm();
override async ngOnInit() {
this.loading.set(true);
const initialValues = await this.service.get();
console.log('initialValues.price', initialValues);
this.form.controls.price.setValue((initialValues || 0) + '');
this.loading.set(false);
}
override submitForm() {
const formValue = this.form.value.price as IPosConfigGoldPricePayload;
this.toastService.success({ text: 'تغییرات با موفقیت اعمال شد.' });
return this.service.submit(formValue);
}
}
@@ -0,0 +1,3 @@
export type IPosConfigGoldPriceResponse = number;
export type IPosConfigGoldPricePayload = number;
@@ -0,0 +1,19 @@
import { Injectable } from '@angular/core';
import { LOCAL_STORAGE_KEYS } from 'src/assets/constants';
import { IPosConfigGoldPricePayload, IPosConfigGoldPriceResponse } from '../models';
@Injectable({ providedIn: 'root' })
export class PosConfigGoldPriceService {
get(): IPosConfigGoldPriceResponse {
const defaultPrice = Number(
window.localStorage.getItem(LOCAL_STORAGE_KEYS.POS_CONFIG_GOLD_PRICE) || '0'
);
this.submit(defaultPrice);
return defaultPrice;
}
submit(data: IPosConfigGoldPricePayload) {
window.localStorage.setItem(LOCAL_STORAGE_KEYS.POS_CONFIG_GOLD_PRICE, data.toString());
}
}
@@ -1,8 +1,11 @@
<div class="flex h-full w-full items-center justify-center p-4">
<div class="flex h-full w-full flex-col items-center justify-center gap-6 p-4">
@if (info()?.guild!.code.toLocaleLowerCase() === 'gold') {
<pos-config-gold-price-form class="w-full" (onClose)="returnToMainPage()" />
}
<app-card-data cardTitle="تنظیمات فاکتور" class="w-full">
<p-message variant="text" severity="info" icon="pi pi-info-circle">
هریک از موارد زیر را که می‌خواهید در چاپ فاکتور نمایش داده‌ شوند را انتخاب کنید
</p-message>
<pos-config-print-form class="mt-6 block w-full" (onClose)="returnToMainPage()" (onSubmit)="returnToMainPage()" />
<pos-config-print-form class="mt-6 block w-full" (onClose)="returnToMainPage()" />
</app-card-data>
</div>
@@ -1,17 +1,27 @@
import { PosInfoStore } from '@/domains/pos/store';
import { AppCardComponent } from '@/shared/components';
import { UikitFlatpickrJalaliComponent } from '@/uikit';
import { Component, inject } from '@angular/core';
import { Component, computed, inject } from '@angular/core';
import { Router } from '@angular/router';
import { Message } from 'primeng/message';
import { PosConfigGoldPriceFormComponent } from '../components/goldPrice/form.component';
import { PosConfigPrintFormComponent } from '../components/print/form.component';
@Component({
selector: 'pos-config-page',
templateUrl: './root.component.html',
imports: [PosConfigPrintFormComponent, AppCardComponent, Message, UikitFlatpickrJalaliComponent],
imports: [
PosConfigPrintFormComponent,
AppCardComponent,
Message,
PosConfigGoldPriceFormComponent,
],
})
export class PosConfigPageComponent {
private readonly router = inject(Router);
private readonly posInfoStore = inject(PosInfoStore);
readonly info = computed(() => this.posInfoStore.entity());
returnToMainPage() {
this.router.navigateByUrl('/');
}