Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
ElyasMehraein committed Apr 29, 2024
2 parents 54080dc + f29716e commit a0b355b
Show file tree
Hide file tree
Showing 2 changed files with 101 additions and 73 deletions.
172 changes: 100 additions & 72 deletions components/templates/index/Bills/CreateBill.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField";
import Button from '@mui/material/Button';
import Autocomplete from '@mui/material/Autocomplete';
import { Accordion, AccordionDetails, Chip, Container } from "@mui/material";
import { Accordion, AccordionDetails, Chip, CircularProgress, Container } from "@mui/material";
import CreateBillFrame from "./CreateBillFrame";
import CustomSnackbar from "@/components/modules/CustomSnackbar";
import QuestionMarkOutlinedIcon from '@mui/icons-material/QuestionMarkOutlined';
import IconButton from '@mui/material/IconButton';
import CloseIcon from '@mui/icons-material/Close';

export default function CreateBill({ user }) {
export default function CreateBill({ user, fabHandler }) {
const [isLoading, setIsLoading] = React.useState(false);

const userBusinesses = user.businesses.map(business => {
if (business.agentCode == user.code) {
Expand Down Expand Up @@ -44,6 +47,8 @@ export default function CreateBill({ user }) {
setOpenSnackbar(true);
};
async function createThisBill(selectedBusiness, customerCode, bills) {
fabHandler();
setIsLoading(true);
const res = await fetch('api/createBill', {
method: "POST",
headers: { 'Content-Type': 'application/json' },
Expand All @@ -54,6 +59,7 @@ export default function CreateBill({ user }) {
} else if (res.status === 201) {
console.log("bill signed successfully");
handleShowSnackbar()
setIsLoading(false)
} else if (res.status === 404) {
setOpenSnackbar404Error(true)
} else if (res.status === 406) {
Expand All @@ -65,6 +71,10 @@ export default function CreateBill({ user }) {
const [expanded, setExpanded] = React.useState(false);
return (
<Container maxWidth="md">

{/* <Box className="inMiddle">
<CircularProgress />
</Box>: */}
<Accordion sx={{ boxShadow: 0 }} expanded={expanded}>
<Chip
label="راهنمایی"
Expand Down Expand Up @@ -110,82 +120,100 @@ export default function CreateBill({ user }) {
{user ?
<>
{userBusinesses[0] ?
<>
<Typography sx={{ m: 1 }}>ایجاد صورتحساب</Typography>
<Autocomplete
blurOnSelect
id="combo-box-demo"
options={userBusinesses}
sx={{ m: 2, width: 300 }}
renderInput={(params) => <TextField {...params} label="انتخاب کسب و کار" />}
onChange={(e, value) => setSelectedBusiness(value)}
/>
{selectedBusiness &&
<>
{selectedBusiness.products ?
isLoading ? <Box className="inMiddle">
<CircularProgress />
</Box>

:
<>
<Box
sx={{
display: "flex",
justifyContent: "space-between",
// justifyContent:"space-around",
width: "100%"
}}
>
<Typography sx={{ mr: 5, mt: 1 }}>ایجاد صورتحساب</Typography>
<IconButton aria-label="settings" onClick={() => fabHandler()}>
<CloseIcon />
</IconButton>
</Box>

<Autocomplete
blurOnSelect
id="combo-box-demo"
options={userBusinesses}
sx={{ m: 2, width: 300 }}
renderInput={(params) => <TextField {...params} label="انتخاب کسب و کار" />}
onChange={(e, value) => setSelectedBusiness(value)}
/>
{selectedBusiness &&
<>
{selectedBusiness.products ?

<modulesAutocomplete optionsArray={products} label={"انتخاب محصول"} addMessage={"ایجاد محصول جدید"} onChangeHandler={(inputValue) => setSelectedProduct(inputValue)} />
:
<>
<TextField
value={selectedProduct}
<modulesAutocomplete optionsArray={products} label={"انتخاب محصول"} addMessage={"ایجاد محصول جدید"} onChangeHandler={(inputValue) => setSelectedProduct(inputValue)} />
:
<>
<TextField
value={selectedProduct}

placeholder='حداکثر 30 کارکتر' variant="outlined"
label="محصولی که ارائه نموده اید"
onChange={(e) => setSelectedProduct(e.target.value)}
sx={{ width: 300 }}
/>
<TextField
value={unitOfMeasurement}
placeholder='حداکثر 30 کارکتر' variant="outlined"
label="محصولی که ارائه نموده اید"
onChange={(e) => setSelectedProduct(e.target.value)}
sx={{ width: 300 }}
/>
<TextField
value={unitOfMeasurement}

placeholder="مثلا کیلوگرم یا عدد" variant="outlined"
label="واحد اندازه گیری"
onChange={(e) => setUnitOfMeasurement(e.target.value)}
sx={{ mt: 2, width: 300 }}
/>
</>
}
<TextField
value={amount}
placeholder="مثلا 5" variant="outlined"
label="مقدار"
onChange={(e) => setAmount(e.target.value)}
sx={{ mt: 2, width: 300 }}
type="number"
/>
placeholder="مثلا کیلوگرم یا عدد" variant="outlined"
label="واحد اندازه گیری"
onChange={(e) => setUnitOfMeasurement(e.target.value)}
sx={{ mt: 2, width: 300 }}
/>
</>
}
<TextField
value={amount}
placeholder="مثلا 5" variant="outlined"
label="مقدار"
onChange={(e) => setAmount(e.target.value)}
sx={{ mt: 2, width: 300 }}
type="number"
/>

<Button
sx={{ mt: 2 }}
children={"اضافه نمودن به فاکتور"}
variant="contained"
onClick={addToBills}
/>
{bills[0] &&
<>
{bills.map(bill => {
return <CreateBillFrame key={bill.id} {...bill} deleteFrame={deleteFrame} />
<Button
sx={{ mt: 2 }}
children={"اضافه نمودن به فاکتور"}
variant="contained"
onClick={addToBills}
/>
{bills[0] &&
<>
{bills.map(bill => {
return <CreateBillFrame key={bill.id} {...bill} deleteFrame={deleteFrame} />

})
}
<TextField
value={customerCode}
placeholder="در پروفایل کاربران قابل مشاهده است" variant="outlined"
label=" کد کاربری مشتری"
onChange={(e) => setCustomerCode(e.target.value)}
sx={{ mt: 2, width: 300 }}
/>
< Button
sx={{ mt: 2 }}
children={"ارسال صورتحساب"}
variant="contained"
onClick={() => createThisBill(selectedBusiness, customerCode, bills)}
/>
})
}
<TextField
value={customerCode}
placeholder="در پروفایل کاربران قابل مشاهده است" variant="outlined"
label=" کد کاربری مشتری"
onChange={(e) => setCustomerCode(e.target.value)}
sx={{ mt: 2, width: 300 }}
/>
< Button
sx={{ mt: 2 }}
children={"ارسال صورتحساب"}
variant="contained"
onClick={() => createThisBill(selectedBusiness, customerCode, bills)}
/>

</>
}
</>
}
</>
</>
}
</>
}
</>
:
<Typography color="error">
ارسال صورتحساب تنها توسط نماینده کسب و کار امکانپذیر است
Expand Down
2 changes: 1 addition & 1 deletion components/templates/index/Tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export default function BasicTabs({ user, bills, distinctGuilds }) {
<CustomTabPanel value={value} index={2} dir={theme.direction}>
{
fabIndex === 2 ?
<CreateBill user={user} />
<CreateBill user={user} fabHandler={fabHandler} />
:
<Bill bills={bills} user={user} />
}
Expand Down

0 comments on commit a0b355b

Please sign in to comment.