-- --------------------------------------------------------

--
-- Struttura della tabella `accomp_invoices`
--

CREATE TABLE `accomp_invoices` (
  `id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL,
  `customer_id` int(20) NOT NULL DEFAULT '0',
  `supplier_id` int(20) NOT NULL DEFAULT '0',
  `order_id` int(20) NOT NULL DEFAULT '0',
  `waybill_id` int(20) NOT NULL DEFAULT '0',
  `type` varchar(225) DEFAULT NULL,
  `price_list_id` varchar(225) DEFAULT NULL,
  `number` int(20) NOT NULL,
  `year` int(20) NOT NULL,
  `items_qty` int(20) NOT NULL DEFAULT '0',
  `subtotal` double(11,2) NOT NULL,
  `payment_id` int(20) NOT NULL,
  `payment_date` datetime DEFAULT NULL,
  `payment_action` varchar(225) DEFAULT NULL,
  `payment_amount` double(11,2) DEFAULT NULL,
  `tax_id` int(20) NOT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `status` varchar(225) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `accomp_invoice_details`
--

CREATE TABLE `accomp_invoice_details` (
  `id` int(20) NOT NULL,
  `accomp_invoice_id` int(20) NOT NULL,
  `product_id` int(20) NOT NULL,
  `variation_id` int(20) NOT NULL,
  `item_id` int(20) NOT NULL,
  `description` text,
  `qty` int(20) DEFAULT NULL,
  `price` double(11,2) NOT NULL,
  `source` varchar(225) NOT NULL,
  `discount` double(11,2) NOT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `attributes`
--

CREATE TABLE `attributes` (
  `id` varchar(225) NOT NULL,
  `name` varchar(225) NOT NULL,
  `description` text,
  `active` int(20) DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `credit_notes`
--

CREATE TABLE `credit_notes` (
  `id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL,
  `customer_id` int(20) NOT NULL DEFAULT '0',
  `supplier_id` int(20) NOT NULL DEFAULT '0',
  `order_id` int(20) NOT NULL DEFAULT '0',
  `invoice_id` int(20) NOT NULL DEFAULT '0',
  `waybill_id` int(20) NOT NULL DEFAULT '0',
  `type` varchar(225) DEFAULT NULL,
  `price_list_id` varchar(225) DEFAULT NULL,
  `number` int(20) NOT NULL,
  `year` int(20) NOT NULL,
  `items_qty` int(20) NOT NULL DEFAULT '0',
  `subtotal` double(11,2) NOT NULL,
  `payment_id` int(20) NOT NULL,
  `payment_date` datetime DEFAULT NULL,
  `payment_action` varchar(225) DEFAULT NULL,
  `payment_amount` double(11,2) DEFAULT NULL,
  `tax_id` int(20) NOT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `status` varchar(225) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `credit_note_details`
--

CREATE TABLE `credit_note_details` (
  `id` int(20) NOT NULL,
  `credit_note_id` int(20) NOT NULL,
  `product_id` int(20) NOT NULL,
  `variation_id` int(20) NOT NULL,
  `item_id` int(20) NOT NULL,
  `description` text,
  `qty` int(20) DEFAULT NULL,
  `price` double(11,2) NOT NULL,
  `source` varchar(225) NOT NULL,
  `discount` double(11,2) NOT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `customer_payment`
--

CREATE TABLE `customer_payment` (
  `id` int(20) NOT NULL,
  `customer_id` int(20) NOT NULL,
  `payment_id` int(20) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `families`
--

CREATE TABLE `families` (
  `id` int(20) NOT NULL,
  `name` varchar(225) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `invoices`
--

CREATE TABLE `invoices` (
  `id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL,
  `customer_id` int(20) NOT NULL DEFAULT '0',
  `supplier_id` int(20) NOT NULL DEFAULT '0',
  `order_id` int(20) NOT NULL DEFAULT '0',
  `waybill_id` int(20) NOT NULL DEFAULT '0',
  `type` varchar(225) DEFAULT NULL,
  `price_list_id` varchar(225) DEFAULT NULL,
  `number` int(20) NOT NULL,
  `year` int(20) NOT NULL,
  `items_qty` int(20) NOT NULL DEFAULT '0',
  `subtotal` double(11,2) NOT NULL,
  `payment_id` int(20) NOT NULL,
  `payment_date` datetime DEFAULT NULL,
  `payment_action` varchar(225) DEFAULT NULL,
  `payment_amount` double(11,2) DEFAULT NULL,
  `tax_id` int(20) NOT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `status` varchar(225) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `invoice_details`
--

CREATE TABLE `invoice_details` (
  `id` int(20) NOT NULL,
  `invoice_id` int(20) NOT NULL,
  `product_id` int(20) NOT NULL,
  `variation_id` int(20) NOT NULL,
  `item_id` int(20) NOT NULL,
  `description` text,
  `qty` int(20) DEFAULT NULL,
  `price` double(11,2) NOT NULL,
  `source` varchar(225) NOT NULL,
  `discount` double(11,2) NOT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `invoice_instances`
--

CREATE TABLE `invoice_instances` (
  `id` int(20) NOT NULL,
  `invoice_id` int(20) DEFAULT NULL,
  `invoice_type` int(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `items`
--

CREATE TABLE `items` (
  `id` int(20) NOT NULL,
  `barcode` varchar(225) DEFAULT NULL,
  `product_id` int(20) NOT NULL,
  `variation_id` int(20) NOT NULL,
  `size_id` varchar(20) NOT NULL,
  `active` int(20) DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `item_links`
--

CREATE TABLE `item_links` (
  `id` int(20) NOT NULL,
  `item_id_1` int(20) NOT NULL,
  `item_id_2` int(20) NOT NULL,
  `ratio` varchar(225) NOT NULL DEFAULT '1:1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `item_prices`
--

CREATE TABLE `item_prices` (
  `id` int(20) NOT NULL,
  `item_id` int(20) NOT NULL,
  `price_list_id` varchar(20) NOT NULL,
  `price` double(11,2) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `logs`
--

CREATE TABLE `logs` (
  `id` int(20) NOT NULL,
  `product_id` int(20) DEFAULT NULL,
  `customer_id` int(20) DEFAULT NULL,
  `order_id` int(20) DEFAULT NULL,
  `user_id` int(20) DEFAULT NULL,
  `action` varchar(225) NOT NULL DEFAULT 'U',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `options`
--

CREATE TABLE `options` (
  `id` int(20) NOT NULL,
  `name` varchar(225) NOT NULL,
  `value` varchar(225) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `orders`
--

CREATE TABLE `orders` (
  `id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL,
  `customer_id` int(20) NOT NULL,
  `season_id` int(20) NOT NULL,
  `price_list_id` varchar(225) NOT NULL,
  `season_delivery_id` int(20) NOT NULL,
  `customer_delivery_id` int(20) NOT NULL,
  `products_qty` int(20) NOT NULL,
  `items_qty` int(20) NOT NULL,
  `subtotal` double(11,2) DEFAULT NULL,
  `payment_id` int(20) NOT NULL,
  `payment_action` varchar(225) DEFAULT NULL,
  `payment_amount` double(11,2) DEFAULT NULL,
  `type` varchar(20) DEFAULT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `status` varchar(225) DEFAULT 'confirmed',
  `products_array` varchar(225) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `order_details`
--

CREATE TABLE `order_details` (
  `id` int(20) NOT NULL,
  `order_id` int(20) NOT NULL,
  `product_id` int(20) NOT NULL,
  `variation_id` int(20) NOT NULL,
  `variation_constraint` int(20) DEFAULT NULL,
  `item_id` int(20) NOT NULL,
  `description` text,
  `qty` int(20) DEFAULT NULL,
  `price` double(11,2) NOT NULL,
  `source` varchar(225) NOT NULL DEFAULT 'active_season',
  `discount` double(11,2) DEFAULT '0.00',
  `total` double(11,2) NOT NULL,
  `note` text,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `payments`
--

CREATE TABLE `payments` (
  `id` int(20) NOT NULL,
  `slug` varchar(225) NOT NULL,
  `name` varchar(225) NOT NULL,
  `description` text,
  `action` varchar(225) NOT NULL,
  `amount` double(11,2) NOT NULL DEFAULT '0.00',
  `active` int(20) NOT NULL DEFAULT '1',
  `terms` varchar(225) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `permission_role`
--

CREATE TABLE `permission_role` (
  `permission_id` int(20) NOT NULL,
  `role_id` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `price_lists`
--

CREATE TABLE `price_lists` (
  `id` varchar(225) NOT NULL,
  `name` varchar(225) NOT NULL,
  `active` int(20) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `prodmodels`
--

CREATE TABLE `prodmodels` (
  `id` int(20) NOT NULL,
  `slug` varchar(225) DEFAULT NULL,
  `name` varchar(225) NOT NULL,
  `description` text,
  `picture` varchar(225) DEFAULT NULL,
  `type_id` int(20) NOT NULL,
  `active` int(20) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `products`
--

CREATE TABLE `products` (
  `id` int(20) NOT NULL,
  `prodmodel_id` int(20) NOT NULL,
  `season_id` int(20) NOT NULL,
  `family_id` int(20) NOT NULL,
  `type_id` int(20) NOT NULL,
  `sku` varchar(225) DEFAULT NULL,
  `name` varchar(225) NOT NULL,
  `description` text,
  `pictures` varchar(225) NOT NULL DEFAULT 'a:1:{i:0;s:11:"default.jpg";}',
  `has_variations` int(20) NOT NULL DEFAULT '1',
  `active` int(20) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `proformas`
--

CREATE TABLE `proformas` (
  `id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL,
  `customer_id` int(20) NOT NULL DEFAULT '0',
  `supplier_id` int(20) NOT NULL DEFAULT '0',
  `order_id` int(20) NOT NULL DEFAULT '0',
  `waybill_id` int(20) NOT NULL DEFAULT '0',
  `type` varchar(225) DEFAULT NULL,
  `price_list_id` varchar(225) DEFAULT NULL,
  `number` int(20) NOT NULL,
  `year` int(20) NOT NULL,
  `items_qty` int(20) NOT NULL DEFAULT '0',
  `subtotal` double(11,2) NOT NULL,
  `payment_id` int(20) NOT NULL,
  `payment_date` datetime DEFAULT NULL,
  `payment_action` varchar(225) DEFAULT NULL,
  `payment_amount` double(11,2) DEFAULT NULL,
  `tax_id` int(20) NOT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `status` varchar(225) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `proforma_details`
--

CREATE TABLE `proforma_details` (
  `id` int(20) NOT NULL,
  `proforma_id` int(20) NOT NULL,
  `product_id` int(20) NOT NULL,
  `variation_id` int(20) NOT NULL,
  `item_id` int(20) NOT NULL,
  `description` text,
  `qty` int(20) DEFAULT NULL,
  `price` double(11,2) NOT NULL,
  `source` varchar(225) NOT NULL,
  `discount` double(11,2) NOT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `role_user`
--

CREATE TABLE `role_user` (
  `id` int(20) NOT NULL,
  `role_id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `seasons`
--

CREATE TABLE `seasons` (
  `id` int(20) NOT NULL,
  `slug` varchar(225) DEFAULT NULL,
  `name` varchar(225) NOT NULL,
  `description` text,
  `accepts_orders_creation` int(20) NOT NULL DEFAULT '0',
  `accepts_orders_modification` int(20) NOT NULL DEFAULT '0',
  `active` int(20) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `season_deliveries`
--

CREATE TABLE `season_deliveries` (
  `id` int(20) NOT NULL,
  `slug` varchar(225) DEFAULT NULL,
  `name` varchar(225) NOT NULL,
  `season_id` int(20) NOT NULL,
  `date` varchar(225) DEFAULT NULL,
  `active` int(20) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `sizes`
--

CREATE TABLE `sizes` (
  `id` varchar(225) NOT NULL,
  `name` varchar(225) NOT NULL,
  `family_id` int(20) NOT NULL,
  `types` varchar(225) DEFAULT NULL,
  `active` int(20) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `stocks`
--

CREATE TABLE `stocks` (
  `id` int(20) NOT NULL,
  `product_id` int(20) NOT NULL,
  `variation_id` int(20) NOT NULL,
  `item_id` int(20) NOT NULL,
  `qty` int(20) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `stock_prices`
--

CREATE TABLE `stock_prices` (
  `id` int(20) NOT NULL,
  `stock_id` int(20) NOT NULL,
  `price_list_id` varchar(20) NOT NULL,
  `price` double(11,2) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `taxes`
--

CREATE TABLE `taxes` (
  `id` int(20) NOT NULL,
  `name` varchar(225) NOT NULL,
  `percentage` double(11,2) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `terms`
--

CREATE TABLE `terms` (
  `id` varchar(225) NOT NULL,
  `attribute_id` varchar(225) NOT NULL,
  `name` varchar(225) NOT NULL,
  `color` varchar(225) DEFAULT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL,
  `active` int(20) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `term_variation`
--

CREATE TABLE `term_variation` (
  `variation_id` int(20) NOT NULL,
  `term_id` varchar(225) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `user_percentage`
--

CREATE TABLE `user_percentage` (
  `id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL,
  `percentage` double(11,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `user_permission`
--

CREATE TABLE `user_permission` (
  `user_id` int(20) NOT NULL,
  `permission_id` int(20) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `user_price_list`
--

CREATE TABLE `user_price_list` (
  `id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL,
  `price_list_id` varchar(20) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `user_type`
--

CREATE TABLE `user_type` (
  `id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL,
  `type_id` int(20) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `variations`
--

CREATE TABLE `variations` (
  `id` int(20) NOT NULL,
  `product_id` int(20) NOT NULL,
  `constraints` varchar(225) DEFAULT NULL,
  `sku` varchar(225) NOT NULL,
  `description` text,
  `pictures` varchar(225) NOT NULL DEFAULT 'a:1:{i:0;s:11:"default.jpg";}',
  `active` int(20) NOT NULL DEFAULT '1',
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `variation_annulments`
--

CREATE TABLE `variation_annulments` (
  `id` int(20) NOT NULL,
  `variation_id` int(20) NOT NULL,
  `variation_constraint` int(20) DEFAULT NULL,
  `type` varchar(225) NOT NULL,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `waybills`
--

CREATE TABLE `waybills` (
  `id` int(20) NOT NULL,
  `user_id` int(20) NOT NULL,
  `customer_id` int(20) NOT NULL DEFAULT '0',
  `supplier_id` int(20) NOT NULL DEFAULT '0',
  `order_id` int(20) NOT NULL DEFAULT '0',
  `price_list_id` int(20) NOT NULL DEFAULT '0',
  `number` int(20) NOT NULL,
  `year` int(20) NOT NULL,
  `charge` varchar(225) DEFAULT NULL,
  `carrier_code` varchar(225) DEFAULT NULL,
  `packages` int(20) NOT NULL DEFAULT '1',
  `items_qty` int(20) NOT NULL DEFAULT '0',
  `weight` int(20) NOT NULL DEFAULT '0',
  `delivery_date` datetime DEFAULT NULL,
  `note` text,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- --------------------------------------------------------

--
-- Struttura della tabella `waybill_details`
--

CREATE TABLE `waybill_details` (
  `id` int(20) NOT NULL,
  `waybill_id` int(20) NOT NULL,
  `product_id` int(20) NOT NULL,
  `variation_id` int(20) NOT NULL,
  `item_id` int(20) NOT NULL,
  `description` text,
  `qty` int(20) DEFAULT NULL,
  `price` double(11,2) NOT NULL,
  `source` varchar(225) NOT NULL,
  `discount` double(11,2) NOT NULL,
  `total` double(11,2) NOT NULL,
  `note` text,
  `created_at` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `updated_at` datetime DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Indici per le tabelle scaricate
--

--
-- Indici per le tabelle `accomp_invoices`
--
ALTER TABLE `accomp_invoices`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `accomp_invoice_details`
--
ALTER TABLE `accomp_invoice_details`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `attributes`
--
ALTER TABLE `attributes`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `credit_notes`
--
ALTER TABLE `credit_notes`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `credit_note_details`
--
ALTER TABLE `credit_note_details`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `customer_payment`
--
ALTER TABLE `customer_payment`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `families`
--
ALTER TABLE `families`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `invoices`
--
ALTER TABLE `invoices`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `invoice_details`
--
ALTER TABLE `invoice_details`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `invoice_instances`
--
ALTER TABLE `invoice_instances`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `items`
--
ALTER TABLE `items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `size_id` (`size_id`),
  ADD KEY `item_product1` (`product_id`),
  ADD KEY `item_variation1` (`variation_id`);

--
-- Indici per le tabelle `item_links`
--
ALTER TABLE `item_links`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `item_prices`
--
ALTER TABLE `item_prices`
  ADD PRIMARY KEY (`id`),
  ADD KEY `item_id` (`item_id`),
  ADD KEY `price_list_id` (`price_list_id`),
  ADD KEY `item_id_2` (`item_id`),
  ADD KEY `price_list_id_2` (`price_list_id`),
  ADD KEY `item_id_3` (`item_id`),
  ADD KEY `price_list_id_3` (`price_list_id`),
  ADD KEY `item_id_4` (`item_id`),
  ADD KEY `price_list_id_4` (`price_list_id`);

--
-- Indici per le tabelle `logs`
--
ALTER TABLE `logs`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `options`
--
ALTER TABLE `options`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `orders`
--
ALTER TABLE `orders`
  ADD PRIMARY KEY (`id`),
  ADD KEY `season_id` (`season_id`),
  ADD KEY `customer_id` (`customer_id`),
  ADD KEY `user_id` (`user_id`),
  ADD KEY `price_list_id` (`price_list_id`),
  ADD KEY `season_delivery_id` (`season_delivery_id`),
  ADD KEY `customer_delivery_id` (`customer_delivery_id`),
  ADD KEY `payment_id` (`payment_id`);

--
-- Indici per le tabelle `order_details`
--
ALTER TABLE `order_details`
  ADD PRIMARY KEY (`id`),
  ADD KEY `order_id` (`order_id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `variation_id` (`variation_id`),
  ADD KEY `item_id` (`item_id`),
  ADD KEY `order_id_2` (`order_id`),
  ADD KEY `product_id_2` (`product_id`),
  ADD KEY `variation_id_2` (`variation_id`),
  ADD KEY `item_id_2` (`item_id`),
  ADD KEY `order_id_3` (`order_id`),
  ADD KEY `product_id_3` (`product_id`),
  ADD KEY `variation_id_3` (`variation_id`),
  ADD KEY `item_id_3` (`item_id`),
  ADD KEY `order_id_4` (`order_id`),
  ADD KEY `product_id_4` (`product_id`),
  ADD KEY `variation_id_4` (`variation_id`),
  ADD KEY `item_id_4` (`item_id`);

--
-- Indici per le tabelle `payments`
--
ALTER TABLE `payments`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `price_lists`
--
ALTER TABLE `price_lists`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `prodmodels`
--
ALTER TABLE `prodmodels`
  ADD PRIMARY KEY (`id`),
  ADD KEY `type_id` (`type_id`),
  ADD KEY `type_id_2` (`type_id`),
  ADD KEY `type_id_3` (`type_id`),
  ADD KEY `type_id_4` (`type_id`),
  ADD KEY `type_id_5` (`type_id`),
  ADD KEY `type_id_6` (`type_id`);

--
-- Indici per le tabelle `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`),
  ADD KEY `prodmodel_id` (`prodmodel_id`),
  ADD KEY `season_id` (`season_id`),
  ADD KEY `family_id` (`family_id`),
  ADD KEY `type_id` (`type_id`),
  ADD KEY `prodmodel_id_2` (`prodmodel_id`),
  ADD KEY `season_id_2` (`season_id`),
  ADD KEY `family_id_2` (`family_id`),
  ADD KEY `type_id_2` (`type_id`),
  ADD KEY `prodmodel_id_3` (`prodmodel_id`),
  ADD KEY `season_id_3` (`season_id`),
  ADD KEY `family_id_3` (`family_id`),
  ADD KEY `type_id_3` (`type_id`),
  ADD KEY `prodmodel_id_4` (`prodmodel_id`),
  ADD KEY `season_id_4` (`season_id`),
  ADD KEY `family_id_4` (`family_id`),
  ADD KEY `type_id_4` (`type_id`),
  ADD KEY `prodmodel_id_5` (`prodmodel_id`),
  ADD KEY `season_id_5` (`season_id`),
  ADD KEY `family_id_5` (`family_id`),
  ADD KEY `type_id_5` (`type_id`),
  ADD KEY `prodmodel_id_6` (`prodmodel_id`),
  ADD KEY `season_id_6` (`season_id`),
  ADD KEY `family_id_6` (`family_id`),
  ADD KEY `type_id_6` (`type_id`);

--
-- Indici per le tabelle `proformas`
--
ALTER TABLE `proformas`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `proforma_details`
--
ALTER TABLE `proforma_details`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `role_user`
--
ALTER TABLE `role_user`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `seasons`
--
ALTER TABLE `seasons`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `season_deliveries`
--
ALTER TABLE `season_deliveries`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `sizes`
--
ALTER TABLE `sizes`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `stocks`
--
ALTER TABLE `stocks`
  ADD PRIMARY KEY (`id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `variation_id` (`variation_id`),
  ADD KEY `item_id` (`item_id`),
  ADD KEY `product_id_2` (`product_id`),
  ADD KEY `variation_id_2` (`variation_id`),
  ADD KEY `item_id_2` (`item_id`),
  ADD KEY `product_id_3` (`product_id`),
  ADD KEY `variation_id_3` (`variation_id`),
  ADD KEY `item_id_3` (`item_id`);

--
-- Indici per le tabelle `stock_prices`
--
ALTER TABLE `stock_prices`
  ADD PRIMARY KEY (`id`),
  ADD KEY `stock_id` (`stock_id`),
  ADD KEY `price_list_id` (`price_list_id`),
  ADD KEY `stock_id_2` (`stock_id`),
  ADD KEY `price_list_id_2` (`price_list_id`),
  ADD KEY `stock_id_3` (`stock_id`),
  ADD KEY `price_list_id_3` (`price_list_id`);

--
-- Indici per le tabelle `taxes`
--
ALTER TABLE `taxes`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `terms`
--
ALTER TABLE `terms`
  ADD PRIMARY KEY (`id`),
  ADD KEY `attribute_id` (`attribute_id`),
  ADD KEY `attribute_id_2` (`attribute_id`),
  ADD KEY `attribute_id_3` (`attribute_id`);

--
-- Indici per le tabelle `user_percentage`
--
ALTER TABLE `user_percentage`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `user_price_list`
--
ALTER TABLE `user_price_list`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `user_type`
--
ALTER TABLE `user_type`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `variations`
--
ALTER TABLE `variations`
  ADD PRIMARY KEY (`id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `product_id_2` (`product_id`),
  ADD KEY `product_id_3` (`product_id`),
  ADD KEY `product_id_4` (`product_id`),
  ADD KEY `product_id_5` (`product_id`),
  ADD KEY `product_id_6` (`product_id`);

--
-- Indici per le tabelle `variation_annulments`
--
ALTER TABLE `variation_annulments`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `waybills`
--
ALTER TABLE `waybills`
  ADD PRIMARY KEY (`id`);

--
-- Indici per le tabelle `waybill_details`
--
ALTER TABLE `waybill_details`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT per le tabelle scaricate
--

--
-- AUTO_INCREMENT per la tabella `accomp_invoices`
--
ALTER TABLE `accomp_invoices`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `accomp_invoice_details`
--
ALTER TABLE `accomp_invoice_details`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `credit_notes`
--
ALTER TABLE `credit_notes`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `credit_note_details`
--
ALTER TABLE `credit_note_details`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `customer_payment`
--
ALTER TABLE `customer_payment`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=101;
--
-- AUTO_INCREMENT per la tabella `families`
--
ALTER TABLE `families`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;
--
-- AUTO_INCREMENT per la tabella `invoices`
--
ALTER TABLE `invoices`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `invoice_details`
--
ALTER TABLE `invoice_details`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `invoice_instances`
--
ALTER TABLE `invoice_instances`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `items`
--
ALTER TABLE `items`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10994;
--
-- AUTO_INCREMENT per la tabella `item_links`
--
ALTER TABLE `item_links`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `item_prices`
--
ALTER TABLE `item_prices`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=66613;
--
-- AUTO_INCREMENT per la tabella `logs`
--
ALTER TABLE `logs`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1640;
--
-- AUTO_INCREMENT per la tabella `options`
--
ALTER TABLE `options`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=13;
--
-- AUTO_INCREMENT per la tabella `orders`
--
ALTER TABLE `orders`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=501;
--
-- AUTO_INCREMENT per la tabella `order_details`
--
ALTER TABLE `order_details`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=20474;
--
-- AUTO_INCREMENT per la tabella `payments`
--
ALTER TABLE `payments`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=32;
--
-- AUTO_INCREMENT per la tabella `prodmodels`
--
ALTER TABLE `prodmodels`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=34;
--
-- AUTO_INCREMENT per la tabella `products`
--
ALTER TABLE `products`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=317;
--
-- AUTO_INCREMENT per la tabella `proformas`
--
ALTER TABLE `proformas`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `proforma_details`
--
ALTER TABLE `proforma_details`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `role_user`
--
ALTER TABLE `role_user`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=57;
--
-- AUTO_INCREMENT per la tabella `seasons`
--
ALTER TABLE `seasons`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5;
--
-- AUTO_INCREMENT per la tabella `season_deliveries`
--
ALTER TABLE `season_deliveries`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=22;
--
-- AUTO_INCREMENT per la tabella `stocks`
--
ALTER TABLE `stocks`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1011;
--
-- AUTO_INCREMENT per la tabella `stock_prices`
--
ALTER TABLE `stock_prices`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `taxes`
--
ALTER TABLE `taxes`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `user_price_list`
--
ALTER TABLE `user_price_list`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=45;
--
-- AUTO_INCREMENT per la tabella `user_type`
--
ALTER TABLE `user_type`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=85;
--
-- AUTO_INCREMENT per la tabella `variations`
--
ALTER TABLE `variations`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1233;
--
-- AUTO_INCREMENT per la tabella `variation_annulments`
--
ALTER TABLE `variation_annulments`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `waybills`
--
ALTER TABLE `waybills`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- AUTO_INCREMENT per la tabella `waybill_details`
--
ALTER TABLE `waybill_details`
  MODIFY `id` int(20) NOT NULL AUTO_INCREMENT;
--
-- Limiti per le tabelle scaricate
--

--
-- Limiti per la tabella `items`
--
ALTER TABLE `items`
  ADD CONSTRAINT `item_product1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `item_size1` FOREIGN KEY (`size_id`) REFERENCES `sizes` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `item_variation1` FOREIGN KEY (`variation_id`) REFERENCES `variations` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

--
-- Limiti per la tabella `item_prices`
--
ALTER TABLE `item_prices`
  ADD CONSTRAINT `item_prices_ibfk_1` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `item_prices_ibfk_2` FOREIGN KEY (`price_list_id`) REFERENCES `price_lists` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `item_prices_ibfk_3` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `item_prices_ibfk_4` FOREIGN KEY (`price_list_id`) REFERENCES `price_lists` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `item_prices_ibfk_5` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `item_prices_ibfk_6` FOREIGN KEY (`price_list_id`) REFERENCES `price_lists` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

--
-- Limiti per la tabella `orders`
--
ALTER TABLE `orders`
  ADD CONSTRAINT `orders_ibfk_1` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `orders_ibfk_2` FOREIGN KEY (`price_list_id`) REFERENCES `price_lists` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `orders_ibfk_3` FOREIGN KEY (`season_delivery_id`) REFERENCES `season_deliveries` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `orders_ibfk_4` FOREIGN KEY (`payment_id`) REFERENCES `payments` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

--
-- Limiti per la tabella `order_details`
--
ALTER TABLE `order_details`
  ADD CONSTRAINT `order_details_ibfk_1` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_10` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_11` FOREIGN KEY (`variation_id`) REFERENCES `variations` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_12` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_13` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_14` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_15` FOREIGN KEY (`variation_id`) REFERENCES `variations` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_16` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_3` FOREIGN KEY (`variation_id`) REFERENCES `variations` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_4` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_5` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_6` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_7` FOREIGN KEY (`variation_id`) REFERENCES `variations` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_8` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `order_details_ibfk_9` FOREIGN KEY (`order_id`) REFERENCES `orders` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

--
-- Limiti per la tabella `products`
--
ALTER TABLE `products`
  ADD CONSTRAINT `products_ibfk_1` FOREIGN KEY (`prodmodel_id`) REFERENCES `prodmodels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_10` FOREIGN KEY (`prodmodel_id`) REFERENCES `prodmodels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_11` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_12` FOREIGN KEY (`family_id`) REFERENCES `families` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_13` FOREIGN KEY (`prodmodel_id`) REFERENCES `prodmodels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_14` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_15` FOREIGN KEY (`family_id`) REFERENCES `families` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_16` FOREIGN KEY (`prodmodel_id`) REFERENCES `prodmodels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_17` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_18` FOREIGN KEY (`family_id`) REFERENCES `families` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_2` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_3` FOREIGN KEY (`family_id`) REFERENCES `families` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_4` FOREIGN KEY (`prodmodel_id`) REFERENCES `prodmodels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_5` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_6` FOREIGN KEY (`family_id`) REFERENCES `families` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_7` FOREIGN KEY (`prodmodel_id`) REFERENCES `prodmodels` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_8` FOREIGN KEY (`season_id`) REFERENCES `seasons` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `products_ibfk_9` FOREIGN KEY (`family_id`) REFERENCES `families` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

--
-- Limiti per la tabella `stocks`
--
ALTER TABLE `stocks`
  ADD CONSTRAINT `stocks_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stocks_ibfk_2` FOREIGN KEY (`variation_id`) REFERENCES `variations` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stocks_ibfk_3` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stocks_ibfk_4` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stocks_ibfk_5` FOREIGN KEY (`variation_id`) REFERENCES `variations` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stocks_ibfk_6` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stocks_ibfk_7` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stocks_ibfk_8` FOREIGN KEY (`variation_id`) REFERENCES `variations` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stocks_ibfk_9` FOREIGN KEY (`item_id`) REFERENCES `items` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

--
-- Limiti per la tabella `stock_prices`
--
ALTER TABLE `stock_prices`
  ADD CONSTRAINT `stock_prices_ibfk_1` FOREIGN KEY (`stock_id`) REFERENCES `stocks` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stock_prices_ibfk_2` FOREIGN KEY (`price_list_id`) REFERENCES `price_lists` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stock_prices_ibfk_3` FOREIGN KEY (`stock_id`) REFERENCES `stocks` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stock_prices_ibfk_4` FOREIGN KEY (`price_list_id`) REFERENCES `price_lists` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stock_prices_ibfk_5` FOREIGN KEY (`stock_id`) REFERENCES `stocks` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `stock_prices_ibfk_6` FOREIGN KEY (`price_list_id`) REFERENCES `price_lists` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

--
-- Limiti per la tabella `terms`
--
ALTER TABLE `terms`
  ADD CONSTRAINT `terms_ibfk_1` FOREIGN KEY (`attribute_id`) REFERENCES `attributes` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `terms_ibfk_2` FOREIGN KEY (`attribute_id`) REFERENCES `attributes` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `terms_ibfk_3` FOREIGN KEY (`attribute_id`) REFERENCES `attributes` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

--
-- Limiti per la tabella `variations`
--
ALTER TABLE `variations`
  ADD CONSTRAINT `variations_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `variations_ibfk_2` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `variations_ibfk_3` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  ADD CONSTRAINT `variations_ibfk_4` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
