def post(self, code): json_values = {} try: name = self.request.get('name') address = self.request.get('address') tel = self.request.get('tel') hp = self.request.get('hp') email = self.request.get('email') last_modified = self.request.get('lastModified') agent = Agent.query(Agent.code == code).get() vm = RegisterViewModel() vm.code = code vm.name = name vm.address = address vm.tel = tel vm.hp = hp vm.email = email vm.account_type = agent.account_type vm.active = True vm.last_modified = last_modified app_service = RegisterAppService() app_service.update(vm) json_values['returnStatus'] = True except Exception, ex: json_values['returnStatus'] = False json_values['returnMessage'] = str(ex)
def post(self): json_values = {} try: name = self.request.get('name') code = self.request.get("code") q = Agent.query() if name: q = q.filter(Agent.name==name) if code: q = q.filter(Agent.code==code) agents = q.fetch() # create json data = [] for agent in agents: data.append({ 'code':agent.code, 'name': agent.name, 'address': agent.address, 'tel': agent.tel, 'hp': agent.hp, 'email': agent.email, }) json_values['returnStatus'] = True json_values['data'] = data except Exception, ex: json_values['returnStatus'] = False json_values['returnMessage'] = str(ex)
def current_agent(self): if not hasattr(self, "_current_agent"): self._current_agent = None code = self.session.get("agent_code") if code: q = Agent.query(Agent.code == str(code)) obj = q.get() self._current_agent = obj return self._current_agent
def login(self, vm): try: q = Agent.query(ancestor=ndb.Key(Agent, vm.code)) q = q.filter(Agent.pwd==vm.pwd) obj = q.get() if obj is None: raise Exception('Invalid ID or Password.') except Exception as ex: audit_da = AgentAuditTrailDataAccess() audit_da.create(vm.code, 'Agent login', 'Fail. Error=%s' % str(ex)) raise ex audit_da = AgentAuditTrailDataAccess() audit_da.create(vm.code, 'Agent login', 'Ok.')
def get(self, code): # validate admin is logined or not # if not redirect to login page if self.authenticate() == False: return current_agent = self.current_agent() agent = Agent.query(Agent.code == code).get() template_values = { 'title': 'Update Profile', 'current_agent': current_agent, 'agent': agent } template = JINJA_ENVIRONMENT.get_template('account/update.html') self.response.write(template.render(template_values))
def get(self): # validate agent is logined or not # if not redirect to login page if self.authenticate() == False: return current_agent = self.current_agent() agents = Agent.query().fetch() template_values = { 'title': 'Statement', 'today': DateTime.to_date_string(DateTime.malaysia_today()), 'current_agent': current_agent, 'agents': agents } template = JINJA_ENVIRONMENT.get_template('statement/index.html') self.response.write(template.render(template_values))
def update_agent(self): try: data = Agent.query(ancestor=ndb.Key('Agent', '1')).get() vm = AgentViewModel() vm.code = '1' vm.name = '2' vm.account_type = 1 vm.comm_per = 5 vm.credit_limit = -100 vm.last_modified = data.last_modified app_service = AgentAppService() app_service.update(vm) self.response.write("update_agent OK.") except Exception, ex: self.response.write("update_agent failed. %s" % str(ex))
def get(self, code): # validate admin is logined or not # if not redirect to login page if self.authenticate() == False: return current_user = self.current_user() agent = Agent.query(Agent.code==code).get() template_values = { 'title': 'Update Agent', 'today': DateTime.to_date_string(DateTime.malaysia_today()), 'current_user': current_user, 'agent': agent } template = JINJA_ENVIRONMENT.get_template('agent/update.html') self.response.write(template.render(template_values))
def get(self, agent_code): # validate agent is logined or not # if not redirect to login page if self.authenticate() == False: return current_user = self.current_user() register = Register.query(Register.agent_code==agent_code).get() agent = Agent.query(Agent.code==agent_code).get() template_values = { 'title': 'Detail Register List', 'today': DateTime.to_date_string(DateTime.malaysia_today()), 'current_user': current_user, 'register': register, 'agent': agent } template = JINJA_ENVIRONMENT.get_template('register/detail.html') self.response.write(template.render(template_values))
def get(self, code): return Agent.query(ancestor=ndb.Key('Agent', code)).get()
def __create(self, vm): # validate id data_validate = self.get(vm.code) if data_validate != None: raise Exception('Agent ID already exist.') data = Agent(id=vm.code) data.code = vm.code data.name = vm.name data.pwd = vm.pwd data.account_type = vm.account_type data.address = vm.address data.tel = vm.tel data.hp = vm.hp data.email = vm.email data.comm_per = vm.comm_per data.credit_limit = vm.credit_limit data.bal_amt = vm.bal_amt data.active = vm.active data.last_modified = str(DateTime.malaysia_now()) data.put()
def __close_agent_movement(self, closing_date): # sum deposit by agent deposit_agents = self.__sum_agent_deposit(closing_date) # sum top_up by agent top_up_agents = self.__sum_agent_top_up(closing_date) # get bf amt mv_da = AgentMovementDataAccess() movement_date = closing_date + timedelta(days=-1) bfs = mv_da.fetch(movement_date) # group bf by agent code bf_agents = {} for bf in bfs: bf_obj = {} bf_obj['agent_code'] = bf.agent_code bf_obj['bal_amt'] = bf.bal_amt bf_agents[bf.agent_code] = bf_obj # get agents q_agent = Agent.query() agents = q_agent.fetch() # sum to balance bals = {} for agent in agents: bal_obj = None if bals.has_key(agent.code): bal_obj = bals[agent.code] else: bal_obj = AgentMovementViewModel() bal_obj.agent_code = agent.code bal_obj.movement_date = closing_date bals[agent.code] = bal_obj # bf amt if bf_agents.has_key(agent.code): bf_obj = bf_agents[agent.code] bal_obj.bf_amt = bf_obj['bal_amt'] # deposit amt if deposit_agents.has_key(agent.code): deposit_obj = deposit_agents[agent.code] bal_obj.deposit_amt = deposit_obj['amt'] # top up amt if top_up_agents.has_key(agent.code): top_up_obj = top_up_agents[agent.code] bal_obj.top_up_amt = top_up_obj['amt'] # cal bal amt for agent_code in bals: bal_obj = bals[agent_code] bal_obj.cal_bal_amt() # delete balance mv_da.delete(closing_date) # insert balance for agent_code in bals: bal_obj = bals[agent_code] mv_da.create(bal_obj)