-- View: fies.v_entity_attributes


-- DROP VIEW v_entity_attributes;

CREATE OR REPLACE VIEW v_entity_attributes AS
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 900 + t1.sectionlevel AS index,
    1 AS attributetype,
    t1.sectionalias AS name,
    t1.name AS description,
        CASE
            WHEN t3.entname IS NOT NULL THEN (t3.schema::text || '.'::text) || t3.entname::text
            ELSE NULL::text
        END AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
        CASE
            WHEN t2.entname::text = 'PLAN_ITEM'::text THEN true
            ELSE false
        END AS isrequired,
    1 AS mappingtype,
    t1.sectionalias AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    NULL::character varying AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    (900 + (( SELECT max(t_plan_section.sectionlevel) + 1
           FROM fies.t_plan_section)) - t1.sectionlevel) * '-1'::integer AS attributeid
   FROM fies.t_plan_section t1
     JOIN vclib.t_entities t2 ON t2.entname::text = ANY (ARRAY['PLAN_ITEM'::character varying::text, 'PLAN_ITEM_LIMITS'::character varying::text, 'SECTION_DEPEND_SETTINGS'::character varying::text, 'SMO_COEF_MONTH_VALUES'::character varying::text, 'FACT_ITEM'::character varying::text, 'MEETING_RESOLVE'::character varying::text, 'SPLIT_SETTINGS'::character varying::text, 'FACT_ITEM_SUM'::character varying::text, 'EXTERNAL_PLAN_SUM'::character varying::text, 'COEFFICENT_STATINFO'::character varying::text, 'BASE_TARIFF'::character varying::text, 'MO_PARAMETER_ITEM'::character varying::text, 'TP_FIN_CLOSE_ITEM'::character varying::text, 'TP_TYPE'::character varying::text, 'PLAN_FACT_STATISTICS'::character varying::text])
     LEFT JOIN vclib.t_entities t3 ON t3.entityid = t1.entities
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 900 + t1.priority AS index,
    0 AS attributetype,
    t1.periodalias AS name,
    t1.name AS description,
    'float'::text AS systemtype,
    NULL::integer AS maxlength,
    20 AS "precision",
    6 AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    true AS isrequired,
    1 AS mappingtype,
    t1.periodalias AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    NULL::character varying AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    (900 + (( SELECT max(t_period_section.priority) + 1
           FROM fies.t_period_section)) - t1.priority) * '-1'::integer AS attributeid
   FROM fies.t_period_section t1
     JOIN vclib.t_entities t2 ON t2.entname::text = 'MONTH_VALUES'::text
  WHERE t1.periodsection IS NULL
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 920 + t1.parametrorder AS index,
        CASE
            WHEN t1.dependtype = 0 THEN 1
            ELSE 0
        END AS attributetype,
    t1.parameteralias AS name,
    t1.name AS description,
        CASE
            WHEN t1.dependtype = 0 THEN 'FIES.PLAN_VALUE'::text
            ELSE 'float'::text
        END AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(3) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
        CASE
            WHEN t1.dependtype = 0 THEN ((('<lx:ChildCount xmlns:lx="lexem">
    <condition>
        <lx:Criterion type="=">
            <lx:Path OwnerQueryLevel="0">
                <lx:StepInt index="5440002" />
                <lx:StepInt index="5420001" />
            </lx:Path>
            <lx:ConstOperand type="Guid">'::text || t1.payparametrid::character varying(40)::text) || '</lx:ConstOperand>
        </lx:Criterion>
    </condition>
    <lx:Path OwnerQueryLevel="0">
        <lx:StepInt index="5410003" />
    </lx:Path>
    <lx:First>
        <lx:Path OwnerQueryLevel="0">
        <lx:StepCurrent />
    </lx:Path>
    </lx:First>
</lx:ChildCount>'::text)::character varying)::text
            ELSE t1.parameterlexem
        END AS attrlexem,
        CASE
            WHEN t1.dependtype = 0 THEN '{5410003}'::character varying
            ELSE NULL::character varying(255)
        END AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    (920 + (( SELECT max(t_plan_parameter.parametrorder) + 1
           FROM fies.t_plan_parameter)) - t1.parametrorder) * '-1'::integer AS attributeid
   FROM fies.t_plan_parameter t1
     JOIN vclib.t_entities t2 ON t2.entname::text = 'PLAN_ITEM'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 1000 + (t3.displayorder * 10 + t1.parametrorder) AS index,
    1 AS attributetype,
    t3.typealias::text || t1.groupalias::text AS name,
    ((t1.name::text || ' ('::text) || t3.name::text) || ')'::text AS description,
    'FIES.LIMIT_VALUE'::text AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(3) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    (((('<lx:QueryValue entity="FIES.LIMIT_VALUE" top="1" xmlns:lx="lexem">
    <condition>
        <lx:Criteria type="And">
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5470002" />
                    <lx:StepInt index="5460001" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5460001" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5470006" />
                    <lx:StepInt index="5520001" />
                </lx:Path>
                <lx:ConstOperand type="Guid">'::text || t1.parametergroupid::character varying(36)::text) || '</lx:ConstOperand>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5470005" />
                    <lx:StepInt index="5510001" />
                </lx:Path>
                <lx:ConstOperand type="Guid">'::text) || t3.planlimittypeid::character varying(36)::text) || '</lx:ConstOperand>
            </lx:Criterion>
        </lx:Criteria>
    </condition>
    <value>
        <lx:Path OwnerQueryLevel="0">
            <lx:StepInt index="5470001" />
        </lx:Path>
    </value>
</lx:QueryValue>'::text)::character varying AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    (1000 + (( SELECT max(t_plan_limit_type.displayorder * 10 + t_parameter_group.parametrorder) + 1
           FROM fies.t_plan_limit_type,
            fies.t_parameter_group)) - (t3.displayorder * 10 + t1.parametrorder)) * '-1'::integer AS attributeid
   FROM fies.t_parameter_group t1,
    vclib.t_entities t2,
    fies.t_plan_limit_type t3
  WHERE t2.entname::text = 'PLAN_ITEM_LIMITS'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 888 AS index,
    1 AS attributetype,
    'ActualPlanItem'::character varying AS name,
    'Действующая запись плана'::character varying AS description,
    (t2.schema::text || '.'::text) || t2.entname::text AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ('<lx:QueryValue entity="FIES.PLAN_ITEM" top="1"  xmlns:lx="lexem">
  <condition>
    <lx:Criteria type="And">
      <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Plan" />
                    <lx:StepString name="PlanPeriod" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="Plan" />
                    <lx:StepString name="PlanPeriod" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Mo" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="Mo" />
                </lx:Path>
            </lx:Criterion>'::text || (( SELECT string_agg(((('<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepInt index="'::text || ((t2_1.entityid * 10000 + 900 + t1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepInt index="'::text) || ((t2_1.entityid * 10000 + 900 + t1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
              </lx:Criterion>'::text, ''::text) AS string_agg
           FROM fies.t_plan_section t1
             JOIN vclib.t_entities t2_1 ON t2_1.entname::text = 'PLAN_ITEM'::text
             LEFT JOIN vclib.t_entities t3 ON t3.entityid = t1.entities))) || '<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Approved" />
                </lx:Path>
                <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
            </lx:Criterion>
            <lx:Criterion type="&lt;">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Plan" />
                    <lx:StepAs as="FIES.PLAN_REQUEST" />
                    <lx:StepString name="RequestTime" />
                </lx:Path>
                    <lx:Argument>
                        <lx:ConstOperand type="Int32">0</lx:ConstOperand>
                    </lx:Argument>
            </lx:Criterion>
    </lx:Criteria>
  </condition>
  <orderBy>
    <lx:Path OwnerQueryLevel="0">
      <lx:StepString name="Plan" />
      <lx:StepAs as="FIES.PLAN_REQUEST" />
      <lx:StepString name="RequestTime" />
    </lx:Path>
    <desc>True</desc>
    <lx:Path OwnerQueryLevel="0">
        <lx:StepString name="PlanItemID" />
    </lx:Path>
    <desc>False</desc>
  </orderBy>
  <value>
    <lx:Path OwnerQueryLevel="0">
      <lx:StepString name="PlanItemID" />
    </lx:Path>
  </value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    '<?xml version="1.0" encoding="utf-16"?><Parameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Parameter Name="OnDate" Description="На дату" Type="datetime"><lx:ParamHolder xmlns:lx="lexem"><lx:StepString name="CURRENT_DATETIME" /></lx:ParamHolder></Parameter></Parameters>'::character varying AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    888 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'PLAN_ITEM'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 889 AS index,
    1 AS attributetype,
    'PrevPlanItem'::character varying AS name,
    'Предыдущая запись плана'::character varying AS description,
    (t2.schema::text || '.'::text) || t2.entname::text AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ('<lx:QueryValue entity="FIES.PLAN_ITEM" top="1"  xmlns:lx="lexem">
  <condition>
    <lx:Criteria type="And">
      <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Plan" />
                    <lx:StepString name="PlanPeriod" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="Plan" />
                    <lx:StepString name="PlanPeriod" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Mo" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="Mo" />
                </lx:Path>
            </lx:Criterion>'::text || (( SELECT string_agg(((('<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                  <lx:StepInt index="'::text || ((t2_1.entityid * 10000 + 900 + t1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                  <lx:StepInt index="'::text) || ((t2_1.entityid * 10000 + 900 + t1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
              </lx:Criterion>'::text, ''::text) AS string_agg
           FROM fies.t_plan_section t1
             JOIN vclib.t_entities t2_1 ON t2_1.entname::text = 'PLAN_ITEM'::text
             LEFT JOIN vclib.t_entities t3 ON t3.entityid = t1.entities))) || '<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepString name="Approved" />
                </lx:Path>
                <lx:ConstOperand type="Boolean">True</lx:ConstOperand>
            </lx:Criterion>
      <lx:Criterion type="&lt;">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5410002" />
                    <lx:StepAs as="FIES.PLAN_REQUEST" />
                    <lx:StepInt index="5400006" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5410002" />
                    <lx:StepAs as="FIES.PLAN_REQUEST" />
                    <lx:StepInt index="5400006" />
                </lx:Path>
        </lx:Criterion>
    </lx:Criteria>
  </condition>
  <orderBy>
    <lx:Path OwnerQueryLevel="0">
      <lx:StepInt index="5410002" />
      <lx:StepAs as="FIES.PLAN_REQUEST" />
      <lx:StepInt index="5400006" />
    </lx:Path>
    <desc>True</desc>
    <lx:Path OwnerQueryLevel="0">
        <lx:StepInt index="5410001" />
    </lx:Path>
    <desc>False</desc>
  </orderBy>
  <value>
    <lx:Path OwnerQueryLevel="0">
      <lx:StepInt index="5410001" />
    </lx:Path>
  </value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    889 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'PLAN_ITEM'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 900 AS index,
    1 AS attributetype,
    'Subprogramm'::character varying AS name,
    'Подпрограмма'::character varying AS description,
    'FIES.SUBPROGRAMM'::text AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
        CASE
            WHEN (( SELECT count(*) AS count
               FROM fies.t_subprogramm)) = 0 THEN '<lx:ConstOperand isNull="1" xmlns:lx="lexem" />'::text
            ELSE ('<lx:QueryValue entity="FIES.SUBPROGRAMM" top="1"  xmlns:lx="lexem">
        <condition>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5720001" />
                </lx:Path>
                <lx:Case>'::text || (((( SELECT string_agg(((((('<When xmlns:lx="lexem">
                        '::text || replace(regexp_replace(t1.condition::character varying::text, '<lx:BaseObjectOperand Entity="[A-z]*\..+" PrimaryKey="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"\s*\/>'::text, '<lx:ConstOperand type="Guid">\1</lx:ConstOperand>'::text, 'g'::text), '<lx:Path OwnerQueryLevel="0">'::text, '<lx:Path OwnerQueryLevel="1">'::text)) || '
                    </When>
                    <Then xmlns:lx="lexem">
                        <lx:ConstOperand type="Guid">'::text) || t1.subprogrammid::character varying::text) || '</lx:ConstOperand>
                    </Then>'::text)::character varying)::text, ''::text) AS string_agg
               FROM fies.t_subprogramm t1
               /*ORDER BY t1.priority*/))::character varying)::text)) || '            <Else>
                        <lx:ConstOperand isNull="1" />
                    </Else>
                </lx:Case>
            </lx:Criterion>
        </condition>
        <value>
            <lx:Path OwnerQueryLevel="0">
                <lx:StepInt index="5720001" />
            </lx:Path>
        </value>
    </lx:QueryValue>'::text
        END AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    900 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'PLAN_VALUE'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 901 AS index,
    0 AS attributetype,
    'SubprogrammID'::character varying AS name,
    'Подпрограмма(ID)'::character varying AS description,
    'guid'::text AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
        CASE
            WHEN (( SELECT count(*) AS count
               FROM fies.t_subprogramm)) = 0 THEN '<lx:ConstOperand isNull="1" xmlns:lx="lexem" />'::text
            ELSE ('<lx:Case  xmlns:lx="lexem">'::text || (((( SELECT string_agg(((((('<When xmlns:lx="lexem">
                        '::text || regexp_replace(t1.condition::character varying::text, '<lx:BaseObjectOperand Entity="[A-z]*\..+" PrimaryKey="([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})"\s*\/>'::text, '<lx:ConstOperand type="Guid">\1</lx:ConstOperand>'::text, 'g'::text)) || '
                    </When>
                    <Then xmlns:lx="lexem">
                        <lx:ConstOperand type="Guid">'::text) || t1.subprogrammid::character varying::text) || '</lx:ConstOperand>
                    </Then>'::text)::character varying)::text, ''::text) AS string_agg
               FROM fies.t_subprogramm t1))::character varying)::text)) || '            <Else>
                        <lx:ConstOperand isNull="1" />
                    </Else>
                </lx:Case>'::text
        END AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    901 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'PLAN_VALUE'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 950 + t1.priority AS index,
    0 AS attributetype,
    t1.periodalias::text || '_FACT'::text AS name,
    t1.name::text || ' (Факт)'::text AS description,
    'float'::text AS systemtype,
    NULL::integer AS maxlength,
    20 AS "precision",
    6 AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ((('<lx:QueryValue entity="FIES.FACT_ITEM" top="1" xmlns:lx="lexem">
    <condition>
        <lx:Criteria type="And">
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360007" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5450001" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390006" />
                    <lx:StepInt index="5500002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360003" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5450001" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390004" />
                </lx:Path>
            </lx:Criterion>'::text || (( SELECT string_agg(((('<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="'::text || ((536 * 10000 + 900 + t1_1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5450001" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="'::text) || ((541 * 10000 + 900 + t1_1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
            </lx:Criterion>'::text, 'g'::text) AS string_agg
           FROM fies.t_plan_section t1_1))) || '        <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360004" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5450001" />
                    <lx:StepInt index="5440002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360005" />
                    <lx:StepInt index="5600001" />
                </lx:Path>
                <lx:ConstOperand type="Guid">'::text) || t1.periodsectionid::character varying(36)::text) || '</lx:ConstOperand>
            </lx:Criterion>
        </lx:Criteria>
    </condition>
    <value>
        <lx:IsNull>
            <lx:Sum>
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360006" />
                </lx:Path>
            </lx:Sum>
            <lx:ConstOperand type="Decimal">0,0</lx:ConstOperand>
        </lx:IsNull>
    </value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    (950 + (( SELECT max(t_period_section.priority) + 1
           FROM fies.t_period_section)) - t1.priority) * '-1'::integer AS attributeid
   FROM fies.t_period_section t1
     JOIN vclib.t_entities t2 ON t2.entname::text = 'PLAN_ITEM_MONTH_VALUES'::text
  WHERE t1.periodsection IS NULL
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 950 AS index,
    0 AS attributetype,
    'ValueFact'::character varying AS name,
    'Значение (Факт)'::character varying AS description,
    'float'::text AS systemtype,
    NULL::integer AS maxlength,
    20 AS "precision",
    6 AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ('<lx:QueryValue entity="FIES.FACT_ITEM" top="1" xmlns:lx="lexem">
    <condition>
        <lx:Criteria type="And">
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360007" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="MonthValues" />
                    <lx:StepAs as="FIES.PLAN_ITEM_MONTH_VALUES" />
                    <lx:StepString name="PlanValue" />
                    <lx:StepString name="PlanItem" />
                    <lx:StepString name="Plan" />
                    <lx:StepString name="PlanPeriod" />
                    <lx:StepString name="Year" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360003" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="MonthValues" />
                    <lx:StepAs as="FIES.PLAN_ITEM_MONTH_VALUES" />
                    <lx:StepString name="PlanValue" />
                    <lx:StepString name="PlanItem" />
                    <lx:StepString name="Plan" />
                    <lx:StepString name="Mo" />
                </lx:Path>
            </lx:Criterion>'::text || (( SELECT string_agg(((('<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="'::text || ((536 * 10000 + 900 + t1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="MonthValues" />
                    <lx:StepAs as="FIES.PLAN_ITEM_MONTH_VALUES" />
                    <lx:StepInt index="5450001" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="'::text) || ((541 * 10000 + 900 + t1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
            </lx:Criterion>'::text, ''::text) AS string_agg
           FROM fies.t_plan_section t1))) || '        <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360004" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="MonthValues" />
                    <lx:StepAs as="FIES.PLAN_ITEM_MONTH_VALUES" />
                    <lx:StepString name="PlanValue" />
                    <lx:StepString name="PlanParameter" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360005" />
                    <lx:StepInt index="5600001" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepString name="PeriodSection" />
                    <lx:StepString name="PeriodSectionID" />
                </lx:Path>
            </lx:Criterion>
        </lx:Criteria>
    </condition>
    <value>
        <lx:IsNull>
            <lx:Sum>
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360006" />
                </lx:Path>
            </lx:Sum>
            <lx:ConstOperand type="Decimal">0,0</lx:ConstOperand>
        </lx:IsNull>
    </value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    950 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'MONTH_VALUE'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 950 + t1.priority AS index,
    0 AS attributetype,
    t1.periodalias::text || '_FACT'::text AS name,
    t1.name::text || ' (Факт)'::text AS description,
    'float'::text AS systemtype,
    NULL::integer AS maxlength,
    20 AS "precision",
    6 AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ((('<lx:QueryValue entity="FIES.FACT_ITEM" top="1" xmlns:lx="lexem">
    <condition>
        <lx:Criteria type="And">
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360007" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390006" />
                    <lx:StepInt index="5500002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360003" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390004" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360002" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550006" />
                </lx:Path>
            </lx:Criterion>
            '::text || (( SELECT string_agg(((('<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="'::text || ((536 * 10000 + 900 + t1_1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="'::text) || ((541 * 10000 + 900 + t1_1.sectionlevel))::character varying(20)::text) || '" />
                </lx:Path>
            </lx:Criterion>'::text, ''::text) AS string_agg
           FROM fies.t_plan_section t1_1))) || '
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360901" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410901" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360902" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410902" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360903" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410903" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360904" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410904" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360004" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360005" />
                    <lx:StepInt index="5600001" />
                </lx:Path>
                <lx:ConstOperand type="Guid">'::text) || t1.periodsectionid::character varying::text) || '</lx:ConstOperand>
            </lx:Criterion>
        </lx:Criteria>
    </condition>
    <value>
        <lx:IsNull>
            <lx:Sum>
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360006" />
                </lx:Path>
            </lx:Sum>
            <lx:ConstOperand type="Decimal">0,0</lx:ConstOperand>
        </lx:IsNull>
    </value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    (950 + (( SELECT max(t_period_section.priority) + 1
           FROM fies.t_period_section)) - t1.priority) * '-1'::integer AS attributeid
   FROM fies.t_period_section t1
     JOIN vclib.t_entities t2 ON t2.entname::text = 'PLAN_ITEM_MONTH_VALUES_SMO'::text
  WHERE t1.periodsection IS NULL
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 890 AS index,
    0 AS attributetype,
    'ValueFact'::character varying AS name,
    'Значение (факт)'::character varying AS description,
    'float'::text AS systemtype,
    NULL::integer AS maxlength,
    20 AS "precision",
    6 AS scale,
    '{0:0.######}'::character varying AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ('<lx:QueryValue entity="FIES.FACT_ITEM" top="1" xmlns:lx="lexem">
    <condition>
        <lx:Criteria type="And">
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360007" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390006" />
                    <lx:StepInt index="5500002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360003" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390004" />
                </lx:Path>
            </lx:Criterion>
            '::text || (( SELECT string_agg(((('<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="'::text || (((536 * 10000 + 900 + t1.sectionlevel)::character varying)::text)) || '" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="'::text) || (((541 * 10000 + 900 + t1.sectionlevel)::character varying)::text)) || '" />
                </lx:Path>
            </lx:Criterion>'::text, ''::text) AS string_agg
           FROM fies.t_plan_section t1))) || '
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360004" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5440002" />
                </lx:Path>
            </lx:Criterion>
        </lx:Criteria>
    </condition>
    <value>
        <lx:IsNull>
            <lx:Sum>
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360006" />
                </lx:Path>
            </lx:Sum>
            <lx:ConstOperand type="Decimal">0,0</lx:ConstOperand>
        </lx:IsNull>
    </value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    890 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'PLAN_VALUE'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 965 + t1.priority AS index,
    0 AS attributetype,
    t1.periodalias::text || '_FACT_SUM'::text AS name,
    t1.name::text || ' (Сумма факт)'::text AS description,
    'float'::text AS systemtype,
    NULL::integer AS maxlength,
    20 AS "precision",
    6 AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ((('<lx:QueryValue entity="FIES.FACT_ITEM" top="1" xmlns:lx="lexem">
    <condition>
        <lx:Criteria type="And">
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360007" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5450001" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390006" />
                    <lx:StepInt index="5500002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360003" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5450001" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390004" />
                </lx:Path>
            </lx:Criterion>'::text || (( SELECT string_agg(((('<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="'::text || (((536 * 10000 + 900 + t1_1.sectionlevel)::character varying)::text)) || '" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5450001" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="'::text) || (((541 * 10000 + 900 + t1_1.sectionlevel)::character varying)::text)) || '" />
                </lx:Path>
            </lx:Criterion>'::text, ''::text) AS string_agg
           FROM fies.t_plan_section t1_1))) || '        <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360004" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5450001" />
                    <lx:StepInt index="5440002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360005" />
                    <lx:StepInt index="5600001" />
                </lx:Path>
                <lx:ConstOperand type="Guid">'::text) || t1.periodsectionid::character varying::text) || '</lx:ConstOperand>
            </lx:Criterion>
        </lx:Criteria>
    </condition>
    <value>
        <lx:IsNull>
            <lx:Sum>
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360008" />
                </lx:Path>
            </lx:Sum>
            <lx:ConstOperand type="Decimal">0,0</lx:ConstOperand>
        </lx:IsNull>
    </value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    (965 + (( SELECT max(t_period_section.priority) + 1
           FROM fies.t_period_section)) - t1.priority) * '-1'::integer AS attributeid
   FROM fies.t_period_section t1
     JOIN vclib.t_entities t2 ON t2.entname::text = 'PLAN_ITEM_MONTH_VALUES'::text
  WHERE t1.periodsection IS NULL
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 965 + t1.priority AS index,
    0 AS attributetype,
    t1.periodalias::text || '_FACT_SUM'::text AS name,
    t1.name::text || ' (Сумма факт)'::text AS description,
    'float'::text AS systemtype,
    NULL::integer AS maxlength,
    20 AS "precision",
    6 AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ((('<lx:QueryValue entity="FIES.FACT_ITEM" top="1" xmlns:lx="lexem">
    <condition>
        <lx:Criteria type="And">
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360007" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390006" />
                    <lx:StepInt index="5500002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360003" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390004" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360002" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550006" />
                </lx:Path>
            </lx:Criterion>
            '::text || (( SELECT string_agg(((('<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="'::text || (((536 * 10000 + 900 + t1_1.sectionlevel)::character varying)::text)) || '" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="'::text) || (((541 * 10000 + 900 + t1_1.sectionlevel)::character varying)::text)) || '" />
                </lx:Path>
            </lx:Criterion>'::text, ''::text) AS string_agg
           FROM fies.t_plan_section t1_1))) || '
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360901" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410901" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360902" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410902" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360903" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410903" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360904" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410904" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360004" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5560001" />
                    <lx:StepInt index="5550007" />
                    <lx:StepInt index="5440002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360005" />
                    <lx:StepInt index="5600001" />
                </lx:Path>
                <lx:ConstOperand type="Guid">'::text) || t1.periodsectionid::character varying::text) || '</lx:ConstOperand>
            </lx:Criterion>
        </lx:Criteria>
    </condition>
    <value>
        <lx:IsNull>
            <lx:Sum>
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360008" />
                </lx:Path>
            </lx:Sum>
            <lx:ConstOperand type="Decimal">0,0</lx:ConstOperand>
        </lx:IsNull>
    </value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    (965 + (( SELECT max(t_period_section.priority) + 1
           FROM fies.t_period_section)) - t1.priority) * '-1'::integer AS attributeid
   FROM fies.t_period_section t1
     JOIN vclib.t_entities t2 ON t2.entname::text = 'PLAN_ITEM_MONTH_VALUES_SMO'::text
  WHERE t1.periodsection IS NULL
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 891 AS index,
    0 AS attributetype,
    'ValueFactSum'::character varying AS name,
    'Значение (Сумма факт)'::character varying AS description,
    'float'::text AS systemtype,
    NULL::integer AS maxlength,
    20 AS "precision",
    6 AS scale,
    '{0:0.######}'::character varying AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ('<lx:QueryValue entity="FIES.FACT_ITEM" top="1" xmlns:lx="lexem">
    <condition>
        <lx:Criteria type="And">
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360007" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390006" />
                    <lx:StepInt index="5500002" />
                </lx:Path>
            </lx:Criterion>
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360003" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="5410002" />
                    <lx:StepInt index="5390004" />
                </lx:Path>
            </lx:Criterion>
            '::text || (( SELECT string_agg(((('<lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="'::text || (((536 * 10000 + 900 + t1.sectionlevel)::character varying)::text)) || '" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5440003" />
                    <lx:StepInt index="'::text) || (((541 * 10000 + 900 + t1.sectionlevel)::character varying)::text)) || '" />
                </lx:Path>
            </lx:Criterion>'::text, ''::text) AS string_agg
           FROM fies.t_plan_section t1))) || '
            <lx:Criterion type="=">
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360004" />
                </lx:Path>
                <lx:Path OwnerQueryLevel="1">
                    <lx:StepInt index="5440002" />
                </lx:Path>
            </lx:Criterion>
        </lx:Criteria>
    </condition>
    <value>
        <lx:IsNull>
            <lx:Sum>
                <lx:Path OwnerQueryLevel="0">
                    <lx:StepInt index="5360008" />
                </lx:Path>
            </lx:Sum>
            <lx:ConstOperand type="Decimal">0,0</lx:ConstOperand>
        </lx:IsNull>
    </value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    891 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'PLAN_VALUE'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 10000 + 901 AS index,
    4 AS attributetype,
    'StatGroupLevels'::character varying AS name,
    'Срезы статистики'::character varying AS description,
    'int'::text AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    true AS isflag,
    false AS isrequired,
    1 AS mappingtype,
    'StatGroupLevels'::character varying AS mappingname,
    true AS save,
    NULL::character varying(255) AS linkattributename,
    (('<?xml version="1.0" encoding="utf-16"?><ChoiceItems xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        '::text || (((( SELECT string_agg((((('<ChoiceItem '::text || 'Name="'::text) || t_plan_section.name::text) || '" Index="'::text) || power(2::double precision, (t_plan_section.sectionlevel - 1)::double precision)) || '"/>'::text, ''::text) AS string_agg
           FROM fies.t_plan_section))::character varying)::text)) || '
    </ChoiceItems>'::text)::character varying AS choiceattributedata,
    true AS isstored,
    NULL::character varying AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    'T_COEFFICIENT'::character varying AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    901 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'COEFFICIENT'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    t2.entityid * 1000 + 900 + t1."position" AS index,
    0 AS attributetype,
    t1.alias AS name,
    t1.name AS description,
    'int'::text AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    1 AS mappingtype,
    t1.alias AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    NULL::character varying AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    (900 + (( SELECT max(t_age_group."position") + 1
           FROM fies.t_age_group)) - t1."position") * '-1'::integer AS attributeid
   FROM fies.t_age_group t1
     JOIN vclib.t_entities t2 ON t2.entname::text = 'MO_PEOPLE'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    NULL::integer AS index,
    1 AS attributetype,
    'TpFinTarif'::character varying AS name,
    'Тарифы'::character varying AS description,
    'FIES.TP_FIN_CLOSED_MONTH_TARIFS'::text AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying(255) AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ('<lx:QueryValue entity="FIES.TP_FIN_CLOSED_MONTH_TARIFS" top="1" xmlns:lx="lexem">
	<condition>
		<lx:Criteria type="And">
			<lx:Criterion type="=">
				<lx:Path OwnerQueryLevel="0">
					<lx:StepString name="TpFinCloseItem" />
					<lx:StepString name="Mo" />
				</lx:Path>
				<lx:Path OwnerQueryLevel="1">
					<lx:StepString name="PlanItem" />
					<lx:StepString name="Plan" />
					<lx:StepString name="Mo" />
				</lx:Path>
			</lx:Criterion>
				'::text || (( SELECT string_agg(((((((((((('
						<!-- Обман сортировки :) '::text || t1.index::character varying::text) || ' -->
						<lx:Criteria type="Or">
							<lx:Criterion type="=">
								<lx:Path OwnerQueryLevel="0">
								    <lx:StepString name="TpFinCloseItem" />
									<lx:StepString name="'::text) || t1.sectionalias::text) || '" />
								</lx:Path>
								<lx:BaseObjectOperand Entity="'::text) || t2_1.schema::text) || '.'::text) || t2_1.entname::text) || '" isNull="1" />
							</lx:Criterion>
							<lx:Criterion type="=">
								<lx:Path OwnerQueryLevel="0">
								    <lx:StepString name="TpFinCloseItem" />
									<lx:StepString name="'::text) || t1.sectionalias::text) || '" />
								</lx:Path>
								<lx:Path OwnerQueryLevel="1">
									<lx:StepString name="PlanItem" />
									<lx:StepString name="'::text) || t1.sectionalias::text) || '" />
								</lx:Path>
							</lx:Criterion>							
						</lx:Criteria>'::text, ''::text) AS string_agg
           FROM ( SELECT t100.plansectionid,
                    t100.entities,
                    t100.datebegin,
                    t100.dateend,
                    t100.name,
                    t100.sectionlevel,
                    t100.sectionalias,
                    t100.sectioncodepath,
                    row_number() OVER (ORDER BY t100.sectionlevel) AS index
                   FROM fies.t_plan_section t100) t1
             JOIN vclib.t_entities t2_1 ON t2_1.entityid = t1.entities))) || '
				<!--<lx:Criteria type="Or">
					<lx:Criterion type="=">
						<lx:Path OwnerQueryLevel="0">
							<lx:StepString name="TpFinCloseItem" />
							<lx:StepString name="Subprogramm" />
						</lx:Path>
						<lx:BaseObjectOperand Entity="FIES.SUBPROGRAMM" isNull="1" />
					</lx:Criterion>
					<lx:Criterion type="=">
						<lx:Path OwnerQueryLevel="0">
							<lx:StepString name="TpFinCloseItem" />
							<lx:StepString name="Subprogramm" />
						</lx:Path>
						<lx:Path OwnerQueryLevel="1">
							<lx:StepString name="Subprogramm" />
						</lx:Path>
					</lx:Criterion>
				</lx:Criteria> -->
				<lx:Criteria type="Or">
				<lx:Criteria type="And">
					<lx:Criterion type="=">
						<lx:Argument>
							<lx:ConstOperand type="Int32">0</lx:ConstOperand>
						</lx:Argument>
						<lx:ConstOperand isNull="1" />
					</lx:Criterion>
					<lx:Criterion type="=">
						<lx:Path OwnerQueryLevel="0">
							<lx:StepString name="TpFinCloseItem" />
							<lx:StepString name="TpFinClose" />
							<lx:StepString name="TpFin" />
							<lx:StepString name="PlanPeriod" />
						</lx:Path>
						<lx:Path OwnerQueryLevel="1">
							<lx:StepString name="PlanItem" />
							<lx:StepString name="Plan" />
							<lx:StepString name="PlanPeriod" />
						</lx:Path>
					</lx:Criterion>
				</lx:Criteria>
				<lx:Criterion type="=">
					<lx:Path OwnerQueryLevel="0">
						<lx:StepString name="TpFinCloseItem" />
						<lx:StepString name="TpFinClose" />
						<lx:StepString name="TpFin" />
					</lx:Path>
					<lx:Argument>
						<lx:ConstOperand type="Int32">0</lx:ConstOperand>
					</lx:Argument>
				</lx:Criterion>
			</lx:Criteria>
			<lx:Criterion type="&lt;=">
				<lx:Path OwnerQueryLevel="0">
					<lx:StepString name="TpFinCloseItem" />
					<lx:StepString name="TpFinClose" />
					<lx:StepString name="TpFin" />
					<lx:StepString name="TpDate" />
				</lx:Path>
				<lx:Path OwnerQueryLevel="1">
					<lx:StepString name="PlanItem" />
					<lx:StepString name="Plan" />
					<lx:StepString name="CreateDate" />
				</lx:Path>
			</lx:Criterion>
			<lx:Criteria type="Or">
				<lx:Criterion type="=">
					<lx:Path OwnerQueryLevel="0">
						<lx:StepString name="TpFinClosedValue" />
						<lx:StepString name="TpFinItemTarif" />
						<lx:StepString name="AgeGroup" />
					</lx:Path>
					<lx:Path OwnerQueryLevel="1">
						<lx:StepString name="PlanParameter" />
						<lx:StepString name="AgeGroup" />
					</lx:Path>
				</lx:Criterion>
				<lx:Criterion type="=">
					<lx:Path OwnerQueryLevel="0">
						<lx:StepString name="TpFinClosedValue" />
					</lx:Path>
					<lx:BaseObjectOperand Entity="FIES.TP_FIN_CLOSED_VALUE" isNull="1" />
				</lx:Criterion>
			</lx:Criteria>
		</lx:Criteria>
	</condition>
	<orderBy>
		<lx:Path OwnerQueryLevel="0">
			<lx:StepString name="TpFinCloseItem" />
			<lx:StepString name="TpFinClose" />
			<lx:StepString name="TpFin" />
			<lx:StepString name="TpDate" />
		</lx:Path>
		<desc>True</desc>
	</orderBy>
	<value>
		<lx:Path OwnerQueryLevel="0">
			<lx:StepString name="MonthValuesID" />
		</lx:Path>
	</value>
