Cp1251
DOC 
foreground = lightgray
document_width = 1000
document_height = 700
document_title = "ZetaSE.Autocomplect/ Заявка на выдачу материалов для списка продукции"
preloadscript="
(global.create = 0)
(global.d1 = ('\''+'01.01.2003'+'\'') )
(global.get_num = 0)
(global.cur_id_active = -1)"

postloadscript="($X
	 	 ($IF (($g.D_HEAD@getvalue 'HEAD.ACCEPT') == 1)
		  ($g.progress@setValue 'Только для чтения')
		 )
		 ($if (global.create == 1)
		   (
		     ($g.ds_copy@retrieve)
		     (i = 0)
		     ($while (i < ($g.ds_copy@size))
		       (
		         ($g.ds_copy@setCurRow i)
		         ($g.d_spc@NewRow)
		         ($g.d_spc@setValue 'spc.id_unit' ($g.ds_copy@getValue 'spc.id_unit'))
		         ($g.d_spc@setValue 'spc.id_active' ($g.ds_copy@getValue 'spc.id_active'))
		         ($g.d_spc@setValue 'active.name_active' ($g.ds_copy@getValue 'active.name_active'))
		         ($g.d_spc@setValue 'spc.q1_spc' ($g.ds_copy@getValue 'spc.q1_spc'))
		         ($g.d_spc@setValue 'spc.comments' ($g.ds_copy@getValue 'spc.comments'))
		         (i += 1)
		       )
		     )
		     ($g.d_spc@notifyViews)
		     ($if (($g.ds_copy@size) > 0)
		       (
                         (g.sklad_t = ($g.ds_copy@getValue 'head.id_department1'))
                         (g.sklad = ($g.ds_copy@getValue 'department.name1_dep'))
                         (g.field_id_work_area = ($g.ds_copy@getValue 'type1'))
                         (g.field_name_work_area = ($g.ds_copy@getValue 'work_area.name_work_area'))
                       )
                      $else
                       (
                        (g.field_id_work_area = 1)
                        (g.field_name_work_area = 'Армирование')
                       )
                     )
		   )
		 )

                 ($ret '')
		)"

{dscollection
   alias = ds
   initQuery = "select head_sq.nextval, sysdate, trunc(sysdate, 'month'), id_personal from personal where upper(login)=user"
   aliases = "hpk, date, month_beginning, 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=check_spec
    query="select id_head
             from head
            where head.id_type_doc = 10
              and head.id_active = ~global.cur_id_active~
              and head.accept = 3"
} // end of ds

{datastore  alias=ds_copy
    query="select spc.id_unit, spc.id_active, spc.q1_spc, active.name_active, spc.comments, head.id_department1, department.name1_dep, nvl(head.type1, 2) type1, work_area.name_work_area
             from spc, active, head, department, work_area
            where spc.id_head = ~ARGUMENTS.0~
              and head.id_head = spc.id_head
              and head.id_department1 = department.id_department
              and head.type1 = work_area.id_work_area (+)
              and spc.id_active = active.id_active
              and spc.parent_id_spc = 0
            order by spc.id_spc"
} // end of ds

