Cp1251
DOC 
foreground = lightgray
document_width = 750
document_height = 550
document_title = "Заявка на аренду ТС"
style = "style/docs.st"
preloadscript="
(global.create = 0)
(global.get_num = 0)
"

postloadscript="($X
	 	 ($IF (($g.D_HEAD@getvalue 'HEAD.ACCEPT') == 1)
		  ($g.progress@setValue 'Только для чтения')
		 )
		($ret ''))"

{dscollection
   alias = ds
   initQuery = "select head_sq.nextval,sysdate,id_personal from personal where upper(login)=user"
   aliases = "hpk,date,idp"
   initAction ="(global.create = 1)
                (global.get_num = 1)"
}
{datastore  alias=doc_num
    query="select num_sd from (select 'ЗаТС-'||(nvl(max(to_number(substr(num_sd, 6))), 0) + 1) num_sd
             from head
            where head.num_sd like 'ЗаТС-%')"
  } // end of ds

{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel   percent=40
{scrollpane 
{form width=780 height=208       bg_color="#c0c0c0"   alias = fm
   {label
       value="N док."       
       left=11    top=8     height=20       width=40
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }  
   {field
       target=head.num_sd   border = box
       left=55     top=8    height=20       width=95
       alias=num_sd         font_size=12    font_family=0    bg_color="#ffffff"
       editable=readonly
   }  
   {label
       value="Дата док."    
       left=155    top=8    height=20       width=50
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.date_sd  border = box
       left=210    top=8    height=20       width=70
       alias=date_sd        font_size=12    font_family=0    bg_color="#ffffff"
   }
   {label
       value="Контрагент"
       left=11     top=33   height=20        width=65
       font_size=12         font_family=0    bg_color="#c0c0c0"
   }
   {field
       target=head.id_client1                 halignment = right
       left=80     top=33   height=20        width=70
       alias=cli1_numb_client                border = box        
       font_size=12         font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="opennew find_client.rml"
       editexp="cli1_numb_client=STORE.client.id_client"
       dep="name_client1"
   }
   {field
      target=client.name1_client              border = box
      left=155     top=33   height=20        width=320
      alias=name_client1    font_size=12     font_family=0    bg_color="#ffffff"
      editexp="name_client1=STORE.client.name1_client"
      editable = readonly
   }   
   {field
       target=head.accept    border = box   visible=no
       left=11   top=33    height=20      width=40
       alias=accept         font_size=12    font_family=0    bg_color="#ffffff"
   }
   {label
       value="Контактное лицо"    
       left=11    top=58     height=20      width=85
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head_auto.comment2_sd   border = box
       left=100    top=58    height=20      width=375
       alias=comment2_sd         font_size=12   font_family=0    bg_color="#ffffff"
   }   
   {label
       value="Примечание"    
       left=11    top=83     height=20      width=85
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.comment_sd   border = box
       left=100    top=83    height=20      width=375
       alias=comment_sd         font_size=12   font_family=0    bg_color="#ffffff"
   }
   {label
       value="Подразделение"        
       left=290    top=8    height=20       width=80
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.id_department1
       visible=no           border = box
       left=375    top=8    height=20       width=100
       alias=sklad_t        font_size=12    font_family=0    bg_color="#ffffff"
       editexp="(sklad_t=STORE.department.id_department)"
   }
   {field
       target=department.name1_dep                 border = box
       left=375    top=8    height=20       width=100
       alias=sklad          font_size=12    font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="opennew department_gr.rml "
       editexp="sklad=STORE.department.name1_dep"
       dep="sklad_t"
   }
   {label
    alias=progress
    left = 630  top = 8      width = 150     height = 20 
    font_size=16              font_family=2   font_color="#000088"
    bg_color="#c0c0c0"        border=none     
   }
     
{datastore 
        alias = d_head
        query = "select head.id_head,head.id_type_doc,head.accept,
                        head.num_sd,head.date_sd,
                        head.date_per_sd,
                        head.id_department1,department.name1_dep,
                        head.id_client1,client.name1_client,
                        head.id_client2,
                        head.comment_sd,
                        head.id_personal,personal.fname,
                        head_auto.id_head,head_auto.date_end_sd,head_auto.comment2_sd,head_auto.id_automobile
                   from head,client,personal,department,head_auto
                  where head.id_head = ~($try ($if (global.create == 0)
                                                (ARGUMENTS.0)
                                               $else (ds.hpk))
                                         $catch ('any') (-1))~
                   and head_auto.id_head=head.id_head                      
                   and head.id_client1 = client.id_client (+)
                   and head.id_department1 = department.id_department (+)
                   and head.id_personal = personal.id_personal(+)
                   and head.id_type_doc = 97"
              editable = yes
                  head = yes
                unique = "('head_auto','head_auto.id_head') ('head','head.id_head')"
               default = "head.id_head=~ds.hpk~,head.id_type_doc=~97~,
                          head.date_sd=~ds.date~,
                          head.id_personal=~ds.idp~,
                          head.accept=~0~,
                          head.num_sd=~'ЗаТС-'~,
                          head.date_per_sd=~ds.date~,
                          head.id_department1=~0~,
                          head.id_department2=~0~,
                          head.id_client1=~1~,
                          client.name1_client=~'ФИРМА'~, 
                          head.id_client2=~1~,
                          head_auto.id_head=~ds.hpk~,
                          head_auto.id_automobile=~-1~,
                          head_auto.date_end_sd=~ds.date~"
} // ds

} // form
} // scroll
{form alias = frm_spc
} // form
} // split
{button
  left = 11  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Сохранить и выйти F3"
  action = "($X
	     ($if (($G.D_HEAD@getValue 'HEAD.ACCEPT') == 1)
		  (
		    ($g.self@actcancel)
		    ($ret '')
		  )
	     )
             (tmp = 'Вы действительно хотите сохранить все изменения и выйти' + '')
             (m = ($g.self@sure tmp 0))
               ($if (m == 0)()
               $else
                    (
                        ($if (global.get_num == 1)
                            (
                                ($g.doc_num@retrieve)
                                d_head.head.num_sd = ($try ($g.doc_num@GetValue 'NUM_SD') $catch ('Any')(''))
                                g.num_sd = ($try ($g.doc_num@GetValue 'NUM_SD') $catch ('Any')(''))
                                (global.get_num = 0)
                            )
                        )
			#($if (($G.D_HEAD@getValue 'HEAD.ACCEPT') == 1)
			#  (
			#    ($g.self@doAction 'execute exec doc_lib.de_accept(' + ($G.D_HEAD@getValue 'HEAD.ID_HEAD') + ');')
			#    ($g.self@actsave)
  			#    ($g.self@doAction 'execute exec doc_lib.accept(' + ($G.D_HEAD@getValue 'HEAD.ID_HEAD') + ');')
			#    ($g.self@actcancel)
			#  )
			#  $else (
			    ($g.self@actdok)
			#  )
			#)
			
                        
                    )
               )
             ($ret ''))"
  shortcut = "F3"
}
{button
  left = 11  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Запись F4"
  action = "($if (($G.D_HEAD@getValue 'HEAD.ACCEPT') == 1)
		  (
		    ($g.self@actcancel)
		    ($ret '')
		  )
	     )
	    ($if (global.get_num == 1)
                (
                    ($g.doc_num@retrieve)
                    d_head.head.num_sd = ($try ($g.doc_num@GetValue 'NUM_SD') $catch ('Any')(''))
                    g.num_sd = ($try ($g.doc_num@GetValue 'NUM_SD') $catch ('Any')(''))
                    (global.get_num = 0)
                )
            )
	    #($if (($G.D_HEAD@getValue 'HEAD.ACCEPT') == 1)
		#  (
		#    ($g.self@doAction 'execute exec doc_lib.de_accept(' + ($G.D_HEAD@getValue 'HEAD.ID_HEAD') + ');')
		#    ($g.self@actsave)
		#    ($g.self@doAction 'execute exec doc_lib.accept(' + ($G.D_HEAD@getValue 'HEAD.ID_HEAD') + ');')
		#  )
		#  $else (
		    ($g.self@actsave)
		#  )
		#)
		"
  shortcut = "F4"
}
{button
  left = 72  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Отмена ESC"
  action = "($X
             (tmp = 'Вы действительно хотите выйти без сохранения данных' + '')
             (m = ($g.self@sure tmp 0))
               ($if (m == 0)()
               $else ($g.self@actcancel)
               )
             ($ret ''))"
  shortcut = "escape"
}
} // toolbar

