Cp1251
DOC 
foreground = lightgray
document_width = 700
document_height = 300
document_title = "ZetaSE.Autocomplect/ Аналоги"

{ datastore
  alias = child_doc
  query = "select id_head from head where parent_id_head = ~ARGUMENTS.1~"
}


{toolbar
{grid
editable = yes
alias = GRIDPROD
buttonbar_font_family=0       buttonbar_font_size=12           
buttonbar_size = 30           titlebar_size = 18            rowsize=20
titlebar_height = 30

del = ""

addexp="($X
          ($ret '')

	)"



 {column size=50     
    title="Код"              font_family=0            editable = readonly 
    target=id_active     title_font_family=0      halignment=center
    font_color="#000000"     font_size=12
    editmask = "##0."
    visible = no
 }
 {column size=250       title="Название"
    target=name_active  title_font_family=0     halignment=left
    font_color="#000000"      font_size=12              font_family=0 font_face = "Tahoma"
    editable = readonly 
 }
 {column size=100       title="Остаток"
    target=rest  title_font_family=0     halignment=right
    font_color="#000000"      font_size=12              font_family=0 font_face = "Tahoma"
    editmask = "# #0.000"
    editable = readonly 
 }
 {column size=100       title="Кол-во"
    target=q1_spc  title_font_family=0     halignment=right
    font_color="#000000"      font_size=12              font_family=0 font_face = "Tahoma"
    editmask = "# #0.000"
 }

 {datastore 
      alias = ds_prod
      query = "select id_active, name_active, rest, q1_spc
                 from (
               select active.id_active, active.name_active,
                      doc_lib.getRestBefore(~ARGUMENTS.2~, active.id_active, 1e20) rest,
                      case 
                          when rownum = 1 then ~ARGUMENTS.3~ 
                          else 0
                      end q1_spc
                 from active
                where active.id_active = ~ARGUMENTS.0~ or active.analog_id = ~ARGUMENTS.0~ or active.id_active in (select analog_id from active where id_active = ~ARGUMENTS.0~)
                      )
                order by name_active
                  "


} // ds
} //grid
{button
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Сохранить (Ctrl+Enter)"
  shortcut = "Ctrl+Enter"
  action = "($X
                # перемещение (head) должно делаться в момент заполнения заявки, проверяем, что оно есть
                ($g.child_doc@retrieve)
                ($if (($g.child_doc@size) == 0)
                  (
                     ($g.self@sure 'Ошибка в алгоритме - не найдено соответствующее заявке перемещение. Создайте новую заявку на выдачу материалов.' 1)
                     ($ret '')
                  )
                )
                (global.id_head_move = ($g.child_doc@getValue 'id_head'))
                (i = 0)
                (sz = ($g.ds_prod@size))
                ($while (i < sz)
                  (
                    ($g.ds_prod@fastSetCurRow i)
                    ($g.self@doAction 'execute exec util.update_movement(' + ARGUMENTS.1 + ', ' + ($g.ds_prod@getValue 'id_active') + ', ' + ($g.ds_prod@getValue 'q1_spc') + ')')
                    ($g.self@doAction 'execute exec util.update_movement(' + global.id_head_move + ', ' + ($g.ds_prod@getValue 'id_active') + ', ' + ($g.ds_prod@getValue 'q1_spc') + ')')
                    (i += 1)
                  )
                )
                ($g.self@doAction 'execute exec commit')
                ($g.self@actDok)
                ($ret '')
            )"
}
{button
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Выход (ESC)"
  action = "($X
               ($g.self@actcancel)
               ($ret '')
            )"
  shortcut = "escape"
}
} // toolbar

