-- phpMyAdmin SQL Dump
-- version 3.4.5
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Erstellungszeit: 15. Jul 2022 um 17:41
-- Server Version: 5.5.16
-- PHP-Version: 5.3.8

SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


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

--
-- Datenbank: `kasse`
--

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

--
-- Tabellenstruktur für Tabelle `invoice_details`
--

DROP TABLE IF EXISTS `invoice_details`;
CREATE TABLE IF NOT EXISTS `invoice_details` (
  `project_id` int(11) NOT NULL DEFAULT '1',
  `invoice_number` int(11) NOT NULL,
  `line_number` int(11) NOT NULL,
  `item` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  `seller_id` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
  `item_id` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
  `price` decimal(6,2) NOT NULL,
  `cancelled` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`project_id`,`invoice_number`,`line_number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Tabellenstruktur für Tabelle `invoice_header`
--

DROP TABLE IF EXISTS `invoice_header`;
CREATE TABLE IF NOT EXISTS `invoice_header` (
  `invoice_number` int(11) NOT NULL AUTO_INCREMENT,
  `project_id` int(11) NOT NULL,
  `pos_id` int(11) NOT NULL,
  `invoice_date` datetime NOT NULL,
  `cashier` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  `line_count` int(11) NOT NULL,
  `total` decimal(6,2) NOT NULL,
  `paid` decimal(6,2) NOT NULL,
  `checkout` tinyint(4) NOT NULL DEFAULT '0',
  `printed` tinyint(4) NOT NULL DEFAULT '0',
  `mdate` datetime NOT NULL,
  `cdate` datetime NOT NULL,
  PRIMARY KEY (`invoice_number`)
) ENGINE=InnoDB  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=2477 ;

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

--
-- Tabellenstruktur für Tabelle `items`
--

DROP TABLE IF EXISTS `items`;
CREATE TABLE IF NOT EXISTS `items` (
  `project_id` int(11) NOT NULL,
  `seller_id` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
  `item_id` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
  `description` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `price` decimal(6,2) NOT NULL,
  `mdate` datetime NOT NULL,
  `cdate` datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Tabellenstruktur für Tabelle `pos`
--

DROP TABLE IF EXISTS `pos`;
CREATE TABLE IF NOT EXISTS `pos` (
  `pos_id` int(11) NOT NULL,
  `token` int(11) NOT NULL,
  `active` tinyint(4) NOT NULL,
  `disabled` tinyint(4) NOT NULL,
  `cashier_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `mdate` datetime NOT NULL,
  `cdate` datetime NOT NULL,
  PRIMARY KEY (`pos_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Tabellenstruktur für Tabelle `projects`
--

DROP TABLE IF EXISTS `projects`;
CREATE TABLE IF NOT EXISTS `projects` (
  `project_id` int(11) NOT NULL AUTO_INCREMENT,
  `event_date` date NOT NULL,
  `event_location` varchar(255) NOT NULL,
  `print_header` text NOT NULL,
  `print_footer` text NOT NULL,
  `active` tinyint(4) NOT NULL DEFAULT '0',
  `mdate` datetime NOT NULL,
  `cdate` datetime NOT NULL,
  PRIMARY KEY (`project_id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

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

--
-- Tabellenstruktur für Tabelle `sellers`
--

DROP TABLE IF EXISTS `sellers`;
CREATE TABLE IF NOT EXISTS `sellers` (
  `project_id` int(11) NOT NULL DEFAULT '1',
  `seller_id` varchar(5) COLLATE utf8_unicode_ci NOT NULL,
  `name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `first_name` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
  `address` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `zip_code` varchar(10) COLLATE utf8_unicode_ci NOT NULL,
  `place` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `mail` varchar(100) COLLATE utf8_unicode_ci NOT NULL,
  `phone` varchar(30) COLLATE utf8_unicode_ci NOT NULL,
  `mdate` datetime NOT NULL,
  `cdate` datetime NOT NULL,
  PRIMARY KEY (`project_id`,`seller_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;

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

--
-- Stellvertreter-Struktur des Views `view_invoices`
--
DROP VIEW IF EXISTS `view_invoices`;
CREATE TABLE IF NOT EXISTS `view_invoices` (
`invoice_number` int(11)
,`project_id` int(11)
,`pos_id` int(11)
,`invoice_date` datetime
,`cashier` varchar(30)
,`line_count` bigint(21)
,`total` decimal(28,2)
,`line_number` int(11)
,`item` varchar(10)
,`seller_id` varchar(5)
,`item_id` varchar(5)
,`price` decimal(6,2)
);
-- --------------------------------------------------------

--
-- Stellvertreter-Struktur des Views `view_invoice_header`
--
DROP VIEW IF EXISTS `view_invoice_header`;
CREATE TABLE IF NOT EXISTS `view_invoice_header` (
`invoice_number` int(11)
,`project_id` int(11)
,`pos_id` int(11)
,`invoice_date` datetime
,`cashier` varchar(30)
,`paid` decimal(6,2)
,`checkout` tinyint(4)
,`printed` tinyint(4)
,`line_count` bigint(21)
,`total` decimal(28,2)
,`mdate` datetime
,`cdate` datetime
);
-- --------------------------------------------------------

--
-- Stellvertreter-Struktur des Views `view_totals`
--
DROP VIEW IF EXISTS `view_totals`;
CREATE TABLE IF NOT EXISTS `view_totals` (
`invoice_number` int(11)
,`line_count` bigint(21)
,`total` decimal(28,2)
);
-- --------------------------------------------------------

--
-- Struktur des Views `view_invoices`
--
DROP TABLE IF EXISTS `view_invoices`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_invoices` AS select `a`.`invoice_number` AS `invoice_number`,`a`.`project_id` AS `project_id`,`a`.`pos_id` AS `pos_id`,`a`.`invoice_date` AS `invoice_date`,`a`.`cashier` AS `cashier`,`a`.`line_count` AS `line_count`,`a`.`total` AS `total`,`b`.`line_number` AS `line_number`,`b`.`item` AS `item`,`b`.`seller_id` AS `seller_id`,`b`.`item_id` AS `item_id`,`b`.`price` AS `price` from (`view_invoice_header` `a` left join `invoice_details` `b` on((`a`.`invoice_number` = `b`.`invoice_number`)));

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

--
-- Struktur des Views `view_invoice_header`
--
DROP TABLE IF EXISTS `view_invoice_header`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_invoice_header` AS select `a`.`invoice_number` AS `invoice_number`,`a`.`project_id` AS `project_id`,`a`.`pos_id` AS `pos_id`,`a`.`invoice_date` AS `invoice_date`,`a`.`cashier` AS `cashier`,`a`.`paid` AS `paid`,`a`.`checkout` AS `checkout`,`a`.`printed` AS `printed`,`b`.`line_count` AS `line_count`,`b`.`total` AS `total`,`a`.`mdate` AS `mdate`,`a`.`cdate` AS `cdate` from (`invoice_header` `a` left join `view_totals` `b` on((`a`.`invoice_number` = `b`.`invoice_number`)));

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

--
-- Struktur des Views `view_totals`
--
DROP TABLE IF EXISTS `view_totals`;

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `view_totals` AS select `a`.`invoice_number` AS `invoice_number`,count(`a`.`line_number`) AS `line_count`,sum(`a`.`price`) AS `total` from `invoice_details` `a` group by `a`.`invoice_number`;

/*!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 */;