def __get(self, date_from, date_to, date_format='%Y%m%d'):
        # get top up
        q = TopUp.query()

        if date_from:
            q = q.filter(TopUp.tran_date >= date_from)

        if date_to:
            q = q.filter(TopUp.tran_date <= date_to)

        q = q.filter(TopUp.void == False)
        top_ups = q.order(TopUp.tran_date).fetch()

        # sum amt
        top_up_list = []
        top_up_days = {}
        for top_up in top_ups:
            key = "%s" % (top_up.tran_date.strftime(date_format))

            top_up_day = None
            if top_up_days.has_key(key):
                top_up_day = top_up_days[key]
            else:
                top_up_day = TopUpSummaryViewModel()
                top_up_day.tran_date = top_up.tran_date
                top_up_days[key] = top_up_day
                top_up_list.append(top_up_day)

            top_up_day.sub_total += top_up.sub_total
            top_up_day.comm_amt += top_up.comm_amt
            top_up_day.amt += top_up.amt

        return top_up_list
 def __sum_car_top_up(self, closing_date):
     # get topup
     da = TopUpDataAccess()
     key = da.get_key(closing_date)
     
     q2 = TopUp.query(ancestor=key)
     q2 = q2.filter(TopUp.void==False)
     top_ups = q2.fetch()
     
     # sum by car
     top_up_cars = {}
     for top_up in top_ups:
         top_up_obj = None
         if top_up_cars.has_key(top_up.car_reg_no):
             top_up_obj = top_up_cars[top_up.car_reg_no]
         else:
             top_up_obj = {}
             top_up_obj['car_reg_no'] = top_up.car_reg_no
             top_up_obj['tran_date'] = top_up.tran_date
             top_up_obj['amt'] = 0
             top_up_cars[top_up.car_reg_no] = top_up_obj
             
         top_up_obj['amt'] += top_up.sub_total
         
     return top_up_cars
 def __get(self, date_from, date_to, date_format='%Y%m%d'):
     # get top up
     q = TopUp.query()
     
     if date_from:
         q = q.filter(TopUp.tran_date >= date_from)
         
     if date_to:
         q = q.filter(TopUp.tran_date <= date_to)
         
     q = q.filter(TopUp.void==False)
     top_ups = q.order(TopUp.tran_date).fetch()
     
     # sum amt
     top_up_list = []
     top_up_days = {}
     for top_up in top_ups:
         key = "%s" % (top_up.tran_date.strftime(date_format))
         
         top_up_day = None
         if top_up_days.has_key(key):
             top_up_day = top_up_days[key]
         else:
             top_up_day = TopUpSummaryViewModel()
             top_up_day.tran_date = top_up.tran_date
             top_up_days[key] = top_up_day
             top_up_list.append(top_up_day)
         
         top_up_day.sub_total += top_up.sub_total
         top_up_day.comm_amt += top_up.comm_amt
         top_up_day.amt += top_up.amt
     
     return top_up_list
Beispiel #4
0
    def post(self, agent_code):
        json_values = {}

        try:
            #get
            agent_code = self.request.get('agentCode')

            topups = TopUp.query(TopUp.agent_code == agent_code).fetch()

            data = []
            for topup in topups:
                data.append({
                    'carPlate':
                    topup.car_reg_no,
                    'tranDate':
                    DateTime.to_date_string(topup.tran_date),
                    'subTotal':
                    topup.sub_total,
                    'commission':
                    topup.comm_amt,
                    'amount':
                    topup.amt,
                    'tranCode':
                    topup.tran_code,
                })

            json_values['returnStatus'] = True
            json_values['data'] = data
        except Exception, ex:
            json_values['returnStatus'] = False
            json_values['returnMessage'] = str(ex)
 def __sum_agent_top_up(self, closing_date):
     # get topup
     da = TopUpDataAccess()
     key = da.get_key(closing_date)
     
     q2 = TopUp.query(ancestor=key)
     q2 = q2.filter(TopUp.void==False)
     top_ups = q2.fetch()
     
     # sum by agent
     top_up_agents = {}
     for top_up in top_ups:
         top_up_obj = None
         if top_up_agents.has_key(top_up.agent_code):
             top_up_obj = top_up_agents[top_up.agent_code]
         else:
             top_up_obj = {}
             top_up_obj['agent_code'] = top_up.agent_code
             top_up_obj['tran_date'] = top_up.tran_date
             top_up_obj['amt'] = 0
             top_up_agents[top_up.agent_code] = top_up_obj
             
         top_up_obj['amt'] += top_up.amt
         
     return top_up_agents
    def __sum_car_top_up(self, closing_date):
        # get topup
        da = TopUpDataAccess()
        key = da.get_key(closing_date)

        q2 = TopUp.query(ancestor=key)
        q2 = q2.filter(TopUp.void == False)
        top_ups = q2.fetch()

        # sum by car
        top_up_cars = {}
        for top_up in top_ups:
            top_up_obj = None
            if top_up_cars.has_key(top_up.car_reg_no):
                top_up_obj = top_up_cars[top_up.car_reg_no]
            else:
                top_up_obj = {}
                top_up_obj['car_reg_no'] = top_up.car_reg_no
                top_up_obj['tran_date'] = top_up.tran_date
                top_up_obj['amt'] = 0
                top_up_cars[top_up.car_reg_no] = top_up_obj

            top_up_obj['amt'] += top_up.sub_total

        return top_up_cars
    def __sum_agent_top_up(self, closing_date):
        # get topup
        da = TopUpDataAccess()
        key = da.get_key(closing_date)

        q2 = TopUp.query(ancestor=key)
        q2 = q2.filter(TopUp.void == False)
        top_ups = q2.fetch()

        # sum by agent
        top_up_agents = {}
        for top_up in top_ups:
            top_up_obj = None
            if top_up_agents.has_key(top_up.agent_code):
                top_up_obj = top_up_agents[top_up.agent_code]
            else:
                top_up_obj = {}
                top_up_obj['agent_code'] = top_up.agent_code
                top_up_obj['tran_date'] = top_up.tran_date
                top_up_obj['amt'] = 0
                top_up_agents[top_up.agent_code] = top_up_obj

            top_up_obj['amt'] += top_up.amt

        return top_up_agents
