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
1 change: 1 addition & 0 deletions .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

$finder = Finder::create()
->in(__DIR__ . '/src/Infrastructure/Console/Commands/')
->in(__DIR__ . '/src/Services/CRM/Quote/')
->in(__DIR__ . '/src/Services/CRM/Lead/')
->in(__DIR__ . '/src/Services/CRM/Currency/')
->name('*.php')
Expand Down
33 changes: 33 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,39 @@

### Added

- 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
- `get` returns the settings of the quote by Id
- `list` returns a list of quote
- `add` creates a new quote
- `delete` deletes a quote
- `update` modifies the quote
- `countByFilter` count quotes by filter
- Added support for events:
- `OnCrmQuoteAdd`
- `OnCrmQuoteDelete`
- `OnCrmQuoteUpdate`
- `OnCrmQuoteUserFieldAdd`
- `OnCrmQuoteUserFieldDelete`
- `OnCrmQuoteUserFieldSetEnumValues`
- `OnCrmQuoteUserFieldUpdate`
- Added service `Services\CRM\Quote\Service\QuoteUserfield` with support methods:
- `add` add userfield to a quote
- `get` get userfield to a quote
- `list` list userfields
- `delete` delete userfield
- `update` update userfield
- Added service `Services\CRM\Quote\Service\QuoteProductRows` with support methods:
- `set` Adds products to a quote
- `get` Returns the products of a quote
- Added service `Services\CRM\Quote\Service\QuoteContact` with support methods,
- `fields` get fiels for quote contact connection
- `setItems` set contacts related with quote
- `get` get contacts related to quote
- `deleteItems` delete all relations for quote
- `add` add contact relation with quote
- `delete` delete contact relation with quote
- Added service `CRM\Lead\Service\LeadUserfield` with support methods,
see [add crm.lead.userfield.* methods](https://github.com/bitrix24/b24phpsdk/issues/177):
- `add` add userfield to lead
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,9 @@ 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_crm_quote
integration_tests_crm_quote:
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_crm_quote

# work dev environment
.PHONY: php-dev-server-up
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ parameters:
- tests/Integration/Services/IMOpenLines
- tests/Integration/Services/Main
- tests/Integration/Services/Placement
- tests/Integration/Services/CRM/Quote/Service/QuoteTest.php
- tests/Integration/Services/CRM/Quote/Service/BatchTest.php
- tests/Integration/Services/CRM/Quote/Service/QuoteContactTest.php
- tests/Integration/Services/CRM/Quote/Service/QuoteUserfieldTest.php
- tests/Integration/Services/CRM/Quote/Service/QuoteProductRowsTest.php
- tests/Integration/Services/CRM/Lead/Service/LeadUserfieldTest.php
- tests/Integration/Services/CRM/Currency
bootstrapFiles:
Expand Down
3 changes: 3 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@
<testsuite name="integration_tests_scope_automation">
<directory>./tests/Integration/Services/CRM/Automation/</directory>
</testsuite>
<testsuite name="integration_tests_crm_quote">
<directory>./tests/Integration/Services/CRM/Quote/</directory>
</testsuite>
</testsuites>
<source>
<include>
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/Quote',
__DIR__ . '/tests/Integration/Services/CRM/Quote/Service',
__DIR__ . '/src/Services/CRM/Currency',
__DIR__ . '/tests/Integration/Services/CRM/Currency',
__DIR__ . '/tests/Unit/',
Expand Down
52 changes: 51 additions & 1 deletion src/Services/CRM/CRMServiceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ public function lead(): Lead\Service\Lead

return $this->serviceCache[__METHOD__];
}

public function leadUserfield(): Lead\Service\LeadUserfield
{
if (!isset($this->serviceCache[__METHOD__])) {
Expand All @@ -324,6 +324,56 @@ public function leadUserfield(): Lead\Service\LeadUserfield

return $this->serviceCache[__METHOD__];
}

public function quote(): Quote\Service\Quote
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Quote\Service\Quote(
new Quote\Service\Batch($this->batch, $this->log),
$this->core,
$this->log
);
}

return $this->serviceCache[__METHOD__];
}

public function quoteContact(): Quote\Service\QuoteContact
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Quote\Service\QuoteContact(
$this->core,
$this->log
);
}

return $this->serviceCache[__METHOD__];
}

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

return $this->serviceCache[__METHOD__];
}

public function quoteUserfield(): Quote\Service\QuoteUserfield
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Quote\Service\QuoteUserfield(
new UserfieldConstraints(),
$this->core,
$this->log
);
}

return $this->serviceCache[__METHOD__];
}

