Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 5 additions & 10 deletions src/app/api/quickbooks/invoice/invoice.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,26 +134,22 @@ export class InvoiceService extends BaseService {
}

private async handleItemAmount({
unitPrice,
copilotUnitPrice,
priceId,
mappingId,
productService,
}: {
unitPrice: string | null
copilotUnitPrice: string | null
priceId: string
mappingId: string
productService: ProductService
}) {
console.log('Checking if QB item unit price is available and not zero.')
// if unitPrice (QB unit price) is null, return copilot unit price.
let itemAmount =
unitPrice && unitPrice !== '0' ? unitPrice : copilotUnitPrice
console.log(
'Checking if Assembly item unit price is available and not zero.',
)
if (copilotUnitPrice && copilotUnitPrice !== '0') return copilotUnitPrice

// fetch price amount from copilot if copilotUnitPrice is null
if (itemAmount && itemAmount !== '0') return itemAmount

console.info(
'Copilot product price not found in mapping table. Fetching from copilot SDK',
)
Expand All @@ -163,7 +159,7 @@ export class InvoiceService extends BaseService {
httpStatus.NOT_FOUND,
'Price not found. Id: ' + priceId,
)
itemAmount = copilotPriceRes.amount.toFixed()
const itemAmount = copilotPriceRes.amount.toFixed()

// update the price amount in our DB
const priceUpdatePayload = {
Expand Down Expand Up @@ -201,7 +197,6 @@ export class InvoiceService extends BaseService {
console.info('InvoiceService#getInvoiceItemRef | Product map found')

const itemAmount = await this.handleItemAmount({
unitPrice: mapping.unitPrice,
copilotUnitPrice: mapping.copilotUnitPrice,
priceId,
mappingId: mapping.id,
Expand Down
Loading