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.cur_id_spc = 0)
(global.get_num = 0)
(global.cur_id_vehicle)=-1
"

postloadscript="($X
		    ($IF (($g.D_HEAD@getvalue 'HEAD.ACCEPT') == 1)
		            ($g.progress@setValue 'Только для чтения')
		    )
                    ($if (global.create == 1)
                        (
                            ($g.d_ts@newRow)
                            ($g.d_ts@notifyviews)
                            (g.track_vehicle = 0)
                            (g.status_got=1)
                        )
                     $else
                        (
                            #($g.self@sure '1' 1)
                            (g.track_vehicle=($try (d_head.repair_leaf.track_vehicle) $catch ('NullException') (-1) ))
                            ($if (($try ((g.track_vehicle_osn)) $catch ('NullException') (-1) ) != -1)
                                (
                                    (g.track_vehicle_osn=($try (d_head.repair_leaf.track_vehicle_osn) $catch ('NullException') (-1) ))
                                )
                            )                            
                            (g.status_got=($try (d_head.repair_leaf.status_got) $catch ('NullException') (-1) ))
                        )
                    )
                    
                )"
{dscollection
   alias = ds
   initQuery = "select head_sq.nextval,repair_leaf_sq.nextval,sysdate,id_personal from personal where upper(login)=user"
   aliases = "hpk,rlsq,date,idp"
   seqquery = "select spc_sq.nextval from dual"
   seqnames = "spk"
   initAction ="(global.create = 1)
                (global.get_num = 1)"
}

{datastore  alias=cur_date
    query="select sysdate 
             from dual"
  } // end of ds

{datastore  alias=damsq
    query="select damage_sq.nextval 
             from dual"
  } // end of ds

{datastore  alias=count_docs
    query="select count(1) docs from repair_leaf_spc 
             where id_spc_repair_leaf=~global.cur_id_spc~"
  } // end of ds

{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=damage_tc
    query="select damage_vehicle.id_damage, 
                      damage_vehicle.name_damage,
                      damage_vehicle.date_damage,
                      damage_vehicle.id_vehicle
                 from (select  MAX(repair_leaf2.id_repair_leaf) id_r
                        from repair_leaf repair_leaf2, head
                        where repair_leaf2.id_vehicle= ~global.cur_id_vehicle~
			      and repair_leaf2.id_head = head.id_head
			      and head.accept = 1
                              and repair_leaf2.id_repair_leaf != ~($try (d_head.repair_leaf.id_repair_leaf) $catch ('NullException') (-1) )~
                 ),damage_vehicle
                where damage_vehicle.id_vehicle = ~global.cur_id_vehicle~ and damage_vehicle.id_repair_leaf=id_r
             order by damage_vehicle.id_damage"
  } // end of ds

{datastore  alias=pok_tc
    query="select repair_leaf.track_vehicle,
                        repair_leaf.track_vehicle_osn,
                        repair_leaf.status_got
           from (select  MAX(repair_leaf2.id_repair_leaf) id_r
                     from repair_leaf repair_leaf2, head
                 where repair_leaf2.id_vehicle= ~global.cur_id_vehicle~
		       and repair_leaf2.id_head = head.id_head
		       and head.accept = 1
                       and repair_leaf2.id_repair_leaf != ~($try (d_head.repair_leaf.id_repair_leaf) $catch ('NullException') (-1) )~
                 ), repair_leaf
                   where repair_leaf.id_repair_leaf=id_r"
  } // end of ds