{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel type = horizontal percent = 20
{form width=780 height=150       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=160    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=80
       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=310  top=8      height=20       width=130
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=personal.fname                border = box
       left=440    top=8    height=20       width=100
       alias=name           font_size=12    font_family=0    bg_color="#ffffff"
       editable = readonly
   }     

   {label
       value="Склад"        
       left=600    top=8    height=20       width=40
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.id_department1
       visible=no           border = box
       left=50    top=70    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=650    top=8    height=20       width=200
       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=580    top=40    height=20       width=60
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.type1
       visible=no           border = box
       left=50    top=70    height=20       width=100
       alias=field_id_work_area        font_size=12    font_family=0    bg_color="#ffffff"
       editexp="field_id_work_area=STORE.work_area.id_work_area"
   }
   {field
       target=work_area.name_work_area               border = box
       left=650    top=40    height=20       width=200
       alias=field_name_work_area          font_size=12    font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="opennew sprav/sprav_work_areas_readonly.rml"
       editexp="field_name_work_area=STORE.work_area.name_work_area"
       dep = "field_id_work_area"
   }
   
   {label
       value="Примечание:"
       left=10    top=40     height=20      width=70
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.comment_sd   border = box
       left=80    top=40    height=20      width=495
       alias=comment_sd         font_size=12   font_family=0    bg_color="#ffffff"
   }
   {label
    alias=progress
    left = 630  top = 40      width = 150     height = 20 
    font_size=17              font_family=1   font_color="#FF0000"
    bg_color="#c0c0c0"        border=none     
   }
{datastore 
        alias = d_head
        query = "select head.id_head,head.id_type_doc,head.accept, head.sort,
                        head.num_sd,head.date_sd,
                        head.id_department1,department.name1_dep,
             		head.id_department2,dep2.name1_dep,
           		head.id_client1,head.id_client2,
                        head.comment_sd,
			head.id_personal,personal.fname,
			head.parent_id_head, head.date1, head.id_contract,
			head.id_active, active.name_active, head.id_unit,
			active_pseudo_unit.id_pseudo_unit, active_pseudo_unit.obozn,
			head.sum1_sd, head.type1, work_area.name_work_area
                   from head,personal,department,department dep2, active,active_pseudo_unit,work_area
                  where head.id_head = ~($try ($if (global.create == 0)
                                  	    	(ARGUMENTS.0)
	                                       $else (ds.hpk))
		                         $catch ('any') (-1))~
                   and head.id_department1 = department.id_department (+)
		   and head.id_department2 = dep2.id_department(+)
                   and head.id_personal = personal.id_personal(+)
                   and head.id_active = active.id_active (+)
                   and head.id_unit = active_pseudo_unit.id_pseudo_unit (+)
                   and head.type1 = work_area.id_work_area (+)"
              editable = yes
                  head = yes
                unique = "('head','head.id_head')"
               default = "head.id_head=~ds.hpk~,head.id_type_doc=~17~,
                          head.date_sd=~ds.date~,
                          head.date1=~ds.month_beginning~,
                          head.id_personal=~ds.idp~,
                          head.accept=~0~,
                          head.num_sd=~'Звм-'~,
			  head.id_department1=~0~,
			  head.id_department2=~0~,
                          head.id_client1=~1~,
                          head.id_client2=~1~,
                          head.id_contract=~1~,
                          head.type1=~1~"
} // ds
} // form
{grid
editable = yes
alias = GRIDSPC
buttonbar_font_family=0       buttonbar_font_size=12           
buttonbar_size = 30           titlebar_size = 18            rowsize=20
titlebar_height = 30

del = ""

addexp="($X
          (rrr = ($g.d_spc@getCurRow))
          (t = ($g.d_spc@iterator))
          (i = 0)
          (is_in = 1)
          ($while ($t@next)
            (
              (i += 1)
              ($g.d_spc@FastSetCurRow (i-1))
              (l_id_active = ($try ($g.d_spc@GetValue 'SPC.ID_ACTIVE') $catch ('Any')(-1)))
              ($if (l_id_active == store.active.id_active) (
                ($g.self@sure 'Продукция \"'+store.active.name_active+'\" уже есть в спецификации!' 1)
                (is_in = 0)
              ))
            )
          )
          (global.cur_id_active = store.active.id_active)
          ($g.check_spec@retrieve)
          ($if (($g.check_spec@size) == 0)
            (
              ($g.self@sure 'У этой продукции нет спецификации.' 1)
              (is_in = 0)
            )
          )
          ($if (is_in == 1)
            (
              ($g.d_spc@setValue 'SPC.ID_ACTIVE' store.active.id_active)
              ($g.d_spc@setValue 'ACTIVE.NAME_ACTIVE' store.active.name_active)
            )
            $else (
              ($g.d_spc@delRow ($g.d_spc@getCurRow))
            )
          )
          ($g.d_spc@setCurRow rrr)
          ($ret '')

	)"



{menu
   {item label = "Добавить" action="opennew find_choose.rml 1, 0"}
   {item label = "-"}
   {item label = "Удалить" action="~($X
                                        
                                        ($g.d_spc@delRow ($g.d_spc@getCurRow))
                                        ($g.d_spc@notifyViews)
                                        ($ret '')
                                    )~"
   }
}

 {column size=50     
    title="Код"              font_family=0            editable = readonly 
    target=spc.id_active     title_font_family=0      halignment=center
    font_color="#000000"     font_size=12
    editmask = "##0."
 }
 {column size=250       title="Наименование"
    target=active.name_active  title_font_family=0     halignment=left
    font_color="#000000"      font_size=12              font_family=0 font_face = "Arial narrow"
    editable = readonly 
 }
 {column size=70       title="Кол-во" 
    target=spc.q1_spc      title_font_family=0      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"    alias = q1_spc
    dep = "total_q_spc,q_dep1_after"
 }
 {column size=200       title="<html>Примечание</html>" 
    target=spc.comments      title_font_family=0      halignment=left
    font_color="#000000"     font_size=12            font_family=0
 }

 {datastore 
      alias = d_spc
      query = "select spc.id_spc, spc.id_head, spc.id_unit,
                      spc.id_active, active.name_active,
                      spc.q1_spc,
                      spc.q2_spc,
                      spc.parent_id_spc,
                      spc.comments
                 from spc, active
                where spc.id_head = ~($try (d_head.head.id_head) $catch ('NullException') (-1) )~ 
                  and spc.parent_id_spc = 0
                  and active.id_active = spc.id_active
                  "
             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~,
			 spc.q2_spc=~0~,
			 spc.parent_id_spc=~0~"


} // ds
} // grid

} // 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 '')
		  )
	     )
             ($if (($try (g.sklad_t) $catch ('NullException')(0)) == 0)
               (
                  ($g.self@sure 'Не указан склад, с которого произойдет списание по данной заявке.' 1)
                  ($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)
                 )
             )
             ($g.self@actDok)
             ($ret '')
             )"
  shortcut = "F3"
}
{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

