Cp1251
DOC
foreground = lightgray 
document_width = 750
document_height = 550
document_title = "ZetaSE.Autocomplect/Аналоги"
preloadscript="
(global.retr = 0)
(global.id_h = 0)
(global.no_selaction = 0)
"

{DSCollection
   alias = dscoll
   SeqQuery = "select to_char(sysdate) from dual"
   seqnames = "date"
}

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

{toolbar   BACKGROUND = "White"
{splitpanel type=horizontal   percent=15 gapsize = 10
{form bg_color="#c0c0c0"
   {field
       type = string   border = box
       left=20     top=10    height=25       width=100
       alias=search         font_size=16    font_family=0    bg_color="#ffffff"

   }
   { button left = 130 top = 5 width = 100 height = 35
     label = "Поиск"  font_size=16
     shortcut = "Enter"
     action = "($X
                   ($g.self@doAction 'retrieve grid_group1')
                   ($g.self@doAction 'retrieve grid_group2')
                   ($ret '')
                )"
   }

   { button left = 600 top = 5 width = 200 height = 35
     label = "Проверка аналогов"  font_size=16
     action = "($X
                   ($g.self@doAction 'execute exec big3.check_analog')
                   ($ret '')
                )"
   }
}
{splitpanel type=vertical     percent=50 gapsize = 10
{grid
    alias = GRID_GROUP1
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselect = yes                      editable = no
    rowsize = 20
   // add = "createnew docs/analog.rml -1 ; retrieve grid_group1 ; retrieve grid_group2"
    edit = "opennew docs/analog.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~, -1 ; retrieve grid_group1 ; retrieve grid_group2"
    del = "~($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 '')
		)
	     )
               (tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.NUM_SD' ) + '')
               (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') + '); retrieve grid_group1 ; retrieve grid_group2')
            ($ret ''))~"

   {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/analog.rml -1, -1 ; retrieve grid_group1 ; retrieve grid_group2')
             ($ret '')
             )~"}
        {item label = "-"}
        {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 'opennew docs/analog.rml ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD') + ', -1')
             ($g.self@doAction 'retrieve grid_group1 ; retrieve grid_group2')
             ($ret '')
             )~"}
        {item label = "-"}
        {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 '')
          		)
          	     )
                       ($IF (($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ACCEPT' ) == 1)
		             ((tmp = 'Запрещено удалять проведенный документ')
            		      (m = ($g.self@sure tmp 1))
		             )
			$else
		         ((tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.NUM_SD' ) + '')
	                  (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') + '); retrieve grid_group1 ; retrieve grid_group2')
			 )
		       )
	              ($ret ''))~"
        }
   }
   {column size=40             title="номер"      alias=id_hd
        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=60             title="N док."
        target=head.num_sd         title_font_family=2     title_font_color="#000000"
        halignment=left            font_color="#000000"     
        font_size = 12             font_family=0
   }
   {column size=70             title="Дата док."
        target=head.date_sd        title_font_family=2     title_font_color="#000000"
        halignment=center          font_size = 12          font_family=0
   }
//   {column size=80            title="Есть аналог"
//        target=active.analog  title_font_family=2     title_font_color="#000000"
//        halignment=center            font_size = 12          font_family=0
//        editmask = "# #0."
//   }
   {column size=80            title="Код"
        target=active.id_active  title_font_family=2     title_font_color="#000000"
        halignment=center            font_size = 12          font_family=0
        editmask = "# #0."
   }
   {column size=300            title="Актив - оригинал"
        target=active.name_active  title_font_family=2     title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {column size=150            title="Последнее исправление"
        target="PERSONAL.SNAME || ' ' || PERSONAL"  title_font_family=2     title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }

   {datastore 
           alias = GRIDDS01
           query = "select head.id_head,head.num_sd,head.date_sd,
                           head.comment_sd,
                           head.accept, active.id_active, active.analog, active.name_active,
                           personal.sname || ' ' || personal.fname
                      from head, active, personal
                     where head.id_active = active.id_active (+)
                       and head.id_type_doc = 16
                       and head.id_personal = personal.id_personal (+)
                       ~($if (($try (g.search) $catch ('NullException')(0)) != 0)
                           (' and ( upper(active.name_active) like upper (\'%' + ($reg2ora g.search) + '%\')
                                    or active.id_active in (select active.analog_id from active where upper(active.name_active) like upper (\'%' + ($reg2ora g.search) + '%\')  and active.analog = 1)
                                  )
                            ' )
                         $else
                           ('')
                        )~
                     order by head.date_sd,head.num_sd

                       ~($X 
                           ($if (($G.gridds01@size)>0) 
                             (global.id_h =($G.gridds01@getValue 'HEAD.ID_HEAD' ))
                           ) 
                           ($ret '')
                        )~
                     "



                selaction = "~($X
                                 ($if (global.no_selaction == 1)
                                   ($ret '')
                                 )
                                 ($g.grid_group2@retrieve)
                                 ($ret '')
                               )~"

          {datastore
            alias = set_row_ds
            query = "select user from dual
                     ~($X 
                        (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.id_h = 0)
                        ($ret '')
                      )~"
            editable = no
       } // ds set_row_ds

   } // end of ds
} // end of grid
{grid
    alias = GRID_GROUP2
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselect = yes                      editable = no
    rowsize = 20
   {column size=80            title="Код"
        target=active.id_active  title_font_family=2     title_font_color="#000000"
        halignment=center            font_size = 12          font_family=0
        editmask = "# #0."
   }
   {column size=300            title="Актив - аналог"
        target=active.name_active  title_font_family=2     title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {column size=100            title="Код оригинала"
        target=active.analog_id  title_font_family=2     title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }

   {datastore 
           alias = GRIDDS02
           query = "select active.id_active, active.name_active, active.analog_id
                      from spc, active
                     where spc.id_head = ~($try ($g.gridds01@getValue 'head.id_head') $catch ('Any')(-1))~
                       and spc.id_active = active.id_active (+)
                     order by active.name_active"
   } // end of ds
} // end of grid
} // end of vertical split
} // end of horizontal split
{button
  left = 72  width = 50    height = 20
  BACKGROUND = "LIGHTGREEN"    foreground="#000000"
  label = "Выход ESC"
  action = "($g.self@actcancel)"
  shortcut = "escape"
}

} // toolbar
