def __sum_car_register(self, closing_date): # get register da = RegisterDataAccess() key = da.get_key(closing_date) q2 = Register.query(ancestor=key) q2 = q2.filter(Register.void==False) registers = q2.fetch() # sum by car register_cars = {} for register in registers: register_obj = None if register_cars.has_key(register.car_reg_no): register_obj = register_cars[register.car_reg_no] else: register_obj = {} register_obj['car_reg_no'] = register.car_reg_no register_obj['tran_date'] = register.tran_date register_obj['amt'] = 0 register_cars[register.car_reg_no] = register_obj register_obj['amt'] += register.sub_total return register_cars
def __sum_car_register(self, closing_date): # get register da = RegisterDataAccess() key = da.get_key(closing_date) q2 = Register.query(ancestor=key) q2 = q2.filter(Register.void == False) registers = q2.fetch() # sum by car register_cars = {} for register in registers: register_obj = None if register_cars.has_key(register.car_reg_no): register_obj = register_cars[register.car_reg_no] else: register_obj = {} register_obj['car_reg_no'] = register.car_reg_no register_obj['tran_date'] = register.tran_date register_obj['amt'] = 0 register_cars[register.car_reg_no] = register_obj register_obj['amt'] += register.sub_total return register_cars
def post(self, agent_code): json_values = {} try: #get agent_code = self.request.get('agentCode') registers = Register.query(Register.agent_code==agent_code).fetch() # create json data = [] for register in registers: data.append({ 'carPlate': register.car_reg_no, 'tranDate': DateTime.to_date_string(register.tran_date), 'ic': register.customer_ic, 'name': register.customer_name, 'address': register.customer_address, 'tel': register.customer_tel, 'hp': register.customer_hp, 'email': register.customer_email, 'tagNo': register.tag_code, 'tranCode': register.tran_code, }) json_values['returnStatus'] = True json_values['data'] = data except Exception, ex: json_values['returnStatus'] = False json_values['returnMessage'] = str(ex)
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 = Register.query() if date_from and len(date_from) > 0: date_from = DateTime.to_date(date_from) if date_to and len(date_to) > 0: date_to = DateTime.to_date(date_to) if agent_code: q = q.filter(Register.agent_code == agent_code) if (not date_from and date_to): raise Exception('You must enter a Date.') registers = q.fetch() # create json data = [] for register in registers: data.append({ 'tranCode': register.tran_code, 'carPlate': register.car_reg_no, 'tranDate': DateTime.to_date_string(register.tran_date), 'agentCode': register.agent_code, 'ic': register.customer_ic, 'name': register.customer_name, 'address': register.customer_address, 'tel': register.customer_tel, 'hp': register.customer_hp, 'email': register.customer_email, 'tagNo': register.tag_code, }) json_values['returnStatus'] = True json_values['data'] = data 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") carPlate = self.request.get('carPlate') current_agent = self.current_agent() code = current_agent.code q = Register.query() if date_from and len(date_from) > 0: date_from = DateTime.to_date(date_from) q = q.filter(Register.tran_date >= date_from) if date_to and len(date_to) > 0: date_to = DateTime.to_date(date_to) q = q.filter(Register.tran_date <= date_to) if carPlate: q = q.filter(Register.car_reg_no == carPlate) if (not date_from and date_to and carPlate): q = q.filter(Register.agent_code == code) registers = q.fetch() # create json data = [] for register in registers: data.append({ 'agentCode': register.agent_code, 'tranCode': register.tran_code, 'date': DateTime.to_date_string(register.tran_date), 'carPlate': register.car_reg_no, 'name': register.customer_name, 'ic': register.customer_ic, 'address': register.customer_address, 'tel': register.customer_tel, 'hp': register.customer_hp, 'email': register.customer_email, 'tagNo': register.tag_code }) json_values['returnStatus'] = True json_values['data'] = data except Exception, ex: json_values['returnStatus'] = False json_values['returnMessage'] = str(ex)
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() registers = Register.query(Register.tran_code == tran_code).get() template_values = { 'title': 'Borneo Ixora Co', 'today': DateTime.to_date_string(DateTime.malaysia_today()), 'current_agent': current_agent, 'registers': registers } template = JINJA_ENVIRONMENT.get_template('register/receipt.html') self.response.write(template.render(template_values))
def get(self, reg_no): # validate admin is logined or not # if not redirect to login page if self.authenticate() == False: return current_customer = self.current_customer() register = Register.query(Register.car_reg_no == reg_no).get() template_values = { 'title': 'Statement', 'today': DateTime.to_date_string(DateTime.malaysia_today()), 'current_customer': current_customer, 'register': register } template = JINJA_ENVIRONMENT.get_template('statement/index.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, tran_date, agent_code, tran_code): key = self.get_key(tran_date, agent_code, tran_code) return Register.query(ancestor=key).get()
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, car_reg_no, tran_date): # get bf amt bal_amt = 0 bal_start_date = None car_mv = CarMovement.query(CarMovement.movement_date <= tran_date - timedelta(days=1) ).order(-CarMovement.movement_date).get() if car_mv: bal_amt = car_mv.bal_amt bal_start_date = car_mv.movement_date + timedelta(days=1) # get trans trans = Tran.query( Tran.tran_date >= bal_start_date, Tran.car_reg_no==car_reg_no ).order(Tran.tran_date, Tran.seq).fetch() registers = Register.query( Register.tran_date >= bal_start_date, Register.car_reg_no==car_reg_no, Charge.void==False, ).fetch() top_ups = TopUp.query( TopUp.tran_date >= bal_start_date, TopUp.car_reg_no==car_reg_no, Charge.void==False, ).fetch() charges = Charge.query( Charge.tran_date >= bal_start_date, Charge.car_reg_no==car_reg_no, Charge.void==False, ).fetch() # group tran by tran_code mix_tran_codes = {} 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 for charge in charges: mix_tran_codes[charge.tran_code] = charge # 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.car_reg_no = tran.car_reg_no if mix_tran_codes.has_key(tran.tran_code): mix_tran = mix_tran_codes[tran.tran_code] if tran.tran_type == Tran.TRAN_TYPE_REGISTER: tran_vm.description = 'Register' tran_vm.db_amt = mix_tran.sub_total elif tran.tran_type == Tran.TRAN_TYPE_TOP_UP: tran_vm.description = 'Top Up' tran_vm.db_amt = mix_tran.sub_total elif tran.tran_type == Tran.TRAN_TYPE_CHARGE: tran_vm.description = 'Charge' tran_vm.cr_amt = mix_tran.sub_total tran_vm.cal_bal_amt() bal_amt = tran_vm.bal_amt return_values.append(tran_vm) return return_values
def fetch(self, tran_date, agent_code=None, tran_code=None): key = self.get_key(tran_date, agent_code, tran_code) return Register.query(ancestor=key).fetch()
def __create(self, vm): # save car car_vm = CarViewModel() car_vm.reg_no = vm.car_reg_no car_vm.customer_ic = vm.customer_ic car_vm.customer = vm.customer car_vm.bal_amt = vm.sub_total car_da = CarDataAccess() vm.car = car_da.save_register(car_vm) # save tag tag_vm = TagViewModel() tag_vm.code = vm.tag_code tag_vm.agent_code = vm.agent_code tag_vm.agent = vm.agent tag_vm.car_reg_no = vm.car_reg_no tag_vm.car = vm.car tag_da = TagDataAccess() vm.tag = tag_da.demo_save_register(tag_vm) # get master seq master_da = MasterDataAccess() master = master_da.get('Register') master.seq += 1 master.put() # insert register tran_code = Register.get_tran_code(master.seq) vm.tran_code = tran_code data = Register(parent=self.get_key(vm.tran_date, vm.agent_code), id=tran_code) data.tran_code = tran_code data.tran_type = vm.tran_type data.tran_date = vm.tran_date data.seq = master.seq data.agent_code = vm.agent_code data.agent = vm.agent.key data.remark = vm.remark data.car_reg_no = vm.car_reg_no data.car = vm.car.key data.customer_ic = vm.customer_ic data.customer_name = vm.customer_name data.customer_address = vm.customer_address data.customer_tel = vm.customer_tel data.customer_hp = vm.customer_hp data.customer_email = vm.customer_email data.customer = vm.customer.key data.tag_code = vm.tag_code data.tag = vm.tag.key data.sub_total = vm.sub_total data.created_by = vm.user_code data.created_date = DateTime.malaysia_now() data.modified_by = '' data.modified_date = None data.void_by = '' data.void_date = None data.void = False data.last_modified = str(data.created_date) data.put() # insert tran tran_obj = TranViewModel() tran_obj.tran_code = data.tran_code tran_obj.tran_date = data.tran_date tran_obj.tran_type = data.tran_type tran_obj.agent_code = data.agent_code tran_obj.car_reg_no = data.car_reg_no tran_da = TranDataAccess() tran_da.create(tran_obj)
def post(self, reg_no): json_values = {} try: reg_no = self.request.get('reg_no') cars = Car.query(Car.reg_no == reg_no).fetch() car = cars[0] today_date = DateTime.malaysia_today() trans = Tran.query(Tran.car_reg_no == reg_no, Tran.tran_date == today_date).order( Tran.seq).fetch() registers = Register.query( Register.car_reg_no == reg_no, Register.tran_date == today_date).fetch() topups = TopUp.query(TopUp.car_reg_no == reg_no, TopUp.tran_date == today_date).fetch() charges = Charge.query(Charge.car_reg_no == car.reg_no, Charge.tran_date == today_date).fetch() # group by tran_code register_tran_codes = {} for register in registers: register_tran_codes[register.tran_code] = register topup_tran_codes = {} for topup in topups: topup_tran_codes[topup.tran_code] = topup charge_tran_codes = {} for charge in charges: charge_tran_codes[charge.tran_code] = charge # create json data = [] bal_amt = 0 for tran in trans: if register_tran_codes.has_key(tran.tran_code): register = register_tran_codes[tran.tran_code] bal_amt += register.sub_total bal_amt = round(bal_amt, 2) data.append({ 'carRegNo': car.reg_no, 'date': DateTime.to_date_string(register.tran_date), 'description': register.tran_code, 'dbAmt': register.sub_total, 'crAmt': 0, 'balAmt': bal_amt }) elif topup_tran_codes.has_key(tran.tran_code): topup = topup_tran_codes[tran.tran_code] bal_amt += topup.sub_total bal_amt = round(bal_amt, 2) data.append({ 'carRegNo': car.reg_no, 'date': DateTime.to_date_string(topup.tran_date), 'description': topup.tran_code, 'dbAmt': topup.sub_total, 'crAmt': 0, 'balAmt': bal_amt }) elif charge_tran_codes.has_key(tran.tran_code): charge = charge_tran_codes[tran.tran_code] bal_amt -= charge.sub_total bal_amt = round(bal_amt, 2) data.append({ 'carRegNo': car.reg_no, 'date': DateTime.to_date_string(charge.tran_date), 'description': charge.tran_code, 'dbAmt': 0, 'crAmt': charge.sub_total, 'balAmt': bal_amt }) json_values['returnStatus'] = True json_values['data'] = data except Exception, ex: json_values['returnStatus'] = False json_values['returnMessage'] = str(ex)
def __create(self, vm): # save car car_vm = CarViewModel() car_vm.reg_no = vm.car_reg_no car_vm.customer_ic = vm.customer_ic car_vm.customer = vm.customer car_vm.bal_amt = vm.sub_total car_da = CarDataAccess() vm.car = car_da.save_register(car_vm) # save tag tag_vm = TagViewModel() tag_vm.code = vm.tag_code tag_vm.agent_code = vm.agent_code tag_vm.agent = vm.agent tag_vm.car_reg_no = vm.car_reg_no tag_vm.car = vm.car tag_da = TagDataAccess() vm.tag = tag_da.demo_save_register(tag_vm) # get master seq master_da = MasterDataAccess() master = master_da.get('Register') master.seq += 1 master.put() # insert register tran_code = Register.get_tran_code(master.seq) vm.tran_code = tran_code data = Register( parent=self.get_key(vm.tran_date, vm.agent_code), id=tran_code ) data.tran_code = tran_code data.tran_type = vm.tran_type data.tran_date = vm.tran_date data.seq = master.seq data.agent_code = vm.agent_code data.agent = vm.agent.key data.remark = vm.remark data.car_reg_no = vm.car_reg_no data.car = vm.car.key data.customer_ic = vm.customer_ic data.customer_name = vm.customer_name data.customer_address = vm.customer_address data.customer_tel = vm.customer_tel data.customer_hp = vm.customer_hp data.customer_email = vm.customer_email data.customer = vm.customer.key data.tag_code = vm.tag_code data.tag = vm.tag.key data.sub_total = vm.sub_total data.created_by = vm.user_code data.created_date = DateTime.malaysia_now() data.modified_by = '' data.modified_date = None data.void_by = '' data.void_date = None data.void = False data.last_modified = str(data.created_date) data.put() # insert tran tran_obj = TranViewModel() tran_obj.tran_code = data.tran_code tran_obj.tran_date = data.tran_date tran_obj.tran_type = data.tran_type tran_obj.agent_code = data.agent_code tran_obj.car_reg_no = data.car_reg_no tran_da = TranDataAccess() tran_da.create(tran_obj)