Обновление базы для маркировки ЛС — различия между версиями

Материал из wiki.standart-n.ru
Перейти к: навигация, поиск
(Выполняем скрипт)
(Выполняем скрипт)
Строка 235: Строка 235:
  
 
SET TERM ; ^
 
SET TERM ; ^
 
</pre>
 
  
  
Строка 264: Строка 262:
 
^
 
^
 
SET TERM ; ^
 
SET TERM ; ^
 +
 +
</pre>
  
 
==Дополнительно==
 
==Дополнительно==

Версия 10:56, 25 августа 2020

Заменить версию Менеджера

Заменить ManagerXP2.exe на версию 274_47_8 от июля 2020 г. или более новую.

Выполняем скрипт


SET TERM ^ ;
create or alter procedure PR_COPY_MARK_DETAIL (
    DOC_ID_IN integer,
    DOC_ID_OUT integer)
as
begin
INSERT INTO MARK_DETAIL (DOC_ID, PART_ID, MARK_DATA, QUANT, COMMITDATE, INSERTDT, DOCNUM, DOC_DATE, DDA_ID,
PLACE_ID_IN, PLACE_ID_OUT, GTIN, SERIES_NUMBER, EXPIRATION_DATE, ACTIVEPOS, SERIA, KIZ,  SSCC, ACCEPTED)
    select :DOC_ID_OUT, PART_ID, MARK_DATA, -QUANT, COMMITDATE, INSERTDT, DOCNUM, DOC_DATE,(select first 1 id from doc_detail_active dd where dd.doc_id=:doc_id_out and dd.part_id=md.part_id),
PLACE_ID_IN, PLACE_ID_OUT, GTIN, SERIES_NUMBER, EXPIRATION_DATE, 2, SERIA, KIZ, SSCC, ACCEPTED
from  MARK_DETAIL md where doc_id = :DOC_ID_IN ;
end^
SET TERM ; ^
/* Следующие операторы GRANT сгенерированы автоматически */
GRANT SELECT,INSERT ON MARK_DETAIL TO PROCEDURE PR_COPY_MARK_DETAIL;
GRANT SELECT ON DOC_DETAIL_ACTIVE TO PROCEDURE PR_COPY_MARK_DETAIL;
/* Существующие привилегии на эту процедуру */
GRANT EXECUTE ON PROCEDURE PR_COPY_MARK_DETAIL TO SYSDBA;
SET TERM ^ ;
create or alter procedure PR_DOC_CANCEL (
    DOC_ID type of DM_ID,
    DOC_CANCEL type of DM_STATUS,
    AUDIT_ID type of DM_ID,
    OWNER_ID type of DM_ID)
returns (
    CANCEL_RESULT integer)
