Exemple #1
0
    def delete(self, id):
        """function for "DELETE /clients/<id>" endpoint

        Args:
            id (int): id for the Client

        Returns:
            {
                "status" : "success,
                "message" : "Successfully deleted the item from Clients with Id 1"
            }
        """

        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json',
                            401)

        client = Clients.query.filter(Clients.id_ == id).first()

        if not client:
            abort(404)

        db_session.delete(client)
        db_session.commit()

        return response(
            'success',
            'Successfully deleted the item from Client with Id ' + str(id),
            200)
Exemple #2
0
    def put(self, item_code):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json', 401)

        item = Items.query.filter(Items.item_code == item_code).first()

        if not item:
            return response('Not Found', f'Item with Item Code {item_code} is not available.', 404)

        data = request.get_json()

        if data.get("name"):
            item.name = data.get('name')

        if data.get("qty"):
            item.qty = data.get('qty')

        if data.get("retail_price"):
                    item.retail_price = data.get('retail_price')

        if data.get("wholesale_price"):
                    item.wholesale_price = data.get('wholesale_price')

        if data.get("mfd_date"):
                    item.mfd_date = data.get('mfd_date')

        if data.get("exp_date"):
                    item.exp_date = data.get('exp_date')

        db_session.commit()

        return response('Update Successful.', f'Successfully updated the Items with Item Code {str(item_code)}', 200,item_schema.dump(item))
Exemple #3
0
    def put(self, id):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json', 401)

        bill = Bills.query.filter(Bills.id_ == id).first()

        if not bill:
            return response('Not Found', f'Bill with Bill Code {id} is not available.', 404)

        data = request.get_json()

        if data.get('bill_number'):
            bill.bill_number = data.get('bill_number')

        if data.get('client'):
            bill.client = data.get('client')

        if data.get('cashier'):
            bill.cashier = data.get('cashier')

        if data.get('paid'):
            bill.paid = data.get('paid')

        if data.get('date'):
            bill.date = data.get('date')

        if data.get('amount'):
            bill.amount = data.get('amount')

        db_session.commit()

        return response('success', 'Successfully updated the item from Bills with Id ' + str(id), 200)
Exemple #4
0
    def post(self):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json', 401)

        data = request.get_json()

        fields = ['bill_number', 'client', 'cashier', 'paid','date', 'amount']
        string = ''

        for i in fields:
            if not data.get(f'{i}'):
                string = string+f'\"{i}\", '

        if string:
            return response('Invalid POST Request', f'These fields should be included in the POST Request. {string}', 404)

        client1 = Clients.query.filter(Clients.id_ == data.get('client')).first()

        bill = Bills(
            bill_number=data.get('bill_number'),
            client=client1,
            cashier=data.get('cashier'),
            paid=data.get('paid'),
            date=data.get('date'),
            amount=data.get('amount')
        )

        db_session.add(bill)
        db_session.commit()

        return response('Added Successfully.', f'Successfully added the Bill with Code {str(bill.bill_number)}', 200, bill_schema.dump(bill))
Exemple #5
0
def register():
    if not request.content_type == 'application/json':
        return response('Failed', 'Content-type must be application/json', 401)

    data = request.get_json()

    fields = ['email', 'username', 'password']
    string = ''

    for i in fields:
        if not data.get(f'{i}'):
            string = string + f'\"{i}\", '

    if string:
        return response(
            'Invalid POST Request',
            f'These fields should be included in the POST Request. {string}',
            404)

    user = User.query.filter(User.email == data.get('username')).first()

    if user:
        return response('Not Found',
                        f'User with username {user} alreay exists.', 404)

    security.datastore.create_user(email=data.get('email'),
                                   username=data.get('username'),
                                   password=hash_password(
                                       data.get('password')))

    security.datastore.commit()

    return 'success'
