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 = () => {
+
- Contact No. : {franchiDetails?.contact_Number} -
-- contact Person Name. : {franchiDetails?.contact_Person_Name} -
- - - - - - - -+ Contact No. : {AllStates.shipingInfo.franchisees?.contact_Number} +
++ contact Person Name. : {AllStates.shipingInfo.franchisees?.contact_Person_Name} +
+ + + + + + +