Cp1251
DOC 
foreground = lightgray
document_width = 800
document_height = 900
document_title = "Протокол цен"
style = "style/docs.st"
preloadscript="
(global.create = 0)
(global.d1 = ('\''+'01.01.2003'+'\'') )
(global.get_num = 0)
(global.cur_id_active = -1)
(global.no_combo_action = 0)
(global.excel_load = 0)
"
postloadscript="($X
                 # этот флаг нужен, чтобы не выполнялся action у комбобокса, иначе он запишет в датасторю документа первое значение комбобокса,
                 # перезатерев существующее
                 (global.no_combo_action = 1)
                 ($g.self@doAction 'retrieve combo1')
                 (global.no_combo_action = 0)

	 	 ($IF (($g.D_HEAD@getvalue 'HEAD.ACCEPT') == 1)
		  ($g.progress@setValue 'Только для чтения')
		 )
                 ($if (global.create == 0)
                   (
                     # если данный документ уже существует, надо установить комбобокс в соответствии со значением, сохраненным в этом документе
                     ($debug 'head.id_unit: [' + ($try ($g.d_head@getValue 'head.id_unit') $catch ('NullException')(0)) + ']')
                     (sz = ($g.data_ds1@size))
                     (i = 0) (found_i = 0)
                     ($while (i < sz)
                       (
                         ($g.data_ds1@setCurRow i)
                         ($if (($g.data_ds1@getValue 'id_unit') == ($try ($g.d_head@getValue 'head.id_unit') $catch ('NullException')(-999)) )
                           (
                             ($debug 'setSelectedItem ' + i)
                             ($g.combo1@setSelectedItem i)
                             (found_i = i)
                           )
                          )
                          (i += 1)
                       )
                     )
                     ($g.data_ds1@setCurRow found_i)
                   )
                  $else
                   (
                     # Документ новый, оставим значение по умолчанию
                     ($debug 'data_ds1 idunit: ' + ($g.data_ds1@getValue 'id_unit'))
                   )
                 )
		 ($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 ="(global.create = 1)
                (global.get_num = 1)
                 ($X 
		    ($debug ' substore @ retrieve ')
		    ($G.substore@retrieve)
                    ($if (($G.substore@size) != 0)(

                         (tmp = ($try ($g.substore@getvalue 'HEAD.ID_DEPARTMENT1') $catch ('NullException')(0)))
                         ($G.d_head@setvalue 'HEAD.ID_DEPARTMENT1' tmp)
                         (tmp = ($try ($g.substore@getvalue 'DEPARTMENT.NAME1_DEP') $catch ('NullException')('')))
                         ($G.d_head@setvalue 'DEPARTMENT.NAME1_DEP' tmp)
                         (tmp = ($try ($g.substore@getvalue 'HEAD.DATE_SD') $catch ('NullException')(0)))
                         ($G.d_head@setvalue 'HEAD.DATE_SD' tmp)
                         (tmp = ($try ($g.substore@getvalue 'HEAD.ID_CLIENT1') $catch ('NullException')(0)))
                         ($G.d_head@setvalue 'HEAD.ID_CLIENT1' tmp)
                         (tmp = ($try ($g.substore@getvalue 'HEAD.ID_UNIT') $catch ('NullException')(0)))
                         ($G.d_head@setvalue 'HEAD.ID_UNIT' tmp)
                         (tmp = ($try ($g.substore@getvalue 'CLIENT.NAME1_CLIENT') $catch ('NullException')(0)))
                         ($G.d_head@setvalue 'CLIENT.NAME1_CLIENT' tmp)
                         (tmp = ($try ($g.substore@getvalue 'HEAD.COMMENT_SD') $catch ('Any')(' ')))
                         ($if (tmp != 0)
                            ($G.d_head@setvalue 'HEAD.COMMENT_SD' tmp)
                         )
                         (tmp = ($try ($g.substore@getvalue 'spc.id_active') $catch ('Any')(' ')))
                         ($if (tmp != 0)
                           (

                             (i = 0)
                             ($while (i < ($G.substore@size))
                               (
                                 ($g.substore@setCurRow i)
                                 ($g.d_spc@newRow)
                                 ($g.d_spc@setValue 'spc.id_active' ($g.substore@getValue 'spc.id_active'))
                                 ($g.d_spc@setValue 'active.name_active' ($g.substore@getValue 'active.name_active'))
                                 ($g.d_spc@setValue 'spc.id_unit' ($g.substore@getValue 'spc.id_unit'))
                                 ($g.d_spc@setValue 'active_pseudo_unit.obozn' ($g.substore@getValue 'active_pseudo_unit.obozn'))
                                 ($g.d_spc@setValue 'spc.price1_spc' ($g.substore@getValue 'spc.price1_spc'))
                                 (i += 1)
                               )
                             )
                             ($g.d_spc@notifyViews)
                           )
                         )
                       )
		   )
                   ($ret '')
		)"
}
{datastore  alias=doc_num
    query="select num_sd from (select 'ПЦ-'||(nvl(max(to_number(substr(num_sd, 4))), 0) + 1) num_sd
             from head
            where head.num_sd like 'ПЦ-%')"
  } // end of ds

          {datastore
               alias = substore
               query = "select head.id_head, head.id_type_doc, head.num_sd,
                               head.date_sd,
                               head.id_department1, department.name1_dep,
                               head.id_client1, head.id_client2, head.id_unit,
                               head.comment_sd, client.name1_client,
                               spc.id_active, active.name_active,
                               spc.id_unit, active_pseudo_unit.obozn, spc.price1_spc
                          from head, department, client, spc, active, active_pseudo_unit
                         where head.id_head=~($try (ARGUMENTS.1) $catch ('NullException') (-1) )~
                           and head.id_department1 = department.id_department
                           and head.id_client1 = client.id_client
                           and head.id_head = spc.id_head (+)
                           and spc.id_active = active.id_active (+)
                           and spc.id_unit = active_pseudo_unit.id_pseudo_unit (+)"
              }
			 
