Exemplo n.º 1
0
 def post(self):
     json_values = {}
     
     try:
         #get
         date_from = DateTime.to_date(self.request.get('dateFrom'))
         date_to = DateTime.to_date(self.request.get('dateTo'))
         attendant_code = self.request.get('attendantCode')
         
         charge_by_month = ChargeSummary()
         values = charge_by_month.get_by_month_and_attendant(date_from, date_to, attendant_code)
         
         data = []
         for value in values:
             data.append({
                          'tranDate': DateTime.to_date_string(value.tran_date),
                          'attendantCode': value.attendant_code,
                          'subTotal': value.sub_total,
                          'chargeComm': value.comm_amt,
                          'total': value.amt
                          })
             
         json_values['returnStatus'] = True
         json_values['data'] = data
     except Exception, ex:
         json_values['returnStatus'] = False
         json_values['returnMessage'] = str(ex)
Exemplo n.º 2
0
 def __get(self, date_from, date_to, date_format='%Y%m%d'):
     # get cost
     sale_app = SaleByDay()
     sales = sale_app.get(date_from, date_to)
     
     # get charge
     charge_app = ChargeSummary()
     charges = charge_app.get_by_day(date_from, date_to)
     
     # group
     profit_list = []
     profit_days = {}
     
     for sale in sales:
         key = "%s" % (sale.tran_date.strftime(date_format))
         
         profit = None
         if profit_days.has_key(key):
             profit = profit_days[key]
         else:
             profit = ProfitViewModel()
             profit.tran_date = sale.tran_date
             profit_days[key] = profit
             profit_list.append(profit)
             
         profit.top_up_comm_amt += sale.top_up_comm_amt
         
     for charge in charges:
         key = "%s" % (charge.tran_date.strftime(date_format))
         
         profit = None
         if profit_days.has_key(key):
             profit = profit_days[key]
         else:
             profit = ProfitViewModel()
             profit.tran_date = charge.tran_date
             profit_days[key] = profit
             profit_list.append(profit)
             
         profit.charge_sub_total += charge.sub_total
         profit.charge_comm_amt += charge.comm_amt
         
     # sort by date
     profit_list = sorted(profit_list, key=lambda profit: profit.tran_date)
     
     # cal amt
     for profit in profit_list:
         profit.cal_amt()
         
     return profit_list
Exemplo n.º 3
0
 def get_charge_summary_by_month(self):
     try:
         charge_app = ChargeSummary()
         values = charge_app.get_by_month(DateTime.malaysia_today(), None)
         
         self.response.write("<table border='1'>")
         for value in values:
             self.response.write("<tr>")
             self.response.write("<td>%s</td>" % DateTime.to_month_string(value.tran_date))
             self.response.write("<td>%s</td>" % value.sub_total)
             self.response.write("<td>%s</td>" % value.comm_amt)
             self.response.write("<td>%s</td>" % value.amt)
             self.response.write("</tr>")
         self.response.write("</table>")
         
         self.response.write("get_charge_summary_by_month OK.")
     except Exception, ex:
         self.response.write("get_charge_summary_by_month failed. %s" % str(ex))
Exemplo n.º 4
0
    def post(self):
        json_values = {}

        try:
            #get
            date_from = self.request.get('dateFrom')
            date_to = self.request.get('dateTo')
            attendant_code = self.request.get('attendantCode')

            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 (not date_from and date_to):
                raise Exception('You must enter a Date.')

            charge_by_day = ChargeSummary()
            values = charge_by_day.get_by_day_and_attendant(
                date_from, date_to, attendant_code)

            data = []
            for value in values:
                data.append({
                    'tranDate':
                    DateTime.to_date_string(value.tran_date),
                    'attendantCode':
                    value.attendant_code,
                    'subTotal':
                    value.sub_total,
                    'chargeComm':
                    value.comm_amt,
                    'total':
                    value.amt
                })

            json_values['returnStatus'] = True
            json_values['data'] = data
        except Exception, ex:
            json_values['returnStatus'] = False
            json_values['returnMessage'] = str(ex)
Exemplo n.º 5
0
    def get_charge_summary_by_month(self):
        try:
            charge_app = ChargeSummary()
            values = charge_app.get_by_month(DateTime.malaysia_today(), None)

            self.response.write("<table border='1'>")
            for value in values:
                self.response.write("<tr>")
                self.response.write("<td>%s</td>" %
                                    DateTime.to_month_string(value.tran_date))
                self.response.write("<td>%s</td>" % value.sub_total)
                self.response.write("<td>%s</td>" % value.comm_amt)
                self.response.write("<td>%s</td>" % value.amt)
                self.response.write("</tr>")
            self.response.write("</table>")

            self.response.write("get_charge_summary_by_month OK.")
        except Exception, ex:
            self.response.write("get_charge_summary_by_month failed. %s" %
                                str(ex))