From a83baaf9ccc363729012ebb27ab1917c106d1898 Mon Sep 17 00:00:00 2001
From: Ari Angga Nugraha <ari.angga@ui.ac.id>
Date: Fri, 18 Dec 2020 11:31:38 +0700
Subject: [PATCH] now can count netpresentvalue with dummy fpv

---
 src/Lib.hs             |  2 +-
 src/NetPresentValue.hs | 30 ++++++++++++++++++++++++------
 2 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/src/Lib.hs b/src/Lib.hs
index 3bb7a13..3dfc832 100755
--- a/src/Lib.hs
+++ b/src/Lib.hs
@@ -21,7 +21,7 @@ data Event = Event
 data Response = Response
   { statusCode :: Int
   , headers :: Value
-  , body :: Int
+  , body :: Double
   } deriving (Generic, ToJSON)
 
 header :: Value
diff --git a/src/NetPresentValue.hs b/src/NetPresentValue.hs
index f3bb4d5..5e8b32b 100644
--- a/src/NetPresentValue.hs
+++ b/src/NetPresentValue.hs
@@ -11,12 +11,30 @@ import Aws.Lambda
 import Data.Aeson
 
 data InputNetPresentValue = InputNetPresentValue
-    { income_1 :: Int
-    , outcome_1 :: Int
+    { income_1 :: Double
+    , income_2 :: Double
+    , income_3 :: Double
+    , income_4 :: Double
+    , income_5 :: Double
+    , outcome_1 :: Double
+    , outcome_2 :: Double
+    , outcome_3 :: Double
+    , outcome_4 :: Double
+    , outcome_5 :: Double
+    , project_interest :: Double
+    , project_cost :: Double
     } deriving (Generic, FromJSON, ToJSON)
 
-calculateNetPresentValue :: InputNetPresentValue -> Int
-calculateNetPresentValue inputNetPresentValue = p + q
+calculateNetPresentValue :: InputNetPresentValue -> Double
+calculateNetPresentValue inputNetPresentValue = netPresentValue inputNetPresentValue
+
+netPresentValue inputNetPresentValue = foldl (+) 0 pv
+    where
+        pv = presentValue inputNetPresentValue
+
+presentValue inputNetPresentValue = zipWith (*) (netcashflow income outcome) [0.833, 0.694, 0.579, 0.482, 0.402]
     where
-        p = income_1 inputNetPresentValue
-        q = outcome_1 inputNetPresentValue   
\ No newline at end of file
+        income = [income_1 inputNetPresentValue, income_2 inputNetPresentValue, income_3 inputNetPresentValue, income_4 inputNetPresentValue, income_5 inputNetPresentValue]
+        outcome = [outcome_1 inputNetPresentValue, outcome_2 inputNetPresentValue, outcome_3 inputNetPresentValue, outcome_4 inputNetPresentValue, outcome_5 inputNetPresentValue]
+
+netcashflow a b = zipWith (-) a b 
-- 
GitLab