示例#1
0
 def getAllTransactions(self):
     dao = TransactionDAO()
     transaction_list = dao.getAllTransactions()
     if not transaction_list:
         return jsonify(Error="Transaction Not Found"), 404
     else:
         result_list = []
         for row in transaction_list:
             result = self.build_transaction_dict(row)
             result_list.append(result)
         return jsonify(Transactions=result_list)
示例#2
0
    def searchSupplierOfThisTransaction(self, tid, args):

        daoTrans = TransactionDAO()
        dao = SupplierDAO()

        if not daoTrans.getTransactionById(tid):
            return jsonify(Error = 'Transaction Not Found'), 404

        afirst = args.get('afirst')
        alast = args.get('alast')
        email = args.get('email')
        phone = args.get('phone')

        suppliers_list = []

        if(len(args) == 4) and afirst and alast and email and phone:
            suppliers_list = dao.getSupplierOfThisTransactionByAfirstAlastEmailPhone(tid, afirst, alast, email, phone)
        elif(len(args) == 3) and afirst and alast and email:
            suppliers_list = dao.getSupplierOfThisTransactionByAfirstAlastEmail(tid, afirst, alast, email)
        elif(len(args) == 3) and afirst and alast and phone:
            suppliers_list = dao.getSupplierOfThisTransactionByAfirstAlastPhone(tid, afirst, alast, phone)
        elif(len(args) == 3) and afirst and phone and email:
            suppliers_list = dao.getSupplierOfThisTransactionByAfirstPhoneEmail(tid, afirst, phone, email)
        elif(len(args) == 3) and alast and email and phone:
            suppliers_list = dao.getSupplierOfThisTransactionByAlastEmailPhone(tid, alast, email, phone)
        elif(len(args) == 2) and afirst and alast:
            suppliers_list = dao.getSupplierOfThisTransactionByAfirstAlast(tid, afirst, alast)
        elif(len(args) == 2) and afirst and email:
            suppliers_list = dao.getSupplierOfThisTransactionByAfirstEmail(tid, afirst, email)
        elif(len(args) == 2) and afirst and phone:
            suppliers_list = dao.getSupplierOfThisTransactionByAfirstPhone(tid, afirst, phone)
        elif(len(args) == 2) and alast and email:
            suppliers_list = dao.getSupplierOfThisTransactionByAlastEmail(tid, alast, email)
        elif(len(args) == 2) and alast and phone:
            suppliers_list = dao.getSupplierOfThisTransactionByAlastPhone(tid, alast, phone)
        elif(len(args) == 2) and email and phone:
            suppliers_list = dao.getSupplierOfThisTransactionByEmailPhone(tid, email, phone)
        elif(len(args) == 1) and afirst:
            suppliers_list = dao.getSupplierOfThisTransactionByAfirst(tid, afirst)
        elif(len(args) == 1) and alast:
            suppliers_list = dao.getSupplierOfThisTransactionByAlast(tid, alast)
        elif(len(args) == 1) and email:
            suppliers_list = dao.getSupplierOfThisTransactionByEmail(tid, email)
        elif(len(args) == 1) and phone:
            suppliers_list = dao.getSupplierOfThisTransactionByPhone(tid, phone)
        else:
            return jsonify(Error = "Malformed query string"), 400
        result_list = []
        for row in suppliers_list:
            result = self.build_supplier_dict(row)
            result_list.append(result)
        return jsonify(Suppliers = result_list)
示例#3
0
 def getTransactionSum(self, args):
     s_id = args.get("seller")
     b_id = args.get("buyer")
     t_date = args.get("date")
     r_id = args.get("resource")
     region = args.get("region")
     city = args.get("city")
     dao = TransactionDAO()
     sum = []
     if (len(args) == 1) and s_id:
         sum = dao.getTransactionSumBySeller(s_id)
     elif (len(args) == 1) and b_id:
         sum = dao.getTransactionSumByBuyer(b_id)
     elif (len(args) == 1) and t_date:
         sum = dao.getTransactionSumByDate(t_date)
     elif (len(args) == 1) and r_id:
         sum = dao.getTransactionSumByResource(r_id)
     elif (len(args) == 1) and region:
         sum = dao.getTransactionSumByRegion(region)
     elif (len(args) == 1) and city:
         sum = dao.getTransactionSumByCity(city)
     else:
         return jsonify(Error="Malformed query string"), 400
     if not sum:
         return jsonify(Error="Transaction Not Found"), 404
     else:
         if sum[0] is None:
             sum = []
             sum.append(0)
         return jsonify(TransactionsSum=sum[0])