public function activity(): Activity\Service\Activity
{
Expand Down
66 changes: 66 additions & 0 deletions src/Services/CRM/Quote/Events/CrmQuoteEventsFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?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\Quote\Events;

use Bitrix24\SDK\Core\Contracts\Events\EventInterface;
use Bitrix24\SDK\Core\Contracts\Events\EventsFabricInterface;
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
use Bitrix24\SDK\Services\CRM\Quote\Events\OnCrmQuoteAdd\OnCrmQuoteAdd;
use Bitrix24\SDK\Services\CRM\Quote\Events\OnCrmQuoteDelete\OnCrmQuoteDelete;
use Bitrix24\SDK\Services\CRM\Quote\Events\OnCrmQuoteUpdate\OnCrmQuoteUpdate;
use Bitrix24\SDK\Services\CRM\Quote\Events\OnCrmQuoteUserFieldAdd\OnCrmQuoteUserFieldAdd;
use Bitrix24\SDK\Services\CRM\Quote\Events\OnCrmQuoteUserFieldDelete\OnCrmQuoteUserFieldDelete;
use Bitrix24\SDK\Services\CRM\Quote\Events\OnCrmQuoteUserFieldSetEnumValues\OnCrmQuoteUserFieldSetEnumValues;
use Bitrix24\SDK\Services\CRM\Quote\Events\OnCrmQuoteUserFieldUpdate\OnCrmQuoteUserFieldUpdate;
use Symfony\Component\HttpFoundation\Request;

readonly class CrmQuoteEventsFactory implements EventsFabricInterface
{
public function isSupport(string $eventCode): bool
{
return in_array(strtoupper($eventCode), [
OnCrmQuoteAdd::CODE,
OnCrmQuoteUpdate::CODE,
OnCrmQuoteDelete::CODE,
OnCrmQuoteUserFieldAdd::CODE,
OnCrmQuoteUserFieldUpdate::CODE,
OnCrmQuoteUserFieldDelete::CODE,
OnCrmQuoteUserFieldSetEnumValues::CODE,
], true);
}

/**
* @throws InvalidArgumentException
*/
public function create(Request $eventRequest): EventInterface
{
$eventPayload = $eventRequest->request->all();
if (!array_key_exists('event', $eventPayload)) {
throw new InvalidArgumentException('«event» key not found in event payload');
}

return match ($eventPayload['event']) {
OnCrmQuoteAdd::CODE => new OnCrmQuoteAdd($eventRequest),
OnCrmQuoteUpdate::CODE => new OnCrmQuoteUpdate($eventRequest),
OnCrmQuoteDelete::CODE => new OnCrmQuoteDelete($eventRequest),
OnCrmQuoteUserFieldAdd::CODE => new OnCrmQuoteUserFieldAdd($eventRequest),
OnCrmQuoteUserFieldUpdate::CODE => new OnCrmQuoteUserFieldUpdate($eventRequest),
OnCrmQuoteUserFieldDelete::CODE => new OnCrmQuoteUserFieldDelete($eventRequest),
OnCrmQuoteUserFieldSetEnumValues::CODE => new OnCrmQuoteUserFieldSetEnumValues($eventRequest),
default => throw new InvalidArgumentException(
sprintf('Unexpected event code «%s»', $eventPayload['event'])
),
};
}
}
26 changes: 26 additions & 0 deletions src/Services/CRM/Quote/Events/OnCrmQuoteAdd/OnCrmQuoteAdd.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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\Quote\Events\OnCrmQuoteAdd;

use Bitrix24\SDK\Application\Requests\Events\AbstractEventRequest;

class OnCrmQuoteAdd extends AbstractEventRequest
{
public const CODE = 'ONCRMQUOTEADD';

public function getPayload(): OnCrmQuoteAddPayload
{
return new OnCrmQuoteAddPayload($this->eventPayload['data']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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\Quote\Events\OnCrmQuoteAdd;

use Bitrix24\SDK\Core\Result\AbstractItem;

/**
* @property-read array{
* ID: int,
* } $FIELDS
*/
class OnCrmQuoteAddPayload extends AbstractItem
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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\Quote\Events\OnCrmQuoteDelete;

use Bitrix24\SDK\Application\Requests\Events\AbstractEventRequest;

class OnCrmQuoteDelete extends AbstractEventRequest
{
public const CODE = 'ONCRMQUOTEDELETE';

public function getPayload(): OnCrmQuoteDeletePayload
{
return new OnCrmQuoteDeletePayload($this->eventPayload['data']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?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\Quote\Events\OnCrmQuoteDelete;

use Bitrix24\SDK\Core\Result\AbstractItem;

/**
* @property-read array{
* ID: int,
* } $FIELDS
*/
class OnCrmQuoteDeletePayload extends AbstractItem
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?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\Quote\Events\OnCrmQuoteUpdate;

use Bitrix24\SDK\Application\Requests\Events\AbstractEventRequest;

class OnCrmQuoteUpdate extends AbstractEventRequest
{
public const CODE = 'ONCRMQUOTEUPDATE';

public function getPayload(): OnCrmQuoteUpdatePayload
{
return new OnCrmQuoteUpdatePayload($this->eventPayload['data']);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

/**
* This file is part of the bitrix24-php-sdk package.
*
* © Maksim Mesilov <mesilov.maxim@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\Quote\Events\OnCrmQuoteUpdate;

use Bitrix24\SDK\Core\Result\AbstractItem;

/**
* @property-read array{
* ID: int,
* RECURRING_DEAL_ID: int,
* } $FIELDS
*/
class OnCrmQuoteUpdatePayload extends AbstractItem
{
}
Loading