Cp1251
DOC
foreground = lightgray 
document_width = 750
document_height = 550
document_title = "Вывод из эксплуатации ОС"
style = "style/group.st"
preloadscript="
(global.retr = 0)
(global.id_h = 0)
"

{DSCollection
   alias = dscoll
   SeqQuery = "select to_char(sysdate) from dual"
   seqnames = "date"
}

{datastore alias=doc_vehicles
	   query="select num_doc from (select count(*) num_doc from vehicle v
		  where v.vin in (select vin from vehicle 
				where id_head2 = ~($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD')~)
		  and operation = 0)"
	} // end ds

{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel type=vertical     percent=20
{treeview2
   alias=tree1  
   listAction="retrieve gridds01"  
   nodeAction="retrieve gridds01"  
   nodefont="Courier,bold|italic,12"      pointfont="Courier,italic,12"  
   hilite=gray,white
   node=blue   point=blue
   rootname="Вывод из эксплуатации ТС"
   hiliting=on
   storepath = yes

        {groupreport 
          alias = datastore1
          query = "select distinct to_char(date_sd,'yyyy') y, to_char(date_sd,'mm') m ,
                          to_char(date_sd,'dd') d, date_sd 
                     from head
                    where head.id_type_doc = 91"
                 grouping = "y;m;d"
                  sorting = "1;1;1"
        } // end of gr
} // end of tree
{grid
    alias = GRID_GROUP1
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselect = yes                      editable = no
    rowsize = 20
    add = "create docs/vivod_os.rml -1 ; retrieve tree1;retrieve gridds01"
    edit = "open docs/vivod_os.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~ ;retrieve gridds01"
    del = "~($X
               (tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.NUM_SD' ) + '')
               (m = ($g.self@sure tmp 0))
               ($if (m == 0)
                   ($ret 'NOTDELETE')
               )
               ($g.self@doAction 'execute exec util.del_doc(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD') + '); retrieve grid_group1')
            ($ret 'NOTDELETE'))~ ;retrieve gridds01"

   {menu
        {item label = "Обновить" action="retrieve gridds01"}
        {item label = "Обновить все" action="retrieve tree1;retrieve gridds01"}
        {item label = "Добавить" action="create docs/vivod_os.rml -1 ; retrieve tree1;retrieve gridds01"}
        {item label = "-"}
        {item label = "Просмотреть" action="open docs/vivod_os.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~ ;retrieve gridds01"}
        {item label = "-"}
//        {item label = "Печатная форма" action="open pech_form/pech_form_vivod_os.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~"}
//        {item label = "-"}
        {item label = "Удалить"
           action = "~($X
               (tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.NUM_SD' ) + '')
               (m = ($g.self@sure tmp 0))
               ($if (m == 0)
                   ($ret 'NOTDELETE')
               )
               ($g.self@doAction 'execute exec util.del_doc(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD') + '); retrieve grid_group1')
            ($ret 'NOTDELETE'))~ ;retrieve gridds01"
        }
        {item label = "-"}
        //{item label = "Вывести ТС" action= "execute exec update vehicle set operation = 1 where id_head2 = ~($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD')~; execute exec ~'doc_lib.accept('+($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve gridds01" }
	{item label = "Вывести ТС" action= "~($X
						($g.doc_vehicles@retrieve)
						($if (($g.doc_vehicles@getValue 'NUM_DOC') > 0) (
							($g.self@sure 'ТС уже выведено из эксплуатации' 1)
						)
						$else (
							(l_id_head = ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD'))
							($g.self@doAction 'execute exec update vehicle set operation = 0 where id_head2 = ' + l_id_head + '; execute exec doc_lib.accept(' + l_id_head + ') ; retrieve gridds01')
						  )
						)
					     )~"
	}
        {item label = "Отменить вывод ТС" action= "execute exec update vehicle set operation = 1 where id_head2 = ~($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD')~; execute exec ~'doc_lib.de_accept('+($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve gridds01" }
   }
   {column size=30             title="X"
        target=head.accept
        title_font_family=2
        title_font_color="#000000"
        halignment=center
        font_size = 12     
   }
   {column size=40             title="номер"      alias=id_hd
        target=head.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=head.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=head.date_sd        title_font_family=2     title_font_color="#000000"
        halignment=center          font_size = 12          font_family=0
   }
   {column size=70             title="ТС"
        target=vehicle.id_vehicle
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=70             title="Модель ТС"
        target=vehicle.id_models_of_vehicle     visible=no
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=70             title="Модель ТС"
        target=models_of_vehicle.name_of_models
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=100             title="Примечание"
        target=head.comment_sd
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {datastore 
           alias = GRIDDS01
           query = "select head.id_head,head.num_sd,head.date_sd,
                           head.id_department1,
                           head.comment_sd,
                           vehicle.id_vehicle,
                           head.accept,vehicle.id_models_of_vehicle,
                           models_of_vehicle.name_of_models
                      from head,vehicle,models_of_vehicle
                     where head.date_sd ~ 
         ($if (($g.tree1@getLevel) == 0)
                   ($try ('=to_date(\''+
                   #  '01-01-0001' +
                   dscoll.date+                 
                  '\',\'dd-mm-yyyy\')') 
                $catch ('Any') ('=\'11-11-1999\'')
                    )
                $if (($g.tree1@getLevel) == 1)
                    ($try ('between
                            to_date(\'01-01-'+
                            datastore1.y+
             '\',\'dd-mm-yyyy\')
                         and
                            to_date(\'31-12-'+
                            datastore1.y+
             '\',\'dd-mm-yyyy\')')
                     $catch ('Any') ('=\'01-01-1999\'')
                     )               
                 $if (($g.tree1@getLevel) == 2)
                     ($if (($@number (datastore1.m)) == 12)
                          ($try ('between
                                  to_date(\'01-12-'+
                                  datastore1.y+
                   '\',\'dd-mm-yyyy\')
                                  and
                                  to_date(\'31-12-'+
                                  datastore1.y+
                   '\',\'dd-mm-yyyy\')')
                            $catch ('Any') ('=\'01-01-1999\'')
                            )                                  
                      $else ($try (' >= to_date(\'01-'+
                                      datastore1.m+                
                       '-'+
                       datastore1.y+
                       '\',\'dd-mm-yyyy\') 
                                  and 
                              date_sd < to_date(\'01-'+
                       ($(($@number (datastore1.m))+1)@int)+
                                      '-'+
                                      datastore1.y+
                       '\',\'dd-mm-yyyy\')')
                      $catch ('Any') ('=\'11-11-1999\'')
                      )  
                     )              
                 $else ($try ('=to_date(\''+
                  datastore1.d+
                  '-'+
                  datastore1.m+
                  '-'+
                  datastore1.y+
                  '\',\'dd-mm-yyyy\')') 
                    $catch ('Any') ('=\'11-11-1999\'')
                        )
                 ) ~ 
		and head.id_head=vehicle.id_head2 (+)
                and vehicle.id_models_of_vehicle=models_of_vehicle.id_models_of_vehicle(+)
                and head.id_type_doc = 91
           order by head.date_sd,head.num_sd"
           editable = yes
             unique = "('head','head.id_head')"
   } // end of ds
} // end of grid
} // end of split1
{button
  left = 72  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Выход ESC"
  action = "($g.self@actcancel)"
  shortcut = "escape"
}
} // toolbar
