Files
mirror-cathay/src/app/pages/report/warehouse-received/warehouse-received-index.component.ts
2023-10-10 03:58:47 +07:00

84 lines
2.9 KiB
TypeScript

import {ChangeDetectorRef, Component, OnInit} from "@angular/core";
import {BaseListComponent} from "../../../@common/base/base-list.component";
import {lastValueFrom} from "rxjs";
import {AppService} from "../../../app.service";
import {API, EAction, EStatusContract, EText} from "../../../@config/app";
import {ActivatedRoute} from "@angular/router";
import {IQuotation} from "../../../@common/interface/Quotation";
import generateParamsValue from "../../../@common/utils/GenerateParamsValue";
@Component({
selector: "app-report-warehouse-received-index",
templateUrl: "./warehouse-received-index.component.html",
styleUrls: []
})
export class WarehouseReceivedIndexComponent extends BaseListComponent implements OnInit {
pageTitle = "รายงานสินค้าในคลัง";
apiUrl: string = API.quotation;
api: any = API;
masterArea = [];
constructor(
public appService: AppService,
public activatedRoute: ActivatedRoute,
public changeDetectorRef: ChangeDetectorRef
) {
super();
}
async ngOnInit() {
this.masterArea = await lastValueFrom(this.appService.get(`${this.api.masterArea}?showAll=true&status=true&orderBy=name&sort=asc`));
}
async onExport($event?: any) {
try {
this.dataFilter.statusContract = EStatusContract.APPROVED;
this.dataFilter.statusWarehouse = 'warehouse';
this.dataFilter.isReceived = true;
this.dataFilter.showAll = true;
const filter = generateParamsValue(this.dataFilter);
const dataSource = await lastValueFrom(this.appService.get(`${API.quotation}?${filter}`));
if (dataSource.length === 0) return this.appService.message(EAction.INFO, 'ไม่พบข้อมูล');
const data : any = [];
dataSource.map((item : any) => {
const customerPrefix = item.customerPrefix ? item.customerPrefix : '';
const customerName = item.customerId ? `${item.customer?.prefix} ${item.customer?.firstName} ${item.customer?.lastName}` :
`${customerPrefix} ${item.customerFirstName} ${item.customerLastName}`;
const map = {
product_code: item.productNo,
customer_name: customerName,
product_name: item.productName,
s_n: item.sellerSnProduct,
amount: Number(item.price),
installment: Number(item.wantToInstallmentTerm),
inventory_name: item.areaName,
location: item.areaLocation,
room: item.areaRoomName,
box_code: item.storageBoxCode,
messenger: item.deliveryWorker,
remark: ""
}
data.push(map)
})
const response = await lastValueFrom(this.appService.post(`${this.api.receiveInventory}/xlsx`, data, { responseType: "arraybuffer" }));
const url = URL.createObjectURL(new Blob([response], { type: "application/vnd.ms-excel" }));
window.open(url);
} catch (e) {
this.appService.message(EAction.ERROR, EText.ERROR);
}
}
}