Commit b5144226 by tdgiang

update code

parent 0ee66d2b
......@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8" />
<!-- <link rel="shortcut icon" href="%PUBLIC_URL%/logo.png" /> -->
<link rel="shortcut icon" href="%PUBLIC_URL%/logo.png" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<!--
......
......@@ -17,6 +17,7 @@ import MerchantRoutes from './views/Merchant/MerchantRoutes'
import GasStationRoutes from './views/GasStation/GasStationRoutes'
import ListRequestRoutes from './views/ListRequest/routes'
import SignUp from './views/SignUp/routes'
import InvoiceSupplier from './views/InvoiceSupplier/routes'
const redirectRoute = [
{
......@@ -33,6 +34,7 @@ const errorRoute = [
]
const routes = [
...InvoiceSupplier,
...SignUp,
...ListRequestRoutes,
...GasStationRoutes,
......
/* eslint-disable handle-callback-err */
import { PostData, GetURL } from '../helpers'
import url from '../url'
export const getListInvoiceSupp = async (body) =>
PostData(url.urlGetListInvoiceSupp, body)
.then((res) => res)
.catch((err) => null)
export const createInvoiceSupp = async (body) =>
PostData(url.urlCreateInvoiceSupp, body)
.then((res) => res)
.catch((err) => null)
export const updateInvoiceSupp = async (body) =>
PostData(url.urlUpdateInvoiceSupp, body)
.then((res) => res)
.catch((err) => null)
export const detailInvoiceSupp = async (id, body) =>
GetURL(`${url.urlDetailInvoiceSupp}/${id}`, body)
.then((res) => res)
.catch((err) => null)
export const deleteInvoiceSupp = async (body) =>
PostData(url.urlDeleteInvoiceSupp, body)
.then((res) => res)
.catch((err) => null)
export const changeStatusInvoiceSupp = async (body) =>
PostData(url.changeStatusInvoiceSupp, body)
.then((res) => res)
.catch((err) => null)
......@@ -84,6 +84,14 @@ export default {
deleteGasOnline: `${root}/gasoline/delete`,
deleteGasField: `${root}/gasfield/delete`,
//Supplier Invoice
urlGetListInvoiceSupp: `${root}/supplierInvoice/list`,
urlCreateInvoiceSupp: `${root}/supplierInvoice/create`,
urlUpdateInvoiceSupp: `${root}/supplierInvoice/update`,
urlDeleteInvoiceSupp: `${root}/supplierInvoice/delete`,
urlDetailInvoiceSupp: `${root}/supplierInvoice`,
changeStatusInvoiceSupp: `${root}/supplierInvoice/changeStatus`,
//Log
logAuth: `${root}/logging/listLogin`,
logApi: `${root}/logging/listCallApi`,
......
......@@ -352,6 +352,7 @@
"ERROR_CODE_IS_EXISTS":"Mã code đã tồn tại",
"ERROR_NAME_IS_EXISTS":"Tên sản phẩm đã tồn tại",
"ERROR_MERCHAN_STORE_CODE_EXIST":"Mã cây xăng đã tồn tại",
"ERROR_CODE_IS_EXITS":"Mã code đã tồn tại",
......
......@@ -3,20 +3,43 @@ import { Avatar, Typography, Badge } from '@material-ui/core'
import PhotoCamera from '@material-ui/icons/PhotoCamera'
import { toast } from 'react-toastify'
import { apiUploadFile } from 'app/apis/Functions/Upload.js'
const supportedExtensions = ['jpeg', 'jpg', 'png']
const validateImg = (string) => {
const path = string.name.split('.')
const extension = `${path[path.length - 1]}`
if (supportedExtensions.includes(extension)) {
return true
// TODO: upload
} else {
// TODO: show "invalid file type" message to user
// reset value
return false
}
}
function UploadButtons(props) {
const { image, onFileChange } = props
const upLoadImage = async (event) => {
const res = await apiUploadFile(
createFormData(event.target.files[0], {})
)
if (res.data.status == 200 && res.data.data) {
onFileChange(res.data.data[0].url)
toast.success('Upload ảnh thành công!', {
theme: 'colored',
})
if (validateImg(event.target.files[0])) {
const res = await apiUploadFile(
createFormData(event.target.files[0], {})
)
if (res.data.status == 200 && res.data.data) {
onFileChange(res.data.data[0].url)
toast.success('Upload ảnh thành công!', {
theme: 'colored',
})
} else {
toast.success('Upload ảnh thất bại!', {
theme: 'colored',
})
}
} else {
toast.success('Upload ảnh thất bại!', {
toast.warn('File không đúng định dạng!', {
theme: 'colored',
})
}
......
......@@ -7,22 +7,46 @@ import { apiUploadFile } from 'app/apis/Functions/Upload.js'
import { CKEditor } from '@ckeditor/ckeditor5-react'
const supportedExtensions = ['jpeg', 'jpg', 'png']
const validateImg = (string) => {
const path = string.name.split('.')
const extension = `${path[path.length - 1]}`
if (supportedExtensions.includes(extension)) {
return true
// TODO: upload
} else {
// TODO: show "invalid file type" message to user
// reset value
return false
}
}
function UploadButtons(props) {
const { images, onFileChange, title } = props
const upLoadImage = async (event) => {
const res = await apiUploadFile(
createFormData(event.target.files[0], {})
)
console.log('res image', res)
if (res.data.status == 200 && res.data.data) {
console.log(res.data.data[0].url)
onFileChange(res.data.data[0].url)
toast.success('Upload ảnh thành công!', {
theme: 'colored',
})
if (validateImg(event.target.files[0])) {
const res = await apiUploadFile(
createFormData(event.target.files[0], {})
)
console.log('res image', res)
if (res.data.status == 200 && res.data.data) {
console.log(res.data.data[0].url)
onFileChange(res.data.data[0].url)
toast.success('Upload ảnh thành công!', {
theme: 'colored',
})
} else {
toast.success('Upload ảnh thất bại!', {
theme: 'colored',
})
}
} else {
toast.success('Upload ảnh thất bại!', {
toast.warn('File không đúng định dạng!', {
theme: 'colored',
})
}
......
......@@ -241,6 +241,14 @@ export const navigationsAdmin = [
},
{
name: 'NCC hoá đơn',
iconText: 'IV',
path: '/invoice-supplier',
hide: false,
id: 'INVOICE_SUPPLIER',
},
{
name: 'Log login,logout',
iconText: 'NO',
path: '/system/log-auth',
......
import React, { useState, useEffect } from 'react'
import ToolUserView from './View'
import {
getListInvoiceSupp,
changeStatusInvoiceSupp,
deleteInvoiceSupp,
} from 'app/apis/Functions/supplierInvoice'
import { useHistory } from 'react-router-dom'
import KEY from 'app/assets/Key'
import { connect } from 'react-redux'
import { showLoading, hideLoading } from 'app/redux/actions/loadingAction'
import { toast } from 'react-toastify'
import useDebounce from 'app/hooks/useDebounce'
import { useTranslation } from 'react-i18next'
import { dropdownProductType } from 'app/apis/Functions/dropdown'
const ToolNotificate = (props) => {
const [txtSearch, setTxtSearch] = useState('')
const [activeSelected, setActiveSeleted] = useState(null)
const [changeActive, setChangeActive] = useState(1)
const searchDebount = useDebounce(txtSearch, 1000)
const [status, setStatus] = useState()
const [pageIndex, setPageIndex] = useState(0)
const [pageSize] = useState(10)
const [totalRecords, setTotalRecord] = useState(0)
const [type, setType] = useState()
const [listType, setListType] = useState([])
const history = useHistory()
const { t } = useTranslation()
const [data, setData] = useState([])
const [permissions, setPermissions] = useState([])
useEffect(() => {}, [])
const handeChangeActive = async (id, status_id) => {
props.showLoading()
const res = await changeStatusInvoiceSupp({ id, status_id })
props.hideLoading()
if (res.data.code == 200) {
getData()
toast.success('Thay đổi trạng thái thành công!', {
theme: 'colored',
})
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
const getData = async (init) => {
props.showLoading()
let res
if (init) {
setPageIndex(0)
res = await getListInvoiceSupp({
supplier_code: searchDebount,
page_no: 0,
page_size: pageSize,
status,
type_id: type,
})
} else {
res = await getListInvoiceSupp({
supplier_code: searchDebount,
page_no: pageIndex + 1,
page_size: pageSize,
status,
type_id: type,
})
}
props.hideLoading()
console.log(res.data)
if (res.data.code == 200 && res.data.data) {
console.log(res.data)
const newList = res.data.data.data.map((e, i) => {
return { ...e, index: i + 1 + pageIndex * pageSize }
})
setData(newList)
setTotalRecord(res.data.data.total_elements)
} else if (res.data.code == 401) {
localStorage.removeItem(KEY.API_TOKEN)
setTimeout(() => {
history.push('/')
}, 100)
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
useEffect(() => {
getData(false)
}, [pageIndex])
useEffect(() => {
getData(true)
}, [searchDebount, status, type])
const removeItem = async (id) => {
props.showLoading()
const res = await deleteInvoiceSupp({ id })
props.hideLoading()
if (res.data.code == 200) {
getData()
toast.success('Xoá bản ghi thành công!', {
theme: 'colored',
})
} else if (res.data.code == 401) {
localStorage.removeItem(KEY.API_TOKEN)
setTimeout(() => {
history.push('/')
}, 100)
} else {
toast.error(t(res.data.error), {
theme: 'colored',
})
}
}
return (
<ToolUserView
data={data}
removeItem={removeItem}
setTxtSearch={setTxtSearch}
setActiveSeleted={setActiveSeleted}
pageIndex={pageIndex}
changeActive={changeActive}
setChangeActive={setChangeActive}
setPageIndex={setPageIndex}
activeSelected={activeSelected}
handeChangeActive={handeChangeActive}
totalRecords={totalRecords}
permissions={permissions}
status={status}
setStatus={setStatus}
listType={listType}
type={type}
setType={setType}
/>
)
}
const mapStateToProps = (state) => {
return {}
}
export default connect(mapStateToProps, { showLoading, hideLoading })(
ToolNotificate
)
import React, { Fragment, useState, useEffect } from 'react'
import {
TextField,
Icon,
Button,
StepLabel,
Step,
Stepper,
Grid,
FormControl,
InputLabel,
Select,
MenuItem,
} from '@material-ui/core'
import Table from './Table'
import { Breadcrumb } from 'app/components'
import { Link } from 'react-router-dom'
import { Autocomplete, createFilterOptions } from '@material-ui/lab'
import useAuth from 'app/hooks/useAuth'
import { checkRole } from 'app/config/Function'
function CustomerView(props) {
const [age, setAge] = React.useState('')
const {
data,
updateItem,
removeItem,
setTxtSearch,
changeActive,
setChangeActive,
handeChangeActive,
setPageIndex,
pageIndex,
totalRecords,
permissions,
status,
setStatus,
listType,
type,
setType,
} = props
const { user } = useAuth()
const handleChange = (event) => {
setAge(event.target.value)
}
return (
<Fragment>
<div className="m-sm-30">
<div className="mb-sm-30">
<Breadcrumb
routeSegments={[
{
name: 'NCC hoá đơn',
path: '/invoice-supplier',
},
]}
/>
</div>
<Grid
style={{
padding: 10,
marginBottom: 20,
}}
justify={'space-between'}
alignItems={'center'}
container
spacing={3}
>
<Grid
container
spacing={3}
item
lg={8}
md={8}
sm={8}
xs={8}
>
<Grid item lg={4} md={4} sm={4} xs={4}>
<TextField
variant="outlined"
className="w-full"
label="Tìm kiếm"
onChange={(e) => {
const text = e.target.value
setTimeout(() => {
setTxtSearch(text)
}, 1000)
}}
/>
</Grid>
<Grid item lg={4} md={4} sm={4} xs={4}>
<FormControl variant="outlined" fullWidth>
<InputLabel htmlFor="outlined-age-native-simple">
Trng thái
</InputLabel>
<Select
label="Trạng thái"
value={status}
onChange={(e) => setStatus(e.target.value)}
inputProps={{
name: 'age',
id: 'outlined-age-native-simple',
}}
>
<MenuItem value="">
<em>Tt c</em>
</MenuItem>
{[
{
id: 1,
name: 'Hoạt động',
},
{
id: 2,
name: 'Khoá',
},
].map((e) => (
<MenuItem value={e.id}>
{e.name}
</MenuItem>
))}
</Select>
</FormControl>
</Grid>
</Grid>
{checkRole(user, '/invoice-supplier/create') ? (
<Link to="/invoice-supplier/create">
<Button
variant="contained"
className={'bg-light-primary'}
>
<span className={'text-primary'}>Thêm mi</span>
</Button>
</Link>
) : null}
</Grid>
<Table
data={data}
changeActive={changeActive}
setChangeActive={setChangeActive}
handeChangeActive={handeChangeActive}
updateItem={updateItem}
removeItem={removeItem}
pageIndex={pageIndex}
setPageIndex={setPageIndex}
totalRecords={totalRecords}
permissions={permissions}
/>
</div>
</Fragment>
)
}
export default CustomerView
import React from 'react'
const routes = [
{
path: '/invoice-supplier/update',
component: React.lazy(() => import('./Update')),
},
{
path: '/invoice-supplier/create',
component: React.lazy(() => import('./Create')),
},
{
path: '/invoice-supplier',
component: React.lazy(() => import('./Index')),
},
]
export default routes
......@@ -31,7 +31,7 @@ const columns = [
id: 'store_name',
label: 'Cây xăng',
align: 'left',
minWidth: 'auto',
minWidth: 160,
},
// {
// id: 'application',
......@@ -43,13 +43,13 @@ const columns = [
id: 'order_code',
label: 'Mã hoá đơn',
align: 'left',
minWidth: 'auto',
minWidth: 160,
},
{
id: 'created_date',
label: 'Ngày giao dịch',
align: 'left',
minWidth: 'auto',
minWidth: 110,
},
// {
......@@ -62,25 +62,25 @@ const columns = [
id: 'product_name',
label: 'Sản phẩm',
align: 'left',
minWidth: 'auto',
minWidth: 120,
},
{
id: 'unit_price',
label: 'Đơn giá',
align: 'left',
minWidth: 100,
minWidth: 80,
},
{
id: 'quantity',
label: 'Lượng nhiên liệu',
align: 'left',
minWidth: 100,
minWidth: 80,
},
{
id: 'price',
label: 'Thành tiền',
align: 'left',
minWidth: 100,
minWidth: 80,
},
{
id: 'type_payment',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment