All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
- Integrated BulkObjectActions component across various management and dashboard components for improved batch processing capabilities. - Updated components including Invoices, PaymentPolicies, Payments, TaxRecords, and multiple Inventory and Management sections to include bulk action functionality. - Enhanced user experience by allowing users to perform actions on multiple items simultaneously, streamlining workflows and improving efficiency.
390 lines
8.8 KiB
JavaScript
390 lines
8.8 KiB
JavaScript
import { createElement, lazy } from 'react'
|
|
|
|
const ProductInfo = lazy(
|
|
() => import('../../components/Dashboard/Management/Products/ProductInfo')
|
|
)
|
|
const NewProduct = lazy(
|
|
() => import('../../components/Dashboard/Management/Products/NewProduct')
|
|
)
|
|
const DeleteObject = lazy(
|
|
() => import('../../components/Dashboard/common/DeleteObject')
|
|
)
|
|
import ProductIcon from '../../components/Icons/ProductIcon'
|
|
import PlusIcon from '../../components/Icons/PlusIcon'
|
|
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
|
|
import EditIcon from '../../components/Icons/EditIcon'
|
|
import CheckIcon from '../../components/Icons/CheckIcon'
|
|
import XMarkIcon from '../../components/Icons/XMarkIcon'
|
|
import ListIcon from '../../components/Icons/ListIcon'
|
|
import DuplicateIcon from '../../components/Icons/DuplicateIcon'
|
|
import BinIcon from '../../components/Icons/BinIcon'
|
|
|
|
export const Product = {
|
|
name: 'product',
|
|
label: 'Product',
|
|
labelPlural: 'Products',
|
|
url: '/dashboard/management/products',
|
|
prefix: 'PRD',
|
|
icon: ProductIcon,
|
|
actions: [
|
|
{
|
|
name: 'new',
|
|
type: 'modal',
|
|
pageName: 'list',
|
|
modalWidth: 700,
|
|
label: 'New Product',
|
|
icon: PlusIcon,
|
|
content: (objectData, { onOk } = {}) => {
|
|
return createElement(NewProduct, {
|
|
defaultValues: objectData,
|
|
onOk,
|
|
reset: true
|
|
})
|
|
}
|
|
},
|
|
{
|
|
name: 'duplicate',
|
|
type: 'alias',
|
|
objectType: 'product',
|
|
aliasAction: 'new',
|
|
pageName: 'info',
|
|
label: 'Duplicate',
|
|
icon: DuplicateIcon,
|
|
objectData: (objectData) => objectData
|
|
},
|
|
{
|
|
name: 'list',
|
|
type: 'page',
|
|
pageName: 'list',
|
|
label: 'List',
|
|
icon: ListIcon
|
|
},
|
|
{
|
|
name: 'info',
|
|
type: 'page',
|
|
pageName: 'info',
|
|
label: 'Info',
|
|
default: true,
|
|
row: true,
|
|
icon: InfoCircleIcon
|
|
},
|
|
{
|
|
name: 'edit',
|
|
type: 'page',
|
|
pageName: 'info',
|
|
label: 'Edit',
|
|
row: true,
|
|
icon: EditIcon,
|
|
visible: (objectData) => {
|
|
return !(objectData?._isEditing && objectData?._isEditing == true)
|
|
}
|
|
},
|
|
{
|
|
name: 'cancelEdit',
|
|
label: 'Cancel Edits',
|
|
type: 'page',
|
|
pageName: 'info',
|
|
icon: XMarkIcon,
|
|
visible: (objectData) => {
|
|
return objectData?._isEditing && objectData?._isEditing == true
|
|
}
|
|
},
|
|
{
|
|
name: 'finishEdit',
|
|
label: 'Save Edits',
|
|
type: 'page',
|
|
pageName: 'info',
|
|
icon: CheckIcon,
|
|
visible: (objectData) => {
|
|
return objectData?._isEditing && objectData?._isEditing == true
|
|
}
|
|
},
|
|
{
|
|
type: 'divider'
|
|
},
|
|
{
|
|
name: 'newProductSku',
|
|
type: 'alias',
|
|
objectType: 'productSku',
|
|
aliasAction: 'new',
|
|
visible: (objectData) => {
|
|
return !(objectData?._isEditing && objectData?._isEditing == true)
|
|
},
|
|
objectData: (objectData) => ({ product: objectData })
|
|
},
|
|
{ type: 'divider' },
|
|
{
|
|
name: 'delete',
|
|
bulk: true,
|
|
type: 'modal',
|
|
modalWidth: 520,
|
|
modalCentered: true,
|
|
label: 'Delete',
|
|
icon: BinIcon,
|
|
danger: true,
|
|
content: (objectData, { onOk } = {}) => {
|
|
return createElement(DeleteObject, { objectData, onOk })
|
|
}
|
|
}
|
|
],
|
|
pages: [
|
|
{
|
|
name: 'info',
|
|
content: () => createElement(ProductInfo)
|
|
}
|
|
],
|
|
columns: [
|
|
'_reference',
|
|
'name',
|
|
'productCategory',
|
|
'tags',
|
|
'vendor',
|
|
'cost',
|
|
'costWithTax',
|
|
'price',
|
|
'priceWithTax',
|
|
'createdAt',
|
|
'updatedAt'
|
|
],
|
|
filters: [
|
|
'_id',
|
|
'name',
|
|
'globalPrice',
|
|
'productCategory',
|
|
'cost',
|
|
'costWithTax',
|
|
'price',
|
|
'margin',
|
|
'priceWithTax',
|
|
'createdAt',
|
|
'updatedAt',
|
|
'_reference'
|
|
],
|
|
sorters: [
|
|
'name',
|
|
'productCategory',
|
|
'createdAt',
|
|
'type',
|
|
'vendor',
|
|
'cost',
|
|
'costWithTax',
|
|
'price',
|
|
'margin',
|
|
'priceWithTax',
|
|
'updatedAt'
|
|
],
|
|
properties: [
|
|
{
|
|
name: '_id',
|
|
label: 'ID',
|
|
type: 'id',
|
|
objectType: 'product',
|
|
showCopy: true,
|
|
readOnly: true,
|
|
columnWidth: 140
|
|
},
|
|
{
|
|
name: 'createdAt',
|
|
label: 'Created At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: '_reference',
|
|
label: 'Reference',
|
|
type: 'reference',
|
|
columnFixed: 'left',
|
|
objectType: 'product',
|
|
showCopy: true,
|
|
readOnly: true,
|
|
columnWidth: 180
|
|
},
|
|
{
|
|
name: 'updatedAt',
|
|
label: 'Updated At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: 'name',
|
|
label: 'Name',
|
|
required: true,
|
|
type: 'text',
|
|
columnWidth: 200,
|
|
columnFixed: 'left'
|
|
},
|
|
{
|
|
name: 'productCategory',
|
|
label: 'Category',
|
|
required: true,
|
|
type: 'object',
|
|
objectType: 'productCategory',
|
|
showHyperlink: true,
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: 'version',
|
|
label: 'Version',
|
|
required: false,
|
|
type: 'text',
|
|
columnWidth: 120
|
|
},
|
|
{
|
|
name: 'vendor',
|
|
label: 'Vendor',
|
|
required: true,
|
|
type: 'object',
|
|
objectType: 'vendor',
|
|
showHyperlink: true,
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: 'tags',
|
|
label: 'Tags',
|
|
required: false,
|
|
type: 'tags',
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: 'cost',
|
|
label: 'Cost',
|
|
required: true,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.01,
|
|
columnWidth: 100
|
|
},
|
|
{
|
|
name: 'costWithTax',
|
|
label: 'Cost w/ Tax',
|
|
required: true,
|
|
readOnly: true,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.01,
|
|
columnWidth: 150,
|
|
value: (objectData) => {
|
|
const cost = objectData?.cost
|
|
if (!cost) return 0
|
|
if (objectData?.costTaxRate?.rateType == 'percentage') {
|
|
return (
|
|
(cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) || 0
|
|
)
|
|
} else if (objectData?.costTaxRate?.rateType == 'amount') {
|
|
return (cost + objectData?.costTaxRate?.rate).toFixed(2) || 0
|
|
}
|
|
return cost
|
|
}
|
|
},
|
|
{
|
|
name: 'costTaxRate',
|
|
label: 'Cost Tax Rate',
|
|
required: true,
|
|
type: 'object',
|
|
objectType: 'taxRate',
|
|
showHyperlink: true,
|
|
columnWidth: 150
|
|
},
|
|
{
|
|
name: 'priceMode',
|
|
label: 'Price Mode',
|
|
required: true,
|
|
type: 'priceMode',
|
|
columnWidth: 150
|
|
},
|
|
{
|
|
name: 'price',
|
|
label: 'Price',
|
|
required: true,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.1,
|
|
columnWidth: 100,
|
|
readOnly: (objectData) => objectData?.priceMode == 'margin',
|
|
value: (objectData) => {
|
|
if (
|
|
objectData?.priceMode == 'margin' &&
|
|
objectData?.margin !== undefined &&
|
|
objectData?.margin !== null &&
|
|
objectData?.cost != null
|
|
) {
|
|
return (
|
|
(objectData.cost * (1 + objectData.margin / 100)).toFixed(2) || 0
|
|
)
|
|
}
|
|
return objectData?.price
|
|
}
|
|
},
|
|
{
|
|
name: 'margin',
|
|
label: 'Margin',
|
|
required: true,
|
|
type: 'number',
|
|
readOnly: (objectData) => objectData?.priceMode == 'amount',
|
|
suffix: '%',
|
|
min: 0,
|
|
max: 100,
|
|
step: 0.01,
|
|
value: (objectData) => {
|
|
const priceMode = objectData?.priceMode
|
|
const cost = objectData?.cost
|
|
if (priceMode == 'amount') {
|
|
const price = objectData?.price
|
|
if (price != null && cost != null) {
|
|
return Number(((price / cost - 1) * 100).toFixed(2)) || undefined
|
|
}
|
|
return undefined
|
|
}
|
|
return objectData?.margin
|
|
},
|
|
columnWidth: 85
|
|
},
|
|
{
|
|
name: 'priceWithTax',
|
|
label: 'Price w/ Tax',
|
|
required: true,
|
|
readOnly: true,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.01,
|
|
columnWidth: 150,
|
|
value: (objectData) => {
|
|
let price
|
|
if (
|
|
objectData?.priceMode == 'margin' &&
|
|
objectData?.margin != null &&
|
|
objectData?.cost != null
|
|
) {
|
|
price = objectData.cost * (1 + objectData.margin / 100)
|
|
} else {
|
|
price = objectData?.price
|
|
}
|
|
if (!price) return 0
|
|
if (objectData?.priceTaxRate?.rateType == 'percentage') {
|
|
return (
|
|
(price * (1 + objectData?.priceTaxRate?.rate / 100)).toFixed(2) || 0
|
|
)
|
|
} else if (objectData?.priceTaxRate?.rateType == 'amount') {
|
|
return (price + objectData?.priceTaxRate?.rate).toFixed(2) || 0
|
|
}
|
|
return price
|
|
}
|
|
},
|
|
{
|
|
name: 'priceTaxRate',
|
|
label: 'Price Tax Rate',
|
|
required: true,
|
|
type: 'object',
|
|
objectType: 'taxRate',
|
|
showHyperlink: true,
|
|
columnWidth: 150
|
|
}
|
|
]
|
|
}
|