def retrieve(self, request, pk=None):
     queryset = Employee.objects.all()
     employee = get_object_or_404(queryset, pk=pk)
     serializer = EmployeeSerializer(employee, context={"request": request})
     return Response({
         "error": False,
         "message": "Single Data Fetch",
         "data": serializer.data
     })
 def list(self, request):
     employee = Employee.objects.all()
     serializer = EmployeeSerializer(employee,
                                     many=True,
                                     context={"request": request})
     response_dict = {
         "error": False,
         "message": "All Employee List Data",
         "data": serializer.data
     }
     return Response(response_dict)
Exemplo n.º 3
0
 def update(self,request,pk=None):
     queryset=Employee.objects.all()
     employee=get_object_or_404(queryset,pk=pk)
     serializer=EmployeeSerializer(employee,data=request.data,context={"request":request})
     serializer.is_valid()
     serializer.save()
     return Response({"error":False,"message":"Data Has Been Updated"})
Exemplo n.º 4
0
 def create(self,request):
     try:
         serializer=EmployeeSerializer(data=request.data,context={"request":request})
         serializer.is_valid(raise_exception=True)
         serializer.save()
         dict_response={"error":False,"message":"Employee Data Save Successfully"}
     except:
         dict_response={"error":True,"message":"Error During Saving Employee Data"}
     return Response(dict_response)
Exemplo n.º 5
0
 def create(self, request):
     try:
         serializer = EmployeeSerializer(data=request.data,
                                         context={"request": request})
         serializer.is_valid()
         serializer.save()
         response_dict = {
             "error": False,
             "message": "Employee data save successfully"
         }
     except:
         response_dict = {
             "error": True,
             "message": "Error during saving employee data"
         }
     return Response(response_dict)
    def list(self, request):
        customer_request = CustomerRequest.objects.all()
        customer_request_serializer = CustomerRequestSerializer(
            customer_request, many=True, context={"request": request})

        bill_count = Bill.objects.all()
        bill_count_serializer = BillSerializer(bill_count,
                                               many=True,
                                               context={"request": request})

        medicine_count = Medicine.objects.all()
        medicine_count_serializer = MedicineSerliazer(
            medicine_count, many=True, context={"request": request})

        company_count = Company.objects.all()
        company_count_serializer = CompanySerliazer(
            company_count, many=True, context={"request": request})

        employee_count = Employee.objects.all()
        employee_count_serializer = EmployeeSerializer(
            employee_count, many=True, context={"request": request})

        bill_details = BillDetails.objects.all()
        profit_amt = 0
        sell_amt = 0
        buy_amt = 0
        for bill in bill_details:
            buy_amt = float(buy_amt + float(bill.medicine_id.buy_price)) * int(
                bill.qty)
            sell_amt = float(sell_amt +
                             float(bill.medicine_id.sell_price)) * int(
                                 bill.qty)

        profit_amt = sell_amt - buy_amt

        customer_request_pending = CustomerRequest.objects.filter(status=False)
        customer_request_pending_serializer = CustomerRequestSerializer(
            customer_request_pending, many=True, context={"request": request})

        customer_request_completed = CustomerRequest.objects.filter(
            status=True)
        customer_request_completed_serializer = CustomerRequestSerializer(
            customer_request_completed,
            many=True,
            context={"request": request})

        current_date = datetime.today().strftime("%Y-%m-%d")
        current_date1 = datetime.today()
        current_date_7days = current_date1 + timedelta(days=7)
        current_date_7days = current_date_7days.strftime("%Y-%m-%d")
        bill_details_today = BillDetails.objects.filter(
            added_on__date=current_date)
        profit_amt_today = 0
        sell_amt_today = 0
        buy_amt_today = 0
        for bill in bill_details_today:
            buy_amt_today = float(buy_amt_today +
                                  float(bill.medicine_id.buy_price)) * int(
                                      bill.qty)
            sell_amt_today = float(sell_amt_today +
                                   float(bill.medicine_id.sell_price)) * int(
                                       bill.qty)

        profit_amt_today = sell_amt_today - buy_amt_today

        medicine_expire = Medicine.objects.filter(
            expire_date__range=[current_date, current_date_7days])
        medicine_expire_serializer = MedicineSerliazer(
            medicine_expire, many=True, context={"request": request})

        bill_dates = BillDetails.objects.order_by().values(
            "added_on__date").distinct()
        profit_chart_list = []
        sell_chart_list = []
        buy_chart_list = []
        for billdate in bill_dates:
            access_date = billdate["added_on__date"]

            bill_data = BillDetails.objects.filter(added_on__date=access_date)
            profit_amt_inner = 0
            sell_amt_inner = 0
            buy_amt_inner = 0

            for billsingle in bill_data:
                buy_amt_inner = float(buy_amt_inner + float(
                    billsingle.medicine_id.buy_price)) * int(billsingle.qty)
                sell_amt_inner = float(sell_amt_inner + float(
                    billsingle.medicine_id.sell_price)) * int(billsingle.qty)

            profit_amt_inner = sell_amt_inner - buy_amt_inner

            profit_chart_list.append({
                "date": access_date,
                "amt": profit_amt_inner
            })
            sell_chart_list.append({
                "date": access_date,
                "amt": sell_amt_inner
            })
            buy_chart_list.append({"date": access_date, "amt": buy_amt_inner})

        dict_respone = {
            "error": False,
            "message": "Home Page Data",
            "customer_request": len(customer_request_serializer.data),
            "bill_count": len(bill_count_serializer.data),
            "medicine_count": len(medicine_count_serializer.data),
            "company_count": len(company_count_serializer.data),
            "employee_count": len(employee_count_serializer.data),
            "sell_total": sell_amt,
            "buy_total": buy_amt,
            "profit_total": profit_amt,
            "request_pending": len(customer_request_pending_serializer.data),
            "request_completed":
            len(customer_request_completed_serializer.data),
            "profit_amt_today": profit_amt_today,
            "sell_amt_today": sell_amt_today,
            "medicine_expire_serializer_data":
            len(medicine_expire_serializer.data),
            "sell_chart": sell_chart_list,
            "buy_chart": buy_chart_list,
            "profit_chart": profit_chart_list
        }
        return Response(dict_respone)