Fix payment transaction edit save and Jalali due date display.
Convert dates between Jalali picker values and ISO before API calls, and format due dates with proper Persian calendar tokens and digits.
This commit is contained in:
@@ -19,34 +19,49 @@ export function usePersianDate() {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatJalali = (date, formatStr = 'YYYY/MM/DD') => {
|
const formatJalali = (date, formatStr = 'jYYYY/jMM/jDD') => {
|
||||||
if (!date) return '-';
|
if (!date) return '-';
|
||||||
try {
|
try {
|
||||||
return moment(date).locale('fa').format(formatStr);
|
return toPersianDigits(moment(date).locale('fa').format(formatStr));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return '-';
|
return '-';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const formatJalaliWithTime = (date) => {
|
const formatJalaliWithTime = (date) => {
|
||||||
return formatJalali(date, 'YYYY/MM/DD - HH:mm');
|
return formatJalali(date, 'jYYYY/jMM/jDD - HH:mm');
|
||||||
};
|
};
|
||||||
|
|
||||||
const jalaliToIso = (jalaliStr) => {
|
const toJalaliPickerValue = (value) => {
|
||||||
if (!jalaliStr) return null;
|
if (!value) return '';
|
||||||
try {
|
try {
|
||||||
const latinStr = toLatinDigits(jalaliStr);
|
return moment(value).locale('fa').format('jYYYY/jMM/jDD');
|
||||||
return moment(latinStr, 'jYYYY/jMM/jDD').toISOString();
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return null;
|
return '';
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const toGregorianIso = (jalaliValue) => {
|
||||||
|
if (!jalaliValue) return undefined;
|
||||||
|
if (jalaliValue instanceof Date) return jalaliValue.toISOString();
|
||||||
|
try {
|
||||||
|
const latin = toLatinDigits(String(jalaliValue));
|
||||||
|
const m = moment(latin, 'jYYYY/jMM/jDD');
|
||||||
|
return m.isValid() ? m.toDate().toISOString() : undefined;
|
||||||
|
} catch (e) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const jalaliToIso = (jalaliStr) => toGregorianIso(jalaliStr) || null;
|
||||||
|
|
||||||
return {
|
return {
|
||||||
toPersianDigits,
|
toPersianDigits,
|
||||||
toLatinDigits,
|
toLatinDigits,
|
||||||
formatJalali,
|
formatJalali,
|
||||||
formatJalaliWithTime,
|
formatJalaliWithTime,
|
||||||
|
toJalaliPickerValue,
|
||||||
|
toGregorianIso,
|
||||||
jalaliToIso
|
jalaliToIso
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -235,7 +235,7 @@ import DatePicker from 'vue3-persian-datetime-picker';
|
|||||||
|
|
||||||
const route = useRoute();
|
const route = useRoute();
|
||||||
const paymentId = route.params.id;
|
const paymentId = route.params.id;
|
||||||
const { toPersianDigits, formatJalali } = usePersianDate();
|
const { toPersianDigits, formatJalali, toJalaliPickerValue, toGregorianIso } = usePersianDate();
|
||||||
const { showSuccess, showError } = useToast();
|
const { showSuccess, showError } = useToast();
|
||||||
|
|
||||||
const payment = ref(null);
|
const payment = ref(null);
|
||||||
@@ -293,6 +293,8 @@ const fetchPayment = async () => {
|
|||||||
const handleRecordTransaction = async () => {
|
const handleRecordTransaction = async () => {
|
||||||
if (!trxForm.amount) { showError('لطفا مبلغ را وارد کنید'); return; }
|
if (!trxForm.amount) { showError('لطفا مبلغ را وارد کنید'); return; }
|
||||||
if (!trxForm.dueDate) { showError('لطفا تاریخ سررسید را وارد کنید'); return; }
|
if (!trxForm.dueDate) { showError('لطفا تاریخ سررسید را وارد کنید'); return; }
|
||||||
|
const dueDate = toGregorianIso(trxForm.dueDate);
|
||||||
|
if (!dueDate) { showError('تاریخ سررسید نامعتبر است'); return; }
|
||||||
if (trxForm.status === 'paid' && !trxForm.receiptNumber) {
|
if (trxForm.status === 'paid' && !trxForm.receiptNumber) {
|
||||||
showError('لطفا شماره فیش یا پیگیری را وارد کنید');
|
showError('لطفا شماره فیش یا پیگیری را وارد کنید');
|
||||||
return;
|
return;
|
||||||
@@ -303,13 +305,14 @@ const handleRecordTransaction = async () => {
|
|||||||
const payload = {
|
const payload = {
|
||||||
amount: trxForm.amount,
|
amount: trxForm.amount,
|
||||||
status: trxForm.status,
|
status: trxForm.status,
|
||||||
dueDate: trxForm.dueDate,
|
dueDate,
|
||||||
notes: trxForm.notes || undefined
|
notes: trxForm.notes || undefined
|
||||||
};
|
};
|
||||||
if (trxForm.status === 'paid') {
|
if (trxForm.status === 'paid') {
|
||||||
payload.method = trxForm.method;
|
payload.method = trxForm.method;
|
||||||
payload.receiptNumber = trxForm.receiptNumber;
|
payload.receiptNumber = trxForm.receiptNumber;
|
||||||
if (trxForm.date) payload.date = trxForm.date;
|
const paymentDate = toGregorianIso(trxForm.date);
|
||||||
|
if (paymentDate) payload.date = paymentDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await paymentApi.recordTransaction(paymentId, payload);
|
const res = await paymentApi.recordTransaction(paymentId, payload);
|
||||||
@@ -330,8 +333,8 @@ const openEditTransaction = (trx) => {
|
|||||||
editForm.status = trx.status || (trx.date ? 'paid' : 'pending');
|
editForm.status = trx.status || (trx.date ? 'paid' : 'pending');
|
||||||
editForm.method = trx.method || 'card';
|
editForm.method = trx.method || 'card';
|
||||||
editForm.receiptNumber = trx.receiptNumber || '';
|
editForm.receiptNumber = trx.receiptNumber || '';
|
||||||
editForm.dueDate = trx.dueDate || '';
|
editForm.dueDate = toJalaliPickerValue(trx.dueDate);
|
||||||
editForm.date = trx.date || '';
|
editForm.date = toJalaliPickerValue(trx.date);
|
||||||
editForm.notes = trx.notes || '';
|
editForm.notes = trx.notes || '';
|
||||||
showEditModal.value = true;
|
showEditModal.value = true;
|
||||||
};
|
};
|
||||||
@@ -345,19 +348,24 @@ const handleUpdateTransaction = async () => {
|
|||||||
showError('لطفا تاریخ سررسید را وارد کنید');
|
showError('لطفا تاریخ سررسید را وارد کنید');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const dueDate = toGregorianIso(editForm.dueDate);
|
||||||
|
if (!dueDate) {
|
||||||
|
showError('تاریخ سررسید نامعتبر است');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
isSubmittingEdit.value = true;
|
isSubmittingEdit.value = true;
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
amount: editForm.amount,
|
amount: editForm.amount,
|
||||||
status: editForm.status,
|
status: editForm.status,
|
||||||
dueDate: editForm.dueDate,
|
dueDate,
|
||||||
notes: editForm.notes
|
notes: editForm.notes
|
||||||
};
|
};
|
||||||
if (editForm.status === 'paid') {
|
if (editForm.status === 'paid') {
|
||||||
payload.method = editForm.method;
|
payload.method = editForm.method;
|
||||||
payload.receiptNumber = editForm.receiptNumber;
|
payload.receiptNumber = editForm.receiptNumber;
|
||||||
payload.date = editForm.date || undefined;
|
payload.date = toGregorianIso(editForm.date);
|
||||||
}
|
}
|
||||||
|
|
||||||
const res = await paymentApi.updateTransaction(editingTransactionId.value, payload);
|
const res = await paymentApi.updateTransaction(editingTransactionId.value, payload);
|
||||||
|
|||||||
@@ -198,7 +198,7 @@ import Checkbox from 'primevue/checkbox';
|
|||||||
import Textarea from 'primevue/textarea';
|
import Textarea from 'primevue/textarea';
|
||||||
import DatePicker from 'vue3-persian-datetime-picker';
|
import DatePicker from 'vue3-persian-datetime-picker';
|
||||||
|
|
||||||
const { toPersianDigits, formatJalali } = usePersianDate();
|
const { toPersianDigits, formatJalali, toGregorianIso } = usePersianDate();
|
||||||
const { showSuccess, showError } = useToast();
|
const { showSuccess, showError } = useToast();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@@ -326,6 +326,8 @@ const handleCreatePayment = async () => {
|
|||||||
if (!createForm.user) { showError('لطفا کاربر را انتخاب کنید'); return; }
|
if (!createForm.user) { showError('لطفا کاربر را انتخاب کنید'); return; }
|
||||||
if (!createForm.amount) { showError('لطفا مبلغ را وارد کنید'); return; }
|
if (!createForm.amount) { showError('لطفا مبلغ را وارد کنید'); return; }
|
||||||
if (!createForm.dueDate) { showError('لطفا تاریخ سررسید را وارد کنید'); return; }
|
if (!createForm.dueDate) { showError('لطفا تاریخ سررسید را وارد کنید'); return; }
|
||||||
|
const dueDate = toGregorianIso(createForm.dueDate);
|
||||||
|
if (!dueDate) { showError('تاریخ سررسید نامعتبر است'); return; }
|
||||||
|
|
||||||
if (hasDiscount.value && (createForm.discount || 0) > createForm.amount) {
|
if (hasDiscount.value && (createForm.discount || 0) > createForm.amount) {
|
||||||
showError('مبلغ تخفیف نمیتواند بیشتر از مبلغ کل باشد');
|
showError('مبلغ تخفیف نمیتواند بیشتر از مبلغ کل باشد');
|
||||||
@@ -336,6 +338,7 @@ const handleCreatePayment = async () => {
|
|||||||
try {
|
try {
|
||||||
await paymentApi.create({
|
await paymentApi.create({
|
||||||
...createForm,
|
...createForm,
|
||||||
|
dueDate,
|
||||||
discount: hasDiscount.value ? (createForm.discount || 0) : 0,
|
discount: hasDiscount.value ? (createForm.discount || 0) : 0,
|
||||||
notify: { ...createNotify }
|
notify: { ...createNotify }
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user