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.show_all = 0)
"
{DSCollection
   alias = dscoll
   SeqQuery = "select to_char(sysdate) from dual"
   seqnames = "date"
}


{datastore
 alias = plan_proiz
 query = "select id_head, num_sd, to_char(date_sd, 'dd.mm.yyyy') date_sd_char
            from head
           where date_sd between to_date('01.'||to_char(to_date('~g.date_sd_char~', 'dd.mm.yyyy'), 'mm.yyyy'), 'dd.mm.yyyy')
                             and last_day(to_date('~g.date_sd_char~', 'dd.mm.yyyy'))
             and id_type_doc = 14
             and accept = 1"
}
{datastore
 alias = check_spec
 query = "select spc.id_active, active.name_active
            from spc, active
           where spc.id_head = ~($G.gridds01@getValue 'head.id_head')~
             and spc.id_active = active.id_active
             and not exists (
                              select 1 from head where id_type_doc = 10 and accept in (1, 3) and id_active = spc.id_active -- and sort < ~($G.gridds01@getValue 'head.sort')~
                            )"
}

{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel type=vertical     percent=20
{treeview2
   alias=tree1  
   listAction="retrieve gridds01"  
   nodeAction="retrieve gridds01"  
   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 = 14
                           ~($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
{grid
    alias = GRID_GROUP1
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
    multiselect = yes                      editable = no
    rowsize = 20
    edit = "opennew docs/plan_proiz.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~ ; retrieve tree1; 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
        {item label = "Обновить" action="retrieve tree1;retrieve gridds01"}
        {item label = "Добавить" action="createnew docs/plan_proiz.rml -1, -1 ; retrieve tree1;retrieve gridds01"}
        {item label = "Копировать" action="createnew docs/plan_proiz.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~, -1 ; retrieve tree1;retrieve gridds01"}
        {item label = "-"}
        {item label = "Печатная форма" action="open pech_form/pech_form_plan_proiz.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~"}
        {item label = "-"}
        {item label = "Удалить"
           action = "~($X
                       ($IF (($($G.GRID_GROUP1@getDatastore)@getValue 'ACCEPT' ) == 'X')
		             ((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 ''))~"
        }
        {item label = "-"}
        {item label = "Утвердить" 
         action= "~($X
                     ($if (($($G.GRID_GROUP1@getDatastore)@getValue 'ACCEPT') == 'X')
                        ($ret '')
                     )

                     #($g.plan_proiz@retrieve)
                     #($if (($g.plan_proiz@size) > 0)
                     #  ($if (($g.self@sure 'В этом месяце уже есть утвержденный план производства ' + ($g.plan_proiz@getValue 'num_sd') + ' от ' + ($g.plan_proiz@getValue 'date_sd_char') + '. Вы хотите его отменить и утвердить план ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.NUM_SD') + '?' 0) == 0)
                     #    ($ret '')
                     #  )
                     #)

                     # проверяем, что у всей продукции, внесенной в этот план производства, есть актуальная спецификация

                     ($g.check_spec@retrieve)
                     ($if (($g.check_spec@size) > 0)
                       (
                         (str = 'В плане производства присутствует продукция, для которой не задана спецификация:%%')
                         (i = 0)
                         ($while (i < ($g.check_spec@size))
                           (
                             ($g.check_spec@SetCurRow i)
                             (str += '(' + ($($g.check_spec@getValue 'spc.id_active')@int) + ') ' + ($g.check_spec@getValue 'active.name_active') + '%')
                             (i += 1)
                           )
                         )
                         (str += '%Вы уверены, что хотите утвердить план производства?')
                         ($if (($g.self@sure str 0) == 0)
                           ($ret '')
                         )
                       )
                     )

                     ($g.self@doAction 'execute exec doc_lib.accept('+($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+');retrieve gridds01')
                     ($ret '')
                  )~"
        }        
        {item label = "Отменить" action= "execute exec ~'doc_lib.de_accept('+($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ;retrieve gridds01" }            
   }
   {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=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=80             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=200             title="Склад"
        target=department.name1_dep         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="Дата док. dd.mm.yyyy"
        target="date_sd_char"        title_font_family=2     title_font_color="#000000"
        halignment=center          font_size = 12          font_family=0
        visible = no
        alias = date_sd_char
   }
   {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=70             title="Склад"
        target=department.name1_dep
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
        visible=no
   }                  
   {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.sort, head.num_sd,head.date_sd, to_char(head.date_sd, 'dd.mm.yyyy') date_sd_char,
                           head.id_department1,department.name1_dep,head.comment_sd,
                           decode(head.accept, 1, 'X', ' ') accept
                      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 = 14
           order by head.sort
                       ~($X 
                           ($if (($G.gridds01@size)>0) 
                             (global.id_h =($G.gridds01@getValue 'HEAD.ID_HEAD' ))
                           ) 
                           ($ret '')
                        )~

           "
          {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
