Cp1251
DOC
foreground = lightgray 
document_width = 1000
document_height = 900
document_title = "ZetaSE.Autocomplect/Создание заказа поставщику"
preloadscript="
(global.retr = 0)
(global.id_h = 0)
(global.no_selaction = 0)
(global.id_active = -1)
(global.create = 0)
(global.loading = 1)
"

postloadscript = "($X
                     (global.loading = 0)
                     ($g.client@retrieve)
                     ($if (($g.client@size) > 0)
                       (g.field_name_client = ($g.client@getValue 'name1_client'))
                     )
                     ($if (ARGUMENTS.1 == -999)
                       (
                         # копирование заказа
                         ($g.ds_copy@retrieve)
                         (sz = ($g.ds_copy@size))
                         (i = 0)
                         ($while (i < sz)
                           (
                             ($g.ds_copy@setCurRow i)
                             ($g.d_spc@NewRow)
                             ($g.d_spc@setValue 'spc.id_active' ($g.ds_copy@getValue 'spc.id_active'))
                             ($g.d_spc@setValue 'spc.id_unit' ($g.ds_copy@getValue 'spc.id_unit'))
                             ($g.d_spc@setValue 'active.name_active' ($g.ds_copy@getValue 'active.name_active'))
                             ($g.d_spc@setValue 'spc.q1_spc' ($g.ds_copy@getValue 'spc.q1_spc'))
                             ($g.d_spc@setValue 'spc.q2_spc' ($g.ds_copy@getValue 'spc.q2_spc'))
                             ($g.d_spc@setValue 'spc.q3_spc' ($g.ds_copy@getValue 'spc.q3_spc'))
                             ($g.d_spc@setValue 'spc.price1_spc' ($g.ds_copy@getValue 'spc.price1_spc'))
                             ($g.d_spc@setValue '@@COMPUTE_0' ( (($g.ds_copy@getValue 'spc.q1_spc') + ($g.ds_copy@getValue 'spc.q2_spc') + ($g.ds_copy@getValue 'spc.q3_spc'))* ($g.ds_copy@getValue 'spc.price1_spc') ))
                             (i += 1)
                           )
                         )
                         ($g.d_spc@notifyViews)
                         (g.field_name_client = ($g.ds_copy@getValue 'client.name1_client'))
                         (d_head.head.id_client1 = ($g.ds_copy@getValue 'head.id_client1'))
                       )
                     )

                     ($ret '')
                  )"

{DSCollection
   alias = ds

   initQuery = "select head_sq.nextval,sysdate,id_personal from personal where upper(login)=user"
   aliases = "hpk,date,idp"

   SeqQuery  = "select spc_sq.nextval from dual"
   seqnames = "spk"
   initaction = "($X
                   (global.create = 1)
                   ($ret '')
                )"


   { datastore
     alias = client
     query = "select name1_client from client where id_client = ~($try (ARGUMENTS.1) $catch ('Any')(0))~"
   }
   {datastore  alias=doc_num
       query="select num_sd from (select 'Зак-'||(nvl(max(to_number(substr(num_sd, 5))), 0) + 1) num_sd
                from head
               where head.num_sd like 'Зак-%')"
   }
   {datastore  alias=ds_copy
       query="select spc.id_active, spc.id_unit, active.name_active, spc.q1_spc, spc.q2_spc, spc.q3_spc, spc.price1_spc,
                     head.id_client1, client.name1_client
                from spc, active, active_pseudo_unit, head, client
               where spc.id_head = ~($try (ARGUMENTS.0) $catch ('Any')(0))~
                 and spc.id_active = active.id_active
                 and spc.id_unit = active_pseudo_unit.id_pseudo_unit
                 and spc.id_head = head.id_head
                 and head.id_client1 = client.id_client"
   }
   { datastore
     alias = ds_date
     query = "select date1
                from (
                       select to_date(~($if (global.create == 0)
                                    	   ('\'' + ($g.d_head@getValue 'date1_char') + '\'')
                                         $else ('to_char(sysdate. \'dd.mm.yyyy\')')
                                       )~, 'dd.mm.yyyy') + 7*~($try ($g.d_spc@getValue 'spc.q2_spc') $catch ('Any')(0))~ date1
                       from dual
                     )"
   }
   { datastore
     alias = ds_price
     query = "select price
                from price
               where price.id_active = ~($if (global.create == 0)
                                           (global.id_active)
                                         $else (-1)
                                        )~
                 and price.id_client = ~($if (global.create == 0)
                                           ($g.d_head@getValue 'head.id_client1')
                                         $else (-1)
                                        )~"
   }
   { datastore
     alias = ds_supply_time
     query = "select supply_time
                from (
                      -- если материал из группы импортных материалов, срок поставки 12 недель, иначе 4 недели
                      select decode(cnt, 0, 4, 12) supply_time
                        from (
                             select count(1) cnt
                               from active
                              where id_active = ~($if (global.create == 0) (global.id_active)  $else (-1) )~
                            connect by prior id_active = parent_act_id                        
                               start with id_active in (select active.id_active
                                                          from active
                                                         where active.status_group = 0
                                                           and import = 1
                                                       )
                             )
                     )"

   }
}

