Exemplo n.º 1
0
    def PostContext(self):
        tContext = {}
        tAgent = Agent()

        tUser = self.GetUser()
        tAgent = Agent.GetAgentByEmail(tUser.email())
        tSaveAgent = False
        tNewNick = self.request.get('nick')
        tSoundOpt = self.request.get('sound')

        if (tNewNick != None and len(tNewNick) > 0):
            tAgent.agentNickName = tNewNick
            tSaveAgent = True

        if (tSoundOpt != None and len(tSoundOpt) > 0):
            tSoundOpt = str(tSoundOpt)
            if (tSoundOpt == "true"):
                tAgent.agentSoundPreference = 'True'
                tSaveAgent = True
            elif (tSoundOpt == "false"):
                tAgent.agentSoundPreference = 'False'
                tSaveAgent = True

        if (tSaveAgent):
            tAgent.put()
        self.LOCATION = "/"
        self.REDIRECT = True
        return tContext
 def post(self):
     tAgentQuery = Agent().all()
     tAgentList = tAgentQuery.fetch(100)
     agent = Agent()
     
     for agent in tAgentList:
         agent.agentOnline = False
         agent.put()
     
     self.response.out.write("Success")
Exemplo n.º 3
0
 def PostContext(self):
     
     tUser = self.GetUser()
     tDonor = DonorRecord()
     
     tDonatorRsName = self.request.get('name')
     #logging.debug("Quantity Entered: " + str(self.request.get('quantity')))
     tDonatorAmount = int(self.request.get('quantity'))
     tDonatorNote = self.request.get('memo')
     tDonatorForumName = self.request.get('fname')
     tFormEmail = self.request.get('email')
     tAgentGold = self.request.get('agentgold')
     
     tDonor.donorAgent = tUser.email()
     tDonor.donorForumName = tDonatorForumName
     tDonor.donorMemo = tDonatorNote
     tDonor.donorRsName = tDonatorRsName
     tDonor.donorGoldAmount = int(tDonatorAmount)
     tDonor.put()
     
     tAgent = Agent()
     try:
         if (len(tFormEmail) > 0):
             tAgent = Agent().GetAgentByEmail(tFormEmail)
         else: 
             tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     except:
         tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     
     if (tAgent.agentGoldSupply == None):
         tAgent.agentGoldSupply = 0
         
     if (tDonatorAmount < 0):
         #logging.debug(str(tAgentGold))
         tDonatorAmount = tDonatorAmount / 1000000.0
         if (tAgentGold == 'on'):
             tCommission = tDonatorAmount * 0.65 * -1.0
         else:
             tAgent.agentGoldSupply += int(tDonatorAmount * 1000000.0)
             tCommission = tDonatorAmount * 0.05 * -1.0
         #logging.debug("Agent Commission: " + str(tDonatorAmount * -1.0))
         tAgent.agentCurrentCommission += tCommission
         tAgent.agentTotalCommission += tCommission
     else:
         tAgent.agentGoldSupply += tDonatorAmount
         
     tAgent.put()
     
     return {}
     
     
 
 
     
                 
Exemplo n.º 4
0
 def post(self):
     tAgent = Agent()
     tUser = users.get_current_user()
     if (tUser):
         tAgent = Agent().GetAgentByEmail(tUser.email())
         tAgent.put()
         #logging.debug("Action by Agent: " + tUser.email())
         if (tAgent.agentOnline == False):
             self.response.out.write("offline")
         else:
             self.response.out.write("online")
Exemplo n.º 5
0
 def PostContext(self):
     tContext = {}
     if (self.IsUserAdmin()):
         try:
             tAgentKey = self.request.get('custid')
             tAgent = Agent()
             tAgent = Agent().get(tAgentKey)
             tAgent.agentCurrentCommission = 0.0
             tAgent.put()
             self.response.out.write("Success")
         except:
             self.response.out.write("Error")
         tContext['nowrite'] = True
     return tContext
 def PostContext(self):
     tContext = {}
     if (self.IsUserAdmin()):
         try:
             tAgentKey = self.request.get('custid')
             tAgent = Agent()
             tAgent = Agent().get(tAgentKey)
             tAgent.agentCurrentCommission = 0.0
             tAgent.put()
             self.response.out.write("Success")
         except:
             self.response.out.write("Error")
         tContext['nowrite'] = True
     return tContext
     
