Cp1251
DOC 
foreground = lightgray
document_width = 750
document_height = 550
document_title = "Демонтаж оборудования"
style = "style/docs.st"
preloadscript="
(global.create = 0)
(global.d1 = ('\''+'01.01.2003'+'\'') )
(global.get_num = 0)
"

postloadscript = "($X
			($IF (($g.D_HEAD@getvalue 'HEAD.ACCEPT') == 1)
		            ($g.progress@setValue 'Только для чтения')
		        )
                        (v = ($@validator))
                        ($v@SetType 'NUMBER')
                        ($v@SetMask '##0.')
                        ($g.d_spc_init@retrieve)
                        (t = ($g.d_spc_init@iterator))
                        (i = 0)
                        l_id_spc = 0
                        l_id_active = 0
                        l_id_unit = 0
                        l_q1_spc = 0
                        l_name_active = ''
                        l_obozn_n = ''

                        ($while ($t@next)
                            (
                                (i += 1)
                                ($g.d_spc_init@SetCurRow (i-1))
     
                                ($g.d_spc@newrow)
                                #l_id_spc_new = ($try ($g.d_spc@GetValue 'SPC.ID_SPC') $catch ('Any')(1))
                                ($g.d_repair_leaf_spc@newrow)
                                l_id_spc = ($try ($g.d_spc_init@GetValue 'SPC.ID_SPC') $catch ('Any')(1))
                                l_id_active = ($try ($g.d_spc_init@GetValue 'SPC.ID_ACTIVE') $catch ('Any')(1))
                                l_id_unit = ($try ($g.d_spc_init@GetValue 'SPC.ID_UNIT') $catch ('Any')(1))
                                l_q1_spc = ($try ($g.d_spc_init@GetValue 'SPC.Q1_SPC') $catch ('Any')(1))
                                l_name_active = ($try ($g.d_spc_init@GetValue 'ACTIVE.NAME_ACTIVE') $catch ('Any')(1))
                                l_obozn_n = ($try ($g.d_spc_init@GetValue 'ACTIVE_PSEUDO_UNIT.OBOZN') $catch ('Any')(1))

                                ($g.d_repair_leaf_spc@SetValue 'REPAIR_LEAF_SPC.ID_SPC_REPAIR_LEAF' l_id_spc)
                                ($g.d_spc@SetValue 'SPC.ID_ACTIVE' l_id_active)
                                ($g.d_spc@SetValue 'SPC.ID_UNIT' l_id_unit)
                                ($g.d_spc@SetValue 'SPC.Q1_SPC' l_q1_spc)
                                ($g.d_spc@SetValue 'ACTIVE.NAME_ACTIVE' l_name_active)
                                ($g.d_spc@SetValue 'ACTIVE_PSEUDO_UNIT.OBOZN' l_obozn_n)
                            
                             )
                         )
                         ($g.d_spc@notifyviews)

                         ($g.d_rab_center@retrieve)
                         g.sklad_t = ($try ($g.d_rab_center@GetValue 'HEAD.ID_DEPARTMENT1') $catch ('Any')(1))
                         g.sklad = ($try ($g.d_rab_center@GetValue 'DEPARTMENT.NAME1_DEP') $catch ('Any')(1))

                         ($g.d_mesto@retrieve)
                         g.ins_d_rml = 'find_choose.rml'
                         g.ins_d_fl = 'id_active'
                         g.ins_d_tab = 'active'
                         g.ins_prim = 'актив'
                         g.ins_prim_t = 4
                         g.ins_d_value = ($try ($g.d_mesto@GetValue 'ACTIVE.ID_ACTIVE') $catch ('Any')(1))

                         ($if (($try (g.ins_d_tab) $catch ('Any')('')) == 'client')
                             (
                                 ($g.d_znach_cl@retrieve)
                                  ($if (($g.d_znach_cl@size) > 0)
                                      (
                                        (g.ins_d_value_name=($try ($g.d_znach_cl@GetValue 'CLIENT.NAME1_CLIENT') $catch ('Any')(1)))
                                      )
                                  )                       
                             )
                         )
                         ($if (($try (g.ins_d_tab) $catch ('Any')('')) == 'department')
                             (
                                  ($g.d_znach_dep@retrieve)
                                  ($if (($g.d_znach_dep@size) > 0)
                                      (
                                        (g.ins_d_value_name=($try ($g.d_znach_dep@GetValue 'DEPARTMENT.NAME1_DEP') $catch ('Any')(1)))
                                      )
                                  )
                             )
                         )
                         ($if (($try (g.ins_d_tab) $catch ('Any')('')) == 'active')
                             (
                                  ($g.d_znach_active@retrieve)
                                  ($if (($g.d_znach_active@size) > 0)
                                      (
                                        (g.ins_d_value_name=($try ($g.d_znach_active@GetValue 'ACTIVE.NAME_ACTIVE') $catch ('Any')(1)))
                                      )
                                  )
                             )
                         )

                         ($ret '')
                  )"

