Cp1251
DOC 
foreground = lightgray
document_width = 1000
document_height = 700
document_title = "ZetaSE.Autocomplect/ Материалы для производства продукции"

preloadscript="

(global.sklad = '465')
(global.sklad_tseh = '445')
(global.id_head = -1)
(global.id_active = -1)
(global.spc_operation = 'no')

($defun paint1<arg>
  ($X
    (i = 0)
    (sz = ($g.d_spc@size))
    (rrr = ($g.d_spc@getCurRow))
    ($while (i < sz)
     (
       ($g.d_spc@fastSetCurRow i)
       ($if (($g.d_spc@getValue 'sort') == 1)

           (
             (j = 0)
             ($while (j < 11)
               (
                 ($g.gridspc@setcellbgcolor i j 'WHITE')
                 (j += 1)
               )
             )
           )
         $else
           (
             (j = 0)
             ($while (j < 11)
               (
                 ($g.gridspc@setcellbgcolor i j '#FFCCCC')
                 (j += 1)
               )
             )
           )
       )
       (i += 1)
     )
    )
    ($g.d_spc@setCurRow rrr)
    ($g.d_spc@notifyViews)
    ($g.gridspc@repaint)
    ($ret '')
  )
)
"

postloadscript = "($X
                     ($paint1 0)
                     ($Ret '')
                  )"

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

{ datastore
  alias = get_rest
  query = "select rest1, rest2
             from (
           select   doc_lib.getRestBefore(
                                          (select id_department1 from head where id_head = ~($try (ARGUMENTS.0) $catch ('any') (-1))~),
                                          ~global.id_active~,
                                          (select sort from head where id_head = ~($try (ARGUMENTS.0) $catch ('any') (-1))~)
                                        ) rest1,
                    doc_lib.getRestBefore(
                                           (select dep1 from department where id_department = 
                                             (select id_department1 from head where id_head = ~($try (ARGUMENTS.0) $catch ('any') (-1))~)
                                           ),
                                          ~global.id_active~,
                                          (select sort from head where id_head = ~($try (ARGUMENTS.0) $catch ('any') (-1))~)
                                        ) rest2

           from dual
                  )"
}

{datastore  alias=check_month
    query="select active.id_active, active.name_active
             from active, spc, head
            where head.date_sd between trunc(to_date('~($g.d_head@getValue 'date_sd')~', 'dd.mm.yyyy'), 'month')
                                   and last_day(to_date('~($g.d_head@getValue 'date_sd')~', 'dd.mm.yyyy'))
              and head.id_type_doc = 17
              and spc.id_head = head.id_head
              and spc.id_active = ~(global.id_active)~
              and head.id_active = active.id_active
              
            union 
            
           select active_prod.id_active, active_prod.name_active
             from active active_prod, spc, head, spc spc_spec, head head_spec
            where head.date_sd between trunc(to_date('~($g.d_head@getValue 'date_sd')~', 'dd.mm.yyyy'), 'month')
                                   and last_day(to_date('~($g.d_head@getValue 'date_sd')~', 'dd.mm.yyyy'))
              and head.id_type_doc = 17
              and head.id_head != ~($try (ARGUMENTS.0) $catch ('NullException') (0) )~
              and spc.id_head = head.id_head
              and head.id_active = active_prod.id_active
              and nvl(active_prod.id_head2, active_prod.id_head) = head_spec.id_head
              and head_spec.id_head = spc_spec.id_head
              and spc_spec.id_active = ~(global.id_active)~
            "
} // end of ds


{dscollection
   alias = ds
   seqquery = "select spc_sq.nextval from dual"
   seqnames = "spk"
}


