Cp1251
DOC
foreground = lightgray 
document_width = 750
document_height = 350
document_title = "Спецификация продукции"
style = "style/group.st"
preloadscript="
(global.id_h = 0)
(global.loading = 1)
(global.no_combo_action = 0)
"
postloadscript = "($X
(global.loading = 0)
($g.self@doAction 'retrieve combo1')
($ret '')
)
"

{ datastore
  alias = check_privileges
  query = "select id_group
             from personal
            where UPPER(login) = UPPER(user)"
}

{ datastore
  alias = check_proiz
  query = "select head.id_head, head.num_sd, to_char(head.date_sd, 'dd.mm.yyyy') datedoc
             from head, spc, active
            where head.date_sd between trunc(sysdate, 'year') and trunc(sysdate, 'year') + 364
              and head.id_type_doc = 14
              and head.id_head = spc.id_head
              and spc.id_active = active.id_active
              and active.id_head2 = ~($try ($g.gridds01@getValue 'head.id_head') $catch ('NullException')(0))~
              "
}

{ datastore
  alias = search_ds
  query = "select id_active
             from active
            where UPPER(name_active) ~($if (($g.check_exact@getValue) == '1')
                                         (' = UPPER(\'' + ($try (g.search_string2) $catch ('NullException')('')) + '\')')
                                       $else
                                         (' like UPPER(\'%' + ($try (g.search_string2) $catch ('NullException')('')) + '%\')')
                                      )~
           "
}



