exchangerate direkt in Tabelle oe ablegen.
Die Implementierung, um bei Angeboten/Aufträgen den Wechselkurs pro Beleg
zu speichern folgt in weiteren commits und wird erstmal nur für den neuen
Auftrags-Controller umgesetzt.
Bezieht sich auch auf #135
Refs #135
delivery_vendor_id => { type => 'integer' },
department_id => { type => 'integer' },
employee_id => { type => 'integer' },
+ exchangerate => { type => 'numeric', precision => 15, scale => 5 },
expected_billing_date => { type => 'date' },
globalproject_id => { type => 'integer' },
id => { type => 'integer', not_null => 1, sequence => 'id' },
--- /dev/null
+-- @tag: exchangerate_in_oe
+-- @description: Wechselkurs pro Angebot/Auftrag in Belegtabelle speichern
+-- @depends: release_3_5_5
+
+ALTER TABLE oe ADD COLUMN exchangerate NUMERIC(15,5);
+
+WITH table_ex AS
+ (SELECT oe.id, COALESCE(CASE WHEN customer_id IS NOT NULL THEN buy ELSE sell END, 1.0) AS exchangerate FROM oe
+ LEFT JOIN exchangerate ON (oe.transdate = exchangerate.transdate AND oe.currency_id = exchangerate.currency_id)
+ WHERE oe.currency_id != (SELECT currency_id FROM defaults))
+ UPDATE oe SET exchangerate = (SELECT exchangerate FROM table_ex WHERE table_ex.id = oe.id)
+ WHERE EXISTS (SELECT table_ex.exchangerate FROM table_ex WHERE table_ex.id = oe.id);