Esempio n. 1
0
def SearchOrders(session):
    req = SearchItemsReq(request.json)
    if (req.order_id):
        orders = models.Orders.query.filter(
            models.Orders.order_id == req.order_id)
        return jsonify(ConvertModelListToDictList(orders))

    orders = models.Orders.query.all()
    if req.type != None:
        orders = [order for order in orders if order.type == req.type]

    if req.customer_id != None:
        orders = [
            order for order in orders
            if order.customer != None and order.customer.customer_id == (
                req.customer_id)
        ]

    if req.customer_phone != None:
        orders = [
            order for order in orders
            if order.customer != None and order.customer.phone == (
                req.customer_phone)
        ]

    orders = [order for order in orders if order.delete_at == None]
    orders = ConvertModelListToDictList(orders)
    return jsonify(orders)
Esempio n. 2
0
def SearchAccounts():
    req = SearchItemsReq(request.json)
    if (req.account_id):
        accounts = models.Accounts.query.filter(
            models.Accounts.account_id == req.account_id).all()
        info_accounts = []
        for account in ConvertModelListToDictList(accounts):
            user_info = {}
            if (account['role']['role_id'] == 3):  # customer
                search_customer_req = SearchCustomersReq(
                    {'account_id': account['account_id']})
                user_info = CustomerRep.SearchCustomers(search_customer_req)

            if (account['role']['role_id'] == 1
                    or account['role']['role_id'] == 2):  # admin, manager
                search_employee_req = SearchEmployeesReq(
                    {'account_id': account['account_id']})
                user_info = EmployeeRep.SearchEmployees(search_employee_req)

            account_info = user_info[0] if user_info else {'account': account}
            account_info['account_id'] = account['account_id']
            account_info['account_name'] = account['account_name']
            account_info['role'] = account['role']
            account_info['note'] = account['note']
            account_info['delete_at'] = account['delete_at']
            info_accounts.append(account_info)
        return jsonify((info_accounts))
    all_accounts = models.Accounts.query
    if req.account_name != None:
        all_accounts = all_accounts.filter(
            models.Accounts.account_name.contains(req.account_name))
    if req.role_id != None:
        all_accounts = all_accounts.filter(
            models.Accounts.role_id == (req.role_id))
    all_accounts = all_accounts.filter(models.Accounts.delete_at == None)
    accounts = ConvertModelListToDictList(all_accounts.all())
    info_accounts = []
    for account in accounts:
        user_info = {}
        if (account['role']['role_id'] == 3):  # customer
            search_customer_req = SearchCustomersReq(
                {'account_id': account['account_id']})
            user_info = CustomerRep.SearchCustomers(search_customer_req)

        if (account['role']['role_id'] == 1
                or account['role']['role_id'] == 2):  # admin, manager
            search_employee_req = SearchEmployeesReq(
                {'account_id': account['account_id']})
            user_info = EmployeeRep.SearchEmployees(search_employee_req)

        account_info = user_info[0] if user_info else {'account': account}
        account_info['account_id'] = account['account_id']
        account_info['account_name'] = account['account_name']
        account_info['role'] = account['role']
        account_info['note'] = account['note']
        account_info['delete_at'] = account['delete_at']
        info_accounts.append(account_info)
    return jsonify(info_accounts)
def searchBorrowTickets():
    req = SearchItemsReq(request.json)
    borrow_tickets = []
    if (req.borrow_ticket_id):
        borrow_tickets = models.Borrowtickets.query.filter(models.Borrowtickets.borrow_ticket_id == req.borrow_ticket_id)
        return jsonify({"borrow_tickets": ConvertModelListToDictList(borrow_tickets)})
    return jsonify({
        "borrow_tickets":ConvertModelListToDictList(borrow_tickets)
    })
def SearchEmployees():
    req = SearchItemsReq(request.json)
    if (req.employee_id):
        employees = models.Employees.query.filter(
            models.Employees.employee_id == req.employee_id,
            models.Employees.delete_at == None)
        return jsonify(ConvertModelListToDictList(employees.all()))

    employees = models.Employees.query
    if req.phone != None:
        employees = employees.filter(models.Employees.phone.contains(
            req.phone))

    employees = employees.filter(models.Employees.delete_at == None)
    employees = ConvertModelListToDictList(employees.all())
    return jsonify(employees)
def searchBorrowTickets():
    req = SearchItemsReq(request.json)
    borrow_tickets = []
    if (req.borrow_ticket_id):
        borrow_tickets = models.Borrowtickets.query.filter(models.Borrowtickets.borrow_ticket_id == req.borrow_ticket_id)
        return jsonify({"borrow_tickets": ConvertModelListToDictList(borrow_tickets)})

    borrow_tickets = models.Borrowtickets.query.all()
    if req.customer_name != None:
        all_customers = models.Customers.query.filter((models.Customers.first_name.ilike(f'%{req.customer_name}%'))).all()
        customer_ids = []
        for customer in (all_customers):
            customer_ids.append(customer.customer_id)
        borrow_tickets = models.Borrowtickets.query.filter(models.Borrowtickets.customer_id.in_(customer_ids))

    if req.customer_phone != None:
        all_customers = models.Customers.query.filter((models.Customers.phone.ilike(f'%{req.customer_phone}%'))).all()
        customer_ids = []
        for customer in (all_customers):
            customer_ids.append(customer.customer_id)
        borrow_tickets = models.Borrowtickets.query.filter(models.Borrowtickets.customer_id.in_(customer_ids))

    if req.borrow_ticket_status != None and req.borrow_ticket_status != "":
        current_date = datetime.now()
        if req.borrow_ticket_status == "B":
            borrow_tickets = models.Borrowtickets.query.filter( (models.Borrowtickets.appointment_date >= current_date), (models.Borrowtickets.return_date == None) )
        if req.borrow_ticket_status == "L":
            borrow_tickets = models.Borrowtickets.query.filter((models.Borrowtickets.appointment_date < current_date),
                                                               (models.Borrowtickets.return_date == None))
        if req.borrow_ticket_status == "LF":
            borrow_tickets = models.Borrowtickets.query.filter((models.Borrowtickets.return_date > models.Borrowtickets.appointment_date),
                                                               (models.Borrowtickets.return_date != None))
        if req.borrow_ticket_status == "F":
            borrow_tickets = models.Borrowtickets.query.filter(
                (models.Borrowtickets.return_date <= models.Borrowtickets.appointment_date),
                (models.Borrowtickets.return_date != None))
    return jsonify({
        "borrow_tickets":ConvertModelListToDictList(borrow_tickets)
    })
Esempio n. 6
0
def SearchSuppliers():
    req = SearchItemsReq(request.json)
    if (req.supplier_id):
        suppliers = models.Suppliers.query.filter(
            models.Suppliers.supplier_id == req.supplier_id)
        return jsonify(ConvertModelListToDictList(suppliers))

    suppliers = models.Suppliers.query.all()
    if req.email != None:
        suppliers = [
            supplier for supplier in suppliers if supplier.email == req.email
        ]

    if req.contact_name != None:
        suppliers = [
            supplier for supplier in suppliers
            if supplier.contact_name == (req.contact_name)
        ]

    suppliers = [
        supplier for supplier in suppliers if supplier.delete_at == None
    ]
    suppliers = ConvertModelListToDictList(suppliers)
    return jsonify(suppliers)
def SearchBorrowTicket():
    req = SearchItemsReq(request.json)
    req = SearchBorrowTicketReq(request.json)
    result = BorrowTicketSvc.SearchBorrowTicket(req)
    res = SearchBorrowTicketRsp(result).serialize()
    return jsonify(res)