ТНВЭД — различия между версиями
Материал из wiki.standart-n.ru
								
												
				Olgav  (обсуждение | вклад)  | 
				Olgav  (обсуждение | вклад)   | 
				||
| Строка 66: | Строка 66: | ||
* Заполняем коды    | * Заполняем коды    | ||
  <nowiki>  |   <nowiki>  | ||
| − | update wares w set tnvedcode=(select first 1  t.tnvedcode from tnved t where t.barcode=w.barcode)  where  exists  (select first 1  t.tnvedcode from tnved t where t.barcode=w.barcode)  | + | update wares w set tnvedcode=(select first 1  t.tnvedcode from tnved t where t.barcode=w.barcode)  where  exists  (select first 1  t.tnvedcode from tnved t where t.barcode=w.barcode);  | 
| − | update wares w set tnvedcode=(select first 1  t.tnvedcode from tnved t where t.sname=w.sname) where  exists  (select first 1  t.tnvedcode from tnved t where t.sname=w.sname) and coalesce(trim(w.tnvedcode),'')=''  | + | update wares w set tnvedcode=(select first 1  t.tnvedcode from tnved t where t.sname=w.sname) where  exists  (select first 1  t.tnvedcode from tnved t where t.sname=w.sname) and coalesce(trim(w.tnvedcode),'')='';  | 
| − | update wares w set tnvedcode=(select first 1 ww.tnvedcode from wares ww where ww.name_id=w.name_id and ww.tnvedcode is not null )  where exists  (select first 1 ww.tnvedcode from wares ww  where ww.name_id=w.name_id and ww.tnvedcode is not null )  and w.tnvedcode is null  | + | update wares w set tnvedcode=(select first 1 ww.tnvedcode from wares ww where ww.name_id=w.name_id and ww.tnvedcode is not null )  where exists  (select first 1 ww.tnvedcode from wares ww  where ww.name_id=w.name_id and ww.tnvedcode is not null )  and w.tnvedcode is null;  | 
| + | |||
| + | EXECUTE BLOCK  | ||
| + | AS  | ||
| + | declare variable b dm_text;  | ||
| + | declare variable t dm_text;  | ||
| + | declare variable ware_id dm_uuid;  | ||
| + | BEGIN  | ||
| + |   for select t.barcode,t.tnvedcode from tnved t into :b,:t do  | ||
| + |   begin  | ||
| + |     update wares set tnvedcode=:t where barcode containing :b and tnvedcode is null;  | ||
| + |   end  | ||
| + | END;  | ||
  </nowiki>  |   </nowiki>  | ||
* Обновить менеджер до версии не ниже 273.71  | * Обновить менеджер до версии не ниже 273.71  | ||
Версия 12:14, 16 августа 2018
- В глобальной базе в таблицу wares добавляем поле TNVEDCODE.
 
ALTER TABLE WARES ADD TNVEDCODE DM_TEXT; SET TERM ^ ; CREATE trigger wares_biu_tnved for wares active before insert or update position 0 AS begin new.tnvedcode=trim(new.tnvedcode); end^ SET TERM ; ^
- Для всех сводных баз и локальных по g$tasks так же отправляем создание новой колонки
 - В vw_doc_detail добавить колонку TNVEDCODE. Заполнять значением из wares. Распространить изменение по g$tasks на все локальные базы.
 - Новая вспомогательная таблица TNVED
 
/******************************************************************************/
/***               Generated by IBExpert 16.08.2018 12:21:47                ***/
/******************************************************************************/
/******************************************************************************/
/***      Following SET SQL DIALECT is just for the Database Comparer       ***/
/******************************************************************************/
SET SQL DIALECT 3;
/******************************************************************************/
/***                                 Tables                                 ***/
/******************************************************************************/
CREATE TABLE TNVED (
    TNVEDCODE  DM_TEXT NOT NULL /* DM_TEXT = VARCHAR(250) */,
    BARCODE    DM_TEXT NOT NULL /* DM_TEXT = VARCHAR(250) */,
    SNAME      DM_TEXT NOT NULL /* DM_TEXT = VARCHAR(250) */
);
/******************************************************************************/
/***                              Primary keys                              ***/
/******************************************************************************/
ALTER TABLE TNVED ADD CONSTRAINT PK_TNVED PRIMARY KEY (TNVEDCODE, BARCODE, SNAME);
/******************************************************************************/
/***                                Indices                                 ***/
/******************************************************************************/
CREATE INDEX TNVED_IDX1 ON TNVED (TNVEDCODE);
CREATE INDEX TNVED_IDX2 ON TNVED (BARCODE);
CREATE INDEX TNVED_IDX3 ON TNVED (SNAME);
/******************************************************************************/
/***                               Privileges                               ***/
/******************************************************************************/
 
- Выполнить файл tnved.sql
 - Заполняем коды
 
update wares w set tnvedcode=(select first 1  t.tnvedcode from tnved t where t.barcode=w.barcode)  where  exists  (select first 1  t.tnvedcode from tnved t where t.barcode=w.barcode);
update wares w set tnvedcode=(select first 1  t.tnvedcode from tnved t where t.sname=w.sname) where  exists  (select first 1  t.tnvedcode from tnved t where t.sname=w.sname) and coalesce(trim(w.tnvedcode),'')='';
update wares w set tnvedcode=(select first 1 ww.tnvedcode from wares ww where ww.name_id=w.name_id and ww.tnvedcode is not null )  where exists  (select first 1 ww.tnvedcode from wares ww  where ww.name_id=w.name_id and ww.tnvedcode is not null )  and w.tnvedcode is null;
EXECUTE BLOCK
AS
declare variable b dm_text;
declare variable t dm_text;
declare variable ware_id dm_uuid;
BEGIN
  for select t.barcode,t.tnvedcode from tnved t into :b,:t do
  begin
    update wares set tnvedcode=:t where barcode containing :b and tnvedcode is null;
  end
END;
 
- Обновить менеджер до версии не ниже 273.71