def create_product(): if user_validate(): if request.method == 'POST': name = request.form['name'].strip().upper() gross_price = float(request.form['gross_price'].strip()) net_price = float(request.form['net_price'].strip()) profit_percentage = round((net_price - gross_price) / gross_price, 2) provider = persistence.read_one( 'SELECT * FROM PROVIDERS WHERE NAME="{}"'.format( request.form['provider'].strip())) if provider and persistence.create( 'INSERT INTO PRODUCTS (NAME, GROSS_PRICE, NET_PRICE, PROFIT_PERCENTAGE, PROVIDER) VALUES ("{}", {}, {}, {}, {})' .format(name, gross_price, net_price, profit_percentage, provider[0])): flash('Produto cadastrado com sucesso.') flash('success') log( 'create', 'PRODUCT: ("{}", {}, {}, {}, {}) -- {} ({})'.format( name, gross_price, net_price, profit_percentage, provider, session['user'][0], datetime.now())) else: flash('Não foi possível cadastrar o produto.') flash('danger') return redirect(url_for('products')) else: return redirect(url_for('login'))
def create_client(): if user_validate(): if request.method == 'POST': name = request.form['name'].strip().upper() cpf = request.form['cpf'].strip() address = request.form['address'].strip().upper() neighborhood = request.form['neighborhood'].strip().upper() city = request.form['city'].strip().upper() telephone = request.form['telephone'].strip() cellphone = request.form['cellphone'].strip() if persistence.create( 'INSERT INTO CLIENTS (NAME, CPF, ADDRESS, NEIGHBORHOOD, CITY, TELEPHONE, CELLPHONE) VALUES ("{}", "{}", "{}", "{}", "{}", "{}", "{}")' .format(name, cpf, address, neighborhood, city, telephone, cellphone)): flash('Cliente cadastrado com sucesso.') flash('success') log( 'create', 'CLIENT: ("{}", "{}", "{}", "{}", "{}", "{}", "{}") -- {} ({})' .format(name, cpf, address, neighborhood, city, telephone, cellphone, session['user'][0], datetime.now())) else: flash('Não foi possível cadastrar o cliente.') flash('danger') return redirect(url_for('clients')) else: return redirect(url_for('login'))
def create_service(): if user_validate(): if request.method == 'POST': name = request.form['name'].strip().upper() price = float(request.form['price'].strip()) if persistence.create( 'INSERT INTO SERVICES (NAME, PRICE) VALUES ("{}", {})'. format(name, price)): flash('Serviço cadastrado com sucesso.') flash('success') log( 'create', 'SERVICE: ("{}", {}) -- {} ({})'.format( name, price, session['user'][0], datetime.now())) else: flash('Não foi possível cadastrar o serviço.') flash('danger') return redirect(url_for('services')) else: return redirect(url_for('login'))
def create_provider(): if user_validate(): if request.method == 'POST': name = request.form['name'].strip().upper() cnpj = request.form['cnpj'].strip() email = request.form['email'].strip().lower() if persistence.create( 'INSERT INTO PROVIDERS (NAME, CNPJ, EMAIL) VALUES ("{}", "{}", "{}")' .format(name, cnpj, email)): flash('Fornecedor cadastrado com sucesso.') flash('success') log( 'create', 'PROVIDER: ("{}", "{}", "{}") -- {} ({})'.format( name, cnpj, email, session['user'][0], datetime.now())) else: flash('Não foi possível cadastrar o fornecedor.') flash('danger') return redirect(url_for('providers')) else: return redirect(url_for('login'))
def create_user(): if user_validate(): if request.method == 'POST': name = request.form['name'].strip().upper() alias = request.form['alias'].strip() password = request.form['password'] if persistence.create( 'INSERT INTO USERS (NAME, ALIAS, PASSWORD) VALUES ("{}", "{}", "{}")' .format(name, alias, password)): flash('Usuário cadastrado com sucesso.') flash('success') log( 'create', 'USER: ("{}", "{}", "{}") -- {} ({})'.format( name, alias, password, session['user'][0], datetime.now())) else: flash('Não foi possível cadastrar o usuário.') flash('danger') return redirect(url_for('users')) else: return redirect(url_for('login'))