Skip to content

Commit

Permalink
Merge pull request #527 from truekharit/feature/INTEGR-386
Browse files Browse the repository at this point in the history
INTEGR-386
  • Loading branch information
bessudnov authored Sep 22, 2023
2 parents 2fbd2e3 + 641bf80 commit cd123d0
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 3 deletions.
41 changes: 40 additions & 1 deletion src/AmoCRM/Models/CatalogElementModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace AmoCRM\Models;

use AmoCRM\Client\AmoCRMApiRequest;
use AmoCRM\Exceptions\InvalidArgumentException;
use AmoCRM\Helpers\EntityTypesInterface;
use AmoCRM\Models\Interfaces\CanBeLinkedInterface;
Expand Down Expand Up @@ -106,6 +107,13 @@ class CatalogElementModel extends BaseApiModel implements TypeAwareInterface, Ca
*/
protected $invoiceLink;

/**
* Предупреждение о перерасчете в счете
*
* @var InvoiceWarningModel|null
*/
protected $invoiceWarning;

/**
* @return null|int
*/
Expand Down Expand Up @@ -352,6 +360,26 @@ public function setInvoiceLink(?string $invoiceLink): CatalogElementModel
return $this;
}

/**
* @return InvoiceWarningModel|null
*/
public function getInvoiceWarning(): ?InvoiceWarningModel
{
return $this->invoiceWarning;
}

/**
* @param InvoiceWarningModel $invoiceWarning
*
* @return CatalogElementModel
*/
private function setInvoiceWarning(InvoiceWarningModel $invoiceWarning): CatalogElementModel
{
$this->invoiceWarning = $invoiceWarning;

return $this;
}

/**
* @param array $catalogElement
*
Expand Down Expand Up @@ -401,6 +429,13 @@ public static function fromArray(array $catalogElement): self
$customFieldsValues = $valuesCollection::fromArray($catalogElement['custom_fields_values']);
$catalogElementModel->setCustomFieldsValues($customFieldsValues);
}
if (
array_key_exists(AmoCRMApiRequest::EMBEDDED, $catalogElement)
&& array_key_exists('warning', $catalogElement[AmoCRMApiRequest::EMBEDDED])
) {
$invoiceWarning = InvoiceWarningModel::fromArray($catalogElement[AmoCRMApiRequest::EMBEDDED]['warning']);
$catalogElementModel->setInvoiceWarning($invoiceWarning);
}

//Костылик для связей
if (isset($catalogElement['to_element_id'])) {
Expand Down Expand Up @@ -446,7 +481,11 @@ public function toArray(): array
'quantity' => $this->getQuantity(),
'catalog_id' => $this->getCatalogId(),
'price_id' => $this->getPriceId(),
]
],
'warning' => $this->getInvoiceWarning() === null
? null
: $this->getInvoiceWarning()->toArray(),

];

if (!is_null($this->getCurrencyId())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@ class ItemsCustomFieldValueModel extends BaseCustomFieldValueModel
public const FIELD_DISCOUNT_TYPE_PERCENTAGE = 'percentage';
/** Скдика - цифра от стоимости товара */
public const FIELD_DISCOUNT_TYPE_AMOUNT = 'amount';
/** Произошел ли перерасчет скидки товарной позиции */
public const FIELD_IS_DISCOUNT_RECALCULATED = 'is_discount_recalculated';
/** Произошел ли перерасчет суммы товарной позиции при скидке 0 */
public const FIELD_IS_TOTAL_SUM_RECALCULATED = 'is_total_sum_recalculated';
/** Сумма товарной позиции */
public const FIELD_TOTAL_SUM = 'total_sum';

/**
* @var string|int|null
Expand Down Expand Up @@ -98,6 +104,15 @@ class ItemsCustomFieldValueModel extends BaseCustomFieldValueModel
/** @var array|null */
protected $metadata;

/** @var bool */
protected $isDiscountRecalculated;

/** @var bool */
protected $isTotalSumRecalculated;

/** @var float */
protected $totalSum;

