Cp1251
DOC
foreground = lightgray 
document_width = 1100
document_height = 800
document_title = "Журнал заказов"
preloadscript="
(global.loading = 1)
(global.retr = 0)
(global.id_h = 0)
(global.no_selaction = 0)
(global.id_client = -999)
(global.id_active = -1)
(global.data1 = '01.01.0001')
(global.dat1 = '01.01.0001')
($debug 'ARGUMENTS debug ================== ')
($debug 'ARGUMENTS size: ' + ($ARGUMENTS@size))
#($debug 'ARGUMENTS: ' + ($ARGUMENTS))
#($debug 'ARGUMENTS.0 size: ' + ($ARGUMENTS.0@size))
#($debug 'ARGUMENTS.1 size: ' + ($ARGUMENTS.1@size))
#($debug 'ARGUMENTS.2 size: ' + ($ARGUMENTS.2@size))
"

postloadscript = "(global.loading = 0)"


   { datastore
     alias = check_zakaz
     query = "select char_date_sd
                from (
              select head.num_sd, head.date_sd, to_char(head.date_sd, 'dd.mm.yyyy') char_date_sd
                from head
               where id_type_doc = 9
                 and id_client1 = ~global.id_client~
                 and date1 between trunc(to_date('~global.data1~', 'dd.mm.yyyy'), 'month')
                             and last_day(to_date('~global.data1~', 'dd.mm.yyyy'))
                     )"
   }

   { datastore
     alias = data1
     query = "select trunc(sysdate, 'month') dat1
                from dual"
   }




