fix: make last license date input only applicable to one-time purchases and ensure multiplier only affects one_time products
All checks were successful
Staging Build / build (push) Successful in 2m22s
All checks were successful
Staging Build / build (push) Successful in 2m22s
This commit is contained in:
@@ -274,6 +274,9 @@ export function OrderWizard({
|
|||||||
const handleBillingIntervalChange = (val: 'one_time' | 'monthly') => {
|
const handleBillingIntervalChange = (val: 'one_time' | 'monthly') => {
|
||||||
setSelectedBillingInterval(val)
|
setSelectedBillingInterval(val)
|
||||||
setModuleQuantities({})
|
setModuleQuantities({})
|
||||||
|
if (val === 'monthly') {
|
||||||
|
setLastLicenseDate("")
|
||||||
|
}
|
||||||
const newSelections: Record<string, CategorySelection> = {}
|
const newSelections: Record<string, CategorySelection> = {}
|
||||||
categories.forEach(cat => {
|
categories.forEach(cat => {
|
||||||
const matchingProd = products.find(p =>
|
const matchingProd = products.find(p =>
|
||||||
@@ -437,24 +440,6 @@ export function OrderWizard({
|
|||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{selectedEndCustomerId && (
|
|
||||||
<div className="p-4 rounded-xl bg-white/5 border border-white/10 space-y-3 mt-4 max-w-md">
|
|
||||||
<Label htmlFor="last-license-date" className="text-white font-medium flex items-center gap-2">
|
|
||||||
<Calendar className="w-4 h-4 text-primary" />
|
|
||||||
Datum der letzten CAS-Lizenz (falls vorhanden)
|
|
||||||
</Label>
|
|
||||||
<Input
|
|
||||||
id="last-license-date"
|
|
||||||
type="date"
|
|
||||||
value={lastLicenseDate}
|
|
||||||
onChange={e => setLastLicenseDate(e.target.value)}
|
|
||||||
className="bg-[#0b1329] border-white/10 text-white focus:border-primary"
|
|
||||||
/>
|
|
||||||
<p className="text-xs text-slate-400">
|
|
||||||
Falls dieser Kunde bereits Lizenzen besitzt, tragen Sie das Datum der letzten Lizenzierung ein. Damit werden die korrekten Update-Gebühren ermittelt.
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@@ -583,6 +568,24 @@ export function OrderWizard({
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
{selectedBillingInterval === 'one_time' && customerMode === 'select' && selectedEndCustomerId && (
|
||||||
|
<div className="p-4 rounded-xl bg-white/5 border border-white/10 space-y-3 mt-6 max-w-md animate-in fade-in slide-in-from-top-2 duration-300">
|
||||||
|
<Label htmlFor="last-license-date" className="text-white font-medium flex items-center gap-2">
|
||||||
|
<Calendar className="w-4 h-4 text-primary" />
|
||||||
|
Datum der letzten CAS-Lizenz (falls vorhanden)
|
||||||
|
</Label>
|
||||||
|
<Input
|
||||||
|
id="last-license-date"
|
||||||
|
type="date"
|
||||||
|
value={lastLicenseDate}
|
||||||
|
onChange={e => setLastLicenseDate(e.target.value)}
|
||||||
|
className="bg-[#0b1329] border-white/10 text-white focus:border-primary"
|
||||||
|
/>
|
||||||
|
<p className="text-xs text-slate-400">
|
||||||
|
Falls dieser Kunde bereits Lizenzen besitzt, tragen Sie das Datum der letzten Lizenzierung ein. Damit werden die korrekten Update-Gebühren ermittelt.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
<CardFooter className="flex justify-between border-t border-white/10 pt-6">
|
<CardFooter className="flex justify-between border-t border-white/10 pt-6">
|
||||||
<Button variant="ghost" className="text-white" onClick={prevStep}>
|
<Button variant="ghost" className="text-white" onClick={prevStep}>
|
||||||
|
|||||||
@@ -138,7 +138,8 @@ export function buildOrderSnapshot(
|
|||||||
: 'monthly')
|
: 'monthly')
|
||||||
|
|
||||||
let multiplier = 1
|
let multiplier = 1
|
||||||
if (lastLicenseDate && billingCycle === 'one_time') {
|
const hasOneTime = items.some(item => item.billing_interval === 'one_time')
|
||||||
|
if (lastLicenseDate && hasOneTime) {
|
||||||
const lastDate = new Date(lastLicenseDate)
|
const lastDate = new Date(lastLicenseDate)
|
||||||
const today = new Date()
|
const today = new Date()
|
||||||
const yearsDiff = today.getFullYear() - lastDate.getFullYear()
|
const yearsDiff = today.getFullYear() - lastDate.getFullYear()
|
||||||
@@ -159,11 +160,13 @@ export function buildOrderSnapshot(
|
|||||||
multiplier = 0.90
|
multiplier = 0.90
|
||||||
}
|
}
|
||||||
|
|
||||||
// Multiply item_total in items by multiplier
|
// Multiply only one_time item totals by multiplier
|
||||||
items.forEach(item => {
|
items.forEach(item => {
|
||||||
item.item_total = item.item_total * multiplier
|
if (item.billing_interval === 'one_time') {
|
||||||
|
item.item_total = item.item_total * multiplier
|
||||||
|
}
|
||||||
})
|
})
|
||||||
subtotal = subtotal * multiplier
|
subtotal = items.reduce((acc, item) => acc + item.item_total, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
const taxAmount = Math.round(subtotal * (dominantTaxRate / 100) * 100) / 100
|
const taxAmount = Math.round(subtotal * (dominantTaxRate / 100) * 100) / 100
|
||||||
@@ -178,7 +181,7 @@ export function buildOrderSnapshot(
|
|||||||
tax_amount: taxAmount,
|
tax_amount: taxAmount,
|
||||||
total,
|
total,
|
||||||
last_license_date: lastLicenseDate || null,
|
last_license_date: lastLicenseDate || null,
|
||||||
price_multiplier: lastLicenseDate && billingCycle === 'one_time' ? multiplier : null,
|
price_multiplier: lastLicenseDate && hasOneTime ? multiplier : null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user