/**
* @param int|string|null $value
*
Expand Down Expand Up @@ -133,7 +148,9 @@ public static function fromArray($value): BaseCustomFieldValueModel
->setProductId($val[self::FIELD_PRODUCT_ID] ?? null)
->setBonusPointsPerPurchase($val[self::FIELD_BONUS_POINTS_PER_PURCHASE] ?? null)
->setMetadata($val[self::FIELD_METADATA] ?? null)
;
->setIsDiscountRecalculated($val[self::FIELD_IS_DISCOUNT_RECALCULATED] ?? false)
->setIsTotalSumRecalculated($val[self::FIELD_IS_TOTAL_SUM_RECALCULATED] ?? false)
->setTotalSum($val[self::FIELD_TOTAL_SUM] ?? null);

return $model;
}
Expand Down Expand Up @@ -370,6 +387,66 @@ public function setMetadata(?array $metadata): ItemsCustomFieldValueModel
return $this;
}

/**
* @return bool
*/
public function getIsDiscountRecalculated(): bool
{
return $this->isDiscountRecalculated;
}

/**
* @param bool $isDiscountRecalculated
*
* @return ItemsCustomFieldValueModel
*/
private function setIsDiscountRecalculated(bool $isDiscountRecalculated): ItemsCustomFieldValueModel
{
$this->isDiscountRecalculated = $isDiscountRecalculated;

return $this;
}

/**
* @return bool
*/
public function getIsTotalSumRecalculated(): bool
{
return $this->isTotalSumRecalculated;
}

/**
* @param bool $isTotalSumRecalculated
*
* @return ItemsCustomFieldValueModel
*/
private function setIsTotalSumRecalculated(bool $isTotalSumRecalculated): ItemsCustomFieldValueModel
{
$this->isTotalSumRecalculated = $isTotalSumRecalculated;

return $this;
}

/**
* @return float
*/
public function getTotalSum(): float
{
return $this->totalSum;
}

/**
* @param float $totalSum
*
* @return ItemsCustomFieldValueModel
*/
private function setTotalSum(float $totalSum): ItemsCustomFieldValueModel
{
$this->totalSum = $totalSum;

return $this;
}

public function toArray(): array
{
return [
Expand All @@ -385,6 +462,9 @@ public function toArray(): array
self::FIELD_PRODUCT_ID => $this->getProductId(),
self::FIELD_BONUS_POINTS_PER_PURCHASE => $this->getBonusPointsPerPurchase(),
self::FIELD_METADATA => $this->getMetadata(),
self::FIELD_IS_DISCOUNT_RECALCULATED => $this->getIsDiscountRecalculated(),
self::FIELD_IS_TOTAL_SUM_RECALCULATED => $this->getIsTotalSumRecalculated(),
self::FIELD_TOTAL_SUM => $this->getTotalSum(),
];
}

Expand All @@ -399,8 +479,23 @@ public function getValue()

public function toApi(string $requestId = null): array
{
$result = [
self::FIELD_SKU => $this->getSku(),
self::FIELD_DESCRIPTION => $this->getDescription(),
self::FIELD_UNIT_PRICE => $this->getUnitPrice(),
self::FIELD_QUANTITY => $this->getQuantity(),
self::FIELD_UNIT_TYPE => $this->getUnitType(),
self::FIELD_DISCOUNT => $this->getDiscount(),
self::FIELD_VAT_RATE_ID => $this->getVatRateId(),
self::FIELD_VAT_RATE_VALUE => $this->getVatRateValue(),
self::FIELD_EXTERNAL_UID => $this->getExternalUid(),
self::FIELD_PRODUCT_ID => $this->getProductId(),
self::FIELD_BONUS_POINTS_PER_PURCHASE => $this->getBonusPointsPerPurchase(),
self::FIELD_METADATA => $this->getMetadata(),
];

return [
'value' => $this->getValue(),
'value' => $result,
];
}
}
38 changes: 38 additions & 0 deletions src/AmoCRM/Models/InvoiceWarningModel.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace AmoCRM\Models;

class InvoiceWarningModel extends BaseApiModel
{
/**
* @var string|null
*/
protected $message;

public function __construct(?string $message)
{
$this->message = $message;
}

public function getInvoiceWarningMessage(): ?string
{
return $this->message;
}

public static function fromArray(array $value): self
{
return new self($value['message']);
}

public function toArray(): array
{
return [
'message' => $this->getInvoiceWarningMessage(),
];
}

public function toApi(string $requestId = null): array
{
return $this->toArray();
}
}

0 comments on commit cd123d0

Please sign in to comment.