Cp1251
DOC 
foreground = lightgray
document_width = 1100
document_height = 900
document_title = "План производства"
style = "style/docs.st"
preloadscript="
(global.id_head = -1000000)
(global.create = 0)
(global.get_num = 0)
(global.cur_id_active = -1)
(global.no_combo_action = 0)
"
postloadscript="($X
	 	 ($IF (($g.D_HEAD@getvalue 'HEAD.ACCEPT') == 1)
		  ($g.progress@setValue 'Только для чтения')
		 )
		 ($if (global.create == 1)
		   (
		     # если вызвали пунктом меню Копировать, заполняем данными из копируемого документа
		     (global.id_head = ($try (ARGUMENTS.0) $catch ('Any')(-1000000)))
		     ($g.copy_doc@retrieve)
      		     (sz = ($g.copy_doc@size))
		     ($if (sz > 0)
		       (
			     (g.sklad = ($g.copy_doc@getValue 'department.name1_dep'))
			     (g.sklad_t = ($g.copy_doc@getValue 'head.id_department1'))
			     (g.comment_sd = ($try ($g.copy_doc@getValue 'head.comment_sd') $catch ('NullException')('')))
         		     (i = 0)
         		     (sz = ($g.copy_doc@size))
         		     ($while (i < sz)
         		       (
         		         ($g.copy_doc@setCurRow i)
         		         ($g.d_spc@newRow)
         		         ($g.d_spc@setValue 'spc.id_active' ($g.copy_doc@getValue 'spc.id_active'))
         		         ($g.d_spc@setValue 'active.name_active' ($g.copy_doc@getValue 'active.name_active'))
         		         ($g.d_spc@setValue 'spc.id_unit' ($g.copy_doc@getValue 'spc.id_unit'))
         		         ($g.d_spc@setValue 'active_pseudo_unit.obozn' ($g.copy_doc@getValue 'active_pseudo_unit.obozn'))
         		         ($g.d_spc@setValue 'spc.q1_spc' ($g.copy_doc@getValue 'spc.q1_spc'))
         		         ($g.d_spc@setValue 'spc.price1_spc' ($g.copy_doc@getValue 'spc.price1_spc'))
                                 ($g.d_spc@setValue 'spc.work_type' ($g.copy_doc@getValue 'spc.work_type'))
                                 ($g.d_spc@setValue 'work_stage.name_work_stage' ($g.copy_doc@getValue 'work_stage.name_work_stage'))
         		         (i += 1)
         		       )
         		     )
         		     ($g.d_spc@notifyViews)
         	       )
         	     )
		   )
		 )

                 ($g.self@doAction 'retrieve combo1')

		 ($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)"
}
{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=defaults
    query="select active_type.name_type, work_stage.id_work_stage, work_stage.name_work_stage
             from active,active_type,work_stage
            where active.id_active = ~global.cur_id_active~
              and active.id_type_active = active_type.id_type
              and work_stage.id_work_stage = 1"
} // end of ds
{datastore  alias=copy_doc
    query="select head.id_department1, department.name1_dep, head.comment_sd,
                  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,
                  spc.work_type, work_stage.name_work_stage
             from head, spc, active, active_pseudo_unit, active_type, department, work_stage
            where head.id_head = spc.id_head
              and head.id_head = ~global.id_head~
              and head.id_department1 = department.id_department 
              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
              and spc.work_type = work_stage.id_work_stage (+)"
} // end of ds
{datastore  alias=check_spec
    query="select id_head, comment_sd
             from head
            where head.id_type_doc = 10
              and head.id_active = ~global.cur_id_active~
              and head.accept = 3"
} // end of ds


