Modify the pro-rate computation. #370
This commit is contained in:
parent
33c76d6d78
commit
efba8f1f48
3 changed files with 7 additions and 21 deletions
|
|
@ -35,10 +35,9 @@ class TestWarrantyComputationCommand extends Command
|
|||
|
||||
// set test values
|
||||
$warr_criteria->setTotalWarranty(24)
|
||||
->setPurchaseDate(DateTime::createFromFormat('Y-m-d', '2018-06-15'))
|
||||
->setPurchaseDate(DateTime::createFromFormat('Y-m-d', '2019-01-15'))
|
||||
->setClaimDate(new DateTime())
|
||||
->setBatteryPrice(100.00)
|
||||
->setRate(5)
|
||||
->setWarrantyLimit(12);
|
||||
|
||||
$amount = $this->wcs->generateWarrantyComputation($warr_criteria);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ class WarrantyComputationCriteria
|
|||
protected $purchase_date; // DateTime
|
||||
protected $claim_date; // DateTime
|
||||
protected $battery_price;
|
||||
protected $rate; // percent?
|
||||
protected $warranty_limit;
|
||||
|
||||
public function setTotalWarranty($total_warranty)
|
||||
|
|
@ -55,17 +54,6 @@ class WarrantyComputationCriteria
|
|||
return $this->battery_price;
|
||||
}
|
||||
|
||||
public function setRate($rate)
|
||||
{
|
||||
$this->rate = $rate;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getRate()
|
||||
{
|
||||
return $this->rate;
|
||||
}
|
||||
|
||||
public function setWarrantyLimit($warranty_limit)
|
||||
{
|
||||
$this->warranty_limit = $warranty_limit;
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ class WarrantyComputationService
|
|||
// $purchase_date = DateTime::createFromFormat('Y-m-d', $criteria->getPurchaseDate());
|
||||
// $claim_date = DateTime::createFromFormat('Y-m-d', $criteria->getClaimDate());
|
||||
$purchase_date = $criteria->getPurchaseDate();
|
||||
$claim_date = $criteria->getClaimdate();
|
||||
$claim_date = $criteria->getClaimDate();
|
||||
|
||||
// compute number of months between purchase date and claim date
|
||||
$interval = $purchase_date->diff($claim_date);
|
||||
|
|
@ -46,14 +46,13 @@ class WarrantyComputationService
|
|||
if (($diff_in_months > $warranty_limit) && ($diff_in_days > 0))
|
||||
{
|
||||
// compute pro-rate
|
||||
// assuming percentage
|
||||
// this whole thing can still change
|
||||
// formula: remaining months/total warranty = percent discount
|
||||
$percent_discount = ($total_warranty - $diff_in_months)/$total_warranty;
|
||||
|
||||
$battery_price = $criteria->getBatteryPrice();
|
||||
$rate = $criteria->getRate() * 0.01;
|
||||
|
||||
$total_rate = ($diff_in_months - $warranty_limit) * $rate;
|
||||
|
||||
$customer_amount = $total_rate * $battery_price;
|
||||
$discount_amount = $battery_price * $percent_discount;
|
||||
$customer_amount = $battery_price - $discount_amount;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue