Files
psp_panel/src/app/domains/consumer/components/invoices/shared-saleInvoice.component.ts
T

128 lines
3.1 KiB
TypeScript
Raw Normal View History

import { Maybe } from '@/core';
import { NativeBridgeService } from '@/core/services';
import { CatalogTaxProviderStatusTagComponent } from '@/shared/catalog';
2026-04-23 01:22:44 +03:30
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
import { PageLoadingComponent } from '@/shared/components/page-loading.component';
2026-04-23 01:22:44 +03:30
import {
IColumn,
PageDataListComponent,
} from '@/shared/components/pageDataList/page-data-list.component';
import { PriceMaskDirective } from '@/shared/directives';
import { UikitEmptyStateComponent } from '@/uikit';
2026-04-23 01:22:44 +03:30
import { getGoodUnitTypeProperties } from '@/utils';
import {
Component,
EventEmitter,
inject,
Input,
Output,
TemplateRef,
ViewChild,
} from '@angular/core';
2026-05-04 20:02:10 +03:30
import { UrlTree } from '@angular/router';
2026-04-23 01:22:44 +03:30
import { ButtonDirective } from 'primeng/button';
import { Divider } from 'primeng/divider';
import { TableModule } from 'primeng/table';
import { ISaleInvoiceFullResponse } from '../../models';
2026-04-23 01:22:44 +03:30
export type TConsumerSaleInvoice = 'full' | 'customer' | 'pos';
@Component({
selector: 'consumer-saleInvoice-shared',
templateUrl: './shared-saleInvoice.component.html',
imports: [
AppCardComponent,
KeyValueComponent,
Divider,
ButtonDirective,
PageDataListComponent,
TableModule,
PageLoadingComponent,
UikitEmptyStateComponent,
PriceMaskDirective,
CatalogTaxProviderStatusTagComponent,
2026-04-23 01:22:44 +03:30
],
})
export class ConsumerSaleInvoiceSharedComponent {
private readonly nativeBridge = inject(NativeBridgeService);
2026-04-23 01:22:44 +03:30
@Input({ required: true }) loading!: boolean;
@Input() invoice?: Maybe<ISaleInvoiceFullResponse>;
2026-04-23 01:22:44 +03:30
@Input() variant: TConsumerSaleInvoice = 'full';
2026-05-04 20:02:10 +03:30
@Input() backRoute?: UrlTree | string | any[];
2026-04-23 01:22:44 +03:30
@Output() onRefresh = new EventEmitter<void>();
@ViewChild('totalAmount', { static: false }) totalAmount!: TemplateRef<any>;
2026-04-23 01:22:44 +03:30
printInvoice = () => {
if (this.nativeBridge.isEnabled()) {
const result = this.nativeBridge.print({
invoiceId: this.invoice?.id,
code: this.invoice?.code,
});
if (result.success) return;
}
2026-04-23 01:22:44 +03:30
window.print();
};
columns: IColumn[] = [
{
field: '',
header: '',
type: 'index',
},
{
field: 'name',
header: 'عنوان',
type: 'nested',
nestedOption: {
path: 'good.name',
},
2026-04-23 01:22:44 +03:30
},
{
field: 'unit_price',
header: 'قیمت واحد',
type: 'price',
},
{
field: 'quantity',
header: 'مقدار',
customDataModel(item) {
return `${item.quantity} ${getGoodUnitTypeProperties(item.good.unit_type).quantitySymbolText}`;
},
},
{
field: 'total_amount',
header: 'قیمت نهایی',
type: 'price',
// customDataModel: this.totalAmount,
2026-04-23 01:22:44 +03:30
},
];
expandableColumns: IColumn[] = [
{
field: 'commission',
header: 'کارمزد',
type: 'price',
},
{
field: 'wages',
header: 'اجرت',
2026-04-23 01:22:44 +03:30
type: 'price',
},
{
field: 'profit',
header: 'سود',
2026-04-23 01:22:44 +03:30
type: 'price',
},
];
expandedRows: { [key: string]: boolean } = {};
refresh() {
this.onRefresh.emit();
}
2026-04-23 01:22:44 +03:30
}