Exemplo n.º 7
0
    def GetAssignedAgent(self, pOrder=None):
        tAgent = Agent()
        tPaypal = PaypalOrder()
        tAgents = []
        Switch = {}
        tOrder = Order()
        tOrder = pOrder

        #Need to implement these methods
        #Switch[(1,2)] = tPaypal.UseFullAndBackupAgents
        #Switch[(0,2)] = tPaypal.UseBackupAgent
        #Switch[(2,2)] = tPaypal.UseFullAgent
        Switch[(0, 0)] = tPaypal.AssignNoAgent
        Switch[(0, 1)] = tPaypal.UseBackupAgent
        Switch[(1, 0)] = tPaypal.UseFullAgent
        Switch[(1, 1)] = tPaypal.UseFullAndBackupAgents
        Switch[(2, 0)] = tPaypal.UseFullAgent
        Switch[(2, 1)] = tPaypal.UseFullAndBackupAgents
        Switch[(3, 0)] = tPaypal.UseFullAgent
        Switch[(3, 1)] = tPaypal.UseFullAgent

        #Based on the raw online numbers of each group
        tCurrentState = (tPaypal.GetNumberofOnlineFullAgents(),
                         tPaypal.GetNumberofOnlineBackupAgents())
        #logging.debug("Current State" + str(tCurrentState))

        #The end agent will be handled in each function
        tAgent = Switch[tCurrentState]()
        if (tOrder != None):
            try:
                #logging.debug("Agent Current Total: " + str(tAgent.agentCurrentOrderTotal))
                #logging.debug("Order Quantity: " + str(tOrder.orderQuantity))
                tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + int(
                    tOrder.orderQuantity)
                #logging.debug("New Agent Current Total: " + str(tAgent.agentCurrentOrderTotal))
                tAgent.agentNotify = True
                tAgent.put()
                #logging.debug("GetAssignedAgent returning agent: " + str(tAgent.agentId))
                return tAgent.agentId
            except:
                #logging.debug("Hit an error")
                return "No Agent Online"
        else:
            try:
                return str(tAgent.agentId)
            except:
                return "No Agent Online"
 def GetAssignedAgent(self, pOrder = None):
     tAgent = Agent()
     tAssignment = DeliveryAssignment()
     tAgents = []
     Switch = {}
     tOrder = PaOrder()
     tOrder = pOrder
     
     #Need to implement these methods
     #Switch[(1,2)] = tPaypal.UseFullAndBackupAgents
     #Switch[(0,2)] = tPaypal.UseBackupAgent
     #Switch[(2,2)] = tPaypal.UseFullAgent
     Switch[(0,0)] = tAssignment.AssignNoAgent
     Switch[(0,1)] = tAssignment.UseBackupAgent
     Switch[(1,0)] = tAssignment.UseFullAgent
     Switch[(1,1)] = tAssignment.UseFullAndBackupAgents
     Switch[(2,0)] = tAssignment.UseFullAgent
     Switch[(2,1)] = tAssignment.UseFullAndBackupAgents
     Switch[(3,0)] = tAssignment.UseFullAgent
     Switch[(3,1)] = tAssignment.UseFullAgent
     
     
     #Based on the raw online numbers of each group
     tCurrentState = (tAssignment.GetNumberofOnlineFullAgents(), tAssignment.GetNumberofOnlineBackupAgents())
     #logging.debug("Current State" + str(tCurrentState))
     
     #The end agent will be handled in each function
     tAgent = Switch[tCurrentState]()
     if (tOrder != None):
         try:
             #logging.debug("Agent Current Total: " + str(tAgent.agentCurrentOrderTotal))
             #logging.debug("Order Quantity: " + str(tOrder.paAmountInt))
             tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + 1
             #logging.debug("New Agent Current Total: " + str(tAgent.agentCurrentOrderTotal))
             tAgent.agentNotify = True
             tAgent.put()
             #logging.debug("GetAssignedAgent returning agent: " + str(tAgent.agentId))
             return tAgent
         except:
             #logging.debug("Hit an error")
             return "No Agent Online"
     else:
         try:
             return tAgent
         except:
             return "No Agent Online"
