product change and franchisee
This commit is contained in:
parent
b71589fa55
commit
ffc90fe61a
@ -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) {
|
||||
// if (isItemExist) {
|
||||
// state.cartItems.forEach((i) => {
|
||||
// if (i.id === item.id) i.quantity += 1;
|
||||
// });
|
||||
return;
|
||||
} else {
|
||||
state.franchisees.push(item);
|
||||
}
|
||||
// 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);
|
||||
|
||||
},
|
||||
}
|
||||
|
@ -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 },
|
||||
|
@ -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,9 @@ const AddProduct = () => {
|
||||
<div className="col-lg-6 col-md-6 col-sm-12 my-1">
|
||||
<div className="card h-100">
|
||||
<div className="card-body px-5">
|
||||
<div className="d-flex flex-wrap">
|
||||
|
||||
<div className="mb-3">
|
||||
<div className="mb-3 me-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Base Price*
|
||||
</label>
|
||||
@ -260,6 +328,41 @@ const AddProduct = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Base Price With Tax
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled
|
||||
className="form-control"
|
||||
id="base_Price_With_Tax"
|
||||
value={data.base_Price_With_Tax}
|
||||
placeholder={data.base_Price_With_Tax}
|
||||
// onChange={(e) => handleChange(e)}
|
||||
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
{/* <div className="mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Base Price*
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
className="form-control"
|
||||
id="base_Price"
|
||||
value={data.base_Price}
|
||||
onChange={(e) => handleChange(e)}
|
||||
|
||||
/>
|
||||
</div> */}
|
||||
|
||||
<div className="d-flex flex-wrap">
|
||||
|
||||
<div className="mb-3 me-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Level 2*
|
||||
</label>
|
||||
@ -274,6 +377,29 @@ const AddProduct = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Level 2 with Tax
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled
|
||||
className="form-control"
|
||||
id="price_Level_2_With_Tax"
|
||||
value={data.price_Level_2_With_Tax}
|
||||
placeholder={data.price_Level_2_With_Tax}
|
||||
// onChange={(e) => handleChange(e)}
|
||||
|
||||
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div className="d-flex flex-wrap">
|
||||
|
||||
<div className="mb-3 me-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Level 3*
|
||||
</label>
|
||||
@ -287,6 +413,41 @@ const AddProduct = () => {
|
||||
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Level 3 with Tax
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled
|
||||
className="form-control"
|
||||
id="price_Level_3_With_Tax"
|
||||
placeholder={data.price_Level_3_With_Tax}
|
||||
// onChange={(e) => handleChange(e)}
|
||||
|
||||
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{allTax.length > 0 && <div className=" mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Tax*
|
||||
</label> <select className=" form-control" name="" id=""
|
||||
onChange={(e) => TaxRatechange(e)}
|
||||
>
|
||||
<option value="" disabled>---</option>
|
||||
|
||||
{allTax.map((t, i) =>
|
||||
<option key={i} value={`tax:${t.tax},name:${t.name} ,taxId:${t._id}`}>{t.tax}% {t.name}</option>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -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 (
|
||||
<div className="container">
|
||||
<div className="row">
|
||||
@ -190,7 +261,7 @@ const EditProduct = () => {
|
||||
onClick={() => handleSubmit()}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Loading' : 'Save'}
|
||||
{loading ? 'Loading' : 'Edit'}
|
||||
</Button>
|
||||
<Link to="/products">
|
||||
<Button
|
||||
@ -280,8 +351,9 @@ const EditProduct = () => {
|
||||
<div className="col-lg-6 col-md-6 col-sm-12 my-1">
|
||||
<div className="card h-100">
|
||||
<div className="card-body px-5">
|
||||
<div className="d-flex flex-wrap">
|
||||
|
||||
<div className="mb-3">
|
||||
<div className="mb-3 me-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Base Price*
|
||||
</label>
|
||||
@ -295,6 +367,41 @@ const EditProduct = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Base Price With Tax
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled
|
||||
className="form-control"
|
||||
id="base_Price_With_Tax"
|
||||
value={data.base_Price_With_Tax}
|
||||
placeholder={data.base_Price_With_Tax}
|
||||
// onChange={(e) => handleChange(e)}
|
||||
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
{/* <div className="mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Base Price*
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
className="form-control"
|
||||
id="base_Price"
|
||||
value={data.base_Price}
|
||||
onChange={(e) => handleChange(e)}
|
||||
|
||||
/>
|
||||
</div> */}
|
||||
|
||||
<div className="d-flex flex-wrap">
|
||||
|
||||
<div className="mb-3 me-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Level 2*
|
||||
</label>
|
||||
@ -309,6 +416,29 @@ const EditProduct = () => {
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Level 2 with Tax
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled
|
||||
className="form-control"
|
||||
id="price_Level_2_With_Tax"
|
||||
value={data.price_Level_2_With_Tax}
|
||||
placeholder={data.price_Level_2_With_Tax}
|
||||
// onChange={(e) => handleChange(e)}
|
||||
|
||||
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div className="d-flex flex-wrap">
|
||||
|
||||
<div className="mb-3 me-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Level 3*
|
||||
</label>
|
||||
@ -322,6 +452,41 @@ const EditProduct = () => {
|
||||
|
||||
/>
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Level 3 with Tax
|
||||
</label>
|
||||
<input
|
||||
type="number"
|
||||
disabled
|
||||
className="form-control"
|
||||
id="price_Level_3_With_Tax"
|
||||
placeholder={data.price_Level_3_With_Tax}
|
||||
// onChange={(e) => handleChange(e)}
|
||||
|
||||
|
||||
/>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{allTax.length > 0 && <div className=" mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Tax*
|
||||
</label> <select className=" form-control" name="" id=""
|
||||
onChange={(e) => TaxRatechange(e)}
|
||||
>
|
||||
<option value="" disabled>---</option>
|
||||
|
||||
{allTax.map((t, i) =>
|
||||
<option key={i} value={`tax:${t.tax},name:${t.name} ,taxId:${t._id}`}>{t.tax}% {t.name}</option>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -23,11 +23,8 @@ const AddTemple = () => {
|
||||
state_name: '',
|
||||
short_url: '',
|
||||
contact_Number: '',
|
||||
contact_Person_Name: ''
|
||||
// pan: '',
|
||||
// business_name: '',
|
||||
// gstin: '',
|
||||
// option: '',
|
||||
contact_Person_Name: '',
|
||||
price_Lable: ''
|
||||
})
|
||||
|
||||
const [cities, setCities] = useState([])
|
||||
@ -111,6 +108,7 @@ const AddTemple = () => {
|
||||
data.contact_Person_Name === '' ||
|
||||
data.address_line_1.trim() === '' ||
|
||||
data.address_line_2.trim() === '' ||
|
||||
data.price_Lable.trim() === '' ||
|
||||
data.city === '' ||
|
||||
data.short_url === '' ||
|
||||
data.state_name === '' ||
|
||||
@ -139,8 +137,10 @@ const AddTemple = () => {
|
||||
formData.set('contact_Number', data.contact_Number)
|
||||
formData.set('contact_Person_Name', data.contact_Person_Name)
|
||||
|
||||
formData.set('price_Lable', data.price_Lable)
|
||||
formData.set('url', WebsiteURL + data.short_url + '/login')
|
||||
formData.set('short_url', data.short_url)
|
||||
|
||||
formData.append('image', data.image)
|
||||
axios
|
||||
.post(`/api/temple`, formData, {
|
||||
@ -356,6 +356,25 @@ const AddTemple = () => {
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className=" mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Lable*
|
||||
</label> <select className="form-control" name="price_Lable" id="price_Lable"
|
||||
onChange={(e) => handleChange(e)}
|
||||
value={data.price_Lable}
|
||||
>
|
||||
|
||||
|
||||
|
||||
<option value="" disabled>---</option>
|
||||
|
||||
<option value="base_Price">Base Price</option>
|
||||
<option value="price_Level_2"> price Level 2</option>
|
||||
<option value="price_Level_3">price Level 3</option>
|
||||
|
||||
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div className="mb-3">
|
||||
<label htmlFor="image" className="form-label">
|
||||
|
@ -22,6 +22,7 @@ const EditTemple = () => {
|
||||
address_line_2: '',
|
||||
contact_Person_Name: '',
|
||||
contact_Number: '',
|
||||
price_Lable: '',
|
||||
city: '',
|
||||
state_name: '',
|
||||
short_url: '',
|
||||
@ -126,6 +127,7 @@ const EditTemple = () => {
|
||||
data.name.trim() === '' ||
|
||||
data.address_line_1.trim() === '' ||
|
||||
data.address_line_2.trim() === '' ||
|
||||
data.price_Lable.trim() === '' ||
|
||||
data.contact_Number === '' ||
|
||||
data.contact_Person_Name === '' ||
|
||||
data.city === '' ||
|
||||
@ -151,6 +153,9 @@ const EditTemple = () => {
|
||||
formData.set('address_line_1', data.address_line_1)
|
||||
formData.set('address_line_2', data.address_line_2)
|
||||
formData.set('city', data.city)
|
||||
formData.set('price_Lable', data.price_Lable)
|
||||
|
||||
|
||||
formData.set('state_name', data.state_name)
|
||||
formData.set('contact_Number', data.contact_Number)
|
||||
formData.set('contact_Person_Name', data.contact_Person_Name)
|
||||
@ -408,21 +413,25 @@ const EditTemple = () => {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/* <div className="mb-3">
|
||||
<label htmlFor="option" className="form-label">
|
||||
Option*
|
||||
</label>
|
||||
<select
|
||||
className="form-control"
|
||||
id="option"
|
||||
value={data.option}
|
||||
<div className=" mb-3">
|
||||
<label htmlFor="title" className="form-label">
|
||||
Price Lable*
|
||||
</label> <select className="form-control" name="price_Lable" id="price_Lable"
|
||||
onChange={(e) => handleChange(e)}
|
||||
value={data.price_Lable}
|
||||
>
|
||||
<option value="">None</option>
|
||||
<option value="group">Group</option>
|
||||
<option value="bundle">Bundle</option>
|
||||
|
||||
|
||||
|
||||
<option value="" disabled>---</option>
|
||||
|
||||
<option value="base_Price">Base Price</option>
|
||||
<option value="price_Level_2"> price Level 2</option>
|
||||
<option value="price_Level_3">price Level 3</option>
|
||||
|
||||
|
||||
</select>
|
||||
</div> */}
|
||||
</div>
|
||||
<div className="mb-3">
|
||||
<label htmlFor="image" className="form-label">
|
||||
Temple Banner*
|
||||
|
@ -19,13 +19,13 @@ function AddOrder() {
|
||||
const { cartItems, subTotal, tax, shipping, total } = useSelector(
|
||||
(state) => state.cart
|
||||
);
|
||||
|
||||
// const { cart, shippingInfo } = useSelector(
|
||||
// (state) => state
|
||||
// );
|
||||
const AllStates = useSelector(
|
||||
(state) => state
|
||||
);
|
||||
console.log(AllStates.shipingInfo.franchisees)
|
||||
const getValue = useRef()
|
||||
const getFranchiseeID = useRef()
|
||||
const dispatch = useDispatch();
|
||||
@ -34,6 +34,8 @@ function AddOrder() {
|
||||
const token = isAutheticated()
|
||||
const [productData, setProductData] = useState([])
|
||||
const [allFranchisee, setAllFranchisee] = useState([])
|
||||
const [allTax, setAllTax] = useState([])
|
||||
|
||||
|
||||
|
||||
const [productDetails, setProductDetails] = useState()
|
||||
@ -46,6 +48,19 @@ function AddOrder() {
|
||||
contact_Number: '',
|
||||
total_Price: '',
|
||||
})
|
||||
useEffect(() => {
|
||||
const getAllTax = async () => {
|
||||
const res = await axios.get(`/api/tax/view_tax`, {
|
||||
headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
|
||||
})
|
||||
if (res.data) {
|
||||
// console.log(res.data)
|
||||
setAllTax(res.data)
|
||||
}
|
||||
}
|
||||
getAllTax()
|
||||
|
||||
}, [token])
|
||||
|
||||
useEffect(() => {
|
||||
function getProductDetails() {
|
||||
@ -72,7 +87,7 @@ function AddOrder() {
|
||||
})
|
||||
.then((res) => {
|
||||
setLoading(false)
|
||||
// console.log(res.data.product)
|
||||
console.log(res.data.data)
|
||||
setAllFranchisee(res.data.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
@ -101,6 +116,7 @@ function AddOrder() {
|
||||
|
||||
}
|
||||
// ------------------------product handle------------------------------//
|
||||
|
||||
const handleGetSingleProduct = async (e) => {
|
||||
|
||||
|
||||
@ -115,7 +131,12 @@ function AddOrder() {
|
||||
price: res?.data?.product?.base_Price,
|
||||
id: res?.data?.product?._id,
|
||||
quantity: 1,
|
||||
image: res?.data?.product?.image?.url
|
||||
|
||||
image: res?.data?.product?.image?.url,
|
||||
taxRate: 0.0,
|
||||
taxName: '',
|
||||
taxId: '',
|
||||
PriceWithTax: res?.data?.product?.base_Price,
|
||||
}
|
||||
dispatch({ type: "addToCart", payload: options });
|
||||
|
||||
@ -131,7 +152,28 @@ function AddOrder() {
|
||||
})
|
||||
}
|
||||
|
||||
// const TaxRatechange = async (id, e) => {
|
||||
// // console.log(e.target.value)
|
||||
// // console.log(e.target.value.slice(4, 6))
|
||||
// // console.log(e.target.value.slice(12, 16))
|
||||
// // console.log(e.target.value.slice(23))
|
||||
|
||||
|
||||
// let taxDetails = {
|
||||
// name: e.target.value.slice(12, 16),
|
||||
// rate: e.target.value.slice(4, 6),
|
||||
// productId: id,
|
||||
// taxId: e.target.value.slice(24)
|
||||
|
||||
// }
|
||||
// dispatch({ type: "selectTax", payload: taxDetails });
|
||||
|
||||
// dispatch({ type: "calculatePrice" });
|
||||
// localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
|
||||
|
||||
// toast.success("Tax Added");
|
||||
|
||||
// }
|
||||
const handleRemove = (id) => {
|
||||
dispatch({
|
||||
type: "deleteFromCart",
|
||||
@ -144,6 +186,17 @@ function AddOrder() {
|
||||
};
|
||||
//increase qty
|
||||
const increaseQuantity = (id) => {
|
||||
if (
|
||||
tax === 1) {
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: 'Please select Tax Rate ',
|
||||
icon: 'error',
|
||||
button: 'Close',
|
||||
dangerMode: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
dispatch({
|
||||
type: "addToCart",
|
||||
payload: { id },
|
||||
@ -155,6 +208,17 @@ function AddOrder() {
|
||||
|
||||
|
||||
const decreaseQuantity = (id) => {
|
||||
if (
|
||||
tax === 1) {
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: 'Please select Tax Rate ',
|
||||
icon: 'error',
|
||||
button: 'Close',
|
||||
dangerMode: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
dispatch({
|
||||
type: "decrement",
|
||||
payload: id,
|
||||
@ -169,6 +233,7 @@ function AddOrder() {
|
||||
// ------------------------Frenchisee handle------------------------------//
|
||||
|
||||
const handleGetSingleFrenchisee = async () => {
|
||||
console.log(getFranchiseeID.current.value)
|
||||
|
||||
axios
|
||||
.get(`/api/Temple/arrayspopulate/${getFranchiseeID.current.value}`, {
|
||||
@ -179,7 +244,7 @@ function AddOrder() {
|
||||
})
|
||||
.then((res) => {
|
||||
setLoading(false)
|
||||
console.log(res.data.data)
|
||||
// console.log(res.data.data)
|
||||
let options = {
|
||||
id: res?.data?.data?._id,
|
||||
name: res?.data?.data?.name,
|
||||
@ -216,11 +281,33 @@ function AddOrder() {
|
||||
|
||||
};
|
||||
// ------------------------Frenchisee handle End------------------------------//
|
||||
console.log(AllStates.shipingInfo.franchisees.length)
|
||||
console.log(cartItems)
|
||||
console.log(AllStates.shipingInfo.franchisees)
|
||||
// cartItems.map(i => console.log(i.taxName))
|
||||
function handleSubmit() {
|
||||
if (
|
||||
AllStates.shipingInfo.franchisees.length < 1) {
|
||||
|
||||
|
||||
if (cartItems.length < 1) {
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: 'Please select atleast one product',
|
||||
icon: 'error',
|
||||
button: 'Close',
|
||||
dangerMode: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
// else if (cartItems.find(i => i.taxName === '')) {
|
||||
// swal({
|
||||
// title: 'Warning',
|
||||
// text: 'Please select tax rate for every Product',
|
||||
// icon: 'error',
|
||||
// button: 'Close',
|
||||
// dangerMode: true,
|
||||
// })
|
||||
// return
|
||||
// }
|
||||
else if (
|
||||
AllStates.shipingInfo.franchisees === null) {
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: 'Please select Franchisee ',
|
||||
@ -230,16 +317,7 @@ function AddOrder() {
|
||||
})
|
||||
return
|
||||
}
|
||||
else if (cartItems.length < 1) {
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: 'Please select atleast one product',
|
||||
icon: 'error',
|
||||
button: 'Close',
|
||||
dangerMode: true,
|
||||
})
|
||||
return
|
||||
} else if (
|
||||
else if (
|
||||
shipping === '' ||
|
||||
|
||||
tax === '' ||
|
||||
@ -257,6 +335,7 @@ function AddOrder() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
setLoading(true)
|
||||
// const formData = new FormData()
|
||||
// formData.set('orderItems', cartItems)
|
||||
@ -291,7 +370,7 @@ function AddOrder() {
|
||||
},
|
||||
)
|
||||
.then((res) => {
|
||||
console.log(res)
|
||||
// console.log(res)
|
||||
swal({
|
||||
title: 'Created',
|
||||
text: 'Order Created!',
|
||||
@ -436,13 +515,30 @@ function AddOrder() {
|
||||
<button className='btn btn-sm btn-primary' onClick={() => increaseQuantity(productDetails?.id)}>+</button>
|
||||
|
||||
</div>
|
||||
|
||||
{productDetails?.PriceWithTax && <p className="m-0 mt-3">
|
||||
<stong>Price With Tax:</stong> ₹{productDetails?.PriceWithTax}
|
||||
</p>}
|
||||
<button className='btn btn-danger btn-sm ms-2 mt-3' onClick={() => handleRemove(productDetails?.id)} >Delete</button>
|
||||
</div>
|
||||
<div className="col-sm-6">
|
||||
<h6 className="m-0 mt-3">
|
||||
<p className="m-0 mt-3">
|
||||
<stong> Price:</stong> ₹{productDetails?.price}
|
||||
</h6>
|
||||
{' '}
|
||||
</p>
|
||||
{/* {allTax.length > 0 && <div className="d-flex mt-4">
|
||||
<h6 className="me-2 mt-1">Tax:</h6>
|
||||
<select className=" " name="" id=""
|
||||
onChange={(e) => TaxRatechange(productDetails?.id, e)}
|
||||
>
|
||||
<option value="" disabled>---</option>
|
||||
|
||||
{allTax.map((t, i) =>
|
||||
<option key={i} value={`tax:${t.tax},name:${t.name} ,taxId:${t._id}`}>{t.tax}% {t.name}</option>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
} */}
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
@ -486,13 +582,13 @@ function AddOrder() {
|
||||
|
||||
|
||||
{
|
||||
AllStates.shipingInfo.franchisees && AllStates.shipingInfo.franchisees.map((franchiDetails, i) =>
|
||||
AllStates?.shipingInfo?.franchisees !== null &&
|
||||
<div className="my-2">
|
||||
<div className="row" style={{ fontSize: '14px' }}>
|
||||
<div className="col-sm-4">
|
||||
<img
|
||||
src={franchiDetails?.banner}
|
||||
alt={franchiDetails?.name}
|
||||
src={AllStates.shipingInfo.franchisees?.banner}
|
||||
alt={AllStates.shipingInfo.franchisees?.name}
|
||||
width='100%'
|
||||
// style={{
|
||||
// width: '100%',
|
||||
@ -502,21 +598,21 @@ function AddOrder() {
|
||||
/>
|
||||
</div>
|
||||
<div className="col-sm-8">
|
||||
<h6 className="m-0 ms-2">{franchiDetails?.name}</h6>
|
||||
<h6 className="m-0 ms-2">{AllStates.shipingInfo.franchisees?.name}</h6>
|
||||
<parent className="m-0 ms-2 mt-3">
|
||||
Address. : {franchiDetails?.address}
|
||||
Address. : {AllStates.shipingInfo.franchisees?.address}
|
||||
</parent>
|
||||
<p className="m-0 ms-2 mt-1">
|
||||
Contact No. : {franchiDetails?.contact_Number}
|
||||
Contact No. : {AllStates.shipingInfo.franchisees?.contact_Number}
|
||||
</p>
|
||||
<p className="m-0 ms-2 mt-1">
|
||||
contact Person Name. : {franchiDetails?.contact_Person_Name}
|
||||
contact Person Name. : {AllStates.shipingInfo.franchisees?.contact_Person_Name}
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<button className='btn btn-danger btn-sm ms-2 mt-2' onClick={() => FranchiseeRemove(franchiDetails?.id)} >Delete</button>
|
||||
<button className='btn btn-danger btn-sm ms-2 mt-2' onClick={() => FranchiseeRemove(AllStates.shipingInfo.franchisees?.id)} >Delete</button>
|
||||
|
||||
|
||||
</div>
|
||||
@ -524,7 +620,6 @@ function AddOrder() {
|
||||
<hr />
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
{/* <div className="mt-1">
|
||||
<label className="fw-bold">Address :</label>
|
||||
@ -652,7 +747,7 @@ function AddOrder() {
|
||||
})}
|
||||
</label>
|
||||
</div> */}
|
||||
<div className="mt-1">
|
||||
<div className="mt-3">
|
||||
<label>
|
||||
<span className="fw-bold">Razorpay Order ID : </span>
|
||||
{productData?.razorpay_order_id}
|
||||
|
818
src/views/orders/EditOrder.js
Normal file
818
src/views/orders/EditOrder.js
Normal file
@ -0,0 +1,818 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import React, { useState, useEffect, useRef } from 'react'
|
||||
import axios from 'axios'
|
||||
import { Link, useNavigate, useParams } from 'react-router-dom'
|
||||
import QRCode from 'react-qr-code'
|
||||
import { isAutheticated } from 'src/auth'
|
||||
import { useDispatch, useSelector } from 'react-redux'
|
||||
import { addItemsToCart } from 'src/redux/Actions/cartAction'
|
||||
import toast from 'react-hot-toast'
|
||||
import { cibBlackberry } from '@coreui/icons'
|
||||
import Button from '@material-ui/core/Button'
|
||||
// import PrintOrderDetails from './PrintOrderDetails.js'
|
||||
|
||||
function EditOrder() {
|
||||
const { status, id } = useParams()
|
||||
|
||||
const { cartItems, subTotal, tax, shipping, total } = useSelector(
|
||||
(state) => state.cart
|
||||
);
|
||||
// const { cart, shippingInfo } = useSelector(
|
||||
// (state) => state
|
||||
// );
|
||||
const AllStates = useSelector(
|
||||
(state) => state
|
||||
);
|
||||
console.log(AllStates.shipingInfo.franchisees)
|
||||
const getValue = useRef()
|
||||
const getFranchiseeID = useRef()
|
||||
const dispatch = useDispatch();
|
||||
const navigate = useNavigate()
|
||||
const printOrderRef = useRef()
|
||||
const token = isAutheticated()
|
||||
const [productData, setProductData] = useState([])
|
||||
const [allFranchisee, setAllFranchisee] = useState([])
|
||||
|
||||
|
||||
const [productDetails, setProductDetails] = useState()
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [orderStatus, setOrderStatus] = useState('')
|
||||
const [data, setData] = useState({
|
||||
product_Name: '',
|
||||
address: '',
|
||||
quantity: '',
|
||||
contact_Number: '',
|
||||
total_Price: '',
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
function getProductDetails() {
|
||||
setLoading(true)
|
||||
axios
|
||||
.get(`/api/product/getAll/`, {
|
||||
headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
|
||||
})
|
||||
.then((res) => {
|
||||
setLoading(false)
|
||||
// console.log(res.data.product)
|
||||
setProductData(res.data.product)
|
||||
})
|
||||
.catch((err) => {
|
||||
setLoading(false)
|
||||
// getBack()
|
||||
})
|
||||
}
|
||||
function getFranchiseeDetails() {
|
||||
setLoading(true)
|
||||
axios
|
||||
.get(`/api/temple`, {
|
||||
headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
|
||||
})
|
||||
.then((res) => {
|
||||
setLoading(false)
|
||||
// console.log(res.data.product)
|
||||
setAllFranchisee(res.data.data)
|
||||
})
|
||||
.catch((err) => {
|
||||
setLoading(false)
|
||||
// getBack()
|
||||
})
|
||||
}
|
||||
getProductDetails()
|
||||
getFranchiseeDetails()
|
||||
}, [])
|
||||
|
||||
const handleChange = (e) => {
|
||||
if (e.target.type === 'text') {
|
||||
setData((prev) => ({ ...prev, [e.target.id]: e.target.value }))
|
||||
} else {
|
||||
setOrderStatus(e.target.value)
|
||||
}
|
||||
}
|
||||
const handleQuantityChange = (e) => {
|
||||
|
||||
setData((prev) => ({
|
||||
...prev,
|
||||
quantity: e.target.value,
|
||||
total_Price: (productDetails?.base_Price * e.target.value)
|
||||
}))
|
||||
|
||||
}
|
||||
// ------------------------product handle------------------------------//
|
||||
const handleGetSingleProduct = async (e) => {
|
||||
|
||||
|
||||
axios
|
||||
.get(`/api/product/getOne/${getValue.current.value}`, {
|
||||
headers: { 'Access-Control-Allow-Origin': '*', Authorization: `Bearer ${token}` },
|
||||
})
|
||||
.then((res) => {
|
||||
setLoading(false)
|
||||
let options = {
|
||||
name: res?.data?.product?.name,
|
||||
price: res?.data?.product?.base_Price,
|
||||
id: res?.data?.product?._id,
|
||||
quantity: 1,
|
||||
image: res?.data?.product?.image?.url
|
||||
}
|
||||
dispatch({ type: "addToCart", payload: options });
|
||||
|
||||
dispatch({ type: "calculatePrice" });
|
||||
localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
|
||||
|
||||
toast.success("Product Added");
|
||||
|
||||
})
|
||||
.catch((err) => {
|
||||
setLoading(false)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
const handleRemove = (id) => {
|
||||
dispatch({
|
||||
type: "deleteFromCart",
|
||||
payload: id,
|
||||
});
|
||||
dispatch({ type: "calculatePrice" });
|
||||
localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
|
||||
toast.success("Item Removed");
|
||||
|
||||
};
|
||||
//increase qty
|
||||
const increaseQuantity = (id) => {
|
||||
dispatch({
|
||||
type: "addToCart",
|
||||
payload: { id },
|
||||
});
|
||||
dispatch({ type: "calculatePrice" });
|
||||
localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
|
||||
|
||||
}
|
||||
|
||||
|
||||
const decreaseQuantity = (id) => {
|
||||
dispatch({
|
||||
type: "decrement",
|
||||
payload: id,
|
||||
});
|
||||
|
||||
dispatch({ type: "calculatePrice" });
|
||||
localStorage.setItem("cartItems", JSON.stringify(AllStates.cart));
|
||||
|
||||
};
|
||||
// ------------------------product handle End------------------------------//
|
||||
|
||||
// ------------------------Frenchisee handle------------------------------//
|
||||
|
||||
const handleGetSingleFrenchisee = async () => {
|
||||
|
||||
axios
|
||||
.get(`/api/Temple/arrayspopulate/${getFranchiseeID.current.value}`, {
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
setLoading(false)
|
||||
console.log(res.data.data)
|
||||
let options = {
|
||||
id: res?.data?.data?._id,
|
||||
name: res?.data?.data?.name,
|
||||
|
||||
|
||||
contact_Number: res?.data?.data?.contact_Number,
|
||||
contact_Person_Name: res?.data?.data?.contact_Person_Name,
|
||||
address: (res?.data?.data?.address_line_1 + ' ' + res?.data?.data?.address_line_2),
|
||||
city: res?.data?.data?.city?.city_name,
|
||||
state: res?.data?.data?.city?.state?.state_name,
|
||||
banner: res?.data?.data?.banner?.url,
|
||||
Franchisee_Url: res?.data?.data?.url
|
||||
}
|
||||
|
||||
dispatch({ type: "addShippingInfo", payload: options });
|
||||
|
||||
localStorage.setItem("shippingInfo", JSON.stringify(AllStates.shipingInfo));
|
||||
|
||||
toast.success("Franchisee Added");
|
||||
|
||||
})
|
||||
.catch((err) => {
|
||||
setLoading(false)
|
||||
|
||||
})
|
||||
}
|
||||
const FranchiseeRemove = (id) => {
|
||||
dispatch({
|
||||
type: "deleteFromshippingInfo",
|
||||
payload: id,
|
||||
});
|
||||
localStorage.setItem("shippingInfo", JSON.stringify(AllStates.shipingInfo));
|
||||
toast.success("Franchisee Removed");
|
||||
|
||||
};
|
||||
// ------------------------Frenchisee handle End------------------------------//
|
||||
console.log(AllStates.shipingInfo.franchisees.length)
|
||||
console.log(cartItems)
|
||||
function handleSubmit() {
|
||||
if (
|
||||
AllStates.shipingInfo.franchisees.length < 1) {
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: 'Please select Franchisee ',
|
||||
icon: 'error',
|
||||
button: 'Close',
|
||||
dangerMode: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
else if (cartItems.length < 1) {
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: 'Please select atleast one product',
|
||||
icon: 'error',
|
||||
button: 'Close',
|
||||
dangerMode: true,
|
||||
})
|
||||
return
|
||||
} else if (
|
||||
shipping === '' ||
|
||||
|
||||
tax === '' ||
|
||||
total === ''
|
||||
|
||||
) {
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: 'Fill all mandatory fields',
|
||||
icon: 'error',
|
||||
button: 'Close',
|
||||
dangerMode: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
|
||||
setLoading(true)
|
||||
// const formData = new FormData()
|
||||
// formData.set('orderItems', cartItems)
|
||||
|
||||
|
||||
// formData.set('shippingInfo', AllStates.shipingInfo.franchisees)
|
||||
// formData.set('shipping_charge', shipping)
|
||||
// formData.set('tax_amount', tax)
|
||||
// formData.set('total_amount', total)
|
||||
|
||||
|
||||
|
||||
setLoading(true)
|
||||
axios
|
||||
.post(
|
||||
`/api/order/create`,
|
||||
{
|
||||
orderItems: cartItems,
|
||||
shippingInfo: AllStates.shipingInfo.franchisees,
|
||||
shipping_charge: shipping,
|
||||
tax_amount: tax,
|
||||
total_amount: total
|
||||
|
||||
|
||||
},
|
||||
|
||||
{
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
},
|
||||
)
|
||||
.then((res) => {
|
||||
console.log(res)
|
||||
swal({
|
||||
title: 'Created',
|
||||
text: 'Order Created!',
|
||||
icon: 'success',
|
||||
button: 'ok',
|
||||
})
|
||||
setLoading(false)
|
||||
navigate('/orders/new')
|
||||
})
|
||||
.catch((err) => {
|
||||
setLoading(false)
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: 'Something went wrong!',
|
||||
icon: 'error',
|
||||
button: 'Retry',
|
||||
dangerMode: true,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
function getBack() {
|
||||
navigate(`/orders/${status}`, { replace: true })
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
{' '}
|
||||
<div className="main-content">
|
||||
<div className="page-content">
|
||||
<div className="container-fluid">
|
||||
<div className="row">
|
||||
<div className="col-12">
|
||||
<div
|
||||
className="
|
||||
page-title-box
|
||||
d-flex
|
||||
align-items-center
|
||||
justify-content-between
|
||||
"
|
||||
>
|
||||
<div style={{ fontSize: '22px' }} className="fw-bold">
|
||||
Edit Order
|
||||
</div>
|
||||
<div className="page-title-right">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="primary"
|
||||
style={{
|
||||
fontWeight: 'bold',
|
||||
marginBottom: '1rem',
|
||||
textTransform: 'capitalize',
|
||||
marginRight: '5px',
|
||||
}}
|
||||
onClick={() => handleSubmit()}
|
||||
disabled={loading}
|
||||
>
|
||||
{loading ? 'Loading' : ' Edit Order'}
|
||||
</Button>
|
||||
<Link to="/orders/new">
|
||||
<Button
|
||||
variant="contained"
|
||||
color="secondary"
|
||||
style={{
|
||||
fontWeight: 'bold',
|
||||
marginBottom: '1rem',
|
||||
textTransform: 'capitalize',
|
||||
}}
|
||||
>
|
||||
Back
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
<div className="row">
|
||||
<div className="col-lg-7 mt-3">
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<div className="mt-1">
|
||||
<label className="fw-bold">Select Product:</label>
|
||||
<div className="d-flex">
|
||||
<select
|
||||
className="form-control me-2"
|
||||
// onChange={handleGetSingleProduct}
|
||||
// value={productData?._id}
|
||||
ref={getValue}
|
||||
|
||||
>
|
||||
<option value="" >-----</option>
|
||||
{productData && productData.map((item, index) =>
|
||||
<option key={index} value={item?._id}>{item?.name}</option>
|
||||
)}
|
||||
|
||||
</select>
|
||||
<button className='btn-sm btn-primary' onClick={(e) => handleGetSingleProduct(e)}>Add</button>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<div className="mt-2">
|
||||
<label className="fw-bold">Product :</label>
|
||||
|
||||
{
|
||||
cartItems && cartItems.map((productDetails, i) =>
|
||||
<div className="my-2">
|
||||
<div className="row" style={{ fontSize: '14px' }}>
|
||||
<div className="col-sm-4">
|
||||
<img
|
||||
src={productDetails?.image}
|
||||
alt={productDetails?.name}
|
||||
style={{
|
||||
width: '100%',
|
||||
objectFit: 'contain',
|
||||
maxHeight: '150px',
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-sm-8">
|
||||
<h6 className="m-0 ms-2">{productDetails?.name}</h6>
|
||||
<div className="row">
|
||||
<div className="col-sm-6">
|
||||
|
||||
|
||||
<div
|
||||
className='d-flex justify-content-center mt-3 me-3 '
|
||||
style={{
|
||||
|
||||
width: "6rem",
|
||||
|
||||
|
||||
}}>
|
||||
<button className='btn btn-sm btn-primary ' onClick={() => decreaseQuantity(productDetails?.id)} >-</button>
|
||||
<span className='px-2 mt-1' style={{}}>{productDetails?.quantity}</span>
|
||||
<button className='btn btn-sm btn-primary' onClick={() => increaseQuantity(productDetails?.id)}>+</button>
|
||||
|
||||
</div>
|
||||
<button className='btn btn-danger btn-sm ms-2 mt-3' onClick={() => handleRemove(productDetails?.id)} >Delete</button>
|
||||
</div>
|
||||
<div className="col-sm-6">
|
||||
<h6 className="m-0 mt-3">
|
||||
<stong> Price:</stong> ₹{productDetails?.price}
|
||||
</h6>
|
||||
{' '}
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
{subTotal && <h5 className="m-0 contents-center mt-3">
|
||||
<span> Total Order Value:</span> ₹{subTotal}
|
||||
</h5>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="col-lg-5 mt-3">
|
||||
<div className="card">
|
||||
<div className="card-body">
|
||||
<div className="mt-1">
|
||||
<label className="fw-bold">Franchisee :</label>
|
||||
<div className="d-flex">
|
||||
<select
|
||||
className="form-control me-2"
|
||||
onChange={handleChange}
|
||||
value={orderStatus}
|
||||
ref={getFranchiseeID}
|
||||
>
|
||||
<option value="" disabled></option>
|
||||
{allFranchisee && allFranchisee.map((item, index) =>
|
||||
<option key={index} value={item?._id}>{item?.name}</option>
|
||||
)}
|
||||
</select>
|
||||
<button className='btn-sm btn-primary' onClick={(e) => handleGetSingleFrenchisee(e)} >Add</button>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
{
|
||||
AllStates.shipingInfo.franchisees && AllStates.shipingInfo.franchisees.map((franchiDetails, i) =>
|
||||
<div className="my-2">
|
||||
<div className="row" style={{ fontSize: '14px' }}>
|
||||
<div className="col-sm-4">
|
||||
<img
|
||||
src={franchiDetails?.banner}
|
||||
alt={franchiDetails?.name}
|
||||
width='100%'
|
||||
// style={{
|
||||
// width: '100%',
|
||||
// objectFit: 'contain',
|
||||
// maxHeight: '100px',
|
||||
// }}
|
||||
/>
|
||||
</div>
|
||||
<div className="col-sm-8">
|
||||
<h6 className="m-0 ms-2">{franchiDetails?.name}</h6>
|
||||
<parent className="m-0 ms-2 mt-3">
|
||||
Address. : {franchiDetails?.address}
|
||||
</parent>
|
||||
<p className="m-0 ms-2 mt-1">
|
||||
Contact No. : {franchiDetails?.contact_Number}
|
||||
</p>
|
||||
<p className="m-0 ms-2 mt-1">
|
||||
contact Person Name. : {franchiDetails?.contact_Person_Name}
|
||||
</p>
|
||||
|
||||
|
||||
|
||||
|
||||
<button className='btn btn-danger btn-sm ms-2 mt-2' onClick={() => FranchiseeRemove(franchiDetails?.id)} >Delete</button>
|
||||
|
||||
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
|
||||
</div>
|
||||
)
|
||||
}
|
||||
{/* <div className="mt-1">
|
||||
<label className="fw-bold">Address :</label>
|
||||
</div>
|
||||
<div className="mt-1">
|
||||
<label className="fw-bold">Contact Number :</label>
|
||||
</div> */}
|
||||
{/* <div className="mt-3">
|
||||
<label>
|
||||
<span className="fw-bold">Order ID: {productData?.order_id}</span>
|
||||
</label>
|
||||
</div> */}
|
||||
|
||||
{/* <div className="mt-3">
|
||||
{productData?.order_id && (
|
||||
<div className="d-flex">
|
||||
<p className="fw-bold me-3">Order ID QR Code:</p>
|
||||
<QRCode
|
||||
value={JSON.stringify({ order_id: productData?.order_id })}
|
||||
size={256}
|
||||
style={{ height: '150px', width: '150px' }}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div> */}
|
||||
{/* {productData.status === 'processing' && (
|
||||
<>
|
||||
<div className="mt-3">
|
||||
<label className="fw-bold">Courier Name* :</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-control"
|
||||
id="courier_name"
|
||||
value={data.courier_name}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-3">
|
||||
<label className="fw-bold">Tracking ID* :</label>
|
||||
<input
|
||||
type="text"
|
||||
className="form-control"
|
||||
id="tracking_id"
|
||||
value={data.tracking_id}
|
||||
onChange={handleChange}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)} */}
|
||||
{/* <div className="mt-3">
|
||||
<label>
|
||||
<span className="fw-bold">Amount Paid : </span>Rs.{productData?.total_amount}
|
||||
</label>
|
||||
</div> */}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{/* {productData?.address && (
|
||||
<>
|
||||
<div className="mt-1">
|
||||
<label>
|
||||
<span className="fw-bold">Address : </span>
|
||||
{`${productData.address?.full_name}, ${productData.address?.flat_house_no_apartment
|
||||
}, ${productData.address?.area_street_sector_village}, ${productData.address?.landmark && productData.address?.landmark + ', '
|
||||
}${productData.address?.address_line &&
|
||||
productData.address?.address_line + ', '
|
||||
}${productData.address?.city}, ${productData.address?.state}, ${productData.address?.pincode
|
||||
}`}
|
||||
</label>
|
||||
</div>
|
||||
<div className="mt-1">
|
||||
<label>
|
||||
{' '}
|
||||
<span className="fw-bold">Contact Number : </span>
|
||||
{productData.address?.mobile_number}
|
||||
</label>
|
||||
</div>
|
||||
</>
|
||||
)} */}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{/* {productData?.courier_name && (
|
||||
<div className="mt-1">
|
||||
<label>
|
||||
<span className="fw-bold">Courier Name : </span>
|
||||
{productData?.courier_name}
|
||||
</label>
|
||||
</div>
|
||||
)}
|
||||
{productData?.tracking_id && (
|
||||
<div className="mt-1">
|
||||
<label>
|
||||
<span className="fw-bold">Tracking ID : </span>
|
||||
{productData?.tracking_id}
|
||||
</label>
|
||||
</div>
|
||||
)} */}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
{/* <div className="mt-1">
|
||||
<label>
|
||||
<span className="fw-bold">Order Placed On : </span>
|
||||
{new Date(productData?.placed_on).toLocaleString('en-IN', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: 'numeric',
|
||||
hour12: true,
|
||||
})}
|
||||
</label>
|
||||
</div> */}
|
||||
<div className="mt-1">
|
||||
<label>
|
||||
<span className="fw-bold">Razorpay Order ID : </span>
|
||||
{productData?.razorpay_order_id}
|
||||
</label>
|
||||
</div>{' '}
|
||||
<div className="mt-1">
|
||||
<label>
|
||||
<span className="fw-bold">Razorpay Payment ID : </span>
|
||||
{productData?.razorpay_payment_id}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="card my-1">
|
||||
<div className="card-body">
|
||||
<label className="fw-bold">Status Timeline :</label>
|
||||
<table
|
||||
className="table table-info table-sm m-0"
|
||||
style={{
|
||||
borderRadius: '8px',
|
||||
borderCollapse: 'collapse',
|
||||
overflow: 'hidden',
|
||||
}}
|
||||
>
|
||||
<tbody>
|
||||
<tr className="text-center">
|
||||
<th scope="row">Order Placed On</th>
|
||||
<td> : </td>
|
||||
<td>
|
||||
{productData?.status_timeline?.new
|
||||
? new Date(productData?.status_timeline?.new).toLocaleString('en-IN', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: 'numeric',
|
||||
hour12: true,
|
||||
})
|
||||
: new Date(productData?.placed_on).toLocaleString('en-IN', {
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: 'numeric',
|
||||
hour12: true,
|
||||
})}
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="text-center">
|
||||
<th scope="row">Processing Started</th>
|
||||
<td> : </td>
|
||||
<td>
|
||||
{productData?.status_timeline?.processing
|
||||
? new Date(productData?.status_timeline?.processing).toLocaleString(
|
||||
'en-IN',
|
||||
{
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: 'numeric',
|
||||
hour12: true,
|
||||
},
|
||||
)
|
||||
: '-'}
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="text-center">
|
||||
<th scope="row">Dispatched On</th>
|
||||
<td> : </td>
|
||||
<td>
|
||||
{productData?.status_timeline?.dispatched
|
||||
? new Date(productData?.status_timeline?.dispatched).toLocaleString(
|
||||
'en-IN',
|
||||
{
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: 'numeric',
|
||||
hour12: true,
|
||||
},
|
||||
)
|
||||
: '-'}
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="text-center">
|
||||
<th scope="row">Delivered On</th>
|
||||
<td> : </td>
|
||||
<td>
|
||||
{productData?.status_timeline?.delivered
|
||||
? new Date(productData?.status_timeline?.delivered).toLocaleString(
|
||||
'en-IN',
|
||||
{
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: 'numeric',
|
||||
hour12: true,
|
||||
},
|
||||
)
|
||||
: '-'}
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="text-center">
|
||||
<th scope="row">Cancelled On</th>
|
||||
<td> : </td>
|
||||
<td>
|
||||
{productData?.status_timeline?.cancelled
|
||||
? new Date(productData?.status_timeline?.cancelled).toLocaleString(
|
||||
'en-IN',
|
||||
{
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: 'numeric',
|
||||
hour12: true,
|
||||
},
|
||||
)
|
||||
: '-'}
|
||||
</td>
|
||||
</tr>
|
||||
<tr className="text-center">
|
||||
<th scope="row">Returned On</th>
|
||||
<td> : </td>
|
||||
<td>
|
||||
{productData?.status_timeline?.returned
|
||||
? new Date(productData?.status_timeline?.returned).toLocaleString(
|
||||
'en-IN',
|
||||
{
|
||||
month: 'short',
|
||||
day: 'numeric',
|
||||
year: 'numeric',
|
||||
hour: '2-digit',
|
||||
minute: 'numeric',
|
||||
hour12: true,
|
||||
},
|
||||
)
|
||||
: '-'}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div style={{ display: 'none' }}>
|
||||
{/* <PrintOrderDetails productData={productData} ref={printOrderRef} /> */}
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default EditOrder
|
@ -37,7 +37,7 @@ function NewOrders() {
|
||||
})
|
||||
}
|
||||
getNewOrder()
|
||||
}, [])
|
||||
}, [success])
|
||||
|
||||
useEffect(() => {
|
||||
const loadData = () => {
|
||||
@ -48,6 +48,38 @@ function NewOrders() {
|
||||
loadData()
|
||||
}, [currentPage, itemPerPage, newOrdersData])
|
||||
|
||||
|
||||
const handleDelete = (id) => {
|
||||
console.log(id)
|
||||
swal({
|
||||
title: 'Are you sure?',
|
||||
icon: 'error',
|
||||
buttons: { Yes: { text: 'Yes', value: true }, Cancel: { text: 'Cancel', value: 'cancel' } },
|
||||
}).then((value) => {
|
||||
if (value === true) {
|
||||
axios
|
||||
.delete(`/api/order/delete/${id}`, {
|
||||
headers: {
|
||||
'Access-Control-Allow-Origin': '*',
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
})
|
||||
.then((res) => {
|
||||
setSuccess((prev) => !prev)
|
||||
})
|
||||
.catch((err) => {
|
||||
swal({
|
||||
title: 'Warning',
|
||||
text: err.response.data.message ? err.response.data.message : 'Something went wrong!',
|
||||
icon: 'error',
|
||||
button: 'Retry',
|
||||
dangerMode: true,
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="main-content">
|
||||
<div className="page-content">
|
||||
@ -150,7 +182,7 @@ function NewOrders() {
|
||||
return (
|
||||
<tr key={i}>
|
||||
<td className="text-start">{order?.order_id}</td>
|
||||
<td className="text-start">{order?.user?.name}</td>
|
||||
<td className="text-start">{order?.shippingInfo?.name}</td>
|
||||
<td className="text-start">₹{order?.total_amount}</td>
|
||||
<td className="text-start">
|
||||
{new Date(order?.createdAt).toLocaleString('en-IN', {
|
||||
@ -176,12 +208,41 @@ function NewOrders() {
|
||||
btn btn-primary btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
ms-2
|
||||
ms-2 mt-1
|
||||
"
|
||||
>
|
||||
View
|
||||
</button>
|
||||
</Link>
|
||||
<Link to={`/orders/edit/${order._id}`}>
|
||||
<button
|
||||
style={{ color: 'white' }}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-info btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
ms-2 mt-1
|
||||
"
|
||||
>
|
||||
Edit
|
||||
</button>
|
||||
</Link>
|
||||
|
||||
<button
|
||||
style={{ color: 'white' }}
|
||||
type="button"
|
||||
className="
|
||||
btn btn-danger btn-sm
|
||||
waves-effect waves-light
|
||||
btn-table
|
||||
ms-2 mt-1
|
||||
"
|
||||
onClick={() => handleDelete(order._id)}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user