    import Bid from 'pvbid-sdk/src/domain/Bid.js'

public class | source

# Bid

#### Extends:

eventemitter3~EventEmitter → AdvanceEventEmitter → BidEntity → Bid

Bids are self assessing classes representing the totality of a bid estimate. A bid contains collections of the following type of BidEntitys: LineItem, Metric, Field, Component, Datatable, Assembly, FieldGroup, ComponentGroup.

## Constructor Summary

Public Constructor
public | constructor(bidData: object, bidService: BidService) Creates an instance of Bid. |

## Member Summary

Public Members
public get | actualCost: number |
public set | actualCost: number |
public get | actualHours: number |
public set | actualHours: number |
public get | cost: number |
public set | cost: number Overrides bid cost. |
public get | createdAt: number |
public | entities: BidEntityRelationsHelper |
public get | id: number Persistent id of the bid. |
public set | isActive: boolean Sets the bid active state. |
public get | isActive: boolean Determines if the bid is active. |
public get | laborHours: number |
public get | marginPercent: number |
public set | marginPercent: number |
public set | markup: number |
public get | markup: number Markup Property |
public get | markupPercent: number |
public set | markupPercent: number |
public | maxEvents: number |
public set | price: number |
public get | price: number |
public get | tax: number Tax Property |
public set | taxPercent: number |
public get | taxPercent: number Tax Percent Property |
public get | type: string Gets the type of bid entity. |
public get | updatedAt: number |
public get | watts: number |

## Method Summary

Public Methods
public | async addAssemblies(assemblyMapIds: number[]): Promise<null> Adds assemblies to bid. |
public | async addField(title: string, type: string): Promise<Field> Adds a new field to the bid. |
public | async addLineItem(title: string): Promise<LineItem> Adds a new line item to the bid. |
public | async addMetric(title: string): Promise<Metric> Adds a new metric to the bid. |
public | applySubMarginChange() this method was deprecated. |
public | assess(dependency: BidEntity, forceUpdate: boolean) Assess bid values. |
public | bind() Binds all interconnected bid entity "update" events |
public | canLock(): boolean Determines if bid can be locked by user. |
public | canUnlock(): boolean Determines if bid can be unlocked by user. |
public | clearEntityBindings() Removes all event listeners for the bid entities in a bid. |
public | async clone(): Promise<Bid> Clones the current bid and returns the cloned bid. |
public | async createSnapshot(title: string, description: string): Promise<object> Creates a snapshot of current Bid data. |
public | async delete(): Promise<null> Deletes bid. |
public | dirtyAll() Flags all fields, metrics, lineItems, and components as dirty. |
public | exportData(): object Exports the bid's data to an object. |
public | getIndicativePrice(value: number, isLow: boolean): number Gets indicative price |
public | getMarginOfError(): number Gets the margin of error for indicative pricing. |
public | getMarginPercent(): number Calculates and returns the Bid Margin Percent. |
public | getUncategorizedLineItems(componentGroupId: number): LineItem[] Gets all the uncategorized Line Items by component group. |
public | hasNullDependency(property: string): boolean Determines if a property depends on a null dependency somewhere in it's calculation |
public | includeTaxInMarkup(): boolean Determines if markup should also be assessed on the tax. |
public | isAssessable(): boolean Determines if bid is in an "assessable" state. |
public | isIndicativePricing(): boolean Determines if indicative pricing is enabled. |
public | isLocked(): boolean Determines if the bid is locked. |
public | isPredicted(property: string): boolean Determines if a bid property is predicted. |
public | isReadOnly(): boolean Determines if bid can be modified by the user. |
public | isShell(): boolean Determines if is a shell bid. |
public | isUpdateable(): boolean this method was deprecated. Determines if bid is updateable by the user. |
public | isValid(): boolean Determines if bid has valid dependency references and configurations.. |
public | async lock(): Promise<null> Locks bid, forcing read-only mode for everyone. |
public | needsReassessment(): boolean Analyzes line items and components calculations. |
public | pristine() Marks bid and all bid entities as clean. |
public | reassessAll(forceReassessment: boolean) Reassess all LineItems, Fieldss, Metricss, and {@ linkComponents}s. |
public | async recover(snapshotId: number): Promise<null> Recovers bid to previous snapshot. |
public | async removeAssembly(assemblyId: number): Promise<null> Removes assembly from a bid. |
public | resetMarkup() Globally resets markup on all line items in the bid. |
public | toggleActive() this method was deprecated. use isActive property. |
public | async unlock(): Promise<null> Unlocks bid, making it writable for those with permission. |
public | validate(): object[] Validates bid and returns a resultset of issues, if exists. |

## Inherited Summary

From class AdvanceEventEmitter
public | maxEvents: number Maximum number of events fired for the requester before events stop. |
public | on(eventName: string, requesterId: string, callback: function) |
public | onDelay(eventName: string, ms: number, requesterId: string, callback: function) |
public | removeListenerByRequester(eventName: string, requesterId: string) Removes event listeners by event and requesterId. |

