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

101 lines
4.3 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 'includes/Loader.php';
vimport ('includes.runtime.Globals');
vimport ('includes.runtime.BaseModel');
vimport ('includes.runtime.LanguageHandler');
function vtws_createproject($contactid, $offenderid, $agentid, $sms, $ip, $source, $region, $formid, $category, $direction, $agrprice, $subject, $agrdate, $startdate, $finishdate, $loss, $servicecost, $progress, $country, $hotel, $transport, $insurance, $other, $description, $independently, $claimdate, $returned, $user = false) {
$output = 'Внутрення ошибка CRM, данные не сохранены';
$logstring = date("Y-m-d H:i:s").' '.json_encode($_REQUEST);
file_put_contents('logs/CreateProject.log', $logstring.PHP_EOL, FILE_APPEND);
if(empty($contactid) or empty($offenderid)){
$logstring = date("Y-m-d H:i:s").' Не указано одно из обязательных полей: id клиента-физлица или id контрагента-обидчика';
file_put_contents('logs/CreateProject.log', $logstring.PHP_EOL, FILE_APPEND);
throw new WebServiceException(WebServiceErrorCode::$INVALIDID, "Не указаны обязательные поля");
}
global $adb, $current_user;
$query = "select c.lastname
from vtiger_contactdetails c
left join vtiger_crmentity e on e.crmid = c.contactid
where e.deleted = 0 and c.contactid = ?
limit 1";
$result = $adb->pquery($query, array($contactid));
$name = $adb->query_result($result, 0, 'lastname'); // Первая часть названия Проекта - фамилия терпилы
$query = "select a.accountname
from vtiger_account a
left join vtiger_crmentity e on e.crmid = a.accountid
where e.deleted = 0 and a.accountid = ?
limit 1";
$result = $adb->pquery($query, array($offenderid));
$name .= ' '.$adb->query_result($result, 0, 'accountname'); // Вторая часть названия Проекта - название злодея
// Основные поля модуля Проекты
$params = array (
'projectname' => $name,
'linktoaccountscontacts' => '12x'.$contactid,
'cf_2274' => '11x'.$offenderid,
'projectstatus' => 'модерация',
'projecttype' => 'Претензионно - исковая работа',
'cf_2206' => $sms,
'cf_2210' => $ip,
'cf_2212' => $source,
'cf_2214' => $region,
'cf_2208' => $formid,
'cf_1830' => $category,
'cf_1469' => $direction,
'assigned_user_id' => vtws_getWebserviceEntityId('Users', $current_user->id)
);
if (!empty($agentid)) {
$params['cf_2276'] = '11x'.$agentid;
}
// Блок с условиями договора
$params['cf_1191'] = $agrprice;
$params['cf_1189'] = $subject;
$params['cf_1203'] = $agrdate;
$params['cf_1839'] = $startdate;
$params['cf_1841'] = $finishdate;
$params['cf_1207'] = $loss;
$params['cf_1479'] = $servicecost;
$params['cf_1227'] = $progress;
$params['cf_1231'] = $country;
$params['cf_1239'] = $hotel;
$params['cf_1566'] = $transport;
$params['cf_1564'] = $insurance;
$params['cf_1249'] = $other;
$params['description'] = $description;
// Блок про претензионный порядок
$params['cf_1471'] = $independently;
$params['cf_1473'] = $claimdate;
$params['cf_1475'] = $returned;
$logstring = date('Y-m-d H:i:s').' Массив для создания Контакта: '.json_encode($params).PHP_EOL;
file_put_contents('logs/CreateProject.log', $logstring, FILE_APPEND);
try {
$project = vtws_create('Project', $params, $current_user);
$output = substr($project['id'], 3);
$logstring = date('Y-m-d H:i:s').' создан Проект с id '.$output.PHP_EOL;
file_put_contents('logs/CreateProject.log', $logstring, FILE_APPEND);
} catch (WebServiceException $ex) {
$logstring = date('Y-m-d H:i:s').' '.$ex->getMessage().PHP_EOL;
file_put_contents('logs/CreateProject.log', $logstring, FILE_APPEND);
}
return $output;
}