{dscollection
   alias = ds
   initQuery = "select head_sq.nextval,sysdate,id_personal,obj_data_equip_sq.nextval from personal where upper(login)=user"
   aliases = "hpk,date,idp,odpk"
   seqquery = "select spc_sq.nextval,repair_leaf_spc_sq.nextval from dual"
   seqnames = "spk,rlhsq"
   initAction ="(global.create = 1)
                (global.get_num = 1)"
}

{datastore  alias=doc_num
    query="select num_sd from (select 'ДмОб-'||(nvl(max(to_number(substr(num_sd, 6))), 0) + 1) num_sd
             from head
            where head.num_sd like 'ДмОб-%')"
  } // end of ds

//{datastore 
//      alias = d_spc_init
//      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,head
//                where
//                  head.id_head=~($try (ARGUMENTS.0) $catch ('NullException') (-1) )~ 
//                  and spc.id_head = head.id_head 
//                  and spc.id_active = active.id_active 
//                  and spc.id_unit = active_pseudo_unit.id_pseudo_unit
//                  and spc.id_nds = nds.id_nds
//                  and active.id_type_active = 4
//                  and spc.work_type = 1
//                  and NOT EXISTS (select * from repair_leaf_spc where 
//                        repair_leaf_spc.id_spc_repair_leaf = spc.id_spc
//                        and repair_leaf_spc.id_repair_leaf = ~($try (ARGUMENTS.1) $catch ('NullException') (-1) )~)
//             order by spc.id_spc"
//             editable = no
//}
{datastore 
      alias = d_spc_init
      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,head
                where
                  head.id_head=~($try (ARGUMENTS.0) $catch ('NullException') (-1) )~ 
                  and spc.id_head = head.id_head 
                  and spc.id_active = active.id_active 
                  and spc.id_unit = active_pseudo_unit.id_pseudo_unit
                  and spc.id_nds = nds.id_nds
                  and active.id_type_active = 4
                  and spc.work_type = 1
             order by spc.id_spc"
             editable = no
}

{datastore 
      alias = d_rab_center
      query = "select head.id_department1,department.name1_dep
                 from head,department,repair_leaf
                where head.id_department1 = department.id_department
                      and head.id_head = repair_leaf.id_head
                      and repair_leaf.id_repair_leaf = ~($try (ARGUMENTS.1) $catch ('NullException') (-1) )~"
             editable = no
}


