Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 74 additions & 24 deletions src/AmoCRM/Models/Customers/CustomerModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CustomerModel extends BaseApiModel implements
protected $name;

/**
* @var int|null
* @var int|float|null
*/
protected $nextPrice;

Expand Down Expand Up @@ -109,7 +109,7 @@ class CustomerModel extends BaseApiModel implements
protected $closestTaskAt;

/**
* @var int|null
* @var int|float|null
*/
protected $ltv;

Expand All @@ -119,7 +119,7 @@ class CustomerModel extends BaseApiModel implements
protected $purchasesCount;

/**
* @var int|null
* @var int|float|null
*/
protected $averageCheck;

Expand Down Expand Up @@ -471,16 +471,29 @@ public function setContacts(?ContactsCollection $contacts): self
*/
public function getNextPrice(): ?int
{
return $this->nextPrice;
return isset($this->nextPrice) ? (int)$this->nextPrice : null;
}

/**
* На данный момент поддержка минорных единиц валют доступна только в Kommo
*/
public function getNextPriceWithMinorUnits(): ?float
{
return isset($this->nextPrice) ? (float)$this->nextPrice : null;
}

/**
* @param int|null $nextPrice
* @param int|float|null $nextPrice
*
* @return CustomerModel
* @throws InvalidArgumentException
*/
public function setNextPrice(?int $nextPrice): CustomerModel
public function setNextPrice($nextPrice): CustomerModel
{
if (!is_int($nextPrice) && !is_float($nextPrice) && !is_null($nextPrice)) {
throw new InvalidArgumentException('Customer next price must be an integer, float or null.');
}

$this->nextPrice = $nextPrice;

return $this;
Expand Down Expand Up @@ -531,16 +544,29 @@ public function setPeriodicity(?int $periodicity): CustomerModel
*/
public function getLtv(): ?int
{
return $this->ltv;
return isset($this->ltv) ? (int)$this->ltv : null;
}

/**
* @param int|null $ltv
* На данный момент поддержка минорных единиц валют доступна только в Kommo
*/
public function getLtvWithMinorUnits(): ?float
{
return isset($this->ltv) ? (float)$this->ltv : null;
}

/**
* @param int|float|null $ltv
*
* @return CustomerModel
* @throws InvalidArgumentException
*/
public function setLtv(?int $ltv): CustomerModel
public function setLtv($ltv): CustomerModel
{
if (!is_int($ltv) && !is_float($ltv) && !is_null($ltv)) {
throw new InvalidArgumentException('Customer ltv must be an integer, float or null.');
}

$this->ltv = $ltv;

return $this;
Expand Down Expand Up @@ -571,16 +597,29 @@ public function setPurchasesCount(?int $purchasesCount): CustomerModel
*/
public function getAverageCheck(): ?int
{
return $this->averageCheck;
return isset($this->averageCheck) ? (int)$this->averageCheck : null;
}

/**
* @param int|null $averageCheck
* На данный момент поддержка минорных единиц валют доступна только в Kommo
*/
public function getAverageCheckWithMinorUnits(): ?float
{
return isset($this->averageCheck) ? (float)$this->averageCheck : null;
}

/**
* @param int|float|null $averageCheck
*
* @return CustomerModel
* @throws InvalidArgumentException
*/
public function setAverageCheck(?int $averageCheck): CustomerModel
public function setAverageCheck($averageCheck): CustomerModel
{
if (!is_int($averageCheck) && !is_float($averageCheck) && !is_null($averageCheck)) {
throw new InvalidArgumentException('Customer average check must be an integer, float or null.');
}

$this->averageCheck = $averageCheck;

return $this;
Expand Down Expand Up @@ -635,7 +674,9 @@ public static function fromArray(array $customer): self
if (!empty($customer['name'])) {
$customerModel->setName($customer['name']);
}
if (array_key_exists('next_price', $customer) && !is_null($customer['next_price'])) {
if (array_key_exists('next_price_with_minor_units', $customer) && !is_null($customer['next_price_with_minor_units'])) {
$customerModel->setNextPrice((float)$customer['next_price_with_minor_units']);
} elseif (array_key_exists('next_price', $customer) && !is_null($customer['next_price'])) {
$customerModel->setNextPrice((int)$customer['next_price']);
}
if (array_key_exists('next_date', $customer) && !is_null($customer['next_date'])) {
Expand All @@ -650,14 +691,18 @@ public static function fromArray(array $customer): self
if (array_key_exists('periodicity', $customer) && !is_null($customer['periodicity'])) {
$customerModel->setPeriodicity((int)$customer['periodicity']);
}
if (array_key_exists('ltv', $customer) && !is_null($customer['ltv'])) {
if (array_key_exists('ltv_with_minor_units', $customer) && !is_null($customer['ltv_with_minor_units'])) {
$customerModel->setLtv((float)$customer['ltv_with_minor_units']);
} elseif (array_key_exists('ltv', $customer) && !is_null($customer['ltv'])) {
$customerModel->setLtv((int)$customer['ltv']);
}
if (array_key_exists('purchases_count', $customer) && !is_null($customer['purchases_count'])) {
$customerModel->setPeriodicity((int)$customer['purchases_count']);
$customerModel->setPurchasesCount((int)$customer['purchases_count']);
}
if (array_key_exists('average_check', $customer) && !is_null($customer['average_check'])) {
$customerModel->setPeriodicity((int)$customer['average_check']);
if (array_key_exists('average_check_with_minor_units', $customer) && !is_null($customer['average_check_with_minor_units'])) {
$customerModel->setAverageCheck((float)$customer['average_check_with_minor_units']);
} elseif (array_key_exists('average_check', $customer) && !is_null($customer['average_check'])) {
$customerModel->setAverageCheck((int)$customer['average_check']);
}
if (!empty($customer['custom_fields_values'])) {
$valuesCollection = new CustomFieldsValuesCollection();
Expand All @@ -683,13 +728,7 @@ public static function fromArray(array $customer): self
$customerModel->setIsDeleted((bool)$customer['is_deleted']);
}

if (array_key_exists('average_check', $customer) && !is_null($customer['average_check'])) {
$customerModel->setAverageCheck((int)$customer['average_check']);
}

if (array_key_exists('purchases_count', $customer) && !is_null($customer['purchases_count'])) {
$customerModel->setPurchasesCount((int)$customer['purchases_count']);
}

if (!empty($customer[AmoCRMApiRequest::EMBEDDED]['tags'])) {
$tagsCollection = new TagsCollection();
Expand Down Expand Up @@ -744,6 +783,7 @@ public function toArray(): array
'id' => $this->getId(),
'name' => $this->getName(),
'next_price' => $this->getNextPrice(),
'next_price_with_minor_units' => $this->getNextPriceWithMinorUnits(),
'next_date' => $this->getNextDate(),
'responsible_user_id' => $this->getResponsibleUserId(),
'status_id' => $this->getStatusId(),
Expand All @@ -758,8 +798,10 @@ public function toArray(): array
? null
: $this->getCustomFieldsValues()->toArray(),
'ltv' => $this->getLtv(),
'ltv_with_minor_units' => $this->getLtvWithMinorUnits(),
'purchases_count' => $this->getPurchasesCount(),
'average_check' => $this->getAverageCheck(),
'average_check_with_minor_units' => $this->getAverageCheckWithMinorUnits(),
'account_id' => $this->getAccountId(),
];

Expand Down Expand Up @@ -807,7 +849,7 @@ public function toApi(?string $requestId = "0"): array
}

if (!is_null($this->getNextPrice())) {
$result['next_price'] = $this->getNextPrice();
$result['next_price'] = $this->getNextPriceWithMinorUnits();
}

if (!is_null($this->getNextDate())) {
Expand All @@ -818,6 +860,14 @@ public function toApi(?string $requestId = "0"): array
$result['periodicity'] = $this->getPeriodicity();
}

if (!is_null($this->getLtv())) {
$result['ltv'] = $this->getLtvWithMinorUnits();
}

if (!is_null($this->getAverageCheck())) {
$result['average_check'] = $this->getAverageCheckWithMinorUnits();
}

if (!is_null($this->getResponsibleUserId())) {
$result['responsible_user_id'] = $this->getResponsibleUserId();
}
Expand Down
58 changes: 46 additions & 12 deletions src/AmoCRM/Models/Customers/Transactions/TransactionModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class TransactionModel extends BaseApiModel implements HasIdInterface
protected $id;

/**
* @var int|null
* @var int|float|null
*/
protected $price;

Expand Down Expand Up @@ -91,7 +91,7 @@ class TransactionModel extends BaseApiModel implements HasIdInterface
protected $nextDate;

/**
* @var int|null
* @var int|float|null
*/
protected $nextPrice;

Expand All @@ -116,10 +116,20 @@ public static function fromArray(array $transaction): self

$model->setId($transaction['id']);

if (array_key_exists('price', $transaction) && !is_null($transaction['price'])) {
if (array_key_exists('price_with_minor_units', $transaction) && !is_null($transaction['price_with_minor_units'])) {
$model->setPrice((float)$transaction['price_with_minor_units']);
}
elseif (array_key_exists('price', $transaction) && !is_null($transaction['price'])) {
$model->setPrice((int)$transaction['price']);
}

if (array_key_exists('next_price_with_minor_units', $transaction) && !is_null($transaction['next_price_with_minor_units'])) {
$model->setNextPrice((float)$transaction['next_price_with_minor_units']);
}
elseif (array_key_exists('next_price', $transaction) && !is_null($transaction['next_price'])) {
$model->setNextPrice((int)$transaction['next_price']);
}

if (array_key_exists('completed_at', $transaction) && !is_null($transaction['completed_at'])) {
$model->setCompletedAt((int)$transaction['completed_at']);
}
Expand Down Expand Up @@ -185,6 +195,7 @@ public function toArray(): array
return [
'id' => $this->getId(),
'price' => $this->getPrice(),
'price_with_minor_units' => $this->getPriceWithMinorUnits(),
'completed_at' => $this->getCompletedAt(),
'comment' => $this->getComment(),
'created_at' => $this->getCreatedAt(),
Expand All @@ -195,7 +206,6 @@ public function toArray(): array
'account_id' => $this->getAccountId(),
'catalog_elements' => $this->getCatalogElements() ? $this->getCatalogElements()->toArray() : null,
'customer_id' => $this->getCustomerId(),
'customer' => $this->getCustomer()->toArray(),
];
}

Expand Down Expand Up @@ -224,16 +234,28 @@ public function setId(int $id): self
*/
public function getPrice(): ?int
{
return $this->price;
return isset($this->price) ? (int)$this->price : null;
}

/**
* На данный момент поддержка минорных единиц валют доступна только в Kommo
*/
public function getPriceWithMinorUnits(): ?float
{
return isset($this->price) ? (float)$this->price : null;
}

/**
* @param int|null $price
* @param int|float|null $price
*
* @return TransactionModel
*/
public function setPrice(?int $price): TransactionModel
public function setPrice($price): TransactionModel
{
if (!is_int($price) && !is_float($price) && !is_null($price)) {
throw new InvalidArgumentException('Transaction price must be an integer, float or null.');
}

$this->price = $price;

return $this;
Expand Down Expand Up @@ -484,16 +506,28 @@ public function setNextDate(?int $nextDate): TransactionModel
*/
public function getNextPrice(): ?int
{
return $this->nextPrice;
return isset($this->nextPrice) ? (int)$this->nextPrice : null;
}

/**
* На данный момент поддержка минорных единиц валют доступна только в Kommo
*/
public function getNextPriceWithMinorUnits(): ?float
{
return isset($this->nextPrice) ? (float)$this->nextPrice : null;
}

/**
* @param int|null $nextPrice
* @param int|float|null $nextPrice
*
* @return TransactionModel
*/
public function setNextPrice(?int $nextPrice): TransactionModel
public function setNextPrice($nextPrice): TransactionModel
{
if (!is_int($nextPrice) && !is_float($nextPrice) && !is_null($nextPrice)) {
throw new InvalidArgumentException('Transaction next price must be an integer, float or null.');
}

$this->nextPrice = $nextPrice;

return $this;
Expand All @@ -507,7 +541,7 @@ public function setNextPrice(?int $nextPrice): TransactionModel
public function toApi(?string $requestId = "0"): array
{
$result = [
'price' => $this->getPrice(),
'price' => $this->getPriceWithMinorUnits(),
];

if (!is_null($this->getCompletedAt())) {
Expand Down Expand Up @@ -539,7 +573,7 @@ public function toApi(?string $requestId = "0"): array
}

if (!is_null($this->getNextPrice())) {
$result['next_price'] = $this->getNextPrice();
$result['next_price'] = $this->getNextPriceWithMinorUnits();
}

if (!is_null($this->getReceiptLink())) {
Expand Down
Loading