Exemple #1
0
def getcollectionperformance(request):
    if request.method == 'GET':
        obj_col_per = mCore.login()
        obj_col_per.action = request.GET['action']
        obj_col_per.type = request.GET['type']
        obj_col_per.from_date = common.convertDate(request.GET['f_date'])
        obj_col_per.to_date = common.convertDate(request.GET['t_date'])
        obj_col_per.customer_gid = request.GET['cust_gid']
        obj_col_per.entity_gid = request.session['Entity_gid']
        out_message = obj_col_per.getcollectionperformance()
        jdata = out_message.to_json(orient='records')
        return JsonResponse(json.loads(jdata), safe=False)
Exemple #2
0
def snapsales(request):
    if request.method == 'GET':
        if (request.GET['todate'] != request.GET['fromdate']):
            ddd = (request.GET['todate'])
            today = datetime.datetime.strptime(ddd, "%d/%m/%Y")
            fdate = datetime.date(today.year, today.month, 1)
            # tdate = fdate + relativedelta(months=-11)
            # teee=relativedelta(dt1=fdate,dt2=tdate)
            temp = fdate
            header = []
            for x in range(12):
                data = {
                    'month': temp.month,
                    'year': temp.year,
                    'month_year': str(temp.month) + '-' + str(temp.year)
                }
                temp = temp + relativedelta(months=-1)
                header.append(data)
            # return JsonResponse(header, safe=False)
            mMaster.action = 'customerwisesale'
            mMaster.name = ''
            mMaster.jsonData = '{"customer_gid":' + request.GET[
                'cust_gid'] + ',"fromdate":"' + common.convertDate(
                    request.GET['fromdate']
                ) + '","todate":"' + common.convertDate(
                    request.GET['todate']) + '"}'
            mMaster.entity_gid = request.session['Entity_gid']
            df_custsales = mMaster.getcustomersales()
            df_product = (df_custsales[['customer_gid', 'customer_name']]) \
                .groupby(['customer_gid', 'customer_name']).size().reset_index()
        else:
            today = datetime.date.today()
            fdate = datetime.date(today.year, today.month, 1)
            # tdate = fdate + relativedelta(months=-11)
            # teee=relativedelta(dt1=fdate,dt2=tdate)
            temp = fdate
            header = []
            for x in range(12):
                data = {
                    'month': temp.month,
                    'year': temp.year,
                    'month_year': str(temp.month) + '-' + str(temp.year)
                }
                temp = temp + relativedelta(months=-1)
                header.append(data)
            # return JsonResponse(header, safe=False)
            mMaster.action = 'customerwisesale'
            mMaster.name = ''
            mMaster.jsonData = '{"customer_gid":' + request.GET[
                'cust_gid'] + ',"fromdate":"' + '' + '","todate":"' + '' + '"}'
            mMaster.entity_gid = request.session['Entity_gid']
            df_custsales = mMaster.getcustomersales()
            df_product = (df_custsales[['customer_gid', 'customer_name']]) \
                .groupby(['customer_gid', 'customer_name']).size().reset_index()
        sales_details = []
        for x, item in df_product.iterrows():
            details = {
                'customer_gid': item['customer_gid'],
                'customer_name': item['customer_name']
            }
            for y in header:
                month_dtl = {}
                d = df_custsales[(df_custsales['sales_month'] == y['month'])
                                 & (df_custsales['sales_year'] == y['year']) &
                                 (df_custsales['customer_gid']
                                  == item['customer_gid'])]
                if d.empty:
                    month_dtl['sales_qty'] = ''
                    month_dtl['sales_amt_wgst'] = ''
                    details[y['month_year']] = month_dtl
                else:
                    month_dtl['sales_qty'] = d['sales_qty'].iloc[0]
                    month_dtl['sales_amt_wgst'] = d['sales_amt_wgst'].iloc[0]
                    details[y['month_year']] = month_dtl
            sales_details.append(details)
        datadetails = {
            'customer_name': df_custsales['customer_name'].iloc[0],
            'employee_name': df_custsales['employee_name'].iloc[0],
            'sales_details': sales_details,
            'headers': header
        }
        return JsonResponse(datadetails, safe=False)