Cp1251
DOC 
foreground = lightgray
document_width = 1000
document_height = 700
document_title = "ZetaSE.Autocomplect/ Заявки на выдачу материалов, невыданные материалы"

preloadscript = "($X
                    (global.loading = 1)
                    (global.update = 0)
                    (global.no_combo_action = 1)
                    (global.dat1 = '01.01.0001')
                    (global.dat2 = '01.01.0001')
                    ($ret '')
                 )"

postloadscript = "($X
                    (global.loading = 0)
                    (global.no_combo_action = 1)
                    ($g.self@doAction 'retrieve combo1')
                    (global.no_combo_action = 0)
                    (global.update = 1)
                    ($ret '')
                 )"


{toolbar   BACKGROUND = "LIGHTGRAY"
{ splitpanel type = horizontal percent = 10
{form width=780 height=150       bg_color="#c0c0c0"   alias = fm
   {label
       value="Дата с "    
       left=10    top=5    height=20       width=40
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=dat1  border = box
       left=50    top=5    height=20       width=100
       alias=dat1        font_size=12    font_family=0    bg_color="#ffffff"
       dep = "n_dat1"
   }
   {field  alias=n_dat1  type=string 
     left = 50 top = 40 width = 100 height = 30 font_size = 16	visible = no
     exp="($X
            (g.n_dat1 = ($($@date g.dat1)@toPLString))
            ($if (global.dat1 == g.n_dat1) ($ret '') ) # бага/фича ядра - дата не меняется, а этот скрипт вызывается
            (global.dat1 = g.n_dat1)
            ($if (global.loading == 1) ($ret '') )
            (global.no_combo_action = 1)
            ($g.self@doAction 'retrieve combo1')
            (global.no_combo_action = 0)
            (global.update = 0)
            ($g.grid_group1@retrieve)
            (global.update = 1)
            ($ret '')
          )" 
   }
   {label
       value="по"    
       left=160    top=5    height=20       width=30
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=dat2  border = box
       left=180    top=5    height=20       width=100
       alias=dat2        font_size=12    font_family=0    bg_color="#ffffff"
       dep = "n_dat2"
   }
   {field  alias=n_dat2  type=string 
     left = 50 top = 40 width = 100 height = 30 font_size = 16	visible = no
     exp="($X
            (g.n_dat2 = ($($@date g.dat2)@toPLString))
            ($if (global.dat2 == g.n_dat2) ($ret '') ) # бага/фича ядра - дата не меняется, а этот скрипт вызывается
            (global.dat2 = g.n_dat2)
            ($if (global.loading == 1) ($ret '') )
            (global.no_combo_action = 1)
            ($g.self@doAction 'retrieve combo1')
            (global.no_combo_action = 0)
            (global.update = 0)
            ($g.grid_group1@retrieve)
            (global.update = 1)
            ($ret '')
          )" 
   }

   
   
   {label
       value="Склад"        
       left=300    top=5    height=20       width=50
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {combobox
      left = 350     top = 5      width = 200        height = 25  font_size = 12
      alias = combo1               border = box
      target = name_dep
      action = "~($X
                  ($if (global.loading == 1) ($ret '') )
                  ($debug 'combo1')
                  ($if (global.no_combo_action == 1) ($ret '') )
                  (global.update = 0)
                  ($g.grid_group1@retrieve)
                  (global.update = 1)
                  ($ret '')
                )~"
      {datastore
       alias = data_ds1
       query = "select id_department, name_dep, sort
                  from (
                select head.id_department1 id_department, department.name1_dep name_dep, 2 sort
                  from head, department
                 where head.id_type_doc = 17
                   and head.date_sd between to_date('~g.n_dat1~', 'dd.mm.yyyy') and to_date('~g.n_dat2~', 'dd.mm.yyyy')
                   and head.id_department1 = department.id_department
                 group by head.id_department1, department.name1_dep

                 union all

                select -999 id_department, '--- все ---' name_dep, 1 sort
                  from dual
                       )
                 order by sort, name_dep"
      }
   }

   {label
       value="Материал:"    
       left=10    top=40    height=20       width=60
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field  alias=name_filter  type=string VALUE = "" 
     left = 70 top = 40 width = 200 height = 25 font_size = 12
     firstfocus = yes
     dep = "name_filter_upd"
   }

   {field  alias=name_filter_upd  type=string  visible = no
     left = 70 top = 40 width = 200 height = 25 font_size = 12
     exp="($X
            ($if (global.loading == 1) ($ret '') )
            (global.update = 0)
            ($g.grid_group1@retrieve)
            (global.update = 1)
            ($ret '')
          )" 
   }
      
   { checkgroup
     left = 300 top =40
    { checkbox
      label = "Только те строки, где \"выдано\" < \"требуется\""
      check = yes  font_size = 12 bg_color="#c0c0c0"
      alias = check_less
      onvalue = "only_less"
      offvalue = "all"
      action = "~($X
                  ($if (global.loading == 1) ($ret '') )
                  (global.update = 0)
                  ($g.grid_group1@retrieve)
                  (global.update = 1)
                  ($ret '')
                )~"
    }
   }

   {button left = 600 top = 10 width = 25 height = 25
    icon = "images/excel.jpg"
    tooltiptext = "Выгрузка в Excel"
       action = "($X
                      
                     (global.grid_name = 'GRID_GROUP1')
                     ($g.self@calculate 'js:js_file:/docs/print_grid.js')
                     ($ret '')
                   )"
      }
   
