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=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.GRIDDS01@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS01@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd >= '~($try ($($@date ($g.GRIDDS01@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.GRIDDS01@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS01@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd <= '~($try ($($@date ($g.GRIDDS01@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.GRIDDS01@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS01@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd <= '~($try ($($@date ($g.GRIDDS01@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.GRIDDS01@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS01@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd <= '~($try ($($@date ($g.GRIDDS01@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.GRIDDS01@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS01@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd  <='~($try ($($@date ($g.GRIDDS01@GetValue 'DATE_END_SD') )@toPLString) $catch ('Any')(global.d1))~'
	      and head_auto.date_end_sd >='~($try ($($@date ($g.GRIDDS01@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.GRIDDS01@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS01@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd  <='~($try ($($@date ($g.GRIDDS01@GetValue 'DATE_END_SD') )@toPLString) $catch ('Any')(global.d1))~'
	      and head_auto.date_end_sd >='~($try ($($@date ($g.GRIDDS01@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.GRIDDS01@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS01@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd <= '~($try ($($@date ($g.GRIDDS01@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.GRIDDS01@GetValue 'ID_HEAD') $catch ('Any')(-1))~
              and head_auto.id_automobile = ~($try ($g.GRIDDS01@GetValue 'ID_AUTOMOBILE') $catch ('Any')(-1))~
	      and head.date_sd  <='~($try ($($@date ($g.GRIDDS01@GetValue 'DATE_END_SD') )@toPLString) $catch ('Any')(global.d1))~'
	      and head_auto.date_end_sd >='~($try ($($@date ($g.GRIDDS01@GetValue 'DATE_SD') )@toPLString) $catch ('Any')(global.d1))~'
	    "
} // end of 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,type_doc
                    where head.id_type_doc = type_doc.id_type_doc
                      and type_doc.id_sys = 7"
                 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
    edit = "open util/docs/~($($GRID_GROUP1@getDatastore)@getValue 'DOC_NAME' )~ ~($($GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' )~ ;retrieve gridds01"
    del = "~($X
               (tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP1@getDatastore)@getValue 'NUM_SD' ) + '')
               (m = ($g.self@sure tmp 0))
               ($if (m == 0)
                   ($ret 'NOTDELETE')
               )
  		($if (($($G.GRID_GROUP1@getDatastore)@getValue 'ACCEPT' ) == 1)
                     ($g.self@sure 'Нельзя удалить проведенный документ' 1)
                 $else
                  ($g.self@doAction 'execute exec util.del_doc(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'ID_HEAD') + '); retrieve grid_group1')
                )
            ($ret 'NOTDELETE'))~ ;retrieve gridds01"

   {menu
        {item label = "Обновить" action="retrieve gridds01"}
        {item label = "Обновить все" action="retrieve tree1;retrieve gridds01"}
        {menu label = "Добавить событие" 
             {item label = "Ввод в автопарк" action="create util/docs/vvod_v_ap.rml -1 , -1; retrieve grid_group1"}
             {item label = "Вывод из автопарка" action="create util/docs/vivod_iz_ap.rml -1 , -1 ; retrieve grid_group1"}
             {item label = "Перегон авто" action="create util/docs/peregon.rml -1 , -1 ; retrieve grid_group1"}
             {item label = "Бронирование авто" action="create util/docs/for_rent.rml -1 , -1 ; retrieve grid_group1"}
             {item label = "Сдача в аренду авто" action="create util/docs/into_rent.rml -1 , -1 ; retrieve grid_group1"}
             {item label = "Ремонт авто" action="create util/docs/repaire.rml -1 , -1 ; retrieve grid_group1"}
             {item label = "Выставление на продажу" action="create util/docs/sale_auto.rml -1 , -1 ; retrieve grid_group1"}
        }
        {item label = "-"}
        {item label = "Просмотреть" action="open util/docs/~($($GRID_GROUP1@getDatastore)@getValue 'DOC_NAME' )~ ~($($GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' )~ ;retrieve gridds01"}
        {item label = "-"}
        {item label = "Удалить"
           action = "~($X
               (tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP1@getDatastore)@getValue 'NUM_SD' ) + '')
               (m = ($g.self@sure tmp 0))
               ($if (m == 0)
                   ($ret 'NOTDELETE')
               )
  		($if (($($G.GRID_GROUP1@getDatastore)@getValue 'ACCEPT' ) == 1)
                     ($g.self@sure 'Нельзя удалить проведенный документ' 1)
                 $else
                     ($g.self@doAction 'execute exec util.del_doc(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'ID_HEAD') + '); retrieve grid_group1')
		)
            ($ret 'NOTDELETE'))~ ;retrieve gridds01"
        }
        {item label = "-"}
        {item label = "Провести документ" action= "~($X
   	        (global.id_auto = ($g.GRIDDS01@getValue 'ID_AUTOMOBILE' ))
		($IF (($g.GRIDDS01@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.GRIDDS01@getValue 'ID_HEAD' ) + ')) ')
		 ))
		    $else
 	             (($IF (($g.GRIDDS01@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.GRIDDS01@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.GRIDDS01@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.GRIDDS01@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.GRIDDS01@getValue 'ID_HEAD' ) + ')) ')
                                  )	
	                 )       )	
	         )       )	
	         )       )	
		 )       )	
                 )       ) 
                 )       )
		 )       )  
                ($ret ''))~; retrieve gridds01" }
        {item label = "Отменить документ" action= "~($X
	  	(global.id_auto = ($g.GRIDDS01@getValue 'ID_AUTOMOBILE' )) 
		($IF (($g.GRIDDS01@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.GRIDDS01@getValue 'ID_HEAD' ) + ')) ')
		 ))
		    $else
 	             (($IF (($g.GRIDDS01@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.GRIDDS01@getValue 'ID_HEAD' ) + ')) ')
		     ))
		      $else
                    ($g.self@doAction 'execute exec doc_lib.de_accept('  + ($g.GRIDDS01@getValue 'ID_HEAD' ) + ') ')
		   ))
		  )
                 ($ret ''))~; retrieve gridds01"}
   }
   {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 
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {column size=120             title="Рег. Номер"
        target=number_body 
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {column size=120             title="VIN"
        target=vin
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {column size=120             title="Событие"
        target=name_type_dok 
        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=150             title="Примечание"
        target=comment_sd
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {datastore 
           alias = GRIDDS01
           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,
                           type_doc.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.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=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
           order by head.date_sd,head.num_sd)"
           editable = yes
   } // 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
