Files
crm.clientright.ru/include/Webservices/CreateAccount.php

82 lines
3.5 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
/*********************************************************************************
* API-интерфейс для создани Контрагента
* All Rights Reserved.
* Contributor(s): Илья Руденко itsaturn@yandex.ru
********************************************************************************/
include_once 'include/Webservices/Query.php';
include_once 'modules/Users/Users.php';
require_once('include/Webservices/Utils.php');
require_once 'include/Webservices/Create.php';
require_once 'include/Webservices/Revise.php';
require_once 'includes/Loader.php';
vimport ('includes.runtime.Globals');
vimport ('includes.runtime.BaseModel');
vimport ('includes.runtime.LanguageHandler');
function vtws_CreateAccount($accountname, $address, $email, $website, $phone, $inn, $ogrn, $user = false) {
$logstring = date("Y-m-d H:i:s").' '.json_encode($_REQUEST);
file_put_contents('logs/CreateAccount.log', $logstring.PHP_EOL, FILE_APPEND);
if(empty($accountname) or empty($inn) or empty($ogrn)){
$logstring = date("Y-m-d H:i:s").' Не указано одно из обязательных полей: Наименование контрагента, ИНН или ОГРН';
file_put_contents('logs/CreateAccount.log', $logstring.PHP_EOL, FILE_APPEND);
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Не заполнены обязательные поля");
}
$output = 'Внутрення ошибка CRM, данные не сохранены';
$params = array (
'accountname' => $accountname,
'bill_street' => $address,
'email1' => $email,
'website' => $website,
'phone' => $phone,
'inn' => $inn,
'cf_1951' => $ogrn
);
global $adb, $current_user;
$query = "select a.accountid
from vtiger_account a
left join vtiger_crmentity e on e.crmid = a.accountid
where e.deleted = 0 and a.inn = ?
limit 1";
$result = $adb->pquery($query, array($inn));
if ($adb->num_rows($result) > 0) {
//$params['id'] = '11x'.$adb->query_result($result, 0, 'accountid');
$output = $adb->query_result($result, 0, 'accountid');
$logstring = date('Y-m-d H:i:s').' Найден контрагент с id = '.$output.', просто вернем его наружу'.PHP_EOL;
file_put_contents('logs/CreateAccount.log', $logstring, FILE_APPEND);
/*
try {
$account = vtws_revise($params, $current_user);
$output = substr($account['id'], 3);
$logstring = date('Y-m-d H:i:s').' обновлен Контрагент с id '.$output.PHP_EOL;
file_put_contents('logs/CreateAccount.log', $logstring, FILE_APPEND);
} catch (WebServiceException $ex) {
$logstring = date('Y-m-d H:i:s').' '.$ex->getMessage().PHP_EOL;
file_put_contents('logs/CreateAccount.log', $logstring, FILE_APPEND);
}
*/
} else {
$params['assigned_user_id'] = vtws_getWebserviceEntityId('Users', $user->id);
$logstring = date('Y-m-d H:i:s').' Массив для создания Контрагента: '.json_encode($params).PHP_EOL;
file_put_contents('logs/CreateAccount.log', $logstring, FILE_APPEND);
try {
$account = vtws_create('Accounts', $params, $user);
$output = substr($account['id'], 3);
$logstring = date('Y-m-d H:i:s').' создан Контрагент с id '.$output.PHP_EOL;
file_put_contents('logs/CreateAccount.log', $logstring, FILE_APPEND);
} catch (WebServiceException $ex) {
$logstring = date('Y-m-d H:i:s').' '.$ex->getMessage().PHP_EOL;
file_put_contents('logs/CreateAccount.log', $logstring, FILE_APPEND);
}
}
return $output;
}