|
|
@@ -315,6 +315,59 @@
|
|
|
주문일: "ORDER_DATE",
|
|
|
};
|
|
|
|
|
|
+ // Excel 날짜를 문자열로 변환하는 함수 (시간 포함)
|
|
|
+ const convertExcelDate = (value) => {
|
|
|
+ // Date 객체인 경우 (XLSX 라이브러리가 cellDates: true로 자동 변환한 경우)
|
|
|
+ if (value instanceof Date) {
|
|
|
+ try {
|
|
|
+ const year = value.getFullYear();
|
|
|
+ const month = String(value.getMonth() + 1).padStart(2, '0');
|
|
|
+ const day = String(value.getDate()).padStart(2, '0');
|
|
|
+ const hours = String(value.getHours()).padStart(2, '0');
|
|
|
+ const minutes = String(value.getMinutes()).padStart(2, '0');
|
|
|
+ const seconds = String(value.getSeconds()).padStart(2, '0');
|
|
|
+ return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
|
|
|
+ } catch (error) {
|
|
|
+ console.warn('Date 객체 변환 실패:', value, error);
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 숫자 타입이고 날짜 범위에 있는지 확인 (Excel 시리얼 날짜)
|
|
|
+ if (typeof value === 'number' && value > 1 && value < 100000) {
|
|
|
+ try {
|
|
|
+ // Excel의 시리얼 번호를 Date 객체로 변환
|
|
|
+ const excelStartDate = new Date(1900, 0, 1); // 1900년 1월 1일
|
|
|
+ const convertedDate = new Date(excelStartDate.getTime() + (value - 2) * 24 * 60 * 60 * 1000);
|
|
|
+
|
|
|
+ const year = convertedDate.getFullYear();
|
|
|
+ const month = String(convertedDate.getMonth() + 1).padStart(2, '0');
|
|
|
+ const day = String(convertedDate.getDate()).padStart(2, '0');
|
|
|
+
|
|
|
+ return `${year}-${month}-${day} 00:00:00`;
|
|
|
+ } catch (error) {
|
|
|
+ console.warn('Excel 시리얼 날짜 변환 실패:', value, error);
|
|
|
+ return value;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 이미 문자열 형태의 날짜인 경우
|
|
|
+ if (typeof value === 'string') {
|
|
|
+ // YYYY.MM.DD 또는 YYYY-MM-DD 형태를 YYYY-MM-DD 00:00:00로 변환
|
|
|
+ let dateStr = value.replace(/\./g, '-').trim();
|
|
|
+
|
|
|
+ // 시간 부분이 없으면 00:00:00 추가
|
|
|
+ if (!dateStr.includes(' ') && dateStr.match(/^\d{4}-\d{2}-\d{2}$/)) {
|
|
|
+ dateStr += ' 00:00:00';
|
|
|
+ }
|
|
|
+
|
|
|
+ return dateStr;
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log('날짜 변환 대상이 아님:', typeof value, value);
|
|
|
+ return value;
|
|
|
+ };
|
|
|
+
|
|
|
const addEmptyRow = () => {
|
|
|
const newRow = {
|
|
|
BUYER_NAME: "",
|
|
|
@@ -438,10 +491,10 @@
|
|
|
reader.onload = async (e) => {
|
|
|
try {
|
|
|
const data = new Uint8Array(e.target.result);
|
|
|
- const workbook = XLSX.read(data, { type: "array" });
|
|
|
+ const workbook = XLSX.read(data, { type: "array", cellDates: true });
|
|
|
const sheetName = workbook.SheetNames[0];
|
|
|
const worksheet = workbook.Sheets[sheetName];
|
|
|
- const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
|
|
|
+ const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1, raw: false, dateNF: 'yyyy-mm-dd' });
|
|
|
|
|
|
if (jsonData.length < 2) {
|
|
|
$toast.error(
|
|
|
@@ -472,7 +525,12 @@
|
|
|
headers.forEach((header, index) => {
|
|
|
const fieldName = excelColumnMapping[header];
|
|
|
if (fieldName && row[index] !== undefined && row[index] !== "") {
|
|
|
- mappedRow[fieldName] = row[index];
|
|
|
+ // 주문일 필드인 경우 날짜 변환 처리
|
|
|
+ if (fieldName === 'ORDER_DATE') {
|
|
|
+ mappedRow[fieldName] = convertExcelDate(row[index]);
|
|
|
+ } else {
|
|
|
+ mappedRow[fieldName] = row[index];
|
|
|
+ }
|
|
|
hasValidData = true;
|
|
|
}
|
|
|
});
|
|
|
@@ -586,10 +644,10 @@
|
|
|
reader.onload = async (e) => {
|
|
|
try {
|
|
|
const data = new Uint8Array(e.target.result);
|
|
|
- const workbook = XLSX.read(data, { type: "array" });
|
|
|
+ const workbook = XLSX.read(data, { type: "array", cellDates: true });
|
|
|
const sheetName = workbook.SheetNames[0];
|
|
|
const worksheet = workbook.Sheets[sheetName];
|
|
|
- const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1 });
|
|
|
+ const jsonData = XLSX.utils.sheet_to_json(worksheet, { header: 1, raw: false, dateNF: 'yyyy-mm-dd' });
|
|
|
|
|
|
if (jsonData.length < 2) {
|
|
|
$toast.error("엑셀 파일에 데이터가 없습니다. 헤더와 최소 1개 이상의 데이터 행이 필요합니다.");
|
|
|
@@ -806,8 +864,19 @@
|
|
|
|
|
|
const formatDateForComparison = (dateStr) => {
|
|
|
if (!dateStr) return '';
|
|
|
- // YYYY.MM.DD 또는 YYYY-MM-DD 형태를 YYYY-MM-DD로 통일
|
|
|
- return dateStr.toString().replace(/\./g, '-').trim();
|
|
|
+
|
|
|
+ // 문자열로 변환하고 공백 제거
|
|
|
+ let formattedDate = dateStr.toString().trim();
|
|
|
+
|
|
|
+ // YYYY.MM.DD 형태를 YYYY-MM-DD로 변환
|
|
|
+ formattedDate = formattedDate.replace(/\./g, '-');
|
|
|
+
|
|
|
+ // 시간 부분이 있으면 제거하고 날짜 부분만 추출
|
|
|
+ if (formattedDate.includes(' ')) {
|
|
|
+ formattedDate = formattedDate.split(' ')[0];
|
|
|
+ }
|
|
|
+
|
|
|
+ return formattedDate;
|
|
|
};
|
|
|
|
|
|
const validateAndMatchOrders = async (uploadData) => {
|