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)
(global.sklad = '210, 306, 206, 209, 208, 225')
"
postloadscript = "($X
(global.loading = 0)



##########################  defun
($defun repaint_grid3 <par1>
  ($X
    (sz = ($($g.grid3@getDatastore)@size))
    (i = 0)
    ($while (i < sz)
      (
        ($($g.grid3@getDatastore)@FastSetCurRow i)

        ($if (($try ($($g.grid3@getDatastore)@getValue 'util.get_last_date_mod(spc_spec.id_spc)') $catch ('NullException')(0)) == 0)
          (
            (j = 4)
            ($while (j < 5)
              (
                ($g.grid3@setcellbgcolor i j 'RED')
                (j += 1)
              )
            )
          )
         $else
          (
                 ($if (($global.d@after ($try ($($g.grid3@getDatastore)@getValue 'util.get_last_date_mod(spc_spec.id_spc)') $catch ('NullException')('01.01.0001')) ) == 1)
                   (
                     (j = 4)
                     ($while (j < 5)
                       (
                         ($g.grid3@setcellbgcolor i j 'RED')
                         (j += 1)
                       )
                     )
                   )
                  $else
                   (
                     (j = 4)
                     ($while (j < 5)
                       (
                         ($g.grid3@setcellbgcolor i j 'WHITE')
                         (j += 1)
                       )
                     )
                   )
                 )
          )
        )

        (i += 1)
      )
    )
    ($g.grid3@repaint)
    ($ret '')
  )
)
##########################  end defun

($g.last_update@retrieve)
($debug 'last_update: ' + ($g.last_update@getValue 'LAST_UPDATE'))
(global.d = ($@date ($g.last_update@getValue 'LAST_UPDATE')))

($ret '')
)
"
{ datastore
  alias = last_update
  query = "select last_update
             from (
           select parameters.d last_update
             from parameters 
            where parameters.id = 10
                  )"
}




{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel type=horizontal     percent=70
{splitpanel type=vertical     percent=20
{splitpanel type = horizontal percent = 50
{form
  { label left = 5 top = 50 width = 70 height = 30 font_size = 12 value = "продукция: " }
  { field left = 75 top = 50 width = 170 height = 30  font_size = 16 alias = search_string_gp  type = string
    firstfocus = yes
  }
  //{ label left = 5 top = 80 width = 60 height = 30 font_size = 12 value = "материал: " }
  //{ field left = 70 top = 80 width = 170 height = 30  font_size = 16 alias = search_string_mat  type = string
  //}
  { button left = 30 top = 140 width = 150 height = 30 label = "Найти (Enter)" foreground = "#000000"
    shortcut = "Enter"
    action = "($X
                 ($g.grid3@retrieve)
                 #($repaint_grid3)
                 ($if (($($g.grid3@getDatastore)@size) > 0)
                   (
                    ($g.grid_group1@retrieve)
                   )
                 )
                 ($ret '')
              )"
  }
  { field left = 50 top = 10 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 '')
         )" 
  }
      {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
                      )"
        
      }

} // end of form
{grid
    alias = GRID_SKLAD
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselect = no                      editable = no
    rowsize = 20
          add=""
       addexp="(g.col_id_dep = store.department.id_department)
               (g.col_name1_dep = store.department.name1_dep)
               (g.col_dep_checked = 'X')"
          del=""
          edit = "~($X
                     ($if (($try ($g.gridds_sklad@getValue 'checked') $catch ('NullException')('')) == 'X')
                       ($g.gridds_sklad@setValue 'checked' '')
                      $else
                       ($g.gridds_sklad@setValue 'checked' 'X')
                     )
                     ($g.gridds_sklad@notifyViews)
                     ($ret '')
                   )~"

   { menu
     {item
       label = "Добавить"
       action = "~($X
                     ($g.self@doAction 'opennew find_department.rml')
                     ($ret '')
                  )~"
     }
   }


   {column size=50             title="ID"
        target=id_department   alias = col_id_dep   visible = no
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
        editable = readonly
   }                  
   {column size=140             title="Склад"
        target=name1_dep   alias = col_name1_dep
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
        editable = readonly
   }                  
   {column size=40             title="X"
        target=checked     alias = col_dep_checked
        title_font_family=2        title_font_color="#000000"
        halignment=center            font_size = 12          font_family=0
        editable = readonly
   }                  
   {datastore 
           alias = GRIDDS_SKLAD
           query = "select id_department, name1_dep, 'X' checked
                      from department
                     where id_department in (~global.sklad~)
                     order by name1_dep"

   } // end of ds
} // end of grid_sklad

} //horizontal split
{grid
    alias = GRID_GROUP1
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
                                           titlebar_height = 40
    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 = "opennew util/sroki_postavki.rml ~($g.gridds03@getValue 'id_active')~"
      }
      {item label = "Заказы по данному активу"
       action = "open docs/group_zakaz.rml ~($g.gridds03@getValue 'id_active')~, '~g.n_dat1~', '~g.n_zakaz_data1~', '~g.n_zakaz_data2~'"
      }
      {item label = "Все заказы "
       action = "open docs/group_zakaz.rml 0, '~g.n_dat1~', '~g.n_zakaz_data1~', '~g.n_zakaz_data2~'"
      }
      {item label = "Выгрузка в Excel"
       action = "~($X
                      
                     (global.grid_name = 'GRID3')
                     ($g.self@calculate 'js:js_file:/docs/print_grid.js')
                     ($ret '')
                   )~"
      }
   }

   {column size=50             title="Код"
        target=id_active
        alias = id_active_component
        font_size = 12          font_family=0
        editable = readonly
   }                  
   {column size=230             title="Материал"
        target=name_active
        alias = name_active_component
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
        editable = readonly
   }                  
   {column size=80             title="<html>Требуется<br>в произв-во</html>"
        target=q_proiz
        title_font_family=2        title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0 editmask = "# #0.00"
        editable = readonly
        alias = q_proiz
   }                  
   {column size=70             title="Остатки"
        target=ost
        title_font_family=2        title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0 editmask = "# #0.00"
        editable = readonly
        alias = q_ost
   }                  
   {column size=70             title="Хитрый колумн"
        type = string
        title_font_family=2        title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0 editmask = "# #0.00"
        editable = readonly
        alias = hidden1
        visible = no
   }                  
   {column size=70             title="В заказах"
        target=zak
        title_font_family=2        title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0 editmask = "# #0.00"
        editable = readonly
   }                  
   {column size=70             title="Дефицит"
        target = def
        title_font_family=2        title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0 editmask = "# #0.00"
        editable = readonly
        alias = def
   }                  

   