Exemple #6
0
    def put(self, id):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json', 401)

        stock = Stock.query.filter(Stock.id_ == id).first()

        if not stock:
            return response('Not Found', f'Item with Item Code {id} is not available.', 404)

        data = request.get_json()

        if data.get('item_code'):
            item = Items.query.filter(Items.id_ == data.get('item_code')).first()
            stock.item=item

        if data.get("qty"):
            stock.qty = data.get('qty')

        if data.get("retail_price"):
                    stock.retail_price = data.get('retail_price')

        if data.get("wholesale_price"):
                    stock.wholesale_price = data.get('wholesale_price')

        if data.get("mfd_date"):
                    stock.mfd_date = data.get('mfd_date')

        if data.get("exp_date"):
                    stock.exp_date = data.get('exp_date')

        db_session.commit()

        return response('Update Successful.', f'Successfully updated the Items with Item Code {str(id)}', 200, stock_schema.dump(stock))
Exemple #7
0
    def post(self):
        if not request.content_type == 'application/json':
            return response('Failed', 'Content-type must be application/json', 401)

        data = request.get_json()

        fields = ['item_code', 'name', 'qty', 'retail_price',
            'wholesale_price', 'mfd_date', 'exp_date']
        string = ''

        for i in fields:
            if not data.get(f'{i}'):
                string = string+f'\"{i}\", '

        if string:
            return response('Invalid POST Request', f'These fields should be included in the POST Request. {string}', 404)

        item = Items(
            item_code=data.get('item_code'),
            name=data.get('name'),
            qty=data.get('qty'),
            retail_price=data.get('retail_price'),
            wholesale_price=data.get('wholesale_price'),
            mfd_date=data.get('mfd_date'),
            exp_date=data.get('exp_date')
        )

        db_session.add(item)
        db_session.commit()

        return response('Added Successfully.', f'Successfully added the item with Item Code {str(item.item_code)}', 200, item_schema.dump(item))
Exemple #8
0
    def put(self, id):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json', 401)

        payment = Payments.query.filter(Payments.id_ == id).first()

        if not payment:
            abort(404)

        data = request.get_json()

        payment_type1 = Payment_Types.query.filter(
            Payment_Types.type_name == data.get('payment_types')).first()

        payment_method1 = Payment_Methods.query.filter(
            Payment_Methods.method_name == data.get('payment_methods')).first()

        payment.payment_types = payment_type1
        payment.payment_methods = payment_method1
        payment.amount = data.get('amount'),
        payment.date = data.get('date'),
        payment.due_date = data.get('due_date'),
        payment.paid = False

        db_session.commit()

        return response('success', 'Successfully updated the item from Payments with Id ' + str(id), 200)
Exemple #9
0
    def put(self, id):
        """function for "PUT /clients/<id>" endpoint

        Args:
            id (int): id for the Client

        Returns:
            {
                "status" : "success,
                "message" : "Successfully updated the item from Clients with Id 1"
            }
        """

        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json',
                            401)

        client = Clients.query.filter(Clients.id_ == id).first()

        if not client:
            abort(404)

        data = request.get_json()

        client.name = data.get('name'),
        client.address = data.get('address'),
        client.telephone = data.get('telephone'),
        client.email = data.get('email')

        db_session.commit()

        return response(
            'success',
            'Successfully updated the item from Clients with Id ' + str(id),
            200)
Exemple #10
0
    def delete(self, id):
        bill = Bills.query.filter(Bills.id_ == id).first()

        if not bill:
            return response('Not Found', f'Bill with Bill Code {id} is not available.', 404)

        db_session.delete(bill)
        db_session.commit()

        return response('Deleted Successfully.', f'Successfully deleted the Bill with Code {str(bill.bill_number)}', 200, bill_schema.dump(bill))
Exemple #11
0
    def delete(self, item_code):

        item = Items.query.filter(Items.item_code == item_code).first()

        if not item:
            return response('Not Found', f'Item with Item Code {item_code} is not available.', 404)

        db_session.delete(item)
        db_session.commit()

        return response('Delete Successful.', f'Successfully deleted the Items with Item Code {str(item_code)}', 200, item_schema.dump(item))
Exemple #12
0
    def delete(self, id):

        stock = Stock.query.filter(Stock.id_ == id).first()

        if not stock:
            return response('Not Found', f'Item with Item Code {id} is not available.', 404)

        db_session.delete(stock)
        db_session.commit()

        return response('Delete Successful.', f'Successfully deleted the Items with Item Code {str(id)}', 200, stock_schema.dump(stock))
