Joywork/engine/classes/WebAppRaiser/forms/OrderCreateForm.php
2026-05-22 21:21:54 +03:00

411 lines
12 KiB
PHP
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
class OrderCreateForm extends WebAppRaiserForm
{
public function __construct($form_id)
{
parent::__construct($form_id);
}
public function form()
{
$form = parent::form();
$header = '<div style="border-bottom: 2px solid rgb(67, 160, 71); margin: 2em 0;"><h2>%s</h2></div>';
$label = function($data) {
return array('#text' => $data, '#class' => ['label'], '#style' => ['float:none;min-height: 28px;padding-top: 4px;width:100%;']);
};
$form['form_attributes']['enctype'] = 'multipart/form-data';
$form['form_attributes']['js'][] = 'engine/classes/WebAppRaiser/forms/OrderCreateForm.js';
$form['woid'] = array(
'inputs' => array(
'#type'=> 'hidden',
),
);
$form['object_id'] = array(
'inputs' => array(
'#type'=> 'hidden',
),
);
/*$form['appraisalCompanyId'] = array(
'inputs' => array(
'#type'=> 'hidden',
'#required'=> false,
),
); // */
// Информация о заказе
$form['markup_zakaz_header'] = array(
'#prefix' => '<div class="row">',
'inputs' => array(
'#type' => 'markup',
'#value' => sprintf($header, 'Заказ'),
),
'#suffix' => '</div>',
);
$form['serviceType'] = array(
'#prefix' => '<div class="row"><div class="col col-md-6">',
'label'=> $label('Тип заказа'), // Тип услуги оценки
'inputs' => array(
'#type'=> 'select',
'#required'=> true,
'#options' => WebAppRaiserAPI::getDict('APPRAISAL_SERVICE_TYPE'),
'#inputs_style' => 'float:none; width:90%',
),
);
$form['objectType'] = array(
'label'=> $label('Объект оценки'), // Тип объекта оценки
'inputs' => array(
'#type'=> 'select',
'#required'=> true,
'#options' => WebAppRaiserAPI::getDict('OBJECT_TYPE'),
'#inputs_style' => 'float:none; width:90%',
),
);
$form['reportUsageType'] = array(
'label'=> $label('Цель оценки'),
'inputs' => array(
'#type'=> 'select',
'#required'=> true,
'#options' => WebAppRaiserAPI::getDict('REPORT_USAGE_TYPE'),
'#inputs_style' => 'float:none; width:90%',
),
);
$form['address'] = array(
'label'=> $label('Адрес объекта'), // Адрес объекта оценки
'inputs' => array(
'#type'=> 'textarea',
'#required'=> true,
'#inputs_style' => 'float:none; width:90%',
),
);
$form['bankId'] = array(
'label'=> $label('Идентификатор банка в Системе'),
'inputs' => array(
'#type'=> 'select',
'#otions'=> [0 => 'Выберите банк'],
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div>',
);
// получаем список банков по API
global $WebAppRaiserAPI;
$banks = $WebAppRaiserAPI->loadBanks();
if(!empty($banks)){
foreach($banks as $bank_id => $bank_name){
$form['bankId']['inputs']['#options'][$bank_id] = $bank_name;
}
}
$form['contractCost'] = array(
'#prefix' => '<div class="col col-md-6"><div class="row"><div class="col col-md-6">',
'label'=> $label('Стоимость в договоре'), // Стоимость объекта при покупке
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div>',
);
$form['makeAnaliceButton'] = array(
'#prefix'=> '<div class="col col-md-6">',
'#markup'=> '<a href="#" id="cost_analice_button" style="margin-top: 15px;padding: 8px 12px;height: auto;" class="fr-btn edit-btn steel i-btn small cost_analice_form_modal_open">Расчитать стоимость</a>',
'#suffix' => '</div></div>',
);
$form['managerEmail'] = array(
'label'=> $label('Email менеджера'),
'inputs' => array(
'#type'=> 'email',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
);
$form['managerComment'] = array(
'label'=> $label('Комментарий менеджера'),
'inputs' => array(
'#type'=> 'textarea',
'#required'=> false,
'#rows' => 8,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div></div>',
);
// Заказчик и менеджер
$form['markup_zakazchik_manager_start'] = array(
'inputs' => array(
'#type' => 'markup',
'#value' => '<div class="row">',
),
);
$form['customerName'] = array(
'#prefix' => '<div class="col-12 col-md-6">'.sprintf($header, 'Заказчик / заемщик'),
'label'=> $label('ФИО клиента'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
);
$form['customerPhone'] = array(
'label'=> $label('Контактный телефон клиента'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
);
$form['customerEmail'] = array(
'label'=> $label('Email клиента'),
'inputs' => array(
'#type'=> 'email',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div>',
);
/* $form['customerPassportSerial'] = array(
'label'=> 'Серия паспорта клиента',
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
),
);
$form['customerPassportNumber'] = array(
'label'=> 'Номер паспорта клиента',
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
),
);
$form['customerPassportSub'] = array(
'label'=> 'Код подразделения, выдавшего паспорт клиенту',
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
),
);
$form['customerPassportIssuedBy'] = array(
'label'=> 'Название отделения, кем выдан паспорт клиенту',
'inputs' => array(
'#type'=> 'textarea',
'#required'=> false,
),
);
$form['customerPassportIssueDate'] = array(
'label'=> 'Дата выдачи паспорта',
'inputs' => array(
'#type'=> 'date',
'#required'=> false,
),
);
$form['customerPassportAddress'] = array(
'label'=> 'Адрес регистрации клиента',
'inputs' => array(
'#type'=> 'textarea',
'#required'=> false,
),
); // */
$form['bankManagerName'] = array(
'#prefix' => '<div class="col-12 col-md-6">'.sprintf($header, 'Менеджер банка'),
'label'=> $label('ФИО менеджера банка'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
);
$form['bankManagerEmail'] = array(
'label'=> $label('Email менеджера банка'),
'inputs' => array(
'#type'=> 'email',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div>',
);
$form['markup_zakazchik_manager_end'] = array(
'inputs' => array(
'#type' => 'markup',
'#value' => '</div>',
),
);
$form['markup_osmotr_dostavka_start'] = array(
'inputs' => array(
'#type' => 'markup',
'#value' => '<div class="row">',
),
);
$form['inspectionContactName'] = array(
'#prefix' => '<div class="col-12 col-md-6">'.sprintf($header, 'Осмотр'),
'label'=> $label('ФИО, ответственного за осмотр'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
);
$form['inspectionContactPhone'] = array(
'label'=> $label('Контактный телефон, ответственного за осмотр'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div>',
);
$form['deliveryRequired'] = array(
'#prefix' => '<div class="col-12 col-md-6">'.sprintf($header, 'Доставка'),
'label_append'=> ['#text' => 'Требуется доставка', '#class' => ['label'], '#style' => ['float:left;margin-top: 12px;']],
'inputs' => array(
'#type'=> 'checkbox',
'#required'=> false,
'#check_option' => 1,
'#inputs_style' => 'float: left;width: 70px;',
),
);
$form['deliveryAddress'] = array(
'label'=> $label('Адрес доставки'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
);
$form['deliveryContactName'] = array(
'label'=> $label('Контактное лицо'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
);
$form['deliveryContactPhone'] = array(
'label'=> $label('Номер телефона контакта'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div>',
);
$form['markup_osmotr_dostavka_end'] = array(
'inputs' => array(
'#type' => 'markup',
'#value' => '</div>',
),
);
$form['сontactName'] = array(
'#prefix' => '<div class="col-12 col-md-12">'.sprintf($header, 'Ответственный агент').'</div><div class="col-12 col-md-4">',
'label'=> $label('ФИО контактного лица'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div>',
);
$form['сontactPhone'] = array(
'#prefix' => '<div class="col-12 col-md-4">',
'label'=> $label('Номер телефона контактного лица'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div>',
);
$form['сontactEmail'] = array(
'#prefix' => '<div class="col-12 col-md-4">',
'label'=> $label('Email контактного лица'),
'inputs' => array(
'#type'=> 'text',
'#required'=> false,
'#inputs_style' => 'float:none; width:90%',
),
'#suffix' => '</div>',
);
$form['images'] = array(
'#prefix' => '<div class="col-12 col-md-12">'.sprintf($header, 'Фотографии').'',
'inputs' => array(
'#type' => 'markup',
'#value'=> 'картинки',
),
'#suffix' => '</div>',
);
$form['submit'] = array(
'inputs' => array(
'#type'=> 'submit',
'#value'=> 'Сохранить',
),
);
return $form;
}
public function validate()
{
$status = parent::validate();
return $status;
}
public function submit($status, &$page, WebAppRaiserAPI $WebAppRaiserAPI)
{
parent::submit($status, $page, $WebAppRaiserAPI);
$page['status'] = $status['code'];
$page['msg'] = array_merge($page['msg'], $status['message']);
if($status['code'] == 'success'){
if($status['post']['deliveryRequired']){
$status['post']['deliveryRequired'] = true;
}
if(!empty($status['post']['photolist'])){
$photo_post = array();
$photo_list = trim($status['post']['photolist'], ' ,.');
$photo_ids = explode(',', $photo_list);
foreach($photo_ids as $photo_id){
$photo_data = WebAppRaiserDB::select('object_photo', 'id', $photo_id);
$photo_url = $photo_data[0]['photo'];
$filename = pathinfo($photo_url, PATHINFO_BASENAME);
$data = file_get_contents($photo_url);
$base64 = base64_encode($data);
$photo_post[] = array(
'name' => $filename,
'data' => $base64,
);
}
}
$status['post']['photos'] = $photo_post;
$status['post']['allowMessaging'] = true;
$result = $WebAppRaiserAPI->createOrder($status['post']);
$page['status'] = $result['status'];
$page['msg'][] = $result['msg'];
}
else {
// validation fail
}
parent::redirect($page);
}
}