Skip to content

UPDATE trip_bill.bill->'operator_fees' (VAT) inside of the bill JSON

Note: bill uuid needs to be queried beforehand with SELECT to the UPDATE query. Note 2: The JSON here is just an example from another trip_bill.

SELECT index, uuid, org_uuid, state, bill->'operator_fees' AS bill_operator_fees FROM trip_bill WHERE uuid = '<TRIP_BILL_UUID>';

BEGIN ;
UPDATE trip_bill SET bill = jsonb_set(bill, '{operator_fees}', '{"items": [{"type": 2, "uuid": "<THIS_IS_UNIQUE_BILL_JSON_UUID_NOT_TRIP_BILL_UUID>", "amount": {"vat": {"nanos": 60000000, "serialized": "1.06", "currency_code": "EUR", "display_float": 1.06, "serialized_currency": "1.06 €"}, "total": {"nanos": 220000000, "units": "2", "serialized": "5.22", "currency_code": "EUR", "display_float": 5.22, "serialized_currency": "5.22 €"}, "value": {"nanos": 160000000, "units": "1", "serialized": "4.16", "currency_code": "EUR", "display_float": 4.16, "serialized_currency": "4.16 €"}, "vat_percent": 25, "vat_percent_fraction": 5}, "created": "2024-07-29T07:51:05Z", "updated": "2024-07-29T07:51:05Z", "metadata_percentage": "5.98", "metadata_percentage_of": "69.54"}], "total": {"vat": {"nanos": 60000000, "serialized": "1.06", "currency_code": "EUR", "display_float": 1.06, "serialized_currency": "1.06 €"}, "total": {"nanos": 220000000, "units": "2", "serialized": "5.22", "currency_code": "EUR", "display_float": 5.22, "serialized_currency": "5.22 €"}, "value": {"nanos": 160000000, "units": "1", "serialized": "4.16", "currency_code": "EUR", "display_float": 4.16, "serialized_currency": "4.16 €"}}, "vat_components": [{"vat": {"nanos": 60000000, "serialized": "1.06", "currency_code": "EUR", "display_float": 1.06, "serialized_currency": "1.06 €"}, "total": {"nanos": 220000000, "units": "2", "serialized": "5.22", "currency_code": "EUR", "display_float": 5.22, "serialized_currency": "5.22 €"}, "value": {"nanos": 160000000, "units": "1", "serialized": "4.16", "currency_code": "EUR", "display_float": 4.16, "serialized_currency": "4.16 €"}, "vat_percent": 25, "vat_percent_fraction": 5}]}', true) WHERE uuid = '<TRIP_BILL_UUID>' RETURNING index, uuid, org_uuid, state, bill->'operator_fees' AS bill_operator_fees;