Cp1251
DOC
document_title="Кросс-таблица"
orientation = landscape
preloadscript = "
(global.rowcount = 3000)
(global.d1 = '\''+'01.01.2008'+'\'')
(global.load = 0)
(global.name_of_models = '')
(global.id_auto = 0)
"
postloadscript = "
(global.load = 1)
"
// документов больше текушей даты?
{datastore  alias=dial_more_doc
    query="select head.id_head
             from head,head_auto
            where head.id_head = head_auto.id_head
	      and head.accept = 1
	      and head.id_head <> ~($try ($g.GRIDDS2@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS2@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd >= '~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_SD') )@toPLString) $catch ('Any')(global.d1))~'
		 "
} // end of ds
// автомобиль уже в автопарке?
{datastore  alias=dial_vv
    query="select head.id_head
	     from head
	    where head.id_type_doc = 71
	      and head.sort =
	   (select max(head.sort)
             from head,head_auto
            where head.id_head = head_auto.id_head
	      and head.accept = 1
	      and head.id_type_doc in (71,72)
	      and head.id_head <> ~($try ($g.GRIDDS2@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS2@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd <= '~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_SD') )@toPLString) $catch ('Any')(global.d1))~'
	   ) "
} // end of ds
// автомобиль введен в автопарк?
{datastore  alias=dial1
    query="select head.id_head
             from head,head_auto
            where head.id_head = head_auto.id_head
	      and head.accept = 1
	      and head.id_head <> ~($try ($g.GRIDDS2@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS2@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd <= '~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_SD') )@toPLString) $catch ('Any')(global.d1))~'
		 "
} // end of ds
// автомобиль выведен из автопарк?
{datastore  alias=dial2
    query="select head.id_head
	     from head
	    where head.id_type_doc = 72
	      and head.sort =
	   (select max(head.sort)
             from head,head_auto
            where head.id_head = head_auto.id_head
	      and head.accept = 1
	      and head.id_type_doc in (71,72)
	      and head.id_head <> ~($try ($g.GRIDDS2@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS2@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd <= '~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_SD') )@toPLString) $catch ('Any')(global.d1))~'
	   ) "
} // end of ds
// автомобиль забронирован?
{datastore  alias=dial3
    query="select head.id_head
             from head,head_auto
            where head.id_head = head_auto.id_head
	      and head.accept = 1
	      and head.id_type_doc = 74
	      and head.id_head <> ~($try ($g.GRIDDS2@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS2@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd  <='~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_END_SD') )@toPLString) $catch ('Any')(global.d1))~'
	      and head_auto.date_end_sd >='~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_SD') )@toPLString) $catch ('Any')(global.d1))~'
	    "
} // end of ds 
// автомобиль сдан в аренду?
{datastore  alias=dial4
    query="select head.id_head
             from head,head_auto
            where head.id_head = head_auto.id_head
	      and head.accept = 1
	      and head.id_type_doc = 75
	      and head.id_head <> ~($try ($g.GRIDDS2@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS2@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd  <='~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_END_SD') )@toPLString) $catch ('Any')(global.d1))~'
	      and head_auto.date_end_sd >='~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_SD') )@toPLString) $catch ('Any')(global.d1))~'
	    "
} // end of ds
// автомобиль выставлен на продажу?
{datastore  alias=dial5
    query="select head.id_head
             from head,head_auto
            where head.id_head = head_auto.id_head
	      and head.accept = 1
	      and head.id_type_doc = 79
	      and head.id_head <> ~($try ($g.GRIDDS2@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS2@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd <= '~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_END_SD') )@toPLString) $catch ('Any')(global.d1))~'
	    "
} // end of ds
// автомобиль в ремонте?
{datastore  alias=dial6
    query="select head.id_head
             from head,head_auto
            where head.id_head = head_auto.id_head
	      and head.accept = 1
	      and head.id_type_doc = 76
	      and head.id_head <> ~($try ($g.GRIDDS2@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS2@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd  <='~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_END_SD') )@toPLString) $catch ('Any')(global.d1))~'
	      and head_auto.date_end_sd >='~($try ($($@date ($g.GRIDDS2@GetValue 'DATE_SD') )@toPLString) $catch ('Any')(global.d1))~'
	    "
} // end of ds
{toolbar   BACKGROUND = "LIGHTGRAY"
{tabset
 labels = "Параметры, Кросс-таблица, История событий по автомобилю"
{form width = 300 height = 300 alias = pf
{label 
   left = 5  top = 10          width = 50         height = 20       font_size = 12
   value="Месяц"    bg_color="#c0c0c0"
}
{field 
   target = dat 
   left = 60   top = 10        width = 70        height=20 
   alias = paryear   font_size = 12    border = box
   dep="ficd1"
}
{field 
   type = number
   left = 80  width = 70 height=25    
   alias=ficd1           visible=no
   exp="(ficd1=0)
        (global.d1 = '\''+($($@date paryear)@toPLString)+'\'')"
}
     {label
         value="Модель"
         left=25    top=35    height=20       width=60
         font_size=12         font_family=0   bg_color="#c0c0c0"
     }
     {field
         type=string	  border = box
         left=165    top=35    height=20       width=230
         alias=name_of_models        font_size=12    font_family=0    bg_color="#ffffff"
         editable=yes
	     editexp="($X
		   (global.name_of_models='and upper(models_of_vehicle.name_of_models) like upper(\'%' + g.name_of_models + '%\')' )
		  ($ret ''))"
          dep="nv_name_of_models"
     }
     {field
         type=string	  border = box visible=no
         left=165    top=35    height=20       width=230
         alias=nv_name_of_models        font_size=12    font_family=0    bg_color="#ffffff"
         editable=yes
	     exp="($X
                     (global.name_of_models='and upper(models_of_vehicle.name_of_models) like upper(\'%' + g.name_of_models + '%\')' )
                  ($ret ''))"
     }
{button
  left = 450  top = 35   width = 100    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Очистить"
  action = "($X
		(g.name_of_models='')
		(global.name_of_models='')
  	    ($ret ''))"
}
     {label
         value="Класс"
         left=25    top=60    height=20       width=60
         font_size=12         font_family=0   bg_color="#c0c0c0"
     }
     {field
         type=number  border = box visible=no
         left=155    top=60    height=20       width=300
         alias=type_auto        font_size=12    font_family=0    bg_color="#ffffff"
         editable=no                    value="-1"
         editexp="($X
		    (g.type_auto=STORE.class_auto.type_auto)
		  ($ret ''))"
     }
     {field
         type=string	  border = box
         left=95    top=60    height=20       width=150
         alias=name_type_class        font_size=12    font_family=0    bg_color="#ffffff"
         editable=handbook
         edit="opennew util/sprav/class_auto_choose.rml"
         editexp="name_type_class=STORE.class_auto.name_type_class"
         dep="type_auto"
     }
{button
  left = 450  top = 60   width = 100    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Очистить"
  action = "($X
		(g.type_auto=-1)
		(g.name_type_class='')
  	    ($ret ''))"
}
     {label
         value="Тип кузова"
         left=25    top=85    height=20       width=60
         font_size=12         font_family=0   bg_color="#c0c0c0"
     }
     {field
         type=number  border = box visible=no
         left=155    top=85    height=20       width=300
         alias=id_type_vagon        font_size=12    font_family=0    bg_color="#ffffff"
	 editable=no                                value="-1"
         editexp="($X
		    (g.id_type_vagon=STORE.type_vagon.id_type_vagon)
		  ($ret ''))"
     }
     {field
         type=string	  border = box
         left=95    top=85    height=20       width=150
         alias=name_type_vagon        font_size=12    font_family=0    bg_color="#ffffff"
	 editable=handbook
         edit="opennew util/sprav/type_vagon_choose.rml"
         editexp="name_type_vagon=STORE.type_vagon.name_type_vagon"
         dep="id_type_vagon"
     }
{button
  left = 450  top = 85   width = 100    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Очистить"
  action = "($X
		(g.id_type_vagon=-1)
		(g.name_type_vagon='')
  	    ($ret ''))"
}
     {label
         value="Тип трансмиссии"
         left=25    top=110    height=20       width=120
         font_size=12         font_family=0   bg_color="#c0c0c0"
     }
     {field
         type=number  border = box visible=no
         left=155    top=110    height=20       width=300
         alias=id_type_transmission        font_size=12    font_family=0    bg_color="#ffffff"
         editable=no			   value="-1"
         editexp="($X
		    (g.id_type_transmission=STORE.type_transmission.id_type_transmission)
		  ($ret ''))"
     }
     {field
         type=string	  border = box
         left=155    top=110    height=20       width=250
         alias=name_transmission        font_size=12    font_family=0    bg_color="#ffffff"
         editable=handbook
         edit="opennew util/sprav/type_transmission_choose.rml"
         editexp="name_transmission=STORE.type_transmission.name_transmission"
         dep="id_type_transmission"
     }
{button
  left = 450  top = 110   width = 100    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Очистить"
  action = "($X
		(g.id_type_transmission=-1)
		(g.name_transmission='')
  	    ($ret ''))"
}
     {label
         value="Тип климатконтроля"
         left=25    top=135    height=20       width=120
         font_size=12         font_family=0   bg_color="#c0c0c0"
     }
     {field
         type=number	  border = box 	visible=no
         left=155    top=155    height=20       width=300
         alias=id_type_climat        font_size=12    font_family=0    bg_color="#ffffff"
         editable=no			value="-1"
         editexp="($X
		   (g.id_type_climat=STORE.type_climat.id_type_climat)
		  ($ret ''))"
     }
     {field
         type=string	  border = box
         left=155    top=135    height=20       width=150
         alias=name_type_climat        font_size=12    font_family=0    bg_color="#ffffff"
         editable=handbook
         edit="opennew util/sprav/type_climat_choose.rml"
         editexp="name_type_climat=STORE.type_climat.name_type_climat"
         dep="id_type_climat"
     }
{button
  left = 450  top = 135   width = 100    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Очистить"
  action = "($X
		(g.id_type_climat=-1)
		(g.name_type_climat='')
  	    ($ret ''))"
}
     {label
         value="парк"
         left=25    top=160    height=20       width=120
         font_size=12         font_family=0   bg_color="#c0c0c0"
     }
     {field
         type=number	  border = box 	visible=no
         left=155    top=160    height=20       width=300
         alias=id_department        font_size=12    font_family=0    bg_color="#ffffff"
         editable=no			value="-1"
         editexp="($X
		   (g.id_department=STORE.department.id_department)
		  ($ret ''))"
     }
     {field
         type=string	  border = box
         left=155    top=160    height=20       width=150
         alias=name1_dep        font_size=12    font_family=0    bg_color="#ffffff"
         editable=handbook
	 edit="opennew department_gr.rml "
         editexp="name1_dep=STORE.department.name1_dep"
         dep="id_department"
     }
{button
  left = 450  top = 160   width = 100    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Очистить"
  action = "($X
		(g.id_department=-1)
		(g.name1_dep='')
  	    ($ret ''))"
}
{datastore
     alias = ddd
     query = "select dat
                from (select to_date(sysdate,'dd.mm,yyyy') dat
                        from dual   )"
}
} // end of form
{Grid 
  alias=GRID1
  buttonbar_font_family = 0              buttonbar_font_size = 12
  buttonbar_size = 30                    titlebar_size = 18
  editable = no
  rowsize = 20
  left = 95    // rowsize = 12    
  drawgrid = 7
   {menu
    {item label = "Обновить" action = "~($X
		        ($G.GRID1@retrieve)
			($ret ''))~"}
    {item label = "-"}
    {menu label = "Добавить событие" 
          {item label = "Бронирование авто" 
	        action = "~($X
	 	 	   (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
	                   ($g.self@doaction 'create util/docs/for_rent.rml -1 , '+(global.id_auto) )
			  ($RET ''))~ "}
          {item label = "Перегон авто" 
	        action = "~($X
	 	 	   (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
	                   ($g.self@doaction 'create util/docs/peregon.rml -1 , '+(global.id_auto) )
			  ($RET ''))~ "}
          {item label = "Сдача в аренду авто" 
	        action = "~($X
	 	 	   (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
	                   ($g.self@doaction 'create util/docs/into_rent.rml -1 , '+(global.id_auto) )
			  ($RET ''))~ "}
          {item label = "Ремонт авто" 
	        action = "~($X
	 	 	   (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
	                   ($g.self@doaction 'create util/docs/repaire.rml -1 , '+(global.id_auto) )
			  ($RET ''))~ "}
          {item label = "Выставление на продажу" 
	        action = "~($X
	 	 	   (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
	                   ($g.self@doaction 'create util/docs/sale_auto.rml -1 , '+(global.id_auto) )
			  ($RET ''))~ "}
          {item label = "Вывод из автопарка" 
	        action = "~($X
	 	 	   (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
	                   ($g.self@doaction 'create util/docs/vivod_iz_ap.rml -1 , '+(global.id_auto) )
			  ($RET ''))~ "}
          {item label = "Ввод в автопарк" 
	        action = "~($X
	 	 	   (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
	                   ($g.self@doaction 'create util/docs/vvod_v_ap.rml -1 , '+(global.id_auto) )
			  ($RET ''))~ "}
    }
   }
  {column size=50        target=id_automobile           title="id"
   halignment=center      font_color="#0000ff"   font_size = 10     
     alias = id             visible=no
  }
  {column size=87        target=name_of_models           title="Название"
   title_font_family=2     title_font_color="#000000"
   halignment=left            font_color="#000000"     
   font_size = 10             font_family=0
   alias = name
  }
  {column size=35        target=sumtype           title="Тип"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = sumtype
  }
  {column size=56        target=number_body           title="Гос.Ном"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = number_body
  }
 {column size=33         target=d01           title="01"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 9             font_family=0
   alias = d01
  }
 {column size=33         target=d02           title="02"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 9             font_family=0
   alias = d02
  }
 {column size=33         target=d03           title="03"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d03
  }
 {column size=33         target=d04           title="04"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d04
  }
 {column size=33         target=d05           title="05"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d05
  }
 {column size=33         target=d06           title="06"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d06
  }
 {column size=33         target=d07           title="07"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d07
  }
 {column size=33         target=d08           title="08"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d08
  }
 {column size=34         target=d09           title="09"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d09
  }
 {column size=34         target=d10           title="10"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d10
  }
 {column size=34         target=d11           title="11"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d11
  }
 {column size=34         target=d12           title="12"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d12
  }
 {column size=34         target=d13           title="13"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d13
  }
 {column size=34         target=d14           title="14"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d14
  }
 {column size=34         target=d15           title="15"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d15
  }
 {column size=34         target=d16           title="16"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d16
  }
 {column size=34         target=d17           title="17"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d17
  }
 {column size=34         target=d18           title="18"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d18
  }
 {column size=34         target=d19           title="19"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d19
  }
 {column size=34         target=d20           title="20"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d20
  }
 {column size=34         target=d21           title="21"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d21
  }
 {column size=34         target=d22           title="22"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d22
  }
 {column size=34         target=d23           title="23"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d23
  }
 {column size=34         target=d24           title="24"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d24
  }
 {column size=34         target=d25           title="25"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d25
  }
 {column size=34         target=d26           title="26"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d26
  }
 {column size=34         target=d27           title="27"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d27
  }
 {column size=34         target=d28           title="28"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d28
  }
 {column size=34         target=d29           title="29"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d29
  }
 {column size=34         target=d30           title="30"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d30
  }
 {column size=34         target=d31           title="31"
   title_font_family=2     title_font_color="#000000"
   halignment=center            font_color="#000000"     
   font_size = 10             font_family=0
   alias = d31
  }
 {datastore 
      alias = GRIDDS1
query="SELECT --count(*)
id_automobile,name_of_models,number_body, sumtype,
d01,
d02,
d03,
d04,
d05,
d06,
d07,
d08,
d09,
d10,
d11,
d12,
d13,
d14,
d15,
d16,
d17,
d18,
d19,
d20,
d21,
d22,
d23,
d24,
d25,
d26,
d27,
d28,
d29,
d30,
d31
from (SELECT id_automobile,name_of_models,number_body, sumtype,
    util.get_typ_ch_event(dd01)  d01,
    util.get_typ_ch_event(dd02)  d02,
    util.get_typ_ch_event(dd03)  d03,
    util.get_typ_ch_event(dd04)  d04,
    util.get_typ_ch_event(dd05)  d05,
    util.get_typ_ch_event(dd06)  d06,
    util.get_typ_ch_event(dd07)  d07,
    util.get_typ_ch_event(dd08)  d08,
    util.get_typ_ch_event(dd09)  d09,
    util.get_typ_ch_event(dd10)  d10,
    util.get_typ_ch_event(dd11)  d11,
    util.get_typ_ch_event(dd12)  d12,
    util.get_typ_ch_event(dd13)  d13,
    util.get_typ_ch_event(dd14)  d14,
    util.get_typ_ch_event(dd15)  d15,
    util.get_typ_ch_event(dd16)  d16,
    util.get_typ_ch_event(dd17)  d17,
    util.get_typ_ch_event(dd18)  d18,
    util.get_typ_ch_event(dd19)  d19,
    util.get_typ_ch_event(dd20)  d20,
    util.get_typ_ch_event(dd21)  d21,
    util.get_typ_ch_event(dd22)  d22,
    util.get_typ_ch_event(dd23)  d23,
    util.get_typ_ch_event(dd24)  d24,
    util.get_typ_ch_event(dd25)  d25,
    util.get_typ_ch_event(dd26)  d26,
    util.get_typ_ch_event(dd27)  d27,
    util.get_typ_ch_event(dd28)  d28,
    util.get_typ_ch_event(dd29)  d29,
    util.get_typ_ch_event(dd30)  d30,
    util.get_typ_ch_event(dd31)  d31
from (SELECT id_automobile,name_of_models,ddat,number_body, sumtype,
max(DECODE(SUBSTR(ddat,1,2),'01',PRIZ,'0#')) dd01,
max(DECODE(SUBSTR(ddat,1,2),'02',PRIZ,'0#')) dd02,
max(DECODE(SUBSTR(ddat,1,2),'03',PRIZ,'0#')) dd03,
max(DECODE(SUBSTR(ddat,1,2),'04',PRIZ,'0#')) dd04,
max(DECODE(SUBSTR(ddat,1,2),'05',PRIZ,'0#')) dd05,
max(DECODE(SUBSTR(ddat,1,2),'06',PRIZ,'0#')) dd06,
max(DECODE(SUBSTR(ddat,1,2),'07',PRIZ,'0#')) dd07,
max(DECODE(SUBSTR(ddat,1,2),'08',PRIZ,'0#')) dd08,
max(DECODE(SUBSTR(ddat,1,2),'09',PRIZ,'0#')) dd09,
max(DECODE(SUBSTR(ddat,1,2),'10',PRIZ,'0#')) dd10,
max(DECODE(SUBSTR(ddat,1,2),'11',PRIZ,'0#')) dd11,
max(DECODE(SUBSTR(ddat,1,2),'12',PRIZ,'0#')) dd12,
max(DECODE(SUBSTR(ddat,1,2),'13',PRIZ,'0#')) dd13,
max(DECODE(SUBSTR(ddat,1,2),'14',PRIZ,'0#')) dd14,
max(DECODE(SUBSTR(ddat,1,2),'15',PRIZ,'0#')) dd15,
max(DECODE(SUBSTR(ddat,1,2),'16',PRIZ,'0#')) dd16,
max(DECODE(SUBSTR(ddat,1,2),'17',PRIZ,'0#')) dd17,
max(DECODE(SUBSTR(ddat,1,2),'18',PRIZ,'0#')) dd18,
max(DECODE(SUBSTR(ddat,1,2),'19',PRIZ,'0#')) dd19,
max(DECODE(SUBSTR(ddat,1,2),'20',PRIZ,'0#')) dd20,
max(DECODE(SUBSTR(ddat,1,2),'21',PRIZ,'0#')) dd21,
max(DECODE(SUBSTR(ddat,1,2),'22',PRIZ,'0#')) dd22,
max(DECODE(SUBSTR(ddat,1,2),'23',PRIZ,'0#')) dd23,
max(DECODE(SUBSTR(ddat,1,2),'24',PRIZ,'0#')) dd24,
max(DECODE(SUBSTR(ddat,1,2),'25',PRIZ,'0#')) dd25,
max(DECODE(SUBSTR(ddat,1,2),'26',PRIZ,'0#')) dd26,
max(DECODE(SUBSTR(ddat,1,2),'27',PRIZ,'0#')) dd27,
max(DECODE(SUBSTR(ddat,1,2),'28',PRIZ,'0#')) dd28,
max(DECODE(SUBSTR(ddat,1,2),'29',PRIZ,'0#')) dd29,
max(DECODE(SUBSTR(ddat,1,2),'30',PRIZ,'0#')) dd30,
max(DECODE(SUBSTR(ddat,1,2),'31',PRIZ,'0#')) dd31
FROM (select id_automobile,ddat,priz,name_of_models,number_body, sumtype
   from (
       select automobile.id_automobile,name_of_models,
              automobile.number_body, (class_auto.short_name_class || 
                                       type_vagon.short_name_type_vagon ||
                                       type_transmission.short_name_transmission ||
                                       type_climat.short_name_type_climat) sumtype,
              to_char(dd.ddat,'dd.mm.yyyy') ddat,
        --nvl(util.get_code_event(automobile.id_automobile,dd.ddat),'0#')  priz
        '0#' priz
   from automobile,models_of_vehicle,class_auto,type_vagon,type_transmission,type_climat,
(select aa.d+dd.x   ddat  
from (select
to_date(('01.'||to_char(to_date('01.09.2008','dd.mm.yyyy'),'mm.yyyy')),'dd.mm.yyyy') d,
add_months(to_date(('01.'||to_char(to_date('01.09.2008','dd.mm.yyyy'),'mm.yyyy')),'dd.mm.yyyy'),1)-1 d2
from dual) aa,
(select x from
(select 0 x from dual
union all
select 1  from dual
union all
select 2  from dual
union all
select 3  from dual
union all
select 4  from dual
union all
select 5  from dual
union all
select 6  from dual
union all
select 7  from dual
union all
select 8  from dual
union all
select 9  from dual
union all
select 10  from dual
union all
select 11  from dual
union all
select 12  from dual
union all
select 13  from dual
union all
select 14  from dual
union all
select 15  from dual
union all
select 16  from dual
union all
select 17  from dual
union all
select 18  from dual
union all
select 19  from dual
union all
select 20  from dual
union all
select 21  from dual
union all
select 22  from dual
union all
select 23  from dual
union all
select 24  from dual
union all
select 25  from dual
union all
select 26  from dual
union all
select 27  from dual
union all
select 28  from dual
union all
select 29  from dual
union all
select 30  from dual
union all
select 31  from dual
)) dd
where aa.d+dd.x <=aa.d2) dd

  where 
    automobile.id_models_of_vehicle = models_of_vehicle.id_models_of_vehicle
    --and automobile.type_auto = class_auto.type_auto
    --and automobile.id_type_vagon = type_vagon.id_type_vagon
    --and automobile.id_type_transmission = type_transmission.id_type_transmission
    --and automobile.id_type_climat = type_climat.id_type_climat
    --and util.get_work_auto(automobile.id_automobile,'01.09.2008') = 1
    and rownum <= ~global.rowcount~
             )
            )
     group by id_automobile,name_of_models,number_body,sumtype
))"
	 selaction = "retrieve GRID2"
          {datastore
          alias=set_row_ds
          query="select user from dual
                 ~($X
                    (t=($g.GRIDDS1@iterator))
                    (row=0) (f=0)
                    ($while ($t@next)(
                     ($if (global.id_auto != ($($t@value)@field 'ID_AUTOMOBILE'))
                       (row = row +1)
          	     $else ((f=1) ($break))
                     )             
                    ))
                    ($if (f==1)
                     ($if (($g.GRIDDS1@SIZE) !=0)
                      (
                       ($g.GRIDDS1@setCurRow row)
                       ($g.GRIDDS1@notifyviews)
                      )
                     )
                    )
                  ($ret ))~"
          editable=no
          }
 }
} // end of Report
{splitpanel type=gorizontal     percent=90
{Grid 
  alias=GRID2
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselect = yes                      editable = no
    rowsize = 20
    edit = "~($X
   	      (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
	      ($g.self@doaction 'open util/docs/'+($($G.GRID2@getDatastore)@getValue 'DOC_NAME' )+' '+($($G.GRID2@getDatastore)@getValue 'ID_HEAD' ) +'')
	     ($RET ''))~ ;retrieve GRID2"
   {menu
    {item label = "Обновить" action = "retrieve GRID2"}
    {item label = "Просмотреть" action = "~($X
	     	           (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
	                   ($g.self@doaction 'open util/docs/'+($($G.GRID2@getDatastore)@getValue 'DOC_NAME' )+' '+($($G.GRID2@getDatastore)@getValue 'ID_HEAD' ) +'')
			  ($RET ''))~ ;retrieve GRID2"}
        {item label = "-"}
        {item label = "Провести документ" action= "~($X
   	        (global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' ))
		($IF (($g.GRIDDS2@getValue 'ID_TYPE_DOC' ) == 71)  
	         (($debug 'g.dial_vv' )
                     ($g.dial_vv@retrieve)
                     ($IF (($G.dial_vv@size) != 0)
	              ((tmp = 'Автомобиль уже в автопарке на . Нельзя провести документ' + '')
            	       (m = ($g.self@sure tmp 1))
		      )
		      $else
	  	       ($g.self@doAction 'execute exec doc_lib.accept(to_number('  + ($g.GRIDDS2@getValue 'ID_HEAD' ) + ')) ')
		 ))
		    $else
 	             (($IF (($g.GRIDDS2@getValue 'ID_TYPE_DOC' ) == 72)  
	             (($debug 'g.dial2' )
                      ($g.dial2@retrieve)
                       ($IF (($G.dial2@size) != 0)
	                ((tmp = 'Автомобиль уже выведен из автопарка на . Нельзя провести документ' + '')
            	         (m = ($g.self@sure tmp 1))
		        )
			$else
	  	         ($g.self@doAction 'execute exec doc_lib.accept(to_number('  + ($g.GRIDDS2@getValue 'ID_HEAD' ) + ')) ')
		     ))
		      $else
 	              (
		($debug 'g.dial1' )
                       ($g.dial1@retrieve)
                       ($IF (($G.dial1@size) == 0)
	                ((tmp = 'Автомобиль не введен в автопарк на   . Нельзя провести документ' + '')
            	         (m = ($g.self@sure tmp 1))
			)
			$else
			 (
			  ($g.dial2@retrieve)
	($debug 'g.dial2' )
      			  ($IF (($G.dial2@size) != 0)
	                   ((tmp = 'Автомобиль выведен из автопарка на   .Нельзя провести документ' + '')
            	            (m = ($g.self@sure tmp 1))
			   )
			   $else
			    (
			     ($g.dial3@retrieve)
	($debug 'g.dial3' )
  			     ($IF (($G.dial3@size) != 0)
	                      ($IF (($g.GRIDDS2@getValue 'ID_TYPE_DOC' ) == 75) 
			       ((tmp = 'В этот период автомобиль забронирован. Провести документ?!' + '')
            	                (m = ($g.self@sure tmp 0))
	                        ($if (m == 1)
	       ($g.self@doAction 'execute exec doc_lib.accept(to_number('  + ($g.GRIDDS2@getValue 'ID_HEAD' ) + ')) ')
			        ) 
			       )
                               $else 
			       ((tmp = 'В этот период автомобиль забронирован. Нельзя провести документ' + '')
            	                (m = ($g.self@sure tmp 1))
			       )
			      )
                              $else 
			     (
			      ($g.dial4@retrieve)
	($debug 'g.dial4' )
  			      ($IF (($G.dial4@size) != 0)
	                       ((tmp = 'В этот период автомобиль сдан в аренду. Нельзя провести документ' + '')
             	                (m = ($g.self@sure tmp 1))
			       )
			       $else
			       (
			        ($g.dial5@retrieve)
	($debug 'g.dial5' )
  			        ($IF (($G.dial5@size) != 0)
				  ((tmp = 'В этот период автомобиль выставлен на продажу. Нельзя провести документ' + '')
            	                   (m = ($g.self@sure tmp 1))
			          )
			         $else
			         (
			          ($g.dial6@retrieve)
	($debug 'g.dial6' )
  			          ($IF (($G.dial6@size) != 0)
	                           ((tmp = 'В этом периоде автомобиль в Ремонте. Нельзя провести документ' + '')
             	                    (m = ($g.self@sure tmp 1))
				   )
			           $else
				       ($g.self@doAction 'execute exec doc_lib.accept(to_number('  + ($g.GRIDDS2@getValue 'ID_HEAD' ) + ')) ')
                                  )	
	                 )       )	
	         )       )	
	         )       )	
		 )       )	
                 )       ) 
                 )       )
		 )       )  
                ($ret ''))~; retrieve GRID2" }
        {item label = "Отменить документ" action= "~($X
	  	(global.id_auto = ($($G.GRID1@getDatastore)@getValue 'ID_AUTOMOBILE' )) 
		($IF (($g.GRIDDS2@getValue 'ID_TYPE_DOC' ) == 71)  
	         (($debug 'g.dial_more_doc' )
                     ($g.dial_more_doc@retrieve)
                     ($IF (($G.dial_more_doc@size) != 0)
	              ((tmp = 'Нельзя снять с проводки документ' + '')
            	       (m = ($g.self@sure tmp 1))
		      )
		      $else
	  	       ($g.self@doAction 'execute exec doc_lib.de_accept(to_number('  + ($g.GRIDDS2@getValue 'ID_HEAD' ) + ')) ')
		 ))
		    $else
 	             (($IF (($g.GRIDDS2@getValue 'ID_TYPE_DOC' ) == 72)  
	             (($debug 'g.dial_more_doc' )
                      ($g.dial_more_doc@retrieve)
                       ($IF (($G.dial_more_doc@size) != 0)
	                ((tmp = 'Нельзя снять с проводки документ' + '')
            	         (m = ($g.self@sure tmp 1))
		        )
			$else
	  	         ($g.self@doAction 'execute exec doc_lib.de_accept(to_number('  + ($g.GRIDDS2@getValue 'ID_HEAD' ) + ')) ')
		     ))
		      $else
                    ($g.self@doAction 'execute exec doc_lib.de_accept('  + ($g.GRIDDS2@getValue 'ID_HEAD' ) + ') ')
		   ))
		  )
                 ($ret ''))~; retrieve GRID2"}
   }
  {column size=30             title="СТАТУС"
        target=accept
        title_font_family=2
        title_font_color="#000000"
        halignment=center
        font_size = 12     
   }
   {column size=40            title="номер"      alias=id_hd
        target=id_head        title_font_family=2     title_font_color="#000000"
        halignment=right      font_size = 12          font_family=0
        visible = no          alias=idh
   }
   {column size=60            title="N док."
        target=num_sd         title_font_family=2     title_font_color="#000000"
        halignment=left       font_color="#000000"     
        font_size = 12        font_family=0
   }
   {column size=70            title="Дата нач. соб."
        target=date_sd        title_font_family=2     title_font_color="#000000"
        halignment=center     font_size = 12          font_family=0
   }
   {column size=70            title="Дата окн. соб."
        target=date_end_sd    title_font_family=2     title_font_color="#000000"
        halignment=center     font_size = 12          font_family=0
   }
   {column size=120             title="Автомобиль"
	target=name_of_models 	alias = name_of2
        title_font_family=2     title_font_color="#000000"
        halignment=left         font_size = 12          font_family=0
   }                  
   {column size=120             
        target=number_body      title="Рег. Номер"
        title_font_family=2     title_font_color="#000000"
        halignment=left         font_size = 12          font_family=0
   }
   {column size=120             
        target=vin              title="VIN"
        title_font_family=2     title_font_color="#000000"
        halignment=left         font_size = 12          font_family=0
   }
   {column size=120             
        target=name_type_dok    title="Событие"
        title_font_family=2     title_font_color="#000000"
        halignment=left         font_size = 12          font_family=0
   }                  
   {column size=120             title="id Событие"
        target=id_type_doc      visible=no
        title_font_family=2     title_font_color="#000000"
        halignment=left         font_size = 12          font_family=0
   }                  
   {column size=120             title="Событие"
        target=doc_name   	visible=no
        title_font_family=2     title_font_color="#000000"
        halignment=left         font_size = 12          font_family=0
   }                  
   {column size=250             
        target=comment_sd       title="Примечание"
        title_font_family=2     title_font_color="#000000"
        halignment=left         font_size = 12          font_family=0
   } 
 {datastore 
    alias = GRIDDS2
    query = "select id_head,num_sd,date_sd,accept,
                    id_automobile,date_end_sd,
                    number_body,vin,id_type_doc,name_type_dok,doc_name,
	 	    name_of_models,comment_sd
       from (select head.id_head,head.num_sd,head.date_sd,head.accept,
                    head_auto.id_automobile,head_auto.date_end_sd,
                    automobile.number_body, automobile.vin,
		    head.id_type_doc,type_doc.name_type_dok,type_doc.doc_name,
	 	    models_of_vehicle.name_of_models,
                    rtrim(head_auto.comment2_sd)||','||rtrim(head.comment_sd)  comment_sd
               from head,head_auto,automobile,type_doc,models_of_vehicle
              where head_auto.id_automobile = ~($try (GRIDDS1.id_automobile) $catch ('any') (-1))~
                and head.id_head = head_auto.id_head
                and head_auto.id_automobile = automobile.id_automobile
		and automobile.id_models_of_vehicle = models_of_vehicle.id_models_of_vehicle
                and head.id_type_doc = type_doc.id_type_doc
		and type_doc.id_sys = 7
               ~($if (($g.check1@getValue) == 'ON')
                       (' and head.accept = 1 ')
		 $else (' ')
 	        )~
		)
           order by date_sd desc"
   }
} // end of grid
{form width = 300 height = 100 alias = pf2
  {Checkgroup
    left = 20   top= 10
     {Checkbox
      alias = check1           font_size=12
      label = "Только проведенные"
      check = yes
      onvalue = "ON"
      offvalue = "OFF"
     }
  }
} // end of form
} // end of split
} // end of tabset
{button
  left = 250  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Выход ESC"
  action = "($g.self@actcancel)"
  shortcut = "escape"
}
{button
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Обновить КРОСС-ТАБЛИЦУ"
  action = "($X
	      ($G.GRID1@retrieve)
	    ($ret ''))"
}
{button
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Обновить"
  action = "($G.GRID2@retrieve)"
}
}