</lx:QueryValue>
	'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    '<?xml version="1.0" encoding="utf-16"?><Parameters xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Parameter Name="OnTpFin" Description="Финансовый расчет" Type="guid"><lx:BaseObjectOperand Entity="FIES.TP_FIN" isNull="1" xmlns:lx="lexem" /></Parameter></Parameters>'::character varying AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    892 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'PLAN_VALUE'::text
UNION ALL
 SELECT uuid_generate_v1() AS entityattributesid,
    t2.entityid,
    NULL::integer AS index,
    1 AS attributetype,
    'ClosedTpFinGroup'::character varying AS name,
    'Предыдущая закрытая группа'::character varying AS description,
    'FIES.TP_FIN_GROUP'::text AS systemtype,
    NULL::integer AS maxlength,
    NULL::integer AS "precision",
    NULL::integer AS scale,
    NULL::character varying AS defaultformat,
    false AS iscalculated,
    false AS isflag,
    false AS isrequired,
    4 AS mappingtype,
    NULL::character varying(255) AS mappingname,
    false AS save,
    NULL::character varying(255) AS linkattributename,
    NULL::character varying(1024) AS choiceattributedata,
    true AS isstored,
    ((('<lx:QueryValue entity="FIES.TP_FIN_GROUP" top="1" xmlns:lx="lexem">
	<condition>
		<lx:Criteria type="And">
			<lx:Criterion not="1" type="=">
				<lx:Path OwnerQueryLevel="0">
					<lx:StepString name="TpFin" />
					<lx:StepString name="TpFinClose" />
				</lx:Path>
				<lx:BaseObjectOperand Entity="FIES.TP_FIN_CLOSE" isNull="1" />
			</lx:Criterion>
			<lx:Criterion type="=">
				<lx:Path OwnerQueryLevel="0">
					<lx:StepString name="TpFinTypeLink" />
					<lx:StepString name="TpFinType" />
				</lx:Path>
				<lx:Path OwnerQueryLevel="1">
					<lx:StepString name="TpFinTypeLink" />
					<lx:StepString name="TpFinType" />
				</lx:Path>
			</lx:Criterion>
			<lx:Criterion type="&lt;">
				<lx:DatePart datepart="'::text ||
        CASE
            WHEN (( SELECT count(*) AS count
               FROM fies.t_period_section)) = 4 THEN 'Quarter'::text
            ELSE 'Month'::text
        END) || '">
					<lx:Path OwnerQueryLevel="0">
						<lx:StepString name="TpFin" />
						<lx:StepString name="TpDate" />
					</lx:Path>
				</lx:DatePart>
				<lx:DatePart datepart="'::text) ||
        CASE
            WHEN (( SELECT count(*) AS count
               FROM fies.t_period_section)) = 4 THEN 'Quarter'::text
            ELSE 'Month'::text
        END) || '">
					<lx:Path OwnerQueryLevel="1">
						<lx:StepString name="TpFin" />
						<lx:StepString name="TpDate" />
					</lx:Path>
				</lx:DatePart>
			</lx:Criterion>
		</lx:Criteria>
	</condition>
	<orderBy>
		<lx:Path OwnerQueryLevel="0">
			<lx:StepString name="TpFin" />
			<lx:StepString name="TpDate" />
		</lx:Path>
		<desc>True</desc>
		<lx:Path OwnerQueryLevel="0">
			<lx:StepString name="TpFin" />
			<lx:StepString name="CreateDate" />
		</lx:Path>
		<desc>True</desc>
	</orderBy>
	<value>
		<lx:Path OwnerQueryLevel="0">
			<lx:StepString name="TpFinGroupID" />
		</lx:Path>
	</value>
</lx:QueryValue>'::text AS attrlexem,
    NULL::character varying AS pathsattributes,
    false AS iscashed,
    NULL::character varying(255) AS mappingtable,
    NULL::character varying(255) AS mappingreftable,
    NULL::character varying(255) AS reftablesearchmode,
    NULL::character varying(255) AS reftablehashfunc,
    NULL::character varying(8000) AS parametersdata,
    NULL::character varying(8000) AS customsdata,
    NULL::character varying(8000) AS requiredattributes,
    NULL::character varying(8000) AS sortingattribute,
    NULL::character varying(8000) AS enumtype,
    false AS isidentity,
    false AS iscustom,
    true AS removeaction,
    false AS isprimarykey,
    893 * '-1'::integer AS attributeid
   FROM vclib.t_entities t2
  WHERE t2.entname::text = 'TP_FIN_GROUP'::text;

ALTER TABLE v_entity_attributes
    OWNER TO postgres;
