Skip to content

Commit

Permalink
Support transfer company and vat number in CRM custom fields
Browse files Browse the repository at this point in the history
  • Loading branch information
uryvskiy-dima committed Jul 30, 2024
1 parent d078202 commit d3f5a8c
Show file tree
Hide file tree
Showing 6 changed files with 6,077 additions and 88 deletions.
34 changes: 18 additions & 16 deletions retailcrm/lib/RetailcrmOrderBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ private function buildRegularAddress()
->setAddress($this->invoiceAddress)
->build()
->getDataArray()
;
;
}

/**
Expand All @@ -354,7 +354,7 @@ private function buildCorporateAddress($isMain = true)
->setWithExternalId(true)
->build()
->getDataArray()
;
;
}

/**
Expand Down Expand Up @@ -979,15 +979,26 @@ function ($v) use ($customer) {
;
$crmOrder = array_merge($crmOrder, $addressBuilder->getDataArray());

if ($addressInvoice instanceof Address && !empty($addressInvoice->company)) {
$crmOrder['contragent']['legalName'] = $addressInvoice->company;
$isCorporateEnabled = RetailcrmTools::isCorporateEnabled();

$crmOrder['contragent']['contragentType'] = $isCorporateEnabled && RetailcrmTools::isOrderCorporate($order)
? 'legal-entity'
: 'individual';

if (!$isCorporateEnabled && RetailcrmTools::isCampanyAndVatNumberSendEnabled()) {
$company = $addressDelivery->company;
$vatNumber = $addressDelivery->vat_number;

if (!empty($addressInvoice->vat_number)) {
$crmOrder['contragent']['INN'] = $addressInvoice->vat_number;
if ($addressInvoice instanceof Address) {
$company = !empty($addressInvoice->company) ? $addressInvoice->company : $company;
$vatNumber = !empty($addressInvoice->vat_number) ? $addressInvoice->vat_number : $vatNumber;
}

$crmOrder['customFields']['ps_company'] = $company;
$crmOrder['customFields']['ps_vat_number'] = $vatNumber;
}

if (isset($payment[$paymentType]) && !empty($payment[$paymentType])) {
if (!empty($payment[$paymentType])) {
$order_payment = [
'externalId' => $order->id . '#' . $order->reference,
'type' => $payment[$paymentType],
Expand Down Expand Up @@ -1124,9 +1135,6 @@ function ($v) use ($customer) {
'productName' => $product['product_name'],
'quantity' => $product['product_quantity'],
'initialPrice' => round($product['product_price'], 2),
/*'initialPrice' => !empty($item['rate'])
? $item['price'] + ($item['price'] * $item['rate'] / 100)
: $item['price'],*/
'purchasePrice' => round($product['purchase_supplier_price'], 2),
];

Expand Down Expand Up @@ -1161,12 +1169,6 @@ function ($v) use ($customer) {
if (!empty($site)) {
$crmOrder['customer']['site'] = $site;
}

if (RetailcrmTools::isCorporateEnabled() && RetailcrmTools::isOrderCorporate($order)) {
$crmOrder['contragent']['contragentType'] = 'legal-entity';
} else {
$crmOrder['contragent']['contragentType'] = 'individual';
}
}

return RetailcrmTools::filter(
Expand Down
26 changes: 10 additions & 16 deletions retailcrm/lib/RetailcrmTools.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ public static function isIcmlServicesEnabled()
return (bool) Configuration::get(RetailCRM::ENABLE_ICML_SERVICES);
}

/**
* Returns true if the transfer of company and VAT number is enabled in the settings
*
* @return bool
*/
public static function isCampanyAndVatNumberSendEnabled()
{
return (bool) Configuration::get(RetailCRM::ENABLE_COMPANY_AND_VAT_NUMBER_SEND);
}

/**
* Returns true if customer is corporate
*
Expand Down Expand Up @@ -969,22 +979,6 @@ public static function getConfigurationByName($name)
}
}

/**
* @param $name
*
* @return DateTime|false
*/
public static function getConfigurationCreatedAtByName($name)
{
$config = self::getConfigurationByName($name);

if (empty($config)) {
return false;
}

return DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $config['date_add']);
}

/**
* @return string
*/
Expand Down
1 change: 1 addition & 0 deletions retailcrm/lib/settings/RetailcrmSettingsItems.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public function __construct()
'enableCorporate' => new RetailcrmSettingsItemBool('enableCorporate', RetailCRM::ENABLE_CORPORATE_CLIENTS),
'enableOrderNumberSending' => new RetailcrmSettingsItemBool('enableOrderNumberSending', RetailCRM::ENABLE_ORDER_NUMBER_SENDING),
'enableOrderNumberReceiving' => new RetailcrmSettingsItemBool('enableOrderNumberReceiving', RetailCRM::ENABLE_ORDER_NUMBER_RECEIVING),
'enableCompanyAndVatNumberSend' => new RetailcrmSettingsItemBool('enableCompanyAndVatNumberSend', RetailCRM::ENABLE_COMPANY_AND_VAT_NUMBER_SEND),
'webJobs' => new RetailcrmSettingsItemBool('webJobs', RetailCRM::ENABLE_WEB_JOBS, '1'),
'debugMode' => new RetailcrmSettingsItemBool('debugMode', RetailCRM::ENABLE_DEBUG_MODE),

Expand Down
4 changes: 2 additions & 2 deletions retailcrm/retailcrm.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,11 @@ class RetailCRM extends Module
const ENABLE_BALANCES_RECEIVING = 'RETAILCRM_ENABLE_BALANCES_RECEIVING';
const ENABLE_ORDER_NUMBER_SENDING = 'RETAILCRM_ENABLE_ORDER_NUMBER_SENDING';
const ENABLE_ORDER_NUMBER_RECEIVING = 'RETAILCRM_ENABLE_ORDER_NUMBER_RECEIVING';
const ENABLE_COMPANY_AND_VAT_NUMBER_SEND = 'RETAILCRM_ENABLE_COMPANY_AND_VAT_NUMBER_SEND';
const ENABLE_DEBUG_MODE = 'RETAILCRM_ENABLE_DEBUG_MODE';

const CONSULTANT_SCRIPT = 'RETAILCRM_CONSULTANT_SCRIPT';
const CONSULTANT_RCCT = 'RETAILCRM_CONSULTANT_RCCT';
const ENABLE_WEB_JOBS = 'RETAILCRM_ENABLE_WEB_JOBS';

const REQUIRED_CRM_SITE_ACCESS = 'access_selective';
const REQUIRED_CRM_SITE_COUNT = 1;
const REQUIRED_CRM_SCOPES = [
Expand Down Expand Up @@ -343,6 +342,7 @@ public function uninstall()
&& Configuration::deleteByName(static::ENABLE_BALANCES_RECEIVING)
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_SENDING)
&& Configuration::deleteByName(static::ENABLE_ORDER_NUMBER_RECEIVING)
&& Configuration::deleteByName(static::ENABLE_COMPANY_AND_VAT_NUMBER_SEND)
&& Configuration::deleteByName(static::ENABLE_DEBUG_MODE)
&& Configuration::deleteByName(static::ENABLE_WEB_JOBS)
&& Configuration::deleteByName('RETAILCRM_LAST_SYNC')
Expand Down
3,540 changes: 3,539 additions & 1 deletion retailcrm/views/js/app.js

Large diffs are not rendered by default.

2,560 changes: 2,507 additions & 53 deletions retailcrm/views/js/chunk-vendors.js

Large diffs are not rendered by default.

0 comments on commit d3f5a8c

Please sign in to comment.