|  | @@ -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 |  }
 |