Cp1251
DOC 
foreground = lightgray
document_width = 1000
document_height = 700
document_title = "ZetaSE.Autocomplect/ Документ Поступление ТМЦ"
preloadscript="
(global.create = 0)
(global.d1 = ('\''+'01.01.2003'+'\'') )
(global.get_num = 0)
(global.cur_id_active = -1)
"

postloadscript="($X
	 	 ($IF (($g.D_HEAD@getvalue 'HEAD.ACCEPT') == 1)
		  ($g.progress@setValue 'Только для чтения')
		 )
		($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)
                (global.get_num = 1)
                ($G.copy@retrieve)
                ($if (($G.copy@size) == 0)
                   ($ret '')
                )
                ($g.copy@SetCurRow 0)
                (tmp = ($try ($g.copy@getvalue 'HEAD.NUM_PER_SD') $catch ('NullException')(0)))
                ($if (tmp != 0)
                  ($G.d_head@setvalue 'HEAD.NUM_PER_SD' tmp)  
                )
                (tmp = ($try ($g.copy@getvalue 'HEAD.DATE_PER_SD') $catch ('NullException')(0)))
                ($if (tmp != 0)
                  ($G.d_head@setvalue 'HEAD.DATE_PER_SD' tmp)
                )
                (tmp = ($try ($g.copy@getvalue 'HEAD.ID_DEPARTMENT1') $catch ('NullException')(0)))
                ($G.d_head@setvalue 'HEAD.ID_DEPARTMENT1' tmp)                         
                (tmp = ($try ($g.copy@getvalue 'DEPARTMENT.NAME1_DEP') $catch ('NullException')(0)))
                ($G.d_head@setvalue 'DEPARTMENT.NAME1_DEP' tmp)
                (tmp = ($try ($g.copy@getvalue 'HEAD.ID_DEPARTMENT2') $catch ('NullException')(0)))
                ($G.d_head@setvalue 'HEAD.ID_DEPARTMENT2' tmp)
                (tmp = ($try ($g.copy@getvalue 'HEAD.ID_CLIENT1') $catch ('NullException')(0)))
                ($G.d_head@setvalue 'HEAD.ID_CLIENT1' tmp)
                (tmp = ($try ($g.copy@getvalue 'CLIENT.NAME1_CLIENT') $catch ('NullException')(0)))
                ($G.d_head@setvalue 'CLIENT.NAME1_CLIENT' tmp)
                #(tmp = ($try ($g.copy@getvalue 'HEAD.ID_CLIENT2') $catch ('NullException')(0)))
                ($G.d_head@setvalue 'HEAD.ID_CLIENT2' 543)
                (tmp = ($try ($g.copy@getvalue 'CLIENT2.NAME1_CLIENT') $catch ('NullException')(0)))
                ($G.d_head@setvalue 'CLIENT2.NAME1_CLIENT' tmp)
                (tmp = ($try ($g.copy@getvalue 'HEAD.COMMENT_SD') $catch ('NullException')(0)))
                ($if (tmp != 0)
                  ($G.d_head@setvalue 'HEAD.COMMENT_SD' tmp)
                )
                (tmp = ($try ($g.copy@getvalue 'HEAD.PARENT_ID_HEAD') $catch ('NullException')(0)))
                ($if (tmp != 0)
                  ($G.d_head@setvalue 'HEAD.PARENT_ID_HEAD' tmp)
                )

                ($if (($g.copy@getvalue 'HEAD.ID_TYPE_DOC') == 9)
                  (
                    ($G.substore_order@retrieve)
                    ($if (($G.substore_order@size) !=0)
                      (
        	         (sz = ($g.substore_order@size))
                         (i = 0)
        	             ($while (i < sz)
                           (
                              ($g.substore_order@SetCurRow i)
                              ($G.d_spc@newrow)
                              (tmp = ($try ($g.substore_order@getvalue 'HEAD.ID_ACTIVE') $catch ('NullException')(0)))
                              ($G.d_spc@setvalue 'SPC.ID_ACTIVE' tmp)
                              (tmp = ($try ($g.substore_order@getvalue 'ACTIVE.NAME_ACTIVE') $catch ('NullException')(' ')))
                              ($G.d_spc@setvalue 'ACTIVE.NAME_ACTIVE' tmp)
                              (tmp = ($try ($g.substore_order@getvalue 'SPC.ID_UNIT') $catch ('NullException')(0)))
                              ($G.d_spc@setvalue 'SPC.ID_UNIT' tmp)
                              (tmp = ($try ($g.substore_order@getvalue 'SPC.Q1_SPC') $catch ('NullException')(0)))
                              ($G.d_spc@setvalue 'SPC.Q1_SPC' tmp)
                              (tmp = ($try ($g.substore_order@getvalue 'ACTIVE_PSEUDO_UNIT.OBOZN') $catch ('NullException')(' ')))
                              ($G.d_spc@setvalue 'ACTIVE_PSEUDO_UNIT.OBOZN' tmp)
                              (i = i + 1)
                           )
                         ) 
                      ) 
                    )
                  )
                 $else
                  (

                    ($G.substore@retrieve)
                    ($if (($G.substore@size) !=0)
                      (
        	             (sz = ($g.substore@size))
                         (i = 0)
        	             ($while (i < sz)
                           (
                              ($g.substore@SetCurRow i)
                              ($G.d_spc@newrow)
                              (tmp = ($try ($g.substore@getvalue 'SPC.ID_ACTIVE') $catch ('NullException')(0)))
                              ($G.d_spc@setvalue 'SPC.ID_ACTIVE' tmp)
                              (tmp = ($try ($g.substore@getvalue 'ACTIVE.NAME_ACTIVE') $catch ('NullException')(' ')))
                              ($G.d_spc@setvalue 'ACTIVE.NAME_ACTIVE' tmp)
                              (tmp = ($try ($g.substore@getvalue 'SPC.ID_UNIT') $catch ('NullException')(0)))
                              ($G.d_spc@setvalue 'SPC.ID_UNIT' tmp)
                              (tmp = ($try ($g.substore@getvalue 'SPC.Q1_SPC') $catch ('NullException')(0)))
                              ($G.d_spc@setvalue 'SPC.Q1_SPC' tmp)
                              (tmp = ($try ($g.substore@getvalue 'SPC.Q2_SPC') $catch ('NullException')(0)))
                              ($G.d_spc@setvalue 'SPC.Q2_SPC' tmp)
                              (tmp = ($try ($g.substore@getvalue 'SPC.PRICE1_SPC') $catch ('NullException')(0)))
                              ($G.d_spc@setvalue 'SPC.PRICE1_SPC' tmp)
                              (tmp = ($try ($g.substore@getvalue 'SPC.PRICE2_SPC') $catch ('NullException')(0)))
                              ($G.d_spc@setvalue 'SPC.PRICE2_SPC' tmp)
                              (tmp = ($try ($g.substore@getvalue 'ACTIVE_PSEUDO_UNIT.OBOZN') $catch ('NullException')(' ')))
                              ($G.d_spc@setvalue 'ACTIVE_PSEUDO_UNIT.OBOZN' tmp)
                              (i = i + 1)
                           )
                         ) 
                      ) 
                    )
                  )
                )
                ($G.d_spc@notifyviews)
                ($G.d_head@notifyviews)
                ($ret '')
                )                                    
                "
}

