Skip to main content

Function: addHarvest()

addHarvest(fdm, principal_id, b_lu, b_lu_harvest_date, b_lu_yield, b_lu_n_harvestable?, b_lu_n_residue?, b_lu_p_harvestable?, b_lu_p_residue?, b_lu_k_harvestable?, b_lu_k_residue?): Promise<any>

Defined in: fdm-core/src/harvest.ts:43

Adds a new harvest to a cultivation.

This function verifies the principal's permission and ensures that the designated cultivation exists before adding a new harvest record. Within a single transaction, it creates associated records for the harvestable, its analyses, and the corresponding sampling entry. If the cultivation allows only one harvest, the function also updates its termination date to the harvest date.

The function assumes that the harvest is not combined with another harvestable and that the analysis is performed on the same day as the harvest.

Parameters

fdm

any

The FDM instance providing the connection to the database. The instance can be created with createFdmServer.

principal_id

any

The principal's ID used for permission verification.

b_lu

any

The cultivation ID.

b_lu_harvest_date

any

The date of the harvest.

b_lu_yield

any

The dry-matter yield for the harvest, in kg/ha.

b_lu_n_harvestable?

any

The total nitrogen content in the harvestable yield (g N/kg).

b_lu_n_residue?

any

The total nitrogen content in the crop residue (g N/kg).

b_lu_p_harvestable?

any

The total phosphorus content in the harvestable yield (g P2O5/kg).

b_lu_p_residue?

any

The total phosphorus content in the crop residue (g P2O5/kg).

b_lu_k_harvestable?

any

The total potassium content in the harvestable yield (g K2O/kg).

b_lu_k_residue?

any

The total potassium content in the crop residue (g K2O/kg).

Returns

Promise<any>

A Promise that resolves with the new harvest's unique identifier.

Throws

Error If the cultivation does not exist, permission checks fail, or any database insertion fails.