{datastore 
        alias = d_head
        query = "select dat1, dat2
                   from (
                        select to_date(~ARGUMENTS.0~, 'dd.mm.yyyy') -7 dat1,
                               to_date(~ARGUMENTS.0~, 'dd.mm.yyyy') dat2
                          from dual
                        )"
} // ds
} // form

{grid
    alias = GRID_GROUP1
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18  titlebar_height = 40
    multiselect = no                       editable = yes
    rowsize = 25

    del = "~($X
              ($ret '')
            )~"


    {menu
      {item label = "Открыть заявку"
       action = "open docs/material2.rml ~($g.gridds01@getValue 'id_head')~"
      }
    }


   {column size=40             title="id_head"      alias=id_hd
        target=id_head        title_font_family=2     title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        visible = no            alias=idh
        editable = readonly
   }
   {column size=40             title="id_head"      alias=id_hd
        target=id_spc        title_font_family=2     title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        visible = no            alias=column_id_spc
        editable = readonly
   }
   {column size=60             title="N док."
        target=num_sd         title_font_family=2     title_font_color="#000000"
        halignment=left            font_color="#000000"     
        font_size = 12             font_family=0
        editable = readonly
   }
   {column size=70             title="Дата док."
        target=date_sd        title_font_family=2     title_font_color="#000000"
        halignment=center          font_size = 12          font_family=0
        editable = readonly
   }
   {column size=150             title="Склад"
        target=name_sklad
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
        editable = readonly
   }
   {column size=200             title="Продукция"
        target=name_prod
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
        editable = readonly
   }
   {column size=200             title="Материал"
        target=name_material
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
        editable = readonly
   }
   {column size=80             title="<html>Требуется в<br> производство"
        target=q1_spc        title_font_family=2     title_font_color="#000000"
        halignment=right          font_size = 12          font_family=0
        editmask = "# #0.000"
        editable = readonly
   }
   {column size=80             title="Выдано"
        target=q2_spc        title_font_family=2     title_font_color="#000000"
        halignment=right          font_size = 12          font_family=0
        editmask = "# #0.000"
        alias = column_q2_spc
        dep = "column_q2_spc_exp"
   }
   {column size=80             title="Выдано exp"
        type = number     title_font_family=2     title_font_color="#000000"
        halignment=right          font_size = 12          font_family=0
        editmask = "# #0.000"
        alias = column_q2_spc_exp
        visible = no
        exp = "($X
                  ($debug 'column_q2_spc  exp')
                  ($if (global.loading == 1) ($ret '') )
                  ($if (global.update == 0) ($ret '') )
                  ($g.self@doAction 'execute exec update spc set q2_spc = ' + g.column_q2_spc + ' where id_spc = ' + g.column_id_spc)
                  ($g.self@doAction 'execute exec commit')
                  (r = ($g.gridds01@getCurRow))
                  (global.update = 0)
                  ($g.grid_group1@retrieve)
                  (global.update = 1)
                  ($g.gridds01@setCurRow r)
                  ($ret '')
               )"
   }

   {datastore 
           alias = GRIDDS01
           query = "select id_spc, id_head, num_sd, date_sd, name_material, name_prod, accept, type_zvm, name_sklad, id_department1, dep1,
                           q1_spc, q2_spc
                      from (
                    select head.id_head, spc.id_spc, head.num_sd,head.date_sd,
                           head.id_department1,department.name1_dep name_sklad, department.dep1, head.comment_sd,
                           head.id_department2,dep2.name1_dep,
                           nvl(head.id_contract, 0) type_zvm,
                           head.accept,
                           active_material.name_active name_material, active_prod.name_active name_prod,
                           spc.q1_spc, spc.q2_spc
                      from head, department, department dep2, spc, active active_material, active active_prod
                     where head.date_sd between to_date('~g.n_dat1~', 'dd.mm.yyyy') and to_date('~g.n_dat2~', 'dd.mm.yyyy')
                       ~($if (global.loading == 1) (' and 1 = 0') $else (''))~
                       and head.id_department1 = department.id_department (+)                 
                       and head.id_department2 = dep2.id_department (+)                    
                       and head.id_type_doc = 17
                       and nvl(head.id_contract, 0) = 1
                       and head.id_head = spc.id_head
                       and active_material.id_Active = spc.id_active
                       and nvl(spc.parent_id_spc, 1) != 0
                       and spc.id_department = active_prod.id_active
                       ~($X
                                (q = '')
                                
                                ($if (($try (g.name_filter) $catch ('NullException')(0)) != 0)
                                   (q += ' and upper(active_material.name_active) like upper(\'' + ($reg2ora g.name_filter) + '%\')')
                                )
                                ($if (global.loading == 1) ($ret q))
                                ($g.data_ds1@setCurRow ($g.combo1@getSelectedIndex))
                                ($if (($g.data_ds1@getValue 'id_department') != -999)
                                   (q += ' and department.id_department = ' + ($g.data_ds1@getValue 'id_department'))
                                )
                                ($ret q)
                        )~

                    )
                       ~($X
                                (q = '')
                                ($if (($g.check_less@getValue) == 'only_less')
                                   (q += ' where q2_spc < q1_spc ')
                                )
                                ($ret q)
                        )~
           order by date_sd,num_sd,name_material

           "
   } // end of ds
} // end of grid
} // splitpanel
{button
  left = 72  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Выход (ESC)"
  action = "($X
              ($g.self@actcancel)
              ($ret '')
            )"
  shortcut = "escape"
}
} // toolbar