{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel type = horizontal  percent=15
{splitpanel type = vertical percent = 40
{form width=780 height=100       bg_color="#c0c0c0"   alias = fm
   {label
       value="Готовая продукция"
       left=11    top=20     height=25      width=110
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.id_active  border = box
       left=130    top=20    height=25      width=495
       alias=id__active         font_size=12   font_family=0    bg_color="#ffffff"
       visible = no
   }
   {field
       target=active.name_active   border = box
       left=130    top=20    height=25      width=300
       alias=name__active         font_size=12   font_family=0    bg_color="#ffffff"
       halignment = left
       editable = readonly
   }
   {label
       value="Кол-во"
       left=10    top=60     height=25      width=50
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.sum1_sd   border = box
       left=60    top=60    height=25      width=70
       alias=sum1__sd         font_size=12   font_family=0    bg_color="#ffffff"
       editmask = "# #0.000"  halignment = right
       editable = readonly
   }
   {label
       value="Ед. изм."
       left=150    top=60     height=25      width=50
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.id_unit  border = box
       left=200    top=20    height=25      width=495
       alias=id__unit         font_size=12   font_family=0    bg_color="#ffffff"
       visible = no
   }
   {field
       target=active_pseudo_unit.obozn   border = box
       left=200    top=60    height=25      width=70
       alias=name__unit         font_size=12   font_family=0    bg_color="#ffffff"
       editable = readonly
       halignment = left
   }

   {label
       value="Склад"        
       left=5    top=90    height=20       width=50
       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=60    top=90    height=25       width=210
       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"
   }


{button
  left = 350  top = 60 width = 100    height = 30
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Перемещение"
  action = "($X
                ($if (($g.d_head@getValue 'head.id_department1') == 0)
                  (
                     ($g.self@sure 'Не указан склад.' 1)
                     ($ret '')
                  )
                )

                (global.id_head = ($try (ARGUMENTS.0) $catch ('any') (-1)))
                ($g.child_doc@retrieve)
                ($if (($g.child_doc@size) > 0)
                  (
                     ($g.self@sure 'Перемещение уже есть.' 1)
                     ($ret '')
                  )
                )
                ($g.self@doAction 'execute exec util.create_movement(' + ($try (ARGUMENTS.0) $catch ('any') (-1)) + ')')
                ($g.gridspc@retrieve)
                ($paint1 0)
                ($ret '')
            )"
}

{button
  left = 350  top = 90 width = 100    height = 30
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Отменить"
  action = "($X
                (global.id_head = ($try (ARGUMENTS.0) $catch ('any') (-1)))
                ($g.child_doc@retrieve)
                ($if (($g.child_doc@size) > 0)
                  (
                    ($g.self@doAction 'execute exec util.del_doc(' + ($g.child_doc@getValue 'id_head') + ')')
                    ($g.gridspc@retrieve)
                    ($paint1 0)
                  )
                 $else
                   (
                     ($g.self@sure 'Перемещения нет.' 1)
                   )
                )
                ($ret '')
            )"
}


{button
  left = 72  top = 250 width = 200    height = 30
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Тест (Bug 790)"
  action = "($X
                ($($g.self@getAliases)@put '_DS' g.d_spc) 
                ($g.self@doAction 'open pech_form/pech_form_zvm_test.rml &_DS')
                ($ret '')
            )"
}

