1
0
mirror of synced 2024-11-30 01:06:06 +03:00
bitrix-module/intaro.retailcrm/install/step3.php

325 lines
14 KiB
PHP
Raw Normal View History

2013-07-05 18:19:42 +04:00
<?php
2021-09-08 10:19:29 +03:00
use Intaro\RetailCrm\Component\Constants;
2021-09-08 10:19:29 +03:00
use RetailCrm\ApiClient;
/** @var $APPLICATION */
if (!check_bitrix_sessid()) {
return;
2021-09-08 10:19:29 +03:00
}
IncludeModuleLangFile(__FILE__);
$api_host = COption::GetOptionString(Constants::MODULE_ID, Constants::CRM_API_HOST_OPTION, 0);
$api_key = COption::GetOptionString(Constants::MODULE_ID, Constants::CRM_API_KEY_OPTION, 0);
2021-09-08 10:19:29 +03:00
$arResult['arSites'] = RCrmActions::getSitesList();
2020-04-24 13:18:18 +03:00
2021-09-08 10:19:29 +03:00
$RETAIL_CRM_API = new ApiClient($api_host, $api_key);
COption::SetOptionString(Constants::MODULE_ID, Constants::CRM_API_HOST_OPTION, $api_host);
COption::SetOptionString(Constants::MODULE_ID, Constants::CRM_API_KEY_OPTION, $api_key);
if (count($arResult['arSites']) === 1) {
COption::SetOptionString(Constants::MODULE_ID, Constants::CRM_SITES_LIST, serialize([]));
}
2020-04-24 13:18:18 +03:00
if (!isset($arResult['bitrixOrderTypesList'])) {
$arResult['bitrixOrderTypesList'] = RCrmActions::OrderTypesList($arResult['arSites']);
$arResult['arProp'] = RCrmActions::OrderPropsList();
$arResult['locationProp'] = RCrmActions::getLocationProps();
$arResult['ORDER_PROPS'] = unserialize(COption::GetOptionString(Constants::MODULE_ID, Constants::CRM_ORDER_PROPS, 0));
2020-04-24 13:18:18 +03:00
}
if (!isset($arResult['LEGAL_DETAILS'])) {
$arResult['LEGAL_DETAILS'] = unserialize(COption::GetOptionString(Constants::MODULE_ID, Constants::CRM_LEGAL_DETAILS, 0));
2020-04-24 13:18:18 +03:00
}
if (!isset($arResult['CONTRAGENT_TYPES'])) {
$arResult['CONTRAGENT_TYPES'] = unserialize(COption::GetOptionString(Constants::MODULE_ID, Constants::CRM_CONTRAGENT_TYPE, 0));
if ($arResult['CONTRAGENT_TYPES'] === false) {
foreach ($arResult['contragentType'] as $crmContrAgentType) {
if ($crmContrAgentType['ID'] === 'individual') {
$arResult['CONTRAGENT_TYPES']['1'] = 'individual';
}
if ($crmContrAgentType['ID'] === 'legal-entity') {
$arResult['CONTRAGENT_TYPES']['2'] = 'legal-entity';
}
}
}
2020-04-24 13:18:18 +03:00
}
2021-09-08 10:19:29 +03:00
if (isset($arResult['ORDER_PROPS'])) {
2016-09-15 16:42:10 +03:00
$defaultOrderProps = $arResult['ORDER_PROPS'];
2021-09-08 10:19:29 +03:00
} else {
$defaultOrderProps = [
1 => [
'fio' => 'FIO',
2016-09-15 16:42:10 +03:00
'index' => 'ZIP',
2021-09-08 10:19:29 +03:00
'text' => 'ADDRESS',
2016-09-15 16:42:10 +03:00
'phone' => 'PHONE',
2021-09-08 10:19:29 +03:00
'email' => 'EMAIL',
],
2 => [
'fio' => 'CONTACT_PERSON',
2016-09-15 16:42:10 +03:00
'index' => 'ZIP',
2021-09-08 10:19:29 +03:00
'text' => 'ADDRESS',
2016-09-15 16:42:10 +03:00
'phone' => 'PHONE',
2021-09-08 10:19:29 +03:00
'email' => 'EMAIL',
],
];
2016-09-15 16:42:10 +03:00
}
2013-09-05 12:11:29 +04:00
?>
<?php CJSCore::Init(['jquery']);?>
<script type="text/javascript">
function updateAddressList()
{
splitName = $(this).attr('name').split('-');
orderType = splitName[2];
if (parseInt($(this).val()) === 1) {
let locationElement = document.getElementById('locationElement-' + orderType);
let replacedSelect = document.getElementsByName('order-prop-text-' + orderType);
let replacedElement = replacedSelect[0].parentNode.parentNode;
let addedLocation = locationElement.cloneNode(true);
addedLocation.querySelector(`select`).setAttribute("name", 'order-prop-text-' + orderType);
addedLocation.removeAttribute("hidden");
addedLocation.removeAttribute("id");
replacedElement.replaceWith(addedLocation);
$('tr.address-detail-' + orderType).show('slow');
} else if (parseInt($(this).val()) === 0) {
let locationElement = document.getElementById('textAddressElement-' + orderType);
let replacedSelect = document.getElementsByName('order-prop-text-' + orderType);
let replacedElement = replacedSelect[0].parentNode.parentNode;
let addedLocation = locationElement.cloneNode(true);
addedLocation.querySelector(`select`).setAttribute("name", 'order-prop-text-' + orderType);
addedLocation.removeAttribute("hidden");
addedLocation.removeAttribute("id");
replacedElement.replaceWith(addedLocation);
$('tr.address-detail-' + orderType).hide('slow');
}
}
2020-04-24 13:18:18 +03:00
$(document).ready(function() {
2021-09-08 10:19:29 +03:00
const individual = $("[name='contragent-type-1']").val();
const legalEntity = $("[name='contragent-type-2']").val();
$('input:checked[name^="address-detail-"]').each(updateAddressList);
2020-04-24 13:18:18 +03:00
2021-09-08 10:19:29 +03:00
if (legalEntity !== 'individual') {
2020-04-24 13:18:18 +03:00
$('tr.legal-detail-2').each(function(){
if($(this).hasClass(legalEntity)){
$(this).show();
$('.legal-detail-title-2').show();
}
});
}
2021-09-08 10:19:29 +03:00
if (individual !== 'individual') {
2020-04-24 13:18:18 +03:00
$('tr.legal-detail-1').each(function(){
if($(this).hasClass(individual)){
$(this).show();
$('.legal-detail-title-1').show();
}
});
}
$('input[name^="address-detail-"]').change(updateAddressList);
2015-03-03 16:37:34 +03:00
$('tr.contragent-type select').change(function(){
2021-09-08 10:19:29 +03:00
const splitName = $(this).attr('name').split('-');
const contragentType = $(this).val();
const orderType = splitName[2];
let legalDetailOrderType = $('tr.legal-detail-' + orderType);
legalDetailOrderType.hide();
2015-03-03 16:37:34 +03:00
$('.legal-detail-title-' + orderType).hide();
2021-09-08 10:19:29 +03:00
legalDetailOrderType.each(function(){
2015-03-03 16:37:34 +03:00
if($(this).hasClass(contragentType)){
$(this).show();
$('.legal-detail-title-' + orderType).show();
}
});
2015-03-03 16:37:34 +03:00
});
2013-09-05 12:11:29 +04:00
});
</script>
2013-09-05 12:11:29 +04:00
<div class="adm-detail-content-item-block">
2021-09-08 10:19:29 +03:00
<form action="<?= $APPLICATION->GetCurPage() ?>" method="POST">
<?= bitrix_sessid_post()?>
<input type="hidden" name="lang" value="<?= LANGUAGE_ID ?>">
2016-09-15 16:42:10 +03:00
<input type="hidden" name="id" value="intaro.retailcrm">
<input type="hidden" name="install" value="Y">
<input type="hidden" name="step" value="4">
<input type="hidden" name="continue" value="3">
2013-09-05 12:11:29 +04:00
<table class="adm-detail-content-table edit-table" id="edit1_edit_table">
<tbody>
<tr class="heading">
2021-09-08 10:19:29 +03:00
<td colspan="2"><b><?= GetMessage('STEP_NAME')?></b></td>
2013-09-05 12:11:29 +04:00
</tr>
<tr class="heading">
2021-09-08 10:19:29 +03:00
<td colspan="2"><b><?= GetMessage('ORDER_PROPS')?></b></td>
2013-09-05 12:11:29 +04:00
</tr>
2013-09-05 13:38:58 +04:00
<tr align="center">
2021-09-08 10:19:29 +03:00
<td colspan="2"><b><?= GetMessage('INFO_2')?></b></td>
2013-09-05 13:38:58 +04:00
</tr>
<?php foreach($arResult['bitrixOrderTypesList'] as $bitrixOrderType): ?>
<tr class="heading">
2021-09-08 10:19:29 +03:00
<td colspan="2"><b><?= GetMessage('ORDER_TYPE_INFO') . ' ' . $bitrixOrderType['NAME']?></b></td>
2013-09-05 13:38:58 +04:00
</tr>
2015-03-03 16:37:34 +03:00
<tr class="contragent-type">
<td width="50%" class="adm-detail-content-cell-l">
2021-09-08 10:19:29 +03:00
<?= GetMessage('CONTRAGENT_TYPE')?>
2015-03-03 16:37:34 +03:00
</td>
<td width="50%" class="adm-detail-content-cell-r">
2021-09-08 10:19:29 +03:00
<select name="contragent-type-<?= $bitrixOrderType['ID']?>" class="typeselect">
2015-03-03 16:37:34 +03:00
<?php foreach ($arResult['contragentType'] as $contragentType): ?>
2021-09-08 10:19:29 +03:00
<option value="<?= $contragentType['ID']; ?>"
<?=
(isset($arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']])
&& $arResult['CONTRAGENT_TYPES'][$bitrixOrderType['ID']] == $contragentType['ID']) ?
'selected'
: ''
?>
>
<?= $contragentType['NAME']?>
2015-03-03 16:37:34 +03:00
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
2013-09-05 13:38:58 +04:00
<?php $countProps = 0; foreach($arResult['orderProps'] as $orderProp): ?>
2021-09-08 10:19:29 +03:00
<?php if($orderProp['ID'] === 'text'): ?>
2013-09-05 12:11:29 +04:00
<tr class="heading">
2013-09-19 00:18:32 +04:00
<td colspan="2" style="background-color: transparent;">
2013-09-05 12:11:29 +04:00
<b>
2021-09-08 10:19:29 +03:00
<label>
<input class="addr" type="radio" name="address-detail-<?= $bitrixOrderType['ID']?>" value="0"
<?= (is_array($defaultOrderProps[$bitrixOrderType['ID']]) && count($defaultOrderProps[$bitrixOrderType['ID']]) < 6) ? 'checked' : '' ?>>
2021-09-08 10:19:29 +03:00
<?= GetMessage('ADDRESS_SHORT')?>
</label>
<label>
<input class="addr" type="radio" name="address-detail-<?= $bitrixOrderType['ID']?>" value="1"
<?= (is_array($defaultOrderProps[$bitrixOrderType['ID']]) && count($defaultOrderProps[$bitrixOrderType['ID']]) > 5) ? 'checked' : '' ?>>
2021-09-08 10:19:29 +03:00
<?= GetMessage('ADDRESS_FULL')?>
</label>
2013-09-05 12:11:29 +04:00
</b>
</td>
</tr>
<?php endif; ?>
2015-03-03 16:37:34 +03:00
2021-09-08 10:19:29 +03:00
<tr <?= ($countProps > 3) ? 'class="address-detail-' . $bitrixOrderType['ID'] . '"' : ''?>
<?= (is_array($defaultOrderProps[$bitrixOrderType['ID']] && ($countProps > 3) && (count($defaultOrderProps[$bitrixOrderType['ID']]) < 6)))
2021-09-08 10:19:29 +03:00
? 'style="display:none;"'
: ''
?>
>
<td width="50%" class="adm-detail-content-cell-l" name="<?= $orderProp['ID']?>">
<?= $orderProp['NAME']; ?>
2013-09-05 12:11:29 +04:00
</td>
2015-03-03 16:37:34 +03:00
<td width="50%" class="adm-detail-content-cell-r">
2021-09-08 10:19:29 +03:00
<select name="order-prop-<?= $orderProp['ID'] . '-' . $bitrixOrderType['ID']?>" class="typeselect">
2015-03-03 16:37:34 +03:00
<option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
2021-09-08 10:19:29 +03:00
<option value="<?= $arProp['CODE']?>"
<?= ($defaultOrderProps[$bitrixOrderType['ID']][$orderProp['ID']] === $arProp['CODE'])
? 'selected'
: '' ?>
>
<?= $arProp['NAME']?>
2015-03-03 16:37:34 +03:00
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php $countProps++; endforeach; ?>
<tr id="<?php echo 'locationElement-' . $bitrixOrderType['ID']; ?>" hidden="hidden">
<td class="adm-detail-content-cell-l" width="50%" name="text"><?php echo GetMessage('LOCATION_LABEL'); ?></td>
<td class="adm-detail-content-cell-r" width="50%">
<select class="typeselect">
<option value=""></option>
<?php foreach ($arResult['locationProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>"
<?php if ($defaultOrderProps[$bitrixOrderType['ID']]['text'] === $arProp['CODE']) {
echo 'selected';
} ?>
>
<?php echo $arProp['NAME'];?>
</option>
<?php endforeach;?>
</select>
</td>
</tr>
<tr id="<?php echo 'textAddressElement-' . $bitrixOrderType['ID']; ?>" hidden="hidden">
<td class="adm-detail-content-cell-l" width="50%" name="text"><?php echo GetMessage('TEXT_ADDRESS_LABEL'); ?></td>
<td class="adm-detail-content-cell-r" width="50%">
<select class="typeselect">
<option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
<option value="<?php echo $arProp['CODE']; ?>"
<?php if ($defaultOrderProps[$bitrixOrderType['ID']]['text'] === $arProp['CODE']) {
echo 'selected';
} ?>
>
<?php echo $arProp['NAME']; ?>
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
2021-09-08 10:19:29 +03:00
<tr class="heading legal-detail-title-<?= $bitrixOrderType['ID']?>" style="display:none">
2015-03-03 16:37:34 +03:00
<td colspan="2" style="background-color: transparent;">
<b>
2021-09-08 10:19:29 +03:00
<?= GetMessage('ORDER_LEGAL_INFO'); ?>
2015-03-03 16:37:34 +03:00
</b>
</td>
</tr>
2020-04-24 13:18:18 +03:00
2015-03-03 16:37:34 +03:00
<?php foreach($arResult['legalDetails'] as $legalDetails): ?>
2021-09-08 10:19:29 +03:00
<tr class="legal-detail-<?= $bitrixOrderType['ID']?> <?php foreach($legalDetails['GROUP'] as $gr) echo $gr . ' ';?>" style="display:none">
2015-03-03 16:37:34 +03:00
<td width="50%" class="adm-detail-content-cell-l">
2021-09-08 10:19:29 +03:00
<?= $legalDetails['NAME']; ?>
2015-03-03 16:37:34 +03:00
</td>
<td width="50%" class="adm-detail-content-cell-r">
2021-09-08 10:19:29 +03:00
<select name="legal-detail-<?= $legalDetails['ID'] . '-' . $bitrixOrderType['ID']?>" class="typeselect">
2015-03-03 16:37:34 +03:00
<option value=""></option>
<?php foreach ($arResult['arProp'][$bitrixOrderType['ID']] as $arProp): ?>
2021-09-08 10:19:29 +03:00
<option value="<?= $arProp['CODE']?>"
<?= (isset($arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']])
&& $arResult['LEGAL_DETAILS'][$bitrixOrderType['ID']][$legalDetails['ID']] === $arProp['CODE'])
? 'selected' : ''
?>
>
<?= $arProp['NAME']?>
2015-03-03 16:37:34 +03:00
</option>
<?php endforeach; ?>
</select>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
2013-09-05 12:11:29 +04:00
</tbody>
</table>
<br />
<div style="padding: 1px 13px 2px; height:28px;">
<div align="right" style="float:right; width:50%; position:relative;">
2021-09-08 10:19:29 +03:00
<input type="submit" name="inst" value="<?= GetMessage('MOD_NEXT_STEP')?>" class="adm-btn-save">
</div>
<div align="left" style="float:right; width:50%; position:relative; visible: none;">
2021-09-08 10:19:29 +03:00
<input type="submit" name="back" value="<?= GetMessage('MOD_PREV_STEP')?>" class="adm-btn-save">
</div>
</div>
2013-09-05 12:11:29 +04:00
</form>
2021-09-08 10:19:29 +03:00
</div>