From class BidEntity
public get | id: number Gets the id of the bid entity. |
public get | title: string Gets the bid entity title. |
public set | title: string Sets the bid entity title. |
public get | type: string Gets the bid entity type. |
public abstract | assess(dependency: BidEntity) Assesses bid entity. |
public | dependants(): BidEntity[] Gets an array of depndants that rely on the bid entity. |
public | dependencies(): BidEntity[] Gets all the dependencies that the bid entity relies on. |
public | dirty() Flags the bid entity as dirty and to be saved. |
public | exportData(): object Exports the internal data for the bid entity. |
public | hasNullDependency(field: string): boolean Determines if bid entity relies on a null or undefined dependency value |
public | isDirty(): boolean Determines of bid entity is dirty. |
public | pristine() Marks the bid entity as clean. |

## Public Constructors

### public constructor(bidData: object, bidService: BidService) source

Creates an instance of Bid.

#### Override:

BidEntity#constructor

#### Params:

Name | Type | Attribute | Description
bidData | object |  |
bidService | BidService |  |

## Public Members

### public get actualCost: number source

### public set actualCost: number source

### public get actualHours: number source

### public set actualHours: number source

### public get cost: number source

### public set cost: number source

Overrides bid cost. Overrides are distibuted proportionally to the included line items.

### public get createdAt: number source

### public entities: BidEntityRelationsHelper source

### public get id: number source

Persistent id of the bid. NOTE: id will soon be in alpha-numerical format

#### Override:

BidEntity#id

### public set isActive: boolean source

Sets the bid active state.

### public get isActive: boolean source

Determines if the bid is active.

### public get laborHours: number source

### public get marginPercent: number source

### public set marginPercent: number source

### public set markup: number source

### public get markup: number source

Markup Property

### public get markupPercent: number source

### public set markupPercent: number source

### public maxEvents: number source

Maximum number of events fired for the requester before events stop.

#### Override:

AdvanceEventEmitter#maxEvents

### public set price: number source

### public get price: number source

### public get tax: number source

Tax Property

### public set taxPercent: number source

### public get taxPercent: number source

Tax Percent Property

### public get type: string source

Gets the type of bid entity.

#### Override:

BidEntity#type

### public get updatedAt: number source

### public get watts: number source

## Public Methods

### public async addAssemblies(assemblyMapIds: number[]): Promise<null> source

Adds assemblies to bid. A wrapper function for BidService.addAssemblies

#### Params:

Name | Type | Attribute | Description
assemblyMapIds | number[] |  | An array of assembly mapping ids to add.

#### Return:

Promise<null>

### public async addField(title: string, type: string): Promise<Field> source

Adds a new field to the bid. This is a wrapper function for BidService.addField

#### Params:

Name | Type | Attribute | Description

title

string

- optional
- default: New Field

type

string

- optional
- default: number

#### Return:

Promise<Field>

### public async addLineItem(title: string): Promise<LineItem> source

Adds a new line item to the bid. The added line item is uncategorized in all component groups. This is a wrapper function for BidService.addLineItem

#### Params:

Name | Type | Attribute | Description

title

string

- optional
- default: New Line Item

#### Return:

Promise<LineItem>

### public async addMetric(title: string): Promise<Metric> source

Adds a new metric to the bid. This is a wrapper function for BidService.addMetric

#### Params:

Name | Type | Attribute | Description

title

string

- optional
- default: New Metric

#### Return:

Promise<Metric>

### public applySubMarginChange() source

this method was deprecated.

### public assess(dependency: BidEntity, forceUpdate: boolean) source

Assess bid values. If bid values changes, the bid will be flagged as dirty and an "updated" event will fire.

#### Override:

BidEntity#assess

#### Params:

Name | Type | Attribute | Description

dependency

BidEntity

- nullable: true

The calling dependency.

forceUpdate

boolean

- optional
- nullable: true

Force fires "update" event and flags bid as dirty.

#### Emit:

assessing
assessed
updated

### public bind() source

Binds all interconnected bid entity "update" events

### public canLock(): boolean source

Determines if bid can be locked by user.

#### Return:

boolean

### public canUnlock(): boolean source

Determines if bid can be unlocked by user.

#### Return:

boolean

### public clearEntityBindings() source

Removes all event listeners for the bid entities in a bid. It does not remove any event listeners for the bid itself.

### public async clone(): Promise<Bid> source

Clones the current bid and returns the cloned bid. The cloned bid is also added to the project automatically.

#### Return:

Promise<Bid>

### public async createSnapshot(title: string, description: string): Promise<object> source

Creates a snapshot of current Bid data.

#### Params:

Name | Type | Attribute | Description

title

string

- nullable: true

description

string

- nullable: true

#### Return:

Promise<object> | Returns a data object of the snapshot.

#### Return Properties:

Name | Type | Attribute | Description
id | number |  | The snapshot id.
title | string |  |
bid_id | number |  |
description | string |  |
is_auto | boolean |  | A flag to indicate the snapshot was generated automatically by the PVBid system.
created_at | string |  | Example format: 2016-04-11T21:08:05+00:00

