updated forms
This commit is contained in:
@@ -213,6 +213,9 @@ app.register_blueprint(ticket_blueprint, url_prefix='/ticket')
|
||||
from .promo import promo as promo_blueprint
|
||||
app.register_blueprint(promo_blueprint, url_prefix='/promo')
|
||||
|
||||
from .social import social as social_blueprint
|
||||
app.register_blueprint(social_blueprint, url_prefix='/social')
|
||||
|
||||
with app.app_context():
|
||||
|
||||
db.configure_mappers()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#
|
||||
from app import db, ma, login_manager
|
||||
from datetime import datetime
|
||||
from app import db, ma
|
||||
|
||||
|
||||
|
||||
class Customer_Customer(db.Model):
|
||||
|
||||
25
app/classes/customer_social.py
Normal file
25
app/classes/customer_social.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#
|
||||
from app import db, ma
|
||||
|
||||
|
||||
class Customer_Customer_Social(db.Model):
|
||||
__tablename__ = 'customer_customer_social'
|
||||
__table_args__ = {"schema": "public"}
|
||||
|
||||
|
||||
id = db.Column(db.Integer,
|
||||
primary_key=True,
|
||||
autoincrement=True,
|
||||
unique=False)
|
||||
created = db.Column(db.DATE())
|
||||
customer_id = db.Column(db.INTEGER)
|
||||
poster_employee_id = db.Column(db.INTEGER)
|
||||
comment = db.Column(db.VARCHAR(1000))
|
||||
|
||||
|
||||
|
||||
|
||||
class Customer_Customer_Social_schema(ma.SQLAlchemyAutoSchema):
|
||||
class Meta:
|
||||
model = Customer_Customer_Social
|
||||
|
||||
@@ -138,8 +138,14 @@ def create_customer():
|
||||
"""
|
||||
"""
|
||||
now = datetime.utcnow()
|
||||
get_company = db.session.query(Admin_Company).filter(Admin_Company.id == 1).first()
|
||||
last_customer = (db.session.query(Customer_Customer).order_by(Customer_Customer.id.desc()).first())
|
||||
get_company = (db.session
|
||||
.query(Admin_Company)
|
||||
.filter(Admin_Company.id == 1)
|
||||
.first())
|
||||
last_customer = (db.session
|
||||
.query(Customer_Customer)
|
||||
.order_by(Customer_Customer.id.desc())
|
||||
.first())
|
||||
new_customer_id = last_customer.id + 1
|
||||
if len(str(new_customer_id)) == 2:
|
||||
new_customer_id = '000' + str(new_customer_id)
|
||||
@@ -161,17 +167,13 @@ def create_customer():
|
||||
response_customer_state = request.json["customer_state"]
|
||||
response_customer_zip = request.json["customer_zip"]
|
||||
response_customer_email = request.json["customer_email"]
|
||||
response_customer_automatic = request.json["customer_automatic"]
|
||||
response_customer_home_type = request.json["customer_home_type"]
|
||||
customer_phone_number = request.json["customer_phone_number"]
|
||||
customer_address = request.json["customer_address"]
|
||||
customer_apt = request.json["customer_apt"]
|
||||
customer_description_msg = request.json["customer_description"]
|
||||
|
||||
if response_customer_automatic is True:
|
||||
auto_customer = 1
|
||||
else:
|
||||
auto_customer = 0
|
||||
|
||||
|
||||
int_customer_home_type = int(response_customer_home_type)
|
||||
response_customer_zip = str(response_customer_zip)
|
||||
@@ -186,7 +188,7 @@ def create_customer():
|
||||
customer_zip=response_customer_zip,
|
||||
customer_first_call=now,
|
||||
customer_email=response_customer_email,
|
||||
customer_automatic=auto_customer,
|
||||
customer_automatic=0,
|
||||
customer_home_type=int_customer_home_type,
|
||||
customer_phone_number=customer_phone_number,
|
||||
customer_address=customer_address,
|
||||
@@ -336,44 +338,12 @@ def edit_customer(customer_id):
|
||||
response_customer_email = request.json["customer_email"]
|
||||
response_customer_home_type = request.json["customer_home_type"]
|
||||
response_customer_address = request.json["customer_address"]
|
||||
response_customer_automatic = request.json["customer_automatic"]
|
||||
|
||||
response_customer_description = request.json["customer_description"]
|
||||
|
||||
response_customer_fill_location = request.json["customer_fill_location"]
|
||||
|
||||
|
||||
|
||||
|
||||
if response_customer_automatic is True:
|
||||
get_auto = (db.session
|
||||
.query(Auto_Delivery)
|
||||
.filter(Auto_Delivery.customer_id == customer_id)
|
||||
.first())
|
||||
|
||||
auto = 1
|
||||
# customer becames an automatic
|
||||
if get_auto is None:
|
||||
create_auto = Auto_Delivery(customer_id = customer_id,
|
||||
customer_full_name =get_customer.customer_first_name + ' ' + get_customer.customer_last_name,
|
||||
account_number=get_customer.account_number,
|
||||
customer_town=get_customer.customer_town,
|
||||
customer_state=get_customer.customer_state,
|
||||
customer_zip=get_customer.customer_zip,
|
||||
customer_address=get_customer.customer_address,
|
||||
last_fill = datetime.utcnow(),
|
||||
last_updated = None,
|
||||
estimated_gallons_left = 0,
|
||||
estimated_gallons_left_prev_day = 0,
|
||||
tank_height = 0,
|
||||
tank_size =275,
|
||||
house_factor = 1,
|
||||
auto_status=0
|
||||
)
|
||||
db.session.add(create_auto)
|
||||
|
||||
else:
|
||||
auto = 0
|
||||
if get_customer_description is not None:
|
||||
get_customer_description.description = response_customer_description
|
||||
get_customer_description.fill_location = response_customer_fill_location
|
||||
@@ -389,7 +359,6 @@ def edit_customer(customer_id):
|
||||
get_customer.customer_state = response_customer_state
|
||||
get_customer.customer_zip = response_customer_zip
|
||||
get_customer.customer_email = response_customer_email
|
||||
get_customer.customer_automatic = auto
|
||||
|
||||
db.session.add(get_customer)
|
||||
db.session.commit()
|
||||
|
||||
@@ -127,9 +127,7 @@ def get_deliveries_not_delivered_all(page):
|
||||
|
||||
deliveries = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(Delivery_Delivery.delivery_status != 10)
|
||||
.filter(Delivery_Delivery.delivery_status != 3)
|
||||
.order_by(Delivery_Delivery.id.asc())
|
||||
.order_by(Delivery_Delivery.id.desc())
|
||||
.limit(per_page_amount).offset(offset_limit))
|
||||
|
||||
|
||||
@@ -895,8 +893,13 @@ def calculate_total(delivery_id):
|
||||
.query(Promo_Promo)
|
||||
.filter(Promo_Promo.id == get_delivery.promo_id)
|
||||
.first())
|
||||
discount = (get_delivery.total_price * get_promo_data.money_off_delivery)
|
||||
total_amount_after_discount = (get_delivery.total_price - discount)
|
||||
discount_gallon_price = get_delivery.customer_price - get_promo_data.money_off_delivery
|
||||
|
||||
total_amount_after_discount = (get_delivery.gallons_ordered * discount_gallon_price)
|
||||
|
||||
|
||||
discount = (get_delivery.gallons_ordered * get_delivery.customer_price) - total_amount_after_discount
|
||||
|
||||
else:
|
||||
discount = 0
|
||||
total_amount_after_discount = 0
|
||||
@@ -906,22 +909,30 @@ def calculate_total(delivery_id):
|
||||
.first())
|
||||
|
||||
if get_delivery.prime == 1:
|
||||
priceprime = get_price_query.price_prime
|
||||
priceprime = float(get_price_query.price_prime)
|
||||
else:
|
||||
priceprime = 0
|
||||
|
||||
if get_delivery.emergency == 1:
|
||||
priceemergency = get_price_query.price_emergency
|
||||
priceemergency = float(get_price_query.price_emergency)
|
||||
else:
|
||||
priceemergency = 0
|
||||
|
||||
if get_delivery.same_day == 1:
|
||||
pricesameday = get_price_query.price_same_day
|
||||
pricesameday = float(get_price_query.price_same_day)
|
||||
else:
|
||||
pricesameday = 0
|
||||
|
||||
total = float(get_delivery.total_price) + float(priceprime) + float(pricesameday) + float(priceemergency)
|
||||
|
||||
priceprime = round(priceprime, 2)
|
||||
pricesameday = round(pricesameday, 2)
|
||||
priceemergency = round(priceemergency, 2)
|
||||
priceprime = round(priceprime, 2)
|
||||
total_amount_after_discount = round(total_amount_after_discount, 2)
|
||||
discount = round(discount, 2)
|
||||
total = round(total, 2)
|
||||
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'priceprime': priceprime,
|
||||
|
||||
@@ -44,7 +44,7 @@ def office_finalize_delivery(delivery_id):
|
||||
description = None,
|
||||
)
|
||||
db.session.add(new_customer_desc)
|
||||
db.session.commit()
|
||||
db.session.flush()
|
||||
get_customer_description = db.session \
|
||||
.query(Customer_Description) \
|
||||
.filter(Customer_Description.customer_id == get_delivery.customer_id) \
|
||||
@@ -121,66 +121,14 @@ def office_finalize_delivery(delivery_id):
|
||||
cash_amount = None
|
||||
|
||||
|
||||
prime_info = request.json["prime"]
|
||||
if prime_info is True:
|
||||
prime_info = 1
|
||||
current_primes = get_stats_employee.total_primes
|
||||
newprimes = current_primes + 1
|
||||
get_stats_employee.total_primes = newprimes
|
||||
else:
|
||||
prime_info = 0
|
||||
|
||||
|
||||
|
||||
gallons_delivered = request.json["gallons_delivered"]
|
||||
cash = request.json["cash"]
|
||||
card_payment = request.json["card"]
|
||||
check_payment = request.json["check"]
|
||||
other_payment = request.json["other"]
|
||||
check_number = request.json["other"]
|
||||
|
||||
check_number = request.json["check_number"]
|
||||
|
||||
|
||||
if request.json["credit_card_id"]:
|
||||
card_payment_id = request.json["credit_card_id"]
|
||||
else:
|
||||
card_payment_id = None
|
||||
|
||||
if card_payment_id is not None:
|
||||
get_card = (db.session
|
||||
.query(Card_Card)
|
||||
.filter(Card_Card.id == card_payment_id)
|
||||
.filter(Card_Card.user_id == get_customer.id)
|
||||
.first())
|
||||
card_id_from_customer = get_card.id
|
||||
else:
|
||||
card_id_from_customer = None
|
||||
|
||||
|
||||
if cash is True and card_payment is False:
|
||||
delivery_payment_method = 0
|
||||
elif card_payment is True and cash is False:
|
||||
delivery_payment_method = 1
|
||||
elif card_payment is True and cash is True:
|
||||
delivery_payment_method = 2
|
||||
elif check_payment is True :
|
||||
delivery_payment_method = 3
|
||||
elif other_payment is True :
|
||||
delivery_payment_method = 4
|
||||
else:
|
||||
delivery_payment_method = 4
|
||||
|
||||
|
||||
same_day_info = request.json["same_day"]
|
||||
if same_day_info is True:
|
||||
same_day_info = 1
|
||||
else:
|
||||
same_day_info = 0
|
||||
|
||||
|
||||
emergency_info = request.json["emergency"]
|
||||
if emergency_info is True:
|
||||
emergency_info = 1
|
||||
else:
|
||||
emergency_info = 0
|
||||
|
||||
fill_location = request.json["fill_location"]
|
||||
|
||||
@@ -194,11 +142,6 @@ def office_finalize_delivery(delivery_id):
|
||||
# update delivery
|
||||
get_delivery.when_delivered = now
|
||||
get_delivery.gallons_delivered = gallons_delivered
|
||||
get_delivery.prime = prime_info
|
||||
get_delivery.emergency = emergency_info
|
||||
get_delivery.same_day = same_day_info
|
||||
get_delivery.payment_type = delivery_payment_method
|
||||
get_delivery.payment_card_id = card_id_from_customer
|
||||
get_delivery.cash_recieved = cash_amount
|
||||
get_delivery.check_number = check_number
|
||||
get_delivery.delivery_status = 10
|
||||
@@ -240,134 +183,134 @@ def office_finalize_delivery(delivery_id):
|
||||
|
||||
|
||||
|
||||
@delivery_data.route("/driver/finalize/<int:delivery_id>", methods=["PUT"])
|
||||
def driver_finalize_delivery(delivery_id):
|
||||
"""
|
||||
This will make a delivery finalized from the driver
|
||||
"""
|
||||
# @delivery_data.route("/driver/finalize/<int:delivery_id>", methods=["PUT"])
|
||||
# def driver_finalize_delivery(delivery_id):
|
||||
# """
|
||||
# This will make a delivery finalized from the driver
|
||||
# """
|
||||
|
||||
"""
|
||||
Finalizes a delivery from office
|
||||
"""
|
||||
# """
|
||||
# Finalizes a delivery from office
|
||||
# """
|
||||
|
||||
|
||||
get_delivery = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(Delivery_Delivery.id == delivery_id)
|
||||
.first())
|
||||
# get_delivery = (db.session
|
||||
# .query(Delivery_Delivery)
|
||||
# .filter(Delivery_Delivery.id == delivery_id)
|
||||
# .first())
|
||||
|
||||
get_stats = (db.session
|
||||
.query(Stats_Employee_Oil)
|
||||
.filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
.first())
|
||||
# get_stats = (db.session
|
||||
# .query(Stats_Employee_Oil)
|
||||
# .filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
# .first())
|
||||
|
||||
if get_stats is None:
|
||||
create_stats = Stats_Employee_Oil(
|
||||
employee_id = get_delivery.driver_employee_id,
|
||||
total_deliveries = 0,
|
||||
total_gallons_delivered = 0,
|
||||
total_primes = 0,
|
||||
oil_total_profit_delivered = 0,
|
||||
)
|
||||
db.session.add(create_stats)
|
||||
db.session.flush()
|
||||
# if get_stats is None:
|
||||
# create_stats = Stats_Employee_Oil(
|
||||
# employee_id = get_delivery.driver_employee_id,
|
||||
# total_deliveries = 0,
|
||||
# total_gallons_delivered = 0,
|
||||
# total_primes = 0,
|
||||
# oil_total_profit_delivered = 0,
|
||||
# )
|
||||
# db.session.add(create_stats)
|
||||
# db.session.flush()
|
||||
|
||||
|
||||
get_stats = (db.session
|
||||
.query(Stats_Employee_Oil)
|
||||
.filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
.first())
|
||||
gallons_delivered = request.json["gallons_delivered"]
|
||||
# get_stats = (db.session
|
||||
# .query(Stats_Employee_Oil)
|
||||
# .filter(Stats_Employee_Oil.employee_id == get_delivery.driver_employee_id)
|
||||
# .first())
|
||||
# gallons_delivered = request.json["gallons_delivered"]
|
||||
|
||||
gallons_delivered = Decimal(gallons_delivered)
|
||||
# gallons_delivered = Decimal(gallons_delivered)
|
||||
|
||||
delivery_driver_id = request.json["driver_employee_id"]
|
||||
# delivery_driver_id = request.json["driver_employee_id"]
|
||||
|
||||
get_driver = (db.session
|
||||
.query(Employee_Employee)
|
||||
.filter(Employee_Employee.id == delivery_driver_id)
|
||||
.first())
|
||||
# get_driver = (db.session
|
||||
# .query(Employee_Employee)
|
||||
# .filter(Employee_Employee.id == delivery_driver_id)
|
||||
# .first())
|
||||
|
||||
if get_delivery.automatic == 0:
|
||||
customer_filled = request.json["customer_filled"]
|
||||
if customer_filled is True:
|
||||
customer_filled = 1
|
||||
else:
|
||||
customer_filled = 0
|
||||
else:
|
||||
customer_filled = 1
|
||||
# if get_delivery.automatic == 0:
|
||||
# customer_filled = request.json["customer_filled"]
|
||||
# if customer_filled is True:
|
||||
# customer_filled = 1
|
||||
# else:
|
||||
# customer_filled = 0
|
||||
# else:
|
||||
# customer_filled = 1
|
||||
|
||||
|
||||
if request.json["cash_amount"]:
|
||||
cash_amount = request.json["cash_amount"]
|
||||
else:
|
||||
cash_amount = None
|
||||
# if request.json["cash_amount"]:
|
||||
# cash_amount = request.json["cash_amount"]
|
||||
# else:
|
||||
# cash_amount = None
|
||||
|
||||
|
||||
|
||||
prime_info = request.json["prime"]
|
||||
if prime_info is True:
|
||||
prime_info = 1
|
||||
current_primes = get_stats.total_primes
|
||||
newprimes = current_primes + 1
|
||||
get_stats.total_primes = newprimes
|
||||
else:
|
||||
prime_info = 0
|
||||
# prime_info = request.json["prime"]
|
||||
# if prime_info is True:
|
||||
# prime_info = 1
|
||||
# current_primes = get_stats.total_primes
|
||||
# newprimes = current_primes + 1
|
||||
# get_stats.total_primes = newprimes
|
||||
# else:
|
||||
# prime_info = 0
|
||||
|
||||
|
||||
|
||||
## AUTOMATIC
|
||||
if get_delivery.automatic == 1:
|
||||
get_auto_delivery = (db.session
|
||||
.query(Auto_Delivery)
|
||||
.filter(Auto_Delivery.customer_id == get_delivery.customer_id)
|
||||
.first())
|
||||
# ## AUTOMATIC
|
||||
# if get_delivery.automatic == 1:
|
||||
# get_auto_delivery = (db.session
|
||||
# .query(Auto_Delivery)
|
||||
# .filter(Auto_Delivery.customer_id == get_delivery.customer_id)
|
||||
# .first())
|
||||
|
||||
get_auto_delivery.auto_status = 2
|
||||
db.session.add(get_auto_delivery)
|
||||
# get_auto_delivery.auto_status = 2
|
||||
# db.session.add(get_auto_delivery)
|
||||
|
||||
get_delivery.gallons_delivered = gallons_delivered
|
||||
# get_delivery.gallons_delivered = gallons_delivered
|
||||
|
||||
get_delivery.prime = prime_info
|
||||
get_delivery.customer_filled = customer_filled
|
||||
get_delivery.cash_recieved = cash_amount
|
||||
# get_delivery.prime = prime_info
|
||||
# get_delivery.customer_filled = customer_filled
|
||||
# get_delivery.cash_recieved = cash_amount
|
||||
|
||||
|
||||
get_delivery.driver_last_name = get_driver.employee_last_name
|
||||
get_delivery.driver_first_name = get_driver.employee_first_name
|
||||
get_delivery.driver_employee_id = get_driver.id
|
||||
# get_delivery.driver_last_name = get_driver.employee_last_name
|
||||
# get_delivery.driver_first_name = get_driver.employee_first_name
|
||||
# get_delivery.driver_employee_id = get_driver.id
|
||||
|
||||
|
||||
# update stats
|
||||
current_deliveres = get_stats.total_deliveries + 1
|
||||
get_stats.total_deliveries = current_deliveres
|
||||
# # update stats
|
||||
# current_deliveres = get_stats.total_deliveries + 1
|
||||
# get_stats.total_deliveries = current_deliveres
|
||||
|
||||
current_gallons_delivered = get_stats.total_gallons_delivered + gallons_delivered
|
||||
get_stats.total_gallons_delivered = current_gallons_delivered
|
||||
# current_gallons_delivered = get_stats.total_gallons_delivered + gallons_delivered
|
||||
# get_stats.total_gallons_delivered = current_gallons_delivered
|
||||
|
||||
|
||||
# update delivery status to delivered
|
||||
if get_delivery.automatic == 0:
|
||||
if get_delivery.payment_type == 0:
|
||||
get_delivery.delivery_status = 10
|
||||
else:
|
||||
#office needs to confirm credit card
|
||||
get_delivery.delivery_status = 1
|
||||
else:
|
||||
get_delivery.delivery_status = 1
|
||||
# # update delivery status to delivered
|
||||
# if get_delivery.automatic == 0:
|
||||
# if get_delivery.payment_type == 0:
|
||||
# get_delivery.delivery_status = 10
|
||||
# else:
|
||||
# #office needs to confirm credit card
|
||||
# get_delivery.delivery_status = 1
|
||||
# else:
|
||||
# get_delivery.delivery_status = 1
|
||||
|
||||
|
||||
db.session.add(get_stats)
|
||||
db.session.add(get_delivery)
|
||||
# db.session.add(get_stats)
|
||||
# db.session.add(get_delivery)
|
||||
|
||||
db.session.commit()
|
||||
# db.session.commit()
|
||||
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'delivery': {
|
||||
'id': get_delivery.id,
|
||||
},
|
||||
}), 200
|
||||
# return jsonify({
|
||||
# "ok": True,
|
||||
# 'delivery': {
|
||||
# 'id': get_delivery.id,
|
||||
# },
|
||||
# }), 200
|
||||
|
||||
|
||||
|
||||
@@ -25,6 +25,19 @@ def delivered_delivery():
|
||||
delivery_schema = Delivery_Delivery_schema(many=True)
|
||||
return jsonify(delivery_schema.dump(delivery_ticket))
|
||||
|
||||
@deliverystatus.route("/count/delivered", methods=["GET"])
|
||||
def delivered_delivery_count():
|
||||
|
||||
delivery_ticket = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(or_(Delivery_Delivery.delivery_status == 1,
|
||||
Delivery_Delivery.delivery_status == 10))
|
||||
.count())
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'count':delivery_ticket,
|
||||
}), 200
|
||||
|
||||
@deliverystatus.route("/today/driver/<int:user_id>", methods=["GET"])
|
||||
def get_deliveries_driver_today(user_id):
|
||||
@@ -41,6 +54,28 @@ def get_deliveries_driver_today(user_id):
|
||||
return jsonify(delivery_schema.dump(get_delivery))
|
||||
|
||||
|
||||
|
||||
@deliverystatus.route("/count/today", methods=["GET"])
|
||||
def get_deliveries_driver_today_count():
|
||||
"""
|
||||
Get deliveries for driver that day
|
||||
"""
|
||||
get_delivery = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(Delivery_Delivery.delivery_status != 10)
|
||||
.filter(Delivery_Delivery.delivery_status != 5)
|
||||
.filter(Delivery_Delivery.delivery_status != 3)
|
||||
.filter(Delivery_Delivery.delivery_status != 1)
|
||||
.filter(Delivery_Delivery.expected_delivery_date == date.today())
|
||||
.count())
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'count':get_delivery,
|
||||
}), 200
|
||||
|
||||
|
||||
|
||||
@deliverystatus.route("/tommorrow/driver/<int:user_id>", methods=["GET"])
|
||||
def get_deliveries_driver_tommorrow(user_id):
|
||||
"""
|
||||
@@ -57,6 +92,23 @@ def get_deliveries_driver_tommorrow(user_id):
|
||||
return jsonify(delivery_schema.dump(get_delivery))
|
||||
|
||||
|
||||
@deliverystatus.route("/count/tommorrow", methods=["GET"])
|
||||
def get_deliveries_driver_tommorrow_count():
|
||||
"""
|
||||
"""
|
||||
tomm = date.today() + timedelta(days=1)
|
||||
get_delivery = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(Delivery_Delivery.expected_delivery_date == tomm)
|
||||
.count())
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'count':get_delivery,
|
||||
}), 200
|
||||
|
||||
|
||||
|
||||
@deliverystatus.route("/waiting/driver/<int:user_id>", methods=["GET"])
|
||||
def get_deliveries_driver_waiting(user_id):
|
||||
"""
|
||||
@@ -73,3 +125,24 @@ def get_deliveries_driver_waiting(user_id):
|
||||
|
||||
delivery_schema = Delivery_Delivery_schema(many=True)
|
||||
return jsonify(delivery_schema.dump(get_delivery))
|
||||
|
||||
|
||||
@deliverystatus.route("/count/waiting", methods=["GET"])
|
||||
def get_deliveries_driver_waiting_count():
|
||||
"""
|
||||
waiting deliveries scheduled out
|
||||
"""
|
||||
tomm = date.today() + timedelta(days=1)
|
||||
get_delivery = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
|
||||
.filter(Delivery_Delivery.delivery_status == 0)
|
||||
.filter(Delivery_Delivery.expected_delivery_date != tomm)
|
||||
.filter(Delivery_Delivery.expected_delivery_date != date.today())
|
||||
.count())
|
||||
|
||||
|
||||
return jsonify({
|
||||
"ok": True,
|
||||
'count':get_delivery,
|
||||
}), 200
|
||||
|
||||
7
app/social/__init__.py
Normal file
7
app/social/__init__.py
Normal file
@@ -0,0 +1,7 @@
|
||||
# coding=utf-8
|
||||
|
||||
from flask import Blueprint
|
||||
|
||||
social = Blueprint('social', __name__)
|
||||
|
||||
from . import views
|
||||
76
app/social/views.py
Normal file
76
app/social/views.py
Normal file
@@ -0,0 +1,76 @@
|
||||
from flask import jsonify, request
|
||||
import datetime
|
||||
from app.social import social
|
||||
from app import db
|
||||
|
||||
from app.classes.customer_social import (Customer_Customer_Social_schema,
|
||||
Customer_Customer_Social)
|
||||
|
||||
|
||||
@social.route("/posts/<int:customer_id>/<int:page>", methods=["GET"])
|
||||
def get_customer_posts(customer_id, page):
|
||||
per_page_amount = 50
|
||||
if page is None:
|
||||
offset_limit = 0
|
||||
elif page == 1:
|
||||
offset_limit = 0
|
||||
else:
|
||||
offset_limit = (per_page_amount * page) - per_page_amount
|
||||
|
||||
customer_posts = (db.session
|
||||
.query(Customer_Customer_Social)
|
||||
.filter(Customer_Customer_Social.customer_id == customer_id)
|
||||
.limit(per_page_amount).offset(offset_limit))
|
||||
customer_social_schema = Customer_Customer_Social_schema(many=True)
|
||||
return jsonify(customer_social_schema.dump(customer_posts))
|
||||
|
||||
|
||||
|
||||
@social.route("/create/<int:customer_id>", methods=["POST"])
|
||||
def create_post(customer_id):
|
||||
|
||||
comment = request.json["comment"]
|
||||
poster_employee_id = request.json["poster_employee_id"]
|
||||
|
||||
create_post = Customer_Customer_Social(
|
||||
created = datetime.datetime.utcnow(),
|
||||
customer_id = customer_id,
|
||||
poster_employee_id = poster_employee_id,
|
||||
comment = comment
|
||||
)
|
||||
|
||||
db.session.add(create_post)
|
||||
db.session.commit()
|
||||
return jsonify({ "ok": True,}), 200
|
||||
|
||||
|
||||
|
||||
@social.route("/posts/<int:post_id>", methods=["PATCH"])
|
||||
def edit_post(post_id):
|
||||
|
||||
customer_post = (db.session
|
||||
.query(Customer_Customer_Social)
|
||||
.filter(Customer_Customer_Social.id == post_id)
|
||||
.first())
|
||||
comment = request.json["comment"]
|
||||
customer_post.comment = comment
|
||||
|
||||
db.session.add(customer_post)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({ "ok": True,}), 200
|
||||
|
||||
|
||||
|
||||
@social.route("/delete/<int:post_id>", methods=["DELETE"])
|
||||
def delete_post(post_id):
|
||||
|
||||
customer_post = (db.session
|
||||
.query(Customer_Customer_Social)
|
||||
.filter(Customer_Customer_Social.id == post_id)
|
||||
.first())
|
||||
|
||||
db.session.delete(customer_post)
|
||||
db.session.commit()
|
||||
|
||||
return jsonify({ "ok": True,}), 200
|
||||
@@ -147,6 +147,7 @@ def get_user_stats(user_id):
|
||||
.query(Stats_Customer) \
|
||||
.filter(Stats_Customer.customer_id == user_id) \
|
||||
.first()
|
||||
|
||||
user_schema = Stats_Customer_schema(many=False)
|
||||
return jsonify(user_schema.dump(get_user))
|
||||
|
||||
@@ -190,3 +191,27 @@ def total_gallons_delivered_this_week():
|
||||
'total': total_gallons,
|
||||
}), 200
|
||||
|
||||
@stats.route("/gallons/check/total/<int:user_id>", methods=["GET"])
|
||||
def calculate_gallons_user(user_id):
|
||||
# Get today's date
|
||||
total_gallons = 0
|
||||
|
||||
|
||||
# Get the date of the Monday for today
|
||||
|
||||
get_total = (db.session
|
||||
.query(Delivery_Delivery)
|
||||
.filter(Delivery_Delivery.customer_id == user_id)
|
||||
.all())
|
||||
get_user = db.session \
|
||||
.query(Stats_Customer) \
|
||||
.filter(Stats_Customer.customer_id == user_id) \
|
||||
.first()
|
||||
for f in get_total:
|
||||
total_gallons = total_gallons + f.gallons_delivered
|
||||
get_user.oil_total_gallons = total_gallons
|
||||
db.session.add(get_user)
|
||||
db.session.commit()
|
||||
return jsonify({"ok": True,
|
||||
}), 200
|
||||
|
||||
|
||||
Reference in New Issue
Block a user