Cp1251
DOC
foreground = lightgray 
document_width = 750
document_height = 550
document_title = "ZetaSE.Autocomplect/Поступление ТМЦ и услуг"
preloadscript="
(global.retr = 0)
(global.id_h = 0)
(global.id_client = -111)
($defun refresh<arg>
  ($X
     ($g.grid_group1@retrieve)
     (g.sum1 = ($try ($g.gridds01@sum 'head.sum1_sd') $catch ('Any')(0)))
     (g.sum2 = ($try ($g.gridds01@sum 'HEAD.SUM2_SD - HEAD') $catch ('Any')(0)))
     (g.sum3 = ($try ($g.gridds01@sum 'head.sum2_sd') $catch ('Any')(0)))
     (g.sum4 = ($try ($g.gridds01@sum 'head.sum3_sd') $catch ('Any')(0)))
     ($ret '')
   )
)
"

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

{toolbar   BACKGROUND = "White"
{splitpanel type=horizontal     percent=15
{form
  {label left = 10 top = 10 width = 54 height = 30 font_size = 14 value = "Дата с" }

  { field left = 60 top = 10 width = 100 height = 30 font_size = 16 alias = dat1  target = dat1
    dep = "n_dat1" visible = yes
  }
  {field  visible=no   alias=n_dat1  type=string 
    left = 50 top = 10 width = 100 height = 30 font_size = 16
    exp="($X
            
           (g.n_dat1 = ($($@date g.dat1)@toPLString))
           ($debug 'n_dat1 = ' + g.n_dat1)
           ($refresh)
           ($ret '')
         )" 
  }
  {label left = 170 top = 10 width = 30 height = 30 font_size = 14 value = "по" }

  { field left = 190 top = 10 width = 100 height = 30 font_size = 16 alias = dat2  target = dat2
    dep = "n_dat2" visible = yes
  }
  {field  visible=no   alias=n_dat2  type=string 
    left = 50 top = 10 width = 100 height = 30 font_size = 16
    exp="($X
            
           (g.n_dat2 = ($($@date g.dat2)@toPLString))
           ($debug 'n_dat2 = ' + g.n_dat2)
           ($refresh)
           ($ret '')
         )" 
  }

  {label  value="Поставщик:" halignment = right
    top=52  left=10  width=100  height=20  bg_color="#c0c0c0" font_size = 14
  }
  {field
    alias=field_client  type=string
    left=130  top=50  height=25  width=280  border=box  font_size=12  font_family=0  bg_color="#ffffff"
    editable = handbook
    edit = "opennew find_client.rml 1  2, 4, 6"
    editexp = "($X
                  (g.field_client = store.client.name1_client)
                  (global.id_client = store.client.id_client)
                  ($refresh)
                  ($ret '')
               )"
  }
   {button left = 420 top = 52 width = 28 height = 25
     action = "($X
                 (g.field_client = '')
                 (global.id_client = -111)
                 ($refresh)
                 ($ret '')
               )"
    icon = "images/delete1.png"
    tooltiptext = "Очистить поле \"Поставщик\""
   }

  {button
   left = 300 top = 10 width = 250 height = 30 font_size = 14
   label = "Отчет \"Поставки ТМЦ/Услуг\""
   action = "($X
                ($g.self@doAction 'open reports/report_history_prih.rml')
                ($ret '')
             )"
  }

  {label  value="Документ:" halignment = right
    top=90  left=10  width=70  height=20  bg_color="#c0c0c0" font_size = 14
  }
  {field
    alias=field_doc  type=string
    left=80  top=90  height=25  width=100  border=box  font_size=12  font_family=0  bg_color="#ffffff"
    dep = doc_search
    firstfocus = yes
  }
  { field left = 510 top = 92 width = 200 height = 30 font_size = 16 alias = doc_search  type = string visible = no
    exp = "($X
              ($refresh)
              ($ret '')
           )"
  }
  {label  value="Первичка:" halignment = right
    top=90  left=190  width=70  height=20  bg_color="#c0c0c0" font_size = 14
  }
  {field
    alias=field_doc_perv  type=string
    left=260  top=90  height=25  width=100  border=box  font_size=12  font_family=0  bg_color="#ffffff"
    dep = doc_search
  }

  {label left = 600 top = 10 width = 100 height = 30 font_size = 14 halignment = right value = "Сумма без НДС:" }

  { field left = 710 top = 10 width = 150 height = 30 font_size = 16 alias = sum1
    type = number  editmask = "# #0.00"  editable = readonly  halignment = right
  }
  {label left = 600 top = 45 width = 100 height = 30 font_size = 14 halignment = right value = "Сумма НДС:" }

  { field left = 710 top = 45 width = 150 height = 30 font_size = 16 alias = sum2
    type = number  editmask = "# #0.00"  editable = readonly  halignment = right
  }
  {label left = 600 top = 80 width = 100 height = 30 font_size = 14 halignment = right value = "Сумма с НДС:" }

  { field left = 710 top = 80 width = 150 height = 30 font_size = 16 alias = sum3
    type = number  editmask = "# #0.00"  editable = readonly halignment = right
  }
  {label left = 870 top = 10 width = 100 height = 30 font_size = 14 halignment = right value = "Количество:" }

  { field left =970 top = 10 width = 150 height = 30 font_size = 16 alias = sum4
    type = number  editmask = "# #0.00"  editable = readonly  halignment = right
  }



      {datastore  alias=date_ds
        query="select dat1, dat2
                 from (
                         select trunc(sysdate-7) dat1,
                                trunc(sysdate) dat2
                           from dual
                      )"
        
      }

} // form

