Cp1251
DOC 
foreground = lightgray
document_width = 1000
document_height = 700
document_title = "Акт инвентаризации"
style = "style/docs.st"
//hashable=yes
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 'Только для чтения')
		 )
		($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=get_active_details
    query="select rest, price
             from (

           select doc_lib.getRestBeforeBefore(
                                               ~($try (g.sklad_t) $catch ('NullException')(-1))~,
                                               active.id_active,
                                               ~($if (global.create == 0)
                                                    ($try ($g.d_head@getValue 'head.sort') $catch ('NullException')(-1))
                                                 $else 
                                                    ('1e10')
                                                )~
                                             ) rest,
                  (select max(price) from price where id_active = active.id_active) price
             from active
            where active.id_active = ~global.cur_id_active~
                  )"
} // end of ds
{datastore  alias=get_ostat
    query="select id_active,name_active,
		  id_type_active,name_type,
		  id_pseudo_unit,obozn,
		  kolvo,price1,
		  spc_sq.nextval
      from(select id_active,name_active,
		  id_type_active,name_type,
		  id_pseudo_unit,obozn,
		  kolvo,price1
      from(select active.id_active,active.name_active,
		  active.id_type_active,active_type.name_type,
		  active_pseudo_unit.id_pseudo_unit,active_pseudo_unit.obozn,
		  doc_lib.getRestBefore(~($try ($g.d_head@getvalue 'HEAD.ID_DEPARTMENT1') $catch ('any') (0))~,active.id_active, (select max(head.sort) 
																    from head 
																   where head.date_sd <= \'~($try ($($@date ($g.d_head@GetValue 'HEAD.DATE_SD') )@toPLString) $catch ('Any')('01.01.2009'))~\'))/active_pseudo_unit.koeff  kolvo,
		  doc_lib.getPriceBefore(~($try ($g.d_head@getvalue 'HEAD.ID_DEPARTMENT1') $catch ('any') (0))~,active.id_active, (select max(head.sort) 
																    from head 
																   where head.date_sd <= \'~($try ($($@date ($g.d_head@GetValue 'HEAD.DATE_SD') )@toPLString) $catch ('Any')('01.01.2009'))~\')) 	price1
	     from active,active_type,active_pseudo_unit
            where active_pseudo_unit.id_active = active.id_active
	      and active_pseudo_unit.priz = 1
	      and active.id_type_active <> 2
              and active.id_type_active = active_type.id_type)
	    where kolvo <> 0)"
  } // end of ds
  
{datastore  alias=nulls_for_not_nulls  
    query="select id_active,name_active,id_type_active,name_type,id_pseudo_unit,obozn,price1, rest
              from(
			        select active.id_active,active.name_active,active.id_type_active,active_type.name_type,
		                   active_pseudo_unit.id_pseudo_unit,active_pseudo_unit.obozn,
							doc_lib.getPriceBefore(~($try ($g.d_head@getvalue 'HEAD.ID_DEPARTMENT1') $catch ('any') (0))~,
											   active.id_active,
												   (select max(head.sort) 
													from head 
												   where head.date_sd <= \'~($try ($($@date ($g.d_head@GetValue 'HEAD.DATE_SD') )@toPLString) $catch ('Any')('01.01.2009'))~\')
										   ) 	price1,
					                  doc_lib.getRestBeforeBefore(
                                                                                        ~($try (g.sklad_t) $catch ('NullException')(-1))~,
                                                                                        active.id_active,
                                                                                        ~($if (global.create == 0)
                                                                                             ($try (g.d_head.head.sort) $catch ('NullException')(-1))
                                                                                          $else 
                                                                                             ('1e10')
                                                                                         )~
                                                                                    ) rest

				      from (
					        select id_active 
							from(
								select active.id_active,active.name_active, active.id_type_active,active_type.name_type,
									   active_pseudo_unit.id_pseudo_unit,active_pseudo_unit.obozn,
										doc_lib.getRestBefore(~($try ($g.d_head@getvalue 'HEAD.ID_DEPARTMENT1') $catch ('any') (0))~,
															  active.id_active, 
															  (select max(head.sort) 
																 from head 
																where head.date_sd <= \'~($try ($($@date ($g.d_head@GetValue 'HEAD.DATE_SD') )@toPLString) $catch ('Any')('01.01.2009'))~\')
															)/active_pseudo_unit.koeff  kolvo
							   from active,active_type,active_pseudo_unit
							  where active_pseudo_unit.id_active = active.id_active
								and active_pseudo_unit.priz = 1
								and active.id_type_active <> 2
								and active.id_type_active = active_type.id_type
								)
							 where kolvo <> 0
							 
							 minus
							 
							select spc.id_active
							  from spc
							 where spc.id_head = ~($g.d_head@GetValue 'HEAD.ID_HEAD')~
							 ) active_to_add,
							 
							active, active_type, active_pseudo_unit
					  where active_to_add.id_active = active.id_active
					    and active_pseudo_unit.id_active = active.id_active
                                            and active_pseudo_unit.priz = 1
                                            and active.id_type_active = active_type.id_type
							 
					 )"
  } // end of ds

{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel   percent=30
{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"
       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=300    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=350    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=350    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
       value="Исполнитель"  
       left=470  top=8      height=20       width=70
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=personal.fname                border = box
       left=550    top=8    height=20       width=70
       alias=name           font_size=12    font_family=0    bg_color="#ffffff"
       editable = readonly
   }     
   {label
       value="Примечание"    
       left=11    top=33     height=20      width=65
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.comment_sd   border = box
       left=80    top=33    height=20      width=495
       alias=comment_sd         font_size=12   font_family=0    bg_color="#ffffff"
   }
   {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     
   }
   {label
       value="Фильтр по наименованию"    
       left=11    top=58     height=20      width=150
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       type=string   border = box
       left=170    top=58    height=20      width=300
       alias=name_filter         font_size=12   font_family=0    bg_color="#ffffff"
   }
   {button
       left=500    top=58    height=20      width=150
       BACKGROUND = "LIGHTGRAY"    foreground="#000000"
       label = "Показать"
       action = "($g.gridspc@retrieve)"
   }
{button
  left = 11   top = 83   width = 200    height = 25
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Удалить строки с остатками"
  action = "($X
                (s = ($g.d_spc@size))
                (i=0)
                ($while (i<s)
                  (
                   ($g.d_spc@fastSetCurRow i)
                   ($if (($g.radio_del_rows@getValue) == 'greater')
                        ($if (($g.d_spc@getValue 'SPC.Q1_SPC') > g.ost1)
                          (
                            ($g.d_spc@DelRow i)
                            (s -= 1)
                          )
                         $else
                           (i+=1)
                        )
                    $if (($g.radio_del_rows@getValue) == 'lower')
                        ($if (($g.d_spc@getValue 'SPC.Q1_SPC') < g.ost2)
                          (
                            ($g.d_spc@DelRow i)
                            (s -= 1)
                          )
                         $else
                           (i+=1)
                        )
                    $else
                     ($debug '============ shit ! ================')
                   )
                  )
                )
                ($g.d_spc@NotifyViews)
	        ($ret '')
	    )"
}
    {radiogroup  alias=radio_del_rows    bg_color="#c0c0c0"
      top=83 left=220
      {radiobutton  label="<"     bg_color="#c0c0c0"
        value="lower"
        check=yes
      }
      {radiobutton  label=">"    bg_color="#c0c0c0"
        value="greater"
      }
    }
   {field
       type = number  border = box
       value = "0"
       left=260    top=83    height=20      width=50
       alias=ost1       font_size=12   font_family=0    bg_color="#ffffff"
   }
   {field
       type = number  border = box
       value = "0"
       left=260    top=105    height=20      width=50
       alias=ost2       font_size=12   font_family=0    bg_color="#ffffff"
   }
{button
  left = 11   top = 140   width = 200    height = 25
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Установить остаток"
  action = "($X
                (s = ($g.d_spc@size))
                (i=0)
                ($while (i<s)
                  (
                    ($g.d_spc@fastSetCurRow i)
                    ($g.d_spc@setValue 'spc.q1_spc' g.ost3)
                    (i += 1)
                  )
                )
                ($g.d_spc@NotifyViews)
	        ($ret '')
	    )"
}
   {field
       type = number  border = box
       value = "0"
       left=220    top=140    height=25      width=50
       alias=ost3       font_size=14   font_family=0    bg_color="#ffffff"
   }


{button
  left = 500   top = 83   width = 200    height = 25
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Заполнить остатками на складе"
  action = "($X
       	      ($if (($try ($G.d_head@getvalue 'HEAD.ID_DEPARTMENT1') $catch ('any') (0))==0)
                ($g.self@sure 'Не указан склад в документе' 1)
               $else 
		(($g.get_ostat@retrieve)
		 ($if (($g.get_ostat@size)==0)
                   ($g.self@sure 'На данном складе нет товаров' 1)
	          $else
		  ((s=($g.get_ostat@size))
		   (i=0)
 	           (tmp_dop = 0)     
                   ($while (i<s)
                    (($g.get_ostat@SetCurRow i)
		     ($g.d_spc@NewRow)
                     ($g.d_spc@SetValue 'SPC.ID_HEAD' ($g.d_head@GetValue 'HEAD.ID_HEAD'))
                     ($g.d_spc@SetValue 'SPC.ID_ACTIVE' ($g.get_ostat@GetValue 'ID_ACTIVE'))
                     ($g.d_spc@SetValue 'ACTIVE.NAME_ACTIVE' ($g.get_ostat@GetValue 'NAME_ACTIVE'))
                     ($g.d_spc@SetValue 'ACTIVE_TYPE.NAME_TYPE' ($g.get_ostat@GetValue 'NAME_TYPE'))
     		     ($g.d_spc@SetValue 'SPC.ID_UNIT' ($g.get_ostat@GetValue 'ID_PSEUDO_UNIT'))
     		     ($g.d_spc@SetValue 'ACTIVE_PSEUDO_UNIT.OBOZN' ($g.get_ostat@GetValue 'OBOZN'))
                     ($g.d_spc@SetValue 'SPC.Q1_SPC' ($g.get_ostat@GetValue 'KOLVO'))
                     ($g.d_spc@SetValue 'DOC_LIB.GETRESTBEFOREBEFORE(HEAD.ID_DEPARTMENT1,SPC.ID_ACTIVE,HEAD.SORT)' ($g.get_ostat@GetValue 'KOLVO'))
                     ($g.d_spc@SetValue 'SPC.PRICE1_SPC' ($g.get_ostat@GetValue 'PRICE1'))
		     (i+=1)
                    )
                   )
                   ($g.d_spc@NotifyViews)
	          )
                 )
                )
	      )    
	    ($ret ''))"
}

{button
  left = 500   top = 115   width = 400    height = 25
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Добавить позиции, имеющие остатки на складе, с нулевым количеством"
  action = "($X
       	      ($if (($try ($G.d_head@getvalue 'HEAD.ID_DEPARTMENT1') $catch ('any') (0))==0)
                ($g.self@sure 'Не указан склад в документе' 0)
               $else 
               (
			     ($if (($g.self@sure 'Сейчас в документ будет добавлены позиции, которые имеют остатки на складе, с нулевым количеством. Выполнить?' 0) == 0)
				   ($ret '')
				 )
				 ($g.self@actSave)
                 ($g.nulls_for_not_nulls@retrieve)
		         ($if (($g.nulls_for_not_nulls@size)==0)
				   (
                    ($g.self@sure 'Добавлять нечего.' 1)
					($ret '')
				   )
	             $else
		          (
				  (s=($g.nulls_for_not_nulls@size))
		          (i=0)
                   ($while (i<s)
                    (
					 ($g.nulls_for_not_nulls@SetCurRow i)
		             ($g.d_spc@NewRow)
                     ($g.d_spc@SetValue 'SPC.ID_SPC' ds.spk)
                     ($g.d_spc@SetValue 'SPC.ID_HEAD' ($g.d_head@GetValue 'HEAD.ID_HEAD'))
                     ($g.d_spc@SetValue 'SPC.ID_ACTIVE' ($g.nulls_for_not_nulls@GetValue 'ID_ACTIVE'))
                     ($g.d_spc@SetValue 'ACTIVE.NAME_ACTIVE' ($g.nulls_for_not_nulls@GetValue 'NAME_ACTIVE'))
                     ($g.d_spc@SetValue 'ACTIVE_TYPE.NAME_TYPE' ($g.nulls_for_not_nulls@GetValue 'NAME_TYPE'))
     		         ($g.d_spc@SetValue 'SPC.ID_UNIT' ($g.nulls_for_not_nulls@GetValue 'ID_PSEUDO_UNIT'))
     		         ($g.d_spc@SetValue 'ACTIVE_PSEUDO_UNIT.OBOZN' ($g.nulls_for_not_nulls@GetValue 'OBOZN'))
                     ($g.d_spc@SetValue 'SPC.Q1_SPC' 0)
                     ($g.d_spc@SetValue 'DOC_LIB.GETRESTBEFOREBEFORE(HEAD.ID_DEPARTMENT1,SPC.ID_ACTIVE,HEAD.SORT)' ($g.nulls_for_not_nulls@GetValue 'REST'))
                     ($g.d_spc@SetValue 'SPC.PRICE1_SPC' ($g.nulls_for_not_nulls@GetValue 'PRICE1'))
		             (i+=1)
                    )
                   )
                   ($g.d_spc@NotifyViews)
                   (v = ($@validator))
                   ($v@SetType 'NUMBER')
                   ($v@SetMask '##0.')
                   ($g.progress@setValue 'Добавлено строк: ' + ($v@toString i))
	          )
                )
               )
	          )    
	          ($ret '')
			)"
}



{datastore 
        alias = d_head
        query = "select head.id_head,head.id_type_doc,head.accept,
                        head.num_sd,head.date_sd,
                        head.id_department1,department.name1_dep,head.id_department2,
                        head.id_client1,head.id_client2,
                        head.comment_sd,
			head.id_personal,personal.fname,
			head.parent_id_head,
                        head.sort
                   from head,personal,department
                  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_personal = personal.id_personal(+)
                   and head.id_type_doc = 54"
              editable = yes
                  head = yes
                unique = "('head','head.id_head')"
               default = "head.id_head=~ds.hpk~,head.id_type_doc=~54~,
                          head.date_sd=~ds.date~,
                          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~"
} // 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 = 40           titlebar_size = 18            rowsize=20     
addexp="($X
	#($g.d_spc@retrieve)
	(t = ($g.d_spc@iterator))
	(i = 0)
	(is_in = 1)
	($while ($t@next)
	    (
		(i += 1)
		($g.d_spc@SetCurRow (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)
		  #($g.d_spc@delRow (($g.d_spc@size) - 1))
		))
        ))
	($if (is_in == 1) (
		#($g.d_spc@newRow)
		($g.d_spc@setValue 'SPC.ID_ACTIVE' store.active.id_active)
		($g.d_spc@setValue 'ACTIVE.NAME_ACTIVE' store.active.name_active)
		($g.d_spc@setValue 'SPC.ID_UNIT' store.id_pseudo_unit)
		($g.d_spc@setValue 'ACTIVE_PSEUDO_UNIT.OBOZN' store.obozn)
		(global.cur_id_active = store.active.id_active)
		($g.get_active_details@retrieve)
		($g.d_spc@setValue 'DOC_LIB.GETRESTBEFOREBEFORE(HEAD.ID_DEPARTMENT1,SPC.ID_ACTIVE,HEAD.SORT)' ($try ($g.get_active_details@GetValue 'REST') $catch ('Any')('')))
		($g.d_spc@setValue 'SPC.PRICE1_SPC' ($try ($g.get_active_details@GetValue 'PRICE') $catch ('Any')(0)))
	)
	$else (
		($g.d_spc@setCurRow (($g.d_spc@size) - 1))
		($g.d_spc@delRow ($g.d_spc@getCurRow))
	)
	)
	)"

{menu
   {item label = "Поиск в справочнике" action="opennew find_choose.rml 1, 0"}
   {item label = "-"}

   {item label = "История изменений строки" action= "open reports/report_spc_log.rml ~($g.d_spc@getValue 'spc.id_spc')~"}
   {item label = "История изменений документа" action= "open reports/report_spc_log_doc.rml ~($g.d_spc@getValue 'spc.id_head')~"}
}
 {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=right
    alias=war                font_color="#000000"     font_size=12   
 }
 {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="Тип актива" visible = no
    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 
 }
 {column size=60     
    visible=no
    title="Код"              font_family=0
    target=spc.id_unit       title_font_family=2     halignment=left
    alias=id_un                font_color="#000000"     font_size=12   
    editexp = "id_un=STORE.active_pseudo_unit.id_pseudo_unit"
 }
 {column size=60       title="Ед. изм."
    target=active_pseudo_unit.obozn  title_font_family=2     halignment=center
    font_color="#000000"      font_size=12              font_family=0
    alias=name_un             
    editable = handbook     
    edit = "opennew psevdo_units.rml ~($try (war) $catch ('NullException') (-1) )~"
    editexp = "name_un=STORE.active_pseudo_unit.obozn"
    dep = "id_un"
 }
 {column size=100       title="Кол-во " 
    target=spc.q1_spc      title_font_family=2      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"    alias = q1_spc
    dep="summ"
 }
 {column size=80
    target = spc.price1_spc   title="Цена"      title_font_family=2
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"     alias = price1_spc        halignment=right
    dep="summ"
 }
 {column size=80       title="Остаток" visible = yes
    target="DOC_LIB.GETRESTBEFOREBEFORE(HEAD.ID_DEPARTMENT1,SPC.ID_ACTIVE,HEAD.SORT)"
    title_font_family=2      halignment=right
    font_color="#000000"   font_size=12           font_family=0
    editmask = "# #0.000"  editable=no
 }
 {datastore 
      alias = d_spc
      query = "select spc.id_spc,spc.id_head,spc.id_active,spc.id_unit,
                      spc.q1_spc,spc.q2_spc,spc.price1_spc,spc.price2_spc,
                      active.name_active,active_pseudo_unit.obozn,active_type.name_type,
                      doc_lib.getRestBeforeBefore(head.id_department1, spc.id_active, head.sort)
                 from spc,head,active,active_pseudo_unit,active_type
                where spc.id_head = ~($try (d_head.head.id_head) $catch ('NullException') (-1) )~ 
                  and spc.id_head = head.id_head
                  and spc.id_active = active.id_active 
                  and spc.id_unit = active_pseudo_unit.id_pseudo_unit 
                  and active.id_type_active = active_type.id_type
                  ~($if (($try (g.name_filter) $catch ('NullException')('')) != '')
                      (' and upper(active.name_active) like upper(\'%' + g.name_filter + '%\') ')
                    $else ('')
                   )~
             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~,spc.q2_spc=~0~,
			 spc.price1_spc=~0~,spc.price2_spc=~0~"  
} // ds
} // grid1
{grid alias=gridgr1
buttonbar_font_family=0       buttonbar_font_size=12           
buttonbar_size = 30           titlebar_size = 18            
rowsize=20                    multiselect = no           
editable = no
    edit = "~($X
              (nn = ($($G.GRIDGR1@getDatastore)@getValue 'HEAD.ID_HEAD') )
              (nn2 = ($($G.GRIDGR1@getDatastore)@getValue 'TYPE_DOC.DOC_NAME' ) )
             ($ret 'open '+ nn2 +' '+ nn + '; retrieve docs'))~"
        {menu
        {item label = "Обновить" action="retrieve gridgr1"}
        {item label = "Просмотреть" action="
            ~($X
              (nn = ($($G.GRIDGR1@getDatastore)@getValue 'HEAD.ID_HEAD') )
              (nn2 = ($($G.GRIDGR1@getDatastore)@getValue 'TYPE_DOC.DOC_NAME' ) )
             ($ret 'open docs/'+ nn2 +' '+ nn + '; retrieve docs'))~"
	}
	{item label = "-"}
        {item label = "Удалить"
           action = "~($X
                       ($IF (($($G.GRIDGR1@getDatastore)@getValue 'HEAD.ACCEPT' ) == 1)
		             ((tmp = 'Запрещено удалять проведенный документ')
            		      (m = ($g.self@sure tmp 1))
		             )
			$else
	                 ((tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRIDGR1@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.GRIDGR1@getDatastore)@getValue 'HEAD.ID_HEAD') + '); retrieve docs')
	  	         )
		       )
        	      ($ret 'NOTDELETE'))~"
        }
	{item label = "-"}
        {item label = "Провести документ" action= "execute exec ~'doc_lib.accept('+($($G.GRIDGR1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve docs" }        
        {item label = "Отменить проведение" action= "execute exec ~'doc_lib.de_accept('+($($G.GRIDGR1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve docs" }
      }
       {column size=40              title="Номер"             visible=no
	target=head.id_head     
        title_font_family=2         title_font_color="#000000"
	halignment=right            font_color="#0000ff"      font_size = 12        
      }
      {column size=30              title="Статус"
	target=head.accept
        title_font_family=2         halignment=left
	font_color="#000000"        font_size = 12
      }
      {column size=120              title="Тип док."
	target=type_doc.name_type_dok   
        title_font_family=2         halignment=left
	font_color="#000000"        font_size = 12
      }
      {column size=70               title="Номер док."
	target=head.num_sd          title_font_family=2       halignment=left
	font_color="#000000"        font_size=12              font_family=0
      }
      {column size=70               title="Дата док."
	target=head.date_sd         title_font_family=2       halignment=center
	font_color="#000000"        font_size=12              font_family=0
      }
      {column size=150              title="Клиент"
	target=client.name1_client   title_font_family=2       halignment=left
	font_color="#000000"        font_size=12              font_family=0
     }
  {column size=90            title="Сумма"
   target = "UTIL.DOC_SUM(HEAD"
   title_font_family=2        title_font_color="#000000"
   halignment=right           font_size = 12          font_family=0
   editmask = "# #0.00"
  }
  {column size=150              title="Название rml"
   target=type_doc.doc_name   title_font_family=2       halignment=left
   font_color="#000000"        font_size=12              font_family=0
   visible=no
  }
   {datastore
           alias = docs
           query = "select head.id_head,head.accept,head.num_sd,head.date_sd,
			   type_doc.doc_name,type_doc.name_type_dok,
			   client.name1_client,
                      	   util.doc_sum(head.id_head) \"util.doc_sum(head\"
	              from head,client,type_doc
         	     where parent_id_head = ~($try (d_head.head.id_head) $catch ('NullException') (0) )~
                       and head.id_client1 = client.id_client 
                       and head.id_type_doc = type_doc.id_type_doc"
          editable = yes
  } // docs
} // gridgr1

} // 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)
                            )
                        )
      
                 ($ARGUMENTS.1@put 'find' 0)
                 (tmp = ($($@date ($g.d_head@getValue 'HEAD.DATE_SD'))@toPLString))
                 ($ARGUMENTS.1@put 'date_sd' tmp)	                        
                 ($ARGUMENTS.1@put 'id_head' ($g.d_head@getValue 'HEAD.ID_HEAD'))
                 ($debug '1111111111111111: '+ ($ARGUMENTS.1@get 'find')+' ; '+ ($ARGUMENTS.1@get 'date_sd')+' ; '+ ($ARGUMENTS.1@get 'id_head'))
                        
                        #($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 = "
     ($X
            ($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)
                )
            )

  
                 ($ARGUMENTS.1@put 'find' 0)
                 (tmp = ($($@date ($g.d_head@getValue 'HEAD.DATE_SD'))@toPLString))
                 ($ARGUMENTS.1@put 'date_sd' tmp)	                        
                 ($ARGUMENTS.1@put 'id_head' ($g.d_head@getValue 'HEAD.ID_HEAD'))
                 ($debug '1111111111111111: '+ ($ARGUMENTS.1@get 'find')+' ; '+ ($ARGUMENTS.1@get 'date_sd')+' ; '+ ($ARGUMENTS.1@get 'id_head'))
            
            #($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