{datastore 
        alias = d_head
        query = "select head.id_head, head.sort, head.id_active, head.id_department1, active.name_active, head.id_unit,
                        to_char(head.date_sd, 'dd.mm.yyyy') date_sd,
			active_pseudo_unit.id_pseudo_unit, active_pseudo_unit.obozn,
			head.sum1_sd, department.name1_dep
                   from head, active, active_pseudo_unit, department
                  where head.id_head = ~($try (ARGUMENTS.0) $catch ('any') (-1))~
                   and head.id_active = active.id_active
                   and head.id_unit = active_pseudo_unit.id_pseudo_unit
                   and head.id_department1 = department.id_department"
             editable = yes
               unique = "('head','head.id_head')" 
} // ds
} // form
{splitpanel type = vertical  percent=40
  {grid
      alias = GRID_WORK_STAGE
      buttonbar_font_family = 0              buttonbar_font_size = 12
      buttonbar_size = 30                    titlebar_size = 18
      multiselect = no                      editable = no
      rowsize = 20
                del = "~($X
                           ($ret '') 
                        )~"

     {column size=100             title="work_stage.id_work_stage"  visible = no
          target=work_stage.id_work_stage
     }                  
     {column size=100             title="Этап сборки"
          target=work_stage.name_work_stage
          title_font_family=2        title_font_color="#000000"
          halignment=left            font_size = 12          font_family=0
     }                  

    {datastore 
             alias = GRIDDS_WORK_STAGE
             query = "select work_stage.id_work_stage, work_stage.name_work_stage
                        from work_stage
                       where work_stage.id_work_stage not in (0, 6)

                       union all

                      select -999 id_work_stage, '-- все этапы --' name_work_stage
                        from dual

                       order by name_work_stage"
                editable = no

                 selaction = "~($X
                                  ($g.grid1@retrieve)
                                  ($g.gridspc@retrieve)
                                  ($paint1 0)
                                  ($ret '')
                               )~"

     } // end of ds
  } // end of grid
  {grid
   editable = no
   alias = GRID1
   buttonbar_font_family=0       buttonbar_font_size=12           
   buttonbar_size = 30           titlebar_size = 18            rowsize=25     
   titlebar_height = 0

    {column size=150       title="Группа"
       target=name_active  title_font_family=2     halignment=left
       font_color="#000000"      font_size=12              font_family=0
       alias=name_w              editable = readonly 
    }

   {datastore
    alias = gr
    query = "select id_active, name_active
               from (
             select -1000000 id_active, '/   показать все' name_active
               from dual
              union all
             select distinct util.rootActiveID(id_active) id_active, util.rootActiveName(id_active) name_active
               from (
                      select distinct active_material.id_active
                        from head, active active_prod, active active_material, head head_spec, spc spc_spec
                       where head.id_head = ~($try (ARGUMENTS.0) $catch ('NullException') (0) )~
                         and head.id_active = active_prod.id_active
                         and active_prod.id_head2 = head_spec.id_head
                         and head_spec.id_head = spc_spec.id_head
                         and spc_spec.id_active = active_material.id_active
                                  ~($if (($g.gridds_work_stage@size) > 0)
                                                         ($if (($g.gridds_work_stage@getValue 'work_stage.id_work_stage') != -999)
                                                            (' and spc_spec.work_type = ' + ($g.gridds_work_stage@getValue 'work_stage.id_work_stage'))
                                                          $else ('
                                                          -- all work stages
                                                          ')
                                                         )

                                                        $else ('
                                                          -- all work stages
                                                          ')

                                    )~
                    )
                    )
              order by name_active"

                 selaction = "~($X
                                  ($g.gridspc@retrieve)
                                  ($paint1 0)
                                  ($ret '')
                               )~"
   } // datastore
  } // 
} // vertical split
} // vertical split
{grid
editable = yes
alias = GRIDSPC
buttonbar_font_family=0       buttonbar_font_size=12           
buttonbar_size = 30           titlebar_size = 18            rowsize=20
titlebar_height = 60

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)
              ))
            )
          )
          ($if (is_in == 1)
            (
              (global.id_active = store.active.id_active)
              ($g.check_month@retrieve)
              ($if (($g.check_month@size) > 0)
                (
                  (msg = 'Этот материал уже использовался в текущем месяце для следующей готовой продукции:%%')
                  (i = 0)
                  (sz = ($g.check_month@size))
                  ($while (i < sz)
                    (
                      ($g.check_month@setCurRow i)
                      ($if (i > 3)
                        (
                          (msg += '%...%(список неполный)%')
                          (i = sz)
                        )
                       $else
                        (msg += '(' + ($($g.check_month@getValue 'active.id_active')@int) + ') ' + ($g.check_month@getValue 'active.name_active') + '%')
                      )
                      (i += 1)
                    )
                  )

                  (msg += '%%Все равно добавить его?')
                  ($if (($g.self@sure msg 0) == 0)
                    (is_in = 0)
                  )
                )
              )
            )
          )
          ($if (is_in == 1)
            (
              ($g.d_spc@setValue 'SPC.ID_ACTIVE' store.active.id_active)
              ($g.d_spc@setValue 'NAME_ACTIVE' store.active.name_active)
              ($g.d_spc@setValue 'SPC.ID_UNIT' store.id_pseudo_unit)
              ($g.d_spc@setValue 'OBOZN' store.obozn)
              (global.id_active = store.active.id_active)
              ($g.get_rest@retrieve)
              ($g.d_spc@setValue 'q_dep1' ($g.get_rest@GetValue 'REST1'))
              ($g.d_spc@setValue 'q_spc' 0)
              ($g.d_spc@setValue 'q_dep1_after' ($g.get_rest@GetValue 'REST1'))
              ($g.d_spc@setValue 'q_dep2' ($g.get_rest@GetValue 'REST2'))
              ($if (global.spc_operation == 'change')
                (
                  ($g.d_spc@setValue 'replace_material' global.name_active) 
                  ($g.d_spc@setValue 'spc.parent_id_spc' global.parent_id_active) 
                )
              )
            )
            $else (
              ($g.d_spc@delRow ($g.d_spc@getCurRow))
            )
          )
          ($g.d_spc@setCurRow rrr)
          ($paint1 0)
          ($ret '')

	)"



