CREATE TABLE IF NOT EXISTS pessoa_vendedores (id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,pessoa_id BIGINT UNSIGNED NOT NULL,empresa_id BIGINT UNSIGNED NOT NULL,grupo_pessoa_id BIGINT UNSIGNED NULL,tipo_vendedor VARCHAR(20) NOT NULL DEFAULT 'interno',comissao_padrao DECIMAL(10,4) NOT NULL DEFAULT 0,desconto_maximo DECIMAL(10,4) NOT NULL DEFAULT 0,meta_mensal DECIMAL(15,2) NOT NULL DEFAULT 0,data_admissao DATE NULL,data_desligamento DATE NULL,permite_desconto TINYINT(1) NOT NULL DEFAULT 1,bloqueado TINYINT(1) NOT NULL DEFAULT 0,motivo_bloqueio TEXT NULL,ativo TINYINT(1) NOT NULL DEFAULT 1,criado_em TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,atualizado_em TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,excluido_em TIMESTAMP NULL,CONSTRAINT fk_pv_pessoa FOREIGN KEY(pessoa_id) REFERENCES pessoas(id),CONSTRAINT fk_pv_empresa FOREIGN KEY(empresa_id) REFERENCES empresas(id),CONSTRAINT fk_pv_grupo FOREIGN KEY(grupo_pessoa_id) REFERENCES grupos_pessoa(id),UNIQUE KEY uk_pv_pessoa_empresa(pessoa_id,empresa_id),INDEX idx_pv_empresa(empresa_id,ativo));
