| @@ -0,0 +1,17 @@ | |||||
| "use server"; | |||||
| import { serverFetchBlob } from "@/app/utils/fetchUtil"; | |||||
| import { BASE_API_URL } from "@/config/api"; | |||||
| import { cache } from "react"; | |||||
| export const getMailTemplateForStockInLine = cache(async (stockInLineId: number) => { | |||||
| console.log("stockInLineId", stockInLineId) | |||||
| return serverFetchBlob(`${BASE_API_URL}/mailTemplates/getMailTemplateForStockInLine/${stockInLineId}`, | |||||
| { | |||||
| method: "GET", | |||||
| headers: { "Content-Type": "application/json" }, | |||||
| next: { | |||||
| tags: ["mailTemplateForStockInLine"], | |||||
| }, | |||||
| }) | |||||
| }) | |||||
| @@ -3,6 +3,11 @@ import { getServerSession } from "next-auth"; | |||||
| import { headers } from "next/headers"; | import { headers } from "next/headers"; | ||||
| import { redirect } from "next/navigation"; | import { redirect } from "next/navigation"; | ||||
| export interface BlobResponse { | |||||
| filename: string; | |||||
| blobValue: Uint8Array; | |||||
| } | |||||
| export interface Pageable { | export interface Pageable { | ||||
| pageSize?: number; | pageSize?: number; | ||||
| pageNum?: number; | pageNum?: number; | ||||
| @@ -86,7 +91,7 @@ export async function serverFetchJson<T>(...args: FetchParams) { | |||||
| } | } | ||||
| } | } | ||||
| export async function serverFetchBlob<T>(...args: FetchParams) { | |||||
| export async function serverFetchBlob<T extends BlobResponse>(...args: FetchParams) { | |||||
| const response = await serverFetch(...args); | const response = await serverFetch(...args); | ||||
| if (response.ok) { | if (response.ok) { | ||||
| @@ -68,7 +68,7 @@ import PoQcStockInModal from "./PoQcStockInModal"; | |||||
| import QrModal from "./QrModal"; | import QrModal from "./QrModal"; | ||||
| import { PlayArrow } from "@mui/icons-material"; | import { PlayArrow } from "@mui/icons-material"; | ||||
| import DoneIcon from "@mui/icons-material/Done"; | import DoneIcon from "@mui/icons-material/Done"; | ||||
| import { getCustomWidth } from "@/app/utils/commonUtil"; | |||||
| import { downloadFile, getCustomWidth } from "@/app/utils/commonUtil"; | |||||
| import PoInfoCard from "./PoInfoCard"; | import PoInfoCard from "./PoInfoCard"; | ||||
| import { decimalFormatter, integerFormatter } from "@/app/utils/formatUtil"; | import { decimalFormatter, integerFormatter } from "@/app/utils/formatUtil"; | ||||
| import { List, ListItem, ListItemButton, ListItemText, Divider } from "@mui/material"; | import { List, ListItem, ListItemButton, ListItemText, Divider } from "@mui/material"; | ||||
| @@ -78,6 +78,7 @@ import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; | |||||
| import { DatePicker, LocalizationProvider, zhHK } from "@mui/x-date-pickers"; | import { DatePicker, LocalizationProvider, zhHK } from "@mui/x-date-pickers"; | ||||
| import { debounce } from "lodash"; | import { debounce } from "lodash"; | ||||
| import LoadingComponent from "../General/LoadingComponent"; | import LoadingComponent from "../General/LoadingComponent"; | ||||
| import { getMailTemplateForStockInLine } from "@/app/api/mailTemplate/actions"; | |||||
| //import { useRouter } from "next/navigation"; | //import { useRouter } from "next/navigation"; | ||||
| @@ -333,6 +334,13 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { | |||||
| setPurchaseOrder(newPo); | setPurchaseOrder(newPo); | ||||
| }, [purchaseOrder.id]); | }, [purchaseOrder.id]); | ||||
| const handleMailTemplateForStockInLine = useCallback(async (stockInLineId: number) => { | |||||
| const response = await getMailTemplateForStockInLine(stockInLineId) | |||||
| if (response) { | |||||
| downloadFile(new Uint8Array(response.blobValue), response.filename); | |||||
| } | |||||
| }, []) | |||||
| useEffect(() => { | useEffect(() => { | ||||
| setRows(purchaseOrder.pol || []); | setRows(purchaseOrder.pol || []); | ||||
| }, [purchaseOrder]); | }, [purchaseOrder]); | ||||
| @@ -849,6 +857,7 @@ const PoDetail: React.FC<Props> = ({ po, qc, warehouse }) => { | |||||
| itemDetail={selectedRow} | itemDetail={selectedRow} | ||||
| warehouse={warehouse} | warehouse={warehouse} | ||||
| fetchPoDetail={fetchPoDetail} | fetchPoDetail={fetchPoDetail} | ||||
| handleMailTemplateForStockInLine={handleMailTemplateForStockInLine} | |||||
| /> | /> | ||||
| </Box> | </Box> | ||||
| </TableCell> | </TableCell> | ||||
| @@ -74,6 +74,7 @@ interface Props { | |||||
| stockInLine: StockInLine[]; | stockInLine: StockInLine[]; | ||||
| warehouse: WarehouseResult[]; | warehouse: WarehouseResult[]; | ||||
| fetchPoDetail: (poId: string) => void; | fetchPoDetail: (poId: string) => void; | ||||
| handleMailTemplateForStockInLine: (stockInLineId: number) => void; | |||||
| } | } | ||||
| export type StockInLineEntryError = { | export type StockInLineEntryError = { | ||||
| @@ -112,7 +113,8 @@ function PoInputGrid({ | |||||
| itemDetail, | itemDetail, | ||||
| stockInLine, | stockInLine, | ||||
| warehouse, | warehouse, | ||||
| fetchPoDetail | |||||
| fetchPoDetail, | |||||
| handleMailTemplateForStockInLine | |||||
| }: Props) { | }: Props) { | ||||
| console.log(itemDetail); | console.log(itemDetail); | ||||
| const { t } = useTranslation("purchaseOrder"); | const { t } = useTranslation("purchaseOrder"); | ||||
| @@ -595,7 +597,7 @@ const closeNewModal = useCallback(() => { | |||||
| variant="contained" | variant="contained" | ||||
| color="primary" | color="primary" | ||||
| sx={{ width: '150px' }} | sx={{ width: '150px' }} | ||||
| // onClick={formProps.handleSubmit(onSubmitEmailSupplier)} | |||||
| onClick={() => handleMailTemplateForStockInLine(params.row.id as number)} | |||||
| > | > | ||||
| {t("email supplier")} | {t("email supplier")} | ||||
| </Button>} | </Button>} | ||||
| @@ -604,7 +606,7 @@ const closeNewModal = useCallback(() => { | |||||
| // color: "primary.main", | // color: "primary.main", | ||||
| // marginRight: 1, | // marginRight: 1, | ||||
| }} | }} | ||||
| onClick={handleNewQC(params.row.id, params)} | |||||
| // onClick={handleNewQC(params.row.id, params)} | |||||
| color="inherit" | color="inherit" | ||||
| key="edit" | key="edit" | ||||
| />, | />, | ||||
| @@ -914,6 +916,7 @@ const closeNewModal = useCallback(() => { | |||||
| open={newOpen} | open={newOpen} | ||||
| onClose={closeNewModal} | onClose={closeNewModal} | ||||
| itemDetail={modalInfo} | itemDetail={modalInfo} | ||||
| handleMailTemplateForStockInLine={handleMailTemplateForStockInLine} | |||||
| /> | /> | ||||
| </> | </> | ||||
| ) | ) | ||||
| @@ -54,6 +54,7 @@ interface CommonProps extends Omit<ModalProps, "children"> { | |||||
| qc?: QcItemWithChecks[]; | qc?: QcItemWithChecks[]; | ||||
| warehouse?: any[]; | warehouse?: any[]; | ||||
| // type: "qc" | "stockIn" | "escalation" | "putaway" | "reject"; | // type: "qc" | "stockIn" | "escalation" | "putaway" | "reject"; | ||||
| handleMailTemplateForStockInLine: (stockInLineId: number) => void; | |||||
| } | } | ||||
| interface Props extends CommonProps { | interface Props extends CommonProps { | ||||
| itemDetail: StockInLine & { qcResult?: PurchaseQcResult[] }; | itemDetail: StockInLine & { qcResult?: PurchaseQcResult[] }; | ||||
| @@ -69,6 +70,7 @@ const PoQcStockInModalVer2: React.FC<Props> = ({ | |||||
| setItemDetail, | setItemDetail, | ||||
| qc, | qc, | ||||
| warehouse, | warehouse, | ||||
| handleMailTemplateForStockInLine, | |||||
| }) => { | }) => { | ||||
| const { | const { | ||||
| t, | t, | ||||