﻿CREATE TABLE [dbo].[QuoteRM] (
    [QuoteType]       CHAR (1)        CONSTRAINT [DF_QuoteRM_QuoteType] DEFAULT ('Q') NOT NULL,
    [CodQuote]        BIGINT          NOT NULL,
    [QuoteRev]        INT             CONSTRAINT [DF_QuoteRM_QuoteRev] DEFAULT ((0)) NOT NULL,
    [NumRM]           INT             NOT NULL,
    [RawMat]          NVARCHAR (50)   NOT NULL,
    [RawMatCost]      DECIMAL (18, 6) CONSTRAINT [DF_QuoteRM_RawMatCost] DEFAULT ((0)) NOT NULL,
    [RawMatExtraCost] DECIMAL (18, 6) CONSTRAINT [DF_QuoteRM_RawMatExtraCost] DEFAULT ((0)) NOT NULL,
    [CodPackag]       NVARCHAR (50)   CONSTRAINT [DF_QuoteRM_CodPackag] DEFAULT ((0)) NOT NULL,
    [FCR]             DECIMAL (18, 6) CONSTRAINT [DF_QuoteRM_ConvRatio] DEFAULT ((1)) NOT NULL,
    [FYR]             AS              ((1)/[FCR]),
    [FSR]             AS              ((1)-(1)/[FCR]),
    [valid]           BIT             CONSTRAINT [DF_QuoteRM_valid] DEFAULT ((1)) NOT NULL,
    CONSTRAINT [PK_QuoteRM] PRIMARY KEY CLUSTERED ([QuoteType] ASC, [CodQuote] ASC, [QuoteRev] ASC, [NumRM] ASC),
    CONSTRAINT [FK_QuoteRM_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'tipo di preventivo: Q = quote, S = simulation', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteRM', @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'QuoteRM', @level2type = N'COLUMN', @level2name = N'CodQuote';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'progressivo interno', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteRM', @level2type = N'COLUMN', @level2name = N'NumRM';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'codice MP', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteRM', @level2type = N'COLUMN', @level2name = N'RawMat';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'costo della MP €/kg', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteRM', @level2type = N'COLUMN', @level2name = N'RawMatCost';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'costo degli extra della MP €/kg', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteRM', @level2type = N'COLUMN', @level2name = N'RawMatExtraCost';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'Tasso di conversione TOTALE, messa al cento, quantità di MP necessaria per produrre un unità di prodotto', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteRM', @level2type = N'COLUMN', @level2name = N'FCR';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'FULL Yield Ratio, percentuale RESA TOTALE', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteRM', @level2type = N'COLUMN', @level2name = N'FYR';


GO
EXECUTE sp_addextendedproperty @name = N'MS_Description', @value = N'FULL Scrape Ratio, percentuale scarto TOTALE', @level0type = N'SCHEMA', @level0name = N'dbo', @level1type = N'TABLE', @level1name = N'QuoteRM', @level2type = N'COLUMN', @level2name = N'FSR';

