Cp1251
DOC
document_title="Этапы производства"
document_width=900
document_height=700

preloadscript = "($X
                     (global.no_combo_action = 1)
                     (global.loading = 1)
                     ($ret '')
                  )"

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


{toolbar   BACKGROUND = "LIGHTGRAY"
 { splitpanel type = horizontal percent = 10
    {   form
       {label left = 10 top = 10 width = 700 height = 20 font_size = 14 font_color = "BLUE" alias = info }
       {label left = 5 top = 40 width = 54 height = 30 font_size = 14 value = "Дата с" }
       { field left = 50 top = 40 width = 100 height = 30 font_size = 16 alias = dat1  target = month_beginning
         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))
                ($debug 'n_dat1 = ' + g.n_dat1)
                ($ret '')
              )" 
       }
       {label left = 160 top = 40 width = 25 height = 30 font_size = 14 value = "по" }
       { field left = 190 top = 40 width = 100 height = 30 font_size = 16 alias = dat2  target = month_end
         dep = "n_dat2"
       }
       {field  alias=n_dat2  type=string 
         left = 175 top = 40 width = 100 height = 30 font_size = 16	visible = no
         exp="($X
                (g.n_dat2 = ($($@date g.dat2)@toPLString))
                ($debug 'n_dat2 = ' + g.n_dat2)
                ($ret '')
              )" 
       }
       { button left = 300 top = 40 width = 27 height = 27 
         icon = "images/reload.png"
         tooltiptext = "Обновить данные"

         action = "($X
                      (global.no_combo_action = 1)
                      ($g.self@doAction 'retrieve combo1')
                      (global.no_combo_action = 0)
                      ($g.grid1@retrieve)
                      ($ret '')
                   )"
       }

       {label
           value="Склад"        
           left=350    top=5    height=20       width=50
           font_size=12         font_family=0   bg_color="#c0c0c0"
       }
       {combobox
          left = 400     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 '') )
                      ($g.grid1@retrieve)
                      ($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 in (96, 14)
                       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=350    top=40    height=20       width=60
           font_size=12         font_family=0   bg_color="#c0c0c0"
       }
       {field  alias=name_filter  type=string VALUE = "" 
         left = 410 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 '') )
                ($g.grid1@retrieve)
                ($ret '')
              )" 
       }


      {datastore  alias=date_ds
        query="select month_beginning, month_end
                 from (
               select to_date('01.'||to_char(sysdate, 'mm.yyyy'), 'dd.mm.yyyy') month_beginning,
                      last_day(to_date('01.'||to_char(sysdate, 'mm.yyyy'), 'dd.mm.yyyy')) month_end
                 from dual
                      )"
        
      }

    } //form

    {grid  alias=grid1
    titlebar_height = 90
     del=""
     edit = ""
      {column  size=50
        title="ID"  target=id_active
        font_size = 12 editmask = "##0."
      }
      {column  size=250
        title="Название"  target=name_active
        font_size = 12
      }
      {column  size=90
        title="<html>Кол-во<br>жгутов"  target="sum(q1_spc)"
        editmask = "# #0."  halignment = right
        font_size = 12
      }
      {column  size=90
        title="<html>Проводов в<br>одном жгуте"  target="sum(q_prov)"
        editmask = "# #0."  halignment = right
        font_size = 12
      }
      {column  size=90
        title="<html>Всего контактов<br>на один жгут<br><br>"  target="sum(q_kont)"
        editmask = "# #0."  halignment = right
        font_size = 12
      }
      {column  size=90
        title="<html>Сколько проводов<br>нарезано на линии<br><br><br>"  target="sum(null)"
        editmask = "# #0.000"  halignment = right
        font_size = 12
      }
      {column  size=90
        title="<html>Сколько контактов<br>заармировано на линии<br><br><br>"  target="sum(null)"
        editmask = "# #0.000"  halignment = right
        font_size = 12
      }
      {column  size=90
        title="<html>Сколько проводов<br>нарезано на каппах<br><br><br>"  target="sum(null)"
        editmask = "# #0.000"  halignment = right
        font_size = 12
      }
      {column  size=90
        title="<html>Сколько контактов<br>осталось заармировать<br>на станках<br><br><br>"  target="sum(null)"
        editmask = "# #0.000"  halignment = right
        font_size = 12
      }
      {column  size=90
        title="<html>Сколько проводов<br>осталось нарезать<br><br><br>"  target="sum(null)"
        editmask = "# #0.000"  halignment = right
        font_size = 12
      }
      {column  size=90
        title="<html>Сколько контактов<br>осталось заармировать<br><br><br>"  target="sum(null)"
        editmask = "# #0.000"  halignment = right
        font_size = 12
      }

  {datastore alias=DS
    query="select id_active, name_active, sum(q1_spc), sum(q_prov), sum(q_kont), sum(null)
             from (
           select head_proiz.id_department1 id_department, active_prod.id_active, active_prod.name_active, 
                  spc_proiz.q1_spc,
                  case when upper(active_material.name_active) like '%ПВАМ%' then spc_proiz.q1_spc
                       else null
                  end q_prov,
                  case when upper(active_material.name_active) like '%КОНТАКТ%' then spc_proiz.q1_spc
                       else null
                  end q_kont
             from head head_proiz, spc spc_proiz, head head_spec, spc spc_spec, active active_prod, active active_material
            where head_proiz.date_sd between to_date('~g.n_dat1~', 'dd.mm.yyyy') and to_date('~g.n_dat2~', 'dd.mm.yyyy')
              and head_proiz.id_type_doc = 14
              and head_proiz.accept = 1
              and active_material.closed = 0
              and head_proiz.id_head = spc_proiz.id_head
              and spc_proiz.id_active = active_prod.id_active
              and head_spec.id_head = active_prod.id_head2
              and spc_spec.id_head = head_spec.id_head
              and spc_spec.id_active = active_material.id_active
                       ~($X
                                (q = '')
                                
                                ($if (($try (g.name_filter) $catch ('NullException')(0)) != 0)
                                   (q += ' and upper(active_prod.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 head_proiz.id_department1 = ' + ($g.data_ds1@getValue 'id_department'))
                                )
                                ($ret q)
                        )~
                  )
            group by id_active, name_active
            order by name_active"
   } //datastore
 } // end of grid
} // splitpanel

  {button  label = "Выход (Esc)"
    shortcut = "Escape"
   action = "($G.SELF@ACTCANCEL)"
  }
} // end of toolbar
