Skip to content

Commit

Permalink
updated code with main
Browse files Browse the repository at this point in the history
  • Loading branch information
prabhatsuman committed Jul 6, 2024
1 parent 0211acc commit 5193971
Show file tree
Hide file tree
Showing 25 changed files with 3,928 additions and 14,117 deletions.
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@ services:
container_name: duck_farm_frontend
volumes:
- ./duck_farm_frontend:/app
- react_build:/app/build # Mount the volume here
- react_build:/app/dist # Mount the volume here
networks:
- duck_farm_network
ports:
- "3000:3000"
depends_on:
- duck_farm_backend


networks:
duck_farm_network:
Expand Down
27 changes: 10 additions & 17 deletions duck_farm_backend/management/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,7 @@ def daily_view(self, request):
queryset = self.queryset.filter(
date__range=[start_date, end_date]).order_by('date')

days = ['Sunday', 'Monday', 'Tuesday',
'Wednesday', 'Thursday', 'Friday', 'Saturday']
days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
data = []

for single_date in (start_date + timedelta(n) for n in range(7)):
Expand Down Expand Up @@ -612,7 +611,7 @@ def daily_view(self, request):

queryset = self.queryset.filter(date__range=[start_date, end_date]).order_by('date')

days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday']
days=['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
data = []

for single_date in (start_date + timedelta(n) for n in range(7)):
Expand Down Expand Up @@ -695,18 +694,12 @@ def list(self, request):
return Response({'total_earning': total_earning, 'total_expense': total_expense, 'total_sales': total_sales})

@action(detail=False, methods=['get'], url_path='this_month', permission_classes=[IsAuthenticated])
def this_month(self, request):
cache_key = 'total_earning_data'
cached_data = cache.get(cache_key)
if cached_data:
return Response(cached_data)
else:
total_expense = Expense.objects.filter(date__month=date.today().month).aggregate(total_expense=Sum('amount'))[
'total_expense'] or 0
total_sales = Sales.objects.filter(date__month=date.today().month).aggregate(total_sales=Sum('amount'))[
'total_sales'] or 0
total_earning = total_sales - total_expense
return Response({'total_earnings': total_earning})
def this_month(self, request):
total_expense = Expense.objects.filter(date__month=date.today().month,date__year=date.today().year).aggregate(total_expense=Sum('amount'))['total_expense'] or 0
total_sales = Sales.objects.filter(date__month=date.today().month,date__year=date.today().year).aggregate(total_sales=Sum('amount'))['total_sales'] or 0
print(total_sales, total_expense)
total_earning = total_sales - total_expense
return Response({'total_earnings': total_earning})

@action(detail=False, methods=['get'], url_path='monthly_total_pages', permission_classes=[IsAuthenticated])
def monthly_total_pages(self, request):
Expand All @@ -733,7 +726,7 @@ def monthly_view(self, request):
'July', 'August', 'September', 'October', 'November', 'December']

for month in range(1,13):
total_sales = queryset.filter(date__year=target_year, date__month=month).aggregate(total_sales=Sum('amount'))['total_sales'] or 0
total_sales = Sales.objects.filter(date__year=target_year, date__month=month).aggregate(total_sales=Sum('amount'))['total_sales'] or 0
total_expense = Expense.objects.filter(date__year=target_year, date__month=month).aggregate(total_expense=Sum('amount'))['total_expense'] or 0
total_earning = total_sales - total_expense
data.append({
Expand Down Expand Up @@ -905,4 +898,4 @@ def get(self, request, selected_type, selected_period):
'total_eggs'] or 0
return Response({'data': f'{total_eggs} eggs sold {self.mapping[selected_period]}'})

return Response({'error': 'Invalid type or period'}, status=400)
return Response({'error': 'Invalid type or period'}, status=400)
4 changes: 2 additions & 2 deletions duck_farm_frontend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WORKDIR /app

# Install dependencies
COPY package.json package-lock.json ./
RUN npm install
RUN npm i

# Copy the project files
COPY . .
Expand All @@ -16,4 +16,4 @@ RUN npm run build

# Serve the React app
RUN npm install -g serve
CMD ["serve", "-s", "build"]
CMD ["serve", "-s", "dist"]
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Duck Farm</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="utf-8" />
<link rel="icon" href="/logo192.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />

<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->

<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Duck Farm</title>
</head>

<body>

<div id="root"></div>
<script type="module" src="/src/main.jsx"></script>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

</html>
Loading

0 comments on commit 5193971

Please sign in to comment.