def saveItem(valueCard, valueItem, price): tranId = 1 if len( ndb.dbTran) == 0 else ndb.dbTran[len(ndb.dbTran) - 1].tranId + 1 tranData = TranData(tranId, valueCard.cardId, valueCard.cardNo, valueCard.name, UtilGp.now(), valueItem.itemId, price) DbTranData.addToTran(tranData) valueCard.creditUsed += price tranRewardPoint = price // 100 * (1 if valueCard.cardType == 'Gold' else 2) valueCard.creditUsed += price valueCard.rewardPoint += tranRewardPoint DbCardData.updateCards(ndb.dbCard, valueCard) print() print("Reward Points earned for this transaction : %d" % (tranRewardPoint, )) print() UtilGp.printCaptionData( ('Credit Limit Used', 'Credit Limit Available', 'Total Reward Points'), (UtilGp.priceToStr(valueCard.creditUsed), UtilGp.priceToStr(valueCard.creditBal()), valueCard.rewardPoint), 25) print("Loading..DB.2.\r", end="") ndb.loadCard(False) ndb.loadTran(valueCard, False) print(" \n", end="") Shop.showFailure()
def showFailure(): ndb.IsLoggedIn = False ndb.logInCard = None choice = input("\n1-Exit App, 2-Main Menu\nYour Choice:") if not choice.isdigit(): return choice = int(choice) if not (choice == 2): return UtilGp.mainMenu()
def genCardNo(dbCard): noStart = 8000 noEnd = 9000 stepValue = 1 cardNo = UtilGp.randNo(noStart, noEnd, stepValue, True) while DbCardData.checkCardNoExist(cardNo, dbCard): cardNo = UtilGp.randNo(noStart, noEnd, stepValue, True) cardNo = str(cardNo) return cardNo
def show(): UtilGp.title('Main Menu') print("\n%s\n"%(UtilGp.centerText("SBI Credit Cards... Make Your Life Easy."),)) print("Loading...\r",end="") UtilGp.sleep(2) print("1. Apply for Credit Card") print("2. Shopping") print("3. My Trasactions") choice = int(input("Please Enter Your Choice:")) return choice
def showCatTot(): UtilGp.sleep(2) UtilGp.clear() UtilGp.title('Reports(%s)' % ('Total Amount Spent on a Category', )) for valueCat in ndb.dbCat: print("%d %s" % (valueCat.catId, valueCat.category)) choiceCatId = int(input("Enter Catgory ID\nYour Choice:")) isExist = False resCat = None for valueCat in ndb.dbCat: if valueCat.catId == choiceCatId: isExist = True resCat = valueCat break if isExist: dbTran = DbTranData.queryByCategory(ndb.dbTran, choiceCatId) amount = sum(list(map(lambda x: x.price, dbTran))) UtilGp.printCaptionData( ('Category', 'Total Amount Spent is'), (valueCat.category, 'Rs.%.2f' % (amount, )), 45) #print("Total Amount Spent for category %s is Rs.%f"%(valueCat.category,amount)) print("****End of Report****") print() Shop.showFailure() else: print("You Category Not Exist.") Shop.showFailure()
def showDateRange(): UtilGp.sleep(2) UtilGp.clear() UtilGp.title('Reports(%s)' % ('Transactions between two dates', )) fromDate = input("From Date(dd-MM-YYYY):") toDate = input("To Date (dd-MM-YYYY):") fromDate = UtilGp.strToDate(fromDate + ' 00:00:00') toDate = UtilGp.strToDate(toDate + ' 23:59:00') #print(fromDate,toDate) dbTran = DbTranData.queryByDateRange(ndb.dbTran, fromDate, toDate) DbTranData.printTran(dbTran) print("****End of Report****") print() from frmPageShop import Shop Shop.showFailure()
def showBySortedAmount(): UtilGp.sleep(2) UtilGp.clear() UtilGp.title('Reports(%s)' % ('All Transactions sorted on amount', )) dbTran = DbTranData.queryAll(ndb.dbTran) dbTran.sort(key=lambda x: x.price) #print(dbTran) DbTranData.printTran(dbTran) print("****End of Report****") print() from frmPageShop import Shop Shop.showFailure()
def showAmountRange(): UtilGp.sleep(2) UtilGp.clear() UtilGp.title('Reports(%s)' % ('Transactions within amount range', )) fromAmount = float(input("From Amount:")) toAmount = float(input("To Amount:")) #print(fromDate,toDate) dbTran = DbTranData.queryByAmount(ndb.dbTran, fromAmount, toAmount) DbTranData.printTran(dbTran) print("****End of Report****") print() Shop.showFailure()
def printTran(dbTran): from UtilGp import UtilGp print() UtilGp.linePrint('*') print('%-12s%-14s %-16s%-20s%14s' % ('Date', 'Category', 'Sub Category', 'Item', 'Amount')) UtilGp.linePrint('*') print() for valueTran in dbTran: print('%-12s%-14s %-16s%-20s%14s ' % (UtilGp.dateToStr(valueTran.tranDate), valueTran.Category(), valueTran.SubCategory(), valueTran.ItemName(), 'Rs.%7.2f' % (valueTran.price, ))) if len(dbTran) == 0: print("**No Data Found**") print() UtilGp.linePrint('*') print()
def savingItem(resItem): #amount validations against credit balance #confirming pin #success message res = UtilGp.parseItemMsg(resItem, ndb.logInCard.passCode, ndb.logInCard.creditBal()) #end if res[0] == False: if res[1] == 1: print( "No sufficient credit balance.\nYour transaction is cancelled.\n" ) else: print( "Incorrect PIN.\nFor security reason Your transaction is cancelled.\n" ) Shop.showFailure() else: #print(ndb.logInCard,resItem,res[4]) Shop.saveItem(ndb.logInCard, resItem, res[4])
def reportMenu(): UtilGp.sleep(2) UtilGp.clear() UtilGp.title('Reports') print("1-All transactions done between two dates") print("2-All transactions that fall within a specified amount range") print("3-All transactions done on a category") print("4-Total amount spent on a category") print("5-Transactions sorted based on amount") choice = int(input("Your Choice:")) if choice == 1: Report.showDateRange() elif choice == 2: Report.showAmountRange() elif choice == 3: Report.showByCat() elif choice == 4: Report.showCatTot() elif choice == 5: Report.showBySortedAmount()
def showByCat(): UtilGp.sleep(2) UtilGp.clear() UtilGp.title('Reports(%s)' % ('Transactions of a Category', )) for valueCat in ndb.dbCat: print("%d %s" % (valueCat.catId, valueCat.category)) choiceCatId = int(input("Enter Catgory ID\nYour Choice:")) isExist = False resCat = None for valueCat in ndb.dbCat: if valueCat.catId == choiceCatId: isExist = True resCat = valueCat break if isExist: dbTran = DbTranData.queryByCategory(ndb.dbTran, choiceCatId) DbTranData.printTran(dbTran) print("****End of Report****") print() Shop.showFailure() else: print("You Category Not Exist.") Shop.showFailure()
from UtilGp import UtilGp UtilGp.startApp()
def showCat(): UtilGp.sleep(2) UtilGp.clear() UtilGp.title('Shopping') UtilGp.creditLine() print("\n %-10s %-16s" % ('ID', 'Category')) UtilGp.linePrint('-', 42) for valueCat in ndb.dbCat: print(" %-10d %-16s" % (valueCat.catId, valueCat.category)) UtilGp.linePrint('-', 42) choiceCatId = int(input("Enter Catgory ID\nYour Choice:")) isExist = False resCat = None for valueCat in ndb.dbCat: if valueCat.catId == choiceCatId: isExist = True resCat = valueCat break if isExist: Shop.showSubCat(resCat) else: print("You Category Not Exist.") Shop.showFailure()
def show(): UtilGp.Login(Report.reportMenu, ndb.loadTranByItem, 'Reports (Login)')
def showSubCat(valueCat): UtilGp.sleep(2) UtilGp.clear() UtilGp.title('Shopping(%s)' % (valueCat.category, )) UtilGp.creditLine() subCat = list(filter(lambda x: x.catId == valueCat.catId, ndb.dbSubCat)) print("\n %-10s %-16s" % ('ID', 'Sub Category')) UtilGp.linePrint('-', 42) for valueSubCat in subCat: print(" %-10d %-16s" % (valueSubCat.subCatId, valueSubCat.subCategory)) UtilGp.linePrint('-', 42) choiceSubCatId = int(input("Enter Sub Category ID\nYour Choice:")) #print(choiceSubCatId) isExist = False resSubCat = None for valueSubCat in subCat: if valueSubCat.subCatId == choiceSubCatId: isExist = True resSubCat = valueSubCat break if isExist: Shop.showItem(resSubCat) else: print("You Sub Category Not Exist.") Shop.showFailure()
def showItem(valueSubCat): UtilGp.sleep(2) UtilGp.clear() UtilGp.title('Shopping(%s)' % (valueSubCat.subCategory, )) UtilGp.creditLine() its = list( filter(lambda x: x.itemId // 100 == valueSubCat.subCatId, ndb.dbItem)) if len(its) == 1: if its[0].itemType == 1: Shop.savingItem(its[0]) else: print("\n %-10s %-22s %12s" % ('ID', 'Item', 'Price') if valueSubCat.subCatId != 21 else "\n %-10s %-16s" % ('ID', 'Item')) UtilGp.linePrint('-', 48) for valueItem in its: print(" %-10d %-22s %12s" % (valueItem.itemId, valueItem.itemName, 'Rs.%7.2f' % (valueItem.price, )) if valueSubCat.subCatId != 21 else "%-10d %-16s" % (valueItem.itemId, valueItem.itemName)) UtilGp.linePrint('-', 48) choidItemId = int(input("Enter Item ID\nYour Choice:")) #print(choidItemId) isExist = False resItem = None for valueItem in its: if valueItem.itemId == choidItemId: isExist = True resItem = valueItem break if isExist: Shop.savingItem(resItem) else: print("Your Item Not Exist.") Shop.showFailure()
def show(): UtilGp.Login(Shop.showCat, ndb.loadTran, 'Shopping (Login)')
def show(): UtilGp.clear() UtilGp.title('Applying Card') print("Loading...\r",end="") UtilGp.sleep(2) name=input("%-30s:"%"Enter Name") mobileNo=input("%-30s:"%"Enter Mobile Number") if not UtilGp.isValidDigit(mobileNo): print("Invalid Mobile Number") Shop.showFailure() return dob=input("%s\n%-30s:"%("Enter Date of Birth","(DD-MM-YYYY)")) if not UtilGp.isValidDate(dob): print("Invalid Date Format") Shop.showFailure() return dob = dob + ' 00:00:00' dobDate = UtilGp.strToDate(dob) if UtilGp.age(dobDate)<18: print("Minimum age to apply should be 18 years") Shop.showFailure() return netSalary=input("%-30s:"%"Enter Net Annual Salary") if not UtilGp.isValidDigit(netSalary,False): print("Invalid Salary Input") Shop.showFailure() return netSalary =float(netSalary) if netSalary < 300000: print("Minimum Salary to apply for Credit Card is Rs.300000.00") Shop.showFailure() return adharNo = input("%-30s:" % "ADHAAR Number") if not UtilGp.isValidDigit(adharNo,True,12): print("Invalid ADHAAR number") Shop.showFailure() return adharCount = DbCardData.countCardByAdhaar(ndb.dbCard,adharNo) if adharCount>0: print("Only one credit card per user is allowed") Shop.showFailure() return card = CardData(name,mobileNo,dobDate,netSalary,adharNo) card.preCardRegister() passCode=input("%-30s:" % "Select Your PIN (4-Digit)") if not UtilGp.isValidDigit(passCode,True,4): print("Invalid PIN format") Shop.showFailure() return card.passCode = passCode DbCardData.addToCard(card) print();print("Congratulation!\nYour SBI Credit Card is Approved.");print(); UtilGp.printCaptionData(('Card No', 'Credit Limit', 'Card Type'), (card.cardNo, UtilGp.priceToStr(card.creditLimit), card.cardType), 20) Shop.showFailure()