Exemplo n.º 9
0
 def post(self):
     tUser = users.get_current_user()
     tAgent = Agent().GetAgentByEmail(tUser.email())
     tStatus = tAgent.agentOnline
     
     if (tStatus == False):
         tAgent.agentOnline = True
         tAgent.agentCurrentOrderTotal = 100
         tReturn = "You're Online!"
     else:
         tAgent.agentOnline = False
         tReturn = "You're Offline!"
         
     tAgent.put()
     
     self.response.out.write(tReturn)
     exit
 def get(self):
     tAgent = Agent()
     tUser = users.get_current_user()
     if (tUser):
         tAgent = Agent().GetAgentByEmail(tUser.email())
         if (tAgent.agentOnline == True):
             if (tAgent.agentNotify == True):
                 tAgent.agentNotify = False
                 tAgent.put()
                 self.response.out.write("1")
             elif (tAgent.agentNotify == False):
                 self.response.out.write("0")
             else:
                 self.response.out.write("0")
                 tAgent.agentNotify = False
                 tAgent.put()
         else:
             self.response.out.write("2")
Exemplo n.º 11
0
    def get(self):
        tAgent = Agent()
        tAgentsOnline = []
        
        tCurrentTime = datetime.datetime.now()
        tIncrement = datetime.timedelta(minutes = -30)
        tTime = tIncrement + tCurrentTime
        
        tAgentQuery = Agent().all()
        tAgentQuery.filter("agentOnline", True)
        tAgentQuery.filter("agentLastActive <", tTime)
        
        tAgentsOnline = tAgentQuery.fetch(10)

        if (len(tAgentsOnline) > 0):
            for tAgent in tAgentsOnline:
                tAgent.agentOnline = False
                tAgent.put()
 def get(self):
     tAgent = Agent()
     tUser = users.get_current_user()
     if (tUser):
         tAgent = Agent().GetAgentByEmail(tUser.email())
         if(tAgent.agentOnline == True):
             if (tAgent.agentNotify == True):
                 tAgent.agentNotify = False
                 tAgent.put()
                 self.response.out.write("1")
             elif (tAgent.agentNotify == False):
                 self.response.out.write("0")
             else:
                 self.response.out.write("0")
                 tAgent.agentNotify = False
                 tAgent.put()
         else:
             self.response.out.write("2")
             
Exemplo n.º 13
0
    def post(self):
        tOrderKey = self.request.get('orderid')

        #logging.debug("tOrderKey: " + tOrderKey)

        tPaOrder = PaOrder()
        tPaOrder = PaOrder.get(tOrderKey)

        tUser = users.get_current_user()
        tAgent = Agent().GetAgentByEmail(str(tUser.email()))

        if (tPaOrder.paOrderDeliver == False and tPaOrder.paOrderLock == False
                and tAgent.agentIsEnabled == True):
            tGoldAmount = tPaOrder.paAmountInt

            tGoldAmountLong = tGoldAmount
            tGoldAmount = tGoldAmount / 1000000

            if (tAgent.agentGoldSupply == None):
                tAgent.agentGoldSupply = 0

            tCommission = tGoldAmount * 0.05 + 0.50

            tAgent.agentGoldSupply = int(
                tAgent.agentGoldSupply) - int(tGoldAmountLong)
            tAgent.agentCurrentCommission = tAgent.agentCurrentCommission + tCommission
            tAgent.agentTotalCommission = tAgent.agentTotalCommission + tCommission

            tAgentOrders = tAgent.agentOrders  #Add order to agent pa orders
            tAgentOrders.append(tOrderKey)
            tAgent.agentOrders = tAgentOrders

            tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + 1

            tAgentKey = tAgent.put()

            tPaOrder.paDeliveryAgent = str(tAgent.agentId)
            tPaOrder.paDeliveryAgentNick = tAgent.agentNickName
            tPaOrder.paOrderDeliver = True
            tPaOrder.paOrderLock = True
            tKey = tPaOrder.put()

            #logging.debug("Delivery by Agent: " + str(tAgentKey))
            #logging.debug("Delivery of Order: " + str(tKey))

            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Delivered")
        else:
            #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Not Deliverable")
