Cp1251
DOC 
foreground = lightgray
document_width = 900
document_height = 600
document_title = "Спецификация продукции///"
//style = "style/docs.st"
preloadscript="
(global.create = 0)
(global.d1 = ('\''+'01.01.2003'+'\'') )
(global.get_num = 0)
(global.h = ($@hash))
($global.h@put 'find' 999)
($global.h@put 'id_active' 999)
($global.h@put 'active_id_active' 999)
(global.cur_id_active = -1)"

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"
   seqquery = "select spc_sq.nextval from dual"
   seqnames = "spk"
   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, 5))), 0) + 1) num_sd
             from head
            where head.num_sd like 'СГП-%')"
  } // end of ds

{datastore  alias=about_active
    query="select active.name_active, unit.name_unit, active_type.name_type
             from active, unit, active_type
            where active.id_active = ~global.cur_id_active~
              and active.id_type_active = active_type.id_type
              and active.id_unit = unit.id_unit"
  } // end of ds

{toolbar   BACKGROUND = "LIGHTGREEN"
{splitpanel   percent=20
{scrollpane 
{form width=780 height=110       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=100
       alias=date_sd        font_size=12    font_family=0    bg_color="#ffffff"
       dep="ficd1"
   }
 {field 
   type = string
   left = 500  width = 70 height=25    
   alias=ficd1           visible=no
   exp="(ficd1 = global.d1)"
  }
   {field
       target=head.accept    border = box   visible=no
       left=200   top=83    height=20      width=40
       alias=accept         font_size=12    font_family=0    bg_color="#ffffff"
   }
   {label
       value="Склад"        
       left=320    top=8    height=20       width=40
       font_size=12         font_family=0   bg_color="#c0c000"
   }
   {field
       target=head.id_department1
       visible=no           border = box
       left=370    top=8    height=20       width=130
       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=370    top=8    height=20       width=130
       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
       value="Исполнитель"  
       left=510  top=8      height=20       width=70
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=personal.fname                border = box
       left=580    top=8    height=20       width=200
       alias=name           font_size=12    font_family=0    bg_color="#ffffff"
       editable = readonly
   }     
   {label
       value="Готовая продукция"
       left=11     top=33   height=20        width=100
       font_size=12         font_family=0    bg_color="#c0c0c0"
   }
   {field
       target=head.id_active                 halignment = right
       left=120     top=33   height=20        width=70
       alias=id__active               border = box        
       font_size=12         font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="~($X 
                  ($debug 'id_head = ' + ($g.d_head@getValue 'head.id_head'))
                  ($global.h@put 'find' 1)
                  ($($g.self@getAliases)@put '_SELECTION' global.h) 
                  ($g.self@doAction 'opennew find_active.rml &_SELECTION')
                  ($debug 'find = ' + ($global.h@get 'find'))
                  ($if (($global.h@get 'find') != 1)
                    (
                      (g.id__active = ($global.h@get 'active_id_active'))
                      (global.cur_id_active = g.id__active)
                      ($g.about_active@retrieve)
                      (g.name__active = ($g.about_active@getValue 'ACTIVE.NAME_ACTIVE'))
                      (g.name__unit = ($g.about_active@getValue 'UNIT.NAME_UNIT'))
                    )
                  )
                  ($ret '') 
               )~;"
   }
   {field
      target=active.name_active              border = box
      left=200     top=33   height=20        width=270
      alias=name__active    font_size=12     font_family=0    bg_color="#ffffff"
      editable = readonly
   }
   {label
       value="Мин. ед. изм"
       left=500     top=33   height=20        width=65
       font_size=12         font_family=0    bg_color="#c0c0c0"
   }
   {field
      target=unit.name_unit              border = box
      left=570     top=33   height=20        width=100
      alias=name__unit    font_size=12     font_family=0    bg_color="#ffffff"
      editable = readonly
   }
   {label
       value="Примечание"    
       left=11    top=60     height=20      width=65
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.comment_sd   border = box
       left=80    top=60    height=20      width=495
       alias=comment_sd         font_size=12   font_family=0    bg_color="#ffffff"
   }
   {label
    alias=progress
    left = 10  top = 90      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.num_per_sd,head.date_per_sd,
                        head.comment_sd,
			head.id_personal,personal.fname,
			head.parent_id_head,
			head.id_active,
			active.name_active,
			unit.name_unit,
			head.id_department1,
			department.name1_dep
                   from head,personal,active,unit,department
                  where head.id_head = ~($try ($if (global.create == 0)
                                  	    	(ARGUMENTS.0)
	                                       $else (ds.hpk))
		                         $catch ('any') (-1))~
                   and head.id_personal = personal.id_personal(+)
                   and head.id_active = active.id_active (+)
                   and active.id_unit = unit.id_unit (+)
                   and head.id_department1 = department.id_department (+)"
              editable = yes
                  head = yes
                unique = "('head','head.id_head')"
               default = "head.id_head=~ds.hpk~,head.id_type_doc=~10~,
                          head.date_sd=~ds.date~,
                          head.id_personal=~ds.idp~,
                          head.accept=~0~,
                          head.num_sd=~'СГП-'~,
			  head.num_per_sd=~'.'~,head.date_per_sd=~ds.date~,
			  head.id_department1=~0~,
			  head.id_active=~-100~,active.name_active=~'Не известен'~"
} // ds
} // form
} // scroll
{tabset labels = "перечень комплектующих"
 tabs_on_top=yes
{grid
editable = yes
add="opennew find_choose.rml 1, 0"
alias = GRIDSPC
buttonbar_font_family=0       buttonbar_font_size=12           
buttonbar_size = 30           titlebar_size = 18            rowsize=20     
addexp="war=store.active.id_active;
        name_w=store.active.name_active;
    	id_un=store.active.id_unit;
        name_un=store.unit.name_unit;
        global.cur_id_active = store.active.id_active"
{menu
   {item label = "Поиск в справочнике" action="opennew find_choose.rml 1, 0"}
}
 {column size=40  
     visible=no
     title="Номер"   
     target=spc.id_spc        title_font_family=2     halignment=left
     font_color="#000000"     font_size=12              font_family=0
 }
 {column size=110 
    visible=no
    title="Номер"   
    target=spc.id_head        title_font_family=2
    font_color="#000000"      font_size = 12            font_family=0
 }
 {column size=60
    title="Код"              font_family=0	     editable = readonly   
    target=spc.id_active     title_font_family=2     halignment=left
    alias=war                font_color="#000000"    font_size=12   
    visible = no
 }
 {column size=300       title="Наименование"
    target=active.name_active  title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=name_w              editable = readonly 
 }
 {column size=80       title="Тип актива"
    target=active_type.name_type  title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=name_type              editable = readonly 
    visible = no
 }
 {column size=60
    title="id_unit"              font_family=0	     editable = readonly   
    target=spc.id_unit     title_font_family=2     halignment=left
    alias=id_un                font_color="#000000"    font_size=12   
    visible = no
 }
 {column size=80       title="Мин. ед. изм."
    target=unit.name_unit     title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=name_un             
    editable = readonly
 }
 {column size=50       title="Кол-во " 
    target=spc.q1_spc      title_font_family=2      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.00"    alias = q1_spc
    dep="summ"
 }

 {datastore 
      alias = d_spc
      query = "select spc.id_spc, spc.id_head, spc.id_active, spc.id_unit,
                      spc.q1_spc, active.name_active, unit.name_unit,
		      active_type.name_type
                 from spc, active, unit, active_type
                where spc.id_head = ~($try (d_head.head.id_head) $catch ('NullException') (-1) )~ 
                  and spc.id_active = active.id_active 
                  and spc.id_unit = unit.id_unit 
                  and active.id_type_active = active_type.id_type
             order by spc.id_spc"
             editable = yes
               unique = "('spc','spc.id_spc')" 
              default = "spc.id_head=~($try (d_head.head.id_head) $catch ('NullException') (-1) )~,
                         spc.id_spc=~ds.spk~,
			 spc.q1_spc=~0~,"
} // ds
} // grid1
} // tabset
} // 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') + ');')
		    ($g.self@actcancel)
		#  )
		#  $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

