UPDATE [dbo].[S_EOD_TEMPLATES] 
    SET	[TEMPLATE_IMAGE] = '<?xml version="1.0" encoding="windows-1251" ?>

<transform xmlns="urn:keysystems:eod:transform" xmlns:b="urn:keysystems:budget:eod:transform">

  <!-- FK -->
  <caption-table name="FK" format-ver="NUM_VER" soft-name="FORMER" soft-ver="FORM_VER"/>

  <!-- FROM -->
  <clone-table source="head" name="FROM" direction="export">
    <child-relation name="TempRelation_FROM_ZS" column="link" child-table="head" child-column="link"/>

    <move>
      <document>
        <b:budget-level link="bcorr"/>
      </document>
      <file field="BUDG_LEVEL"/>
    </move>

    <move>
      <document>
        <b:dictionary-first name="DICTIONARY_USER" dict-field="CORR_NAME" open-code="CODE"/>
      </document>
      <file field="KOD_UBP, NAME_UBP"/>
    </move>

  </clone-table>


  <!-- TO -->
  <clone-table source="head" name="TO" direction="export">
    <child-relation name="TempRelation_TO_ZS" column="link" child-table="head" child-column="link"/>

    <rename-column document="ate1_code" file="KOD_TOFK"/>
    <rename-column document="ate1_n" file="NAME_TOFK"/>

  </clone-table>


  <!-- ZS -->
  <rename-table document="head" file="ZS">
    <rename-column document="number" file="NOM_ZVK"/>
    <rename-column document="date" file="DATE_ZVK"/>
    <rename-column document="date_max" file="DATE_LIM"/>
    <rename-column document="boss_dol" file="DOL_RUK"/>
    <rename-column document="boss" file="NAME_RUK"/>
    <rename-column document="buh_dol" file="DOL_BUH"/>
    <rename-column document="buh_fio" file="NAME_BUH"/>
    <rename-column document="date_sign" file="DATE_POD"/>
    <rename-column document="worker_dol" file="DOL_ISP_DOV"/>
    <rename-column document="worker" file="NAME_ISP_DOV"/>
    <rename-column document="doc_name" file="NAME_DOV"/>
    <rename-column document="doc_number" file="NOM_DOC"/>
    <rename-column document="doc_iwho" file="ORG_DOC"/>
    <rename-column document="doc_idate" file="DATE_DOC"/>

 
    <move>
      <document>
        <b:dictionary name="DICTIONARY_BUDJET_EXP" open-code="" dict-field="BUDJET_NAME, CORR_NAME" field="bcorr"/>
      </document>
      <file field="NAME_BUD, NAME_UBP_FO"/>
    </move>

    <move direction="export">
      <document>
        <coalesce>
          <b:dictionary name="DICTIONARY_CORR_MAIN_GRBS_EOD" open-code="" dict-field="TOP_DEP, TOP_NAME" field="corr1"/>
          <b:dictionary name="DICTIONARY_CORR" open-code="" dict-field="CDEP, CORR_NAME" field="corr1"/>
        </coalesce>
      </document>
      <file field="GLAVA_GRBS, NAME_GRBS"/>
    </move>

    <move>
      <document>
        <b:correspondent link="corr1">
          <b:account group-link="account1"/>
        </b:correspondent>
      </document>
      <file>
        <b:correspondent code-bp="KOD_UBP_PAY" name-bp="NAME_UBP_PAY">
          <b:account ls="LS_PAY"/>
        </b:correspondent>
      </file>
    </move>

    <move direction="export">
      <document field="KOD_UBP_PAY, NAME_UBP_PAY"/>
      <file>
        <parent-row table="FROM">
          <field name="KOD_UBP, NAME_UBP"/>
        </parent-row>
      </file>
    </move>


    <move direction="export">
      <document>
        <b:budget-level link="bcorr"/>
      </document>
      <file field="BUDG_LEVEL"/>
    </move>

    <move direction="export">
      <document>
        <expression text="''''"/>
      </document>
      <file>
        <switch test="Row[''BUDG_LEVEL'']==''1''">
          <case value="False" field="KOD_UBP_PAY"/>
        </switch>
      </file>
    </move>


    <move>
      <document>
        <b:dictionary name="DICTIONARY_CORR_ORFK" open-code="CODE_ORFK" dict-field="CORR_NAME" field="ate1"/>
      </document>
      <file field="KOD_TOFK_PAY, NAME_TOFK_PAY"/>
    </move>

    <move>
      <document>
        <b:dictionary name="DICTIONARY_DOC_98N" open-code="number" field="bo1"/>
      </document>
      <file field="NOM_BO"/>
    </move>

    <move>
      <document>
        <sum column="ROWS.summa" mode="child-rows"/>
      </document>
      <file field="SUM_ITOG"/>
    </move>

  </rename-table>


  <!-- ZSCH1 -->
  <rename-table document="check" file="ZSCH1">
    <rename-column document="check_symb" file="CHECK_KAS"/>
    <rename-column document="check_sum" file="SUMR_ZVK"/>
    
    <move direction="export">
      <document>
        <switch test="Row[''SUMR_ZVK''] == DBNull">
          <case value="True">
            <expression text="0.00"/>
          </case>
        </switch>
      </document>
      <file field="SUMR_ZVK"/>
    </move>
    
    <move>
      <document>
        <parent-row table="head">
          <field name="check_num"/>
        </parent-row>
      </document>
      <file field="CHECK_NOM"/>
    </move>

    <move>
      <document>
        <parent-row table="head">
          <field name="check_ser"/>
        </parent-row>
      </document>
      <file field="CHECK_SER"/>
    </move>

    <move>
      <document>
        <parent-row table="head">
          <field name="check_date"/>
        </parent-row>
      </document>
      <file field="DATE_CHECK"/>
    </move>

    <move>
      <document>
        <parent-row table="head">
          <field name="check_ldate"/>
        </parent-row>
      </document>
      <file field="DATE_CHECK_LIM"/>
    </move>

  </rename-table>

  <!-- ZSCH2 -->
  <rename-table document="ROWS" file="ZSCH2">

    <rename-column document="summa" file="SUMR_KBK"/>
    <rename-column document="note1" file="PURPOSE"/>
    <rename-column document="note2" file="NOTE"/>

    <move>
      <document>
        <b:dictionary name="DICTIONARY_ACCOUNT_SUMKIND" open-code="id" field="sumkind"/>
      </document>
      <file field="KOD_IST"/>
    </move>

    <move direction="import">
      <document field="LOCAL"/>
      <file>
        <expression text="Row[''NOTE''].split('' '')[0].split(''='')[1]"/>
      </file>
    </move>

    <move direction="import">
      <document field="NOTE"/>
      <file>
        <expression text="'''' if len(Row[''NOTE''].split('' '')) &lt;= 1 else Row[''NOTE''].split('' '')[1]"/>
      </file>
    </move>

    <move>
      <document>
        <b:kbk link-dep="dep" link-div="div" link-exp="exp" link-inc="inc" link-item="item" 
               link-src="src" link-tgt="tgt" link-addbk="add_bk" link-local="lcl"/>
      </document>
      <file>
        <b:kbk type-kbk="TYPE_KBK" kbk="KBK" addbk="ADD_KLASS" local="LOCAL"/>
      </file>
    </move>
  </rename-table>

</transform>'
	WHERE [CODE] = 'FK-TXZS090101_trns.xml'

GO