示例#4
0
    def getBankAccountOfThisTransaction(self, tid):

        dao = BankAccountDAO()
        daoTran = TransactionDAO()

        if not daoTran.getTransactionById(tid):
            return jsonify(Error='Transaction Not Found'), 404

        bank_accounts_list = dao.getBankAccountOfThisTransaction(tid)
        result_list = []
        for row in bank_accounts_list:
            result = self.build_bank_account_dict(row)
            result_list.append(result)
        return jsonify(Bank_Account=result_list)
示例#5
0
    def getRequestersOfThisTransaction(self, tid):

        dao = RequesterDAO()
        daoT = TransactionDAO()

        if not daoT.getTransactionById(tid):
            return jsonify(Error="Transaction Not Found"), 404

        requesters_list = dao.getRequestersOnThisTransaction(tid)
        result_list = []

        for row in requesters_list:
            result = self.build_requester_dict(row)
            result_list.append(result)
        return jsonify(Requesters=result_list)
示例#6
0
    def getSupplierOfThisTransaction(self, tid):

        daoTrans = TransactionDAO()
        dao = SupplierDAO()

        if not daoTrans.getTransactionById(tid):
            return jsonify(Error = 'Transaction Not Found'), 404

        suppliers_list = dao.getSupplierOfThisTransaction(tid)

        result_list = []
        for row in suppliers_list:
            result = self.build_supplier_dict(row)
            result_list.append(result)
        return jsonify(Supplier = result_list)
示例#7
0
 def purchase_donation(self, args):
     if len(args) != 4:
         return jsonify(ERROR='Malformed URL.'), 404
     try:
         TAmount = args['TAmount']
         BID = args['BID']
         CID = args['CID']
         IID = args['IID']
     except KeyError:
         return jsonify(ERROR='Malformed URL.'), 404
     dao = TransactionDAO()
     transaction = dao.insert_donation(TAmount, BID, CID, IID)
     if transaction:
         transaction = dao.get_transaction(transaction)
         transaction = self.build_transaction_dict(transaction)
         return jsonify(Transaction=transaction), 201
     return jsonify(ERROR='Malformed URL.'), 404
示例#8
0
 def updateTransaction(self, t_id, form):
     dao = TransactionDAO()
     if not dao.getTransactionById(t_id):
         return jsonify(Error="Transaction not found."), 404
     else:
         if len(form) != 9:
             return jsonify(Error="Malformed update Transaction"), 400
         else:
             s_id = form['s_id']
             b_id = form['b_id']
             ba_id = form['ba_id']
             c_id = form['c_id']
             r_id = form['r_id']
             t_qty = form['t_qty']
             t_total = form['t_total']
             t_donation = form['t_donation']
             t_reservation = form['t_reservation']
             if s_id and b_id and ba_id and c_id and r_id and t_qty and t_total and t_donation and t_reservation:
                 dao = TransactionDAO()
                 dao.update(t_id, s_id, b_id, ba_id, c_id, r_id, t_qty,
                            t_total, t_donation, t_reservation)
                 result = self.build_transaction_attributes(
                     t_id, s_id, b_id, ba_id, c_id, r_id, t_qty, t_total,
                     t_donation, t_reservation)
                 return jsonify(Transaction=result), 201
             else:
                 return jsonify(
                     Error="Unexpected attributes in update Transaction"
                 ), 400
示例#9
0
    def seatchBankAccountOfThisTransaction(self, tid, args):

        dao = BankAccountDAO()
        daoTran = TransactionDAO()

        if not daoTran.getTransactionById(tid):
            return jsonify(Error='Transaction Not Found'), 404

        routing = args.get('routing')
        accountNumber = args.get('accountNumber')
        BankName = args.get('BankName')

        bank_accounts_list = []

        if (len(args) == 3) and routing and accountNumber and BankName:
            bank_accounts_list = dao.getBankAccountOfThisTransactionByRoutingAccountNumberBankName(
                tid, routing, accountNumber, BankName)
        elif (len(args) == 2) and routing and accountNumber:
            bank_accounts_list = dao.getBankAccountOfThisTransactionByRoutingAccountNumber(
                tid, routing, accountNumber)
        elif (len(args) == 2) and routing and BankName:
            bank_accounts_list = dao.getBankAccountOfThisTransactionByRoutingBankName(
                tid, routing, BankName)
        elif (len(args) == 2) and accountNumber and BankName:
            bank_accounts_list = dao.getBankAccountOfThisTransactionByAccountNumberBankName(
                tid, accountNumber, BankName)
        elif (len(args) == 1) and routing:
            bank_accounts_list = dao.getBankAccountOfThisTransactionByRouting(
                tid, routing)
        elif (len(args) == 1) and accountNumber:
            bank_accounts_list = dao.getBankAccountOfThisTransactionByAccountNumber(
                tid, accountNumber)
        elif (len(args) == 1) and BankName:
            bank_accounts_list = dao.getBankAccountOfThisTransactionByBankName(
                tid, BankName)
        else:
            return jsonify(Error="Malformed query string"), 400
        result_list = []

        for row in bank_accounts_list:
            result = self.build_bank_account_dict(row)
            result_list.append(result)
        return jsonify(Bank_Account=result_list)
 def getCategoriesByTransactionId(self, tid):
     if not TransactionDAO().getTransactionById(tid):
         return jsonify(Error="Transaction Not Found"), 404
     else:
         category_list = CategoryDAO().getCategoriesByTransactionId(tid)
         result_list = []
         for row in category_list:
             result = self.build_category_dict(row)
             result_list.append(result)
         if not result_list:
             return jsonify(Error="Categories Not Found"), 404
         else:
             return jsonify(Categories=result_list)
