Skip to content
Merged
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

### Added

- Added service `Services\CRM\Lead\Service\LeadProductRows` with support methods,
see [add crm.lead.productrows* methods](https://github.com/bitrix24/b24phpsdk/issues/175):
- `set` Adds products to a lead
- `get` Returns the products of a lead
- Added service `Services\CRM\Quote\Service\Quote` with support methods,
see [crm.quote.* methods](https://github.com/bitrix24/b24phpsdk/issues/179):
- `fields` returns a list of fields for the quote
Expand Down
8 changes: 8 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,14 @@ integration_tests_scope_crm_currency:
integration_tests_deal_recurring:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_deal_recurring

.PHONY: integration_tests_scope_automation
integration_tests_scope_automation:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_automation

.PHONY: integration_tests_lead_productrows
integration_tests_lead_productrows:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_lead_productrows

.PHONY: integration_tests_crm_quote
integration_tests_crm_quote:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_crm_quote
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ parameters:
- tests/Integration/Services/IMOpenLines
- tests/Integration/Services/Main
- tests/Integration/Services/Placement
- tests/Integration/Services/CRM/Lead/Service/LeadProductRowsTest.php
- tests/Integration/Services/CRM/Quote/Service/QuoteTest.php
- tests/Integration/Services/CRM/Quote/Service/BatchTest.php
- tests/Integration/Services/CRM/Quote/Service/QuoteContactTest.php
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
<testsuite name="integration_tests_scope_ai_admin">
<directory>./tests/Integration/Services/AI/</directory>
</testsuite>
<testsuite name="integration_tests_lead_productrows">
<file>./tests/Integration/Services/CRM/Lead/Service/LeadProductRowsTest.php</file>
</testsuite>
<testsuite name="integration_tests_lead_userfield">
<file>./tests/Integration/Services/CRM/Lead/Service/LeadUserfieldTest.php</file>
</testsuite>
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
__DIR__ . '/tests/Integration/Services/Main',
__DIR__ . '/src/Services/Placement',
__DIR__ . '/tests/Integration/Services/Placement',
__DIR__ . '/src/Services/CRM/Lead',
__DIR__ . '/tests/Integration/Services/CRM/Lead/Service',
__DIR__ . '/src/Services/CRM/Quote',
__DIR__ . '/tests/Integration/Services/CRM/Quote/Service',
__DIR__ . '/src/Services/CRM/Currency',
Expand Down
12 changes: 12 additions & 0 deletions src/Services/CRM/CRMServiceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,18 @@ public function lead(): Lead\Service\Lead

return $this->serviceCache[__METHOD__];
}

/**
* @return Lead\Service\LeadProductRows
*/
public function leadProductRows(): Lead\Service\LeadProductRows
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Lead\Service\LeadProductRows($this->core, $this->log);
}

return $this->serviceCache[__METHOD__];
}

