Commit all views for ITSA
This commit is contained in:
188
Database Backups/SQL Views/view_by_forex.sql
Normal file
188
Database Backups/SQL Views/view_by_forex.sql
Normal file
@@ -0,0 +1,188 @@
|
||||
CREATE OR REPLACE VIEW public.view_by_forex AS
|
||||
WITH contract_lines AS (
|
||||
SELECT forex.id AS forex_id,
|
||||
forex.number AS forex_number,
|
||||
fcpc.id AS fcpc_id,
|
||||
fcpc.amount AS forex_amount,
|
||||
fcpc.amount AS forex_amount_for_all,
|
||||
((fcpc.amount)::double precision * (((lh.quantity)::double precision * (unit.factor / unit_line.factor)) / pl.quantity)) AS line_amount,
|
||||
((pl.unit_price)::double precision * ((lh.quantity)::double precision * (unit.factor / unit_line.factor))) AS qt_amount,
|
||||
p.id AS purchase_id,
|
||||
p.number AS purchase_number,
|
||||
pl.id AS purchase_line_id,
|
||||
pl.quantity,
|
||||
pp.code AS product_code,
|
||||
cc.code AS currency,
|
||||
ll.lot_type,
|
||||
ll.invoice_line,
|
||||
ll.invoice_line_prov,
|
||||
aml.reconciliation
|
||||
FROM (((((((((((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((p.currency = cc.id)))
|
||||
LEFT JOIN lot_lot ll ON ((pl.id = ll.line)))
|
||||
LEFT JOIN lot_qt_hist lh ON ((lh.lot = ll.id)))
|
||||
LEFT JOIN lot_qt_type lt ON (((lh.quantity_type = lt.id) AND (lt.sequence = 1))))
|
||||
LEFT JOIN product_uom unit ON ((unit.id = pl.unit)))
|
||||
LEFT JOIN product_uom unit_line ON ((unit_line.id = ll.lot_unit_line)))
|
||||
LEFT JOIN account_move_line aml ON (((split_part((aml.origin)::text, ','::text, 1) = 'invoice.line'::text) AND ((ll.invoice_line_prov = (split_part((aml.origin)::text, ','::text, 2))::integer) OR (ll.invoice_line = (split_part((aml.origin)::text, ','::text, 2))::integer)))))
|
||||
WHERE ((forex.move IS NULL) AND (forex.buy_currency = 2))
|
||||
), contracts_by_status AS (
|
||||
SELECT contract_lines.forex_id,
|
||||
contract_lines.forex_number,
|
||||
contract_lines.fcpc_id,
|
||||
contract_lines.line_amount,
|
||||
contract_lines.forex_amount,
|
||||
contract_lines.forex_amount_for_all,
|
||||
contract_lines.qt_amount,
|
||||
contract_lines.purchase_id,
|
||||
contract_lines.purchase_number,
|
||||
contract_lines.purchase_line_id,
|
||||
contract_lines.quantity,
|
||||
contract_lines.product_code,
|
||||
contract_lines.currency,
|
||||
contract_lines.lot_type,
|
||||
contract_lines.invoice_line,
|
||||
contract_lines.invoice_line_prov,
|
||||
contract_lines.reconciliation,
|
||||
CASE
|
||||
WHEN ((contract_lines.lot_type)::text = 'virtual'::text) THEN 'open'::text
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND (contract_lines.invoice_line IS NULL) AND (contract_lines.invoice_line_prov IS NULL)) THEN 'shipped'::text
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND ((contract_lines.invoice_line IS NOT NULL) OR (contract_lines.invoice_line_prov IS NOT NULL)) AND ((contract_lines.reconciliation IS NULL) OR (contract_lines.reconciliation = 0))) THEN 'invoiced'::text
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND ((contract_lines.invoice_line IS NOT NULL) OR (contract_lines.invoice_line_prov IS NOT NULL)) AND (contract_lines.reconciliation > 0)) THEN 'paid'::text
|
||||
ELSE 'total'::text
|
||||
END AS qt_type,
|
||||
CASE
|
||||
WHEN ((contract_lines.lot_type)::text = 'virtual'::text) THEN 1
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND (contract_lines.invoice_line IS NULL) AND (contract_lines.invoice_line_prov IS NULL)) THEN 2
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND ((contract_lines.invoice_line IS NOT NULL) OR (contract_lines.invoice_line_prov IS NOT NULL)) AND ((contract_lines.reconciliation IS NULL) OR (contract_lines.reconciliation = 0))) THEN 3
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND ((contract_lines.invoice_line IS NOT NULL) OR (contract_lines.invoice_line_prov IS NOT NULL)) AND (contract_lines.reconciliation > 0)) THEN 4
|
||||
ELSE 0
|
||||
END AS qt_order
|
||||
FROM contract_lines
|
||||
), amounts_adjusted AS (
|
||||
SELECT c.forex_id,
|
||||
c.fcpc_id,
|
||||
c.purchase_id,
|
||||
c.purchase_number,
|
||||
c.purchase_line_id,
|
||||
c.product_code,
|
||||
c.currency,
|
||||
c.qt_type,
|
||||
c.qt_order,
|
||||
c.line_amount,
|
||||
c.qt_amount,
|
||||
NULL::numeric AS forex_amount,
|
||||
GREATEST(LEAST(COALESCE(c.line_amount, (0)::double precision), ((COALESCE(c.forex_amount_for_all, (0)::numeric))::double precision - COALESCE(sum(COALESCE(c.line_amount, (0)::double precision)) OVER (PARTITION BY c.forex_id, c.fcpc_id ORDER BY c.qt_order DESC, c.purchase_line_id, c.invoice_line ROWS BETWEEN UNBOUNDED PRECEDING AND 1 PRECEDING), (0)::double precision))), (0)::double precision) AS amount_covered
|
||||
FROM contracts_by_status c
|
||||
WHERE (c.qt_type = ANY (ARRAY['paid'::text, 'invoiced'::text, 'shipped'::text, 'open'::text]))
|
||||
), amounts_total AS (
|
||||
SELECT a.forex_id,
|
||||
a.fcpc_id,
|
||||
a.purchase_id,
|
||||
a.purchase_number,
|
||||
NULL::integer AS purchase_line_id,
|
||||
NULL::text AS product_code,
|
||||
max((a.currency)::text) AS currency,
|
||||
'total'::text AS qt_type,
|
||||
5 AS qt_order,
|
||||
NULL::numeric AS line_amount,
|
||||
NULL::numeric AS qt_amount,
|
||||
max(fcpc.amount) AS forex_amount,
|
||||
NULL::numeric AS amount_covered
|
||||
FROM (((forex_cover_physical_contract fcpc
|
||||
JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
JOIN forex_forex f ON ((f.id = fcpc.forex)))
|
||||
JOIN amounts_adjusted a ON (((a.fcpc_id = fcpc.id) AND (a.purchase_id = p.id))))
|
||||
GROUP BY a.forex_id, a.fcpc_id, a.purchase_id, a.purchase_number
|
||||
), forex_summary AS (
|
||||
SELECT forex.number AS forex_number,
|
||||
'forex'::text AS line_type,
|
||||
NULL::text AS purchase_number,
|
||||
NULL::text AS purchase_line,
|
||||
NULL::text AS qt_type,
|
||||
0 AS qt_order,
|
||||
max(forex.rate) AS rate,
|
||||
NULL::numeric AS amount_covered,
|
||||
NULL::numeric AS forex_amount,
|
||||
NULL::numeric AS qt_amount,
|
||||
forex.buy_amount AS total_amount_forex,
|
||||
(forex.buy_amount - COALESCE(sum(fcpc.amount), (0)::numeric)) AS amount_remaining,
|
||||
max((cc.code)::text) AS currency,
|
||||
forex.value_date AS maturity_date,
|
||||
forex.move
|
||||
FROM ((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN currency_currency cc ON ((forex.buy_currency = cc.id)))
|
||||
WHERE ((forex.move IS NULL) AND (forex.buy_currency = 2))
|
||||
GROUP BY forex.id, forex.number, forex.buy_amount
|
||||
)
|
||||
SELECT forex_summary.forex_number,
|
||||
forex_summary.line_type,
|
||||
forex_summary.purchase_number,
|
||||
forex_summary.purchase_line,
|
||||
forex_summary.qt_type,
|
||||
forex_summary.qt_order,
|
||||
forex_summary.rate,
|
||||
forex_summary.amount_covered,
|
||||
forex_summary.forex_amount,
|
||||
forex_summary.qt_amount,
|
||||
forex_summary.total_amount_forex,
|
||||
forex_summary.amount_remaining,
|
||||
forex_summary.currency,
|
||||
forex_summary.maturity_date,
|
||||
CASE
|
||||
WHEN (forex_summary.move > 0) THEN 'executed'::text
|
||||
ELSE 'not executed'::text
|
||||
END AS executed
|
||||
FROM forex_summary
|
||||
UNION ALL
|
||||
SELECT c.number AS forex_number,
|
||||
'contract'::text AS line_type,
|
||||
a.purchase_number,
|
||||
((a.product_code)::text || COALESCE(((' ('::text || a.purchase_line_id) || ')'::text), ''::text)) AS purchase_line,
|
||||
a.qt_type,
|
||||
a.qt_order,
|
||||
NULL::numeric AS rate,
|
||||
a.amount_covered,
|
||||
a.forex_amount,
|
||||
a.qt_amount,
|
||||
NULL::numeric AS total_amount_forex,
|
||||
NULL::numeric AS amount_remaining,
|
||||
a.currency,
|
||||
NULL::date AS maturity_date,
|
||||
NULL::text AS executed
|
||||
FROM (( SELECT amounts_adjusted.forex_id,
|
||||
amounts_adjusted.fcpc_id,
|
||||
amounts_adjusted.purchase_id,
|
||||
amounts_adjusted.purchase_number,
|
||||
amounts_adjusted.purchase_line_id,
|
||||
amounts_adjusted.product_code,
|
||||
amounts_adjusted.currency,
|
||||
amounts_adjusted.qt_type,
|
||||
amounts_adjusted.qt_order,
|
||||
amounts_adjusted.line_amount,
|
||||
amounts_adjusted.qt_amount,
|
||||
amounts_adjusted.forex_amount,
|
||||
amounts_adjusted.amount_covered
|
||||
FROM amounts_adjusted
|
||||
UNION ALL
|
||||
SELECT amounts_total.forex_id,
|
||||
amounts_total.fcpc_id,
|
||||
amounts_total.purchase_id,
|
||||
amounts_total.purchase_number,
|
||||
amounts_total.purchase_line_id,
|
||||
amounts_total.product_code,
|
||||
amounts_total.currency,
|
||||
amounts_total.qt_type,
|
||||
amounts_total.qt_order,
|
||||
amounts_total.line_amount,
|
||||
amounts_total.qt_amount,
|
||||
amounts_total.forex_amount,
|
||||
amounts_total.amount_covered
|
||||
FROM amounts_total) a
|
||||
JOIN forex_forex c ON ((c.id = a.forex_id)))
|
||||
ORDER BY 1, 2 DESC, 3, 6 DESC;;
|
||||
34
Database Backups/SQL Views/view_contract_blocked.sql
Normal file
34
Database Backups/SQL Views/view_contract_blocked.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
CREATE OR REPLACE VIEW public.view_contract_blocked AS
|
||||
SELECT p.number AS purchase_number,
|
||||
'contract'::text AS line_type,
|
||||
NULL::character varying AS forex_number,
|
||||
NULL::numeric AS amount_covered,
|
||||
string_agg(DISTINCT (pp.code)::text, ', '::text) AS products,
|
||||
max((pl.quantity * (pl.unit_price)::double precision)) AS total_contract_value,
|
||||
(max((pl.quantity * (pl.unit_price)::double precision)) - (sum(fcpc.amount))::double precision) AS amount_remaining,
|
||||
max((cc.code)::text) AS currency,
|
||||
NULL::numeric AS rate,
|
||||
NULL::date AS maturity_date
|
||||
FROM ((((purchase_purchase p
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((p.currency = cc.id)))
|
||||
WHERE (p.currency = 2)
|
||||
GROUP BY p.number, pl.id
|
||||
UNION ALL
|
||||
SELECT p.number AS purchase_number,
|
||||
'forex'::text AS line_type,
|
||||
forex.number AS forex_number,
|
||||
fcpc.amount AS amount_covered,
|
||||
NULL::text AS products,
|
||||
NULL::numeric AS total_contract_value,
|
||||
NULL::numeric AS amount_remaining,
|
||||
cc.code AS currency,
|
||||
forex.rate,
|
||||
forex.value_date AS maturity_date
|
||||
FROM (((purchase_purchase p
|
||||
JOIN forex_cover_physical_contract fcpc ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN forex_forex forex ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN currency_currency cc ON ((forex.buy_currency = cc.id)))
|
||||
ORDER BY 1, 2;;
|
||||
98
Database Backups/SQL Views/view_forex_blocked.sql
Normal file
98
Database Backups/SQL Views/view_forex_blocked.sql
Normal file
@@ -0,0 +1,98 @@
|
||||
CREATE OR REPLACE VIEW public.view_forex_blocked AS
|
||||
SELECT forex.number AS forex_number,
|
||||
'forex'::text AS line_type,
|
||||
NULL::character varying AS purchase_number,
|
||||
NULL::text AS purchase_line,
|
||||
NULL::text AS qt_type,
|
||||
max(forex.rate) AS rate,
|
||||
NULL::numeric AS amount_covered,
|
||||
forex.buy_amount AS total_amount_forex,
|
||||
(forex.buy_amount - COALESCE(sum(fcpc.amount), (0)::numeric)) AS amount_remaining,
|
||||
max((cc.code)::text) AS currency,
|
||||
forex.value_date AS maturity_date
|
||||
FROM ((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN currency_currency cc ON ((forex.buy_currency = cc.id)))
|
||||
GROUP BY forex.id, forex.number, forex.buy_amount
|
||||
UNION ALL
|
||||
SELECT forex.number AS forex_number,
|
||||
'contract'::text AS line_type,
|
||||
p.number AS purchase_number,
|
||||
((((pp.code)::text || ' ('::text) || pl.quantity) || ')'::text) AS purchase_line,
|
||||
'open'::text AS qt_type,
|
||||
NULL::numeric AS rate,
|
||||
fcpc.amount AS amount_covered,
|
||||
NULL::numeric AS total_amount_forex,
|
||||
NULL::numeric AS amount_remaining,
|
||||
cc.code AS currency,
|
||||
NULL::date AS maturity_date
|
||||
FROM ((((((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((p.currency = cc.id)))
|
||||
LEFT JOIN lot_lot ll ON ((pl.id = ll.line)))
|
||||
WHERE ((ll.lot_type)::text = 'virtual'::text)
|
||||
UNION ALL
|
||||
SELECT forex.number AS forex_number,
|
||||
'contract'::text AS line_type,
|
||||
p.number AS purchase_number,
|
||||
((((pp.code)::text || ' ('::text) || pl.quantity) || ')'::text) AS purchase_line,
|
||||
'shipped'::text AS qt_type,
|
||||
NULL::numeric AS rate,
|
||||
fcpc.amount AS amount_covered,
|
||||
NULL::numeric AS total_amount_forex,
|
||||
NULL::numeric AS amount_remaining,
|
||||
cc.code AS currency,
|
||||
NULL::date AS maturity_date
|
||||
FROM ((((((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((p.currency = cc.id)))
|
||||
LEFT JOIN lot_lot ll ON ((pl.id = ll.line)))
|
||||
WHERE (((ll.lot_type)::text = 'physic'::text) AND (ll.invoice_line_prov IS NULL) AND (ll.invoice_line IS NULL))
|
||||
UNION ALL
|
||||
SELECT forex.number AS forex_number,
|
||||
'contract'::text AS line_type,
|
||||
p.number AS purchase_number,
|
||||
((((pp.code)::text || ' ('::text) || pl.quantity) || ')'::text) AS purchase_line,
|
||||
'invoiced'::text AS qt_type,
|
||||
NULL::numeric AS rate,
|
||||
fcpc.amount AS amount_covered,
|
||||
NULL::numeric AS total_amount_forex,
|
||||
NULL::numeric AS amount_remaining,
|
||||
cc.code AS currency,
|
||||
NULL::date AS maturity_date
|
||||
FROM ((((((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((p.currency = cc.id)))
|
||||
LEFT JOIN lot_lot ll ON ((pl.id = ll.line)))
|
||||
WHERE (((ll.lot_type)::text = 'physic'::text) AND ((ll.invoice_line_prov > 0) OR (ll.invoice_line > 0)))
|
||||
UNION ALL
|
||||
SELECT forex.number AS forex_number,
|
||||
'contract'::text AS line_type,
|
||||
p.number AS purchase_number,
|
||||
((((pp.code)::text || ' ('::text) || pl.quantity) || ')'::text) AS purchase_line,
|
||||
'paid'::text AS qt_type,
|
||||
NULL::numeric AS rate,
|
||||
fcpc.amount AS amount_covered,
|
||||
NULL::numeric AS total_amount_forex,
|
||||
NULL::numeric AS amount_remaining,
|
||||
cc.code AS currency,
|
||||
NULL::date AS maturity_date
|
||||
FROM (((((((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((p.currency = cc.id)))
|
||||
LEFT JOIN lot_lot ll ON ((pl.id = ll.line)))
|
||||
LEFT JOIN account_move_line aml ON (((split_part((aml.origin)::text, ','::text, 1) = 'invoice.line'::text) AND ((ll.invoice_line_prov = (split_part((aml.origin)::text, ','::text, 2))::integer) OR (ll.invoice_line = (split_part((aml.origin)::text, ','::text, 2))::integer)))))
|
||||
WHERE (((ll.lot_type)::text = 'physic'::text) AND ((ll.invoice_line_prov > 0) OR (ll.invoice_line > 0)) AND (aml.reconciliation > 0))
|
||||
ORDER BY 1, 2 DESC;;
|
||||
15
Database Backups/SQL Views/view_forex_summary.sql
Normal file
15
Database Backups/SQL Views/view_forex_summary.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
CREATE OR REPLACE VIEW public.view_forex_summary AS
|
||||
SELECT forex.number AS forex_number,
|
||||
fcpc.id AS coverage_id,
|
||||
p.number AS purchase_number,
|
||||
pp.code AS product_code,
|
||||
pl.quantity AS purchase_quantity,
|
||||
fcpc.amount AS amount_covered,
|
||||
forex.for_amount AS forex_amount,
|
||||
sum(fcpc.amount) OVER (PARTITION BY forex.id ORDER BY fcpc.id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_covered,
|
||||
(forex.for_amount - sum(fcpc.amount) OVER (PARTITION BY forex.id ORDER BY fcpc.id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) AS balance
|
||||
FROM ((((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)));;
|
||||
6
Database Backups/SQL Views/vw_bi_dim_location.sql
Normal file
6
Database Backups/SQL Views/vw_bi_dim_location.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_dim_location AS
|
||||
SELECT "intLocationId",
|
||||
"strLocationName" AS "Location",
|
||||
"strLocationType" AS "Location Type"
|
||||
FROM vw_utility_location
|
||||
WHERE ("ysnIsActive" = true);;
|
||||
14
Database Backups/SQL Views/vw_bi_dim_price_curve.sql
Normal file
14
Database Backups/SQL Views/vw_bi_dim_price_curve.sql
Normal file
@@ -0,0 +1,14 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_dim_price_curve AS
|
||||
SELECT "intPriceCurveId",
|
||||
"strPriceDescription" AS "Description",
|
||||
"strPriceIndex" AS "Index",
|
||||
"strCurrency" AS "Currency",
|
||||
"strUnit" AS "Unit",
|
||||
"strPriceCurveType" AS "Type",
|
||||
"strPriceArea" AS "Area",
|
||||
"strPriceCalendar" AS "Calendard",
|
||||
"strPricingType" AS "Pricing Type",
|
||||
"dtmPricingStartDate" AS "Pricing Start Date",
|
||||
"dtmPricingEndDate" AS "Pricing End Date",
|
||||
"strPricingMonth" AS "Pricing Month"
|
||||
FROM vw_utility_price_curve p;;
|
||||
9
Database Backups/SQL Views/vw_bi_dim_product.sql
Normal file
9
Database Backups/SQL Views/vw_bi_dim_product.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_dim_product AS
|
||||
SELECT "intProductId",
|
||||
"strProductCode" AS "Product Code",
|
||||
"strProductDescription" AS "Description",
|
||||
"ysnActive" AS "Is Active",
|
||||
"strTemplate" AS "Template",
|
||||
"strTemplateCode" AS "Template Code",
|
||||
"strDefaultUom" AS "Default Uom"
|
||||
FROM vw_utility_product pr;;
|
||||
@@ -0,0 +1,45 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_dim_purchase_physical_contract AS
|
||||
SELECT "intPurchaseLineId",
|
||||
"strContractNb" AS "Contract Nb",
|
||||
"strCounterparty" AS "Supplier",
|
||||
"strReference" AS "Contract Ref",
|
||||
"dtmContractDate" AS "Contract Date",
|
||||
CASE
|
||||
WHEN (("strContractStatus")::text = 'Draft'::text) THEN ((("strContractStatus")::text || ' 🧾'::text))::character varying
|
||||
WHEN (("strContractStatus")::text = 'Confirmed'::text) THEN ((("strContractStatus")::text || ' ✅'::text))::character varying
|
||||
WHEN (("strContractStatus")::text = 'Validated'::text) THEN ((("strContractStatus")::text || ' ✔️'::text))::character varying
|
||||
WHEN (("strContractStatus")::text = 'Processing'::text) THEN ((("strContractStatus")::text || ' ⏳'::text))::character varying
|
||||
ELSE "strContractStatus"
|
||||
END AS "Contract Status",
|
||||
"strPaymentTerm" AS "Payment Terms",
|
||||
"strCurrency" AS "Currency",
|
||||
"strWeightBasis" AS "Weight Basis",
|
||||
"strBroker" AS "Broker",
|
||||
"strCertif" AS "Certification",
|
||||
"strAssociation" AS "Association",
|
||||
"strCrop" AS "Crop",
|
||||
"dblTolMinPct" AS "Tolerance Min %",
|
||||
"dblTolMaxPct" AS "Tolerance Max %",
|
||||
"strIncoterm" AS "Inco Terms",
|
||||
"strLoadingPlace" AS "Loading Place",
|
||||
"strDestinationPlace" AS "Destination Place",
|
||||
"strProduct" AS "Product",
|
||||
"strDeliveryPeriod" AS "Delivery Period",
|
||||
"strRegion" AS "Bassin",
|
||||
"strBookName" AS "Book",
|
||||
"strStrategyName" AS "Strategy",
|
||||
"strQuantityUom" AS "Quantity UOM",
|
||||
"dtmDeliveryDateFrom" AS "Delivery Date From",
|
||||
"dtmDeliveryDateTo" AS "Delivery Date To",
|
||||
CASE
|
||||
WHEN ("dtmDeliveryDateTo" < CURRENT_DATE) THEN 'Overdue'::text
|
||||
WHEN (("dtmDeliveryDateFrom" <= CURRENT_DATE) AND ("dtmDeliveryDateTo" >= CURRENT_DATE)) THEN 'Current'::text
|
||||
WHEN ("dtmDeliveryDateFrom" > CURRENT_DATE) THEN 'Future'::text
|
||||
ELSE 'Unknown'::text
|
||||
END AS "Delivery Status",
|
||||
CASE
|
||||
WHEN (("strBookName")::text ~~ '%Projection%'::text) THEN 'Yes'::text
|
||||
ELSE 'No'::text
|
||||
END AS "Is Projection",
|
||||
"strIncotermCode" AS "Incoterm Code"
|
||||
FROM vw_utility_dim_physical_purchase_contract dpc;;
|
||||
@@ -0,0 +1,45 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_dim_sale_physical_contract AS
|
||||
SELECT "intSaleLineId",
|
||||
"strContractNb" AS "Contract Nb",
|
||||
"strCounterparty" AS "Customer",
|
||||
"strReference" AS "Contract Ref",
|
||||
"dtmContractDate" AS "Contract Date",
|
||||
CASE
|
||||
WHEN (("strContractStatus")::text = 'Draft'::text) THEN ((("strContractStatus")::text || ' 🧾'::text))::character varying
|
||||
WHEN (("strContractStatus")::text = 'Confirmed'::text) THEN ((("strContractStatus")::text || ' ✅'::text))::character varying
|
||||
WHEN (("strContractStatus")::text = 'Validated'::text) THEN ((("strContractStatus")::text || ' ✔️'::text))::character varying
|
||||
WHEN (("strContractStatus")::text = 'Processing'::text) THEN ((("strContractStatus")::text || ' ⏳'::text))::character varying
|
||||
ELSE "strContractStatus"
|
||||
END AS "Contract Status",
|
||||
"strPaymentTerm" AS "Payment Terms",
|
||||
"strCurrency" AS "Currency",
|
||||
"strWeightBasis" AS "Weight Basis",
|
||||
"strBroker" AS "Broker",
|
||||
"strCertif" AS "Certification",
|
||||
"strAssociation" AS "Association",
|
||||
"strCrop" AS "Crop",
|
||||
"dblTolMinPct" AS "Tolerance Min %",
|
||||
"dblTolMaxPct" AS "Tolerance Max %",
|
||||
"strIncoterm" AS "Inco Terms",
|
||||
"strLoadingPlace" AS "Loading Place",
|
||||
"strDestinationPlace" AS "Destination Place",
|
||||
"strProduct" AS "Product",
|
||||
"strDeliveryPeriod" AS "Delivery Period",
|
||||
"strQuantityUom" AS "Quantity UOM",
|
||||
"dtmDeliveryDateFrom" AS "Delivery Date From",
|
||||
"dtmDeliveryDateTo" AS "Delivery Date To",
|
||||
CASE
|
||||
WHEN ("dtmDeliveryDateTo" < CURRENT_DATE) THEN 'Overdue'::text
|
||||
WHEN (("dtmDeliveryDateFrom" <= CURRENT_DATE) AND ("dtmDeliveryDateTo" >= CURRENT_DATE)) THEN 'Current'::text
|
||||
WHEN ("dtmDeliveryDateFrom" > CURRENT_DATE) THEN 'Future'::text
|
||||
ELSE 'Unknown'::text
|
||||
END AS "Delivery Status",
|
||||
"strRegion" AS "Bassin",
|
||||
"strBookName" AS "Book",
|
||||
"strStrategyName" AS "Strategy",
|
||||
CASE
|
||||
WHEN (("strBookName")::text ~~ '%Projection%'::text) THEN 'Yes'::text
|
||||
ELSE 'No'::text
|
||||
END AS "Is Projection",
|
||||
"strIncotermCode" AS "Incoterm Code"
|
||||
FROM vw_utility_dim_physical_sale_contract dpc;;
|
||||
13
Database Backups/SQL Views/vw_bi_dim_shipment.sql
Normal file
13
Database Backups/SQL Views/vw_bi_dim_shipment.sql
Normal file
@@ -0,0 +1,13 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_dim_shipment AS
|
||||
SELECT "intShipmentId",
|
||||
"strShipmentNb" AS "Shipment Nb",
|
||||
"strBillOfLading" AS "BL Number",
|
||||
"dtmBillOfLadingDate" AS "BL Date",
|
||||
"strState" AS "State",
|
||||
"strFromLocation" AS "From Location",
|
||||
"strToLocation" AS "To Location",
|
||||
"strVessel" AS "Vessel",
|
||||
"strCarrier" AS "Carrier",
|
||||
"strSupplier" AS "Supplier",
|
||||
"strCargoMode" AS "Cargo Mode"
|
||||
FROM vw_utility_shipment_in s;;
|
||||
24
Database Backups/SQL Views/vw_bi_dim_trade.sql
Normal file
24
Database Backups/SQL Views/vw_bi_dim_trade.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_dim_trade AS
|
||||
SELECT pc."intPurchaseLineId" AS "intTradeId",
|
||||
'Physical'::text AS "Trade Category",
|
||||
'Purchase'::text AS "Trade Type",
|
||||
pc."strReference" AS "Trade Ref",
|
||||
pc."dtmContractDate" AS "Trade Date",
|
||||
pc."strCounterparty" AS "Counterparty",
|
||||
pc."strRegion" AS "Bassin",
|
||||
pc."strBookName" AS "Book",
|
||||
pc."strStrategyName" AS "Strategy"
|
||||
FROM vw_utility_dim_physical_purchase_contract pc
|
||||
WHERE ((1 = 1) AND (pc."intPurchaseLineId" > 0))
|
||||
UNION ALL
|
||||
SELECT sc."intSaleLineId" AS "intTradeId",
|
||||
'Physical'::text AS "Trade Category",
|
||||
'Sale'::text AS "Trade Type",
|
||||
sc."strReference" AS "Trade Ref",
|
||||
sc."dtmContractDate" AS "Trade Date",
|
||||
sc."strCounterparty" AS "Counterparty",
|
||||
sc."strRegion" AS "Bassin",
|
||||
sc."strBookName" AS "Book",
|
||||
sc."strStrategyName" AS "Strategy"
|
||||
FROM vw_utility_dim_physical_sale_contract sc
|
||||
WHERE ((1 = 1) AND (sc."intSaleLineId" > 0));;
|
||||
79
Database Backups/SQL Views/vw_bi_fct_open_position.sql
Normal file
79
Database Backups/SQL Views/vw_bi_fct_open_position.sql
Normal file
@@ -0,0 +1,79 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_fct_open_position AS
|
||||
WITH purchase_position AS (
|
||||
SELECT contracts."intTradeId",
|
||||
contracts."Trade Category",
|
||||
contracts."Trade Type",
|
||||
contracts."Delivery Date",
|
||||
to_char((contracts."Delivery Date")::timestamp with time zone, 'YYYY-MM'::text) AS delivery_month,
|
||||
to_char((contracts."Delivery Date")::timestamp with time zone, 'Mon YYYY'::text) AS delivery_month_label,
|
||||
to_char((contracts."Delivery Date")::timestamp with time zone, 'YYYYMM'::text) AS delivery_month_code,
|
||||
contracts."Quantity",
|
||||
(contracts."Quantity" - COALESCE(delivery.delivered_quantity, (0)::double precision)) AS "Open Position Quantity",
|
||||
(((('Deal '::text || (dc."Contract Nb")::text) || ' ('::text) || (dc."Contract Ref")::text) || ')'::text) AS "Label"
|
||||
FROM ((vw_bi_fct_trade_line contracts
|
||||
JOIN vw_bi_dim_purchase_physical_contract dc ON ((contracts."intTradeId" = dc."intPurchaseLineId")))
|
||||
LEFT JOIN ( SELECT ffe."intTradeId",
|
||||
sum(ffe."Quantity") AS delivered_quantity
|
||||
FROM vw_bi_fct_trade_fulfillment_event ffe
|
||||
WHERE ((ffe."Trade Category" = 'Physical'::text) AND (ffe."Trade Type" = 'Purchase'::text))
|
||||
GROUP BY ffe."intTradeId") delivery ON ((contracts."intTradeId" = delivery."intTradeId")))
|
||||
WHERE ((1 = 1) AND (contracts."Trade Category" = 'Physical'::text) AND (contracts."Trade Type" = 'Purchase'::text))
|
||||
), sale_position AS (
|
||||
SELECT contracts."intTradeId",
|
||||
contracts."Trade Category",
|
||||
contracts."Trade Type",
|
||||
contracts."Delivery Date",
|
||||
to_char((contracts."Delivery Date")::timestamp with time zone, 'YYYY-MM'::text) AS delivery_month,
|
||||
to_char((contracts."Delivery Date")::timestamp with time zone, 'Mon YYYY'::text) AS delivery_month_label,
|
||||
to_char((contracts."Delivery Date")::timestamp with time zone, 'YYYYMM'::text) AS delivery_month_code,
|
||||
contracts."Quantity",
|
||||
((contracts."Quantity" - COALESCE(delivery.delivered_quantity, (0)::double precision)) * ('-1'::integer)::double precision) AS "Open Position Quantity",
|
||||
(((('Deal '::text || (dc."Contract Nb")::text) || ' ('::text) || (dc."Contract Ref")::text) || ')'::text) AS "Label"
|
||||
FROM ((vw_bi_fct_trade_line contracts
|
||||
JOIN vw_bi_dim_sale_physical_contract dc ON ((contracts."intTradeId" = dc."intSaleLineId")))
|
||||
LEFT JOIN ( SELECT ffe."intTradeId",
|
||||
sum(ffe."Quantity") AS delivered_quantity
|
||||
FROM vw_bi_fct_trade_fulfillment_event ffe
|
||||
WHERE ((ffe."Trade Category" = 'Physical'::text) AND (ffe."Trade Type" = 'Sale'::text))
|
||||
GROUP BY ffe."intTradeId") delivery ON ((contracts."intTradeId" = delivery."intTradeId")))
|
||||
WHERE ((1 = 1) AND (contracts."Trade Category" = 'Physical'::text) AND (contracts."Trade Type" = 'Sale'::text))
|
||||
)
|
||||
SELECT purchase_position."intTradeId",
|
||||
purchase_position."Trade Category",
|
||||
purchase_position."Trade Type",
|
||||
purchase_position."Delivery Date",
|
||||
purchase_position.delivery_month,
|
||||
purchase_position.delivery_month_label,
|
||||
purchase_position.delivery_month_code,
|
||||
purchase_position."Quantity",
|
||||
purchase_position."Open Position Quantity",
|
||||
purchase_position."Label"
|
||||
FROM purchase_position
|
||||
WHERE (purchase_position."Open Position Quantity" <> (0)::double precision)
|
||||
UNION ALL
|
||||
SELECT sale_position."intTradeId",
|
||||
sale_position."Trade Category",
|
||||
sale_position."Trade Type",
|
||||
sale_position."Delivery Date",
|
||||
sale_position.delivery_month,
|
||||
sale_position.delivery_month_label,
|
||||
sale_position.delivery_month_code,
|
||||
sale_position."Quantity",
|
||||
sale_position."Open Position Quantity",
|
||||
sale_position."Label"
|
||||
FROM sale_position
|
||||
WHERE (sale_position."Open Position Quantity" <> (0)::double precision)
|
||||
UNION ALL
|
||||
SELECT ffe."intTradeId",
|
||||
'Physical'::text AS "Trade Category",
|
||||
'Shipped'::text AS "Trade Type",
|
||||
sh."BL Date" AS "Delivery Date",
|
||||
to_char((sh."BL Date")::timestamp with time zone, 'YYYY-MM'::text) AS delivery_month,
|
||||
to_char((sh."BL Date")::timestamp with time zone, 'Mon YYYY'::text) AS delivery_month_label,
|
||||
to_char((sh."BL Date")::timestamp with time zone, 'YYYYMM'::text) AS delivery_month_code,
|
||||
ffe."Quantity",
|
||||
0 AS "Open Position Quantity",
|
||||
(((((('Shipment '::text || (sh."Shipment Nb")::text) || ' ('::text) || (dc."Contract Ref")::text) || ' - '::text) || (sh."Vessel")::text) || ')'::text) AS "Label"
|
||||
FROM ((vw_bi_fct_trade_fulfillment_event ffe
|
||||
JOIN vw_bi_dim_shipment sh ON ((ffe."intShipmentId" = sh."intShipmentId")))
|
||||
JOIN vw_bi_dim_purchase_physical_contract dc ON ((ffe."intTradeId" = dc."intPurchaseLineId")));;
|
||||
8
Database Backups/SQL Views/vw_bi_fct_prices.sql
Normal file
8
Database Backups/SQL Views/vw_bi_fct_prices.sql
Normal file
@@ -0,0 +1,8 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_fct_prices AS
|
||||
SELECT "intPriceCurveId",
|
||||
"dtmPriceDate" AS "Price Date",
|
||||
"dblHighPrice" AS "High",
|
||||
"dblLowPrice" AS "Low",
|
||||
"dblOpenPrice" AS "Open",
|
||||
"dblPriceValue" AS "Price Value"
|
||||
FROM vw_utility_price_curve_prices;;
|
||||
@@ -0,0 +1,16 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_fct_purchase_physical_contract AS
|
||||
SELECT "intPurchaseLineId" AS "PurchaseLineId",
|
||||
"dtmDeliveryDateFrom" AS "Delivery Date From",
|
||||
"dtmDeliveryDateTo" AS "Delivery DateTo",
|
||||
"dblQuantity" AS "Quantity",
|
||||
"dblInTransitQuantity" AS "In Transit Quantity",
|
||||
"dblDropshippedQuantity" AS "Dropship Quantity",
|
||||
"dblReceivedQuantity" AS "Received Quantity",
|
||||
"dblPrice" AS "Price",
|
||||
"dblUnitPrice" AS "Unit Price",
|
||||
"dblTheoriticalQuantity" AS "Theoretical Quantity",
|
||||
"dblLineAmount" AS "Line Amount",
|
||||
"dblPhysicalQty" AS "Physical Quantity",
|
||||
"dblOpenQuantity" AS "Open Quantity",
|
||||
"dblInInstructedQuantity" AS "Instructed Quantity"
|
||||
FROM vw_utility_purchase_physical_contract pc;;
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_fct_sale_physical_contract AS
|
||||
SELECT "intSaleLineId",
|
||||
"dtmDeliveryDateFrom" AS "Delivery Date From",
|
||||
"dtmDeliveryDateTo" AS "Delivery DateTo",
|
||||
"dblQuantity" AS "Quantity",
|
||||
"dblPrice" AS "Price",
|
||||
"dblUnitPrice" AS "Unit Price",
|
||||
"dblTheoreticalQuantity" AS "Theoretical Quantity",
|
||||
"dblLineAmount" AS "Line Amount",
|
||||
"dblTheoreticalWeightKg" AS "Theoretical Weight(Kg)",
|
||||
"dblPhysicalWeightKg" AS "Physical Weight(Kg)",
|
||||
"dblOpenWeightKg" AS "Open Weight(Kg)"
|
||||
FROM vw_utility_sale_physical_contract pc;;
|
||||
@@ -0,0 +1,48 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_fct_trade_fulfillment_event AS
|
||||
SELECT sm."intPurchaseLineId" AS "intTradeId",
|
||||
'Physical'::text AS "Trade Category",
|
||||
'Purchase'::text AS "Trade Type",
|
||||
'Shipped'::text AS "Event Type",
|
||||
sm."dtmBLDate" AS "Event Date",
|
||||
sm."dblQuantity" AS "Quantity",
|
||||
sm."intLotId",
|
||||
sm."strLotStatus" AS "Lot Status",
|
||||
sm."intShipmentId"
|
||||
FROM vw_utility_stock_movements sm
|
||||
WHERE (sm."strMovementType" = 'Inbound'::text)
|
||||
UNION ALL
|
||||
SELECT sm."intSaleLineId" AS "intTradeId",
|
||||
'Physical'::text AS "Trade Category",
|
||||
'Sale'::text AS "Trade Type",
|
||||
'Shipped'::text AS "Event Type",
|
||||
sm."dtmBLDate" AS "Event Date",
|
||||
sm."dblQuantity" AS "Quantity",
|
||||
sm."intLotId",
|
||||
sm."strLotStatus" AS "Lot Status",
|
||||
sm."intShipmentId"
|
||||
FROM vw_utility_stock_movements sm
|
||||
WHERE (sm."strMovementType" = 'Outbound'::text)
|
||||
UNION ALL
|
||||
SELECT sm."intPurchaseLineId" AS "intTradeId",
|
||||
'Physical'::text AS "Trade Category",
|
||||
'Purchase'::text AS "Trade Type",
|
||||
'Shipped'::text AS "Event Type",
|
||||
sm."dtmBLDate" AS "Event Date",
|
||||
sm."dblQuantity" AS "Quantity",
|
||||
sm."intLotId",
|
||||
sm."strLotStatus" AS "Lot Status",
|
||||
sm."intShipmentId"
|
||||
FROM vw_utility_stock_movements sm
|
||||
WHERE (sm."strMovementType" = 'Dropship'::text)
|
||||
UNION ALL
|
||||
SELECT sm."intSaleLineId" AS "intTradeId",
|
||||
'Physical'::text AS "Trade Category",
|
||||
'Sale'::text AS "Trade Type",
|
||||
'Shipped'::text AS "Event Type",
|
||||
sm."dtmBLDate" AS "Event Date",
|
||||
sm."dblQuantity" AS "Quantity",
|
||||
sm."intLotId",
|
||||
sm."strLotStatus" AS "Lot Status",
|
||||
sm."intShipmentId"
|
||||
FROM vw_utility_stock_movements sm
|
||||
WHERE (sm."strMovementType" = 'Dropship'::text);;
|
||||
24
Database Backups/SQL Views/vw_bi_fct_trade_line.sql
Normal file
24
Database Backups/SQL Views/vw_bi_fct_trade_line.sql
Normal file
@@ -0,0 +1,24 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_fct_trade_line AS
|
||||
SELECT pc."intPurchaseLineId" AS "intTradeId",
|
||||
'Physical'::text AS "Trade Category",
|
||||
'Purchase'::text AS "Trade Type",
|
||||
pc."dtmEstimatedBLDate" AS "Delivery Date",
|
||||
pc."dblTheoriticalQuantity" AS "Contracted Quantity",
|
||||
pc."dblQuantity" AS "Quantity",
|
||||
pc."dblPrice" AS "Price",
|
||||
pc."dblUnitPrice" AS "Unit Price",
|
||||
'USD'::text AS "Price Currency",
|
||||
pc."dblLineAmount" AS "Line Amount"
|
||||
FROM vw_utility_purchase_physical_contract pc
|
||||
UNION ALL
|
||||
SELECT pc."intSaleLineId" AS "intTradeId",
|
||||
'Physical'::text AS "Trade Category",
|
||||
'Sale'::text AS "Trade Type",
|
||||
pc."dtmEstimatedBLDate" AS "Delivery Date",
|
||||
pc."dblTheoreticalQuantity" AS "Contracted Quantity",
|
||||
pc."dblQuantity" AS "Quantity",
|
||||
pc."dblPrice" AS "Price",
|
||||
pc."dblUnitPrice" AS "Unit Price",
|
||||
'USD'::text AS "Price Currency",
|
||||
pc."dblLineAmount" AS "Line Amount"
|
||||
FROM vw_utility_sale_physical_contract pc;;
|
||||
30
Database Backups/SQL Views/vw_bi_itsa_fct_contract.sql
Normal file
30
Database Backups/SQL Views/vw_bi_itsa_fct_contract.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_contract AS
|
||||
SELECT 'Purchase'::text AS "TradeType",
|
||||
pc."intPurchaseLineId" AS "TradeLineId",
|
||||
pc."dblQuantity" AS "Quantity",
|
||||
pc."dblTheoriticalQuantity" AS "TheoriticalQuantity",
|
||||
pc."dblInInstructedQuantity" AS "InstructedQuantity",
|
||||
CASE
|
||||
WHEN (pc."ysnFinished" = true) THEN (0)::numeric(18,3)
|
||||
WHEN ((pc."dblTheoriticalQuantity")::double precision > pc."dblInInstructedQuantity") THEN (((pc."dblTheoriticalQuantity")::double precision - pc."dblInInstructedQuantity"))::numeric(18,3)
|
||||
ELSE (0)::numeric(18,3)
|
||||
END AS "OpenQuantity",
|
||||
pc."dblUnitPrice" AS "Price",
|
||||
COALESCE(pc."dtmEstimatedBLDate", pc."dtmDeliveryDateFrom") AS "DeliveryDate"
|
||||
FROM vw_utility_purchase_physical_contract pc
|
||||
WHERE (1 = 1)
|
||||
UNION ALL
|
||||
SELECT 'Sale'::text AS "TradeType",
|
||||
pc."intSaleLineId" AS "TradeLineId",
|
||||
pc."dblQuantity" AS "Quantity",
|
||||
pc."dblTheoreticalQuantity" AS "TheoriticalQuantity",
|
||||
pc."dblInstructedQuantity" AS "InstructedQuantity",
|
||||
CASE
|
||||
WHEN (pc."ysnFinished" = true) THEN (0)::numeric(18,3)
|
||||
WHEN ((pc."dblTheoreticalQuantity")::double precision > pc."dblInstructedQuantity") THEN (((pc."dblTheoreticalQuantity")::double precision - pc."dblInstructedQuantity"))::numeric(18,3)
|
||||
ELSE (0)::numeric(18,3)
|
||||
END AS "OpenQuantity",
|
||||
pc."dblUnitPrice" AS "Price",
|
||||
COALESCE(pc."dtmEstimatedBLDate", pc."dtmDeliveryDateFrom") AS "DeliveryDate"
|
||||
FROM vw_utility_sale_physical_contract pc
|
||||
WHERE (1 = 1);;
|
||||
22
Database Backups/SQL Views/vw_bi_itsa_fct_contract_fees.sql
Normal file
22
Database Backups/SQL Views/vw_bi_itsa_fct_contract_fees.sql
Normal file
@@ -0,0 +1,22 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_contract_fees AS
|
||||
SELECT "intFeeId",
|
||||
"strContractType" AS "Contract Type",
|
||||
"intContractLineId",
|
||||
"strPackaging" AS "Packaging",
|
||||
"strPayOrRec" AS "Pay or Rec",
|
||||
"strType" AS "Type",
|
||||
"strProduct" AS "Fee",
|
||||
"strSupplier" AS "Supplier",
|
||||
"strState" AS "State",
|
||||
"strWeightType" AS "Weighing Type",
|
||||
"dblQuantity" AS "Quantity",
|
||||
("dblPrice" * ("dblSignMultiplier")::numeric) AS "Price",
|
||||
"strCurrency" AS "Currency",
|
||||
"strUnit" AS "Unit",
|
||||
(("dblQuantity" * "dblPrice") * ("dblSignMultiplier")::numeric) AS "Amount",
|
||||
CASE
|
||||
WHEN (upper(("strProduct")::text) = 'MARITIME FREIGHT'::text) THEN "strProduct"
|
||||
WHEN (upper(("strProduct")::text) = 'PROFIT SHARING'::text) THEN "strProduct"
|
||||
ELSE 'Other Costs'::character varying
|
||||
END AS "Cost Group"
|
||||
FROM vw_utility_contract_fees;;
|
||||
29
Database Backups/SQL Views/vw_bi_itsa_fct_shipment_fees.sql
Normal file
29
Database Backups/SQL Views/vw_bi_itsa_fct_shipment_fees.sql
Normal file
@@ -0,0 +1,29 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_shipment_fees AS
|
||||
SELECT "intFeeId",
|
||||
"strShipmentType" AS "Shipment Type",
|
||||
"intShipmentId",
|
||||
"strPackaging" AS "Packaging",
|
||||
"strPayOrRec" AS "Pay or Rec",
|
||||
"strType" AS "Type",
|
||||
"strProduct" AS "Fee",
|
||||
"strSupplier" AS "Supplier",
|
||||
"strState" AS "State",
|
||||
"strWeightType" AS "Weighing Type",
|
||||
COALESCE("dblQuantity", (0)::numeric) AS "Quantity",
|
||||
CASE
|
||||
WHEN (upper(("strProduct")::text) = 'PROFIT SHARING'::text) THEN abs("dblPrice")
|
||||
ELSE ("dblPrice" * ("dblSignMultiplier")::numeric)
|
||||
END AS "Price",
|
||||
"strCurrency" AS "Currency",
|
||||
"strUnit" AS "Unit",
|
||||
(COALESCE("dblQuantity", (0)::numeric) *
|
||||
CASE
|
||||
WHEN (upper(("strProduct")::text) = 'PROFIT SHARING'::text) THEN abs("dblPrice")
|
||||
ELSE ("dblPrice" * ("dblSignMultiplier")::numeric)
|
||||
END) AS "Amount",
|
||||
CASE
|
||||
WHEN (upper(("strProduct")::text) = 'MARITIME FREIGHT'::text) THEN "strProduct"
|
||||
WHEN (upper(("strProduct")::text) = 'PROFIT SHARING'::text) THEN "strProduct"
|
||||
ELSE 'Other Costs'::character varying
|
||||
END AS "Cost Group"
|
||||
FROM vw_utility_shipment_fees;;
|
||||
16
Database Backups/SQL Views/vw_bi_itsa_fct_shipments.sql
Normal file
16
Database Backups/SQL Views/vw_bi_itsa_fct_shipments.sql
Normal file
@@ -0,0 +1,16 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_itsa_fct_shipments AS
|
||||
SELECT sm."intLotId",
|
||||
sm."intProductId",
|
||||
sm."intFromLocationId",
|
||||
sm."intToLocationId",
|
||||
sm."intShipmentId",
|
||||
sm."strMovementType" AS "Movement Type",
|
||||
sm."intPurchaseLineId",
|
||||
sm."intSaleLineId",
|
||||
sm."dblQuantity" AS "Shipped Quantity",
|
||||
sm."strUnit" AS "Quantity Unit",
|
||||
COALESCE(p."dblUnitPrice", (0)::numeric) AS "Purchase Price",
|
||||
COALESCE(s."dblUnitPrice", (0)::numeric) AS "Sale Price"
|
||||
FROM ((vw_utility_stock_movements sm
|
||||
LEFT JOIN vw_utility_purchase_physical_contract p ON ((sm."intPurchaseLineId" = p."intPurchaseLineId")))
|
||||
LEFT JOIN vw_utility_sale_physical_contract s ON ((sm."intSaleLineId" = s."intSaleLineId")));;
|
||||
@@ -0,0 +1,31 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_os_migration_instructed_shipments AS
|
||||
SELECT il."intLotId" AS "intPurchaseLotId",
|
||||
il."intLotId" AS "intSaleLotId",
|
||||
il."intShipmentId",
|
||||
il."intPurchaseLineId",
|
||||
il."intSaleLineId",
|
||||
il."dblQuantity",
|
||||
il."strUnit",
|
||||
pl.source_id AS purchase_source_id,
|
||||
sl.source_id AS sale_source_id,
|
||||
'Physical'::text AS "strLotType"
|
||||
FROM ((vw_utility_instructed_lots il
|
||||
LEFT JOIN vw_bi_os_migration_mapping pl ON (((il."intPurchaseLineId" = pl.tryton_id) AND (pl.tryton_model = '{purchase.line}'::character varying[]))))
|
||||
LEFT JOIN vw_bi_os_migration_mapping sl ON (((il."intSaleLineId" = sl.tryton_id) AND (sl.tryton_model = '{sale.line}'::character varying[]))))
|
||||
UNION ALL
|
||||
SELECT ml."intPurchaseLotId",
|
||||
ml."intSaleLotId",
|
||||
ml."intLotShipmentIn" AS "intShipmentId",
|
||||
pl."intPurchaseLineId",
|
||||
sl."intSaleLineId",
|
||||
ml."dblQuantity",
|
||||
ml."strUnit",
|
||||
ospl.source_id AS purchase_source_id,
|
||||
ossl.source_id AS sale_source_id,
|
||||
'Virtual'::text AS "strLotType"
|
||||
FROM ((((vw_utility_matched_lots ml
|
||||
JOIN vw_utility_lot pl ON ((ml."intPurchaseLotId" = pl."intLotId")))
|
||||
JOIN vw_utility_lot sl ON ((ml."intSaleLotId" = sl."intLotId")))
|
||||
LEFT JOIN vw_bi_os_migration_mapping ospl ON (((pl."intPurchaseLineId" = ospl.tryton_id) AND (ospl.tryton_model = '{purchase.line}'::character varying[]))))
|
||||
LEFT JOIN vw_bi_os_migration_mapping ossl ON (((sl."intSaleLineId" = ossl.tryton_id) AND (ossl.tryton_model = '{sale.line}'::character varying[]))))
|
||||
WHERE ((1 = 1) AND (ml."dblQuantity" > (0)::numeric) AND (ml."intLotShipmentIn" > 0));;
|
||||
@@ -0,0 +1,8 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_os_migration_mapping AS
|
||||
SELECT object_type AS source_object_type,
|
||||
source_id,
|
||||
tryton_model,
|
||||
tryton_id,
|
||||
recon_key AS reconciliation_key,
|
||||
write_date AS import_date
|
||||
FROM os_migration_mapping;;
|
||||
@@ -0,0 +1,28 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_os_migration_purchase_line AS
|
||||
SELECT mm.source_id,
|
||||
mm.object_type,
|
||||
mm.recon_key,
|
||||
mm.tryton_id,
|
||||
mm.write_date AS migration_date,
|
||||
mm.tryton_model,
|
||||
p.number AS tradon_number,
|
||||
p.reference AS tradon_reference,
|
||||
p.our_reference AS tradon_our_reference,
|
||||
p.purchase_date AS tradon_purchase_date,
|
||||
pa.name AS tradon_counterparty,
|
||||
c.name AS tradon_currency,
|
||||
pl.sequence AS tradon_line_number,
|
||||
pl.quantity AS tradon_line_quantity,
|
||||
pp.code AS tradon_product_code,
|
||||
pu.symbol AS tradon_unit_symbol,
|
||||
pl.from_del AS tradon_delivery_from_date,
|
||||
pl.to_del AS tradon_delivery_to_date
|
||||
FROM (((((((os_migration_mapping mm
|
||||
JOIN purchase_line pl ON ((pl.id = mm.tryton_id)))
|
||||
JOIN purchase_purchase p ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN party_party pa ON ((pa.id = p.party)))
|
||||
LEFT JOIN currency_currency c ON ((c.id = p.currency)))
|
||||
LEFT JOIN incoterm_incoterm i ON ((p.incoterm = i.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN product_uom pu ON ((pl.unit = pu.id)))
|
||||
WHERE (mm.tryton_model = '{purchase.line}'::character varying[]);;
|
||||
@@ -0,0 +1,75 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_os_migration_purchase_purchase AS
|
||||
SELECT (mm.source_id)::character varying AS source_id,
|
||||
(mm.object_type)::character varying AS object_type,
|
||||
(mm.recon_key)::character varying AS recon_key,
|
||||
(mm.tryton_id)::integer AS tryton_id,
|
||||
(mm.write_date)::timestamp without time zone AS migration_date,
|
||||
(mm.tryton_model)::character varying[] AS tryton_model,
|
||||
p.number AS tradon_number,
|
||||
p.reference AS tradon_reference,
|
||||
p.our_reference AS tradon_our_reference,
|
||||
p.purchase_date AS tradon_purchase_date,
|
||||
pa.name AS tradon_counterparty,
|
||||
c.name AS tradon_currency,
|
||||
p.state AS tradon_state,
|
||||
p.invoice_method AS tradon_invoice_method,
|
||||
i.code AS tradon_incoterm,
|
||||
i.version AS tradon_incoterm_version,
|
||||
fromloc.name AS tradon_from_location,
|
||||
toloc.name AS tradon_to_location,
|
||||
pwb.name AS tradon_weight_basis,
|
||||
p.tol_max AS tradon_tol_max_pct,
|
||||
p.tol_min AS tradon_tol_min_pct,
|
||||
p.tol_max_qt AS tradon_tol_max_qty,
|
||||
p.tol_min_qt AS tradon_tol_min_qty,
|
||||
op.name AS tradon_operator,
|
||||
tr.name AS tradon_trader
|
||||
FROM (((((((((os_migration_mapping mm
|
||||
JOIN purchase_purchase p ON ((p.id = mm.tryton_id)))
|
||||
LEFT JOIN party_party pa ON ((pa.id = p.party)))
|
||||
LEFT JOIN currency_currency c ON ((c.id = p.currency)))
|
||||
LEFT JOIN incoterm_incoterm i ON ((p.incoterm = i.id)))
|
||||
LEFT JOIN stock_location fromloc ON ((p.from_location = fromloc.id)))
|
||||
LEFT JOIN stock_location toloc ON ((p.to_location = toloc.id)))
|
||||
LEFT JOIN purchase_weight_basis pwb ON ((p.wb = pwb.id)))
|
||||
LEFT JOIN party_party op ON ((p.operator = op.id)))
|
||||
LEFT JOIN party_party tr ON ((p.trader = tr.id)))
|
||||
WHERE (mm.tryton_model = ARRAY['purchase.purchase'::character varying])
|
||||
UNION ALL
|
||||
SELECT ''::character varying AS source_id,
|
||||
''::character varying AS object_type,
|
||||
NULL::character varying AS recon_key,
|
||||
NULL::integer AS tryton_id,
|
||||
NULL::timestamp without time zone AS migration_date,
|
||||
NULL::character varying[] AS tryton_model,
|
||||
p.number AS tradon_number,
|
||||
p.reference AS tradon_reference,
|
||||
p.our_reference AS tradon_our_reference,
|
||||
p.purchase_date AS tradon_purchase_date,
|
||||
pa.name AS tradon_counterparty,
|
||||
c.name AS tradon_currency,
|
||||
p.state AS tradon_state,
|
||||
p.invoice_method AS tradon_invoice_method,
|
||||
i.code AS tradon_incoterm,
|
||||
i.version AS tradon_incoterm_version,
|
||||
fromloc.name AS tradon_from_location,
|
||||
toloc.name AS tradon_to_location,
|
||||
pwb.name AS tradon_weight_basis,
|
||||
p.tol_max AS tradon_tol_max_pct,
|
||||
p.tol_min AS tradon_tol_min_pct,
|
||||
p.tol_max_qt AS tradon_tol_max_qty,
|
||||
p.tol_min_qt AS tradon_tol_min_qty,
|
||||
op.name AS tradon_operator,
|
||||
tr.name AS tradon_trader
|
||||
FROM ((((((((purchase_purchase p
|
||||
LEFT JOIN party_party pa ON ((pa.id = p.party)))
|
||||
LEFT JOIN currency_currency c ON ((c.id = p.currency)))
|
||||
LEFT JOIN incoterm_incoterm i ON ((p.incoterm = i.id)))
|
||||
LEFT JOIN stock_location fromloc ON ((p.from_location = fromloc.id)))
|
||||
LEFT JOIN stock_location toloc ON ((p.to_location = toloc.id)))
|
||||
LEFT JOIN purchase_weight_basis pwb ON ((p.wb = pwb.id)))
|
||||
LEFT JOIN party_party op ON ((p.operator = op.id)))
|
||||
LEFT JOIN party_party tr ON ((p.trader = tr.id)))
|
||||
WHERE (NOT (EXISTS ( SELECT 1
|
||||
FROM os_migration_mapping mm
|
||||
WHERE ((mm.tryton_id = p.id) AND (mm.tryton_model = ARRAY['purchase.purchase'::character varying])))));;
|
||||
28
Database Backups/SQL Views/vw_bi_os_migration_sale_line.sql
Normal file
28
Database Backups/SQL Views/vw_bi_os_migration_sale_line.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_os_migration_sale_line AS
|
||||
SELECT mm.source_id,
|
||||
mm.object_type,
|
||||
mm.recon_key,
|
||||
mm.tryton_id,
|
||||
mm.write_date AS migration_date,
|
||||
mm.tryton_model,
|
||||
p.number AS tradon_number,
|
||||
p.reference AS tradon_reference,
|
||||
p.our_reference AS tradon_our_reference,
|
||||
p.sale_date AS tradon_sale_date,
|
||||
pa.name AS tradon_counterparty,
|
||||
c.name AS tradon_currency,
|
||||
pl.sequence AS tradon_line_number,
|
||||
pl.quantity AS tradon_line_quantity,
|
||||
pp.code AS tradon_product_code,
|
||||
pu.symbol AS tradon_unit_symbol,
|
||||
pl.from_del AS tradon_delivery_from_date,
|
||||
pl.to_del AS tradon_delivery_to_date
|
||||
FROM (((((((os_migration_mapping mm
|
||||
JOIN sale_line pl ON ((pl.id = mm.tryton_id)))
|
||||
JOIN sale_sale p ON ((pl.sale = p.id)))
|
||||
LEFT JOIN party_party pa ON ((pa.id = p.party)))
|
||||
LEFT JOIN currency_currency c ON ((c.id = p.currency)))
|
||||
LEFT JOIN incoterm_incoterm i ON ((p.incoterm = i.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN product_uom pu ON ((pl.unit = pu.id)))
|
||||
WHERE (mm.tryton_model = '{sale.line}'::character varying[]);;
|
||||
75
Database Backups/SQL Views/vw_bi_os_migration_sale_sale.sql
Normal file
75
Database Backups/SQL Views/vw_bi_os_migration_sale_sale.sql
Normal file
@@ -0,0 +1,75 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_os_migration_sale_sale AS
|
||||
SELECT (mm.source_id)::character varying AS source_id,
|
||||
(mm.object_type)::character varying AS object_type,
|
||||
(mm.recon_key)::character varying AS recon_key,
|
||||
(mm.tryton_id)::integer AS tryton_id,
|
||||
(mm.write_date)::timestamp without time zone AS migration_date,
|
||||
(mm.tryton_model)::character varying[] AS tryton_model,
|
||||
p.number AS tradon_number,
|
||||
p.reference AS tradon_reference,
|
||||
p.our_reference AS tradon_our_reference,
|
||||
p.sale_date AS tradon_sale_date,
|
||||
pa.name AS tradon_counterparty,
|
||||
c.name AS tradon_currency,
|
||||
p.state AS tradon_state,
|
||||
p.invoice_method AS tradon_invoice_method,
|
||||
i.code AS tradon_incoterm,
|
||||
i.version AS tradon_incoterm_version,
|
||||
fromloc.name AS tradon_from_location,
|
||||
toloc.name AS tradon_to_location,
|
||||
pwb.name AS tradon_weight_basis,
|
||||
p.tol_max AS tradon_tol_max_pct,
|
||||
p.tol_min AS tradon_tol_min_pct,
|
||||
p.tol_max_qt AS tradon_tol_max_qty,
|
||||
p.tol_min_qt AS tradon_tol_min_qty,
|
||||
op.name AS tradon_operator,
|
||||
tr.name AS tradon_trader
|
||||
FROM (((((((((os_migration_mapping mm
|
||||
JOIN sale_sale p ON ((p.id = mm.tryton_id)))
|
||||
LEFT JOIN party_party pa ON ((pa.id = p.party)))
|
||||
LEFT JOIN currency_currency c ON ((c.id = p.currency)))
|
||||
LEFT JOIN incoterm_incoterm i ON ((p.incoterm = i.id)))
|
||||
LEFT JOIN stock_location fromloc ON ((p.from_location = fromloc.id)))
|
||||
LEFT JOIN stock_location toloc ON ((p.to_location = toloc.id)))
|
||||
LEFT JOIN purchase_weight_basis pwb ON ((p.wb = pwb.id)))
|
||||
LEFT JOIN party_party op ON ((p.operator = op.id)))
|
||||
LEFT JOIN party_party tr ON ((p.trader = tr.id)))
|
||||
WHERE (mm.tryton_model = ARRAY['sale.sale'::character varying])
|
||||
UNION ALL
|
||||
SELECT ''::character varying AS source_id,
|
||||
''::character varying AS object_type,
|
||||
NULL::character varying AS recon_key,
|
||||
NULL::integer AS tryton_id,
|
||||
NULL::timestamp without time zone AS migration_date,
|
||||
NULL::character varying[] AS tryton_model,
|
||||
p.number AS tradon_number,
|
||||
p.reference AS tradon_reference,
|
||||
p.our_reference AS tradon_our_reference,
|
||||
p.sale_date AS tradon_sale_date,
|
||||
pa.name AS tradon_counterparty,
|
||||
c.name AS tradon_currency,
|
||||
p.state AS tradon_state,
|
||||
p.invoice_method AS tradon_invoice_method,
|
||||
i.code AS tradon_incoterm,
|
||||
i.version AS tradon_incoterm_version,
|
||||
fromloc.name AS tradon_from_location,
|
||||
toloc.name AS tradon_to_location,
|
||||
pwb.name AS tradon_weight_basis,
|
||||
p.tol_max AS tradon_tol_max_pct,
|
||||
p.tol_min AS tradon_tol_min_pct,
|
||||
p.tol_max_qt AS tradon_tol_max_qty,
|
||||
p.tol_min_qt AS tradon_tol_min_qty,
|
||||
op.name AS tradon_operator,
|
||||
tr.name AS tradon_trader
|
||||
FROM ((((((((sale_sale p
|
||||
LEFT JOIN party_party pa ON ((pa.id = p.party)))
|
||||
LEFT JOIN currency_currency c ON ((c.id = p.currency)))
|
||||
LEFT JOIN incoterm_incoterm i ON ((p.incoterm = i.id)))
|
||||
LEFT JOIN stock_location fromloc ON ((p.from_location = fromloc.id)))
|
||||
LEFT JOIN stock_location toloc ON ((p.to_location = toloc.id)))
|
||||
LEFT JOIN purchase_weight_basis pwb ON ((p.wb = pwb.id)))
|
||||
LEFT JOIN party_party op ON ((p.operator = op.id)))
|
||||
LEFT JOIN party_party tr ON ((p.trader = tr.id)))
|
||||
WHERE (NOT (EXISTS ( SELECT 1
|
||||
FROM os_migration_mapping mm
|
||||
WHERE ((mm.tryton_id = p.id) AND (mm.tryton_model = ARRAY['sale.sale'::character varying])))));;
|
||||
35
Database Backups/SQL Views/vw_bi_purchase_follow_up.sql
Normal file
35
Database Backups/SQL Views/vw_bi_purchase_follow_up.sql
Normal file
@@ -0,0 +1,35 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_purchase_follow_up AS
|
||||
SELECT dpc."Contract Nb",
|
||||
dpc."Supplier",
|
||||
dpc."Contract Ref",
|
||||
dpc."Contract Date",
|
||||
dpc."Contract Status",
|
||||
dpc."Payment Terms",
|
||||
dpc."Currency",
|
||||
dpc."Weight Basis",
|
||||
dpc."Broker",
|
||||
dpc."Certification",
|
||||
dpc."Association",
|
||||
dpc."Crop",
|
||||
dpc."Tolerance Min %",
|
||||
dpc."Tolerance Max %",
|
||||
dpc."Inco Terms",
|
||||
dpc."Loading Place",
|
||||
dpc."Destination Place",
|
||||
dpc."Product",
|
||||
dpc."Delivery Period",
|
||||
fpc."Delivery Date From",
|
||||
fpc."Delivery DateTo",
|
||||
fpc."Quantity",
|
||||
fpc."In Transit Quantity",
|
||||
fpc."Dropship Quantity",
|
||||
fpc."Received Quantity",
|
||||
fpc."Price",
|
||||
fpc."Unit Price",
|
||||
fpc."Theoretical Quantity",
|
||||
fpc."Line Amount",
|
||||
fpc."Physical Quantity",
|
||||
fpc."Open Quantity",
|
||||
fpc."Instructed Quantity"
|
||||
FROM (vw_bi_fct_purchase_physical_contract fpc
|
||||
JOIN vw_bi_dim_purchase_physical_contract dpc ON ((fpc."PurchaseLineId" = dpc."intPurchaseLineId")));;
|
||||
34
Database Backups/SQL Views/vw_bi_sale_follow_up.sql
Normal file
34
Database Backups/SQL Views/vw_bi_sale_follow_up.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
CREATE OR REPLACE VIEW public.vw_bi_sale_follow_up AS
|
||||
SELECT dsc."Contract Nb",
|
||||
dsc."Customer",
|
||||
dsc."Contract Ref",
|
||||
dsc."Contract Date",
|
||||
dsc."Contract Status",
|
||||
dsc."Payment Terms",
|
||||
dsc."Currency",
|
||||
dsc."Weight Basis",
|
||||
dsc."Broker",
|
||||
dsc."Certification",
|
||||
dsc."Association",
|
||||
dsc."Crop",
|
||||
dsc."Tolerance Min %",
|
||||
dsc."Tolerance Max %",
|
||||
dsc."Inco Terms",
|
||||
dsc."Loading Place",
|
||||
dsc."Destination Place",
|
||||
dsc."Product",
|
||||
dsc."Delivery Period",
|
||||
dsc."Delivery Date From",
|
||||
dsc."Delivery Date To",
|
||||
dsc."Delivery Status",
|
||||
fsc."Quantity",
|
||||
dsc."Quantity UOM",
|
||||
fsc."Price",
|
||||
fsc."Unit Price",
|
||||
fsc."Theoretical Quantity",
|
||||
fsc."Line Amount",
|
||||
fsc."Theoretical Weight(Kg)",
|
||||
fsc."Physical Weight(Kg)",
|
||||
fsc."Open Weight(Kg)"
|
||||
FROM (vw_bi_fct_sale_physical_contract fsc
|
||||
JOIN vw_bi_dim_sale_physical_contract dsc ON ((fsc."intSaleLineId" = dsc."intSaleLineId")));;
|
||||
157
Database Backups/SQL Views/vw_cash_forecast.sql
Normal file
157
Database Backups/SQL Views/vw_cash_forecast.sql
Normal file
@@ -0,0 +1,157 @@
|
||||
CREATE OR REPLACE VIEW public.vw_cash_forecast AS
|
||||
WITH contract_lines AS (
|
||||
SELECT forex.id AS forex_id,
|
||||
forex.number AS forex_number,
|
||||
fcpc.id AS fcpc_id,
|
||||
fcpc.amount AS forex_amount,
|
||||
fcpc.amount AS forex_amount_for_all,
|
||||
((fcpc.amount)::double precision * (((lh.quantity)::double precision * (unit.factor / unit_line.factor)) / pl.quantity)) AS line_amount,
|
||||
(COALESCE(((pl.unit_price)::double precision * ((lh.quantity)::double precision * (unit.factor / unit_line.factor))), ((0)::numeric)::double precision) * ('-1'::integer)::double precision) AS qt_amount,
|
||||
p.id AS contract_id,
|
||||
p.number AS contract_number,
|
||||
'purchase'::text AS contract_type,
|
||||
COALESCE((pe.estimated_date + ptld.days), p.purchase_date) AS maturity_date,
|
||||
pl.id AS contract_line_id,
|
||||
pl.quantity,
|
||||
pp.code AS product_code,
|
||||
cc.code AS currency,
|
||||
ll.lot_type,
|
||||
ll.invoice_line,
|
||||
ll.invoice_line_prov,
|
||||
aml.reconciliation
|
||||
FROM (((((((((((((((purchase_purchase p
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((p.id = fcpc.contract)))
|
||||
LEFT JOIN forex_forex forex ON ((fcpc.forex = forex.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((p.currency = cc.id)))
|
||||
LEFT JOIN account_invoice_payment_term pt ON ((pt.id = p.payment_term)))
|
||||
LEFT JOIN account_invoice_payment_term_line ptl ON ((ptl.payment = pt.id)))
|
||||
LEFT JOIN account_invoice_payment_term_line_delta ptld ON ((ptld.line = ptl.id)))
|
||||
LEFT JOIN pricing_estimated pe ON (((pe.purchase = p.id) AND ((pe.trigger)::text = (ptl.trigger_event)::text))))
|
||||
LEFT JOIN lot_lot ll ON ((pl.id = ll.line)))
|
||||
LEFT JOIN lot_qt_hist lh ON ((lh.lot = ll.id)))
|
||||
LEFT JOIN lot_qt_type lt ON (((lh.quantity_type = lt.id) AND (lt.sequence = 1))))
|
||||
LEFT JOIN product_uom unit ON ((unit.id = pl.unit)))
|
||||
LEFT JOIN product_uom unit_line ON ((unit_line.id = ll.lot_unit_line)))
|
||||
LEFT JOIN account_move_line aml ON (((split_part((aml.origin)::text, ','::text, 1) = 'invoice.line'::text) AND ((ll.invoice_line_prov = (split_part((aml.origin)::text, ','::text, 2))::integer) OR (ll.invoice_line = (split_part((aml.origin)::text, ','::text, 2))::integer)))))
|
||||
WHERE (p.currency = 2)
|
||||
UNION ALL
|
||||
SELECT forex.id AS forex_id,
|
||||
forex.number AS forex_number,
|
||||
fcpc.id AS fcpc_id,
|
||||
fcpc.amount AS forex_amount,
|
||||
fcpc.amount AS forex_amount_for_all,
|
||||
((fcpc.amount)::double precision * (((lh.quantity)::double precision * (unit.factor / unit_line.factor)) / sl.quantity)) AS line_amount,
|
||||
((sl.unit_price)::double precision * ((lh.quantity)::double precision * (unit.factor / unit_line.factor))) AS qt_amount,
|
||||
s.id AS contract_id,
|
||||
s.number AS contract_number,
|
||||
'sale'::text AS contract_type,
|
||||
s.sale_date AS maturity_date,
|
||||
sl.id AS contract_line_id,
|
||||
sl.quantity,
|
||||
pp.code AS product_code,
|
||||
cc.code AS currency,
|
||||
ll.lot_type,
|
||||
ll.sale_invoice_line AS invoice_line,
|
||||
ll.sale_invoice_line_prov AS invoice_line_prov,
|
||||
aml.reconciliation
|
||||
FROM (((((((((((sale_sale s
|
||||
LEFT JOIN forex_cover_physical_sale fcpc ON ((s.id = fcpc.contract)))
|
||||
LEFT JOIN forex_forex forex ON ((fcpc.forex = s.id)))
|
||||
LEFT JOIN sale_line sl ON ((sl.sale = s.id)))
|
||||
LEFT JOIN product_product pp ON ((sl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((s.currency = cc.id)))
|
||||
LEFT JOIN lot_lot ll ON ((sl.id = ll.sale_line)))
|
||||
LEFT JOIN lot_qt_hist lh ON ((lh.lot = ll.id)))
|
||||
LEFT JOIN lot_qt_type lt ON (((lh.quantity_type = lt.id) AND (lt.sequence = 1))))
|
||||
LEFT JOIN product_uom unit ON ((unit.id = sl.unit)))
|
||||
LEFT JOIN product_uom unit_line ON ((unit_line.id = ll.lot_unit_line)))
|
||||
LEFT JOIN account_move_line aml ON (((split_part((aml.origin)::text, ','::text, 1) = 'invoice.line'::text) AND ((ll.sale_invoice_line_prov = (split_part((aml.origin)::text, ','::text, 2))::integer) OR (ll.sale_invoice_line = (split_part((aml.origin)::text, ','::text, 2))::integer)))))
|
||||
WHERE (s.currency = 2)
|
||||
), contracts_by_status AS (
|
||||
SELECT contract_lines.forex_id,
|
||||
contract_lines.forex_number,
|
||||
contract_lines.fcpc_id,
|
||||
contract_lines.line_amount,
|
||||
contract_lines.forex_amount,
|
||||
contract_lines.forex_amount_for_all,
|
||||
contract_lines.qt_amount,
|
||||
contract_lines.contract_id,
|
||||
contract_lines.contract_number,
|
||||
contract_lines.contract_type,
|
||||
contract_lines.maturity_date,
|
||||
contract_lines.contract_line_id,
|
||||
contract_lines.quantity,
|
||||
contract_lines.product_code,
|
||||
contract_lines.currency,
|
||||
contract_lines.lot_type,
|
||||
contract_lines.invoice_line,
|
||||
contract_lines.invoice_line_prov,
|
||||
contract_lines.reconciliation,
|
||||
CASE
|
||||
WHEN ((contract_lines.lot_type)::text = 'virtual'::text) THEN 'open'::text
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND (contract_lines.invoice_line IS NULL) AND (contract_lines.invoice_line_prov IS NULL)) THEN 'shipped'::text
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND ((contract_lines.invoice_line IS NOT NULL) OR (contract_lines.invoice_line_prov IS NOT NULL)) AND ((contract_lines.reconciliation IS NULL) OR (contract_lines.reconciliation = 0))) THEN 'invoiced'::text
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND ((contract_lines.invoice_line IS NOT NULL) OR (contract_lines.invoice_line_prov IS NOT NULL)) AND (contract_lines.reconciliation > 0)) THEN 'paid'::text
|
||||
ELSE 'total'::text
|
||||
END AS qt_type,
|
||||
CASE
|
||||
WHEN ((contract_lines.lot_type)::text = 'virtual'::text) THEN 1
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND (contract_lines.invoice_line IS NULL) AND (contract_lines.invoice_line_prov IS NULL)) THEN 2
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND ((contract_lines.invoice_line IS NOT NULL) OR (contract_lines.invoice_line_prov IS NOT NULL)) AND ((contract_lines.reconciliation IS NULL) OR (contract_lines.reconciliation = 0))) THEN 3
|
||||
WHEN (((contract_lines.lot_type)::text = 'physic'::text) AND ((contract_lines.invoice_line IS NOT NULL) OR (contract_lines.invoice_line_prov IS NOT NULL)) AND (contract_lines.reconciliation > 0)) THEN 4
|
||||
ELSE 0
|
||||
END AS qt_order
|
||||
FROM contract_lines
|
||||
), forex_summary AS (
|
||||
SELECT forex.number AS forex_number,
|
||||
'forex'::text AS line_type,
|
||||
NULL::text AS contract_number,
|
||||
NULL::text AS contract_type,
|
||||
NULL::text AS contract_line,
|
||||
NULL::text AS qt_type,
|
||||
0 AS qt_order,
|
||||
max(forex.rate) AS rate,
|
||||
NULL::numeric AS amount_covered,
|
||||
NULL::numeric AS forex_amount,
|
||||
forex.buy_amount AS qt_amount,
|
||||
forex.buy_amount AS total_amount_forex,
|
||||
(forex.buy_amount - COALESCE(sum(fcpc.amount), (0)::numeric)) AS amount_remaining,
|
||||
max((cc.code)::text) AS currency,
|
||||
forex.value_date AS maturity_date
|
||||
FROM ((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN currency_currency cc ON ((forex.buy_currency = cc.id)))
|
||||
GROUP BY forex.id, forex.number, forex.buy_amount
|
||||
)
|
||||
SELECT forex_summary.line_type,
|
||||
forex_summary.forex_number AS contract_ref,
|
||||
forex_summary.contract_line,
|
||||
forex_summary.qt_type,
|
||||
forex_summary.qt_order,
|
||||
forex_summary.rate,
|
||||
forex_summary.forex_amount,
|
||||
forex_summary.qt_amount,
|
||||
forex_summary.total_amount_forex,
|
||||
forex_summary.amount_remaining,
|
||||
forex_summary.currency,
|
||||
forex_summary.maturity_date,
|
||||
to_char((forex_summary.maturity_date)::timestamp with time zone, 'MONYY'::text) AS maturity_month
|
||||
FROM forex_summary
|
||||
UNION ALL
|
||||
SELECT cl.contract_type AS line_type,
|
||||
cl.contract_number AS contract_ref,
|
||||
((cl.product_code)::text || COALESCE(((' ('::text || cl.contract_line_id) || ')'::text), ''::text)) AS contract_line,
|
||||
cl.qt_type,
|
||||
cl.qt_order,
|
||||
NULL::numeric AS rate,
|
||||
cl.forex_amount,
|
||||
cl.qt_amount,
|
||||
NULL::numeric AS total_amount_forex,
|
||||
NULL::numeric AS amount_remaining,
|
||||
cl.currency,
|
||||
cl.maturity_date,
|
||||
to_char((cl.maturity_date)::timestamp with time zone, 'MONYY'::text) AS maturity_month
|
||||
FROM contracts_by_status cl
|
||||
ORDER BY 1, 2 DESC, 3, 6 DESC;;
|
||||
17
Database Backups/SQL Views/vw_forex.sql
Normal file
17
Database Backups/SQL Views/vw_forex.sql
Normal file
@@ -0,0 +1,17 @@
|
||||
CREATE OR REPLACE VIEW public.vw_forex AS
|
||||
SELECT forex.number AS forex_number,
|
||||
p.number AS purchase_number,
|
||||
((((pp.code)::text || ' ('::text) || pl.quantity) || ')'::text) AS purchase_line,
|
||||
ai.number AS invoice_number,
|
||||
forex.for_amount AS forex_amount,
|
||||
fcpc.amount AS amount_covered,
|
||||
sum(fcpc.amount) OVER (PARTITION BY forex.id ORDER BY fcpc.id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) AS cumulative_covered,
|
||||
(forex.for_amount - sum(fcpc.amount) OVER (PARTITION BY forex.id ORDER BY fcpc.id ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW)) AS balance
|
||||
FROM ((((((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN account_invoice_line ail ON (((split_part((ail.origin)::text, ','::text, 1) = 'purchase.line'::text) AND (pl.id = (split_part((ail.origin)::text, ','::text, 2))::integer))))
|
||||
LEFT JOIN account_invoice ai ON ((ail.invoice = ai.id)))
|
||||
ORDER BY forex.number, fcpc.id;;
|
||||
61
Database Backups/SQL Views/vw_fx_by_maturity_by_contract.sql
Normal file
61
Database Backups/SQL Views/vw_fx_by_maturity_by_contract.sql
Normal file
@@ -0,0 +1,61 @@
|
||||
CREATE OR REPLACE VIEW public.vw_fx_by_maturity_by_contract AS
|
||||
WITH combined AS (
|
||||
SELECT p.number AS purchase_number,
|
||||
'contract'::text AS line_type,
|
||||
NULL::character varying AS forex_number,
|
||||
NULL::numeric AS amount_covered,
|
||||
string_agg(DISTINCT (pp.code)::text, ', '::text) AS products,
|
||||
max((pl.quantity * (pl.unit_price)::double precision)) AS total_contract_value,
|
||||
(max((pl.quantity * (pl.unit_price)::double precision)) - COALESCE((sum(fcpc.amount))::double precision, (0)::double precision)) AS amount_remaining,
|
||||
max((cc.code)::text) AS currency,
|
||||
NULL::numeric AS rate,
|
||||
COALESCE(max((pe.estimated_date + ptld.days)), max(p.purchase_date)) AS maturity_date,
|
||||
NULL::text AS status
|
||||
FROM ((((((((purchase_purchase p
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((p.currency = cc.id)))
|
||||
LEFT JOIN account_invoice_payment_term pt ON ((pt.id = p.payment_term)))
|
||||
LEFT JOIN account_invoice_payment_term_line ptl ON ((ptl.payment = pt.id)))
|
||||
LEFT JOIN account_invoice_payment_term_line_delta ptld ON ((ptld.line = ptl.id)))
|
||||
LEFT JOIN pricing_estimated pe ON (((pe.purchase = p.id) AND ((pe.trigger)::text = (ptl.trigger_event)::text))))
|
||||
WHERE (p.currency = 2)
|
||||
GROUP BY p.number
|
||||
UNION ALL
|
||||
SELECT p.number AS purchase_number,
|
||||
'forex'::text AS line_type,
|
||||
forex.number AS forex_number,
|
||||
fcpc.amount AS amount_covered,
|
||||
NULL::text AS products,
|
||||
NULL::numeric AS total_contract_value,
|
||||
NULL::numeric AS amount_remaining,
|
||||
cc.code AS currency,
|
||||
forex.rate,
|
||||
forex.value_date AS maturity_date,
|
||||
CASE
|
||||
WHEN (forex.move > 0) THEN 'executed'::text
|
||||
ELSE 'not executed'::text
|
||||
END AS status
|
||||
FROM (((purchase_purchase p
|
||||
JOIN forex_cover_physical_contract fcpc ON ((fcpc.contract = p.id)))
|
||||
JOIN forex_forex forex ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN currency_currency cc ON ((forex.buy_currency = cc.id)))
|
||||
WHERE (forex.buy_currency = 2)
|
||||
)
|
||||
SELECT to_char((max(maturity_date))::timestamp with time zone, 'MONYY'::text) AS maturity_month,
|
||||
max(maturity_date) AS maturity_date,
|
||||
line_type,
|
||||
purchase_number,
|
||||
forex_number,
|
||||
max(status) AS status,
|
||||
max(products) AS products,
|
||||
COALESCE(sum(amount_covered), (0)::numeric) AS amount_covered,
|
||||
COALESCE(sum(total_contract_value), (0)::double precision) AS total_contract_value,
|
||||
COALESCE(sum(amount_remaining), (0)::double precision) AS amount_remaining,
|
||||
((COALESCE(sum(amount_covered), (0)::numeric))::double precision / COALESCE(sum(total_contract_value), (1)::double precision)) AS percent_covered,
|
||||
max(currency) AS currency,
|
||||
max(rate) AS rate
|
||||
FROM combined
|
||||
GROUP BY line_type, purchase_number, forex_number
|
||||
ORDER BY (max(maturity_date)), purchase_number, line_type, forex_number;;
|
||||
68
Database Backups/SQL Views/vw_fx_by_maturity_by_forex.sql
Normal file
68
Database Backups/SQL Views/vw_fx_by_maturity_by_forex.sql
Normal file
@@ -0,0 +1,68 @@
|
||||
CREATE OR REPLACE VIEW public.vw_fx_by_maturity_by_forex AS
|
||||
WITH combined AS (
|
||||
SELECT p.number AS purchase_number,
|
||||
'contract'::text AS line_type,
|
||||
forex.number AS forex_number,
|
||||
COALESCE(sum(fcpc.amount), (0)::numeric) AS amount_covered,
|
||||
string_agg(DISTINCT (pp.code)::text, ', '::text) AS products,
|
||||
COALESCE(max((pl.quantity * (pl.unit_price)::double precision)), (0)::double precision) AS total_contract_value,
|
||||
max((cc.code)::text) AS currency,
|
||||
forex.rate,
|
||||
forex.value_date AS maturity_date,
|
||||
CASE
|
||||
WHEN (max(forex.move) > 0) THEN 'executed'::text
|
||||
ELSE 'not executed'::text
|
||||
END AS status
|
||||
FROM (((((purchase_purchase p
|
||||
JOIN forex_cover_physical_contract fcpc ON ((fcpc.contract = p.id)))
|
||||
JOIN forex_forex forex ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN product_product pp ON ((pl.product = pp.id)))
|
||||
LEFT JOIN currency_currency cc ON ((forex.buy_currency = cc.id)))
|
||||
WHERE (p.currency = 2)
|
||||
GROUP BY p.number, forex.number, forex.rate, forex.value_date
|
||||
UNION ALL
|
||||
SELECT NULL::text AS purchase_number,
|
||||
'forex'::text AS line_type,
|
||||
forex.number AS forex_number,
|
||||
COALESCE(NULL::numeric, (0)::numeric) AS amount_covered,
|
||||
NULL::text AS products,
|
||||
COALESCE(NULL::numeric, (0)::numeric) AS total_contract_value,
|
||||
cc.code AS currency,
|
||||
forex.rate,
|
||||
forex.value_date AS maturity_date,
|
||||
CASE
|
||||
WHEN (forex.move > 0) THEN 'executed'::text
|
||||
ELSE 'not executed'::text
|
||||
END AS status
|
||||
FROM (forex_forex forex
|
||||
LEFT JOIN currency_currency cc ON ((forex.buy_currency = cc.id)))
|
||||
WHERE (forex.buy_currency = 2)
|
||||
)
|
||||
SELECT to_char(date_trunc('month'::text, (c.maturity_date)::timestamp with time zone), 'MONYY'::text) AS maturity_period,
|
||||
max(c.maturity_date) AS maturity_date,
|
||||
c.line_type,
|
||||
c.forex_number,
|
||||
c.purchase_number,
|
||||
max(c.status) AS status,
|
||||
max(c.products) AS products,
|
||||
max(c.currency) AS currency,
|
||||
max(c.rate) AS rate,
|
||||
CASE
|
||||
WHEN (c.line_type = 'forex'::text) THEN fx.buy_amount
|
||||
ELSE NULL::numeric
|
||||
END AS forex_total_amount,
|
||||
sum(COALESCE(c.amount_covered, (0)::numeric)) AS amount_covered,
|
||||
CASE
|
||||
WHEN (c.line_type = 'forex'::text) THEN (fx.buy_amount - COALESCE(sum(fc.amount_covered), (0)::numeric))
|
||||
ELSE NULL::numeric
|
||||
END AS amount_remaining
|
||||
FROM ((combined c
|
||||
LEFT JOIN forex_forex fx ON (((fx.number)::text = (c.forex_number)::text)))
|
||||
LEFT JOIN ( SELECT forex.number AS forex_number,
|
||||
sum(fcpc.amount) AS amount_covered
|
||||
FROM (forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
GROUP BY forex.number) fc ON (((fc.forex_number)::text = (c.forex_number)::text)))
|
||||
GROUP BY (date_trunc('month'::text, (c.maturity_date)::timestamp with time zone)), c.line_type, c.forex_number, c.purchase_number, fx.buy_amount
|
||||
ORDER BY (date_trunc('month'::text, (c.maturity_date)::timestamp with time zone)), c.forex_number, c.line_type, c.purchase_number;;
|
||||
20
Database Backups/SQL Views/vw_fx_by_maturity_sum.sql
Normal file
20
Database Backups/SQL Views/vw_fx_by_maturity_sum.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
CREATE OR REPLACE VIEW public.vw_fx_by_maturity_sum AS
|
||||
SELECT period,
|
||||
max(maturity_date) AS max,
|
||||
max(amount_remaining_contract) AS rem_ct,
|
||||
COALESCE(max(amount_remaining_forex), (0)::numeric) AS rem_fx,
|
||||
(COALESCE(max(amount_remaining_contract), (0)::double precision) - COALESCE((max(amount_remaining_forex))::double precision, (0)::double precision)) AS req_fx
|
||||
FROM ( SELECT vw_fx_by_maturity_by_contract.maturity_month AS period,
|
||||
max(vw_fx_by_maturity_by_contract.maturity_date) AS maturity_date,
|
||||
sum(vw_fx_by_maturity_by_contract.amount_remaining) AS amount_remaining_contract,
|
||||
NULL::numeric AS amount_remaining_forex
|
||||
FROM vw_fx_by_maturity_by_contract
|
||||
GROUP BY vw_fx_by_maturity_by_contract.maturity_month
|
||||
UNION ALL
|
||||
SELECT vw_fx_by_maturity_by_forex.maturity_period AS period,
|
||||
max(vw_fx_by_maturity_by_forex.maturity_date) AS maturity_date,
|
||||
NULL::double precision AS amount_remaining_contract,
|
||||
sum(vw_fx_by_maturity_by_forex.amount_remaining) AS amount_remaining_forex
|
||||
FROM vw_fx_by_maturity_by_forex
|
||||
GROUP BY vw_fx_by_maturity_by_forex.maturity_period) m
|
||||
GROUP BY period;;
|
||||
48
Database Backups/SQL Views/vw_fx_running.sql
Normal file
48
Database Backups/SQL Views/vw_fx_running.sql
Normal file
@@ -0,0 +1,48 @@
|
||||
CREATE OR REPLACE VIEW public.vw_fx_running AS
|
||||
WITH forex_event AS (
|
||||
SELECT max(forex.value_date) AS event_date,
|
||||
'Execution FX'::text AS type,
|
||||
max(forex.buy_amount) AS amount,
|
||||
forex.number AS event_ref,
|
||||
string_agg((p.number)::text, ', '::text) AS linked_purchase
|
||||
FROM ((forex_forex forex
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((fcpc.forex = forex.id)))
|
||||
LEFT JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
WHERE (forex.move IS NOT NULL)
|
||||
GROUP BY forex.number
|
||||
), all_events AS (
|
||||
SELECT forex_event.event_date,
|
||||
forex_event.type,
|
||||
forex_event.amount,
|
||||
forex_event.event_ref,
|
||||
forex_event.linked_purchase
|
||||
FROM forex_event
|
||||
UNION ALL
|
||||
SELECT max(am.post_date) AS event_date,
|
||||
'Payment P'::text AS type,
|
||||
(- max(aml.amount_second_currency)) AS amount,
|
||||
max((p.number)::text) AS event_ref,
|
||||
max(fe.linked_purchase) AS linked_purchase
|
||||
FROM (((((((((((forex_forex forex
|
||||
LEFT JOIN forex_event fe ON (((fe.event_ref)::text = (forex.number)::text)))
|
||||
LEFT JOIN forex_cover_physical_contract fcpc ON ((forex.id = fcpc.forex)))
|
||||
LEFT JOIN purchase_purchase p ON ((fcpc.contract = p.id)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.purchase = p.id)))
|
||||
LEFT JOIN lot_lot ll ON ((pl.id = ll.line)))
|
||||
LEFT JOIN account_invoice_line ail ON ((ll.invoice_line_prov = ail.id)))
|
||||
LEFT JOIN account_invoice_line ail2 ON ((ll.invoice_line = ail2.id)))
|
||||
LEFT JOIN account_invoice ai ON ((ail.invoice = ai.id)))
|
||||
LEFT JOIN account_invoice ai2 ON ((ail2.invoice = ai2.id)))
|
||||
LEFT JOIN account_move am ON (((split_part((am.origin)::text, ','::text, 1) = 'account.invoice'::text) AND ((ai.id = (split_part((am.origin)::text, ','::text, 2))::integer) OR (ai2.id = (split_part((am.origin)::text, ','::text, 2))::integer)))))
|
||||
LEFT JOIN account_move_line aml ON ((am.id = aml.move)))
|
||||
WHERE ((forex.move IS NOT NULL) AND (aml.reconciliation > 0))
|
||||
GROUP BY forex.number
|
||||
)
|
||||
SELECT event_date,
|
||||
type,
|
||||
amount,
|
||||
event_ref,
|
||||
linked_purchase,
|
||||
sum(amount) OVER (ORDER BY event_date) AS running_amount
|
||||
FROM all_events
|
||||
ORDER BY event_date;;
|
||||
19
Database Backups/SQL Views/vw_pnl.sql
Normal file
19
Database Backups/SQL Views/vw_pnl.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
CREATE OR REPLACE VIEW public.vw_pnl AS
|
||||
SELECT pp.name AS "Supplier",
|
||||
sp.name AS "Client",
|
||||
CASE
|
||||
WHEN (pt.name IS NOT NULL) THEN pt.name
|
||||
ELSE pt2.name
|
||||
END AS "Product",
|
||||
v.amount AS "Amount"
|
||||
FROM ((((((((((valuation_valuation v
|
||||
LEFT JOIN product_product pr ON ((pr.id = v.product)))
|
||||
LEFT JOIN product_template pt ON ((pt.id = v.product)))
|
||||
LEFT JOIN product_template pt2 ON ((pt2.id = pr.template)))
|
||||
LEFT JOIN product_product pr2 ON ((pr2.template = pt2.id)))
|
||||
LEFT JOIN purchase_purchase p ON ((p.id = v.purchase)))
|
||||
LEFT JOIN purchase_line pl ON ((pl.id = v.line)))
|
||||
LEFT JOIN sale_sale s ON ((s.id = v.sale)))
|
||||
LEFT JOIN sale_line sl ON ((sl.id = v.sale_line)))
|
||||
LEFT JOIN party_party pp ON ((pp.id = p.party)))
|
||||
LEFT JOIN party_party sp ON ((sp.id = s.party)));;
|
||||
30
Database Backups/SQL Views/vw_utility_account_move.sql
Normal file
30
Database Backups/SQL Views/vw_utility_account_move.sql
Normal file
@@ -0,0 +1,30 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_account_move AS
|
||||
SELECT am.id AS "intAccountMoveId",
|
||||
am.date AS "dtmDate",
|
||||
am.post_date AS "dtmPostDate",
|
||||
COALESCE(am.post_number, ''::character varying) AS "strPostNumber",
|
||||
COALESCE(am.description, ''::character varying) AS "strDescription",
|
||||
am.journal AS "intJournalId",
|
||||
am.number AS "strJournalNb",
|
||||
am.state AS "strState",
|
||||
COALESCE(split_part((am.origin)::text, ','::text, 1), ''::text) AS "strOrigin",
|
||||
COALESCE((split_part((am.origin)::text, ','::text, 2))::integer, 0) AS "intOriginId",
|
||||
aml.lot AS "intLotId",
|
||||
COALESCE(aml.reconciliation, 0) AS "intReconciliation",
|
||||
aml.debit AS "dblDebit",
|
||||
aml.credit AS "dblCredit",
|
||||
aml.maturity_date AS "dtmMaturityDate",
|
||||
COALESCE(split_part((aml.origin)::text, ','::text, 1), ''::text) AS "strLineOrigin",
|
||||
COALESCE((split_part((aml.origin)::text, ','::text, 2))::integer, 0) AS "intLineOriginId",
|
||||
acc.name AS "strAccount",
|
||||
aj.code AS "strAccountJournalCode",
|
||||
aj.name AS "strAccountJournal",
|
||||
aj.type AS "strAccountJournalType",
|
||||
COALESCE(cc.name, ''::character varying) AS "strSecondCurrency",
|
||||
COALESCE(aml.amount_second_currency, (0)::numeric) AS "dblAmountSecondCurrency",
|
||||
(aml.debit - aml.credit) AS "dblAmount"
|
||||
FROM ((((account_move am
|
||||
JOIN account_move_line aml ON ((am.id = aml.move)))
|
||||
JOIN account_account acc ON ((aml.account = acc.id)))
|
||||
JOIN account_journal aj ON ((am.journal = aj.id)))
|
||||
LEFT JOIN currency_currency cc ON ((aml.second_currency = cc.id)));;
|
||||
32
Database Backups/SQL Views/vw_utility_book_dimension.sql
Normal file
32
Database Backups/SQL Views/vw_utility_book_dimension.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_book_dimension AS
|
||||
WITH bookvalue AS (
|
||||
SELECT ad.id AS "dimensionId",
|
||||
adv.id AS "valueId",
|
||||
ad.code AS "dimensionCode",
|
||||
adv.code AS "valueCode",
|
||||
adv.name AS "valueName"
|
||||
FROM (analytic_dimension ad
|
||||
JOIN analytic_dimension_value adv ON ((ad.id = adv.dimension)))
|
||||
WHERE ((1 = 1) AND ((ad.code)::text = 'book'::text))
|
||||
)
|
||||
SELECT DISTINCT aa.purchase AS "intTradeId",
|
||||
pl.id AS "intTradeLineId",
|
||||
'Physical'::text AS "strTradeCategory",
|
||||
'Purchase'::text AS "strTradeType",
|
||||
bv."valueCode" AS "strValueCode",
|
||||
bv."valueName" AS "strValueName"
|
||||
FROM ((analytic_dimension_assignment aa
|
||||
JOIN bookvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
|
||||
JOIN purchase_line pl ON ((aa.purchase = pl.purchase)))
|
||||
WHERE (COALESCE(aa.purchase, 0) > 0)
|
||||
UNION ALL
|
||||
SELECT DISTINCT aa.sale AS "intTradeId",
|
||||
sl.id AS "intTradeLineId",
|
||||
'Physical'::text AS "strTradeCategory",
|
||||
'Sale'::text AS "strTradeType",
|
||||
bv."valueCode" AS "strValueCode",
|
||||
bv."valueName" AS "strValueName"
|
||||
FROM ((analytic_dimension_assignment aa
|
||||
JOIN bookvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
|
||||
JOIN sale_line sl ON ((sl.sale = aa.sale)))
|
||||
WHERE (COALESCE(aa.sale, 0) > 0);;
|
||||
56
Database Backups/SQL Views/vw_utility_contract_fees.sql
Normal file
56
Database Backups/SQL Views/vw_utility_contract_fees.sql
Normal file
@@ -0,0 +1,56 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_contract_fees AS
|
||||
SELECT f.id AS "intFeeId",
|
||||
'Purchase'::text AS "strContractType",
|
||||
f.line AS "intContractLineId",
|
||||
f.mode AS "strPackaging",
|
||||
f.p_r AS "strPayOrRec",
|
||||
f.type AS "strType",
|
||||
p.code AS "strProduct",
|
||||
sup.name AS "strSupplier",
|
||||
f.state AS "strState",
|
||||
CASE
|
||||
WHEN (upper((f.weight_type)::text) = 'BRUT'::text) THEN 'Gross'::text
|
||||
ELSE 'Net'::text
|
||||
END AS "strWeightType",
|
||||
f.quantity AS "dblQuantity",
|
||||
f.price AS "dblPrice",
|
||||
c.name AS "strCurrency",
|
||||
uom.name AS "strUnit",
|
||||
CASE
|
||||
WHEN (upper((f.p_r)::text) = 'REC'::text) THEN '-1'::integer
|
||||
ELSE 1
|
||||
END AS "dblSignMultiplier"
|
||||
FROM ((((fee_fee f
|
||||
JOIN currency_currency c ON ((f.currency = c.id)))
|
||||
JOIN product_product p ON ((f.product = p.id)))
|
||||
JOIN product_uom uom ON ((f.unit = uom.id)))
|
||||
JOIN party_party sup ON ((f.supplier = sup.id)))
|
||||
WHERE (COALESCE(f.line, 0) > 0)
|
||||
UNION ALL
|
||||
SELECT f.id AS "intFeeId",
|
||||
'Sale'::text AS "strContractType",
|
||||
f.sale_line AS "intContractLineId",
|
||||
f.mode AS "strPackaging",
|
||||
f.p_r AS "strPayOrRec",
|
||||
f.type AS "strType",
|
||||
p.code AS "strProduct",
|
||||
sup.name AS "strSupplier",
|
||||
f.state AS "strState",
|
||||
CASE
|
||||
WHEN (upper((f.weight_type)::text) = 'BRUT'::text) THEN 'Gross'::text
|
||||
ELSE 'Net'::text
|
||||
END AS "strWeightType",
|
||||
f.quantity AS "dblQuantity",
|
||||
f.price AS "dblPrice",
|
||||
c.name AS "strCurrency",
|
||||
uom.name AS "strUnit",
|
||||
CASE
|
||||
WHEN (upper((f.p_r)::text) = 'REC'::text) THEN 1
|
||||
ELSE '-1'::integer
|
||||
END AS "dblSignMultiplier"
|
||||
FROM ((((fee_fee f
|
||||
JOIN currency_currency c ON ((f.currency = c.id)))
|
||||
JOIN product_product p ON ((f.product = p.id)))
|
||||
JOIN product_uom uom ON ((f.unit = uom.id)))
|
||||
JOIN party_party sup ON ((f.supplier = sup.id)))
|
||||
WHERE (COALESCE(f.sale_line, 0) > 0);;
|
||||
@@ -0,0 +1,83 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_dim_physical_purchase_contract AS
|
||||
SELECT 0 AS "intPurchaseLineId",
|
||||
''::character varying AS "strContractNb",
|
||||
''::character varying AS "strCounterparty",
|
||||
''::character varying AS "strReference",
|
||||
NULL::date AS "dtmContractDate",
|
||||
''::character varying AS "strContractStatus",
|
||||
''::character varying AS "strPaymentTerm",
|
||||
''::character varying AS "strCurrency",
|
||||
''::character varying AS "strCertification",
|
||||
''::character varying AS "strWeightBasis",
|
||||
''::character varying AS "strBroker",
|
||||
''::character varying AS "strCertif",
|
||||
''::character varying AS "strAssociation",
|
||||
''::character varying AS "strCrop",
|
||||
0 AS "dblTolMinPct",
|
||||
0 AS "dblTolMaxPct",
|
||||
''::character varying AS "strIncoterm",
|
||||
''::character varying AS "strLoadingPlace",
|
||||
''::character varying AS "strDestinationPlace",
|
||||
''::text AS "strProduct",
|
||||
''::character varying AS "strDeliveryPeriod",
|
||||
NULL::date AS "dtmDeliveryDateFrom",
|
||||
NULL::date AS "dtmDeliveryDateTo",
|
||||
''::character varying AS "strRegion",
|
||||
''::character varying AS "strStrategyName",
|
||||
''::character varying AS "strBookName",
|
||||
''::character varying AS "strQuantityUom",
|
||||
''::character varying AS "strIncotermCode"
|
||||
UNION ALL
|
||||
SELECT pl.id AS "intPurchaseLineId",
|
||||
pc.number AS "strContractNb",
|
||||
pty.name AS "strCounterparty",
|
||||
pc.reference AS "strReference",
|
||||
pc.purchase_date AS "dtmContractDate",
|
||||
CASE
|
||||
WHEN ((pc.state)::text = 'draft'::text) THEN 'Draft'::text
|
||||
WHEN ((pc.state)::text = 'confirmed'::text) THEN 'Confirmed'::text
|
||||
WHEN ((pc.state)::text = 'processing'::text) THEN 'Processing'::text
|
||||
ELSE 'Validated'::text
|
||||
END AS "strContractStatus",
|
||||
COALESCE(pt.name, ''::character varying) AS "strPaymentTerm",
|
||||
cur.name AS "strCurrency",
|
||||
COALESCE(pc.certification, ''::character varying) AS "strCertification",
|
||||
COALESCE(wbs.name, ''::character varying) AS "strWeightBasis",
|
||||
COALESCE(brk.name, ''::character varying) AS "strBroker",
|
||||
COALESCE(cer.name, ''::character varying) AS "strCertif",
|
||||
COALESCE(ass.name, ''::character varying) AS "strAssociation",
|
||||
COALESCE(crp.name, ''::character varying) AS "strCrop",
|
||||
pc.tol_min AS "dblTolMinPct",
|
||||
pc.tol_max AS "dblTolMaxPct",
|
||||
COALESCE(inc.name, ''::character varying) AS "strIncoterm",
|
||||
COALESCE(src.name, ''::character varying) AS "strLoadingPlace",
|
||||
COALESCE(dst.name, ''::character varying) AS "strDestinationPlace",
|
||||
concat('[', pr."strProductCode", '] ', pr."strTemplate") AS "strProduct",
|
||||
COALESCE(pm.month_name) AS "strDeliveryPeriod",
|
||||
pl.from_del AS "dtmDeliveryDateFrom",
|
||||
pl.to_del AS "dtmDeliveryDateTo",
|
||||
ad."strRegion",
|
||||
strategy."strValueName" AS "strStrategyName",
|
||||
book."strValueName" AS "strBookName",
|
||||
pu1.name AS "strQuantityUom",
|
||||
COALESCE(inc.code, ''::character varying) AS "strIncotermCode"
|
||||
FROM ((((((((((((((((((purchase_line pl
|
||||
JOIN purchase_purchase pc ON ((pl.purchase = pc.id)))
|
||||
JOIN party_party pty ON ((pc.party = pty.id)))
|
||||
JOIN currency_currency cur ON ((pc.currency = cur.id)))
|
||||
JOIN product_uom pu1 ON ((pl.unit = pu1.id)))
|
||||
LEFT JOIN party_party brk ON ((pc.broker = brk.id)))
|
||||
LEFT JOIN account_invoice_payment_term pt ON ((pc.payment_term = pt.id)))
|
||||
LEFT JOIN purchase_crop crp ON ((pc.crop = crp.id)))
|
||||
LEFT JOIN purchase_certification cer ON ((pc.certif = cer.id)))
|
||||
LEFT JOIN purchase_association ass ON ((pc.association = ass.id)))
|
||||
LEFT JOIN purchase_weight_basis wbs ON ((pc.wb = wbs.id)))
|
||||
LEFT JOIN stock_location src ON ((pc.from_location = src.id)))
|
||||
LEFT JOIN stock_location dst ON ((pc.to_location = dst.id)))
|
||||
LEFT JOIN incoterm_incoterm inc ON ((pc.incoterm = inc.id)))
|
||||
JOIN vw_utility_product pr ON ((pl.product = pr."intProductId")))
|
||||
LEFT JOIN product_month pm ON ((pl.del_period = pm.id)))
|
||||
LEFT JOIN vw_utility_last_counterparty_address ad ON ((pty.id = ad."intPartyId")))
|
||||
LEFT JOIN vw_utility_strategy_dimension strategy ON (((pl.id = strategy."intTradeLineId") AND (strategy."strTradeCategory" = 'Physical'::text) AND (strategy."strTradeType" = 'Purchase'::text))))
|
||||
LEFT JOIN vw_utility_book_dimension book ON (((pl.id = book."intTradeLineId") AND (book."strTradeCategory" = 'Physical'::text) AND (book."strTradeType" = 'Purchase'::text))))
|
||||
WHERE ((1 = 1) AND ((pl.type)::text = 'line'::text) AND ((pc.line_type)::text = 'goods'::text));;
|
||||
@@ -0,0 +1,78 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_dim_physical_sale_contract AS
|
||||
SELECT 0 AS "intSaleLineId",
|
||||
''::character varying AS "strContractNb",
|
||||
''::character varying AS "strCounterparty",
|
||||
''::character varying AS "strReference",
|
||||
NULL::date AS "dtmContractDate",
|
||||
''::character varying AS "strContractStatus",
|
||||
''::character varying AS "strPaymentTerm",
|
||||
''::character varying AS "strCurrency",
|
||||
''::character varying AS "strCertification",
|
||||
''::character varying AS "strWeightBasis",
|
||||
''::character varying AS "strBroker",
|
||||
''::character varying AS "strCertif",
|
||||
''::character varying AS "strAssociation",
|
||||
''::character varying AS "strCrop",
|
||||
0 AS "dblTolMinPct",
|
||||
0 AS "dblTolMaxPct",
|
||||
''::character varying AS "strIncoterm",
|
||||
''::character varying AS "strLoadingPlace",
|
||||
''::character varying AS "strDestinationPlace",
|
||||
''::text AS "strProduct",
|
||||
''::character varying AS "strDeliveryPeriod",
|
||||
NULL::date AS "dtmDeliveryDateFrom",
|
||||
NULL::date AS "dtmDeliveryDateTo",
|
||||
''::character varying AS "strQuantityUom",
|
||||
''::character varying AS "strRegion",
|
||||
''::character varying AS "strStrategyName",
|
||||
''::character varying AS "strBookName",
|
||||
''::character varying AS "strIncotermCode"
|
||||
UNION ALL
|
||||
SELECT sl.id AS "intSaleLineId",
|
||||
sc.number AS "strContractNb",
|
||||
pty.name AS "strCounterparty",
|
||||
sc.reference AS "strReference",
|
||||
sc.sale_date AS "dtmContractDate",
|
||||
sc.state AS "strContractStatus",
|
||||
COALESCE(pt.name, ''::character varying) AS "strPaymentTerm",
|
||||
cur.name AS "strCurrency",
|
||||
COALESCE(sc.certification, ''::character varying) AS "strCertification",
|
||||
COALESCE(wbs.name, ''::character varying) AS "strWeightBasis",
|
||||
COALESCE(brk.name, ''::character varying) AS "strBroker",
|
||||
COALESCE(cer.name, ''::character varying) AS "strCertif",
|
||||
COALESCE(ass.name, ''::character varying) AS "strAssociation",
|
||||
COALESCE(crp.name, ''::character varying) AS "strCrop",
|
||||
sc.tol_min AS "dblTolMinPct",
|
||||
sc.tol_max AS "dblTolMaxPct",
|
||||
COALESCE(inc.name, ''::character varying) AS "strIncoterm",
|
||||
COALESCE(src.name, ''::character varying) AS "strLoadingPlace",
|
||||
COALESCE(dst.name, ''::character varying) AS "strDestinationPlace",
|
||||
concat('[', pr."strProductCode", '] ', pr."strTemplate") AS "strProduct",
|
||||
COALESCE(pm.month_name) AS "strDeliveryPeriod",
|
||||
sl.from_del AS "dtmDeliveryDateFrom",
|
||||
sl.to_del AS "dtmDeliveryDateTo",
|
||||
pu1.name AS "strQuantityUom",
|
||||
ad."strRegion",
|
||||
strategy."strValueName" AS "strStrategyName",
|
||||
book."strValueName" AS "strBookName",
|
||||
COALESCE(inc.code, ''::character varying) AS "strIncotermCode"
|
||||
FROM ((((((((((((((((((sale_line sl
|
||||
JOIN sale_sale sc ON ((sl.sale = sc.id)))
|
||||
JOIN party_party pty ON ((sc.party = pty.id)))
|
||||
JOIN currency_currency cur ON ((sc.currency = cur.id)))
|
||||
JOIN product_uom pu1 ON ((sl.unit = pu1.id)))
|
||||
LEFT JOIN party_party brk ON ((sc.broker = brk.id)))
|
||||
LEFT JOIN account_invoice_payment_term pt ON ((sc.payment_term = pt.id)))
|
||||
LEFT JOIN purchase_crop crp ON ((sc.crop = crp.id)))
|
||||
LEFT JOIN purchase_certification cer ON ((sc.certif = cer.id)))
|
||||
LEFT JOIN purchase_association ass ON ((sc.association = ass.id)))
|
||||
LEFT JOIN purchase_weight_basis wbs ON ((sc.wb = wbs.id)))
|
||||
LEFT JOIN stock_location src ON ((sc.from_location = src.id)))
|
||||
LEFT JOIN stock_location dst ON ((sc.to_location = dst.id)))
|
||||
LEFT JOIN incoterm_incoterm inc ON ((sc.incoterm = inc.id)))
|
||||
JOIN vw_utility_product pr ON ((sl.product = pr."intProductId")))
|
||||
LEFT JOIN product_month pm ON ((sl.del_period = pm.id)))
|
||||
LEFT JOIN vw_utility_last_counterparty_address ad ON ((pty.id = ad."intPartyId")))
|
||||
LEFT JOIN vw_utility_strategy_dimension strategy ON (((sl.id = strategy."intTradeLineId") AND (strategy."strTradeCategory" = 'Physical'::text) AND (strategy."strTradeType" = 'Sale'::text))))
|
||||
LEFT JOIN vw_utility_book_dimension book ON (((sl.id = book."intTradeLineId") AND (book."strTradeCategory" = 'Physical'::text) AND (book."strTradeType" = 'Sale'::text))))
|
||||
WHERE ((1 = 1) AND ((sl.type)::text = 'line'::text));;
|
||||
12
Database Backups/SQL Views/vw_utility_dropshipped_lots.sql
Normal file
12
Database Backups/SQL Views/vw_utility_dropshipped_lots.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_dropshipped_lots AS
|
||||
SELECT fm."intCompanyId",
|
||||
fm."intPurchaseLineId",
|
||||
fm."intShipmentId",
|
||||
fm."intLotId",
|
||||
fm."dblQuantity",
|
||||
fm."strUnit",
|
||||
fm."dblQuantityKg"
|
||||
FROM ((vw_utility_stock_movements fm
|
||||
JOIN vw_utility_shipment_in ds ON ((fm."intShipmentId" = ds."intShipmentId")))
|
||||
JOIN vw_utility_location dl ON ((fm."intToLocationId" = dl."intLocationId")))
|
||||
WHERE ((1 = 1) AND (fm."intLotId" > 0) AND ((ds."strToLocationType")::text <> 'storage'::text) AND ((dl."strLocationType")::text <> 'storage'::text) AND ((fm."strState")::text = 'done'::text));;
|
||||
21
Database Backups/SQL Views/vw_utility_instructed_lots.sql
Normal file
21
Database Backups/SQL Views/vw_utility_instructed_lots.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_instructed_lots AS
|
||||
WITH stock_move AS (
|
||||
SELECT DISTINCT mvt_1."intLotId",
|
||||
mvt_1."intShipmentId",
|
||||
mvt_1."dblQuantity",
|
||||
mvt_1."strUnit",
|
||||
mvt_1."dblQuantityKg"
|
||||
FROM vw_utility_stock_movements mvt_1
|
||||
WHERE ((1 = 1) AND (mvt_1."strMovementType" = ANY (ARRAY['Inbound'::text, 'Dropship'::text])))
|
||||
)
|
||||
SELECT mvt."intLotId",
|
||||
mvt."intShipmentId",
|
||||
lot."intPurchaseLineId",
|
||||
mvt."dblQuantity",
|
||||
mvt."strUnit",
|
||||
mvt."dblQuantityKg",
|
||||
lot."intSaleLineId"
|
||||
FROM ((stock_move mvt
|
||||
JOIN vw_utility_shipment_in spt ON ((mvt."intShipmentId" = spt."intShipmentId")))
|
||||
JOIN vw_utility_lot lot ON ((mvt."intLotId" = lot."intLotId")))
|
||||
WHERE ((1 = 1) AND ((spt."strState")::text = 'draft'::text));;
|
||||
19
Database Backups/SQL Views/vw_utility_intransit_lots.sql
Normal file
19
Database Backups/SQL Views/vw_utility_intransit_lots.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_intransit_lots AS
|
||||
SELECT fm."intCompanyId",
|
||||
fm."intPurchaseLineId",
|
||||
fm."intShipmentId",
|
||||
fm."intLotId",
|
||||
fm."dblQuantity",
|
||||
fm."strUnit",
|
||||
fm."dblQuantityKg"
|
||||
FROM ((vw_utility_stock_movements fm
|
||||
JOIN vw_utility_shipment_in ds ON ((fm."intShipmentId" = ds."intShipmentId")))
|
||||
JOIN vw_utility_location dl ON ((fm."intToLocationId" = dl."intLocationId")))
|
||||
WHERE ((1 = 1) AND (fm."intLotId" > 0) AND ((ds."strToLocationType")::text = 'storage'::text) AND ((dl."strLocationType")::text = 'storage'::text) AND ((dl."strLocationName")::text = 'Transit'::text) AND ((fm."strState")::text = 'done'::text) AND (NOT (EXISTS ( SELECT fm2."intPurchaseLineId",
|
||||
fm2."intShipmentId",
|
||||
fm2."intLotId",
|
||||
fm2."dblQuantity"
|
||||
FROM ((vw_utility_stock_movements fm2
|
||||
JOIN vw_utility_shipment_in ds2 ON ((fm2."intShipmentId" = ds2."intShipmentId")))
|
||||
JOIN vw_utility_location dl2 ON ((fm2."intFromLocationId" = dl2."intLocationId")))
|
||||
WHERE ((1 = 1) AND (fm2."intLotId" > 0) AND ((ds2."strToLocationType")::text = 'storage'::text) AND ((dl2."strLocationType")::text = 'storage'::text) AND ((dl2."strLocationName")::text = 'Transit'::text) AND ((fm2."strState")::text = 'done'::text) AND (fm2."intLotId" = fm."intLotId") AND (fm2."intPurchaseLineId" = fm."intPurchaseLineId") AND (fm2."intShipmentId" = fm."intShipmentId"))))));;
|
||||
20
Database Backups/SQL Views/vw_utility_invoice_lines.sql
Normal file
20
Database Backups/SQL Views/vw_utility_invoice_lines.sql
Normal file
@@ -0,0 +1,20 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_invoice_lines AS
|
||||
SELECT ail.invoice AS "intInvoiceId",
|
||||
ail.id AS "intInvoiceLineId",
|
||||
ail.lot AS "intLotId",
|
||||
CASE
|
||||
WHEN (COALESCE(split_part((ail.origin)::text, ','::text, 1), ''::text) = 'purchase.line'::text) THEN 'Purchase'::text
|
||||
WHEN (COALESCE(split_part((ail.origin)::text, ','::text, 1), ''::text) = 'sale.line'::text) THEN 'Sale'::text
|
||||
ELSE ''::text
|
||||
END AS "strContractType",
|
||||
COALESCE((split_part((ail.origin)::text, ','::text, 2))::integer, 0) AS "intContractLineId",
|
||||
ail.quantity AS "dblQuantity",
|
||||
pu.name AS "strQuantityUom",
|
||||
cc.name AS "strCurrencyCode",
|
||||
ail.unit_price AS "dblUnitPrice",
|
||||
round(((ail.quantity * (ail.unit_price)::double precision))::numeric, get_rounding_position(cc.rounding)) AS "dblLineTotal"
|
||||
FROM (((account_invoice_line ail
|
||||
JOIN account_invoice ai ON ((ail.invoice = ai.id)))
|
||||
JOIN currency_currency cc ON ((ai.currency = cc.id)))
|
||||
JOIN product_uom pu ON ((ail.unit = pu.id)))
|
||||
WHERE (1 = 1);;
|
||||
57
Database Backups/SQL Views/vw_utility_invoices.sql
Normal file
57
Database Backups/SQL Views/vw_utility_invoices.sql
Normal file
@@ -0,0 +1,57 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_invoices AS
|
||||
WITH invoice_lines_agg AS (
|
||||
SELECT vil."intInvoiceId",
|
||||
sum(vil."dblQuantity") AS "dblTotalQuantity",
|
||||
sum(vil."dblLineTotal") AS "dblTotalLineAmount",
|
||||
max(vil."intContractLineId") AS "intContractLineId"
|
||||
FROM vw_utility_invoice_lines vil
|
||||
GROUP BY vil."intInvoiceId"
|
||||
), payments_agg AS (
|
||||
SELECT am."intOriginId" AS "intInvoiceId",
|
||||
sum(am."dblAmount") AS "dblPaidAmountInBaseCurrency",
|
||||
sum(am."dblAmountSecondCurrency") AS "dblPaidAmountInSecondCurrency",
|
||||
count(*) AS "intCountPayments"
|
||||
FROM vw_utility_account_move am
|
||||
WHERE ((1 = 1) AND (am."intReconciliation" > 0) AND ((am."strAccountJournalCode")::text = 'CASH'::text) AND (am."strOrigin" = 'account.invoice'::text))
|
||||
GROUP BY am."intOriginId"
|
||||
)
|
||||
SELECT ai.id AS "intInvoiceId",
|
||||
ai.company AS "intCompanyId",
|
||||
company_party.name AS "strCompanyName",
|
||||
cur.name AS "strCompanyCurrency",
|
||||
COALESCE(ai.number, ''::character varying) AS "strInvoiceNumber",
|
||||
ai.invoice_date AS "dtmInvoiceDate",
|
||||
invoice_party.name AS "strPartyName",
|
||||
ai.type AS "strInvoiceType",
|
||||
aipt.name AS "strPaymentTerm",
|
||||
ai.accounting_date AS "dtmAccountingDate",
|
||||
ai.currency AS "intCurrencyId",
|
||||
cc.name AS "strCurrencyCode",
|
||||
ai.state AS "strInvoiceState",
|
||||
COALESCE(ai.move, 0) AS "intMoveId",
|
||||
ai.account AS "intAccountId",
|
||||
aa.name AS "strAccountName",
|
||||
ila."dblTotalQuantity" AS "dblInvoiceQuantity",
|
||||
ila."dblTotalLineAmount" AS "dblInvoiceAmount",
|
||||
ila."intContractLineId",
|
||||
pa."dblPaidAmountInBaseCurrency",
|
||||
pa."dblPaidAmountInSecondCurrency",
|
||||
CASE
|
||||
WHEN ((cur.name)::text = (cc.name)::text) THEN COALESCE(pa."dblPaidAmountInBaseCurrency", (0)::numeric)
|
||||
ELSE COALESCE(pa."dblPaidAmountInSecondCurrency", (0)::numeric)
|
||||
END AS "dblPaidAmount",
|
||||
(ila."dblTotalLineAmount" -
|
||||
CASE
|
||||
WHEN ((cur.name)::text = (cc.name)::text) THEN COALESCE(pa."dblPaidAmountInBaseCurrency", (0)::numeric)
|
||||
ELSE COALESCE(pa."dblPaidAmountInSecondCurrency", (0)::numeric)
|
||||
END) AS "dblOpenedAmount"
|
||||
FROM (((((((((account_invoice ai
|
||||
JOIN invoice_lines_agg ila ON ((ila."intInvoiceId" = ai.id)))
|
||||
JOIN currency_currency cc ON ((cc.id = ai.currency)))
|
||||
JOIN party_party invoice_party ON ((invoice_party.id = ai.party)))
|
||||
JOIN company_company comp ON ((comp.id = ai.company)))
|
||||
JOIN currency_currency cur ON ((comp.currency = cur.id)))
|
||||
JOIN party_party company_party ON ((company_party.id = comp.party)))
|
||||
JOIN account_invoice_payment_term aipt ON ((aipt.id = ai.payment_term)))
|
||||
LEFT JOIN account_account aa ON ((aa.id = ai.account)))
|
||||
LEFT JOIN payments_agg pa ON ((pa."intInvoiceId" = ai.id)));;
|
||||
@@ -0,0 +1,19 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_last_counterparty_address AS
|
||||
WITH lastaddresses AS (
|
||||
SELECT pa_1.id,
|
||||
row_number() OVER (PARTITION BY pa_1.party ORDER BY pa_1.create_date DESC) AS rn
|
||||
FROM party_address pa_1
|
||||
WHERE (pa_1.active = true)
|
||||
)
|
||||
SELECT pa.id AS "intPartyAddressId",
|
||||
pa.party AS "intPartyId",
|
||||
COALESCE(TRIM(BOTH FROM pa.street), ''::text) AS "strStreet",
|
||||
COALESCE(pa.postal_code, ''::character varying) AS "strPostalCode",
|
||||
pa.city AS "strCity",
|
||||
c.name AS "strCountry",
|
||||
COALESCE(cr.name, 'Undefined'::character varying) AS "strRegion"
|
||||
FROM (((party_address pa
|
||||
JOIN lastaddresses la ON ((pa.id = la.id)))
|
||||
JOIN country_country c ON ((pa.country = c.id)))
|
||||
LEFT JOIN country_region cr ON ((c.region = cr.id)))
|
||||
WHERE (pa.active = true);;
|
||||
11
Database Backups/SQL Views/vw_utility_location.sql
Normal file
11
Database Backups/SQL Views/vw_utility_location.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_location AS
|
||||
SELECT 0 AS "intLocationId",
|
||||
''::character varying AS "strLocationName",
|
||||
''::character varying AS "strLocationType",
|
||||
true AS "ysnIsActive"
|
||||
UNION ALL
|
||||
SELECT sl.id AS "intLocationId",
|
||||
sl.name AS "strLocationName",
|
||||
sl.type AS "strLocationType",
|
||||
sl.active AS "ysnIsActive"
|
||||
FROM stock_location sl;;
|
||||
34
Database Backups/SQL Views/vw_utility_lot.sql
Normal file
34
Database Backups/SQL Views/vw_utility_lot.sql
Normal file
@@ -0,0 +1,34 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_lot AS
|
||||
SELECT lot.id AS "intLotId",
|
||||
COALESCE(lot.lot_container, ''::character varying) AS "strContainer",
|
||||
COALESCE(lot.lot_name, ''::character varying) AS "strLotName",
|
||||
COALESCE(lot.lot_status, ''::character varying) AS "strStatus",
|
||||
COALESCE(lot.lot_type, ''::character varying) AS "strType",
|
||||
COALESCE(lot.lot_av, ''::character varying) AS "strAvailability",
|
||||
lot.line AS "intPurchaseLineId",
|
||||
lot.sale_line AS "intSaleLineId",
|
||||
lot.lot_product AS "intProductId",
|
||||
lot.lot_state AS "intLotStateId",
|
||||
lot.lot_unit AS "intUnitId",
|
||||
lot.lot_unit_line AS "intUnitLineId",
|
||||
lot.lot_qt AS "dblQuantity",
|
||||
lot.invoice_line AS "intInvoiceLineId",
|
||||
lot.invoice_line_prov AS "intInvoiceLineProvId",
|
||||
COALESCE(lot.lot_pur_inv_state, ''::character varying) AS "strPurchaseInvoiceState",
|
||||
COALESCE(lot.lot_sale_inv_state, ''::character varying) AS "strSaleInvoiceState",
|
||||
lot.lot_shipment_in AS "intShipmentInId",
|
||||
lot.lot_shipment_internal AS "intShipmentInternalId",
|
||||
lot.lot_shipment_out AS "intShipmentOutId",
|
||||
lot.sale_invoice_line AS "intSaleInvoiceLineId",
|
||||
lot.sale_invoice_line_prov AS "intSaleInvoiceLineProvId",
|
||||
qth.quantity AS "dblNetWeight",
|
||||
qth.gross_quantity AS "dblGrossWeight",
|
||||
pu.name AS "strUnitName",
|
||||
pu_line.name AS "strUnitLineName",
|
||||
convert_weight(qth.quantity, (pu_line.name)::text, 'Kilogram'::text) AS "dblNetWeightKg",
|
||||
convert_weight(qth.gross_quantity, (pu_line.name)::text, 'Kilogram'::text) AS "dblGrossWeightKg"
|
||||
FROM (((lot_lot lot
|
||||
LEFT JOIN lot_qt_hist qth ON (((lot.id = qth.lot) AND (lot.lot_state = qth.quantity_type))))
|
||||
LEFT JOIN product_uom pu ON ((lot.lot_unit = pu.id)))
|
||||
LEFT JOIN product_uom pu_line ON ((lot.lot_unit_line = pu_line.id)))
|
||||
WHERE (1 = 1);;
|
||||
@@ -0,0 +1,21 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_lot_not_invoiced_on_purchase AS
|
||||
SELECT pur.id AS "intPurchaseId",
|
||||
pl.id AS "intPurchaseLineId",
|
||||
l.id AS "intLotId",
|
||||
si.id AS "intShipmentInId",
|
||||
pur.party AS "intVendorId",
|
||||
l.lot_qt AS "dblLotQuantity",
|
||||
qth.quantity AS "dblNetWeight",
|
||||
qth.gross_quantity AS "dblGrossWeight",
|
||||
pl.quantity AS "dblLineQuantity",
|
||||
pl.unit_price AS "dblLineUnitPrice",
|
||||
pl.price_type AS "strLinePriceType",
|
||||
pur.currency AS "intCurrencyId"
|
||||
FROM ((((((lot_lot l
|
||||
LEFT JOIN lot_qt_hist qth ON (((l.id = qth.lot) AND (l.lot_state = qth.quantity_type))))
|
||||
JOIN stock_shipment_in si ON ((si.id = l.lot_shipment_in)))
|
||||
JOIN purchase_line pl ON ((pl.id = l.line)))
|
||||
JOIN purchase_purchase pur ON ((pur.id = pl.purchase)))
|
||||
JOIN party_party pp ON ((pp.id = pur.party)))
|
||||
JOIN currency_currency cur ON ((cur.id = pur.currency)))
|
||||
WHERE ((1 = 1) AND ((l.lot_type)::text = 'physic'::text) AND ((si.state)::text = ANY ((ARRAY['received'::character varying, 'done'::character varying])::text[])) AND (l.invoice_line IS NULL));;
|
||||
@@ -0,0 +1,21 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_lot_not_invoiced_on_sale AS
|
||||
SELECT s.id AS "intSaleId",
|
||||
sl.id AS "intSaleLineId",
|
||||
l.id AS "intLotId",
|
||||
so.id AS "intShipmentOutId",
|
||||
s.party AS "intCustomerId",
|
||||
l.lot_qt AS "dblLotQuantity",
|
||||
qth.quantity AS "dblNetWeight",
|
||||
qth.gross_quantity AS "dblGrossWeight",
|
||||
sl.quantity AS "dblLineQuantity",
|
||||
sl.unit_price AS "dblLineUnitPrice",
|
||||
sl.price_type AS "strLinePriceType",
|
||||
s.currency AS "intCurrencyId"
|
||||
FROM ((((((lot_lot l
|
||||
LEFT JOIN lot_qt_hist qth ON (((l.id = qth.lot) AND (l.lot_state = qth.quantity_type))))
|
||||
JOIN stock_shipment_out so ON ((so.id = l.lot_shipment_out)))
|
||||
JOIN sale_line sl ON ((sl.id = l.sale_line)))
|
||||
JOIN sale_sale s ON ((s.id = sl.sale)))
|
||||
JOIN party_party pp ON ((pp.id = s.party)))
|
||||
JOIN currency_currency cur ON ((cur.id = s.currency)))
|
||||
WHERE ((1 = 1) AND ((so.state)::text = 'done'::text) AND (l.sale_invoice_line IS NULL));;
|
||||
12
Database Backups/SQL Views/vw_utility_matched_lots.sql
Normal file
12
Database Backups/SQL Views/vw_utility_matched_lots.sql
Normal file
@@ -0,0 +1,12 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_matched_lots AS
|
||||
SELECT matching.lot_p AS "intPurchaseLotId",
|
||||
matching.lot_s AS "intSaleLotId",
|
||||
COALESCE(matching.lot_shipment_in, 0) AS "intLotShipmentIn",
|
||||
matching.lot_quantity AS "dblQuantity",
|
||||
uom.name AS "strUnit",
|
||||
matching.lot_av AS "strAvailability",
|
||||
matching.lot_status AS "strStatus"
|
||||
FROM ((lot_qt matching
|
||||
LEFT JOIN vw_utility_shipment_in shipment ON ((matching.lot_shipment_in = shipment."intShipmentId")))
|
||||
LEFT JOIN product_uom uom ON ((matching.lot_unit = uom.id)))
|
||||
WHERE ((1 = 1) AND (COALESCE(matching.lot_p, 0) > 0) AND (COALESCE(matching.lot_s, 0) > 0));;
|
||||
21
Database Backups/SQL Views/vw_utility_price_curve.sql
Normal file
21
Database Backups/SQL Views/vw_utility_price_curve.sql
Normal file
@@ -0,0 +1,21 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_price_curve AS
|
||||
SELECT pp.id AS "intPriceCurveId",
|
||||
pp.price_desc AS "strPriceDescription",
|
||||
pp.price_index AS "strPriceIndex",
|
||||
cc.name AS "strCurrency",
|
||||
pu.name AS "strUnit",
|
||||
pp.price_curve_type AS "strPriceCurveType",
|
||||
COALESCE(pa.name, ''::character varying) AS "strPriceArea",
|
||||
COALESCE(pc.name, ''::character varying) AS "strPriceCalendar",
|
||||
COALESCE(pft.name, ''::character varying) AS "strPricingType",
|
||||
pm.beg_date AS "dtmPricingStartDate",
|
||||
pm.end_date AS "dtmPricingEndDate",
|
||||
pm.month_name AS "strPricingMonth"
|
||||
FROM ((((((price_price pp
|
||||
JOIN currency_currency cc ON ((pp.price_currency = cc.id)))
|
||||
LEFT JOIN price_area pa ON ((pp.price_area = pa.id)))
|
||||
LEFT JOIN price_calendar pc ON ((pp.price_calendar = pc.id)))
|
||||
LEFT JOIN product_uom pu ON ((pp.price_unit = pu.id)))
|
||||
LEFT JOIN product_month pm ON ((pp.price_period = pm.id)))
|
||||
LEFT JOIN price_fixtype pft ON ((pp.price_type = pft.id)))
|
||||
WHERE ((1 = 1) AND (pp.active = true));;
|
||||
10
Database Backups/SQL Views/vw_utility_price_curve_prices.sql
Normal file
10
Database Backups/SQL Views/vw_utility_price_curve_prices.sql
Normal file
@@ -0,0 +1,10 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_price_curve_prices AS
|
||||
SELECT pp.id AS "intPriceCurveId",
|
||||
ppv.price_date AS "dtmPriceDate",
|
||||
(ppv.high_price)::numeric(18,6) AS "dblHighPrice",
|
||||
(ppv.low_price)::numeric(18,6) AS "dblLowPrice",
|
||||
(ppv.open_price)::numeric(18,6) AS "dblOpenPrice",
|
||||
(ppv.price_value)::numeric(18,6) AS "dblPriceValue"
|
||||
FROM (price_price pp
|
||||
LEFT JOIN price_price_value ppv ON (((pp.id = ppv.price) AND (ppv.active = true))))
|
||||
WHERE ((1 = 1) AND (pp.active = true));;
|
||||
54
Database Backups/SQL Views/vw_utility_product.sql
Normal file
54
Database Backups/SQL Views/vw_utility_product.sql
Normal file
@@ -0,0 +1,54 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_product AS
|
||||
SELECT 0 AS "intProductId",
|
||||
''::character varying AS "strProductCode",
|
||||
''::text AS "strProductDescription",
|
||||
true AS "ysnActive",
|
||||
''::character varying AS "strTemplate",
|
||||
''::character varying AS "strTemplateCode",
|
||||
''::character varying AS "strDefaultUom",
|
||||
0 AS "dblDefaultUomFactor",
|
||||
0 AS "dblDefaultUomRate",
|
||||
0 AS "dblDefaultUomRounding",
|
||||
''::character varying(10) AS "strDefaultUomSymbol",
|
||||
true AS "ysnAvailableOnPurchase",
|
||||
''::character varying AS "strPurchaseUom",
|
||||
0 AS "dblPurchaseUomFactor",
|
||||
0 AS "dblPurchaseUomRate",
|
||||
0 AS "dblPurchaseUomRounding",
|
||||
''::character varying(10) AS "strPurchaseUomSymbol",
|
||||
true AS "ysnAvailableOnSale",
|
||||
''::character varying AS "strSaleUom",
|
||||
0 AS "dblSaleUomFactor",
|
||||
0 AS "dblSaleUomRate",
|
||||
0 AS "dblSaleUomRounding",
|
||||
''::character varying(10) AS "strSaleUomSymbol"
|
||||
UNION ALL
|
||||
SELECT p.id AS "intProductId",
|
||||
p.code AS "strProductCode",
|
||||
COALESCE(p.description, ''::text) AS "strProductDescription",
|
||||
p.active AS "ysnActive",
|
||||
pt.name AS "strTemplate",
|
||||
pt.type AS "strTemplateCode",
|
||||
pu1.name AS "strDefaultUom",
|
||||
pu1.factor AS "dblDefaultUomFactor",
|
||||
pu1.rate AS "dblDefaultUomRate",
|
||||
pu1.rounding AS "dblDefaultUomRounding",
|
||||
pu1.symbol AS "strDefaultUomSymbol",
|
||||
pt.purchasable AS "ysnAvailableOnPurchase",
|
||||
pu2.name AS "strPurchaseUom",
|
||||
pu2.factor AS "dblPurchaseUomFactor",
|
||||
pu2.rate AS "dblPurchaseUomRate",
|
||||
pu2.rounding AS "dblPurchaseUomRounding",
|
||||
pu2.symbol AS "strPurchaseUomSymbol",
|
||||
pt.salable AS "ysnAvailableOnSale",
|
||||
pu3.name AS "strSaleUom",
|
||||
pu3.factor AS "dblSaleUomFactor",
|
||||
pu3.rate AS "dblSaleUomRate",
|
||||
pu3.rounding AS "dblSaleUomRounding",
|
||||
pu3.symbol AS "strSaleUomSymbol"
|
||||
FROM ((((product_product p
|
||||
JOIN product_template pt ON ((p.template = pt.id)))
|
||||
JOIN product_uom pu1 ON ((pt.default_uom = pu1.id)))
|
||||
JOIN product_uom pu2 ON ((pt.purchase_uom = pu2.id)))
|
||||
JOIN product_uom pu3 ON ((pt.sale_uom = pu3.id)))
|
||||
WHERE (1 = 1);;
|
||||
@@ -0,0 +1,63 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_purchase_physical_contract AS
|
||||
SELECT pl.id AS "intPurchaseLineId",
|
||||
pl.from_del AS "dtmDeliveryDateFrom",
|
||||
pl.to_del AS "dtmDeliveryDateTo",
|
||||
pl.quantity AS "dblQuantity",
|
||||
pu1.name AS "strPurchaseUom",
|
||||
COALESCE(vult.dblintransitquantity, (0)::double precision) AS "dblInTransitQuantity",
|
||||
COALESCE(dropship.dbldropshippedquantity, (0)::double precision) AS "dblDropshippedQuantity",
|
||||
COALESCE(received.dblreceivedquantity, (0)::double precision) AS "dblReceivedQuantity",
|
||||
COALESCE(pl.linked_price, (0)::numeric) AS "dblPrice",
|
||||
pu2.name AS "strPriceUnit",
|
||||
'n/a'::text AS "strPriceCurrency",
|
||||
pl.unit_price AS "dblUnitPrice",
|
||||
COALESCE(pl.quantity_theorical, (0)::numeric) AS "dblTheoriticalQuantity",
|
||||
round(((pl.quantity * (pl.unit_price)::double precision))::numeric, get_rounding_position(mcr.rounding)) AS "dblLineAmount",
|
||||
cur.name AS "strCurrency",
|
||||
(0)::numeric AS "dblLineBaseAmount",
|
||||
''::text AS "strBaseCurrency",
|
||||
(0)::numeric AS "dblQuantityInBaseUnit",
|
||||
''::text AS "strBaseUnit",
|
||||
(0)::numeric AS "dblFixedPrice",
|
||||
(0)::numeric AS "dblFixedQuantity",
|
||||
(0)::numeric AS "dblFixedAmount",
|
||||
(0)::numeric AS "dblUnFixedPrice",
|
||||
(0)::numeric AS "dblUnfixedQuantity",
|
||||
(0)::numeric AS "dblUnfixedAmount",
|
||||
(0)::numeric AS "dblInvoicedQuantity",
|
||||
(0)::numeric AS "dblInvoicedAmount",
|
||||
''::text AS "strInvoiceCurrency",
|
||||
COALESCE(phys.dblphysicalqty, (0)::double precision) AS "dblPhysicalQty",
|
||||
(COALESCE((pl.quantity_theorical)::double precision, (0)::double precision) - COALESCE(phys.dblphysicalqty, (0)::double precision)) AS "dblOpenQuantity",
|
||||
COALESCE(inst.dblinstructedqty, (0)::double precision) AS "dblInInstructedQuantity",
|
||||
COALESCE(bl.estimated_date, pl.to_del) AS "dtmEstimatedBLDate",
|
||||
pl.finished AS "ysnFinished"
|
||||
FROM (((((((((((purchase_line pl
|
||||
JOIN purchase_purchase pc ON ((pl.purchase = pc.id)))
|
||||
JOIN product_uom pu1 ON ((pl.unit = pu1.id)))
|
||||
LEFT JOIN product_uom pu2 ON ((pl.linked_unit = pu2.id)))
|
||||
LEFT JOIN currency_linked cur ON ((pl.linked_currency = cur.id)))
|
||||
LEFT JOIN currency_currency mcr ON ((cur.currency = mcr.id)))
|
||||
LEFT JOIN ( SELECT transit."intPurchaseLineId",
|
||||
sum(transit."dblQuantity") AS dblintransitquantity
|
||||
FROM vw_utility_intransit_lots transit
|
||||
GROUP BY transit."intPurchaseLineId") vult ON ((pl.id = vult."intPurchaseLineId")))
|
||||
LEFT JOIN ( SELECT t1."intPurchaseLineId",
|
||||
sum(t1."dblQuantity") AS dbldropshippedquantity
|
||||
FROM vw_utility_dropshipped_lots t1
|
||||
GROUP BY t1."intPurchaseLineId") dropship ON ((pl.id = dropship."intPurchaseLineId")))
|
||||
LEFT JOIN ( SELECT t1."intPurchaseLineId",
|
||||
sum(t1."dblQuantity") AS dblreceivedquantity
|
||||
FROM vw_utility_received_lots t1
|
||||
GROUP BY t1."intPurchaseLineId") received ON ((pl.id = received."intPurchaseLineId")))
|
||||
LEFT JOIN ( SELECT t1."intPurchaseLineId",
|
||||
sum(t1."dblQuantity") AS dblphysicalqty
|
||||
FROM vw_utility_lot t1
|
||||
WHERE ((t1."strType")::text = 'physic'::text)
|
||||
GROUP BY t1."intPurchaseLineId") phys ON ((pl.id = phys."intPurchaseLineId")))
|
||||
LEFT JOIN ( SELECT t1."intPurchaseLineId",
|
||||
sum(t1."dblQuantity") AS dblinstructedqty
|
||||
FROM vw_utility_instructed_lots t1
|
||||
GROUP BY t1."intPurchaseLineId") inst ON ((pl.id = inst."intPurchaseLineId")))
|
||||
LEFT JOIN pricing_estimated bl ON (((pl.id = bl.line) AND ((bl.trigger)::text = 'bldate'::text))))
|
||||
WHERE (1 = 1);;
|
||||
19
Database Backups/SQL Views/vw_utility_received_lots.sql
Normal file
19
Database Backups/SQL Views/vw_utility_received_lots.sql
Normal file
@@ -0,0 +1,19 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_received_lots AS
|
||||
SELECT fm."intCompanyId",
|
||||
fm."intPurchaseLineId",
|
||||
fm."intShipmentId",
|
||||
fm."intLotId",
|
||||
fm."dblQuantity",
|
||||
fm."strUnit",
|
||||
fm."dblQuantityKg"
|
||||
FROM ((vw_utility_stock_movements fm
|
||||
JOIN vw_utility_shipment_in ds ON ((fm."intShipmentId" = ds."intShipmentId")))
|
||||
JOIN vw_utility_location dl ON ((fm."intToLocationId" = dl."intLocationId")))
|
||||
WHERE ((1 = 1) AND (fm."intLotId" > 0) AND ((ds."strToLocationType")::text = 'storage'::text) AND ((dl."strLocationType")::text = 'storage'::text) AND ((dl."strLocationName")::text = 'Transit'::text) AND ((fm."strState")::text = 'done'::text) AND (EXISTS ( SELECT fm2."intPurchaseLineId",
|
||||
fm2."intShipmentId",
|
||||
fm2."intLotId",
|
||||
fm2."dblQuantity"
|
||||
FROM ((vw_utility_stock_movements fm2
|
||||
JOIN vw_utility_shipment_in ds2 ON ((fm2."intShipmentId" = ds2."intShipmentId")))
|
||||
JOIN vw_utility_location dl2 ON ((fm2."intFromLocationId" = dl2."intLocationId")))
|
||||
WHERE ((1 = 1) AND (fm2."intLotId" > 0) AND ((ds2."strToLocationType")::text = 'storage'::text) AND ((dl2."strLocationType")::text = 'storage'::text) AND ((dl2."strLocationName")::text = 'Transit'::text) AND ((fm2."strState")::text = 'done'::text) AND (fm2."intLotId" = fm."intLotId") AND (fm2."intPurchaseLineId" = fm."intPurchaseLineId") AND (fm2."intShipmentId" = fm."intShipmentId")))));;
|
||||
@@ -0,0 +1,49 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_sale_physical_contract AS
|
||||
SELECT sl.id AS "intSaleLineId",
|
||||
sl.from_del AS "dtmDeliveryDateFrom",
|
||||
sl.to_del AS "dtmDeliveryDateTo",
|
||||
sl.quantity AS "dblQuantity",
|
||||
pu1.name AS "strSaleUom",
|
||||
0 AS "dblDeliveredQuantity",
|
||||
COALESCE(sl.linked_price, (0)::numeric) AS "dblPrice",
|
||||
pu2.name AS "strPriceUnit",
|
||||
'n/a'::text AS "strPriceCurrency",
|
||||
sl.unit_price AS "dblUnitPrice",
|
||||
COALESCE(sl.quantity_theorical, (0)::numeric) AS "dblTheoreticalQuantity",
|
||||
round(((sl.quantity * (sl.unit_price)::double precision))::numeric, get_rounding_position((2)::numeric)) AS "dblLineAmount",
|
||||
'n/a'::text AS "strCurrency",
|
||||
(0)::numeric AS "dblLineBaseAmount",
|
||||
''::text AS "strBaseCurrency",
|
||||
(0)::numeric AS "dblQuantityInBaseUnit",
|
||||
''::text AS "strBaseUnit",
|
||||
(0)::numeric AS "dblFixedPrice",
|
||||
(0)::numeric AS "dblFixedQuantity",
|
||||
(0)::numeric AS "dblFixedAmount",
|
||||
(0)::numeric AS "dblUnFixedPrice",
|
||||
(0)::numeric AS "dblUnfixedQuantity",
|
||||
(0)::numeric AS "dblUnfixedAmount",
|
||||
(0)::numeric AS "dblInvoicedQuantity",
|
||||
(0)::numeric AS "dblInvoicedAmount",
|
||||
''::text AS "strInvoiceCurrency",
|
||||
convert_weight(sl.quantity_theorical, (pu1.name)::text, 'Kilogram'::text) AS "dblTheoreticalWeightKg",
|
||||
COALESCE((shipped."dblNetWeightKg")::double precision, (0)::double precision) AS "dblPhysicalWeightKg",
|
||||
((convert_weight(sl.quantity_theorical, (pu1.name)::text, 'Kilogram'::text))::double precision - COALESCE((shipped."dblNetWeightKg")::double precision, (0)::double precision)) AS "dblOpenWeightKg",
|
||||
COALESCE(bl.estimated_date, sl.from_del) AS "dtmEstimatedBLDate",
|
||||
COALESCE(instructed.dblinstructedqty, ((0)::numeric)::double precision) AS "dblInstructedQuantity",
|
||||
sl.finished AS "ysnFinished"
|
||||
FROM ((((((sale_line sl
|
||||
JOIN sale_sale sc ON ((sl.sale = sc.id)))
|
||||
JOIN product_uom pu1 ON ((sl.unit = pu1.id)))
|
||||
LEFT JOIN product_uom pu2 ON ((sl.linked_unit = pu2.id)))
|
||||
LEFT JOIN ( SELECT lot."intSaleLineId",
|
||||
sum(lot."dblNetWeightKg") AS "dblNetWeightKg"
|
||||
FROM vw_utility_lot lot
|
||||
WHERE (((lot."strType")::text = 'physic'::text) AND (lot."intSaleLineId" IS NOT NULL) AND (lot."intSaleLineId" > 0))
|
||||
GROUP BY lot."intSaleLineId") shipped ON ((sl.id = shipped."intSaleLineId")))
|
||||
LEFT JOIN pricing_estimated bl ON ((sl.id = bl.sale_line)))
|
||||
LEFT JOIN ( SELECT t1."intSaleLineId",
|
||||
sum(t1."dblQuantity") AS dblinstructedqty
|
||||
FROM vw_utility_instructed_lots t1
|
||||
WHERE (COALESCE(t1."intSaleLineId", 0) > 0)
|
||||
GROUP BY t1."intSaleLineId") instructed ON ((sl.id = instructed."intSaleLineId")))
|
||||
WHERE (1 = 1);;
|
||||
28
Database Backups/SQL Views/vw_utility_shipment_fees.sql
Normal file
28
Database Backups/SQL Views/vw_utility_shipment_fees.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_shipment_fees AS
|
||||
SELECT f.id AS "intFeeId",
|
||||
'ShipmentIn'::text AS "strShipmentType",
|
||||
f.shipment_in AS "intShipmentId",
|
||||
f.mode AS "strPackaging",
|
||||
f.p_r AS "strPayOrRec",
|
||||
f.type AS "strType",
|
||||
p.code AS "strProduct",
|
||||
sup.name AS "strSupplier",
|
||||
f.state AS "strState",
|
||||
CASE
|
||||
WHEN (upper((f.weight_type)::text) = 'BRUT'::text) THEN 'Gross'::text
|
||||
ELSE 'Net'::text
|
||||
END AS "strWeightType",
|
||||
f.quantity AS "dblQuantity",
|
||||
f.price AS "dblPrice",
|
||||
c.name AS "strCurrency",
|
||||
COALESCE(uom.name, 'Mt'::character varying) AS "strUnit",
|
||||
CASE
|
||||
WHEN (upper((f.p_r)::text) = 'REC'::text) THEN 1
|
||||
ELSE '-1'::integer
|
||||
END AS "dblSignMultiplier"
|
||||
FROM ((((fee_fee f
|
||||
JOIN currency_currency c ON ((f.currency = c.id)))
|
||||
JOIN product_product p ON ((f.product = p.id)))
|
||||
LEFT JOIN product_uom uom ON ((f.unit = uom.id)))
|
||||
JOIN party_party sup ON ((f.supplier = sup.id)))
|
||||
WHERE (COALESCE(f.shipment_in, 0) > 0);;
|
||||
73
Database Backups/SQL Views/vw_utility_shipment_in.sql
Normal file
73
Database Backups/SQL Views/vw_utility_shipment_in.sql
Normal file
@@ -0,0 +1,73 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_shipment_in AS
|
||||
SELECT 0 AS "intShipmentId",
|
||||
NULL::date AS "dtmEffectiveDate",
|
||||
''::character varying AS "strBookingNumber",
|
||||
''::character varying AS "strShipmentNb",
|
||||
''::character varying AS "strShipmentReference",
|
||||
''::character varying AS "strBillOfLading",
|
||||
NULL::date AS "dtmBillOfLadingDate",
|
||||
NULL::date AS "dtmETADestination",
|
||||
NULL::date AS "dtmOriginPlannedDate",
|
||||
NULL::date AS "dtmPlannedDate",
|
||||
''::character varying AS "strState",
|
||||
''::character varying AS "strSupplier",
|
||||
''::character varying AS "strWarehouse",
|
||||
''::character varying AS "strWarehouseInput",
|
||||
''::character varying AS "strStorage",
|
||||
''::character varying AS "strFromLocation",
|
||||
''::character varying AS "strToLocation",
|
||||
''::character varying AS "strToLocationType",
|
||||
''::character varying AS "strTransportType",
|
||||
''::character varying AS "strVessel",
|
||||
''::character varying AS "strVesselIMO",
|
||||
''::character varying AS "strVesselYearOfBuilt",
|
||||
''::character varying AS "strCarrier",
|
||||
NULL::date AS "dtmETAPol",
|
||||
NULL::date AS "dtmETD",
|
||||
NULL::date AS "dtmETL",
|
||||
NULL::date AS "dtmUnloadingDate",
|
||||
NULL::date AS "dtmBookingDate",
|
||||
''::character varying AS "strReceiveNumber",
|
||||
NULL::date AS "dtmReceiveDate",
|
||||
''::character varying AS "strCargoMode"
|
||||
UNION ALL
|
||||
SELECT ssin.id AS "intShipmentId",
|
||||
ssin.effective_date AS "dtmEffectiveDate",
|
||||
ssin.booking AS "strBookingNumber",
|
||||
ssin.number AS "strShipmentNb",
|
||||
ssin.reference AS "strShipmentReference",
|
||||
ssin.bl_number AS "strBillOfLading",
|
||||
ssin.bl_date AS "dtmBillOfLadingDate",
|
||||
ssin.etad AS "dtmETADestination",
|
||||
ssin.origin_planned_date AS "dtmOriginPlannedDate",
|
||||
ssin.planned_date AS "dtmPlannedDate",
|
||||
ssin.state AS "strState",
|
||||
sup.name AS "strSupplier",
|
||||
wh.name AS "strWarehouse",
|
||||
inp.name AS "strWarehouseInput",
|
||||
sto.name AS "strStorage",
|
||||
src.name AS "strFromLocation",
|
||||
dest.name AS "strToLocation",
|
||||
dest.type AS "strToLocationType",
|
||||
ssin.transport_type AS "strTransportType",
|
||||
COALESCE(vessel.vessel_name, 'Unknown Vessel'::character varying) AS "strVessel",
|
||||
COALESCE(vessel.vessel_imo, ''::character varying) AS "strVesselIMO",
|
||||
COALESCE(vessel.vessel_year, ''::character varying) AS "strVesselYearOfBuilt",
|
||||
car.name AS "strCarrier",
|
||||
ssin.eta AS "dtmETAPol",
|
||||
ssin.etd AS "dtmETD",
|
||||
ssin.etl AS "dtmETL",
|
||||
ssin.unloaded AS "dtmUnloadingDate",
|
||||
ssin.booking_date AS "dtmBookingDate",
|
||||
ssin.receive_nb AS "strReceiveNumber",
|
||||
ssin.receive_date AS "dtmReceiveDate",
|
||||
ssin.cargo_mode AS "strCargoMode"
|
||||
FROM ((((((((stock_shipment_in ssin
|
||||
LEFT JOIN party_party sup ON ((ssin.supplier = sup.id)))
|
||||
LEFT JOIN stock_location wh ON ((ssin.warehouse = wh.id)))
|
||||
LEFT JOIN stock_location inp ON ((ssin.warehouse_input = inp.id)))
|
||||
LEFT JOIN stock_location sto ON ((ssin.warehouse_storage = sto.id)))
|
||||
LEFT JOIN stock_location src ON ((ssin.from_location = src.id)))
|
||||
LEFT JOIN stock_location dest ON ((ssin.to_location = dest.id)))
|
||||
LEFT JOIN trade_vessel vessel ON ((ssin.vessel = vessel.id)))
|
||||
LEFT JOIN party_party car ON ((ssin.carrier_ = car.id)));;
|
||||
42
Database Backups/SQL Views/vw_utility_stock_movements.sql
Normal file
42
Database Backups/SQL Views/vw_utility_stock_movements.sql
Normal file
@@ -0,0 +1,42 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_stock_movements AS
|
||||
SELECT sm.id AS "intStockId",
|
||||
sm.company AS "intCompanyId",
|
||||
COALESCE(sm.lot, 0) AS "intLotId",
|
||||
COALESCE(sm.cost_price, (0)::numeric) AS "dblCostPrice",
|
||||
cur.name AS "strCurrency",
|
||||
sm.effective_date AS "dtmEffectiveDate",
|
||||
sm.bldate AS "dtmBLDate",
|
||||
sm.product AS "intProductId",
|
||||
sm.from_location AS "intFromLocationId",
|
||||
sm.to_location AS "intToLocationId",
|
||||
sm.origin,
|
||||
split_part((sm.origin)::text, ','::text, 1) AS "strSourceType",
|
||||
COALESCE((split_part((sm.shipment)::text, ','::text, 2))::integer, 0) AS "intShipmentId",
|
||||
CASE
|
||||
WHEN (((sl_src.type)::text = 'supplier'::text) AND ((sl_dest.type)::text = 'customer'::text)) THEN 'Dropship'::text
|
||||
WHEN (split_part((sm.origin)::text, ','::text, 1) = 'purchase.line'::text) THEN 'Inbound'::text
|
||||
WHEN (split_part((sm.origin)::text, ','::text, 1) = 'sale.line'::text) THEN 'Outbound'::text
|
||||
ELSE 'Unknown'::text
|
||||
END AS "strMovementType",
|
||||
CASE
|
||||
WHEN (split_part((sm.origin)::text, ','::text, 1) = 'purchase.line'::text) THEN (split_part((sm.origin)::text, ','::text, 2))::integer
|
||||
ELSE 0
|
||||
END AS "intPurchaseLineId",
|
||||
CASE
|
||||
WHEN (((sl_src.type)::text = 'supplier'::text) AND ((sl_dest.type)::text = 'customer'::text)) THEN lot.sale_line
|
||||
WHEN (split_part((sm.origin)::text, ','::text, 1) = 'sale.line'::text) THEN (split_part((sm.origin)::text, ','::text, 2))::integer
|
||||
ELSE 0
|
||||
END AS "intSaleLineId",
|
||||
sm.quantity AS "dblQuantity",
|
||||
uom.name AS "strUnit",
|
||||
round(((sm.quantity * uom.factor))::numeric, get_rounding_position((uom.rounding)::numeric)) AS "dblQuantityKg",
|
||||
sm.unit_price,
|
||||
sm.unit_price_updated AS "ysnPriceUpdated",
|
||||
sm.state AS "strState",
|
||||
lot.lot_status AS "strLotStatus"
|
||||
FROM (((((stock_move sm
|
||||
JOIN currency_currency cur ON ((sm.currency = cur.id)))
|
||||
LEFT JOIN lot_lot lot ON ((sm.lot = lot.id)))
|
||||
LEFT JOIN product_uom uom ON ((sm.unit = uom.id)))
|
||||
LEFT JOIN stock_location sl_src ON ((sl_src.id = sm.from_location)))
|
||||
LEFT JOIN stock_location sl_dest ON ((sl_dest.id = sm.to_location)));;
|
||||
32
Database Backups/SQL Views/vw_utility_strategy_dimension.sql
Normal file
32
Database Backups/SQL Views/vw_utility_strategy_dimension.sql
Normal file
@@ -0,0 +1,32 @@
|
||||
CREATE OR REPLACE VIEW public.vw_utility_strategy_dimension AS
|
||||
WITH dimensionvalue AS (
|
||||
SELECT ad.id AS "dimensionId",
|
||||
adv.id AS "valueId",
|
||||
ad.code AS "dimensionCode",
|
||||
adv.code AS "valueCode",
|
||||
adv.name AS "valueName"
|
||||
FROM (analytic_dimension ad
|
||||
JOIN analytic_dimension_value adv ON ((ad.id = adv.dimension)))
|
||||
WHERE ((1 = 1) AND ((ad.code)::text = 'strategy'::text))
|
||||
)
|
||||
SELECT DISTINCT aa.purchase AS "intTradeId",
|
||||
pl.id AS "intTradeLineId",
|
||||
'Physical'::text AS "strTradeCategory",
|
||||
'Purchase'::text AS "strTradeType",
|
||||
bv."valueCode" AS "strValueCode",
|
||||
bv."valueName" AS "strValueName"
|
||||
FROM ((analytic_dimension_assignment aa
|
||||
JOIN dimensionvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
|
||||
JOIN purchase_line pl ON ((aa.purchase = pl.purchase)))
|
||||
WHERE (COALESCE(aa.purchase, 0) > 0)
|
||||
UNION ALL
|
||||
SELECT DISTINCT aa.sale AS "intTradeId",
|
||||
sl.id AS "intTradeLineId",
|
||||
'Physical'::text AS "strTradeCategory",
|
||||
'Sale'::text AS "strTradeType",
|
||||
bv."valueCode" AS "strValueCode",
|
||||
bv."valueName" AS "strValueName"
|
||||
FROM ((analytic_dimension_assignment aa
|
||||
JOIN dimensionvalue bv ON (((aa.dimension = bv."dimensionId") AND (aa.value = bv."valueId"))))
|
||||
JOIN sale_line sl ON ((sl.sale = aa.sale)))
|
||||
WHERE (COALESCE(aa.sale, 0) > 0);;
|
||||
Reference in New Issue
Block a user