{toolbar   BACKGROUND = "LIGHTGRAY"
{splitpanel   percent=20
{form
   {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=40
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=head.id_department1
       visible=no           border = box
       left=350    top=8    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=350    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=10  top=90      height=20       width=70
       font_size=12         font_family=0   bg_color="#c0c0c0"
   }
   {field
       target=personal.fname                border = box
       left=80    top=90    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.comment_sd   border = box
       left=80    top=33    height=20      width=470
       alias=comment_sd         font_size=12   font_family=0    bg_color="#ffffff"
   }

  { label left = 10 top = 60 width = 110 height = 20 font_size = 12 value = "Этап производства" }

     {combobox
      left = 120     top = 60      width = 150        height = 20
      alias = combo1               border = box
      target = work_stage_plan.name_work_stage
      action = "~($X
                  ($debug 'combo1')
                  ($if (global.no_combo_action == 0)
                    (
                      ($g.data_ds1@setCurRow ($g.combo1@getSelectedIndex))
                      ($debug 'combo1, index: ' + ($g.combo1@getSelectedIndex) + ', value: ' ($g.data_ds1@getValue 'work_stage_plan.name_work_stage'))
                    )
                  )
                  ($ret '')
                )~"

      {datastore
       alias = data_ds1
       query = "select work_stage_plan.id_work_stage, work_stage_plan.name_work_stage
                      from work_stage_plan
                     order by work_stage_plan.id_work_stage"
      }
   }

   {button
     left = 280 top = 60 width = 150 height = 25 font_size = 12
      label="Установить этап"
     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.work_type' ($g.data_ds1@getValue 'work_stage_plan.id_work_stage'))
                                  ($g.d_spc@setValue 'work_stage_plan.name_work_stage' ($g.data_ds1@getValue 'work_stage_plan.name_work_stage'))
                                )
                              )
                              (j += 1)
                            )
                          )
                          (i += 1)
                        )
                      )
                      ($g.d_spc@fastSetCurRow row)
                      ($g.d_spc@notifyViews)
                     )
                    $else
                      ($debug '********* no selection')
                   )
   		(ret '')
              )"
   }



   {label
    alias=progress
    left = 10  top = 120      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.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_personal,personal.fname,
			head.parent_id_head
                   from head,personal,department
                  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"
              editable = yes
                  head = yes
                unique = "('head','head.id_head')"
               default = "head.id_head=~ds.hpk~,head.id_type_doc=~14~,
                          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~"
} // 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=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) 
          (
            (global.cur_id_active = store.active.id_active)
            ($g.check_spec@retrieve)
            ($if (($g.check_spec@size) == 0)
              (
                ($g.self@sure 'У этой продукции нет спецификации.' 1)
                ($g.d_spc@delRow (($g.d_spc@size) - 1))
              )
             $else
              (
                (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)
                ($g.defaults@retrieve)
                (g.name__work_stage=($g.data_ds1@getValue 'work_stage_plan.name_work_stage'))
                (g.id__work_stage=($g.data_ds1@getValue 'work_stage_plan.id_work_stage'))
                (g.column_comment = ($g.check_spec@getValue 'comment_sd'))

              )
            )
          )
        ) # if (is_in == 1) 
        ($g.d_spc@notifyViews)

        ($ret '')
       )"
{menu
   {item label = "Поиск в справочнике" action="opennew find_choose.rml 1, 0"}
   {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=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=60     
    visible=no
    title="work_type"              font_family=0
    target=spc.work_type       title_font_family=2     halignment=left
    alias=id__work_stage                font_color="#000000"     font_size=12   
    editexp = "id__work_stage=STORE.work_stage_plan.id_work_stage"
 }
 {column size=80       title="Этап"
    target=work_stage_plan.name_work_stage
    title_font_family=2     halignment=left
    font_color="#000000"      font_size=12              font_family=0
    alias = name__work_stage
    editable = handbook
    edit = "opennew sprav/sprav_work_stages_plan_readonly.rml"
    editexp = "name__work_stage=STORE.work_stage_plan.name_work_stage"
    dep = "id__work_stage"
 }
 {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=50       title="Ед.изм."
    target=active_pseudo_unit.obozn  title_font_family=2     halignment=center
    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=60       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
 }
 {column size=200
    target = spc.comments   title="Примечание"      title_font_family=2
    font_color="#000000"     font_size=12            font_family=0
    halignment=left
    alias = column_comment
 }
 {datastore 
      alias = d_spc
      query = "select spc.id_spc,spc.id_head,spc.id_active,spc.id_unit,
                      spc.q1_spc, spc.q2_spc, spc.q3_spc, spc.q4_spc, spc.q5_spc,
                      spc.price1_spc,spc.price2_spc,
                      active.name_active,active_pseudo_unit.obozn,active_type.name_type,
                      spc.work_type, work_stage_plan.name_work_stage, spc.comments
                 from spc,active,active_pseudo_unit,active_type, work_stage_plan
                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.work_type = work_stage_plan.id_work_stage (+)
                  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
	     ($if (($G.D_HEAD@getValue 'HEAD.ACCEPT') == 1)
		  (
		    ($g.self@actcancel)
		    ($ret '')
		  )
	     )
             ($if (($try (g.sklad_t) $catch ('NullException')(0)) == 0)
               (
                 ($g.self@sure 'Не указан склад.' 1)
                 ($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 (($try (g.sklad_t) $catch ('NullException')(0)) == 0)
	      (
	        ($g.self@sure 'Не указан склад.' 1)
	        ($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)
            #($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