as
declare variable DELETED_DOC_ID bigint;
declare variable DOC_STATUS type of DM_STATUS;
declare variable CONTRACT_ID DM_ID;
begin
  /*
cancel_result:
0 - удаление проведенного документа
1 - удаление рабочего/отложенного документа
2 - откладываем рабочий документ
3 - отложенный документ делаем рабочим
*/
  select STATUS, CONTRACT_ID, DELETED_DOC_ID
  from DOCS
  where ID = :DOC_ID
  into :DOC_STATUS, :CONTRACT_ID, :DELETED_DOC_ID;
  if (DOC_STATUS = 1) then --если документ проведен
  begin
    delete from DOC_DETAIL
    where DOC_ID = :DOC_ID;
    update DOCS
    set STATUS = -1,
        COMMITSESSION_ID = :AUDIT_ID
    where ID = :DOC_ID;
    if (CONTRACT_ID <> 0) then
    begin
      execute procedure PR_CREDITCOMMIT(:CONTRACT_ID);
    end
    CANCEL_RESULT = 0;
  end
  else
  if (DOC_STATUS in (0, 2)) then --документ рабочий или отложенный
    if (DOC_CANCEL = 1) then --документ отменяем
    begin
      insert into DOCS_CANCELED (ID, PARENT_ID, DOC_TYPE, STATUS, AGENT_ID, DOCNUM, DOCDATE, CAPTION, RGUID, INSERTDT,
                                 POSTDT, AUDIT_ID, VNUM, VSHIFT, CREATER, OWNER, COMMITDATE, PACKET, DEVICE_NUM, SUMMA,
                                 SUMMA_O, SUM_NDSO, SUM_NDSR, CALCSUMMA, COMMENTS, SUMM1, SUMM2, SUMM3, SUMM4,
                                 CHECKDATA, COMMITSESSION_ID, SUM_DSC, CASHDATA, PRICE_TYPE, CURRENCY_ID, BASE_AGENT_ID,
                                 CONTRACT_ID, LINK_ID, DELETED_DOC_ID, OPLATA, DATE_OPL, MAKE_ID, DOC_PAY_DATE, BONUS,
                                 D$UUID, D$SRVUPDDT)
      select ID, PARENT_ID, DOC_TYPE, STATUS, AGENT_ID, DOCNUM, DOCDATE, CAPTION, RGUID, INSERTDT, POSTDT, AUDIT_ID,
             VNUM, VSHIFT, CREATER, OWNER, COMMITDATE, PACKET, DEVICE_NUM, SUMMA, SUMMA_O, SUM_NDSO, SUM_NDSR,
             CALCSUMMA, COMMENTS, SUMM1, SUMM2, SUMM3, SUMM4, CHECKDATA, COMMITSESSION_ID, SUM_DSC, CASHDATA,
             PRICE_TYPE, CURRENCY_ID, BASE_AGENT_ID, CONTRACT_ID, LINK_ID, DELETED_DOC_ID, OPLATA, DATE_OPL, MAKE_ID,
             DOC_PAY_DATE, BONUS, D$UUID, D$SRVUPDDT
      from DOCS
      where ID = :DOC_ID;
      insert into DOC_DETAIL_ACTIVE_CANCELED (ID, PARENT_ID, DOC_ID, PART_ID, PART_PARENT_ID, DOC_DETAIL_ID, PRICE, NAC,
                                              QUANT, DISCOUNT, SUMMA, SUMMA_O, DCARD, WARE_ID, PRICE_O, PRICE_Z,
                                              PRICE_R, BARCODE, BARCODE1, GODENDO, SERIA, NDS, SUM_NDSO, SUM_NDSR, SERT,
                                              DATESERT, KEMVSERT, SDSERT, REGN, NGTD, EDIZM, NAME_ID, IZG_ID,
                                              COUNTRY_ID, ORIG_CODE, ORIG_NAME_ID, ORIG_IZG_ID, ORIG_COUNTRY_ID, Z_ID,
                                              SKLAD_ID, SNAME, SIZG, SCOUNTRY, SORIG_NAME, SORIG_IZG, SORIG_COUNTRY,
                                              INSERTDT, INFO, KOEF, MOTHERPART_ID, DEP, BCODE_IZG, HUMAN_QUANT, SUM_DSC,
                                              CUSTOMDRAW, STATUS, PART_TYPE, BASE_AGENT_ID, GROUP_ID, PACKET, VPART_ID,
                                              GNVLS, MAKE_ID, MNN, ACCOMP_ID, MOTHERPART_UUID)
      select ID, PARENT_ID, DOC_ID, PART_ID, PART_PARENT_ID, DOC_DETAIL_ID, PRICE, NAC, QUANT, DISCOUNT, SUMMA, SUMMA_O,
             DCARD, WARE_ID, PRICE_O, PRICE_Z, PRICE_R, BARCODE, BARCODE1, GODENDO, SERIA, NDS, SUM_NDSO, SUM_NDSR,
             SERT, DATESERT, KEMVSERT, SDSERT, REGN, NGTD, EDIZM, NAME_ID, IZG_ID, COUNTRY_ID, ORIG_CODE, ORIG_NAME_ID,
             ORIG_IZG_ID, ORIG_COUNTRY_ID, Z_ID, SKLAD_ID, SNAME, SIZG, SCOUNTRY, SORIG_NAME, SORIG_IZG, SORIG_COUNTRY,
             INSERTDT, INFO, KOEF, MOTHERPART_ID, DEP, BCODE_IZG, HUMAN_QUANT, SUM_DSC, CUSTOMDRAW, STATUS, PART_TYPE,
             BASE_AGENT_ID, GROUP_ID, PACKET, VPART_ID, GNVLS, MAKE_ID, MNN, ACCOMP_ID, MOTHERPART_UUID
      from DOC_DETAIL_ACTIVE
      where DOC_ID = :DOC_ID;
      delete from DOC_DETAIL_ACTIVE_MMBSH
      where DOC_ID = :DOC_ID;
      delete from DOC_DETAIL_ACTIVE
      where DOC_ID = :DOC_ID;
      delete from DOCS
      where ID = :DOC_ID;
      if (DELETED_DOC_ID > 0) then
      begin
        update DOCS
        set STATUS = 1,
            COMMITSESSION_ID = :AUDIT_ID
        where ID = :DELETED_DOC_ID;
        insert into DOC_DETAIL (PART_TYPE, PARENT_ID, DOC_ID, PART_ID, QUANT, DCARD, SUMMA, SUMMA_O, NAC, DISCOUNT,
                                SUM_NDSO, SUM_NDSR, SUM_DSC)
        select (select PART_TYPE
                from PARTS
                where ID = DDD.PART_ID), PARENT_ID, :DELETED_DOC_ID, PART_ID, QUANT, DCARD, SUMMA, SUMMA_O, NAC,
                DISCOUNT, SUM_NDSO, SUM_NDSR, SUM_DSC
        from DOC_DETAIL_DELETED DDD
        where DOC_ID = :DELETED_DOC_ID;
        delete from DOC_DETAIL_DELETED
        where DOC_ID = :DELETED_DOC_ID;
      end
      CANCEL_RESULT = 1;
    end
    else
    if (DOC_CANCEL = 0) then --откладываем либо возвращаем документ
      if (DOC_STATUS = 0) then --откладываем рабочий документ
      begin
        update DOCS
        set STATUS = 2,
            COMMITSESSION_ID = :AUDIT_ID
        where ID = :DOC_ID;
        CANCEL_RESULT = 2;
      end
      else --возвращаем отложенный документ
      begin
        update DOCS
        set STATUS = 0,
            AUDIT_ID = :AUDIT_ID,
            OWNER = :OWNER_ID
        where ID = :DOC_ID;
        CANCEL_RESULT = 3;
      end
    else
      exception EX_WRONGDOCSTATUS; --передали неправильный статус
  execute procedure PR_UPDBLOCKINFO_BY_DOC(:DOC_ID, :DOC_STATUS);
  execute procedure PR_DOEVENT('EV_DOCCANCEL');
  
    --Удаляме данные из mark_detail при отмене документа
    delete from mark_detail where doc_id = :doc_id;
  suspend;
