def post(self, code): json_values = {} try: tran_code = self.request.get('tranCode') last_modified = self.request.get('lastModified') buy = Buy.query(Buy.tran_code == tran_code).get() data = buy data.agent_code = buy.agent_code data.tran_date = buy.tran_date data.qty = buy.qty data.unit_price = buy.unit_price data.sub_total = buy.sub_total data.comm_per = buy.comm_per data.comm_amt = buy.comm_amt data.amt = buy.amt data.payment_date = buy.payment_date data.payment_ref_no = buy.payment_ref_no data.payment_type = buy.payment_type data.tran_code = buy.tran_code data.void = True data.last_modified = last_modified data.put() json_values['returnStatus'] = True except Exception, ex: json_values['returnStatus'] = False json_values['returnMessage'] = str(ex)
def post(self): json_values = {} try: date_from = self.request.get('dateFrom') date_to = self.request.get("dateTo") current_agent = self.current_agent() agent_code = current_agent.code q = Buy.query() if date_from and len(date_from) > 0: date_from = DateTime.to_date(date_from) q = q.filter(Buy.tran_date >= date_from) if date_to and len(date_to) > 0: date_to = DateTime.to_date(date_to) q = q.filter(Buy.tran_date <= date_to) if (not date_from and date_to): q = q.filter(Buy.agent_code == agent_code) buys = q.fetch() # create json data = [] for buy in buys: data.append({ 'agentCode': buy.agent_code, 'tranCode': buy.tran_code, 'date': DateTime.to_date_string(buy.tran_date), 'qty': buy.qty, 'unitPrice': buy.unit_price, 'subTotal': buy.sub_total, 'commission': buy.comm_amt, 'amount': buy.amt, 'paymentDate': DateTime.to_date_string(buy.payment_date), 'refNo': buy.payment_ref_no, 'paymentType': buy.payment_type, }) json_values['returnStatus'] = True json_values['data'] = data except Exception, ex: json_values['returnStatus'] = False json_values['returnMessage'] = str(ex)
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() buy = Buy.query(Buy.tran_code == code).get() template_values = { 'title': 'Void Buy', 'current_agent': current_agent, 'buy': buy } template = JINJA_ENVIRONMENT.get_template('buy/void.html') self.response.write(template.render(template_values))
def get(self, tran_code): # validate agent is logined or not # if not redirect to login page if self.authenticate() == False: return current_agent = self.current_agent() buys = Buy.query(Buy.tran_code == tran_code).get() template_values = { 'title': 'Borneo Ixora Co', 'today': DateTime.to_date_string(DateTime.malaysia_today()), 'current_agent': current_agent, 'buys': buys } template = JINJA_ENVIRONMENT.get_template('buy/receipt.html') self.response.write(template.render(template_values))
def post(self): json_values = {} try: #get date_from = self.request.get('dateFrom') date_to = self.request.get('dateTo') agent_code = self.request.get('agentCode') q = Buy.query() if date_from and len(date_from) > 0: date_from = DateTime.to_date(date_from) q = q.filter(Buy.tran_date >= date_from) if date_to and len(date_to) > 0: date_to = DateTime.to_date(date_to) q = q.filter(Buy.tran_date <= date_to) if agent_code: q = q.filter(Buy.agent_code == agent_code) if (not date_from and date_to and agent_code): raise Exception('You must enter a Date or Agent Code.') buys = q.fetch() # create json data = [] for buy in buys: data.append({ 'agentCode': buy.agent_code, 'tranDate': DateTime.to_date_string(buy.tran_date), 'quantity': buy.qty, 'amt': buy.sub_total, }) json_values['returnStatus'] = True json_values['data'] = data except Exception, ex: json_values['returnStatus'] = False json_values['returnMessage'] = str(ex)
def get(self, agent_code): # validate admin is logined or not # if not redirect to login page if self.authenticate() == False: return current_user = self.current_user() buy = Buy.query(Buy.agent_code == agent_code).get() agent = Agent.query(Agent.code == agent_code).get() template_values = { 'title': 'Detail Buy List', 'today': DateTime.to_date_string(DateTime.malaysia_today()), 'current_user': current_user, 'buy': buy, 'agent': agent } template = JINJA_ENVIRONMENT.get_template('buy/detail.html') self.response.write(template.render(template_values))
def post(self, agent_code): json_values = {} try: #get agent_code = self.request.get('agentCode') buys = Buy.query(Buy.agent_code == agent_code).fetch() # create json data = [] for buy in buys: data.append({ 'date': DateTime.to_date_string(buy.tran_date), 'qty': buy.qty, 'unitPrice': buy.unit_price, 'subTotal': buy.sub_total, 'commission': buy.comm_amt, 'amount': buy.amt, 'paymentDate': DateTime.to_date_string(buy.payment_date), 'refNo': buy.payment_ref_no, 'paymentType': buy.payment_type, 'tranCode': buy.tran_code, }) json_values['returnStatus'] = True json_values['data'] = data except Exception, ex: json_values['returnStatus'] = False json_values['returnMessage'] = str(ex)
def fetch(self, tran_date, agent_code=None, tran_code=None): key = self.get_key(tran_date, agent_code, tran_code) return Buy.query(ancestor=key).fetch()
def get(self, tran_date, agent_code, tran_code): key = self.get_key(tran_date, agent_code, tran_code) return Buy.query(ancestor=key).get()
def __get(self, date_from, date_to, date_format='%Y%m%d'): # get buy q_buy = Buy.query() if date_from: q_buy = q_buy.filter(Buy.tran_date >= date_from) if date_to: q_buy = q_buy.filter(Buy.tran_date <= date_to) q_buy = q_buy.filter(Buy.void==False) buys = q_buy.order(Buy.tran_date).fetch() # get top_up q_top_up = TopUp.query() if date_from: q_top_up = q_top_up.filter(TopUp.tran_date >= date_from) if date_to: q_top_up = q_top_up.filter(TopUp.tran_date <= date_to) q_top_up = q_top_up.filter(TopUp.void==False) top_ups = q_top_up.order(TopUp.tran_date).fetch() # sum amt sale_list = [] sale_days = {} for buy in buys: key = "%s" % (buy.tran_date.strftime(date_format)) sale = None if sale_days.has_key(key): sale = sale_days[key] else: sale = SaleViewModel() sale.tran_date = buy.tran_date sale_days[key] = sale sale_list.append(sale) sale.buy_sub_total += buy.sub_total sale.buy_comm_amt += buy.comm_amt sale.buy_amt += buy.amt for top_up in top_ups: key = "%s" % (top_up.tran_date.strftime(date_format)) sale = None if sale_days.has_key(key): sale = sale_days[key] else: sale = SaleViewModel() sale.tran_date = top_up.tran_date sale_days[key] = sale sale_list.append(sale) sale.top_up_sub_total += top_up.sub_total sale.top_up_comm_amt += top_up.comm_amt sale.top_up_amt += top_up.amt # cal amt for sale in sale_list: sale.cal_sub_total() sale.cal_amt() return sale_list
def get(self, agent_code, tran_date): # get bf amt bal_amt = 0 bal_start_date = None agent_mv = AgentMovement.query( AgentMovement.movement_date <= tran_date - timedelta(days=1) ).order(-AgentMovement.movement_date).get() if agent_mv: bal_amt = agent_mv.bal_amt bal_start_date = agent_mv.movement_date + timedelta(days=1) # get trans trans = Tran.query( Tran.tran_date >= bal_start_date, Tran.agent_code==agent_code ).order(Tran.tran_date, Tran.seq).fetch() buys = Buy.query( Buy.tran_date >= bal_start_date, Buy.agent_code==agent_code, Buy.void==False, ).fetch() deposits = Deposit.query( Deposit.tran_date >= bal_start_date, Deposit.agent_code==agent_code, Deposit.void==False, ).fetch() registers = Register.query( Register.tran_date >= bal_start_date, Register.agent_code==agent_code, Register.void==False, ).fetch() top_ups = TopUp.query( TopUp.tran_date >= bal_start_date, TopUp.agent_code==agent_code, TopUp.void==False, ).fetch() # group tran by tran_code mix_tran_codes = {} for buy in buys: mix_tran_codes[buy.tran_code] = buy for deposit in deposits: mix_tran_codes[deposit.tran_code] = deposit for register in registers: mix_tran_codes[register.tran_code] = register for top_up in top_ups: mix_tran_codes[top_up.tran_code] = top_up # ppl records return_values = [] # bf tran_bf_vm = StatementViewModel() tran_bf_vm.tran_date = bal_start_date tran_bf_vm.description = "B/F" tran_bf_vm.bal_amt = bal_amt return_values.append(tran_bf_vm) for tran in trans: tran_vm = StatementViewModel() tran_vm.bf_amt = bal_amt tran_vm.tran_date = tran.tran_date tran_vm.tran_code = tran.tran_code tran_vm.tran_type = tran.tran_type tran_vm.agent_code = tran.agent_code if mix_tran_codes.has_key(tran.tran_code): mix_tran = mix_tran_codes[tran.tran_code] if tran.tran_type == Tran.TRAN_TYPE_BUY: tran_vm.description = 'Buy %s Tag(s)' % (mix_tran.qty) elif tran.tran_type == Tran.TRAN_TYPE_DEPOSIT: tran_vm.description = 'Deposit' tran_vm.db_amt = mix_tran.amt elif tran.tran_type == Tran.TRAN_TYPE_REGISTER: tran_vm.description = "Register Car Reg. No. '%s'" % (mix_tran.car_reg_no) elif tran.tran_type == Tran.TRAN_TYPE_TOP_UP: tran_vm.description = "Top Up Car Reg. No. '%s'" % (mix_tran.car_reg_no) tran_vm.cr_amt = mix_tran.amt tran_vm.cal_bal_amt() bal_amt = tran_vm.bal_amt return_values.append(tran_vm) return return_values
def __get(self, date_from, date_to, date_format='%Y%m%d'): # get buy q_buy = Buy.query() if date_from: q_buy = q_buy.filter(Buy.tran_date >= date_from) if date_to: q_buy = q_buy.filter(Buy.tran_date <= date_to) q_buy = q_buy.filter(Buy.void == False) buys = q_buy.order(Buy.tran_date).fetch() # get top_up q_top_up = TopUp.query() if date_from: q_top_up = q_top_up.filter(TopUp.tran_date >= date_from) if date_to: q_top_up = q_top_up.filter(TopUp.tran_date <= date_to) q_top_up = q_top_up.filter(TopUp.void == False) top_ups = q_top_up.order(TopUp.tran_date).fetch() # sum amt sale_list = [] sale_days = {} for buy in buys: key = "%s" % (buy.tran_date.strftime(date_format)) sale = None if sale_days.has_key(key): sale = sale_days[key] else: sale = SaleViewModel() sale.tran_date = buy.tran_date sale_days[key] = sale sale_list.append(sale) sale.buy_sub_total += buy.sub_total sale.buy_comm_amt += buy.comm_amt sale.buy_amt += buy.amt for top_up in top_ups: key = "%s" % (top_up.tran_date.strftime(date_format)) sale = None if sale_days.has_key(key): sale = sale_days[key] else: sale = SaleViewModel() sale.tran_date = top_up.tran_date sale_days[key] = sale sale_list.append(sale) sale.top_up_sub_total += top_up.sub_total sale.top_up_comm_amt += top_up.comm_amt sale.top_up_amt += top_up.amt # cal amt for sale in sale_list: sale.cal_sub_total() sale.cal_amt() return sale_list