{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel type=horizontal     percent=40
{splitpanel type=vertical     percent=25
{form
  { label left = 10 top = 10 width = 200 height = 30 font_size = 12 font_face = tahoma value = "Поиск по названию" }
  { label left = 10 top = 50 width = 70 height = 30 font_size = 12 font_face = tahoma value = "Продукция" }
  { field left = 80 top = 50 width = 150 height = 30  font_size = 16 alias = search_string1  type = string   firstfocus = yes  dep = "search1" }
  { label left = 10 top = 80 width = 70 height = 30 font_size = 12 font_face = tahoma value = "Материал" }
  { field left = 80 top = 80 width = 150 height = 30  font_size = 16 alias = search_string2  type = string  dep = "search1" }
  {checkgroup  left=240  top=80
   {checkbox  label="Точное совпадение"
     alias=check_exact       font_size = 12 font_face = tahoma
     onvalue="1"  offvalue="0"  check=yes
     action = "~($X
                 ($g.grid_group1@retrieve)
                 ($if (($($g.grid_group1@getDatastore)@size) > 0)
                   (
                    ($g.grid3@retrieve)
                   )
                 )
                 (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
                 ($ret '')
               )~"
   }
  }

  { field left = 30 top = 100 width = 150 height = 30 visible = no alias = search1
    exp = "($X
                 ($g.grid_group1@retrieve)
                 ($if (($($g.grid_group1@getDatastore)@size) > 0)
                   (
                    ($g.grid3@retrieve)
                   )
                 )
                 (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
                 ($ret '')
              )"
  }
  { label left = 10 top = 120 width = 120 height = 20  font_size = 12
    value = "технологическая"
  }
  { label left = 10 top = 140 width = 120 height = 20  font_size = 12
    value = "контрольная сумма"
  }
  { field left = 130 top = 135 width = 100 height = 25  font_size = 16 alias = sum1  type = number  editmask = "# #0.000" halignment = right
  }
  { label left = 10 top = 170 width = 80 height = 20  font_size = 12 font_face = tahoma
    value = "Статус"
  }
  {checkgroup  left=90  top=170
    {checkbox  label="Утвержденные"
      alias=check_status1        font_size = 12 font_face = tahoma
      onvalue="1"  offvalue="0"  check=yes
      action = "~($X
                   ($g.grid_group1@retrieve)
                   ($ret '')
                )~"
    }
    {checkbox  label="Удаленные"
      alias=check_status2        font_size = 12 font_face = tahoma
      onvalue="1"  offvalue="0"  check=no
      action = "~($X
                   ($g.grid_group1@retrieve)
                   ($ret '')
                )~"
    }
  }

} // end of form
{grid
    alias = GRID_GROUP1
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselect = no                      editable = no
    rowsize = 20
    del = ""
    edit = "opennew docs/doc_spec.rml ~($g.gridds01@getValue 'head.id_head')~; retrieve grid_group1; retrieve grid3"

   {menu
        {item label = "Создать новую спецификацию"
          action="~($X 
                	     ($g.check_privileges@retrieve)
                	     ($debug 'ID_GROUP = ' + ($g.check_privileges@GetValue 'ID_GROUP'))	     
                             ($if (($g.check_privileges@GetValue 'ID_GROUP') > 4)
                		(
                	     	  ($g.self@sure 'Недостаточно привилегий, у вас есть доступ только на просмотр.' 1)
                	     	  ($ret '')
                		)
                	     )
                      ($g.self@doAction 'createnew docs/doc_spec.rml -1, -1, 3')
                      ($g.grid_group1@retrieve)
                      ($if (($($g.grid_group1@getDatastore)@size) > 0)
                        (
                         ($g.grid3@retrieve)
                        )
                      )
                      (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
                      ($ret '') 
                   )~"
        }
        {item label = "Скопировать спецификацию"
          action="~($X 
                	     ($g.check_privileges@retrieve)
                	     ($debug 'ID_GROUP = ' + ($g.check_privileges@GetValue 'ID_GROUP'))	     
                             ($if (($g.check_privileges@GetValue 'ID_GROUP') > 4)
                		(
                	     	  ($g.self@sure 'Недостаточно привилегий, у вас есть доступ только на просмотр.' 1)
                	     	  ($ret '')
                		)
                	     )
                      ($g.self@doAction 'createnew docs/doc_spec.rml -1, ' + ($g.gridds01@getValue 'head.id_head') + ', 3')
                      ($g.grid_group1@retrieve)
                      ($if (($($g.grid_group1@getDatastore)@size) > 0)
                        (
                         ($g.grid3@retrieve)
                        )
                      )
                      (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
                      ($ret '') 
                   )~"
        }
        {item label = "Утвердить спецификацию"
           action = "~($X
                	     ($g.check_privileges@retrieve)
                	     ($debug 'ID_GROUP = ' + ($g.check_privileges@GetValue 'ID_GROUP'))	     
                             ($if (($g.check_privileges@GetValue 'ID_GROUP') > 4)
                		(
                	     	  ($g.self@sure 'Недостаточно привилегий, у вас есть доступ только на просмотр.' 1)
                	     	  ($ret '')
                		)
                	     )
	                  ($g.self@doAction 'execute exec update head set accept = 3 where id_head = ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD'))
	                  ($g.self@doAction 'retrieve grid_group1')
                          ($if (($($g.grid_group1@getDatastore)@size) > 0)
                            (
                             ($g.grid3@retrieve)
                            )
                          )
                          (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
		      ($ret '')
		     )~"
        }
        {item label = "Удалить спецификацию"
           action = "~($X
                	     ($g.check_privileges@retrieve)
                	     ($debug 'ID_GROUP = ' + ($g.check_privileges@GetValue 'ID_GROUP'))	     
                             ($if (($g.check_privileges@GetValue 'ID_GROUP') > 4)
                		(
                	     	  ($g.self@sure 'Недостаточно привилегий, у вас есть доступ только на просмотр.' 1)
                	     	  ($ret '')
                		)
                	     )
                	 ($g.check_proiz@retrieve)
                	 ($if (($g.check_proiz@size) > 0)
                	   ($if (($g.self@sure 'Спецификация используется в производстве текущего года. ' + ($g.check_proiz@getValue 'head.num_sd') + ' от ' + ($g.check_proiz@getValue 'datedoc') + ' %%Точно удалить? ' 0) == 0)
                	     ($ret '')
                	   )
                	  $else
                	   (
                	     (tmp = 'Удалить спецификацию. Вы уверены?')
	                     (m = ($g.self@sure tmp 0))
                             ($if (m == 0) ($ret '') )
                           )
                	 )
	                  ($g.self@doAction 'execute exec update head set accept = 0 where id_head = ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD'))
	                  ($g.self@doAction 'retrieve grid_group1')
                          ($if (($($g.grid_group1@getDatastore)@size) > 0)
                            (
                             ($g.grid3@retrieve)
                            )
                          )
                          (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
		      ($ret '')
		     )~"
        }
        {item label = "Удалить окончательно"
           action = "~($X
                	     ($g.check_privileges@retrieve)
                	     ($debug 'ID_GROUP = ' + ($g.check_privileges@GetValue 'ID_GROUP'))	     
                             ($if (($g.check_privileges@GetValue 'ID_GROUP') > 4)
                		(
                	     	  ($g.self@sure 'Недостаточно привилегий, у вас есть доступ только на просмотр.' 1)
                	     	  ($ret '')
                		)
                	     )
                	 ($g.check_proiz@retrieve)
                	 ($if (($g.check_proiz@size) > 0)
                	   ($if (($g.self@sure 'Спецификация используется в производстве текущего года. ' + ($g.check_proiz@getValue 'head.num_sd') + ' от ' + ($g.check_proiz@getValue 'datedoc') + ' %%Точно удалить? ' 0) == 0)
                	     ($ret '')
                	   )
                         )
     	                 (tmp = 'Удалить спецификацию БЕЗ ВОЗМОЖНОСТИ ВОССТАНОВЛЕНИЯ. Вы уверены?')
     	                  (m = ($g.self@sure tmp 0))
     	                  ($if (m == 0)
     	                   ($ret '')
     	                  )
	                  ($g.self@doAction 'execute exec util.del_doc(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD') +')')
	                  ($g.self@doAction 'retrieve grid_group1')
                          ($if (($($g.grid_group1@getDatastore)@size) > 0)
                            (
                             ($g.grid3@retrieve)
                            )
                          )
                          (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
		      ($ret '')
		     )~"
        }

        {item label = "Контроль цен" action= "open reports/report_price_diff1.rml ~($g.gridds01@getValue 'head.id_head')~"}
        {item label = "История изменений документа" action= "open reports/report_spc_log_doc.rml ~($g.gridds01@getValue 'head.id_head')~"}
        {item label = "Поиск в документах" action= "open history_all_documents.rml ~($try ($g.gridds01@GetValue 'head.id_active') $catch ('Any') (-1) )~" }
        {item label = "Выгрузка в Excel"
           action = "~($X
                        (global.grid_name = 'GRID_GROUP1')
                        ($g.self@calculate 'js:js_file:/docs/print_grid.js')
                        ($ret '')
                       )~"
        }
  
   }
   {column size=40             title="номер"
        target=head.id_head        title_font_family=2     title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        visible = no            alias=idh
   }
   {column size=100             title="sort"   
        target=head.sort        title_font_family=2     title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        editmask = "##0.00000"
        visible = no
   }
   {column size=30             title="X"
        target=accept        title_font_family=2     title_font_color="#000000"
        halignment=center           font_size = 12          font_family=0
   }
   {column size=80             title="Дата"
        target=head.date_sd        title_font_family=2     title_font_color="#000000"
        halignment=center          font_size = 12          font_family=0
   }
   {column size=50             title="Код"  visible = yes
        target=head.id_active
        alias = id_active
        editmask = "##0."       font_size = 12
   }                  
   {column size=100             title="id_head"  visible = no
        target=head.id_head
        editmask = "##0."       font_size = 12
   }                  
   {column size=300             title="Наименование готовой продукции"
        target=name_active
        alias = name_active
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=100             title="head.id_unit"  visible = no
        target=head.id_unit
        alias = id_unit
   }                  
   {column size=60             title="Ед. изм."
        target=name_unit
        alias = name_unit
        title_font_family=2
        title_font_color="#000000"
        halignment=right
        font_size = 12     
   }
   {column size=70             title="Кол-во"
        target=quantity
        title_font_family=2
        title_font_color="#000000"
        editmask = "# #0.000"
        halignment=right
        font_size = 12     
   }
   {column size=200             title="Примечание"
        target=head.comment_sd        title_font_family=2     title_font_color="#000000"
        halignment=left          font_size = 12          font_family=0
   }
   {column size=120             title="Последнее изменение"
        target=last_changed        title_font_family=2     title_font_color="#000000"
        halignment=left          font_size = 12          font_family=0
        editable = readonly
   }

   {datastore 
           alias = GRIDDS01
           query = "select head.id_head, head.sort, head.accept, head.num_sd, head.date_sd, head.id_type_doc, head.id_active, head.id_personal, head.id_department1,
                           head.id_unit, name1_dep, head.comment_sd,
                           doc_sum, accept, name_active, name_unit, last_changed, quantity
                      from (
                    select head.id_head, head.sort,
                           decode(head.accept, 3, 'X', 0, '-', '?') accept,
                           head.num_sd, head.date_sd, head.id_personal, head.id_type_doc, head.id_active, head.id_unit,
                           head.id_department1, department.name1_dep, head.comment_sd,
                           util.doc_sum(head.id_head) doc_sum,
                           --decode(head.accept, 0, '', 1, 'X', 'ХЗ') accept,
                           active.name_active, active_pseudo_unit.name_pseudo_unit name_unit,
                           personal.sname||' '||personal.fname last_changed,
                           ~($X
                                ($if (($try (g.search_string2) $catch ('Any')(0)) == 0)
                                  ($ret 'null quantity')
                                )
                                ($g.search_ds@retrieve)
                                # если найден 1 материал, выдаем, сколько его в спецификации этой продукции
                                ($if (($g.search_ds@size) == 1)
                                  ($ret '(select sum(spc.q1_spc)
                                            from spc, head
                                           where spc.id_head = head.id_head
                                             and head.id_active = active.id_active
                                             and spc.id_active = ' + ($g.search_ds@getValue 'id_active') + '
                                             and head.id_type_doc = 10
                                             and head.accept = 3
                                         ) quantity')
                                )

                                # найдено более 1 материала
                                ($ret '\'X\' quantity' )
                            )~
                      from head, department, active, active_pseudo_unit, personal
                     where head.id_department1 = department.id_department (+)                 
                       ~($if (global.loading == 1)
                             (' and 1 = 0 ')
                          $else ('')
                        )~ 
                       and head.id_active = active.id_active (+)
                       and head.id_type_doc = 10
                       ~($if (($g.check_status1@getValue) == '0')
                          ($if (($g.check_status2@getValue) == '0')
                            (' and head.accept = -1')
                           $else
                            (' and head.accept = 0')
                          )
                         $else
                          ($if (($g.check_status2@getValue) == '0')
                            (' and head.accept = 3 ')
                           $else
                            (' and head.accept in (0, 3)')
                          )

                        )~
                       
                       and head.id_unit = active_pseudo_unit.id_pseudo_unit (+)
                       and head.last_changed = personal.id_personal (+)

                       ~($if (($try (g.search_string1) $catch ('Any')(0)) != 0)
                           ($if (($try (g.search_string2) $catch ('Any')(0)) != 0)
                             (' and (
                                       upper(active.name_active) like upper(\'%' + ($reg2ora g.search_string1) + '%\')
                                       and
                                       active.id_active in
                                         (
                                           select distinct head.id_active
                                             from head, spc
                                            where head.id_type_doc = 10
                                              and spc.id_head = head.id_head
                                              and spc.id_active in (
                                                                    select active.id_active from active
                                                                     where id_active in
                                                                       ( select id_active from active where upper(active.name_active) like upper(\'%' + ($reg2ora g.search_string2) + '%\') )
                                                                    -- or analog_id in  
                                                                    --  ( select id_active from active where upper(active.name_active) like (\'%' + ($reg2ora g.search_string2) + '%\') )
                                                                   )

                                         )
                                    )
                             ')
                            $else
                              (' and upper(active.name_active) like upper(\'%' + ($reg2ora g.search_string1) + '%\')')
                           )
                         $else
                          ($if (($try (g.search_string2) $catch ('Any')(0)) == 0)
                             (' ')
                           $else
                             (' and active.id_active in
                                         (
                                           select distinct head.id_active
                                             from head, spc
                                            where head.id_type_doc = 10
                                              and spc.id_head = head.id_head
                                              and spc.id_active in (
                                                                    select active.id_active from active
                                                                     where id_active in
                                                                       ( select id_active from active where upper(active.name_active) like upper(\'%' + ($reg2ora g.search_string2) + '%\') )
                                                                    -- or analog_id in  
                                                                    --  ( select id_active from active where upper(active.name_active) like (\'%' + ($reg2ora g.search_string2) + '%\') )
                                                                   )
                                         )
                             ')
                          )
                        )~ 


                           ) head
                     order by name_active
                    
                  ~($X ($if (($($G.GRID_GROUP1@getDatastore)@size)>0) (global.id_h =($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' ))) ($ret ''))~                     

                     "
              editable = yes
                  head = yes
                unique = "('head','head.id_head')"
               default = "head.id_head=~($X
                                           ($g.head_sq@retrieve)
                                           ($ret ($g.head_sq@getValue 'head_sq.nextval'))
                                        )~,head.id_type_doc=~10~,
                          head.date_sd=~ds.date~,
                          head.id_personal=~ds.idp~,
                          head.num_sd=~global.num_sd~,
                          head.id_active=~-999~"
               selaction = "~($X
                                ($g.grid3@retrieve)
                                (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
                                ($ret '')
                             )~"

       {datastore
            alias = set_row_ds
            query = "select user from dual 
                     ~($X 
                         #($debug 'global.id_h='+global.id_h)
                         (global.no_selaction = 1)
                         (t = ($g.GRIDDS01@iterator))
                         (row = 0)  (f=0)
                         ($while ($t@next)
                            (
                              ($if (global.id_h != ($($t@value)@field 'HEAD.ID_HEAD'))
                                   (row = row + 1)
                               $else ((f=1) ($break))
                              )
                            )
                         )
                         ($if (f==1) (
                         ($if (($g.GRIDDS01@size) != 0 )(
                              ($g.GRIDDS01@setCurRow row)
                              ($g.GRIDDS01@notifyviews)
                         ))
                         ))
                         (global.no_selaction = 0)
                         ($ret)
                      )~"
            editable = no
       } // ds set_row_ds
   
   
   } // end of ds
} // end of grid
} // end of split1
{splitpanel type = vertical percent=20
{splitpanel type = horizontal percent=30
{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   font_size = 12  font_face = tahoma
   }                  
   {column size=150             title="Этап сборки"
        target=work_stage.name_work_stage
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12  font_face = tahoma         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 != 0
                     order by work_stage.id_work_stage"
              editable = no

               selaction = "~($X
                                ($g.grid3@retrieve)
                                (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
                                ($ret '')
                             )~"

   } // end of ds
} // end of grid
{form
  {button
    left = 10 top = 10 width = 100 height = 30 font_size = 12
    label = "Переместить"
    action = "($X
                ($if (($g.gridds03@size) == 0)
                  (
                   ($g.self@sure 'Нечего перемещать.' 1)
                   ($ret '')
                  )
                )
                ($try 
                  (
                    (selection = ($g.grid3@selectionValues 'id_spc'))
                    ($debug '******** selection: ' + selection)
                  )
                 $catch ('Any')
                  (
                    ($debug 'selection: ----exception!!!---------')
                    ($ret '')
                  )
                )

                (len = ($selection@length))
                (id = '-1') (i = 0)
                ($while (i < len)
                  (
                    (id += ', ' + ($selection@ i))
                    (i += 1)
                  )
                )

                ($g.data_ds1@setCurRow ($g.combo1@getSelectedIndex))
                ($g.self@doAction 'execute exec update SPC set WORK_TYPE = ' + ($g.data_ds1@getValue 'work_stage.id_work_stage') + ' where ID_SPC in ( ' + id + ' )')
                ($g.grid3@retrieve)
                (g.sum1 = ($($g.grid3@getDatastore)@sum 'spc.q1_spc'))
                ($ret '')
              )"
  }
   {combobox
      left = 120     top = 10      width = 150        height = 30 
      alias = combo1               border = box
      target = work_stage.name_work_stage

      {datastore
       alias = data_ds1
       query = "select work_stage.id_work_stage, work_stage.name_work_stage
                      from work_stage
                     where work_stage.id_work_stage != 0
                     order by work_stage.name_work_stage"
      }
   }


}
} // horizontal splitpanel
{grid
    alias = GRID3
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselection = yes    editable = no
    rowsize = 20
              del = "~($X
                         ($ret '') 
                      )~"

   {menu

   {item label = "История изменений строки" action= "open reports/report_spc_log.rml ~($g.gridds03@getValue 'spc.id_spc')~"}
   {item label = "История изменений документа" action= "open reports/report_spc_log_doc.rml ~($g.gridds03@getValue 'spc.id_head')~"}

   }


   {column size=100             title="spc.id_spc"  visible = no
        target=spc.id_spc       font_size = 12                    font_family=0
        alias = id_spc
   }                  
   {column size=50             title="Код"
        target=spc.id_active
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
        editmask = "##0."
   }                  
   {column size=250             title="Наименование"
        target=active.name_active
        alias = name_active_component
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=70             title="Кол-во"
        target=spc.q1_spc
        title_font_family=2        title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0         editmask = "# #0.000"
   }                  
   {column size=100             title="spc.id_unit"  visible = no
        target=spc.id_unit      font_size = 12          font_family=0
        alias = id_unit_component
   }                  
   {column size=70             title="Ед. изм."
        target=active_pseudo_unit.name_pseudo_unit
        alias = name_unit_component
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=70             title="вид сборки"
        target=work_type.name_type
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=300             title="Примечание"
        target=spc.comments        title_font_family=2     title_font_color="#000000"
        halignment=left          font_size = 12          font_family=0
   }
   {column size=120             title="Последнее изменение"
        target=util.get_last_date_mod(spc.id_spc)        title_font_family=2     title_font_color="#000000"
        halignment=left          font_size = 12          font_family=0
        editable = readonly
   }

  {datastore 
           alias = GRIDDS03
           query = "select spc.id_spc, spc.parent_id_spc, spc.id_head, spc.id_unit, spc.id_active, active.name_active, spc.q1_spc, spc.work_type, active_pseudo_unit.name_pseudo_unit,
                           spc.comments, util.get_last_date_mod(spc.id_spc), work_stage.name_work_stage, work_type.name_type
                      from spc, active, active_pseudo_unit, work_stage, work_type
                     where spc.id_head = ~($if (($g.gridds01@size) > 0)
                                             ($try ($g.gridds01@getValue 'head.id_head') $catch ('Any')(-1))
                                           $else (-1)
                                          )~
                       and spc.id_active = active.id_active
                       and spc.work_type = ~($if (($g.gridds_work_stage@size) > 0)
                                             ($try ($g.gridds_work_stage@getValue 'work_stage.id_work_stage') $catch ('Any')(-1))
                                           $else (-1)
                                          )~
                       and spc.id_unit = active_pseudo_unit.id_pseudo_unit (+)
                       and spc.work_type = work_stage.id_work_stage (+)
                       and spc.id_department = work_type.id_work_type (+)
                     --order by work_stage.name_work_stage, active.name_active
                     order by spc.id_spc"
              editable = no
                unique = "('spc','spc.id_spc')"
               default = "spc.id_spc=~ds.spk~,spc.id_active=~-999~,spc.id_head=~($g.gridds01@getValue 'head.id_head')~, spc.work_type=~2~,spc.parent_id_spc=~($g.gridds02@getValue 'spc.id_spc')~, spc.q1_spc=~0~"
   } // end of ds
} // end of grid
} // vertical split
} // horizontal split
{button
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Выход (ESC)"
  action = "($g.self@actcancel)"
  shortcut = "escape"
}

} // toolbar