end^
SET TERM ; ^
/* Следующие операторы GRANT сгенерированы автоматически */
GRANT SELECT,DELETE,UPDATE ON DOCS TO PROCEDURE PR_DOC_CANCEL;
GRANT SELECT,INSERT,DELETE ON DOC_DETAIL TO PROCEDURE PR_DOC_CANCEL;
GRANT EXECUTE ON PROCEDURE PR_CREDITCOMMIT TO PROCEDURE PR_DOC_CANCEL;
GRANT INSERT ON DOCS_CANCELED TO PROCEDURE PR_DOC_CANCEL;
GRANT INSERT ON DOC_DETAIL_ACTIVE_CANCELED TO PROCEDURE PR_DOC_CANCEL;
GRANT SELECT,DELETE ON DOC_DETAIL_ACTIVE TO PROCEDURE PR_DOC_CANCEL;
GRANT SELECT,DELETE ON DOC_DETAIL_ACTIVE_MMBSH TO PROCEDURE PR_DOC_CANCEL;
GRANT SELECT ON PARTS TO PROCEDURE PR_DOC_CANCEL;
GRANT SELECT,DELETE ON DOC_DETAIL_DELETED TO PROCEDURE PR_DOC_CANCEL;
GRANT EXECUTE ON PROCEDURE PR_UPDBLOCKINFO_BY_DOC TO PROCEDURE PR_DOC_CANCEL;
GRANT EXECUTE ON PROCEDURE PR_DOEVENT TO PROCEDURE PR_DOC_CANCEL;
GRANT SELECT,DELETE ON MARK_DETAIL TO PROCEDURE PR_DOC_CANCEL;
/* Существующие привилегии на эту процедуру */
GRANT EXECUTE ON PROCEDURE PR_DOC_CANCEL TO PROCEDURE PR_DOC_CANCELDEFER;
GRANT EXECUTE ON PROCEDURE PR_DOC_CANCEL TO PROCEDURE PR_DOC_REACTIVATE;
GRANT EXECUTE ON PROCEDURE PR_DOC_CANCEL TO PROCEDURE PR_DOC_SPLITBYBASEAGENT;
GRANT EXECUTE ON PROCEDURE PR_DOC_CANCEL TO "PUBLIC";
GRANT EXECUTE ON PROCEDURE PR_DOC_CANCEL TO STANDART;
GRANT EXECUTE ON PROCEDURE PR_DOC_CANCEL TO SYSDBA;