Exemple #13
0
    def post(self):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json', 401)

        data = request.get_json()

        payment_type1 = Payment_Types.query.filter(
            Payment_Types.type_name == data.get('payment_types')).first()

        payment_method1 = Payment_Methods.query.filter(
            Payment_Methods.method_name == data.get('payment_methods')).first()

        payment = Payments(
            amount=data.get('amount'),
            date=data.get('date'),
            due_date=data.get('due_date'),
            paid=False,
            payment_methods=payment_method1,
            payment_types=payment_type1
        )

        db_session.add(payment)
        db_session.commit()

        return payment_schema.jsonify(payment)
Exemple #14
0
    def put(self, item_code):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json', 401)

        item = Items.query.filter(Items.id_ == item_code).first()

        if not item:
            return response('Not Found', f'Item with Item Code {item_code} is not available.', 404)

        data = request.get_json()

        item.name = data.get('name')

        db_session.commit()

        return response('Update Successful.', f'Successfully updated the Items with Item Code {str(item_code)}', 200,item_schema.dump(item))
Exemple #15
0
    def post(self):
        """function for "POST /clients/" endpoint

        Returns:
            {
                "address": "Address 1",
                "created_at": "2019-09-20T06:07:23.611071",
                "email": "*****@*****.**",
                "id_": 1,
                "name": "Client 1",
                "telephone": "123456789",
                "updated_at": null
            }
        """

        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json',
                            401)

        data = request.get_json()

        clients = Clients(name=data.get('name'),
                          address=data.get('address'),
                          telephone=data.get('telephone'),
                          email=data.get('email'))

        db_session.add(clients)
        db_session.commit()

        client = Clients.query.filter(Clients.name == data.get('name')).first()

        return client_schema.jsonify(client)
Exemple #16
0
    def delete(self, id):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json',
                            401)

        payment = Payments.query.filter(Payments.id_ == id).first()

        if not payment:
            abort(404)

        db_session.delete(payment)
        db_session.commit()

        return response(
            'success',
            'Successfully deleted the item from Payments with Id ' + str(id),
            200)
Exemple #17
0
    def delete(self, id):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json',
                            401)

        distributor = Distributors.query.filter(Distributors.id_ == id).first()

        if not distributor:
            abort(404)

        db_session.delete(distributor)
        db_session.commit()

        return response(
            'success',
            'Successfully deleted the item from Distributors with Id ' +
            str(id), 200)
Exemple #18
0
    def delete(self, id):
        distributor = Distributors.query.filter(Distributors.id_ == id).first()

        if not distributor:
            abort(404)

        db_session.delete(distributor)
        db_session.commit()

        return response('success', 'Successfully deleted the item from Distributors with Id ' + str(id), 200)
Exemple #19
0
    def put(self, id):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json', 401)

        distributor = Distributors.query.filter(Distributors.id_ == id).first()

        if not distributor:
            abort(404)

        data = request.get_json()

        distributor.name = data.get('name'),
        distributor.address = data.get('address'),
        distributor.telephone = data.get('telephone'),
        distributor.email = data.get('email')

        db_session.commit()

        return response('success', 'Successfully updated the item from Distributors with Id ' + str(id), 200)
Exemple #20
0
    def delete(self, id):
        payment = Payments.query.filter(Payments.id_ == id).first()

        if not payment:
            abort(404)

        db_session.delete(payment)
        db_session.commit()

        return response('success', 'Successfully deleted the item from Payments with Id ' + str(id), 200)
Exemple #21
0
    def put(self, id):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json',
                            401)

        bill = Bills.query.filter(Bills.id_ == id).first()

        if not bill:
            return response('Not Found',
                            f'Bill with Bill Code {id} is not available.', 404)

        data = request.get_json()

        print(data)

        # if data.get('bill_number'):
        #     bill.bill_number = data.get('bill_number')

        if data.get('client'):
            bill.client_id = data.get('client')

        if data.get('cashier'):
            bill.cashier = data.get('cashier')

        if data.get('paid') == "paid":
            bill.paid = True
        else:
            bill.paid = False

        if data.get('date'):
            bill.date = data.get('date')

        if data.get('amount'):
            bill.amount = data.get('amount')

        db_session.commit()

        return response(
            'Updated Successfully.',
            f'Successfully updated the Bill with Code {str(bill.bill_number)}',
            200, bill_schema.dump(bill))