{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 'ПТУ-%')"
} // end of ds

{datastore  alias=ds_active
    query="select price
             from price
            where id_active = ~global.cur_id_active~"
} // end of ds

{datastore
  alias = substore
  query = "select 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
             from active, spc, active_pseudo_unit
            where spc.id_head=~($try ($if ((ARGUMENTS.1) == 'NOTHING') (-1) $else (ARGUMENTS.1)) $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"
}
{datastore
  alias = substore_order
  query = "select head.id_active, spc.id_unit, spc.q1_spc, spc.q2_spc, spc.price1_spc, spc.price2_spc,
                  active.name_active, active_pseudo_unit.obozn
             from head head1, head, active, spc, active_pseudo_unit
            where head1.id_head = ~($try ($if ((ARGUMENTS.1) == 'NOTHING') (-1) $else (ARGUMENTS.1)) $catch ('NullException') (-1) )~
              and head.id_client1 = head1.id_client1
              and head.date1 = head1.date1
              and spc.id_head = head.id_head
              and head.id_active = active.id_active 
              and spc.id_unit = active_pseudo_unit.id_pseudo_unit (+)
            order by spc.id_spc"
}

{datastore
 alias = copy
 query = "select 
          head.date_sd,
          head.num_per_sd, head.date_per_sd, head.id_type_doc,
          head.id_department1, department.name1_dep, head.id_department2,
          head.id_client1, client.name1_client,
          head.id_client2, client2.name1_client,
          head.comment_sd,
          head.parent_id_head
     from head, client, client client2, department
    where head.id_head = ~($try ($if ((ARGUMENTS.1) == 'NOTHING') (-1) $else (ARGUMENTS.1)) $catch ('NullException') (-1) )~
      and head.id_client1 = client.id_client (+)
      and client2.id_client = 543
      and head.id_department1 = department.id_department (+)"
}
{datastore
 alias = prev_price_ds
 query = "select prev_price
            from (
              select spc.price1_spc prev_price
                from head, spc
               where head.id_client1 = ~($try (g.cli1_numb_client) $catch ('NullException')(-1))~
                 and head.id_type_doc = 20
                 and head.id_head = spc.id_head
                 and spc.id_active = ~global.cur_id_active~
               order by head.date_sd desc
                )
           where rownum = 1"
}

{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel   percent=25
{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=160    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=80
       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=305    top=8    height=20       width=35
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.id_department1
       visible=no           border = box
       left=308    top=8    height=20       width=200
       alias=sklad_t        font_size=12    font_family=0    bg_color="#ffffff"
       editexp="(sklad_t=STORE.department.id_department)"
   }
   {field
       target=department.name1_dep                 border = box
       left=340    top=8    height=20       width=200
       alias=sklad          font_size=12    font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="opennew department_gr.rml "
       editexp="sklad=STORE.department.name1_dep"
       dep="sklad_t"
   }
   {label
       value="Исполнитель"  
       left=550  top=8      height=20       width=70
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=personal.fname                border = box
       left=617    top=8    height=20       width=70
       alias=name           font_size=12    font_family=0    bg_color="#ffffff"
       editable = readonly
   }     
   {label
       value="Поставщик"
       left=11     top=33   height=20        width=65
       font_size=12         font_family=0    bg_color="#c0c0c0"
   }
   {field
       target=head.id_client1                 halignment = right
       left=80     top=33   height=20        width=70
       alias=cli1_numb_client                border = box        
       font_size=12         font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="opennew find_client.rml"
       editexp="cli1_numb_client=STORE.client.id_client"
       dep="name_client1"
   }
   {field
      target=client.name1_client              border = box
      left=155     top=33   height=20        width=270
      alias=name_client1    font_size=12     font_family=0    bg_color="#ffffff"
      editexp="name_client1=STORE.client.name1_client"
      editable = readonly
   }
   {label
       value="Покупатель"
       left=11    top=58     height=20       width=65
       font_size=12          font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.id_client2            halignment = right
       left=80    top=58     height=20       width=70         border = box
       alias=cli3_numb_client                font_size=12     font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="opennew find_client.rml"
       editexp="cli3_numb_client=STORE.client.id_client"
       dep="name_client2"
   }
   {field
      target=client2.name1_client
      left=155    top=58     height=20       width=270        border = box
      alias=name_client2     font_size=12    font_family=0    bg_color="#ffffff"
      editexp="name_client2=STORE.client.name1_client"
           editable = readonly
   }
   {label
       value="Номер пер док."
       left=537    top=33     height=20       width=80
       font_size=12          font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.num_per_sd            halignment = right
       left=617    top=33     height=20       width=70         border = box
       alias=num_per         font_size=12     font_family=0    bg_color="#ffffff"
   }
   {label
       value="Дата пер док."
       left=547    top=58     height=20       width=80
       font_size=12          font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.date_per_sd            halignment = right
       left=617    top=58     height=20       width=70         border = box
       alias=dat_per         font_size=12     font_family=0    bg_color="#ffffff"
   }
   {label
       value="Сумма"
       left=547    top=88     height=20       width=80
       font_size=12          font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.sum2_sd           halignment = right
       left=617    top=88     height=20       width=70         border = box
       alias=sum1_sd font_size=12     font_family=0    bg_color="#ffffff"
       editable = readonly
       editmask = "# #0.00"
   }
   {label
       value="Примечание"    
       left=11    top=108     height=20      width=65
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.comment_sd   border = box
       left=80    top=108    height=20      width=495
       alias=comment_sd         font_size=12   font_family=0    bg_color="#ffffff"
   }
   {label
    alias=progress
    left = 700  top = 8      width = 250     height = 20 
    font_size=17              font_family=1   font_color="#FF0033"
    bg_color="#c0c0c0"        border=none     
   }
{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,client.name1_client,
                        head.id_client2,client2.name1_client,
                        head.comment_sd,
                        head.id_contract,contract.name_contract,
                        head.id_personal,personal.fname,
                        head.parent_id_head,
                        head.sum1_sd, head.sum2_sd
                   from head,client,client client2,personal,department,contract
                  where head.id_head = ~ARGUMENTS.0~
                   and head.id_client1 = client.id_client (+)
                   and head.id_client2 = client2.id_client (+)
                   and head.id_contract = contract.id_contract (+)
                   and head.id_department1 = department.id_department (+)
                   and head.id_personal = personal.id_personal(+)"
              editable = yes
                  head = yes
                unique = "('head','head.id_head')"
               default = "head.id_head=~ds.hpk~,head.id_type_doc=~78~,
                          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_contract=~1~,
                          head.id_client1=~1~,
                          client.name1_client=~'ФИРМА'~, 
                          head.id_client2=~1~,
                          client2.name1_client=~'ФИРМА'~"
} // ds

} // form
{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            rowsize=24     
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)
          (global.cur_id_active = store.active.id_active)
          ($g.ds_active@retrieve)
          (g.price1_spc=($try ($g.ds_active@GetValue 'PRICE') $catch ('Any')(0)))

        ))
        ($ret '')
        )"
{menu
   {item label = "Поиск в справочнике" action="opennew find_choose.rml 1, 0"}
//   {item label = "Ввод в эксплуатацию ТС" action="create docs/vvod_os.rml ~($g.d_spc@getValue 'SPC.ID_ACTIVE' )~"}
//     {item label = "Ввод в эксплуатацию ТС" action="~($X 
//                ($g.check_possibility@retrieve)
//                (t=($g.check_possibility@getvalue 'KOL'))
//                ($if (t<d_spc.spc.q1_spc)
//                 ($ret 'create docs/vvod_exp_ts.rml '+($g.d_spc@getValue 'SPC.ID_SPC' )+';')
//                 $else
//                 ($g.self@sure 'ТС уже введен' 1)
//                 ($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
 }
 {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=45
    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=200       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=40     
    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
    editexp = "id_un=STORE.active_pseudo_unit.id_pseudo_unit"
 }
 {column size=60       title="Ед. изм."
    target=active_pseudo_unit.obozn  title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=name_un               
    editable = handbook    
    edit = "opennew psevdo_units.rml ~($try (war) $catch ('NullException') (-1) )~"
    editexp = "name_un=STORE.active_pseudo_unit.obozn"
    dep = "id_un"
 }
 {column size=70       title="Кол-во " 
    target=spc.q1_spc      title_font_family=2      halignment=right
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.00"    alias = q1_spc
    dep="summ, sum_nds, itog_sum"
 }
