Passed
Push — developer ( 6d71b3...948c6c )
by Radosław
32:02 queued 16:41
created

PaymentsIn_FinvoicePaymentStatus_Model   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 10
c 0
b 0
f 0
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A canUpdatePaymentStatus() 0 9 4
1
<?php
2
/**
3
 * The file contains: Class to change the payment status of a sales invoice.
4
 *
5
 * @package Model
6
 *
7
 * @copyright YetiForce S.A.
8
 * @license YetiForce Public License 5.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author Arkadiusz Adach <[email protected]>
10
 */
11
12
/**
13
 * Class to change the payment status of a sales invoice.
14
 */
15
class PaymentsIn_FinvoicePaymentStatus_Model extends PaymentsIn_PaymentStatus_Model
16
{
17
	/** {@inheritdoc} */
18
	protected static $moduleName = 'FInvoice';
19
20
	/** {@inheritdoc} */
21
	protected static $fieldPaymentStatusName = 'payment_status';
22
23
	/** {@inheritdoc} */
24
	protected static $fieldPaymentSumName = 'payment_sum';
25
26
	/** {@inheritdoc} */
27
	protected static $relatedRecordIdName = 'finvoiceid';
28
29
	/** {@inheritdoc} */
30
	protected static function canUpdatePaymentStatus(Vtiger_Record_Model $recordModel): bool
31
	{
32
		$returnValue = parent::canUpdatePaymentStatus($recordModel);
33
		if (($returnValue || false !== $recordModel->getPreviousValue(static::$relatedRecordIdName)) && (int) $recordModel->get('currency_id') !== \App\Record::getCurrencyIdFromInventory($recordModel->get(static::$relatedRecordIdName), static::$moduleName)
34
		) {
35
			\App\Log::warning('The payment is in a different currency than the related record: ' . $recordModel->get(static::$relatedRecordIdName));
36
			$returnValue = false;
37
		}
38
		return $returnValue;
39
	}
40
}
41