public function leadUserfield(): Lead\Service\LeadUserfield
{
Expand Down
1 change: 0 additions & 1 deletion src/Services/CRM/Lead/Result/LeadItemResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@
class LeadItemResult extends AbstractCrmItem
{
/**
* @param string $userfieldName
*
* @return mixed|null
* @throws \Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException
Expand Down
54 changes: 54 additions & 0 deletions src/Services/CRM/Lead/Result/LeadProductRowItemResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Vadim Soluyanov <vadimsallee@gmail.com>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Lead\Result;

use Money\Money;
use MoneyPHP\Percentage\Percentage;
use Bitrix24\SDK\Services\CRM\Common\Result\DiscountType;
use Carbon\CarbonImmutable;
use Bitrix24\SDK\Services\CRM\Common\Result\AbstractCrmItem;

/**
* @property-read int $ID
* @property-read int $OWNER_ID
* @property-read string $OWNER_TYPE
* @property-read int $PRODUCT_ID
* @property-read string $PRODUCT_NAME
* @property-read string|null $ORIGINAL_PRODUCT_NAME
* @property-read string|null $PRODUCT_DESCRIPTION
* @property-read Money $PRICE price with taxes and discounts
* @property-read Money $PRICE_EXCLUSIVE without taxes but with discounts
* @property-read Money $PRICE_NETTO without taxes and discounts
* @property-read Money $PRICE_BRUTTO without discounts but with taxes
* @property-read Money $PRICE_ACCOUNT formatted price
* @property-read string $QUANTITY
* @property-read DiscountType $DISCOUNT_TYPE_ID
* @property-read Percentage $DISCOUNT_RATE
* @property-read Money $DISCOUNT_SUM
* @property-read string $TAX_RATE
* @property-read bool $TAX_INCLUDED
* @property-read string $CUSTOMIZED
* @property-read int $MEASURE_CODE
* @property-read string $MEASURE_NAME
* @property-read int $SORT
* @property-read string|null $XML_ID
* @property-read int $TYPE
* @property-read int|null $STORE_ID
* @property-read int|null $RESERVE_ID
* @property-read CarbonImmutable|null $DATE_RESERVE_END
* @property-read int|null $RESERVE_QUANTITY
*/
class LeadProductRowItemResult extends AbstractCrmItem
{
}
53 changes: 53 additions & 0 deletions src/Services/CRM/Lead/Result/LeadProductRowItemsResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Vadim Soluyanov <vadimsallee@gmail.com>
*
* For the full copyright and license information, please view the MIT-LICENSE.txt
* file that was distributed with this source code.
*/


declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Lead\Result;

use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Response\Response;
use Bitrix24\SDK\Core\Result\AbstractResult;
use Money\Currency;

/**
* Class LeadProductRowItemsResult
*
* @package Bitrix24\SDK\Services\CRM\Lead\Result
*/
class LeadProductRowItemsResult extends AbstractResult
{
public function __construct(Response $coreResponse, private readonly Currency $currency)
{
parent::__construct($coreResponse);
}

/**
* @return LeadProductRowItemResult[]
* @throws BaseException
*/
public function getProductRows(): array
{
$res = [];
if (!empty($this->getCoreResponse()->getResponseData()->getResult()['result']['rows'])) {
foreach ($this->getCoreResponse()->getResponseData()->getResult()['result']['rows'] as $productRow) {
$res[] = new LeadProductRowItemResult($productRow, $this->currency);
}
} else {
foreach ($this->getCoreResponse()->getResponseData()->getResult() as $productRow) {
$res[] = new LeadProductRowItemResult($productRow, $this->currency);
}
}

return $res;
}
}
12 changes: 2 additions & 10 deletions src/Services/CRM/Lead/Service/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,11 @@
#[ApiBatchServiceMetadata(new Scope(['crm']))]
class Batch
{
protected BatchOperationsInterface $batch;
protected LoggerInterface $log;

/**
* Batch constructor.
*
* @param BatchOperationsInterface $batch
* @param LoggerInterface $log
*/
public function __construct(BatchOperationsInterface $batch, LoggerInterface $log)
public function __construct(protected BatchOperationsInterface $batch, protected LoggerInterface $log)
{
$this->batch = $batch;
$this->log = $log;
}

/**
Expand Down Expand Up @@ -133,7 +125,6 @@ public function __construct(BatchOperationsInterface $batch, LoggerInterface $lo
* UTM_TERM?: string,
* } $filter
* @param array $select = ['ID','TITLE','TYPE_ID','CATEGORY_ID','STAGE_ID','STAGE_SEMANTIC_ID','IS_NEW','IS_RECURRING','IS_RETURN_CUSTOMER','IS_REPEATED_APPROACH','PROBABILITY','CURRENCY_ID','OPPORTUNITY','IS_MANUAL_OPPORTUNITY','TAX_VALUE','COMPANY_ID','CONTACT_ID','CONTACT_IDS','QUOTE_ID','BEGINDATE','CLOSEDATE','OPENED','CLOSED','COMMENTS','ASSIGNED_BY_ID','CREATED_BY_ID','MODIFY_BY_ID','DATE_CREATE','DATE_MODIFY','SOURCE_ID','SOURCE_DESCRIPTION','LEAD_ID','ADDITIONAL_INFO','LOCATION_ID','ORIGINATOR_ID','ORIGIN_ID','UTM_SOURCE','UTM_MEDIUM','UTM_CAMPAIGN','UTM_CONTENT','UTM_TERM']
* @param int|null $limit
*
* @return Generator<int, DealItemResult>
* @throws BaseException
Expand Down Expand Up @@ -222,6 +213,7 @@ public function add(array $leads): Generator
'fields' => $lead,
];
}

foreach ($this->batch->addEntityItems('crm.lead.add', $items) as $key => $item) {
yield $key => new AddedItemBatchResult($item);
}
Expand Down
21 changes: 2 additions & 19 deletions src/Services/CRM/Lead/Service/Lead.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,19 +31,12 @@
#[ApiServiceMetadata(new Scope(['crm']))]
class Lead extends AbstractService
{
public Batch $batch;

/**
* Lead constructor.
*
* @param Batch $batch
* @param CoreInterface $core
* @param LoggerInterface $log
*/
public function __construct(Batch $batch, CoreInterface $core, LoggerInterface $log)
public function __construct(public Batch $batch, CoreInterface $core, LoggerInterface $logger)
{
parent::__construct($core, $log);
$this->batch = $batch;
parent::__construct($core, $logger);
}

/**
Expand Down Expand Up @@ -113,7 +106,6 @@ public function __construct(Batch $batch, CoreInterface $core, LoggerInterface $
* REGISTER_SONET_EVENT?: string
* } $params
*
* @return AddedItemResult
* @throws BaseException
* @throws TransportException
*/
Expand All @@ -140,9 +132,7 @@ public function add(array $fields, array $params = []): AddedItemResult
*
* @link https://training.bitrix24.com/rest_help/crm/leads/crm_lead_delete.php
*
* @param int $id
*
* @return DeletedItemResult
* @throws BaseException
* @throws TransportException
*/
Expand All @@ -168,7 +158,6 @@ public function delete(int $id): DeletedItemResult
*
* @link https://training.bitrix24.com/rest_help/crm/leads/crm_lead_fields.php
*
* @return FieldsResult
* @throws BaseException
* @throws TransportException
*/
Expand All @@ -187,9 +176,7 @@ public function fields(): FieldsResult
*
* @link https://training.bitrix24.com/rest_help/crm/leads/crm_lead_get.php
*
* @param int $id
*
* @return LeadResult
* @throws BaseException
* @throws TransportException
*/
Expand All @@ -215,7 +202,6 @@ public function get(int $id): LeadResult
*
* @throws BaseException
* @throws TransportException
* @return LeadsResult
*/
#[ApiEndpointMetadata(
'crm.lead.list',
Expand All @@ -242,7 +228,6 @@ public function list(array $order, array $filter, array $select, int $startItem
*
* @link https://training.bitrix24.com/rest_help/crm/leads/crm_lead_update.php
*
* @param int $id
* @param array{
* ID?: int,
* TITLE?: string,
Expand Down Expand Up @@ -305,7 +290,6 @@ public function list(array $order, array $filter, array $select, int $startItem
* REGISTER_SONET_EVENT?: string
* } $params
*
* @return UpdatedItemResult
* @throws BaseException
* @throws TransportException
*/
Expand Down Expand Up @@ -389,7 +373,6 @@ public function update(int $id, array $fields, array $params = []): UpdatedItemR
* LINK?: string
* } $filter
*
* @return int
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
* @throws \Bitrix24\SDK\Core\Exceptions\TransportException
*/
Expand Down
Loading