示例#11
0
 def insertTransaction(self, form):
     if len(form) != 9:
         return jsonify(Error="Malformed post Transaction"), 400
     else:
         s_id = form['s_id']
         b_id = form['b_id']
         ba_id = form['ba_id']
         c_id = form['c_id']
         r_id = form['r_id']
         t_qty = form['t_qty']
         t_total = form['t_total']
         t_donation = form['t_donation']
         t_reservation = form['t_reservation']
         if s_id and b_id and ba_id and c_id and r_id and t_qty and t_total and t_donation and t_reservation:
             dao = TransactionDAO()
             t_id = dao.insert(s_id, b_id, ba_id, c_id, r_id, t_qty,
                               t_total, t_donation, t_reservation)
             result = self.build_transaction_attributes(
                 t_id, s_id, b_id, ba_id, c_id, r_id, t_qty, t_total,
                 t_donation, t_reservation)
             return jsonify(Transaction=result), 201
         else:
             return jsonify(
                 Error="Unexpected attributes in post Transaction"), 400
 def insertTransaction(self, form):
     if form and len(form) == 6:
         s_id = form['s_id']
         c_id = form['c_id']
         r_id = form['r_id']
         t_price = form['t_price']
         t_date = form['t_date']
         t_qty = form['t_qty']
         if s_id and c_id and r_id and t_price and t_date and t_qty:
             dao = TransactionDAO()
             t_id = dao.insert(s_id, c_id, r_id, t_price, t_date, t_qty)
             result = {}
             result["t_id"] = t_id
             result["s_id"] = s_id
             result["c_id"] = c_id
             result["r_id"] = r_id
             result["t_price"] = t_price
             result["t_date"] = t_date
             result["t_qty"] = t_qty
             return jsonify(Transaction=result), 201
         else:
             return jsonify(Error="Malformed post request")
     else:
         return jsonify(Error="Malformed post request")
示例#13
0
    def searchTransaction(self, args):
        resourceid = args.get('resourceid')
        userid = args.get('userid')
        ccnumb = args.get('ccnumb')
        transactionid = args.get('transactionid')
        ccfirst = args.get('ccfirst')
        cclast = args.get('cclast')
        expdate = args.get('expdate')
        ccv = args.get('ccv')
        cctype = args.get('cctype')
        user_first_name = args.get('user_fisrt_name')
        user_last_name = args.get('user_last_name')
        user_email = args.get('user_email')
        collectioncenterid = ('collectioncenterid')
        resourcetype = ('resourcetype')
        buy_free = args.get('buy_free')
        market_price = args.get('market_price')
        qty = args.get('qty')

        dao = TransactionDAO()
        if resourceid:
            transaction_list = dao.getTransactionByResourceid(resourceid)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)
        elif userid:
            transaction_list = dao.getTransactionByUserid(userid)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif ccnumb:
            transaction_list = dao.getTransactionByCCNumb(ccnumb)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif ccfirst:
            transaction_list = dao.getTransactionByCCFirst(ccfirst)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif cclast:
            transaction_list = dao.getTransactionByCCLast(cclast)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif cctype:
            transaction_list = dao.getTransactionByCCType(cctype)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif resourcetype:
            transaction_list = dao.getTransactionByResourceType(resourcetype)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif user_first_name:
            transaction_list = dao.getTransactionByUserFirstName(
                user_first_name)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif user_last_name:
            transaction_list = dao.getTransactionByUserLastName(user_last_name)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif collectioncenterid:
            transaction_list = dao.getTransactionByCenter(collectioncenterid)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif buy_free:
            transaction_list = dao.getTransactionByBF(buy_free)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif market_price:
            transaction_list = dao.getTransactionByMarketPrice(market_price)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)

        elif user_email:
            transaction_list = dao.getTransactionByEmail(user_email)
            result_list = []
            for row in transaction_list:
                result = self.build_transactioninfo_dict(row)
                result_list.append(result)
                return jsonify(Transactions=result_list)
        else:
            return jsonify(Error="Malformed query string"), 400