コード例 #1
0
def Material_page_handler(id):
    mat_name = Material.get_mat_name(id)
    vend_edrpous = Material.find_vend_edrpou(id)

    global current_material
    current_material = Material(id)

    prices = []
    suppliers = []
    if vend_edrpous == []:
        suppliers = [('Інформація, на жаль, відсутня', '')]
    else:
        for ed in vend_edrpous:
            price = current_material.get_vendors_price(ed)
            prices.append(price)
            suppliers.append((Vendors.get_vend_name(ed), price))

    if prices != []:
        avg_price = sum(prices) / len(prices)
    else:
        avg_price = 'Недостатньо інформації'
    description = current_material.get_mat_description()

    if description in [None, '']:
        description = 'Не вказано'

    return render_template("material_page.html",
                           user_logged=user_logged,
                           mat_name=mat_name,
                           username=user_name,
                           suppliers=suppliers,
                           description=description,
                           avg_price=avg_price)
コード例 #2
0
def Dynamic():
    global current_page
    current_page = "Dynamic"
    supplier_name_pattern = request.args.get('supp')
    material_name_pattern = request.args.get('products')
    year = request.args.get('year')

    ed_list = Vendors.get_edrpou(supplier_name_pattern)
    id_list = Material.find_material_id(material_name_pattern)

    if supplier_name_pattern == None or ed_list == []:
        supplier = 39080209
    else:
        supplier = ed_list[0]

    if material_name_pattern == None or id_list == []:
        mat_id = 27
    else:
        mat_id = id_list[0]

    bar = create_plot(supplier, mat_id, year)

    return render_template("Dynamic.html",
                           user_logged=user_logged,
                           user_name=user_name,
                           plot=bar)
コード例 #3
0
def create_plot(supplier, mat_id, year):
    if supplier == None:
        supplier = 39080209
    if mat_id == None:
        mat_id = 27
    if year == None:
        year = 2019

    x = [
        "січень", "лютий", "березень", "квітень", "травень", "червень",
        "липень", "серпень", "вересень", "жовтень", "листопад", "грудень"
    ]

    #y = get_filtred_year_date(2019,39080209,27)
    y, message = get_filtred_year_date(int(year), int(supplier), int(mat_id))

    df = pd.DataFrame({'x': x, 'y': y})  # creating a sample dataframe

    mat_name = Material.get_mat_name(mat_id)
    vend_name = Vendors.get_vend_name(supplier)

    fig = go.Figure(
        data=[
            go.Bar(
                x=df['x'],  # assign x as the dataframe column 'x'
                y=df['y'],
                marker_color='crimson')
        ],
        layout_title_text=
        f'Зміна ціни за {year} рік на "{mat_name}" у "{vend_name}"',
    )

    graphJSON = json.dumps(fig, cls=plotly.utils.PlotlyJSONEncoder)

    return graphJSON
コード例 #4
0
def Create_sup_record():
    if user_name == 'admin':

        message1 = Vendors.add_vendor(request.form['sup_name'],
                                      request.form['ed'], request.form['adr'],
                                      request.form['city'],
                                      request.form['tel'],
                                      request.form['m_name'],
                                      request.form['email'])

        message2 = Bank.add_bank(request.form['bank_name'], request.form['rr'],
                                 request.form['mfo'], request.form['ed'])

        flash(message1)
        flash(message2)
        return redirect(url_for('Suppliers'))
    else:
        flash("Тільки менеджер може додавати постачальників")
        return redirect(url_for('Suppliers'))
コード例 #5
0
def Supplier_page_handler(ed):
    vend_name = Vendors.get_vend_name(ed)

    prod_list_ids = Vendors.get_products(ed)

    global current_supplier
    current_supplier = Vendors(ed)

    products = []

    if prod_list_ids == []:
        products = [(('Інформація, на жаль, відсутня', -1), '-')]
    else:
        for id in prod_list_ids:
            products.append(((Material.get_mat_name(id), id),
                             Material.get_mat_price(id, ed)))

    vend_city = Vendors.get_vend_city(ed)
    vend_address = Vendors.get_vend_adress(ed)
    vend_email = Vendors.get_vend_email(ed)
    vend_tel = Vendors.get_vend_tel(ed)
    vend_m_name = Vendors.get_vend_m_name(ed)
    vend_ed = ed
    roz_rah = Bank.get_bank_roz_rah(ed)
    bank_name = Vendor_Material.get_bank_name(ed)
    mfo = Vendor_Material.get_bank_mfo(int(ed))
    details = [
        vend_city, vend_address, vend_email, vend_tel, vend_m_name, vend_ed,
        roz_rah, bank_name, mfo
    ]

    return render_template("supplier_page.html",
                           user_logged=user_logged,
                           user_name=user_name,
                           materials=products,
                           details=details,
                           sup_name=vend_name)
