{"_id":"55116f04e2990b0d00fb054d","parentDoc":null,"__v":18,"user":"54cba76f6d1eee0d00c33dee","version":{"_id":"54f8de4e4339bb1900c8bffb","project":"54c0e51215af820d001a38a6","forked_from":"54f8de14c6cabe23005c02a2","__v":31,"createdAt":"2015-03-05T22:53:02.044Z","releaseDate":"2015-03-05T22:53:02.044Z","categories":["54f8de4e4339bb1900c8bffc","54f8de4e4339bb1900c8bffd","54f8de4e4339bb1900c8bffe","54f8de4e4339bb1900c8bfff","54f8de4e4339bb1900c8c000","54ff6057563d7419002d666e","55007b6ecfeeea17004717dc","5501d779f2ef1e0d003116eb","55116ef89f7c7619005f853b","554bb366f245703100ddd39f","554d226b374fec0d007e64db","555e09f18ab3180d001ac605","555e0b2b4f5e5a0d00836d77","561d1f8b92a0cc350018b24f","562a956c96b5f40d0026eb60","5654c3378a26202b00c17cb8","5697a94b0b09a41900b24546","5739d89e37b52e3200a3a3cc","57ac94252c0b220e00a94570","57ac97a1ad44fc0e003be066","57ac9a3a8f312d0e00e96c75","57ac9c187ae5c60e004ba3a3","58178bee62e4500f009404f6","581a39711a63870f008b621d","581a3b4f0c65b20f00247fcb","5926e0606c729e0f00595f95","5954033ea5bbca002d27ae91","596ce53e0aeafe00157eb1ba","596ce87a8b79f4001a8f6139","598cad2e96193400190d879a","598cbcd3dc20c6000fdfb9c3","598cbd8496193400190d8955","59fcc7c9591add0026c91457","5a020b7856ea82001c8c9342","5a09bc64a91882001c56c2ed"],"is_deprecated":false,"is_hidden":false,"is_beta":true,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1"},"category":{"_id":"55116ef89f7c7619005f853b","project":"54c0e51215af820d001a38a6","__v":1,"pages":["55116f04e2990b0d00fb054d"],"version":"54f8de4e4339bb1900c8bffb","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-03-24T14:04:40.355Z","from_sync":false,"order":10,"slug":"work-order-line-items","title":"Work Order Line Items"},"project":"54c0e51215af820d001a38a6","updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-03-24T14:04:52.882Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":0,"body":"Work order line items specify each unit of work that the work order targets. Line items must reference either a ``Service Task`` or an ``Issue``, and support fields such as description, labor cost, and parts cost. For more information about work orders and line items in general, please reference our [help center docs](http://help.fleetio.com/article/98-work-order-overview).\n\n##Item\nAs mentioned above, each line item must reference either a ``Service Task`` or an ``Issue``. This association is called ``item`` in Fleetio and is polymorphic. In a standard belongs-to association, a child belongs-to a parent and that parent is always the same class. Such as a fuel entry always belonging to a vehicle. A polymorphic association is a belongs-to association where the parent object can be one of a number of classes, such as a meter entry belonging to either a fuel entry, service, entry, work order, etc.\n\nA polymorphic association is typically defined by two fields: the standard ``foreign key`` field and a ``type`` field which serves as the placeholder for the parent's class name. For work order line items (and several other resources in Fleetio), the foreign key is called ``item_id`` and the type field is called ``item_type``. If you wish to create a line item that is associated with a Service Task with an id of 12345, you would set item_type to \"ServiceTask\" and item_id to 12345. Both fields are required.\n\n##Parts and Labor\nLine items allow for the specification of cost for both parts and labor. There are two ways to denote these costs for each line item, either by specifying the cost directly, or by adding parts and labor sub line items to the line item in question.\n\nTo add costs directly to a line item, simply pass a value to the ``parts_cost`` and/or ``labor_cost`` fields.\n\nAdding sub line items is a bit trickier, but not terribly complicated in the long run. Each line item can have many sub line items (or none at all), which specify any parts used or any labor performed. Sub line items support 3 properties: ``item``, ``unit_cost``, and ``quantity``. unit_cost and quantity should be self explanatory. The total cost for the sub line item is simply calculated as ``unit_cost * quantity``.  The ``item`` property for sub line items works exactly the same way as it does for line items. There is an ``item_type`` field and an ``item_id`` field. Supported values for ``item_type`` are ``\"Part\"`` (denotes a part line item), and ``\"Contact\"`` (denotes a labor line item). Below is an example creation of a line item with a part and a labor sub line item:\n[block:code]\n{\n  \"codes\": [\n    {\n      \"code\": \"curl https://secure.fleetio.com/api/v1/work_orders/123/work_order_line_items \\\\\\n  -H 'Authorization: Token token=\\\"API_KEY\\\"' \\\\\\n\\t-H \\\"Account-Token: ACCOUNT_TOKEN\\\" \\\\\\n  -H \\\"Content-Type: application/json\\\" \\\\\\n  -X POST -d '{\\n\\t\\t\\\"item_type\\\": \\\"ServiceTask\\\",\\n    \\\"item_id\\\": 12345,\\n    \\\"description\\\": \\\"Replacing brake pads\\\",\\n    \\\"work_order_sub_line_item_attributes\\\":[\\n      {\\n        \\\"item_type\\\": \\\"Part\\\",\\n\\t\\t\\t\\t\\\"item_id\\\": 101,\\n        \\\"unit_cost\\\": 9.95,\\n        \\\"quantity\\\": 2\\n      },\\n      {\\n        \\\"item_type\\\": \\\"Contact\\\",\\n\\t\\t\\t\\t\\\"item_id\\\": 4455,\\n        \\\"unit_cost\\\": 24,\\n        \\\"quantity\\\": 0.5\\n      }]\\n  }'\",\n      \"language\": \"curl\"\n    }\n  ]\n}\n[/block]\nThe above example will create a line item for work order #123. The line item will be associated with the service task #12345 and will have 1 part line item and 1 labor line item. The part line item will be associated to part #101 and have a total cost of $19.90, while the labor line item will reference contact #4455 and will have a total cost of $12.00. The line item will then be created with a ``part_cost`` of 19.90 and a ``labor_cost`` of 12.00, causing the work order's ``total_amount`` to be recalculated to a value of 31.90.\n\n## Work order line item fields\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"``item_type``\",\n    \"h-0\": \"Field\",\n    \"h-1\": \"Description\",\n    \"0-1\": \"***string*** (required, editable)\\nUsed in conjunction with ``item_id`` denotes the class name for the ``item`` association. Valid values are ``\\\"ServiceTask\\\"`` and ``\\\"Issue\\\"``.\",\n    \"1-0\": \"``item_id``\",\n    \"1-1\": \"***integer*** (required, editable)\\nUsed in conjunction with ``item_id``, denotes the foreign key for the ``item`` association.\",\n    \"2-0\": \"``description``\",\n    \"2-1\": \"***text*** (optional, editable)\\nFree text field for item description.\",\n    \"3-0\": \"``labor_cost``\",\n    \"3-1\": \"***double*** (optional, editable)\\nTotal labor cost for this line item. If there are labor line items present, the labor cost will be calculated from the sum of their totals and this value will be overwritten.\",\n    \"4-0\": \"``parts_cost``\",\n    \"4-1\": \"***double*** (optional, editable)\\nTotal parts cost for this line item. If there are part line items present, the labor cost will be calculated from the sum of their totals and this value will be overwritten.\"\n  },\n  \"cols\": 2,\n  \"rows\": 5\n}\n[/block]\n## Work order sub line item fields\n[block:parameters]\n{\n  \"data\": {\n    \"0-0\": \"``item_type``\",\n    \"1-0\": \"``item_id``\",\n    \"h-0\": \"Field\",\n    \"h-1\": \"Description\",\n    \"2-0\": \"``unit_cost``\",\n    \"3-0\": \"``quantity``\",\n    \"0-1\": \"***string*** (required, editable)\\nUsed in conjunction with ``item_id`` denotes the class name for the ``item`` association. Valid values are ``\\\"Part\\\"`` and ``\\\"Contact\\\"`` for part line items and labor line items respectively.\",\n    \"1-1\": \"***integer*** (required, editable)\\nUsed in conjunction with ``item_id``, denotes the foreign key for the ``item`` association.\",\n    \"2-1\": \"***double*** (optional, editable)\\nCost per unit for part or labor. If labor, this represents the contact's hourly labor rate.\",\n    \"3-1\": \"***double*** (optional, editable)\\nNumber of units for this line item. If labor, this represents the number of hours the contact worked.\"\n  },\n  \"cols\": 2,\n  \"rows\": 4\n}\n[/block]","excerpt":"","slug":"reference-2","type":"basic","title":"Reference"}
Work order line items specify each unit of work that the work order targets. Line items must reference either a ``Service Task`` or an ``Issue``, and support fields such as description, labor cost, and parts cost. For more information about work orders and line items in general, please reference our [help center docs](http://help.fleetio.com/article/98-work-order-overview). ##Item As mentioned above, each line item must reference either a ``Service Task`` or an ``Issue``. This association is called ``item`` in Fleetio and is polymorphic. In a standard belongs-to association, a child belongs-to a parent and that parent is always the same class. Such as a fuel entry always belonging to a vehicle. A polymorphic association is a belongs-to association where the parent object can be one of a number of classes, such as a meter entry belonging to either a fuel entry, service, entry, work order, etc. A polymorphic association is typically defined by two fields: the standard ``foreign key`` field and a ``type`` field which serves as the placeholder for the parent's class name. For work order line items (and several other resources in Fleetio), the foreign key is called ``item_id`` and the type field is called ``item_type``. If you wish to create a line item that is associated with a Service Task with an id of 12345, you would set item_type to "ServiceTask" and item_id to 12345. Both fields are required. ##Parts and Labor Line items allow for the specification of cost for both parts and labor. There are two ways to denote these costs for each line item, either by specifying the cost directly, or by adding parts and labor sub line items to the line item in question. To add costs directly to a line item, simply pass a value to the ``parts_cost`` and/or ``labor_cost`` fields. Adding sub line items is a bit trickier, but not terribly complicated in the long run. Each line item can have many sub line items (or none at all), which specify any parts used or any labor performed. Sub line items support 3 properties: ``item``, ``unit_cost``, and ``quantity``. unit_cost and quantity should be self explanatory. The total cost for the sub line item is simply calculated as ``unit_cost * quantity``. The ``item`` property for sub line items works exactly the same way as it does for line items. There is an ``item_type`` field and an ``item_id`` field. Supported values for ``item_type`` are ``"Part"`` (denotes a part line item), and ``"Contact"`` (denotes a labor line item). Below is an example creation of a line item with a part and a labor sub line item: [block:code] { "codes": [ { "code": "curl https://secure.fleetio.com/api/v1/work_orders/123/work_order_line_items \\\n -H 'Authorization: Token token=\"API_KEY\"' \\\n\t-H \"Account-Token: ACCOUNT_TOKEN\" \\\n -H \"Content-Type: application/json\" \\\n -X POST -d '{\n\t\t\"item_type\": \"ServiceTask\",\n \"item_id\": 12345,\n \"description\": \"Replacing brake pads\",\n \"work_order_sub_line_item_attributes\":[\n {\n \"item_type\": \"Part\",\n\t\t\t\t\"item_id\": 101,\n \"unit_cost\": 9.95,\n \"quantity\": 2\n },\n {\n \"item_type\": \"Contact\",\n\t\t\t\t\"item_id\": 4455,\n \"unit_cost\": 24,\n \"quantity\": 0.5\n }]\n }'", "language": "curl" } ] } [/block] The above example will create a line item for work order #123. The line item will be associated with the service task #12345 and will have 1 part line item and 1 labor line item. The part line item will be associated to part #101 and have a total cost of $19.90, while the labor line item will reference contact #4455 and will have a total cost of $12.00. The line item will then be created with a ``part_cost`` of 19.90 and a ``labor_cost`` of 12.00, causing the work order's ``total_amount`` to be recalculated to a value of 31.90. ## Work order line item fields [block:parameters] { "data": { "0-0": "``item_type``", "h-0": "Field", "h-1": "Description", "0-1": "***string*** (required, editable)\nUsed in conjunction with ``item_id`` denotes the class name for the ``item`` association. Valid values are ``\"ServiceTask\"`` and ``\"Issue\"``.", "1-0": "``item_id``", "1-1": "***integer*** (required, editable)\nUsed in conjunction with ``item_id``, denotes the foreign key for the ``item`` association.", "2-0": "``description``", "2-1": "***text*** (optional, editable)\nFree text field for item description.", "3-0": "``labor_cost``", "3-1": "***double*** (optional, editable)\nTotal labor cost for this line item. If there are labor line items present, the labor cost will be calculated from the sum of their totals and this value will be overwritten.", "4-0": "``parts_cost``", "4-1": "***double*** (optional, editable)\nTotal parts cost for this line item. If there are part line items present, the labor cost will be calculated from the sum of their totals and this value will be overwritten." }, "cols": 2, "rows": 5 } [/block] ## Work order sub line item fields [block:parameters] { "data": { "0-0": "``item_type``", "1-0": "``item_id``", "h-0": "Field", "h-1": "Description", "2-0": "``unit_cost``", "3-0": "``quantity``", "0-1": "***string*** (required, editable)\nUsed in conjunction with ``item_id`` denotes the class name for the ``item`` association. Valid values are ``\"Part\"`` and ``\"Contact\"`` for part line items and labor line items respectively.", "1-1": "***integer*** (required, editable)\nUsed in conjunction with ``item_id``, denotes the foreign key for the ``item`` association.", "2-1": "***double*** (optional, editable)\nCost per unit for part or labor. If labor, this represents the contact's hourly labor rate.", "3-1": "***double*** (optional, editable)\nNumber of units for this line item. If labor, this represents the number of hours the contact worked." }, "cols": 2, "rows": 4 } [/block]