Skip to content

Commit 1592ff5

Browse files
committed
#4107 removed subtotal from backend
1 parent 8ee4a71 commit 1592ff5

7 files changed

Lines changed: 23 additions & 34 deletions

File tree

src/backend/src/controllers/projects.controllers.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,6 @@ export default class ProjectsController {
220220
quantity,
221221
unitName,
222222
price,
223-
subtotal,
224223
linkUrl,
225224
notes
226225
} = req.body;
@@ -237,7 +236,6 @@ export default class ProjectsController {
237236
manufacturerPartNumber,
238237
quantity,
239238
price,
240-
subtotal,
241239
notes,
242240
assemblyId,
243241
pdmFileName,

src/backend/src/prisma/seed.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3529,7 +3529,6 @@ const performSeed: () => Promise<void> = async () => {
35293529
'abcdef',
35303530
new Decimal(20),
35313531
30,
3532-
600,
35333532
'Here are some notes',
35343533
assembly1.assemblyId,
35353534
undefined,
@@ -3552,7 +3551,6 @@ const performSeed: () => Promise<void> = async () => {
35523551
'bacfed',
35533552
new Decimal(10),
35543553
7,
3555-
70,
35563554
'Here are some more notes',
35573555
undefined,
35583556
undefined,
@@ -3575,7 +3573,6 @@ const performSeed: () => Promise<void> = async () => {
35753573
'lalsd',
35763574
new Decimal(5),
35773575
10,
3578-
50,
35793576
undefined,
35803577
undefined,
35813578
undefined

src/backend/src/services/boms.services.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ export default class BillOfMaterialsService {
5656
* @param manufacturerPartNumber the manufacturer part number for the material (optional)
5757
* @param quantity the quantity of material as a number (optional)
5858
* @param price the price of the material in whole cents (optional)
59-
* @param subtotal the subtotal of the price for the material in whole cents (optional)
6059
* @param notes any notes about the material as a string (optional)
6160
* @param assemblyId the id of the Assembly for the material (optional)
6261
* @param pdmFileName the name of the pdm file for the material (optional)
@@ -75,7 +74,6 @@ export default class BillOfMaterialsService {
7574
manufacturerPartNumber?: string,
7675
quantity?: Decimal,
7776
price?: number,
78-
subtotal?: number,
7977
notes?: string,
8078
assemblyId?: string,
8179
pdmFileName?: string,
@@ -119,6 +117,9 @@ export default class BillOfMaterialsService {
119117

120118
if (!perms) throw new AccessDeniedException('create materials');
121119

120+
const computedSubtotal =
121+
price !== undefined && quantity !== undefined ? Math.round(price * Number(quantity)) : undefined;
122+
122123
const createdMaterial = await prisma.material.create({
123124
data: {
124125
userCreatedId: creator.userId,
@@ -132,7 +133,7 @@ export default class BillOfMaterialsService {
132133
quantity,
133134
unitId: unit ? unit.id : null,
134135
price,
135-
subtotal,
136+
subtotal: computedSubtotal,
136137
linkUrl,
137138
notes,
138139
dateCreated: new Date(),
@@ -611,7 +612,6 @@ export default class BillOfMaterialsService {
611612
* @param manufacturerPartNumber the manufacturerPartNumber of the edited material (optional)
612613
* @param quantity the quantity of the edited material (optional)
613614
* @param price the price of the edited material (optional)
614-
* @param subtotal the subtotal of the edited material (optional)
615615
* @param notes the notes of the edited material (optional)
616616
* @param unitName the unit name of the edited material (optional)
617617
* @param assemblyId the assembly id of the edited material (optional)

src/backend/src/utils/validation.utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ export const materialValidators = [
284284
decimalMinZero(body('quantity')).optional(),
285285
nonEmptyString(body('unitName')).optional(),
286286
intMinZero(body('price')).optional(), // in cents
287-
intMinZero(body('subtotal')).optional(), // in cents
288287
body('linkUrl').optional().isString(),
289288
body('notes').isString().optional()
290289
];

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/BOMTableWrapper.tsx

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -129,34 +129,34 @@ const BOMTableWrapper: React.FC<BOMTableWrapperProps> = ({
129129

130130
const processRowUpdate = async (newRow: BomRow, oldRow: BomRow): Promise<BomRow> => {
131131
// assemblies are not editable
132-
if (String(newRow.id).startsWith('assembly')) return newRow;
132+
if (newRow.id.startsWith('assembly')) return newRow;
133133

134134
const material = materials.find((m) => m.materialId === newRow.materialId);
135135
if (!material) return newRow;
136136

137-
const newQuantity = typeof newRow.quantity === 'number' ? (newRow.quantity as number) : null;
138-
const newPriceDollars = typeof newRow.price === 'number' ? (newRow.price as number) : null;
137+
const quantityChanged = newRow.quantityRaw !== oldRow.quantityRaw;
138+
const priceChanged = newRow.priceRaw !== oldRow.priceRaw;
139139

140140
if (
141141
newRow.name === oldRow.name &&
142142
newRow.type === oldRow.type &&
143143
newRow.manufacturer === oldRow.manufacturer &&
144144
newRow.manufacturerPN === oldRow.manufacturerPN &&
145145
newRow.pdmFileName === oldRow.pdmFileName &&
146-
newQuantity === null &&
147-
newPriceDollars === null
146+
!quantityChanged &&
147+
!priceChanged
148148
)
149149
return newRow;
150150

151151
if (newRow.name !== undefined && !newRow.name.trim()) {
152152
toast.error('Name cannot be empty');
153153
return oldRow;
154154
}
155-
if (newQuantity !== null && (isNaN(newQuantity) || newQuantity <= 0)) {
155+
if (quantityChanged && newRow.quantityRaw !== undefined && (isNaN(newRow.quantityRaw) || newRow.quantityRaw <= 0)) {
156156
toast.error('Quantity must be a positive number');
157157
return oldRow;
158158
}
159-
if (newPriceDollars !== null && (isNaN(newPriceDollars) || newPriceDollars < 0)) {
159+
if (priceChanged && newRow.priceRaw !== undefined && (isNaN(newRow.priceRaw) || newRow.priceRaw < 0)) {
160160
toast.error('Price must be a non-negative number');
161161
return oldRow;
162162
}
@@ -167,11 +167,12 @@ const BOMTableWrapper: React.FC<BOMTableWrapperProps> = ({
167167
if (newRow.manufacturer !== oldRow.manufacturer) changedFields.push('Manufacturer');
168168
if (newRow.manufacturerPN !== oldRow.manufacturerPN) changedFields.push('Manufacturer PN');
169169
if (newRow.pdmFileName !== oldRow.pdmFileName) changedFields.push('PDM File Name');
170-
if (newQuantity !== null) changedFields.push('Quantity');
171-
if (newPriceDollars !== null) changedFields.push('Price');
170+
if (quantityChanged) changedFields.push('Quantity');
171+
if (priceChanged) changedFields.push('Price');
172172

173-
const priceInCents = newPriceDollars !== null ? Math.round(newPriceDollars * 100) : material.price;
174-
const quantityValue = newQuantity !== null ? newQuantity : Number(material.quantity);
173+
const priceInCents = priceChanged && newRow.priceRaw !== undefined ? Math.round(newRow.priceRaw * 100) : material.price;
174+
const quantityValue =
175+
quantityChanged && newRow.quantityRaw != null ? new Decimal(newRow.quantityRaw) : material.quantity;
175176

176177
try {
177178
await editMaterial({
@@ -183,8 +184,8 @@ const BOMTableWrapper: React.FC<BOMTableWrapperProps> = ({
183184
manufacturerName: newRow.manufacturer || undefined,
184185
manufacturerPartNumber: newRow.manufacturerPN || undefined,
185186
pdmFileName: newRow.pdmFileName,
186-
price: priceInCents,
187-
quantity: new Decimal(quantityValue),
187+
price: priceInCents,
188+
quantity: quantityValue,
188189
unitName: material.unitName,
189190
linkUrl: material.linkUrl,
190191
notes: material.notes,
@@ -195,7 +196,6 @@ const BOMTableWrapper: React.FC<BOMTableWrapperProps> = ({
195196
return {
196197
...newRow,
197198
quantity: material.unitName ? `${quantityValue} ${material.unitName}` : `${quantityValue}`,
198-
quantityRaw: quantityValue,
199199
price: priceInCents !== undefined ? `$${centsToDollar(priceInCents)}` : newRow.price,
200200
priceRaw: priceInCents !== undefined ? priceInCents / 100 : newRow.priceRaw
201201
};
@@ -209,7 +209,7 @@ const BOMTableWrapper: React.FC<BOMTableWrapperProps> = ({
209209

210210
const getActions = (params: GridRowParams) => {
211211
const actions: JSX.Element[] = [];
212-
const rowId = String(params.row.id);
212+
const rowId = params.row.id;
213213
const material = materials.find((mat) => mat.materialId === params.row.materialId);
214214
const shouldShowInMenu = windowWidth < 1000;
215215

@@ -371,7 +371,7 @@ const BOMTableWrapper: React.FC<BOMTableWrapperProps> = ({
371371
headerName: 'Status',
372372
renderCell: (params) => {
373373
// assemblies are not editable
374-
if (!params.value || String(params.row.id).startsWith('assembly')) return null;
374+
if (!params.value || params.row.id.startsWith('assembly')) return null;
375375
const material = materials.find((m) => m.materialId === params.row.materialId);
376376
if (!material) return null;
377377
return (
@@ -483,23 +483,21 @@ const BOMTableWrapper: React.FC<BOMTableWrapperProps> = ({
483483
},
484484
{
485485
...bomBaseColDef,
486-
field: 'quantity',
486+
field: 'quantityRaw',
487487
headerName: 'Quantity',
488488
type: 'number',
489489
editable: editPerms,
490-
valueGetter: (params) => params.row.quantityRaw,
491490
renderCell: (params) => params.row.quantity,
492491
sortable: false,
493492
filterable: false,
494493
hide: hideColumn[7]
495494
},
496495
{
497496
...bomBaseColDef,
498-
field: 'price',
497+
field: 'priceRaw',
499498
headerName: 'Price per Unit',
500499
type: 'number',
501500
editable: editPerms,
502-
valueGetter: (params) => params.row.priceRaw,
503501
renderCell: (params) => params.row.price,
504502
sortable: false,
505503
filterable: false,

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/ImportBOMModal.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,6 @@ const ImportBOMModal: React.FC<ImportBOMModalProps> = ({ open, onHide, wbsNum, a
350350
manufacturerPartNumber: material.manufacturerPartNumber || undefined,
351351
quantity: new Decimal(material.quantity),
352352
price: material.unitPrice,
353-
subtotal: material.subtotal,
354353
unitName: material.unit || undefined,
355354
assemblyId: material.assemblyId || undefined,
356355
linkUrl: '',

src/frontend/src/pages/ProjectDetailPage/ProjectViewContainer/BOM/MaterialForm/MaterialForm.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@ export interface MaterialDataSubmission {
6060
linkUrl?: string;
6161
notes?: string;
6262
assemblyId?: string;
63-
subtotal?: number;
6463
}
6564

6665
export interface MaterialFormProps {
@@ -124,8 +123,7 @@ const MaterialForm: React.FC<MaterialFormProps> = ({
124123

125124
const onSubmitWrapper = (data: MaterialFormInput): void => {
126125
const price = data.price != null ? Math.round(data.price * 100) : undefined;
127-
const subtotal = price != null && data.quantity != null ? parseFloat((data.quantity * price).toFixed(2)) : undefined;
128-
onSubmit({ ...data, subtotal, price, quantity: data.quantity != null ? new Decimal(data.quantity) : undefined });
126+
onSubmit({ ...data, price, quantity: data.quantity != null ? new Decimal(data.quantity) : undefined });
129127
};
130128

131129
const createManufacturerWrapper = async (manufacturerName: string): Promise<void> => {

0 commit comments

Comments
 (0)