Cp1251
DOC
foreground = lightgray 
document_width = 750
document_height = 550
document_title = "Акт инвентаризации"
style = "style/group.st"
preloadscript="
(global.retr = 0)
(global.id_h = 0)
(global.d1 = ('\''+'01.01.2003'+'\'') )
(global.find = -1)
(global.h = ($@hash))
($global.h@put 'find' global.find)
($global.h@put 'id_head' global.id_h )
(global.no_selaction = 0)
(global.show_all = 0)
"
POSTLOADSCRIPT = "($X

                     ($ret '')

                  )"

{DSCollection
   alias = dscoll
   SeqQuery = "select to_char(sysdate) from dual"
   seqnames = "date"
}
 {datastore 
      alias = doc_child
      query = "select id_head
                 from head
                where parent_id_head = ~($try ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' ) $catch ('NullException') (-1) )~ "
} // ds
 {datastore 
      alias = doc_child_prih
      query = "select id_head
                 from head
                where parent_id_head = ~($try ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' ) $catch ('NullException') (-1) )~ 
                  and id_type_doc = 55"
} // ds
 {datastore 
      alias = doc_child_rash
      query = "select id_head
                 from head
                where parent_id_head = ~($try ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' ) $catch ('NullException') (-1) )~ 
                  and id_type_doc = 57"
} // ds

{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel type=vertical     percent=20   gapsize = 10
{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 = 54
                          ~($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 gapsize = 10
{grid
    alias = GRID_GROUP1
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselect = yes                      editable = no
    rowsize = 20
    add = "createnew docs/inv.rml -1, &_SELECTION 
     ~($X 
          ($($g.self@getAliases)@put '_SELECTION' global.h) 
          ($ret '') 
      )~; retrieve tree1;retrieve gridd_group1"
    edit = "opennew docs/inv.rml ~($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~, &_SELECTION 
     ~($X 
          ($($g.self@getAliases)@put '_SELECTION' global.h) 
          ($ret '') 
      )~; retrieve tree1;retrieve gridd_group1"
    del = "~($X
               (tmp = 'Вы действительно хотите удалить документ №' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.NUM_SD' ) + '')
               (m = ($g.self@sure tmp 0))
               ($if (m == 0)
                   ($ret 'NOTDELETE')
               )
               ($g.self@doAction 'execute exec util.del_doc(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD') + '); retrieve grid_group1')
            ($ret 'NOTDELETE'))~ ;retrieve gridd_group1"

   {menu
        {item label = "Обновить" action="retrieve grid_group1"}
        {item label = "Обновить все" action="retrieve tree1;retrieve grid_group1"}
        {item label = "Добавить" action="
     ~($X 
          ($($g.self@getAliases)@put '_SELECTION' global.h) 
          ($g.self@doAction 'createnew docs/inv.rml -1, &_SELECTION')
          ($g.self@doAction 'retrieve tree1')
          ($g.self@doAction 'retrieve grid_group1')
          ($ret '') 
      )~"}
        {item label = "-"}
        {item label = "Просмотреть" action="opennew docs/inv.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~, &_SELECTION 
     ~($X 
          ($($g.self@getAliases)@put '_SELECTION' global.h) 
          ($ret '') 
      )~; retrieve tree1;retrieve grid_group1"}
        {item label = "-"}
	{menu label = "Печатные формы"
           {item label = "Акт инвентаризации" action="open pech_form/pech_form_inv.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~"}
           {item label = "Сличительная ведомость" action="open pech_form/pech_form_slich_ved.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~"}
	}        
	{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') + ')')
          	          (global.id_h = 0)
          	          ($g.self@doAction 'retrieve gridds01')
	  	         )
		       )	
	               ($ret '')
	              )~"
        }
        {item label = "-"}
        {item label = "Принять на склад" action= "execute exec ~'doc_lib.accept('+($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve gridds01" } 
        {item label = "Изъять со склада" action= "~($X
				($g.doc_child@retrieve)
	                   ($IF (($g.doc_child@size ) != 0)
		             ((tmp = 'Нельзя отменять проведение, т.к. есть порожденные документы.')
            		      (m = ($g.self@sure tmp 1))
		             )
			    $else
	                    ($g.self@doaction 'execute exec doc_lib.de_accept(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' ) + ') ;retrieve gridds01' ) 
			   )
			  ($RET ''))~ " } 
        {item label = "-"}
        {item label = "Добавить позиции, имеющие остатки на складе, с нулевым количеством"
           action= "~($X
	   		($IF (($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ACCEPT') != 0)
	   		  (
          		    ($g.self@sure 'Для выполнения процедуры документ должен быть не проведен.' 1)
					($Ret '')
              )
            )
   		    ($if (($g.self@sure 'Эта процедура занулит остатки активов на складе, кроме уже введенных в документ, т.е. добавит в документ инвентаризации с указанием кол-ва = 0 все активы данного склада с ненулевым остатком, кроме уже внесенных в документ.            Вы уверены?' 0) == 0)
				($Ret '')
			)
            ($g.self@doaction 'execute exec util.add_inv_zeros(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' ) + ')' ) 
            ($RET '')
                   )~ " 
        } 
        {item label = "-"}
        {menu label = "Ввести на основании"
          {item label = "Списание ТМЦ" action="~($X
	                   ($IF (($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ACCEPT' ) == 0)
		             (
		              (tmp = 'Нельзя создавать документы%на основании непроведенной инвентаризации.')
            		      (m = ($g.self@sure tmp 1))
            		      ($ret '')
		             )
			   )
			   ($g.doc_child_rash@retrieve)
	                   ($IF (($g.doc_child_rash@size ) != 0)
		             (
		               (tmp = 'Уже есть расходный документ, созданный на основании данной инвентаризации.')
            		       (m = ($g.self@sure tmp 1))
            		       ($ret '')
		             )
			   )

                          #($g.self@doaction 'createnew docs/act_rash.rml -1 ,'+($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+';retrieve grid_group2' )

                          ($g.self@doaction 'execute exec util.create_child_doc( ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' ) + ', 57) ;retrieve grid_group2' )
			  ($RET ''))~"
          }
          {item label = "Оприходование ТМЦ" action="~($X
	                   ($IF (($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ACCEPT' ) == 0)
		             (
		              (tmp = 'Нельзя создавать документы%на основании непроведенной инвентаризации.')
            		      (m = ($g.self@sure tmp 1))
                              ($ret '')
		             )
			   )
			   ($g.doc_child_prih@retrieve)
	                   ($IF (($g.doc_child_prih@size ) != 0)
		             (
		               (tmp = 'Уже есть приходный документ, созданный на основании данной инвентаризации.')
            		       (m = ($g.self@sure tmp 1))
            		       ($ret '')
		             )
			   )

                          #($g.self@doaction 'createnew docs/act_prih.rml -1 ,'+($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+';retrieve grid_group2' )

                          ($g.self@doaction 'execute exec util.create_child_doc( ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' ) + ', 55) ;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
   }
   {column size=70             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=left            font_size = 12          font_family=0
   }                  
   {column size=80            title="Сумма"
        target = summ
        title_font_family=2        title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        editmask = "# #0.00"
   }
   {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=200             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) summ,
                           head.accept,  document_author(head.id_head) author
                      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 = 54
           order by head.date_sd,head.num_sd"

                selaction = "~($X
                                 ($if (global.no_selaction == 1)
                                   ($ret '')
                                 )
                                 ($g.grid_group2@retrieve)
                                 ($ret '')
                               )~"

   
   } // end of ds
} // end of grid

{grid
    alias = GRID_GROUP2
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselect = yes                      editable = no
    rowsize = 20
    edit = "opennew ~($($G.GRID_GROUP2@getDatastore)@getValue 'type_doc.doc_name' )~ ~($($G.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 'NOTDELETE')
               )
               ($g.self@doAction 'execute exec util.del_doc(' + ($($G.GRID_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD') + '); retrieve grid_group2')
            ($ret 'NOTDELETE'))~ ;retrieve grid_group2"

   {menu
        {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') + ')')
          	          ($g.self@doAction 'retrieve grid_group2')
	  	         )
		       )	
	              ($ret '')
	              )~"
        }
        {item label = "-"}
        {item label = "Принять на склад" action= "execute exec doc_lib.accept( ~($($G.GRID_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD' )~);retrieve grid_group2" } 
        {item label = "Изъять со склада" action= "execute exec doc_lib.de_accept(~($($G.GRID_GROUP2@getDatastore)@getValue 'HEAD.ID_HEAD' )~) ;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
   }
   {column size=70             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=left            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"
   }
   {column size=200             title="Примечание"
        target=head.comment_sd
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {datastore 
           alias = GRIDDS02
           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, type_doc.doc_name
                      from head,department, type_doc
                     where head.parent_id_head = ~($try ($g.gridds01@getvalue 'head.id_head') $catch ('Any')(-1))~~ 
                       and head.id_department1 = department.id_department 
                       and head.id_type_doc in (55, 57)
                       and head.id_type_doc = type_doc.id_type_doc
                     order by head.sort"
   } // end of ds
} // end of grid

} // 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
