def getQuoteInfo(): quote = dbSession.query(Quote).all() dbSession.commit() return quote
def saveAppearance(): """For saving or updating apperance options""" project_id = request.args.get('proj_id') appearance_id = None if 'appearanceId' in request.json: appearance_id = request.json['appearanceId'] appearance_name = request.json['name'] style = request.json['style'] height = request.json['height'] border_colour = request.json['borderColor'] panel_colour = request.json['panelColor'] base_price = request.json['basePrice'] appearance_id = updateAppearanceInfo(project_id, appearance_id, appearance_name, style, height, border_colour, panel_colour, base_price) if "saveSelection" in request.json: project = dbSession.query(Project).filter( Project.project_id == project_id).one() project.appearance_selected = appearance_id dbSession.commit() return "{" + '"appearanceId": {appearance_id}'.format( appearance_id=appearance_id) + "}"
def testMaterialData(): newMaterial1 = Material(material_name = 'WPR6C* Pocket Rail 1.5"x 71.5" Clay' , my_price = 18.37, pieces_in_bundle = 144, category = "Privacy Fence Rails", note = "Clay", company_name = "Fence", material_id = 1) newMaterial2 = Material(material_name = "875U.16A .875x16' U Channel Almond" , my_price = 13.16, pieces_in_bundle = 36, category = "U-Channel (Plastic)", note = "Almond", company_name = "Fence", material_id = 2) newMaterial3 = Material(material_name = 'APSB4 4 x 1-7/8" Post Collar Adapter" 2pc', my_price = 4.75, pieces_in_bundle = 150, category = "Collars", note = "Adapter", company_name = "Fence", material_id = 3) newMaterial4 = Material(material_name = 'HSSDR36 36 Stainless Steel Drop Rod Black', my_price = 37.98, pieces_in_bundle = 6, category = "Gate Hardware", note = "Stainless Steel", company_name = "Fence", material_id = 4) newMaterial5 = Material(material_name = 'GAAKA Gate Assembly Kit -Almond ', my_price = 7.00, pieces_in_bundle = 1, category = "Gates", note = "issa gate", company_name = "Fence", material_id = 5) newMaterial6 = Material(material_name = 'ABLOCK THE BLOCK" Vinyl post pounding block"', my_price = 52.50, pieces_in_bundle = 1, category = "Accessories", note = "Its a pounding block", company_name = "Fence", material_id = 6) newMaterial7 = Material(material_name = 'Cap235FA 2x3.5" Flat Cap Almond', my_price = 1.13, pieces_in_bundle = 100, category = "Caps", note = "cappa", company_name = "Fence", material_id = 7) newMaterial8 = Material(material_name = 'W55.A* 5x5"x54" Post Almond', my_price = 19.36, pieces_in_bundle = 72, category = "Ranch Rail", note = "ranch sauce", company_name = "Fence", material_id = 8) dbSession.add(newMaterial1) dbSession.add(newMaterial2) dbSession.add(newMaterial3) dbSession.add(newMaterial4) dbSession.add(newMaterial5) dbSession.add(newMaterial6) dbSession.add(newMaterial7) dbSession.add(newMaterial8) dbSession.commit()
def finalizeQuote(): if request.method == 'POST': """ Given a project ID and a boolean finalize. Turn finalize to false if finalize is False. Generate and save the quote and material expenses if finalize is True Customer quote is calculated for each fence by the following formula. quote = length * (style + height + base price + (border colour + panel colour) / 2) """ project_id = request.values.get('proj_id') # A dictionary with keywords and values of material_ids material_types = json.loads(request.values.get('material_types')) # A dictionary with keywords and values of the amount of material needed material_amounts = json.loads(request.values.get('material_amounts')) misc_modifier_label = request.values.get('misc_modifier_label') # A flat rate which allows the user to alter the subtotal of the quote misc_modifier = request.values.get('misc_modifier') if misc_modifier == "": misc_modifier = 0 else: misc_modifier = int(misc_modifier) payment = request.values.get('payment') notes = request.values.get('notes') description = request.values.get('description') project = dbSession.query(Project).filter( Project.project_id == project_id).one() if project is None: print('Project does not exist') return bad_request('Project does not exist') if material_types is None or material_amounts is None: print('Material Parameters not given') return bad_request('Material Parameters not given') if project.finalize: print('Project has already been finalized') return bad_request('Project has already been finalized') project.finalize = True try: newQuote = generateQuote(project, material_types, material_amounts, misc_modifier, payment, notes, misc_modifier_label, description) dbSession.add(newQuote) dbSession.commit() except BaseException as e: raise e print('Error in saving the quote') return bad_request('Error in saving the quote') return created_request('Quote has been generated') print('Request is not a POST request') return bad_request('Request is not a POST request')
def pictureTestData(): newPic = Picture(picture_id = 1, file_name = "garden.jpg", thumbnail_name = "thumbnail_garden.png", project_id = 1) newPic1 = Picture(picture_id = 2, file_name = "corner.jpg", thumbnail_name = "thumbnail_corner.png", project_id = 1) newPic2 = Picture(picture_id = 3, file_name = "backyard.png", thumbnail_name = "thumbnail_backyard.png", project_id = 2) dbSession.add(newPic) dbSession.add(newPic1) dbSession.add(newPic2) dbSession.commit()
def statusTestData(): status1 = Status(status_name = "Not Reached", status_number = 1) status2 = Status(status_name = "Paid", status_number = 2) status3 = Status(status_name = "Appraisal Booked", status_number = 3) dbSession.add(status1) dbSession.add(status2) dbSession.add(status3) dbSession.commit()
def testLayoutData(): newLayout1 = Layout(layout_id = 1, project_id = 1, layout_name = "Layout 1", layout_info = "test") newLayout2 = Layout(layout_id = 2, project_id = 2, layout_name = "Layout 2", layout_info = "test") newLayout3 = Layout(layout_id = 3, project_id = 1, layout_name = "Layout 3", layout_info = "test") dbSession.add(newLayout1) dbSession.add(newLayout2) dbSession.add(newLayout3) dbSession.commit()
def customerTestData(): newCustomer1 = Customer(customer_id = 1, first_name = 'Kat', email = '*****@*****.**', cellphone = '541-689-4681', company_name = 'Fence') newCustomer2 = Customer(customer_id = 2, first_name = 'Davis', email = '*****@*****.**', cellphone = '761-158-2113', company_name = 'Builder') newCustomer3 = Customer(customer_id = 3, first_name = 'Jason', email = '*****@*****.**', cellphone = '688-946-8781', company_name = 'Fence') dbSession.add(newCustomer1) dbSession.add(newCustomer2) dbSession.add(newCustomer3) dbSession.commit()
def saveLayoutName(): """ Update a layout's name """ layout_id = request.json['layoutId'] layout_name = request.json['name'] layout = dbSession.query(Layout).filter( Layout.layout_id == layout_id).one() layout.layout_name = layout_name dbSession.commit() return "{}"
def saveLayoutSelection(): """Saving layout on projectinfo page""" project_id = request.args.get("proj_id") selected = request.json["selected"] project = dbSession.query(Project).filter( Project.project_id == project_id).one() project.layout_selected = selected dbSession.commit() return "{}"
def projectTestData(): newProject1 = Project(customer_id = 1, status_name = 'Not Reached', address = 'Bear St', end_date = None , note = 'A fun fencing project', project_name = "Kat's house fence", company_name = 'Fence', layout_selected = None, appearance_selected = None, project_id = 1 ) newProject2 = Project(customer_id = 1, status_name = 'Not Reached', address = 'Grand Ave', end_date = None, note = 'Dog lives here', project_name = "Kat's second house fence", company_name = 'Fence',layout_selected = None, appearance_selected = None, project_id = 2 ) #newProject3 = Project(customer_id = 3, status_name = 'Complete', address = 'Park St', end_date = None, note = 'Concrete fence', project_name = "Jason's fence for company building", company_name = 'Fence', project_id = 3, layout_selected = 3, appearance_selected = 1) dbSession.add(newProject1) dbSession.add(newProject2) #dbSession.add(newProject3) dbSession.commit()
def acceptUser(): """ accepts user, in app.py because of userDatastore """ if request.method == 'POST': user_id = request.values.get("user_id") user = dbSession.query(User).filter(User.id == user_id).all() userDatastore.activate_user(user[0]) user[0].active = True dbSession.commit() users = dbSession.query(User).filter(User.active == False).all() return jsonify(users)
def addCustomer(name, email, ph, addr, cname): """Add a customer to the database with the given field values""" customer = Customer(email=email, first_name=name, cellphone=ph, company_name=cname) dbSession.add(customer) dbSession.commit() return True
def updatecompany(): company = dbSession.query(Company).filter( Company.company_name == current_user.company_name).one() company.supplier_email = request.json["supplier_email"] company.office = request.json["office"] company.phone = request.json["phone"] company.web = request.json["web"] company.disclaimer = request.json["disclaimer"] dbSession.commit() return "{}"
def userTestData(): newUser = User(id = 1, email = "*****@*****.**", username = "******", password = "******", company_name = "Fence", active = True) newUser1 = User(id = 2, email = "*****@*****.**", username = "******", password = "******", company_name = "Builder", active = True) newUser2 = User(id = 3, email = "*****@*****.**", username = "******", password = "******", company_name = "Fence", active = False) newUser3 = User(id = 4, email = "*****@*****.**", username = "******", password = "******", company_name = "Builder", active = False) dbSession.add(newUser) dbSession.add(newUser1) dbSession.add(newUser2) dbSession.add(newUser3) dbSession.commit()
def updateCustomerInfo(customer_id, email, first_name, cellphone): """ Updates the customer information of a given customer id """ customer = dbSession.query(Customer).filter( Customer.customer_id == customer_id).all() customer[0].email = email customer[0].first_name = first_name customer[0].cellphone = cellphone dbSession.commit() return True
def uploadPrice(): """ Parses the given csv file into fencing materials prices for a given company """ company_name = current_user.company_name if request.method == 'POST': priceFile = request.files['prices'] if not priceFile: return bad_request('Invalid price file uploaded') stream = io.StringIO(priceFile.stream.read().decode("UTF8"), newline=None) csv_input = csv.reader(stream) # Clear materials list? This will cause issues for appearances due to ForeignKeys dbSession.query(Material).filter( Material.company_name == current_user.company_name).delete() category = '' for row in csv_input: if row[2] == 'My Price' and row[4] == 'Pieces in Bundle': # Category category = row[0] if row[0] != '' and row[2] == '' and row[4] == '': # Category category = row[0] if row[1].startswith('$') and row[2].startswith('$'): # Material try: my_price = Decimal(row[2][1:]) except: print( 'My Price value could not be converted into a Decimal, default to 0' ) my_price = 0 try: pieces_in_bundle = Decimal(row[4]) except: print( 'Pieces in bundle value could not be converted into a number, default to 1' ) pieces_in_bundle = 1 material_name = row[0] note = row[5] # Insert data into db newMaterial = Material(material_name=material_name, my_price=my_price, pieces_in_bundle=pieces_in_bundle, category=category, note=note, company_name=current_user.company_name) dbSession.add(newMaterial) # Otherwise, ignore row dbSession.commit() return created_request('Prices were changed') return bad_request('Request is not a POST request')
def user_registered_sighandler(app, user, confirm_token): """Deactivates new users""" changeUser = dbSession.query(User).filter(User.id == user.id).one() newCompany = Company(company_name=user.username, email=user.email) dbSession.add(newCompany) dbSession.commit() changeUser.company_name = user.username userDatastore.deactivate_user(user) userDatastore.add_role_to_user(user, 'primary') dbSession.commit()
def createLayout(project_id): """Creates the default draw io layout with green edit diagram button image""" newLayout = Layout( project_id=project_id, layout_name="Layout 1", layout_info= "data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHhtbG5zOnhsaW5rPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5L3hsaW5rIiB3aWR0aD0iNzAxcHgiIGhlaWdodD0iMzIxcHgiIHZlcnNpb249IjEuMSIgY29udGVudD0iJmx0O214ZmlsZSB1c2VyQWdlbnQ9JnF1b3Q7TW96aWxsYS81LjAgKE1hY2ludG9zaDsgSW50ZWwgTWFjIE9TIFggMTBfMTNfMSkgQXBwbGVXZWJLaXQvNTM3LjM2IChLSFRNTCwgbGlrZSBHZWNrbykgQ2hy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ayout) dbSession.commit() return newLayout
def removeProject(proj_id): """Delete image files""" pictures = dbSession.query(Picture).filter( Picture.project_id == proj_id).all() for image in pictures: Pictures.deleteImageHelper(image.file_name) Pictures.deleteImageHelper(image.thumbnail_name) """Cascade delete all information related to project""" project = dbSession.query(Project).filter( Project.project_id == proj_id).one() dbSession.delete(project) dbSession.commit()
def createAppearance(project_id): """Helper function for saveApperance""" newAppearance = Appearance(project_id=project_id, appearance_name="Appearance 1", style=None, height=None, border_colour=None, panel_colour=None, base_price=0) dbSession.add(newAppearance) dbSession.commit() return newAppearance
def removeCustomer(cust_id): """Helper function for deleteproject()""" #Get all projects projects = dbSession.query(Project).filter(Project.customer_id == cust_id) for proj in projects: removeProject(proj.project_id) # Cascade delete all information related to project cust = dbSession.query(Customer).filter( Customer.customer_id == cust_id).one() dbSession.delete(cust) dbSession.commit()
def updateProjectInfo(project_id, project_name, address, status, note, customer, end_date): """ Updates the project information of a given project id """ project = dbSession.query(Project).filter( Project.project_id == project_id).all() project[0].project_name = project_name project[0].address = address project[0].status_name = status project[0].note = note project[0].end_date = end_date dbSession.commit() return True
def updateLayoutInfo(project_id, layout_name, layout_info, layout_id=None): """Update layout information using layout_id """ if layout_id is None: layout = createLayout(project_id) else: layout = dbSession.query(Layout) layout = layout.filter(Layout.layout_id == layout_id).one() layout.layout_name = layout_name layout.layout_info = layout_info layout_id = layout.layout_id dbSession.commit() return layout_id
def quoteTestData(): newQuote = Quote(quote_id=2, project_id=1, amount=99439.12, amount_gst=100.00, amount_total=99539.12, material_expense=123, material_expense_gst=52, material_expense_total=172, gst_rate=0.5) newQuote1 = Quote(quote_id=1, project_id=1, amount=105.12, amount_gst=10.00, amount_total=115.12, material_expense=52.52, material_expense_gst=5.08, material_expense_total=57.60, gst_rate=0.5) newQuote2 = Quote(quote_id=3, project_id=2, amount=73.00, amount_gst=7.00, amount_total=80, material_expense=52.52, material_expense_gst=5.08, material_expense_total=57.60, gst_rate=0.5) newQuote3 = Quote(quote_id=4, project_id=1, amount=105.12, amount_gst=10.00, amount_total=116.12, material_expense=52.52, material_expense_gst=5.08, material_expense_total=57.60, gst_rate=0.5) dbSession.add(newQuote) dbSession.add(newQuote1) dbSession.add(newQuote2) dbSession.commit()
def testAppearanceData(): appearance = Appearance(appearance_name = 'Appearance', project_id = 1, panel_gap = 0.5, height = 0.5, appearance_id = 1 ) appearance1 = Appearance(appearance_name='Appearance1', project_id=1, panel_gap=0.6, height=6, appearance_id=2) appearance2 = Appearance(appearance_name='Appearance2', project_id=1, panel_gap=0.7, height=9, appearance_id=3) appearance3 = Appearance(appearance_name = 'Appearance3', project_id = 2, panel_gap = 0.8, height = 12, appearance_id = 4 ) appearance4 = Appearance(appearance_name = 'Appearance4', project_id = 2, panel_gap = 0.9, height = 13, appearance_id = 5 ) dbSession.add(appearance) dbSession.add(appearance1) dbSession.add(appearance2) dbSession.add(appearance3) dbSession.add(appearance4) dbSession.commit()
def unfinalizeQuote(): if request.method == 'POST': project_id = request.values.get('proj_id') project = dbSession.query(Project).filter( Project.project_id == project_id).one() quoteToDelete = dbSession.query(Quote).filter( Quote.project_id == project_id) quoteFiles = quoteToDelete.one() deletePDFHelper(quoteFiles.quote_pdf) deletePDFHelper(quoteFiles.supply_pdf) quoteToDelete.delete() project.finalize = False dbSession.commit() return "{}" return bad_request('Request is not a POST request')
def createProject(customerId, statusName, address, companyName, project_name): """Access mysql and add in project""" newProject = Project(customer_id=customerId, address=address, status_name=statusName, end_date=None, note='', project_name=project_name, company_name=companyName, finalize=False, layout_selected=None, appearance_selected=None) dbSession.add(newProject) dbSession.commit() newAppearance = Appearances.createAppearance(newProject.project_id) newProject.appearance_selected = newAppearance.appearance_id newLayout = Layouts.createLayout(newProject.project_id) newProject.layout_selected = newLayout.layout_id dbSession.commit() return newProject.project_id
def updateAppearanceInfo(project_id, appearance_id, appearance_name, style, height, border_colour, panel_colour, base_price): """Helper function for saveApperance""" if appearance_id is None: appearance = createAppearance(project_id) else: appearance = dbSession.query(Appearance) appearance = appearance.filter( Appearance.appearance_id == appearance_id).one() appearance.appearance_name = appearance_name appearance.style = style appearance.height = height appearance.border_colour = border_colour appearance.panel_colour = panel_colour appearance.base_price = base_price dbSession.commit() appearance_id = appearance.appearance_id return appearance_id
def testEstimateData(): # STYLE, COLOUR, HEIGHT, GATE newStyle = Style(style = "Full Privacy", value = 40, company_name = None, style_id = 1 ) newColor = Colour(colour = "White", value = 0, company_name = None, colour_id = 1) newHeight = Height(height = "6", value = 0, company_name = None, height_id = 1) newGate = Gate(gate = "Man gate 4'", value = 550, company_name = None, gate_id = 1) newStyle1 = Style(style = "Picket Top", value = 44, company_name = None, style_id = 2 ) newColor1 = Colour(colour = "Almond (Tan)", value = 4, company_name = None, colour_id = 2) newHeight1 = Height(height = "5", value = -3, company_name = None, height_id = 2) newGate1 = Gate(gate = "RV gate 12'", value = 1300, company_name = None, gate_id = 2) newStyle2 = Style(style = "Lattice Top", value = 44, company_name = None, style_id = 3 ) newColor2 = Colour(colour = "Clay", value = 8, company_name = None, colour_id = 3) newHeight2 = Height(height = "4", value = -3, company_name = None, height_id = 3) newStyle3 = Style(style = "Picket Fence", value = 40, company_name = None, style_id = 4 ) newColor3 = Colour(colour = "Pebblestone", value = 4, company_name = None, colour_id = 4) newHeight3 = Height(height = "3", value = -6, company_name = None, height_id = 4) dbSession.add(newStyle) dbSession.add(newColor) dbSession.add(newHeight) dbSession.add(newGate) dbSession.add(newStyle1) dbSession.add(newColor1) dbSession.add(newHeight1) dbSession.add(newGate1) dbSession.add(newStyle2) dbSession.add(newColor2) dbSession.add(newHeight2) dbSession.add(newStyle3) dbSession.add(newColor3) dbSession.add(newHeight3) dbSession.commit()