Files
controles/database.sql

100 lines
2.9 KiB
MySQL
Raw Permalink Normal View History

-- Tabela de Militantes
CREATE TABLE militantes (
id INT PRIMARY KEY AUTO_INCREMENT,
nome VARCHAR(100) NOT NULL,
cpf VARCHAR(14) UNIQUE,
email VARCHAR(100) UNIQUE,
telefone VARCHAR(15),
endereco VARCHAR(255),
filiado BOOLEAN DEFAULT false
);
-- Tabela de Cotas Mensais
CREATE TABLE cotas_mensais (
id INT PRIMARY KEY AUTO_INCREMENT,
militante_id INT,
valor_antigo DECIMAL(10, 2) NOT NULL,
valor_novo DECIMAL(10, 2) NOT NULL,
data_alteracao DATE NOT NULL,
FOREIGN KEY (militante_id) REFERENCES militantes(id)
);
-- Tabela de Pagamentos
CREATE TABLE tipos_pagamento (
id INT PRIMARY KEY AUTO_INCREMENT,
descricao VARCHAR(100) NOT NULL
);
CREATE TABLE pagamentos (
id INT PRIMARY KEY AUTO_INCREMENT,
militante_id INT,
tipo_pagamento_id INT,
valor DECIMAL(10, 2) NOT NULL,
data_pagamento DATE NOT NULL,
FOREIGN KEY (militante_id) REFERENCES militantes(id),
FOREIGN KEY (tipo_pagamento_id) REFERENCES tipos_pagamento(id)
);
-- Tabela de Tipos de Materiais
CREATE TABLE tipos_materiais (
id INT PRIMARY KEY AUTO_INCREMENT,
descricao VARCHAR(100) NOT NULL
);
-- Tabela de Materiais Vendidos
CREATE TABLE materiais_vendidos (
id INT PRIMARY KEY AUTO_INCREMENT,
militante_id INT,
tipo_material_id INT,
descricao VARCHAR(255) NOT NULL,
valor DECIMAL(10, 2) NOT NULL,
data_venda DATE NOT NULL,
FOREIGN KEY (militante_id) REFERENCES militantes(id),
FOREIGN KEY (tipo_material_id) REFERENCES tipos_materiais(id)
);
-- Tabela de Vendas de Jornais Avulsos
CREATE TABLE vendas_jornais_avulsos (
id INT PRIMARY KEY AUTO_INCREMENT,
militante_id INT,
quantidade INT NOT NULL,
valor_total DECIMAL(10, 2) NOT NULL,
data_venda DATE NOT NULL,
FOREIGN KEY (militante_id) REFERENCES militantes(id)
);
-- Tabela de Assinaturas Anuais
CREATE TABLE assinaturas_anuais (
id INT PRIMARY KEY AUTO_INCREMENT,
militante_id INT,
tipo_material_id INT,
quantidade INT NOT NULL,
valor_total DECIMAL(10, 2) NOT NULL,
data_inicio DATE NOT NULL,
data_fim DATE NOT NULL,
FOREIGN KEY (militante_id) REFERENCES militantes(id),
FOREIGN KEY (tipo_material_id) REFERENCES tipos_materiais(id)
);
-- Tabela de Relatório de Cotas Mensais
CREATE TABLE relatorio_cotas_mensais (
id INT PRIMARY KEY AUTO_INCREMENT,
setor_id INT,
comite_id INT,
total_cotas DECIMAL(10, 2) NOT NULL,
data_relatorio DATE NOT NULL,
FOREIGN KEY (setor_id) REFERENCES setores(id),
FOREIGN KEY (comite_id) REFERENCES comites_centrais(id)
);
-- Tabela de Relatório de Vendas de Materiais
CREATE TABLE relatorio_vendas_materiais (
id INT PRIMARY KEY AUTO_INCREMENT,
setor_id INT,
comite_id INT,
total_vendas DECIMAL(10, 2) NOT NULL,
data_relatorio DATE NOT NULL,
FOREIGN KEY (setor_id) REFERENCES setores(id),
FOREIGN KEY (comite_id) REFERENCES comites_centrais(id)
);