{grid
    alias = GRID_GROUP1
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18          titlebar_height = 40
    multiselect = yes                      editable = no
    rowsize = 20
    add = "createnew docs/prih.rml -1 ; retrieve grid_group1"
    edit = "opennew docs/prih.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 '')
               )
               ($g.self@doAction 'execute exec util.del_doc(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD') + ')')
               ($refresh)
               ($ret '')
            )~"

   {menu
        {menu label = "Сформировать"
        	{item label = "Поступление ТМЦ и услуг" action="createnew docs/prih.rml -1, -1 ; retrieve grid_group1"}
        	{item label = "копию документа ПТУ" action="createnew docs/prih.rml -1, ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~; retrieve grid_group1"}
        } 
        {item label = "-"}
        {item label = "Принять на склад" action= "execute exec ~'doc_lib.accept('+($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ; retrieve grid_group1" }        
        {item label = "Изъять со склада" action= "execute exec ~'doc_lib.de_accept('+($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )+')'~ ; retrieve grid_group1" }            
        {item label = "-"}
        {menu label = "Печатные формы"

          {item label = "Печатная форма" action="open pech_form/pech_form_postup.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~"}
          {item label = "M-4" action="open pech_form/pech_form_postup_m4.rml ~($($GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD' )~"}
        }
        {item label = "-"}
        {item label = "Обновить" action="retrieve grid_group1"}
        {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 grid_group1')
			 )
		       )
	              ($ret ''))~"
        }
        {item label = "-"}
        {item label = "Присвоить активам поставщика"
           action = "~($X
	                 (tmp = 'Вы действительно хотите изменить поставщика всех активов этого документа?')
                         ($if (($g.self@sure tmp 0) == 0) ($ret '')  )
	                 ($g.self@doAction 'execute exec util.change_post(' + ($($G.GRID_GROUP1@getDatastore)@getValue 'HEAD.ID_HEAD') + ')')
                         ($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=70             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="N перв. док."
        target=head.num_per_sd        title_font_family=2     title_font_color="#000000"
        halignment=left          font_size = 12          font_family=0
   }
   {column size=70             title="<html>Дата<br>перв. док.</html>"
        target=head.date_per_sd        title_font_family=2     title_font_color="#000000"
        halignment=center          font_size = 12          font_family=0
   }
   {column size=250            title="Поставщик"
        target=client.name1_client  title_font_family=2     title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }
   {column size=170             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=170             title="Склад"
        target=department.name1_dep
        title_font_family=2        title_font_color="#000000"
        halignment=left            font_size = 12          font_family=0
   }                  
   {column size=90            title="Кол-во"
        target = head.sum3_sd
        title_font_family=2        title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        editmask = "# #0.00"
   } 
   {column size=90            title="<html>Сумма <br>без НДС</html>"
        target = head.sum1_sd
        title_font_family=2        title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        editmask = "# #0.00"
   }
   {column size=90            title="Сумма НДС"
        target = "HEAD.SUM2_SD - HEAD"
        title_font_family=2        title_font_color="#000000"
        halignment=right           font_size = 12          font_family=0
        editmask = "# #0.00"
   } 
   {column size=90            title="Сумма"
        target = head.sum2_sd
        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 = GRIDDS01
           query = "select head.id_head, head.num_sd, head.date_sd, head.num_per_sd, head.date_per_sd,
			   head.id_client1, client.name1_client,
                           head.id_client2, client2.name1_client,
                           head.id_department1, department.name1_dep, head.comment_sd,
                           head.sum1_sd, head.sum2_sd, head.sum2_sd - head.sum1_sd,
                           head.sum3_sd,
                           head.accept
                      from head,client,department,client client2
                     where ~($if (($try (g.field_doc) $catch ('NullException')(0)) == 0)
                              ($if (($try (g.field_doc_perv) $catch ('NullException')(0)) == 0)
                                ('head.date_sd between to_date(\'' + ($try (g.n_dat1) $catch ('Any')('01.01.0001')) + '\', \'dd.mm.yyyy\')
                                              and to_date(\'' + ($try (g.n_dat2) $catch ('Any')('01.01.0001')) + '\', \'dd.mm.yyyy\')'
                                )
                               $else
                                 (' head.num_per_sd like \'%' + g.field_doc_perv + '%\' ')

                              )
                             $else
                              ($if (($try (g.field_doc_perv) $catch ('NullException')(0)) == 0)
                                 (' head.num_sd like \'%' + g.field_doc + '%\' ')
                               $else
                                 (' head.num_per_sd like \'%' + g.field_doc_perv + '%\' ')
                               )
                            )~
                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 in (78)
                ~($if (global.id_client == -111)
                     ('')
                  $else (' and head.id_client1 = ' + global.id_client)
                  )~
           order by head.date_sd,head.num_sd
                       ~($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 = "LIGHTGREEN"    foreground="#000000"
  label = "Выход ESC"
  action = "($g.self@actcancel)"
  shortcut = "escape"
}

} // toolbar
