diff --git a/src/redux/reducers/cartReducer.js b/src/redux/reducers/cartReducer.js index 8366656..8fab70d 100644 --- a/src/redux/reducers/cartReducer.js +++ b/src/redux/reducers/cartReducer.js @@ -38,9 +38,33 @@ export const cartReducer = createReducer( deleteFromCart: (state, action) => { state.cartItems = state.cartItems.filter((i) => i.id !== action.payload); }, + + // selectTax: (state, action) => { + + // const tax = action.payload; + + // const item = state.cartItems.find((i) => i.id === tax.productId); + // if (item) { + + // state.cartItems.forEach((i) => { + // if (i.id === item.id) { + + // i.taxName = tax.name; + // i.taxRate = tax.rate; + // i.taxId = tax.taxId + // let rate = tax.rate / 100 + // let PriceWithT = i.price; + // PriceWithT += + (i.price * rate).toFixed(); + // i.PriceWithTax = PriceWithT + + // } + // }); + // } + // }, + calculatePrice: (state) => { let sum = 0; - state.cartItems.forEach((i) => (sum += i.price * i.quantity)); + state.cartItems.forEach((i) => (sum += i.PriceWithTax * i.quantity)); state.subTotal = sum; // state.shipping = state.subTotal > 1000 ? 0 : 200; // state.tax = +(state.subTotal * 0.18).toFixed(); @@ -48,6 +72,7 @@ export const cartReducer = createReducer( // + state.tax + state.shipping; }, + } ); @@ -55,7 +80,7 @@ export const cartReducer = createReducer( let initialInfo = localStorage.getItem("shippingInfo") ? JSON.parse(localStorage.getItem("shippingInfo")) : ({ - franchisees: [], + franchisees: null, }) @@ -65,20 +90,21 @@ export const shipingReducer = createReducer( { addShippingInfo: (state, action) => { const item = action.payload; - const isItemExist = state.franchisees.find((i) => i.id === item.id); + // const isItemExist = state.franchisees.find((i) => i.id === item.id); - if (isItemExist) { - // state.cartItems.forEach((i) => { - // if (i.id === item.id) i.quantity += 1; - // }); - return; - } else { - state.franchisees.push(item); - } + // if (isItemExist) { + // state.cartItems.forEach((i) => { + // if (i.id === item.id) i.quantity += 1; + // }); + // return; + // } else { + state.franchisees = item; + // } }, deleteFromshippingInfo: (state, action) => { - state.franchisees = state.franchisees.filter((i) => i.id !== action.payload); + state.franchisees = null + // state.franchisees.filter((i) => i.id !== action.payload); }, } diff --git a/src/routes.js b/src/routes.js index 2ad63f9..9abfda9 100644 --- a/src/routes.js +++ b/src/routes.js @@ -45,6 +45,7 @@ import AddOrder from './views/orders/AddOrder' import Tax from './views/configuration/tax/Tax' import Addtax from './views/configuration/tax/Addtax' import Edittax from './views/configuration/tax/Edittax' +import EditOrder from './views/orders/EditOrder' const routes = [ { path: '/', exact: true, name: 'Home' }, @@ -63,6 +64,9 @@ const routes = [ { path: '/orders/new', name: 'New Orders', element: NewOrders }, { path: '/order/add', name: 'add Order', element: AddOrder }, + { path: '/orders/edit/:id', name: 'Edit Order', element: EditOrder }, + //{ path: '/orders/view/:id', name: 'Edit Order', element: EditOrder }, + // { path: '/orders/processing', name: 'Processing Orders', element: ProcessingOrders }, // { path: '/orders/dispatched', name: 'Dispatched Orders', element: DispatchedOrders }, // { path: '/orders/delivered', name: 'Delivered Orders', element: DeliveredOrders }, diff --git a/src/views/Products/AddProduct.js b/src/views/Products/AddProduct.js index d435137..98f0b75 100644 --- a/src/views/Products/AddProduct.js +++ b/src/views/Products/AddProduct.js @@ -19,13 +19,36 @@ const AddProduct = () => { description: '', base_Price: '', + base_Price_With_Tax: '', price_Level_2: '', - price_Level_3: '' + price_Level_2_With_Tax: '', + + price_Level_3: '', + price_Level_3_With_Tax: '', + taxId: '' }) const [loading, setLoading] = useState(false) + const [allTax, setAllTax] = useState([]) + + + + + useEffect(() => { + const getAllTax = async () => { + const res = await axios.get(`/api/tax/view_tax`, { + headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` }, + }) + if (res.data) { + setAllTax(res.data) + } + } + getAllTax() + + }, [token]) + const handleChange = (e) => { if (e.target.id === 'image') { @@ -61,6 +84,39 @@ const AddProduct = () => { } + const TaxRatechange = async (e) => { + let taxDetails = { + name: e.target.value.slice(12, 16), + rate: Number(e.target.value.slice(4, 6)), + + taxId: e.target.value.slice(24) + + } + + let trRate = taxDetails.rate / 100 + let PriceWithT = Number(data.base_Price); + PriceWithT += +((PriceWithT * trRate).toFixed()); + + //price_Level_2_With_Tax + let price_Level_2_With_Tax = Number(data.price_Level_2); + price_Level_2_With_Tax += +((price_Level_2_With_Tax * trRate).toFixed()); + // + //price_Level_3_With_Tax + let price_Level_3_With_Tax = Number(data.price_Level_3); + price_Level_3_With_Tax += +((price_Level_3_With_Tax * trRate).toFixed()); + setData((prev) => ({ + ...prev, + base_Price_With_Tax: PriceWithT, + + price_Level_2_With_Tax: price_Level_2_With_Tax, + + + price_Level_3_With_Tax: price_Level_3_With_Tax, + taxId: taxDetails.taxId + + })) + } + const handleSubmit = () => { if ( @@ -68,8 +124,11 @@ const AddProduct = () => { data.description.trim() === '' || data.base_Price === '' || + data.base_Price_With_Tax === '' || data.price_Level_2 === '' || + data.price_Level_2_With_Tax === '' || data.price_Level_3 === '' || + data.price_Level_3_With_Tax === '' || data.imageURL.trim() === '' ) { swal({ @@ -87,8 +146,16 @@ const AddProduct = () => { formData.set('description', data.description) formData.set('base_Price', data.base_Price) + formData.set('base_Price_With_Tax', data.base_Price_With_Tax) + formData.set('price_Level_2', data.price_Level_2) + formData.set('price_Level_2_With_Tax', data.price_Level_2_With_Tax) + formData.set('price_Level_3', data.price_Level_3) + formData.set('price_Level_3_With_Tax', data.price_Level_3_With_Tax) + formData.set('taxId', data.taxId) + + formData.append('image', data.image) @@ -245,8 +312,41 @@ const AddProduct = () => {
+
-
+
+ + handleChange(e)} + + /> +
+
+ + handleChange(e)} + + /> +
+ + + +
+ {/*
@@ -258,35 +358,96 @@ const AddProduct = () => { onChange={(e) => handleChange(e)} /> +
*/} + +
+ +
+ + handleChange(e)} + + + /> +
+
+ + handleChange(e)} + + + /> +
+ + +
-
+ +
+ +
+ + handleChange(e)} + + + /> +
+
+ + handleChange(e)} + + + /> +
+ + + +
+ + + {allTax.length > 0 &&
- handleChange(e)} + Tax* + handleChange(e)} - - - /> + {allTax.map((t, i) => + + )} +
+ }
diff --git a/src/views/Products/EditProduct.js b/src/views/Products/EditProduct.js index 9e6f411..c534dd8 100644 --- a/src/views/Products/EditProduct.js +++ b/src/views/Products/EditProduct.js @@ -1,6 +1,19 @@ + + + + + + + + + + + + + import React, { useEffect, useState } from 'react' import Button from '@material-ui/core/Button' import { Link, useNavigate, useParams } from 'react-router-dom' @@ -10,9 +23,10 @@ import { isAutheticated } from 'src/auth' // import { WebsiteURL } from '../WebsiteURL' const EditProduct = () => { + const id = useParams()?.id + const token = isAutheticated() const navigate = useNavigate() - const id = useParams()?.id const [data, setData] = useState({ image: '', imageURL: '', @@ -20,13 +34,20 @@ const EditProduct = () => { description: '', base_Price: '', + base_Price_With_Tax: '', price_Level_2: '', - price_Level_3: '' + price_Level_2_With_Tax: '', + + price_Level_3: '', + price_Level_3_With_Tax: '', + taxId: '' }) const [loading, setLoading] = useState(false) + const [allTax, setAllTax] = useState([]) + //get Productdata const getProduct = async () => { @@ -52,14 +73,18 @@ const EditProduct = () => { getProduct() }, []) + useEffect(() => { + const getAllTax = async () => { + const res = await axios.get(`/api/tax/view_tax`, { + headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` }, + }) + if (res.data) { + setAllTax(res.data) + } + } + getAllTax() - - - - - - - + }, [token]) const handleChange = (e) => { @@ -96,6 +121,39 @@ const EditProduct = () => { } + const TaxRatechange = async (e) => { + let taxDetails = { + name: e.target.value.slice(12, 16), + rate: Number(e.target.value.slice(4, 6)), + + taxId: e.target.value.slice(24) + + } + let trRate = taxDetails.rate / 100 + let PriceWithT = Number(data.base_Price); + PriceWithT += +((PriceWithT * trRate).toFixed()); + + //price_Level_2_With_Tax + let price_Level_2_With_Tax = Number(data.price_Level_2); + price_Level_2_With_Tax += +((price_Level_2_With_Tax * trRate).toFixed()); + // + //price_Level_3_With_Tax + let price_Level_3_With_Tax = Number(data.price_Level_3); + price_Level_3_With_Tax += +((price_Level_3_With_Tax * trRate).toFixed()); + setData((prev) => ({ + ...prev, + base_Price_With_Tax: PriceWithT, + + price_Level_2_With_Tax: price_Level_2_With_Tax, + + + price_Level_3_With_Tax: price_Level_3_With_Tax, + taxId: taxDetails.taxId + + + })) + } + const handleSubmit = () => { if ( @@ -103,8 +161,11 @@ const EditProduct = () => { data.description.trim() === '' || data.base_Price === '' || + data.base_Price_With_Tax === '' || data.price_Level_2 === '' || + data.price_Level_2_With_Tax === '' || data.price_Level_3 === '' || + data.price_Level_3_With_Tax === '' || data.imageURL.trim() === '' ) { swal({ @@ -122,8 +183,17 @@ const EditProduct = () => { formData.set('description', data.description) formData.set('base_Price', data.base_Price) + formData.set('base_Price_With_Tax', data.base_Price_With_Tax) + formData.set('price_Level_2', data.price_Level_2) + formData.set('price_Level_2_With_Tax', data.price_Level_2_With_Tax) + formData.set('price_Level_3', data.price_Level_3) + + formData.set('price_Level_3_With_Tax', data.price_Level_3_With_Tax) + formData.set('taxId', data.taxId) + + formData.append('image', data.image) @@ -137,7 +207,7 @@ const EditProduct = () => { }) .then((res) => { swal({ - title: 'Added', + title: 'Edited', text: 'Product Edited successfully!', icon: 'success', button: 'Return', @@ -145,6 +215,7 @@ const EditProduct = () => { setLoading(false) navigate('/products', { replace: true }) }) + .catch((err) => { setLoading(false) const message = err.response?.data?.message || 'Something went wrong!' @@ -157,7 +228,7 @@ const EditProduct = () => { }) }) } - console.log(data) + return (
@@ -190,7 +261,7 @@ const EditProduct = () => { onClick={() => handleSubmit()} disabled={loading} > - {loading ? 'Loading' : 'Save'} + {loading ? 'Loading' : 'Edit'}
- {/*
- - handleChange(e)} + value={data.price_Lable} > - - - + + + + + + + + + + -
*/} +
+ + {productDetails?.PriceWithTax &&

+ Price With Tax: ₹{productDetails?.PriceWithTax} +

}
-
+

Price: ₹{productDetails?.price} -

- {' '} +

+ {/* {allTax.length > 0 &&
+
Tax:
+ +
+ } */} +
@@ -486,45 +582,44 @@ function AddOrder() { { - AllStates.shipingInfo.franchisees && AllStates.shipingInfo.franchisees.map((franchiDetails, i) => -
-
-
- {franchiDetails?.name} -
-
-
{franchiDetails?.name}
- - Address. : {franchiDetails?.address} - -

- Contact No. : {franchiDetails?.contact_Number} -

-

- contact Person Name. : {franchiDetails?.contact_Person_Name} -

- - - - - - - -
+ AllStates?.shipingInfo?.franchisees !== null && +
+
+
+ {AllStates.shipingInfo.franchisees?.name}
-
+
+
{AllStates.shipingInfo.franchisees?.name}
+ + Address. : {AllStates.shipingInfo.franchisees?.address} + +

+ Contact No. : {AllStates.shipingInfo.franchisees?.contact_Number} +

+

+ contact Person Name. : {AllStates.shipingInfo.franchisees?.contact_Person_Name} +

+ + + + + + +
- ) +
+ +
} {/*
@@ -652,7 +747,7 @@ function AddOrder() { })}
*/} -
+