From 694b2ec946e526e10ee66b8d9dcb6fc47fdc0587 Mon Sep 17 00:00:00 2001 From: ahasani194 Date: Wed, 3 Jun 2026 17:48:54 +0330 Subject: [PATCH] refactor: replace economic code fields with individual and legal variants, add equal length validation --- src/app/core/services/form-errors.service.ts | 7 ++ .../core/validators/equalLength.validator.ts | 19 ++++ src/app/core/validators/index.ts | 1 + .../components/form.component.html | 5 +- .../components/form.component.ts | 8 +- .../businessActivities/form.component.html | 2 +- .../businessActivities/form.component.ts | 10 +- .../layouts/pagesLayout/layout.component.html | 17 ++- .../customers/individual/form.component.html | 5 +- .../customers/individual/form.component.ts | 75 ++++++++++--- .../customers/legal/form.component.html | 11 +- .../customers/legal/form.component.ts | 100 ++++++++++++++---- .../order/order-section-dialog.component.ts | 8 +- .../order/order-section.component.ts | 4 +- .../pos/modules/shop/models/customer.ts | 19 ++-- .../businessActivities/form.component.html | 5 +- .../businessActivities/form.component.ts | 6 +- src/app/shared/components/fields/index.ts | 3 +- .../individual_economic_code.component.ts | 19 ++++ ...nt.ts => legal_economic_code.component.ts} | 14 ++- .../sale-invoice-single-view.component.ts | 24 +++-- src/app/shared/constants/fields/index.ts | 9 +- .../datepicker/datepicker.component.html | 2 +- 23 files changed, 272 insertions(+), 101 deletions(-) create mode 100644 src/app/core/validators/equalLength.validator.ts create mode 100644 src/app/shared/components/fields/individual_economic_code.component.ts rename src/app/shared/components/fields/{economic_code.component.ts => legal_economic_code.component.ts} (53%) diff --git a/src/app/core/services/form-errors.service.ts b/src/app/core/services/form-errors.service.ts index a2f7997..621e70b 100644 --- a/src/app/core/services/form-errors.service.ts +++ b/src/app/core/services/form-errors.service.ts @@ -68,6 +68,13 @@ export class FormErrorsService { const info = errors['invalidUsername']; out.push({ key: 'invalidUsername', message: info.message ?? `${label} معتبر نیست.` }); } + if (errors['equalLength']) { + const info = errors['equalLength']; + out.push({ + key: 'equalLength', + message: `تعداد کاراکترهای ${label} باید برابر با ${info.length} باشد.`, + }); + } if (errors['invalidFiscalId']) { const info = errors['invalidFiscalId']; diff --git a/src/app/core/validators/equalLength.validator.ts b/src/app/core/validators/equalLength.validator.ts new file mode 100644 index 0000000..b22694b --- /dev/null +++ b/src/app/core/validators/equalLength.validator.ts @@ -0,0 +1,19 @@ +import { AbstractControl, ValidationErrors, ValidatorFn } from '@angular/forms'; + +export function equalLengthValidator(length: number): ValidatorFn { + return (control: AbstractControl): ValidationErrors | null => { + const v = control.value; + if (v === null || v === undefined || v === '') { + return null; + } + const normalized = String(v); + + return normalized.length !== length + ? { + equalLength: { + length, + }, + } + : null; + }; +} diff --git a/src/app/core/validators/index.ts b/src/app/core/validators/index.ts index a0cb048..dac72ae 100644 --- a/src/app/core/validators/index.ts +++ b/src/app/core/validators/index.ts @@ -1,3 +1,4 @@ +export * from './equalLength.validator'; export * from './fiscal-id.validator'; export * from './greater.validator'; export * from './iban.validator'; diff --git a/src/app/domains/consumer/modules/businessActivities/components/form.component.html b/src/app/domains/consumer/modules/businessActivities/components/form.component.html index 73dc803..084ae0c 100644 --- a/src/app/domains/consumer/modules/businessActivities/components/form.component.html +++ b/src/app/domains/consumer/modules/businessActivities/components/form.component.html @@ -4,11 +4,10 @@ [modal]="true" [style]="{ width: '500px' }" [closable]="true" - (onHide)="close()" -> + (onHide)="close()">
- + diff --git a/src/app/domains/consumer/modules/businessActivities/components/form.component.ts b/src/app/domains/consumer/modules/businessActivities/components/form.component.ts index e32fb31..aabdd9e 100644 --- a/src/app/domains/consumer/modules/businessActivities/components/form.component.ts +++ b/src/app/domains/consumer/modules/businessActivities/components/form.component.ts @@ -1,7 +1,7 @@ import { AbstractFormDialog } from '@/shared/abstractClasses'; import { - EconomicCodeComponent, FiscalIdComponent, + IndividualEconomicCodeComponent, NameComponent, PartnerTokenComponent, } from '@/shared/components'; @@ -22,7 +22,7 @@ import { BusinessActivitiesService } from '../services/main.service'; SharedDialogComponent, FormFooterActionsComponent, NameComponent, - EconomicCodeComponent, + IndividualEconomicCodeComponent, PartnerTokenComponent, InvoiceNumberSequenceComponent, FiscalIdComponent, @@ -37,11 +37,11 @@ export class ConsumerBusinessActivityFormComponent extends AbstractFormDialog< form = this.fb.group({ name: fieldControl.name(this.initialValues?.name || ''), - economic_code: fieldControl.economic_code(this.initialValues?.economic_code || ''), + economic_code: fieldControl.individual_economic_code(this.initialValues?.economic_code || ''), fiscal_id: fieldControl.fiscal_id(this.initialValues?.fiscal_id || ''), partner_token: fieldControl.partner_token(this.initialValues?.partner_token || ''), invoice_number_sequence: fieldControl.invoice_number_sequence( - this.initialValues?.invoice_number_sequence || 1, + this.initialValues?.invoice_number_sequence || 1 ), }); diff --git a/src/app/domains/partner/modules/consumers/components/businessActivities/form.component.html b/src/app/domains/partner/modules/consumers/components/businessActivities/form.component.html index 0b2094a..6f3752c 100644 --- a/src/app/domains/partner/modules/consumers/components/businessActivities/form.component.html +++ b/src/app/domains/partner/modules/consumers/components/businessActivities/form.component.html @@ -1,6 +1,6 @@ - + diff --git a/src/app/domains/partner/modules/consumers/components/businessActivities/form.component.ts b/src/app/domains/partner/modules/consumers/components/businessActivities/form.component.ts index f857eba..f2471b4 100644 --- a/src/app/domains/partner/modules/consumers/components/businessActivities/form.component.ts +++ b/src/app/domains/partner/modules/consumers/components/businessActivities/form.component.ts @@ -1,8 +1,8 @@ import { AbstractForm } from '@/shared/abstractClasses'; import { - EconomicCodeComponent, FiscalIdComponent, GuildIdComponent, + IndividualEconomicCodeComponent, LicenseStartsAtComponent, NameComponent, PartnerTokenComponent, @@ -22,7 +22,7 @@ import { PartnerConsumerBusinessActivitiesService } from '../../services/busines imports: [ ReactiveFormsModule, NameComponent, - EconomicCodeComponent, + IndividualEconomicCodeComponent, FiscalIdComponent, PartnerTokenComponent, GuildIdComponent, @@ -44,10 +44,10 @@ export class ConsumerBusinessActivitiesFormComponent extends AbstractForm< initForm = () => { const form = this.fb.group({ name: fieldControl.name(this.initialValues?.name || ''), - economic_code: fieldControl.economic_code(this.initialValues?.economic_code || ''), + economic_code: fieldControl.individual_economic_code(this.initialValues?.economic_code || ''), fiscal_id: fieldControl.fiscal_id(this.initialValues?.fiscal_id || ''), invoice_number_sequence: fieldControl.invoice_number_sequence( - parseInt(this.initialValues?.invoice_number_sequence || '1'), + parseInt(this.initialValues?.invoice_number_sequence || '1') ), partner_token: fieldControl.partner_token(this.initialValues?.partner_token || ''), guild_id: fieldControl.guild_id(this.initialValues?.guild?.id || ''), @@ -63,7 +63,7 @@ export class ConsumerBusinessActivitiesFormComponent extends AbstractForm< this.fb.control('', { nonNullable: true, validators: fieldControl.license_starts_at('')[1], - }), + }) ); } diff --git a/src/app/domains/pos/layouts/pagesLayout/layout.component.html b/src/app/domains/pos/layouts/pagesLayout/layout.component.html index 758ab48..d890b43 100644 --- a/src/app/domains/pos/layouts/pagesLayout/layout.component.html +++ b/src/app/domains/pos/layouts/pagesLayout/layout.component.html @@ -5,12 +5,11 @@ @if (posInfo()) { -
+
Logo + class="bg-surface-card h-full w-full rounded-md object-cover" />
{{ posInfo()?.partner?.name }}
@@ -19,7 +18,7 @@
- +
@@ -57,11 +56,11 @@ } @default { -
- -
- - عدم دسترسی +
+ +
+ + عدم دسترسی

متاسفانه امکان دسترسی برای کاربر شما فراهم نیست

diff --git a/src/app/domains/pos/modules/shop/components/customers/individual/form.component.html b/src/app/domains/pos/modules/shop/components/customers/individual/form.component.html index 5b4723b..5abc5e6 100644 --- a/src/app/domains/pos/modules/shop/components/customers/individual/form.component.html +++ b/src/app/domains/pos/modules/shop/components/customers/individual/form.component.html @@ -1,9 +1,10 @@ + وارد کردن شماره اقتصادی و یا کد ملی به همراه کد پستی الزامی است. + - + - diff --git a/src/app/domains/pos/modules/shop/components/customers/individual/form.component.ts b/src/app/domains/pos/modules/shop/components/customers/individual/form.component.ts index 64cefbe..95a79fd 100644 --- a/src/app/domains/pos/modules/shop/components/customers/individual/form.component.ts +++ b/src/app/domains/pos/modules/shop/components/customers/individual/form.component.ts @@ -1,9 +1,8 @@ import { AbstractForm } from '@/shared/abstractClasses'; import { - EconomicCodeComponent, FirstNameComponent, + IndividualEconomicCodeComponent, LastNameComponent, - MobileNumberComponent, NationalIdComponent, PostalCodeComponent, } from '@/shared/components'; @@ -11,7 +10,8 @@ import { FormFooterActionsComponent } from '@/shared/components/formFooterAction import { fieldControl } from '@/shared/constants'; import { CustomerType } from '@/shared/localEnum/constants/customerTypes'; import { Component, computed, inject } from '@angular/core'; -import { ReactiveFormsModule } from '@angular/forms'; +import { AbstractControl, ReactiveFormsModule, ValidationErrors } from '@angular/forms'; +import { Message } from 'primeng/message'; import { Observable } from 'rxjs'; import { IIndividualCustomer } from '../../../models/customer'; import { PosLandingStore } from '../../../store/main.store'; @@ -24,10 +24,10 @@ import { PosLandingStore } from '../../../store/main.store'; FormFooterActionsComponent, FirstNameComponent, LastNameComponent, - NationalIdComponent, - EconomicCodeComponent, - MobileNumberComponent, + IndividualEconomicCodeComponent, PostalCodeComponent, + Message, + NationalIdComponent, ], }) export class CustomerIndividualFormComponent extends AbstractForm< @@ -38,14 +38,56 @@ export class CustomerIndividualFormComponent extends AbstractForm< costumerInfo = computed(() => this.store.customer().info?.customer_individual); override showSuccessMessage = false; - form = this.fb.group({ - first_name: fieldControl.first_name(this.costumerInfo()?.first_name || ''), - last_name: fieldControl.last_name(this.costumerInfo()?.last_name || ''), - national_id: fieldControl.national_id(this.costumerInfo()?.national_id || ''), - postal_code: fieldControl.postal_code(this.costumerInfo()?.postal_code || ''), - economic_code: fieldControl.economic_code(this.costumerInfo()?.economic_code || ''), - mobile_number: fieldControl.mobile_number(this.costumerInfo()?.mobile_number || ''), - }); + private readonly identityOrEconomicCodeValidator = ( + control: AbstractControl + ): ValidationErrors | null => { + const economicCode = control.get('economic_code')?.value; + const nationalId = control.get('national_id')?.value; + const postalCode = control.get('postal_code')?.value; + + const hasEconomicCode = !!String(economicCode ?? '').trim(); + const hasNationalId = !!String(nationalId ?? '').trim(); + const hasPostalCode = !!String(postalCode ?? '').trim(); + + const isValid = hasEconomicCode || (hasNationalId && hasPostalCode); + + if (!isValid) { + return { identityOrEconomicCodeRequired: true }; + } + + return null; + }; + + form = this.fb.group( + { + first_name: fieldControl.first_name(this.costumerInfo()?.first_name || '', false), + last_name: fieldControl.last_name(this.costumerInfo()?.last_name || '', false), + economic_code: fieldControl.individual_economic_code( + this.costumerInfo()?.economic_code || '', + false + ), + national_id: fieldControl.national_id(this.costumerInfo()?.national_id || '', false), + postal_code: fieldControl.postal_code(this.costumerInfo()?.postal_code || '', false), + }, + { validators: this.identityOrEconomicCodeValidator } + ); + + override submit() { + this.form.markAllAsTouched(); + this.form.updateValueAndValidity({ onlySelf: false, emitEvent: false }); + + if (this.form.hasError('identityOrEconomicCodeRequired')) { + this.toastService.warn({ + text: 'وارد کردن شماره اقتصادی و یا کد ملی به همراه کد پستی الزامی است.', + }); + } + + if (this.form.invalid) { + return; + } + + super.submit(); + } override submitForm() { return new Observable((observer) => { @@ -54,7 +96,10 @@ export class CustomerIndividualFormComponent extends AbstractForm< customer_id: '', type: CustomerType.INDIVIDUAL, info: { - customer_individual: info, + customer_individual: { + ...info, + economic_code: info.economic_code ? info.economic_code.toString() : undefined, + }, }, }); return observer.next(info); diff --git a/src/app/domains/pos/modules/shop/components/customers/legal/form.component.html b/src/app/domains/pos/modules/shop/components/customers/legal/form.component.html index 4ba8a36..aa2cf96 100644 --- a/src/app/domains/pos/modules/shop/components/customers/legal/form.component.html +++ b/src/app/domains/pos/modules/shop/components/customers/legal/form.component.html @@ -1,8 +1,11 @@ - - - - + + وارد کردن شماره اقتصادی و یا شناسه‌ ملی به همراه کد پستی الزامی است. + + + + + diff --git a/src/app/domains/pos/modules/shop/components/customers/legal/form.component.ts b/src/app/domains/pos/modules/shop/components/customers/legal/form.component.ts index 826a946..90e3b13 100644 --- a/src/app/domains/pos/modules/shop/components/customers/legal/form.component.ts +++ b/src/app/domains/pos/modules/shop/components/customers/legal/form.component.ts @@ -1,10 +1,16 @@ -import { postalCodeValidator } from '@/core/validators'; import { AbstractForm } from '@/shared/abstractClasses'; -import { InputComponent } from '@/shared/components'; +import { + LegalEconomicCodeComponent, + NameComponent, + PostalCodeComponent, + RegistrationNumberComponent, +} from '@/shared/components'; import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component'; +import { fieldControl } from '@/shared/constants'; import { CustomerType } from '@/shared/localEnum/constants/customerTypes'; import { Component, inject } from '@angular/core'; -import { ReactiveFormsModule, Validators } from '@angular/forms'; +import { AbstractControl, ReactiveFormsModule, ValidationErrors } from '@angular/forms'; +import { Message } from 'primeng/message'; import { Observable } from 'rxjs'; import { ILegalCustomer } from '../../../models/customer'; import { PosLandingStore } from '../../../store/main.store'; @@ -12,31 +18,76 @@ import { PosLandingStore } from '../../../store/main.store'; @Component({ selector: 'pos-customer-legal-form', templateUrl: './form.component.html', - imports: [ReactiveFormsModule, InputComponent, FormFooterActionsComponent], + imports: [ + ReactiveFormsModule, + FormFooterActionsComponent, + LegalEconomicCodeComponent, + NameComponent, + RegistrationNumberComponent, + PostalCodeComponent, + Message, + ], }) export class CustomerLegalFormComponent extends AbstractForm { private readonly store = inject(PosLandingStore); override showSuccessMessage = false; - form = this.fb.group({ - company_name: [ - this.store.customer().info?.customer_legal?.company_name || '', - [Validators.required], - ], - registration_number: [ - this.store.customer().info?.customer_legal?.registration_number || '', - [Validators.required], - ], - economic_code: [ - this.store.customer().info?.customer_legal?.economic_code || '', - [Validators.required], - ], - postal_code: [ - this.store.customer().info?.customer_legal?.postal_code || '', - [postalCodeValidator()], - ], - }); + private readonly registrationOrEconomicCodeValidator = ( + control: AbstractControl + ): ValidationErrors | null => { + const economicCode = control.get('economic_code')?.value; + const registrationNumber = control.get('registration_number')?.value; + const postalCode = control.get('postal_code')?.value; + + const hasEconomicCode = !!String(economicCode ?? '').trim(); + const hasRegistrationNumber = !!String(registrationNumber ?? '').trim(); + const hasPostalCode = !!String(postalCode ?? '').trim(); + + const isValid = hasEconomicCode || (hasRegistrationNumber && hasPostalCode); + + if (!isValid) { + return { registrationOrEconomicCodeRequired: true }; + } + + return null; + }; + + form = this.fb.group( + { + name: fieldControl.name(this.store.customer().info?.customer_legal?.name || ''), + economic_code: fieldControl.legal_economic_code( + this.store.customer().info?.customer_legal?.economic_code || '', + false + ), + registration_number: fieldControl.registration_number( + this.store.customer().info?.customer_legal?.registration_number || '', + false + ), + postal_code: fieldControl.postal_code( + this.store.customer().info?.customer_legal?.postal_code || '', + false + ), + }, + { validators: this.registrationOrEconomicCodeValidator } + ); + + override submit() { + this.form.markAllAsTouched(); + this.form.updateValueAndValidity({ onlySelf: false, emitEvent: false }); + + if (this.form.hasError('registrationOrEconomicCodeRequired')) { + this.toastService.warn({ + text: 'وارد کردن شماره اقتصادی و یا شناسه‌ ملی به همراه کد پستی الزامی است.', + }); + } + + if (this.form.invalid) { + return; + } + + super.submit(); + } override submitForm() { return new Observable((observer) => { @@ -45,7 +96,10 @@ export class CustomerLegalFormComponent extends AbstractForm { - this.onCloseInvoiceBottomSheet.emit(); + this.onAddMoreGoods.emit(); }; submitOrder = () => { - this.onSubmitOrder.emit(); + this.onSubmit.emit(); }; } diff --git a/src/app/domains/pos/modules/shop/components/order/order-section.component.ts b/src/app/domains/pos/modules/shop/components/order/order-section.component.ts index a2a8812..0a7ed72 100644 --- a/src/app/domains/pos/modules/shop/components/order/order-section.component.ts +++ b/src/app/domains/pos/modules/shop/components/order/order-section.component.ts @@ -64,7 +64,7 @@ export class PosOrderSectionComponent { customerNameToShow = `${info?.customer_individual ? info?.customer_individual.first_name + ' ' + info?.customer_individual.last_name : '-----'} (نوع اول)`; break; case 'LEGAL': - customerNameToShow = `${info?.customer_legal?.company_name || '-----'} (نوع اول)`; + customerNameToShow = `${info?.customer_legal?.name || '-----'} (نوع اول)`; break; } @@ -85,6 +85,8 @@ export class PosOrderSectionComponent { } submitAndPay() { + console.log('submitAndPay'); + this.onSubmit.emit(); } diff --git a/src/app/domains/pos/modules/shop/models/customer.ts b/src/app/domains/pos/modules/shop/models/customer.ts index ccb6238..9d33f4d 100644 --- a/src/app/domains/pos/modules/shop/models/customer.ts +++ b/src/app/domains/pos/modules/shop/models/customer.ts @@ -1,17 +1,16 @@ export interface IIndividualCustomer { - first_name: string; - last_name: string; - national_id: string; - postal_code: string; - mobile_number: string; - economic_code: string; + first_name?: string; + last_name?: string; + national_id?: string; + postal_code?: string; + economic_code?: string; is_favorite?: boolean; } export interface ILegalCustomer { - company_name: string; - economic_code: string; - registration_number: string; - postal_code: string; + name?: string; + economic_code?: string; + registration_number?: string; + postal_code?: string; is_favorite?: boolean; } diff --git a/src/app/domains/superAdmin/modules/consumers/components/businessActivities/form.component.html b/src/app/domains/superAdmin/modules/consumers/components/businessActivities/form.component.html index e3c7002..5799f68 100644 --- a/src/app/domains/superAdmin/modules/consumers/components/businessActivities/form.component.html +++ b/src/app/domains/superAdmin/modules/consumers/components/businessActivities/form.component.html @@ -4,11 +4,10 @@ [modal]="true" [style]="{ width: '500px' }" [closable]="true" - (onHide)="close()" -> + (onHide)="close()">
- + diff --git a/src/app/domains/superAdmin/modules/consumers/components/businessActivities/form.component.ts b/src/app/domains/superAdmin/modules/consumers/components/businessActivities/form.component.ts index 1873ed8..ab15797 100644 --- a/src/app/domains/superAdmin/modules/consumers/components/businessActivities/form.component.ts +++ b/src/app/domains/superAdmin/modules/consumers/components/businessActivities/form.component.ts @@ -1,9 +1,9 @@ // import { CatalogRolesComponent } from '@/shared/catalog/roles'; import { AbstractFormDialog } from '@/shared/abstractClasses'; import { - EconomicCodeComponent, FiscalIdComponent, GuildIdComponent, + IndividualEconomicCodeComponent, NameComponent, PartnerTokenComponent, } from '@/shared/components'; @@ -22,7 +22,7 @@ import { AdminConsumerBusinessActivitiesService } from '../../services/businessA ReactiveFormsModule, SharedDialogComponent, NameComponent, - EconomicCodeComponent, + IndividualEconomicCodeComponent, FiscalIdComponent, PartnerTokenComponent, GuildIdComponent, @@ -41,7 +41,7 @@ export class ConsumerBusinessActivitiesFormComponent extends AbstractFormDialog< initForm = () => { return this.fb.group({ name: fieldControl.name(this.initialValues?.name || ''), - economic_code: fieldControl.economic_code(this.initialValues?.economic_code || ''), + economic_code: fieldControl.individual_economic_code(this.initialValues?.economic_code || ''), fiscal_id: fieldControl.fiscal_id(this.initialValues?.fiscal_id || ''), partner_token: fieldControl.partner_token(this.initialValues?.partner_token || ''), // @ts-ignore diff --git a/src/app/shared/components/fields/index.ts b/src/app/shared/components/fields/index.ts index 4e60196..9f14696 100644 --- a/src/app/shared/components/fields/index.ts +++ b/src/app/shared/components/fields/index.ts @@ -4,13 +4,14 @@ export * from './code.component'; export * from './company_name.component'; export * from './description.component'; export * from './device_id.component'; -export * from './economic_code.component'; export * from './email.component'; export * from './first_name.component'; export * from './fiscal_id.component'; export * from './guild_id.component'; +export * from './individual_economic_code.component'; export * from './invoice_templates.component'; export * from './last_name.component'; +export * from './legal_economic_code.component'; export * from './legal_name.component'; export * from './license_starts_at.component'; export * from './mobile.component'; diff --git a/src/app/shared/components/fields/individual_economic_code.component.ts b/src/app/shared/components/fields/individual_economic_code.component.ts new file mode 100644 index 0000000..553d759 --- /dev/null +++ b/src/app/shared/components/fields/individual_economic_code.component.ts @@ -0,0 +1,19 @@ +import { Component, Input } from '@angular/core'; +import { FormControl, ReactiveFormsModule } from '@angular/forms'; +import { InputComponent } from '../input/input.component'; + +@Component({ + selector: 'field-individual-economic-code', + template: ``, + imports: [ReactiveFormsModule, InputComponent], +}) +export class IndividualEconomicCodeComponent { + @Input({ required: true }) control = new FormControl(''); + @Input() name = 'individual_economic_code'; +} diff --git a/src/app/shared/components/fields/economic_code.component.ts b/src/app/shared/components/fields/legal_economic_code.component.ts similarity index 53% rename from src/app/shared/components/fields/economic_code.component.ts rename to src/app/shared/components/fields/legal_economic_code.component.ts index 8c9cd7f..7b9ed6b 100644 --- a/src/app/shared/components/fields/economic_code.component.ts +++ b/src/app/shared/components/fields/legal_economic_code.component.ts @@ -3,11 +3,17 @@ import { FormControl, ReactiveFormsModule } from '@angular/forms'; import { InputComponent } from '../input/input.component'; @Component({ - selector: 'field-economic-code', - template: ``, + selector: 'field-legal-economic-code', + template: ``, imports: [ReactiveFormsModule, InputComponent], }) -export class EconomicCodeComponent { +export class LegalEconomicCodeComponent { @Input({ required: true }) control = new FormControl(''); - @Input() name = 'economic_code'; + @Input() name = 'legal_economic_code'; } diff --git a/src/app/shared/components/invoices/sale-invoice-single-view.component.ts b/src/app/shared/components/invoices/sale-invoice-single-view.component.ts index 1bf7103..01cfc18 100644 --- a/src/app/shared/components/invoices/sale-invoice-single-view.component.ts +++ b/src/app/shared/components/invoices/sale-invoice-single-view.component.ts @@ -6,6 +6,7 @@ import { PosInfoStore } from '@/domains/pos/store'; import { CatalogInvoiceTypeTagComponent, CatalogTaxProviderStatusTagComponent, + TspProviderResponseStatus, } from '@/shared/catalog'; import { CatalogInvoiceSettlementTypeTagComponent } from '@/shared/catalog/invoiceSettlementType'; import { @@ -87,6 +88,7 @@ export class SharedSaleInvoiceSingleViewComponent { @Output() onRefresh = new EventEmitter(); @Output() onSendToTsp = new EventEmitter>(); + @Output() onResendToTsp = new EventEmitter>(); @Output() onInquiry = new EventEmitter>(); @ViewChild('totalAmount', { static: false }) totalAmount!: TemplateRef; @@ -102,6 +104,7 @@ export class SharedSaleInvoiceSingleViewComponent { this.showBackFromSale = this.showBackFromSale.bind(this); this.printInvoice = this.printInvoice.bind(this); this.send = this.send.bind(this); + this.resend = this.resend.bind(this); this.inquiry = this.inquiry.bind(this); } @@ -116,6 +119,9 @@ export class SharedSaleInvoiceSingleViewComponent { send() { this.onSendToTsp.emit(); } + resend() { + this.onResendToTsp.emit(); + } async showRevokeConfirmation() { await this.confirmationService.ask({ header: `ابطال صورت‌حساب‌ شماره ${this.invoice!.invoice_number}`, @@ -146,40 +152,46 @@ export class SharedSaleInvoiceSingleViewComponent { if (changes['invoice'] && this.invoice) { const invoiceStatus = this.invoice.status.value; const actions: MenuItem[] = [ + { + label: 'ارسال مجدد صورت‌حساب', + icon: 'pi pi-send', + neededStatus: TspProviderResponseStatus.SEND_FAILURE, + command: this.resend, + }, { label: 'ارسال صورت‌حساب', icon: 'pi pi-send', - neededStatus: 'NOT_SEND', + neededStatus: TspProviderResponseStatus.NOT_SEND, command: this.send, }, { label: 'استعلام وضعیت', icon: 'pi pi-info', - neededStatus: 'FISCAL_QUEUED', + neededStatus: TspProviderResponseStatus.FISCAL_QUEUED, command: this.inquiry, }, { label: 'دلایل خطا', icon: 'pi pi-question', - neededStatus: 'FAILURE', + neededStatus: TspProviderResponseStatus.FAILURE, command: this.showErrors, }, { label: 'ابطال', icon: 'pi pi-eraser', - neededStatus: 'SUCCESS', + neededStatus: TspProviderResponseStatus.SUCCESS, command: this.showRevokeConfirmation, }, { label: 'اصلاح', icon: 'pi pi-file-edit', - neededStatus: 'SUCCESS', + neededStatus: TspProviderResponseStatus.SUCCESS, command: this.showCorrection, }, { label: 'برگشت از فروش', icon: 'pi pi-cart-minus', - neededStatus: 'SUCCESS', + neededStatus: TspProviderResponseStatus.SUCCESS, command: this.showBackFromSale, }, { diff --git a/src/app/shared/constants/fields/index.ts b/src/app/shared/constants/fields/index.ts index 88a5d33..0910762 100644 --- a/src/app/shared/constants/fields/index.ts +++ b/src/app/shared/constants/fields/index.ts @@ -1,4 +1,5 @@ import { + equalLengthValidator, fiscalIdValidator, mobileValidator, password, @@ -70,9 +71,13 @@ export const fieldControl = { value, isRequired ? [...required(), usernameValidator()] : [usernameValidator()], ], - economic_code: (value = '', isRequired = true): ControlConfig => [ + legal_economic_code: (value = '', isRequired = true): ControlConfig => [ value, - isRequired ? required() : [], + isRequired ? [...required(), equalLengthValidator(11)] : [equalLengthValidator(11)], + ], + individual_economic_code: (value = '', isRequired = true): ControlConfig => [ + value, + isRequired ? [...required(), equalLengthValidator(14)] : [equalLengthValidator(14)], ], fiscal_id: (value = '', isRequired = true): ControlConfig => [ value, diff --git a/src/app/uikit/datepicker/datepicker.component.html b/src/app/uikit/datepicker/datepicker.component.html index b40532e..b0c5340 100644 --- a/src/app/uikit/datepicker/datepicker.component.html +++ b/src/app/uikit/datepicker/datepicker.component.html @@ -43,7 +43,7 @@ [ngClass]="{ 'bg-surface-ground font-bold': day.isCurrentDay, 'bg-primary! text-primary-contrast!': isSelected(day), - 'text-muted-color! font-normal': day.isDisabled, + 'text-muted-color! font-light': day.isDisabled, }" (click)="selectDate(day)"> {{ day.day }}