Cp1251
DOC
foreground = lightgray 
document_width = 750
document_height = 550
document_title = "Нарезки"
style = "style/group.st"
preloadscript="
(global.retr = 0)
(global.id_h = 0)
"

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

{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel type=vertical     percent=20
{treeview2
   alias=tree1  
   listAction="retrieve grid_group1"  
   nodeAction="retrieve grid_group1"  
   nodefont="Courier,bold|italic,12"      pointfont="Courier,italic,12"  
   hilite=gray,white
   node=blue   point=blue
   rootname="Нарезки"
   hiliting=on
   storepath = yes

        {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 = 8"
                 grouping = "y;m;d"
                  sorting = "1;1;1"
        } // end of gr
} // end of tree
{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/doc_narezka.rml -1 ; retrieve grid_group1"
    edit = "opennew docs/doc_narezka~($if (($($($GRID_GROUP1@getDatastore)@getValue 'HEAD.NUM_SD')@substr 0 3) == 'НАР')
                                        ('')
                                      $else
                                        ('_vozvrat')
                                     )~.rml 
                               ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~ ;retrieve grid_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 gridds01"

   {menu
        {item label = "Добавить" action="createnew docs/doc_narezka.rml -1 ; retrieve tree1; retrieve grid_group1"}
        {item label = "-"}
        {item label = "Открыть" action="opennew docs/doc_narezka.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~ ;retrieve grid_group1"}
        {item label = "-"}
        {item label = "Удалить"
           action = "~($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') + ')')
    	          ($g.self@doAction 'retrieve tree1')
    	          ($g.self@doAction 'retrieve grid_group1')

               ($ret '')
            )~"
        }
        {item label = "-"}
        {item label = "Cписать нарезку со склада" 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 = "Вернуть остатки на склад" action= "createnew docs/doc_narezka_vozvrat.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~ ;retrieve grid_group1" }
   }
   {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=150             title="Склад"
        target=department.name1_dep
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=150             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_client1,client.name1_client,
                           head.id_client2,client2.name1_client,
                           head.id_department1,department.name1_dep,head.comment_sd,
                           head.accept,  document_author(head.id_head) author
                      from head,client,department,client client2
                     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_client1 = client.id_client (+)
                and head.id_client2 = client2.id_client (+)
                and head.id_department1 = department.id_department (+)                 
                and head.id_type_doc = 8
           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 = yes
             unique = "('head','head.id_head')"

          {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
} // end of split1
{button
  left = 72  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Выход ESC"
  action = "($g.self@actcancel)"
  shortcut = "escape"
}

} // toolbar