{datastore 
      alias = d_znach_cl
      query = "select client.name1_client from client where client.id_client = ~d_head.obj_data_equip.value~"
      editable = no
}
{datastore 
      alias = d_znach_dep
      query = "select department.name1_dep from department where department.id_department = ~d_head.obj_data_equip.value~"
      editable = no
}
{datastore 
      alias = d_znach_active
      query = "select active.name_active from active where active.id_active = ~d_head.obj_data_equip.value~"
      editable = no
}
{datastore 
      alias = d_mesto
      query = "select active.id_active
                 from repair_leaf,vehicle,active
                where repair_leaf.id_repair_leaf = ~($try (ARGUMENTS.1) $catch ('NullException') (-1) )~
                      and repair_leaf.id_vehicle = vehicle.id_vehicle
                      and vehicle.id_active = active.id_active"
             editable = no
}
{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel   percent=40
{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=11    top=33   height=20       width=90
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.id_department1
       visible=no           border = box
       left=110    top=33    height=20       width=100
       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=110    top=33    height=20       width=100
       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=470  top=8      height=20       width=70
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=personal.fname                border = box
       left=550    top=8    height=20       width=70
       alias=name           font_size=12    font_family=0    bg_color="#ffffff"
       editable = readonly
   }     
   {label
       value="Примечание"    
       left=11    top=83     height=20      width=65
       font_size=12          font_family=0  bg_color="#c0c0c0"
   }
   {field
       target=head.comment_sd   border = box
       left=80    top=83    height=20      width=495
       alias=comment_sd         font_size=12   font_family=0    bg_color="#ffffff"
   }
   {label
       value= "Откуда забираем"
       left=11    top=58    height=20       width=90
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=obj_data_equip.id_head
       visible=no           border = box     visible=no
       left=110    top=58    height=20       width=100
       alias=ins_d_head        font_size=12    font_family=0    bg_color="#ffffff"
   }
   {field
       target=obj_data_equip.id_obj_ins_equip
       visible=no           border = box      visible=no
       left=110    top=58    height=20       width=100
       alias=ins_prim_t        font_size=12    font_family=0    bg_color="#ffffff"
       editexp="(ins_prim_t=STORE.obj_ins_equip.id_obj_ins_equip)"
   }
   {field
       target=obj_ins_equip.prim                 border = box
       left=110    top=58    height=20       width=100
       alias=ins_prim          font_size=12    font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="opennew obj_ins_equip.rml "
       editexp="ins_prim=STORE.obj_ins_equip.prim"
       dep="ins_prim_t,ins_d_tab,ins_d_fl,ins_d_rml"
   }
   {field
       target=obj_ins_equip.name_table          border = box
       left=400    top=58    height=20       width=100    visible=no
       alias=ins_d_tab        font_size=12    font_family=0    bg_color="#ffffff"
       editexp="(ins_d_tab=STORE.obj_ins_equip.name_table)"
   }
   {field
       target=obj_ins_equip.field          border = box
       left=500    top=58    height=20       width=100        visible=no
       alias=ins_d_fl        font_size=12    font_family=0    bg_color="#ffffff"
       editexp="(ins_d_fl=STORE.obj_ins_equip.field)"
   }
   {field
       target=obj_ins_equip.rml          border = box
       left=500    top=40   height=20       width=100          visible=no
       alias=ins_d_rml        font_size=12    font_family=0    bg_color="#ffffff"
       editexp="(ins_d_rml=STORE.obj_ins_equip.rml)"
   }
   {label
       value="Значение"
       left=220    top=58    height=20       width=70
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=obj_data_equip.value          border = box
       left=300    top=58    height=20       width=100
       alias=ins_d_value        font_size=12    font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="~($X
		($debug g.ins_d_rml)
              ($ret 'opennew ' + g.ins_d_rml) )~"
       editexp="($X
		  ($debug g.ins_d_tab)
		 ($if ((g.ins_d_tab) == 'client')
	              ($ret g.ins_d_value=STORE.client.id_client)
		  $else
		   ($if ((g.ins_d_tab) == 'department')
	              ($ret g.ins_d_value=STORE.department.id_department)
		    $else
	 	     ($if ((g.ins_d_tab) == 'active')
	               ($ret g.ins_d_value=STORE.active.id_active)
		      $else
		       ($ret g.ins_d_value= -1)
 		     )
		   )
		 )
		)"
        dep="ins_d_value_name"
   }
   {field
       border = box type=string
       left=405    top=58    height=20       width=150
       alias=ins_d_value_name        font_size=12    font_family=0    bg_color="#ffffff"
       editable=readonly      
       editexp="($X
		  ($debug g.ins_d_tab)
		 ($if ((g.ins_d_tab) == 'client')
	              ($ret g.ins_d_value_name=STORE.client.name1_client)
		  $else
		   ($if ((g.ins_d_tab) == 'department')
	              ($ret g.ins_d_value_name=STORE.department.name1_dep)
		    $else
	 	     ($if ((g.ins_d_tab) == 'active')
	               ($ret g.ins_d_value_name=STORE.active.name_active)
		      $else
		       ($ret g.ins_d_value_nane= '')
 		     )
		   )
		 )
		)"
   }
   {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     
   }
{datastore 
        alias = d_head
        query = "select head.id_head,head.id_type_doc,head.accept,
                        head.num_sd,head.date_sd,
                        head.id_department1,department.name1_dep,
                        head.id_department2,
                        head.id_client1,head.id_client2,head.comment_sd,
                        head.id_personal,personal.fname,
                        obj_data_equip.id_head,obj_data_equip.id_obj_data_equip,
			obj_data_equip.value,
			obj_ins_equip.name_table,obj_ins_equip.field,obj_ins_equip.rml,
			obj_data_equip.id_obj_ins_equip,obj_ins_equip.prim,
			head.parent_id_head
                   from head,personal,department,
			obj_data_equip,obj_ins_equip 
                  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_head = obj_data_equip.id_head 
	      	   and obj_data_equip.id_obj_ins_equip = obj_ins_equip.id_obj_ins_equip
                   and head.id_type_doc = 95"
              editable = yes
                  head = yes
                unique = "('head','head.id_head');('obj_data_equip','obj_data_equip.id_obj_data_equip')"
               default = "head.id_head=~ds.hpk~,head.id_type_doc=~95~,
                          head.date_sd=~ds.date~,
                          head.id_personal=~ds.idp~,
                          head.accept=~0~,
                          head.num_sd=~'ДмОб-'~,
                          head.id_department1=~0~,head.id_department2=~0~,
                          head.id_client1=~1~,head.id_client2=~1~,
			  head.parent_id_head = ~($try (ARGUMENTS.0) $catch ('any') (-1))~,
		     obj_data_equip.id_obj_data_equip=~ds.odpk~,
		     obj_data_equip.id_obj_ins_equip=~1~,
		     obj_ins_equip.prim=~'не указан'~,
		     obj_data_equip.id_head=~ds.hpk~,
		     obj_data_equip.value=~0~ "
} // ds
} // form
} // scroll
{tabset labels = "перечень продукции"
 tabs_on_top=yes
{grid
editable = yes
add="opennew find_choose_obor.rml"
alias = GRIDSPC
buttonbar_font_family=0       buttonbar_font_size=12           
buttonbar_size = 30           titlebar_size = 18            rowsize=20     
addexp="war=store.active.id_active;
        name_w=store.active.name_active;
	id_un=store.active_pseudo_unit.id_pseudo_unit;
        name_un=store.active_pseudo_unit.obozn"
{menu
   {item label = "Поиск в справочнике" action="opennew find_choose_obor.rml"}
}
 {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=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   
 }
 {column size=180       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   
    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=50       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
 }
 {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
                 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.price1_spc=~0~,spc.price2_spc=~0~"  
  {datastore
        alias=d_repair_leaf_spc
        query="select repair_leaf_spc.id_repair_leaf_spc,
                      repair_leaf_spc.id_repair_leaf,
                      repair_leaf_spc.id_spc,
                      repair_leaf_spc.id_spc_repair_leaf
               from repair_leaf_spc where repair_leaf_spc.id_repair_leaf_spc = -1"
        editable = yes
        unique = "('repair_leaf_spc','repair_leaf_spc.id_repair_leaf_spc')" 
        default = "repair_leaf_spc.id_repair_leaf_spc=~ds.rlhsq~,
                   repair_leaf_spc.id_repair_leaf=~($try (ARGUMENTS.1) $catch ('any') (-1))~,
                   repair_leaf_spc.id_spc=~($try (d_spc.spc.id_spc) $catch ('NullException') (-1) )~"
   } // ds
} // 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 '')
		  )
	     )
             (tmp = 'Вы действительно хотите сохранить все изменения и выйти' + '')
             (m = ($g.self@sure tmp 0))
               ($if (m == 0)()
               $else 
                    (
                        ($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)
                )
            )
            ($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

