277 lines
6.7 KiB
JavaScript
277 lines
6.7 KiB
JavaScript
import ProductIcon from '../../components/Icons/ProductIcon'
|
|
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 PlusIcon from '../../components/Icons/PlusIcon'
|
|
|
|
export const Product = {
|
|
name: 'product',
|
|
label: 'Product',
|
|
prefix: 'PRD',
|
|
icon: ProductIcon,
|
|
actions: [
|
|
{
|
|
name: 'info',
|
|
label: 'Info',
|
|
default: true,
|
|
row: true,
|
|
icon: InfoCircleIcon,
|
|
url: (_id) => `/dashboard/management/products/info?productId=${_id}`
|
|
},
|
|
{
|
|
name: 'edit',
|
|
label: 'Edit',
|
|
row: true,
|
|
icon: EditIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/products/info?productId=${_id}&action=edit`,
|
|
visible: (objectData) => {
|
|
return !(objectData?._isEditing && objectData?._isEditing == true)
|
|
}
|
|
},
|
|
{
|
|
name: 'finishEdit',
|
|
label: 'Save Edits',
|
|
icon: CheckIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/products/info?productId=${_id}&action=finishEdit`,
|
|
visible: (objectData) => {
|
|
return objectData?._isEditing && objectData?._isEditing == true
|
|
}
|
|
},
|
|
{
|
|
name: 'cancelEdit',
|
|
label: 'Cancel Edits',
|
|
icon: XMarkIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/products/info?productId=${_id}&action=cancelEdit`,
|
|
visible: (objectData) => {
|
|
return objectData?._isEditing && objectData?._isEditing == true
|
|
}
|
|
},
|
|
{
|
|
type: 'divider'
|
|
},
|
|
{
|
|
name: 'newProductSku',
|
|
label: 'New Product SKU',
|
|
type: 'button',
|
|
icon: PlusIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/products/info?productId=${_id}&action=newProductSku`,
|
|
visible: (objectData) => {
|
|
return !(objectData?._isEditing && objectData?._isEditing == true)
|
|
}
|
|
}
|
|
],
|
|
columns: [
|
|
'_reference',
|
|
'name',
|
|
'tags',
|
|
'vendor',
|
|
'cost',
|
|
'costWithTax',
|
|
'price',
|
|
'priceWithTax',
|
|
'createdAt',
|
|
'updatedAt'
|
|
],
|
|
filters: ['_id', 'name', 'type', 'color', 'vendor', 'cost', 'costWithTax', 'price', 'priceWithTax'],
|
|
sorters: ['name', 'createdAt', 'type', 'vendor', 'cost', 'costWithTax', 'price', '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: 175
|
|
},
|
|
{
|
|
name: '_reference',
|
|
label: 'Reference',
|
|
type: 'reference',
|
|
columnFixed: 'left',
|
|
objectType: 'product',
|
|
showCopy: true,
|
|
readOnly: true
|
|
},
|
|
{
|
|
name: 'name',
|
|
label: 'Name',
|
|
required: true,
|
|
type: 'text',
|
|
columnWidth: 200,
|
|
columnFixed: 'left'
|
|
},
|
|
{
|
|
name: 'updatedAt',
|
|
label: 'Updated At',
|
|
type: 'dateTime',
|
|
readOnly: true,
|
|
columnWidth: 175
|
|
},
|
|
{
|
|
name: 'vendor',
|
|
label: 'Vendor',
|
|
required: true,
|
|
type: 'object',
|
|
objectType: 'vendor',
|
|
showHyperlink: true,
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: 'version',
|
|
label: 'Version',
|
|
required: false,
|
|
type: 'text',
|
|
columnWidth: 120
|
|
},
|
|
{
|
|
name: 'tags',
|
|
label: 'Tags',
|
|
required: false,
|
|
type: 'tags',
|
|
columnWidth: 200
|
|
},
|
|
{
|
|
name: 'cost',
|
|
label: 'Cost',
|
|
required: false,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.01,
|
|
columnWidth: 100
|
|
},
|
|
{
|
|
name: 'costWithTax',
|
|
label: 'Cost w/ Tax',
|
|
required: false,
|
|
readOnly: true,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.01,
|
|
columnWidth: 150,
|
|
value: (objectData) => {
|
|
const cost = objectData?.cost
|
|
if (!cost) return undefined
|
|
if (objectData?.costTaxRate?.rateType == 'percentage') {
|
|
return (
|
|
(cost * (1 + objectData?.costTaxRate?.rate / 100)).toFixed(2) ||
|
|
undefined
|
|
)
|
|
} else if (objectData?.costTaxRate?.rateType == 'amount') {
|
|
return (cost + objectData?.costTaxRate?.rate).toFixed(2) || undefined
|
|
}
|
|
return cost
|
|
}
|
|
},
|
|
{
|
|
name: 'costTaxRate',
|
|
label: 'Cost Tax Rate',
|
|
required: false,
|
|
type: 'object',
|
|
objectType: 'taxRate',
|
|
showHyperlink: true,
|
|
columnWidth: 150
|
|
},
|
|
{
|
|
name: 'priceMode',
|
|
label: 'Price Mode',
|
|
required: false,
|
|
type: 'priceMode',
|
|
columnWidth: 150
|
|
},
|
|
{
|
|
name: 'price',
|
|
label: 'Price',
|
|
required: false,
|
|
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) ||
|
|
undefined
|
|
)
|
|
}
|
|
return objectData?.price
|
|
}
|
|
},
|
|
{
|
|
name: 'margin',
|
|
label: 'Margin',
|
|
required: false,
|
|
type: 'number',
|
|
disabled: (objectData) => objectData?.priceMode == 'amount',
|
|
suffix: '%',
|
|
min: 0,
|
|
max: 100,
|
|
step: 0.01,
|
|
columnWidth: 85
|
|
},
|
|
{
|
|
name: 'priceWithTax',
|
|
label: 'Price w/ Tax',
|
|
required: false,
|
|
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 undefined
|
|
if (objectData?.priceTaxRate?.rateType == 'percentage') {
|
|
return (
|
|
(price * (1 + objectData?.priceTaxRate?.rate / 100)).toFixed(2) ||
|
|
undefined
|
|
)
|
|
} else if (objectData?.priceTaxRate?.rateType == 'amount') {
|
|
return (price + objectData?.priceTaxRate?.rate).toFixed(2) || undefined
|
|
}
|
|
return price
|
|
}
|
|
},
|
|
{
|
|
name: 'priceTaxRate',
|
|
label: 'Price Tax Rate',
|
|
required: false,
|
|
type: 'object',
|
|
objectType: 'taxRate',
|
|
showHyperlink: true,
|
|
columnWidth: 150
|
|
}
|
|
]
|
|
}
|