{toolbar   BACKGROUND = "White"
{splitpanel type=horizontal   percent=15 gapsize = 10
{form bg_color="#c0c0c0"
  {label left = 20 top = 5 width = 100 height = 25 font_size = 16
    value = "Поставщик"
  }
  { field left = 130 top = 5 width = 200 height = 30 font_size = 16 alias = field_name_client
    target = client.name1_client
    editable = readonly
  }
  {label left = 350 top = 5 width = 50 height = 25 font_size = 16
    value = "N док."
  }
  { field left = 400 top = 5 width = 100 height = 30 font_size = 16 alias = field_num_sd
    target = head.num_sd
    editable = readonly
  }
  {label left = 520 top = 5 width = 50 height = 25 font_size = 16
    value = "Создан"
  }
  { field left = 580 top = 5 width = 100 height = 30 font_size = 16 alias = field_num_sd
    target = head.date_sd
    editable = readonly
  }
  {label left = 20 top = 40 width = 100 height = 25 font_size = 16
    value = "Примечание"
  }
  { field left = 130 top = 40 width = 550 height = 30 font_size = 16 alias = field_comment_sd
    target = head.comment_sd
  }
  {button
    left = 10 top = 80 width = 150 height = 25 font_size = 12
     label="Установить дату"
    action = "($X 

                  ($if (($try (g.field_date_order) $catch ('NullException')(0)) == 0) ($ret '') )
                  
                  ($debug '******** selection: ' + ($g.GRID_GROUP1@selectionValues 'column_id_spc'))

                  ($if (($g.GRID_GROUP1@selectionValues 'column_id_spc') == 'NIL') ($ret '') )

                  ($if (($($g.GRID_GROUP1@selectionValues 'column_id_spc')@size) != 0)
                    (
                     ($debug '******** selection: ' + ($g.GRID_GROUP1@selectionValues 'column_id_spc'))
                     (a = ($g.GRID_GROUP1@selectionValues 'column_id_spc'))
                     (a_sz = ($a@size))
                     (sz = ($g.d_spc@size))
                     (i = 0)
                     (row = ($g.d_spc@getCurRow))
                     ($while (i < sz)
                       (
                         ($g.d_spc@fastSetCurRow i)
                         (j = 0)
                         ($while (j < a_sz)
                           (
                             ($if (($g.d_spc@getValue 'spc.id_spc') == ($a@ j))
                               (
                                 ($g.d_spc@setValue 'spc.date1' g.field_date_order)
                               )
                             )
                             (j += 1)
                           )
                         )
                         (i += 1)
                       )
                     )
                     ($g.d_spc@fastSetCurRow row)
                     ($g.d_spc@notifyViews)
                    )
                   $else
                     ($debug '********* no selection')
                  )
  		(ret '')
             )"
  }
  { field left = 170 top = 80 width = 100 height = 25 font_size = 12 alias = field_date_order
    type = date
  }


  {datastore 
          alias = d_head
          query = "select head.id_head, head.id_type_doc, head.accept, head.comment_sd,
                          head.num_sd, head.date_sd, head.date1,
                          to_char(head.date1, 'dd.mm.yyyy') date1_char,
                          to_char(add_months(head.date1, -36), 'dd.mm.yyyy') date2_char,
                          head.id_department1, head.id_department2, head.id_client1, head.id_personal,
                          client.name1_client
                     from head, client
                    where head.id_head = ~($try ($if (global.create == 0)
                                    	    	(ARGUMENTS.0)
  	                                       $else (ds.hpk))
  		                         $catch ('any') (-1))~
                      and head.id_client1 = client.id_client
  		   "
                editable = yes
                    head = yes
                  unique = "('head','head.id_head')"
                 default = "head.id_head=~ds.hpk~,head.id_type_doc=~9~,
                            head.date1=~ds.date~,
                            head.id_personal=~ds.idp~,
                            head.accept=~0~,
                            head.num_sd=~'Заказ-'~,
                            head.id_department1=~0~,
                            head.id_department2=~0~,
                            head.id_client1=~($try (ARGUMENTS.1) $catch ('Any')(0))~"
  } // ds

}
{grid
    alias = GRID_GROUP1
    buttonbar_font_family = 0              buttonbar_font_size = 12
    buttonbar_size = 30                    titlebar_size = 18
                                           titlebar_height = 40
    multiselect = yes                      editable = yes
    rowsize = 20
    del = "~($X
             ($g.gridds01@delRow ($g.gridds01@getCurRow))
             ($g.gridds01@notifyViews)
             ($ret '')
            )~"

addexp="column_id_active = store.active.id_active;
        global.id_active = store.active.id_active;
        column_id_unit = store.id_pseudo_unit;
        column_name_active = store.active.name_active;
	column_min_kolvo = store.active.min_post;
	column_kolvo1 = store.active.min_post;
	($g.ds_price@retrieve)
	($if (($g.ds_price@size) > 0)
           (g.column_price = ($g.ds_price@getValue 'price'))
         $else
           (g.column_price = 0)
        )
	($g.ds_supply_time@retrieve)
        (g.column_supply_time=($g.ds_supply_time@getValue 'supply_time'))
        ($g.ds_date@retrieve)
        (g.column_date = ($g.ds_date@getValue 'DATE1'))
	column_summ=column_kolvo1*column_price"
{menu
   {item label = "Добавить" action="opennew find_choose.rml 1, 0"}
   {item label = "-"}
   {item label = "История поставок"
    action = "~($X
                  ($g.self@doAction 'opennew reports/report_history_supply.rml ' + ($g.d_spc@getValue 'spc.id_active') + ', \'' + ($g.d_head@getValue 'date2_char') + '\', \'' + ($g.d_head@getValue 'date1_char') + '\'')
                  ($ret '')
                )~"
   }
}


   {column size=100             title="ID_SPC"
        target=spc.id_spc       title_font_family=2     title_font_color="#000000"
        halignment=left            font_color="#000000"     
        font_size = 12             font_family=0
        editable = readonly
        alias = column_id_spc
        visible = no
   }
   {column size=250             title="ID материала"
        target=spc.id_active       title_font_family=2     title_font_color="#000000"
        halignment=left            font_color="#000000"     
        font_size = 12             font_family=0
        editable = readonly
        alias = column_id_active
        visible = no
   }
   {column size=250             title="ID_unit"
        target=spc.id_unit       title_font_family=2     title_font_color="#000000"
        halignment=left            font_color="#000000"     
        font_size = 12             font_family=0
        alias = column_id_unit
        editable = readonly
        visible = no
   }
   {column size=250             title="Наименование материала"
        target=active.name_active       title_font_family=2     title_font_color="#000000"
        halignment=left            font_color="#000000"     
        font_size = 12             font_family=0
        editable = readonly
        alias = column_name_active
   }
   {column size=80            title="<html>Мин.<br>кол-во"
        target=active.min_post  title_font_family=2     title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0
        editmask = "# #0.000"
        editable = readonly
        alias = column_min_kolvo
   }
   {column size=80            title="<html>Кол-во<br>"
        target=spc.q1_spc title_font_family=2     title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0
        editmask = "# #0.000"
        alias = column_kolvo1
        dep = "column_summ"
   }
   {column size=70             title="Цена"
        target=spc.price1_spc
        title_font_family=2        title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0 editmask = "# #0.00"
        alias = column_price
        dep = "column_summ"
   }                  
   {column size=100             title="Сумма"
        type = number
        title_font_family=2        title_font_color="#000000"
        halignment=right            font_size = 12          font_family=0 editmask = "# #0.00"
        alias = column_summ
        exp = "column_summ = column_price * column_kolvo1"
   }                  
   {column size=50             title="<html>Срок<br>пост."
        target = spc.q2_spc
        title_font_family=2        title_font_color="#000000"
        halignment=center         font_size = 12          font_family=0 editmask = "##0."
        alias = column_supply_time
        dep = "column_date"
   }                  
   {column size=100             title="Дата поставки"
        target = spc.date1
        title_font_family=2        title_font_color="#000000"
        halignment=center         font_size = 12          font_family=0 editmask = "# #0.00"
        alias = column_date
        exp = "($X
                  ($if (global.loading == 1) ($ret '') )
                  ($g.ds_date@retrieve)
                  (g.column_date = ($g.ds_date@getValue 'DATE1'))
                  ($ret '')
               )"
   }                  

 {datastore 
      alias = d_spc
      query = "select spc.id_spc, spc.id_head, spc.id_active, spc.id_unit,
                      spc.q1_spc, spc.q2_spc, spc.q3_spc, spc.price1_spc, spc.date1,
                      active.name_active, active_pseudo_unit.obozn, active.min_post
                 from spc, active, active_pseudo_unit
                where spc.id_head = ~($try (d_head.head.id_head) $catch ('NullException') (-1) )~ 
                  and spc.id_active = active.id_active 
                  and spc.id_unit = active_pseudo_unit.id_pseudo_unit 
             order by spc.id_spc"
             editable = yes
               unique = "('spc','spc.id_spc')" 
              default = "spc.id_head=~($try (d_head.head.id_head) $catch ('NullException') (-1) )~,
                         spc.id_spc=~ds.spk~,
			 spc.q1_spc=~0~,spc.q2_spc=~0~,spc.q3_spc=~0~,
			 spc.price1_spc=~0~"
} // ds

} // end of grid
} // end of horizontal split
{button
  left = 72  width = 50    height = 20
  BACKGROUND = "LIGHTGREEN"    foreground="#000000"
  label = "Сохранить"
  action = "($X
              ($if (global.create == 1)
                  (
                      ($g.doc_num@retrieve)
                      d_head.head.num_sd = ($try ($g.doc_num@GetValue 'NUM_SD') $catch ('Any')(''))
                  )
              )
              ($g.self@actDok)
              ($ret '')
            )"
}
{button
  left = 72  width = 50    height = 20
  BACKGROUND = "LIGHTGREEN"    foreground="#000000"
  label = "Выход ESC"
  action = "($g.self@actcancel)"
  shortcut = "escape"
}

} // toolbar
