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.show_all = 0)
"

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

{datastore
 alias = children
  query = "select cnt
             from (
		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 = 57
                           ~($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
    multiselect = yes                      editable = no
    rowsize = 25
    add = "createnew docs/act_rash.rml -1, -1 ; retrieve gridds01"
    edit = "opennew docs/act_rash.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~, -1 ; retrieve gridds01"
    del = "~($X
               (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 tree1; retrieve grid_group1')
            ($ret ''))~"

   {menu
        {menu label = "Сформировать"
           {item label = "новое Списание" action="createnew docs/act_rash.rml -1, -1 ; retrieve tree1; retrieve gridds01"}
           {item label = "копию Списания" action="createnew docs/act_rash.rml -1, ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~; retrieve tree1; retrieve gridds01"}
        }
        {menu label = "Ввести на основании"
              {item label = "Приход ТМЦ" action="createnew docs/act_prih.rml -1,~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~ ; retrieve grid_group2"}
        }
        {item label = "-"}
        {item label = "Списать" action= "execute exec ~'doc_lib.accept('+($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve gridds01" }        
        {item label = "Отменить списание" action= "execute exec ~'doc_lib.de_accept('+($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve gridds01" }            
        {item label = "-"}
        {item label = "Просмотр" action="open docs/act_rash.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~ ;retrieve gridds01"}
        {item label = "-"}
        {menu label = "Печатные формы и отчёты"
           {item label = "печатная форма" action="open pech_form/pech_form_act_rash.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~"}
           {item label = "печатная форма (M11)" action="open pech_form/pech_form_m11.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~"}
        }
        {item label = "-"}        
        {item label = "Обновить" action="retrieve gridds01"}
//        {item label = "Обновить все" action="retrieve tree1;retrieve gridds01"}
//        {item label = "Добавить" action="create docs/act_rash.rml -1 ; retrieve tree1;retrieve gridds01"}
        {item label = "-"}
        {item label = "Удалить"
           action = "~($X
                       ($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 tree1; retrieve grid_group1')
			 )
		       )
            ($ret ''))~ "
        }
   }
   {column size=40             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=70             title="N док."
        target=head.num_sd         title_font_family=2     title_font_color="#000000"
        halignment=center            font_color="#000000"     
        font_size = 12             font_family=0
   }
   {column size=80             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=parent_doc
        title_font_family=2        title_font_color="#000000"
        halignment=center            font_size = 12          font_family=0
   }                  
   {column size=200             title="Склад"
        target=head.id_department1           visible=no
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=200             title="Склад"
        target=department.name1_dep
        title_font_family=2        title_font_color="#000000"
        halignment=center            font_size = 12          font_family=0
   }                  
   {column size=80            title="Сумма"
        target = "UTIL.DOC_SUM(HEAD"
        title_font_family=2        title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        editmask = "# #0.00"	   visible = no
   }
   {column size=170             title="Автор"
        target=author        title_font_family=2     title_font_color="#000000"
        halignment=left          font_size = 12          font_family=0
        editable = readonly
   }
   {column size=250             title="Примечание"
        target=head.comment_sd
        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.id_department1,department.name1_dep,head.comment_sd,
                           util.doc_sum(head.id_head) \"UTIL.DOC_SUM(HEAD\",
                           head.accept,  document_author(head.id_head) author,
                           util.parent_doc(head.id_head) parent_doc
                      from head,department
                     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 
                              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_type_doc = 57
           order by head.date_sd,head.num_sd
                       ~($X 
                           ($if (($G.gridds01@size)>0) 
                             (global.id_h =($G.gridds01@getValue 'HEAD.ID_HEAD' ))
                           ) 
                           ($ret '')
                        )~
               "
           editable = no
             selaction = "retrieve grid_group2"

          {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
{ 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' )~"
  del = "~($X
              (global.id_head = ($($G.GRID_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD' ))
              ($g.children@retrieve)
              ($if (($g.children@getValue 'cnt') > 0)
			    (
				  ($g.self@sure 'Удаление документа невозможно, т.к. есть порожденные из него документы.' 1)
				  ($ret '')
				)
			  )
             (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
              (global.id_head = ($($G.GRID_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD' ))
              ($g.children@retrieve)
              ($if (($g.children@getValue 'cnt') > 0)
			    (
				  ($g.self@sure 'Удаление документа невозможно, т.к. есть порожденные из него документы.' 1)
				  ($ret '')
				)
			   )
                     ($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 ''))~"
      }
 }
 {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 'head.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