{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel   percent=15
{scrollpane 
{form width=780 height=208       bg_color="#c0c0c0"   alias = fm
   {label
       value="N док."       
       left=11    top=8     height=20       width=40
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }  
   {field
       target=head.num_sd   border = box
       left=55     top=8    height=20       width=95
       alias=num_sd         font_size=12    font_family=0    bg_color="#ffffff"
       editable=readonly
   }  
   {label
       value="Дата док."    
       left=155    top=8    height=20       width=50
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.date_sd  border = box
       left=210    top=8    height=20       width=70
       alias=date_sd        font_size=12    font_family=0    bg_color="#ffffff"
       dep="ficd1"
   }
 {field 
   type = string
   left = 500  width = 70 height=25    
   alias=ficd1           visible=no
   exp="(ficd1 = global.d1)"
  }
   {field
       target=head.accept    border = box   visible=no
       left=200   top=83    height=20      width=40
       alias=accept         font_size=12    font_family=0    bg_color="#ffffff"
   }
   {label
       value="Поставщик"
       left=300    top=8    height=20       width=70
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.id_client1                 halignment = right
       left=350     top=33   height=20        width=70
       alias=cli1_numb_client                border = box        
       font_size=12         font_family=0    bg_color="#ffffff"
       visible = no
   }
   {field
      target=client.name1_client              border = box
      left=380     top=8   height=20        width=150
      alias=name_client1    font_size=12     font_family=0    bg_color="#ffffff"
      editable=handbook
      edit="opennew find_client.rml"
      editexp="cli1_numb_client=STORE.client.id_client;name_client1=STORE.client.name1_client"
   }
   {label
       value="Исполнитель"  
       left=540  top=8      height=20       width=70
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=personal.fname                border = box
       left=610    top=8    height=20       width=70
       alias=name           font_size=12    font_family=0    bg_color="#ffffff"
       editable = readonly
   }     
   {label
       value="Валюта"
       left=10    top=33    height=20       width=70
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {combobox
      left = 80     top = 33      width = 70        height = 20 
      alias = combo1               border = box
      target = name_unit
      action = "~($X
                  ($debug 'combo1')
                  ($if (global.no_combo_action == 0)
                    (
                      ($g.data_ds1@setCurRow ($g.combo1@getSelectedIndex))
                      ($g.d_head@setValue 'head.id_unit' ($g.data_ds1@getValue 'id_unit'))
                      ($debug 'combo1, index: ' + ($g.combo1@getSelectedIndex) + ', value: ' + ($g.data_ds1@getValue 'id_unit') )
                    )
                  )
                  ($ret '')
                )~"
      {datastore
       alias = data_ds1
       query = "select id_unit, name_unit
                  from (
                select id_currency id_unit, trim(name_currency) name_unit
                  from currency
                       )
                 order by id_unit desc"
      }
   }
   {label
       value="Примечание"    
       left=250    top=33     height=20      width=65
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.comment_sd   border = box
       left=320    top=33    height=20      width=360
       alias=comment_sd         font_size=12   font_family=0    bg_color="#ffffff"
   }
   {label
    alias=progress
    left = 630  top = 8      width = 150     height = 20 
    font_size=16              font_family=2   font_color="#000088"
    bg_color="#c0c0c0"        border=none     
   }

   {button
       label="Установить цену"
       left=10    top=70     height=30      width=120
       font_size=12          font_family=0  bg_color="#c0c0c0"
       action = "($X
                     ($debug '******** selection: ' + ($g.gridspc@selectionValues 'column_id_spc'))

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

                     ($if (($($g.gridspc@selectionValues 'column_id_spc')@size) != 0)
                       (
                        ($debug '******** selection: ' + ($g.gridspc@selectionValues 'column_id_spc'))
                        (a = ($g.gridspc@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.price1_spc' g.field_price)
                                  )
                                )
                                (j += 1)
                              )
                            )
                            (i += 1)
                          )
                        )
                        ($g.d_spc@fastSetCurRow row)
                        ($g.d_spc@notifyViews)
                       )
                      $else
                        ($debug '********* no selection')
                     )
     		(ret '')
                )"
   }
   {field
       type = number  border = box  value = "0"
       left=140    top=72    height=25      width=60
       alias=field_price    font_size=12   font_family=0    bg_color="#ffffff"
       editmask = "0.000"
   }
{datastore 
        alias = d_head
        query = "select head.id_head,head.id_type_doc,head.accept,
                        head.num_sd,head.date_sd,
                        head.num_per_sd,head.date_per_sd,
                        head.id_department1,department.name1_dep,head.id_department2,
                        head.id_client1, head.id_client2,
                        head.comment_sd, head.id_unit,
			head.id_personal,personal.fname,
			head.parent_id_head,
			client.name1_client
                   from head, personal, department, client
                  where head.id_head = ~($try ($if (global.create == 0)
                                  	    	(ARGUMENTS.0)
	                                       $else (ds.hpk))
		                         $catch ('any') (-1))~
                   and head.id_department1 = department.id_department 
                   and head.id_personal = personal.id_personal
                   and head.id_client1 = client.id_client
                   and head.id_type_doc = 20"
              editable = yes
                  head = yes
                unique = "('head','head.id_head')"
               default = "head.id_head=~ds.hpk~,head.id_type_doc=~20~,
                          head.date_sd=~ds.date~,
                          head.id_personal=~ds.idp~,
                          head.accept=~0~,
                          head.num_sd=~'ПЦ-'~,
			  head.num_per_sd=~'.'~,head.date_per_sd=~ds.date~,
			  head.id_department1=~0~,
			  head.id_department2=~0~,
                          head.id_client1=~1~,
                          head.id_client2=~1~, head.id_unit=~1~"
} // ds
} // form
} // scroll
{tabset labels = "перечень продукции"
 tabs_on_top=yes
{grid
editable = yes
add="opennew find_choose.rml 1, 0"
alias = GRIDSPC
buttonbar_font_family=0       buttonbar_font_size=12           
buttonbar_size = 30           titlebar_size = 18      titlebar_height = 40
rowsize=20     
addexp="($X
	(t = ($g.d_spc@iterator))
	(i = 0)
	(is_in = 1)
	($while ($t@next)
	    (
		(i += 1)
		($g.d_spc@SetCurRow (i-1))
		(l_id_active = ($try ($g.d_spc@GetValue 'SPC.ID_ACTIVE') $catch ('Any')(-1)))
		($if (l_id_active == store.active.id_active) (
		  ($g.self@sure 'Актив '+store.active.name_active+' уже присутствует в спецификации!' 1)
		  (is_in = 0)
		  ($g.d_spc@delRow (($g.d_spc@size) - 1))
		))
        ))
	($if (is_in == 1) (

          (g.war=store.active.id_active)
          (g.name_w=store.active.name_active)
	  (g.id_un=store.id_pseudo_unit)
          (g.name_un=store.obozn)
          ($if (($try (store.price1_spc) $catch ('Any')(0)) != 0)
            (g.price1_spc = store.price1_spc)
          )
        
        ))
        ($ret '')
        )"
{menu
   {item label = "Поиск в справочнике" action="opennew find_choose.rml 1, 0"}
   {item label  = "Добавить из приходов"
   action = "~($X
                ($if (($try (g.cli1_numb_client) $catch ('NullException')(0)) == 0)
                  (
                    ($g.self@sure 'Не указан поставщик.' 1)
                    ($ret '')
                  )
                )
                ($g.self@doAction 'opennew history_prih_all.rml ' +g.cli1_numb_client)
                ($ret '')
              )~"
   }
   {item label = "-"}

   {item label = "История изменений строки" action= "open reports/report_spc_log.rml ~($g.d_spc@getValue 'spc.id_spc')~"}
   {item label = "История изменений документа" action= "open reports/report_spc_log_doc.rml ~($g.d_spc@getValue 'spc.id_head')~"}
}
 {column size=40  
     visible=no
     title="Номер"   
     target=spc.id_spc        title_font_family=2     halignment=left
     font_color="#000000"     font_size=12              font_family=0
     alias = column_id_spc
 }
 {column size=110 
    visible=no
    title="Номер"   
    target=spc.id_head        title_font_family=2
    font_color="#000000"      font_size = 12            font_family=0
 }
 {column size=40     
    title="Код"              font_family=0           editable = readonly 
    target=spc.id_active     title_font_family=2     halignment=left
    alias=war                font_color="#000000"     font_size=12   
    editmask = "##0."
 }
 {column size=250       title="Наименование"
    target=active.name_active  title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=name_w              editable = readonly 
 }
 {column size=60     
    visible=no
    title="Код"              font_family=0
    target=spc.id_unit       title_font_family=2     halignment=left
    alias=id_un                font_color="#000000"     font_size=12   
 }
 {column size=40       title="<html>Ед.<br> изм."
    target=active_pseudo_unit.obozn  title_font_family=2     halignment=center
    font_color="#000000"      font_size=12              font_family=0
    alias=name_un            
    editable = readonly
 }
 {column size=70
    target = spc.price1_spc   title="Цена"      title_font_family=2
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"     alias = price1_spc        halignment=right
 }
 {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.price1_spc,spc.price2_spc,
                      active.name_active,active_pseudo_unit.obozn,active_type.name_type
                 from spc,active,active_pseudo_unit,active_type
                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 
                  and active.id_type_active = active_type.id_type
             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.price1_spc=~0~,spc.price2_spc=~0~"  
} // ds
} // grid1
} // tabset
} // split
{button
  left = 11  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Сохранить и выйти F3"
  action = "($X
             # проверка на нули
             (str = '-1')
             (nulls = 0)
             (i = 0)
             (sz = ($g.d_spc@size))
             ($while (i < sz)
               (
                 ($g.d_spc@fastSetCurRow i)
                 ($if (($g.d_spc@getValue 'spc.price1_spc') == 0)
                   (
                     (nulls += 1)
                     ($if (nulls == 1) (str = '' + ($(i+1)@integer))
                      $else
                      ($if (nulls < 4) (str += ', ' + ($(i+1)@integer)) 
                       $if (nulls == 4) (str += ' (...)')
                      )
                     )
                   )
                 )
                 (i += 1)
               )
             )
             ($if (str != '-1')
               (
                 ($g.self@sure 'В строках ' + str + ' нулевая цена.' 1)
                 ($ret '')
               )
             )

	     ($if (($G.D_HEAD@getValue 'HEAD.ACCEPT') == 1)
		  (
		    ($g.self@actcancel)
		    ($ret '')
		  )
	     )
             ($if (global.get_num == 1)
                 (
                     ($g.doc_num@retrieve)
                     (d_head.head.num_sd = ($try ($g.doc_num@GetValue 'NUM_SD') $catch ('Any')('')))
                     (g.num_sd = ($try ($g.doc_num@GetValue 'NUM_SD') $catch ('Any')('')))
                     (global.get_num = 0)
                 )
             )
	     ($g.self@actdok)
             ($ret '')
             
             )"
  shortcut = "F3"
}
{button
  left = 72  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Отмена ESC"
  action = "($X
             (tmp = 'Вы действительно хотите выйти без сохранения данных' + '')
             (m = ($g.self@sure tmp 0))
               ($if (m == 0)()
               $else ($g.self@actcancel)
               )
             ($ret ''))"
  shortcut = "escape"
}

  {button
   label = "Открыть файл Excel"
   action = "($X
               (file = ($g.self@FILEDIALOG 'load'))
               (global.file = ($try ($file@ 0) $catch ('NullException')('no file')))
               ($debug 'file : ' + global.file)
               ($try 
                 ($g.self@calculate 'js:js_file:docs/price_protocol_load_excel.js')
                $catch ('Any')('')
               )
               ($debug 'global.excel_load: ' + global.excel_load)
               ($ret '')
             )"
  }

} // toolbar

