UPDATE billing_bill_items
JOIN billing_item_pricelists ON billing_item_pricelists.item_id = billing_bill_items.item_id AND billing_item_pricelists.pricelist_id = 1
SET billing_bill_items.unit_cost = billing_item_pricelists.price
WHERE billing_bill_items.item_id = billing_item_pricelists.item_id
AND billing_item_pricelists.pricelist_id = 1;

UPDATE billing_bill_items SET cost = unit_cost * quantity;

UPDATE billing_bills SET billing_bills.cost = (SELECT SUM(billing_bill_items.cost) FROM billing_bill_items WHERE billing_bill_items.transaction_id = billing_bills.id);

UPDATE billing_invoice_items
JOIN billing_item_pricelists ON billing_item_pricelists.item_id = billing_invoice_items.item_id AND billing_item_pricelists.pricelist_id = 1
SET billing_invoice_items.unit_cost = billing_item_pricelists.price
WHERE billing_invoice_items.item_id = billing_item_pricelists.item_id
AND billing_item_pricelists.pricelist_id = 1;

UPDATE billing_invoice_items SET cost = unit_cost * quantity;

UPDATE billing_invoices SET billing_invoices.cost = (SELECT SUM(billing_invoice_items.cost) FROM billing_invoice_items WHERE billing_invoice_items.transaction_id = billing_invoices.id);
