# JOB_COSTING

job-costing endpoints.

**Base URL:** `https://api.trustpager.com/functions/v1/api/v1`

## Endpoints

### POST /work-orders/:work_order_id/dependencies

Say that a work order can only start once another work order on the same job is done (a dependency on the job timeline). Refused when it would make a loop.

**Scopes:** `work-orders:write` — [full detail](./job-costing/post-work-orders-work-order-id-dependencies.md)

### DELETE /job-costing/staff-rates/:user_id

Clear one team member's cost per hour. Their time then shows under people_without_a_cost_rate on job costing.

**Scopes:** `job-costing:write` — [full detail](./job-costing/delete-job-costing-staff-rates-user-id.md)

### POST /opportunities/:opportunity_id/progress-invoices

Bill the next stage of a job with a progress invoice. Say how far the job is now, cumulatively: percent_complete for the whole contract (30, then 60, then 100), or lines to bill quote lines one by one. It bills only what has not been billed yet (an earlier progress invoice or a deposit invoice is taken off), holds back the job's retention (set_job_retention) as a minus line, and never goes backwards (void its invoice to take it back). The invoice is made from an invoice design (template_id, else the workspace default; it must be an invoice design that bills the full amount), which sets its page, email, due date and GST, and it goes into Xero like any new invoice. Variations are not part of the contract: bill them with create_invoice (deal_product_ids). Once a job has progress invoices, its contract lines can no longer be billed by create_invoice. The invoice is a draft unless status is "open". Send preview true first to show the figures.

**Scopes:** `invoices:write` — [full detail](./job-costing/post-opportunities-opportunity-id-progress-invoices.md)

### GET /opportunities/:opportunity_id/job-costing

Job costing for one opportunity (a customer job): what was quoted against what it is costing. quoted: contract value (the quote lines), variations (extra work added after the job was won), estimated cost (the supplier cost lines on each product) and estimated margin. actual: labour hours and labour cost (time logged on the job times each person's cost per hour; people with no cost rate are listed in people_without_a_cost_rate), materials cost (purchase orders bought for the job), total cost and margin (labour cost, total cost and margin are pay information: null without the job costing write permission, hours and materials cost stay). billing: invoiced and paid so far, how much of the contract has been claimed (claimed_percent, left_to_claim), and retention held, released and outstanding. lines: each quote line with its value, estimated cost, whether it is a variation, and how far it has been claimed. Free read.

**Scopes:** `job-costing:read` — [full detail](./job-costing/get-opportunities-opportunity-id-job-costing.md)

### GET /opportunities/:opportunity_id/timeline

A job's work orders as a timeline (Gantt): each with its title, status, start day (schedule_date) and end day (end_date, or the start day for a one-day job; both null when it has no schedule date yet), whether it is a milestone, the work orders it waits for (depends_on), and clash (the ids of those it is booked to start before the last day of). Ordered by start day. Free read.

**Scopes:** `work-orders:read` — [full detail](./job-costing/get-opportunities-opportunity-id-timeline.md)

### GET /opportunities/:opportunity_id/progress-invoices

The progress invoices on a job, oldest first: number, kind (progress or retention_release), how far the job was billed to, the lines billed, the amount before and after retention, the retention held, and the invoice made (number and status; one whose invoice was voided no longer counts). Also returns the contract value, claimed_percent (how much of the contract has been billed by progress invoices and deposits) and retention totals. Free read.

**Scopes:** `invoices:read` — [full detail](./job-costing/get-opportunities-opportunity-id-progress-invoices.md)

### GET /job-costing/staff-rates

Every member of the workspace with their cost per hour (what an hour of their time costs the business, used by get_job_costing to turn logged time into labour cost), or null when none is set. Pay information, so it needs the job costing write permission. Free read.

**Scopes:** `job-costing:write` — [full detail](./job-costing/get-job-costing-staff-rates.md)

### POST /opportunities/:opportunity_id/progress-invoices/retention-release

Bill retention held on a job back to the customer (all of what is still held, or an amount for a release in stages), and create its invoice from an invoice design (template_id, else the workspace default), the same way as a progress invoice. The invoice is a draft unless status is "open".

**Scopes:** `invoices:write` — [full detail](./job-costing/post-opportunities-opportunity-id-progress-invoices-retention-release.md)

### DELETE /work-orders/:work_order_id/dependencies/:depends_on_work_order_id

Remove a dependency between two work orders on the job timeline.

**Scopes:** `work-orders:delete` — [full detail](./job-costing/delete-work-orders-work-order-id-dependencies-depends-on-work-order-id.md)

### PATCH /opportunities/:opportunity_id/retention

Set the retention on a job: the percent held back from every progress invoice (0 to 20), billed later with release_retention. Applies to progress invoices made from now on; earlier ones keep what they held.

**Scopes:** `opportunities:write` — [full detail](./job-costing/patch-opportunities-opportunity-id-retention.md)

### PATCH /job-costing/staff-rates/:user_id

Set what an hour of one team member's time costs the business (cost per hour, ex GST). Job costing uses it to turn time logged on a job into labour cost. Replaces any rate already set.

**Scopes:** `job-costing:write` — [full detail](./job-costing/patch-job-costing-staff-rates-user-id.md)