### public async delete(): Promise<null> source

Deletes bid. Wrapper function for BidService.deleteBid

#### Return:

Promise<null>

### public dirtyAll() source

Flags all fields, metrics, lineItems, and components as dirty.

### public exportData(): object source

Exports the bid's data to an object.

#### Override:

BidEntity#exportData

#### Return:

object

#### Return Properties:

Name | Type | Attribute | Description
id | number |  | NOTE: id will soon be in UUID format.
title | string |  |
cost | number |  |
taxable_cost | number |  |
labor_cost | number |  |
labor_hours | number |  |
price | number |  |
margin_percent | number |  |
markup | number |  |
markup_percent | number |  |
tax | number |  |
tax_percent | number |  |
price | number |  |
actual_cost | number |  |
actual_hours | number |  |
watts | number |  |
is_active | boolean |  |
is_locked | boolean |  |
created_at | string |  |
updated_at | string |  |

### public getIndicativePrice(value: number, isLow: boolean): number source

Gets indicative price

#### Params:

Name | Type | Attribute | Description
value | number |  | The value to assess.
isLow | boolean |  | The lower or upper bounds (low | high)

#### Return:

number

### public getMarginOfError(): number source

Gets the margin of error for indicative pricing.

#### Return:

number

### public getMarginPercent(): number source

Calculates and returns the Bid Margin Percent.

#### Return:

number

### public getUncategorizedLineItems(componentGroupId: number): LineItem[] source

Gets all the uncategorized Line Items by component group.

#### Params:

Name | Type | Attribute | Description
componentGroupId | number |  | The component group id.

#### Return:

LineItem[] | Returns an array of Line Items.

### public hasNullDependency(property: string): boolean source

Determines if a property depends on a null dependency somewhere in it's calculation

#### Override:

BidEntity#hasNullDependency

#### Params:

Name | Type | Attribute | Description
property | string |  | The bid property name

#### Return:

boolean

### public includeTaxInMarkup(): boolean source

Determines if markup should also be assessed on the tax.

#### Return:

boolean

### public isAssessable(): boolean source

Determines if bid is in an "assessable" state. Factors include if the bid is as shell bid, if the bid is in read only mode, and if the bid has no validation issues.

#### Return:

boolean

### public isIndicativePricing(): boolean source

Determines if indicative pricing is enabled.

#### Return:

boolean

### public isLocked(): boolean source

Determines if the bid is locked.

#### Return:

boolean

### public isPredicted(property: string): boolean source

Determines if a bid property is predicted.

#### Params:

Name | Type | Attribute | Description
property | string |  | The bid property

#### Return:

boolean

### public isReadOnly(): boolean source

Determines if bid can be modified by the user. Considers if the bid is locked, if the project is closed, and the user permissions.

#### Return:

boolean

### public isShell(): boolean source

Determines if is a shell bid. Shell bids are simple data stores for past bids that can not be assesed. Shell bids do not have line items. Typically shell bids are created to import old bid data prior a companies using PVBid.

#### Return:

boolean

### public isUpdateable(): boolean source

this method was deprecated.

Determines if bid is updateable by the user. This method is deprecated. Use Bid.isReadOnly instead.

#### Return:

boolean

### public isValid(): boolean source

Determines if bid has valid dependency references and configurations..

#### Return:

boolean

### public async lock(): Promise<null> source

Locks bid, forcing read-only mode for everyone. Bid must be unlocked before it can be modified again. This function immediately saves the bid. Will return a rejected promise if the bid cannot be locked.

#### Return:

Promise<null>

### public needsReassessment(): boolean source

Analyzes line items and components calculations. If the sum up correctly to match the bid, reassessment is considered unnecessary.

#### Return:

boolean

### public pristine() source

Marks bid and all bid entities as clean.

#### Override:

BidEntity#pristine

### public reassessAll(forceReassessment: boolean) source

Reassess all LineItems, Fieldss, Metricss, and {@ linkComponents}s. This function checks Bid.needsReassessment first, to determine if reassessment is necessary. Use the force flag to reasses reguardless of necessity.

#### Params:

Name | Type | Attribute | Description
forceReassessment | boolean |  |

### public async recover(snapshotId: number): Promise<null> source

Recovers bid to previous snapshot. An auto snapshot of the current state will be created. This is a wrapper function for BidService.recoverBid

#### Params:

Name | Type | Attribute | Description
snapshotId | number |  |

#### Return:

Promise<null>

### public async removeAssembly(assemblyId: number): Promise<null> source

Removes assembly from a bid. A wrapper function for BidService.removeAssembly

#### Params:

Name | Type | Attribute | Description
assemblyId | number |  |

#### Return:

Promise<null>

### public resetMarkup() source

Globally resets markup on all line items in the bid.

### public toggleActive() source

this method was deprecated. use isActive property.

### public async unlock(): Promise<null> source

Unlocks bid, making it writable for those with permission. This function immediately saves the bid.

#### Return:

Promise<null>

### public validate(): object[] source

Validates bid and returns a resultset of issues, if exists.

#### Return:

object[]