<?php // этот модуль необходимо делать тольео для крупных проектов, для небольшых описание пунктов меню и файлов меню лучше делать в init.php
$__functions['init'][]      ='_esmo_ruda_admin_vars' ;
$__functions['boot_admin'][] ='_esmo_ruda_admin_boot' ;
//$__functions['alert'][]   ='_esmo_ruda_admin_alert' ;
$__functions['install'][]	='_esmo_ruda_install_modul' ;



function _esmo_ruda_admin_vars() //
{
   $_SESSION['descr_clss'][800]['name']='Маршрут ЭСМО Руда' ;
   $_SESSION['descr_clss'][800]['parent']=0 ;
   $_SESSION['descr_clss'][800]['fields']['from_zone_id']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][800]['fields']['to_zone_id']=array('type'=>'int(11)') ; ;

   $_SESSION['descr_clss'][801]['name']='Точка маршрута ЭСМО Руда' ;
   $_SESSION['descr_clss'][801]['parent']=0 ;
   $_SESSION['descr_clss'][801]['fields']['type']=array('type'=>'int(11)','default'=>1) ; ;
   $_SESSION['descr_clss'][801]['fields']['point_id']=array('type'=>'int(11)') ; ;


   $_SESSION['descr_clss'][806]['name']='Задача на перевозку руды' ;
   $_SESSION['descr_clss'][806]['parent']=0 ;
   $_SESSION['descr_clss'][806]['fields']['task_uid']=array('type'=>'varchar(32)','index'=>'task_uid') ; ; // UID задачи (1С)
   $_SESSION['descr_clss'][806]['fields']['route_id']=array('type'=>'int(11)','index'=>'route_id') ; ;
   $_SESSION['descr_clss'][806]['fields']['header_id']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][806]['fields']['line_id']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][806]['fields']['invoice_id']=array('type'=>'varchar(128)','index'=>'invoice_id') ; ;
   $_SESSION['descr_clss'][806]['fields']['time_from']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][806]['fields']['time_to']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][806]['fields']['value']=array('type'=>'float(10,2)') ; ;
   $_SESSION['descr_clss'][806]['fields']['status']=array('type'=>'int(11)','default'=>1) ; ;
   $_SESSION['descr_clss'][806]['fields']['order_number']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][806]['fields']['status_code_line']=array('type'=>'varchar(12)') ; ;
   $_SESSION['descr_clss'][806]['fields']['ver_ord']=array('type'=>'int(11)') ; ;


   $_SESSION['descr_clss'][802]['name']='Заявка на перевозку руды' ;
   $_SESSION['descr_clss'][802]['parent']=0 ;
   $_SESSION['descr_clss'][802]['fields']['request_id']=array('type'=>'varchar(128)','index'=>'request_id') ;
   $_SESSION['descr_clss'][802]['fields']['request_uid']=array('type'=>'varchar(128)','index'=>'request_uid') ;
   $_SESSION['descr_clss'][802]['fields']['task_id']=array('type'=>'int(11)','index'=>'task_id') ; ;
   $_SESSION['descr_clss'][802]['fields']['line_id']=array('type'=>'int(11)','index'=>'line_id') ; ;
   $_SESSION['descr_clss'][802]['fields']['time_from']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][802]['fields']['time_to']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][802]['fields']['account_id']=array('type'=>'int(11)','index'=>'account_id') ; ;
   $_SESSION['descr_clss'][802]['fields']['url_pdf_doc']=array('type'=>'varchar(256)') ; ;

   $_SESSION['descr_clss'][803]['name']='Позиция заявки на перевозку руды' ;
   $_SESSION['descr_clss'][803]['parent']=0 ;
   $_SESSION['descr_clss'][803]['fields']['task_id']=array('type'=>'int(11)','index'=>'task_id') ; ;
   $_SESSION['descr_clss'][803]['fields']['request_uid']=array('type'=>'varchar(128)','index'=>'request_uid') ; ;
   $_SESSION['descr_clss'][803]['fields']['person_id']=array('type'=>'int(11)','index'=>'person_id') ; ;
   $_SESSION['descr_clss'][803]['fields']['car_id']=array('type'=>'int(11)','index'=>'car_id') ; ;
   $_SESSION['descr_clss'][803]['fields']['trip_id']=array('type'=>'int(11)','index'=>'trip_id') ; ;
   $_SESSION['descr_clss'][803]['fields']['line_id']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][803]['fields']['time_from']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][803]['fields']['time_to']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][803]['fields']['status']=array('type'=>'varchar(32)') ; ;
   $_SESSION['descr_clss'][803]['fields']['pass_id']=array('type'=>'int(11)','index'=>'pass_id') ; ;
   $_SESSION['descr_clss'][803]['fields']['url_pdf_doc']=array('type'=>'varchar(256)') ; ;
   $_SESSION['descr_clss'][803]['fields']['comment']=array('type'=>'varchar(256)') ; ;


   $_SESSION['descr_clss'][807]['name']='Смена водителя' ;
   $_SESSION['descr_clss'][807]['parent']=0 ;
   $_SESSION['descr_clss'][807]['fields']['route_id']=array('type'=>'int(11)','index'=>'route_id') ; ;
   $_SESSION['descr_clss'][807]['fields']['task_id']=array('type'=>'int(11)','index'=>'task_id') ; ;
   $_SESSION['descr_clss'][807]['fields']['request_id']=array('type'=>'int(11)','index'=>'request_id') ; ;
   $_SESSION['descr_clss'][807]['fields']['pass_id']=array('type'=>'int(11)','index'=>'pass_id') ; ;
   $_SESSION['descr_clss'][807]['fields']['pass_type']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][807]['fields']['pass_name']=array('type'=>'varchar(128)') ; ;
   $_SESSION['descr_clss'][807]['fields']['person_id']=array('type'=>'int(11)','index'=>'person_id') ; ;
   $_SESSION['descr_clss'][807]['fields']['car_id']=array('type'=>'int(11)','index'=>'car_id') ; ;
   $_SESSION['descr_clss'][807]['fields']['skd_person_id']=array('type'=>'int(11)','index'=>'skd_person_id') ; ;  // ID водителя в ЭСМО СКУД - попадает из пропуска
   $_SESSION['descr_clss'][807]['fields']['skd_car_id']=array('type'=>'int(11)','index'=>'skd_car_id') ; ;     // ID водителя в ЭСМО СКУД - попадает из пропуска
   $_SESSION['descr_clss'][807]['fields']['person_name']=array('type'=>'varchar(128)') ; ;
   $_SESSION['descr_clss'][807]['fields']['car_name']=array('type'=>'varchar(32)') ; ;
   $_SESSION['descr_clss'][807]['fields']['status']=array('type'=>'int(11)','default'=>1,'index'=>'status') ; ;
   $_SESSION['descr_clss'][807]['fields']['trip_count']=array('type'=>'int(11)','default'=>0) ; // число рейсов в смене
   $_SESSION['descr_clss'][807]['fields']['wt']=array('type'=>'float(10,2)','default'=>0) ; // вес нетто, перевезенный за смену
   $_SESSION['descr_clss'][807]['fields']['wn']=array('type'=>'float(10,2)','default'=>0) ; // вес нетто, перевезенный за смену
   $_SESSION['descr_clss'][807]['fields']['t_start']=array('type'=>'int(11)') ; // начало смены
   $_SESSION['descr_clss'][807]['fields']['t_end']=array('type'=>'int(11)') ; // окончание смены

   $_SESSION['descr_clss'][804]['name']='Рейс водителя' ;
   $_SESSION['descr_clss'][804]['parent']=0 ;
   //$_SESSION['descr_clss'][804]['fields']['task_id']=array('type'=>'int(11)') ; ;
   //$_SESSION['descr_clss'][804]['fields']['request_id']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][804]['fields']['smena_id']=array('type'=>'int(11)','index'=>'smena_id') ; ;
   //$_SESSION['descr_clss'][804]['fields']['route_id']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][804]['fields']['t_start']=array('type'=>'int(11)') ; ;
   $_SESSION['descr_clss'][804]['fields']['t_end']=array('type'=>'int(11)') ; ;
   //$_SESSION['descr_clss'][804]['fields']['person_id']=array('type'=>'int(11)') ; ;
   //$_SESSION['descr_clss'][804]['fields']['car_id']=array('type'=>'int(11)') ; ;
   //$_SESSION['descr_clss'][804]['fields']['skd_person_id']=array('type'=>'int(11)') ; ;  // ID водителя в ЭСМО СКУД - попадает из пропуска
   //$_SESSION['descr_clss'][804]['fields']['skd_car_id']=array('type'=>'int(11)') ; ;     // ID водителя в ЭСМО СКУД - попадает из пропуска
   //$_SESSION['descr_clss'][804]['fields']['person_name']=array('type'=>'varchar(128)') ; ;
   //$_SESSION['descr_clss'][804]['fields']['car_name']=array('type'=>'varchar(32)') ; ;
   $_SESSION['descr_clss'][804]['fields']['status']=array('type'=>'int(11)','default'=>1,'index'=>'status') ; ;
   $_SESSION['descr_clss'][804]['fields']['num']=array('type'=>'int(11)','default'=>0) ; // номер ходки за смену
   //$_SESSION['descr_clss'][804]['fields']['w']=array('type'=>'float(10,2)','default'=>0) ;
   //$_SESSION['descr_clss'][804]['fields']['wp']=array('type'=>'int(11)','default'=>0) ; //
   $_SESSION['descr_clss'][804]['fields']['wt']=array('type'=>'float(10,2)','default'=>0) ; // вес тары
   $_SESSION['descr_clss'][804]['fields']['wb']=array('type'=>'float(10,2)','default'=>0) ; // вес брутто
   $_SESSION['descr_clss'][804]['fields']['wn']=array('type'=>'float(10,2)','default'=>0) ; // вес нетто
   $_SESSION['descr_clss'][804]['fields']['confirmed']=array('type'=>'int(1)','default'=>0) ; // подтверждение операции
   $_SESSION['descr_clss'][804]['fields']['confirmed_account_id']=array('type'=>'int(11)','default'=>0) ; // подтверждение операции
   $_SESSION['descr_clss'][804]['fields']['confirmed_time']=array('type'=>'int(11)','default'=>0) ; // подтверждение операции

   $_SESSION['descr_clss'][805]['name']='Точка рейса' ;
   $_SESSION['descr_clss'][805]['parent']=0 ;
   $_SESSION['descr_clss'][805]['fields']['zone_id']=array('type'=>'int(11)','index'=>'zone_id') ; ;
   $_SESSION['descr_clss'][805]['fields']['point_id']=array('type'=>'int(11)','index'=>'point_id') ; ;
   $_SESSION['descr_clss'][805]['fields']['point_pkey']=array('type'=>'int(11)','index'=>'point_pkey') ; ;
   $_SESSION['descr_clss'][805]['fields']['weight']=array('type'=>'float(10,2)') ; ;
   $_SESSION['descr_clss'][805]['fields']['wt']=array('type'=>'int(11)','default'=>0) ; // вес тары
   $_SESSION['descr_clss'][805]['fields']['wb']=array('type'=>'int(11)','default'=>0) ; // вес брутто
   $_SESSION['descr_clss'][805]['fields']['wn']=array('type'=>'int(11)','default'=>0) ; // вес нетто
   $_SESSION['descr_clss'][805]['fields']['comment']=array('type'=>'varchar(255)') ; 
   $_SESSION['descr_clss'][805]['fields']['message_id']=array('type'=>'varchar(40)','default'=>'') ;
   $_SESSION['descr_clss'][805]['fields']['session_uid']=array('type'=>'varchar(40)','default'=>'') ;


	$_SESSION['descr_clss'][808]['name']='Водитель' ;
	$_SESSION['descr_clss'][808]['parent']=0 ;
	$_SESSION['descr_clss'][808]['fields']['name']=array('type'=>'varchar(128)') ; ;
	$_SESSION['descr_clss'][808]['fields']['dr']=array('type'=>'varchar(12)') ; ;
	$_SESSION['descr_clss'][808]['fields']['company']=array('type'=>'varchar(128)') ; ;
	$_SESSION['descr_clss'][808]['fields']['department']=array('type'=>'varchar(128)') ; ;
	$_SESSION['descr_clss'][808]['fields']['workers']=array('type'=>'varchar(128)') ; ;
	$_SESSION['descr_clss'][808]['fields']['uid_1c']=array('type'=>'varchar(64)') ; ;
	$_SESSION['descr_clss'][808]['fields']['skd_id']=array('type'=>'int(11)','default'=>0,'index'=>'skd_id') ; ;
	$_SESSION['descr_clss'][808]['fields']['pol']=array('type'=>'int(11)') ; ;


	$_SESSION['descr_clss'][511]['name']='Посетитель' ;
	$_SESSION['descr_clss'][511]['parent']=0 ;
	$_SESSION['descr_clss'][511]['fields']['name1']='varchar(255)' ; // id пользователя создавшего заявку
	$_SESSION['descr_clss'][511]['fields']['name2']='varchar(255)' ;
	$_SESSION['descr_clss'][511]['fields']['name3']='varchar(255)' ;
	$_SESSION['descr_clss'][511]['fields']['company']='varchar(255)' ;
	$_SESSION['descr_clss'][511]['fields']['department']='varchar(255)' ;
	$_SESSION['descr_clss'][511]['fields']['uid_1c']=array('type'=>'varchar(128)','index'=>'uid_1c') ;
	$_SESSION['descr_clss'][511]['fields']['uid']=array('type'=>'varchar(128)','index'=>'uid') ;
	$_SESSION['descr_clss'][511]['fields']['city']='varchar(255)' ;
	$_SESSION['descr_clss'][511]['fields']['working']='varchar(255)' ;
	$_SESSION['descr_clss'][511]['fields']['doc_type']=array('type'=>'indx_select','array'=>'ARR_doc_type') ;
	$_SESSION['descr_clss'][511]['fields']['doc_seria']=array('type'=>'varchar(10)','default'=>'') ;
	$_SESSION['descr_clss'][511]['fields']['doc_number']=array('type'=>'varchar(10)','default'=>'') ;
	$_SESSION['descr_clss'][511]['fields']['status']='int(11)' ;
	$_SESSION['descr_clss'][511]['fields']['black_list']=array('type'=>'int(1)','default'=>0) ;
	$_SESSION['descr_clss'][511]['fields']['phone']='varchar(10)' ;
	$_SESSION['descr_clss'][511]['fields']['email']='varchar(128)' ;
	$_SESSION['descr_clss'][511]['fields']['pol']=array('type'=>'indx_select','array'=>'ARR_pol','default'=>0) ;
	$_SESSION['descr_clss'][511]['fields']['dr']='varchar(10)' ;
	$_SESSION['descr_clss'][511]['fields']['age']='int(11)' ;
	$_SESSION['descr_clss'][511]['fields']['personal_id']='int(11)' ;
	//$_SESSION['descr_clss'][511]['fields']['_image_name']='varchar(255)' ;
	//$_SESSION['descr_clss'][511]['fields']['demo']='int(1)' ;
	//$_SESSION['descr_clss'][511]['fields']['ext_info']='serialize';
	//$_SESSION['descr_clss'][511]['fields']['inside']='int(1)' ;  // 1 - вошел, 0 - вышел
	//$_SESSION['descr_clss'][511]['fields']['tab_number']=array('type'=>'varchar(32)') ;

	$_SESSION['descr_clss'][511]['list']['field']['pkey']='ID' ;
	$_SESSION['descr_clss'][511]['list']['field']['obj_name']='Имя' ;
	$_SESSION['descr_clss'][511]['list']['field']['dr']='Дата рождения' ;
	$_SESSION['descr_clss'][511]['list']['field']['pol']='Пол' ;
	//$_SESSION['descr_clss'][511]['list']['field']['company']='Компания' ;
	$_SESSION['descr_clss'][511]['list']['field']['city']='Город' ;
	$_SESSION['descr_clss'][511]['list']['field']['working']='Должность' ;
	$_SESSION['descr_clss'][511]['list']['field']['doc_type']='Тип документа' ;
	$_SESSION['descr_clss'][511]['list']['field']['doc_seria']='Серия' ;
	$_SESSION['descr_clss'][511]['list']['field']['doc_number']='Номер' ;
	$_SESSION['descr_clss'][511]['list']['field']['demo']='DEMO' ;
	$_SESSION['descr_clss'][511]['no_show_in_tree']=1 ;

	$_SESSION['descr_clss'][506]['name']='Автомобиль' ;
	$_SESSION['descr_clss'][506]['parent']=0 ;
	$_SESSION['descr_clss'][506]['code']='cars' ;
	$_SESSION['descr_clss'][506]['fields']['obj_name']='varchar(10)' ;
	$_SESSION['descr_clss'][506]['fields']['model']=array('type'=>'varchar(32)','default'=>'') ;
	$_SESSION['descr_clss'][506]['fields']['type']=array('type'=>'int(11)','default'=>0) ;
	$_SESSION['descr_clss'][506]['fields']['owner_type']=array('type'=>'int(11)','default'=>0) ;
	$_SESSION['descr_clss'][506]['fields']['owner_id']=array('type'=>'int(11)','default'=>0) ;
	$_SESSION['descr_clss'][506]['fields']['owner_name']=array('type'=>'varchar(211)','default'=>'') ;
	$_SESSION['descr_clss'][506]['fields']['inside']=array('type'=>'int(1)','default'=>0) ;  // 1 - вошел, 0 - вышел
	$_SESSION['descr_clss'][506]['fields']['uid']=array('type'=>'varchar(128)','index'=>'uid') ;
	$_SESSION['descr_clss'][506]['fields']['uid_1c']=array('type'=>'varchar(128)','index'=>'uid_1c') ;
	$_SESSION['descr_clss'][506]['fields']['skd_id']=array('type'=>'int(11)','default'=>0,'index'=>'skd_id') ; ;


	$_SESSION['descr_clss'][507]['name']='Пакет Rabbit' ;
	$_SESSION['descr_clss'][507]['parent']=0 ;
	$_SESSION['descr_clss'][507]['code']='rabbit' ;
	$_SESSION['descr_clss'][507]['fields']['obj_name']='varchar(10)' ;
	$_SESSION['descr_clss'][507]['fields']['content']='text' ;
	$_SESSION['descr_clss'][507]['fields']['type']=array('type'=>'varchar(32)','default'=>'') ;
	$_SESSION['descr_clss'][507]['fields']['message_id']=array('type'=>'varchar(40)','default'=>'') ;
	$_SESSION['descr_clss'][507]['fields']['direct']=array('type'=>'int(11)','default'=>0) ;
	$_SESSION['descr_clss'][507]['fields']['status']=array('type'=>'int(11)','default'=>0) ;
	$_SESSION['descr_clss'][507]['fields']['uid']=array('type'=>'varchar(64)') ;
	$_SESSION['descr_clss'][507]['fields']['trip_id']=array('type'=>'int(11)') ;
	$_SESSION['descr_clss'][507]['fields']['point_id']=array('type'=>'int(11)') ;

	$_SESSION['descr_clss'][508]['name']='Запрос на взвешивание' ;
	$_SESSION['descr_clss'][508]['parent']=0 ;
	$_SESSION['descr_clss'][508]['code']='weight_req' ;
	$_SESSION['descr_clss'][508]['fields']['id_request']='int(11)' ;
	$_SESSION['descr_clss'][508]['fields']['id_trip']='int(11)' ;
	$_SESSION['descr_clss'][508]['fields']['driver_name']=array('type'=>'varchar(64)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['driver_org']=array('type'=>'varchar(64)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['driver_work']=array('type'=>'varchar(64)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['car_number']=array('type'=>'varchar(32)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['car_model']=array('type'=>'varchar(32)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['car_owner']=array('type'=>'varchar(64)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['cargo_type']=array('type'=>'varchar(32)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['doc_num']=array('type'=>'varchar(32)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['path_from']=array('type'=>'varchar(32)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['path_to']=array('type'=>'varchar(32)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['device_ip']=array('type'=>'varchar(32)','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['response_status']=array('type'=>'int(11)','default'=>0) ;
	$_SESSION['descr_clss'][508]['fields']['rec_pass']=array('type'=>'text','default'=>'') ;
	$_SESSION['descr_clss'][508]['fields']['pass_id']=array('type'=>'int(11)','default'=>0,'index'=>'pass_id') ;
	$_SESSION['descr_clss'][508]['fields']['pass_PDP']=array('type'=>'text','default'=>'') ;
	$_SESSION['descr_clss'][508]['index']['AAAA']='driver_name,driver_org,driver_work,car_number';


	$_SESSION['descr_clss'][509]['name']='Ход взвешивания' ;
	$_SESSION['descr_clss'][509]['parent']=0 ;
	$_SESSION['descr_clss'][509]['fields']['ip']='varchar(32)' ;
	$_SESSION['descr_clss'][509]['fields']['status']='int(11)' ;
	$_SESSION['descr_clss'][509]['fields']['point_id']=array('type'=>'int(11)','default'=>0,'index'=>'point_id') ;
	$_SESSION['descr_clss'][509]['fields']['weight']='int(11)' ;
	$_SESSION['descr_clss'][509]['fields']['motion']='int(11)' ;
	$_SESSION['descr_clss'][509]['fields']['time_exec']='float(10,5)' ;






}

function _esmo_ruda_admin_boot($options)
{
  create_system_modul_obj('esmo_ruda',$options) ;
}


function _esmo_ruda_install_modul($DOT_root)
{
	//check_exists_dir('/storage/esmo_ruda') ;

	SETUP()->reg_event_lister('rabbit_packet_received','esmo_ruda','on_event_rabbit_packet_received') ;         //

	SETUP()->reg_cron('запрос rabbit','esmo_ruda/rabbit_kanal_read','*/1 * * * *',array('enabled'=>1)) ;
	SETUP()->reg_cron('Проверка статуса смен','esmo_ruda/check_smena_time','*/1 * * * *',array('enabled'=>1)) ;
	SETUP()->reg_cron('Проверка выполнения задач','esmo_ruda/send_notife_email_check_task','*/1 * * * *',array('enabled'=>0)) ;

	SETUP()->reg_report('Руда - отчеты','esmo_ruda/report_rabbit_time.php') ;         //
	
	$id_sect=SETUP_add_section_to_site_setting('ЭСМО Руда') ;
	SETUP_add_rec_to_site_setting($id_sect,"Порог выполнения задачи для отправки уведомоения:",80,'LS_esmo_ruda_task_check_value',array('el'=>'input')) ;
	SETUP_add_rec_to_site_setting($id_sect,"email для отправки уведомлений о завершении задачи:","",'LS_esmo_ruda_task_check_email',array('el'=>'input')) ;

	

	$pattern=array() ;
    $pattern['table_title']		        = 	'Автомобили' ;
    $pattern['use_clss']		        = 	'506' ;
    $pattern['table_name']				= 	'obj_site_cars' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;

	$pattern=array() ;
    $pattern['table_title']		        = 	'Маршруты ЭСМО Руда' ;
    $pattern['use_clss']		        = 	'800' ;
    $pattern['table_name']				= 	'car_routers' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    $id_root=create_table_by_pattern($pattern) ;
	                                                   
	$pattern=array() ;
    $pattern['table_title']		        = 	'Точки маршрутов ЭСМО Руда' ;
    $pattern['use_clss']		        = 	'801' ;
    $pattern['table_name']				= 	'car_routers_points' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$id_root;
    create_table_by_pattern($pattern) ;

	$pattern=array() ;
    $pattern['table_title']		        = 	'Заявки на перевозку руды' ;
    $pattern['use_clss']		        = 	'802' ;
    $pattern['table_name']				= 	'ruda_request' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
	$id_root=create_table_by_pattern($pattern) ;

	$pattern=array() ;
	$pattern['table_title']		        = 	'Задачи на перевозку руды' ;
	$pattern['use_clss']		        = 	'806' ;
	$pattern['table_name']				= 	'ruda_task' ;
	$pattern['table_clss']				= 	101 ;
	$pattern['table_parent']			= 	$id_root;
	create_table_by_pattern($pattern) ;


	$pattern=array() ;
    $pattern['table_title']		        = 	'Заявки на перевозку руды - позиции' ;
    $pattern['use_clss']		        = 	'803' ;
    $pattern['table_name']				= 	'ruda_request_recs' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$id_root;
    create_table_by_pattern($pattern) ;

    $pattern=array() ;
    $pattern['table_title']		        = 	'Смены' ;
    $pattern['use_clss']		        = 	'807' ;
    $pattern['table_name']				= 	'car_smena' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
	$id_root=create_table_by_pattern($pattern) ;

    $pattern=array() ;
    $pattern['table_title']		        = 	'Рейсы' ;
    $pattern['use_clss']		        = 	'804' ;
    $pattern['table_name']				= 	'car_trip' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
	$id_root=create_table_by_pattern($pattern) ;

    $pattern=array() ;
    $pattern['table_title']		        = 	'Поездки - позиции' ;
    $pattern['use_clss']		        = 	'805' ;
    $pattern['table_name']				= 	'car_trip_recs' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$id_root;
    create_table_by_pattern($pattern) ;

    $pattern=array() ;
    $pattern['table_title']		        = 	'Водители' ;
    $pattern['use_clss']		        = 	'808' ;
    $pattern['table_name']				= 	'drivers' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;

    $pattern=array() ;
    $pattern['table_title']		        = 	'Пакеты Rabbit' ;
    $pattern['use_clss']		        = 	'507' ;
    $pattern['table_name']				= 	'log_rabbit' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;

    $pattern=array() ;
    $pattern['table_title']		        = 	'Ход взвешивания' ;
    $pattern['use_clss']		        = 	'509' ;
    $pattern['table_name']				= 	'data_weighing' ;
    $pattern['table_clss']				= 	101 ;
    $pattern['table_parent']			= 	$DOT_root;
    create_table_by_pattern($pattern) ;


    $sql='create view view_ruda_request_line as 
		    select t1.*,
		    t1.request_uid as request_id,
		    t3.route_id,t3.invoice_id,t3.task_uid,t3.header_id, 
		    t4.from_zone_id as route_from_zone_id,t4.to_zone_id as route_to_zone_id,t4.obj_name as route_name,
		    t5.obj_name as driver_name,t5.skd_id as driver_skd_id,
            t6.obj_name as car_number,t6.skd_id as car_skd_id,
            t7.pkey as smena_id,t7.status as smena_status,t7.trip_count as smena_trip_count,t7.wn as smena_wn,t7.t_start as smena_start
			from ruda_request_recs t1
			left join ruda_task t3 on t3.pkey=t1.task_id 
			left join car_routers t4 on t4.pkey=t3.route_id 
            left join drivers t5 on t5.pkey=t1.person_id
            left join obj_site_cars t6 on t6.pkey=t1.car_id			
            left join car_smena t7 on t7.request_id=t1.parent and t7.pass_id=t1.pass_id			
		  ' ;

	 create_viewer('view_ruda_request_line',$sql) ;

	  $sql='create view view_ruda_request as 
		    select t1.*,
		    t2.route_id,t2.invoice_id,t2.task_uid, 
		    t3.from_zone_id as route_from_zone_id,t3.to_zone_id as route_to_zone_id,t3.obj_name as route_name
			from ruda_request t1
			left join ruda_task t2 on t2.pkey=t1.task_id 
			left join car_routers t3 on t3.pkey=t2.route_id 
			
		  ' ;

	 create_viewer('view_ruda_request',$sql) ;

	  $sql='create view view_car_trip as 
		    select t1.*,
		    ts.status as smena_status,ts.person_id,ts.car_id,ts.skd_person_id,ts.skd_car_id,ts.person_name,ts.car_name,ts.route_id,ts.task_id,ts.request_id,
		    ts.pass_id,ts.pass_name,ts.pass_type,
		    t_pers.uid_1c as person_uid,
		    t_car.uid_1c as car_uid,
		    t4.pkey as request_line_pkey,t4.line_id as request_line,t4.request_uid, 
		    t6.task_uid,t6.invoice_id,t6.header_id as task_header_id,t6.line_id as task_line_id  
		    from car_trip t1
		    left join car_smena ts on ts.pkey=t1.smena_id
			left join drivers t_pers on t_pers.pkey=ts.person_id 
			left join obj_site_cars t_car on t_car.pkey=ts.car_id 
			left join ruda_request_recs t4 on t4.pass_id=ts.pass_id 
			left join ruda_task t6 on t6.pkey=ts.task_id 
			 
		  ' ;

	 create_viewer('view_car_trip',$sql) ;

	  $sql='create view view_car_smena as 
		    select t1.*,
		    t2.uid_1c as person_uid,
		    t3.uid_1c as car_uid,
		    t4.pkey as request_line_pkey,t4.request_uid, 
		    t6.task_uid,t6.invoice_id,t6.header_id as task_header_id,t6.line_id as task_line_id,
		    t7.obj_name as route_name 
		    from car_smena t1
			left join drivers t2 on t2.skd_id=t1.skd_person_id 
			left join obj_site_cars t3 on t3.skd_id=t1.skd_car_id 
			left join ruda_request_recs t4 on t4.pass_id=t1.pass_id 
			left join ruda_task t6 on t6.pkey=t1.task_id 
			left join car_routers t7 on t7.pkey=t1.route_id
			 
		  ' ;

	 create_viewer('view_car_smena',$sql) ;

	  $sql='create view view_task as 
		    select t1.*,
		    t2.obj_name as route_name 
		    from ruda_task t1
			left join car_routers t2 on t2.pkey=t1.route_id
		  ' ;

	 create_viewer('view_task',$sql) ;


}




?>