{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=80
       font_size=12         font_family=0    bg_color="#c0c0c0"
   }
   {field
       target=head.id_client1                 halignment = right
       left=95     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=170     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=repair_leaf.id_vehicle            halignment = right
       left=95    top=58     height=20       width=70         border = box
       alias=id_vehicle                font_size=12     font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="opennew find_TC.rml"
       editexp=" 
                ($X
                    (global.cur_id_vehicle = STORE.vehicle.id_vehicle)
                    ($if (g.id_vehicle == STORE.vehicle.id_vehicle)
                        (
                            ($ret '')
                        )
                    )
                    (g.track_vehicle = 0)
                    (g.track_vehicle_osn = '')
                    (g.status_got = 1)
                    (d_head.repair_leaf.id_vehicle=STORE.vehicle.id_vehicle)

                    ($g.damage_tc@retrieve)
                    (t = ($g.damage_tc@iterator))
                    (i = 0)
                    (l_id_damage = -1)
                    (l_name_damage = '')
                    (l_date_damage = 0)
                    (l_id_vehicle = -1)

                    ($g.d_damage@clear)

                    ($while ($t@next)
                    (
                        (i += 1)
                        ($g.damage_tc@SetCurRow (i-1))
                        ($g.damsq@retrieve)
                        (l_id_damage = ($g.damsq@getValue 'DAMAGE_SQ.NEXTVAL'))
                        l_name_damage = ($try ($g.damage_tc@GetValue 'DAMAGE_VEHICLE.NAME_DAMAGE') $catch ('Any')(0))
                        l_date_damage = ($try ($g.damage_tc@GetValue 'DAMAGE_VEHICLE.DATE_DAMAGE') $catch ('Any')(0))
                        l_id_vehicle = ($try ($g.damage_tc@GetValue 'DAMAGE_VEHICLE.ID_VEHICLE') $catch ('Any')(0))

                        ($g.d_damage@newrow)
                        ($g.d_damage@SetValue 'DAMAGE_VEHICLE.ID_DAMAGE' l_id_damage)
                        ($g.d_damage@SetValue 'DAMAGE_VEHICLE.NAME_DAMAGE' l_name_damage)
                        ($g.d_damage@SetValue 'DAMAGE_VEHICLE.DATE_DAMAGE' l_date_damage)
                        ($g.d_damage@SetValue 'DAMAGE_VEHICLE.ID_VEHICLE' l_id_vehicle)
                        ($g.d_damage@SetValue 'DAMAGE_VEHICLE.ID_REPAIR_LEAF' d_head.repair_leaf.id_repair_leaf)
                    )
                    )
                     ($g.pok_tc@retrieve)
                     ($g.d_ts@clear)
                     ($g.d_ts@newrow)

                     ($if (($g.pok_tc@size) > 0)
                         (
                             l_track_vehicle = ($try ($g.pok_tc@GetValue 'REPAIR_LEAF.TRACK_VEHICLE') $catch ('Any')(0))
                             l_track_vehicle_osn =($try ($g.pok_tc@GetValue 'REPAIR_LEAF.TRACK_VEHICLE_OSN') $catch ('Any')(''))
                             l_status_got = ($try ($g.pok_tc@GetValue 'REPAIR_LEAF.STATUS_GOT') $catch ('Any')(1))
                           
                             ($g.d_ts@SetValue 'REPAIR_LEAF.TRACK_VEHICLE' l_track_vehicle)
                             ($g.d_ts@SetValue 'REPAIR_LEAF.TRACK_VEHICLE_OSN' l_track_vehicle_osn)
                             ($g.d_ts@SetValue 'REPAIR_LEAF.STATUS_GOT' l_status_got)

                             (g.track_vehicle = l_track_vehicle)
                             (g.track_vehicle_osn = l_track_vehicle_osn)
                             (g.status_got = l_status_got)
                         )
                     )
                     
                     ($g.d_ts@notifyviews)
                     ($g.d_damage@notifyviews)
                     ($ret '')
                ) id_vehicle=STORE.vehicle.id_vehicle"
       dep="name_of_models"
   }
   {field
      target=models_of_vehicle.name_of_models
      left=170    top=58     height=20       width=270        border = box
      alias=name_of_models     font_size=12    font_family=0    bg_color="#ffffff"
      editexp="name_of_models=STORE.models_of_vehicle.name_of_models"
           editable = readonly
   }

   {label
       value="Рабочий центр"        
       left=11    top=83    height=20       width=80
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.id_department1
       border = box
       left=95    top=83    height=20       width=70
       alias=sklad_t        font_size=12    font_family=0    bg_color="#ffffff"
       editable=handbook
       edit="opennew find_department.rml "
       editexp="sklad_t=STORE.department.id_department"
       dep="sklad"
   }
   {field
       target=department.name1_dep                 border = box
       left=170    top=83    height=20       width=200
       alias=sklad          font_size=12    font_family=0    bg_color="#ffffff"
       editable=readonly
       editexp="sklad=STORE.department.name1_dep"
   }

   {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 = 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 repair_leaf.id_repair_leaf,
                        repair_leaf.id_head,
                        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.comment_sd,
                        head.parent_id_head,
                        head.id_client1,head.id_client2,
                        repair_leaf.id_vehicle,
                        repair_leaf.track_vehicle,
                        repair_leaf.track_vehicle_osn,
                        repair_leaf.status_got,
                        head.id_personal,
                        models_of_vehicle.name_of_models,
			client.name1_client
                   from head,department,vehicle,repair_leaf,models_of_vehicle,client
                  where head.id_head = ~($try ($if (global.create == 0)
                                  	    	(ARGUMENTS.0)
	                                       $else (ds.hpk))
		                         $catch ('any') (-1))~
                   and head.id_head = repair_leaf.id_head
                   and head.id_department1 = department.id_department (+)
                   and head.id_type_doc = 77
                   and repair_leaf.id_vehicle = vehicle.id_vehicle
                   and vehicle.id_models_of_vehicle=models_of_vehicle.id_models_of_vehicle
		   and head.id_client1 = client.id_client
                 "
              editable = yes
                  head = yes
                unique = "('head','head.id_head')('repair_leaf','repair_leaf.id_repair_leaf')"
               default = "repair_leaf.id_repair_leaf=~ds.rlsq~,
                          repair_leaf.id_vehicle=~-1~,
                          repair_leaf.id_head=~ds.hpk~,
                          repair_leaf.track_vehicle=~0~,
                          repair_leaf.status_got=~1~,
                          department.name1_dep=~'Неизвестный'~,
                          models_of_vehicle.name_of_models=~'МОДЕЛЬ'~,
                          head.id_head=~ds.hpk~,head.id_type_doc=~77~,
                          head.date_sd=~ds.date~,
                          head.accept=~0~,
                          head.num_sd=~'РЛ-'~,
                          head.id_department1=~0~,
                          head.id_department2=~0~,
                          head.id_client1=~1~,
                          head.id_client2=~1~,
                          head.id_personal=~ds.idp~"
} // ds
} // form
} // scroll
{tabset labels = "ТМЦ и услуги,Оборудование и агрегаты,Показатели и статус ТС,Список повреждений,Порожденные документы"
 tabs_on_top=yes

 // ТМЦ и услуги
{grid
editable = yes
add="opennew find_active_tmc_usl.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"
del = "~($X 
            global.cur_id_spc = ($try ($g.d_spc@GetValue 'SPC.ID_SPC') $catch ('Any')(1))
            ($g.count_docs@retrieve)
            ($if (($g.count_docs@getValue 'DOCS') > 0)
                (
                    ($g.self@sure 'Удаление невозможно! Уже сформированы документы.' 1)
                    ($ret '')
                )
            )
            ($g.d_spc@DelRow ($g.d_spc@GetCurRow))
            ($g.self@actsave)
            ($g.d_spc@NotifyViews)
            ($ret '') 
        )~"

{menu
   {item label = "Поиск в справочнике" action="opennew find_active_tmc_usl.rml 1,2"}
   {item label = "-"}
   {item label = "Приходовать" action="create docs/prih_repair_leaf.rml ~($g.d_head@getValue 'HEAD.ID_HEAD' )~,~($g.d_head@getValue 'REPAIR_LEAF.ID_REPAIR_LEAF' )~;retrieve GRIDSPC; retrieve griddoc"}
   {item label = "Списать" action="create docs/rash_repair_leaf.rml ~($g.d_head@getValue 'HEAD.ID_HEAD' )~,~($g.d_head@getValue 'REPAIR_LEAF.ID_REPAIR_LEAF' )~;retrieve GRIDSPC;retrieve griddoc"}
}
 {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=400       title="Наименование"
    target=active.name_active  title_font_family=2     halignment=right
    font_color="#191970"      font_size=12              font_family=1
    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=center
    font_color="#191970"      font_size=12              font_family=1
    alias=name_un               
    editable = handbook    
    edit = "opennew psevdo_units.rml ~($try (d_spc.spc.id_active) $catch ('NullException') (-1) )~"
    editexp = "name_un=STORE.active_pseudo_unit.obozn"
    dep = "id_un"
 }

 {column size=90       title=" Кол-во " 
    target=spc.q1_spc      title_font_family=2      halignment=right
    font_color="#191970"     font_size=12            font_family=1
    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,
		              spc.id_nds,nds.proc_nds,
                      active_pseudo_unit.obozn
                 from spc,active,nds,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_nds = nds.id_nds
                  and spc.id_unit = active_pseudo_unit.id_pseudo_unit 
                  and (active.id_type_active = 1 or active.id_type_active = 2)
             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=~18~,
                         spc.price1_spc=~0~,spc.price2_spc=~0~"
} // ds
} // grid1

 // Оборудование и агрегаты
{grid
editable = yes
add="opennew find_active_oborud.rml"
alias = GRIDOB
buttonbar_font_family=0       buttonbar_font_size=12           
buttonbar_size = 30           titlebar_size = 18            rowsize=20     
addexp="war2=store.active.id_active;
        name_w2=store.active.name_active;
	    id_un2=store.active_pseudo_unit.id_pseudo_unit;
        name_un2=store.active_pseudo_unit.obozn"
{menu
   {item label = "Поиск в справочнике" action="opennew find_active_oborud.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=war2                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_w2              editable = readonly 
 }
 {column size=70       title="Тип работы" visible=no
    target=spc.work_type  
    title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=spc_work_type              
    editexp="spc_work_type=STORE.work_type.id_work_type"
 }
 {column size=100       title="Тип работы"
    target=work_type.name_type
    title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=name_work_type
    editable=handbook
    edit="opennew work_type.rml "
    editexp="name_work_type=STORE.work_type.name_type"
    dep="spc_work_type"
 }
 {column size=100       title="ID Рабочий центр" visible=no
    target=spc.id_department  title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=spc_id_department              editable = readonly 
    editexp="spc_id_department=STORE.department.id_department"
 }
 {column size=100       title="Рабочий центр"
    target=department.name1_dep  title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=spc_name1_dep              
    editable=handbook
    edit="opennew find_department.rml "
    editexp="spc_name1_dep=STORE.department.name1_dep"
    dep="spc_id_department"
 }
 {column size=60     
    visible=no
    title="Код"              font_family=0
    target=spc.id_unit       title_font_family=2     halignment=left
    alias=id_un2                font_color="#000000"     font_size=12
    editexp = "id_un2=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_un2               
    editable = handbook    
    edit = "opennew psevdo_units.rml ~($try (d_spc1.spc.id_active) $catch ('NullException') (-1) )~"
    editexp = "name_un2=STORE.active_pseudo_unit.obozn"
    dep = "id_un2"
 }
 {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_spc1
      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,
		              spc.id_nds,nds.proc_nds,
                      spc.work_type,
                      spc.id_department,
                      department.name1_dep,
                      work_type.name_type,
                      active_pseudo_unit.obozn
                 from spc,active,nds,department,work_type,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_nds = nds.id_nds
                  and active.id_type_active = 4
                  and spc.id_unit = active_pseudo_unit.id_pseudo_unit 
                  and spc.id_department=department.id_department
                  and spc.work_type = work_type.id_work_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.id_nds=~2~,nds.proc_nds=~18~,
                         spc.price1_spc=~0~,spc.price2_spc=~0~,
                         spc.work_type=~0~,
                         spc.id_department=~($try (d_head.head.id_department1) $catch ('NullException') (-1) )~,
                         department.name1_dep=~($try (d_head.department.name1_dep) $catch ('NullException') (-1) )~,
                         work_type.name_type=~'Установлено'~"
} // ds
} // grid2

// Показатели и статус ТС
{scrollpane
{form width=780 height=208       bg_color="#c0c0c0"   alias = form_ts
   {label
       value="Показатели спидометра"       
       left=11    top=8     height=20       width=170
       font_size=12         font_family=1   bg_color="#c0c0c0"
   } 
   {label
       value="Числовой показатель"       
       left=14    top=33     height=20       width=130
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=repair_leaf.track_vehicle border = box
       left=145     top=33    height=20       width=95
       alias=track_vehicle         font_size=12    font_family=0    bg_color="#ffffff"
       editable=yes editmask = "# #0.00"
   }
   
   {label
       value="Основания к изменению"       
       left=14    top=58     height=20       width=130
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=repair_leaf.track_vehicle_osn border = box 
       left=145     top=58    height=20       width=370
       alias=track_vehicle_osn         font_size=12    font_family=0    bg_color="#ffffff"
       editable=yes
   }

   {label
       value="Статус готовности к коммерческому использованию"       
       left=11    top=83     height=20       width=400
       font_size=12         font_family=1   bg_color="#c0c0c0"
   }

   {radiogroup alias=status_got
        left=14 top=108
        {radiobutton 
            value="0" check=no label="Готов к эксплуатации"
        }
        {radiobutton 
            value="1" check=yes label="Не готов к эксплуатации"
        }
   }


   {datastore 
        alias = d_ts
        query = "select repair_leaf.id_head,
                        repair_leaf.id_repair_leaf,
                        repair_leaf.track_vehicle,
                        repair_leaf.track_vehicle_osn,
                        repair_leaf.status_got,
                        repair_leaf.id_vehicle
                   from repair_leaf
                   where repair_leaf.id_repair_leaf=~($try (d_head.repair_leaf.id_repair_leaf) $catch ('NullException') (-1) )~"
                editable = no
                unique = "('repair_leaf','repair_leaf.id_repair_leaf')"
                default = "repair_leaf.id_repair_leaf=~($try (d_head.repair_leaf.id_repair_leaf) $catch ('NullException') (-1) )~,
                           repair_leaf.id_vehicle=~($try (d_head.repair_leaf.id_vehicle) $catch ('NullException') (-1) )~,
                           repair_leaf.id_head=~($try ($if (global.create == 0)
                                  	    	(ARGUMENTS.0)
	                                       $else (ds.hpk))
		                         $catch ('any') (-1))~,
                           repair_leaf.track_vehicle=~0~,
                           repair_leaf.status_got=~1~"
} // ds

} // end form
} // end scrollpane

 // Повреждения
{grid
alias=GRIDDAM
buttonbar_font_family = 0
buttonbar_font_size = 12
buttonbar_size = 30
titlebar_size = 18
rowsize = 20
editable = yes
del = "~($X 
          ($if (($g.self@sure 'Вы дествительно хотите удалить повреждение ' + d_damage.damage_vehicle.id_damage@int + '?'  0) == 1)
            (
             ($g.d_damage@DelRow ($g.d_damage@GetCurRow))
             ($g.self@actsave)
             ($g.d_damage@NotifyViews)
            )
          )
          ($ret '') 
        )~"
{menu        
    {item label="Добавить"
     exp="($X
             ($g.d_damage@newrow)
             ($g.d_damage@notifyviews)
             ($ret '')
           )"
    }
 }
  
 {column size=100
    title="Код повреждения"              font_family=0           editable = readonly 
    target=damage_vehicle.id_damage     title_font_family=2     halignment=left
    alias=id_damage                font_color="#000000"    font_size=12   visible=no
 }
 {column size=200      title="Наименование повреждения"
    target=damage_vehicle.name_damage  title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=name_damage              
 }
 {column size=120       title="Дата регистрации"
    target=damage_vehicle.date_damage title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias=date_damage               
 }
 {datastore 
      alias = d_damage
      query = "select damage_vehicle.id_damage, 
                      damage_vehicle.name_damage,
                      damage_vehicle.date_damage,
                      damage_vehicle.id_vehicle,
                      damage_vehicle.id_repair_leaf
                 from damage_vehicle
                where damage_vehicle.id_vehicle = ~($try (d_head.repair_leaf.id_vehicle) $catch ('NullException') (-1) )~
                      and damage_vehicle.id_repair_leaf = ~($try (d_head.repair_leaf.id_repair_leaf) $catch ('NullException') (-1) )~
             order by damage_vehicle.id_damage"
             editable = yes
               unique = "('damage_vehicle','damage_vehicle.id_damage')" 
              default = "damage_vehicle.id_damage=~($X
                                                      ($g.damsq@retrieve)
                                                      ($ret ($g.damsq@getValue 'DAMAGE_SQ.NEXTVAL'))
                                                   )~,
                         damage_vehicle.date_damage=~($X
                                                      ($if (($g.cur_date@size) < 1)
                                                        ($g.cur_date@retrieve)
                                                      )
                                                      ($ret ($g.cur_date@getValue 'SYSDATE'))
                                                   )~,
                         damage_vehicle.id_vehicle=~($try (d_head.repair_leaf.id_vehicle) $catch ('NullException') (-1) )~,
                         damage_vehicle.id_repair_leaf = ~($try (d_head.repair_leaf.id_repair_leaf) $catch ('NullException') (-1) )~"
} // ds

} // grid3