Exemplo n.º 14
0
 def post(self):
     tOrderKey = self.request.get('orderid')
     
     #logging.debug("tOrderKey: " + tOrderKey)
     
     tPaOrder = PaOrder()
     tPaOrder = PaOrder.get(tOrderKey)
     
     tUser = users.get_current_user()
     tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     
     if (tPaOrder.paOrderDeliver == False and tPaOrder.paOrderLock == False and tAgent.agentIsEnabled == True):
         tGoldAmount = tPaOrder.paAmountInt
         
         tGoldAmountLong = tGoldAmount
         tGoldAmount = tGoldAmount / 1000000
         
         if (tAgent.agentGoldSupply == None):
             tAgent.agentGoldSupply = 0
         
         tCommission = tGoldAmount * 0.05 + 0.50
         
         tAgent.agentGoldSupply = int(tAgent.agentGoldSupply) - int(tGoldAmountLong)
         tAgent.agentCurrentCommission = tAgent.agentCurrentCommission + tCommission
         tAgent.agentTotalCommission = tAgent.agentTotalCommission + tCommission
         
         tAgentOrders = tAgent.agentOrders #Add order to agent pa orders
         tAgentOrders.append(tOrderKey)
         tAgent.agentOrders = tAgentOrders           
         
         tAgent.agentCurrentOrderTotal = tAgent.agentCurrentOrderTotal + 1
         
         tAgentKey = tAgent.put()
         
         tPaOrder.paDeliveryAgent = str(tAgent.agentId)
         tPaOrder.paDeliveryAgentNick = tAgent.agentNickName
         tPaOrder.paOrderDeliver = True
         tPaOrder.paOrderLock = True
         tKey = tPaOrder.put()
         
         #logging.debug("Delivery by Agent: " + str(tAgentKey))
         #logging.debug("Delivery of Order: " + str(tKey))
         
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Delivered")
     else:
         #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Not Deliverable")    
