mirror of
https://github.com/FirebirdSQL/firebird-qa.git
synced 2025-01-22 21:43:06 +01:00
3621 lines
154 KiB
Python
3621 lines
154 KiB
Python
#coding:utf-8
|
||
|
||
"""
|
||
ID: issue-6318
|
||
ISSUE: 6318
|
||
TITLE: Server hangs when compiling big package with error
|
||
DESCRIPTION:
|
||
JIRA: CORE-6068
|
||
FBTEST: bugs.core_6068
|
||
"""
|
||
|
||
import pytest
|
||
from firebird.qa import *
|
||
|
||
db = db_factory(charset='UTF8')
|
||
|
||
test_script = """
|
||
CREATE DOMAIN DOM$ABONENT AS
|
||
NUMERIC(9,0)
|
||
CHECK (CHAR_LENGTH(VALUE) IN (8, 9));
|
||
|
||
CREATE DOMAIN DOM$ABONENT_LONG AS
|
||
VARCHAR(12);
|
||
|
||
CREATE DOMAIN DOM$ADDRESS AS
|
||
VARCHAR(200);
|
||
|
||
CREATE DOMAIN DOM$AMOUNT AS
|
||
NUMERIC(18,2)
|
||
DEFAULT 0;
|
||
|
||
CREATE DOMAIN DOM$BLOB AS
|
||
BLOB SUB_TYPE 0 SEGMENT SIZE 1024;
|
||
|
||
CREATE DOMAIN DOM$BOOLEAN AS
|
||
SMALLINT
|
||
DEFAULT 0
|
||
NOT NULL
|
||
CHECK (VALUE IN (0,1));
|
||
|
||
CREATE DOMAIN DOM$BOOLEAN_REAL AS
|
||
BOOLEAN;
|
||
|
||
CREATE DOMAIN DOM$CITIZEN_NAME AS
|
||
VARCHAR(50);
|
||
|
||
CREATE DOMAIN DOM$CITIZEN_PATRONYMIC AS
|
||
VARCHAR(50);
|
||
|
||
CREATE DOMAIN DOM$CITIZEN_SURNAME AS
|
||
VARCHAR(50);
|
||
|
||
CREATE DOMAIN DOM$COMMENT AS
|
||
VARCHAR(250);
|
||
|
||
CREATE DOMAIN DOM$CURRENT_TIMESTAMP AS
|
||
TIMESTAMP
|
||
DEFAULT CURRENT_TIMESTAMP
|
||
NOT NULL;
|
||
|
||
CREATE DOMAIN DOM$DATE AS
|
||
DATE
|
||
CHECK (VALUE BETWEEN DATE '01.01.1900' AND DATE '31.12.2100');
|
||
|
||
CREATE DOMAIN DOM$EMAIL AS
|
||
VARCHAR(50);
|
||
|
||
CREATE DOMAIN DOM$EMAILS AS
|
||
VARCHAR(255);
|
||
|
||
CREATE DOMAIN DOM$EMAIL_BODY AS
|
||
VARCHAR(5000);
|
||
|
||
CREATE DOMAIN DOM$EMAIL_SUBJECT AS
|
||
VARCHAR(100);
|
||
|
||
CREATE DOMAIN DOM$INN AS
|
||
VARCHAR(20)
|
||
CHECK (CHAR_LENGTH(VALUE) = 10 OR CHAR_LENGTH(VALUE) = 12);
|
||
|
||
CREATE DOMAIN DOM$INTEGER AS
|
||
INTEGER;
|
||
|
||
CREATE DOMAIN DOM$KEY AS
|
||
INTEGER;
|
||
|
||
CREATE DOMAIN DOM$NAME_CONTRACTOR AS
|
||
VARCHAR(200);
|
||
|
||
CREATE DOMAIN DOM$NAME_HUGE AS
|
||
VARCHAR(150);
|
||
|
||
CREATE DOMAIN DOM$NAME_LONG AS
|
||
VARCHAR(100);
|
||
|
||
CREATE DOMAIN DOM$NAME_SHORT AS
|
||
VARCHAR(25);
|
||
|
||
CREATE DOMAIN DOM$NAME_STANDARD AS
|
||
VARCHAR(50);
|
||
|
||
CREATE DOMAIN DOM$NAME_TINY AS
|
||
VARCHAR(10);
|
||
|
||
CREATE DOMAIN DOM$NETWORK_PORT AS
|
||
INTEGER
|
||
CHECK (VALUE BETWEEN 0 AND 65535);
|
||
|
||
CREATE DOMAIN DOM$NUMBER_CHECK AS
|
||
VARCHAR(6);
|
||
|
||
CREATE DOMAIN DOM$NUMBER_EXEC_PROCESS AS
|
||
VARCHAR(20);
|
||
|
||
CREATE DOMAIN DOM$NUMBER_FILE AS
|
||
VARCHAR(20);
|
||
|
||
CREATE DOMAIN DOM$NUMBER_PAYMENT_ORDER AS
|
||
INTEGER
|
||
CHECK (VALUE > 0);
|
||
|
||
CREATE DOMAIN DOM$NUMBER_WRIT_EXEC AS
|
||
VARCHAR(12)
|
||
CHECK (CHAR_LENGTH (VALUE) IN (11, 12));
|
||
|
||
CREATE DOMAIN DOM$PERIOD AS
|
||
INTEGER
|
||
CHECK (CHAR_LENGTH(VALUE) = 6);
|
||
|
||
CREATE DOMAIN DOM$POSITION AS
|
||
INTEGER
|
||
NOT NULL
|
||
CHECK (VALUE > 0);
|
||
|
||
CREATE DOMAIN DOM$SERIES_WRIT_EXEC AS
|
||
CHAR(2);
|
||
|
||
CREATE DOMAIN DOM$STATE AS
|
||
SMALLINT
|
||
DEFAULT 0
|
||
NOT NULL
|
||
CHECK ((VALUE >= 0) AND (VALUE <= 11));
|
||
|
||
CREATE DOMAIN DOM$STRING_DATE AS
|
||
VARCHAR(10);
|
||
|
||
CREATE DOMAIN DOM$TEXT_EXCEPTION AS
|
||
VARCHAR(5000);
|
||
|
||
CREATE DOMAIN DOM$TIME AS
|
||
TIME;
|
||
|
||
CREATE DOMAIN DOM$TIMESTAMP AS
|
||
TIMESTAMP;
|
||
|
||
CREATE DOMAIN DOM$VERSION AS
|
||
VARCHAR(7);
|
||
|
||
CREATE DOMAIN DOM$YEAR AS
|
||
SMALLINT
|
||
CHECK ((VALUE >= 1960) AND (VALUE <= 2025));
|
||
|
||
CREATE DOMAIN D_INTEGER AS
|
||
INTEGER;
|
||
|
||
CREATE DOMAIN D_KEY AS
|
||
INTEGER;
|
||
|
||
CREATE DOMAIN D_LIST_ID AS
|
||
VARCHAR(1000);
|
||
|
||
CREATE DOMAIN D_NATURAL AS
|
||
INTEGER
|
||
CHECK (VALUE >= 0);
|
||
|
||
CREATE DOMAIN D_NUMBER AS
|
||
INTEGER
|
||
CHECK (VALUE > 0);
|
||
|
||
CREATE DOMAIN D_QUANTITY AS
|
||
INTEGER
|
||
DEFAULT 0
|
||
CHECK (VALUE >= 0);
|
||
|
||
CREATE DOMAIN D_VARCHAR_10 AS
|
||
VARCHAR(10);
|
||
|
||
CREATE DOMAIN D_VARCHAR_100 AS
|
||
VARCHAR(100);
|
||
|
||
CREATE DOMAIN D_VARCHAR_15 AS
|
||
VARCHAR(15);
|
||
|
||
CREATE DOMAIN D_VARCHAR_150 AS
|
||
VARCHAR(150);
|
||
|
||
CREATE DOMAIN D_VARCHAR_200 AS
|
||
VARCHAR(200);
|
||
|
||
CREATE DOMAIN D_VARCHAR_25 AS
|
||
VARCHAR(25);
|
||
|
||
CREATE DOMAIN D_VARCHAR_255 AS
|
||
VARCHAR(255);
|
||
|
||
CREATE DOMAIN D_VARCHAR_50 AS
|
||
VARCHAR(50);
|
||
|
||
CREATE DOMAIN D_VARCHAR_500 AS
|
||
VARCHAR(500);
|
||
|
||
CREATE DOMAIN D_VARCHAR_5000 AS
|
||
VARCHAR(5000);
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Generators ***/
|
||
/******************************************************************************/
|
||
|
||
CREATE SEQUENCE IBE$LOG_TABLES_GEN START WITH 0 INCREMENT BY 1;
|
||
ALTER SEQUENCE IBE$LOG_TABLES_GEN RESTART WITH 0;
|
||
|
||
CREATE SEQUENCE SEQ_BAT$RECEIPT$BATCH_ID START WITH 0 INCREMENT BY 1;
|
||
ALTER SEQUENCE SEQ_BAT$RECEIPT$BATCH_ID RESTART WITH 0;
|
||
|
||
CREATE SEQUENCE SEQ_BAT$RECEIPT$RECEIPT_ID START WITH 0 INCREMENT BY 1;
|
||
ALTER SEQUENCE SEQ_BAT$RECEIPT$RECEIPT_ID RESTART WITH 0;
|
||
|
||
CREATE SEQUENCE SEQ_DOC$LAWSUIT$WRIT_OF_EXEC_ID START WITH 0 INCREMENT BY 1;
|
||
ALTER SEQUENCE SEQ_DOC$LAWSUIT$WRIT_OF_EXEC_ID RESTART WITH 0;
|
||
|
||
CREATE SEQUENCE SEQ_INF$ABONENT$CHARAC_GAS_ID START WITH 0 INCREMENT BY 1;
|
||
ALTER SEQUENCE SEQ_INF$ABONENT$CHARAC_GAS_ID RESTART WITH 0;
|
||
|
||
CREATE SEQUENCE SEQ_INF$WAREHOUSE$TURNOVER_ID START WITH 0 INCREMENT BY 1;
|
||
ALTER SEQUENCE SEQ_INF$WAREHOUSE$TURNOVER_ID RESTART WITH 0;
|
||
|
||
CREATE SEQUENCE SEQ_SYS$LOG$EXCEPTION_ID START WITH 131573 INCREMENT BY 1;
|
||
ALTER SEQUENCE SEQ_SYS$LOG$EXCEPTION_ID RESTART WITH 131573;
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Exceptions ***/
|
||
/******************************************************************************/
|
||
|
||
CREATE EXCEPTION EXC$CANCEL 'Отмена';
|
||
|
||
CREATE EXCEPTION EXC$CHECK_DATA 'Проверка данных';
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Stored procedures ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
|
||
SET TERM ^ ;
|
||
|
||
CREATE PROCEDURE GET$ABONENT$CHARGING_GAS_AMURCC (
|
||
ID_ABONENT DOM$ABONENT NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$BOOLEAN)
|
||
AS
|
||
BEGIN
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE PROCEDURE GET$ABONENT$DEFAULT_TYPE_RECEIP (
|
||
ID_ABONENT DOM$ABONENT NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$KEY)
|
||
AS
|
||
BEGIN
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE PROCEDURE GET$ABONENT$DETERMINE_GD (
|
||
ID_ABONENT DOM$ABONENT_LONG NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$KEY)
|
||
AS
|
||
BEGIN
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE PROCEDURE GET$WRIT_EXEC$CHECK_RESPONDENT (
|
||
ID_WRIT_EXEC DOM$KEY NOT NULL,
|
||
RESPONDENT D_VARCHAR_100 NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$BOOLEAN)
|
||
AS
|
||
BEGIN
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE PROCEDURE GET$WRIT_EXEC$SEARCH_BY_RESPOND (
|
||
NUMBER_FILE DOM$NUMBER_FILE NOT NULL,
|
||
RESPONDENT D_VARCHAR_100 NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$KEY)
|
||
AS
|
||
BEGIN
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE PROCEDURE OPER$EXCEPTION$CANCEL (
|
||
TEXT D_VARCHAR_500)
|
||
AS
|
||
BEGIN
|
||
EXIT;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE PROCEDURE OPER$EXCEPTION$CHECK_DATA (
|
||
TEXT D_VARCHAR_500)
|
||
AS
|
||
BEGIN
|
||
EXIT;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE PROCEDURE OPER$EXCEPTION$CHECK_DATA_ABONE (
|
||
ID_ABONENT DOM$ABONENT NOT NULL,
|
||
TEXT D_VARCHAR_500 NOT NULL)
|
||
AS
|
||
BEGIN
|
||
EXIT;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE PROCEDURE OPER$EXCEPTION$CHECK_DATA_BRANC (
|
||
ID_BRANCH DOM$KEY NOT NULL,
|
||
TEXT D_VARCHAR_500 NOT NULL)
|
||
AS
|
||
BEGIN
|
||
EXIT;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
|
||
SET TERM ; ^
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Stored functions ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
|
||
SET TERM ^ ;
|
||
|
||
CREATE FUNCTION DATE_TO_PERIOD (
|
||
VAL DOM$DATE)
|
||
RETURNS DOM$PERIOD
|
||
AS
|
||
BEGIN
|
||
RETURN NULL;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE FUNCTION DEC_PERIOD (
|
||
VAL DOM$PERIOD)
|
||
RETURNS DOM$PERIOD
|
||
AS
|
||
BEGIN
|
||
RETURN NULL;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
CREATE FUNCTION FORMAT_DATE (
|
||
ARG DOM$DATE)
|
||
RETURNS DOM$STRING_DATE
|
||
AS
|
||
BEGIN
|
||
RETURN NULL;
|
||
END^
|
||
|
||
|
||
|
||
|
||
|
||
|
||
SET TERM ; ^
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Package headers ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
|
||
SET TERM ^ ;
|
||
|
||
CREATE PACKAGE PKG$ABONENT
|
||
AS
|
||
BEGIN
|
||
FUNCTION GET_GROUP_DISTRICT_FOR_PAYMENT(ID_ABONENT DOM$ABONENT NOT NULL) RETURNS DOM$KEY DETERMINISTIC;
|
||
END^
|
||
|
||
|
||
CREATE PACKAGE PKG$CONNECT
|
||
AS
|
||
BEGIN
|
||
FUNCTION ID_USER() RETURNS DOM$KEY DETERMINISTIC;
|
||
FUNCTION ID_DIVISION() RETURNS DOM$KEY DETERMINISTIC;
|
||
FUNCTION ID_WORKER() RETURNS DOM$KEY DETERMINISTIC;
|
||
FUNCTION ID_CS() RETURNS DOM$KEY DETERMINISTIC;
|
||
FUNCTION ID_BRANCH() RETURNS DOM$KEY DETERMINISTIC;
|
||
FUNCTION ID_GROUP_DISTRICT() RETURNS DOM$KEY DETERMINISTIC;
|
||
|
||
FUNCTION CURRENT_USER_SURNAME_NP RETURNS D_VARCHAR_50 DETERMINISTIC;
|
||
END^
|
||
|
||
|
||
CREATE PACKAGE PKG$EXCEPTION
|
||
AS
|
||
BEGIN
|
||
PROCEDURE FOR_CITIZEN(ID_CITIZEN DOM$KEY NOT NULL, TEXT D_VARCHAR_500 NOT NULL);
|
||
PROCEDURE FOR_WORKER(ID_WORKER DOM$KEY NOT NULL, TEXT D_VARCHAR_500 NOT NULL);
|
||
PROCEDURE FOR_BATCH_RECEIPT(ID_BATCH DOM$KEY NOT NULL, TEXT D_VARCHAR_500 NOT NULL);
|
||
END^
|
||
|
||
|
||
CREATE PACKAGE PKG$PAYMENT$BANK_STTM
|
||
AS
|
||
BEGIN
|
||
--
|
||
PROCEDURE GET_LIST_BRANCH RETURNS (ID DOM$KEY, NAME DOM$NAME_STANDARD);
|
||
|
||
-- Загрузка банковской выписки
|
||
PROCEDURE PARSE_PAYMENT_ORDERS;
|
||
PROCEDURE DETECT_SOURCE_PAYMENT(DATE_ACCOUNT DOM$DATE NOT NULL);
|
||
|
||
-- Создание квитанций
|
||
PROCEDURE CREATE_RECEIPTS_FOR_DATE(DATE_ACCOUNT DOM$DATE);
|
||
PROCEDURE CREATE_RECEIPT(ID DOM$KEY NOT NULL, ID_ABONENT DOM$ABONENT);
|
||
PROCEDURE CREATE_INDIVID_RECEIPT(ID DOM$KEY NOT NULL, ID_ABONENT DOM$ABONENT NOT NULL);
|
||
|
||
PROCEDURE TRY_CREATE_RECEIPT_NONACCEPT(ID_BANK DOM$KEY NOT NULL, DATE_ACCOUNT DOM$DATE NOT NULL, DATE_PAYMENT DOM$DATE NOT NULL, NUMBER_RECEIPT DOM$NUMBER_CHECK NOT NULL, AMOUNT DOM$AMOUNT NOT NULL, PURPOSE D_VARCHAR_500 NOT NULL, PAYER D_VARCHAR_200 NOT NULL) RETURNS (RESULT DOM$KEY);
|
||
PROCEDURE TRY_CREATE_RECEIPT_BAILIFF(ID_SOURCE DOM$KEY NOT NULL, DATE_ACCOUNT DOM$DATE NOT NULL, DATE_PAYMENT DOM$DATE NOT NULL, NUMBER_RECEIPT DOM$NUMBER_CHECK NOT NULL, AMOUNT DOM$AMOUNT NOT NULL, PURPOSE D_VARCHAR_500 NOT NULL) RETURNS (RESULT DOM$KEY);
|
||
PROCEDURE TRY_CREATE_RECEIPT_INDIVID(DATE_ACCOUNT DOM$DATE NOT NULL, DATE_PAYMENT DOM$DATE NOT NULL, NUMBER_RECEIPT DOM$NUMBER_CHECK NOT NULL, AMOUNT DOM$AMOUNT NOT NULL, PURPOSE D_VARCHAR_500 NOT NULL, PAYER D_VARCHAR_200 NOT NULL, ID_ABONENT DOM$ABONENT) RETURNS (RESULT DOM$KEY);
|
||
|
||
-- Распознавание
|
||
PROCEDURE RECOGN_NONACCEPT(ID_BANK DOM$KEY NOT NULL, DATE_PAYMENT DOM$DATE NOT NULL, PURPOSE D_VARCHAR_500 NOT NULL, PAYER D_VARCHAR_200 NOT NULL) RETURNS (ID_LAWSUIT DOM$KEY, ID_WRIT_EXEC DOM$KEY, ID_EXEC_PROC DOM$KEY);
|
||
FUNCTION RECOGN_INDIVID(PURPOSE D_VARCHAR_500 NOT NULL) RETURNS DOM$ABONENT;
|
||
FUNCTION SEARCH_NUMBER_FILE(PURPOSE D_VARCHAR_500 NOT NULL, IS_NONACCEPT DOM$BOOLEAN_REAL NOT NULL) RETURNS DOM$NUMBER_FILE DETERMINISTIC;
|
||
|
||
-- Добавление корректировок
|
||
PROCEDURE ADD_CORRECT_NONACCEPT(ID_PAYMENT DOM$KEY NOT NULL, NUMBER_FILE_OLD DOM$NUMBER_FILE NOT NULL, RESPONDENT_OLD D_VARCHAR_100 NOT NULL, NUMBER_FILE_NEW DOM$NUMBER_FILE NOT NULL, RESPONDENT_NEW D_VARCHAR_100 NOT NULL);
|
||
PROCEDURE ADD_CORRECT_BAILIFF(ID_PAYMENT DOM$KEY NOT NULL, NUMBER_FILE DOM$NUMBER_FILE NOT NULL, RESPONDENT D_VARCHAR_100 NOT NULL);
|
||
|
||
-- Извещения
|
||
PROCEDURE SEND_NOTIFY_LOAD_BANK_STATEMENT(DATE_ACCOUNT DOM$DATE NOT NULL, RECOGN DOM$INTEGER NOT NULL, NOT_RECOGN DOM$INTEGER NOT NULL);
|
||
PROCEDURE SEND_NOTIFY_RECONG_BANK_STATEME(DATE_ACCOUNT DOM$DATE NOT NULL);
|
||
PROCEDURE SEND_NOTIFY_ERROR_LOAD_BANK_STA;
|
||
PROCEDURE SEND_NOTIFY_ERROR_DETECT_SOURCE;
|
||
PROCEDURE SEND_NOTIFY_ERROR_CREATE_ALL_RE;
|
||
END^
|
||
|
||
|
||
CREATE PACKAGE PKG$SEND_EMAIL
|
||
AS
|
||
BEGIN
|
||
PROCEDURE SEND_TO_EMAILS(EMAILS DOM$EMAILS NOT NULL, EMAILS_COPY DOM$EMAILS, SUBJECT DOM$EMAIL_SUBJECT NOT NULL, BODY_MAIL DOM$EMAIL_BODY NOT NULL);
|
||
PROCEDURE SEND_TO_LIST_USERS(LIST_USERS D_LIST_ID NOT NULL, LIST_USERS_COPY D_LIST_ID, SUBJECT DOM$EMAIL_SUBJECT NOT NULL, BODY_MAIL DOM$EMAIL_BODY NOT NULL);
|
||
PROCEDURE SEND_TO_GROUP(ID_GROUP DOM$KEY NOT NULL, SUBJECT DOM$EMAIL_SUBJECT NOT NULL, BODY_MAIL DOM$EMAIL_BODY NOT NULL);
|
||
END^
|
||
|
||
|
||
|
||
SET TERM ; ^
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Tables ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
|
||
CREATE TABLE BAT$RECEIPT$BATCH (
|
||
ID D_KEY NOT NULL,
|
||
ID_CREATOR D_KEY NOT NULL,
|
||
ID_LOADER D_KEY,
|
||
ID_GROUP_DISTRICT DOM$KEY NOT NULL,
|
||
ID_PERIOD_ACCOUNT DOM$KEY NOT NULL,
|
||
ID_SOURCE D_KEY NOT NULL,
|
||
ID_CASHIER DOM$KEY,
|
||
ID_VERIFIED_BOOKKEEPER DOM$KEY,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP NOT NULL,
|
||
TIMESTAMP_LOADING DOM$TIMESTAMP,
|
||
TIMESTAMP_VERIFIED_BOOKKEEPER DOM$TIMESTAMP,
|
||
DATE_ACCOUNT DOM$DATE NOT NULL,
|
||
BEGIN_DATE_PAYMENT DOM$DATE,
|
||
END_DATE_PAYMENT DOM$DATE,
|
||
DATE_PAYMENT_ORDER DOM$DATE,
|
||
PAYMENT_ORDER DOM$NUMBER_PAYMENT_ORDER,
|
||
NUMBER_REGISTRY DOM$NUMBER_PAYMENT_ORDER,
|
||
COMMENT DOM$COMMENT,
|
||
IS_CORRECT_RECEIPT DOM$BOOLEAN,
|
||
LOADED DOM$BOOLEAN
|
||
);
|
||
|
||
|
||
CREATE TABLE BAT$RECEIPT$RECEIPT (
|
||
ID D_KEY NOT NULL,
|
||
ID_BATCH D_KEY NOT NULL,
|
||
ID_CREATOR D_KEY NOT NULL,
|
||
ID_ABONENT D_KEY NOT NULL,
|
||
ID_PERIOD_FOR_PAYMENT DOM$KEY NOT NULL,
|
||
ID_TYPE_RECEIPT DOM$KEY NOT NULL,
|
||
ID_CORRECTED_RECEIPT D_KEY,
|
||
ID_REVERSED_RECEIPT DOM$KEY,
|
||
ID_READING_1 DOM$KEY,
|
||
ID_READING_2 DOM$KEY,
|
||
ID_READING_3 DOM$KEY,
|
||
ID_CS_STATEMENT DOM$KEY,
|
||
ID_LAWSUIT DOM$KEY,
|
||
ID_WRIT_EXEC DOM$KEY,
|
||
ID_EXEC_PROC DOM$KEY,
|
||
ID_BT_FINE DOM$KEY,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP NOT NULL,
|
||
DATE_PAYMENT DOM$DATE NOT NULL,
|
||
NUMBER DOM$NUMBER_CHECK,
|
||
AMOUNT_SERVICE_1 DOM$AMOUNT NOT NULL,
|
||
AMOUNT_SERVICE_2 DOM$AMOUNT NOT NULL,
|
||
AMOUNT_SERVICE_3 DOM$AMOUNT NOT NULL,
|
||
AMOUNT_SERVICE_4 DOM$AMOUNT NOT NULL,
|
||
AMOUNT_SERVICE_5 DOM$AMOUNT NOT NULL,
|
||
AMOUNT_FINE DOM$AMOUNT NOT NULL,
|
||
AMOUNT_RECEIPT DOM$AMOUNT NOT NULL,
|
||
AMOUNT_SERVICES COMPUTED BY (AMOUNT_RECEIPT - AMOUNT_FINE),
|
||
COMMISSION DOM$AMOUNT,
|
||
AUTODISTRIBUTE_SERVICES DOM$BOOLEAN DEFAULT 1 NOT NULL,
|
||
CASHLESS DOM$BOOLEAN NOT NULL,
|
||
PURPOSE D_VARCHAR_500,
|
||
PAYER D_VARCHAR_500
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$ABONENT$ABONENT (
|
||
ID D_KEY NOT NULL,
|
||
ID_BRANCH DOM$KEY NOT NULL,
|
||
ID_TYPE_GASSUPPLY DOM$KEY NOT NULL
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$DATABASE$DATABASE (
|
||
ID DOM$KEY NOT NULL,
|
||
NAME DOM$NAME_SHORT NOT NULL,
|
||
DATA_SOURCE DOM$NAME_LONG NOT NULL,
|
||
NAME_BASE_METERS DOM$NAME_TINY,
|
||
USE_SYNC DOM$BOOLEAN NOT NULL,
|
||
MAIN_DATABASE DOM$BOOLEAN_REAL NOT NULL
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$ENTERPRISE$BRANCH (
|
||
ID DOM$KEY NOT NULL,
|
||
NAME DOM$NAME_HUGE NOT NULL,
|
||
INTERNAL_NAME DOM$NAME_STANDARD NOT NULL,
|
||
USE_FOR_BANK_STATEMENT DOM$BOOLEAN_REAL,
|
||
POS DOM$INTEGER,
|
||
ID_SOURCE_PAYMENT_BAILIFF DOM$KEY,
|
||
ID_SOURCE_INDIVID_PAYMENT_ORDER DOM$KEY
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$ENTERPRISE$GROUP_DISTRICT (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_BRANCH DOM$KEY NOT NULL,
|
||
NAME DOM$NAME_STANDARD NOT NULL,
|
||
ID_FIRST_PERIOD DOM$PERIOD NOT NULL,
|
||
ID_LAST_PERIOD DOM$PERIOD NOT NULL,
|
||
ID_LAST_CALCED_PERIOD DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_MONTHS_DEBT DOM$PERIOD,
|
||
ID_OPENED_PERIOD_NETWORK_GAS DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_PAYMENT DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_BOTTLE DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_GTP DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_MS DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_ADS DOM$PERIOD,
|
||
ID_OPENED_PERIOD_ROS DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_EQUIPMENT DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_NOTICE DOM$PERIOD,
|
||
ID_OPENED_PERIOD_MNG_COMPANY DOM$PERIOD,
|
||
ID_OPENED_PERIOD_ABONENT DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_HOUSE DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_UNIT DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_GDP DOM$PERIOD NOT NULL,
|
||
ID_OPENED_PERIOD_COURT_EXPENSES DOM$PERIOD,
|
||
ID_OPENED_PERIOD_ENTRY_REMAINS DOM$PERIOD,
|
||
ID_OPENED_PERIOD_WH_MATERIALS DOM$PERIOD,
|
||
ID_FIRST_YEAR_INTERVAL_MS DOM$YEAR NOT NULL,
|
||
ID_FIRST_PERIOD_TURNOVER_GTP DOM$PERIOD NOT NULL,
|
||
ID_FIRST_PERIOD_TURNOVER_WAREHO DOM$PERIOD NOT NULL,
|
||
ID_FIRST_PERIOD_CHARGE_BY_AVERA DOM$PERIOD,
|
||
ID_FIRST_PERIOD_RECALC_READING DOM$PERIOD,
|
||
ID_FIRST_PERIOD_TIMESHEET DOM$PERIOD,
|
||
ID_FIRST_PERIOD_CELLPHONE DOM$PERIOD,
|
||
ID_FIRST_PERIOD_WH_MATERIAL DOM$PERIOD,
|
||
ID_FIRST_PERIOD_AUTORECALC_AVGM DOM$PERIOD,
|
||
ID_FIRST_PERIOD_RECEPT_READING DOM$PERIOD,
|
||
ID_FIRST_PERIOD_PLAN_WORKS DOM$PERIOD,
|
||
ID_FIRST_PERIOD_METER_SUMMARY DOM$PERIOD,
|
||
ID_FIRST_PERIOD_METER_HISTORY_R DOM$PERIOD,
|
||
ID_LAST_PERIOD_CHANGE_CS DOM$PERIOD NOT NULL,
|
||
ID_UNIT_BOTTLE DOM$KEY,
|
||
ID_UNIT_ABSENCE DOM$KEY NOT NULL,
|
||
ID_UNIT_DISCONNECTED DOM$KEY NOT NULL,
|
||
ID_DIVISION_RETURN_COMMIS_MATER DOM$KEY,
|
||
ID_FIRST_PERIOD_BT_CS_STATEMENT DOM$KEY,
|
||
ID_FIRST_PERIOD_CHARGE_DUTY DOM$PERIOD,
|
||
ID_FIRST_PERIOD_USE_SERIAL_BOTT DOM$PERIOD,
|
||
ID_FIRST_PERIOD_CHARGE_GAS DOM$PERIOD,
|
||
ID_FIRST_PERIOD_CHARGE_MS_MANSI DOM$PERIOD,
|
||
ID_FIRST_PERIOD_CHARGE_MS_NGPH DOM$PERIOD,
|
||
ID_FIRST_PERIOD_CHARGE_MS_DEPAR DOM$PERIOD,
|
||
ID_DIVISION_CS_PAYMENT_EXTERNAL DOM$KEY,
|
||
ID_MASTER_GROUP_DISTRICT DOM$KEY,
|
||
ID_FIRST_PERIOD_PIECEWORK DOM$PERIOD,
|
||
ID_ROUTE_FOR_NEW_HOUSE DOM$KEY NOT NULL,
|
||
ID_NF_ABONENT_FOR_PAYMENT_LAWSU DOM$ABONENT,
|
||
ID_DEFAULT_CHARGE_REGIME_MS DOM$KEY,
|
||
POS DOM$POSITION,
|
||
NAME_WITH_BRANCH DOM$NAME_HUGE NOT NULL,
|
||
PICTURE_RECEIPT_MANSION DOM$BLOB,
|
||
PICTURE_RECEIPT_NGPH DOM$BLOB,
|
||
MAX_CLAIMS_FOR_DEBT_PER_OPERATI D_NATURAL,
|
||
CHARGE_MS_NETWORK_GAS_BY_FACT DOM$BOOLEAN NOT NULL,
|
||
CHARGE_MS_METER_MANSION_BY_FACT DOM$BOOLEAN,
|
||
CHARGE_MS_NGPH_BY_FACT DOM$BOOLEAN NOT NULL,
|
||
CHARGE_MANSION_BY_AMURCC DOM$BOOLEAN NOT NULL,
|
||
CHARGE_ES_FOR_GTP DOM$BOOLEAN,
|
||
AUTOLOAD_RECEPTED_READINGS DOM$BOOLEAN NOT NULL,
|
||
USING_PHONE_IN_RECEPT_READING DOM$BOOLEAN NOT NULL,
|
||
ALLOW_PAYMENT_DUTY_WITHOUT_LAWS DOM$BOOLEAN NOT NULL,
|
||
EXTERNAL_PAYMENT_CS DOM$BOOLEAN,
|
||
CALC_MD_OLD_ALGORITHM DOM$BOOLEAN NOT NULL,
|
||
USING_CAF_FOR_LAWSUIT DOM$BOOLEAN NOT NULL,
|
||
IS_ACTIVE DOM$BOOLEAN,
|
||
IS_MAIN_GROUP_DISTRICT DOM$BOOLEAN_REAL
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$ENTPR$IND_PAYMENT (
|
||
ID DOM$KEY GENERATED BY DEFAULT AS IDENTITY,
|
||
ID_BRANCH DOM$KEY NOT NULL,
|
||
NAME DOM$NAME_STANDARD NOT NULL
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$EXEC_PROC$BANK (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_SOURCE DOM$KEY,
|
||
POS DOM$POSITION NOT NULL,
|
||
NAME DOM$NAME_STANDARD NOT NULL,
|
||
FULL_NAME DOM$NAME_LONG NOT NULL,
|
||
NAME_IN_FILE_BANK_CLIENT DOM$NAME_LONG,
|
||
USE_INFO_ABOUT_REPRESENTATIVE DOM$BOOLEAN,
|
||
BANK_INN DOM$INN
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$EXEC_PROC$BANK_PURPOSE (
|
||
ID DOM$KEY GENERATED BY DEFAULT AS IDENTITY,
|
||
ID_BANK DOM$KEY NOT NULL,
|
||
NAME DOM$NAME_LONG NOT NULL
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$EXEC_PROC$CORRECTION (
|
||
ID DOM$KEY GENERATED BY DEFAULT AS IDENTITY,
|
||
PAYMENT_NUMBER_FILE DOM$NUMBER_FILE,
|
||
PAYMENT_FIO D_VARCHAR_100,
|
||
PAYMENT_PURPOSE D_VARCHAR_500,
|
||
PAYMENT_SERIAL_WRIT_EXEC DOM$NUMBER_WRIT_EXEC,
|
||
CORRECT_NUMBER_FILE DOM$NUMBER_FILE NOT NULL,
|
||
CORRECT_FIO D_VARCHAR_100 NOT NULL,
|
||
TYPE_PAYMENT DOM$INTEGER NOT NULL
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$GASSUPPLY$TYPE_GS (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_REGIME DOM$KEY NOT NULL,
|
||
ID_GROUP_TG DOM$KEY,
|
||
ID_TYPE_RECEIPT DOM$KEY,
|
||
ID_TYPE_CONTRACT_GAS DOM$KEY,
|
||
ID_TYPE_CONTRACT_MS DOM$KEY,
|
||
ID_TYPE_CLAIM_DEBT DOM$KEY,
|
||
ID_TYPE_LAWSUIT DOM$KEY,
|
||
ID_TYPE_GAS DOM$KEY,
|
||
ID_DEFAULT_GC_OBJECT DOM$KEY,
|
||
ID_DEFAULT_GC_LINE DOM$KEY,
|
||
POS DOM$POSITION,
|
||
NAME DOM$NAME_STANDARD NOT NULL,
|
||
SHORT_NAME DOM$NAME_SHORT NOT NULL,
|
||
IS_NETWORK_GAS DOM$BOOLEAN,
|
||
EXTERNAL_PAYMENT_CS DOM$BOOLEAN NOT NULL,
|
||
REPLICATE_PAYMENT DOM$BOOLEAN,
|
||
FORBID_CHANGE_OBJECT_AND_LINE_G DOM$BOOLEAN,
|
||
APPLY_AMORT_FINE DOM$BOOLEAN NOT NULL
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$PAYMENT$SOURCE (
|
||
ID D_KEY NOT NULL,
|
||
ID_TYPE_SOURCE DOM$KEY NOT NULL,
|
||
ID_SOURCE_READING DOM$KEY,
|
||
NAME DOM$NAME_STANDARD NOT NULL,
|
||
NAME_CONTRACTOR DOM$NAME_CONTRACTOR,
|
||
POS DOM$POSITION NOT NULL,
|
||
DATE_PAYMENT_EQUAL_DATE_ACCOUNT DOM$BOOLEAN NOT NULL,
|
||
DATES_PAYMENT_EQUAL DOM$BOOLEAN NOT NULL,
|
||
LOAD_TO_BASE DOM$BOOLEAN NOT NULL,
|
||
LOAD_FROM_FILE DOM$BOOLEAN NOT NULL,
|
||
RECEIPT_HAS_NUMBER DOM$BOOLEAN NOT NULL,
|
||
RECEIPT_IS_FSA DOM$BOOLEAN,
|
||
EXIST_NUMBER_REGISTRY DOM$BOOLEAN,
|
||
EXIST_PAYMENT_ORDER DOM$BOOLEAN NOT NULL,
|
||
EXIST_CASHIER DOM$BOOLEAN NOT NULL,
|
||
IS_PAYMENT_FOR_CS DOM$BOOLEAN NOT NULL,
|
||
IS_PAYMENT_BY_BAILIFF DOM$BOOLEAN NOT NULL,
|
||
PAYMENT_FOR_LAWSUIT DOM$BOOLEAN NOT NULL,
|
||
HIDDEN DOM$BOOLEAN NOT NULL,
|
||
RETURN_RECEIPT DOM$BOOLEAN NOT NULL,
|
||
GROUP_DISTRICTS D_LIST_ID,
|
||
SELL_MATERIAL DOM$BOOLEAN DEFAULT 0 NOT NULL,
|
||
IS_RKC DOM$BOOLEAN NOT NULL,
|
||
PRINT_CHECK_IN_POSSYSTEM DOM$BOOLEAN_REAL DEFAULT FALSE NOT NULL
|
||
);
|
||
|
||
|
||
CREATE TABLE DIR$PAYMENT$SOURCE_GD (
|
||
ID_SOURCE DOM$KEY NOT NULL,
|
||
ID_GROUP_DISTRICT DOM$KEY NOT NULL,
|
||
EXPORT_TO_GIS DOM$BOOLEAN DEFAULT 0 NOT NULL
|
||
);
|
||
|
||
|
||
CREATE TABLE DOC$ABONENT$LAWSUIT (
|
||
ID D_KEY NOT NULL,
|
||
ID_CREATOR D_KEY NOT NULL,
|
||
ID_CLOSER D_KEY,
|
||
ID_BRANCH DOM$KEY NOT NULL,
|
||
ID_GROUP_DISTRICT DOM$KEY NOT NULL,
|
||
ID_TYPE_LAWSUIT DOM$KEY NOT NULL,
|
||
ID_KIND_LAWSUIT DOM$KEY NOT NULL,
|
||
ID_COURT_DISTRICT D_KEY,
|
||
ID_COURT_DISTRICT_DECISION DOM$KEY,
|
||
ID_ABONENT D_KEY NOT NULL,
|
||
ID_COURT_DECISION D_KEY,
|
||
ID_REASON_CANCEL D_KEY,
|
||
ID_BEGIN_PERIOD_DEBT DOM$PERIOD,
|
||
ID_END_PERIOD_DEBT DOM$PERIOD,
|
||
ID_PREPARE_REPRESENTATIVE DOM$KEY,
|
||
ID_SERVICE_COPYING_ERGN DOM$KEY,
|
||
ID_BT_COPYING_ERGN DOM$KEY,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP,
|
||
TIMESTAMP_CLOSING DOM$TIMESTAMP,
|
||
DATE_PREPARED DOM$DATE,
|
||
FILE_NUMBER DOM$NUMBER_FILE,
|
||
DEBT_GAS DOM$AMOUNT NOT NULL,
|
||
DEBT_MS DOM$AMOUNT NOT NULL,
|
||
DEBT_FINE DOM$AMOUNT NOT NULL,
|
||
DEBT_TOTAL COMPUTED BY (DEBT_GAS + DEBT_MS + DEBT_FINE),
|
||
COST_CERTIFICATE_ABOUT_FAMILY DOM$AMOUNT NOT NULL,
|
||
AMOUNT_LAWSUIT DOM$AMOUNT NOT NULL,
|
||
DUTY DOM$AMOUNT NOT NULL,
|
||
DATE_TRANSFERRED_TO_COURT DOM$DATE,
|
||
DECISION_GAS DOM$AMOUNT NOT NULL,
|
||
DECISION_MS DOM$AMOUNT NOT NULL,
|
||
DECISION_FINE DOM$AMOUNT NOT NULL,
|
||
DECISION_DUTY DOM$AMOUNT NOT NULL,
|
||
DECISION_COST_CAF DOM$BOOLEAN NOT NULL,
|
||
DECISION_AMOUNT_LAWSUIT COMPUTED BY (DECISION_GAS + DECISION_MS + DECISION_FINE),
|
||
DECISION_TOTAL COMPUTED BY (DECISION_GAS + DECISION_MS + DECISION_FINE + IIF(DECISION_COST_CAF = 1, COST_CERTIFICATE_ABOUT_FAMILY, 0) + DECISION_DUTY),
|
||
DUTY_SOLIDARED DOM$BOOLEAN,
|
||
STATE DOM$STATE NOT NULL,
|
||
CLOSED DOM$BOOLEAN NOT NULL,
|
||
COMMENT DOM$COMMENT,
|
||
DATE_CANCEL DOM$DATE,
|
||
COMMENT_CANCEL DOM$COMMENT,
|
||
COMMENT_DECISION DOM$COMMENT,
|
||
PAYMENT_GAS DOM$AMOUNT NOT NULL,
|
||
PAYMENT_MS DOM$AMOUNT NOT NULL,
|
||
PAYMENT_FINE DOM$AMOUNT NOT NULL,
|
||
PAYMENT_CAF DOM$AMOUNT NOT NULL,
|
||
PAYMENT_DUTY DOM$AMOUNT NOT NULL,
|
||
REST_AMOUNT_LAWSUIT DOM$AMOUNT NOT NULL,
|
||
DATE_BEGIN_LAWSUIT DOM$DATE,
|
||
DATE_END_LAWSUIT DOM$DATE,
|
||
LAWSUIT_FROM_AMURCC DOM$BOOLEAN NOT NULL,
|
||
FILE_NUMBER_SHORT D_VARCHAR_10,
|
||
NAME_LAWSUIT COMPUTED BY ('Иск' || TRIM(TRAILING FROM IIF(DATE_PREPARED IS NOT NULL, ' от ' || FORMAT_DATE(DATE_PREPARED), ' подготавливается'))
|
||
|| TRIM(TRAILING FROM IIF(FILE_NUMBER IS NOT NULL, ' №' || FILE_NUMBER, ''))
|
||
|| ' за ' || FORMAT_DATE(DATE_BEGIN_LAWSUIT) || ' - ' || FORMAT_DATE(DATE_END_LAWSUIT)),
|
||
REST_LAWSUIT_BY_MONTHS_DEBT DOM$AMOUNT
|
||
);
|
||
|
||
|
||
CREATE TABLE DOC$ABONENT$LAWSUIT_CITIZEN (
|
||
ID D_KEY NOT NULL,
|
||
ID_LAWSUIT D_KEY NOT NULL,
|
||
ID_CITIZEN D_KEY NOT NULL
|
||
);
|
||
|
||
|
||
CREATE TABLE DOC$COURT_PROCESS$SUMMONS (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_CREATOR DOM$KEY NOT NULL,
|
||
ID_GROUP_DISTRICT DOM$KEY NOT NULL,
|
||
ID_COURT_DISTRICT DOM$KEY NOT NULL,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP,
|
||
TIMESTAMP_POSTING DOM$TIMESTAMP,
|
||
DATE_SITTING DOM$DATE NOT NULL,
|
||
TIME_SITTING DOM$TIME NOT NULL,
|
||
QUANTITY D_QUANTITY NOT NULL,
|
||
AMOUNT_LAWSUIT DOM$AMOUNT NOT NULL,
|
||
AMOUNT_DUTY DOM$AMOUNT NOT NULL,
|
||
COST_CAF DOM$AMOUNT NOT NULL,
|
||
COMMENT DOM$COMMENT
|
||
);
|
||
|
||
|
||
CREATE TABLE DOC$COURT_PROCESS$SUMMONS_LAWSU (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_SUMMONS DOM$KEY NOT NULL,
|
||
ID_LAWSUIT DOM$KEY NOT NULL,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP NOT NULL,
|
||
NUMBER_FILE DOM$NUMBER_FILE,
|
||
COMMENT DOM$COMMENT
|
||
);
|
||
|
||
|
||
CREATE TABLE DOC$LAWSUIT$EXEC_PROC (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_WRIT_OF_EXEC DOM$KEY NOT NULL,
|
||
ID_CREATOR DOM$KEY NOT NULL,
|
||
ID_BUMBAILIFF_COMMENCEMENT DOM$KEY,
|
||
ID_BUMBAILIFF_EXPIRE DOM$KEY,
|
||
ID_REASON_EXPIRE DOM$KEY,
|
||
ID_BANK DOM$KEY,
|
||
ID_RESULT_BANK DOM$KEY,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP NOT NULL,
|
||
DATE_TRANSFERENCE DOM$DATE,
|
||
NUMBER DOM$NUMBER_EXEC_PROCESS,
|
||
DATE_COMMENCEMENT DOM$DATE,
|
||
DATE_OBTAIN_COMMENCEMENT DOM$DATE,
|
||
DATE_EXPIRE DOM$DATE,
|
||
DATE_OBTAIN_EXPIRE DOM$DATE,
|
||
DATE_OBTAIN_RESULT_BANK DOM$DATE,
|
||
TO_RECOVER_GAS DOM$AMOUNT NOT NULL,
|
||
TO_RECOVER_MS DOM$AMOUNT NOT NULL,
|
||
TO_RECOVER_FINE DOM$AMOUNT NOT NULL,
|
||
TO_RECOVER_CAF DOM$AMOUNT NOT NULL,
|
||
TO_RECOVER_DUTY DOM$AMOUNT NOT NULL,
|
||
TO_RECOVER_TOTAL COMPUTED BY (TO_RECOVER_GAS + TO_RECOVER_MS + TO_RECOVER_FINE + TO_RECOVER_CAF + TO_RECOVER_DUTY),
|
||
PAYMENT_GAS DOM$AMOUNT NOT NULL,
|
||
PAYMENT_MS DOM$AMOUNT NOT NULL,
|
||
PAYMENT_FINE DOM$AMOUNT NOT NULL,
|
||
PAYMENT_CAF DOM$AMOUNT NOT NULL,
|
||
PAYMENT_DUTY DOM$AMOUNT NOT NULL,
|
||
PAYMENT_TOTAL COMPUTED BY (PAYMENT_GAS + PAYMENT_MS + PAYMENT_FINE + PAYMENT_CAF + PAYMENT_DUTY),
|
||
STATE DOM$STATE NOT NULL,
|
||
NAME_STATE COMPUTED BY (TRIM(CASE STATE
|
||
WHEN 0 THEN 'Подготовлено в ОСП'
|
||
WHEN 1 THEN 'Исполнительный лист передан в ОСП'
|
||
WHEN 2 THEN 'В исполнительном производстве'
|
||
WHEN 3 THEN 'Исполнительное производство окончено'
|
||
WHEN 4 THEN 'Подготовлено для банка'
|
||
WHEN 5 THEN 'Передано в банк'
|
||
END)),
|
||
RECOVERED_AMOUNT DOM$AMOUNT NOT NULL,
|
||
COMMENT DOM$COMMENT,
|
||
NOT_RECOVERED_AMOUNT DOM$AMOUNT NOT NULL,
|
||
AUTO_DATE_COMMENCEMENT DOM$BOOLEAN NOT NULL,
|
||
AUTO_NUMBER DOM$BOOLEAN NOT NULL,
|
||
AUTO_DATE_EXPIRE DOM$BOOLEAN NOT NULL,
|
||
AUTO_REASON_EXPIRE DOM$BOOLEAN NOT NULL,
|
||
AUTO_ID_BUMBAILIFF_COMMENCEMENT DOM$BOOLEAN DEFAULT 0,
|
||
AMOUNT_BY_BAILIFF DOM$AMOUNT,
|
||
REST_AMOUNT_BY_BAILIFF DOM$AMOUNT,
|
||
DATE_RELEVANCE DOM$DATE
|
||
);
|
||
|
||
|
||
CREATE TABLE REG$ABONENT$CITIZEN (
|
||
ID D_KEY NOT NULL,
|
||
ID_CREATOR D_KEY NOT NULL,
|
||
ID_ABONENT D_KEY NOT NULL,
|
||
ID_GENDER DOM$KEY,
|
||
ID_KINSHIP DOM$KEY,
|
||
ID_PASSPORT_ISSUE D_KEY,
|
||
ID_PROPERTY_DOCUMENT DOM$KEY,
|
||
ID_ORG_PROVIDE_INF_ABOUT_OWNER DOM$KEY,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP NOT NULL,
|
||
SURNAME DOM$CITIZEN_SURNAME NOT NULL,
|
||
SURNAME_IN_GENETIVE DOM$CITIZEN_SURNAME,
|
||
SURNAME_IN_DATIVE DOM$CITIZEN_SURNAME,
|
||
MAIDEN_NAME DOM$CITIZEN_SURNAME,
|
||
NAME DOM$CITIZEN_NAME,
|
||
PATRONYMIC DOM$CITIZEN_PATRONYMIC,
|
||
DATE_BEGIN DOM$DATE,
|
||
DATE_END DOM$DATE,
|
||
IS_RESPONSIBILITY DOM$BOOLEAN NOT NULL,
|
||
IS_OWNER DOM$BOOLEAN NOT NULL,
|
||
IS_PENSIONER DOM$BOOLEAN NOT NULL,
|
||
SURNAME_NAME_PATRONYMIC COMPUTED BY (SURNAME || TRIM(TRAILING FROM IIF(NAME IS NOT NULL, ' ' || NAME || TRIM(TRAILING FROM IIF(PATRONYMIC IS NOT NULL, ' ' || PATRONYMIC, '')), '')))
|
||
);
|
||
|
||
|
||
CREATE TABLE DOC$LAWSUIT$WRIT_OF_EXEC (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_LAWSUIT DOM$KEY NOT NULL,
|
||
ID_CREATOR DOM$KEY NOT NULL,
|
||
ID_RESPONDENT DOM$KEY NOT NULL,
|
||
ID_REASON_CLOSE DOM$KEY,
|
||
ID_CURRENT_EXEC_PROCESS DOM$KEY,
|
||
ID_TYPE_WE DOM$KEY NOT NULL,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP NOT NULL,
|
||
NUMBER DOM$NUMBER_WRIT_EXEC,
|
||
NUMBER_WRIT_EXEC_FOR_DUTY DOM$NUMBER_WRIT_EXEC,
|
||
DATE_OBTAINING DOM$DATE,
|
||
DATE_CLOSE DOM$DATE,
|
||
AMOUNT_GAS DOM$AMOUNT NOT NULL,
|
||
AMOUNT_MS DOM$AMOUNT NOT NULL,
|
||
AMOUNT_FINE DOM$AMOUNT NOT NULL,
|
||
AMOUNT_CAF DOM$AMOUNT NOT NULL,
|
||
AMOUNT_DUTY DOM$AMOUNT NOT NULL,
|
||
AMOUNT_TOTAL COMPUTED BY (AMOUNT_GAS + AMOUNT_MS + AMOUNT_FINE + AMOUNT_CAF + AMOUNT_DUTY),
|
||
PAYMENT_GAS DOM$AMOUNT NOT NULL,
|
||
PAYMENT_MS DOM$AMOUNT NOT NULL,
|
||
PAYMENT_FINE DOM$AMOUNT NOT NULL,
|
||
PAYMENT_CAF DOM$AMOUNT NOT NULL,
|
||
PAYMENT_DUTY DOM$AMOUNT NOT NULL,
|
||
PAYMENT_TOTAL COMPUTED BY (PAYMENT_GAS + PAYMENT_MS + PAYMENT_FINE + PAYMENT_CAF + PAYMENT_DUTY),
|
||
STATE DOM$STATE NOT NULL,
|
||
NAME_STATE COMPUTED BY (TRIM(CASE STATE
|
||
WHEN 0 THEN 'Создан'
|
||
WHEN 1 THEN 'Получен'
|
||
WHEN 2 THEN 'Передан в ОСП'
|
||
WHEN 3 THEN 'В исполнительном производстве'
|
||
WHEN 4 THEN 'Отмена исполнительного производства'
|
||
WHEN 5 THEN 'Исполнен'
|
||
WHEN 6 THEN 'Отложено'
|
||
WHEN 7 THEN 'Закрыт'
|
||
WHEN 8 THEN 'Подготовлен для ОСП'
|
||
WHEN 9 THEN 'Подготовлен для банка'
|
||
WHEN 10 THEN 'Передан в банк'
|
||
WHEN 11 THEN 'Недействительный'
|
||
END)),
|
||
QUANTITY_EXEC_PROCESS COMPUTED BY ((SELECT COUNT(*) FROM DOC$LAWSUIT$EXEC_PROC EP WHERE EP.ID_WRIT_OF_EXEC = DOC$LAWSUIT$WRIT_OF_EXEC.ID)),
|
||
DATE_RETURNING DOM$DATE,
|
||
DATE_DEFER DOM$DATE,
|
||
BALANCE_GAS COMPUTED BY (AMOUNT_GAS - PAYMENT_GAS),
|
||
BALANCE_MS COMPUTED BY (AMOUNT_MS - PAYMENT_MS),
|
||
BALANCE_FINE COMPUTED BY (AMOUNT_FINE - PAYMENT_FINE),
|
||
BALANCE_CAF COMPUTED BY (AMOUNT_CAF - PAYMENT_CAF),
|
||
BALANCE_DUTY COMPUTED BY (AMOUNT_DUTY - PAYMENT_DUTY),
|
||
BALANCE_TOTAL COMPUTED BY (AMOUNT_TOTAL - PAYMENT_TOTAL),
|
||
COMMENT DOM$COMMENT,
|
||
IS_VALID DOM$BOOLEAN,
|
||
AUTO_NUMBER DOM$BOOLEAN DEFAULT 0 NOT NULL,
|
||
NAME COMPUTED BY ((SELECT C.SURNAME_NAME_PATRONYMIC FROM REG$ABONENT$CITIZEN C WHERE C.ID = ID_RESPONDENT) || TRIM(TRAILING FROM IIF(NUMBER IS NOT NULL, ' (' || NUMBER || ')', '')))
|
||
);
|
||
|
||
|
||
CREATE TABLE INF$DATABASE$CONST (
|
||
ID DOM$KEY NOT NULL,
|
||
DB_VERSION DOM$VERSION NOT NULL,
|
||
INTERVAL_AUTOREFRESH D_NATURAL NOT NULL,
|
||
MAX_ROWS_IN_HINT D_NATURAL NOT NULL,
|
||
MAX_FILTER_HISTORY D_NATURAL NOT NULL,
|
||
MAX_REPORT_HISTORY D_NATURAL NOT NULL,
|
||
MAX_NOTES_PER_USER D_NATURAL NOT NULL,
|
||
MAX_GLOBAL_ACTION_HISTORY D_NATURAL NOT NULL,
|
||
MAX_SEARCH_HISTORY D_NATURAL NOT NULL,
|
||
EMAIL_HOST D_VARCHAR_15,
|
||
MAX_INTERVAL_MS_IN_MONTH D_NATURAL NOT NULL,
|
||
MAX_DIGIT_IN_READING D_NATURAL NOT NULL,
|
||
SHOW_RECALC_DB_COMPENSATION DOM$BOOLEAN NOT NULL,
|
||
MAX_BOTTLES_FOR_REQUEST D_NATURAL NOT NULL,
|
||
MAX_BOTTLES_FOR_SELF_DELIVERY D_NATURAL NOT NULL,
|
||
MAX_BOTTLES_FOR_INDUSTRY D_NATURAL NOT NULL,
|
||
ONLY_COURT_WORK DOM$BOOLEAN NOT NULL,
|
||
DEFAULT_SERIES_WRIT_EXEC DOM$SERIES_WRIT_EXEC NOT NULL,
|
||
PATH_TO_EXPORT_RECEPTED_READING D_VARCHAR_100,
|
||
EDDS_SEND_INTERVAL D_NUMBER,
|
||
EDDS_LISTENING_PORT DOM$NETWORK_PORT,
|
||
EDDS_URL D_VARCHAR_100,
|
||
EDDS_LOCAL_SERVICE_IP D_VARCHAR_15,
|
||
USERNAME_FOR_SEND_EMAIL_TO_EXTE D_VARCHAR_10,
|
||
PASSWORD_FOR_SEND_EMAIL_TO_EXTE D_VARCHAR_10,
|
||
HOST_OF_BAILIFFS_FTP D_VARCHAR_15,
|
||
USERNAME_FOR_BAILIFFS_FTP D_VARCHAR_15,
|
||
PASSWORD_FOR_BAILIFFS_FTP D_VARCHAR_15,
|
||
NAME_FILE_FROM_BAILIFFS D_VARCHAR_25,
|
||
ENCRYPT_GROUP_NAME D_VARCHAR_10,
|
||
TIMESTAMP_LAST_BAILIFF_FILE DOM$TIMESTAMP,
|
||
PATH_SAVE_BAILIFF_FILE D_VARCHAR_255,
|
||
BAILIFF_UPLOAD_FILE_NAME DOM$NAME_SHORT,
|
||
DATE_LAST_BAILIFF_UPLOAD DOM$DATE,
|
||
USERNAME_EMAIL_READINGS DOM$NAME_SHORT,
|
||
PASSWORD_EMAIL_READINGS DOM$NAME_SHORT,
|
||
PATH_TO_DB_SITE D_VARCHAR_100,
|
||
DEFAULT_EDDS_INCOMING_REQUEST_M DOM$NAME_HUGE,
|
||
MASTER_BASE DOM$NAME_LONG,
|
||
PATH_TO_FOLDER_RECEIPTS D_VARCHAR_100,
|
||
PATH_TO_FOLDER_READINGS D_VARCHAR_100,
|
||
PATH_TO_STORE_SCANS D_VARCHAR_100,
|
||
CONNECTION_STRING_TO_FIAS_BASE D_VARCHAR_500,
|
||
DATE_IMPORTED_ABONENTS_AMURCC DOM$DATE,
|
||
DATE_IMPORTED_METERS DOM$DATE,
|
||
STEP_POS_FOR_HOUSE DOM$POSITION NOT NULL,
|
||
DAYS_PAYMENT_TICKET D_NATURAL NOT NULL,
|
||
MONTHS_BY_AVERAGE_WO_READINGS D_NATURAL NOT NULL,
|
||
MONTHS_AUTORECALC_GAS D_NATURAL NOT NULL,
|
||
IS_MASTER_DB DOM$BOOLEAN NOT NULL,
|
||
IS_DEVELOPER_DB DOM$BOOLEAN,
|
||
TRUSTED_AUTH DOM$BOOLEAN NOT NULL,
|
||
ONLY_ABONENT_NATURE_GAS DOM$BOOLEAN NOT NULL,
|
||
POSSYSTEM_ADDRESS D_VARCHAR_100,
|
||
POSSYSTEM_USER D_VARCHAR_15,
|
||
POSSYSTEM_PASSWORD D_VARCHAR_50,
|
||
POSSYSTEM_ITEM_PRODUCT D_NATURAL,
|
||
POSSYSTEM_ITEM_WORK D_NATURAL,
|
||
POSSYSTEM_ITEM_SERVICE D_NATURAL,
|
||
POSSYSTEM_ITEM_OTHER D_NATURAL,
|
||
PATH_TO_FILE_BANK_STATEMENT D_VARCHAR_50,
|
||
LAST_DATE_BANK_STATEMENT DOM$DATE,
|
||
DATE_PRICE_MS DOM$DATE
|
||
);
|
||
|
||
|
||
CREATE TABLE INF$PAYMENT$BANK_STTM (
|
||
ID DOM$KEY GENERATED BY DEFAULT AS IDENTITY,
|
||
ID_BRANCH DOM$KEY,
|
||
ID_BANK DOM$KEY,
|
||
ID_BAILIFF DOM$KEY,
|
||
DATE_ACCOUNT DOM$DATE NOT NULL,
|
||
DATE_PAYMENT DOM$DATE NOT NULL,
|
||
NUMBER DOM$NUMBER_CHECK NOT NULL,
|
||
AMOUNT DOM$AMOUNT NOT NULL,
|
||
CONTRACTOR DOM$NAME_CONTRACTOR NOT NULL,
|
||
PURPOSE D_VARCHAR_500 NOT NULL,
|
||
PAYER D_VARCHAR_200,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP,
|
||
RECEIPT_CREATED DOM$BOOLEAN_REAL DEFAULT FALSE NOT NULL,
|
||
IS_INDIVIDUAL_PAYMENT DOM$BOOLEAN_REAL DEFAULT FALSE NOT NULL,
|
||
NEED_RECEIPT COMPUTED BY (((ID_BANK IS NOT NULL) OR (ID_BAILIFF IS NOT NULL) OR (IS_INDIVIDUAL_PAYMENT IS TRUE)) AND (NOT RECEIPT_CREATED))
|
||
);
|
||
|
||
|
||
CREATE TABLE SYS$LINK$GASSUPPLY (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_PURPOSE_COOKING_FOOD DOM$KEY NOT NULL,
|
||
ID_PURPOSE_HEATING DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_NATURE_GAS_MANSION DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_TANK_GAS_MANSION DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_NATURE_GAS_PRIVATE DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_NG_PH_IN_CONNECT DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_TANK_GAS_MD DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_MS_FGE_MANSION DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_MS_HGE_PH DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_MS_FGE_WO_CHARGE DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_MS_FGE_CHARGE_OWNER DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_CGBU_MANSION DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_IGBU DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_IGBU_MANSION_WITH_ES DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_IGBU_MANSION_NO_ES DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_IGBU_PRIVATE_WITH_ES DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_IGBU_PRIVATE_NO_ES DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_CGBU_HEATING DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_IGBU_COTTAGE_AREA DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_IGBU_GARDENING DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_NO_CONNECT DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_UNKNOWN DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_BOTTLES_OF_CGBU DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_INDUSTRY_BOTTLE DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_DOMESTIC_BOTTLE DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_DOMESTIC_TANK_GAS DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_CLOSED DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_NATURE_GAS_FLAT_ORG DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_TANK_GAS_FLAT_ORG DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_NATURE_GAS_ORG DOM$KEY NOT NULL,
|
||
ID_TYPE_GS_TANK_GAS_ORG DOM$KEY NOT NULL,
|
||
ID_TYPE_GAS_DISCONN_NETWORK_GAS DOM$KEY NOT NULL,
|
||
ID_TYPE_GAS_NATURE_GAS DOM$KEY NOT NULL,
|
||
ID_TYPE_GAS_LIQUEFIED_GAS DOM$KEY NOT NULL,
|
||
ID_TYPE_GAS_ABSENCE DOM$KEY NOT NULL,
|
||
ID_GIS_PUBLIC_SERVICE_GAS DOM$KEY,
|
||
ID_GIS_TYPE_GAS_NATURE DOM$KEY,
|
||
ID_GIS_TYPE_GAS_TANK DOM$KEY,
|
||
ID_GROUP_TYPE_GS_MANSION DOM$KEY NOT NULL,
|
||
ID_GROUP_TYPE_GS_NGPH DOM$KEY NOT NULL,
|
||
ID_GROUP_TYPE_GS_DEPARTMENT DOM$KEY NOT NULL,
|
||
ID_DEFAULT_TYPE_NORM DOM$KEY NOT NULL,
|
||
ID_TYPE_GAS_UNKNOWN DOM$KEY
|
||
);
|
||
|
||
|
||
CREATE TABLE SYS$LINK$PAYMENT (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_SOURCE_BY_LIST_DB DOM$KEY,
|
||
ID_SOURCE_ALIGNMENT_BALANCE DOM$KEY NOT NULL,
|
||
ID_SOURCE_TRANSFER_PAYMENT DOM$KEY NOT NULL,
|
||
ID_SOURCE_TRANSFER_BALANCE DOM$KEY,
|
||
ID_SOURCE_SBERBANK DOM$KEY,
|
||
ID_SOURCE_SBERBANK_INVOICE DOM$KEY NOT NULL,
|
||
ID_SOURCE_POST DOM$KEY,
|
||
ID_SOURCE_SITE DOM$KEY NOT NULL,
|
||
ID_METHOD_DISTRIB_BY_MONTHS_DEB DOM$KEY NOT NULL,
|
||
ID_METHOD_DISTRIB_ONE_SERVICE DOM$KEY NOT NULL,
|
||
ID_METHOD_DISTRIB_TWO_SERVICE DOM$KEY NOT NULL,
|
||
ID_METHOD_DISTRIB_NO_CHANGE DOM$KEY NOT NULL,
|
||
ID_TYPE_RECEIPT_TRANSFER DOM$KEY,
|
||
ID_TYPE_RECEIPT_VIA_BAILIFF DOM$KEY,
|
||
ID_TYPE_RECEIPT_STATEMENT_CS DOM$KEY NOT NULL,
|
||
ID_TYPE_RECEIPT_MS_IGBU DOM$KEY NOT NULL,
|
||
ID_TYPE_RECEIPT_COURT_EXPENSES DOM$KEY NOT NULL,
|
||
ID_TYPE_SOURCE_NONACCEPT_BANK DOM$KEY,
|
||
ID_TYPE_SOURCE_BAILIFF DOM$KEY,
|
||
ID_TYPE_SOURCE_PENSION_FUND DOM$KEY,
|
||
ID_SOURCE_MTSBANK DOM$KEY,
|
||
ID_SOURCE_NONACCEPT_SB DOM$KEY,
|
||
ID_SOURCE_NONACCEPT_MTSBANK DOM$KEY,
|
||
ID_SOURCE_NONACCEPT_VTB24 DOM$KEY,
|
||
ID_SOURCE_NONACCEPT_ROSBANK DOM$KEY,
|
||
ID_SOURCE_NONACCEPT_VOSTEXPRESS DOM$KEY,
|
||
ID_SOURCE_NONACCEPT_OTKRYTIE DOM$KEY,
|
||
ID_SOURCE_RKC_SOVGAVAN DOM$KEY,
|
||
ID_SOURCE_ERKC_KOMS DOM$KEY,
|
||
ID_SOURCE_ERKC_KOMS_CASHLESS DOM$KEY,
|
||
ID_SOURCE_BAILIFF DOM$KEY,
|
||
ID_SOURCE_SITE_AMURCC DOM$KEY,
|
||
ID_SOURCE_ADVICE DOM$KEY,
|
||
ID_SOURCE_RETURN DOM$KEY
|
||
);
|
||
|
||
|
||
CREATE TABLE SYS$LOG$EXCEPTION (
|
||
ID DOM$KEY NOT NULL,
|
||
ID_CREATOR DOM$KEY NOT NULL,
|
||
ID_EXCEPTION DOM$KEY NOT NULL,
|
||
TIMESTAMP_CREATION DOM$CURRENT_TIMESTAMP,
|
||
TEXT DOM$TEXT_EXCEPTION NOT NULL
|
||
);
|
||
|
||
|
||
CREATE GLOBAL TEMPORARY TABLE TMP$PAYMENT$BANK_STTM (
|
||
POS DOM$POSITION GENERATED BY DEFAULT AS IDENTITY,
|
||
LINE D_VARCHAR_500 NOT NULL
|
||
) ON COMMIT DELETE ROWS;
|
||
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Autoincrement generators ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
ALTER TABLE DIR$ENTPR$IND_PAYMENT ALTER ID RESTART WITH 8;
|
||
ALTER TABLE DIR$EXEC_PROC$BANK_PURPOSE ALTER ID RESTART WITH 2;
|
||
ALTER TABLE DIR$EXEC_PROC$CORRECTION ALTER ID RESTART WITH 99;
|
||
ALTER TABLE INF$PAYMENT$BANK_STTM ALTER ID RESTART WITH 12934;
|
||
ALTER TABLE TMP$PAYMENT$BANK_STTM ALTER POS RESTART WITH 531285;
|
||
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Unique constraints ***/
|
||
/******************************************************************************/
|
||
|
||
ALTER TABLE DIR$PAYMENT$SOURCE ADD CONSTRAINT UNQ_DIR$PAYMENT$SOURCE_NAME UNIQUE (NAME);
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Primary keys ***/
|
||
/******************************************************************************/
|
||
|
||
ALTER TABLE BAT$RECEIPT$BATCH ADD CONSTRAINT PK_BAT$RECEIPT$BATCH PRIMARY KEY (ID);
|
||
ALTER TABLE BAT$RECEIPT$RECEIPT ADD CONSTRAINT PK_BAT$RECEIPT$RECEIPT PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$ABONENT$ABONENT ADD CONSTRAINT PK_DIR$ABONENT$ABONENT PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$DATABASE$DATABASE ADD CONSTRAINT PK_DIR$DATABASE$DATABASE PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$ENTERPRISE$BRANCH ADD CONSTRAINT PK_DIR$ENTERPRISE$BRANCH PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$ENTERPRISE$GROUP_DISTRICT ADD CONSTRAINT PK_DIR$ENTERPRISE$GROUP_DISTRIC PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$ENTPR$IND_PAYMENT ADD CONSTRAINT PK_DIR$ENTPR$IND_PAYMENT PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$EXEC_PROC$BANK ADD CONSTRAINT PK_DIR$EXEC_PROC$BANK PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$EXEC_PROC$BANK_PURPOSE ADD CONSTRAINT PK_DIR$EXEC_PROC$BANK_PURPOSE PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$EXEC_PROC$CORRECTION ADD CONSTRAINT PK_DIR$EXEC_PROC$CORRECTION PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$GASSUPPLY$TYPE_GS ADD CONSTRAINT PK_DIR$GASSUPPLY$TYPE_GS PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$PAYMENT$SOURCE ADD CONSTRAINT PK_DIR$PAYMENT$SOURCE PRIMARY KEY (ID);
|
||
ALTER TABLE DIR$PAYMENT$SOURCE_GD ADD CONSTRAINT PK_DIR$PAYMENT$SOURCE_GD PRIMARY KEY (ID_SOURCE, ID_GROUP_DISTRICT);
|
||
ALTER TABLE DOC$ABONENT$LAWSUIT ADD CONSTRAINT PK_DOC$ABONENT$LAWSUIT PRIMARY KEY (ID);
|
||
ALTER TABLE DOC$ABONENT$LAWSUIT_CITIZEN ADD CONSTRAINT PK_DOC$ABONENT$LAWSUIT_CITIZEN PRIMARY KEY (ID);
|
||
ALTER TABLE DOC$COURT_PROCESS$SUMMONS ADD CONSTRAINT PK_DOC$COURT_PROCESS$SUMMONS PRIMARY KEY (ID);
|
||
ALTER TABLE DOC$COURT_PROCESS$SUMMONS_LAWSU ADD CONSTRAINT PK_DOC$COURT_PROCESS$SUMMONS_LA PRIMARY KEY (ID);
|
||
ALTER TABLE INF$DATABASE$CONST ADD CONSTRAINT PK_INF$DATABASE$CONST PRIMARY KEY (ID);
|
||
ALTER TABLE INF$PAYMENT$BANK_STTM ADD CONSTRAINT PK_INF$PAYMENT$BANK_STTM PRIMARY KEY (ID);
|
||
ALTER TABLE REG$ABONENT$CITIZEN ADD CONSTRAINT PK_REG$ABONENT$CITIZEN PRIMARY KEY (ID);
|
||
ALTER TABLE SYS$LINK$GASSUPPLY ADD CONSTRAINT PK_SYS$LINK$GASSUPPLY PRIMARY KEY (ID);
|
||
ALTER TABLE SYS$LINK$PAYMENT ADD CONSTRAINT PK_SYS$LINK$PAYMENT PRIMARY KEY (ID);
|
||
ALTER TABLE SYS$LOG$EXCEPTION ADD CONSTRAINT PK_SYS$LOG$EXCEPTION PRIMARY KEY (ID);
|
||
ALTER TABLE TMP$PAYMENT$BANK_STTM ADD CONSTRAINT PK_TMP$PAYMENT$BANK_STTM PRIMARY KEY (POS);
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Stored procedures ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
|
||
SET TERM ^ ;
|
||
|
||
ALTER PROCEDURE GET$ABONENT$CHARGING_GAS_AMURCC (
|
||
ID_ABONENT DOM$ABONENT NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$BOOLEAN)
|
||
AS
|
||
BEGIN
|
||
RESULT = 1;
|
||
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
ALTER PROCEDURE GET$ABONENT$DEFAULT_TYPE_RECEIP (
|
||
ID_ABONENT DOM$ABONENT NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$KEY)
|
||
AS
|
||
BEGIN
|
||
RESULT = (SELECT TG.ID_TYPE_RECEIPT FROM DIR$ABONENT$ABONENT A INNER JOIN DIR$GASSUPPLY$TYPE_GS TG ON TG.ID = A.ID_TYPE_GASSUPPLY WHERE A.ID = :ID_ABONENT);
|
||
IF (:RESULT IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA_ABONE(:ID_ABONENT, 'Нет типа квитанции по умолчанию.');
|
||
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
ALTER PROCEDURE GET$ABONENT$DETERMINE_GD (
|
||
ID_ABONENT DOM$ABONENT_LONG NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$KEY)
|
||
AS
|
||
BEGIN
|
||
IF (CHAR_LENGTH(:ID_ABONENT) = 6) THEN
|
||
RESULT = 15;-- Сахалин
|
||
ELSE IF (CHAR_LENGTH(:ID_ABONENT) = 12) THEN
|
||
RESULT = 12;-- Камчатка АИС РНГ
|
||
ELSE IF (LEFT(ID_ABONENT, 1) IN ('3', '4')) THEN
|
||
RESULT = 1;-- Центральный офис
|
||
ELSE IF (LEFT(ID_ABONENT, 3) = '998') THEN
|
||
RESULT = 2;-- Комсомольск
|
||
ELSE IF (LEFT(ID_ABONENT, 3) = '997') THEN
|
||
RESULT = 3;-- Амурск
|
||
ELSE IF (LEFT(ID_ABONENT, 3) = '996') THEN
|
||
RESULT = 2;-- Солнечный// По письму Смиринской Е.А. от 19.03.2019 создание сделано в Комсомольском участке
|
||
ELSE IF (LEFT(ID_ABONENT, 3) = '994') THEN
|
||
RESULT = 5;-- Чегдомын
|
||
ELSE IF ((LEFT(ID_ABONENT, 6) IN ('995000', '995001')) OR (LEFT(ID_ABONENT, 5) = '99504')) THEN
|
||
RESULT = 2;--6;-- Богородское
|
||
ELSE IF (LEFT(ID_ABONENT, 2) = '98') THEN
|
||
RESULT = 7;-- Совгавань
|
||
-- Обработка раньше, чтобы не попал в Хор
|
||
ELSE IF (LEFT(ID_ABONENT, 3) = '892') THEN
|
||
RESULT = 12;-- Камчатка
|
||
ELSE IF ((LEFT(ID_ABONENT, 3) = '291') OR (LEFT(ID_ABONENT, 3) = '292')) THEN
|
||
RESULT = 14;-- Лермонтовка
|
||
ELSE IF ((LEFT(ID_ABONENT, 1) = '2') OR (LEFT(ID_ABONENT, 2) = '92')) THEN
|
||
RESULT = 8;-- Бикин
|
||
ELSE IF ((LEFT(ID_ABONENT, 1) = '1') OR (LEFT(ID_ABONENT, 2) = '91')) THEN
|
||
RESULT = 9;-- Вяземский
|
||
ELSE IF ((LEFT(ID_ABONENT, 1) = '6') OR (LEFT(ID_ABONENT, 3) = '962')) THEN
|
||
RESULT = 10;-- Переяславка
|
||
ELSE IF ((LEFT(ID_ABONENT, 1) = '8') OR (LEFT(ID_ABONENT, 3) = '961')) THEN
|
||
RESULT = 11;-- Хор
|
||
ELSE IF (LEFT(ID_ABONENT, 6) IN ('995002', '995003')) THEN
|
||
RESULT = 2;--13;-- Де-Кастри
|
||
ELSE
|
||
RESULT = 0;-- Неизвестно
|
||
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
ALTER PROCEDURE GET$WRIT_EXEC$CHECK_RESPONDENT (
|
||
ID_WRIT_EXEC DOM$KEY NOT NULL,
|
||
RESPONDENT D_VARCHAR_100 NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$BOOLEAN)
|
||
AS
|
||
DECLARE VARIABLE RESP_WRIT_EXEC D_VARCHAR_100;
|
||
BEGIN
|
||
RESP_WRIT_EXEC = (SELECT UPPER(C.SURNAME_NAME_PATRONYMIC) FROM DOC$LAWSUIT$WRIT_OF_EXEC WE INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = WE.ID_RESPONDENT WHERE WE.ID = :ID_WRIT_EXEC);
|
||
RESP_WRIT_EXEC = REPLACE(:RESP_WRIT_EXEC, ' КЫЗЫ', '');
|
||
RESP_WRIT_EXEC = REPLACE(:RESP_WRIT_EXEC, ' ОГЛЫ', '');
|
||
RESP_WRIT_EXEC = REPLACE(:RESP_WRIT_EXEC, 'Й', 'И');
|
||
RESPONDENT = REPLACE(:RESP_WRIT_EXEC, 'Й', 'И');
|
||
|
||
RESULT = IIF(:RESP_WRIT_EXEC IS NOT DISTINCT FROM :RESPONDENT, 1, 0);
|
||
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
ALTER PROCEDURE GET$WRIT_EXEC$SEARCH_BY_RESPOND (
|
||
NUMBER_FILE DOM$NUMBER_FILE NOT NULL,
|
||
RESPONDENT D_VARCHAR_100 NOT NULL)
|
||
RETURNS (
|
||
RESULT DOM$KEY)
|
||
AS
|
||
DECLARE VARIABLE ID_CURRENT_WRIT_EXEC DOM$KEY;
|
||
DECLARE VARIABLE CURRENT_RESPONDENT D_VARCHAR_100;
|
||
DECLARE VARIABLE SEARCHED D_NATURAL;
|
||
DECLARE VARIABLE WITH_MAIDEN_NAME D_VARCHAR_100;
|
||
BEGIN
|
||
SEARCHED = 0;
|
||
|
||
RESPONDENT = UPPER(REPLACE(:RESPONDENT, 'Ё', 'Е'));
|
||
|
||
FOR SELECT
|
||
WE.ID,
|
||
UPPER(C.SURNAME_NAME_PATRONYMIC),
|
||
IIF(C.MAIDEN_NAME IS NOT NULL, UPPER(C.MAIDEN_NAME || ' ' || C.NAME || ' ' || C.PATRONYMIC), NULL)
|
||
FROM
|
||
DOC$ABONENT$LAWSUIT L
|
||
INNER JOIN DOC$LAWSUIT$WRIT_OF_EXEC WE ON WE.ID_LAWSUIT = L.ID
|
||
INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = WE.ID_RESPONDENT
|
||
WHERE
|
||
(L.FILE_NUMBER STARTING WITH :NUMBER_FILE)
|
||
AND (L.STATE NOT IN (3, 5))
|
||
INTO
|
||
:ID_CURRENT_WRIT_EXEC,
|
||
:CURRENT_RESPONDENT,
|
||
:WITH_MAIDEN_NAME
|
||
DO
|
||
BEGIN
|
||
CURRENT_RESPONDENT = REPLACE(:CURRENT_RESPONDENT, 'Ё', 'Е');
|
||
IF (RIGHT(:CURRENT_RESPONDENT, 5) = ' ОГЛЫ') THEN
|
||
CURRENT_RESPONDENT = LEFT(:CURRENT_RESPONDENT, CHAR_LENGTH(:CURRENT_RESPONDENT) - 5);
|
||
IF (RIGHT(:CURRENT_RESPONDENT, 5) = ' КЫЗЫ') THEN
|
||
CURRENT_RESPONDENT = LEFT(:CURRENT_RESPONDENT, CHAR_LENGTH(:CURRENT_RESPONDENT) - 5);
|
||
|
||
IF (:CURRENT_RESPONDENT IS NOT DISTINCT FROM :RESPONDENT) THEN
|
||
BEGIN
|
||
RESULT = :ID_CURRENT_WRIT_EXEC;
|
||
|
||
SEARCHED = :SEARCHED + 1;
|
||
IF (:SEARCHED > 1) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Найдено более 1 иска по делу №' || :NUMBER_FILE || ' ответчика ' || :RESPONDENT);
|
||
|
||
SUSPEND;
|
||
|
||
-- В КФ есть иск, где два ответчика с одинаковыми ФИО, но разным годом рождения. Если это тот случай, пропускаем второго ответчика
|
||
IF ((:NUMBER_FILE = '2-443/2018') AND (:RESPONDENT = 'СТАРЧЕНКОВ ВЛАДИМИР ВЛАДИМИРОВИЧ')) THEN
|
||
EXIT;
|
||
-- В ЦО есть иск, где два ответчика с одинаковыми ФИО, но разным годом рождения. Если это тот случай, пропускаем второго ответчика
|
||
IF ((:NUMBER_FILE = '2-3197/2018') AND (:RESPONDENT = 'СЫРОВА ТАТЬЯНА ВЛАДИМИРОВНА')) THEN
|
||
EXIT;
|
||
END
|
||
|
||
-- Ищем по девичьей фамилии
|
||
IF (:WITH_MAIDEN_NAME IS NOT NULL) THEN
|
||
BEGIN
|
||
CURRENT_RESPONDENT = :WITH_MAIDEN_NAME;
|
||
|
||
CURRENT_RESPONDENT = REPLACE(:CURRENT_RESPONDENT, 'Ё', 'Е');
|
||
IF (RIGHT(:CURRENT_RESPONDENT, 5) = ' ОГЛЫ') THEN
|
||
CURRENT_RESPONDENT = LEFT(:CURRENT_RESPONDENT, CHAR_LENGTH(:CURRENT_RESPONDENT) - 5);
|
||
IF (RIGHT(:CURRENT_RESPONDENT, 5) = ' КЫЗЫ') THEN
|
||
CURRENT_RESPONDENT = LEFT(:CURRENT_RESPONDENT, CHAR_LENGTH(:CURRENT_RESPONDENT) - 5);
|
||
|
||
IF (:CURRENT_RESPONDENT IS NOT DISTINCT FROM :RESPONDENT) THEN
|
||
BEGIN
|
||
RESULT = :ID_CURRENT_WRIT_EXEC;
|
||
|
||
SEARCHED = :SEARCHED + 1;
|
||
IF (:SEARCHED > 1) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Найдено более 1 иска по делу №' || :NUMBER_FILE || ' ответчика ' || :RESPONDENT);
|
||
SUSPEND;
|
||
END
|
||
END
|
||
END
|
||
|
||
IF (:SEARCHED = 0) THEN
|
||
SUSPEND;
|
||
END^
|
||
|
||
|
||
ALTER PROCEDURE OPER$EXCEPTION$CANCEL (
|
||
TEXT D_VARCHAR_500)
|
||
AS
|
||
BEGIN
|
||
IF ((SELECT MON$READ_ONLY FROM MON$TRANSACTIONS WHERE MON$TRANSACTION_ID = CURRENT_TRANSACTION) = 0) THEN
|
||
IN AUTONOMOUS TRANSACTION DO
|
||
INSERT INTO SYS$LOG$EXCEPTION
|
||
(ID, ID_EXCEPTION, TEXT)
|
||
VALUES
|
||
(NEXT VALUE FOR SEQ_SYS$LOG$EXCEPTION_ID, 8, :TEXT);
|
||
|
||
EXCEPTION EXC$CANCEL :TEXT;
|
||
END^
|
||
|
||
|
||
ALTER PROCEDURE OPER$EXCEPTION$CHECK_DATA (
|
||
TEXT D_VARCHAR_500)
|
||
AS
|
||
BEGIN
|
||
IF (RDB$GET_CONTEXT('SYSTEM', 'READ_ONLY') = 'FALSE') THEN
|
||
IN AUTONOMOUS TRANSACTION DO
|
||
INSERT INTO SYS$LOG$EXCEPTION
|
||
(ID, ID_EXCEPTION, TEXT)
|
||
VALUES
|
||
(NEXT VALUE FOR SEQ_SYS$LOG$EXCEPTION_ID, 7, :TEXT);
|
||
|
||
EXCEPTION EXC$CHECK_DATA :TEXT;
|
||
END^
|
||
|
||
|
||
ALTER PROCEDURE OPER$EXCEPTION$CHECK_DATA_ABONE (
|
||
ID_ABONENT DOM$ABONENT NOT NULL,
|
||
TEXT D_VARCHAR_500 NOT NULL)
|
||
AS
|
||
BEGIN
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA(COALESCE((SELECT RESULT FROM GET$ABONENT$ABONENT_AND_ADDRESS(:ID_ABONENT)), :ID_ABONENT) || '.' || ASCII_CHAR(31) || :TEXT);
|
||
END^
|
||
|
||
|
||
ALTER PROCEDURE OPER$EXCEPTION$CHECK_DATA_BRANC (
|
||
ID_BRANCH DOM$KEY NOT NULL,
|
||
TEXT D_VARCHAR_500 NOT NULL)
|
||
AS
|
||
BEGIN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA((SELECT B.INTERNAL_NAME FROM DIR$ENTERPRISE$BRANCH B WHERE B.ID = :ID_BRANCH) || '.' || ASCII_CHAR(31) || :TEXT);
|
||
END^
|
||
|
||
|
||
|
||
SET TERM ; ^
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Stored functions ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
|
||
SET TERM ^ ;
|
||
|
||
ALTER FUNCTION DATE_TO_PERIOD (
|
||
VAL DOM$DATE)
|
||
RETURNS DOM$PERIOD
|
||
AS
|
||
BEGIN
|
||
RETURN 1;
|
||
END^
|
||
|
||
|
||
ALTER FUNCTION DEC_PERIOD (
|
||
VAL DOM$PERIOD)
|
||
RETURNS DOM$PERIOD
|
||
AS
|
||
begin
|
||
/* Function Text */
|
||
return 1;
|
||
end^
|
||
|
||
|
||
ALTER FUNCTION FORMAT_DATE (
|
||
ARG DOM$DATE)
|
||
RETURNS DOM$STRING_DATE
|
||
AS
|
||
BEGIN
|
||
IF (:ARG IS NOT NULL) THEN
|
||
RETURN RIGHT(:ARG, 2) || '.' || SUBSTRING(:ARG FROM 6 FOR 2) || '.' || LEFT(:ARG, 4);
|
||
ELSE
|
||
RETURN '<NULL>';
|
||
END^
|
||
|
||
|
||
|
||
SET TERM ; ^
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Package headers ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
|
||
SET TERM ^ ;
|
||
|
||
|
||
SET TERM ; ^
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Package bodies ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
|
||
SET TERM ^ ;
|
||
|
||
CREATE PACKAGE BODY PKG$ABONENT
|
||
AS
|
||
BEGIN
|
||
FUNCTION GET_GROUP_DISTRICT_FOR_PAYMENT(ID_ABONENT DOM$ABONENT NOT NULL) RETURNS DOM$KEY DETERMINISTIC
|
||
AS
|
||
DECLARE VARIABLE ID_BRANCH DOM$KEY;
|
||
BEGIN
|
||
RETURN (SELECT A.ID_BRANCH FROM DIR$ABONENT$ABONENT A WHERE A.ID = :ID_ABONENT);
|
||
END
|
||
END^
|
||
|
||
|
||
CREATE PACKAGE BODY PKG$CONNECT
|
||
AS
|
||
BEGIN
|
||
FUNCTION ID_USER() RETURNS DOM$KEY DETERMINISTIC
|
||
AS
|
||
BEGIN
|
||
RETURN RDB$GET_CONTEXT('USER_SESSION', 'ID_USER');
|
||
END
|
||
|
||
FUNCTION ID_DIVISION() RETURNS DOM$KEY DETERMINISTIC
|
||
AS
|
||
BEGIN
|
||
RETURN RDB$GET_CONTEXT('USER_SESSION', 'ID_DIVISION');
|
||
END
|
||
|
||
FUNCTION ID_WORKER() RETURNS DOM$KEY DETERMINISTIC
|
||
AS
|
||
BEGIN
|
||
RETURN RDB$GET_CONTEXT('USER_SESSION', 'ID_WORKER');
|
||
END
|
||
|
||
FUNCTION ID_CS() RETURNS DOM$KEY DETERMINISTIC
|
||
AS
|
||
BEGIN
|
||
RETURN RDB$GET_CONTEXT('USER_SESSION', 'ID_CS');
|
||
END
|
||
|
||
FUNCTION ID_BRANCH() RETURNS DOM$KEY DETERMINISTIC
|
||
AS
|
||
BEGIN
|
||
RETURN RDB$GET_CONTEXT('USER_SESSION', 'ID_BRANCH');
|
||
END
|
||
|
||
FUNCTION ID_GROUP_DISTRICT() RETURNS DOM$KEY DETERMINISTIC
|
||
AS
|
||
BEGIN
|
||
RETURN RDB$GET_CONTEXT('USER_SESSION', 'ID_GROUP_DISTRICT');
|
||
END
|
||
|
||
FUNCTION CURRENT_USER_SURNAME_NP RETURNS D_VARCHAR_50 DETERMINISTIC
|
||
AS
|
||
BEGIN
|
||
RETURN NULL;
|
||
END
|
||
END^
|
||
|
||
|
||
CREATE PACKAGE BODY PKG$EXCEPTION
|
||
AS
|
||
BEGIN
|
||
PROCEDURE FOR_CITIZEN(ID_CITIZEN DOM$KEY NOT NULL, TEXT D_VARCHAR_500 NOT NULL)
|
||
AS
|
||
DECLARE VARIABLE ID_ABONENT DOM$ABONENT;
|
||
BEGIN
|
||
END
|
||
|
||
PROCEDURE FOR_WORKER(ID_WORKER DOM$KEY NOT NULL, TEXT D_VARCHAR_500 NOT NULL)
|
||
AS
|
||
BEGIN
|
||
END
|
||
|
||
PROCEDURE FOR_BATCH_RECEIPT(ID_BATCH DOM$KEY NOT NULL, TEXT D_VARCHAR_500 NOT NULL)
|
||
AS
|
||
BEGIN
|
||
END
|
||
END^
|
||
|
||
|
||
CREATE PACKAGE BODY PKG$PAYMENT$BANK_STTM
|
||
AS
|
||
BEGIN
|
||
PROCEDURE GET_LIST_BRANCH RETURNS (ID DOM$KEY, NAME DOM$NAME_STANDARD)
|
||
AS
|
||
BEGIN
|
||
FOR SELECT
|
||
B.ID,
|
||
B.INTERNAL_NAME
|
||
FROM
|
||
DIR$ENTERPRISE$BRANCH B
|
||
WHERE
|
||
B.USE_FOR_BANK_STATEMENT IS TRUE
|
||
ORDER BY
|
||
B.POS
|
||
INTO
|
||
:ID,
|
||
:NAME
|
||
DO
|
||
SUSPEND;
|
||
END
|
||
|
||
PROCEDURE PARSE_PAYMENT_ORDERS
|
||
AS
|
||
DECLARE VARIABLE POS DOM$POSITION;
|
||
DECLARE VARIABLE LINE D_VARCHAR_500;
|
||
DECLARE VARIABLE NAME_BANK D_VARCHAR_100;
|
||
DECLARE VARIABLE DATE_ACCOUNT DOM$DATE;
|
||
DECLARE VARIABLE DATE_PAYMENT DOM$DATE;
|
||
DECLARE VARIABLE NUMBER_DOC DOM$NUMBER_CHECK;
|
||
DECLARE VARIABLE AMOUNT DOM$AMOUNT;
|
||
DECLARE VARIABLE PURPOSE D_VARCHAR_500;
|
||
DECLARE VARIABLE PAYER D_VARCHAR_200;
|
||
DECLARE VARIABLE SHIFT_LINE D_NATURAL;
|
||
DECLARE VARIABLE LAST_DATE_BANK_STATEMENT DOM$DATE;
|
||
DECLARE VARIABLE MAX_DATE_ACCOUNT DOM$DATE;
|
||
BEGIN
|
||
-- Проверяем наличие платежей
|
||
IF (NOT EXISTS(SELECT 1 FROM TMP$PAYMENT$BANK_STTM)) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CANCEL('Таблица выписки из банка пуста.');
|
||
|
||
--
|
||
LAST_DATE_BANK_STATEMENT = (SELECT LAST_DATE_BANK_STATEMENT FROM INF$DATABASE$CONST);
|
||
IF (:LAST_DATE_BANK_STATEMENT IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CANCEL('Не указана дата последней выписки из банка.');
|
||
|
||
MAX_DATE_ACCOUNT = :LAST_DATE_BANK_STATEMENT;
|
||
|
||
--
|
||
FOR SELECT
|
||
P.POS,
|
||
P.LINE
|
||
FROM
|
||
TMP$PAYMENT$BANK_STTM P
|
||
WHERE
|
||
P.LINE STARTING WITH 'НазначениеПлатежа='
|
||
INTO
|
||
:POS,
|
||
:LINE
|
||
DO
|
||
BEGIN
|
||
-- У документа может отсутствовать поле "ПолучательКорсчет="
|
||
SHIFT_LINE = IIF(LEFT((SELECT LINE FROM TMP$PAYMENT$BANK_STTM WHERE POS = :POS - 13), 18) = 'ПолучательКорсчет=', 0, 1);
|
||
|
||
-- Определяем банк
|
||
NAME_BANK = SUBSTRING((SELECT LINE FROM TMP$PAYMENT$BANK_STTM WHERE POS = :POS - 24 + :SHIFT_LINE) FROM 17);-- Пропускаем слово "ПлательщикБанк1="
|
||
IF (:NAME_BANK IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('По п/п №' || :NUMBER_DOC || ' не указано название банка');
|
||
|
||
-- Определяем номер документа
|
||
NUMBER_DOC = RIGHT(SUBSTRING((SELECT P.LINE FROM TMP$PAYMENT$BANK_STTM P WHERE P.POS = :POS - 33 + :SHIFT_LINE) FROM 7), 6);-- Пропускаем слово "Номер="
|
||
|
||
-- Определяем дату оплаты
|
||
DATE_PAYMENT = SUBSTRING((SELECT P.LINE FROM TMP$PAYMENT$BANK_STTM P WHERE P.POS = :POS - 32 + :SHIFT_LINE) FROM 6);-- Пропускаем слово "Дата="
|
||
|
||
-- Определяем дату учета
|
||
DATE_ACCOUNT = NULLIF(SUBSTRING((SELECT P.LINE FROM TMP$PAYMENT$BANK_STTM P WHERE P.POS = :POS - 20 + :SHIFT_LINE) FROM 15), '');-- Пропускаем слово "ДатаПоступило="
|
||
IF (:DATE_ACCOUNT IS NULL) THEN
|
||
CONTINUE;
|
||
|
||
IF (:DATE_ACCOUNT <= :LAST_DATE_BANK_STATEMENT) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Дата учета (' || FORMAT_DATE(:DATE_ACCOUNT)
|
||
|| ') у документа №' || :NUMBER_DOC || ' меньше или равна дате последней загрузки выписки (' || FORMAT_DATE(:LAST_DATE_BANK_STATEMENT) || ')');
|
||
|
||
IF (:DATE_ACCOUNT > :MAX_DATE_ACCOUNT) THEN
|
||
MAX_DATE_ACCOUNT = :DATE_ACCOUNT;
|
||
|
||
-- Определяем сумму платежа
|
||
AMOUNT = SUBSTRING((SELECT P.LINE FROM TMP$PAYMENT$BANK_STTM P WHERE P.POS = :POS - 31 + :SHIFT_LINE) FROM 7);-- Пропускаем слово "Сумма="
|
||
|
||
-- Определяем назначение
|
||
PURPOSE = SUBSTRING(:LINE FROM 19);-- Пропускаем слово "НазначениеПлатежа="
|
||
|
||
-- Определяем плательщика
|
||
PAYER = SUBSTRING((SELECT P.LINE FROM TMP$PAYMENT$BANK_STTM P WHERE P.POS = :POS - 28 + :SHIFT_LINE) FROM 12);-- Пропускаем слово "Плательщик="
|
||
|
||
-- Создаем платеж
|
||
INSERT INTO INF$PAYMENT$BANK_STTM
|
||
(DATE_ACCOUNT, DATE_PAYMENT, NUMBER, AMOUNT, CONTRACTOR, PURPOSE, PAYER)
|
||
VALUES
|
||
(:DATE_ACCOUNT, :DATE_PAYMENT, :NUMBER_DOC, :AMOUNT, :NAME_BANK, :PURPOSE, :PAYER);
|
||
END
|
||
|
||
UPDATE INF$DATABASE$CONST
|
||
SET
|
||
LAST_DATE_BANK_STATEMENT = :MAX_DATE_ACCOUNT;
|
||
|
||
RDB$SET_CONTEXT('USER_SESSION', 'BANK_STTM_DATE_ACCOUNT', FORMAT_DATE(:MAX_DATE_ACCOUNT));
|
||
END
|
||
|
||
PROCEDURE DETECT_SOURCE_PAYMENT(DATE_ACCOUNT DOM$DATE NOT NULL)
|
||
AS
|
||
DECLARE VARIABLE ID DOM$KEY;
|
||
DECLARE VARIABLE CONTRACTOR D_VARCHAR_200;
|
||
DECLARE VARIABLE PURPOSE D_VARCHAR_500;
|
||
DECLARE VARIABLE PAYER D_VARCHAR_200;
|
||
DECLARE VARIABLE ID_BANK DOM$KEY;
|
||
DECLARE VARIABLE ID_BAILIFF DOM$KEY;
|
||
DECLARE VARIABLE ID_BRANCH DOM$KEY;
|
||
BEGIN
|
||
FOR SELECT
|
||
BS.ID,
|
||
BS.CONTRACTOR,
|
||
BS.PURPOSE,
|
||
BS.PAYER
|
||
FROM
|
||
INF$PAYMENT$BANK_STTM BS
|
||
WHERE
|
||
BS.DATE_ACCOUNT = :DATE_ACCOUNT
|
||
ORDER BY
|
||
BS.ID
|
||
INTO
|
||
:ID,
|
||
:CONTRACTOR,
|
||
:PURPOSE,
|
||
:PAYER
|
||
DO
|
||
BEGIN
|
||
IF (:PURPOSE = 'Перечисление средств в счет погашения долга взыскателю :Булатова Наталья Васильевна 680000, Россия, , , г. Хабаровск, , ул. Тихоокеанская, д. 219, , кв. 66 Исполнительный лист 00319470') THEN
|
||
BEGIN
|
||
UPDATE INF$PAYMENT$BANK_STTM B
|
||
SET
|
||
B.ID_BANK = NULL,
|
||
B.ID_BAILIFF = NULL,
|
||
B.IS_INDIVIDUAL_PAYMENT = FALSE
|
||
WHERE
|
||
B.ID = :ID;
|
||
|
||
CONTINUE;
|
||
END
|
||
|
||
IF (:PURPOSE LIKE '%АРБИТР%') THEN
|
||
BEGIN
|
||
UPDATE INF$PAYMENT$BANK_STTM B
|
||
SET
|
||
B.ID_BANK = NULL,
|
||
B.ID_BAILIFF = NULL,
|
||
B.IS_INDIVIDUAL_PAYMENT = FALSE
|
||
WHERE
|
||
B.ID = :ID;
|
||
|
||
CONTINUE;
|
||
END
|
||
|
||
-- Ищем банк в списке
|
||
ID_BANK = (SELECT B.ID FROM DIR$EXEC_PROC$BANK B WHERE :CONTRACTOR LIKE '%' || B.NAME_IN_FILE_BANK_CLIENT || '%');
|
||
|
||
-- Проверяем, является ли платеж безакцептным от банка
|
||
IF (:ID_BANK IS NOT NULL) THEN
|
||
IF (EXISTS(SELECT 1 FROM DIR$EXEC_PROC$BANK_PURPOSE BP WHERE (BP.ID_BANK = :ID_BANK) AND (:PURPOSE STARTING WITH BP.NAME))) THEN
|
||
BEGIN
|
||
-- Указываем, что это банк
|
||
UPDATE INF$PAYMENT$BANK_STTM B
|
||
SET
|
||
B.ID_BANK = :ID_BANK
|
||
WHERE
|
||
(B.ID = :ID)
|
||
AND (B.ID_BANK IS DISTINCT FROM :ID_BANK);
|
||
|
||
CONTINUE;
|
||
END
|
||
|
||
-- Определяем, является ли платеж от ССП
|
||
ID_BAILIFF = (SELECT S.ID FROM DIR$PAYMENT$SOURCE S WHERE :PAYER LIKE '%' || S.NAME_CONTRACTOR || '%');
|
||
|
||
IF (:ID_BAILIFF IS NOT NULL) THEN
|
||
BEGIN
|
||
-- Указываем, что это ССП
|
||
UPDATE INF$PAYMENT$BANK_STTM B
|
||
SET
|
||
B.ID_BAILIFF = :ID_BAILIFF
|
||
WHERE
|
||
(B.ID = :ID)
|
||
AND (B.ID_BAILIFF IS DISTINCT FROM :ID_BAILIFF);
|
||
|
||
CONTINUE;
|
||
END
|
||
|
||
-- Определяем, является ли платеж индивидуальным
|
||
IF (((:PAYER NOT LIKE '%ИП %') AND (:PAYER NOT LIKE '%Индивидуальный %') AND (:PURPOSE NOT LIKE '%т.ч. НДС%') AND (:PURPOSE NOT LIKE '%МКД-20%') AND (:PURPOSE NOT LIKE '%МКД-10%') AND (:PURPOSE NOT LIKE '%998,%') AND (:PURPOSE NOT LIKE '%ФСГ%') AND (:PURPOSE NOT LIKE '%сч/ф%') AND (:PAYER NOT LIKE 'ООО "МУЛЬТИПРОДУКТ"')) OR (:PURPOSE LIKE '%ЖКУ%')) THEN
|
||
BEGIN
|
||
ID_BRANCH = (SELECT IP.ID_BRANCH FROM DIR$ENTPR$IND_PAYMENT IP WHERE LOWER(:PURPOSE) LIKE '%' || LOWER(IP.NAME) || '%' GROUP BY IP.ID_BRANCH);
|
||
|
||
IF (:ID_BRANCH IS NOT NULL) THEN
|
||
BEGIN
|
||
-- Указываем, что это инд. платеж
|
||
UPDATE INF$PAYMENT$BANK_STTM B
|
||
SET
|
||
B.IS_INDIVIDUAL_PAYMENT = TRUE
|
||
WHERE
|
||
(B.ID = :ID)
|
||
AND (B.IS_INDIVIDUAL_PAYMENT IS FALSE);
|
||
|
||
CONTINUE;
|
||
END
|
||
END
|
||
|
||
UPDATE INF$PAYMENT$BANK_STTM B
|
||
SET
|
||
B.ID_BRANCH = NULL,
|
||
B.ID_BANK = NULL,
|
||
B.ID_BAILIFF = NULL,
|
||
B.IS_INDIVIDUAL_PAYMENT = FALSE
|
||
WHERE
|
||
(B.ID = :ID)
|
||
AND ((B.ID_BRANCH IS NOT NULL) OR (B.ID_BANK IS NOT NULL) OR (B.ID_BAILIFF IS NOT NULL) OR (B.IS_INDIVIDUAL_PAYMENT IS TRUE));
|
||
END
|
||
END
|
||
|
||
PROCEDURE CREATE_RECEIPTS_FOR_DATE(DATE_ACCOUNT DOM$DATE)
|
||
AS
|
||
DECLARE VARIABLE ID DOM$KEY;
|
||
DECLARE VARIABLE TYPE_PAYMENT DOM$INTEGER;
|
||
DECLARE VARIABLE QUANTITY DOM$INTEGER;
|
||
DECLARE VARIABLE NOT_RECOGN DOM$INTEGER;
|
||
BEGIN
|
||
IF (:DATE_ACCOUNT IS NULL) THEN
|
||
DATE_ACCOUNT = RDB$GET_CONTEXT('USER_SESSION', 'BANK_STTM_DATE_ACCOUNT');
|
||
|
||
QUANTITY = 0;
|
||
|
||
FOR SELECT
|
||
I.ID
|
||
FROM
|
||
INF$PAYMENT$BANK_STTM I
|
||
WHERE
|
||
(I.DATE_ACCOUNT = :DATE_ACCOUNT)
|
||
AND ((I.ID_BANK IS NOT NULL) OR (I.ID_BAILIFF IS NOT NULL) OR (I.IS_INDIVIDUAL_PAYMENT IS TRUE))
|
||
AND (I.RECEIPT_CREATED IS FALSE)
|
||
INTO
|
||
:ID
|
||
DO
|
||
BEGIN
|
||
EXECUTE PROCEDURE CREATE_RECEIPT(:ID, NULL);
|
||
|
||
QUANTITY = :QUANTITY + 1;
|
||
END
|
||
|
||
IF (:QUANTITY > 0) THEN
|
||
BEGIN
|
||
NOT_RECOGN = (SELECT COUNT(*) FROM INF$PAYMENT$BANK_STTM I WHERE (I.DATE_ACCOUNT = :DATE_ACCOUNT) AND ((I.ID_BANK IS NOT NULL) OR (I.ID_BAILIFF IS NOT NULL) OR (I.IS_INDIVIDUAL_PAYMENT IS TRUE)) AND (I.RECEIPT_CREATED IS FALSE));
|
||
|
||
-- EXECUTE PROCEDURE SEND_NOTIFY_LOAD_BANK_STATEMENT(:DATE_ACCOUNT, :NOT_RECOGN);
|
||
END
|
||
ELSE
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CANCEL('Не найдено платежей для создания квитанций.');
|
||
END
|
||
|
||
PROCEDURE CREATE_INDIVID_RECEIPT(ID DOM$KEY NOT NULL, ID_ABONENT DOM$ABONENT NOT NULL)
|
||
AS
|
||
DECLARE VARIABLE ID_GROUP_DISTRICT DOM$KEY;
|
||
DECLARE VARIABLE ID_BRANCH DOM$KEY;
|
||
BEGIN
|
||
ID_GROUP_DISTRICT = (SELECT RESULT FROM GET$ABONENT$DETERMINE_GD(:ID_ABONENT));
|
||
IF (:ID_GROUP_DISTRICT IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Группа участков у абонента ' || :ID_ABONENT || ' не распознана.');
|
||
|
||
ID_BRANCH = (SELECT GD.ID_BRANCH FROM DIR$ENTERPRISE$GROUP_DISTRICT GD WHERE GD.ID = :ID_GROUP_DISTRICT);
|
||
IF (:ID_BRANCH IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Филиал у абонента ' || :ID_ABONENT || ' не найден.');
|
||
|
||
-- IF ((SELECT B.IS_INDIVIDUAL_PAYMENT FROM INF$PAYMENT$BANK_STTM B WHERE B.ID = :ID) IS ) THEN
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Платеж ' || :ID || ' не является индивидуальным.');
|
||
|
||
IF (:ID_BRANCH = 2) THEN
|
||
EXECUTE STATEMENT ('EXECUTE PROCEDURE PKG$PAYMENT$BANK_STTM.CREATE_RECEIPT(' || :ID || ', ' || :ID_ABONENT || ')')
|
||
ON EXTERNAL DATA SOURCE (SELECT D.DATA_SOURCE FROM DIR$DATABASE$DATABASE D WHERE D.ID = 2)
|
||
AS USER 'SYSDBA' PASSWORD 'masterkey';
|
||
ELSE
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Филиал ' || :ID_BRANCH || ' не поддерживается для создания инд. платежей.');
|
||
END
|
||
|
||
PROCEDURE CREATE_RECEIPT(ID DOM$KEY NOT NULL, ID_ABONENT DOM$ABONENT)
|
||
AS
|
||
DECLARE VARIABLE DATE_ACCOUNT DOM$DATE;
|
||
DECLARE VARIABLE DATE_PAYMENT DOM$DATE;
|
||
DECLARE VARIABLE NUMBER DOM$NUMBER_CHECK;
|
||
DECLARE VARIABLE AMOUNT DOM$AMOUNT;
|
||
DECLARE VARIABLE CONTRACTOR DOM$NAME_CONTRACTOR;
|
||
DECLARE VARIABLE PURPOSE D_VARCHAR_500;
|
||
DECLARE VARIABLE PAYER D_VARCHAR_200;
|
||
DECLARE VARIABLE ID_RECEIPT DOM$KEY;
|
||
DECLARE VARIABLE ID_BANK DOM$KEY;
|
||
DECLARE VARIABLE ID_BAILIFF DOM$KEY;
|
||
DECLARE VARIABLE ID_BRANCH DOM$KEY;
|
||
DECLARE VARIABLE IS_INDIVIDUAL_PAYMENT DOM$BOOLEAN_REAL;
|
||
DECLARE VARIABLE RECEIPT_CREATED DOM$BOOLEAN_REAL;
|
||
BEGIN
|
||
-- Считываем квитанцию
|
||
SELECT
|
||
B.ID_BRANCH,
|
||
B.ID_BANK,
|
||
B.ID_BAILIFF,
|
||
B.DATE_ACCOUNT,
|
||
B.DATE_PAYMENT,
|
||
B.NUMBER,
|
||
B.AMOUNT,
|
||
B.CONTRACTOR,
|
||
B.PURPOSE,
|
||
B.PAYER,
|
||
B.IS_INDIVIDUAL_PAYMENT,
|
||
B.RECEIPT_CREATED
|
||
FROM
|
||
INF$PAYMENT$BANK_STTM B
|
||
WHERE
|
||
B.ID = :ID
|
||
INTO
|
||
:ID_BRANCH,
|
||
:ID_BANK,
|
||
:ID_BAILIFF,
|
||
:DATE_ACCOUNT,
|
||
:DATE_PAYMENT,
|
||
:NUMBER,
|
||
:AMOUNT,
|
||
:CONTRACTOR,
|
||
:PURPOSE,
|
||
:PAYER,
|
||
:IS_INDIVIDUAL_PAYMENT,
|
||
:RECEIPT_CREATED;
|
||
|
||
IF (:RECEIPT_CREATED IS TRUE) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Квитанция по платежу ' || :ID || ' уже создана.');
|
||
|
||
-- Если указан банк, это безакцепт
|
||
IF ((:ID_ABONENT IS NULL) AND (:ID_BANK IS NOT NULL)) THEN
|
||
BEGIN
|
||
-- Пробуем создать в текущей базе (Хабаровск)
|
||
ID_RECEIPT = (SELECT RESULT FROM TRY_CREATE_RECEIPT_NONACCEPT(:ID_BANK, :DATE_ACCOUNT, :DATE_PAYMENT, :NUMBER, :AMOUNT, :PURPOSE, :PAYER));
|
||
|
||
IF (:ID_RECEIPT IS NOT NULL) THEN
|
||
BEGIN
|
||
UPDATE INF$PAYMENT$BANK_STTM BS
|
||
SET
|
||
BS.ID_BRANCH = 1,
|
||
BS.RECEIPT_CREATED = TRUE
|
||
WHERE
|
||
BS.ID = :ID;
|
||
END
|
||
ELSE
|
||
-- Если иск не найден, пробуем создать в базе Комсомольского филилала
|
||
IF (:ID_RECEIPT IS NULL) THEN
|
||
BEGIN
|
||
EXECUTE STATEMENT ('SELECT RESULT FROM PKG$PAYMENT$BANK_STTM.TRY_CREATE_RECEIPT_NONACCEPT(:ID_BANK, :DATE_ACCOUNT, :DATE_PAYMENT, :NUMBER, :AMOUNT, :PURPOSE, :PAYER)')
|
||
(ID_BANK := :ID_BANK, DATE_ACCOUNT := :DATE_ACCOUNT, DATE_PAYMENT := :DATE_PAYMENT, NUMBER := :NUMBER, AMOUNT := :AMOUNT, PURPOSE := :PURPOSE, PAYER := :PAYER)
|
||
ON EXTERNAL DATA SOURCE (SELECT D.DATA_SOURCE FROM DIR$DATABASE$DATABASE D WHERE D.ID = 2)
|
||
AS USER 'SYSDBA' PASSWORD 'masterkey'
|
||
INTO
|
||
:ID_RECEIPT;
|
||
|
||
IF (:ID_RECEIPT IS NOT NULL) THEN
|
||
BEGIN
|
||
UPDATE INF$PAYMENT$BANK_STTM BS
|
||
SET
|
||
BS.ID_BRANCH = 2,
|
||
BS.RECEIPT_CREATED = TRUE
|
||
WHERE
|
||
BS.ID = :ID;
|
||
END
|
||
END
|
||
END
|
||
ELSE IF ((:ID_ABONENT IS NULL) AND (:ID_BAILIFF IS NOT NULL)) THEN
|
||
BEGIN
|
||
-- Определяем филиал
|
||
ID_BRANCH = (SELECT GD.ID_BRANCH FROM DIR$PAYMENT$SOURCE_GD SG INNER JOIN DIR$ENTERPRISE$GROUP_DISTRICT GD ON GD.ID = SG.ID_GROUP_DISTRICT WHERE SG.ID_SOURCE = :ID_BAILIFF);
|
||
IF (:ID_BRANCH IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Неизвестный филиал у источника оплаты: ' || (SELECT NAME FROM DIR$PAYMENT$SOURCE WHERE ID = :ID_BAILIFF));
|
||
|
||
IF (:ID_BRANCH = 1) THEN
|
||
BEGIN
|
||
ID_RECEIPT = (SELECT RESULT FROM TRY_CREATE_RECEIPT_BAILIFF(:ID_BAILIFF, :DATE_ACCOUNT, :DATE_PAYMENT, :NUMBER, :AMOUNT, :PURPOSE));
|
||
|
||
IF (:ID_RECEIPT IS NOT NULL) THEN
|
||
BEGIN
|
||
UPDATE INF$PAYMENT$BANK_STTM BS
|
||
SET
|
||
BS.ID_BRANCH = 1,
|
||
BS.RECEIPT_CREATED = TRUE
|
||
WHERE
|
||
BS.ID = :ID;
|
||
END
|
||
END
|
||
ELSE IF (:ID_BRANCH = 2) THEN
|
||
BEGIN
|
||
EXECUTE STATEMENT ('SELECT RESULT FROM PKG$PAYMENT$BANK_STTM.TRY_CREATE_RECEIPT_BAILIFF(:ID_BAILIFF, :DATE_ACCOUNT, :DATE_PAYMENT, :NUMBER, :AMOUNT, :PURPOSE)')
|
||
(ID_BAILIFF := :ID_BAILIFF, DATE_ACCOUNT := :DATE_ACCOUNT, DATE_PAYMENT := :DATE_PAYMENT, NUMBER := :NUMBER, AMOUNT := :AMOUNT, PURPOSE := :PURPOSE)
|
||
ON EXTERNAL DATA SOURCE (SELECT D.DATA_SOURCE FROM DIR$DATABASE$DATABASE D WHERE D.ID = 2)
|
||
AS USER 'SYSDBA' PASSWORD 'masterkey'
|
||
INTO
|
||
:ID_RECEIPT;
|
||
|
||
IF (:ID_RECEIPT IS NOT NULL) THEN
|
||
BEGIN
|
||
UPDATE INF$PAYMENT$BANK_STTM BS
|
||
SET
|
||
BS.ID_BRANCH = 2,
|
||
BS.RECEIPT_CREATED = TRUE
|
||
WHERE
|
||
BS.ID = :ID;
|
||
END
|
||
END
|
||
ELSE IF (:ID_BRANCH = 3) THEN
|
||
BEGIN
|
||
EXECUTE STATEMENT ('SELECT RESULT FROM PKG$PAYMENT$BANK_STTM.TRY_CREATE_RECEIPT_BAILIFF(:ID_BAILIFF, :DATE_ACCOUNT, :DATE_PAYMENT, :NUMBER, :AMOUNT, :PURPOSE)')
|
||
(ID_BAILIFF := :ID_BAILIFF, DATE_ACCOUNT := :DATE_ACCOUNT, DATE_PAYMENT := :DATE_PAYMENT, NUMBER := :NUMBER, AMOUNT := :AMOUNT, PURPOSE := :PURPOSE)
|
||
ON EXTERNAL DATA SOURCE (SELECT D.DATA_SOURCE FROM DIR$DATABASE$DATABASE D WHERE D.ID = 5)
|
||
AS USER 'SYSDBA' PASSWORD 'masterkey'
|
||
INTO
|
||
:ID_RECEIPT;
|
||
|
||
IF (:ID_RECEIPT IS NOT NULL) THEN
|
||
BEGIN
|
||
UPDATE INF$PAYMENT$BANK_STTM BS
|
||
SET
|
||
BS.ID_BRANCH = 3,
|
||
BS.RECEIPT_CREATED = TRUE
|
||
WHERE
|
||
BS.ID = :ID;
|
||
END
|
||
END
|
||
ELSE
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Необрабатываемый филиал: ' || :ID_BRANCH || ' (№' || :NUMBER || ')');
|
||
END
|
||
ELSE IF ((:IS_INDIVIDUAL_PAYMENT IS TRUE) OR (:ID_ABONENT IS NOT NULL)) THEN
|
||
BEGIN
|
||
-- Пытаемся создать в базе Комсомольска
|
||
EXECUTE STATEMENT ('SELECT RESULT FROM PKG$PAYMENT$BANK_STTM.TRY_CREATE_RECEIPT_INDIVID(:DATE_ACCOUNT, :DATE_PAYMENT, :NUMBER, :AMOUNT, :PURPOSE, :PAYER, :ID_ABONENT)')
|
||
(DATE_ACCOUNT := :DATE_ACCOUNT, DATE_PAYMENT := :DATE_PAYMENT, NUMBER := :NUMBER, AMOUNT := :AMOUNT, PURPOSE := :PURPOSE, PAYER := :PAYER, ID_ABONENT := :ID_ABONENT)
|
||
ON EXTERNAL DATA SOURCE (SELECT D.DATA_SOURCE FROM DIR$DATABASE$DATABASE D WHERE D.ID = 2)
|
||
AS USER 'SYSDBA' PASSWORD 'masterkey'
|
||
INTO
|
||
:ID_RECEIPT;
|
||
|
||
IF (:ID_RECEIPT IS NOT NULL) THEN
|
||
BEGIN
|
||
UPDATE INF$PAYMENT$BANK_STTM BS
|
||
SET
|
||
BS.ID_BRANCH = 2,
|
||
BS.IS_INDIVIDUAL_PAYMENT = TRUE,
|
||
BS.RECEIPT_CREATED = TRUE
|
||
WHERE
|
||
BS.ID = :ID;
|
||
END
|
||
-- ELSE
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Необрабатываемый филиал: ' || :ID_BRANCH);
|
||
END
|
||
END
|
||
|
||
PROCEDURE TRY_CREATE_RECEIPT_NONACCEPT(ID_BANK DOM$KEY NOT NULL, DATE_ACCOUNT DOM$DATE NOT NULL, DATE_PAYMENT DOM$DATE NOT NULL, NUMBER_RECEIPT DOM$NUMBER_CHECK NOT NULL, AMOUNT DOM$AMOUNT NOT NULL, PURPOSE D_VARCHAR_500 NOT NULL, PAYER D_VARCHAR_200 NOT NULL) RETURNS (RESULT DOM$KEY)
|
||
AS
|
||
DECLARE VARIABLE ID_LAWSUIT DOM$KEY;
|
||
DECLARE VARIABLE ID_BATCH DOM$KEY;
|
||
DECLARE VARIABLE ID_EXEC_PROC DOM$KEY;
|
||
DECLARE VARIABLE ID_WRIT_EXEC DOM$KEY;
|
||
DECLARE VARIABLE ID_ABONENT DOM$ABONENT;
|
||
DECLARE VARIABLE PURPOSE_ORIGIN D_VARCHAR_500;
|
||
DECLARE VARIABLE ID_SOURCE DOM$KEY;
|
||
DECLARE VARIABLE COMMENT_BATCH DOM$COMMENT;
|
||
DECLARE VARIABLE ID_TYPE_RECEIPT_VIA_BAILIFF DOM$KEY;
|
||
DECLARE VARIABLE ID_TYPE_RECEIPT DOM$KEY;
|
||
DECLARE VARIABLE ID_TYPE_RECEIPT_NGPH DOM$KEY;
|
||
DECLARE VARIABLE ID_TYPE_RECEIPT_MD DOM$KEY;
|
||
DECLARE VARIABLE ID_GROUP_DISTRICT DOM$KEY;
|
||
BEGIN
|
||
PURPOSE_ORIGIN = :PURPOSE;
|
||
|
||
ID_TYPE_RECEIPT_VIA_BAILIFF = (SELECT ID_TYPE_RECEIPT_VIA_BAILIFF FROM SYS$LINK$PAYMENT);
|
||
ID_TYPE_RECEIPT_NGPH = (SELECT TG.ID_TYPE_RECEIPT FROM DIR$GASSUPPLY$TYPE_GS TG WHERE TG.ID = (SELECT ID_TYPE_GS_NATURE_GAS_PRIVATE FROM SYS$LINK$GASSUPPLY));
|
||
ID_TYPE_RECEIPT_MD = (SELECT TG.ID_TYPE_RECEIPT FROM DIR$GASSUPPLY$TYPE_GS TG WHERE TG.ID = (SELECT ID_TYPE_GS_TANK_GAS_MD FROM SYS$LINK$GASSUPPLY));
|
||
|
||
-- Ищем иск в базе
|
||
SELECT
|
||
ID_LAWSUIT,
|
||
ID_WRIT_EXEC,
|
||
ID_EXEC_PROC
|
||
FROM
|
||
RECOGN_NONACCEPT(:ID_BANK, :DATE_PAYMENT, :PURPOSE, :PAYER)
|
||
INTO
|
||
:ID_LAWSUIT,
|
||
:ID_WRIT_EXEC,
|
||
:ID_EXEC_PROC;
|
||
|
||
-- Если иск не найден, выходим
|
||
IF (:ID_LAWSUIT IS NULL) THEN
|
||
BEGIN
|
||
RESULT = NULL;
|
||
SUSPEND;
|
||
EXIT;
|
||
END
|
||
|
||
-- Определяем код источника оплаты
|
||
ID_SOURCE = (SELECT BANK.ID_SOURCE FROM DIR$EXEC_PROC$BANK BANK WHERE BANK.ID = :ID_BANK);
|
||
IF (:ID_SOURCE IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Не указан источник оплаты для банка "' || (SELECT BANK.NAME FROM DIR$EXEC_PROC$BANK BANK WHERE BANK.ID = :ID_BANK) || '" (' || :PURPOSE || ').');
|
||
|
||
-- Запоминаем лицевой счет
|
||
ID_ABONENT = (SELECT L.ID_ABONENT FROM DOC$ABONENT$LAWSUIT L WHERE L.ID = :ID_LAWSUIT);
|
||
|
||
-- Сразу проверяем, что тип газоснабжения у абонента корректный
|
||
IF ((SELECT A.ID_TYPE_GASSUPPLY FROM DIR$ABONENT$ABONENT A WHERE A.ID = :ID_ABONENT) NOT IN (1, 2, 3, 4, 20, 25)) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA_ABONE(:ID_ABONENT, 'Неопознанный тип газоснабжения.');
|
||
|
||
-- Проверяем, что такой квитанции еще нет
|
||
IF (EXISTS(SELECT 1 FROM BAT$RECEIPT$RECEIPT R INNER JOIN BAT$RECEIPT$BATCH B ON B.ID = R.ID_BATCH WHERE (B.ID_SOURCE = :ID_SOURCE) AND (R.DATE_PAYMENT = :DATE_PAYMENT) AND (R.NUMBER = :NUMBER_RECEIPT) AND (R.AMOUNT_RECEIPT = :AMOUNT))) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Квитанция №' || :NUMBER_RECEIPT || ' от ' || FORMAT_DATE(:DATE_PAYMENT)
|
||
|| ' по источнику "' || (SELECT NAME FROM DIR$PAYMENT$SOURCE WHERE ID = :ID_SOURCE) || '" на сумму ' || :AMOUNT || ' уже создана');
|
||
|
||
-- Определяем группу участков
|
||
ID_GROUP_DISTRICT = PKG$ABONENT.GET_GROUP_DISTRICT_FOR_PAYMENT(:ID_ABONENT);
|
||
|
||
-- Создаем пачку
|
||
IF ((SELECT A.ID_TYPE_GASSUPPLY FROM DIR$ABONENT$ABONENT A WHERE A.ID = :ID_ABONENT) = (SELECT ID_TYPE_GS_NATURE_GAS_PRIVATE FROM SYS$LINK$GASSUPPLY)) THEN
|
||
BEGIN
|
||
COMMENT_BATCH = 'ПГ ЧД';
|
||
ID_TYPE_RECEIPT = :ID_TYPE_RECEIPT_NGPH;
|
||
END
|
||
ELSE IF ((SELECT A.ID_TYPE_GASSUPPLY FROM DIR$ABONENT$ABONENT A WHERE A.ID = :ID_ABONENT) = (SELECT ID_TYPE_GS_TANK_GAS_MD FROM SYS$LINK$GASSUPPLY)) THEN
|
||
BEGIN
|
||
COMMENT_BATCH = 'Ведомства';
|
||
ID_TYPE_RECEIPT = :ID_TYPE_RECEIPT_MD;
|
||
END
|
||
ELSE IF ((SELECT RESULT FROM GET$ABONENT$CHARGING_GAS_AMURCC(:ID_ABONENT)) = 1) THEN
|
||
BEGIN
|
||
COMMENT_BATCH = 'АмурВЦ';
|
||
ID_TYPE_RECEIPT = :ID_TYPE_RECEIPT_VIA_BAILIFF;
|
||
END
|
||
ELSE
|
||
BEGIN
|
||
COMMENT_BATCH = 'Не распознано';
|
||
ID_TYPE_RECEIPT = :ID_TYPE_RECEIPT_VIA_BAILIFF;
|
||
END
|
||
|
||
IF ((SELECT COUNT(*) FROM BAT$RECEIPT$BATCH B WHERE (B.ID_GROUP_DISTRICT = :ID_GROUP_DISTRICT) AND (B.ID_SOURCE = :ID_SOURCE) AND (B.DATE_ACCOUNT = :DATE_ACCOUNT) AND (B.IS_CORRECT_RECEIPT = 0) AND (B.COMMENT IS NOT DISTINCT FROM :COMMENT_BATCH)) > 1) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Найдено более одной пачки за ' || FORMAT_DATE(:DATE_ACCOUNT) || ' по ' || (SELECT NAME FROM DIR$PAYMENT$SOURCE WHERE ID = :ID_SOURCE));
|
||
|
||
-- Получаем код пачки
|
||
ID_BATCH = (SELECT B.ID FROM BAT$RECEIPT$BATCH B WHERE (B.ID_GROUP_DISTRICT = :ID_GROUP_DISTRICT) AND (B.ID_SOURCE = :ID_SOURCE) AND (B.DATE_ACCOUNT = :DATE_ACCOUNT) AND (B.IS_CORRECT_RECEIPT = 0) AND (B.COMMENT IS NOT DISTINCT FROM :COMMENT_BATCH));
|
||
IF (:ID_BATCH IS NULL) THEN
|
||
BEGIN
|
||
INSERT INTO BAT$RECEIPT$BATCH
|
||
(ID, ID_GROUP_DISTRICT, ID_SOURCE, DATE_ACCOUNT, COMMENT)
|
||
VALUES
|
||
(NEXT VALUE FOR SEQ_BAT$RECEIPT$BATCH_ID, :ID_GROUP_DISTRICT, :ID_SOURCE, :DATE_ACCOUNT, :COMMENT_BATCH)
|
||
RETURNING
|
||
ID
|
||
INTO
|
||
:ID_BATCH;
|
||
END
|
||
ELSE IF ((SELECT B.LOADED FROM BAT$RECEIPT$BATCH B WHERE B.ID = :ID_BATCH) = 1) THEN
|
||
EXECUTE PROCEDURE PKG$EXCEPTION.FOR_BATCH_RECEIPT(:ID_BATCH, 'Пачка квитанций уже загружена.');
|
||
|
||
-- Создаем квитанцию
|
||
INSERT INTO BAT$RECEIPT$RECEIPT
|
||
(ID, ID_BATCH, ID_ABONENT, ID_PERIOD_FOR_PAYMENT, ID_TYPE_RECEIPT, ID_LAWSUIT, ID_WRIT_EXEC, ID_EXEC_PROC, DATE_PAYMENT, NUMBER, AUTODISTRIBUTE_SERVICES, AMOUNT_SERVICE_5, PURPOSE, PAYER)
|
||
VALUES
|
||
(NEXT VALUE FOR SEQ_BAT$RECEIPT$RECEIPT_ID, :ID_BATCH, :ID_ABONENT, DATE_TO_PERIOD(:DATE_PAYMENT), :ID_TYPE_RECEIPT, :ID_LAWSUIT, :ID_WRIT_EXEC, :ID_EXEC_PROC, :DATE_PAYMENT, :NUMBER_RECEIPT, 0, :AMOUNT, :PURPOSE_ORIGIN, :PAYER)
|
||
RETURNING
|
||
ID
|
||
INTO
|
||
:RESULT;
|
||
|
||
SUSPEND;
|
||
END
|
||
|
||
FUNCTION TRIM_COURT_DISTRICT(NUMBER_FILE DOM$NUMBER_FILE) RETURNS DOM$NUMBER_FILE DETERMINISTIC
|
||
AS
|
||
DECLARE VARIABLE STR_YEAR DOM$NUMBER_FILE;
|
||
DECLARE VARIABLE STR_NUMBER DOM$NUMBER_FILE;
|
||
DECLARE VARIABLE RESULT DOM$NUMBER_FILE;
|
||
DECLARE VARIABLE NYEAR DOM$INTEGER;
|
||
BEGIN
|
||
IF (POSITION('/', :NUMBER_FILE) > 1) THEN
|
||
BEGIN
|
||
STR_NUMBER = LEFT(:NUMBER_FILE, POSITION('/', :NUMBER_FILE) - 1);
|
||
STR_YEAR = SUBSTRING(:NUMBER_FILE FROM (POSITION('/', :NUMBER_FILE) + 1));
|
||
IF (CHAR_LENGTH(:STR_YEAR) = 1) THEN
|
||
RETURN NULL;
|
||
IF (CHAR_LENGTH(:STR_YEAR) NOT IN (2, 4)) THEN
|
||
BEGIN
|
||
-- Обработка правой части вида "2-4039/2016-74"
|
||
IF (SUBSTRING(:STR_YEAR FROM 5 FOR 1) = '-') THEN
|
||
BEGIN
|
||
NYEAR = LEFT(:STR_YEAR, 4);
|
||
IF (:NYEAR NOT BETWEEN 2006 AND EXTRACT(YEAR FROM CURRENT_DATE)) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Ошибка в годе в "' || :NUMBER_FILE || '".');
|
||
|
||
RETURN :STR_NUMBER || '/' || :NYEAR;
|
||
END
|
||
-- Обработка правой части вида "2-3028/13-2018"
|
||
ELSE IF ((SUBSTRING(:STR_YEAR FROM 3 FOR 1) = '-') AND (CHAR_LENGTH(:STR_YEAR) = 7)) THEN
|
||
BEGIN
|
||
NYEAR = RIGHT(:STR_YEAR, 4);
|
||
IF (:NYEAR NOT BETWEEN 2006 AND EXTRACT(YEAR FROM CURRENT_DATE)) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Ошибка в годе в "' || :NUMBER_FILE || '".');
|
||
|
||
RETURN :STR_NUMBER || '/' || :NYEAR;
|
||
END
|
||
-- Обработка правой части вида "2-300/9-2017"
|
||
ELSE IF ((SUBSTRING(:STR_YEAR FROM 2 FOR 1) = '-') AND (CHAR_LENGTH(:STR_YEAR) = 6)) THEN
|
||
BEGIN
|
||
NYEAR = RIGHT(:STR_YEAR, 4);
|
||
IF (:NYEAR NOT BETWEEN 2006 AND EXTRACT(YEAR FROM CURRENT_DATE)) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Ошибка в годе в "' || :NUMBER_FILE || '".');
|
||
|
||
RETURN :STR_NUMBER || '/' || :NYEAR;
|
||
END
|
||
ELSE
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Не могу опознать год в "' || :NUMBER_FILE || '".');
|
||
-- RETURN NULL;
|
||
END
|
||
ELSE
|
||
BEGIN
|
||
NYEAR = IIF(CHAR_LENGTH(:STR_YEAR) = 4, :STR_YEAR, '20' || :STR_YEAR);
|
||
IF (:NYEAR NOT BETWEEN 2006 AND 2019) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Ошибка в годе в "' || :NUMBER_FILE || '".');
|
||
|
||
RETURN :STR_NUMBER || '/' || :NYEAR;
|
||
END
|
||
END
|
||
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Нераспознано дело "' || :NUMBER_FILE || '".');
|
||
END
|
||
|
||
FUNCTION CONVERT_NUMBER_FILE(NUMBER_FILE DOM$NUMBER_FILE, PURPOSE D_VARCHAR_500 NOT NULL) RETURNS DOM$NUMBER_FILE DETERMINISTIC
|
||
AS
|
||
DECLARE VARIABLE STR_YEAR DOM$NUMBER_FILE;
|
||
DECLARE VARIABLE STR_NUMBER DOM$NUMBER_FILE;
|
||
DECLARE VARIABLE RESULT DOM$NUMBER_FILE;
|
||
BEGIN
|
||
IF (POSITION('/', :NUMBER_FILE) > 1) THEN
|
||
BEGIN
|
||
STR_NUMBER = LEFT(:NUMBER_FILE, POSITION('/', :NUMBER_FILE) - 1);
|
||
STR_YEAR = SUBSTRING(:NUMBER_FILE FROM (POSITION('/', :NUMBER_FILE) + 1));
|
||
IF (CHAR_LENGTH(:STR_YEAR) = 1) THEN
|
||
RETURN NULL;
|
||
IF (CHAR_LENGTH(:STR_YEAR) NOT IN (2, 4)) THEN
|
||
BEGIN
|
||
-- Обработка правой части вида "2-4039/2016-74"
|
||
IF (SUBSTRING(:STR_YEAR FROM 5 FOR 1) = '-') THEN
|
||
RETURN :STR_NUMBER || LEFT(:STR_YEAR, 4);
|
||
-- Обработка правой части вида "2-300/9-2017"
|
||
IF ((SUBSTRING(:STR_YEAR FROM 2 FOR 1) = '-') AND (CHAR_LENGTH(:STR_YEAR) = 6)) THEN
|
||
RETURN :STR_NUMBER || RIGHT(:STR_YEAR, 4);
|
||
-- Обработка правой части вида "2-375/10-2017"
|
||
IF ((SUBSTRING(:STR_YEAR FROM 3 FOR 1) = '-') AND (CHAR_LENGTH(:STR_YEAR) = 7)) THEN
|
||
RETURN :STR_NUMBER || RIGHT(:STR_YEAR, 4);
|
||
|
||
RETURN NULL;
|
||
END
|
||
|
||
--EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('В номере дела "' || :NUMBER_FILE || '" год не четыре и не два символа.');
|
||
|
||
IF (CHAR_LENGTH(:STR_YEAR) = 2) THEN
|
||
BEGIN
|
||
IF (CAST(:STR_YEAR AS INTEGER) > CAST(RIGHT(EXTRACT(YEAR FROM CURRENT_DATE), 2) AS INTEGER)) THEN
|
||
RETURN NULL;
|
||
--EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('В номере дела "' || :NUMBER_FILE || '" неправильный год.');
|
||
|
||
RETURN :STR_NUMBER || '/' || '20' || :STR_YEAR;
|
||
END
|
||
ELSE
|
||
BEGIN
|
||
IF (CAST(:STR_YEAR AS INTEGER) > EXTRACT(YEAR FROM CURRENT_DATE)) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('В номере дела "' || :NUMBER_FILE || '" неправильный год.');
|
||
|
||
RETURN :STR_NUMBER || '/' || RIGHT(:STR_YEAR, 2);
|
||
END
|
||
END
|
||
ELSE IF (CHAR_LENGTH(:NUMBER_FILE) <= 6) THEN
|
||
RETURN :NUMBER_FILE;
|
||
ELSE
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('В номере дела "' || :NUMBER_FILE || '" не найден слэш (' || :PURPOSE || ').');
|
||
END
|
||
|
||
FUNCTION SEARCH_NUMBER_FILE(PURPOSE D_VARCHAR_500 NOT NULL, IS_NONACCEPT DOM$BOOLEAN_REAL NOT NULL) RETURNS DOM$NUMBER_FILE DETERMINISTIC
|
||
AS
|
||
DECLARE VARIABLE POS_NUMBER_FILE D_INTEGER;
|
||
DECLARE VARIABLE POS_NUMBER_FILE_END D_INTEGER;
|
||
DECLARE VARIABLE SLASH_ALREADY_FOUNDED DOM$BOOLEAN;
|
||
DECLARE VARIABLE RESULT DOM$NUMBER_FILE;
|
||
BEGIN
|
||
POS_NUMBER_FILE = POSITION('2-', :PURPOSE);
|
||
|
||
-- В ССП могут встречаться случаи, когда указан корпус/квартира и номер дела
|
||
-- в виде "г. Комсомольск-на-Амуре, , Ленина пр-кт, д. 81, корп.2-112/ 2-1929/2016"
|
||
IF (:IS_NONACCEPT IS FALSE) THEN
|
||
IF (POSITION('2-', :PURPOSE, :POS_NUMBER_FILE + 1) > 0) THEN
|
||
POS_NUMBER_FILE = POSITION('2-', :PURPOSE, :POS_NUMBER_FILE + 1);
|
||
|
||
IF (:POS_NUMBER_FILE > 0) THEN
|
||
BEGIN
|
||
PURPOSE = SUBSTRING(:PURPOSE FROM :POS_NUMBER_FILE);
|
||
IF (LEFT(:PURPOSE, 3) = '2- ') THEN
|
||
PURPOSE = '2-' || SUBSTRING(:PURPOSE FROM 4);
|
||
PURPOSE = REPLACE(:PURPOSE, './', '/');-- Исправляем возможную опечатку в номере делу
|
||
POS_NUMBER_FILE_END = 3;-- Пропускаем "2-"
|
||
SLASH_ALREADY_FOUNDED = 0;
|
||
|
||
-- Перебираем текст, прекращая поиск, как только находим не цифру или слэш
|
||
WHILE (:POS_NUMBER_FILE_END <= CHAR_LENGTH(:PURPOSE)) DO
|
||
BEGIN
|
||
IF (NOT((SUBSTRING(:PURPOSE FROM :POS_NUMBER_FILE_END FOR 1) BETWEEN '0' AND '9') OR (SUBSTRING(:PURPOSE FROM :POS_NUMBER_FILE_END FOR 1) = '/') OR (SUBSTRING(:PURPOSE FROM :POS_NUMBER_FILE_END FOR 1) = '-'))) THEN
|
||
BREAK;
|
||
|
||
-- Если был найден второй слэш, то останавливаем поиск (это номер вида 2-1077/2014/2)
|
||
IF (SUBSTRING(:PURPOSE FROM :POS_NUMBER_FILE_END FOR 1) = '/') THEN
|
||
BEGIN
|
||
IF (:SLASH_ALREADY_FOUNDED = 0) THEN
|
||
SLASH_ALREADY_FOUNDED = 1;
|
||
ELSE
|
||
BREAK;
|
||
END
|
||
|
||
POS_NUMBER_FILE_END = :POS_NUMBER_FILE_END + 1;
|
||
END
|
||
|
||
RESULT = SUBSTRING(:PURPOSE FROM 1 FOR :POS_NUMBER_FILE_END - 1);
|
||
END
|
||
|
||
IF (CHAR_LENGTH(:RESULT) = 2) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Не найден номер дела в строке: ' || :PURPOSE);
|
||
|
||
RETURN :RESULT;
|
||
END
|
||
|
||
PROCEDURE RECOGN_NONACCEPT(ID_BANK DOM$KEY NOT NULL, DATE_PAYMENT DOM$DATE NOT NULL, PURPOSE D_VARCHAR_500 NOT NULL, PAYER D_VARCHAR_200 NOT NULL) RETURNS (ID_LAWSUIT DOM$KEY, ID_WRIT_EXEC DOM$KEY, ID_EXEC_PROC DOM$KEY)
|
||
AS
|
||
DECLARE VARIABLE POS_NAME D_NATURAL;
|
||
DECLARE VARIABLE POS_PATRONYMIC D_NATURAL;
|
||
DECLARE VARIABLE POS_AFTER_PATRONYMIC D_NATURAL;
|
||
DECLARE VARIABLE FIO_BY_SB D_VARCHAR_200;
|
||
DECLARE VARIABLE NUMBER_FILE D_VARCHAR_200;
|
||
DECLARE VARIABLE NUMBER_WRIT_EXEC D_VARCHAR_100;
|
||
DECLARE VARIABLE FIO_RESPONDENT D_VARCHAR_150;
|
||
DECLARE VARIABLE TMP_ID_EXEC_PROC DOM$KEY;
|
||
DECLARE VARIABLE TMP_ID_WRIT_EXEC DOM$KEY;
|
||
DECLARE VARIABLE CONV_NUMBER_FILE DOM$NUMBER_FILE;
|
||
DECLARE VARIABLE ID_CORRECTION DOM$KEY;
|
||
DECLARE VARIABLE NUMBER_FILE_WO_CD DOM$NUMBER_FILE;
|
||
BEGIN
|
||
-- Модифицируем ФИО
|
||
FIO_BY_SB = UPPER(:PAYER);
|
||
FIO_BY_SB = REPLACE(:FIO_BY_SB, ' ОГЛЫ', '');
|
||
FIO_BY_SB = REPLACE(:FIO_BY_SB, ' КЫЗЫ', '');
|
||
|
||
-- Оставляем фамилию, имя, отчество
|
||
POS_NAME = POSITION(' ', :FIO_BY_SB);
|
||
POS_PATRONYMIC = POSITION(' ', :FIO_BY_SB, :POS_NAME + 1);
|
||
POS_AFTER_PATRONYMIC = POSITION(' ', :FIO_BY_SB, :POS_PATRONYMIC + 1);
|
||
IF (:POS_AFTER_PATRONYMIC > 0) THEN
|
||
FIO_BY_SB = LEFT(:FIO_BY_SB, :POS_AFTER_PATRONYMIC - 1);
|
||
-- Учет случая, когда у ответчика нет отчества, а платеж был через Сбербанк
|
||
IF (LOWER(RIGHT(:FIO_BY_SB, CHAR_LENGTH('дальневосточный'))) = 'дальневосточный') THEN
|
||
FIO_BY_SB = LEFT(:FIO_BY_SB, CHAR_LENGTH(:FIO_BY_SB) - CHAR_LENGTH('дальневосточный') - 1);
|
||
-- exception EXC$CANCEL :FIO_BY_SB || ' ' || :POS_NAME || ' ' || :POS_PATRONYMIC || ' ' || :POS_AFTER_PATRONYMIC;
|
||
|
||
-- Определяем номер дела
|
||
NUMBER_FILE = SEARCH_NUMBER_FILE(:PURPOSE, TRUE);
|
||
|
||
-- Ищем необходимость исправления
|
||
ID_CORRECTION = (SELECT C.ID FROM DIR$EXEC_PROC$CORRECTION C WHERE (C.PAYMENT_NUMBER_FILE IS NOT DISTINCT FROM :NUMBER_FILE) AND (C.PAYMENT_FIO = :FIO_BY_SB));
|
||
IF (:ID_CORRECTION IS NOT NULL) THEN
|
||
SELECT
|
||
C.CORRECT_NUMBER_FILE,
|
||
C.CORRECT_FIO
|
||
FROM
|
||
DIR$EXEC_PROC$CORRECTION C
|
||
WHERE
|
||
C.ID = :ID_CORRECTION
|
||
INTO
|
||
:NUMBER_FILE,
|
||
:FIO_BY_SB;
|
||
|
||
--
|
||
FIO_BY_SB = REPLACE(:FIO_BY_SB, 'Ё', 'Е');
|
||
|
||
-- Исправляем возможную опечатку
|
||
IF (RIGHT(:NUMBER_FILE, 4) = '/218') THEN
|
||
NUMBER_FILE = LEFT(:NUMBER_FILE, CHAR_LENGTH(:NUMBER_FILE) - 3) || '2018';
|
||
|
||
IF (:NUMBER_FILE IS NOT NULL) THEN
|
||
BEGIN
|
||
IF ((SELECT COUNT(*) FROM DOC$ABONENT$LAWSUIT L INNER JOIN DOC$ABONENT$LAWSUIT_CITIZEN LC ON LC.ID_LAWSUIT = L.ID INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = LC.ID_CITIZEN WHERE L.FILE_NUMBER STARTING WITH :NUMBER_FILE AND UPPER(C.SURNAME_NAME_PATRONYMIC) = :FIO_BY_SB) > 1) THEN
|
||
BEGIN
|
||
IF ((SELECT COUNT(*) FROM DOC$ABONENT$LAWSUIT L INNER JOIN DOC$ABONENT$LAWSUIT_CITIZEN LC ON LC.ID_LAWSUIT = L.ID INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = LC.ID_CITIZEN WHERE L.FILE_NUMBER STARTING WITH :NUMBER_FILE || '/' AND UPPER(C.SURNAME_NAME_PATRONYMIC) = :FIO_BY_SB) > 1) THEN
|
||
BEGIN
|
||
IF ((SELECT COUNT(*) FROM DOC$ABONENT$LAWSUIT L INNER JOIN DOC$ABONENT$LAWSUIT_CITIZEN LC ON LC.ID_LAWSUIT = L.ID INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = LC.ID_CITIZEN WHERE L.FILE_NUMBER STARTING WITH :NUMBER_FILE || '/' AND (L.REST_LAWSUIT_BY_MONTHS_DEBT > 0) AND UPPER(C.SURNAME_NAME_PATRONYMIC) = :FIO_BY_SB) > 1) THEN
|
||
ID_LAWSUIT = NULL;
|
||
ELSE
|
||
ID_LAWSUIT = (SELECT L.ID FROM DOC$ABONENT$LAWSUIT L INNER JOIN DOC$ABONENT$LAWSUIT_CITIZEN LC ON LC.ID_LAWSUIT = L.ID INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = LC.ID_CITIZEN WHERE L.FILE_NUMBER STARTING WITH :NUMBER_FILE || '/' AND (L.REST_LAWSUIT_BY_MONTHS_DEBT > 0) AND UPPER(C.SURNAME_NAME_PATRONYMIC) = :FIO_BY_SB);
|
||
END
|
||
ELSE
|
||
ID_LAWSUIT = (SELECT L.ID FROM DOC$ABONENT$LAWSUIT L INNER JOIN DOC$ABONENT$LAWSUIT_CITIZEN LC ON LC.ID_LAWSUIT = L.ID INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = LC.ID_CITIZEN WHERE L.FILE_NUMBER STARTING WITH :NUMBER_FILE || '/' AND UPPER(C.SURNAME_NAME_PATRONYMIC) = :FIO_BY_SB);
|
||
END
|
||
ELSE
|
||
BEGIN
|
||
ID_LAWSUIT = (SELECT L.ID FROM DOC$ABONENT$LAWSUIT L INNER JOIN DOC$ABONENT$LAWSUIT_CITIZEN LC ON LC.ID_LAWSUIT = L.ID INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = LC.ID_CITIZEN WHERE L.FILE_NUMBER STARTING WITH :NUMBER_FILE AND UPPER(C.SURNAME_NAME_PATRONYMIC) = :FIO_BY_SB);
|
||
|
||
IF (:ID_LAWSUIT IS NULL) THEN
|
||
BEGIN
|
||
-- Если иск не найден, ищем его в истории заседаний
|
||
ID_LAWSUIT = (SELECT L.ID FROM DOC$ABONENT$LAWSUIT L INNER JOIN DOC$COURT_PROCESS$SUMMONS_LAWSU SL ON SL.ID_LAWSUIT = L.ID INNER JOIN DOC$ABONENT$LAWSUIT_CITIZEN LC ON LC.ID_LAWSUIT = L.ID INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = LC.ID_CITIZEN WHERE SL.NUMBER_FILE STARTING WITH :NUMBER_FILE AND UPPER(C.SURNAME_NAME_PATRONYMIC) = :FIO_BY_SB);
|
||
|
||
IF (:ID_LAWSUIT IS NULL) THEN
|
||
BEGIN
|
||
-- Если иск не найден, пробуем перевести номер дела в другой формат (год двумя знаками или четырьмя)
|
||
CONV_NUMBER_FILE = CONVERT_NUMBER_FILE(:NUMBER_FILE, :PURPOSE);
|
||
|
||
IF (:CONV_NUMBER_FILE IS NOT NULL) THEN
|
||
BEGIN
|
||
ID_LAWSUIT = (SELECT L.ID FROM DOC$ABONENT$LAWSUIT L INNER JOIN DOC$ABONENT$LAWSUIT_CITIZEN LC ON LC.ID_LAWSUIT = L.ID INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = LC.ID_CITIZEN WHERE L.FILE_NUMBER STARTING WITH :CONV_NUMBER_FILE AND UPPER(C.SURNAME_NAME_PATRONYMIC) = :FIO_BY_SB);
|
||
|
||
IF (:ID_LAWSUIT IS NULL) THEN
|
||
BEGIN
|
||
ID_WRIT_EXEC = (SELECT RESULT FROM GET$WRIT_EXEC$SEARCH_BY_RESPOND(:NUMBER_FILE, :FIO_BY_SB));
|
||
ID_LAWSUIT = (SELECT WE.ID_LAWSUIT FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.ID = :ID_WRIT_EXEC);
|
||
|
||
ID_EXEC_PROC = (SELECT FIRST 1 EP.ID FROM DOC$LAWSUIT$EXEC_PROC EP WHERE (EP.ID_WRIT_OF_EXEC = :ID_WRIT_EXEC) AND (EP.ID_BANK IS NOT NULL) AND (EP.DATE_TRANSFERENCE <= :DATE_PAYMENT) ORDER BY EP.DATE_TRANSFERENCE DESC);
|
||
END
|
||
ELSE
|
||
NUMBER_FILE = :CONV_NUMBER_FILE;
|
||
END
|
||
|
||
-- Если иск не найден, пробуем отрезать номер участка из дела
|
||
IF (:ID_LAWSUIT IS NULL) THEN
|
||
BEGIN
|
||
NUMBER_FILE_WO_CD = TRIM_COURT_DISTRICT(:NUMBER_FILE);
|
||
IF (:NUMBER_FILE_WO_CD IS NOT NULL) THEN
|
||
ID_LAWSUIT = (SELECT L.ID FROM DOC$ABONENT$LAWSUIT L INNER JOIN DOC$ABONENT$LAWSUIT_CITIZEN LC ON LC.ID_LAWSUIT = L.ID INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = LC.ID_CITIZEN WHERE L.FILE_NUMBER STARTING WITH :NUMBER_FILE_WO_CD AND UPPER(C.SURNAME_NAME_PATRONYMIC) = :FIO_BY_SB);
|
||
END
|
||
END
|
||
END
|
||
END
|
||
|
||
-- Ищем иск по номеру дела и ответчику
|
||
IF ((:ID_LAWSUIT IS NOT NULL) AND (:ID_EXEC_PROC IS NULL)) THEN
|
||
BEGIN
|
||
-- IF ((SELECT COUNT(*) FROM DOC$LAWSUIT$EXEC_PROC EP INNER JOIN DOC$LAWSUIT$WRIT_OF_EXEC WE ON WE.ID = EP.ID_WRIT_OF_EXEC INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = WE.ID_RESPONDENT WHERE WE.ID_LAWSUIT = :ID_ISK AND UPPER(C.SURNAME_NAME_PATRONYMIC) = UPPER(:FIO_BY_SB) AND EP.ID_BANK IS NOT NULL) AND (EP.DATE_TRANSFERENCE < :DATE_PAYMENT) > 1) THEN
|
||
-- EXCEPTION CHECK_EXCEPTION 'Более 1 ИП: ' || COALESCE(:FIO_BY_SB, '');
|
||
|
||
ID_EXEC_PROC = NULL;
|
||
|
||
FOR SELECT
|
||
EP.ID,
|
||
EP.ID_WRIT_OF_EXEC,
|
||
REPLACE(UPPER(C.SURNAME_NAME_PATRONYMIC), 'Ё', 'Е')
|
||
FROM
|
||
DOC$LAWSUIT$EXEC_PROC EP
|
||
INNER JOIN DOC$LAWSUIT$WRIT_OF_EXEC WE ON WE.ID = EP.ID_WRIT_OF_EXEC
|
||
INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = WE.ID_RESPONDENT
|
||
WHERE
|
||
WE.ID_LAWSUIT = :ID_LAWSUIT
|
||
AND (EP.ID_BANK IS NOT NULL)
|
||
AND (EP.DATE_TRANSFERENCE <= :DATE_PAYMENT)
|
||
ORDER BY
|
||
EP.DATE_TRANSFERENCE DESC
|
||
INTO
|
||
:TMP_ID_EXEC_PROC,
|
||
:TMP_ID_WRIT_EXEC,
|
||
:FIO_RESPONDENT
|
||
DO
|
||
BEGIN
|
||
IF (RIGHT(:FIO_RESPONDENT, 5) = ' ОГЛЫ') THEN
|
||
FIO_RESPONDENT = LEFT(:FIO_RESPONDENT, CHAR_LENGTH(:FIO_RESPONDENT) - 5);
|
||
IF (RIGHT(:FIO_RESPONDENT, 5) = ' КЫЗЫ') THEN
|
||
FIO_RESPONDENT = LEFT(:FIO_RESPONDENT, CHAR_LENGTH(:FIO_RESPONDENT) - 5);
|
||
|
||
IF (:FIO_RESPONDENT = :FIO_BY_SB) THEN
|
||
BEGIN
|
||
ID_EXEC_PROC = :TMP_ID_EXEC_PROC;
|
||
ID_WRIT_EXEC = :TMP_ID_WRIT_EXEC;
|
||
BREAK;
|
||
END
|
||
END
|
||
|
||
IF (:ID_EXEC_PROC IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('По иску №' || :NUMBER_FILE || ', ИП по ответчику "' || :FIO_BY_SB || '" на ' || FORMAT_DATE(:DATE_PAYMENT) || ' не найдено.');
|
||
END
|
||
ELSE IF (:ID_WRIT_EXEC IS NULL) THEN
|
||
BEGIN
|
||
ID_WRIT_EXEC = (SELECT RESULT FROM GET$WRIT_EXEC$SEARCH_BY_RESPOND(:NUMBER_FILE, :FIO_BY_SB));
|
||
|
||
IF (:ID_WRIT_EXEC IS NOT NULL) THEN
|
||
BEGIN
|
||
ID_EXEC_PROC = (SELECT FIRST 1 EP.ID FROM DOC$LAWSUIT$EXEC_PROC EP WHERE EP.ID_WRIT_OF_EXEC = :ID_WRIT_EXEC AND EP.DATE_TRANSFERENCE < :DATE_PAYMENT ORDER BY EP.DATE_TRANSFERENCE DESC);
|
||
|
||
IF (:ID_EXEC_PROC IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Не найдено ИП (' || :NUMBER_WRIT_EXEC || ', оплачено ' || FORMAT_DATE(:DATE_PAYMENT) || ') по строке: ' || :PURPOSE);
|
||
|
||
ID_LAWSUIT = (SELECT WE.ID_LAWSUIT FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.ID = :ID_WRIT_EXEC);
|
||
END
|
||
END
|
||
END
|
||
ELSE IF (POSITION('№ ВС ', :PURPOSE) > 0) THEN
|
||
BEGIN
|
||
-- Проверка наличия номера после ВС
|
||
PURPOSE = REPLACE(:PURPOSE, '№ ВС №', '№ ВС');
|
||
|
||
IF (SUBSTRING(:PURPOSE FROM POSITION('№ ВС ', :PURPOSE) + 2 FOR 12) CONTAINING '№ ') THEN
|
||
BEGIN
|
||
NUMBER_WRIT_EXEC = REPLACE(SUBSTRING(:PURPOSE FROM POSITION('№ ВС ', :PURPOSE) + 2 FOR 14), ' ', '');
|
||
END
|
||
ELSE IF (SUBSTRING(:PURPOSE FROM POSITION('№ ВС ', :PURPOSE) + 2 FOR 12) CONTAINING '№') THEN
|
||
BEGIN
|
||
NUMBER_WRIT_EXEC = REPLACE(SUBSTRING(:PURPOSE FROM POSITION('№ ВС ', :PURPOSE) + 2 FOR 13), ' ', '');
|
||
END
|
||
ELSE
|
||
NUMBER_WRIT_EXEC = REPLACE(SUBSTRING(:PURPOSE FROM POSITION('№ ВС ', :PURPOSE) + 2 FOR 12), ' ', '');
|
||
|
||
-- exception CHECK_EXCEPTION :NUMBER_WRIT_EXEC;
|
||
-- Ищем исполнительное производство
|
||
ID_EXEC_PROC = (SELECT FIRST 1 EP.ID FROM DOC$LAWSUIT$EXEC_PROC EP INNER JOIN DOC$LAWSUIT$WRIT_OF_EXEC WE ON WE.ID = EP.ID_WRIT_OF_EXEC WHERE ((WE.NUMBER = :NUMBER_WRIT_EXEC) OR (WE.NUMBER_WRIT_EXEC_FOR_DUTY = :NUMBER_WRIT_EXEC)) AND (EP.ID_BANK = :ID_BANK) AND (EP.DATE_TRANSFERENCE <= :DATE_PAYMENT) ORDER BY EP.DATE_TRANSFERENCE DESC);
|
||
IF (:ID_EXEC_PROC IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Не найдено ИП (' || :NUMBER_WRIT_EXEC || ', оплачено ' || FORMAT_DATE(:DATE_PAYMENT) || ') по строке: ' || :PURPOSE);
|
||
|
||
ID_LAWSUIT = (SELECT WE.ID_LAWSUIT FROM DOC$LAWSUIT$EXEC_PROC EP INNER JOIN DOC$LAWSUIT$WRIT_OF_EXEC WE ON WE.ID = EP.ID_WRIT_OF_EXEC WHERE EP.ID = :ID_EXEC_PROC);
|
||
END
|
||
|
||
IF ((:ID_EXEC_PROC IS NOT NULL) AND (:ID_WRIT_EXEC IS NULL)) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Указано ИП, но не указан ИЛ.');
|
||
|
||
SUSPEND;
|
||
END
|
||
|
||
PROCEDURE RECOGN_BAILIFF(DATE_PAYMENT DOM$DATE NOT NULL, PURPOSE D_VARCHAR_500 NOT NULL) RETURNS (ID_LAWSUIT DOM$KEY, ID_WRIT_EXEC DOM$KEY, ID_EXEC_PROC DOM$KEY)
|
||
AS
|
||
DECLARE VARIABLE POS_NUMBER_WRIT_EXEC D_INTEGER;
|
||
DECLARE VARIABLE NUMBER_WRIT_EXEC TYPE OF DOM$NUMBER_WRIT_EXEC;
|
||
DECLARE VARIABLE ID_ABONENT DOM$ABONENT;
|
||
DECLARE VARIABLE POS_SNP_RESPONDENT D_INTEGER;
|
||
DECLARE VARIABLE POS_SNP_RESPONDENT_END D_INTEGER;
|
||
DECLARE VARIABLE SNP_RESPONDENT D_VARCHAR_100;
|
||
DECLARE VARIABLE NUMBER_FILE DOM$NUMBER_FILE;
|
||
DECLARE VARIABLE NUMBER_FILE_WO_CD DOM$NUMBER_FILE;
|
||
DECLARE VARIABLE ID_CORRECTION DOM$KEY;
|
||
BEGIN
|
||
-- У госпошлины нет реквизитов
|
||
IF (POSITION('(ИНН 0; КПП 0) Перечисление ГОСПОШЛИНЫ в АО "Газпром газораспределение дальний Восток":', :PURPOSE) > 0) THEN
|
||
BEGIN
|
||
SUSPEND;
|
||
EXIT;
|
||
END
|
||
|
||
-- Ищем нераспознаваемый платеж
|
||
ID_CORRECTION = (SELECT C.ID FROM DIR$EXEC_PROC$CORRECTION C WHERE C.PAYMENT_PURPOSE = :PURPOSE);
|
||
|
||
IF (:ID_CORRECTION IS NOT NULL) THEN
|
||
SELECT
|
||
C.CORRECT_NUMBER_FILE,
|
||
UPPER(C.CORRECT_FIO)
|
||
FROM
|
||
DIR$EXEC_PROC$CORRECTION C
|
||
WHERE
|
||
C.ID = :ID_CORRECTION
|
||
INTO
|
||
:NUMBER_FILE,
|
||
:SNP_RESPONDENT;
|
||
|
||
-- Получаем ФИО ответчика
|
||
IF (:SNP_RESPONDENT IS NULL) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('Перечисление в АО "Газпром газораспределение дальний Восток":', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('Перечисление в АО "Газпром газораспределение дальний Восток":');
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('Перечисление средств в счет погашения долга взыскателю :', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('Перечисление средств в счет погашения долга взыскателю :');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('КМС ГОСПОШЛИНА в пользу АО "ГАЗПРОМ газораспределение Дальний Восток"":', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('КМС ГОСПОШЛИНА в пользу АО "ГАЗПРОМ газораспределение Дальний Восток"":');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('КМС ДОЛГА в пользу АО "ГАЗПРОМ газораспределение Дальний Восток":', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('КМС ДОЛГА в пользу АО "ГАЗПРОМ газораспределение Дальний Восток":');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('КМС ДОЛГА в пользу ОАО "ХАБАРОВСККРАЙГАЗ":', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('КМС ДОЛГА в пользу ОАО "ХАБАРОВСККРАЙГАЗ":');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('Перечисление средств в счет погашения долга взыскателю :', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('Перечисление средств в счет погашения долга взыскателю :');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('(долг):', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('(долг):');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('(госпошлина):', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('(госпошлина):');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('Перечисление средств :', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('Перечисление средств :');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('Долг с:', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('Долг с:');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('Долг с :', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('Долг с :');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('Долг с ', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('Долг с ');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('Задолженность (АОГазпром газораспред.ДВ): ', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('Задолженность (АОГазпром газораспред.ДВ): ');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION('КМС СУДЕБНЫЕ РАСХ в пользу АО "ГАЗПРОМ газораспределение Дальний Восток":', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH('КМС СУДЕБНЫЕ РАСХ в пользу АО "ГАЗПРОМ газораспределение Дальний Восток":');
|
||
END
|
||
|
||
-- УФК по Хабаровскому краю (ОСП по Советско-Гаванскому району УФССП России по Хабаровскому краю и Еврейской автономной области)
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
-- Пример оплаты:
|
||
-- ДОЛГ ЗА ГАЗ ПО С/ПРИКАЗУ 2-1974/2018 ОТ 09.08.2018 Фамилия Имя Отчество адрес
|
||
POS_SNP_RESPONDENT = POSITION('ДОЛГ ЗА ГАЗ ПО С/ПРИКАЗУ ', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION(' ', :PURPOSE, 42) + 1;-- Ищем пробел после окончания даты приказа
|
||
END
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT = 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT = POSITION(':', :PURPOSE);
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
POS_SNP_RESPONDENT = :POS_SNP_RESPONDENT + CHAR_LENGTH(':');
|
||
END
|
||
|
||
IF (:POS_SNP_RESPONDENT > 0) THEN
|
||
BEGIN
|
||
POS_SNP_RESPONDENT_END = POSITION(' ', :PURPOSE, :POS_SNP_RESPONDENT);-- Фамилия
|
||
IF (:POS_SNP_RESPONDENT_END = 0) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Нет окончания фамилии');
|
||
|
||
POS_SNP_RESPONDENT_END = POSITION(' ', :PURPOSE, :POS_SNP_RESPONDENT_END + 1);-- Имя
|
||
IF (:POS_SNP_RESPONDENT_END = 0) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Нет окончания имени');
|
||
|
||
POS_SNP_RESPONDENT_END = POSITION(' ', :PURPOSE, :POS_SNP_RESPONDENT_END + 1);-- Отчество
|
||
IF (:POS_SNP_RESPONDENT_END = 0) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Нет окончания отчества');
|
||
|
||
SNP_RESPONDENT = REPLACE(:SNP_RESPONDENT, 'Ё', 'Е');
|
||
SNP_RESPONDENT = UPPER(SUBSTRING(:PURPOSE FROM :POS_SNP_RESPONDENT FOR (:POS_SNP_RESPONDENT_END - :POS_SNP_RESPONDENT)));
|
||
|
||
IF (RIGHT(:SNP_RESPONDENT, '1') = ',') THEN
|
||
SNP_RESPONDENT = TRIM(LEFT(:SNP_RESPONDENT, CHAR_LENGTH(:SNP_RESPONDENT) - 1));
|
||
IF (RIGHT(:SNP_RESPONDENT, '1') = '.') THEN
|
||
SNP_RESPONDENT = TRIM(LEFT(:SNP_RESPONDENT, CHAR_LENGTH(:SNP_RESPONDENT) - 1));
|
||
END
|
||
ELSE IF (POSITION('ФС ', :PURPOSE) = 0) THEN
|
||
BEGIN
|
||
SUSPEND;
|
||
EXIT;
|
||
END
|
||
END
|
||
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Не найдено ФИО ответчика');
|
||
|
||
-- Ищем номер ИЛ
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ВС N ', :PURPOSE);
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + 5;
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ВС ', UPPER(:PURPOSE));
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + 3;
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ФС N ', :PURPOSE);
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + 5;
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ФС ', UPPER(:PURPOSE));
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + 3;
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ВС', UPPER(:PURPOSE));
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + 2;
|
||
|
||
-- Это может быть часть текста "Хабаровский"
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
IF (SUBSTRING(:PURPOSE FROM :POS_NUMBER_WRIT_EXEC FOR 1) NOT BETWEEN '0' AND '9') THEN
|
||
POS_NUMBER_WRIT_EXEC = 0;
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ИД ', :PURPOSE);
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + 3;
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ИСПОЛНИТЕЛЬН ЛИСТ ', UPPER(:PURPOSE));
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + CHAR_LENGTH('ИСПОЛНИТЕЛЬН ЛИСТ ');
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ИСПОЛНИТЕЛЬН ', UPPER(:PURPOSE));
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + CHAR_LENGTH('ИСПОЛНИТЕЛЬН ');
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ИСПОЛНИТЕЛЬНЫЙ ', UPPER(:PURPOSE));
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + CHAR_LENGTH('ИСПОЛНИТЕЛЬНЫЙ ');
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ИСПОЛНИТЕЛ ЛИСТ ', UPPER(:PURPOSE));
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + CHAR_LENGTH('ИСПОЛНИТЕЛ ЛИСТ ');
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC = 0) THEN
|
||
BEGIN
|
||
POS_NUMBER_WRIT_EXEC = POSITION('ИСП ЛИСТ ', UPPER(:PURPOSE));
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
POS_NUMBER_WRIT_EXEC = :POS_NUMBER_WRIT_EXEC + CHAR_LENGTH('ИСП ЛИСТ ');
|
||
END
|
||
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
BEGIN
|
||
NUMBER_WRIT_EXEC = 'ВС' || SUBSTRING(:PURPOSE FROM :POS_NUMBER_WRIT_EXEC FOR 9);
|
||
|
||
-- Ищем опечатку в номере ИЛ
|
||
ID_CORRECTION = (SELECT C.ID FROM DIR$EXEC_PROC$CORRECTION C WHERE C.PAYMENT_SERIAL_WRIT_EXEC = :NUMBER_WRIT_EXEC AND C.TYPE_PAYMENT = 2);
|
||
|
||
IF (:ID_CORRECTION IS NOT NULL) THEN
|
||
SELECT
|
||
C.CORRECT_NUMBER_FILE,
|
||
UPPER(C.CORRECT_FIO)
|
||
FROM
|
||
DIR$EXEC_PROC$CORRECTION C
|
||
WHERE
|
||
C.ID = :ID_CORRECTION
|
||
INTO
|
||
:NUMBER_FILE,
|
||
:SNP_RESPONDENT;
|
||
END
|
||
|
||
IF (:NUMBER_FILE IS NULL) THEN
|
||
IF (:POS_NUMBER_WRIT_EXEC > 0) THEN
|
||
BEGIN
|
||
NUMBER_WRIT_EXEC = 'ВС' || SUBSTRING(:PURPOSE FROM :POS_NUMBER_WRIT_EXEC FOR 9);
|
||
|
||
IF (CHAR_LENGTH(:NUMBER_WRIT_EXEC) <> 11) THEN
|
||
BEGIN
|
||
-- Если номер ИЛ не полный, пытается найти его по совпадению известной части и ФИО
|
||
ID_WRIT_EXEC = (SELECT WE.ID FROM DOC$LAWSUIT$WRIT_OF_EXEC WE INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = WE.ID_RESPONDENT WHERE (UPPER(C.SURNAME_NAME_PATRONYMIC) = :SNP_RESPONDENT) AND (WE.NUMBER STARTING WITH :NUMBER_WRIT_EXEC));
|
||
|
||
IF (:ID_WRIT_EXEC IS NULL) THEN
|
||
EXIT;
|
||
END
|
||
ELSE
|
||
BEGIN
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Неправильный номер ИЛ: ' || COALESCE(:NUMBER_WRIT_EXEC, '<NULL>') || '.');
|
||
|
||
IF ((SELECT COUNT(*) FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.NUMBER = :NUMBER_WRIT_EXEC) > 1) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Более 1 исп. листа с №' || :NUMBER_WRIT_EXEC || '.' || ASCII_CHAR(31) || 'Устраните дубликаты.');
|
||
|
||
ID_WRIT_EXEC = (SELECT WE.ID FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.NUMBER = :NUMBER_WRIT_EXEC);
|
||
IF (:ID_WRIT_EXEC IS NULL) THEN
|
||
ID_WRIT_EXEC = (SELECT WE.ID FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.NUMBER_WRIT_EXEC_FOR_DUTY = :NUMBER_WRIT_EXEC);
|
||
END
|
||
|
||
IF (:ID_WRIT_EXEC IS NULL) THEN
|
||
BEGIN
|
||
NUMBER_WRIT_EXEC = 'ФС' || SUBSTRING(:PURPOSE FROM :POS_NUMBER_WRIT_EXEC FOR 9);
|
||
|
||
ID_WRIT_EXEC = (SELECT WE.ID FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.NUMBER = :NUMBER_WRIT_EXEC);
|
||
IF (:ID_WRIT_EXEC IS NULL) THEN
|
||
ID_WRIT_EXEC = (SELECT WE.ID FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.NUMBER_WRIT_EXEC_FOR_DUTY = :NUMBER_WRIT_EXEC);
|
||
END
|
||
|
||
IF (:ID_WRIT_EXEC IS NOT NULL) THEN
|
||
BEGIN
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Исполнительный лист №' || :NUMBER_WRIT_EXEC || ' не найден.');
|
||
|
||
ID_EXEC_PROC = (SELECT FIRST 1 EP.ID FROM DOC$LAWSUIT$EXEC_PROC EP WHERE EP.ID_WRIT_OF_EXEC = :ID_WRIT_EXEC AND EP.ID_BANK IS NULL AND EP.DATE_TRANSFERENCE < :DATE_PAYMENT ORDER BY EP.DATE_TRANSFERENCE DESC);
|
||
IF (:ID_EXEC_PROC IS NOT NULL) THEN
|
||
BEGIN
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Исполнительное производство по исп. листу №' || :NUMBER_WRIT_EXEC || ' не найдено.');
|
||
|
||
ID_LAWSUIT = (SELECT WE.ID_LAWSUIT FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.ID = :ID_WRIT_EXEC);
|
||
|
||
-- Проверяем соответствие ФИО
|
||
IF (:SNP_RESPONDENT IS NOT NULL) THEN
|
||
IF ((SELECT RESULT FROM GET$WRIT_EXEC$CHECK_RESPONDENT(:ID_WRIT_EXEC, :SNP_RESPONDENT)) = 0) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Другое ФИО у ответчика. В квитанции "' || COALESCE(:SNP_RESPONDENT, '<NULL>')
|
||
|| '", в ИЛ "' || COALESCE((SELECT UPPER(C.SURNAME_NAME_PATRONYMIC) FROM DOC$LAWSUIT$WRIT_OF_EXEC WE INNER JOIN REG$ABONENT$CITIZEN C ON C.ID = WE.ID_RESPONDENT WHERE WE.ID = :ID_WRIT_EXEC), 'NULL') || '".');
|
||
END
|
||
END
|
||
END
|
||
|
||
-- Ищем иск по номеру дела
|
||
IF (:ID_LAWSUIT IS NULL) THEN
|
||
BEGIN
|
||
IF (:NUMBER_FILE IS NULL) THEN
|
||
NUMBER_FILE = SEARCH_NUMBER_FILE(:PURPOSE, FALSE);
|
||
|
||
-- Ищем необходимость исправления
|
||
ID_CORRECTION = (SELECT C.ID FROM DIR$EXEC_PROC$CORRECTION C WHERE (C.PAYMENT_NUMBER_FILE IS NOT DISTINCT FROM :NUMBER_FILE) AND (UPPER(C.PAYMENT_FIO) = :SNP_RESPONDENT));
|
||
|
||
IF (:ID_CORRECTION IS NOT NULL) THEN
|
||
SELECT
|
||
C.CORRECT_NUMBER_FILE,
|
||
UPPER(C.CORRECT_FIO)
|
||
FROM
|
||
DIR$EXEC_PROC$CORRECTION C
|
||
WHERE
|
||
C.ID = :ID_CORRECTION
|
||
INTO
|
||
:NUMBER_FILE,
|
||
:SNP_RESPONDENT;
|
||
|
||
-- exception EXC$CHECK_DATA COALESCE(:NUMBER_FILE, '<NULL>') || ' ' || COALESCE(:SNP_RESPONDENT, '<NULL>');
|
||
|
||
IF (:NUMBER_FILE IS NOT NULL) THEN
|
||
BEGIN
|
||
-- Получаем исполнительный лист
|
||
ID_WRIT_EXEC = (SELECT RESULT FROM GET$WRIT_EXEC$SEARCH_BY_RESPOND(:NUMBER_FILE, :SNP_RESPONDENT));
|
||
|
||
IF (:ID_WRIT_EXEC IS NULL) THEN
|
||
BEGIN
|
||
-- Убираем номер участка
|
||
NUMBER_FILE_WO_CD = TRIM_COURT_DISTRICT(:NUMBER_FILE);
|
||
IF (:NUMBER_FILE IS NOT NULL) THEN
|
||
BEGIN
|
||
ID_WRIT_EXEC = (SELECT RESULT FROM GET$WRIT_EXEC$SEARCH_BY_RESPOND(:NUMBER_FILE_WO_CD, :SNP_RESPONDENT));
|
||
IF (:ID_WRIT_EXEC IS NOT NULL) THEN
|
||
NUMBER_FILE = :NUMBER_FILE_WO_CD;
|
||
END
|
||
END
|
||
|
||
IF (:ID_WRIT_EXEC IS NULL) THEN
|
||
BEGIN
|
||
-- Меняем формат года
|
||
NUMBER_FILE = CONVERT_NUMBER_FILE(:NUMBER_FILE, :PURPOSE);
|
||
IF (:NUMBER_FILE IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Пустой номер дела после конвертации: ' || :PURPOSE);
|
||
|
||
ID_WRIT_EXEC = (SELECT RESULT FROM GET$WRIT_EXEC$SEARCH_BY_RESPOND(:NUMBER_FILE, :SNP_RESPONDENT));
|
||
END
|
||
|
||
IF (:ID_WRIT_EXEC IS NOT NULL) THEN
|
||
BEGIN
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Иск №' || :NUMBER_FILE || ' не найден (ответчик ' || :SNP_RESPONDENT || ').');
|
||
|
||
ID_LAWSUIT = (SELECT WE.ID_LAWSUIT FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.ID = :ID_WRIT_EXEC);
|
||
|
||
-- Получаем исполнительное производство
|
||
ID_EXEC_PROC = (SELECT FIRST 1 EP.ID FROM DOC$LAWSUIT$EXEC_PROC EP WHERE EP.ID_WRIT_OF_EXEC = :ID_WRIT_EXEC AND EP.ID_BANK IS NULL AND EP.DATE_TRANSFERENCE < :DATE_PAYMENT ORDER BY EP.DATE_TRANSFERENCE DESC);
|
||
IF (:ID_EXEC_PROC IS NULL) THEN
|
||
BEGIN
|
||
NUMBER_WRIT_EXEC = (SELECT WE.NUMBER FROM DOC$LAWSUIT$WRIT_OF_EXEC WE WHERE WE.ID = :ID_WRIT_EXEC);
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Исполнительное производство по исп. листу №' || COALESCE(:NUMBER_WRIT_EXEC, '<NULL>') || ' дела ' || :NUMBER_FILE || ' не найдено.');
|
||
END
|
||
END
|
||
END
|
||
END
|
||
|
||
IF (:ID_EXEC_PROC IS NOT NULL) THEN
|
||
BEGIN
|
||
IF (:ID_LAWSUIT IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Иск не указан');
|
||
IF (:ID_WRIT_EXEC IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('ИЛ не указан');
|
||
END
|
||
ELSE
|
||
BEGIN
|
||
ID_LAWSUIT = NULL;
|
||
ID_WRIT_EXEC = NULL;
|
||
END
|
||
|
||
SUSPEND;
|
||
END
|
||
|
||
PROCEDURE TRY_CREATE_RECEIPT_BAILIFF(ID_SOURCE DOM$KEY NOT NULL, DATE_ACCOUNT DOM$DATE NOT NULL, DATE_PAYMENT DOM$DATE NOT NULL, NUMBER_RECEIPT DOM$NUMBER_CHECK NOT NULL, AMOUNT DOM$AMOUNT NOT NULL, PURPOSE D_VARCHAR_500 NOT NULL) RETURNS (RESULT DOM$KEY)
|
||
AS
|
||
DECLARE VARIABLE ID_BATCH DOM$KEY;
|
||
DECLARE VARIABLE ID_NF_ABONENT_FOR_PAYMENT_LAWSU DOM$ABONENT;
|
||
DECLARE VARIABLE ID_LAWSUIT DOM$KEY;
|
||
DECLARE VARIABLE ID_WRIT_EXEC DOM$KEY;
|
||
DECLARE VARIABLE ID_EXEC_PROC DOM$KEY;
|
||
DECLARE VARIABLE ID_GROUP_DISTRICT DOM$KEY;
|
||
BEGIN
|
||
-- Ищем иск в базе
|
||
SELECT
|
||
ID_LAWSUIT,
|
||
ID_WRIT_EXEC,
|
||
ID_EXEC_PROC
|
||
FROM
|
||
RECOGN_BAILIFF(:DATE_PAYMENT, :PURPOSE)
|
||
INTO
|
||
:ID_LAWSUIT,
|
||
:ID_WRIT_EXEC,
|
||
:ID_EXEC_PROC;
|
||
|
||
-- Если иск не найден, выходим
|
||
IF (:ID_LAWSUIT IS NULL) THEN
|
||
BEGIN
|
||
RESULT = NULL;
|
||
SUSPEND;
|
||
EXIT;
|
||
END
|
||
|
||
-- ID_NF_ABONENT_FOR_PAYMENT_LAWSU = (SELECT ID_NF_ABONENT_FOR_PAYMENT_LAWSU FROM DIR$ENTERPRISE$GROUP_DISTRICT WHERE ID = PKG$CONNECT.ID_GROUP_DISTRICT());
|
||
-- IF (:ID_NF_ABONENT_FOR_PAYMENT_LAWSU IS NULL) THEN
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('В группе участков "'
|
||
-- || (SELECT NAME FROM DIR$ENTERPRISE$GROUP_DISTRICT WHERE ID = PKG$CONNECT.ID_GROUP_DISTRICT())
|
||
-- || '" не указан лицевой счет для неопознанных платежей.' || ASCII_CHAR(31) || 'Убедитесь, что у вас сейчас правильная группа участков.');
|
||
--
|
||
-- Запоминаем группу участков иска
|
||
ID_GROUP_DISTRICT = PKG$ABONENT.GET_GROUP_DISTRICT_FOR_PAYMENT((SELECT L.ID_ABONENT FROM DOC$ABONENT$LAWSUIT L WHERE L.ID = :ID_LAWSUIT));
|
||
|
||
ID_SOURCE = COALESCE((SELECT B.ID_SOURCE_PAYMENT_BAILIFF FROM DIR$ENTERPRISE$GROUP_DISTRICT GD INNER JOIN DIR$ENTERPRISE$BRANCH B ON B.ID = GD.ID_BRANCH WHERE GD.ID = :ID_GROUP_DISTRICT), :ID_SOURCE);
|
||
|
||
-- Проверяем дублирование оплаты
|
||
IF (EXISTS(SELECT 1 FROM BAT$RECEIPT$RECEIPT R INNER JOIN BAT$RECEIPT$BATCH B ON B.ID = R.ID_BATCH WHERE (B.ID_SOURCE = :ID_SOURCE) AND (R.DATE_PAYMENT = :DATE_PAYMENT) AND (R.NUMBER = :NUMBER_RECEIPT))) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Квитанция №' || :NUMBER_RECEIPT || ' от ' || FORMAT_DATE(:DATE_PAYMENT) || ' на сумму ' || :AMOUNT || ' уже создана.');
|
||
|
||
-- Создаем пачку
|
||
IF ((SELECT COUNT(*) FROM BAT$RECEIPT$BATCH B WHERE (B.ID_GROUP_DISTRICT = :ID_GROUP_DISTRICT) AND (B.ID_SOURCE = :ID_SOURCE) AND (B.DATE_ACCOUNT = :DATE_ACCOUNT)) > 1) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('За ' || FORMAT_DATE(:DATE_ACCOUNT) || ' найдено более 1 пачки квитанций.');
|
||
|
||
ID_BATCH = (SELECT B.ID FROM BAT$RECEIPT$BATCH B WHERE (B.ID_GROUP_DISTRICT = :ID_GROUP_DISTRICT) AND (B.ID_SOURCE = :ID_SOURCE) AND (B.DATE_ACCOUNT = :DATE_ACCOUNT));
|
||
IF (:ID_BATCH IS NULL) THEN
|
||
BEGIN
|
||
INSERT INTO BAT$RECEIPT$BATCH
|
||
(ID, ID_GROUP_DISTRICT, ID_SOURCE, DATE_ACCOUNT)
|
||
VALUES
|
||
(NEXT VALUE FOR SEQ_BAT$RECEIPT$BATCH_ID, :ID_GROUP_DISTRICT, :ID_SOURCE, :DATE_ACCOUNT)
|
||
RETURNING
|
||
ID
|
||
INTO
|
||
:ID_BATCH;
|
||
END
|
||
ELSE IF ((SELECT B.LOADED FROM BAT$RECEIPT$BATCH B WHERE B.ID = :ID_BATCH) = 1) THEN
|
||
EXECUTE PROCEDURE PKG$EXCEPTION.FOR_BATCH_RECEIPT(:ID_BATCH, 'Пачка квитанций уже загружена.');
|
||
|
||
-- Создаем квитанцию
|
||
INSERT INTO BAT$RECEIPT$RECEIPT
|
||
(ID, ID_BATCH, ID_ABONENT, ID_PERIOD_FOR_PAYMENT, ID_TYPE_RECEIPT, ID_LAWSUIT, ID_WRIT_EXEC, ID_EXEC_PROC, DATE_PAYMENT, NUMBER, AUTODISTRIBUTE_SERVICES, AMOUNT_SERVICE_5, PURPOSE)
|
||
VALUES
|
||
(NEXT VALUE FOR SEQ_BAT$RECEIPT$RECEIPT_ID, :ID_BATCH, (SELECT ID_ABONENT FROM DOC$ABONENT$LAWSUIT WHERE ID = :ID_LAWSUIT), DATE_TO_PERIOD(:DATE_PAYMENT), (SELECT ID_TYPE_RECEIPT_VIA_BAILIFF FROM SYS$LINK$PAYMENT), :ID_LAWSUIT, :ID_WRIT_EXEC, :ID_EXEC_PROC, :DATE_PAYMENT, :NUMBER_RECEIPT, 0, :AMOUNT, :PURPOSE)
|
||
RETURNING
|
||
ID
|
||
INTO
|
||
:RESULT;
|
||
|
||
SUSPEND;
|
||
END
|
||
|
||
FUNCTION DETECT_PERS_ACCOUNT(PURPOSE D_VARCHAR_500 NOT NULL, TEXT_BEFORE D_VARCHAR_25 NOT NULL, TEXT_AFTER D_VARCHAR_10 NOT NULL) RETURNS DOM$ABONENT
|
||
AS
|
||
DECLARE VARIABLE POS DOM$INTEGER;
|
||
DECLARE VARIABLE RES DOM$ABONENT;
|
||
BEGIN
|
||
POS = POSITION(:TEXT_BEFORE, :PURPOSE);
|
||
IF (:POS > 0) THEN
|
||
BEGIN
|
||
PURPOSE = SUBSTRING(:PURPOSE FROM :POS + CHAR_LENGTH(:TEXT_BEFORE));
|
||
|
||
IF (SUBSTRING(:PURPOSE FROM 10 FOR CHAR_LENGTH(:TEXT_AFTER)) = :TEXT_AFTER) THEN
|
||
BEGIN
|
||
RES = LEFT(:PURPOSE, 9);
|
||
RETURN :RES;
|
||
WHEN ANY DO
|
||
RETURN NULL;
|
||
END
|
||
END
|
||
|
||
RETURN NULL;
|
||
END
|
||
|
||
FUNCTION RECOGN_INDIVID(PURPOSE D_VARCHAR_500 NOT NULL) RETURNS DOM$ABONENT
|
||
AS
|
||
DECLARE VARIABLE TEMP D_VARCHAR_500;
|
||
DECLARE VARIABLE ID_ABONENT DOM$ABONENT;
|
||
BEGIN
|
||
PURPOSE = REPLACE(REPLACE(:PURPOSE, '-', ''), ' ', '');
|
||
|
||
-- Поиск лицевого счета по шаблону
|
||
-- ПАО "МТС-БАНК"
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/сч', 'Плата');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/с', ',');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- АО "ТИНЬКОФФ БАНК"
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/счет', '.');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'ЛСИ', ';');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'Л/счет', 'за');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/с', '');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ПАО "ПОЧТА БАНК"
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'ЛС//№', '//');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/с', ';');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'ЛС//№', '(');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- РНКО "ПЛАТЕЖНЫЙ ЦЕНТР" (ООО)
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'ЛС', ',');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'Л.С', ',');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ПАО "ПРОМСВЯЗЬБАНК"
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'ЛС //№', '//');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- НКО "ПЕРСПЕКТИВА" (ООО)
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'Номерлицевогосчета', ';');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ДАЛЬНЕВОСТОЧНЫЙ ФИЛИАЛ ПАО РОСБАНК
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'ЛС', ':');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'ЛС', '');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'лс', '');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/счет:', ')');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/счет', ',Адрес');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/счет', '');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'Лицеврйсчет', 'Комсомольс');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ДАЛЬНЕВОСТОЧНЫЙ БАНК ПАО СБЕРБАНК
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'Оплатанал/счет', 'за');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/сч', ',');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'л/счету', 'ул');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ВОЛГО-ВЯТСКИЙ БАНК ПАО СБЕРБАНК
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'Л/СЧВ', '');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'Л/СЧ', '');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ООО КБ "ПЛАТИНА"
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'Л/счет', '/');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ФИЛИАЛ № 2754 БАНКА ВТБ (ПАО)
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'лицевойсчет', 'пред');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- АО "СК "Колымская"
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'пол/с', 'по');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ФИЛИАЛ ЦЕНТРАЛЬНЫЙ ПАО БАНКА "ФК ОТКРЫТИЕ"
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'ЛСИ', '///');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ООО НКО "ЯНДЕКС.ДЕНЬГИ"
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'посчету', 'за');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
-- ООО "ХКФ БАНК"
|
||
ID_ABONENT = DETECT_PERS_ACCOUNT(:PURPOSE, 'Л/счет', 'N');
|
||
IF (:ID_ABONENT IS NOT NULL) THEN
|
||
RETURN :ID_ABONENT;
|
||
|
||
RETURN NULL;
|
||
END
|
||
|
||
PROCEDURE TRY_CREATE_RECEIPT_INDIVID(DATE_ACCOUNT DOM$DATE NOT NULL, DATE_PAYMENT DOM$DATE NOT NULL, NUMBER_RECEIPT DOM$NUMBER_CHECK NOT NULL, AMOUNT DOM$AMOUNT NOT NULL, PURPOSE D_VARCHAR_500 NOT NULL, PAYER D_VARCHAR_200 NOT NULL, ID_ABONENT DOM$ABONENT) RETURNS (RESULT DOM$KEY)
|
||
AS
|
||
DECLARE VARIABLE ID_BRANCH DOM$KEY;
|
||
DECLARE VARIABLE ID_SOURCE DOM$KEY;
|
||
DECLARE VARIABLE ID_BATCH DOM$KEY;
|
||
DECLARE VARIABLE ID_GROUP_DISTRICT DOM$KEY;
|
||
DECLARE VARIABLE COMMENT_BATCH DOM$COMMENT;
|
||
BEGIN
|
||
IF (:ID_ABONENT IS NULL) THEN
|
||
BEGIN
|
||
-- Пробуем распознать плательщика
|
||
ID_ABONENT = RECOGN_INDIVID(:PURPOSE);
|
||
|
||
-- Получаем лицевой счет
|
||
IF (:ID_ABONENT IS NULL) THEN
|
||
BEGIN
|
||
EXIT;
|
||
-- EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Лицевой счет не распознан: "' || :PURPOSE || '" (' || :NUMBER_RECEIPT || ').');
|
||
|
||
/* ID_ABONENT = (SELECT ID_NF_ABONENT_FOR_PAYMENT_LAWSU FROM DIR$ENTERPRISE$GROUP_DISTRICT WHERE ID = :ID_GROUP_DISTRICT);
|
||
|
||
IF (:ID_ABONENT IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('В группе участков "'
|
||
|| (SELECT NAME FROM DIR$ENTERPRISE$GROUP_DISTRICT WHERE ID = :ID_GROUP_DISTRICT)
|
||
|| '" не указан лицевой счет для неопознанных платежей.');*/
|
||
END
|
||
END
|
||
|
||
-- Получаем филиал по абоненту
|
||
ID_BRANCH = (SELECT A.ID_BRANCH FROM DIR$ABONENT$ABONENT A WHERE A.ID = :ID_ABONENT);
|
||
IF (:ID_BRANCH IS NULL) THEN
|
||
BEGIN
|
||
SUSPEND;
|
||
EXIT;
|
||
END
|
||
|
||
-- Определяем источник оплаты
|
||
ID_SOURCE = (SELECT ID_SOURCE_INDIVID_PAYMENT_ORDER FROM DIR$ENTERPRISE$BRANCH WHERE ID = :ID_BRANCH);
|
||
IF (:ID_SOURCE IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA_BRANC(:ID_BRANCH, 'Не указан источник оплаты для индивидуальных платежей.');
|
||
|
||
-- Определяем группу участков
|
||
IF (:ID_BRANCH = 2) THEN
|
||
ID_GROUP_DISTRICT = 2;
|
||
ELSE
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA_BRANC(:ID_BRANCH, 'Не указана группа участков по умолчанию.');
|
||
|
||
-- Определяем, кто ведет учет
|
||
IF ((SELECT RESULT FROM GET$ABONENT$CHARGING_GAS_AMURCC(:ID_ABONENT)) = 1) THEN
|
||
COMMENT_BATCH = 'АмурВЦ';
|
||
ELSE
|
||
COMMENT_BATCH = 'Общество';
|
||
|
||
-- Ищем пачку квитанций
|
||
ID_BATCH = (SELECT B.ID FROM BAT$RECEIPT$BATCH B WHERE (B.ID_GROUP_DISTRICT = :ID_GROUP_DISTRICT) AND (B.ID_SOURCE = :ID_SOURCE) AND (B.DATE_ACCOUNT = :DATE_ACCOUNT) AND (B.COMMENT IS NOT DISTINCT FROM :COMMENT_BATCH));
|
||
|
||
IF (:ID_BATCH IS NULL) THEN
|
||
BEGIN
|
||
INSERT INTO BAT$RECEIPT$BATCH
|
||
(ID, ID_GROUP_DISTRICT, ID_SOURCE, DATE_ACCOUNT, COMMENT)
|
||
VALUES
|
||
(NEXT VALUE FOR SEQ_BAT$RECEIPT$BATCH_ID, :ID_GROUP_DISTRICT, :ID_SOURCE, :DATE_ACCOUNT, :COMMENT_BATCH)
|
||
RETURNING
|
||
ID
|
||
INTO
|
||
:ID_BATCH;
|
||
END
|
||
ELSE IF ((SELECT B.LOADED FROM BAT$RECEIPT$BATCH B WHERE B.ID = :ID_BATCH) = 1) THEN
|
||
EXECUTE PROCEDURE PKG$EXCEPTION.FOR_BATCH_RECEIPT(:ID_BATCH, 'Пачка квитанций уже загружена.');
|
||
|
||
-- Создаем квитанцию
|
||
INSERT INTO BAT$RECEIPT$RECEIPT
|
||
(ID, ID_BATCH, ID_ABONENT, ID_PERIOD_FOR_PAYMENT, ID_TYPE_RECEIPT, DATE_PAYMENT, NUMBER, AUTODISTRIBUTE_SERVICES, AMOUNT_SERVICE_1, PURPOSE, PAYER)
|
||
VALUES
|
||
(NEXT VALUE FOR SEQ_BAT$RECEIPT$RECEIPT_ID, :ID_BATCH, :ID_ABONENT, DEC_PERIOD(DATE_TO_PERIOD(:DATE_PAYMENT)), (SELECT RESULT FROM GET$ABONENT$DEFAULT_TYPE_RECEIP(:ID_ABONENT)), :DATE_PAYMENT, :NUMBER_RECEIPT, 1, :AMOUNT, :PURPOSE, :PAYER)
|
||
RETURNING
|
||
ID
|
||
INTO
|
||
:RESULT;
|
||
|
||
SUSPEND;
|
||
END
|
||
|
||
PROCEDURE ADD_CORRECT_NONACCEPT(ID_PAYMENT DOM$KEY NOT NULL, NUMBER_FILE_OLD DOM$NUMBER_FILE NOT NULL, RESPONDENT_OLD D_VARCHAR_100 NOT NULL, NUMBER_FILE_NEW DOM$NUMBER_FILE NOT NULL, RESPONDENT_NEW D_VARCHAR_100 NOT NULL)
|
||
AS
|
||
DECLARE VARIABLE ID_CORRECTION DOM$KEY;
|
||
BEGIN
|
||
-- Проверяем, что квитанция не создана
|
||
IF ((SELECT B.RECEIPT_CREATED FROM INF$PAYMENT$BANK_STTM B WHERE B.ID = :ID_PAYMENT) IS TRUE) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Платеж с кодом ' || :ID_PAYMENT || ' уже создан.');
|
||
|
||
-- Проверяем, что это безакцепт
|
||
IF ((SELECT B.ID_BANK FROM INF$PAYMENT$BANK_STTM B WHERE B.ID = :ID_PAYMENT) IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Платеж с кодом ' || :ID_PAYMENT || ' не является оплатой безакцепта.');
|
||
|
||
-- Ищем повтор
|
||
IF (EXISTS(SELECT 1 FROM DIR$EXEC_PROC$CORRECTION C WHERE (C.PAYMENT_NUMBER_FILE = :NUMBER_FILE_OLD) AND (C.PAYMENT_FIO = :RESPONDENT_OLD) AND (C.TYPE_PAYMENT = 1))) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Корректировка уже есть в справочнике.');
|
||
|
||
-- Добавляем
|
||
IN AUTONOMOUS TRANSACTION DO
|
||
INSERT INTO DIR$EXEC_PROC$CORRECTION
|
||
(PAYMENT_NUMBER_FILE, PAYMENT_FIO, CORRECT_NUMBER_FILE, CORRECT_FIO, TYPE_PAYMENT)
|
||
VALUES
|
||
(:NUMBER_FILE_OLD, :RESPONDENT_OLD, :NUMBER_FILE_NEW, :RESPONDENT_NEW, 1)
|
||
RETURNING
|
||
ID
|
||
INTO
|
||
:ID_CORRECTION;
|
||
|
||
-- Создаем квитанцию
|
||
BEGIN
|
||
EXECUTE PROCEDURE CREATE_RECEIPT(:ID_PAYMENT, NULL);
|
||
|
||
WHEN ANY DO
|
||
BEGIN
|
||
IN AUTONOMOUS TRANSACTION DO
|
||
DELETE FROM DIR$EXEC_PROC$CORRECTION WHERE ID = :ID_CORRECTION;
|
||
|
||
EXCEPTION;
|
||
-- ### this is line 1731 which was mentioned in the ticket ### -- END
|
||
END
|
||
|
||
-- Проверяем, что она создалась
|
||
IF ((SELECT B.RECEIPT_CREATED FROM INF$PAYMENT$BANK_STTM B WHERE B.ID = :ID_PAYMENT) IS FALSE) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Платеж с кодом ' || :ID_PAYMENT || ' не распознался.' || ASCII_CHAR(31) || 'Проверьте реквизиты.');
|
||
END
|
||
|
||
PROCEDURE ADD_CORRECT_BAILIFF(ID_PAYMENT DOM$KEY NOT NULL, NUMBER_FILE DOM$NUMBER_FILE NOT NULL, RESPONDENT D_VARCHAR_100 NOT NULL)
|
||
AS
|
||
DECLARE VARIABLE PURPOSE D_VARCHAR_500;
|
||
BEGIN
|
||
-- Проверяем, что квитанция не создана
|
||
IF ((SELECT B.RECEIPT_CREATED FROM INF$PAYMENT$BANK_STTM B WHERE B.ID = :ID_PAYMENT) IS TRUE) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Платеж с кодом ' || :ID_PAYMENT || ' уже создан.');
|
||
|
||
-- Проверяем, что это ССП
|
||
IF ((SELECT B.ID_BAILIFF FROM INF$PAYMENT$BANK_STTM B WHERE B.ID = :ID_PAYMENT) IS NULL) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Платеж с кодом ' || :ID_PAYMENT || ' не является оплатой от ССП.');
|
||
|
||
-- Ищем повтор
|
||
PURPOSE = (SELECT B.PURPOSE FROM INF$PAYMENT$BANK_STTM B WHERE B.ID = :ID_PAYMENT);
|
||
IF (EXISTS(SELECT 1 FROM DIR$EXEC_PROC$CORRECTION C WHERE (C.PAYMENT_PURPOSE = :PURPOSE) AND (C.TYPE_PAYMENT = 2))) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Назначение уже есть в справочнике.');
|
||
|
||
-- Добавляем
|
||
INSERT INTO DIR$EXEC_PROC$CORRECTION
|
||
(PAYMENT_PURPOSE, CORRECT_NUMBER_FILE, CORRECT_FIO, TYPE_PAYMENT)
|
||
VALUES
|
||
(:PURPOSE, :NUMBER_FILE, :RESPONDENT, 2);
|
||
|
||
-- Создаем квитанцию
|
||
EXECUTE PROCEDURE CREATE_RECEIPT(:ID_PAYMENT, NULL);
|
||
|
||
-- Проверяем, что она создалась
|
||
IF ((SELECT B.RECEIPT_CREATED FROM INF$PAYMENT$BANK_STTM B WHERE B.ID = :ID_PAYMENT) IS FALSE) THEN
|
||
EXECUTE PROCEDURE OPER$EXCEPTION$CHECK_DATA('Платеж с кодом ' || :ID_PAYMENT || ' не распознался.' || ASCII_CHAR(31) || 'Проверьте реквизиты.');
|
||
END
|
||
|
||
PROCEDURE SEND_NOTIFY_LOAD_BANK_STATEMENT(DATE_ACCOUNT DOM$DATE NOT NULL, RECOGN DOM$INTEGER NOT NULL, NOT_RECOGN DOM$INTEGER NOT NULL)
|
||
AS
|
||
BEGIN
|
||
EXECUTE PROCEDURE PKG$SEND_EMAIL.SEND_TO_EMAILS('ulezlova@gazdv.ru,kuzmina2@gazdv.ru,muratova@gazdv.ru,smirinskayaea@gazdv.ru', 'kuzmin@gazdv.ru', 'Загружена выписка из банк-клиента за ' || FORMAT_DATE(:DATE_ACCOUNT),
|
||
TRIM(IIF(:NOT_RECOGN = 0, 'Распознаны все платежи.', 'Не распознано платежей: ' || :NOT_RECOGN || '.')));
|
||
END
|
||
|
||
PROCEDURE SEND_NOTIFY_RECONG_BANK_STATEME(DATE_ACCOUNT DOM$DATE NOT NULL)
|
||
AS
|
||
BEGIN
|
||
EXECUTE PROCEDURE PKG$SEND_EMAIL.SEND_TO_EMAILS('ulezlova@gazdv.ru,kuzmina2@gazdv.ru,muratova@gazdv.ru,smirinskayaea@gazdv.ru', 'kuzmin@gazdv.ru', 'Распознана выписка за ' || FORMAT_DATE(:DATE_ACCOUNT),
|
||
'Распознаны все платежи.');
|
||
END
|
||
|
||
PROCEDURE SEND_NOTIFY_ERROR_LOAD_BANK_STA
|
||
AS
|
||
BEGIN
|
||
EXECUTE PROCEDURE PKG$SEND_EMAIL.SEND_TO_EMAILS('kuzmin@gazdv.ru,ryazanov@gazdv.ru', NULL, 'Ошибка при загрузке выписки из банк-клиента', 'Загружал пользователь: ' || PKG$CONNECT.CURRENT_USER_SURNAME_NP());
|
||
END
|
||
|
||
PROCEDURE SEND_NOTIFY_ERROR_DETECT_SOURCE
|
||
AS
|
||
BEGIN
|
||
EXECUTE PROCEDURE PKG$SEND_EMAIL.SEND_TO_EMAILS('kuzmin@gazdv.ru,ryazanov@gazdv.ru', 'ulezlova@gazdv.ru,kuzmina2@gazdv.ru,muratova@gazdv.ru,smirinskayaea@gazdv.ru', 'Ошибка при поиске источников оплаты в выписке', 'Загружал пользователь: ' || PKG$CONNECT.CURRENT_USER_SURNAME_NP());
|
||
END
|
||
|
||
PROCEDURE SEND_NOTIFY_ERROR_CREATE_ALL_RE
|
||
AS
|
||
BEGIN
|
||
EXECUTE PROCEDURE PKG$SEND_EMAIL.SEND_TO_EMAILS('kuzmin@gazdv.ru,ryazanov@gazdv.ru', 'ulezlova@gazdv.ru,kuzmina2@gazdv.ru,muratova@gazdv.ru,smirinskayaea@gazdv.ru', 'Ошибка при создании квитанций по выписке', 'Загружал пользователь: ' || PKG$CONNECT.CURRENT_USER_SURNAME_NP());
|
||
END
|
||
END^
|
||
|
||
|
||
CREATE PACKAGE BODY PKG$SEND_EMAIL
|
||
AS
|
||
BEGIN
|
||
PROCEDURE SEND_TO_EMAILS(EMAILS DOM$EMAILS NOT NULL, EMAILS_COPY DOM$EMAILS, SUBJECT DOM$EMAIL_SUBJECT NOT NULL, BODY_MAIL DOM$EMAIL_BODY NOT NULL)
|
||
AS
|
||
DECLARE VARIABLE ERROR D_VARCHAR_255;
|
||
BEGIN
|
||
END
|
||
|
||
PROCEDURE SEND_TO_LIST_USERS(LIST_USERS D_LIST_ID NOT NULL, LIST_USERS_COPY D_LIST_ID, SUBJECT DOM$EMAIL_SUBJECT NOT NULL, BODY_MAIL DOM$EMAIL_BODY NOT NULL)
|
||
AS
|
||
DECLARE VARIABLE EMAILS DOM$EMAILS;
|
||
DECLARE VARIABLE EMAILS_COPY DOM$EMAILS;
|
||
BEGIN
|
||
END
|
||
|
||
PROCEDURE SEND_TO_GROUP(ID_GROUP DOM$KEY NOT NULL, SUBJECT DOM$EMAIL_SUBJECT NOT NULL, BODY_MAIL DOM$EMAIL_BODY NOT NULL)
|
||
AS
|
||
DECLARE VARIABLE EMAILS DOM$EMAILS;
|
||
BEGIN
|
||
END
|
||
END^
|
||
|
||
|
||
|
||
SET TERM ; ^
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Descriptions ***/
|
||
/******************************************************************************/
|
||
|
||
COMMENT ON DOMAIN DOM$ABONENT IS
|
||
'Лицевой счет';
|
||
|
||
COMMENT ON DOMAIN DOM$ABONENT_LONG IS
|
||
'Длинный лицевой счет';
|
||
|
||
COMMENT ON DOMAIN DOM$ADDRESS IS
|
||
'Адрес';
|
||
|
||
COMMENT ON DOMAIN DOM$AMOUNT IS
|
||
'Сумма';
|
||
|
||
COMMENT ON DOMAIN DOM$CITIZEN_NAME IS
|
||
'Имя';
|
||
|
||
COMMENT ON DOMAIN DOM$CITIZEN_PATRONYMIC IS
|
||
'Отчество';
|
||
|
||
COMMENT ON DOMAIN DOM$CITIZEN_SURNAME IS
|
||
'Фамилия';
|
||
|
||
COMMENT ON DOMAIN DOM$COMMENT IS
|
||
'Примечание';
|
||
|
||
COMMENT ON DOMAIN DOM$CURRENT_TIMESTAMP IS
|
||
'Текущее дата/время';
|
||
|
||
COMMENT ON DOMAIN DOM$EMAIL IS
|
||
'E-mail';
|
||
|
||
COMMENT ON DOMAIN DOM$EMAILS IS
|
||
'Список эл. почтовых ящиков';
|
||
|
||
COMMENT ON DOMAIN DOM$NAME_CONTRACTOR IS
|
||
'Наименование контрагента (в 1С)';
|
||
|
||
COMMENT ON DOMAIN DOM$NAME_LONG IS
|
||
'Наименование элемента справочника большой длины';
|
||
|
||
COMMENT ON DOMAIN DOM$NAME_SHORT IS
|
||
'Наименование короткой длины';
|
||
|
||
COMMENT ON DOMAIN DOM$NAME_STANDARD IS
|
||
'Наименование элемента справочника обычной длины';
|
||
|
||
COMMENT ON DOMAIN DOM$NAME_TINY IS
|
||
'Наименование маленькой длины';
|
||
|
||
COMMENT ON DOMAIN DOM$NETWORK_PORT IS
|
||
'Номер порта';
|
||
|
||
COMMENT ON DOMAIN DOM$NUMBER_CHECK IS
|
||
'Номер чека (квитанции)';
|
||
|
||
COMMENT ON DOMAIN DOM$NUMBER_EXEC_PROCESS IS
|
||
'Номер исполнительного производства';
|
||
|
||
COMMENT ON DOMAIN DOM$NUMBER_FILE IS
|
||
'Номер дела';
|
||
|
||
COMMENT ON DOMAIN DOM$NUMBER_PAYMENT_ORDER IS
|
||
'Номер платежного поручения';
|
||
|
||
COMMENT ON DOMAIN DOM$NUMBER_WRIT_EXEC IS
|
||
'Номер исполнительного листа';
|
||
|
||
COMMENT ON DOMAIN DOM$PERIOD IS
|
||
'Период';
|
||
|
||
COMMENT ON DOMAIN DOM$POSITION IS
|
||
'Позиция записи';
|
||
|
||
COMMENT ON DOMAIN DOM$SERIES_WRIT_EXEC IS
|
||
'Серия исполнительного листа';
|
||
|
||
COMMENT ON DOMAIN DOM$STATE IS
|
||
'Код состояния документа';
|
||
|
||
COMMENT ON DOMAIN DOM$STRING_DATE IS
|
||
'Дата в строковом представлении';
|
||
|
||
COMMENT ON DOMAIN DOM$TIME IS
|
||
'Время';
|
||
|
||
COMMENT ON DOMAIN DOM$VERSION IS
|
||
'Версия базы данных (Major.Minor.Release)';
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Descriptions ***/
|
||
/******************************************************************************/
|
||
|
||
COMMENT ON TABLE SYS$LOG$EXCEPTION IS
|
||
'Лог исключений в базе данных';
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Descriptions ***/
|
||
/******************************************************************************/
|
||
|
||
COMMENT ON PROCEDURE GET$ABONENT$DETERMINE_GD IS
|
||
'Определяет группу участков абонента по его лицевому счету';
|
||
|
||
|
||
|
||
/******************************************************************************/
|
||
/*** Privileges ***/
|
||
/******************************************************************************/
|
||
|
||
|
||
/* Privileges of users */
|
||
GRANT USAGE ON EXCEPTION EXC$CANCEL TO PUBLIC;
|
||
GRANT ALL ON SYS$LOG$EXCEPTION TO READER_ROLE;
|
||
GRANT EXECUTE ON PROCEDURE GET$ABONENT$DETERMINE_GD TO READER_ROLE;
|
||
GRANT EXECUTE ON PROCEDURE OPER$EXCEPTION$CANCEL TO READER_ROLE;
|
||
GRANT ALL ON SYS$LOG$EXCEPTION TO USER_ROLE;
|
||
GRANT EXECUTE ON PROCEDURE GET$ABONENT$DETERMINE_GD TO USER_ROLE;
|
||
GRANT EXECUTE ON PROCEDURE GET$WRIT_EXEC$SEARCH_BY_RESPOND TO USER_ROLE;
|
||
GRANT EXECUTE ON PROCEDURE OPER$EXCEPTION$CANCEL TO USER_ROLE;
|
||
|
||
/* Privileges of procedures */
|
||
GRANT SELECT ON DOC$ABONENT$LAWSUIT TO PROCEDURE GET$WRIT_EXEC$SEARCH_BY_RESPOND;
|
||
GRANT SELECT ON DOC$LAWSUIT$WRIT_OF_EXEC TO PROCEDURE GET$WRIT_EXEC$SEARCH_BY_RESPOND;
|
||
GRANT SELECT ON REG$ABONENT$CITIZEN TO PROCEDURE GET$WRIT_EXEC$SEARCH_BY_RESPOND;
|
||
GRANT EXECUTE ON PROCEDURE OPER$EXCEPTION$CHECK_DATA TO PROCEDURE GET$WRIT_EXEC$SEARCH_BY_RESPOND;
|
||
GRANT INSERT ON SYS$LOG$EXCEPTION TO PROCEDURE OPER$EXCEPTION$CANCEL;
|
||
GRANT USAGE ON EXCEPTION EXC$CANCEL TO PROCEDURE OPER$EXCEPTION$CANCEL;
|
||
GRANT USAGE ON SEQUENCE SEQ_SYS$LOG$EXCEPTION_ID TO PROCEDURE OPER$EXCEPTION$CANCEL;
|
||
exit;
|
||
|
||
"""
|
||
|
||
act = isql_act('db', test_script, substitutions=[('- line .*', ''), ('At line .*', '')])
|
||
|
||
expected_stderr = """
|
||
Statement failed, SQLSTATE = 42000
|
||
Dynamic SQL Error
|
||
-SQL error code = -104
|
||
-Token unknown - line 1735, column 9
|
||
-IF
|
||
"""
|
||
|
||
@pytest.mark.version('>=3.0.5')
|
||
def test_1(act: Action):
|
||
act.expected_stderr = expected_stderr
|
||
act.execute()
|
||
assert act.clean_stderr == act.clean_expected_stderr
|