{toolbar   BACKGROUND = "#c0c0c0"
{splitpanel type=horizontal   percent=10 gapsize = 10
{form bg_color="#c0c0c0"


   {button left = 10 top = 10 width = 130 height = 25 label = "Создать заказ"
     action = "($X
                 ($if (($try (g.field_id_client) $catch ('NullException')(0)) == 0)
                    (
                      ($g.self@sure 'Поставщик не указан.' 1)
                      ($ret '')
                    )
                 )
                 (global.id_client = g.field_id_client)
                 ($g.check_zakaz@retrieve)
                 ($if (($g.check_zakaz@size) > 0)
                    ($if (($g.self@sure 'У поставщика уже есть заказы в этом месяце. Создать еще один?' 0) == 0)
                      ($ret '')
                    )
                 )
                 ($g.self@doAction 'createnew docs/doc_zakaz.rml -1, ' +  g.field_id_client)
                 ($g.self@doAction 'retrieve GRID_GROUP0')
                 ($g.self@doAction 'retrieve GRID_GROUP1')
                 ($ret '')
               )"
    icon = "images/new1.png"
    tooltiptext = "Сформировать заказ выбранному поставщику"
   }
  {label left = 150 top = 10 width = 80 height = 20 font_size = 12 value = "Поставщик" }
  { field left = 240 top = 10 width = 200 height = 25 font_size = 12 alias = field_name_client  type = string
    editable = handbook
    edit = "opennew find_client.rml"
    editexp = "($X
                   (g.field_name_client = store.client.name1_client)
                   (g.field_id_client = store.client.id_client)
                   ($ret '')
                )"
    
  }
  { field left = 240 top = 50 width = 200 height = 25 font_size = 12 alias = field_id_client  type = number
    visible = no
  }


   {button left = 450 top = 10 width = 28 height = 25
     action = "($X
                 (g.field_name_client = '')
                 (g.field_id_client = 0)
                 ($ret '')
               )"
    icon = "images/delete1.png"
    tooltiptext = "Очистить поле \"Поставщик\""
   }
      
   {label left = 5 top = 40 width = 54 height = 30 font_size = 14 value = "Дата с" }
   { field left = 50 top = 45 width = 90 height = 25 font_size = 13 alias = dat1  target = month_beginning
     dep = "n_dat1"
   }
   {field  alias=n_dat1  type=string 
     left = 50 top = 40 width = 90 height = 30 font_size = 16	visible = no
     exp="($X
            (g.n_dat1 = ($($@date g.dat1)@toPLString))
            ($debug 'n_dat1 = ' + g.n_dat1)
            ($ret '')
          )" 
   }
   {label left = 150 top = 40 width = 25 height = 30 font_size = 14 value = "по" }
   { field left = 170 top = 45 width = 90 height = 25 font_size = 13 alias = dat2  target = months3
     dep = "n_dat2"
   }
   {field  alias=n_dat2  type=string 
     left = 175 top = 40 width = 100 height = 25 font_size = 12	visible = no
     exp="($X
            (g.n_dat2 = ($($@date g.dat2)@toPLString))
            ($debug 'n_dat2 = ' + g.n_dat2)
            ($ret '')
          )" 
   }
   { button left = 270 top = 45 width = 27 height = 27 
     icon = "images/reload.png"
     tooltiptext = "Обновить данные"

     action = "($X
                  ($g.self@doAction 'retrieve GRID_GROUP0')
                  ($g.self@doAction 'retrieve GRID_GROUP1')
                  ($ret '')
               )"
   }


      {datastore  alias=date_ds
        query="select month_beginning, month_end, months3
                 from (
               select to_date('01.'||to_char(sysdate, 'mm.yyyy'), 'dd.mm.yyyy') month_beginning,
                      last_day(to_date('01.'||to_char(sysdate, 'mm.yyyy'), 'dd.mm.yyyy')) month_end,
                      last_day(add_months(trunc(sysdate, 'month'), 2)) months3
                 from dual
                      )"
        
      }

}
{ splitpanel percent = 20 type = vertical

{grid
    alias = GRID_GROUP0
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
                                           titlebar_height = 40
    multiselect = yes                      editable = yes
    rowsize = 25
    del = ""

     edit=""

    { menu

        {item label = "Удалить все заказы поставщика"
           action = "~($X

                   ($if (($g.self@sure 'Вы уверены, что хотите удалить все заказы поставщика ' + ($g.gridds00@getValue 'client.name1_client') + ' ?' 0) == 0)
                     ($ret '')
                   )
                   ($g.self@doAction 'execute exec util.del_client_docs(' + ($g.gridds00@getValue 'client.id_client') + ', 9)');
                   ($g.self@doAction 'retrieve GRID_GROUP0')
                   ($g.self@doAction 'retrieve GRID_GROUP1')
                   ($ret '')
                   )~"
        }
     }

   
   {column size=200            title="Поставщик"
        target=client.name1_client    title_font_family=2     title_font_color="#000000"
        halignment=center            font_size = 12          font_family=0
        alias = column_name_client
        editable = readonly
        //editable = handbook
        //edit="open find_client.rml"
        editexp="($X
                    ($debug 'ds size : ' + ($g.gridds01@size))
                    (g.column_name_client = STORE.client.id_client)
                    (g.column_id_client = STORE.client.id_client)
                    ($g.self@actSave)
                    ($g.self@doAction 'execute exec commit')
                    ($ret '')
                 )"
   }

   {datastore 
           alias = GRIDDS00
           query = "select client.id_client, client.name1_client
                      from spc, active, client, head, client client_main
                     where head.id_active = active.id_active (+)
                       and head.id_type_doc = 9
                       and nvl(spc.date1, to_date('~g.n_dat1~', 'dd.mm.yyyy')) between to_date('~g.n_dat1~', 'dd.mm.yyyy') and to_date('~g.n_dat2~', 'dd.mm.yyyy')
                       and client_main.id_client = 602
                       and spc.id_head = head.id_head
                       and head.id_client1 = client.id_client
                     group by client.id_client, client.name1_client
                     order by client.name1_client"

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


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


{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
    del = "~($X
               (tmp = 'Вы уверены, что хотите удалить заказ ?')
               (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 grid_group1')
            ($ret ''))~"

     edit="opennew docs/doc_zakaz.rml ~($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD')~, -1;retrieve grid_group1"

   {menu
        {item label = "Скопировать заказ"
           action = "~($X
                         ($g.self@doAction 'createnew docs/doc_zakaz.rml ' +  ($try ($G.GRIDDS01@getValue 'head.id_head') $catch ('Any')(-1)) + ', -999')
                         ($g.self@doAction 'retrieve GRID_GROUP1')
                         ($ret '')
                   )~"

        }
        {item label = "-"}
        {item label = "Статус: черновик"
           action = "~($X
	                  ($g.self@doAction 'execute exec update head set accept = 0 where id_head = ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD'))
                          ($g.self@actSave)
                          ($g.self@doAction 'execute exec commit')
	                  ($g.self@doAction 'retrieve grid_group1')
	                  ($ret '')
	              )~"
	}
        {item label = "Статус: согласован"
           action = "~($X
	                  ($g.self@doAction 'execute exec update head set accept = 1 where id_head = ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD'))
                          ($g.self@actSave)
                          ($g.self@doAction 'execute exec commit')
	                  ($g.self@doAction 'retrieve grid_group1')
	                  ($ret '')
	              )~"
	}
        {item label = "Статус: закрыт"
           action = "~($X
	                  ($g.self@doAction 'execute exec update head set accept = -1 where id_head = ' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD'))
                          ($g.self@actSave)
                          ($g.self@doAction 'execute exec commit')
	                  ($g.self@doAction 'retrieve grid_group1')
	                  ($ret '')
	              )~"
	}
        {item label = "-"}
        {item label = "Удалить заказ"
           action = "~($X
		         (tmp = 'Вы уверены ?')
	                  (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@actSave)
                          ($g.self@doAction 'execute exec commit')
	                  ($g.self@doAction 'retrieve grid_group1')
	                  ($ret '')
	              )~"
	}
        {item label = "-"}
        {item label = "Оприходовать"
           action = "createnew docs/prih.rml -1, ~($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD')~; retrieve grid_group1"
        }

   }
   {column size=100             title="id_head"
        target=head.id_head      title_font_family=2     title_font_color="#000000"
        halignment=left            font_color="#000000"     
        font_size = 12             font_family=0
        editable = readonly     editmask = "##0."
        visible = no
   }
   {column size=40             title="X"
        target=accept       title_font_family=2     title_font_color="#000000"
        halignment=center            font_color="#000000"     
        font_size = 12             font_family=0
        editable = readonly
   }
   {column size=100             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
        editable = readonly
   }
   {column size=100             title="Дата поставки"
        target=date1       title_font_family=2     title_font_color="#000000"
        halignment=left            font_color="#000000"     
        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_color="#000000"     
        font_size = 12             font_family=0
        editable = readonly
   }
   {datastore 
           alias = GRIDDS01
           query = "select head.id_head,  util.orderMinDate(head.id_head) date1, head.num_sd, head.comment_sd,
                           decode(head.accept, 0, '', 1, 'X', -1, '--', 'Z') accept
                      from head
                     where head.id_type_doc = 9
                       and head.id_client1 =  ~($try ($G.GRIDDS00@getValue 'client.id_client') $catch ('Any')(-1))~
                       and ( 
                             nvl(util.orderMinDate(head.id_head), to_date('~g.n_dat1~', 'dd.mm.yyyy')) between to_date('~g.n_dat1~', 'dd.mm.yyyy') and to_date('~g.n_dat2~', 'dd.mm.yyyy')
                             or
                             nvl(util.orderMaxDate(head.id_head), to_date('~g.n_dat1~', 'dd.mm.yyyy')) between to_date('~g.n_dat1~', 'dd.mm.yyyy') and to_date('~g.n_dat2~', 'dd.mm.yyyy')
                           )
                       ~($X 
                           ($if (($G.gridds01@size)>0) 
                             (global.id_h =($G.gridds01@getValue 'HEAD.ID_HEAD' ))
                           ) 
                           ($ret '')
                        )~
                     order by head.date1"




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

} // toolbar