//   {column size=70             title="<html>Перемещено<br>в произв-во</html>"
//        target=perem
//        title_font_family=2        title_font_color="#000000"
//        halignment=right            font_size = 12          font_family=0 editmask = "# #0.00"
//        editable = readonly
//   }                  

   {datastore 
           alias = GRIDDS03
           query = "select id_active, name_active, q_proiz, ost, zak, def, perem, analog, analog_id, dat1, dat2, dat3
                      from (


                    select id_active, name_active, q_proiz, ost, zak,
                           decode(sign(q_proiz - ost - zak - perem), 1, q_proiz - ost - zak - perem, 0) def, perem,
                           analog, 0 analog_id, to_date('01.'||to_char(to_date('~g.n_dat1~', 'dd.mm.yyyy'), 'mm.yyyy'), 'dd.mm.yyyy') dat1,
                           to_char(to_date('~g.n_dat1~', 'dd.mm.yyyy'), 'month YYYY') dat2,
                           '~g.n_dat1~' dat3
                      from (
                    select id_active, name_active, analog,
                               doc_lib.getProizAnalogNew (id_active,
                                                        to_date('01.'||to_char(to_date('~g.n_dat1~', 'dd.mm.yyyy'), 'mm.yyyy'), 'dd.mm.yyyy'),
                                                        last_day(to_date('~g.n_dat1~', 'dd.mm.yyyy')),
                                                        ~($if (($g.gridds01@size) == 0)
                                                           (-1)
                                                          $else
                                                          ($try ($g.gridds01@getValue 'active.id_active') $catch ('Any')(-1))
                                                         )~
                                                       )
                              q_proiz,

                           doc_lib.getRestAnalogBeforeAll (id_active,
                                                                  -- на указанную дату
                                                                  (
                                                                   select max(sort)
                                                                    from head
                                                                   where date_sd <= to_date('~g.n_dat1~', 'dd.mm.yyyy')
                                                                  ),
                                                                '~global.sklad~'      

                                                               )
                             ost,
							
                           case
                               when analog = 1 then
                               
                               util.activeInDocumentsAnalog (id_active,
                                                             to_date('01.'||to_char(to_date('~g.n_dat1~', 'dd.mm.yyyy'), 'mm.yyyy'), 'dd.mm.yyyy'),
                                                             last_day(to_date('~g.n_dat1~', 'dd.mm.yyyy')),
                                                             9,
                                                             '~global.sklad~'      
                                                            )
                               else
                           
                               util.activeInDocuments (id_active,
                                                       to_date('01.'||to_char(to_date('~g.n_dat1~', 'dd.mm.yyyy'), 'mm.yyyy'), 'dd.mm.yyyy'),
                                                       last_day(to_date('~g.n_dat1~', 'dd.mm.yyyy')),
                                                       9,
                                                       '~global.sklad~'      
                                                      )
                           end zak,

                           0
                           perem



                      from (
                    select nvl(active_original.id_active, active.id_active) id_active, nvl(active_original.name_active, active.name_active) name_active,
                           nvl(active_original.analog, active.analog) analog

                      from head head_proiz, spc spc_proiz, head  head_spec, spc spc_spec, active, active active_original, active active_prod
                     where head_proiz.date_sd between to_date('01.'||to_char(to_date('~g.n_dat1~', 'dd.mm.yyyy'), 'mm.yyyy'), 'dd.mm.yyyy')
                                                  and last_day(to_date('~g.n_dat1~', 'dd.mm.yyyy')) 
                       ~($if (global.loading == 1)
                          (' and 1 = 0')
                         $else
                          (' ')
                        )~

                       ~($if (($g.gridds01@size) == 0)
                            (' and 1 = 0 ')
                          $else
                            (' and head_spec.id_head = active_prod.id_head2 ')
                         )~

                       
                       and head_proiz.id_type_doc = 14
                       and head_proiz.accept = 1
                       and head_proiz.id_head = spc_proiz.id_head
                       and spc_proiz.id_active = active_prod.id_active
                       and spc_spec.id_head = head_spec.id_head
                       and spc_spec.id_active = active.id_active
                       and active_original.id_active (+) = active.analog_id
                       and active_original.analog_id is null


                     group by nvl(active_original.id_active, active.id_active), nvl(active_original.name_active, active.name_active),
                              nvl(active_original.analog, active.analog)
                           )
                           )
                     where q_proiz != 0
                           )

                     order by name_active"


   } // end of ds
} // end of grid
} // end of split1
{grid
    alias = GRID3
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
                                           titlebar_height = 40
    multiselect = no                      editable = no
    rowsize = 20
    del = ""

   {column size=85             title="Код"
        target=active.id_active        title_font_family=2     title_font_color="#000000"
        halignment=left          font_size = 12          font_family=0
   }
   {column size=250             title="Готовая продукция"
        target=active.name_active        title_font_family=2     title_font_color="#000000"
        halignment=left          font_size = 12          font_family=0
   }
//   {column size=120             title="<html>Этап<br>производства</html>"
//        target=work_stage.name_work_stage        title_font_family=2     title_font_color="#000000"
//        halignment=left          font_size = 12          font_family=0
//   }

   {column size=80             title="<html>Кол-во к<br>производству"
        target=q_proiz       title_font_family=2     title_font_color="#000000"
        halignment=right         font_size = 12          font_family=0
        editmask = "# #0."
   }

   {datastore 
           alias = GRIDDS01
           query = "select active.id_active, active.name_active,
                           sum(spc_proiz.q1_spc) q_proiz,
                           head_proiz.date_sd
                      from head head_proiz, spc spc_proiz, active
                     where head_proiz.date_sd between to_date('01.'||to_char(to_date('~g.n_dat1~', 'dd.mm.yyyy'), 'mm.yyyy'), 'dd.mm.yyyy')
                                                  and last_day(to_date('~g.n_dat1~', 'dd.mm.yyyy')) 
                       and head_proiz.id_type_doc = 14
                       and head_proiz.accept = 1
                       and head_proiz.id_head = spc_proiz.id_head
                       and spc_proiz.id_active = active.id_active
                       ~($if (global.loading == 1)
                          (' and 1 = 0')
                         $else
                          (' ')
                        )~

                      ~($if (($try (g.search_string_gp) $catch ('NullException')(0)) == 0)
                           ('')
                         $else
                           (' and upper(active.name_active) like upper(\'%' + ($reg2ora g.search_string_gp) + '%\') ')
                        )~
                     group by active.id_active, active.name_active,
                           head_proiz.date_sd
                     order by active.name_active"
              editable = no
                selaction = "~($X
                                 ($if (($g.gridds01@size) > 0)
                                   (
                                    ($g.grid_group1@retrieve)
                                   )
                                 )
                                 ($ret '')
                               )~"
   } // end of ds
} // end of grid1
} // horizontal split
{button
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Выход (ESC)"
  action = "($g.self@actcancel)"
  shortcut = "escape"
}

} // toolbar