// {column size=50       title="Кол-во " 
//    target=spc.q2_spc      title_font_family=2      halignment=right
//    font_color="#000000"     font_size=12            font_family=0
//   editmask = "# #0.00"    alias = q2_spc
//}
 {column size=85
    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    
    dep="summ"
 }
 {column size=80
    type = number            title="Сумма"      title_font_family=2
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.000"    alias = summ        halignment=right
    exp="summ=q1_spc * price1_spc"               value="0"
    editexp="price1_spc=summ /q1_spc"
    dep="sum_nds,itog_sum"
 }
 {column size=40             visible=no
    target = spc.id_nds      title="НДС"      title_font_family=2
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.00"    alias = id_nds        halignment=right
   editexp = "id_nds=STORE.nds.id_nds"
 }
 {column size=60
    target = nds.proc_nds            title="НДС"      title_font_family=2
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0"    alias = pr_nds        halignment=right
    editable = handbook                        value="0"
    edit = "opennew nds.rml"
    editexp = "pr_nds=STORE.nds.proc_nds"
    dep = "id_nds,sum_nds"
 }

 {column size=80
    type = number            title="Сумма НДС"      title_font_family=2
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.00"    alias = sum_nds        halignment=right
    exp="sum_nds=summ * pr_nds /100"
    dep = "itog_sum"
    editable=no
 }
 {column size=100
    type = number            title="Итоговая сумма"      title_font_family=2
    font_color="#000000"     font_size=12            font_family=0
    editmask = "# #0.00"    alias = itog_sum        halignment=right
    exp="itog_sum=summ + sum_nds"
    editexp="price1_spc=itog_sum/(q1_spc*(1 + pr_nds/100))"
 }
 //editexp="price1_spc=(itog_sum - (itog_sum/100 * pr_nds)) / q1_spc"
 //editexp="(sum_nds=itog_sum/100 * pr_nds)(summ=itog_sum-sum_nds)"
 {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,
		      spc.id_nds,nds.proc_nds
                 from spc,active,active_pseudo_unit,nds
                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 spc.id_nds = nds.id_nds
             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.id_nds=~2~,nds.proc_nds=~20~,
                         spc.price1_spc=~0~,spc.price2_spc=~0~"  
//        {datastore alias = check_possibility
//        query="select count(id_vehicle) KOL
//               from vehicle
//             where vehicle.id_spc=~($g.d_spc@getValue 'SPC.ID_SPC' )~
//               "}
} // ds
} // grid1
} // tabset
} // split
{button
  left = 11  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Сохранить и выйти F3"
  action = "($X
	     ($if (($G.D_HEAD@getValue 'HEAD.ACCEPT') == 1)
		  (
		    ($g.self@actcancel)
		    ($ret '')
		  )
	     )

             # проверка цен

             (i = 0) (found = 0)
             (str = 'Некоторые цены отличаются от предыдущих более чем на 30 процентов.% Название : предыдущая приходная цена %---------------------------------------')
             ($while (i < ($g.d_spc@size))
               (
                 ($g.d_spc@fastSetCurRow i)
                  (global.cur_id_active = ($g.d_spc@getValue 'spc.id_active'))
                  ($g.prev_price_ds@retrieve)
                  ($if (($g.prev_price_ds@size) > 0)
                    (
                      ($debug '====================== id_active previous price: ' + ($g.prev_price_ds@getValue 'prev_price'))
                      ($if (($g.prev_price_ds@getValue 'prev_price') != 0)
                         (
                           (diff = ($g.d_spc@getValue 'spc.price1_spc') - ($g.prev_price_ds@getValue 'prev_price'))
                           (diff = diff / ($g.prev_price_ds@getValue 'prev_price') * 100)
                         )
                       $else 
                         (diff = 0)
                      )
                      ($debug '===================== diff: ' + diff)
                      ($if (diff > 30)
                        (
                          (found += 1)
                          ($if (found <= 3)
                             (str += '% ' + ($g.d_spc@getValue 'active.name_active') + ' :        ' + ($round1 ($g.prev_price_ds@getValue 'prev_price')))
                          )
                        )
                      )
                    )
                 )
                 (i += 1)

               )
             )
             ($if (found > 3)
               (str += '% (... показаны не все ... )')
             )
             (str += '%---------------------------------------% Сохранить документ?')
             ($if (found > 0)
                ($if (($g.self@sure str 0) == 0)
                  ($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 = 11  width = 50    height = 20
  BACKGROUND = "LIGHTGRAY"    foreground="#000000"
  label = "Запис F4"
  action = "($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)
                )
            )
	    #($if (($G.D_HEAD@getValue 'HEAD.ACCEPT') == 1)
		#  (
		    #($g.self@doAction 'execute exec doc_lib.de_accept(' + ($G.D_HEAD@getValue 'HEAD.ID_HEAD') + ');')
		    #($g.self@actsave)
		    #($g.self@doAction 'execute exec doc_lib.accept(' + ($G.D_HEAD@getValue 'HEAD.ID_HEAD') + ');')\
		#    ($g.self@actcancel)
		#  )
		#  $else (
		    ($g.self@actsave)
		#  )
		#)
		"
  shortcut = "F4"
}
{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"
}
} // toolbar

