chore: install prettier

This commit is contained in:
Viet An
2026-05-04 15:22:27 +07:00
parent 93d29ca7d8
commit bd58e2b847
267 changed files with 22950 additions and 13581 deletions

View File

@@ -1,5 +1,5 @@
// composables/usePaymentCalculator.js
import { ref, computed } from 'vue';
import { ref, computed } from "vue";
export function usePaymentCalculator() {
// Inputs cơ bản
@@ -24,12 +24,14 @@ export function usePaymentCalculator() {
const details = [];
let currentBalance = originPrice.value || 0;
discounts.value.forEach(discountData => {
discounts.value.forEach((discountData) => {
const d = discountData;
let amount = 0;
if (d.type === 1) { // percent
if (d.type === 1) {
// percent
amount = (currentBalance * Number(d.value)) / 100;
} else { // fixed
} else {
// fixed
amount = Number(d.value);
}
if (currentBalance - amount < 0) {
@@ -44,7 +46,7 @@ export function usePaymentCalculator() {
customValue: d.value,
customType: d.type,
amount: amount,
remaining: currentBalance
remaining: currentBalance,
});
});
return details;
@@ -77,7 +79,7 @@ export function usePaymentCalculator() {
let lastToDateForPeriodCalc = new Date(startDate.value); // Used to calculate the duration of each installment period.
sortedPlan.forEach(plan => {
sortedPlan.forEach((plan) => {
let amount = 0;
// Xử lý linh hoạt theo type của Payment_Plan
@@ -110,7 +112,7 @@ export function usePaymentCalculator() {
status: 1,
type: plan.type,
value: plan.value,
payment_note: `Thanh toán theo kế hoạch đợt số ${plan.cycle}`
payment_note: `Thanh toán theo kế hoạch đợt số ${plan.cycle}`,
});
lastToDateForPeriodCalc = new Date(toDate); // Update the last due date for the next period's duration calculation.
@@ -133,12 +135,18 @@ export function usePaymentCalculator() {
const schedule = originalPaymentSchedule.value;
const numEarly = Math.min(earlyPaymentCycles.value, schedule.length);
const actualPaymentDate = new Date(startDate.value);
const actualPaymentDateOnly = new Date(actualPaymentDate.getFullYear(), actualPaymentDate.getMonth(), actualPaymentDate.getDate());
const actualPaymentDateOnly = new Date(
actualPaymentDate.getFullYear(),
actualPaymentDate.getMonth(),
actualPaymentDate.getDate(),
);
return schedule.slice(0, numEarly).map(item => {
return schedule.slice(0, numEarly).map((item) => {
const originalDate = new Date(item.to_date);
const originalDateOnly = new Date(originalDate.getFullYear(), originalDate.getMonth(), originalDate.getDate());
const earlyDays = Math.round((originalDateOnly.getTime() - actualPaymentDateOnly.getTime()) / (1000 * 60 * 60 * 24));
const earlyDays = Math.round(
(originalDateOnly.getTime() - actualPaymentDateOnly.getTime()) / (1000 * 60 * 60 * 24),
);
if (earlyDays <= 0) {
return 0;
@@ -159,12 +167,18 @@ export function usePaymentCalculator() {
const schedule = originalPaymentSchedule.value;
const numEarly = Math.min(earlyPaymentCycles.value, schedule.length);
const actualPaymentDate = new Date(startDate.value);
const actualPaymentDateOnly = new Date(actualPaymentDate.getFullYear(), actualPaymentDate.getMonth(), actualPaymentDate.getDate());
const actualPaymentDateOnly = new Date(
actualPaymentDate.getFullYear(),
actualPaymentDate.getMonth(),
actualPaymentDate.getDate(),
);
return schedule.slice(0, numEarly).map((item, index) => {
const originalDate = new Date(item.to_date);
const originalDateOnly = new Date(originalDate.getFullYear(), originalDate.getMonth(), originalDate.getDate());
const earlyDays = Math.round((originalDateOnly.getTime() - actualPaymentDateOnly.getTime()) / (1000 * 60 * 60 * 24));
const earlyDays = Math.round(
(originalDateOnly.getTime() - actualPaymentDateOnly.getTime()) / (1000 * 60 * 60 * 24),
);
return {
cycle: item.cycle,
@@ -189,7 +203,7 @@ export function usePaymentCalculator() {
const totalEarlyAmount = earlyItems.reduce((sum, i) => sum + i.amount, 0);
const mergedAmount = totalEarlyAmount - totalEarlyDiscount.value;
const originalCycles = earlyItems.map(i => i.cycle);
const originalCycles = earlyItems.map((i) => i.cycle);
const mergedItem = {
cycle: 1,
@@ -198,11 +212,11 @@ export function usePaymentCalculator() {
amount: Math.max(0, mergedAmount),
paid_amount: 0,
remain_amount: Math.max(0, mergedAmount),
payment_note: `Thanh toán gộp đợt ${originalCycles.join(', ')} (đã trừ số tiền chiết khấu thanh toán sớm là ${totalEarlyDiscount.value})`,
payment_note: `Thanh toán gộp đợt ${originalCycles.join(", ")} (đã trừ số tiền chiết khấu thanh toán sớm là ${totalEarlyDiscount.value})`,
days: 0,
status: 1,
is_merged: true,
original_cycles: originalCycles
original_cycles: originalCycles,
};
const remainingItems = base.slice(numEarly).map((item, idx) => ({
@@ -215,7 +229,7 @@ export function usePaymentCalculator() {
// Lịch thanh toán cuối cùng
const finalPaymentSchedule = computed(() => {
const schedule = scheduleAfterEarly.value.map(item => ({ ...item }));
const schedule = scheduleAfterEarly.value.map((item) => ({ ...item }));
let remainingPaid = paidAmount.value || 0;
for (let i = 0; i < schedule.length && remainingPaid > 0; i++) {
@@ -235,9 +249,7 @@ export function usePaymentCalculator() {
return schedule;
});
const totalRemaining = computed(() =>
finalPaymentSchedule.value.reduce((sum, item) => sum + item.remain_amount, 0)
);
const totalRemaining = computed(() => finalPaymentSchedule.value.reduce((sum, item) => sum + item.remain_amount, 0));
return {
originPrice,
@@ -261,4 +273,4 @@ export function usePaymentCalculator() {
totalEarlyDiscount,
totalRemaining,
};
}
}