feat: implement stock keeping unit management form and list components

- Added StockKeepingUnitFormComponent for creating and editing stock keeping units.
- Introduced StockKeepingUnitsComponent for listing stock keeping units with pagination.
- Integrated form fields for code, name, VAT, and SKU type in the stock keeping unit form.
- Created API routes for stock keeping units with CRUD operations.
- Updated input components to handle numeric and price types with Persian/Arabic digit normalization.
- Enhanced key-value component to support tag display instead of badge.
- Adjusted layout styles for sidebar menu.
- Added AGENT.md for repository-specific coding guidelines and practices.
- Implemented good management form with file upload and category selection.
This commit is contained in:
2026-05-06 22:01:20 +03:30
parent 54d00e19ae
commit b2a1eb8e5b
87 changed files with 882 additions and 434 deletions
@@ -18,7 +18,7 @@ export class ConsumerAccountListComponent extends AbstractList<IConsumerAccountR
@Input({ required: true }) consumerId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{
field: 'username',
header: 'نام کاربری',
@@ -20,7 +20,7 @@ export class ConsumerBusinessActivitiesComponent extends AbstractList<IBusinessA
@Input({ required: true }) consumerId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{ field: 'guild', header: 'صنف', type: 'nested', nestedOption: { path: 'guild.name' } },
{
@@ -21,7 +21,7 @@ export class ConsumerComplexesComponent extends AbstractList<IComplexResponse> {
@Input() businessId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{
field: 'created_at',
@@ -22,7 +22,7 @@ export class ConsumerPosesComponent extends AbstractList<IPosResponse> {
@Input({ required: true }) complexId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{ field: 'serial_number', header: 'شماره سریال' },
{ field: 'device', header: 'دستگاه', type: 'nested', nestedOption: { path: 'device.name' } },
@@ -5,7 +5,6 @@
[items]="items()"
[loading]="loading()"
[showDetails]="true"
[showEdit]="true"
(onAdd)="openAddForm()"
(onDetails)="toSinglePage($event)"
(onEdit)="onEditClick($event)"
@@ -19,7 +19,7 @@ export class ConsumersComponent extends AbstractList<IAdminConsumerResponse> {
override setColumns(): void {
this.columns = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'نام' },
{ field: 'business_counts', header: 'تعداد فعالیت‌های اقتصادی' },
{
@@ -7,7 +7,8 @@
(onHide)="close()"
>
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
<app-input label="عنوان" [control]="form.controls.name" name="name" />
<field-name [control]="form.controls.name" />
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
</shared-dialog>
@@ -1,16 +1,17 @@
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { InputComponent } from '@/shared/components';
import { NameComponent } from '@/shared/components';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { fieldControl } from '@/shared/constants';
import { Component, computed, inject, Input } from '@angular/core';
import { ReactiveFormsModule, Validators } from '@angular/forms';
import { ReactiveFormsModule } from '@angular/forms';
import { IDeviceBrandRequest, IDeviceBrandResponse } from '../models';
import { DeviceBrandsService } from '../services/main.service';
@Component({
selector: 'deviceBrand-form',
templateUrl: './form.component.html',
imports: [ReactiveFormsModule, SharedDialogComponent, InputComponent, FormFooterActionsComponent],
imports: [ReactiveFormsModule, SharedDialogComponent, FormFooterActionsComponent, NameComponent],
})
export class DeviceBrandFormComponent extends AbstractFormDialog<
IDeviceBrandRequest,
@@ -20,10 +21,7 @@ export class DeviceBrandFormComponent extends AbstractFormDialog<
private service = inject(DeviceBrandsService);
form = this.fb.group({
name: this.fb.control<string>(this.initialValues?.name || '', {
nonNullable: true,
validators: [Validators.required],
}),
name: fieldControl.name(this.initialValues?.name),
});
preparedTitle = computed(() => `${this.editMode ? 'ویرایش' : 'افزودن'} برند دستگاه`);
@@ -16,7 +16,7 @@ export class DeviceBrandsComponent extends AbstractList<IDeviceBrandResponse> {
override setColumns(): void {
this.columns = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{
field: 'created_at',
@@ -7,7 +7,7 @@
(onHide)="close()"
>
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
<app-input label="عنوان" [control]="form.controls.name" name="name" />
<field-name [control]="form.controls.name" />
<catalog-deviceBrand-select [control]="form.controls.brand_id" />
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
@@ -1,7 +1,7 @@
// import { CatalogRolesComponent } from '@/shared/catalog/roles';
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { CatalogDeviceBrandSelectComponent } from '@/shared/catalog/deviceBrands';
import { InputComponent } from '@/shared/components';
import { NameComponent } from '@/shared/components';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { Component, inject, Input } from '@angular/core';
@@ -15,9 +15,9 @@ import { SuperAdminDeviceService } from '../services/main.service';
imports: [
ReactiveFormsModule,
SharedDialogComponent,
InputComponent,
FormFooterActionsComponent,
CatalogDeviceBrandSelectComponent,
NameComponent,
],
})
export class UserComplexFormComponent extends AbstractFormDialog<IDeviceRequest, IDeviceResponse> {
@@ -16,7 +16,7 @@ export class DevicesComponent extends AbstractList<IDeviceResponse> {
override setColumns(): void {
this.columns = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{
field: 'brand',
@@ -18,7 +18,7 @@ export class GuildGoodCategoriesListComponent extends AbstractList<IGoodCategori
@Input() guildId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{ field: 'goods_count', header: 'تعداد کالاها' },
{
@@ -0,0 +1,16 @@
<shared-dialog
header="فرم شناسه کالا"
[(visible)]="visible"
[modal]="true"
[style]="{ width: '500px' }"
[closable]="true"
>
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
<field-code [control]="form.controls.code" />
<field-name [control]="form.controls.name" />
<field-vat [control]="form.controls.VAT" />
<field-sku-type [control]="form.controls.type" />
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
</form>
</shared-dialog>
@@ -0,0 +1,73 @@
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
import {
CodeComponent,
NameComponent,
SkuTypeComponent,
VatComponent,
} from '@/shared/components/fields';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { fieldControl } from '@/shared/constants/fields';
import { Component, Input, inject } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { IStockKeepingUnitRequest, IStockKeepingUnitResponse } from '../../models';
import { StockKeepingUnitsService } from '../../services/stockKeepingUnits.service';
@Component({
selector: 'stock-keeping-unit-form',
templateUrl: './form.component.html',
imports: [
ReactiveFormsModule,
SharedDialogComponent,
NameComponent,
CodeComponent,
VatComponent,
SkuTypeComponent,
FormFooterActionsComponent,
],
})
export class StockKeepingUnitFormComponent extends AbstractFormDialog<
IStockKeepingUnitRequest,
IStockKeepingUnitResponse
> {
@Input({ required: true }) guildId!: string;
@Input() stockKeepingUnitId?: string;
private readonly service = inject(StockKeepingUnitsService);
form = this.fb.group({
code: fieldControl.code(this.initialValues?.code || ''),
name: fieldControl.name(this.initialValues?.name || ''),
VAT: fieldControl.VAT(String(this.initialValues?.VAT ?? 0)),
type: fieldControl.type(this.initialValues?.type || 'GOLD'),
is_public: fieldControl.is_public(String(this.initialValues?.is_public ?? true), false),
is_domestic: fieldControl.is_domestic(String(this.initialValues?.is_domestic ?? true), false),
});
override ngOnChanges() {
this.form.patchValue({
code: this.initialValues?.code ?? '',
name: this.initialValues?.name ?? '',
VAT: String(this.initialValues?.VAT ?? 0),
type: this.initialValues?.type ?? 'GOLD',
is_public: String(this.initialValues?.is_public ?? true),
is_domestic: String(this.initialValues?.is_domestic ?? true),
});
if (this.editMode && !this.stockKeepingUnitId) {
throw 'missing some arguments';
}
}
override submitForm(payload: IStockKeepingUnitRequest) {
const preparedPayload: IStockKeepingUnitRequest = {
...payload,
VAT: Number(payload.VAT),
is_public: String(payload.is_public) === 'true',
is_domestic: String(payload.is_domestic) === 'true',
};
if (this.editMode) {
return this.service.update(this.guildId, this.stockKeepingUnitId!, preparedPayload);
}
return this.service.create(this.guildId, preparedPayload);
}
}
@@ -0,0 +1,6 @@
const baseUrl = (guildId: string) => `/api/v1/admin/guilds/${guildId}/stock-keeping-units`;
export const GUILD_STOCK_KEEPING_UNITS_API_ROUTES = {
list: (guildId: string) => `${baseUrl(guildId)}`,
single: (guildId: string, id: string) => `${baseUrl(guildId)}/${id}`,
};
@@ -2,6 +2,7 @@ import { NamedRoutes } from '@/core';
import { Routes } from '@angular/router';
import { GUILD_GOOD_CATEGORIES_ROUTES } from './goodCategories';
import { GUILD_GOODS_ROUTES } from './goods';
import { GUILD_STOCK_KEEPING_UNITS_ROUTES } from './stockKeepingUnits';
export type TGuildsRouteNames = 'guilds' | 'guild';
@@ -40,6 +41,8 @@ export const GUILDS_ROUTES: Routes = [
...GUILD_GOOD_CATEGORIES_ROUTES,
...GUILD_GOODS_ROUTES,
...GUILD_STOCK_KEEPING_UNITS_ROUTES,
// {
// path: 'good_categories/:categoryId',
// loadComponent: () => import('../../views/categories/').then((m) => m.GuildComponent),
@@ -0,0 +1,20 @@
import { NamedRoutes } from '@/core';
import { Routes } from '@angular/router';
export type TStockKeepingUnitsRouteNames = 'stockKeepingUnits';
export const stockKeepingUnitsNamedRoutes: NamedRoutes<TStockKeepingUnitsRouteNames> = {
stockKeepingUnits: {
path: 'stock-keeping-units',
loadComponent: () =>
import('../../views/stockKeepingUnits/list.component').then(
(m) => m.StockKeepingUnitsComponent,
),
meta: {
title: 'شناسه کالاها',
pagePath: () => '/super_admin/guilds/:guildId/stock-keeping-units',
},
},
};
export const GUILD_STOCK_KEEPING_UNITS_ROUTES: Routes = Object.values(stockKeepingUnitsNamedRoutes);
@@ -1,2 +1,3 @@
export * from './goods_io';
export * from './io';
export * from './stockKeepingUnits_io';
@@ -9,6 +9,7 @@ export interface IGuildResponse extends IGuildRawResponse {}
export interface IGuildRequest {
name: string;
code: string;
invoice_template_type: string;
}
export interface IGoodCategoriesRawResponse {
@@ -0,0 +1,21 @@
export interface IStockKeepingUnitRawResponse {
id: string;
code: string;
name: string;
VAT: number;
type: string;
is_public: boolean;
is_domestic: boolean;
created_at?: string;
}
export interface IStockKeepingUnitResponse extends IStockKeepingUnitRawResponse {}
export interface IStockKeepingUnitRequest {
code: string;
name: string;
VAT: number;
type?: string;
is_public?: boolean;
is_domestic?: boolean;
}
@@ -0,0 +1,39 @@
import { IPaginatedResponse } from '@/core/models/service.model';
import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { GUILD_STOCK_KEEPING_UNITS_API_ROUTES } from '../constants/apiRoutes/stockKeepingUnits';
import {
IStockKeepingUnitRawResponse,
IStockKeepingUnitRequest,
IStockKeepingUnitResponse,
} from '../models';
@Injectable({ providedIn: 'root' })
export class StockKeepingUnitsService {
constructor(private http: HttpClient) {}
private apiRoutes = GUILD_STOCK_KEEPING_UNITS_API_ROUTES;
getAll(guildId: string): Observable<IPaginatedResponse<IStockKeepingUnitResponse>> {
return this.http.get<IPaginatedResponse<IStockKeepingUnitRawResponse>>(
this.apiRoutes.list(guildId),
);
}
create(
guildId: string,
payload: IStockKeepingUnitRequest,
): Observable<IStockKeepingUnitResponse> {
return this.http.post<IStockKeepingUnitResponse>(this.apiRoutes.list(guildId), payload);
}
update(
guildId: string,
id: string,
payload: IStockKeepingUnitRequest,
): Observable<IStockKeepingUnitResponse> {
return this.http.patch<IStockKeepingUnitResponse>(this.apiRoutes.single(guildId, id), payload);
}
}
@@ -9,6 +9,7 @@ import { GuildGoodCategoriesListComponent } from '../../components/categories/li
imports: [GuildGoodCategoriesListComponent],
})
export class GuildGoodCategoriesComponent {
route = inject(ActivatedRoute);
guildId = signal<string>(this.route.snapshot.paramMap.get('guildId')!);
private readonly route = inject(ActivatedRoute);
readonly guildId = signal<string>(this.route.snapshot.paramMap.get('guildId')!);
}
@@ -24,7 +24,7 @@ export class GuildsComponent extends AbstractList<IGuildResponse> {
override setColumns(): void {
this.columns = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'عنوان' },
{ field: 'code', header: 'کد' },
{ field: 'businessActivitiesCount', header: 'تعداد فعالیت‌‌های اقتصادی‌ مرتبط' },
@@ -0,0 +1,22 @@
<app-page-data-list
[pageTitle]="'مدیریت شناسه کالاها'"
[addNewCtaLabel]="'افزودن شناسه کالا'"
[columns]="columns"
emptyPlaceholderTitle="شناسه کالایی یافت نشد"
emptyPlaceholderDescription="برای افزودن شناسه کالا، روی دکمهٔ بالا کلیک کنید."
[items]="items()"
[loading]="loading()"
[showDetails]="false"
[showAdd]="true"
(onAdd)="openAddForm()"
(onRefresh)="refresh()"
>
</app-page-data-list>
<stock-keeping-unit-form
[guildId]="guildId()"
[(visible)]="visibleForm"
[initialValues]="selectedItemForEdit()!"
[editMode]="false"
[stockKeepingUnitId]="selectedItemForEdit()?.id"
(onSubmit)="refresh()"
/>
@@ -0,0 +1,33 @@
import { AbstractList } from '@/shared/abstractClasses/abstract-list';
import { PageDataListComponent } from '@/shared/components/pageDataList/page-data-list.component';
import pageParamsUtils from '@/utils/page-params.utils';
import { Component, computed, inject, signal } from '@angular/core';
import { ActivatedRoute } from '@angular/router';
import { StockKeepingUnitFormComponent } from '../../components/stockKeepingUnits/form.component';
import { IStockKeepingUnitResponse } from '../../models';
import { StockKeepingUnitsService } from '../../services/stockKeepingUnits.service';
@Component({
selector: 'superAdmin-stockKeepingUnits',
templateUrl: './list.component.html',
imports: [PageDataListComponent, StockKeepingUnitFormComponent],
})
export class StockKeepingUnitsComponent extends AbstractList<IStockKeepingUnitResponse> {
private readonly route = inject(ActivatedRoute);
pageParams = computed(() => pageParamsUtils(this.route));
readonly guildId = signal<string>(this.pageParams()['guildId']!);
private readonly service = inject(StockKeepingUnitsService);
override setColumns(): void {
this.columns = [
{ field: 'code', header: 'کد' },
{ field: 'name', header: 'عنوان' },
{ field: 'VAT', header: 'مالیات ارزش افزوده' },
];
}
override getDataRequest() {
return this.service.getAll(this.guildId());
}
}
@@ -18,7 +18,7 @@ export class ConsumerAccountListComponent extends AbstractList<IPartnerAccountRe
@Input({ required: true }) partnerId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{
field: 'username',
header: 'نام کاربری',
@@ -17,7 +17,7 @@ export class AdminPartnerLicensesComponent extends AbstractList<IPartnerActivate
override setColumns(): void {
this.columns = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{
field: 'consumer',
header: 'مشتری',
@@ -16,7 +16,7 @@ export class ProvidersComponent extends AbstractList<IProviderResponse> {
override setColumns(): void {
this.columns = [
{ field: 'id', header: 'شناسه', type: 'id' },
// { field: 'id', header: 'شناسه', type: 'id' },
{ field: 'name', header: 'نام' },
{
field: 'created_at',
@@ -1,8 +1,14 @@
<shared-dialog header="فرم واحد شمارش کالا" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true">
<shared-dialog
header="فرم شناسه کالا"
[(visible)]="visible"
[modal]="true"
[style]="{ width: '500px' }"
[closable]="true"
>
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
<field-code [control]="form.controls.code" />
<field-name [control]="form.controls.name" />
<field-vat [control]="$any(form.controls.VAT)" />
<field-vat [control]="form.controls.VAT" />
<field-sku-type [control]="form.controls.type" />
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
@@ -1,8 +1,13 @@
import { AbstractFormDialog } from '@/shared/abstractClasses';
import { fieldControl } from '@/shared/constants/fields';
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
import {
CodeComponent,
NameComponent,
SkuTypeComponent,
VatComponent,
} from '@/shared/components/fields';
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
import { CodeComponent, NameComponent, SkuTypeComponent, VatComponent } from '@/shared/components/fields';
import { fieldControl } from '@/shared/constants/fields';
import { Component, Input, inject } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { IStockKeepingUnitRequest, IStockKeepingUnitResponse } from '../models';
@@ -9,7 +9,7 @@ export const stockKeepingUnitsNamedRoutes: NamedRoutes<TStockKeepingUnitsRouteNa
loadComponent: () =>
import('../../views/list.component').then((m) => m.StockKeepingUnitsComponent),
meta: {
title: 'واحدهای شمارش کالا',
title: 'واحدهای شناسه کالا',
pagePath: () => '/super_admin/stock-keeping-units',
},
},
@@ -2,7 +2,6 @@
[pageTitle]="'مدیریت شناسه کالاها'"
[addNewCtaLabel]="'افزودن شناسه کالا'"
[columns]="columns"
[showAdd]="true"
emptyPlaceholderTitle="شناسه کالایی یافت نشد"
emptyPlaceholderDescription="برای افزودن شناسه کالا، روی دکمهٔ بالا کلیک کنید."
[items]="items()"
@@ -12,13 +11,11 @@
(onAdd)="openAddForm()"
(onRefresh)="refresh()"
>
@if (selectedItemForEdit()) {
<stock-keeping-unit-form
[(visible)]="visibleForm"
[initialValues]="selectedItemForEdit()!"
[editMode]="editMode()"
[stockKeepingUnitId]="selectedItemForEdit()?.id"
(onSubmit)="refresh()"
/>
}
</app-page-data-list>
<stock-keeping-unit-form
[(visible)]="visibleForm"
[initialValues]="selectedItemForEdit()!"
[editMode]="false"
[stockKeepingUnitId]="selectedItemForEdit()?.id"
(onSubmit)="refresh()"
/>
@@ -18,7 +18,6 @@ export class UsersComponent extends AbstractList<IAccountResponse> {
@Input() userId!: string;
@Input() fullHeight?: boolean;
@Input() header: IColumn[] = [
{ field: 'id', header: 'شناسه', type: 'id' },
{ field: 'username', header: 'نام کاربری' },
{ field: 'type', header: 'نوع حساب' },
{
@@ -2,17 +2,15 @@
[pageTitle]="'مدیریت کاربران'"
[addNewCtaLabel]="'افزودن کاربر'"
[columns]="columns"
[showAdd]="true"
emptyPlaceholderTitle="کاربری یافت نشد"
emptyPlaceholderDescription="برای افزودن کاربر، روی دکمهٔ بالا کلیک کنید."
[items]="items()"
[loading]="loading()"
[showDetails]="true"
[showIndex]="false"
[showAdd]="true"
[showEdit]="true"
(onAdd)="openAddForm()"
(onEdit)="onEditClick($event)"
(onDetails)="toSinglePage($event)"
(onRefresh)="refresh()"
/>
<superAdmin-user-form
@@ -19,7 +19,6 @@ export class UsersComponent extends AbstractList<IUserResponse> {
override setColumns(): void {
this.columns = [
{ field: 'id', header: 'شناسه', type: 'id' },
{ field: 'fullname', header: 'نام' },
{ field: 'mobile_number', header: 'شماره موبایل' },
{ field: 'national_code', header: 'کد ملی' },