From efba8f1f48d189bfc3182a2dc6a023a19f8c74e4 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 16 Mar 2020 04:00:06 +0000 Subject: [PATCH] Modify the pro-rate computation. #370 --- src/Command/TestWarrantyComputationCommand.php | 3 +-- src/Service/Prowar/WarrantyComputationCriteria.php | 12 ------------ src/Service/Prowar/WarrantyComputationService.php | 13 ++++++------- 3 files changed, 7 insertions(+), 21 deletions(-) diff --git a/src/Command/TestWarrantyComputationCommand.php b/src/Command/TestWarrantyComputationCommand.php index ee61eef7..8c755925 100644 --- a/src/Command/TestWarrantyComputationCommand.php +++ b/src/Command/TestWarrantyComputationCommand.php @@ -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); diff --git a/src/Service/Prowar/WarrantyComputationCriteria.php b/src/Service/Prowar/WarrantyComputationCriteria.php index 5d1de0c6..1945da54 100644 --- a/src/Service/Prowar/WarrantyComputationCriteria.php +++ b/src/Service/Prowar/WarrantyComputationCriteria.php @@ -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; diff --git a/src/Service/Prowar/WarrantyComputationService.php b/src/Service/Prowar/WarrantyComputationService.php index 723f2a48..a43493e6 100644 --- a/src/Service/Prowar/WarrantyComputationService.php +++ b/src/Service/Prowar/WarrantyComputationService.php @@ -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; } }