@@ -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)
@@ -631,7 +631,6 @@ export default class BillOfMaterialsService {
631631 manufacturerPartNumber ?: string ,
632632 quantity ?: Decimal ,
633633 price ?: number ,
634- subtotal ?: number ,
635634 notes ?: string ,
636635 unitName ?: string ,
637636 assemblyId ?: string ,
@@ -670,6 +669,12 @@ export default class BillOfMaterialsService {
670669 manufacturer = await BillOfMaterialsService . getSingleManufacturerWithQueryArgs ( manufacturerName , organization ) ;
671670 }
672671
672+ // recalculate subtotal on edits
673+ const finalPrice = price ?? material . price ?? undefined ;
674+ const finalQuantity = quantity ?? material . quantity ?? undefined ;
675+ const computedSubtotal =
676+ finalPrice !== undefined && finalQuantity !== undefined ? Math . round ( finalPrice * Number ( finalQuantity ) ) : undefined ;
677+
673678 const updatedMaterial = await prisma . material . update ( {
674679 where : { materialId } ,
675680 data : {
@@ -681,12 +686,12 @@ export default class BillOfMaterialsService {
681686 quantity,
682687 unitId : unit ? unit . id : null ,
683688 price,
684- subtotal,
689+ subtotal : computedSubtotal ,
685690 linkUrl,
686691 notes,
687692 wbsElementId : project . wbsElementId ,
688693 assemblyId,
689- pdmFileName
694+ pdmFileName : pdmFileName !== undefined ? pdmFileName || null : undefined
690695 } ,
691696 ...getMaterialQueryArgs ( organization . organizationId )
692697 } ) ;
0 commit comments