Cp1251
DOC
foreground = lightgray 
document_width = 750
document_height = 550
document_title = "ZetaSE.Autocomplect/ Журнал документов Перемещение ТМЦ"
preloadscript="
(global.retr = 0)
(global.id_h = 0)
(global.id_head = -1)
(global.no_selaction = 0)
(global.show_all = 0)
"

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

{ datastore
  alias = check_children
  query = "select count(1) cnt
             from head
            where parent_id_head = ~global.id_head~"
}

{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel type=vertical     percent=20
{treeview2
   alias=tree1  
   listAction="retrieve grid_group1;retrieve grid_group2"
   nodeAction="retrieve grid_group1;retrieve grid_group2"  
   nodefont="Courier,bold|italic,12"      pointfont="Courier,italic,12"  
   hilite=gray,white
   node=blue   point=blue
   rootname="Перемещение ТМЦ"
   hiliting=on
   storepath = yes
   {menu
        {item label = "Показать все документы"
         action="~($X
                    (global.show_all = 1)
                    ($g.self@doAction 'retrieve tree1')
                    ($ret '')
                  )~"
        }
   }

        {groupreport 
          alias = datastore1
          query = "select distinct to_char(date_sd,'yyyy') y, to_char(date_sd,'mm') m ,
                          to_char(date_sd,'dd') d, date_sd 
                     from head
                    where head.id_type_doc = 96
                          ~($if (global.show_all != 0)
                              ('')
                            $else
                              # показывать последние два года
                              (' and head.date_sd > trunc(add_months(sysdate, -12), \'year\')')
                           )~"
                 grouping = "y;m;d"
                  sorting = "1;1;1"
        } // end of gr
} // end of tree
{ splitpanel type=horizontal     percent=70
{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 = 25
    add = "createnew docs/sklad.rml -1 ; retrieve grid_group1"
    edit = "opennew docs/sklad.rml ~($($GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' )~ ; retrieve grid_group1"
    del = "~($X
               (tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP1@getDatastore)@getValue '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 'ID_HEAD') + '); retrieve tree1; retrieve grid_group1')
            ($ret ''))~"

   {menu
        {item label = "Добавить" action="createnew docs/sklad.rml -1, -1 ; retrieve grid_group1"}
        {item label = "Копировать" action="createnew docs/sklad.rml -1, ~($($GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' )~; retrieve tree1;retrieve gridds01"}
        {item label = "-"}
        {menu label = "Ввести на основании"
                {item label = "Списание ТМЦ" 
                action="~($X
                           (global.id_head = ($($G.GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' ))
                           ($g.check_children@retrieve)
                           ($if (($g.check_children@getValue 'cnt') > 0)
                             (
                               ($g.self@sure 'Списание уже есть.' 1)
                               ($ret '')
                             )
                           )
                           ($g.self@doAction 'createnew docs/act_rash.rml -1, ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' ))
                           ($g.self@doAction 'retrieve grid_group2')
                           ($ret '')
                         )~"}
        }
        {item label = "-"}                
        {item label = "Провести по складам" action= "execute exec ~'doc_lib.accept('+($($GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' )+')'~ ;retrieve grid_group1;retrieve grid_group2" }        
        {item label = "Отменить проведение" action= "execute exec ~'doc_lib.de_accept('+($($GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' )+')'~ ;retrieve grid_group1;retrieve grid_group2" }
        {item label = "-"}
        {item label = "Просмотреть" action="open docs/sklad.rml ~($($GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' )~ "}
        {item label = "-"}
        {item label = "Печатная форма" action="open pech_form/pech_form_sklad.rml ~($($GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' )~"}
        {item label = "-"}
        {item label = "Обновить" action="retrieve grid_group1"}
        {item label = "Обновить все" action="retrieve tree1;retrieve grid_group1"}
        {item label = "-"}
        {item label = "Удалить"
           action = "~($X
                       ($IF (($($G.GRID_GROUP1@getDatastore)@getValue 'ACCEPT' ) == 1)
		             ((tmp = 'Запрещено удалять проведенный документ')
            		      (m = ($g.self@sure tmp 1))
		             )
			$else
	                 ((tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP1@getDatastore)@getValue '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 'ID_HEAD') + ');retrieve grid_group1')
			 )
		       )
		      ($ret ''))~"
        }
        {item label = "-"}
        {item label = "История изменений документа" action= "open reports/report_head_log.rml ~($($G.GRID_GROUP1@getDatastore)@getValue 'ID_HEAD')~"}
        {item label = "История изменений документа - построчно" action= "open reports/report_spc_log_doc.rml ~($($G.GRID_GROUP1@getDatastore)@getValue 'ID_HEAD')~"}
   }
   {column size=30             title="X"
        target=accept
        title_font_family=2
        title_font_color="#000000"
        halignment=center
        font_size = 12     
   }
   {column size=40             title="номер"      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
   }
   {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
   }
   {column size=70             title="Дата док."
        target=date_sd        title_font_family=2     title_font_color="#000000"
        halignment=center          font_size = 12          font_family=0
   }
   {column size=170             title="Склад источник"
        target=dep1_name1_dep
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=170             title="Склад приемник"
        target=dep2_name1_dep
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=100  
      title="<html>Перемещено в<br>производство на</html>"   
      target=date1  title_font_family=2   halignment=center
      font_color="#000000"    font_size=12            font_family=0
   }
   {column size=80            title="Сумма"
        target = sum1_sd
        title_font_family=2        title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        editmask = "# #0.00"
		visible = no
   }
   {column size=80             title="Основание"
        target=parent_doc
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {column size=200             title="Примечание"
        target=comment_sd
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {column size=170             title="Автор"
        target=author        title_font_family=2     title_font_color="#000000"
        halignment=left          font_size = 12          font_family=0
        editable = readonly
   }

   {datastore 
           alias = GRIDDS01
           query = "select id_head, num_sd, date_sd,
                           dep1_name1_dep, comment_sd,
                           dep2_name1_dep,
                           sum1_sd, accept,
                           date1, parent_doc,
                           author
                      from (
                     select head.id_head,head.num_sd,head.date_sd,
                           head.id_department1, department.name1_dep dep1_name1_dep, head.comment_sd,
                           head.id_department2, dep2.name1_dep dep2_name1_dep,
                           head.sum1_sd,
                           head.accept,
                           decode(nvl(head.id_contract, 0), 0, to_char(null), to_char(head.date1, 'Month YYYY')) date1,
                           head_parent.num_sd parent_doc,
                           document_author(head.id_head) author

                      from head,department,department dep2, head head_parent,personal
                     where head.date_sd ~ 
         ($if (($g.tree1@getLevel) == 0)
                   ($try ('=to_date(\''+
                   #  '01-01-0001' +
                   dscoll.date+                 
                  '\',\'dd-mm-yyyy\')') 
                $catch ('Any') ('=\'11-11-1999\'')
                    )
                $if (($g.tree1@getLevel) == 1)
                    ($try ('between
                            to_date(\'01-01-'+
                            datastore1.y+
             '\',\'dd-mm-yyyy\')
                         and
                            to_date(\'31-12-'+
                            datastore1.y+
             '\',\'dd-mm-yyyy\')')
                     $catch ('Any') ('=\'01-01-1999\'')
                     )               
                 $if (($g.tree1@getLevel) == 2)
                     ($if (($@number (datastore1.m)) == 12)
                          ($try ('between
                                  to_date(\'01-12-'+
                                  datastore1.y+
                   '\',\'dd-mm-yyyy\')
                                  and
                                  to_date(\'31-12-'+
                                  datastore1.y+
                   '\',\'dd-mm-yyyy\')')
                            $catch ('Any') ('=\'01-01-1999\'')
                            )                                  
                      $else ($try (' >= to_date(\'01-'+
                                      datastore1.m+                
                       '-'+
                       datastore1.y+
                       '\',\'dd-mm-yyyy\') 
                                  and 
                              head.date_sd < to_date(\'01-'+
                       ($(($@number (datastore1.m))+1)@int)+
                                      '-'+
                                      datastore1.y+
                       '\',\'dd-mm-yyyy\')')
                      $catch ('Any') ('=\'11-11-1999\'')
                      )  
                     )              
                 $else ($try ('=to_date(\''+
                  datastore1.d+
                  '-'+
                  datastore1.m+
                  '-'+
                  datastore1.y+
                  '\',\'dd-mm-yyyy\')') 
                    $catch ('Any') ('=\'11-11-1999\'')
                        )
                 ) ~ 
             and head.id_department1 = department.id_department (+)                 
             and head.id_department2 = dep2.id_department (+)                    
             and head.last_changed = personal.id_personal (+)
             and head.id_type_doc = 96
             and head_parent.id_head (+) = head.parent_id_head
                 )
           order by date_sd, num_sd
           
           ~($X ($if (($($G.GRID_GROUP1@getDatastore)@size)>0) (global.id_h =($($G.GRID_GROUP1@getDatastore)@getValue 'ID_HEAD' ))) ($ret ''))~
           
           "
             selaction = "~($X
                              ($debug 'global.no_selaction = ' + global.no_selaction)
                              ($if (global.no_selaction == 0)
                                ($g.self@doAction 'retrieve grid_group2')
                              )
                              ($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 '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
{ tabset labels = "Порожденные документы"
{ grid
  alias = GRID_GROUP2
  buttonbar_font_family = 0              buttonbar_font_size = 12
  buttonbar_size = 30                    titlebar_size = 18
  multiselect = no                      editable = no
  rowsize = 25
  edit = "opennew ~($($GRID_GROUP2@getDatastore)@getValue 'TYPE_DOC.DOC_NAME' )~ ~($($GRID_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD' )~, -1"
  del = "~($X
             (tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP2@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_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD') + '); retrieve grid_group2')
          ($ret ''))~"

 {menu
      {item label = "Провести по складам" action= "execute exec ~'doc_lib.accept('+($($GRID_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve grid_group2" }        
      {item label = "Отменить проведение" action= "execute exec ~'doc_lib.de_accept('+($($GRID_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve grid_group2" }
      {item label = "-"}
      {item label = "Удалить"
         action = "~($X
                     ($IF (($($G.GRID_GROUP2@getDatastore)@getValue 'HEAD.ACCEPT' ) == 1)
             ((tmp = 'Запрещено удалять проведенный документ')
          		      (m = ($g.self@sure tmp 1))
             )
	$else
	                 ((tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP2@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_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD') + '); retrieve grid_group2')
	 )
       )
      ($ret ''))~"
      }
      {item label = "-"}
      {item label = "Обновить" action="retrieve grid_group2"}
 }
 {column size=30             title="X"
      target=head.accept
      title_font_family=2
      title_font_color="#000000"
      halignment=center
      font_size = 12     
 }
 {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
 }
 {datastore 
         alias = GRIDDS02
         query = "select head.id_head,head.num_sd,head.date_sd,
                         head.id_department1,
                         head.id_department2,
                         head.accept,
                         type_doc.doc_name
                    from head, type_doc
                  where head.parent_id_head = ~($if (($g.gridds01@size) == 0)
                                                  (-1)
                                                 $else
                                                  ($g.gridds01@getValue 'id_head')
                                                )~ 
                     and head.id_type_doc = type_doc.id_type_doc
                order by head.date_sd,head.num_sd"
         editable = no
 } // end of ds
}// end of grid
} //tabset
}// end of horizontal split
} // end of vertical split
{button
  left = 72  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Выход ESC"
  action = "($g.self@actcancel)"
  shortcut = "escape"
}

} // toolbar
