Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 15 additions & 2 deletions src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import axios from 'axios';
import * as XLSX from 'xlsx';
import ads from '../data/ads.js';
import sha256 from 'crypto-js/sha256';
import { format } from 'date-fns';
//import { GET } from 'superagent';
const baseApiUrl = import.meta.env.VITE_API_BASE_URL;
const API_FLAG = import.meta.env.VITE_API_FLAG;
Expand Down Expand Up @@ -497,6 +498,7 @@ export const apiUpdateStoreAsync = async (store) => {
categoryId: store.categoryId,
description: store.description,
isActive: store.isActive,
tax: store.tax
});
}
};
Expand All @@ -510,11 +512,23 @@ export const apiGetAllStoresAsync = async () => {
} else {
apiSetAuthHeader();
const stores = await axios.get(`${baseApiUrl}/api/Admin/stores`);
console.log(stores);
return stores.data;
}
};

export const apiGetMonthlyStoreRevenueAsync = async (id) => {
apiSetAuthHeader();
const now = new Date();
const firstDayOfMonth = new Date(now.getFullYear(), now.getMonth(), 1); // ✅ define it here
const lastDayOfMonth = new Date(now.getFullYear(), now.getMonth() + 1, 0); // ✅ and here
const from = format(firstDayOfMonth, 'yyyy-MM-dd');
const to = format(lastDayOfMonth, 'yyyy-MM-dd');

const rev = await axios.get(`${baseApiUrl}/api/Admin/store/${id}/income?from=${from}&to=${to}`);
console.log(rev);
return rev.data;

};
// DELETE product category
export const apiDeleteProductCategoryAsync = async (categoryId) => {
if (API_ENV_DEV === API_FLAG) {
Expand Down Expand Up @@ -1675,6 +1689,5 @@ export const apiFetchDeliveryAddressByIdAsync = async (addressId) => {
const res = await axios.get(
`${baseApiUrl}/api/user-profile/address/${addressId}`
);
console.log('RESPONSE Adrese: ', res);
return res.data; // Vraća objekat adrese
};
21 changes: 20 additions & 1 deletion src/components/EditStoreModal.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const StoreEditModal = ({ open, onClose, store, onStoreUpdated }) => {
const [categoryId, setCategoryId] = useState('');
const [description, setDescription] = useState('');
const [address, setAddress] = useState('');
const [tax, setTax] = useState('');
const [categories, setCategories] = useState([]);
const [loading, setLoading] = useState(false);

Expand All @@ -34,6 +35,7 @@ const StoreEditModal = ({ open, onClose, store, onStoreUpdated }) => {
setCategoryId(store.categoryId || '');
setDescription(store.description || '');
setAddress(store.address || '');
setTax(store.tax?.toString() || '');
}
}, [store]);

Expand All @@ -47,6 +49,7 @@ const StoreEditModal = ({ open, onClose, store, onStoreUpdated }) => {
address,
categoryId,
description,
tax: parseFloat(tax),
isActive: store.isOnline ?? true,
};

Expand Down Expand Up @@ -142,7 +145,23 @@ const StoreEditModal = ({ open, onClose, store, onStoreUpdated }) => {
margin='normal'
required
/>

<TextField
label='Tax (%)'
type='number'
fullWidth
value={tax}
onChange={(e) => setTax(e.target.value)}
margin='normal'
required
inputProps={{
min: 0,
step: 0.01,
style: {
backgroundColor: 'white',
color: 'black',
},
}}
/>
<Button
type='submit'
fullWidth
Expand Down
47 changes: 46 additions & 1 deletion src/components/StoreCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
apiExportProductsToCSVAsync,
apiExportProductsToExcelAsync,
apiCreateProductAsync,
apiGetMonthlyStoreRevenueAsync
} from '@api/api';
import AddProductModal from '@components/NewProductModal';
import LocationOnIcon from '@mui/icons-material/LocationOn';
Expand All @@ -38,12 +39,23 @@ const StoreCard = ({ store }) => {
const [updating, setUpdating] = useState(false);
const fileInputRef = useRef();
const [parsedProducts, setParsedProducts] = useState([]);

const [revenue, setRevenue] = useState(0);
const openStatus = Boolean(anchorEl);
const openMenu = Boolean(menuAnchor);

useEffect(() => {
apiGetStoreCategoriesAsync().then(setCategories);
const fetchRevenue = async () => {
try {
const rez = await apiGetMonthlyStoreRevenueAsync(store.id);
console.log(rez.taxedIncome); // ✅ This will now work
setRevenue(rez);
} catch (error) {
console.error("Failed to fetch revenue:", error);
}
};

fetchRevenue();
}, []);

const handleStatusClick = (e) => setAnchorEl(e.currentTarget);
Expand Down Expand Up @@ -257,6 +269,39 @@ const StoreCard = ({ store }) => {
>
{store.description}
</Typography>

<Typography
variant="body2"
color="text.secondary"
sx={{
mt: 1,
fontSize: '0.85rem',
}}
>
Tax: {store.tax}
</Typography>

<Typography
variant="body2"
color="text.secondary"
sx={{
mt: 1,
fontSize: '0.85rem',
}}
>
Total monthly income: {revenue.totalIncome}
</Typography>

<Typography
variant="body2"
color="text.secondary"
sx={{
mt: 1,
fontSize: '0.85rem',
}}
>
Taxed monthly income: {revenue.taxedIncome}
</Typography>

{/* Buttons */}
<Box sx={{ mt: 'auto', display: 'flex', alignItems: 'center' }}>
Expand Down
1 change: 0 additions & 1 deletion src/pages/StoresPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const StoresPage = () => {
useEffect(() => {
const fetchStores = async () => {
const data = await apiGetAllStoresAsync();
console.log(data);
const mapped = data.map((store) => ({
...store,
categoryId: store.categoryId || store.category?.id || 0,
Expand Down