def new_purchase_test(db): do.new_purchase(db, '2017_8_8', 'cus_1', 'stu_1', 100, 3) print(do.get_purchases_at_date(db, '2017_8_8')) do.new_purchase(db, '2017_8_8', 'cus_2', 'stu_2', 99, 2) print(do.get_purchases_at_date(db, '2017_8_8')) do.new_purchase(db, '2017_8_8', 'cus_1', 'stu_3', 98, 1) print(do.get_purchases_at_date(db, '2017_8_8'))
def new_purchase(): do.new_purchase(db, request.form['date'], request.form['customer'], request.form['stuff'], int(request.form['amount'])) all_purchase_list = do.get_purchases_at_date(db, request.form['date']) if all_purchase_list is None: return render_template('date.html', date=request.form['date']) sum_total_list = [] for customer_info in all_purchase_list: sum_total = 0 for purchase in customer_info[1]: purchase['total'] = int(purchase['amount']) * int( purchase['price']) sum_total += purchase['total'] sum_total_list.append(sum_total) all_purchase_list = zip(all_purchase_list, sum_total_list) if url_for('date') in request.referrer: return redirect(url_for('date', date=request.form['date'])) elif url_for('cost') in request.referrer: return redirect(url_for('cost', date=request.form['date'])) else: return render_template('calendar.html')
def cost(): # serve index template date = request.args.get('date') all_purchase_list = do.get_purchases_at_date(db, date) if all_purchase_list is None or len(all_purchase_list) <= 0: return render_template('cost.html', date=date) sum_cost = 0 sum_price = 0 sum_cost_list = [] for customer_info in all_purchase_list: sum_total = 0 cost_total = 0 for purchase in customer_info[1]: purchase['total'] = int(purchase['amount']) * int( purchase['price']) purchase['cost_total'] = int(purchase['amount']) * int( purchase['cost']) sum_total += purchase['total'] cost_total += purchase['cost_total'] sum_cost += cost_total sum_price += sum_total sum_cost_list.append((sum_total, cost_total)) sum_profit = sum_price - sum_cost all_purchase_list = zip(all_purchase_list, sum_cost_list) return render_template('cost.html', date=date, all_purchase_list=all_purchase_list, sum_cost=sum_cost, sum_price=sum_price, sum_profit=sum_profit)
def date(): # serve index template date = request.args.get('date') all_purchase_list = do.get_purchases_at_date(db, date) if all_purchase_list is None or len(all_purchase_list) <= 0: return render_template('date.html', date=date) sum_total_list = [] for customer_info in all_purchase_list: sum_total = 0 for purchase in customer_info[1]: purchase['total'] = int(purchase['amount']) * int( purchase['price']) sum_total += purchase['total'] sum_total_list.append(sum_total) all_purchase_list = zip(all_purchase_list, sum_total_list) return render_template('date.html', date=date, all_purchase_list=all_purchase_list)
def remove_purchase_test(db): do.remove_purchase(db, '2017_8_8', 'cus_1', 'stu_3', 98, 1) print(do.get_purchases_at_date(db, '2017_8_8')) do.remove_purchase(db, '2017_8_8', 'cus_2', 'stu_2', 99, 2) print(do.get_purchases_at_date(db, '2017_8_8'))