﻿CREATE TABLE [dbo].[QuoteOC] (
    [QuoteType]  CHAR (1)        CONSTRAINT [DF_QuoteExtra_QuoteType] DEFAULT ('Q') NOT NULL,
    [CodQuote]   BIGINT          NOT NULL,
    [QuoteRev]   INT             CONSTRAINT [DF_QuoteExtra_QuoteRev] DEFAULT ((0)) NOT NULL,
    [NumEx]      INT             NOT NULL,
    [ProcessNum] NVARCHAR (50)   CONSTRAINT [DF_QuoteExtra_ResType] DEFAULT ((0)) NOT NULL,
    [CodPlant]   NVARCHAR (50)   NOT NULL,
    [Class01]    NVARCHAR (50)   CONSTRAINT [DF_QuoteExtra_Class01] DEFAULT ('') NOT NULL,
    [Class02]    NVARCHAR (50)   CONSTRAINT [DF_QuoteExtra_Class02] DEFAULT ('') NOT NULL,
    [Class03]    NVARCHAR (50)   CONSTRAINT [DF_QuoteExtra_Class03] DEFAULT ('') NOT NULL,
    [Class04]    NVARCHAR (50)   CONSTRAINT [DF_QuoteExtra_Class04] DEFAULT ('') NOT NULL,
    [Class05]    NVARCHAR (50)   CONSTRAINT [DF_QuoteExtra_Class05] DEFAULT ('') NOT NULL,
    [TotQty]     DECIMAL (18, 6) CONSTRAINT [DF_QuoteExtra_TotQty] DEFAULT ((1)) NOT NULL,
    [TotCost]    DECIMAL (18, 6) CONSTRAINT [DF_QuoteExtra_TotCost] DEFAULT ((0)) NOT NULL,
    [Quota]      DECIMAL (18, 6) CONSTRAINT [DF_QuoteExtra_Quota] DEFAULT ((1)) NOT NULL,
    [C4UG]       AS              (([TotCost]*[Quota])/[TotQty]) PERSISTED,
    [valid]      BIT             CONSTRAINT [DF_QuoteOC_valid] DEFAULT ((1)) NOT NULL,
    CONSTRAINT [PK_QuoteExtra] PRIMARY KEY CLUSTERED ([QuoteType] ASC, [CodQuote] ASC, [QuoteRev] ASC, [NumEx] ASC),
    CONSTRAINT [FK_QuoteExtra_QuoteList] FOREIGN KEY ([QuoteType], [CodQuote], [QuoteRev]) REFERENCES [dbo].[QuoteList] ([QuoteType], [CodQuote], [QuoteRev]) ON UPDATE CASCADE
);


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Altri costi (diretti-indiretti)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'tipo di preventivo: Q = quote, S = simulation', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'QuoteType';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'numero nel formato yyMMddnnnn dove nnn è incrementale giornaliero', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'CodQuote';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'progressivo del costo OTHER', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'NumEx';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Tipo risorsa (e lavorazione): 01 .. 04', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'ProcessNum';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'codice impianto', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'CodPlant';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Riclass. 01, tipo di costo :
- UTIL (EE/GAS)
- ROTTAME (costo rifusione + quota perdita x ri-vendita)
- CONS 
- TRASP 
- PROVV 
- EXTRA', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'Class01';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Riclass. 02, codice di ricerca per tipo di costo extra, es se consumabili è codice matrice', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'Class02';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Riclass. 03', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'Class03';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Riclass. 04', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'Class04';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Riclass. 05', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'Class05';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'quantità totale di riferimento', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'TotQty';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Costo totale di riferimento', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'TotCost';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Quota di impiego', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'Quota';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Costo pro quota di impiego (per matrici, imballi,...)', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteOC', @level2type = N'COLUMN', @level2name = N'C4UG';

