Skip to content
Open
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
28 changes: 24 additions & 4 deletions src/AmoCRM/Models/LeadModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use AmoCRM\Models\Interfaces\ComplexTagsManagerInterface;
use AmoCRM\Models\Leads\Sources\LeadSourceApi;
use AmoCRM\Models\Traits\MutateTagsTrait;
use AmoCRM\EntitiesServices\Unsorted;
use AmoCRM\Exceptions\InvalidArgumentException;
use AmoCRM\Helpers\EntityTypesInterface;
use AmoCRM\Client\AmoCRMApiRequest;
Expand Down Expand Up @@ -111,7 +110,7 @@ class LeadModel extends BaseApiModel implements
protected $closestTaskAt;

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

Expand Down Expand Up @@ -257,7 +256,12 @@ public function setName(string $name): self
*/
public function getPrice(): ?int
{
return $this->price;
return isset($this->price) ? (int)$this->price : null;
}

public function getPriceWithMinorUnits(): ?float
{
return isset($this->price) ? (float)$this->price : .0;
}

/**
Expand All @@ -266,6 +270,16 @@ public function getPrice(): ?int
* @return self
*/
public function setPrice(?int $price): self
{
$this->price = (float)$price;

return $this;
}

/**
* @noinspection PhpUnused
*/
public function setPriceWithMinorUnits(?float $price): self
{
$this->price = $price;

Expand Down Expand Up @@ -745,7 +759,7 @@ public static function fromArray(array $lead): self
}

if (array_key_exists('price', $lead) && !is_null($lead['price'])) {
$leadModel->setPrice((int)$lead['price']);
$leadModel->setPrice((float)$lead['price']);
}

if (array_key_exists('responsible_user_id', $lead) && !is_null($lead['responsible_user_id'])) {
Expand Down Expand Up @@ -861,6 +875,7 @@ public function toArray(): array
$result = [
'name' => $this->getName(),
'price' => $this->getPrice(),
'price_with_minor_units' => $this->getPriceWithMinorUnits(),
'responsible_user_id' => $this->getResponsibleUserId(),
'group_id' => $this->getGroupId(),
'status_id' => $this->getStatusId(),
Expand Down Expand Up @@ -936,6 +951,11 @@ public function toApi(?string $requestId = "0"): array
$result['price'] = $this->getPrice();
}

$priceWmu = $this->getPriceWithMinorUnits();
if ($priceWmu !== null) {
$result['price_with_minor_units'] = $priceWmu;
}

if (!is_null($this->getResponsibleUserId())) {
$result['responsible_user_id'] = $this->getResponsibleUserId();
}
Expand Down