// Порожденные документы
{grid
alias=GRIDDOC
buttonbar_font_family = 0
buttonbar_font_size = 12
buttonbar_size = 30
titlebar_size = 18
rowsize = 20
editable = no
edit = "open docs/~($G.DSDOC@getValue 'DOC_NAME' )~ ~($G.DSDOC@getValue 'H1_ID_HEAD' )~ ;retrieve gridds01"
del = "~($X
					($if (($G.DSDOC@getValue 'H1_ACCEPT') == 1)(
						($g.self@sure 'Нельзя удалять проведенный документ!' 1)
						($ret 'NOTDELETE')
						)
					)
               (tmp = 'Вы действительно хотите удалить документ №' + ($G.DSDOC@getValue 'H1_NUM_SD' ) + '')
               (m = ($g.self@sure tmp 0))
               ($if (m == 0)
                   ($ret 'NOTDELETE')
               )
               ($g.self@doAction 'execute exec util.del_doc(' + ($G.DSDOC@getValue 'H1_ID_HEAD' ) + '); retrieve griddoc')
            ($ret 'NOTDELETE'))~ ;retrieve griddoc"
	{menu
		{item label = "Удалить"
           action = "~($X
					($if (($G.DSDOC@getValue 'H1_ACCEPT') == 1)(
						($g.self@sure 'Нельзя удалять проведенный документ!' 1)
						($ret 'NOTDELETE')
						)
					)
               (tmp = 'Вы действительно хотите удалить документ №' + ($G.DSDOC@getValue 'H1_NUM_SD' ) + '')
               (m = ($g.self@sure tmp 0))
               ($if (m == 0)
                   ($ret 'NOTDELETE')
               )
               ($g.self@doAction 'execute exec util.del_doc(' + ($G.DSDOC@getValue 'H1_ID_HEAD' ) + '); retrieve griddoc')
            ($ret 'NOTDELETE'))~ ;retrieve griddoc"
        }
        {item label = "-"}
        {item label = "Провести документ" action= "execute exec ~'doc_lib.accept('+($G.DSDOC@getValue 'H1_ID_HEAD' )+')'~ ;retrieve griddoc" }        
        {item label = "Отменить проведение документа" action= "execute exec ~'doc_lib.de_accept('+($G.DSDOC@getValue 'H1_ID_HEAD' )+')'~ ;retrieve griddoc" }
	}
   {column size=30             title="X"
        target=h1_accept
        title_font_family=2
        title_font_color="#000000"
        halignment=center
        font_size = 12     
   }
   {column size=80             title="N док."
        target=h1_num_sd        title_font_family=2     title_font_color="#000000"
        halignment=left            font_color="#000000"     
        font_size = 12             font_family=0
   }
   {column size=100             title="Дата док."
        target=h1_date_sd       title_font_family=2     title_font_color="#000000"
        halignment=center          font_size = 12          font_family=0
   }
   {datastore 
           alias = DSDOC
           query = "select h1_id_head, h1_num_sd, h1_date_sd, h1_accept, doc_name from 
			(select head.id_head h1_id_head, head.num_sd h1_num_sd,head.date_sd h1_date_sd,head.accept h1_accept,type_doc.doc_name
                      from head, type_doc
		      where head.parent_id_head = ~($G.D_HEAD@getValue 'HEAD.ID_HEAD')~
		      and head.id_type_doc = type_doc.id_type_doc)"
             editable = no
} // ds
} // grid3

} // 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
                 (

                    #Проверяем всё ли заполнено в повреждениях
                    (v = ($@validator))
                    ($v@SetType 'NUMBER')
                    ($v@SetMask '##0.')
                    (t = ($g.d_damage@iterator))
                    (i = 0)
                    ($while ($t@next)
                    (
                        (i += 1)
                        ($g.d_damage@SetCurRow (i-1))

                        #Проверяем все ли поля заполнены
                        ($if (($try ($g.d_damage@GetValue 'DAMAGE_VEHICLE.NAME_DAMAGE') $catch ('Any')(0)) == 0)
                              (
                                ($g.self@sure 'В строке ' + ($v@ToString i) + ' пустое поле наименования поврежения.' 1)
                                ($ret '')
                              )
                         )                           
                       )
                    )
                    d_head.repair_leaf.status_got = ($try (($g.status_got@GetValue)) $catch ('NullException') (-1) )
                    d_head.repair_leaf.track_vehicle = ($try ((g.track_vehicle)) $catch ('NullException') (-1) )
                    d_head.repair_leaf.track_vehicle_osn = ($try ((g.track_vehicle_osn)) $catch ('NullException') ('') )

                    ($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 = "($X
	        ($if (($G.D_HEAD@getValue 'HEAD.ACCEPT') == 1)
		  (
		    ($g.self@actcancel)
		    ($ret '')
		  )
	        )
                #Проверяем всё ли заполнено в повреждениях
                    (v = ($@validator))
                    ($v@SetType 'NUMBER')
                    ($v@SetMask '##0.')
                    (t = ($g.d_damage@iterator))
                    (i = 0)
                    ($while ($t@next)
                    (
                        (i += 1)
                        ($g.d_damage@SetCurRow (i-1))

                        #Проверяем все ли поля заполнены
                        ($if (($try ($g.d_damage@GetValue 'DAMAGE_VEHICLE.NAME_DAMAGE') $catch ('Any')(0)) == 0)
                              (
                                ($g.self@sure 'В строке ' + ($v@ToString i) + ' пустое поле наименования поврежения.' 1)
                                ($ret '')
                              )
                         )                           
                       )
                    )
                    d_head.repair_leaf.status_got = ($try (($g.status_got@GetValue)) $catch ('NullException') (-1) )
                    d_head.repair_leaf.track_vehicle = ($try ((g.track_vehicle)) $catch ('NullException') (-1) )
                    d_head.repair_leaf.track_vehicle_osn = ($try ((g.track_vehicle_osn)) $catch ('NullException') ('') )

                    ($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