SET SQL DIALECT 3;



SET TERM ^ ;



CREATE OR ALTER TRIGGER DOCS_CANCELED_BI_DISTR FOR DOCS_CANCELED
ACTIVE BEFORE INSERT POSITION 0
AS
begin
  if (new.d$uuid is null) then
  begin
    new.d$uuid=UUID_TO_CHAR(GEN_UUID());
    new.d$srvupddt='2000-01-01';
--    update or insert into g$distribute (TABLENAME,UUID,SOPER,FROM_PROFILE_ID) values ('DOCS_CANCELED',new.d$uuid,0,null) matching (TABLENAME,UUID);
  end
end
^

SET TERM ; ^


SET SQL DIALECT 3;



SET TERM ^ ;



CREATE OR ALTER TRIGGER AGENTS_CHANGE_MARK_TYPE_BU FOR AGENTS
ACTIVE AFTER UPDATE POSITION 0
AS
begin
update doc_detail_active dd set dd.accepttype=new.mark_type where
dd.doc_id in (select d.id from docs d join doc_detail_active dd1 on dd1.doc_id=d.id where d.agent_id=new.id);
end
^

SET TERM ; ^

SET SQL DIALECT 3;



SET TERM ^ ;



CREATE OR ALTER TRIGGER DOC_DETAIL_ACTIVE_MARK_BI FOR DOC_DETAIL_ACTIVE
ACTIVE BEFORE INSERT OR UPDATE POSITION 0
AS
begin
if (new.marking is null ) then
new.marking=0;
--if (new.accepttype is null) then
new.accepttype=(select a.mark_type from docs d join agents a on d.agent_id=a.id where d.id=new.doc_id);
end
^

SET TERM ; ^


SET TERM ^ ;
CREATE OR ALTER TRIGGER GROUP_DETAIL_AD0 FOR GROUP_DETAIL
ACTIVE AFTER DELETE POSITION 0
AS
begin
   if ((old.group_id=-43) and (old.grouptable='DOC_DETAIL_ACTIVE')) then
  begin
  update doc_detail_active dd set dd.marking=0 where id=old.grouptable_id;
  end
end
^
SET TERM ; ^

SET TERM ^ ;
CREATE OR ALTER TRIGGER GROUP_DETAIL_AIU0 FOR GROUP_DETAIL
ACTIVE AFTER INSERT OR UPDATE POSITION 0
AS
begin
  if ((new.group_id=-43) and (new.grouptable='DOC_DETAIL_ACTIVE')) then
  begin
  update doc_detail_active dd set dd.marking=1 where id=new.grouptable_id;
  end
end
^
SET TERM ; ^

Дополнительно

Убрать прежнее обновление процедуры PR_DOC_PRIHOD_COMMIT_RECURSE, которое добавляло группу "-43"

Поправить процедуру PR_EDITCUSTOMDOC, после строк

if (DOC_BASE_TYPE = 1) then 
  begin
    if (DOC_STATUS = 1) then --
    begin

заменить блок команд, добавить, при необходимости переменные

