Browse Source

Merge remote-tracking branch 'origin/MergeProblem1' into MergeProblem1

MergeProblem1
CANCERYS\kw093 18 hours ago
parent
commit
bdde9644f0
4 changed files with 46 additions and 14 deletions
  1. +18
    -13
      src/components/InventorySearch/InventoryLotLineTable.tsx
  2. +3
    -0
      src/components/InventorySearch/InventorySearch.tsx
  3. +20
    -0
      src/components/Swal/CustomAlerts.tsx
  4. +5
    -1
      src/i18n/zh/inventory.json

+ 18
- 13
src/components/InventorySearch/InventoryLotLineTable.tsx View File

@@ -16,6 +16,7 @@ import { Autocomplete } from "@mui/material";
import { WarehouseResult } from "@/app/api/warehouse";
import { fetchWarehouseListClient } from "@/app/api/warehouse/client";
import { createStockTransfer } from "@/app/api/inventory/actions";
import { msg, msgError } from "@/components/Swal/CustomAlerts";

interface Props {
inventoryLotLines: InventoryLotLineResult[] | null;
@@ -23,9 +24,10 @@ interface Props {
pagingController: typeof defaultPagingController;
totalCount: number;
inventory: InventoryResult | null;
onStockTransferSuccess?: () => void | Promise<void>;
}

const InventoryLotLineTable: React.FC<Props> = ({ inventoryLotLines, pagingController, setPagingController, totalCount, inventory }) => {
const InventoryLotLineTable: React.FC<Props> = ({ inventoryLotLines, pagingController, setPagingController, totalCount, inventory, onStockTransferSuccess }) => {
const { t } = useTranslation(["inventory"]);
const { setIsUploading } = useUploadContext();
const [stockTransferModalOpen, setStockTransferModalOpen] = useState(false);
@@ -44,6 +46,10 @@ const InventoryLotLineTable: React.FC<Props> = ({ inventoryLotLines, pagingContr
}
}, [stockTransferModalOpen]);

const availableLotLines = useMemo(
() => (inventoryLotLines ?? []).filter((line) => line.status?.toLowerCase() === "available"),
[inventoryLotLines]
);
const originalQty = selectedLotLine?.availableQty || 0;
const remainingQty = originalQty - qtyToBeTransferred;

@@ -67,7 +73,7 @@ const InventoryLotLineTable: React.FC<Props> = ({ inventoryLotLines, pagingContr
setStartLocation(lotLine.warehouse.code || "");
setTargetLocation(null);
setTargetLocationInput("");
setQtyToBeTransferred(0);
setQtyToBeTransferred(lotLine.availableQty >= 1 ? 1 : 0);
},
[],
);
@@ -197,7 +203,7 @@ const InventoryLotLineTable: React.FC<Props> = ({ inventoryLotLines, pagingContr
}, []);

const handleSubmitStockTransfer = useCallback(async () => {
if (!selectedLotLine || !targetLocation || qtyToBeTransferred <= 0) {
if (!selectedLotLine || !targetLocation || qtyToBeTransferred < 1) {
return;
}

@@ -213,26 +219,24 @@ const InventoryLotLineTable: React.FC<Props> = ({ inventoryLotLines, pagingContr
const response = await createStockTransfer(request);
if (response && response.type === "success") {
alert(t("Stock transfer successful"));
msg(t("Stock transfer successful"));
handleCloseStockTransferModal();
// Refresh the inventory lot lines list
window.location.reload(); // Or use your preferred refresh method
await onStockTransferSuccess?.();
} else {
throw new Error(response?.message || t("Failed to transfer stock"));
}
} catch (error: any) {
console.error("Error transferring stock:", error);
alert(error?.message || t("Failed to transfer stock. Please try again."));
msgError(error?.message || t("Failed to transfer stock. Please try again."));
} finally {
setIsUploading(false);
}
}, [selectedLotLine, targetLocation, qtyToBeTransferred, handleCloseStockTransferModal, setIsUploading, t]);
}, [selectedLotLine, targetLocation, qtyToBeTransferred, handleCloseStockTransferModal, setIsUploading, t, onStockTransferSuccess]);

return <>
<Typography variant="h6">{inventory ? `${t("Item selected")}: ${inventory.itemCode} | ${inventory.itemName} (${t(inventory.itemType)})` : t("No items are selected yet.")}</Typography>
<SearchResults<InventoryLotLineResult>
items={inventoryLotLines ?? []}
items={availableLotLines}
columns={columns}
pagingController={pagingController}
setPagingController={setPagingController}
@@ -366,10 +370,11 @@ const InventoryLotLineTable: React.FC<Props> = ({ inventoryLotLines, pagingContr
value={qtyToBeTransferred}
onChange={(e) => {
const value = parseInt(e.target.value) || 0;
const minValue = 1;
const maxValue = Math.max(0, originalQty);
setQtyToBeTransferred(Math.min(Math.max(0, value), maxValue));
setQtyToBeTransferred(Math.min(Math.max(minValue, value), maxValue));
}}
inputProps={{ min: 0, max: originalQty, step: 1 }}
inputProps={{ min: 1, max: originalQty, step: 1 }}
InputLabelProps={{
shrink: true,
sx: { fontSize: "0.9375rem" },
@@ -414,7 +419,7 @@ const InventoryLotLineTable: React.FC<Props> = ({ inventoryLotLines, pagingContr
fontSize: '0.9375rem',
}}
onClick={handleSubmitStockTransfer}
disabled={!selectedLotLine || !targetLocation || qtyToBeTransferred <= 0 || qtyToBeTransferred > originalQty}
disabled={!selectedLotLine || !targetLocation || qtyToBeTransferred < 1 || qtyToBeTransferred > originalQty}
>
{t("Submit")}
</Button>


+ 3
- 0
src/components/InventorySearch/InventorySearch.tsx View File

@@ -248,6 +248,9 @@ const InventorySearch: React.FC<Props> = ({ inventories }) => {
setPagingController={setInventoryLotLinesPagingController}
totalCount={inventoryLotLinesTotalCount}
inventory={selectedInventory}
onStockTransferSuccess={() =>
refetchInventoryLotLineData(selectedInventory?.itemId ?? null, "search", inventoryLotLinesPagingController)
}
/>
</>
);


+ 20
- 0
src/components/Swal/CustomAlerts.tsx View File

@@ -28,6 +28,26 @@ export const msg = (title: SweetAlertTitle) => {
});
};

export const msgError = (title: SweetAlertTitle) => {
Swal.mixin({
toast: true,
position: "bottom-end",
showConfirmButton: false,
timer: 3000,
timerProgressBar: true,
didOpen: (toast) => {
toast.onmouseenter = Swal.stopTimer;
toast.onmouseleave = Swal.resumeTimer;
},
customClass: {
container: 'swal2-custom-zindex',
},
}).fire({
icon: "error",
title: title,
});
};

export const popup = (options: SweetAlertOptions) => {
Swal.fire(options);
};


+ 5
- 1
src/i18n/zh/inventory.json View File

@@ -203,6 +203,10 @@
"End Date": "結束日期",
"Loading": "加載中",
"adj": "調整",
"nor": "正常"
"nor": "正常",

"Stock transfer successful": "庫存調撥成功",
"Failed to transfer stock": "庫存調撥失敗",
"Failed to transfer stock. Please try again.": "轉倉失敗,請重試。"

}

Loading…
Cancel
Save