| @@ -175,9 +175,9 @@ | ||
| 175 | 175 | $field_name = $this->camelCaseToSnakeCase(substr($name, 3)); // Remove 'has' prefix |
| 176 | 176 | return !empty($this->__get($field_name)); |
| 177 | 177 | } |
| 178 | 178 | |
| 179 | - throw new \BadMethodCallException("Method $name does not exist"); | |
| 179 | + throw new \BadMethodCallException(esc_html("Method $name does not exist")); | |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
| 183 | 183 | * Convert camelCase to snake_case |
| @@ -226,21 +226,23 @@ | ||
| 226 | 226 | * @since 1.0.0 |
| 227 | 227 | * @return float The calculated amount |
| 228 | 228 | */ |
| 229 | 229 | public function getAmount(): float { |
| 230 | - $quantity = floatval($this->data['quantity'] ?? 1); | |
| 230 | + $quantity = floatval($this->data['quantity'] ?? 0); | |
| 231 | 231 | $price = floatval($this->data['price'] ?? 0); |
| 232 | - $adjust_percentage = floatval($this->data['adjust_percentage'] ?? 0); | |
| 233 | 232 | |
| 234 | 233 | // Calculate base total |
| 235 | 234 | $base_total = $quantity * $price; |
| 236 | 235 | |
| 237 | - // Apply adjustment percentage if any | |
| 238 | - if ($adjust_percentage != 0) { | |
| 239 | - $base_total = $base_total * (1 + $adjust_percentage / 100); | |
| 236 | + // Only apply adjustment percentage if the adjust field setting is enabled | |
| 237 | + if (\EasyInvoice\Controllers\SettingsController::shouldShowInvoiceAdjustField()) { | |
| 238 | + $adjust_percentage = floatval($this->data['adjust_percentage'] ?? 0); | |
| 239 | + if ($adjust_percentage != 0) { | |
| 240 | + $base_total = $base_total * (1 + $adjust_percentage / 100); | |
| 241 | + } | |
| 240 | 242 | } |
| 241 | 243 | |
| 242 | - return $base_total; | |
| 244 | + return easy_invoice_round_money($base_total); | |
| 243 | 245 | } |
| 244 | 246 | |
| 245 | 247 | /** |
| 246 | 248 | * Check if the item is taxable |