- Updated multiple models to change the column identifier from '_id' to '_reference' for consistency across the database schema. - Adjusted relevant filters and properties to align with the new column naming convention.
245 lines
5.8 KiB
JavaScript
245 lines
5.8 KiB
JavaScript
import EditIcon from '../../components/Icons/EditIcon'
|
|
import InfoCircleIcon from '../../components/Icons/InfoCircleIcon'
|
|
import PartIcon from '../../components/Icons/PartIcon'
|
|
import ReloadIcon from '../../components/Icons/ReloadIcon'
|
|
import CheckIcon from '../../components/Icons/CheckIcon'
|
|
import XMarkIcon from '../../components/Icons/XMarkIcon'
|
|
export const Part = {
|
|
name: 'part',
|
|
label: 'Part',
|
|
prefix: 'PRT',
|
|
icon: PartIcon,
|
|
actions: [
|
|
{
|
|
name: 'info',
|
|
label: 'Info',
|
|
default: true,
|
|
row: true,
|
|
icon: InfoCircleIcon,
|
|
url: (_id) => `/dashboard/management/parts/info?partId=${_id}`
|
|
},
|
|
{
|
|
name: 'reload',
|
|
label: 'Reload',
|
|
icon: ReloadIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/parts/info?partId=${_id}&action=reload`
|
|
},
|
|
{
|
|
name: 'edit',
|
|
label: 'Edit',
|
|
row: true,
|
|
icon: EditIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/parts/info?partId=${_id}&action=edit`,
|
|
visible: (objectData) => {
|
|
return !(objectData?._isEditing && objectData?._isEditing == true)
|
|
}
|
|
},
|
|
{
|
|
name: 'finishEdit',
|
|
label: 'Save Edits',
|
|
icon: CheckIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/parts/info?partId=${_id}&action=finishEdit`,
|
|
visible: (objectData) => {
|
|
return objectData?._isEditing && objectData?._isEditing == true
|
|
}
|
|
},
|
|
{
|
|
name: 'cancelEdit',
|
|
label: 'Cancel Edits',
|
|
icon: XMarkIcon,
|
|
url: (_id) =>
|
|
`/dashboard/management/parts/info?partId=${_id}&action=cancelEdit`,
|
|
visible: (objectData) => {
|
|
return objectData?._isEditing && objectData?._isEditing == true
|
|
}
|
|
}
|
|
],
|
|
columns: ['name', '_reference', 'product', 'globalPricing', 'createdAt'],
|
|
filters: ['name', '_id', 'product', 'globalPricing'],
|
|
sorters: ['name', 'email', 'role', 'createdAt', '_id'],
|
|
properties: [
|
|
{
|
|
name: '_id',
|
|
label: 'ID',
|
|
columnFixed: 'left',
|
|
type: 'id',
|
|
objectType: 'part',
|
|
showCopy: true,
|
|
readOnly: true
|
|
},
|
|
{
|
|
name: 'createdAt',
|
|
label: 'Created At',
|
|
type: 'dateTime',
|
|
readOnly: true
|
|
},
|
|
{
|
|
name: 'name',
|
|
label: 'Name',
|
|
columnFixed: 'left',
|
|
required: true,
|
|
type: 'text'
|
|
},
|
|
{
|
|
name: 'updatedAt',
|
|
label: 'Updated At',
|
|
type: 'dateTime',
|
|
readOnly: true
|
|
},
|
|
{
|
|
name: 'vendor',
|
|
label: 'Vendor',
|
|
required: true,
|
|
type: 'object',
|
|
objectType: 'vendor',
|
|
showHyperlink: true,
|
|
value: (objectData) => {
|
|
if (!objectData?.vendor && objectData?.product?.vendor) {
|
|
return objectData?.product?.vendor
|
|
} else {
|
|
return objectData?.vendor
|
|
}
|
|
}
|
|
},
|
|
{
|
|
name: 'cost',
|
|
label: 'Cost',
|
|
columnWidth: 150,
|
|
required: true,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.01
|
|
},
|
|
{
|
|
name: 'costWithTax',
|
|
label: 'Cost w/ Tax',
|
|
columnWidth: 150,
|
|
required: true,
|
|
readOnly: true,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.01,
|
|
value: (objectData) => {
|
|
if (objectData?.costTaxRate?.rateType == 'percentage') {
|
|
return (
|
|
(
|
|
objectData?.cost *
|
|
(1 + objectData?.costTaxRate?.rate / 100)
|
|
).toFixed(2) || undefined
|
|
)
|
|
} else if (objectData?.costTaxRate?.rateType == 'amount') {
|
|
return (
|
|
(objectData?.cost + objectData?.costTaxRate?.rate).toFixed(2) ||
|
|
undefined
|
|
)
|
|
} else {
|
|
return objectData?.cost || undefined
|
|
}
|
|
}
|
|
},
|
|
{
|
|
name: 'costTaxRate',
|
|
label: 'Cost Tax Rate',
|
|
required: true,
|
|
type: 'object',
|
|
objectType: 'taxRate',
|
|
showHyperlink: true
|
|
},
|
|
{
|
|
name: 'price',
|
|
label: 'Price',
|
|
required: true,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.1,
|
|
readOnly: (objectData) => {
|
|
return objectData?.priceMode == 'margin'
|
|
},
|
|
value: (objectData) => {
|
|
if (
|
|
objectData?.priceMode == 'margin' &&
|
|
objectData?.margin !== undefined &&
|
|
objectData?.margin !== null
|
|
) {
|
|
return (
|
|
(objectData?.cost * (1 + objectData?.margin / 100)).toFixed(2) ||
|
|
undefined
|
|
)
|
|
} else {
|
|
return objectData?.price || undefined
|
|
}
|
|
}
|
|
},
|
|
{
|
|
name: 'priceWithTax',
|
|
label: 'Price w/ Tax',
|
|
columnWidth: 150,
|
|
required: true,
|
|
readOnly: true,
|
|
type: 'number',
|
|
prefix: '£',
|
|
min: 0,
|
|
step: 0.01,
|
|
value: (objectData) => {
|
|
if (objectData?.priceTaxRate?.rateType == 'percentage') {
|
|
return (
|
|
(
|
|
objectData?.price *
|
|
(1 + objectData?.priceTaxRate?.rate / 100)
|
|
).toFixed(2) || undefined
|
|
)
|
|
} else if (objectData?.priceTaxRate?.rateType == 'amount') {
|
|
return (
|
|
(objectData?.price + objectData?.priceTaxRate?.rate).toFixed(2) ||
|
|
undefined
|
|
)
|
|
} else {
|
|
return objectData?.price
|
|
}
|
|
}
|
|
},
|
|
{
|
|
name: 'priceMode',
|
|
label: 'Price Mode',
|
|
required: true,
|
|
type: 'priceMode'
|
|
},
|
|
{
|
|
name: 'margin',
|
|
label: 'Margin',
|
|
required: true,
|
|
type: 'number',
|
|
disabled: (objectData) => {
|
|
return objectData.priceMode == 'amount'
|
|
},
|
|
suffix: '%',
|
|
min: 0,
|
|
max: 100,
|
|
step: 0.01
|
|
},
|
|
{
|
|
name: 'priceTaxRate',
|
|
label: 'Price Tax Rate',
|
|
required: true,
|
|
type: 'object',
|
|
objectType: 'taxRate',
|
|
showHyperlink: true
|
|
},
|
|
|
|
{
|
|
name: 'file',
|
|
label: 'File',
|
|
type: 'file',
|
|
value: null,
|
|
required: false,
|
|
showHyperlink: true
|
|
}
|
|
]
|
|
}
|