Exemplo n.º 15
0
    def post(self):
        tOrderKey = self.request.get('orderid')
        tAgentGold = self.request.get('agentgold')

        #logging.debug("tOrderKey: " + tOrderKey)
        #logging.debug("tAgentGold: " + tAgentGold)
        tOrder = Order()
        tOrder = Order.get(tOrderKey)
        tUser = users.get_current_user()
        tAgent = Agent().GetAgentByEmail(str(tUser.email()))

        if (tOrder.orderDeliver == "" or tOrder.orderDeliver == 'False'
                and tOrder.orderLocked != 'True'
                and tAgent.agentIsEnabled == True):

            tGoldAmount = tOrder.orderQuantity
            tPromoCode = ""
            tPromoCode = tOrder.orderPromotionalCode
            tPromo = Promo()
            tPromoCode = tPromoCode.lower()
            tReferCode = tOrder.orderReferralCode
            tCustomerLookup = CustomerHandler()
            tCustomer = Customer()

            tCustomer = Customer().get(str(tOrder.orderCustomer))
            # Promo codes get unlimited uses per customer
            # tUsedBonus = Order.GetCustomerPromoCodes(tCustomer.customerPaypalId)
            # tUsedBonus = tCustomer.customerUsedBonus
            # logging.debug("Customer used bonuses: " + str(tUsedBonus))
            # logging.debug("Order Promo Code: " + str(tPromoCode))
            tUsedBonus = []

            try:
                tPromo = Promo.GetPromoByCode(tPromoCode)
                # logging.debug(str(tPromo.promoGoldAmount))
                # logging.debug(str(tPromo.promoPercentage))
                # logging.debug(str(tPromo.promoIsActive))

                if ((tPromo.promoIsActive)
                        and (tPromo.promoUses <= tPromo.promoLimit)):
                    if (tPromo.promoLimit != 0):
                        tPromo.promoUses = tPromo.promoUses + 1

                    if ((tPromoCode in tUsedBonus) == True):
                        tPercentBonus = 0.0
                    else:
                        tPercentBonus = float(
                            tGoldAmount) * tPromo.promoPercentage
                        #tUsedBonus.append(tPromoCode)

                    tGoldAmount = tGoldAmount + tPercentBonus
                    tGoldAmount = tGoldAmount + tPromo.promoGoldAmount
                    tTotalBonusFloat = tPercentBonus + tPromo.promoGoldAmount
                    tOrder.orderBonusQuantity = int(tTotalBonusFloat)
            except:
                tOrder.orderBonusQuantity = 0

            tGoldAmountLong = tGoldAmount
            tGoldAmount = tGoldAmount / 1000000

            tOrderValue = float(tOrder.orderCost)

            #if(tOrder.orderIsGenerated == True):
            #tGoldAmountLong = 0
            #tGoldAmount = 0

            tStockManager = StockManager()
            tStockManager.LoadAccounts()
            tStockManager.PlaceOrder(tGoldAmountLong * -1,
                                     tOrder.orderGoldType)

            #if tOrder.orderGoldType == '07':
            #tStockAccountManager.Set07Stock(int(tGoldAmountLong * -1))
            #else:
            #tStockAccountManager.SetEOCStock(int(tGoldAmountLong * -1))

            tCommission = float(tOrderValue) * 0.05 + 0.50

            if tCommission >= 10.0:
                tCommission = 10.0

            tAgent.agentCurrentCommission = float(
                tAgent.agentCurrentCommission + tCommission)
            tAgent.agentTotalCommission = float(tAgent.agentTotalCommission +
                                                tCommission)

            tAgentOrders = tAgent.agentOrders
            tAgentOrders.append(tOrderKey)
            tAgent.agentOrders = tAgentOrders
            tAgentKey = tAgent.put()
            tOrder.orderDeliveryAgent = str(tAgent.agentId)
            tOrder.orderAgent = str(tAgentKey)
            tOrder.orderDeliver = 'True'
            tKey = tOrder.put()

            #logging.debug("Delivery by Agent: " + str(tAgentKey))
            #logging.debug("Delivery of Order: " + str(tKey))

            #taskqueue.add(url='/calcreferral', countdown = 1, params={'key' : str(tKey) } )

            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Delivered")
        else:
            #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
            self.response.headers[
                'Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
            self.response.headers['Content-Type'] = 'Content-Type: plain/text'
            self.response.out.write("Order Not Deliverable")
Exemplo n.º 16
0
    def GetContext(self):
        tContext = {}
        tAgent = Agent()
        tAgentHandler = AgentHandler()
        tOrders = []
        tOrder = Order()
        tUser = self.USER

        tAgentQuery = Agent().all()
        tAgentQuery.filter('agentOnline', True)
        tAgents = tAgentQuery.fetch(100)
        if (len(tAgents) > 0):
            tContext['agentnum'] = len(tAgents)
            tContext['agents'] = tAgents
        try:
            tAgent = Agent().GetAgentByEmail(str(tUser.email()))
        except:
            pass
        if (tAgent.agentId == 'No Agent'):
            tAgent.agentCurrentCommission = 0.0
            tAgent.agentTotalCommission = 0.0
            tAgent.agentOrders = []
            tAgent.agentId = str(tUser.email())
            tAgent.agentGoldSupply = 0
            tAgent.agentOnline = False
            tAgent.put()

        if (tAgent.agentGoldSupply == None):
            tAgent.agentGoldSupply = 0

        tOrderQuery = PaOrder.all()
        tOrderQuery.filter("paDeliveryAgent", tAgent.agentId)
        tOrderQuery.order("-paDateDelivered")
        tOrdersRaw = tOrderQuery.fetch(50)

        tAgentDonorsQuery = DonorRecord.all()
        tAgentDonorsQuery.filter('donorAgent', tAgent.agentId)
        tAgentDonorsQuery.order('-donorDate')
        tAgentDonations = tAgentDonorsQuery.fetch(20)

        for o in tOrdersRaw:
            tOrder = o
            if (tOrder != None):
                tOrders.append(tOrder)

        #tGoldSupply = tAgent.agentGoldSupply

        logging.debug('Original eoc ' + str(tAgent.agentGoldSupplyEoc))
        logging.debug('Original 07 ' + str(tAgent.agentGoldSupply07))

        tEocString = NumberToGp.ConvertIntToBet(tAgent.agentGoldSupplyEoc)
        t07String = NumberToGp.ConvertIntToBet(tAgent.agentGoldSupply07)

        logging.debug('Stringed version eoc ' + tEocString)
        logging.debug('Stringed version 07 ' + t07String)

        #tAgent.__setattr__('agentGoldSupplyEocString', tEocString)
        #tAgent.__setattr__('agentGoldSupply07String', t07String)

        tContext['agent'] = tAgent
        tContext['gpeocstring'] = str(tEocString)
        tContext['gp07string'] = str(t07String)
        #tContext['agentgold'] = locale.format("%d", int(tGoldSupply), grouping = True)
        tContext['orders'] = tOrders
        tContext['agentcomm'] = locale.format("%0.2f",
                                              tAgent.agentCurrentCommission,
                                              grouping=True)
        tContext['agenttotal'] = locale.format("%0.2f",
                                               tAgent.agentTotalCommission,
                                               grouping=True)
        tContext['donations'] = tAgentDonations
        return tContext
 def PostContext(self):
             
     tNewOrder = ManualPaOrder()
     tAgent = Agent()
     tPromo = Promo()
     
     tUserEmail = self.GetUser().email()
     
     tStockAccount = StockAccount()
     tStockManager = StockManager()
     tStockManager.LoadAccounts()
     
     tAgent = Agent().GetAgentByEmail(tUserEmail)
     logging.debug('Agent ' + str(tAgent.agentNickName))
             
     tPromoCode = self.request.get('promocode').lower().lstrip().rstrip()
     tPromoCode = tPromoCode.lower().lstrip().rstrip()
     
     tGoldType = str(self.request.get('type')).lower().lstrip().rstrip()
     tGoldAmountWeb = str(self.request.get('amount')).lower()
     tGoldAmountPretty = re.sub(r'[^0-9kmb]*','', tGoldAmountWeb)
     tGoldMatches = re.match(r'^[0-9]*(k|m|b{1})$', tGoldAmountPretty)
     if tGoldMatches is None:
         return {'error' : str(tGoldAmountWeb) + ' is an invalid gold amount'}
     
     tGoldValue = str(self.request.get('value')).lower()
     tGoldValue = float(re.sub(r'[^0-9\.*]*', '', tGoldValue))
     
     tPaId = self.request.get('paid').lower().lstrip().rstrip()
     
     if (tGoldType in ('eoc', '07')) is not True:
         return {'error' : str(tGoldType) + ' is an invalid gold type' }
             
     if not tGoldValue >= 0.0:
         return {'error' : str(tGoldValue) + ' is an invalid gold value'}
     
     tStringOffset = self.request.get('offset')
     if (len(tStringOffset) > 0):
         tOffset = int(tStringOffset)
     else:
         tOffset = 0        
             
     tNewOrder.orderOwner = tUserEmail
     
     tGoldAmount = NumberToGp.ConvertBetToInt(tGoldAmountPretty)
     
     tUsedBonus = []
     try:
         #logging.debug("Promo Code: " + str(tPromoCode))
         tPromo = Promo.GetPromoByCode(tPromoCode)
         #logging.debug("Promo: " + str(tPromo))
         #logging.debug("Gold Amount: " + str(tGoldAmount))
         #logging.debug("Promo is active: " + str(tPromo.promoIsActive))
         
         if ((tPromo.promoIsActive) and (tPromo.promoUses <= tPromo.promoLimit)):
             if (tPromo.promoLimit != 0):
                 tPromo.promoUses = tPromo.promoUses + 1
             
             if((tPromoCode in tUsedBonus) == True):
                 tPercentBonus = 0.0
             else:
                 tPercentBonus = tGoldAmount * tPromo.promoPercentage
                 #tUsedBonus.append(tPromoCode)
 
             tGoldAmount = tGoldAmount + tPercentBonus
             tGoldAmount = tGoldAmount + tPromo.promoGoldAmount
             tTotalBonusFloat = tPercentBonus + tPromo.promoGoldAmount
             #logging.debug("Bonus float: " + str(tTotalBonusFloat))
             tPromoGoldAmount = int(tTotalBonusFloat)
                 
             #logging.debug("Total Bonus Float " + str(tTotalBonusFloat))
             #logging.debug("Promo Gold Amount " + str(tPromo.promoGoldAmount))
             #logging.debug("Promo Percentage " + str(tPercentBonus))
     except:
         tPromoGoldAmount = 0        
     
     tOrderTotalAmount = int(tGoldAmount) + int(tPromoGoldAmount)
     #logging.debug('Order gold ' + str(tOrderTotalAmount))
     
     logging.debug("{}".format(tOrderTotalAmount))
     logging.debug("{}".format(tGoldType))
     tStockManager.PlaceOrder(tOrderTotalAmount * -1, tGoldType)
     
     #if tGoldType == '07':
         ##logging.debug('07 detected')
         #tStockManager.PlaceOrder(aGoldQua
         #tStockAccountManager.Set07Stock(int(tOrderTotalAmount * -1))
         ##tAgent.agentGoldSupply07 = int(tAgent.agentGoldSupply07) - tOrderTotalAmount
     #elif tGoldType == 'eoc':
         ##logging.debug('eoc detected')
         ##tStockAccountManager.SetEOCStock(int(tOrderTotalAmount * -1))
         ##tAgent.agentGoldSupplyEoc = int(tAgent.agentGoldSupplyEoc) - tOrderTotalAmount
         
     #logging.debug('Agent 07 ' + str(tAgent.agentGoldSupply07))
     #logging.debug('Agent eoc ' + str(tAgent.agentGoldSupplyEoc))        
         
     tCommission = float(tGoldValue) * 0.05 + 0.50
     
     if tCommission >= 10.0:
         tCommission = 10.0
     
     tNewOrder.orderCashValue = float(tGoldValue)
     tNewOrder.orderOwner = tUserEmail
     tNewOrder.orderGoldAmount = int(tGoldAmount)
     tNewOrder.orderGoldAmountPretty = tGoldAmountPretty
     tNewOrder.orderGoldType = tGoldType
     tNewOrder.orderPaId = tPaId
     tNewOrder.orderPromoCode = tPromoCode
     tNewOrder.orderPromoGoldAmount = tPromoGoldAmount
     tNewOrderGuid = tNewOrder.put()
     
     tAgent.agentCurrentCommission = float(tAgent.agentCurrentCommission + tCommission)
     tAgent.agentTotalCommission = float(tAgent.agentTotalCommission + tCommission)
     tAgent.agentManualPaOrders = tAgent.agentManualPaOrders + [str(tNewOrderGuid)]
     tAgent.put()
     
     if int(tOffset) > 0:
         self.LOCATION = '/palist?offset=' + str(tOffset)
     else:
         self.LOCATION = '/palist'
         
     self.REDIRECT = True
     return {} 
     
     
     
     
     
     
     
     
     
     
     
Exemplo n.º 18
0
 def post(self):
     tOrderKey = self.request.get('orderid')
     tAgentGold = self.request.get('agentgold')
     
     #logging.debug("tOrderKey: " + tOrderKey)
     #logging.debug("tAgentGold: " + tAgentGold)
     tOrder = Order()
     tOrder = Order.get(tOrderKey)
     tUser = users.get_current_user()
     tAgent = Agent().GetAgentByEmail(str(tUser.email()))
     
     if (tOrder.orderDeliver == "" or tOrder.orderDeliver == 'False' and tOrder.orderLocked != 'True' and tAgent.agentIsEnabled == True):
             
         tGoldAmount = tOrder.orderQuantity
         tPromoCode = ""
         tPromoCode = tOrder.orderPromotionalCode
         tPromo = Promo()
         tPromoCode = tPromoCode.lower()
         tReferCode = tOrder.orderReferralCode
         tCustomerLookup = CustomerHandler()
         tCustomer = Customer()
         
         tCustomer = Customer().get(str(tOrder.orderCustomer))
         # Promo codes get unlimited uses per customer
         # tUsedBonus = Order.GetCustomerPromoCodes(tCustomer.customerPaypalId)
         # tUsedBonus = tCustomer.customerUsedBonus
         # logging.debug("Customer used bonuses: " + str(tUsedBonus))
         # logging.debug("Order Promo Code: " + str(tPromoCode))
         tUsedBonus = [] 
         
         try:
             tPromo = Promo.GetPromoByCode(tPromoCode)
             # logging.debug(str(tPromo.promoGoldAmount))
             # logging.debug(str(tPromo.promoPercentage))
             # logging.debug(str(tPromo.promoIsActive))
             
             if ((tPromo.promoIsActive) and (tPromo.promoUses <= tPromo.promoLimit)):
                 if (tPromo.promoLimit != 0):
                     tPromo.promoUses = tPromo.promoUses + 1
                 
                 if((tPromoCode in tUsedBonus) == True):
                     tPercentBonus = 0.0
                 else:
                     tPercentBonus = float(tGoldAmount) * tPromo.promoPercentage
                     #tUsedBonus.append(tPromoCode)
                     
                 tGoldAmount = tGoldAmount + tPercentBonus
                 tGoldAmount = tGoldAmount + tPromo.promoGoldAmount
                 tTotalBonusFloat = tPercentBonus + tPromo.promoGoldAmount
                 tOrder.orderBonusQuantity = int(tTotalBonusFloat)     
         except:
             tOrder.orderBonusQuantity = 0
             
         tGoldAmountLong = tGoldAmount
         tGoldAmount = tGoldAmount / 1000000
         
         tOrderValue = float(tOrder.orderCost)
         
         #if(tOrder.orderIsGenerated == True):
             #tGoldAmountLong = 0
             #tGoldAmount = 0
         
             
         tStockManager = StockManager()
         tStockManager.LoadAccounts()            
         tStockManager.PlaceOrder(tGoldAmountLong * -1, tOrder.orderGoldType)            
                         
         #if tOrder.orderGoldType == '07':
             #tStockAccountManager.Set07Stock(int(tGoldAmountLong * -1))
         #else:
             #tStockAccountManager.SetEOCStock(int(tGoldAmountLong * -1))
                         
         tCommission = float(tOrderValue) * 0.05 + 0.50
         
         if tCommission >= 10.0:
             tCommission = 10.0                           
             
         tAgent.agentCurrentCommission = float(tAgent.agentCurrentCommission + tCommission)
         tAgent.agentTotalCommission = float(tAgent.agentTotalCommission + tCommission)                
         
         tAgentOrders = tAgent.agentOrders
         tAgentOrders.append(tOrderKey)
         tAgent.agentOrders = tAgentOrders
         tAgentKey = tAgent.put()
         tOrder.orderDeliveryAgent = str(tAgent.agentId)
         tOrder.orderAgent = str(tAgentKey)
         tOrder.orderDeliver = 'True'
         tKey = tOrder.put()
         
         #logging.debug("Delivery by Agent: " + str(tAgentKey))
         #logging.debug("Delivery of Order: " + str(tKey))
         
         #taskqueue.add(url='/calcreferral', countdown = 1, params={'key' : str(tKey) } )
         
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Delivered")
     else:
         #logging.debug('Attempted to Deliver ' + tOrderKey + " by Agent " + tAgent.agentId)
         self.response.headers['Cache-Control'] = 'Cache-Control: no-cache, must-revalidate'
         self.response.headers['Content-Type'] = 'Content-Type: plain/text'
         self.response.out.write("Order Not Deliverable")