for
          select PART_ID, QUANT, SUMMA, DISCOUNT, SUM_DSC, SUM_NDSO, ACCEPTANCE, AGENT_FIRST, DATE_FIRST_PRIHOD,
                 MARKING, DATEPROD, GTIN_SUBJ, ACCEPTTYPE
          from DOC_DETAIL
          where DOC_ID = :DOC_ID
          into :PART_ID, :QUANT, :SUMMA, :DISCOUNT, :SUM_DSC, :SUM_NDSO, :ACCEPTANCE, :AGENT_FIRST, :DATE_FIRST_PRIHOD,
               :MARKING, :DATEPROD, :GTIN_SUBJ, :ACCEPTTYPE
      do
      begin
        CUR_DDA_ID = gen_id(GEN_DOC_DETAIL_ACTIVE_ID, 1);
        insert into DOC_DETAIL_ACTIVE (ID, DOC_ID, PART_ID, QUANT, SUMMA, DISCOUNT, KOEF, SUM_DSC, SUM_NDSO, ACCEPTANCE,
                                       AGENT_FIRST, DATE_FIRST_PRIHOD, MARKING, DATEPROD, GTIN_SUBJ, ACCEPTTYPE)
        values (:CUR_DDA_ID, :CUR_DOC_ID, :PART_ID, :QUANT, :SUMMA, :DISCOUNT, 0, :SUM_DSC, :SUM_NDSO, :ACCEPTANCE,
                :AGENT_FIRST, :DATE_FIRST_PRIHOD, :MARKING, :DATEPROD, :GTIN_SUBJ, :ACCEPTTYPE);
        update MARK_DETAIL M
        set M.DOC_ID = :CUR_DOC_ID,
            M.DDA_ID = :CUR_DDA_ID
        where M.DOC_ID = :DOC_ID and
              M.PART_ID = :PART_ID;
      end

примерно так PR EDITCUSTOMDOC.png

declare variable QUANT DM_DOUBLE;
declare variable ACCEPTTYPE DM_ID;
declare variable CUR_DDA_ID DM_ID;
declare variable SUMMA DM_DOUBLE;
declare variable GTIN_SUBJ DM_TEXT;
declare variable DATEPROD DM_DATE;
declare variable ACCEPTANCE DM_ID;
declare variable MARKING DM_ID;
declare variable AGENT_FIRST DM_TEXT;
declare variable DATE_FIRST_PRIHOD DM_DATE;
declare variable DISCOUNT DM_DOUBLE;
declare variable SUM_NDSO DM_DOUBLE;
declare variable SUM_DSC DM_DOUBLE;
declare variable VNUM type of DM_ID_NULL;
declare variable DOC_TYPE type of DM_ID;
declare variable DOC_BASE_TYPE type of DM_ID;
declare variable DOC_STATUS type of DM_STATUS;
declare variable DOC_AGENT_ID type of DM_ID;
declare variable DOCNUM type of DM_TEXT;
declare variable DOC_CAPTION type of DM_TEXT;
declare variable BASE_AGENT_ID integer;
declare variable DOCDATE type of DM_DATETIME;
declare variable EGAIS_NUM DM_TEXT;
declare variable EGAIS_ID DM_TEXT;
declare variable EGAIS_UNITTYPE DM_TEXT;
declare variable EGAIS_STATUS DM_STATUS;
declare variable PART_ID DM_ID_NULL;
declare variable COMMENTS DM_BLOBTEXT;

Добавить поля, без которых будет ругаться на изменение процедуры:

ALTER TABLE DOC_DETAIL ADD MARKING DM_ID_NULL;  --и на точках и серверной/сводной базе, т.к. это поле может быть нулевым
ALTER TABLE DOC_DETAIL ADD ACCEPTTYPE DM_ID_NULL;  --и на точках и серверной/сводной базе, т.к. это поле может быть нулевым
ALTER TABLE DOC_DETAIL ADD GTIN DM_TEXT;
ALTER TABLE DOC_DETAIL ADD GTIN_SUBJ DM_TEXT;
ALTER TABLE DOC_DETAIL ADD DATEPROD dm_date;
ALTER TABLE DOC_DETAIL ADD GSERNUM DM_TEXT;

ТМС Проведение с авторасходом

Для того, чтобы в авторасход автоматически копировались datamatriх коды, нужно:

1) добавить копирование кодов в расходный документ

        EndIBTransaction(trn1,1);
        STARTIBTRANSACTION(trn1,1);
        try
         query3:=ExecIBQuery(trn1,'execute procedure PR_COPY_MARK_DETAIL('+doc_id2+','+comdoc2+');',1);   //провел расход перемещения
        except          
         EndIBTransaction(trn1,0);      
         exit;
        end;     

2) убрать автоматическое проведение документа

примерно так Авторасход, маркировка.png

Теги: маркировка, МДЛП