Exemple #22
0
    def get(self, item_code):
        if item_code is None:
            items = Items.query.all()

            return items_schema.jsonify(items)
        else:
            item = Items.query.filter(Items.id_ == item_code).first()

            if not item:
                return response('Not Found', f'Item with Item Code {item_code} is not available.', 404)

            return item_schema.jsonify(item)
Exemple #23
0
def login():
    if not request.content_type == 'application/json':
        return response('Failed', 'Content-type must be application/json', 401)

    data = request.get_json()

    fields = ['username', 'password']
    string = ''

    for i in fields:
        if not data.get(f'{i}'):
            string = string + f'\"{i}\", '

    if string:
        return response(
            'Invalid POST Request',
            f'These fields should be included in the POST Request. {string}',
            404)

    user = User.query.filter(User.email == data.get('username')).first()

    if not user:
        return response('Not Found',
                        f'User with username {user} does not exists.', 404)

    if not verify_password(data.get('password'), user.password):
        return response('Wrong Password',
                        f'Password for user {user.username} does not match.',
                        404)

    login_user(user, remember=True)

    security.datastore.commit()

    return response('Success', f'User {user.username} Successfully Logged In.',
                    200, user_schema.dump(user), user.get_auth_token())
Exemple #24
0
    def get(self, item_code):
        if item_code is None:
            items = Items.query.all()

            report = Items.query.with_entities(func.date_trunc("day", Items.created_at).label("date"), func.count(
                Items.item_code).label("count")).group_by(func.date_trunc("day", Items.created_at)).all()

            return jsonify(data=items_schema.dump(items), report=report)
        else:
            item = Items.query.filter(Items.item_code == item_code).first()

            if not item:
                return response('Not Found', f'Item with Item Code {item_code} is not available.', 404)

            return item_schema.jsonify(item)
Exemple #25
0
    def get(self, id):
        if id is None:
            stock = Stock.query.all()

            report = Stock.query.with_entities(func.date_trunc("day", Stock.exp_date).label("date"), func.count(
                Stock.id_).label("count")).group_by(func.date_trunc("day", Stock.exp_date)).all()

            return jsonify(data=stocks_schema.dump(stock), report=report)
        else:
            stock = Stock.query.filter(Stock.id_ == id).first()

            if not stock:
                return response('Not Found', f'Item with Item Code {id} is not available.', 404)

            return stock_schema.jsonify(stock)
Exemple #26
0
    def get(self, id):
        if id is None:
            bills = Bills.query.all()

            report = Bills.query.with_entities(func.date_trunc("day", Bills.date).label("date"), func.count(
                Bills.bill_number).label("count")).group_by(func.date_trunc("day", Bills.date)).all()

            return jsonify(data=bills_schema.dump(bills), report=report)

            return bills_schema.jsonify(bills)
        else:
            bill = Bills.query.filter(Bills.id_ == id).first()

            if not bill:
                return response('Not Found', f'Bill with Bill Code {id} is not available.', 404)

            return bill_schema.jsonify(bill)
Exemple #27
0
    def post(self):
        if not request.content_type == 'application/json':
            return response('failed', 'Content-type must be application/json',
                            401)

        data = request.get_json()

        distributors = Distributors(name=data.get('name'),
                                    address=data.get('address'),
                                    telephone=data.get('telephone'),
                                    email=data.get('email'))

        db_session.add(distributors)
        db_session.commit()

        distributor = Distributors.query.filter(
            Distributors.name == data.get('name')).first()

        return distributor_schema.jsonify(distributor)
Exemple #28
0
    def delete(self, id):
        """function for "DELETE /clients/<id>" endpoint

        Args:
            id (int): id for the Client

        Returns:
            {
                "status" : "success,
                "message" : "Successfully deleted the item from Clients with Id 1"
            }
        """

        client = Clients.query.filter(Clients.id_ == id).first()

        if not client:
            abort(404)

        db_session.delete(client)
        db_session.commit()

        return response('success', 'Successfully deleted the item from Client with Id ' + str(id), 200)
Exemple #29
0
def get_all_users():
    users = User.query.all()

    return response('User List', 'Full user list', 200,
                    users_schema.dump(users), current_user.get_auth_token())