Andrew Wallo 5 月之前
父節點
當前提交
353123ad81
共有 1 個檔案被更改,包括 9 行新增2 行删除
  1. 9
    2
      app/View/Models/DocumentTotalViewModel.php

+ 9
- 2
app/View/Models/DocumentTotalViewModel.php 查看文件

@@ -32,8 +32,7 @@ class DocumentTotalViewModel
32 32
 
33 33
         $grandTotalInCents = $subtotalInCents + ($taxTotalInCents - $discountTotalInCents);
34 34
 
35
-        // Amount Due is the same as Grand Total for now, but can be modified later to account for payments
36
-        $amountDueInCents = $grandTotalInCents;
35
+        $amountDueInCents = $this->calculateAmountDueInCents($grandTotalInCents, $currencyCode);
37 36
 
38 37
         $conversionMessage = $this->buildConversionMessage($grandTotalInCents, $currencyCode, $defaultCurrencyCode);
39 38
 
@@ -128,4 +127,12 @@ class DocumentTotalViewModel
128 127
             $defaultCurrencyCode
129 128
         );
130 129
     }
130
+
131
+    private function calculateAmountDueInCents(int $grandTotalInCents, string $currencyCode): int
132
+    {
133
+        $amountPaid = $this->data['amount_paid'] ?? '0.00';
134
+        $amountPaidInCents = CurrencyConverter::convertToCents($amountPaid, $currencyCode);
135
+
136
+        return $grandTotalInCents - $amountPaidInCents;
137
+    }
131 138
 }

Loading…
取消
儲存