コード例 #6
0
def Supplier_updater():
    if user_name == 'admin':
        ed = current_supplier.v_edrpou

        vend_name = Vendors.get_vend_name(ed)
        vend_city = Vendors.get_vend_city(ed)
        vend_address = Vendors.get_vend_adress(ed)
        vend_email = Vendors.get_vend_email(ed)
        vend_tel = Vendors.get_vend_tel(ed)
        vend_m_name = Vendors.get_vend_m_name(ed)
        roz_rah = Bank.get_bank_roz_rah(ed)

        return render_template("update_supplier.html",
                               user_logged=user_logged,
                               user_name=user_name,
                               sup_name=vend_name,
                               city=vend_city,
                               adr=vend_address,
                               email=vend_email,
                               m_name=vend_m_name,
                               roz_rah=roz_rah)
    else:
        flash('Тільки менеджер може оновлювати записи')
        return redirect(url_for('Suppliers'))
コード例 #7
0
def Materials():

    name_pattern = request.args.get('search')
    id_list = Material.find_material_id(name_pattern)

    if id_list == [] and name_pattern != None:
        flash('Записів, на жаль, не знайдено')
    global material_list
    material_list = []
    if request.args.get('search') != None:
        for id in id_list:

            mat_name = Material.get_mat_name(id)

            vend_edrpous = Material.find_vend_edrpou(id)

            prices = []
            if vend_edrpous == []:
                vend_names = ['На жаль, поки інформації у базі даних немає']
                #continue
            else:
                vend_names = []

                for ed in vend_edrpous:
                    price = Material.get_vendors_price_globally(id, ed)
                    prices.append(price)
                    vend_names.append(Vendors.get_vend_name(ed))

            if prices != []:
                avg_price = sum(prices) / len(prices)
            else:
                avg_price = 'Недостатньо інформації'

            material_list.append((mat_name, vend_names, id, avg_price))
    else:
        id_list = Material.find_material_id('')

        for id in id_list:

            mat_name = Material.get_mat_name(id)

            vend_edrpous = Material.find_vend_edrpou(id)

            prices = []
            if vend_edrpous == []:
                vend_names = ['Інформація, на жаль, відсутня']
                #continue
            else:
                vend_names = []
                for ed in vend_edrpous:
                    price = Material.get_vendors_price_globally(id, ed)
                    prices.append(price)
                    vend_names.append(Vendors.get_vend_name(ed))

            if prices != []:
                avg_price = sum(prices) / len(prices)
            else:
                avg_price = 'Недостатньо інформації'

            material_list.append((mat_name, vend_names, id, avg_price))

    global current_page
    current_page = "Materials"

    if request.args.get('sort') != None:
        sort_method = request.args.get('sort')
    else:
        sort_method = "Name"

    if sort_method == 'Name':
        material_list = sorted(material_list, key=lambda t: t[0])

    if sort_method == 'Sup':
        material_list = sorted(material_list, key=lambda t: t[1][0])

    if name_pattern == None:
        name_pattern = ''
    return render_template("Materials.html",
                           user_logged=user_logged,
                           user_name=user_name,
                           material_list=material_list,
                           name_pattern=name_pattern)
コード例 #8
0
def Suppliers():
    global current_page
    current_page = "Suppliers"

    name_pattern = request.args.get('search')
    ed_list = Vendors.get_edrpou(name_pattern)
    print(ed_list)
    if ed_list == [] and name_pattern != None:
        flash('На жаль, записів не знайдено')

    global supplier_list
    supplier_list = []
    if request.args.get('search') != None:
        for ed in ed_list:
            vend_name = Vendors.get_vend_name(ed)

            prod_list_ids = Vendors.get_products(ed)

            products = []
            for id in prod_list_ids:
                products.append(Material.get_mat_name(id))

            if products == []:
                products = ['На жаль, поки що інформації немає']

            roz_rah = Bank.get_bank_roz_rah(ed)

            supplier_list.append((vend_name, products, ed, roz_rah))
    else:
        ed_list = Vendors.get_edrpou('')

        for ed in ed_list:

            vend_name = Vendors.get_vend_name(ed)

            prod_list_ids = Vendors.get_products(ed)

            products = []
            for id in prod_list_ids:
                products.append(Material.get_mat_name(id))

            if products == []:
                products = ['На жаль, поки що інформації немає']

            roz_rah = Bank.get_bank_roz_rah(ed)

            supplier_list.append((vend_name, products, ed, roz_rah))

    if request.args.get('sort') != None:
        sort_method = request.args.get('sort')
    else:
        sort_method = "Name"

    if sort_method == 'Name':
        supplier_list = sorted(supplier_list, key=lambda t: t[0])

    if sort_method == 'Ed':
        supplier_list = sorted(supplier_list, key=lambda t: t[2])

    if name_pattern == None:
        name_pattern = ''

    print(supplier_list)
    return render_template("Suppliers.html",
                           user_logged=user_logged,
                           user_name=user_name,
                           suppliers_list=supplier_list,
                           name_pattern=name_pattern)