Beispiel #8
0
    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 = TopUp.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(TopUp.agent_code == agent_code)

            if (not date_from and date_to):
                raise Exception('You must enter a Date.')

            topups = q.fetch()

            data = []
            for topup in topups:
                data.append({
                    'tranCode':
                    topup.tran_code,
                    'carPlate':
                    topup.car_reg_no,
                    'tranDate':
                    DateTime.to_date_string(topup.tran_date),
                    'agentCode':
                    topup.agent_code,
                    'subTotal':
                    topup.sub_total,
                    'commission':
                    topup.comm_amt,
                    'amount':
                    topup.amt,
                })

            json_values['returnStatus'] = True
            json_values['data'] = data
        except Exception, ex:
            json_values['returnStatus'] = False
            json_values['returnMessage'] = str(ex)
Beispiel #9
0
    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()
            agent_code = current_agent.code

            q = TopUp.query()

            if date_from and len(date_from) > 0:
                date_from = DateTime.to_date(date_from)
                q = q.filter(TopUp.tran_date >= date_from)

            if date_to and len(date_to) > 0:
                date_to = DateTime.to_date(date_to)
                q = q.filter(TopUp.tran_date <= date_to)

            if carPlate:
                q = q.filter(TopUp.car_reg_no == carPlate)

            if (not date_from and date_to and carPlate):
                q = q.filter(TopUp.agent_code == agent_code)

            topUps = q.fetch()

            # create json
            data = []
            for topUp in topUps:
                data.append({
                    'agentCode': topUp.agent_code,
                    'tranCode': topUp.tran_code,
                    'carPlate': topUp.car_reg_no,
                    'date': DateTime.to_date_string(topUp.tran_date),
                    'subTotal': topUp.sub_total,
                    'commission': topUp.comm_amt,
                    'amount': topUp.amt,
                })

            json_values['returnStatus'] = True
            json_values['data'] = data
        except Exception, ex:
            json_values['returnStatus'] = False
            json_values['returnMessage'] = str(ex)
Beispiel #10
0
    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()
        topups = TopUp.query(TopUp.tran_code == tran_code).get()

        template_values = {
            'title': 'Borneo Ixora Co',
            'today': DateTime.to_date_string(DateTime.malaysia_today()),
            'current_agent': current_agent,
            'topups': topups
        }

        template = JINJA_ENVIRONMENT.get_template('topup/receipt.html')
        self.response.write(template.render(template_values))
Beispiel #11
0
    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()

        topup = TopUp.query(TopUp.agent_code == agent_code).get()
        agent = Agent.query(Agent.code == agent_code).get()

        template_values = {
            'title': 'Detail Top Up List',
            'today': DateTime.to_date_string(DateTime.malaysia_today()),
            'current_user': current_user,
            'topup': topup,
            'agent': agent
        }

        template = JINJA_ENVIRONMENT.get_template('topup/detail.html')
        self.response.write(template.render(template_values))
Beispiel #12
0
 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
Beispiel #13
0
    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
Beispiel #15
0
 def get(self, tran_date, agent_code, tran_code):
     key = self.get_key(tran_date, agent_code, tran_code)
     return TopUp.query(ancestor=key).get()
Beispiel #16
0
 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
Beispiel #17
0
 def fetch(self, tran_date, agent_code=None, tran_code=None):
     key = self.get_key(tran_date, agent_code, tran_code)
     return TopUp.query(ancestor=key).fetch()
Beispiel #18
0
    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)