CREATE OR ALTER TRIGGER EVENT_BRUTTO_BU FOR EVENT_BRUTTO
ACTIVE BEFORE UPDATE POSITION 0
AS
begin
  IF (NEW.ORGANIZATION_OTPRAVITEL_ID < 1)
  THEN
    NEW.ORGANIZATION_OTPRAVITEL_ID = NULL;

  IF (NEW.ORGANIZATION_POLUCHATEL_ID < 1)
  THEN
    NEW.ORGANIZATION_POLUCHATEL_ID = NULL;

  IF (NEW.ORGANIZATION_PLATELSHIK_ID < 1)
  THEN
    NEW.ORGANIZATION_PLATELSHIK_ID = NULL;

  IF (NEW.ORGANIZATION_TRANSPORT_ID < 1)
  THEN
    NEW.ORGANIZATION_TRANSPORT_ID = NULL;

  IF (NEW.DRIVER_ID < 1)
  THEN
    NEW.DRIVER_ID = NULL;

  IF (NEW.PAYMENT_ID < 1)
  THEN
    NEW.PAYMENT_ID = NULL;

  IF (NEW.TRAILER_ID < 1)
  THEN
    NEW.TRAILER_ID = NULL;

  IF (NEW.CARGO_DANGER_ID < 1)
  THEN
    NEW.CARGO_DANGER_ID = NULL;

  IF (ABS(NEW.BRUTTO - OLD.BRUTTO) >= 0.001) THEN NEW.COUNT_WEIGHT = 0;
end;

CREATE OR ALTER TRIGGER EVENT_TARA_BU FOR EVENT_TARA
ACTIVE BEFORE UPDATE POSITION 0
AS
begin
  IF (ABS(NEW.TARA - OLD.TARA) >= 0.001) THEN NEW.COUNT_WEIGHT = 0;
end;