{menu
   {item label = "Добавить" action="~($X (global.spc_operation = 'add') ($ret '') )~
                                    opennew find_choose.rml 1, 0"}
   {item label = "-"}
   {item label = "Удалить" action="~($X
                                        #($if (($g.d_spc@getValue 'sort') == 1)
                                        #  (
                                        #    ($g.self@sure 'Можно удалять только строки, внесенные помимо спецификации.' 1)
                                        #    ($ret '')
                                        #  )
                                        #)
                                        
                                        ($g.d_spc@delRow ($g.d_spc@getCurRow))
                                        ($g.d_spc@notifyViews)
                                        ($paint1 0)
                                        ($ret '')
                                    )~"
   }
   {item label = "-"}
   {item label = "Выгрузка в Excel"
    action = "~($X
                   
                  (global.grid_name = 'GRIDSPC')
                  ($g.self@calculate 'js:js_file:/docs/print_grid.js')
                  ($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=200       title="Наименование"
    target=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=80       title="<html>Остаток<br>Ренталком</html>" 
    target=q_dep1     title_font_family=0      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"   editable = readonly    alias = q_dep1
 }
 {column size=70       title="<html>Кол-во<br>для 1 ед.<BR>продукции</html>" 
    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=70       title="<html>Кол-во<br>для произ-<BR>водства</html>" 
    target=q_spc      title_font_family=0      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"   editable = readonly
    alias = total_q_spc
    exp = "total_q_spc = q1_spc*g.sum1__sd"
 }
 {column size=70       title="<html>Перемещено<br>в пр-во</html>" 
    target=q_moved      title_font_family=0      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"
    editable = readonly
 }
 {column size=70       title="<html>Выдано<br>в цех</html>" 
    target=spc.q2_spc      title_font_family=0      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"
    alias = sent_q_spc
    dep = "per_ost_q_spc"
 }
 {column size=70       title="<html>Переходящий<br>остаток</html>" 
    target=q_per_ost   title_font_family=0      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"
    alias = per_ost_q_spc
    exp = "per_ost_q_spc = sent_q_spc - total_q_spc"
    editable = readonly 
 }
 {column size=80       title="<html>Остаток<br>на складе<br>после выдачи</html>" 
    target=q_dep1_after      title_font_family=0      halignment=right  alias = q_dep1_after
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"    editable = readonly 
    exp = "q_dep1_after = q_dep1 - total_q_spc"
 }
// {column size=70       title="<html>Перемещено<br>в цех</html>" 
//    target=q_moved      title_font_family=0      halignment=right
//    font_color="#000000"     font_size=12            font_family=0
//    editmask = "# #0.000"    editable = readonly 
// }
 {column size=70       title="<html>Остаток<br>Цех</html>" 
    target=q_dep2      title_font_family=0      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"    editable = readonly 
 }
 {column size=150       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, sort, spc.id_active, spc.id_unit, spc.q1_spc, spc.q1_spc, spc.q2_spc, spc.parent_id_spc,
                      name_active, obozn, spc.comments, replace_material,
                      date_sd, num_sd, kod_prod, kolvo_prod, unit_prod, name_prod, comment_sd,
                      q_dep1, q_dep11, q_dep1 - q1_spc q_dep1_after, q_moved, q_dep2, q_dep22,
                      q_spc, q_per_ost,
                      0 type_zvm

                   from (
                          select 1 sort, to_char(head.date_sd, 'dd.mm.yyyy') date_sd, head.num_sd, 0 id_Spc, spc_spec.id_head, spc_spec.id_unit,
                                 active_material.id_active, active_material.name_active, active_pseudo_unit.obozn,
                                 spc_spec.q1_spc,
                                 0 q2_spc,
                                 spc_spec.q1_spc*head.sum1_sd q_spc,
                                 0 q_per_ost,
                                 nvl(spc_spec.comments, ' ') comments,
                                 head.sum1_sd kolvo_prod, active_pseudo_unit_prod.obozn unit_prod, nvl(head.comment_sd, ' ') comment_sd,
                                 spc_spec.work_type, active_prod.id_active kod_prod, active_prod.name_active name_prod,
                                   doc_lib.getRestAnalogBeforeAll(active_material.id_active,
                                                                  1e30,
                                                                  '~global.sklad~'
                                                                 ) q_dep1, 
                                   0 q_dep11, 


                                   doc_lib.getRestAnalogBeforeAll(active_material.id_active,
                                                                  1e30,
                                                                  '~global.sklad_tseh~'
                                                                 ) q_dep2, 
                                   0 q_dep22, 

                                 util.moved_to_production_analog_2(active_material.id_active,
                                                 trunc(head.date_sd, 'month'),
                                                 last_day(trunc(head.date_sd, 'month')),
                                                 '~global.sklad~') q_moved,
                                --0 q_moved,
                                null parent_id_spc,
                                null replace_material

                            from head, active active_material, active active_prod, active_pseudo_unit,
                                 active_pseudo_unit active_pseudo_unit_prod, head head_spec, spc spc_spec,
                                 department
                           where head.id_head = ~($try (ARGUMENTS.0) $catch ('NullException') (0) )~
                             and head.id_department1 = department.id_department
                             and head.id_active = active_prod.id_active
                             and active_prod.id_head2 = head_spec.id_head
                             and head_spec.id_head = spc_spec.id_head
                             and spc_spec.id_unit = active_pseudo_unit.id_pseudo_unit 
                             and head.id_unit = active_pseudo_unit_prod.id_pseudo_unit
                             and spc_spec.id_active = active_material.id_active
                             and not exists (select 1 from spc s where s.id_head = head.id_head and s.parent_id_spc = spc_spec.id_active)
                             -- кроме группы Прочие материалы
                             --and spc_spec.id_active not in ( select id_active from active connect by prior id_active = parent_act_id start with id_active = 13292 )

                        union all                                  

                          select 2 sort, to_char(head.date_sd, 'dd.mm.yyyy') date_sd, head.num_sd, spc.id_spc, spc.id_head, spc.id_unit,
                                 active_material.id_active, active_material.name_active, active_pseudo_unit.obozn,
                                 spc.q1_spc,
                                 spc.q2_spc,
                                 spc.q1_spc*head.sum1_sd q_spc,
                                 spc.q2_spc - spc.q1_spc*head.sum1_sd q_per_ost,
                                 nvl(spc.comments, ' ') comments,
                                 head.sum1_sd, '', head.comment_sd,
                                 spc.work_type, 0 kod_prod, '' name_prod,
                                   doc_lib.getRestAnalogBeforeAll(active_material.id_active,
                                                                  1e30,
                                                                  '206,306,209'
                                                                 ) q_dep1, 
                                   doc_lib.getRestAnalogBeforeAll(active_material.id_active,
                                                                  1e30,
                                                                  '210'
                                                                 ) q_dep11, 


                                   doc_lib.getRestAnalogBeforeAll(active_material.id_active,
                                                                  1e30,
                                                                  '208'
                                                                 ) q_dep2, 
                                   doc_lib.getRestAnalogBeforeAll(active_material.id_active,
                                                                  1e30,
                                                                  '225'
                                                                 ) q_dep22, 

                                 util.moved_to_production_analog_2(active_material.id_active,
                                                 trunc(head.date_sd, 'month'),
                                                 last_day(trunc(head.date_sd, 'month')),
                                                 '~global.sklad~') q_moved,
                                --0 q_moved,
                                spc.parent_id_spc,
                                active_parent.name_active replace_material
                            from spc, active active_material, active_pseudo_unit, head, department, active active_parent
                           where spc.id_head = ~($try (ARGUMENTS.0) $catch ('NullException') (0) )~
                             and head.id_department1 = department.id_department
                             and spc.id_head = head.id_head
                             and active_material.id_Active = spc.id_active
                             and spc.id_unit = active_pseudo_unit.id_pseudo_unit 
                             and spc.parent_id_spc = active_parent.id_active (+)
                             -- кроме группы Прочие материалы
                             --and spc.id_active not in ( select id_active from active connect by prior id_active = parent_act_id start with id_active = 13292 )
                        ) spc

                 where 1=1

               ~($if (($try ($g.gr@getValue 'id_active') $catch ('Any')(-1000000)) == -1000000)
                    ( ' ' )
                 $else
                    ('
                      and id_active
                       in (
                           select active.id_active
                             from active
                          connect by prior id_active = parent_act_id
                            start with id_active = ' + ($try ($g.gr@getValue 'id_active') $catch ('Any')(-1000000)) + '
                          )
                     ')
                 )~

               ~($if (($g.gridds_work_stage@size) > 0)
                  ($if (($g.gridds_work_stage@getValue 'work_stage.id_work_stage') != -999)
                    (' and work_type = ' + ($g.gridds_work_stage@getValue 'work_stage.id_work_stage') )
                   $else ('
                           -- all work stages
                         ')
                  )
                  $else ('
                           -- all work stages
                         ')
                )~

                  order by name_active
                  "
             editable = yes
               unique = "('spc','spc.id_spc')" 
              default = "spc.id_head=~($try (ARGUMENTS.0) $catch ('NullException') (0) )~,
                         spc.id_spc=~ds.spk~,
			 spc.q1_spc=~0~,
			 spc.q2_spc=~0~,
			 sort=~2~"  


} // ds
} // grid
} // horizontal split
{button
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Сохранить"
  action = "($X
                ($g.self@actDok)
                ($ret '')
            )"
}
{button
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Печать (Ctrl+P)"
  action = "($X
                ($($g.self@getAliases)@put '_DS' g.d_spc) 
                ($g.self@doAction 'open pech_form/pech_form_zvm.rml &_DS')
                ($ret '')
            )"
  shortcut = "Ctrl+P"
}
{button
  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

