First initial commit
This commit is contained in:
16
vw_bi_dim_product.sql
Normal file
16
vw_bi_dim_product.sql
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
-- View: public.vw_bi_dim_product
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_bi_dim_product;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_bi_dim_product
|
||||||
|
OWNER TO postgres;
|
||||||
29
vw_bi_dim_purchase_physical_contract.sql
Normal file
29
vw_bi_dim_purchase_physical_contract.sql
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
-- View: public.vw_bi_dim_purchase_physical_contract
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_bi_dim_purchase_physical_contract;
|
||||||
|
|
||||||
|
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",
|
||||||
|
"strContractStatus" 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"
|
||||||
|
FROM vw_utility_dim_physical_purchase_contract dpc;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_bi_dim_purchase_physical_contract
|
||||||
|
OWNER TO postgres;
|
||||||
23
vw_bi_fct_purchase_physical_contract.sql
Normal file
23
vw_bi_fct_purchase_physical_contract.sql
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
-- View: public.vw_bi_fct_purchase_physical_contract
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_bi_fct_purchase_physical_contract;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_bi_fct_purchase_physical_contract
|
||||||
|
OWNER TO postgres;
|
||||||
71
vw_utility_dim_physical_purchase_contract.sql
Normal file
71
vw_utility_dim_physical_purchase_contract.sql
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
-- View: public.vw_utility_dim_physical_sale_contract
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_dim_physical_sale_contract;
|
||||||
|
|
||||||
|
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"
|
||||||
|
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"
|
||||||
|
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
|
||||||
|
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
|
||||||
|
WHERE 1 = 1 AND sl.type::text = 'line'::text;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_dim_physical_sale_contract
|
||||||
|
OWNER TO postgres;
|
||||||
71
vw_utility_dim_physical_sale_contract.sql
Normal file
71
vw_utility_dim_physical_sale_contract.sql
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
-- View: public.vw_utility_dim_physical_sale_contract
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_dim_physical_sale_contract;
|
||||||
|
|
||||||
|
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"
|
||||||
|
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"
|
||||||
|
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
|
||||||
|
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
|
||||||
|
WHERE 1 = 1 AND sl.type::text = 'line'::text;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_dim_physical_sale_contract
|
||||||
|
OWNER TO postgres;
|
||||||
19
vw_utility_dropshipped_lots.sql
Normal file
19
vw_utility_dropshipped_lots.sql
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
-- View: public.vw_utility_dropshipped_lots
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_dropshipped_lots;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_dropshipped_lots
|
||||||
|
OWNER TO postgres;
|
||||||
17
vw_utility_instructed_lots.sql
Normal file
17
vw_utility_instructed_lots.sql
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
-- View: public.vw_utility_instructed_lots
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_instructed_lots;
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public.vw_utility_instructed_lots AS
|
||||||
|
SELECT mvt."intLotId",
|
||||||
|
mvt."intShipmentId",
|
||||||
|
mvt."intPurchaseLineId",
|
||||||
|
mvt."dblQuantity",
|
||||||
|
mvt."strUnit",
|
||||||
|
mvt."dblQuantityKg"
|
||||||
|
FROM vw_utility_stock_movements mvt
|
||||||
|
JOIN vw_utility_shipment_in spt ON mvt."intShipmentId" = spt."intShipmentId"
|
||||||
|
WHERE 1 = 1 AND mvt."strMovementType" = 'Inbound'::text AND spt."strState"::text = 'draft'::text;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_instructed_lots
|
||||||
|
OWNER TO postgres;
|
||||||
26
vw_utility_intransit_lots.sql
Normal file
26
vw_utility_intransit_lots.sql
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
-- View: public.vw_utility_intransit_lots
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_intransit_lots;
|
||||||
|
|
||||||
|
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"));
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_intransit_lots
|
||||||
|
OWNER TO postgres;
|
||||||
31
vw_utility_invoices.sql
Normal file
31
vw_utility_invoices.sql
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
-- View: public.vw_utility_invoices
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_invoices;
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public.vw_utility_invoices AS
|
||||||
|
SELECT ai.id AS "intInvoiceId",
|
||||||
|
ai.company AS "intCompanyId",
|
||||||
|
cparty.name AS "strCompanyName",
|
||||||
|
ai.number AS "strInvoiceNumber",
|
||||||
|
ai.invoice_date AS "dtmInvoiceDate",
|
||||||
|
p.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",
|
||||||
|
ai.move AS "intMoveId",
|
||||||
|
ai.account AS "intAccountId",
|
||||||
|
aa.name AS "strAccountName"
|
||||||
|
FROM account_invoice ai
|
||||||
|
JOIN currency_currency cc ON ai.currency = cc.id
|
||||||
|
JOIN party_party p ON ai.party = p.id
|
||||||
|
JOIN company_company comp ON ai.company = comp.id
|
||||||
|
JOIN party_party cparty ON comp.party = cparty.id
|
||||||
|
JOIN account_invoice_payment_term aipt ON ai.payment_term = aipt.id
|
||||||
|
LEFT JOIN account_account aa ON ai.account = aa.id
|
||||||
|
WHERE 1 = 1;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_invoices
|
||||||
|
OWNER TO postgres;
|
||||||
18
vw_utility_location.sql
Normal file
18
vw_utility_location.sql
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
-- View: public.vw_utility_location
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_location;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_location
|
||||||
|
OWNER TO postgres;
|
||||||
32
vw_utility_lot.sql
Normal file
32
vw_utility_lot.sql
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
-- View: public.vw_utility_lot
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_lot;
|
||||||
|
|
||||||
|
CREATE OR REPLACE VIEW public.vw_utility_lot AS
|
||||||
|
SELECT id AS "intLotId",
|
||||||
|
COALESCE(lot_container, ''::character varying) AS "strContainer",
|
||||||
|
COALESCE(lot_name, ''::character varying) AS "strLotName",
|
||||||
|
COALESCE(lot_status, ''::character varying) AS "strStatus",
|
||||||
|
COALESCE(lot_type, ''::character varying) AS "strType",
|
||||||
|
COALESCE(lot_av, ''::character varying) AS "strAvailability",
|
||||||
|
line AS "intPurchaseLineId",
|
||||||
|
sale_line AS "intSaleLineId",
|
||||||
|
lot_product AS "intProductId",
|
||||||
|
lot_state AS "intLotStateId",
|
||||||
|
lot_unit AS "intUnitId",
|
||||||
|
lot_unit_line AS "intUnitLineId",
|
||||||
|
lot_qt AS "dblQuantity",
|
||||||
|
invoice_line AS "intInvoiceLineId",
|
||||||
|
invoice_line_prov AS "intInvoiceLineProvId",
|
||||||
|
COALESCE(lot_pur_inv_state, ''::character varying) AS "strPurchaseInvoiceState",
|
||||||
|
COALESCE(lot_sale_inv_state, ''::character varying) AS "strSaleInvoiceState",
|
||||||
|
lot_shipment_in AS "intShipmentInId",
|
||||||
|
lot_shipment_internal AS "intShipmentInternalId",
|
||||||
|
lot_shipment_out AS "intShipmentOutId",
|
||||||
|
sale_invoice_line AS "intSaleInvoiceLineId",
|
||||||
|
sale_invoice_line_prov AS "intSaleInvoiceLineProvId"
|
||||||
|
FROM lot_lot lot
|
||||||
|
WHERE 1 = 1;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_lot
|
||||||
|
OWNER TO postgres;
|
||||||
61
vw_utility_product.sql
Normal file
61
vw_utility_product.sql
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
-- View: public.vw_utility_product
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_product;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_product
|
||||||
|
OWNER TO postgres;
|
||||||
67
vw_utility_purchase_physical_contract.sql
Normal file
67
vw_utility_purchase_physical_contract.sql
Normal file
@@ -0,0 +1,67 @@
|
|||||||
|
-- View: public.vw_utility_purchase_physical_contract
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_purchase_physical_contract;
|
||||||
|
|
||||||
|
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",
|
||||||
|
pl.linked_price AS "dblPrice",
|
||||||
|
pu2.name AS "strPriceUnit",
|
||||||
|
'n/a'::text AS "strPriceCurrency",
|
||||||
|
pl.unit_price AS "dblUnitPrice",
|
||||||
|
pl.quantity_theorical 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",
|
||||||
|
pl.quantity_theorical::double precision - COALESCE(phys.dblphysicalqty, 0::double precision) AS "dblOpenQuantity",
|
||||||
|
COALESCE(inst.dblinstructedqty, 0::double precision) AS "dblInInstructedQuantity"
|
||||||
|
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"
|
||||||
|
WHERE 1 = 1;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_purchase_physical_contract
|
||||||
|
OWNER TO postgres;
|
||||||
26
vw_utility_received_lots.sql
Normal file
26
vw_utility_received_lots.sql
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
-- View: public.vw_utility_received_lots
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_received_lots;
|
||||||
|
|
||||||
|
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"));
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_received_lots
|
||||||
|
OWNER TO postgres;
|
||||||
80
vw_utility_shipment_in.sql
Normal file
80
vw_utility_shipment_in.sql
Normal file
@@ -0,0 +1,80 @@
|
|||||||
|
-- View: public.vw_utility_shipment_in
|
||||||
|
|
||||||
|
-- DROP VIEW public.vw_utility_shipment_in;
|
||||||
|
|
||||||
|
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",
|
||||||
|
vessel.vessel_name AS "strVessel",
|
||||||
|
vessel.vessel_imo AS "strVesselIMO",
|
||||||
|
vessel.vessel_year 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;
|
||||||
|
|
||||||
|
ALTER TABLE public.vw_utility_shipment_in
|
||||||
|
OWNER TO postgres;
|
||||||
@@ -2,8 +2,6 @@
|
|||||||
|
|
||||||
-- DROP VIEW public.vw_utility_stock_movements;
|
-- DROP VIEW public.vw_utility_stock_movements;
|
||||||
|
|
||||||
--Comments: This view provides a comprehensive overview of stock movements, including details such as stock IDs, company IDs, lot IDs, cost prices, currencies, effective dates, product IDs, locations, origins, movement types, quantities, units, and states.
|
|
||||||
|
|
||||||
CREATE OR REPLACE VIEW public.vw_utility_stock_movements AS
|
CREATE OR REPLACE VIEW public.vw_utility_stock_movements AS
|
||||||
SELECT sm.id AS "intStockId",
|
SELECT sm.id AS "intStockId",
|
||||||
sm.company AS "intCompanyId",
|
sm.company AS "intCompanyId",
|
||||||
|
|||||||
Reference in New Issue
Block a user