--
-- Host: localhost    Database: pcscale
-- ------------------------------------------------------


--
-- Table structure for table `advertising`
--

CREATE TABLE `advertising` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Scope` smallint(6) DEFAULT '0',
  `Number` int(11) DEFAULT '0',
  `Timeout` int(11) DEFAULT '0',
  `ShowTime` int(11) DEFAULT '10',
  `FadeTime` int(11) DEFAULT '0',
  `FadeType` int(11) DEFAULT '0',
  `ZeroOnly` tinyint(1) DEFAULT '1',
  `ForcedImage` tinyint(1) DEFAULT '0',
  `Publi0` smallint(6) DEFAULT '0',
  `Publi1` smallint(6) DEFAULT '0',
  `PlayList0` varchar(32) NOT NULL DEFAULT '',
  `PlayList1` varchar(32) NOT NULL DEFAULT '',
  `FullScreen0` tinyint(1) DEFAULT '0',
  `FullScreen1` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Scope` (`Scope`,`Number`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `allergenicons`
--

CREATE TABLE `allergenicons` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Allergen` varchar(16) NOT NULL,
  `Description` varchar(127) NOT NULL DEFAULT '',
  `Icon` varchar(127) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Allergen` (`Allergen`)
) ENGINE=InnoDB AUTO_INCREMENT=127 DEFAULT CHARSET=utf8;

--
-- Table structure for table `barcodeean13`
--

CREATE TABLE `barcodeean13` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `NumberType` char(1) DEFAULT NULL,
  `Number` smallint(6) DEFAULT '0',
  `NetworkSales` char(12) NOT NULL,
  `NetworkParked` char(12) NOT NULL DEFAULT '',
  `NetworkLineSLB` char(12) NOT NULL,
  `NetworkTotalSLB` char(12) NOT NULL,
  `NetworkSS` char(12) NOT NULL,
  `NetworkPacket1` char(12) NOT NULL,
  `NetworkPacket2` char(12) NOT NULL,
  `LocalSales` char(12) NOT NULL,
  `LocalLineSLB` char(12) NOT NULL,
  `LocalTotalSLB` char(12) NOT NULL,
  `LocalSS` char(12) NOT NULL,
  `LocalPacket1` char(12) NOT NULL,
  `LocalPacket2` char(12) NOT NULL,
  `LocalTotal` char(12) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `NumberType` (`NumberType`,`Number`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `bovine`
--

CREATE TABLE `bovine` (
  `NumCard` smallint(3) NOT NULL,
  `EarTag` varchar(30) NOT NULL,
  `Weight` decimal(6,3) NOT NULL DEFAULT '0.000',
  `BirthLand` smallint(6) DEFAULT NULL,
  `BirthDate` date DEFAULT NULL,
  `BreedingLand` smallint(6) DEFAULT NULL,
  `SlaughterLand` smallint(6) DEFAULT NULL,
  `SlaughterReg` varchar(30) DEFAULT NULL,
  `SlaughterDate` date DEFAULT NULL,
  `ButcherLand` smallint(6) DEFAULT NULL,
  `ButcherReg` varchar(30) DEFAULT NULL,
  `Lot` varchar(20) DEFAULT NULL,
  PRIMARY KEY (`NumCard`),
  KEY `EarTag` (`EarTag`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `card`
--

CREATE TABLE `card` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(32) NOT NULL DEFAULT '',
  `Enabled` tinyint(1) NOT NULL DEFAULT '0',
  `URL` varchar(128) NOT NULL DEFAULT '',
  `User` varchar(32) NOT NULL DEFAULT '',
  `Password` varchar(128) NOT NULL DEFAULT '',
  `WaitPaid` char(1) NOT NULL DEFAULT '0',
  `Status` char(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `cardreports`
--

CREATE TABLE `cardreports` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `UUID` varchar(48) NOT NULL,
  `DatTim` datetime NOT NULL,
  `Terminal` varchar(32) NOT NULL DEFAULT '',
  `Type` char(1) NOT NULL DEFAULT '-',
  `TextReport` text NOT NULL,
  PRIMARY KEY (`Id`),
  KEY `UUID` (`UUID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `cash`
--

CREATE TABLE `cash` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Scope` smallint(6) DEFAULT '0',
  `Number` int(11) DEFAULT '0',
  `Name` varchar(32) NOT NULL DEFAULT '',
  `IP` int(10) unsigned NOT NULL DEFAULT '0',
  `User` varchar(32) NOT NULL DEFAULT '',
  `Password` varchar(32) NOT NULL DEFAULT '',
  `WaitPaid` char(1) NOT NULL DEFAULT '0',
  `Status` char(1) NOT NULL DEFAULT '0',
  `Oper` int(10) unsigned NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `IP` (`IP`),
  UNIQUE KEY `Scope` (`Scope`,`Number`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `cashdrawer`
--

CREATE TABLE `cashdrawer` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Scale` int(11) NOT NULL DEFAULT '0',
  `Vendor` int(11) NOT NULL DEFAULT '0',
  `DatTim` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `Amount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `CashIn` decimal(10,2) NOT NULL DEFAULT '0.00',
  `CashOut` decimal(10,2) NOT NULL DEFAULT '0.00',
  `CashIP` int(10) unsigned NOT NULL DEFAULT '0',
  `Text` varchar(64) NOT NULL DEFAULT '',
  `CashStatus` char(1) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '-',
  `CashOperId` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `cfgparams`
--

CREATE TABLE `cfgparams` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `ParamKey` varchar(128) NOT NULL DEFAULT '',
  `ParamValue` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `ParamKey` (`ParamKey`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

--
-- Table structure for table `cfgsystem`
--

CREATE TABLE `cfgsystem` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `ParamKey` varchar(128) NOT NULL DEFAULT '',
  `ParamValue` varchar(128) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `ParamKey` (`ParamKey`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

--
-- Table structure for table `clientconfiguration`
--

CREATE TABLE `clientconfiguration` (
  `TypeNumber` int(11) NOT NULL,
  `Name` varchar(20) NOT NULL DEFAULT '',
  `Icon` varchar(16) NOT NULL DEFAULT 'face',
  `InUse` tinyint(1) DEFAULT '0',
  `IPv4` int(10) unsigned NOT NULL DEFAULT '0',
  `Port` smallint(5) unsigned NOT NULL DEFAULT '1900',
  `ConnectTimeout` tinyint(3) unsigned NOT NULL DEFAULT '2',
  `TckSend` tinyint(1) DEFAULT '1',
  `TckWaitShort` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `TckWaitLong` tinyint(3) unsigned NOT NULL DEFAULT '5',
  `TckTimeout` tinyint(3) unsigned NOT NULL DEFAULT '2',
  `CmdRequest` tinyint(1) DEFAULT '1',
  `CmdWaitShort` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `CmdWaitLong` tinyint(3) unsigned NOT NULL DEFAULT '60',
  `CmdTimeout` tinyint(3) unsigned NOT NULL DEFAULT '2',
  `DateRequest` tinyint(1) DEFAULT '1',
  `DateTimeRequest` int(10) unsigned NOT NULL DEFAULT '3600',
  `UseQMatic` tinyint(1) DEFAULT '0',
  `URL` varchar(255) NOT NULL DEFAULT 'http://demo.q-matic.es:9094',
  `UseRemote` tinyint(1) DEFAULT '0',
  `URLRemote` varchar(255) DEFAULT '',
  `Company` int(11) DEFAULT '0',
  `Shop` int(11) DEFAULT '0',
  PRIMARY KEY (`TypeNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `code128`
--

CREATE TABLE `code128` (
  `Counter` int(11) NOT NULL DEFAULT '0',
  `Code1` varchar(32) DEFAULT '',
  `Code2` varchar(32) DEFAULT '',
  `Code3` varchar(32) DEFAULT '',
  `Code4` varchar(32) DEFAULT '',
  `Code5` varchar(32) DEFAULT '',
  `Code6` varchar(32) DEFAULT '',
  `Code7` varchar(32) DEFAULT '',
  `Code8` varchar(32) DEFAULT '',
  `Code9` varchar(32) DEFAULT '',
  `Code10` varchar(32) DEFAULT '',
  PRIMARY KEY (`Counter`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `counterfamilies`
--

CREATE TABLE `counterfamilies` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `CounterCode` int(11) NOT NULL,
  `FamilyIndex` int(11) NOT NULL DEFAULT '1',
  `FamilyCode` int(11) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `idcofam` (`CounterCode`,`FamilyIndex`),
  CONSTRAINT `fkcofam` FOREIGN KEY (`CounterCode`) REFERENCES `counters` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `countergoals`
--

CREATE TABLE `countergoals` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `OnDate` date NOT NULL,
  `Counter` int(11) DEFAULT '0',
  `Amount` decimal(10,2) DEFAULT '0.00',
  `AMCustomers` int(11) DEFAULT '0',
  `PMCustomers` int(11) DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `idx` (`OnDate`,`Counter`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `counters`
--

CREATE TABLE `counters` (
  `Code` int(11) NOT NULL,
  `Name` varchar(64) DEFAULT '',
  `Icon` varchar(127) DEFAULT NULL,
  `MyGroup` int(11) NOT NULL DEFAULT '0',
  `TurnProfile` varchar(3) DEFAULT '',
  `TurnProfileGroup` varchar(3) DEFAULT '',
  `TurnIdentifier` char(1) DEFAULT '',
  `Turn` int(10) unsigned DEFAULT '1',
  `TurnsPending` int(10) unsigned NOT NULL DEFAULT '0',
  `TurnDatTim` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `TurnLast` int(10) unsigned NOT NULL DEFAULT '0',
  `TurnLastTime` time NOT NULL DEFAULT '00:00:00',
  `TurnDelay` int(11) NOT NULL DEFAULT '0',
  `TurnOnTime` tinyint(1) NOT NULL DEFAULT '0',
  `TurnMonitor` tinyint(1) DEFAULT '1',
  `MarkCaptured` tinyint(1) NOT NULL DEFAULT '0' COMMENT 'When close ticket, mark as captured',
  `Description` varchar(127) DEFAULT '',
  `Text1` varchar(255) DEFAULT '',
  `Text2` varchar(255) DEFAULT '',
  `Text3` varchar(255) DEFAULT '',
  `Text4` varchar(255) DEFAULT '',
  `Text5` varchar(255) DEFAULT '',
  `Text6` varchar(255) DEFAULT '',
  `Text7` varchar(255) DEFAULT '',
  `Text8` varchar(255) DEFAULT '',
  `Text9` varchar(255) DEFAULT '',
  `Text10` varchar(255) DEFAULT '',
  PRIMARY KEY (`Code`),
  UNIQUE KEY `Code` (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `countries`
--

CREATE TABLE `countries` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Locale` char(2) NOT NULL DEFAULT '',
  `Code` int(11) NOT NULL DEFAULT '0',
  `Alpha2` char(2) NOT NULL DEFAULT '',
  `Name` varchar(127) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Locale` (`Locale`,`Code`),
  KEY `Name` (`Name`(19))
) ENGINE=InnoDB AUTO_INCREMENT=997 DEFAULT CHARSET=utf8;

--
-- Table structure for table `customers`
--

CREATE TABLE `customers` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `TIN` varchar(16) NOT NULL DEFAULT '',
  `Name` varchar(255) NOT NULL DEFAULT '',
  `Type` char(1) NOT NULL DEFAULT 'C',
  `Address` varchar(255) DEFAULT '',
  `City` varchar(255) DEFAULT '',
  `Postalcode` varchar(80) DEFAULT '',
  `CountryCode` smallint(6) NOT NULL DEFAULT '0',
  `Country` varchar(80) DEFAULT '',
  `WEB` varchar(255) DEFAULT '',
  `Phone` varchar(80) DEFAULT '',
  `Fax` varchar(80) DEFAULT '',
  `MobilePhone` varchar(80) DEFAULT '',
  `eMail` varchar(80) DEFAULT '',
  `SendMail` char(1) NOT NULL DEFAULT 'N',
  `Text` varchar(255) DEFAULT '',
  `Discount` decimal(4,2) DEFAULT '0.00',
  `SimplifiedInvoice` tinyint(1) DEFAULT '0',
  `TicketOrder` tinyint(1) DEFAULT '0',
  `Points` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `TIN` (`TIN`),
  KEY `Name` (`Name`(19))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `datalogger`
--

CREATE TABLE `datalogger` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` int(11) NOT NULL DEFAULT '0',
  `Scale` int(11) NOT NULL DEFAULT '0',
  `DatTim` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `Message` text NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

--
-- Table structure for table `ean128`
--

CREATE TABLE `ean128` (
  `Counter` int(11) NOT NULL DEFAULT '0',
  `Code1` varchar(32) DEFAULT '',
  `Code2` varchar(32) DEFAULT '',
  `Code3` varchar(32) DEFAULT '',
  `Code4` varchar(32) DEFAULT '',
  `Code5` varchar(32) DEFAULT '',
  `Code6` varchar(32) DEFAULT '',
  `Code7` varchar(32) DEFAULT '',
  `Code8` varchar(32) DEFAULT '',
  `Code9` varchar(32) DEFAULT '',
  `Code10` varchar(32) DEFAULT '',
  PRIMARY KEY (`Counter`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `erasetickets`
--

CREATE TABLE `erasetickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` char(1) DEFAULT 'T',
  `DatTim` datetime DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Type` (`Type`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `families`
--

CREATE TABLE `families` (
  `Code` int(11) NOT NULL,
  `Name` varchar(54) NOT NULL DEFAULT '',
  `Icon` varchar(127) DEFAULT '',
  `DefaultIcon` varchar(127) DEFAULT '',
  `IsBovine` tinyint(1) DEFAULT '0',
  `Label` varchar(64) NOT NULL,
  PRIMARY KEY (`Code`),
  KEY `Name` (`Name`(19))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `fiscal`
--

CREATE TABLE `fiscal` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(32) NOT NULL DEFAULT '',
  `Enabled` tinyint(1) NOT NULL DEFAULT '0',
  `URL` varchar(128) NOT NULL DEFAULT '',
  `User` varchar(32) NOT NULL DEFAULT '',
  `Password` varchar(128) NOT NULL DEFAULT '',
  `WaitPaid` char(1) NOT NULL DEFAULT '0',
  `Status` char(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `fiscalrec`
--

CREATE TABLE `fiscalrec` (
  `IdHTicket` int(11) NOT NULL,
  `Status` char(1) DEFAULT '-',
  `TID` int(11) DEFAULT '0',
  `StartD` datetime DEFAULT NULL,
  `FinishD` datetime DEFAULT NULL,
  `QRCode` varchar(2048) DEFAULT '',
  `TicketLines` varchar(2048) DEFAULT '',
  `SentStatus` smallint(6) NOT NULL DEFAULT '0',
  `SentCode` smallint(6) NOT NULL DEFAULT '0',
  `SentDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `SentID` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (`IdHTicket`),
  CONSTRAINT `fiscalrec_ibfk_1` FOREIGN KEY (`IdHTicket`) REFERENCES `htickets` (`Id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `globalvendorlogged`
--

CREATE TABLE `globalvendorlogged` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `IPServer` varchar(80) NOT NULL DEFAULT '',
  `DatTim` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `Counter` int(11) NOT NULL DEFAULT '0',
  `ActiveKeys` int(11) NOT NULL DEFAULT '1',
  `Vendor` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `IPServer` (`IPServer`,`Counter`,`Vendor`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `hangedmarks`
--

CREATE TABLE `hangedmarks` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Identifier` char(1) NOT NULL DEFAULT '0',
  `Description` varchar(127) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Identifier` (`Identifier`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `hcustomerorders`
--

CREATE TABLE `hcustomerorders` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `IdHTicket` int(11) DEFAULT NULL,
  `Number` varchar(16) NOT NULL,
  `Section` decimal(3,0) DEFAULT '0',
  `UseSection` tinyint(1) DEFAULT '0',
  `OrderDate` date NOT NULL DEFAULT '0000-00-00',
  `TIN` varchar(16) NOT NULL DEFAULT '',
  `Customer` varchar(127) NOT NULL DEFAULT '',
  `Phone` varchar(20) NOT NULL DEFAULT '',
  `DeliveryDate` date NOT NULL DEFAULT '0000-00-00',
  `DeliveryHour` time NOT NULL DEFAULT '00:00:00',
  `PreparationDateLimit` date NOT NULL DEFAULT '0000-00-00',
  `PreparationHourLimit` time NOT NULL DEFAULT '00:00:00',
  `Observations` varchar(255) NOT NULL DEFAULT '',
  `Origin` varchar(32) NOT NULL DEFAULT '',
  `StartDateTime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `ReopenDateTime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `NumberHTicket` int(11) NOT NULL DEFAULT '0',
  `Counter` int(11) DEFAULT '0',
  `Scale` int(11) DEFAULT '0',
  `Vendor` int(11) NOT NULL DEFAULT '0',
  `AddedLines` int(11) DEFAULT '0',
  `NetAmount` decimal(10,2) DEFAULT '0.00',
  `TotalWeight` decimal(12,3) DEFAULT '0.000',
  `TotalUnits` int(11) DEFAULT '0',
  `Packages` int(11) NOT NULL DEFAULT '1',
  `DatTim` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `Status` char(1) NOT NULL DEFAULT '0',
  `Captured` char(1) NOT NULL DEFAULT '0',
  `RemoteInstance` varchar(255) DEFAULT '',
  `RemoteCounterChallenge` varchar(255) DEFAULT '',
  `RemoteOrderText` text,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `hctor_idx` (`Number`,`Section`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `htickets`
--

CREATE TABLE `htickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `IdNetHticket` int(11) DEFAULT '0',
  `NetStat` char(1) DEFAULT '',
  `Captured` char(1) DEFAULT '',
  `CapturedDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `tckType` char(1) DEFAULT NULL,
  `Status` char(1) DEFAULT NULL,
  `Number` int(11) DEFAULT '0',
  `Counter` int(11) DEFAULT '0',
  `Scale` int(11) DEFAULT '0',
  `Vendor` int(11) DEFAULT NULL,
  `TurnPrefix` char(1) DEFAULT '0',
  `Turn` int(10) unsigned DEFAULT '0',
  `TurnId` decimal(20,0) DEFAULT '0',
  `TurnDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `TurnOnTime` tinyint(1) NOT NULL DEFAULT '0',
  `SectionItem` int(11) DEFAULT '0',
  `UseSectionItem` tinyint(1) DEFAULT '0',
  `HVATCode` decimal(1,0) unsigned NOT NULL DEFAULT '0',
  `NumLines` int(11) DEFAULT '0',
  `AddedLines` int(11) DEFAULT '0',
  `GrossAmount` decimal(10,2) DEFAULT '0.00',
  `NetAmount` decimal(10,2) DEFAULT '0.00',
  `TotalWeight` decimal(12,3) DEFAULT '0.000',
  `TotalUnits` int(11) DEFAULT '0',
  `NegativeLines` int(11) DEFAULT '0',
  `NegativeAmount` decimal(10,2) DEFAULT '0.00',
  `CanceledLines` int(11) DEFAULT '0',
  `CanceledAmount` decimal(10,2) DEFAULT '0.00',
  `Packages` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `EAN13` char(13) NOT NULL DEFAULT '',
  `Code128` varchar(32) NOT NULL DEFAULT '',
  `StartDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `TimesPrinted` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `DatTim` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ReloadFrom` int(11) DEFAULT '0',
  `ReloadScale` int(11) NOT NULL DEFAULT '0',
  `ReloadDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ReloadTicketNumber` int(11) NOT NULL DEFAULT '0',
  `ReloadtckType` char(1) DEFAULT '',
  `ReloadTo` int(11) DEFAULT '0',
  `Customer` varchar(16) NOT NULL DEFAULT '',
  `CustomerName` varchar(255) NOT NULL DEFAULT '',
  `CustomerAddress` varchar(255) NOT NULL DEFAULT '',
  `CustomerCity` varchar(255) NOT NULL DEFAULT '',
  `CustomerPostalCode` varchar(80) NOT NULL DEFAULT '',
  `CustomerCountryCode` smallint(6) NOT NULL DEFAULT '0',
  `Points` int(11) NOT NULL DEFAULT '0',
  `PointsExtra` int(11) NOT NULL DEFAULT '0',
  `PointsDiscount` int(11) NOT NULL DEFAULT '0',
  `PointsAmount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `PointsChanged` int(11) NOT NULL DEFAULT '0',
  `OrderNumber` varchar(16) DEFAULT '',
  `SimplifiedInvoice` tinyint(1) DEFAULT '0',
  `Invoice` varchar(20) NOT NULL DEFAULT '',
  `InvoiceDate` date DEFAULT '0000-00-00',
  `tckDiscount` decimal(4,2) DEFAULT '0.00',
  `ParkedNumber` int(11) DEFAULT '0',
  `NeedCopy` tinyint(1) DEFAULT '0',
  `CashStatus` char(1) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '-',
  `CashOperId` int(11) DEFAULT '0',
  `CashAmount` decimal(10,2) DEFAULT '0.00',
  `CashIP` int(10) unsigned NOT NULL DEFAULT '0',
  `CardStatus` char(1) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '-',
  `CardOperId` varchar(64) NOT NULL DEFAULT '',
  `CardAmount` decimal(10,2) DEFAULT '0.00',
  `CardId` varchar(32) NOT NULL DEFAULT '',
  `TIN` varchar(80) NOT NULL DEFAULT '',
  `Checksum` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  KEY `Vendor` (`Vendor`),
  KEY `Invoice` (`Invoice`),
  KEY `datim_idx` (`DatTim`),
  KEY `OrderNumber` (`OrderNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `inventory`
--

CREATE TABLE `inventory` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Number` int(11) DEFAULT '0',
  `PrintDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `Code` int(11) DEFAULT NULL,
  `SectionItem` int(11) DEFAULT '0',
  `Name` varchar(127) NOT NULL,
  `DateTime` datetime DEFAULT NULL,
  `Weight` decimal(5,3) DEFAULT NULL,
  `Units` int(11) DEFAULT NULL,
  `Status` smallint(6) DEFAULT '0',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `invoicedetails`
--

CREATE TABLE `invoicedetails` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `IdInvoice` int(11) DEFAULT NULL,
  `IdHTicket` int(11) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `IdInvoice` (`IdInvoice`,`IdHTicket`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `invoices`
--

CREATE TABLE `invoices` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Number` varchar(20) NOT NULL DEFAULT '',
  `OriginalNumber` varchar(20) NOT NULL DEFAULT '',
  `Date` date DEFAULT '0000-00-00',
  `Customer` varchar(16) NOT NULL DEFAULT '',
  `Type` char(1) NOT NULL DEFAULT '0',
  `Reason` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  KEY `Number` (`Number`),
  KEY `OriginalNumber` (`OriginalNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemgroupkeys`
--

CREATE TABLE `itemgroupkeys` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `NumKey` decimal(2,0) NOT NULL,
  `AboveSection` decimal(2,0) DEFAULT '0',
  `Section` decimal(2,0) DEFAULT '0',
  `SubSection` decimal(2,0) DEFAULT '0',
  `Family` decimal(2,0) DEFAULT '0',
  `SubFamily` decimal(2,0) DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `idx_` (`NumKey`,`AboveSection`,`Section`,`SubSection`,`Family`,`SubFamily`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemgroupkeystext`
--

CREATE TABLE `itemgroupkeystext` (
  `NumKey` decimal(2,0) NOT NULL,
  `Text` varchar(64) DEFAULT '',
  `Icon` varchar(127) DEFAULT '',
  PRIMARY KEY (`NumKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemhabitual`
--

CREATE TABLE `itemhabitual` (
  `Position` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `Code` int(11) NOT NULL,
  PRIMARY KEY (`Position`),
  KEY `fk_1` (`Code`),
  CONSTRAINT `itemhabitual_ibfk_1` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemlinkcommon`
--

CREATE TABLE `itemlinkcommon` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `NumCard` int(11) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `commonlink_idx` (`Code`,`NumCard`),
  CONSTRAINT `ilc_ibfk1` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemmiddleweights`
--

CREATE TABLE `itemmiddleweights` (
  `Code` int(11) NOT NULL,
  `MiddleWeight` decimal(7,3) DEFAULT '0.000',
  `Units` int(11) NOT NULL DEFAULT '1',
  PRIMARY KEY (`Code`),
  CONSTRAINT `imwitem` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

--
-- Table structure for table `itemofferdates`
--

CREATE TABLE `itemofferdates` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `StartDate` date NOT NULL,
  `EndDate` date DEFAULT NULL,
  `PriceSet` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Code` (`Code`),
  CONSTRAINT `iod_items` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemofferpricerates`
--

CREATE TABLE `itemofferpricerates` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `Rate` decimal(1,0) NOT NULL DEFAULT '0',
  `Price` decimal(8,2) NOT NULL DEFAULT '0.00',
  `Step` decimal(7,3) NOT NULL DEFAULT '0.000',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `idx_rate` (`Code`,`Rate`,`Step`),
  KEY `iop_rates` (`Rate`),
  CONSTRAINT `iop_dates` FOREIGN KEY (`Code`) REFERENCES `itemofferdates` (`Code`) ON DELETE CASCADE,
  CONSTRAINT `iop_rates` FOREIGN KEY (`Rate`) REFERENCES `pricerates` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itempricerates`
--

CREATE TABLE `itempricerates` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `Rate` decimal(1,0) NOT NULL DEFAULT '1',
  `Price` decimal(8,2) NOT NULL DEFAULT '0.00',
  `Step` decimal(7,3) NOT NULL DEFAULT '0.000',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `idx_rate` (`Code`,`Rate`,`Step`),
  KEY `Rate` (`Rate`),
  CONSTRAINT `itempricerates_ibfk_1` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE,
  CONSTRAINT `itempricerates_ibfk_2` FOREIGN KEY (`Rate`) REFERENCES `pricerates` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `items`
--

CREATE TABLE `items` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `Inactive` tinyint(1) DEFAULT '0',
  `Name` varchar(127) NOT NULL DEFAULT '',
  `ShortName` varchar(64) DEFAULT '',
  `Text` text,
  `Text1` text,
  `Text2` text,
  `Text3` text,
  `Text4` text,
  `Text5` text,
  `Family` int(11) DEFAULT '0',
  `SubFamily` decimal(2,0) DEFAULT '0',
  `FamilyOrder` int(11) DEFAULT '0',
  `OnKey` tinyint(1) DEFAULT '1',
  `AboveSection` decimal(2,0) DEFAULT '0',
  `Section` decimal(3,0) DEFAULT '0',
  `SubSection` decimal(2,0) DEFAULT '0',
  `WorkingMode` varchar(20) DEFAULT '',
  `Price` decimal(8,2) DEFAULT '0.00',
  `Offer` tinyint(1) DEFAULT '0',
  `Discount` decimal(4,2) DEFAULT '0.00',
  `SaleForm` smallint(6) DEFAULT '1',
  `PLU` int(11) DEFAULT '0',
  `Counter` int(11) DEFAULT '0',
  `VAT` decimal(1,0) unsigned DEFAULT '0',
  `VATExemption` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `EAN13` varchar(13) DEFAULT '',
  `Expiring` smallint(6) DEFAULT '0',
  `BestBefore` smallint(6) DEFAULT '0',
  `Tare` decimal(7,3) DEFAULT '0.000',
  `Label` varchar(64) DEFAULT '',
  `Label2` varchar(64) DEFAULT '-',
  `Nutrition` int(11) DEFAULT '0',
  `EAN13Print` varchar(12) DEFAULT '',
  `AI01Prefix` varchar(1) NOT NULL DEFAULT '',
  `AI240` varchar(30) NOT NULL DEFAULT '',
  `PacketExt` char(1) NOT NULL DEFAULT '-',
  `IsFrozen` tinyint(1) DEFAULT '0',
  `Icon` varchar(127) DEFAULT '',
  `Icon2` varchar(127) DEFAULT '',
  `QLevel` varchar(16) DEFAULT '',
  `Mixed` smallint(6) DEFAULT '0',
  `MixedWeight` decimal(7,3) DEFAULT '0.000',
  `CommonCard` int(11) DEFAULT '0',
  `PatternNumberPieces` int(11) NOT NULL DEFAULT '0',
  `PatternWeightPieces` decimal(9,5) NOT NULL DEFAULT '0.00000',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Code` (`Code`),
  KEY `Name` (`Name`(19)),
  KEY `ide_fmor` (`Family`,`FamilyOrder`)
) ENGINE=InnoDB AUTO_INCREMENT=754 DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemsallergenicons`
--

CREATE TABLE `itemsallergenicons` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `Allergen` varchar(16) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `iai_codal` (`Code`,`Allergen`),
  KEY `iai_allergen` (`Allergen`),
  CONSTRAINT `iai_allergen` FOREIGN KEY (`Allergen`) REFERENCES `allergenicons` (`Allergen`) ON DELETE CASCADE,
  CONSTRAINT `iai_codes` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemschangepoints`
--

CREATE TABLE `itemschangepoints` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `Points` int(11) NOT NULL DEFAULT '0',
  `Quantity` decimal(5,3) NOT NULL DEFAULT '1.000',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Code` (`Code`),
  CONSTRAINT `icpitem` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemsean128`
--

CREATE TABLE `itemsean128` (
  `Code` int(11) NOT NULL,
  `AI91` varchar(128) NOT NULL DEFAULT '',
  `AI92` varchar(128) NOT NULL DEFAULT '',
  `AI93` varchar(128) NOT NULL DEFAULT '',
  `AI94` varchar(128) NOT NULL DEFAULT '',
  `AI95` varchar(128) NOT NULL DEFAULT '',
  `AI96` varchar(128) NOT NULL DEFAULT '',
  `AI97` varchar(128) NOT NULL DEFAULT '',
  `AI98` varchar(128) NOT NULL DEFAULT '',
  `AI99` varchar(128) NOT NULL DEFAULT '',
  PRIMARY KEY (`Code`),
  CONSTRAINT `i128item` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemsean13`
--

CREATE TABLE `itemsean13` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `EAN13` decimal(13,0) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `EAN13` (`EAN13`),
  KEY `iean13_item` (`Code`),
  CONSTRAINT `iean13_item` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemsextrapoints`
--

CREATE TABLE `itemsextrapoints` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `Points` int(11) NOT NULL DEFAULT '0',
  `Quantity` decimal(5,3) NOT NULL DEFAULT '1.000',
  `FromQuantity` decimal(5,3) NOT NULL DEFAULT '0.000',
  `Proportional` tinyint(1) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Code` (`Code`),
  CONSTRAINT `iepitem` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemsformats`
--

CREATE TABLE `itemsformats` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `Format` varchar(32) COLLATE utf8_bin NOT NULL,
  `Price` decimal(8,2) DEFAULT '0.00',
  `Expiring` smallint(6) DEFAULT '0',
  `BestBefore` smallint(6) DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Code` (`Code`,`Format`),
  CONSTRAINT `ifitem` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

--
-- Table structure for table `itemtextbonus`
--

CREATE TABLE `itemtextbonus` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) NOT NULL,
  `NumLine` smallint(6) DEFAULT '1',
  `Text` varchar(40) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `itemtext_idx` (`Code`,`NumLine`),
  CONSTRAINT `itemtextbonus_ibfk_1` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `itemtextcommon`
--

CREATE TABLE `itemtextcommon` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `NumCard` int(11) NOT NULL,
  `NumLine` smallint(6) DEFAULT '1',
  `Text` varchar(100) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `commontext_idx` (`NumCard`,`NumLine`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `lcustomerorders`
--

CREATE TABLE `lcustomerorders` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `OrderNumber` varchar(16) NOT NULL,
  `Item` int(11) NOT NULL DEFAULT '0',
  `ItemFormat` varchar(32) NOT NULL DEFAULT '',
  `Name` varchar(127) NOT NULL DEFAULT '',
  `Section` decimal(3,0) DEFAULT '0',
  `Quantity` decimal(8,3) DEFAULT '0.000',
  `Format` varchar(10) NOT NULL DEFAULT '',
  `Price` decimal(8,2) NOT NULL DEFAULT '0.00',
  `Remark` varchar(255) NOT NULL DEFAULT '',
  `Weight` decimal(7,3) DEFAULT '0.000',
  `Units` int(11) DEFAULT '0',
  `Amount` decimal(10,2) DEFAULT '0.00',
  `Status` char(1) NOT NULL DEFAULT '0',
  `DatTim` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `ReplacedBy` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `lctor_idx` (`OrderNumber`,`Item`,`ItemFormat`),
  KEY `lhkey` (`OrderNumber`,`Section`),
  CONSTRAINT `lhkey` FOREIGN KEY (`OrderNumber`, `Section`) REFERENCES `hcustomerorders` (`Number`, `Section`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localcfgforms`
--

CREATE TABLE `localcfgforms` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Form` varchar(20) NOT NULL,
  `Widget` varchar(32) NOT NULL,
  `Value` varchar(50) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Form` (`Form`,`Widget`)
) ENGINE=InnoDB AUTO_INCREMENT=17 DEFAULT CHARSET=utf8;

--
-- Table structure for table `localcfgkeyboard`
--

CREATE TABLE `localcfgkeyboard` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `ParamKey` varchar(128) NOT NULL DEFAULT '',
  `ParamValue` varchar(128) NOT NULL DEFAULT 'none',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `ParamKey` (`ParamKey`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `localcfgparams`
--

CREATE TABLE `localcfgparams` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `ParamKey` varchar(128) NOT NULL DEFAULT '',
  `ParamValue` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `ParamKey` (`ParamKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localcfgscale`
--

CREATE TABLE `localcfgscale` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `ParamKey` varchar(128) NOT NULL DEFAULT '',
  `ParamValue` varchar(128) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `ParamKey` (`ParamKey`)
) ENGINE=InnoDB AUTO_INCREMENT=310 DEFAULT CHARSET=utf8;

--
-- Table structure for table `localcomm`
--

CREATE TABLE `localcomm` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `dev` varchar(16) NOT NULL DEFAULT '',
  `rxprefix` int(11) DEFAULT '2',
  `rxsufix` int(11) DEFAULT '13',
  `txprefix` int(11) DEFAULT '2',
  `txsufix` int(11) DEFAULT '3',
  `txhandshake` int(11) DEFAULT '1',
  `rxhandshake` int(11) DEFAULT '1',
  `baudrate` int(11) DEFAULT '9600',
  `parity` char(1) DEFAULT 'N',
  `stopbits` tinyint(4) DEFAULT '1',
  `bytesize` tinyint(4) DEFAULT '8',
  `port` int(11) DEFAULT '0',
  `remoteip` varchar(15) DEFAULT '000.000.000.000',
  `remoteport` int(11) DEFAULT '0',
  `protocol` varchar(32) DEFAULT 'src_eachconversion',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `dev` (`dev`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `localcountries`
--

CREATE TABLE `localcountries` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` int(11) DEFAULT NULL,
  `Alpha2` char(2) NOT NULL,
  `Name` varchar(127) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Alpha2` (`Alpha2`),
  UNIQUE KEY `Code` (`Code`),
  KEY `Name` (`Name`(19))
) ENGINE=InnoDB AUTO_INCREMENT=250 DEFAULT CHARSET=utf8;

--
-- Table structure for table `localdatalogger`
--

CREATE TABLE `localdatalogger` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` int(11) DEFAULT NULL,
  `DatTim` datetime DEFAULT NULL,
  `Message` varchar(255) NOT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `localerasetickets`
--

CREATE TABLE `localerasetickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` char(1) DEFAULT 'T',
  `DatTim` datetime DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Type` (`Type`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8;

--
-- Table structure for table `localfiscalrec`
--

CREATE TABLE `localfiscalrec` (
  `IdHTicket` int(11) NOT NULL,
  `Status` char(1) DEFAULT '-',
  `TID` int(11) DEFAULT '0',
  `StartD` datetime DEFAULT NULL,
  `FinishD` datetime DEFAULT NULL,
  `QRCode` varchar(2048) DEFAULT '',
  `TicketLines` varchar(2048) DEFAULT '',
  `SentStatus` smallint(6) NOT NULL DEFAULT '0',
  `SentCode` smallint(6) NOT NULL DEFAULT '0',
  `SentDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `SentID` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (`IdHTicket`),
  CONSTRAINT `localfiscalrec_ibfk_1` FOREIGN KEY (`IdHTicket`) REFERENCES `localhtickets` (`Id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localhtickets`
--

CREATE TABLE `localhtickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `IdNetHticket` int(11) DEFAULT '0',
  `NetStat` char(1) DEFAULT '',
  `Captured` char(1) DEFAULT '',
  `CapturedDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `tckType` char(1) DEFAULT NULL,
  `Status` char(1) DEFAULT NULL,
  `Number` int(11) DEFAULT '0',
  `Counter` int(11) DEFAULT '0',
  `Scale` int(11) DEFAULT '0',
  `Vendor` int(11) DEFAULT NULL,
  `TurnPrefix` char(1) DEFAULT '0',
  `Turn` int(10) unsigned DEFAULT '0',
  `TurnId` decimal(20,0) DEFAULT '0',
  `TurnDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `TurnOnTime` tinyint(1) NOT NULL DEFAULT '0',
  `SectionItem` int(11) DEFAULT '0',
  `UseSectionItem` tinyint(1) DEFAULT '0',
  `HVATCode` decimal(1,0) unsigned NOT NULL DEFAULT '0',
  `NumLines` int(11) DEFAULT '0',
  `AddedLines` int(11) DEFAULT '0',
  `GrossAmount` decimal(10,2) DEFAULT '0.00',
  `NetAmount` decimal(10,2) DEFAULT '0.00',
  `TotalWeight` decimal(12,3) DEFAULT '0.000',
  `TotalUnits` int(11) DEFAULT '0',
  `NegativeLines` int(11) DEFAULT '0',
  `NegativeAmount` decimal(10,2) DEFAULT '0.00',
  `CanceledLines` int(11) DEFAULT '0',
  `CanceledAmount` decimal(10,2) DEFAULT '0.00',
  `Packages` tinyint(3) unsigned NOT NULL DEFAULT '1',
  `EAN13` char(13) NOT NULL DEFAULT '',
  `Code128` varchar(32) NOT NULL DEFAULT '',
  `StartDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `TimesPrinted` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `DatTim` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ReloadFrom` int(11) DEFAULT '0',
  `ReloadScale` int(11) NOT NULL DEFAULT '0',
  `ReloadDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ReloadTicketNumber` int(11) NOT NULL DEFAULT '0',
  `ReloadtckType` char(1) DEFAULT '',
  `ReloadTo` int(11) DEFAULT '0',
  `Customer` varchar(16) NOT NULL DEFAULT '',
  `CustomerName` varchar(255) NOT NULL DEFAULT '',
  `CustomerAddress` varchar(255) NOT NULL DEFAULT '',
  `CustomerCity` varchar(255) NOT NULL DEFAULT '',
  `CustomerPostalCode` varchar(80) NOT NULL DEFAULT '',
  `CustomerCountryCode` smallint(6) NOT NULL DEFAULT '0',
  `Points` int(11) NOT NULL DEFAULT '0',
  `PointsExtra` int(11) NOT NULL DEFAULT '0',
  `PointsDiscount` int(11) NOT NULL DEFAULT '0',
  `PointsAmount` decimal(10,2) NOT NULL DEFAULT '0.00',
  `PointsChanged` int(11) NOT NULL DEFAULT '0',
  `OrderNumber` varchar(16) DEFAULT '',
  `SimplifiedInvoice` tinyint(1) DEFAULT '0',
  `Invoice` varchar(20) NOT NULL DEFAULT '',
  `InvoiceDate` date DEFAULT '0000-00-00',
  `tckDiscount` decimal(4,2) DEFAULT '0.00',
  `ParkedNumber` int(11) DEFAULT '0',
  `NeedCopy` tinyint(1) DEFAULT '0',
  `CashStatus` char(1) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '-',
  `CashOperId` int(11) DEFAULT '0',
  `CashAmount` decimal(10,2) DEFAULT '0.00',
  `CashIP` int(10) unsigned NOT NULL DEFAULT '0',
  `CardStatus` char(1) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '-',
  `CardOperId` varchar(64) NOT NULL DEFAULT '',
  `CardAmount` decimal(10,2) DEFAULT '0.00',
  `CardId` varchar(32) NOT NULL DEFAULT '',
  `TIN` varchar(80) NOT NULL DEFAULT '',
  `Checksum` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  KEY `Vendor` (`Vendor`),
  KEY `Invoice` (`Invoice`),
  KEY `IdNetHticket` (`IdNetHticket`),
  KEY `datim_idx` (`DatTim`),
  KEY `OrderNumber` (`OrderNumber`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localints`
--

CREATE TABLE `localints` (
  `i` tinyint(4) NOT NULL DEFAULT '0',
  PRIMARY KEY (`i`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localitemgroupkeyschanges`
--

CREATE TABLE `localitemgroupkeyschanges` (
  `NumKey` decimal(2,0) NOT NULL,
  PRIMARY KEY (`NumKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `locallicenses`
--

CREATE TABLE `locallicenses` (
  `IdProduct` varchar(16) NOT NULL,
  `Scope` char(1) NOT NULL DEFAULT 'S',
  `ProductName` varchar(255) NOT NULL DEFAULT '',
  `Holder` varchar(255) NOT NULL DEFAULT '',
  `License` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (`IdProduct`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localltickets`
--

CREATE TABLE `localltickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `IdHTicket` int(11) DEFAULT NULL,
  `NetStat` char(1) DEFAULT 'L',
  `lineType` smallint(6) DEFAULT NULL,
  `SaleForm` smallint(6) DEFAULT NULL,
  `SaleFormEx` char(1) DEFAULT '-',
  `Item` int(11) DEFAULT NULL,
  `ItemFormat` varchar(32) NOT NULL DEFAULT '',
  `Name` varchar(127) NOT NULL DEFAULT '',
  `Section` decimal(3,0) NOT NULL DEFAULT '0',
  `Family` int(11) DEFAULT '0',
  `ItemAccess` int(11) DEFAULT '0',
  `LineScale` int(11) NOT NULL DEFAULT '0',
  `LineVendor` int(11) NOT NULL DEFAULT '0',
  `LineDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `SourceKey` char(1) NOT NULL DEFAULT '0',
  `PriceChanged` tinyint(1) NOT NULL DEFAULT '0',
  `VATCode` decimal(1,0) unsigned NOT NULL DEFAULT '0',
  `VATPercent` decimal(4,2) unsigned NOT NULL DEFAULT '0.00',
  `VATExemption` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `Weight` decimal(7,3) DEFAULT NULL,
  `NumberPieces` int(11) NOT NULL DEFAULT '0',
  `Tare` decimal(7,3) DEFAULT '0.000',
  `TTare` char(1) DEFAULT '',
  `lineDiscount` decimal(4,2) DEFAULT NULL,
  `Price` decimal(8,2) DEFAULT NULL,
  `Amount` decimal(10,2) DEFAULT NULL,
  `BaseAmount` decimal(13,5) DEFAULT '0.00000',
  `Points` int(11) NOT NULL DEFAULT '0',
  `BovineCard` smallint(3) DEFAULT NULL,
  `EarTag` varchar(30) DEFAULT NULL,
  `BovineLot` varchar(20) DEFAULT NULL,
  `FreezingDate` date DEFAULT NULL,
  `TicketDiscount` decimal(4,2) DEFAULT '0.00',
  `PrintScale` int(11) NOT NULL DEFAULT '0',
  `PrintDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `PrintTicketNumber` int(11) NOT NULL DEFAULT '0',
  `PrinttckType` char(1) DEFAULT '',
  `ReloadScale` int(11) NOT NULL DEFAULT '0',
  `ReloadDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ReloadTicketNumber` int(11) NOT NULL DEFAULT '0',
  `ReloadtckType` char(1) DEFAULT '',
  `ReloadTo` int(11) DEFAULT '0',
  `Checksum` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  KEY `IdHTicket` (`IdHTicket`),
  CONSTRAINT `localltickets_ibfk_1` FOREIGN KEY (`IdHTicket`) REFERENCES `localhtickets` (`Id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localnumtickets`
--

CREATE TABLE `localnumtickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` binary(1) DEFAULT 'T',
  `Identifier` varchar(16) NOT NULL DEFAULT '',
  `Number` int(11) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Identifier` (`Identifier`,`Type`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localpacketlabels`
--

CREATE TABLE `localpacketlabels` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Captured` char(1) DEFAULT '',
  `CapturedDateTime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `Number` int(11) DEFAULT '0',
  `Counter` int(11) DEFAULT '0',
  `Scale` int(11) DEFAULT '0',
  `Vendor` int(11) DEFAULT NULL,
  `lineType` smallint(6) DEFAULT NULL,
  `Item` int(11) DEFAULT NULL,
  `ItemFormat` varchar(32) NOT NULL DEFAULT '',
  `SaleForm` smallint(6) DEFAULT NULL,
  `SaleFormEx` char(1) DEFAULT '-',
  `Weight` decimal(7,3) DEFAULT NULL,
  `NumberPieces` int(10) unsigned NOT NULL DEFAULT '0',
  `Tare` decimal(7,3) DEFAULT '0.000',
  `TTare` char(1) DEFAULT '',
  `Price` decimal(8,2) DEFAULT NULL,
  `lineDiscount` decimal(4,2) DEFAULT NULL,
  `Amount` decimal(10,2) DEFAULT NULL,
  `PacketExt` char(1) NOT NULL DEFAULT '-',
  `BovineCard` int(11) DEFAULT NULL,
  `EarTag` varchar(30) DEFAULT NULL,
  `BovineLot` varchar(20) DEFAULT NULL,
  `FreezingDate` date DEFAULT NULL,
  `Customer` varchar(16) NOT NULL DEFAULT '',
  `DatTim` datetime DEFAULT NULL,
  `EAN13` varchar(13) NOT NULL DEFAULT '',
  `Code128` varchar(32) NOT NULL DEFAULT '',
  `Lot` varchar(20) NOT NULL DEFAULT '',
  `Ordinal` int(10) unsigned DEFAULT NULL,
  `OrderNumber` varchar(30) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localpacketpresets`
--

CREATE TABLE `localpacketpresets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Vendor` int(11) DEFAULT NULL,
  `Level` smallint(6) DEFAULT NULL,
  `Type` smallint(6) DEFAULT NULL,
  `Value` decimal(6,3) DEFAULT NULL,
  `Number` int(11) DEFAULT '1',
  `ItemTotal` int(11) DEFAULT '0',
  `LowerLabels` int(10) unsigned NOT NULL DEFAULT '0',
  `TotalUnits` int(10) unsigned NOT NULL DEFAULT '0',
  `TotalWeight` decimal(12,3) unsigned NOT NULL DEFAULT '0.000',
  `TotalNumberPieces` int(10) unsigned NOT NULL DEFAULT '0',
  `TotalAmount` decimal(12,2) unsigned NOT NULL DEFAULT '0.00',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Vendor` (`Vendor`,`Level`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localpaytickets`
--

CREATE TABLE `localpaytickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `IdHTicket` int(11) DEFAULT NULL,
  `PayMethod` int(11) DEFAULT NULL,
  `Delivered` decimal(10,2) DEFAULT '0.00',
  PRIMARY KEY (`Id`),
  KEY `IdHTicket` (`IdHTicket`),
  CONSTRAINT `localpaytickets_ibfk_1` FOREIGN KEY (`IdHTicket`) REFERENCES `localhtickets` (`Id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localplukeyschanges`
--

CREATE TABLE `localplukeyschanges` (
  `Section` int(11) NOT NULL,
  `Board` int(11) NOT NULL,
  `PLUKey` int(11) NOT NULL,
  `Code` int(11) NOT NULL,
  PRIMARY KEY (`Section`,`Board`,`PLUKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localsservicelabels`
--

CREATE TABLE `localsservicelabels` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Captured` char(1) DEFAULT '',
  `CapturedDateTime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `Number` int(11) DEFAULT '0',
  `Counter` int(11) DEFAULT '0',
  `Scale` int(11) DEFAULT '0',
  `Vendor` int(11) DEFAULT NULL,
  `lineType` smallint(6) DEFAULT NULL,
  `Item` int(11) DEFAULT NULL,
  `ItemFormat` varchar(32) NOT NULL DEFAULT '',
  `SaleForm` smallint(6) DEFAULT NULL,
  `SaleFormEx` char(1) DEFAULT '-',
  `Weight` decimal(7,3) DEFAULT NULL,
  `NumberPieces` int(10) unsigned NOT NULL DEFAULT '0',
  `Tare` decimal(7,3) DEFAULT '0.000',
  `TTare` char(1) DEFAULT '',
  `Price` decimal(8,2) DEFAULT NULL,
  `lineDiscount` decimal(4,2) DEFAULT NULL,
  `Amount` decimal(10,2) DEFAULT NULL,
  `PacketExt` char(1) NOT NULL DEFAULT '-',
  `BovineCard` int(11) DEFAULT NULL,
  `EarTag` varchar(30) DEFAULT NULL,
  `BovineLot` varchar(20) DEFAULT NULL,
  `FreezingDate` date DEFAULT NULL,
  `Customer` varchar(16) NOT NULL DEFAULT '',
  `DatTim` datetime DEFAULT NULL,
  `EAN13` varchar(13) NOT NULL DEFAULT '',
  `Code128` varchar(32) NOT NULL DEFAULT '',
  `Lot` varchar(20) NOT NULL DEFAULT '',
  `Ordinal` int(10) unsigned DEFAULT NULL,
  `OrderNumber` varchar(30) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localstatus`
--

CREATE TABLE `localstatus` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Version` smallint(6) DEFAULT '23',
  `AppVersion` varchar(16) DEFAULT '',
  `Language` varchar(31) NOT NULL DEFAULT '',
  `EraseTickets` tinyint(1) DEFAULT '0',
  `RemoveScale` tinyint(1) DEFAULT '0',
  `CheckCounters` tinyint(1) DEFAULT '0',
  `CheckCountersKeys` tinyint(1) DEFAULT '0',
  `CheckSections` tinyint(1) DEFAULT '0',
  `CheckFamilies` tinyint(1) DEFAULT '0',
  `CheckCounterFamilies` tinyint(1) DEFAULT '0',
  `CheckItemGroupKeysText` tinyint(1) DEFAULT '0',
  `RefreshTouchsel` tinyint(1) DEFAULT '0',
  `ResizeTouch` tinyint(1) DEFAULT '0',
  `CheckTareCodes` tinyint(1) DEFAULT '0',
  `CheckScripts` tinyint(1) DEFAULT '0',
  `CheckQuickKeys` tinyint(1) DEFAULT '0',
  `LocalTickets` tinyint(1) DEFAULT '0',
  `AdvertisingChanged` tinyint(1) DEFAULT '0',
  `CheckCustomerOrders` tinyint(1) DEFAULT '0',
  `CheckCash` tinyint(1) DEFAULT '0',
  `CheckTurn` tinyint(1) DEFAULT '0',
  `CheckCard` tinyint(1) DEFAULT '0',
  `CheckTotalDaily` tinyint(1) DEFAULT '1',
  `CheckTotalScaleFamilies` tinyint(1) DEFAULT '1',
  `CheckShortcuts` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `localtreeboard`
--

CREATE TABLE `localtreeboard` (
  `Board` int(11) NOT NULL COMMENT 'Numeric table on keyboard. Without gaps',
  `Source1` int(11) NOT NULL DEFAULT '0' COMMENT 'Real value. May be gaps',
  `Source2` int(11) NOT NULL DEFAULT '0',
  `Source3` int(11) NOT NULL DEFAULT '0',
  `Source4` int(11) NOT NULL DEFAULT '0',
  `Source5` int(11) NOT NULL DEFAULT '0',
  `Level1` int(11) NOT NULL DEFAULT '0' COMMENT 'Position value. Without gaps',
  `Level2` int(11) NOT NULL DEFAULT '0',
  `Level3` int(11) NOT NULL DEFAULT '0',
  `Level4` int(11) NOT NULL DEFAULT '0',
  `Level5` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Board`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localvendorchanges`
--

CREATE TABLE `localvendorchanges` (
  `Id` int(11) NOT NULL,
  `Vendor` int(11) DEFAULT NULL,
  `tck` char(1) DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localvendorkeys`
--

CREATE TABLE `localvendorkeys` (
  `Counter` int(11) DEFAULT NULL,
  `VendorKey` int(11) DEFAULT NULL,
  `Vendor` int(11) NOT NULL,
  PRIMARY KEY (`Vendor`),
  UNIQUE KEY `Counter` (`Counter`,`VendorKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localvendorkeyschanges`
--

CREATE TABLE `localvendorkeyschanges` (
  `VendorKey` int(11) NOT NULL,
  `Vendor` int(11) DEFAULT '0',
  `VendorRelease` int(11) DEFAULT '0',
  `Name` varchar(64) DEFAULT NULL,
  `Icon` varchar(127) NOT NULL DEFAULT '',
  PRIMARY KEY (`VendorKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localvendorpacket`
--

CREATE TABLE `localvendorpacket` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Vendor` int(11) DEFAULT NULL,
  `Auto` tinyint(1) DEFAULT NULL,
  `ClearStart` tinyint(1) DEFAULT NULL,
  `Repetitions` smallint(6) DEFAULT '0',
  `Copies` smallint(6) DEFAULT '0',
  `EAN13` char(1) DEFAULT '1',
  `PacketExt` char(1) NOT NULL DEFAULT '-',
  `BovineCard` int(11) DEFAULT NULL,
  `EarTag` varchar(30) DEFAULT NULL,
  `BovineLot` varchar(20) DEFAULT NULL,
  `Customer` varchar(16) NOT NULL DEFAULT '',
  `PresetON` tinyint(1) DEFAULT '0',
  `Item` int(11) DEFAULT '0',
  `ItemFormat` varchar(32) NOT NULL DEFAULT '',
  `SaleForm` smallint(6) DEFAULT NULL,
  `MixedMode` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `ManualWeight` decimal(7,3) DEFAULT NULL,
  `Price` decimal(8,2) DEFAULT NULL,
  `Units` int(10) unsigned NOT NULL DEFAULT '0',
  `Tare` decimal(7,3) DEFAULT NULL,
  `Discount` decimal(4,2) DEFAULT NULL,
  `Lot` varchar(20) NOT NULL DEFAULT '',
  `Ordinal` int(10) unsigned DEFAULT NULL,
  `OrderNumber` varchar(30) NOT NULL DEFAULT '',
  `ExpiringDate` date NOT NULL DEFAULT '0000-00-00',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Vendor` (`Vendor`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localvendorregister`
--

CREATE TABLE `localvendorregister` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Vendor` int(11) DEFAULT NULL,
  `RegisterDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `RegisterSend` smallint(6) DEFAULT '0',
  `ReleaseDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ReleaseSend` smallint(6) DEFAULT '0',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `localworkingmodes`
--

CREATE TABLE `localworkingmodes` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `WorkingMode` varchar(20) NOT NULL DEFAULT '',
  `ParamName` varchar(32) NOT NULL,
  `ParamValue` varchar(200) NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `WorkingMode` (`WorkingMode`,`ParamName`)
) ENGINE=InnoDB AUTO_INCREMENT=912 DEFAULT CHARSET=utf8;

--
-- Table structure for table `ltickets`
--

CREATE TABLE `ltickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `IdHTicket` int(11) DEFAULT NULL,
  `NetStat` char(1) DEFAULT 'N',
  `lineType` smallint(6) DEFAULT NULL,
  `SaleForm` smallint(6) DEFAULT NULL,
  `SaleFormEx` char(1) DEFAULT '-',
  `Item` int(11) DEFAULT NULL,
  `ItemFormat` varchar(32) NOT NULL DEFAULT '',
  `Name` varchar(127) NOT NULL DEFAULT '',
  `Section` decimal(3,0) NOT NULL DEFAULT '0',
  `Family` int(11) DEFAULT '0',
  `ItemAccess` int(11) DEFAULT '0',
  `LineScale` int(11) NOT NULL DEFAULT '0',
  `LineVendor` int(11) NOT NULL DEFAULT '0',
  `LineDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `SourceKey` char(1) NOT NULL DEFAULT '0',
  `PriceChanged` tinyint(1) NOT NULL DEFAULT '0',
  `VATCode` decimal(1,0) unsigned NOT NULL DEFAULT '0',
  `VATPercent` decimal(4,2) unsigned NOT NULL DEFAULT '0.00',
  `VATExemption` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `Weight` decimal(7,3) DEFAULT NULL,
  `NumberPieces` int(11) NOT NULL DEFAULT '0',
  `Tare` decimal(7,3) DEFAULT '0.000',
  `TTare` char(1) DEFAULT '',
  `lineDiscount` decimal(4,2) DEFAULT NULL,
  `Price` decimal(8,2) DEFAULT NULL,
  `Amount` decimal(10,2) DEFAULT NULL,
  `BaseAmount` decimal(13,5) DEFAULT '0.00000' COMMENT 'Amount with discounts without tax',
  `Points` int(11) NOT NULL DEFAULT '0',
  `BovineCard` smallint(3) DEFAULT NULL,
  `EarTag` varchar(30) DEFAULT NULL,
  `BovineLot` varchar(20) DEFAULT NULL,
  `FreezingDate` date DEFAULT NULL,
  `TicketDiscount` decimal(4,2) DEFAULT '0.00',
  `PrintScale` int(11) NOT NULL DEFAULT '0',
  `PrintDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `PrintTicketNumber` int(11) NOT NULL DEFAULT '0',
  `PrinttckType` char(1) DEFAULT '',
  `ReloadScale` int(11) NOT NULL DEFAULT '0',
  `ReloadDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ReloadTicketNumber` int(11) NOT NULL DEFAULT '0',
  `ReloadtckType` char(1) DEFAULT '',
  `ReloadTo` int(11) DEFAULT '0',
  `Checksum` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  KEY `IdHTicket` (`IdHTicket`),
  CONSTRAINT `ltickets_ibfk_1` FOREIGN KEY (`IdHTicket`) REFERENCES `htickets` (`Id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `netstatus`
--

CREATE TABLE `netstatus` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `NetworkName` varchar(50) NOT NULL DEFAULT '',
  `NetworkPrivateName` varchar(80) NOT NULL DEFAULT '',
  `MCast_port` decimal(4,0) NOT NULL DEFAULT '2335',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `numberingtickets`
--

CREATE TABLE `numberingtickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` binary(1) DEFAULT 'T',
  `Serial` varchar(14) NOT NULL DEFAULT '',
  `Fiscal` varchar(14) NOT NULL DEFAULT '',
  `Numbering` smallint(6) DEFAULT '0',
  `NumberingLocal` tinyint(1) DEFAULT '0',
  `StartNumber` int(10) unsigned DEFAULT '1',
  `MaximumNumber` int(10) unsigned DEFAULT '9999',
  `MaximumInvoice` int(10) unsigned DEFAULT '9999',
  `ResetNumber` tinyint(1) DEFAULT '0',
  `SaveMode` char(1) DEFAULT '',
  `ClearStart` tinyint(1) DEFAULT '0',
  `ClearStartDays` smallint(6) DEFAULT '0',
  `ClearStartResetNumber` tinyint(1) DEFAULT '0',
  `ClearStartDaily` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Type` (`Type`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `numinvoices`
--

CREATE TABLE `numinvoices` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `MaxNumber` int(11) DEFAULT NULL,
  `Number` int(11) DEFAULT NULL,
  `Serial` varchar(16) NOT NULL DEFAULT '',
  `RecNumber` int(11) DEFAULT NULL,
  `RecSerial` varchar(16) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `numtickets`
--

CREATE TABLE `numtickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` binary(1) DEFAULT 'T',
  `Identifier` varchar(16) NOT NULL DEFAULT '',
  `Number` int(11) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Identifier` (`Identifier`,`Type`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `nutrition`
--

CREATE TABLE `nutrition` (
  `card` int(11) NOT NULL,
  `portion_weight` float DEFAULT '0',
  `energy_kj_100` float DEFAULT '0',
  `energy_kj_portion` float DEFAULT '0',
  `energy_kcal_100` float DEFAULT '0',
  `energy_kcal_portion` float DEFAULT '0',
  `fat_100` float DEFAULT '0',
  `fat_portion` float DEFAULT '0',
  `saturates_100` float DEFAULT '0',
  `saturates_portion` float DEFAULT '0',
  `mono_unsaturates_100` float DEFAULT '0',
  `mono_unsaturates_portion` float DEFAULT '0',
  `polyunsaturates_100` float DEFAULT '0',
  `polyunsaturates_portion` float DEFAULT '0',
  `carbohydrate_100` float DEFAULT '0',
  `carbohydrate_portion` float DEFAULT '0',
  `sugars_100` float DEFAULT '0',
  `sugars_portion` float DEFAULT '0',
  `polyols_100` float DEFAULT '0',
  `polyols_portion` float DEFAULT '0',
  `starch_100` float DEFAULT '0',
  `starch_portion` float DEFAULT '0',
  `fibre_100` float DEFAULT '0',
  `fibre_portion` float DEFAULT '0',
  `protein_100` float DEFAULT '0',
  `protein_portion` float DEFAULT '0',
  `salt_100` float DEFAULT '0',
  `salt_portion` float DEFAULT '0',
  PRIMARY KEY (`card`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `overunderlevels`
--

CREATE TABLE `overunderlevels` (
  `Code` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(16) NOT NULL,
  `LowWeight` decimal(7,3) NOT NULL DEFAULT '0.000',
  `HighWeight` decimal(7,3) NOT NULL DEFAULT '0.000',
  PRIMARY KEY (`Code`),
  UNIQUE KEY `Name` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `packetlabels`
--

CREATE TABLE `packetlabels` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Captured` char(1) DEFAULT '',
  `CapturedDateTime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `Number` int(11) DEFAULT '0',
  `Counter` int(11) DEFAULT '0',
  `Scale` int(11) DEFAULT '0',
  `Vendor` int(11) DEFAULT NULL,
  `lineType` smallint(6) DEFAULT NULL,
  `Item` int(11) DEFAULT NULL,
  `ItemFormat` varchar(32) NOT NULL DEFAULT '',
  `SaleForm` smallint(6) DEFAULT NULL,
  `SaleFormEx` char(1) DEFAULT '-',
  `Weight` decimal(7,3) DEFAULT NULL,
  `NumberPieces` int(10) unsigned NOT NULL DEFAULT '0',
  `Tare` decimal(7,3) DEFAULT '0.000',
  `TTare` char(1) DEFAULT '',
  `Price` decimal(8,2) DEFAULT NULL,
  `lineDiscount` decimal(4,2) DEFAULT NULL,
  `Amount` decimal(10,2) DEFAULT NULL,
  `PacketExt` char(1) NOT NULL DEFAULT '-',
  `BovineCard` int(11) DEFAULT NULL,
  `EarTag` varchar(30) DEFAULT NULL,
  `BovineLot` varchar(20) DEFAULT NULL,
  `FreezingDate` date DEFAULT NULL,
  `Customer` varchar(16) NOT NULL DEFAULT '',
  `DatTim` datetime DEFAULT NULL,
  `EAN13` varchar(13) NOT NULL DEFAULT '',
  `Code128` varchar(32) NOT NULL DEFAULT '',
  `Lot` varchar(20) NOT NULL DEFAULT '',
  `Ordinal` int(10) unsigned DEFAULT NULL,
  `OrderNumber` varchar(30) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `paymethods`
--

CREATE TABLE `paymethods` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Identifier` tinyint(3) unsigned NOT NULL,
  `Name` varchar(64) NOT NULL,
  `InUse` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Identifier` (`Identifier`)
) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8;

--
-- Table structure for table `paytickets`
--

CREATE TABLE `paytickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `IdHTicket` int(11) DEFAULT NULL,
  `PayMethod` int(11) DEFAULT NULL,
  `Delivered` decimal(10,2) DEFAULT '0.00',
  PRIMARY KEY (`Id`),
  KEY `IdHTicket` (`IdHTicket`),
  CONSTRAINT `paytickets_ibfk_1` FOREIGN KEY (`IdHTicket`) REFERENCES `htickets` (`Id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pktfishery`
--

CREATE TABLE `pktfishery` (
  `Code` int(11) NOT NULL,
  `CommercialDesignation` varchar(127) NOT NULL DEFAULT '',
  `SCName` varchar(127) NOT NULL,
  `FAO3Alfa` varchar(3) NOT NULL DEFAULT '',
  `Lot` varchar(20) NOT NULL,
  `Date` date DEFAULT NULL,
  `Production` varchar(127) NOT NULL,
  `VesselName` varchar(127) NOT NULL DEFAULT '',
  `VesselID` varchar(127) NOT NULL DEFAULT '',
  `Catched` varchar(127) NOT NULL,
  `FAOArea` varchar(10) NOT NULL DEFAULT '',
  `CatchDate` date NOT NULL DEFAULT '0000-00-00',
  `LandingDate` date NOT NULL DEFAULT '0000-00-00',
  `FishingGear` varchar(127) NOT NULL DEFAULT '',
  `FishingISSCFG` varchar(10) NOT NULL DEFAULT '',
  `Presentation` varchar(127) NOT NULL,
  `Defrosted` tinyint(1) DEFAULT '0',
  `Size` decimal(1,0) DEFAULT NULL,
  `Freshness` varchar(10) NOT NULL,
  `Issuer` varchar(255) NOT NULL,
  `IssuerTIN` varchar(16) NOT NULL DEFAULT '',
  `IssuerAddress` varchar(255) NOT NULL DEFAULT '',
  `Descriptive` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Code`),
  CONSTRAINT `pktfishery_ibfk_1` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pktgeneric`
--

CREATE TABLE `pktgeneric` (
  `NumCard` smallint(3) NOT NULL,
  `Lot` varchar(20) NOT NULL,
  `OriginLand` smallint(6) DEFAULT NULL,
  `Region` varchar(255) NOT NULL,
  `SanitaryReg1` varchar(30) DEFAULT NULL,
  `Date1` date DEFAULT NULL,
  `SanitaryReg2` varchar(30) DEFAULT NULL,
  `Date2` date DEFAULT NULL,
  `Descriptive` varchar(255) DEFAULT NULL,
  `Text1` varchar(255) DEFAULT NULL,
  `Text2` varchar(255) DEFAULT NULL,
  `Text3` varchar(255) DEFAULT NULL,
  `Text4` varchar(255) DEFAULT NULL,
  `Text5` varchar(255) DEFAULT NULL,
  `Text6` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`NumCard`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pktvegetables`
--

CREATE TABLE `pktvegetables` (
  `Code` int(11) NOT NULL,
  `Variety` varchar(127) NOT NULL,
  `Lot` varchar(20) NOT NULL,
  `OriginLand` smallint(6) DEFAULT NULL,
  `Region` varchar(255) NOT NULL,
  `Quality` varchar(127) NOT NULL,
  `Size` decimal(2,0) DEFAULT NULL,
  `Issuer` varchar(255) NOT NULL,
  `Descriptive` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`Code`),
  CONSTRAINT `pktvegetables_ibfk_1` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `playlists`
--

CREATE TABLE `playlists` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(31) DEFAULT NULL,
  `Type` smallint(6) DEFAULT '0',
  `PlayIndex` int(11) DEFAULT NULL,
  `FileName` varchar(127) NOT NULL,
  `ExposureTime` smallint(6) DEFAULT '0',
  `TransitionTime` smallint(6) DEFAULT '0',
  `TransitionType` smallint(6) DEFAULT '0',
  `StartDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `EndDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `Status` char(1) DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Name` (`Name`,`PlayIndex`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `plugins`
--

CREATE TABLE `plugins` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(16) NOT NULL,
  `Enabled` tinyint(1) DEFAULT '0',
  `Attr` text NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Name` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `plukeys`
--

CREATE TABLE `plukeys` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Section` int(11) DEFAULT NULL,
  `Board` int(11) DEFAULT NULL,
  `PLUKey` int(11) DEFAULT NULL,
  `Code` int(11) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Section` (`Section`,`Board`,`PLUKey`),
  KEY `Code` (`Code`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8;

--
-- Table structure for table `plukeysfile`
--

CREATE TABLE `plukeysfile` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Source1` int(11) NOT NULL DEFAULT '0',
  `Source2` int(11) NOT NULL DEFAULT '0',
  `Source3` int(11) NOT NULL DEFAULT '0',
  `Source4` int(11) NOT NULL DEFAULT '0',
  `Source5` int(11) NOT NULL DEFAULT '0',
  `PLU` int(11) NOT NULL DEFAULT '0',
  `Name` varchar(64) NOT NULL DEFAULT '',
  `Icon` varchar(96) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `idx_keys` (`Source1`,`Source2`,`Source3`,`Source4`,`Source5`,`PLU`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `pricerates`
--

CREATE TABLE `pricerates` (
  `Code` decimal(1,0) NOT NULL,
  `Name` varchar(64) NOT NULL DEFAULT '',
  PRIMARY KEY (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `providers`
--

CREATE TABLE `providers` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `TIN` varchar(16) NOT NULL DEFAULT '',
  `Name` varchar(255) NOT NULL DEFAULT '',
  `Address` varchar(255) DEFAULT '',
  `City` varchar(255) DEFAULT '',
  `Postalcode` varchar(80) DEFAULT '',
  `CountryCode` smallint(6) NOT NULL DEFAULT '0',
  `Country` varchar(80) DEFAULT '',
  `WEB` varchar(255) DEFAULT '',
  `Phone` varchar(80) DEFAULT '',
  `Fax` varchar(80) DEFAULT '',
  `MobilePhone` varchar(80) DEFAULT '',
  `eMail` varchar(80) DEFAULT '',
  `Text` varchar(255) DEFAULT '',
  `Discount` decimal(4,2) DEFAULT '0.00',
  `SimplifiedInvoice` tinyint(1) DEFAULT '0',
  `TicketOrder` tinyint(1) DEFAULT '0',
  `Points` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `TIN` (`TIN`),
  KEY `Name` (`Name`(19))
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `qlevels`
--

CREATE TABLE `qlevels` (
  `Code` varchar(16) NOT NULL,
  `Icon` varchar(64) NOT NULL,
  `Description` varchar(127) NOT NULL,
  PRIMARY KEY (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `qrfields`
--

CREATE TABLE `qrfields` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `SourceTable` char(1) NOT NULL DEFAULT 'H',
  `Name` varchar(127) NOT NULL DEFAULT '',
  `FieldIndex` decimal(2,0) NOT NULL DEFAULT '1',
  `FieldType` char(1) NOT NULL DEFAULT 'F',
  `Size` decimal(2,0) NOT NULL DEFAULT '1',
  `Format` varchar(127) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `qrf_idx` (`SourceTable`,`FieldIndex`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=utf8;

--
-- Table structure for table `quickkeys`
--

CREATE TABLE `quickkeys` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` smallint(6) DEFAULT '1',
  `Name` varchar(32) NOT NULL DEFAULT '',
  `Label` varchar(64) DEFAULT '',
  `Vendor` int(11) DEFAULT '0',
  `EAN13` char(13) NOT NULL DEFAULT '',
  `Code128` decimal(2,0) DEFAULT '0',
  `UserText` varchar(32) NOT NULL DEFAULT '',
  `UseForm` int(11) DEFAULT '0',
  `Transaction` tinyint(1) DEFAULT '1',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `scales`
--

CREATE TABLE `scales` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `MAC` varchar(17) NOT NULL,
  `IP` varchar(16) NOT NULL,
  `Number` int(11) NOT NULL DEFAULT '0',
  `Counter` int(11) NOT NULL DEFAULT '0',
  `Name` varchar(64) NOT NULL DEFAULT '',
  `Type` char(1) DEFAULT NULL,
  `AppVersion` varchar(16) DEFAULT '',
  `ScaleVersion` varchar(32) NOT NULL DEFAULT '',
  `SerialNumber` varchar(10) DEFAULT '',
  `System` varchar(32) DEFAULT '',
  `Keyboard` varchar(128) NOT NULL DEFAULT '',
  `WorkingMode` varchar(128) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `MAC` (`MAC`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `scheduler`
--

CREATE TABLE `scheduler` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(255) NOT NULL DEFAULT '',
  `ScaleType` int(11) DEFAULT '0',
  `ScaleNumber` int(11) DEFAULT '0',
  `Task` smallint(6) DEFAULT '0',
  `Type` smallint(6) DEFAULT '0',
  `DatTim` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `LastExec` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `TaskParam` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `scripts`
--

CREATE TABLE `scripts` (
  `Code` int(11) NOT NULL,
  `Description` varchar(127) DEFAULT '',
  `Script` text,
  PRIMARY KEY (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `sections`
--

CREATE TABLE `sections` (
  `Code` decimal(3,0) NOT NULL,
  `Name` varchar(20) NOT NULL DEFAULT '',
  `Icon` varchar(127) DEFAULT NULL,
  `IsFrozen` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`Code`),
  KEY `Name` (`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `selfctl`
--

CREATE TABLE `selfctl` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Number` int(11) DEFAULT '0',
  `PrintDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `Relation` int(11) DEFAULT NULL,
  `Code` int(11) DEFAULT NULL,
  `SectionItem` int(11) DEFAULT '0',
  `Name` varchar(127) NOT NULL,
  `DateTime` datetime DEFAULT NULL,
  `Weight` decimal(5,3) DEFAULT NULL,
  `Units` int(11) DEFAULT NULL,
  `Status` smallint(6) DEFAULT '0',
  PRIMARY KEY (`Id`),
  KEY `Relation` (`Relation`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `selfctloper`
--

CREATE TABLE `selfctloper` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `OpType` char(1) DEFAULT '0',
  `Code` smallint(6) DEFAULT '0',
  `Name` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `OpType` (`OpType`,`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `selfctlrelations`
--

CREATE TABLE `selfctlrelations` (
  `IdRel` int(11) NOT NULL,
  `Source` smallint(6) DEFAULT '0',
  `Type` smallint(6) DEFAULT '0',
  `Corrective` smallint(6) DEFAULT '0',
  `Name` varchar(30) DEFAULT NULL,
  PRIMARY KEY (`IdRel`),
  UNIQUE KEY `Source` (`Source`,`Type`,`Corrective`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `shoporder`
--

CREATE TABLE `shoporder` (
  `Code` int(11) NOT NULL,
  `Name` varchar(127) NOT NULL,
  `SaleForm` smallint(6) DEFAULT '1',
  `Weight` decimal(12,3) DEFAULT '0.000',
  `Units` int(11) DEFAULT '0',
  `Observations` varchar(127) DEFAULT NULL,
  `DatTim` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  PRIMARY KEY (`Code`),
  CONSTRAINT `shoporder_ibfk_1` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `shortcuts`
--

CREATE TABLE `shortcuts` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` decimal(2,0) NOT NULL,
  `Based` varchar(16) NOT NULL DEFAULT 'sales',
  `LKFunction` varchar(24) NOT NULL DEFAULT '',
  `Param` varchar(54) NOT NULL DEFAULT '',
  `Icon` varchar(127) NOT NULL DEFAULT '',
  `UseDual` tinyint(1) DEFAULT '1',
  `DualField` varchar(54) NOT NULL DEFAULT '',
  `KeyField1` varchar(24) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `sc_codbas` (`Code`,`Based`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `sservicelabels`
--

CREATE TABLE `sservicelabels` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Captured` char(1) DEFAULT '',
  `CapturedDateTime` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',
  `Number` int(11) DEFAULT '0',
  `Counter` int(11) DEFAULT '0',
  `Scale` int(11) DEFAULT '0',
  `Vendor` int(11) DEFAULT NULL,
  `lineType` smallint(6) DEFAULT NULL,
  `Item` int(11) DEFAULT NULL,
  `ItemFormat` varchar(32) NOT NULL DEFAULT '',
  `SaleForm` smallint(6) DEFAULT NULL,
  `SaleFormEx` char(1) DEFAULT '-',
  `Weight` decimal(7,3) DEFAULT NULL,
  `NumberPieces` int(10) unsigned NOT NULL DEFAULT '0',
  `Tare` decimal(7,3) DEFAULT '0.000',
  `TTare` char(1) DEFAULT '',
  `Price` decimal(8,2) DEFAULT NULL,
  `lineDiscount` decimal(4,2) DEFAULT NULL,
  `Amount` decimal(10,2) DEFAULT NULL,
  `PacketExt` char(1) NOT NULL DEFAULT '-',
  `BovineCard` int(11) DEFAULT NULL,
  `EarTag` varchar(30) DEFAULT NULL,
  `BovineLot` varchar(20) DEFAULT NULL,
  `FreezingDate` date DEFAULT NULL,
  `Customer` varchar(16) NOT NULL DEFAULT '',
  `DatTim` datetime DEFAULT NULL,
  `EAN13` varchar(13) NOT NULL DEFAULT '',
  `Code128` varchar(32) NOT NULL DEFAULT '',
  `Lot` varchar(20) NOT NULL DEFAULT '',
  `Ordinal` int(10) unsigned DEFAULT NULL,
  `OrderNumber` varchar(30) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `status`
--

CREATE TABLE `status` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Version` smallint(6) DEFAULT '23',
  `AppVersion` varchar(16) DEFAULT '',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `stock`
--

CREATE TABLE `stock` (
  `Code` int(11) NOT NULL,
  `Name` varchar(127) NOT NULL,
  `SaleForm` smallint(6) DEFAULT '1',
  `Weight` decimal(12,3) DEFAULT '0.000',
  `Units` int(11) DEFAULT '0',
  `Inventory_Weight` decimal(12,3) DEFAULT '0.000',
  `Inventory_Units` int(11) DEFAULT '0',
  `Shrink_Weight` decimal(12,3) DEFAULT '0.000',
  `Shrink_Units` int(11) DEFAULT '0',
  `Return_Weight` decimal(12,3) DEFAULT '0.000',
  `Return_Units` int(11) DEFAULT '0',
  PRIMARY KEY (`Code`),
  CONSTRAINT `stock_ibfk_1` FOREIGN KEY (`Code`) REFERENCES `items` (`Code`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `tarecodes`
--

CREATE TABLE `tarecodes` (
  `Code` decimal(2,0) NOT NULL,
  `Tare` decimal(7,3) DEFAULT '0.000',
  `Name` varchar(20) NOT NULL DEFAULT '',
  PRIMARY KEY (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `totaldaily`
--

CREATE TABLE `totaldaily` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` char(1) DEFAULT '',
  `NetStat` char(1) DEFAULT '',
  `Date` date NOT NULL,
  `Number` int(10) unsigned DEFAULT '0',
  `PrintChgCounter` int(10) unsigned DEFAULT '1',
  `Printing` tinyint(3) unsigned DEFAULT '0',
  `Printed` tinyint(3) unsigned DEFAULT '0',
  `Tickets` int(11) DEFAULT '1',
  `TotalLines` int(11) DEFAULT '0',
  `TotalAmount` decimal(12,2) DEFAULT '0.00',
  `TotalDiscount` decimal(12,2) DEFAULT '0.00',
  `TotalWeight` decimal(12,3) DEFAULT '0.000',
  `TotalUnits` int(11) DEFAULT '0',
  `NegativeLines` int(11) DEFAULT '0',
  `NegativeAmount` decimal(12,2) DEFAULT '0.00',
  `CanceledLines` int(11) DEFAULT '0',
  `CanceledAmount` decimal(12,2) DEFAULT '0.00',
  `ReloadedTickets` int(11) NOT NULL DEFAULT '0',
  `TotalReloadedAmount` decimal(12,2) NOT NULL DEFAULT '0.00',
  `Invoices` int(11) DEFAULT '0',
  `InvoiceAmount` decimal(12,2) DEFAULT '0.00',
  `InvoicesRefund` int(11) NOT NULL DEFAULT '0',
  `InvoiceAmountRefund` decimal(12,2) NOT NULL DEFAULT '0.00',
  `AccumulatedAmount` decimal(12,2) DEFAULT '0.00',
  `Checksum` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `dailycnt_idx` (`Date`,`Type`,`NetStat`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `totalpaytickets`
--

CREATE TABLE `totalpaytickets` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` char(1) DEFAULT 'T',
  `NetStat` char(1) DEFAULT '',
  `Date` date NOT NULL,
  `PayMethod` int(11) DEFAULT NULL,
  `Delivered` decimal(12,2) DEFAULT '0.00',
  `Checksum` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `paytck_idx` (`Date`,`Type`,`NetStat`,`PayMethod`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `totalperpetual`
--

CREATE TABLE `totalperpetual` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` char(1) DEFAULT '',
  `NetStat` char(1) DEFAULT '',
  `Date` date NOT NULL,
  `Tickets` int(11) DEFAULT '1',
  `TotalLines` int(11) DEFAULT '0',
  `TotalAmount` decimal(12,2) DEFAULT '0.00',
  `TotalDiscount` decimal(12,2) DEFAULT '0.00',
  `TotalWeight` decimal(12,3) DEFAULT '0.000',
  `TotalUnits` int(11) DEFAULT '0',
  `NegativeLines` int(11) DEFAULT '0',
  `NegativeAmount` decimal(12,2) DEFAULT '0.00',
  `CanceledLines` int(11) DEFAULT '0',
  `CanceledAmount` decimal(12,2) DEFAULT '0.00',
  `ReloadedTickets` int(11) NOT NULL DEFAULT '0',
  `TotalReloadedAmount` decimal(12,2) NOT NULL DEFAULT '0.00',
  `Invoices` int(11) DEFAULT '0',
  `InvoiceAmount` decimal(12,2) DEFAULT '0.00',
  `InvoicesRefund` int(11) NOT NULL DEFAULT '0',
  `InvoiceAmountRefund` decimal(12,2) NOT NULL DEFAULT '0.00',
  `Checksum` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `perpetual_idx` (`Type`,`NetStat`)
) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8;

--
-- Table structure for table `totalscalefamilies`
--

CREATE TABLE `totalscalefamilies` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Date` date NOT NULL,
  `Number` int(10) unsigned DEFAULT '0',
  `Scale` int(11) DEFAULT '0',
  `Family` int(11) DEFAULT '0',
  `PrintChgCounter` int(10) unsigned DEFAULT '1',
  `Printing` tinyint(3) unsigned DEFAULT '0',
  `Printed` tinyint(3) unsigned DEFAULT '0',
  `TotalWeight` decimal(12,3) DEFAULT '0.000',
  `TotalUnits` int(11) DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `total_idx` (`Date`,`Scale`,`Family`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `totalvat`
--

CREATE TABLE `totalvat` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Type` char(1) DEFAULT 'T',
  `NetStat` char(1) DEFAULT '',
  `Date` date NOT NULL,
  `Code` decimal(1,0) unsigned NOT NULL,
  `Percentage` decimal(4,2) DEFAULT NULL,
  `Amount` decimal(12,2) DEFAULT '0.00',
  `Base` decimal(12,2) DEFAULT '0.00',
  `Tax` decimal(12,2) DEFAULT '0.00',
  `Checksum` varchar(1024) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `totalvat_idx` (`Date`,`Type`,`NetStat`,`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `trademark`
--

CREATE TABLE `trademark` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `CO_Name` varchar(255) DEFAULT '',
  `Description` varchar(255) DEFAULT '',
  `Business` varchar(255) DEFAULT '',
  `Slogan` varchar(255) DEFAULT '',
  `Headquarter` varchar(255) DEFAULT '',
  `CO_WEB` varchar(255) DEFAULT '',
  `Shop_Name` varchar(255) DEFAULT '',
  `Address` varchar(255) DEFAULT '',
  `City` varchar(255) DEFAULT '',
  `Postalcode` varchar(80) DEFAULT '',
  `CountryCode` smallint(6) NOT NULL DEFAULT '0',
  `Country` varchar(80) DEFAULT '',
  `Phone` varchar(80) DEFAULT '',
  `Fax` varchar(80) DEFAULT '',
  `MobilePhone` varchar(80) DEFAULT '',
  `eMail` varchar(80) DEFAULT '',
  `TIN` varchar(80) DEFAULT '',
  `Shop_WEB` varchar(255) DEFAULT '',
  `Text1` varchar(255) DEFAULT '',
  `Text2` varchar(255) DEFAULT '',
  `Text3` varchar(255) DEFAULT '',
  `Text4` varchar(255) DEFAULT '',
  `Text5` varchar(255) DEFAULT '',
  `Text6` varchar(255) DEFAULT '',
  `Text7` varchar(255) DEFAULT '',
  `Text8` varchar(255) DEFAULT '',
  `Text9` varchar(255) DEFAULT '',
  `Text10` varchar(255) DEFAULT '',
  `Icon` varchar(127) DEFAULT '',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;

--
-- Table structure for table `turn`
--

CREATE TABLE `turn` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Name` varchar(32) NOT NULL DEFAULT '',
  `IP` int(10) unsigned NOT NULL DEFAULT '0',
  `URL` varchar(255) NOT NULL DEFAULT '',
  `Login` varchar(255) NOT NULL DEFAULT '',
  `Enabled` tinyint(1) DEFAULT '0',
  `User` varchar(32) NOT NULL DEFAULT '',
  `Password` varchar(32) NOT NULL DEFAULT '',
  `Status` char(1) NOT NULL DEFAULT '0',
  `MaxNumberRange` int(11) NOT NULL DEFAULT '99',
  `ResetNumberType` smallint(6) NOT NULL DEFAULT '0',
  `LastResetDate` datetime DEFAULT NULL,
  `DisplayType` smallint(6) NOT NULL DEFAULT '0',
  `TicketType` smallint(6) NOT NULL DEFAULT '0',
  `PrintLogo` tinyint(1) NOT NULL DEFAULT '0',
  `ShopId` smallint(6) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `turns`
--

CREATE TABLE `turns` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Counter` int(11) NOT NULL,
  `Number` int(11) NOT NULL DEFAULT '0',
  `Status` smallint(6) NOT NULL DEFAULT '0',
  `ServeDatetime` datetime DEFAULT NULL,
  `OpenDateTime` datetime DEFAULT NULL,
  `CloseDateTime` datetime DEFAULT NULL,
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `turnswaiting`
--

CREATE TABLE `turnswaiting` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Counter` decimal(3,0) DEFAULT '0',
  `DayWeek` decimal(1,0) DEFAULT '0',
  `TimeLimit` int(11) NOT NULL DEFAULT '0',
  `TurnsLimit` int(11) NOT NULL DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `idx_twt` (`Counter`,`DayWeek`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `users`
--

CREATE TABLE `users` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `User` varchar(16) NOT NULL DEFAULT '',
  `Password` varchar(31) NOT NULL,
  `Name` varchar(127) NOT NULL,
  `LevelLab` tinyint(1) DEFAULT '0',
  `LevelAdmin` tinyint(1) DEFAULT '0',
  `LevelConfig` tinyint(1) DEFAULT '0',
  `LevelProg` tinyint(1) DEFAULT '0',
  `LevelVendor` tinyint(1) DEFAULT '0',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `User` (`User`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8;

--
-- Table structure for table `vatexemptions`
--

CREATE TABLE `vatexemptions` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` tinyint(3) unsigned NOT NULL,
  `Description` varchar(255) NOT NULL DEFAULT '',
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Code` (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `vats`
--

CREATE TABLE `vats` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Code` decimal(1,0) unsigned NOT NULL,
  `Name` varchar(16) NOT NULL,
  `Percent` decimal(4,2) DEFAULT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `Code` (`Code`)
) ENGINE=InnoDB AUTO_INCREMENT=30 DEFAULT CHARSET=utf8;

--
-- Table structure for table `vendorkeys`
--

CREATE TABLE `vendorkeys` (
  `Counter` int(11) DEFAULT NULL,
  `VendorKey` int(11) DEFAULT NULL,
  `Vendor` int(11) NOT NULL,
  PRIMARY KEY (`Vendor`),
  UNIQUE KEY `Counter` (`Counter`,`VendorKey`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `vendorregister`
--

CREATE TABLE `vendorregister` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `Vendor` int(11) DEFAULT NULL,
  `RegisterDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `RegisterSend` smallint(6) DEFAULT '0',
  `ReleaseDateTime` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
  `ReleaseSend` smallint(6) DEFAULT '0',
  PRIMARY KEY (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `vendors`
--

CREATE TABLE `vendors` (
  `Code` int(11) NOT NULL,
  `Name` varchar(64) NOT NULL,
  `Password` varchar(31) NOT NULL DEFAULT '',
  `Icon` varchar(127) NOT NULL DEFAULT '',
  `TurnId` varchar(64) DEFAULT NULL,
  PRIMARY KEY (`Code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `vitaminnames`
--

CREATE TABLE `vitaminnames` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `locale` char(2) NOT NULL DEFAULT '',
  `type` char(1) DEFAULT NULL,
  `shortname` char(3) NOT NULL DEFAULT '',
  `name` varchar(50) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `locale` (`locale`,`type`,`shortname`)
) ENGINE=InnoDB AUTO_INCREMENT=109 DEFAULT CHARSET=utf8;

--
-- Table structure for table `vitamins`
--

CREATE TABLE `vitamins` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `card` int(11) NOT NULL,
  `identifier` int(11) NOT NULL,
  `type` char(1) DEFAULT NULL,
  `shortname` char(3) NOT NULL DEFAULT '',
  `name` varchar(50) DEFAULT NULL,
  `units` varchar(2) DEFAULT NULL,
  `daily_ref` float DEFAULT NULL,
  `per100` float DEFAULT '0',
  `perportion` float DEFAULT '0',
  PRIMARY KEY (`id`),
  UNIQUE KEY `vtm` (`card`,`identifier`),
  CONSTRAINT `vitamins_ibfk_1` FOREIGN KEY (`card`) REFERENCES `nutrition` (`card`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Table structure for table `xmltexts`
--

CREATE TABLE `xmltexts` (
  `Id` int(11) NOT NULL AUTO_INCREMENT,
  `XmlType` char(1) DEFAULT NULL,
  `GroupName` varchar(32) NOT NULL DEFAULT '',
  `Name` varchar(32) NOT NULL DEFAULT '',
  `XmlText` text NOT NULL,
  PRIMARY KEY (`Id`),
  UNIQUE KEY `XmlType` (`XmlType`,`GroupName`,`Name`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

--
-- Dumping routines for database 'pcscale'
--
/*!50003 DROP FUNCTION IF EXISTS `gs1_checkdigit` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` FUNCTION `gs1_checkdigit`(base VARCHAR(17)) RETURNS char(1) CHARSET utf8
    DETERMINISTIC
BEGIN
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    DECLARE odds INTEGER DEFAULT 0;     
    DECLARE evens INTEGER DEFAULT 0;    
    DECLARE total INTEGER DEFAULT 0;    
    DECLARE len INTEGER;                
    DECLARE pos INTEGER DEFAULT 0;      
    DECLARE digit INTEGER;              
    DECLARE cd INTEGER;                 
    
    
    SET len = LENGTH(base);
    mainloop: LOOP
        
        
        SET digit = CAST(SUBSTRING(base, len-pos, 1) AS SIGNED INTEGER);
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        IF (pos % 2 = 0)
        THEN
            SET evens = evens + digit;
        ELSE
            SET odds = odds + digit;
        END IF;
        
        
        SET pos = pos + 1;
        IF (pos < LEN)
        THEN
            ITERATE mainloop;
        END IF;
        LEAVE mainloop;
    END LOOP mainloop;
    
    
    SET total = odds + (3 * evens);
    SET cd = total % 10;
    IF (cd <> 0)
    THEN
        SET cd = 10 - cd;
    END IF;
    
    RETURN (CAST(cd AS CHAR));
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `pcs_net` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` FUNCTION `pcs_net`(gross DECIMAL(10,2), discount DECIMAL(4,2), points DECIMAL(10,2)) RETURNS decimal(10,2)
    DETERMINISTIC
BEGIN
  DECLARE net DECIMAL(10,2);

  SET @amount_round := IFNULL(GLOBAL_GET("amount_round"), 0);
  SET @frac_digits := IFNULL(GLOBAL_GET("frac_digits"), 2);
  SET net=gross - ROUND((gross*discount)/100, @frac_digits) - points;
  IF(@amount_round=5) THEN
    SET net=(ROUND(net/5, @frac_digits) * 5);
  END IF;

  RETURN net;

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `pcs_total_to_pay` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` FUNCTION `pcs_total_to_pay`(id_ticket INTEGER, src_db TINYTEXT) RETURNS decimal(10,2)
    DETERMINISTIC
BEGIN
  DECLARE total DECIMAL(10,2);
  DECLARE without_taxes BOOLEAN DEFAULT FALSE;	
  SET without_taxes = (SELECT (IFNULL((SELECT `ParamValue` FROM `CfgSystem` WHERE `ParamKey`='prices-without-taxes'), 0)=1));
  IF(without_taxes=0) THEN
    IF(src_db='HTickets') THEN
      SET total = (SELECT `NetAmount` FROM `HTickets` WHERE `Id`=id_ticket);
    ELSE  
      SET total = (SELECT `NetAmount` FROM `LocalHTickets` WHERE `Id`=id_ticket);
    END IF;

  ELSE
    IF(src_db='HTickets') THEN
      SET total = (SELECT SUM(V_VAT.Amount) + SUM(CAST(((V_VAT.Amount*Percentage)/100) AS DECIMAL(10,2))) FROM
        (SELECT lt.`VATPercent`+'0' AS Percentage, CAST((SUM(lt.`Amount`)*(ht.`NetAmount`/ht.`GrossAmount`)) AS DECIMAL(10,2)) AS Amount
         FROM `HTickets` AS ht
         LEFT JOIN `LTickets` AS lt ON ht.`Id`=lt.`IdHTicket`
         WHERE ht.`Id`=id_ticket AND `lineType`=1 GROUP BY lt.`VATCode`) AS V_VAT);
    ELSE  
      SET total = (SELECT SUM(V_VAT.Amount) + SUM(CAST(((V_VAT.Amount*Percentage)/100) AS DECIMAL(10,2))) FROM
        (SELECT lt.`VATPercent`+'0' AS Percentage, CAST((SUM(lt.`Amount`)*(ht.`NetAmount`/ht.`GrossAmount`)) AS DECIMAL(10,2)) AS Amount
         FROM `LocalHTickets` AS ht
         LEFT JOIN `LocalLTickets` AS lt ON ht.`Id`=lt.`IdHTicket`
         WHERE ht.`Id`=id_ticket AND `lineType`=1 GROUP BY lt.`VATCode`) AS V_VAT);
    END IF;
  END IF;

  RETURN total;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `DataloggerFiscalChange` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` PROCEDURE `DataloggerFiscalChange`(OldName VARCHAR(32), NewName VARCHAR(32), OldEnabled BOOLEAN, NewEnabled BOOLEAN )
BEGIN
  DECLARE msg VARCHAR(255) DEFAULT '';
  IF ((NewName!=OldName) OR (NewEnabled!=OldEnabled)) THEN
    SELECT (SELECT COUNT(*) FROM information_schema.global_status WHERE variable_name='SLAVE_RUNNING' AND VARIABLE_VALUE='ON'), (SELECT COUNT(*) FROM information_schema.processlist WHERE INFO='SELECT trx_get()') INTO @_slave_,@_app_running_;
    IF (@_slave_ = 0) THEN
      IF (NewName = OldName) THEN
        SET msg := CONCAT('Fiscal module ', NewName, IF(NewEnabled, ' enabled', ' disabled'));
      ELSEIF (NewName = '') THEN
        SET msg := CONCAT('Fiscal module ', OldName, ' dropped.');
      ELSEIF (OldName = '') THEN
        SET msg := CONCAT('Fiscal module ', NewName, ' raised. ',IF(NewEnabled, 'Enabled', 'Disabled'));
      ELSE
        SET msg := CONCAT('Fiscal module ', OldName, ' changed to ', NewName, IF(NewEnabled, '. Enabled', '. Disabled'));
      END IF;
    END IF;
    IF (@_app_running_ = 0) THEN
      INSERT INTO `LocalDataLogger` SET Type=134, DatTim=NOW(), Message=msg;
    ELSE
      SET @trx := (SELECT trx_new("FISCAL_RELOAD", "NETWORK"));
      SET @ret := (SELECT trx_set_param(@trx, "LOG", msg));
      SET @ret := (SELECT trx_send(@trx));
    END IF;
  END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `dbTrigger` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` PROCEDURE `dbTrigger`(IN `tbname` VARCHAR (40), `function` VARCHAR (10), `masterkey` VARCHAR (40))
BEGIN
    SET @trx := (SELECT trx_new("DBTRIGGER", "CORE"));
    SET @ret := (SELECT trx_set_param(@trx, "TABLE", `tbname`));
    SET @ret := (SELECT trx_set_param(@trx, "FUNCTION", `function`));
    SET @ret := (SELECT trx_set_param(@trx, "KEY", `masterkey`));
    SET @ret := (SELECT trx_send(@trx));
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `LocalTreeBoardFromPLUKeysFile` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` PROCEDURE `LocalTreeBoardFromPLUKeysFile`()
BEGIN


  DELETE FROM `LocalTreeBoard`;
  SET @rownumber:=100000;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`,`Source2`,`Source3`,`Source4`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1`, puk.`Source2`, puk.`Source3`, puk.`Source4` FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`!=0  AND puk.`Source4`!=0 AND puk.`Source5`!=0) AS VT;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`,`Source2`,`Source3`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1`, puk.`Source2`, puk.`Source3` FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`!=0  AND puk.`Source4`!=0 AND puk.`Source5`=0) AS VT;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`,`Source2`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1`, puk.`Source2` AS kl FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`!=0  AND puk.`Source4`=0 AND puk.`Source5`=0) AS VT;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1` FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`=0  AND puk.`Source4`=0 AND puk.`Source5`=0) AS VT;

  SET @rownumber:=0;
  UPDATE `LocalTreeBoard` SET Board=(@rownumber:=@rownumber+1) ORDER BY `Source1`,`Source2`,`Source3`,`Source4`,`Source5`;

 UPDATE `LocalTreeBoard` AS T1 LEFT JOIN
 (SELECT `Board`,
    IF(@src1!=`Source1`, @lv1:=@lv1+1, @lv1) AS lv1,
    IF(@src1!=`Source1`, IF(`Source2`!=0, @lv2:=1, @lv2:=0), IF(@src2!=`Source2`, @lv2:=@lv2+1, @lv2)) AS lv2,
    IF(@src1!=`Source1` OR @src2!=`Source2`, IF(`Source3`!=0, @lv3:=1, @lv3:=0), IF(@src3!=`Source3`, @lv3:=@lv3+1, @lv3)) AS lv3,
    IF(@src1!=`Source1` OR @src2!=`Source2` OR @src3!=`Source3`, IF(`Source4`!=0, @lv4:=1, @lv4:=0), IF(@src4!=`Source4`, @lv4:=@lv4+1, @lv4)) AS lv4,
    IF(@src1!=`Source1` OR @src2!=`Source2` OR @src3!=`Source3` OR @src4!=`Source4`, IF(`Source5`!=0, @lv5:=1, @lv5:=0), IF(@src5!=`Source5`, @lv5:=@lv5+1, @lv5)) AS lv5,
    @src1:=`Source1`, @src2:=`Source2`, @src3:=`Source3`, @src4:=`Source4`, @src5:=`Source5`
	FROM `LocalTreeBoard`, (SELECT @src1:=0, @lv1:=0, @src2:=0, @lv2:=0, @src3:=0, @lv3:=0, @src4:=0, @lv4:=0, @src5:=0, @lv5:=0) AS TT
    ORDER BY `Board`) AS T2 ON T1.`Board`=T2.`Board`
 SET T1.`Level1`=T2.lv1, T1.`Level2`=T2.lv2, T1.`Level3`=T2.lv3, T1.`Level4`=T2.lv4, T1.`Level5`=T2.lv5;
END ;;
DELIMITER ;


--
-- Host: localhost    Database: pcscale
-- ------------------------------------------------------


--
-- Dumping data for table `advertising`
--

INSERT INTO `advertising` VALUES (1,0,0,0,10,0,0,1,0,0,0,'','',0,0);

--
-- Dumping data for table `allergenicons`
--

INSERT INTO `allergenicons` VALUES (1,'gluten','Cereals containing gluten','gluten.png'),(2,'crustaceans','Crustaceans','crustacean.png'),(3,'eggs','Eggs','egg.png'),(4,'fish','Poisson','fish.png'),(5,'peanuts','Peanuts','peanut.png'),(6,'soybeans','Soybeans','soya.png'),(7,'milk','Milk','milk.png'),(8,'nuts','Nuts','treenut.png'),(9,'celery','Celery','celery.png'),(10,'mustard','Mustard','mustard.png'),(11,'sesame','Sesame seeds','sesame.png'),(12,'sulphurdioxide','Sulphur dioxide','sulphurdioxide.png'),(13,'lupin','Lupin','lupin.png'),(14,'molluscs','Molluscs','molluscs.png');

--
-- Dumping data for table `barcodeean13`
--

INSERT INTO `barcodeean13` VALUES (1,'G',0,'2YTTTTTIIIII','','20VVViiiiiii','10VVVIIIIIII','2YTTTTTiiiii','2CCCCCCiiiii','2CCCCCCiiiii','2YTTTTTIIIII','20VVViiiiiii','10VVVIIIIIII','2YTTTTTiiiii','2CCCCCCiiiii','2CCCCCCiiiii','2CCCCCCIIIII');

--
-- Dumping data for table `bovine`
--


--
-- Dumping data for table `card`
--


--
-- Dumping data for table `cash`
--


--
-- Dumping data for table `cfgparams`
--

INSERT INTO `cfgparams` VALUES (1,'AI91',''),(2,'AI92',''),(3,'AI93',''),(4,'AI94',''),(5,'AI95',''),(6,'AI96',''),(7,'AI97',''),(8,'AI98',''),(9,'AI99','');

--
-- Dumping data for table `cfgsystem`
--

INSERT INTO `cfgsystem` VALUES (1,'simplified-invoice-serial','1500101'),(2,'forms-embedded-dp','1'),(3,'prices-without-taxes','0');

--
-- Dumping data for table `clientconfiguration`
--

INSERT INTO `clientconfiguration` VALUES (1,'ECI','face',0,0,1900,2,1,1,5,2,1,1,60,2,1,3600,0,'http://demo.q-matic.es:9094',0,'',0,0);

--
-- Dumping data for table `code128`
--


--
-- Dumping data for table `counterfamilies`
--

INSERT INTO `counterfamilies` VALUES (1,1,1,1),(2,1,2,2),(3,1,3,3),(4,1,4,4),(5,1,5,5),(6,1,6,6),(7,1,7,7);

--
-- Dumping data for table `counters`
--

INSERT INTO `counters` VALUES (1,'1','',0,'','','',1,0,'0000-00-00 00:00:00',0,'00:00:00',0,0,0,0,'','','','','','','','','','','');

--
-- Dumping data for table `customers`
--


--
-- Dumping data for table `ean128`
--


--
-- Dumping data for table `families`
--

INSERT INTO `families` VALUES (1,'BREBIS','BREBIOU.png','',0,''),(2,'CHEVRE','chabichou.png','',0,''),(3,'PREPARATIONS','fromage-blanc.png','',0,''),(4,'VACHE FRANCE','abondance.png','',0,''),(5,'VACHE HOLLANDE','gouda_jeune.png','',0,''),(6,'VACHE ITALIE','Gorgonzola-2.png','',0,''),(7,'VACHE SUISSE','emmental_suisse.png','',0,'');

--
-- Dumping data for table `fiscal`
--


--
-- Dumping data for table `hangedmarks`
--


--
-- Dumping data for table `itemgroupkeys`
--


--
-- Dumping data for table `itemgroupkeystext`
--


--
-- Dumping data for table `itemhabitual`
--


--
-- Dumping data for table `itemlinkcommon`
--


--
-- Dumping data for table `itemmiddleweights`
--


--
-- Dumping data for table `itemofferdates`
--


--
-- Dumping data for table `itemofferpricerates`
--


--
-- Dumping data for table `itempricerates`
--


--
-- Dumping data for table `items`
--

INSERT INTO `items` VALUES (1,0,0,'','','','','','','','',0,0,999,0,0,0,0,'',0.00,0,0.00,1,0,0,0,0,'',0,0,0.000,'','-',0,'','','','-',NULL,'','','',0,0.000,0,0,0.00000),(8,1001,0,'BREBIOU','BREBIOU','','','','','','',1,0,1,1,0,0,0,'',1.00,0,0.00,1,1001,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'BREBIOU.png','','',0,0.000,0,0,0.00000),(9,1002,0,'BRIQUE de BREBIS du FOREZ','BRIQUE de BREBIS du FOREZ','','','','','','',1,0,2,1,0,0,0,'',1.00,0,0.00,1,1002,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Brique-de-Brebis.png','','',0,0.000,0,0,0.00000),(10,1003,0,'BROUSSE DE BREBIS','BROUSSE DE BREBIS','','','','','','',1,0,3,1,0,0,0,'',1.00,0,0.00,1,1003,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brousse-de-brebis.png','','',0,0.000,0,0,0.00000),(14,1004,0,'ETCHOLA vache/brebis','ETCHOLA vache/brebis','','','','','','',1,0,4,1,0,0,0,'',1.00,0,0.00,1,1004,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'etchola.png','','',0,0.000,0,0,0.00000),(15,1005,0,'ETORKI','ETORKI','','','','','','',1,0,5,1,0,0,0,'',1.00,0,0.00,1,1005,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'etorki.png','','',0,0.000,0,0,0.00000),(16,1006,0,'FETA de BREBIS','FETA de BREBIS','','','','','','',1,0,6,1,0,0,0,'',1.00,0,0.00,1,1006,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Feta.png','','',0,0.000,0,0,0.00000),(17,1007,0,'KAIKOU Brebis','KAIKOU Brebis','','','','','','',1,0,7,1,0,0,0,'',1.00,0,0.00,1,1007,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'kaikou.png','','',0,0.000,0,0,0.00000),(18,1008,0,'MANCHEGO','MANCHEGO','','','','','','',1,0,8,1,0,0,0,'',1.00,0,0.00,1,1008,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'manchego.png','','',0,0.000,0,0,0.00000),(19,1009,0,'Pave de LOZERE','Pave de LOZERE','','','','','','',1,0,9,1,0,0,0,'',1.00,0,0.00,1,1009,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pave_lozere.png','','',0,0.000,0,0,0.00000),(20,1010,0,'PECORINO PEPATO','PECORINO PEPATO','','','','','','',1,0,10,1,0,0,0,'',1.00,0,0.00,1,1010,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pecorino.png','','',0,0.000,0,0,0.00000),(21,1011,0,'PECORINO ROMANO','PECORINO ROMANO','','','','','','',1,0,11,1,0,0,0,'',1.00,0,0.00,1,1011,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pecorino.png','','',0,0.000,0,0,0.00000),(22,1012,0,'PYRENEES PUR BREBIS','PYRENEES PUR BREBIS','','','','','','',1,0,12,1,0,0,0,'',1.00,0,0.00,1,1012,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pyrenee_brebis.png','','',0,0.000,0,0,0.00000),(23,1013,0,'RICOTTA de brebis','RICOTTA de brebis','','','','','','',1,0,13,1,0,0,0,'',1.00,0,0.00,1,1013,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'riccotta.png','','',0,0.000,0,0,0.00000),(24,1014,0,'ROQUEFORT  SOCIETE cave a','ROQUEFORT  SOCIETE cave a','','','','','','',1,0,14,1,0,0,0,'',1.00,0,0.00,1,1014,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'roquefort-societe.png','','',0,0.000,0,0,0.00000),(25,1015,0,'ROQUEFORT caves BARAGNAUD','ROQUEFORT caves BARAGNAUD','','','','','','',1,0,15,1,0,0,0,'',1.00,0,0.00,1,1015,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'roquefort-societe.png','','',0,0.000,0,0,0.00000),(26,1016,0,'ROQUEFORT PAPILLON','ROQUEFORT PAPILLON','','','','','','',1,0,16,1,0,0,0,'',1.00,0,0.00,1,1016,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'roquefort-papillon.png','','',0,0.000,0,0,0.00000),(27,1017,0,'ROQUEFORT PEG','ROQUEFORT PEG','','','','','','',1,0,17,1,0,0,0,'',1.00,0,0.00,1,1017,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'roquefort-societe.png','','',0,0.000,0,0,0.00000),(28,1018,0,'ROQUEFORT RDF','ROQUEFORT RDF','','','','','','',1,0,18,1,0,0,0,'',1.00,0,0.00,1,1018,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'roquefort-societe.png','','',0,0.000,0,0,0.00000),(29,1019,0,'TOMME de BREBIS corse','TOMME de BREBIS corse','','','','','','',1,0,19,1,0,0,0,'',1.00,0,0.00,1,1019,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tome.png','','',0,0.000,0,0,0.00000),(30,1020,0,'CORSICA','CORSICA','','','','','','',1,0,20,1,0,0,0,'',1.00,0,0.00,1,1020,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'corsica.png','','',0,0.000,0,0,0.00000),(31,1021,0,'CORSU VECCHIU','CORSU VECCHIU','','','','','','',1,0,21,1,0,0,0,'',1.00,0,0.00,1,1021,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'corsu_vecchiu.png','','',0,0.000,0,0,0.00000),(32,1022,0,'OSSAU IRATY','OSSAU IRATY','','','','','','',1,0,22,1,0,0,0,'',1.00,0,0.00,1,1022,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'ossau-iraty.png','','',0,0.000,0,0,0.00000),(33,1023,0,'OSSAU IRATY ISTARA','OSSAU IRATY ISTARA','','','','','','',1,0,23,1,0,0,0,'',1.00,0,0.00,1,1023,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'ossau-iraty.png','','',0,0.000,0,0,0.00000),(34,1024,0,'OSSAU IRATY RDF','OSSAU IRATY RDF','','','','','','',1,0,24,1,0,0,0,'',1.00,0,0.00,1,1024,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'ossau-iraty.png','','',0,0.000,0,0,0.00000),(35,1025,0,'PERAIL des ALIZIERS','PERAIL des ALIZIERS','','','','','','',1,0,25,1,0,0,0,'',1.00,0,0.00,0,1025,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'perail.png','','',0,0.000,0,0,0.00000),(36,1026,0,'PERAIL des ALIZIERS X 2','PERAIL des ALIZIERS X 2','','','','','','',1,0,26,1,0,0,0,'',1.00,0,0.00,0,1026,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'perail.png','','',0,0.000,0,0,0.00000),(37,1027,0,'PERAIL LOU PERAC','PERAIL LOU PERAC','','','','','','',1,0,27,1,0,0,0,'',1.00,0,0.00,0,1027,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'perail.png','','',0,0.000,0,0,0.00000),(38,1028,0,'PERAIL LOU PERAC  X2','PERAIL LOU PERAC  X2','','','','','','',1,0,28,1,0,0,0,'',1.00,0,0.00,0,1028,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'perail.png','','',0,0.000,0,0,0.00000),(39,2001,0,'BOUCHON de CHEVRE','BOUCHON de CHEVRE','','','','','','',2,0,1,1,0,0,0,'',1.00,0,0.00,0,2001,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bouchon-de-chevre.png','','',0,0.000,0,0,0.00000),(40,2002,0,'BOUCHON de CHEVRE  X2','BOUCHON de CHEVRE  X2','','','','','','',2,0,2,1,0,0,0,'',1.00,0,0.00,0,2002,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bouchon-de-chevre.png','','',0,0.000,0,0,0.00000),(41,2003,0,'BOUCHON de CHEVRE X3','BOUCHON de CHEVRE X3','','','','','','',2,0,3,1,0,0,0,'',1.00,0,0.00,0,2003,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bouchon-de-chevre.png','','',0,0.000,0,0,0.00000),(42,2004,0,'BOUCHON de CHEVRE X4','BOUCHON de CHEVRE X4','','','','','','',2,0,4,1,0,0,0,'',1.00,0,0.00,0,2004,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bouchon-de-chevre.png','','',0,0.000,0,0,0.00000),(43,2005,0,'BOUTON DE CHEVRE FERMIER','BOUTON DE CHEVRE FERMIER','','','','','','',2,0,5,1,0,0,0,'',1.00,0,0.00,0,2005,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Bouton-chevre.png','','',0,0.000,0,0,0.00000),(44,2006,0,'BUCHE de CHEVRE','BUCHE de CHEVRE','','','','','','',2,0,6,1,0,0,0,'',1.00,0,0.00,0,2006,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'buche_chevre.png','','',0,0.000,0,0,0.00000),(45,2007,0,'CABECOU aux LARDONS','CABECOU aux LARDONS','','','','','','',2,0,7,1,0,0,0,'',1.00,0,0.00,0,2007,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cabecou.png','','',0,0.000,0,0,0.00000),(46,2008,0,'CABECOU du Lot','CABECOU du Lot','','','','','','',2,0,8,1,0,0,0,'',1.00,0,0.00,0,2008,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cabecou.png','','',0,0.000,0,0,0.00000),(47,2009,0,'CABECOU du Lot X 2','CABECOU du Lot X 2','','','','','','',2,0,9,1,0,0,0,'',1.00,0,0.00,0,2009,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cabecou.png','','',0,0.000,0,0,0.00000),(48,2010,0,'CABRI','CABRI','','','','','','',2,0,10,1,0,0,0,'',1.00,0,0.00,0,2010,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cabri.png','','',0,0.000,0,0,0.00000),(49,2011,0,'CHABICHOU  du Poitou','CHABICHOU  du Poitou','','','','','','',2,0,11,1,0,0,0,'',1.00,0,0.00,0,2011,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'chabichou.png','','',0,0.000,0,0,0.00000),(50,2012,0,'CHAROLLAIS FRAIS','CHAROLLAIS FRAIS','','','','','','',2,0,12,1,0,0,0,'',1.00,0,0.00,0,2012,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Charolais.png','','',0,0.000,0,0,0.00000),(51,2013,0,'CHAROLLAIS SEC','CHAROLLAIS SEC','','','','','','',2,0,13,1,0,0,0,'',1.00,0,0.00,0,2013,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Charolais.png','','',0,0.000,0,0,0.00000),(52,2014,0,'CROTTIN CHAVIGNOL','CROTTIN CHAVIGNOL','','','','','','',2,0,14,1,0,0,0,'',1.00,0,0.00,0,2014,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'crottin-de-chavignol.png','','',0,0.000,0,0,0.00000),(53,2015,0,'CROTTIN CHAVIGNOL fermier','CROTTIN CHAVIGNOL fermier','','','','','','',2,0,15,1,0,0,0,'',1.00,0,0.00,0,2015,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'crottin-de-chavignol.png','','',0,0.000,0,0,0.00000),(54,2016,0,'CROTTIN CHAVIGNOL X2','CROTTIN CHAVIGNOL X2','','','','','','',2,0,16,1,0,0,0,'',1.00,0,0.00,0,2016,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'crottin-de-chavignol.png','','',0,0.000,0,0,0.00000),(55,2017,0,'PICODON','PICODON','','','','','','',2,0,17,1,0,0,0,'',1.00,0,0.00,0,2017,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'picodon.png','','',0,0.000,0,0,0.00000),(56,2018,0,'PICODON AOC NU','PICODON AOC NU','','','','','','',2,0,18,1,0,0,0,'',1.00,0,0.00,0,2018,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'picodon.png','','',0,0.000,0,0,0.00000),(57,2019,0,'PYRAMIDE de VALENCAIS','PYRAMIDE de VALENCAIS','','','','','','',2,0,19,1,0,0,0,'',1.00,0,0.00,0,2019,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pyramide-valencay.png','','',0,0.000,0,0,0.00000),(58,2020,0,'PYRAMIDE de VALENCAY 1/2','PYRAMIDE de VALENCAY 1/2','','','','','','',2,0,20,1,0,0,0,'',1.00,0,0.00,0,2020,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pyramide-valencay.png','','',0,0.000,0,0,0.00000),(59,2021,0,'PYRENEES chevre/brebis','PYRENEES chevre/brebis','','','','','','',2,0,21,1,0,0,0,'',1.00,0,0.00,0,2021,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pyrenee_brebis.png','','',0,0.000,0,0,0.00000),(60,2022,0,'ROCAMADOUR','ROCAMADOUR','','','','','','',2,0,22,1,0,0,0,'',1.00,0,0.00,0,2022,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'rocamadour.png','','',0,0.000,0,0,0.00000),(61,2023,0,'ROCAMADOUR x2','ROCAMADOUR x2','','','','','','',2,0,23,1,0,0,0,'',1.00,0,0.00,0,2023,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'rocamadour.png','','',0,0.000,0,0,0.00000),(62,2024,0,'ROCAMADOUR X3','ROCAMADOUR X3','','','','','','',2,0,24,1,0,0,0,'',1.00,0,0.00,0,2024,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'rocamadour.png','','',0,0.000,0,0,0.00000),(63,2025,0,'ROCAMADOUR X4','ROCAMADOUR X4','','','','','','',2,0,25,1,0,0,0,'',1.00,0,0.00,0,2025,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'rocamadour.png','','',0,0.000,0,0,0.00000),(64,2026,0,'TOMME  de CHEVRE','TOMME  de CHEVRE','','','','','','',2,0,26,1,0,0,0,'',1.00,0,0.00,1,2026,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-chevre.png','','',0,0.000,0,0,0.00000),(65,2027,0,'VALENCAY','VALENCAY','','','','','','',2,0,27,1,0,0,0,'',1.00,0,0.00,1,2027,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'valencay.png','','',0,0.000,0,0,0.00000),(66,2028,0,'PETIT BILLY nu','PETIT BILLY nu','','','','','','',2,0,28,1,0,0,0,'',1.00,0,0.00,0,2028,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'chabichou.png','','',0,0.000,0,0,0.00000),(67,2029,0,'SECHON DE CHEVRE','SECHON DE CHEVRE','','','','','','',2,0,29,1,0,0,0,'',1.00,0,0.00,0,2029,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'sechon-chevre.png','','',0,0.000,0,0,0.00000),(68,2030,0,'SECHON DE CHEVRE X2','SECHON DE CHEVRE X2','','','','','','',2,0,30,1,0,0,0,'',1.00,0,0.00,0,2030,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'sechon-chevre.png','','',0,0.000,0,0,0.00000),(69,2031,0,'TOMMETTE DE CHEVRE','TOMMETTE DE CHEVRE','','','','','','',2,0,31,1,0,0,0,'',1.00,0,0.00,0,2031,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tommette_chevre.png','','',0,0.000,0,0,0.00000),(70,2032,0,'MOTHAIS sur FEUILLE','MOTHAIS sur FEUILLE','','','','','','',2,0,32,1,0,0,0,'',1.00,0,0.00,0,2032,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'mothais-sur-feuille.png','','',0,0.000,0,0,0.00000),(71,2033,0,'PELARDON','PELARDON','','','','','','',2,0,33,1,0,0,0,'',1.00,0,0.00,0,2033,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pelardon.png','','',0,0.000,0,0,0.00000),(72,2034,0,'PELARDON X2','PELARDON X2','','','','','','',2,0,34,1,0,0,0,'',1.00,0,0.00,0,2034,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pelardon.png','','',0,0.000,0,0,0.00000),(73,3001,0,'ALIGOT FRAIS DE L\'AUBRAC','ALIGOT FRAIS DE L\'AUBRAC','','','','','','',3,0,1,1,0,0,0,'',1.00,0,0.00,0,3001,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'aligot_frais.png','','',0,0.000,0,0,0.00000),(74,3002,0,'BONBEL','BONBEL','','','','','','',3,0,2,1,0,0,0,'',1.00,0,0.00,0,3002,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bonbel.png','','',0,0.000,0,0,0.00000),(75,3003,0,'BROCCIU POT','BROCCIU POT','','','','','','',3,0,3,1,0,0,0,'',1.00,0,0.00,0,3003,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Brocciu_pot.png','','',0,0.000,0,0,0.00000),(76,3004,0,'CHIMAY A LA BIERE','CHIMAY A LA BIERE','','','','','','',3,0,4,1,0,0,0,'',1.00,0,0.00,1,3004,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Chimay_biere.png','','',0,0.000,0,0,0.00000),(77,3005,0,'CREME FRAICHE  EPAISSE','CREME FRAICHE  EPAISSE','','','','','','',3,0,5,1,0,0,0,'',1.00,0,0.00,1,3005,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'creme-faiche-epaisse.png','','',0,0.000,0,0,0.00000),(78,3006,0,'FROMAGE BLANC de campagne','FROMAGE BLANC de campagne','','','','','','',3,0,6,1,0,0,0,'',1.00,0,0.00,1,3006,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'fromage-blanc.png','','',0,0.000,0,0,0.00000),(79,3007,0,'FROMAGE BLANC Faisselle a','FROMAGE BLANC Faisselle a','','','','','','',3,0,7,1,0,0,0,'',1.00,0,0.00,1,3007,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'fromage-blanc.png','','',0,0.000,0,0,0.00000),(80,3008,0,'FROMAGE pour TARTIFLETTE','FROMAGE pour TARTIFLETTE','','','','','','',3,0,8,1,0,0,0,'',1.00,0,0.00,0,3008,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Fromage_tartiflette.png','','',0,0.000,0,0,0.00000),(81,3009,0,'LEERDAMER CARACTERE','LEERDAMER CARACTERE','','','','','','',3,0,9,1,0,0,0,'',1.00,0,0.00,1,3009,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'leerdammer.png','','',0,0.000,0,0,0.00000),(82,3010,0,'LEERDAMMER','LEERDAMMER','','','','','','',3,0,10,1,0,0,0,'',1.00,0,0.00,1,3010,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'leerdammer.png','','',0,0.000,0,0,0.00000),(83,3011,0,'LEERDAMMER Ligne','LEERDAMMER Ligne','','','','','','',3,0,11,1,0,0,0,'',1.00,0,0.00,1,3011,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'leerdammer.png','','',0,0.000,0,0,0.00000),(84,3012,0,'LIGNE & PLAISIR','LIGNE & PLAISIR','','','','','','',3,0,12,1,0,0,0,'',1.00,0,0.00,1,3012,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'ligne_plaisir.png','','',0,0.000,0,0,0.00000),(85,3013,0,'MASCARPONE au GORGONZOLA','MASCARPONE au GORGONZOLA','','','','','','',3,0,13,1,0,0,0,'',1.00,0,0.00,1,3013,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'mascarpone-gorgonzola.png','','',0,0.000,0,0,0.00000),(86,3014,0,'P\'TIT BASQUE','P\'TIT BASQUE','','','','','','',3,0,14,1,0,0,0,'',1.00,0,0.00,1,3014,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'p-tit-basque.png','','',0,0.000,0,0,0.00000),(87,3015,0,'RAMBOL fourre noix','RAMBOL fourre noix','','','','','','',3,0,15,1,0,0,0,'',1.00,0,0.00,1,3015,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'rambol_noix.png','','',0,0.000,0,0,0.00000),(88,3016,0,'ROULE AIL & FINES HERBES','ROULE AIL & FINES HERBES','','','','','','',3,0,16,1,0,0,0,'',1.00,0,0.00,1,3016,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'roule-a-l-ail.png','','',0,0.000,0,0,0.00000),(89,3017,0,'VIEUX  PANE','VIEUX  PANE','','','','','','',3,0,17,1,0,0,0,'',1.00,0,0.00,1,3017,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'vieux_pane.png','','',0,0.000,0,0,0.00000),(90,3018,0,'CHAMOIS d\'OR','CHAMOIS d\'OR','','','','','','',3,0,18,1,0,0,0,'',1.00,0,0.00,1,3018,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'chamois_or.png','','',0,0.000,0,0,0.00000),(91,3019,0,'CHAUMES','CHAUMES','','','','','','',3,0,19,1,0,0,0,'',1.00,0,0.00,1,3019,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'chaume.png','','',0,0.000,0,0,0.00000),(92,3020,0,'FOL EPI','FOL EPI','','','','','','',3,0,20,1,0,0,0,'',1.00,0,0.00,1,3020,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'fol_epi.png','','',0,0.000,0,0,0.00000),(93,3021,0,'GATEAU ST AMOUR Nature','GATEAU ST AMOUR Nature','','','','','','',3,0,21,1,0,0,0,'',1.00,0,0.00,1,3021,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'saint_amour.png','','',0,0.000,0,0,0.00000),(94,3022,0,'LE BRIN D\'AFFINOIS','LE BRIN D\'AFFINOIS','','','','','','',3,0,22,1,0,0,0,'',1.00,0,0.00,1,3022,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brin_affinois.png','','',0,0.000,0,0,0.00000),(95,3023,0,'PAVE d\'AFFINOIS','PAVE d\'AFFINOIS','','','','','','',3,0,23,1,0,0,0,'',1.00,0,0.00,0,3023,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pave_affinois.png','','',0,0.000,0,0,0.00000),(96,3024,0,'PAVE d\'AFFINOIS leger','PAVE d\'AFFINOIS leger','','','','','','',3,0,24,1,0,0,0,'',1.00,0,0.00,0,3024,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pave_affinois.png','','',0,0.000,0,0,0.00000),(97,3025,0,'PAVE d\'AFFINOIS LOT X2','PAVE d\'AFFINOIS LOT X2','','','','','','',3,0,25,1,0,0,0,'',1.00,0,0.00,0,3025,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pave_affinois.png','','',0,0.000,0,0,0.00000),(98,3026,0,'CARRE d\'AURILLAC','CARRE d\'AURILLAC','','','','','','',3,0,26,1,0,0,0,'',1.00,0,0.00,1,3026,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'carre-d-aurillac.png','','',0,0.000,0,0,0.00000),(99,3027,0,'CHISTOU','CHISTOU','','','','','','',3,0,27,1,0,0,0,'',1.00,0,0.00,1,3027,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'CHISTOU.png','','',0,0.000,0,0,0.00000),(100,3028,0,'MERZER','MERZER','','','','','','',3,0,28,1,0,0,0,'',1.00,0,0.00,1,3028,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'merzer.png','','',0,0.000,0,0,0.00000),(101,3029,0,'MINI MONT D\'OR AOC','MINI MONT D\'OR AOC','','','','','','',3,0,29,1,0,0,0,'',1.00,0,0.00,1,3029,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Mini_Mont_dor.png','','',0,0.000,0,0,0.00000),(102,3030,0,'SAINT AGUR','SAINT AGUR','','','','','','',3,0,30,1,0,0,0,'',1.00,0,0.00,1,3030,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'saint_agur.png','','',0,0.000,0,0,0.00000),(103,4001,0,'ABONDANCE Fermier','ABONDANCE Fermier','','','','','','',4,0,1,1,0,0,0,'',1.00,0,0.00,1,4001,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'abondance.png','','',0,0.000,0,0,0.00000),(104,4002,0,'ABONDANCE fruitier','ABONDANCE fruitier','','','','','','',4,0,2,1,0,0,0,'',1.00,0,0.00,1,4002,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'abondance.png','','',0,0.000,0,0,0.00000),(105,4003,0,'ABONDANCE laitier','ABONDANCE laitier','','','','','','',4,0,3,1,0,0,0,'',1.00,0,0.00,1,4003,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'abondance.png','','',0,0.000,0,0,0.00000),(106,4004,0,'APPENZELLER','APPENZELLER','','','','','','',4,0,4,1,0,0,0,'',1.00,0,0.00,1,4004,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'appenzeller-fromage.png','','',0,0.000,0,0,0.00000),(107,4005,0,'BEAUFORT','BEAUFORT','','','','','','',4,0,5,1,0,0,0,'',1.00,0,0.00,1,4005,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'beaufort.png','','',0,0.000,0,0,0.00000),(108,4006,0,'BEAUFORT d\'ALPAGE','BEAUFORT d\'ALPAGE','','','','','','',4,0,6,1,0,0,0,'',1.00,0,0.00,1,4006,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'beaufort.png','','',0,0.000,0,0,0.00000),(109,4007,0,'BEAUFORT POINTE PERCEE','BEAUFORT POINTE PERCEE','','','','','','',4,0,7,1,0,0,0,'',1.00,0,0.00,1,4007,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'beaufort.png','','',0,0.000,0,0,0.00000),(110,4008,0,'BETHMALE','BETHMALE','','','','','','',4,0,8,1,0,0,0,'',1.00,0,0.00,1,4008,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bethmale.png','','',0,0.000,0,0,0.00000),(111,4009,0,'BLEU AERELE doux','BLEU AERELE doux','','','','','','',4,0,9,1,0,0,0,'',1.00,0,0.00,1,4009,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Bleu-aerelle.png','','',0,0.000,0,0,0.00000),(112,4010,0,'BLEU BAVIERE','BLEU BAVIERE','','','','','','',4,0,10,1,0,0,0,'',1.00,0,0.00,1,4010,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu-de-baviere.png','','',0,0.000,0,0,0.00000),(113,4011,0,'BLEU d\'AUVERGNE','BLEU d\'AUVERGNE','','','','','','',4,0,11,1,0,0,0,'',1.00,0,0.00,1,4011,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu_auvergne.png','','',0,0.000,0,0,0.00000),(114,4012,0,'BLEU de BREBIS','BLEU de BREBIS','','','','','','',4,0,12,1,0,0,0,'',1.00,0,0.00,1,4012,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu-de-brebis.png','','',0,0.000,0,0,0.00000),(115,4013,0,'BLEU de GEX','BLEU de GEX','','','','','','',4,0,13,1,0,0,0,'',1.00,0,0.00,1,4013,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu-de-gex.png','','',0,0.000,0,0,0.00000),(116,4014,0,'BLEU de LAQUEUILLE','BLEU de LAQUEUILLE','','','','','','',4,0,14,1,0,0,0,'',1.00,0,0.00,1,4014,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu.png','','',0,0.000,0,0,0.00000),(117,4015,0,'BLEU de LOZERE','BLEU de LOZERE','','','','','','',4,0,15,1,0,0,0,'',1.00,0,0.00,1,4015,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu.png','','',0,0.000,0,0,0.00000),(118,4016,0,'BLEU de PAYS','BLEU de PAYS','','','','','','',4,0,16,1,0,0,0,'',1.00,0,0.00,1,4016,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu.png','','',0,0.000,0,0,0.00000),(119,4017,0,'BLEU des CAUSSES','BLEU des CAUSSES','','','','','','',4,0,17,1,0,0,0,'',1.00,0,0.00,1,4017,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu.png','','',0,0.000,0,0,0.00000),(120,4018,0,'BLEU du BERGER','BLEU du BERGER','','','','','','',4,0,18,1,0,0,0,'',1.00,0,0.00,1,4018,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu.png','','',0,0.000,0,0,0.00000),(121,4019,0,'BLEU la ROCHE','BLEU la ROCHE','','','','','','',4,0,19,1,0,0,0,'',1.00,0,0.00,1,4019,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu.png','','',0,0.000,0,0,0.00000),(122,4020,0,'BLEU SASSENAGE','BLEU SASSENAGE','','','','','','',4,0,20,1,0,0,0,'',1.00,0,0.00,1,4020,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'bleu.png','','',0,0.000,0,0,0.00000),(123,4021,0,'BREZAIN','BREZAIN','','','','','','',4,0,21,1,0,0,0,'',1.00,0,0.00,1,4021,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brezain.png','','',0,0.000,0,0,0.00000),(124,4022,0,'BRIE de MEAUX  3/4 affin','BRIE de MEAUX  3/4 affin','','','','','','',4,0,22,1,0,0,0,'',1.00,0,0.00,1,4022,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brie_pasteurise.png','','',0,0.000,0,0,0.00000),(125,4023,0,'BRIE de MEAUX 1/2 affin','BRIE de MEAUX 1/2 affin','','','','','','',4,0,23,1,0,0,0,'',1.00,0,0.00,1,4023,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brie_pasteurise.png','','',0,0.000,0,0,0.00000),(126,4024,0,'BRIE DE MELUN 3/4 AFFINE','BRIE DE MELUN 3/4 AFFINE','','','','','','',4,0,24,1,0,0,0,'',1.00,0,0.00,1,4024,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brie-de-melun.png','','',0,0.000,0,0,0.00000),(127,4025,0,'BRIE DE MELUN AOC','BRIE DE MELUN AOC','','','','','','',4,0,25,1,0,0,0,'',1.00,0,0.00,1,4025,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brie-de-melun.png','','',0,0.000,0,0,0.00000),(128,4026,0,'BRIE Pasteurise','BRIE Pasteurise','','','','','','',4,0,26,1,0,0,0,'',1.00,0,0.00,1,4026,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brie_pasteurise.png','','',0,0.000,0,0,0.00000),(129,4027,0,'BRIE ROITELET','BRIE ROITELET','','','','','','',4,0,27,1,0,0,0,'',1.00,0,0.00,1,4027,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brie_roitelet.png','','',0,0.000,0,0,0.00000),(130,4028,0,'BRILLAT SAVARIN','BRILLAT SAVARIN','','','','','','',4,0,28,1,0,0,0,'',1.00,0,0.00,1,4028,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brillat-savarin.png','','',0,0.000,0,0,0.00000),(131,4029,0,'BRILLAT SAVARIN FRAIS','BRILLAT SAVARIN FRAIS','','','','','','',4,0,29,1,0,0,0,'',1.00,0,0.00,1,4029,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'brillat-savarin.png','','',0,0.000,0,0,0.00000),(132,4030,0,'CAMEMBERT CALVA','CAMEMBERT CALVA','','','','','','',4,0,30,1,0,0,0,'',1.00,0,0.00,1,4030,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'camembert-calvados.png','','',0,0.000,0,0,0.00000),(133,4031,0,'CAMEMBERT de NORMANDIE','CAMEMBERT de NORMANDIE','','','','','','',4,0,31,1,0,0,0,'',1.00,0,0.00,1,4031,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'camembert_normandie.png','','',0,0.000,0,0,0.00000),(134,4032,0,'CANTAL doux','CANTAL doux','','','','','','',4,0,32,1,0,0,0,'',0.00,0,0.00,1,4032,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cantal.png','','',0,0.000,0,0,0.00000),(135,4033,0,'CANTAL doux   AOC','CANTAL doux   AOC','','','','','','',4,0,33,1,0,0,0,'',1.00,0,0.00,1,4033,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cantal.png','','',0,0.000,0,0,0.00000),(136,4034,0,'CANTAL ENTRE 2','CANTAL ENTRE 2','','','','','','',4,0,34,1,0,0,0,'',1.00,0,0.00,1,4034,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cantal.png','','',0,0.000,0,0,0.00000),(137,4035,0,'CANTAL entre 2 lait cru','CANTAL entre 2 lait cru','','','','','','',4,0,35,1,0,0,0,'',1.00,0,0.00,1,4035,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cantal.png','','',0,0.000,0,0,0.00000),(138,4036,0,'CANTAL jeune','CANTAL jeune','','','','','','',4,0,36,1,0,0,0,'',1.00,0,0.00,1,4036,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cantal.png','','',0,0.000,0,0,0.00000),(139,4037,0,'CANTAL vieux AOC','CANTAL vieux AOC','','','','','','',4,0,37,1,0,0,0,'',1.00,0,0.00,1,4037,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cantal.png','','',0,0.000,0,0,0.00000),(140,4038,0,'CHAOURCE AOC','CHAOURCE AOC','','','','','','',4,0,38,1,0,0,0,'',1.00,0,0.00,1,4038,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'chaource.png','','',0,0.000,0,0,0.00000),(141,4039,0,'CHAOURCE RDF','CHAOURCE RDF','','','','','','',4,0,39,1,0,0,0,'',1.00,0,0.00,1,4039,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'chaource.png','','',0,0.000,0,0,0.00000),(142,4040,0,'COMTE  AOC','COMTE  AOC','','','','','','',4,0,40,1,0,0,0,'',1.00,0,0.00,1,4040,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'comte.png','','',0,0.000,0,0,0.00000),(143,4041,0,'COMTE 18 MOIS','COMTE 18 MOIS','','','','','','',4,0,41,1,0,0,0,'',1.00,0,0.00,1,4041,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'comte.png','','',0,0.000,0,0,0.00000),(144,4042,0,'COMTE EXTRA DOUX','COMTE EXTRA DOUX','','','','','','',4,0,42,1,0,0,0,'',1.00,0,0.00,1,4042,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'comte.png','','',0,0.000,0,0,0.00000),(145,4043,0,'COMTE EXTRA FRUITE','COMTE EXTRA FRUITE','','','','','','',4,0,43,1,0,0,0,'',1.00,0,0.00,1,4043,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'comte.png','','',0,0.000,0,0,0.00000),(146,4044,0,'COMTE extra RDF','COMTE extra RDF','','','','','','',4,0,44,1,0,0,0,'',1.00,0,0.00,1,4044,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'comte.png','','',0,0.000,0,0,0.00000),(147,4045,0,'COMTE EXTRA VIEILLE RESER','COMTE EXTRA VIEILLE RESER','','','','','','',4,0,45,1,0,0,0,'',1.00,0,0.00,1,4045,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'comte.png','','',0,0.000,0,0,0.00000),(148,4046,0,'COMTE**','COMTE**','','','','','','',4,0,46,1,0,0,0,'',1.00,0,0.00,1,4046,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'comte.png','','',0,0.000,0,0,0.00000),(149,4047,0,'EMMENTAL BIO','EMMENTAL BIO','','','','','','',4,0,47,1,0,0,0,'',1.00,0,0.00,1,4047,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'emmental.png','','',0,0.000,0,0,0.00000),(150,4048,0,'EMMENTAL','EMMENTAL','','','','','','',4,0,48,1,0,0,0,'',0.00,0,0.00,1,4048,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'emmental.png','','',0,0.000,0,0,0.00000),(151,4049,0,'EMMENTAL grand cru','EMMENTAL grand cru','','','','','','',4,0,49,1,0,0,0,'',1.00,0,0.00,1,4049,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'emmental.png','','',0,0.000,0,0,0.00000),(152,4050,0,'EMMENTAL Label Savoie RDF','EMMENTAL Label Savoie RDF','','','','','','',4,0,50,1,0,0,0,'',1.00,0,0.00,1,4050,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'emmental.png','','',0,0.000,0,0,0.00000),(153,4051,0,'EPOISSE AFFINEE','EPOISSE AFFINEE','','','','','','',4,0,51,1,0,0,0,'',1.00,0,0.00,1,4051,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'comte.png','','',0,0.000,0,0,0.00000),(154,4052,0,'FOURME d\'AMBERT','FOURME d\'AMBERT','','','','','','',4,0,52,1,0,0,0,'',1.00,0,0.00,1,4052,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'fourme-d-ambert.png','','',0,0.000,0,0,0.00000),(155,4053,0,'FOURME de MONTBRISON','FOURME de MONTBRISON','','','','','','',4,0,53,1,0,0,0,'',1.00,0,0.00,1,4053,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'fourme_monbrison.png','','',0,0.000,0,0,0.00000),(156,4054,0,'FOURME des Monts ISSYNGEA','FOURME des Monts ISSYNGEA','','','','','','',4,0,54,1,0,0,0,'',1.00,0,0.00,1,4054,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'fourme-d-yssingeaux.png','','',0,0.000,0,0,0.00000),(157,4055,0,'GRUYERE DE SAVOIE','GRUYERE DE SAVOIE','','','','','','',4,0,55,1,0,0,0,'',1.00,0,0.00,1,4055,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gruyere-suisse.png','','',0,0.000,0,0,0.00000),(158,4056,0,'LAGUIOLE','LAGUIOLE','','','','','','',4,0,56,1,0,0,0,'',1.00,0,0.00,1,4056,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'laguiole.png','','',0,0.000,0,0,0.00000),(159,4057,0,'LANGRES','LANGRES','','','','','','',4,0,57,1,0,0,0,'',1.00,0,0.00,1,4057,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'langres.png','','',0,0.000,0,0,0.00000),(160,4058,0,'LIVAROT','LIVAROT','','','','','','',4,0,58,1,0,0,0,'',1.00,0,0.00,1,4058,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'livarot.png','','',0,0.000,0,0,0.00000),(161,4059,0,'MAROILLES AOC','MAROILLES AOC','','','','','','',4,0,59,1,0,0,0,'',1.00,0,0.00,1,4059,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'maroille.png','','',0,0.000,0,0,0.00000),(162,4060,0,'MUNSTER  Ermitage AOC','MUNSTER  Ermitage AOC','','','','','','',4,0,60,1,0,0,0,'',1.00,0,0.00,1,4060,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'munster.png','','',0,0.000,0,0,0.00000),(163,4061,0,'MUNSTER  GEROME au lait c','MUNSTER  GEROME au lait c','','','','','','',4,0,61,1,0,0,0,'',1.00,0,0.00,1,4061,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'munster.png','','',0,0.000,0,0,0.00000),(164,4062,0,'MUNSTER fermier AOC','MUNSTER fermier AOC','','','','','','',4,0,62,1,0,0,0,'',1.00,0,0.00,1,4062,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'munster.png','','',0,0.000,0,0,0.00000),(165,4063,0,'MUNSTER GEROME au cumin','MUNSTER GEROME au cumin','','','','','','',4,0,63,1,0,0,0,'',1.00,0,0.00,1,4063,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'munster.png','','',0,0.000,0,0,0.00000),(166,4064,0,'MUNSTER Lisbeth','MUNSTER Lisbeth','','','','','','',4,0,64,1,0,0,0,'',1.00,0,0.00,1,4064,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'munster.png','','',0,0.000,0,0,0.00000),(167,4065,0,'PONT L\'EVEQUE','PONT L\'EVEQUE','','','','','','',4,0,65,1,0,0,0,'',1.00,0,0.00,1,4065,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pont_eveque.png','','',0,0.000,0,0,0.00000),(168,4066,0,'PYRENEES fermier de vache','PYRENEES fermier de vache','','','','','','',4,0,66,1,0,0,0,'',1.00,0,0.00,1,4066,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'pyrenees-vache.png','','',0,0.000,0,0,0.00000),(169,4067,0,'RACLETTE arom Moutarde','RACLETTE arom Moutarde','','','','','','',4,0,67,1,0,0,0,'',1.00,0,0.00,1,4067,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'raclette-aromatisee-moutarde.png','','',0,0.000,0,0,0.00000),(170,4068,0,'RACLETTE au POIVRE','RACLETTE au POIVRE','','','','','','',4,0,68,1,0,0,0,'',1.00,0,0.00,1,4068,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'raclette-au-poivre.png','','',0,0.000,0,0,0.00000),(171,4069,0,'RACLETTE de SAVOIE au lai','RACLETTE de SAVOIE au lai','','','','','','',4,0,69,1,0,0,0,'',1.00,0,0.00,1,4069,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'raclette-savoie.png','','',0,0.000,0,0,0.00000),(172,4070,0,'RACLETTE en tranchette','RACLETTE en tranchette','','','','','','',4,0,70,1,0,0,0,'',1.00,0,0.00,1,4070,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'raclette_pasteurisé.png','','',0,0.000,0,0,0.00000),(173,4071,0,'RACLETTE pasteurisee','RACLETTE pasteurisee','','','','','','',4,0,71,1,0,0,0,'',1.00,0,0.00,1,4071,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'raclette_pasteurisé.png','','',0,0.000,0,0,0.00000),(174,4072,0,'RACLETTE RICHES MONTS','RACLETTE RICHES MONTS','','','','','','',4,0,72,1,0,0,0,'',1.00,0,0.00,1,4072,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'raclette_rich.png','','',0,0.000,0,0,0.00000),(175,4073,0,'RACLETTE VIN FRANCHE COMT','RACLETTE VIN FRANCHE COMT','','','','','','',4,0,73,1,0,0,0,'',1.00,0,0.00,1,4073,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'raclette_tranchette.png','','',0,0.000,0,0,0.00000),(176,4074,0,'REBLOCHON  fruitier','REBLOCHON  fruitier','','','','','','',4,0,74,1,0,0,0,'',1.00,0,0.00,1,4074,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'reblochon.png','','',0,0.000,0,0,0.00000),(177,4075,0,'REBLOCHON fermier','REBLOCHON fermier','','','','','','',4,0,75,1,0,0,0,'',1.00,0,0.00,1,4075,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'reblochon.png','','',0,0.000,0,0,0.00000),(178,4076,0,'REBLOCHON FRUITIER','REBLOCHON FRUITIER','','','','','','',4,0,76,1,0,0,0,'',1.00,0,0.00,1,4076,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'reblochon.png','','',0,0.000,0,0,0.00000),(179,4077,0,'ST FELICIEN A LA LYONNAIS','ST FELICIEN A LA LYONNAIS','','','','','','',4,0,77,1,0,0,0,'',1.00,0,0.00,1,4077,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_felicien.png','','',0,0.000,0,0,0.00000),(180,4078,0,'ST FELICIEN ALLEGE','ST FELICIEN ALLEGE','','','','','','',4,0,78,1,0,0,0,'',1.00,0,0.00,1,4078,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_felicien.png','','',0,0.000,0,0,0.00000),(181,4079,0,'ST FELICIEN coupelle','ST FELICIEN coupelle','','','','','','',4,0,79,1,0,0,0,'',1.00,0,0.00,1,4079,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_felicien.png','','',0,0.000,0,0,0.00000),(182,4080,0,'ST FELICIEN NU','ST FELICIEN NU','','','','','','',4,0,80,1,0,0,0,'',1.00,0,0.00,1,4080,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_felicien.png','','',0,0.000,0,0,0.00000),(183,4081,0,'ST FELICIEN TENTATION','ST FELICIEN TENTATION','','','','','','',4,0,81,1,0,0,0,'',1.00,0,0.00,1,4081,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_felicien.png','','',0,0.000,0,0,0.00000),(184,4082,0,'ST FELICIEN TRADITION','ST FELICIEN TRADITION','','','','','','',4,0,82,1,0,0,0,'',1.00,0,0.00,1,4082,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_felicien.png','','',0,0.000,0,0,0.00000),(185,4083,0,'ST FELICIEN TRADITION  18','ST FELICIEN TRADITION  18','','','','','','',4,0,83,1,0,0,0,'',1.00,0,0.00,1,4083,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_felicien.png','','',0,0.000,0,0,0.00000),(186,4084,0,'ST MARCELLIN  A LA LYONNA','ST MARCELLIN  A LA LYONNA','','','','','','',4,0,84,1,0,0,0,'',1.00,0,0.00,1,4084,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_marcelin.png','','',0,0.000,0,0,0.00000),(187,4085,0,'ST MARCELLIN  LE CANUT','ST MARCELLIN  LE CANUT','','','','','','',4,0,85,1,0,0,0,'',1.00,0,0.00,1,4085,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_marcelin.png','','',0,0.000,0,0,0.00000),(188,4086,0,'ST MARCELLIN  SELECTION','ST MARCELLIN  SELECTION','','','','','','',4,0,86,1,0,0,0,'',1.00,0,0.00,1,4086,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_marcelin.png','','',0,0.000,0,0,0.00000),(189,4087,0,'ST MARCELLIN RDF coupelle','ST MARCELLIN RDF coupelle','','','','','','',4,0,87,1,0,0,0,'',1.00,0,0.00,1,4087,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_marcelin.png','','',0,0.000,0,0,0.00000),(190,4088,0,'St NECTAIRE fermier','St NECTAIRE fermier','','','','','','',4,0,88,1,0,0,0,'',1.00,0,0.00,1,4088,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'saint-nectaire.png','','',0,0.000,0,0,0.00000),(191,4089,0,'St NECTAIRE FERMIER','St NECTAIRE FERMIER','','','','','','',4,0,89,1,0,0,0,'',1.00,0,0.00,1,4089,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'saint-nectaire.png','','',0,0.000,0,0,0.00000),(192,4090,0,'St NECTAIRE laitier','St NECTAIRE laitier','','','','','','',4,0,90,1,0,0,0,'',1.00,0,0.00,1,4090,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'saint-nectaire.png','','',0,0.000,0,0,0.00000),(193,4091,0,'St NECTAIRE laitier RDF','St NECTAIRE laitier RDF','','','','','','',4,0,91,1,0,0,0,'',1.00,0,0.00,1,4091,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'saint-nectaire.png','','',0,0.000,0,0,0.00000),(194,4092,0,'St PAULIN','St PAULIN','','','','','','',4,0,92,1,0,0,0,'',1.00,0,0.00,1,4092,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st_paulin.png','','',0,0.000,0,0,0.00000),(195,4093,0,'TOME CATALANE','TOME CATALANE','','','','','','',4,0,93,1,0,0,0,'',1.00,0,0.00,1,4093,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tome.png','','',0,0.000,0,0,0.00000),(196,4094,0,'TOME des Bauges','TOME des Bauges','','','','','','',4,0,94,1,0,0,0,'',1.00,0,0.00,1,4094,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tome.png','','',0,0.000,0,0,0.00000),(197,4095,0,'TOME des Bauges RDF','TOME des Bauges RDF','','','','','','',4,0,95,1,0,0,0,'',1.00,0,0.00,1,4095,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tome.png','','',0,0.000,0,0,0.00000),(198,4096,0,'TOMME  SAVOIE  RIVE du FI','TOMME  SAVOIE  RIVE du FI','','','','','','',4,0,96,1,0,0,0,'',1.00,0,0.00,1,4096,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(199,4097,0,'TOMME ALLEGEE','TOMME ALLEGEE','','','','','','',4,0,97,1,0,0,0,'',1.00,0,0.00,1,4097,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(200,4098,0,'TOMME au marc de raisin','TOMME au marc de raisin','','','','','','',4,0,98,1,0,0,0,'',1.00,0,0.00,1,4098,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(201,4099,0,'TOMME BLANCHE d\'OC','TOMME BLANCHE d\'OC','','','','','','',4,0,99,1,0,0,0,'',1.00,0,0.00,1,4099,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(202,4100,0,'TOMME CERONNEE','TOMME CERONNEE','','','','','','',4,0,100,1,0,0,0,'',1.00,0,0.00,1,4100,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(203,4101,0,'TOMME CRAYEUSE','TOMME CRAYEUSE','','','','','','',4,0,101,1,0,0,0,'',1.00,0,0.00,1,4101,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(204,4102,0,'TOMME DE CAMBRAI','TOMME DE CAMBRAI','','','','','','',4,0,102,1,0,0,0,'',1.00,0,0.00,1,4102,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(205,4103,0,'TOMME de MONTAGNE','TOMME de MONTAGNE','','','','','','',4,0,103,1,0,0,0,'',1.00,0,0.00,1,4103,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(206,4104,0,'TOMME de MONTAGNE d\'Auver','TOMME de MONTAGNE d\'Auver','','','','','','',4,0,104,1,0,0,0,'',1.00,0,0.00,1,4104,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(207,4105,0,'TOMME de SAVOIE','TOMME de SAVOIE','','','','','','',4,0,105,1,0,0,0,'',1.00,0,0.00,1,4105,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(208,4106,0,'TOMME DOREE des PYRENEES','TOMME DOREE des PYRENEES','','','','','','',4,0,106,1,0,0,0,'',1.00,0,0.00,1,4106,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(209,4107,0,'TOMME FERMIERE','TOMME FERMIERE','','','','','','',4,0,107,1,0,0,0,'',1.00,0,0.00,1,4107,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(210,4108,0,'TOMME FRAICHE','TOMME FRAICHE','','','','','','',4,0,108,1,0,0,0,'',1.00,0,0.00,1,4108,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tome.png','','',0,0.000,0,0,0.00000),(211,4109,0,'TOMME GRISE','TOMME GRISE','','','','','','',4,0,109,1,0,0,0,'',1.00,0,0.00,1,4109,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(212,4110,0,'TOMME NOIRE','TOMME NOIRE','','','','','','',4,0,110,1,0,0,0,'',1.00,0,0.00,1,4110,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(213,4111,0,'TOMME SAVOIE','TOMME SAVOIE','','','','','','',4,0,111,1,0,0,0,'',1.00,0,0.00,1,4111,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(214,4112,0,'TOMME SAVOIE lait cru','TOMME SAVOIE lait cru','','','','','','',4,0,112,1,0,0,0,'',1.00,0,0.00,1,4112,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tomme-de-savoie.png','','',0,0.000,0,0,0.00000),(215,4113,0,'VACHERIN MONT d\'OR','VACHERIN MONT d\'OR','','','','','','',4,0,113,1,0,0,0,'',1.00,0,0.00,1,4113,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Mini_Mont_dor.png','','',0,0.000,0,0,0.00000),(216,4114,0,'VACHERIN MONT d\'OR petit','VACHERIN MONT d\'OR petit','','','','','','',4,0,114,1,0,0,0,'',1.00,0,0.00,1,4114,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Mini_Mont_dor.png','','',0,0.000,0,0,0.00000),(217,4115,0,'MORBIER AOC REFLETS DE Fr','MORBIER AOC REFLETS DE Fr','','','','','','',4,0,115,1,0,0,0,'',1.00,0,0.00,1,4115,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'morbier.png','','',0,0.000,0,0,0.00000),(218,4116,0,'SAINT ALBRAY','SAINT ALBRAY','','','','','','',4,0,116,1,0,0,0,'',1.00,0,0.00,1,4116,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'st albray.png','','',0,0.000,0,0,0.00000),(219,5001,0,'CHEDDAR BARRE GALLOWAY','CHEDDAR BARRE GALLOWAY','','','','','','',5,0,1,1,0,0,0,'',1.00,0,0.00,1,5001,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cheddar.png','','',0,0.000,0,0,0.00000),(220,5002,0,'CHEDDAR ROUGE NATURE','CHEDDAR ROUGE NATURE','','','','','','',5,0,2,1,0,0,0,'',1.00,0,0.00,1,5002,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'cheddar.png','','',0,0.000,0,0,0.00000),(221,5003,0,'GOUDA ALLEGE EN SEL','GOUDA ALLEGE EN SEL','','','','','','',5,0,3,1,0,0,0,'',1.00,0,0.00,1,5003,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gouda_fruite.png','','',0,0.000,0,0,0.00000),(222,5004,0,'GOUDA DE MAI','GOUDA DE MAI','','','','','','',5,0,4,1,0,0,0,'',1.00,0,0.00,1,5004,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gouda-de-mai.png','','',0,0.000,0,0,0.00000),(223,5005,0,'GOUDA1/2 vieux','GOUDA1/2 vieux','','','','','','',5,0,5,1,0,0,0,'',1.00,0,0.00,1,5005,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gouda_fruite.png','','',0,0.000,0,0,0.00000),(224,5006,0,'GOUDA FRUITE','GOUDA FRUITE','','','','','','',5,0,6,1,0,0,0,'',1.00,0,0.00,1,5006,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gouda_fruite.png','','',0,0.000,0,0,0.00000),(225,5007,0,'GOUDA graine de CUMIN','GOUDA graine de CUMIN','','','','','','',5,0,7,1,0,0,0,'',1.00,0,0.00,1,5007,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gouda_jeune.png','','',0,0.000,0,0,0.00000),(226,5008,0,'GOUDA JEUNE','GOUDA JEUNE','','','','','','',5,0,8,1,0,0,0,'',1.00,0,0.00,1,5008,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gouda_jeune.png','','',0,0.000,0,0,0.00000),(227,5009,0,'GOUDA MOULIN ROUGE','GOUDA MOULIN ROUGE','','','','','','',5,0,9,1,0,0,0,'',1.00,0,0.00,1,5009,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gouda_moulin_rouge.png','','',0,0.000,0,0,0.00000),(228,5010,0,'MIMOLETTE 1/2 vielle FRAN','MIMOLETTE 1/2 vielle FRAN','','','','','','',5,0,10,1,0,0,0,'',1.00,0,0.00,1,5010,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'mimolette.png','','',0,0.000,0,0,0.00000),(229,5011,0,'MIMOLETTE Extra Vieille','MIMOLETTE Extra Vieille','','','','','','',5,0,11,1,0,0,0,'',1.00,0,0.00,1,5011,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'mimolette.png','','',0,0.000,0,0,0.00000),(230,5012,0,'MIMOLETTE Extra Vieille F','MIMOLETTE Extra Vieille F','','','','','','',5,0,12,1,0,0,0,'',1.00,0,0.00,1,5012,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'mimolette.png','','',0,0.000,0,0,0.00000),(231,5013,0,'MIMOLETTE Jeune','MIMOLETTE Jeune','','','','','','',5,0,13,1,0,0,0,'',1.00,0,0.00,1,5013,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'mimolette.png','','',0,0.000,0,0,0.00000),(232,5014,0,'MIMOLETTE PEG','MIMOLETTE PEG','','','','','','',5,0,14,1,0,0,0,'',1.00,0,0.00,1,5014,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'mimolette.png','','',0,0.000,0,0,0.00000),(233,5015,0,'MIMOLETTE vieille','MIMOLETTE vieille','','','','','','',5,0,15,1,0,0,0,'',1.00,0,0.00,1,5015,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'mimolette.png','','',0,0.000,0,0,0.00000),(234,5016,0,'FROMAGE HOLLANDAIS au LAIT','FROMAGE HOLLANDAIS au LAIT','','','','','','',5,0,16,1,0,0,0,'',1.00,0,0.00,1,5016,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Fromage_hollande.png','','',0,0.000,0,0,0.00000),(235,5017,0,'EDAM jeune','EDAM jeune','','','','','','',5,0,17,1,0,0,0,'',1.00,0,0.00,1,5017,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'edam.png','','',0,0.000,0,0,0.00000),(236,5018,0,'EDAM tendre','EDAM tendre','','','','','','',5,0,18,1,0,0,0,'',1.00,0,0.00,1,5018,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'edam.png','','',0,0.000,0,0,0.00000),(237,5019,0,'EDAM vieux','EDAM vieux','','','','','','',5,0,19,1,0,0,0,'',1.00,0,0.00,1,5019,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'edam_vieux.png','','',0,0.000,0,0,0.00000),(238,5020,0,'FRIBOURGEOIS','FRIBOURGEOIS','','','','','','',5,0,20,1,0,0,0,'',1.00,0,0.00,1,5020,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'fribourgeois.png','','',0,0.000,0,0,0.00000),(239,6001,0,'GORGONZOLA','GORGONZOLA','','','','','','',6,0,1,1,0,0,0,'',1.00,0,0.00,1,6001,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'Gorgonzola-2.png','','',0,0.000,0,0,0.00000),(240,6002,0,'MOZZARELLA','MOZZARELLA','','','','','','',6,0,2,1,0,0,0,'',1.00,0,0.00,1,6002,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'mozzarella.png','','',0,0.000,0,0,0.00000),(241,6003,0,'RICOTTA vache','RICOTTA vache','','','','','','',6,0,3,1,0,0,0,'',1.00,0,0.00,1,6003,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'riccotta.png','','',0,0.000,0,0,0.00000),(242,6004,0,'ASIAGO PRESSATO AOP','ASIAGO PRESSATO AOP','','','','','','',6,0,4,1,0,0,0,'',1.00,0,0.00,1,6004,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'asiago.png','','',0,0.000,0,0,0.00000),(243,6005,0,'GRANA PADANO AOP','GRANA PADANO AOP','','','','','','',6,0,5,1,0,0,0,'',1.00,0,0.00,1,6005,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'granapadano.png','','',0,0.000,0,0,0.00000),(244,6006,0,'PARMIGIANO REGGIANO AOP','PARMIGIANO REGGIANO AOP','','','','','','',6,0,6,1,0,0,0,'',1.00,0,0.00,1,6006,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'parmigiano.png','','',0,0.000,0,0,0.00000),(245,6007,0,'PROVOLONE doux AOP','PROVOLONE doux AOP','','','','','','',6,0,7,1,0,0,0,'',1.00,0,0.00,1,6007,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'provolone.png','','',0,0.000,0,0,0.00000),(246,6008,0,'PROVOLONE piquant AOP','PROVOLONE piquant AOP','','','','','','',6,0,8,1,0,0,0,'',1.00,0,0.00,1,6008,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'provolone.png','','',0,0.000,0,0,0.00000),(247,6009,0,'EMMENTAL suisse','EMMENTAL suisse','','','','','','',7,0,1,1,0,0,0,'',1.00,0,0.00,1,6009,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'emmental_suisse.png','','',0,0.000,0,0,0.00000),(248,6010,0,'EMMENTALER','EMMENTALER','','','','','','',7,0,2,1,0,0,0,'',1.00,0,0.00,1,6010,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'emmentaller.png','','',0,0.000,0,0,0.00000),(249,6011,0,'GRUYERE Suisse','GRUYERE Suisse','','','','','','',7,0,3,1,0,0,0,'',1.00,0,0.00,1,6011,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gruyere-suisse.png','','',0,0.000,0,0,0.00000),(250,6012,0,'GRUYERE suisse 10 mois','GRUYERE suisse 10 mois','','','','','','',7,0,4,1,0,0,0,'',1.00,0,0.00,1,6012,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gruyere-suisse.png','','',0,0.000,0,0,0.00000),(251,6013,0,'Gruyere suisse 10 MOIS al','Gruyere suisse 10 MOIS al','','','','','','',7,0,5,1,0,0,0,'',1.00,0,0.00,1,6013,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gruyere-suisse.png','','',0,0.000,0,0,0.00000),(252,6014,0,'GRUYERE suisse 5 mois','GRUYERE suisse 5 mois','','','','','','',7,0,6,1,0,0,0,'',1.00,0,0.00,1,6014,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gruyere-suisse.png','','',0,0.000,0,0,0.00000),(253,6015,0,'GRUYERE suisse 7 mois','GRUYERE suisse 7 mois','','','','','','',7,0,7,1,0,0,0,'',1.00,0,0.00,1,6015,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'gruyere-suisse.png','','',0,0.000,0,0,0.00000),(254,6016,0,'SBRINZ','SBRINZ','','','','','','',7,0,8,1,0,0,0,'',1.00,0,0.00,1,6016,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'SBRINZ.png','','',0,0.000,0,0,0.00000),(255,6017,0,'TETE DE MOINE','TETE DE MOINE','','','','','','',7,0,9,1,0,0,0,'',1.00,0,0.00,1,6017,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tete_moine.png','','',0,0.000,0,0,0.00000),(256,6018,0,'TILSIT','TILSIT','','','','','','',7,0,10,1,0,0,0,'',1.00,0,0.00,1,6018,1,1,0,'',0,0,0.000,'','-',0,'','','','-',0,'tilsit.png','','',0,0.000,0,0,0.00000);

--
-- Dumping data for table `itemsallergenicons`
--


--
-- Dumping data for table `itemschangepoints`
--


--
-- Dumping data for table `itemsean128`
--


--
-- Dumping data for table `itemsean13`
--


--
-- Dumping data for table `itemsextrapoints`
--


--
-- Dumping data for table `itemsformats`
--


--
-- Dumping data for table `itemtextbonus`
--


--
-- Dumping data for table `itemtextcommon`
--


--
-- Dumping data for table `localcfgforms`
--

INSERT INTO `localcfgforms` VALUES (1,'reports','DAILY_DATE_ALL','0'),(2,'reports','DAILY_DATE_TODAY','0'),(3,'reports','DAILY_DATE_SELECT','1'),(4,'reports','DAILY_DAILYPRINT','1'),(5,'reports','DAILY_VATPRINT','1'),(6,'reports','DAILY_PAYMENTPRINT','1'),(7,'reports','DAILY-DETAIL','1'),(8,'reports','DAILY_ORDER','1'),(9,'reports','DAILY_TRAINING','1'),(10,'reports','TICKET-GROUP','0'),(11,'reports','TICKET-DETAIL','3'),(12,'reports','TOTAL-GROUP','1'),(13,'reports','TOTAL-BROKEN','0'),(14,'reports','CASHDRAWER-GROUP','0'),(15,'reports','CASHDRAWER-BROKEN','0'),(16,'reports','EMAIL-TO','');

--
-- Dumping data for table `localcfgkeyboard`
--

INSERT INTO `localcfgkeyboard` VALUES (1,'back_screen','1024x768'),(2,'menu','bionic'),(3,'turn','none');

--
-- Dumping data for table `localcfgparams`
--


--
-- Dumping data for table `localcfgscale`
--

INSERT INTO `localcfgscale` VALUES (7,'TOUCH/scale-icon','neutral'),(8,'TOUCH/loader','1'),(10,'TOUCH/slave-icon','slave'),(24,'RESOURCES/user-icons-path','../share/pcscale/resources/icons/item'),(28,'NETWORK/scale-number','1'),(29,'CORE/mup-group','1'),(30,'CORE/plu-board-group','1'),(31,'NETWORK/scale-counter','1'),(76,'TOUCH/name','Classic'),(77,'sw-full-version','2.14 - Methone. Build id: 20161025 - 2330'),(79,'serial-number','861991'),(80,'TOUCH/vendor-icon','vnd1'),(81,'TOUCH/device-icon','colors'),(82,'TOUCH/items-dnd','1'),(96,'local-ticket/StartNumber','0'),(97,'local-ticket/MaximumNumber','0'),(98,'PRINTER/lbl-format','J45X57'),(99,'PRINTER/prn-format','estandar'),(112,'TOUCH/language','fr_FR'),(118,'TOUCH/background','space'),(267,'backup-path','/home/pcscale/scale/backup'),(279,'SCALE/prices-without-taxes','0'),(303,'TOUCH/GROUPS/menu/default','menu01'),(304,'TOUCH/GROUPS/VendorsGroup/default','Vnd-board-Classic1'),(305,'TOUCH/GROUPS/scroll-sales/default','kbd-PLUBoard-Classic1');

--
-- Dumping data for table `localcomm`
--


--
-- Dumping data for table `localints`
--

INSERT INTO `localints` VALUES (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);

--
-- Dumping data for table `locallicenses`
--


--
-- Dumping data for table `localstatus`
--

INSERT INTO `localstatus` VALUES (1,156,'2.24.4216','en_IE',0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0);

--
-- Dumping data for table `localtreeboard`
--


--
-- Dumping data for table `localvendorkeys`
--

INSERT INTO `localvendorkeys` VALUES (1,1,101),(1,2,102),(1,3,103),(1,4,104);

--
-- Dumping data for table `localvendorregister`
--


--
-- Dumping data for table `localworkingmodes`
--

INSERT INTO `localworkingmodes` VALUES (3,'00 sales','based','sales'),(8,'01 packet','based','packet'),(9,'01 packet','description','Envasado'),(10,'01 packet','keyboard','packet'),(11,'01 packet','user','admin'),(12,'01 packet','keyboard-loop','packet-loop'),(13,'01 packet','in-use','1'),(14,'02 selfservice','based','selfservice'),(20,'03 pos','based','sales'),(93,'01 packet','user-check-mode-form','OFF'),(94,'01 packet','user-check-mode','OFF'),(95,'01 packet','user-prog-prices','ON'),(96,'01 packet','sections',''),(97,'01 packet','packet-customer','ON'),(98,'01 packet','show-print-packet','ON'),(99,'01 packet','allow-mult-key','ON'),(100,'01 packet','packet-vendor','0'),(101,'01 packet','show-form-packet','0'),(102,'01 packet','packet-after-item','OFF'),(103,'01 packet','autocode','ON'),(104,'01 packet','pluprc-key','ON'),(105,'01 packet','constant-key','ON'),(106,'01 packet','change-price','ON'),(107,'01 packet','amount-zero','ON'),(108,'01 packet','negative-amount','ON'),(109,'01 packet','code-digits','6'),(110,'01 packet','item-access','0'),(111,'01 packet','mixed-allowed','ON'),(112,'01 packet','weightlow-tsec','0'),(113,'01 packet','weightlow-beep','ON'),(114,'01 packet','weightlow-zero','OFF'),(129,'00 sales','allow-reload','ON'),(148,'03 pos','user-check-mode-form','OFF'),(149,'03 pos','user-check-mode','OFF'),(150,'03 pos','user-prog-prices','ON'),(151,'03 pos','sections',''),(152,'03 pos','print-ticket','ON'),(153,'03 pos','print-label-total','OFF'),(154,'03 pos','print-label-line','OFF'),(155,'03 pos','close-with-line','OFF'),(156,'03 pos','total-discount','ON'),(157,'03 pos','sales-customer','ON'),(158,'03 pos','allow-orders','ON'),(159,'03 pos','payment','0'),(160,'03 pos','startlocal','0'),(161,'03 pos','allow-cancel','ON'),(162,'03 pos','allow-reload','ON'),(163,'03 pos','allow-amount0','ON'),(164,'03 pos','auto-fix','ON'),(165,'03 pos','times-print','250'),(167,'03 pos','autocode','OFF'),(168,'03 pos','pluprc-key','ON'),(169,'03 pos','constant-key','ON'),(170,'03 pos','change-price','ON'),(171,'03 pos','return-weight','ON'),(172,'03 pos','amount-zero','ON'),(173,'03 pos','negative-amount','ON'),(174,'03 pos','code-digits','6'),(175,'03 pos','item-access','0'),(176,'03 pos','pos-method','ON'),(177,'03 pos','clear-tare','OFF'),(178,'03 pos','weightlow-tsec','0'),(179,'03 pos','weightlow-beep','ON'),(180,'03 pos','weightlow-zero','OFF'),(191,'02 selfservice','description','Self Service'),(192,'02 selfservice','keyboard','selfservice'),(193,'02 selfservice','user','admin'),(194,'02 selfservice','keyboard-loop',''),(195,'02 selfservice','keyboard-vendors',''),(196,'02 selfservice','in-use','1'),(203,'00 sales','description','Venta'),(204,'00 sales','keyboard','salesFamilies'),(205,'00 sales','user','admin'),(206,'00 sales','keyboard-loop',''),(207,'00 sales','keyboard-vendors',''),(208,'00 sales','in-use','1'),(213,'','working-mode','00 sales'),(262,'00 sales','user-check-mode-form','OFF'),(263,'00 sales','user-check-mode','OFF'),(264,'00 sales','user-prog-prices','ON'),(265,'00 sales','sections',''),(266,'00 sales','print-ticket','ON'),(267,'00 sales','print-label-total','OFF'),(268,'00 sales','print-label-line','OFF'),(269,'00 sales','close-with-line','OFF'),(270,'00 sales','total-discount','ON'),(271,'00 sales','sales-customer','ON'),(272,'00 sales','allow-orders','ON'),(273,'00 sales','payment','0'),(274,'00 sales','startlocal','0'),(275,'00 sales','allow-cancel','ON'),(276,'00 sales','allow-amount0','ON'),(277,'00 sales','auto-fix','OFF'),(278,'00 sales','times-print','250'),(280,'00 sales','auto-vendor','ON'),(281,'00 sales','customer-care','OFF'),(282,'00 sales','park-ticket','ON'),(283,'00 sales','ticket-format',''),(284,'00 sales','label-format',''),(285,'00 sales','parking-format','parked'),(286,'00 sales','reload-type','48'),(287,'00 sales','reprint-type','240'),(288,'00 sales','allow-training','OFF'),(289,'00 sales','autocode','ON'),(290,'00 sales','pluprc-key','ON'),(291,'00 sales','constant-key','ON'),(292,'00 sales','change-price','ON'),(293,'00 sales','return-weight','OFF'),(294,'00 sales','amount-zero','ON'),(295,'00 sales','negative-amount','ON'),(296,'00 sales','code-digits','6'),(297,'00 sales','item-access','0'),(298,'00 sales','pos-method','OFF'),(299,'00 sales','clear-tare','ON'),(300,'00 sales','weightlow-tsec','0'),(301,'00 sales','weightlow-beep','ON'),(302,'00 sales','weightlow-zero','OFF'),(303,'03 pos','description','POS'),(304,'03 pos','keyboard','POS'),(305,'03 pos','user','admin'),(306,'03 pos','key-fnc-on-pressed','0'),(307,'03 pos','keyboard-loop',''),(308,'03 pos','keyboard-vendors','POSVendor'),(309,'03 pos','PLUload-func','2'),(310,'03 pos','PLUload-mode','1'),(311,'03 pos','in-use','1'),(355,'00 sales','key-fnc-on-pressed','0'),(358,'00 sales','PLUload-func','2'),(359,'00 sales','PLUload-mode','1'),(364,'01 packet','key-fnc-on-pressed','0'),(366,'01 packet','keyboard-vendors',''),(367,'01 packet','PLUload-func','2'),(368,'01 packet','PLUload-mode','1'),(472,'02 selfservice','key-fnc-on-pressed','1'),(475,'02 selfservice','PLUload-func','2'),(476,'02 selfservice','PLUload-mode','0'),(513,'00 sales','vendor-hide-code','OFF'),(514,'00 sales','vendor-summary','OFF'),(515,'00 sales','single-section','OFF'),(516,'00 sales','ean13-section-item','OFF'),(517,'00 sales','ticket-days','1'),(518,'00 sales','simplified-invoice','OFF'),(519,'00 sales','hold-plusec','ON'),(520,'00 sales','plukey-dnd','Full'),(562,'01 packet','edit-bovine-card','OFF'),(563,'01 packet','label-format',''),(564,'01 packet','hold-plusec','ON'),(565,'01 packet','plukey-dnd','Full'),(588,'03 pos','auto-vendor','ON'),(589,'03 pos','vendor-hide-code','OFF'),(590,'03 pos','vendor-summary','OFF'),(591,'03 pos','customer-care','OFF'),(592,'03 pos','park-ticket','OFF'),(593,'03 pos','single-section','OFF'),(594,'03 pos','ean13-section-item','OFF'),(595,'03 pos','ticket-format',''),(596,'03 pos','label-format',''),(597,'03 pos','parking-format','parked'),(598,'03 pos','reload-type','1'),(599,'03 pos','reprint-type','1'),(600,'03 pos','ticket-days','1'),(601,'03 pos','allow-training','OFF'),(602,'03 pos','simplified-invoice','OFF'),(603,'03 pos','hold-plusec','ON'),(604,'03 pos','plukey-dnd','Full'),(637,'','user-check-menu-form','OFF'),(638,'00 sales','current-data-mode','0'),(639,'00 sales','hold-plu-to-set','Full'),(640,'01 packet','hold-plu-to-set','Full'),(641,'03 pos','hold-plu-to-set','Full'),(742,'03 pos','reprint-ticket','ON'),(743,'03 pos','reprint-label-total','OFF'),(744,'00 sales','reprint-ticket','ON'),(745,'00 sales','reprint-label-total','OFF'),(749,'03 pos','print-ticket-suborder','ON'),(750,'00 sales','print-ticket-suborder','ON'),(752,'03 pos','print-label-total-suborder','OFF'),(753,'00 sales','print-label-total-suborder','OFF'),(755,'03 pos','print-ticket-order','ON'),(756,'00 sales','print-ticket-order','ON'),(758,'03 pos','print-label-order','OFF'),(759,'00 sales','print-label-order','OFF'),(761,'00 sales','ticket-order-format',''),(762,'03 pos','ticket-order-format',''),(764,'00 sales','label-order-format',''),(765,'03 pos','label-order-format',''),(774,'00 sales','keyboard-orders',''),(784,'01 packet','keyboard-orders',''),(794,'03 pos','keyboard-orders',''),(804,'00 sales','Hide-unused-PLUkeys','0'),(811,'00 sales','number-of-packages','OFF'),(812,'00 sales','print-refund','OFF'),(813,'00 sales','print-label-package','OFF'),(814,'00 sales','reprint-label-package','OFF'),(815,'00 sales','park-reprint','OFF'),(816,'00 sales','cancel-hanged','0'),(817,'00 sales','cancel-hanged-time','10'),(818,'00 sales','group-order-tickets','ON'),(819,'00 sales','group-order-as-invoice','OFF'),(820,'00 sales','group-parked-tickets','OFF'),(821,'00 sales','group-parked-as-invoice','OFF'),(822,'00 sales','drawer-with-password','OFF'),(823,'00 sales','drawer-direct','OFF'),(824,'00 sales','drawer-key-on-vendor-menu','OFF'),(825,'00 sales','drawer-open-print','ON'),(826,'00 sales','allow-ticket-check','ON'),(827,'00 sales','max-lines-99','OFF'),(828,'00 sales','line-discount','ON'),(829,'00 sales','slice-ticket-lines',''),(830,'00 sales','slice-ticket-header',''),(831,'00 sales','user-pricerates','ON'),(832,'00 sales','save-code128','0'),(833,'00 sales','item-formats','0'),(834,'00 sales','manual-weight','OFF'),(835,'00 sales','allow-bovine','ON'),(836,'00 sales','edit-bovine-card','OFF'),(837,'00 sales','allow-customer-order','ON'),(838,'00 sales','parking-order-format',''),(839,'00 sales','order-as-ticket','ON'),(840,'00 sales','order-allow-bovine','ON'),(841,'00 sales','order-edit-bovine-card','OFF'),(842,'00 sales','ask-replace','OFF'),(843,'00 sales','button-remark','OFF'),(844,'00 sales','piece-counting','OFF'),(845,'00 sales','over-under','OFF'),(890,'00 sales','change-price0','ON'),(891,'00 sales','weight-min','0,000'),(892,'00 sales','amount-min','0,00'),(893,'00 sales','pricerate','0'),(894,'00 sales','change-saleform','OFF');

--
-- Dumping data for table `numberingtickets`
--

INSERT INTO `numberingtickets` VALUES (1,'I','1500101','',1,0,1,NULL,9999,0,'D',0,0,0,0);

--
-- Dumping data for table `nutrition`
--


--
-- Dumping data for table `overunderlevels`
--


--
-- Dumping data for table `paymethods`
--

INSERT INTO `paymethods` VALUES (1,0,'ESPECES',1),(2,1,'CB',1),(3,2,'CHEQUE',1),(4,3,'PAYMETHOD3',0),(5,4,'PAYMETHOD4',0),(6,5,'PAYMETHOD5',0),(7,6,'PAYMETHOD6',0);

--
-- Dumping data for table `pktfishery`
--


--
-- Dumping data for table `pktgeneric`
--


--
-- Dumping data for table `pktvegetables`
--


--
-- Dumping data for table `playlists`
--


--
-- Dumping data for table `plugins`
--


--
-- Dumping data for table `plukeys`
--

INSERT INTO `plukeys` VALUES (1,0,1,1,4031),(2,0,1,2,3010),(3,0,1,3,1006),(4,0,1,4,3005),(5,0,1,5,4049),(6,0,1,6,5018);

--
-- Dumping data for table `plukeysfile`
--


--
-- Dumping data for table `pricerates`
--

INSERT INTO `pricerates` VALUES (0,'');

--
-- Dumping data for table `qrfields`
--

INSERT INTO `qrfields` VALUES (1,'H','[]',1,'F',0,'123'),(2,'H','Number',2,'N',6,'0FILLED'),(3,'H','DatTim',3,'D',0,'%y%m%d%H%i%s'),(4,'H','AddedLines',4,'N',2,'0FILLED'),(5,'H','NetAmount',5,'M',6,'0FILLED DPNONE'),(6,'L','[]',1,'F',0,'1'),(7,'L','Item',2,'N',5,'0FILLED'),(8,'L','Weight',3,'Q',5,'0FILLED DPNONE'),(9,'L','Price',4,'M',5,'0FILLED DPNONE'),(10,'L','Amount',5,'M',5,'0FILLED DPNONE'),(11,'','[]',1,'',0,'check128');

--
-- Dumping data for table `quickkeys`
--


--
-- Dumping data for table `scheduler`
--


--
-- Dumping data for table `scripts`
--


--
-- Dumping data for table `sections`
--


--
-- Dumping data for table `shortcuts`
--


--
-- Dumping data for table `status`
--

INSERT INTO `status` VALUES (1,156,'2.24.4216');

--
-- Dumping data for table `tarecodes`
--


--
-- Dumping data for table `trademark`
--

INSERT INTO `trademark` VALUES (1,'','','','','','','','','','',0,'','','','','','','','','','','','','','','','','','');

--
-- Dumping data for table `turn`
--


--
-- Dumping data for table `turnswaiting`
--


--
-- Dumping data for table `users`
--

INSERT INTO `users` VALUES (1,'admin','YWRtaW4=','Administrator',0,1,0,0,0),(2,'sales','c2FsZXM=','Sales user',0,0,0,0,1),(3,'packet','cGFja2V0','Packet user',0,0,0,0,1),(4,'sservice','c3NlcnZpY2U=','Self-Service user',0,0,0,0,0);

--
-- Dumping data for table `vatexemptions`
--


--
-- Dumping data for table `vats`
--

INSERT INTO `vats` VALUES (6,0,'Sans TVA',0.00),(11,1,'Réduit',5.50),(12,2,'Intermédiaire',10.00),(13,3,'Normal',20.00);

--
-- Dumping data for table `vendorkeys`
--

INSERT INTO `vendorkeys` VALUES (1,1,101),(1,2,102),(1,3,103),(1,4,104);

--
-- Dumping data for table `vendorregister`
--


--
-- Dumping data for table `vendors`
--

INSERT INTO `vendors` VALUES (101,'MARIE','','BELINDA.jpg','0'),(102,'CATHY','','CATHERINE.jpg','0'),(103,'ERIC','','COLIN.jpg','0'),(104,'JACQUES','','DAVID.jpg','0');

--
-- Dumping data for table `vitamins`
--


--
-- Dumping routines for database 'pcscale'
--
/*!50003 DROP FUNCTION IF EXISTS `gs1_checkdigit` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` FUNCTION `gs1_checkdigit`(base VARCHAR(17)) RETURNS char(1) CHARSET utf8
    DETERMINISTIC
BEGIN
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    DECLARE odds INTEGER DEFAULT 0;     
    DECLARE evens INTEGER DEFAULT 0;    
    DECLARE total INTEGER DEFAULT 0;    
    DECLARE len INTEGER;                
    DECLARE pos INTEGER DEFAULT 0;      
    DECLARE digit INTEGER;              
    DECLARE cd INTEGER;                 
    
    
    SET len = LENGTH(base);
    mainloop: LOOP
        
        
        SET digit = CAST(SUBSTRING(base, len-pos, 1) AS SIGNED INTEGER);
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        IF (pos % 2 = 0)
        THEN
            SET evens = evens + digit;
        ELSE
            SET odds = odds + digit;
        END IF;
        
        
        SET pos = pos + 1;
        IF (pos < LEN)
        THEN
            ITERATE mainloop;
        END IF;
        LEAVE mainloop;
    END LOOP mainloop;
    
    
    SET total = odds + (3 * evens);
    SET cd = total % 10;
    IF (cd <> 0)
    THEN
        SET cd = 10 - cd;
    END IF;
    
    RETURN (CAST(cd AS CHAR));
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `pcs_net` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` FUNCTION `pcs_net`(gross DECIMAL(10,2), discount DECIMAL(4,2), points DECIMAL(10,2)) RETURNS decimal(10,2)
    DETERMINISTIC
BEGIN
  DECLARE net DECIMAL(10,2);

  SET @amount_round := IFNULL(GLOBAL_GET("amount_round"), 0);
  SET @frac_digits := IFNULL(GLOBAL_GET("frac_digits"), 2);
  SET net=gross - ROUND((gross*discount)/100, @frac_digits) - points;
  IF(@amount_round=5) THEN
    SET net=(ROUND(net/5, @frac_digits) * 5);
  END IF;

  RETURN net;

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `pcs_total_to_pay` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` FUNCTION `pcs_total_to_pay`(id_ticket INTEGER, src_db TINYTEXT) RETURNS decimal(10,2)
    DETERMINISTIC
BEGIN
  DECLARE total DECIMAL(10,2);
  DECLARE without_taxes BOOLEAN DEFAULT FALSE;	
  SET without_taxes = (SELECT (IFNULL((SELECT `ParamValue` FROM `CfgSystem` WHERE `ParamKey`='prices-without-taxes'), 0)=1));
  IF(without_taxes=0) THEN
    IF(src_db='HTickets') THEN
      SET total = (SELECT `NetAmount` FROM `HTickets` WHERE `Id`=id_ticket);
    ELSE  
      SET total = (SELECT `NetAmount` FROM `LocalHTickets` WHERE `Id`=id_ticket);
    END IF;

  ELSE
    IF(src_db='HTickets') THEN
      SET total = (SELECT SUM(V_VAT.Amount) + SUM(CAST(((V_VAT.Amount*Percentage)/100) AS DECIMAL(10,2))) FROM
        (SELECT lt.`VATPercent`+'0' AS Percentage, CAST((SUM(lt.`Amount`)*(ht.`NetAmount`/ht.`GrossAmount`)) AS DECIMAL(10,2)) AS Amount
         FROM `HTickets` AS ht
         LEFT JOIN `LTickets` AS lt ON ht.`Id`=lt.`IdHTicket`
         WHERE ht.`Id`=id_ticket AND `lineType`=1 GROUP BY lt.`VATCode`) AS V_VAT);
    ELSE  
      SET total = (SELECT SUM(V_VAT.Amount) + SUM(CAST(((V_VAT.Amount*Percentage)/100) AS DECIMAL(10,2))) FROM
        (SELECT lt.`VATPercent`+'0' AS Percentage, CAST((SUM(lt.`Amount`)*(ht.`NetAmount`/ht.`GrossAmount`)) AS DECIMAL(10,2)) AS Amount
         FROM `LocalHTickets` AS ht
         LEFT JOIN `LocalLTickets` AS lt ON ht.`Id`=lt.`IdHTicket`
         WHERE ht.`Id`=id_ticket AND `lineType`=1 GROUP BY lt.`VATCode`) AS V_VAT);
    END IF;
  END IF;

  RETURN total;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `DataloggerFiscalChange` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` PROCEDURE `DataloggerFiscalChange`(OldName VARCHAR(32), NewName VARCHAR(32), OldEnabled BOOLEAN, NewEnabled BOOLEAN )
BEGIN
  DECLARE msg VARCHAR(255) DEFAULT '';
  IF ((NewName!=OldName) OR (NewEnabled!=OldEnabled)) THEN
    SELECT (SELECT COUNT(*) FROM information_schema.global_status WHERE variable_name='SLAVE_RUNNING' AND VARIABLE_VALUE='ON'), (SELECT COUNT(*) FROM information_schema.processlist WHERE INFO='SELECT trx_get()') INTO @_slave_,@_app_running_;
    IF (@_slave_ = 0) THEN
      IF (NewName = OldName) THEN
        SET msg := CONCAT('Fiscal module ', NewName, IF(NewEnabled, ' enabled', ' disabled'));
      ELSEIF (NewName = '') THEN
        SET msg := CONCAT('Fiscal module ', OldName, ' dropped.');
      ELSEIF (OldName = '') THEN
        SET msg := CONCAT('Fiscal module ', NewName, ' raised. ',IF(NewEnabled, 'Enabled', 'Disabled'));
      ELSE
        SET msg := CONCAT('Fiscal module ', OldName, ' changed to ', NewName, IF(NewEnabled, '. Enabled', '. Disabled'));
      END IF;
    END IF;
    IF (@_app_running_ = 0) THEN
      INSERT INTO `LocalDataLogger` SET Type=134, DatTim=NOW(), Message=msg;
    ELSE
      SET @trx := (SELECT trx_new("FISCAL_RELOAD", "NETWORK"));
      SET @ret := (SELECT trx_set_param(@trx, "LOG", msg));
      SET @ret := (SELECT trx_send(@trx));
    END IF;
  END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `dbTrigger` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` PROCEDURE `dbTrigger`(IN `tbname` VARCHAR (40), `function` VARCHAR (10), `masterkey` VARCHAR (40))
BEGIN
    SET @trx := (SELECT trx_new("DBTRIGGER", "CORE"));
    SET @ret := (SELECT trx_set_param(@trx, "TABLE", `tbname`));
    SET @ret := (SELECT trx_set_param(@trx, "FUNCTION", `function`));
    SET @ret := (SELECT trx_set_param(@trx, "KEY", `masterkey`));
    SET @ret := (SELECT trx_send(@trx));
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `LocalTreeBoardFromPLUKeysFile` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` PROCEDURE `LocalTreeBoardFromPLUKeysFile`()
BEGIN


  DELETE FROM `LocalTreeBoard`;
  SET @rownumber:=100000;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`,`Source2`,`Source3`,`Source4`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1`, puk.`Source2`, puk.`Source3`, puk.`Source4` FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`!=0  AND puk.`Source4`!=0 AND puk.`Source5`!=0) AS VT;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`,`Source2`,`Source3`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1`, puk.`Source2`, puk.`Source3` FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`!=0  AND puk.`Source4`!=0 AND puk.`Source5`=0) AS VT;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`,`Source2`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1`, puk.`Source2` AS kl FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`!=0  AND puk.`Source4`=0 AND puk.`Source5`=0) AS VT;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1` FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`=0  AND puk.`Source4`=0 AND puk.`Source5`=0) AS VT;

  SET @rownumber:=0;
  UPDATE `LocalTreeBoard` SET Board=(@rownumber:=@rownumber+1) ORDER BY `Source1`,`Source2`,`Source3`,`Source4`,`Source5`;

 UPDATE `LocalTreeBoard` AS T1 LEFT JOIN
 (SELECT `Board`,
    IF(@src1!=`Source1`, @lv1:=@lv1+1, @lv1) AS lv1,
    IF(@src1!=`Source1`, IF(`Source2`!=0, @lv2:=1, @lv2:=0), IF(@src2!=`Source2`, @lv2:=@lv2+1, @lv2)) AS lv2,
    IF(@src1!=`Source1` OR @src2!=`Source2`, IF(`Source3`!=0, @lv3:=1, @lv3:=0), IF(@src3!=`Source3`, @lv3:=@lv3+1, @lv3)) AS lv3,
    IF(@src1!=`Source1` OR @src2!=`Source2` OR @src3!=`Source3`, IF(`Source4`!=0, @lv4:=1, @lv4:=0), IF(@src4!=`Source4`, @lv4:=@lv4+1, @lv4)) AS lv4,
    IF(@src1!=`Source1` OR @src2!=`Source2` OR @src3!=`Source3` OR @src4!=`Source4`, IF(`Source5`!=0, @lv5:=1, @lv5:=0), IF(@src5!=`Source5`, @lv5:=@lv5+1, @lv5)) AS lv5,
    @src1:=`Source1`, @src2:=`Source2`, @src3:=`Source3`, @src4:=`Source4`, @src5:=`Source5`
	FROM `LocalTreeBoard`, (SELECT @src1:=0, @lv1:=0, @src2:=0, @lv2:=0, @src3:=0, @lv3:=0, @src4:=0, @lv4:=0, @src5:=0, @lv5:=0) AS TT
    ORDER BY `Board`) AS T2 ON T1.`Board`=T2.`Board`
 SET T1.`Level1`=T2.lv1, T1.`Level2`=T2.lv2, T1.`Level3`=T2.lv3, T1.`Level4`=T2.lv4, T1.`Level5`=T2.lv5;
END ;;
DELIMITER ;


--
-- Host: localhost    Database: pcscale
-- ------------------------------------------------------

DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `AdvertisingInserted` AFTER INSERT ON `Advertising`
FOR EACH ROW BEGIN
  IF ((NEW.`Scope`=2) AND (NEW.`Number`=GLOBAL_GET("current_scale"))) OR
     ((NEW.`Scope`=1) AND (NEW.`Number`=GLOBAL_GET("current_counter"))) OR
     ((NEW.`Scope`=0) AND (NEW.`Number`=0)) THEN
    UPDATE `LocalStatus` SET `AdvertisingChanged` = TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `AdvertisingUpdated` AFTER UPDATE ON `Advertising`
FOR EACH ROW BEGIN
  IF ((NEW.`Scope`=2) AND (NEW.`Number`=GLOBAL_GET("current_scale"))) OR
     ((NEW.`Scope`=1) AND (NEW.`Number`=GLOBAL_GET("current_counter"))) OR
     ((NEW.`Scope`=0) AND (NEW.`Number`=0)) THEN
    UPDATE `LocalStatus` SET `AdvertisingChanged` = TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `AdvertisingDeleted` AFTER DELETE ON `Advertising`
FOR EACH ROW BEGIN
  IF ((OLD.`Scope`=2) AND (OLD.`Number`=GLOBAL_GET("current_scale"))) OR
     ((OLD.`Scope`=1) AND (OLD.`Number`=GLOBAL_GET("current_counter"))) THEN
    UPDATE `LocalStatus` SET `AdvertisingChanged` = TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CardInserted` AFTER INSERT ON `Card`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckCard` = TRUE;
  SET @trx := (SELECT trx_new("CARD_RELOAD", "NETWORK"));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CardUpdated` AFTER UPDATE ON `Card`
FOR EACH ROW BEGIN
  IF ((NEW.`Enabled`!=OLD.`Enabled`) OR (NEW.`Status`!=OLD.`Status`)) THEN
    UPDATE `LocalStatus` SET `CheckCard` = TRUE;
  END IF;
  IF ((NEW.`Enabled`!=OLD.`Enabled`) OR (NEW.`URL`!=OLD.`URL`) OR (NEW.`Name`!=OLD.`Name`)) THEN
    SET @trx := (SELECT trx_new("CARD_RELOAD", "NETWORK"));
    SET @ret := (SELECT trx_send(@trx));
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CardDeleted` AFTER DELETE ON `Card`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckCard` = TRUE;
  SET @trx := (SELECT trx_new("CARD_RELOAD", "NETWORK"));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CashInserted` AFTER INSERT ON `Cash`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckCash` = TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CashUpdated` AFTER UPDATE ON `Cash`
FOR EACH ROW BEGIN
  IF ((NEW.`Scope`!=OLD.`Scope`) OR (NEW.`Number`!=OLD.`Number`) OR (NEW.`Status`!=OLD.`Status`)) THEN
    UPDATE `LocalStatus` SET `CheckCash` = TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CashDeleted` AFTER DELETE ON `Cash`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckCash` = TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CashDrawerUpdated` AFTER UPDATE ON `CashDrawer`
FOR EACH ROW BEGIN
  INSERT INTO `TotalPayTickets` (`Date`, `Type`, `NetStat`, `PayMethod`, `Delivered`)
    VALUES (DATE(NEW.`DatTim`), 'T', 'N', 99, (NEW.`CashIn`-NEW.`CashOut`))
    ON DUPLICATE KEY UPDATE `TotalPayTickets`.`Delivered`=`TotalPayTickets`.`Delivered`+VALUES(`Delivered`);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CfgInserted` AFTER INSERT ON `CfgSystem`
FOR EACH ROW BEGIN
  SET @trx := (SELECT trx_new("BUTTON_UPDATE", "GUI"));
  SET @ret := (SELECT trx_set_param(@trx, "KEYNAME", CONCAT("CFGSYSTEM_", NEW.`ParamKey`)));
  SET @ret := (SELECT trx_set_param(@trx, "PARAMVALUE", NEW.`ParamValue`));
  SET @ret := (SELECT trx_send(@trx));
  IF(NEW.`ParamKey`="allow-customer-order") THEN
    UPDATE `LocalStatus` SET `CheckCustomerOrders` = TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CfgUpdated` AFTER UPDATE ON `CfgSystem`
FOR EACH ROW BEGIN
  IF(OLD.`ParamValue`!=NEW.`ParamValue`) THEN
    SET @trx := (SELECT trx_new("BUTTON_UPDATE", "GUI"));
    SET @ret := (SELECT trx_set_param(@trx, "KEYNAME", CONCAT("CFGSYSTEM_", NEW.`ParamKey`)));
    SET @ret := (SELECT trx_set_param(@trx, "PARAMVALUE", NEW.`ParamValue`));
    SET @ret := (SELECT trx_send(@trx));
    IF((OLD.`ParamKey`="allow-customer-order") OR (NEW.`ParamKey`="allow-customer-order")) THEN
      UPDATE `LocalStatus` SET `CheckCustomerOrders` = TRUE;
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `CfgDeleted` AFTER DELETE ON `CfgSystem`
FOR EACH ROW BEGIN
  SET @trx := (SELECT trx_new("BUTTON_UPDATE", "GUI"));
  SET @ret := (SELECT trx_set_param(@trx, "KEYNAME", CONCAT("CFGSYSTEM_", OLD.`ParamKey`)));
  SET @ret := (SELECT trx_set_param(@trx, "PARAMVALUE", ""));
  SET @ret := (SELECT trx_send(@trx));
  IF(OLD.`ParamKey`="allow-customer-order") THEN
    UPDATE `LocalStatus` SET `CheckCustomerOrders` = TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertCounterFamilies` AFTER INSERT ON `CounterFamilies`
FOR EACH ROW BEGIN
  IF (NEW.`CounterCode`= GLOBAL_GET("current_counter")) THEN
    UPDATE `LocalStatus` SET `CheckCounterFamilies`=TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateCounterFamilies` AFTER UPDATE ON `CounterFamilies`
FOR EACH ROW BEGIN
  IF (OLD.`CounterCode`= GLOBAL_GET("current_counter")) THEN
    UPDATE `LocalStatus` SET `CheckCounterFamilies`=TRUE;
  END IF;
  IF (NEW.`CounterCode`= GLOBAL_GET("current_counter")) THEN
    UPDATE `LocalStatus` SET `CheckCounterFamilies`=TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteCounterFamilies` AFTER DELETE ON `CounterFamilies`
FOR EACH ROW BEGIN
  IF (OLD.`CounterCode`= GLOBAL_GET("current_counter")) THEN
    UPDATE `LocalStatus` SET `CheckCounterFamilies`=TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertCounter` AFTER INSERT ON `Counters`
FOR EACH ROW BEGIN
	UPDATE `LocalStatus` SET `CheckCounters`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateCounter` AFTER UPDATE ON `Counters`
FOR EACH ROW BEGIN
  IF(NEW.`Code`!=OLD.`Code`) THEN
    UPDATE `LocalStatus` SET `CheckCounters`=TRUE;
  ELSE
    UPDATE `LocalStatus` SET `CheckCountersKeys`=TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteCounter` AFTER DELETE ON `Counters`
FOR EACH ROW BEGIN
	UPDATE `LocalStatus` SET `CheckCounters`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertEraseTickets` AFTER INSERT ON `EraseTickets`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `EraseTickets`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TicketsErased` AFTER UPDATE ON `EraseTickets`
FOR EACH ROW BEGIN
	UPDATE `LocalStatus` SET `EraseTickets`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertFamily` AFTER INSERT ON `Families`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckFamilies`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateFamily` AFTER UPDATE ON `Families`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckFamilies`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteFamily` AFTER DELETE ON `Families`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckFamilies`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `FiscalInserted` AFTER INSERT ON `Fiscal`
FOR EACH ROW BEGIN
  CALL DataloggerFiscalChange('', NEW.`Name`, 0, NEW.`Enabled`);
  INSERT INTO `LocalCfgScale` (`ParamKey`,`ParamValue`) VALUES ('CheckFiscal', '1') ON DUPLICATE KEY UPDATE `ParamValue`='1';
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `FiscalUpdated` AFTER UPDATE ON `Fiscal`
FOR EACH ROW BEGIN
  CALL DataloggerFiscalChange(OLD.`Name`, NEW.`Name`, OLD.`Enabled`, NEW.`Enabled`);
  IF ((NEW.`Enabled`!=OLD.`Enabled`) OR (NEW.`Status`!=OLD.`Status`)) THEN
    INSERT INTO `LocalCfgScale` (`ParamKey`,`ParamValue`) VALUES ('CheckFiscal', '1') ON DUPLICATE KEY UPDATE `ParamValue`='1';
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `FiscalDeleted` AFTER DELETE ON `Fiscal`
FOR EACH ROW BEGIN
  CALL DataloggerFiscalChange(OLD.`Name`, '', OLD.`Enabled`, 0);
  INSERT INTO `LocalCfgScale` (`ParamKey`,`ParamValue`) VALUES ('CheckFiscal', '1') ON DUPLICATE KEY UPDATE `ParamValue`='1';
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `HCtordInserted` AFTER INSERT ON `HCustomerOrders`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckCustomerOrders` = TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `HCtordUpdated` AFTER UPDATE ON `HCustomerOrders`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckCustomerOrders` = TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `HCtordDeleted` AFTER DELETE ON `HCustomerOrders`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckCustomerOrders` = TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `HTicketsInsert` AFTER INSERT ON `HTickets`
FOR EACH ROW BEGIN
  IF (NEW.`NetStat`='N') THEN
    IF (NEW.`Counter`= GLOBAL_GET("current_counter")) THEN
      REPLACE INTO `LocalVendorChanges` VALUES ((NEW.`Vendor`*10)+1, NEW.`Vendor`,'1');
    END IF;
    IF (NEW.`OrderNumber`!='') THEN
      UPDATE `HCustomerOrders` SET `HCustomerOrders`.`IdHTicket`=NEW.`Id`, `HCustomerOrders`.`Vendor`=NEW.`Vendor`, `HCustomerOrders`.`Scale`=NEW.`Scale`, `HCustomerOrders`.`Counter`=NEW.`Counter`,
        `HCustomerOrders`.`ReopenDateTime`=NOW(), `HCustomerOrders`.`StartDateTime`=IF(`HCustomerOrders`.`Status`=1, NOW(), `HCustomerOrders`.`StartDateTime`),
        `HCustomerOrders`.`DatTim`=IF(`HCustomerOrders`.`Status`=1, NOW(), `HCustomerOrders`.`DatTim`), `HCustomerOrders`.`Status`=IF(`HCustomerOrders`.`Status`=1, 2, `HCustomerOrders`.`Status`)
      WHERE (`HCustomerOrders`.`Number`=New.`OrderNumber`) AND (`HCustomerOrders`.`Section`=New.`SectionItem`) AND ((`HCustomerOrders`.`Status`>0) AND (`HCustomerOrders`.`Status`!=3));
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `HTicketsUpdateB` BEFORE UPDATE ON `HTickets`
FOR EACH ROW BEGIN
  IF(NEW.`NetStat`='N') THEN
    SET @frac_digits := IFNULL(GLOBAL_GET("frac_digits"), 2);

    IF(OLD.`PointsDiscount`!=NEW.`PointsDiscount`) THEN
      SET @lypoints = (SELECT IFNULL(`ParamValue`,0) FROM `CfgSystem` WHERE `ParamKey`='loyalty-points-discount-currency');
      SET NEW.`PointsAmount`= IF(@lypoints,ROUND(NEW.`PointsDiscount`/@lypoints, @frac_digits),0);
      SET NEW.`NetAmount`=`pcs_net`(NEW.`GrossAmount`, NEW.`tckDiscount`, NEW.`PointsAmount`);
    END IF;
    IF((OLD.`GrossAmount`!=NEW.`GrossAmount`) OR (OLD.`tckDiscount`!=NEW.`tckDiscount`) OR (OLD.`Customer`!=NEW.`Customer`)) THEN
      SET NEW.`PointsDiscount`=0;
      SET NEW.`PointsAmount`= 0;
      SET NEW.`NetAmount`=`pcs_net`(NEW.`GrossAmount`, NEW.`tckDiscount`, NEW.`PointsAmount`);
    END IF;
    IF(OLD.`NetAmount`!=NEW.`NetAmount`) THEN
      SET @points = (SELECT IFNULL(`ParamValue`,0) FROM `CfgSystem` WHERE `ParamKey`='loyalty-currency-give-point');
      SET NEW.`Points`=IF(@points,FLOOR(NEW.`NetAmount`/@points),0);
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `HTicketsUpdate` AFTER UPDATE ON `HTickets`
FOR EACH ROW BEGIN

  IF(NEW.`ReloadTo`!=0) AND (OLD.`Status`!= NEW.`Status`) THEN
    UPDATE `LTickets` SET `LTickets`.`ReloadTo`=NEW.`ReloadTo` WHERE `LTickets`.`IdHTicket`=OLD.`Id`;
  END IF;

  IF((NEW.`NetStat`='N') AND (NEW.`Counter`= GLOBAL_GET("current_counter"))) THEN
    REPLACE INTO `LocalVendorChanges` VALUES ((NEW.`Vendor`*10)+1, NEW.`Vendor`,'1');

    UPDATE `LocalHTickets` SET `Status`=NEW.`Status`, `TimesPrinted`=NEW.`TimesPrinted`,
      `Captured`=IF(NEW.`Captured`!='',NEW.`Captured`,`Captured`), `CapturedDateTime`=IF(NEW.`Captured`!='',NEW.`CapturedDateTime`,`CapturedDateTime`)
      WHERE `IdNetHticket`=NEW.`Id`;
  END IF;

  IF(OLD.`Number`!= NEW.`Number`) THEN
    IF((SELECT IFNULL(`ParamValue`, 0) FROM `CfgSystem` WHERE `ParamKey`='prices-without-taxes')=1) THEN
      UPDATE `LTickets` AS `lt` SET `lt`.`PrintScale`=NEW.`Scale`, `lt`.`PrintDateTime`=NEW.`DatTim`, `lt`.`PrintTicketNumber`=NEW.`Number`,
        `lt`.`PrinttckType`=NEW.`tckType`, `lt`.`TicketDiscount`=NEW.`tckDiscount`, `lt`.`BaseAmount`=`lt`.`Amount`
        WHERE `lt`.`IdHTicket`=NEW.`Id`;
    ELSE
      UPDATE `LTickets` AS `lt` SET `lt`.`PrintScale`=NEW.`Scale`, `lt`.`PrintDateTime`=NEW.`DatTim`, `lt`.`PrintTicketNumber`=NEW.`Number`,
        `lt`.`PrinttckType`=NEW.`tckType`, `lt`.`TicketDiscount`=NEW.`tckDiscount`, `lt`.`BaseAmount`=(`lt`.`Amount`*(100-NEW.`tckDiscount`))/(100+`lt`.`VATPercent`)
        WHERE `lt`.`IdHTicket`=NEW.`Id`;
    END IF;
  END IF;


  IF(BINARY OLD.`Status`!= NEW.`Status`) THEN

   IF(BINARY NEW.`Status` IN ('C','V')) THEN

      INSERT INTO `TotalDaily` (`Date`, `Type`, `NetStat`, `Tickets`, `TotalLines`, `TotalAmount`, `TotalDiscount`, `TotalWeight`, `TotalUnits`,
        `NegativeLines`, `NegativeAmount`, `CanceledLines`, `CanceledAmount`, `ReloadedTickets`, `TotalReloadedAmount`,
        `Invoices`, `InvoiceAmount`, `InvoicesRefund`, `InvoiceAmountRefund`, `AccumulatedAmount`)
        VALUES (DATE(NEW.`DatTim`), NEW.`tckType`, NEW.`NetStat`, 1, NEW.`NumLines`, NEW.`NetAmount`, (NEW.`GrossAmount`-NEW.`NetAmount`), NEW.`TotalWeight`, NEW.`TotalUnits`,
        NEW.`NegativeLines`, NEW.`NegativeAmount`, NEW.`CanceledLines`, NEW.`CanceledAmount`, 0, 0,
        IF(NEW.`Invoice`!='',1,0), IF(NEW.`Invoice`!='',NEW.`NetAmount`,0), IF(BINARY NEW.`Status`='V',1,0), IF(BINARY NEW.`Status`='V',-NEW.`NetAmount`,0),
        NEW.`NetAmount`+IFNULL((SELECT `TotalAmount` FROM `TotalPerpetual` WHERE `TotalPerpetual`.`Type`=NEW.`tckType` AND `TotalPerpetual`.`NetStat`=NEW.`NetStat`),0) )
        ON DUPLICATE KEY UPDATE
          `TotalDaily`.`PrintChgCounter`=`TotalDaily`.`PrintChgCounter`+`TotalDaily`.`Printed`, `TotalDaily`.`Printed`=0,
          `TotalDaily`.`Tickets`=`TotalDaily`.`Tickets`+VALUES(`Tickets`),`TotalDaily`.`TotalLines`=`TotalDaily`.`TotalLines`+VALUES(`TotalLines`),`TotalAmount`=`TotalAmount`+VALUES(`TotalAmount`),
          `TotalDiscount`=`TotalDiscount`+VALUES(`TotalDiscount`), `TotalWeight`=`TotalWeight`+VALUES(`TotalWeight`), `TotalUnits`=`TotalUnits`+VALUES(`TotalUnits`),
          `NegativeLines`=`NegativeLines`+VALUES(`NegativeLines`), `NegativeAmount`=`NegativeAmount`+VALUES(`NegativeAmount`),
          `CanceledLines`=`CanceledLines`+VALUES(`CanceledLines`), `CanceledAmount`=`CanceledAmount`+VALUES(`CanceledAmount`),
          `ReloadedTickets`=`ReloadedTickets`+VALUES(`ReloadedTickets`), `TotalReloadedAmount`=`TotalReloadedAmount`+VALUES(`TotalReloadedAmount`),
          `Invoices`=`Invoices`+VALUES(`Invoices`), `InvoiceAmount`=`InvoiceAmount`+VALUES(`InvoiceAmount`),
          `InvoicesRefund`=`InvoicesRefund`+VALUES(`InvoicesRefund`), `InvoiceAmountRefund`=`InvoiceAmountRefund`+VALUES(`InvoiceAmountRefund`),
          `AccumulatedAmount`=VALUES(`AccumulatedAmount`);

      INSERT INTO `TotalPerpetual` (`Date`, `Type`, `NetStat`, `Tickets`, `TotalLines`, `TotalAmount`, `TotalDiscount`, `TotalWeight`, `TotalUnits`,
        `NegativeLines`, `NegativeAmount`, `CanceledLines`, `CanceledAmount`, `ReloadedTickets`, `TotalReloadedAmount`,
        `Invoices`, `InvoiceAmount`, `InvoicesRefund`, `InvoiceAmountRefund`)
        VALUES (DATE(NEW.`DatTim`), NEW.`tckType`, NEW.`NetStat`, 1, NEW.`NumLines`, NEW.`NetAmount`, (NEW.`GrossAmount`-NEW.`NetAmount`), NEW.`TotalWeight`, NEW.`TotalUnits`,
        NEW.`NegativeLines`, NEW.`NegativeAmount`, NEW.`CanceledLines`, NEW.`CanceledAmount`, 0, 0,
        IF(NEW.`Invoice`!='',1,0), IF(NEW.`Invoice`!='',NEW.`NetAmount`,0), IF(BINARY NEW.`Status`='V',1,0), IF(BINARY NEW.`Status`='V',-NEW.`NetAmount`,0)  )
        ON DUPLICATE KEY UPDATE
          `TotalPerpetual`.`Tickets`=`TotalPerpetual`.`Tickets`+VALUES(`Tickets`),`TotalPerpetual`.`TotalLines`=`TotalPerpetual`.`TotalLines`+VALUES(`TotalLines`),
          `TotalAmount`=`TotalAmount`+VALUES(`TotalAmount`),
          `TotalDiscount`=`TotalDiscount`+VALUES(`TotalDiscount`), `TotalWeight`=`TotalWeight`+VALUES(`TotalWeight`), `TotalUnits`=`TotalUnits`+VALUES(`TotalUnits`),
          `NegativeLines`=`NegativeLines`+VALUES(`NegativeLines`), `NegativeAmount`=`NegativeAmount`+VALUES(`NegativeAmount`),
          `CanceledLines`=`CanceledLines`+VALUES(`CanceledLines`), `CanceledAmount`=`CanceledAmount`+VALUES(`CanceledAmount`),
          `ReloadedTickets`=`ReloadedTickets`+VALUES(`ReloadedTickets`), `TotalReloadedAmount`=`TotalReloadedAmount`+VALUES(`TotalReloadedAmount`),
          `Invoices`=`Invoices`+VALUES(`Invoices`), `InvoiceAmount`=`InvoiceAmount`+VALUES(`InvoiceAmount`),
          `InvoicesRefund`=`InvoicesRefund`+VALUES(`InvoicesRefund`), `InvoiceAmountRefund`=`InvoiceAmountRefund`+VALUES(`InvoiceAmountRefund`);

      IF(NEW.`GrossAmount`!=0) THEN
        IF((SELECT IFNULL(`ParamValue`, 0) FROM `CfgSystem` WHERE `ParamKey`='prices-without-taxes')=1) THEN
          INSERT INTO `TotalVAT` (`Date`, `Type`, `NetStat`, `Code`, `Percentage`, `Amount`, `Base`, `Tax`)
            SELECT DATE(NEW.`DatTim`), NEW.`tckType`, NEW.`NetStat`, `V_VAT`.`VATCode`, `V_VAT`.`VATPercent`, `V_VAT`.`Base` + CAST(((`V_VAT`.`Base`*`VATPercent`)/100) AS DECIMAL(10,2)) AS `Amount`,
            `V_VAT`.`Base` AS `Base`, CAST(((`V_VAT`.`Base`*`VATPercent`)/100) AS DECIMAL(10,2)) AS Tax
            FROM (SELECT `VATCode`, `VATPercent`, CAST(SUM(`LTickets`.`Amount`)*(NEW.`NetAmount`/NEW.`GrossAmount`) AS DECIMAL(10,2)) AS `Base`
              FROM `LTickets` WHERE `LTickets`.`IdHTicket`=OLD.`Id` AND `LTickets`.`lineType`=1 GROUP BY `LTickets`.`VATCode`) AS `V_VAT`
              ON DUPLICATE KEY UPDATE
                `TotalVAT`.`Amount`=`TotalVAT`.`Amount`+VALUES(`Amount`), `TotalVAT`.`Base`=`TotalVAT`.`Base`+VALUES(`Base`),`TotalVAT`.`Tax`=`TotalVAT`.`Tax`+VALUES(`Tax`);
        ELSE
          INSERT INTO `TotalVAT` (`Date`, `Type`, `NetStat`, `Code`, `Percentage`, `Amount`, `Base`, `Tax`)
            SELECT DATE(NEW.`DatTim`), NEW.`tckType`, NEW.`NetStat`, `V_VAT`.`VATCode`, `V_VAT`.`VATPercent`, `V_VAT`.`Amount`,
            CAST((`V_VAT`.`Amount`*100)/(100+`VATPercent`) AS DECIMAL(10,2)) AS `Base`, `V_VAT`.`Amount` - CAST((`V_VAT`.`Amount`*100)/(100+`VATPercent`) AS DECIMAL(10,2)) AS Tax
            FROM (SELECT `VATCode`, `VATPercent`, CAST(SUM(`LTickets`.`Amount`)*(NEW.`NetAmount`/NEW.`GrossAmount`) AS DECIMAL(10,2)) AS `Amount`
              FROM `LTickets` WHERE `LTickets`.`IdHTicket`=OLD.`Id` AND `LTickets`.`lineType`=1 GROUP BY `LTickets`.`VATCode`) AS `V_VAT`
              ON DUPLICATE KEY UPDATE
                `TotalVAT`.`Amount`=`TotalVAT`.`Amount`+VALUES(`Amount`), `TotalVAT`.`Base`=`TotalVAT`.`Base`+VALUES(`Base`),`TotalVAT`.`Tax`=`TotalVAT`.`Tax`+VALUES(`Tax`);
        END IF;
      END IF;

      INSERT INTO `TotalPayTickets` (`Date`, `Type`, `NetStat`, `PayMethod`, `Delivered`)
        (SELECT DATE(NEW.`DatTim`), NEW.`tckType`, NEW.`NetStat`,`PayMethod`, `Delivered` FROM `PayTickets` WHERE `PayTickets`.`IdHTicket`=OLD.`Id`)
        ON DUPLICATE KEY UPDATE
         `TotalPayTickets`.`Delivered`=`TotalPayTickets`.`Delivered`+VALUES(`Delivered`);

      UPDATE `Customers` SET `Customers`.`Points`=GREATEST(`Customers`.`Points`+(NEW.`Points`+NEW.`PointsExtra`)-(NEW.`PointsDiscount`+NEW.`PointsChanged`),0) WHERE `Customers`.`TIN`=NEW.`Customer`;

      IF(NEW.`tckType`!='U') THEN


        IF(OLD.`Invoice`!='') THEN
          INSERT INTO `Invoices` (`Number`, `Date`, `Customer`, `Type`) VALUES (OLD.`Invoice`, OLD.`InvoiceDate`, OLD.`Customer`, IF(OLD.`SimplifiedInvoice`=1,'0','1'));
          INSERT INTO `InvoiceDetails` (`IdInvoice`, `IdHTicket`) VALUES (LAST_INSERT_ID(), OLD.`Id`);
        END IF;

        INSERT INTO `TotalScaleFamilies` (`Date`, `Scale`, `Family`, `TotalWeight`, `TotalUnits`)
          SELECT CONCAT(YEAR(NEW.`DatTim`),'-',MONTH(NEW.`DatTim`), '-01'), NEW.`Scale`, `Family`, SUM(IF(`Saleform`=1,`Weight`,0)), SUM(IF(`Saleform`=0,`Weight`,0))
          FROM `LTickets` WHERE (`IdHTicket`=OLD.`Id` AND `LTickets`.`lineType`=1) GROUP BY `Family`
          ON DUPLICATE KEY UPDATE
            `TotalScaleFamilies`.`PrintChgCounter`=`TotalScaleFamilies`.`PrintChgCounter`+`TotalScaleFamilies`.`Printed`, `TotalScaleFamilies`.`Printed`=0,
            `TotalWeight`=`TotalWeight`+ VALUES(`TotalWeight`), `TotalUnits`=`TotalUnits`+ VALUES(`TotalUnits`);

      END IF;

    END IF;

    IF((OLD.`Status`='C') AND (NEW.`Status`='R')) THEN


      INSERT INTO `TotalDaily` (`Date`, `Type`, `NetStat`, `Tickets`, `TotalLines`, `TotalAmount`, `TotalDiscount`, `TotalWeight`, `TotalUnits`,
        `NegativeLines`, `NegativeAmount`, `CanceledLines`, `CanceledAmount`, `ReloadedTickets`, `TotalReloadedAmount`,
        `Invoices`, `InvoiceAmount`, `InvoicesRefund`, `InvoiceAmountRefund`, `AccumulatedAmount`)
        VALUES (CURDATE(), OLD.`tckType`, OLD.`NetStat`, 1, -OLD.`NumLines`, -OLD.`NetAmount`, -(OLD.`GrossAmount`-OLD.`NetAmount`), -OLD.`TotalWeight`, -OLD.`TotalUnits`,
        -OLD.`NegativeLines`, -OLD.`NegativeAmount`, -OLD.`CanceledLines`, -OLD.`CanceledAmount`, 1, OLD.`NetAmount`,
        -IF(OLD.`Invoice`!='',1,0), -IF(OLD.`Invoice`!='',OLD.`NetAmount`,0), 0, 0,
        -OLD.`NetAmount`+IFNULL((SELECT `TotalAmount` FROM `TotalPerpetual` WHERE `TotalPerpetual`.`Type`=OLD.`tckType` AND `TotalPerpetual`.`NetStat`=OLD.`NetStat`),0) )
        ON DUPLICATE KEY UPDATE
          `TotalDaily`.`PrintChgCounter`=`TotalDaily`.`PrintChgCounter`+`TotalDaily`.`Printed`, `TotalDaily`.`Printed`=0,
          `TotalDaily`.`Tickets`=`TotalDaily`.`Tickets`+VALUES(`Tickets`),`TotalDaily`.`TotalLines`=`TotalDaily`.`TotalLines`+VALUES(`TotalLines`),`TotalAmount`=`TotalAmount`+VALUES(`TotalAmount`),
          `TotalDiscount`=`TotalDiscount`+VALUES(`TotalDiscount`), `TotalWeight`=`TotalWeight`+VALUES(`TotalWeight`), `TotalUnits`=`TotalUnits`+VALUES(`TotalUnits`),
          `NegativeLines`=`NegativeLines`+VALUES(`NegativeLines`), `NegativeAmount`=`NegativeAmount`+VALUES(`NegativeAmount`),
          `CanceledLines`=`CanceledLines`+VALUES(`CanceledLines`), `CanceledAmount`=`CanceledAmount`+VALUES(`CanceledAmount`),
          `ReloadedTickets`=`ReloadedTickets`+VALUES(`ReloadedTickets`), `TotalReloadedAmount`=`TotalReloadedAmount`+VALUES(`TotalReloadedAmount`),
          `Invoices`=`Invoices`+VALUES(`Invoices`), `InvoiceAmount`=`InvoiceAmount`+VALUES(`InvoiceAmount`),
          `InvoicesRefund`=`InvoicesRefund`+VALUES(`InvoicesRefund`), `InvoiceAmountRefund`=`InvoiceAmountRefund`+VALUES(`InvoiceAmountRefund`),
          `AccumulatedAmount`=VALUES(`AccumulatedAmount`);

      INSERT INTO `TotalPerpetual` (`Date`, `Type`, `NetStat`, `Tickets`, `TotalLines`, `TotalAmount`, `TotalDiscount`, `TotalWeight`, `TotalUnits`,
        `NegativeLines`, `NegativeAmount`, `CanceledLines`, `CanceledAmount`, `ReloadedTickets`, `TotalReloadedAmount`,
        `Invoices`, `InvoiceAmount`, `InvoicesRefund`, `InvoiceAmountRefund`)
        VALUES (CURDATE(), OLD.`tckType`, OLD.`NetStat`, 1, -OLD.`NumLines`, -OLD.`NetAmount`, -(OLD.`GrossAmount`-OLD.`NetAmount`), -OLD.`TotalWeight`, -OLD.`TotalUnits`,
        -OLD.`NegativeLines`, -OLD.`NegativeAmount`, -OLD.`CanceledLines`, -OLD.`CanceledAmount`, 1, OLD.`NetAmount`, -IF(OLD.`Invoice`!='',1,0), -IF(OLD.`Invoice`!='',OLD.`NetAmount`,0), 0, 0 )
        ON DUPLICATE KEY UPDATE
          `TotalPerpetual`.`Tickets`=`TotalPerpetual`.`Tickets`+VALUES(`Tickets`),`TotalPerpetual`.`TotalLines`=`TotalPerpetual`.`TotalLines`+VALUES(`TotalLines`),
          `TotalAmount`=`TotalAmount`+VALUES(`TotalAmount`),
          `TotalDiscount`=`TotalDiscount`+VALUES(`TotalDiscount`), `TotalWeight`=`TotalWeight`+VALUES(`TotalWeight`), `TotalUnits`=`TotalUnits`+VALUES(`TotalUnits`),
          `NegativeLines`=`NegativeLines`+VALUES(`NegativeLines`), `NegativeAmount`=`NegativeAmount`+VALUES(`NegativeAmount`),
          `CanceledLines`=`CanceledLines`+VALUES(`CanceledLines`), `CanceledAmount`=`CanceledAmount`+VALUES(`CanceledAmount`),
          `ReloadedTickets`=`ReloadedTickets`+VALUES(`ReloadedTickets`), `TotalReloadedAmount`=`TotalReloadedAmount`+VALUES(`TotalReloadedAmount`),
          `Invoices`=`Invoices`+VALUES(`Invoices`), `InvoiceAmount`=`InvoiceAmount`+VALUES(`InvoiceAmount`),
          `InvoicesRefund`=`InvoicesRefund`+VALUES(`InvoicesRefund`), `InvoiceAmountRefund`=`InvoiceAmountRefund`+VALUES(`InvoiceAmountRefund`);

      IF(OLD.`GrossAmount`!=0) THEN
        IF((SELECT IFNULL(`ParamValue`, 0) FROM `CfgSystem` WHERE `ParamKey`='prices-without-taxes')=1) THEN
          INSERT INTO `TotalVAT` (`Date`, `Type`, `NetStat`, `Code`, `Percentage`, `Amount`, `Base`, `Tax`)
            SELECT DATE(NEW.`DatTim`), NEW.`tckType`, NEW.`NetStat`, `V_VAT`.`VATCode`, `V_VAT`.`VATPercent`, -(`V_VAT`.`Base` + CAST(((`V_VAT`.`Base`*`VATPercent`)/100) AS DECIMAL(10,2))) AS `Amount`,
            -`V_VAT`.`Base` AS `Base`, -CAST(((`V_VAT`.`Base`*`VATPercent`)/100) AS DECIMAL(10,2)) AS Tax
            FROM (SELECT `VATCode`, `VATPercent`, CAST(SUM(`LTickets`.`Amount`)*(NEW.`NetAmount`/NEW.`GrossAmount`) AS DECIMAL(10,2)) AS `Base`
              FROM `LTickets` WHERE `LTickets`.`IdHTicket`=OLD.`Id` AND `LTickets`.`lineType`=1 GROUP BY `LTickets`.`VATCode`) AS `V_VAT`
              ON DUPLICATE KEY UPDATE
                `TotalVAT`.`Amount`=`TotalVAT`.`Amount`+VALUES(`Amount`), `TotalVAT`.`Base`=`TotalVAT`.`Base`+VALUES(`Base`),`TotalVAT`.`Tax`=`TotalVAT`.`Tax`+VALUES(`Tax`);
        ELSE
          INSERT INTO `TotalVAT` (`Date`, `Type`, `NetStat`, `Code`, `Percentage`, `Amount`, `Base`, `Tax`)
            SELECT CURDATE(), OLD.`tckType`, OLD.`NetStat`, `V_VAT`.`VATCode`, `V_VAT`.`VATPercent`, -`V_VAT`.`Amount`,
            -CAST((`V_VAT`.`Amount`*100)/(100+`VATPercent`) AS DECIMAL(10,2)) AS `Base`, -(`V_VAT`.`Amount` - CAST((`V_VAT`.`Amount`*100)/(100+`VATPercent`) AS DECIMAL(10,2))) AS Tax
             FROM (SELECT `VATCode`, `VATPercent`, CAST(SUM(`LTickets`.`Amount`)*(OLD.`NetAmount`/OLD.`GrossAmount`) AS DECIMAL(10,2)) AS `Amount`
              FROM `LTickets` WHERE `LTickets`.`IdHTicket`=OLD.`Id` AND `LTickets`.`lineType`=1 GROUP BY `LTickets`.`VATCode`) AS `V_VAT`
              ON DUPLICATE KEY UPDATE
                `TotalVAT`.`Amount`=`TotalVAT`.`Amount`+VALUES(`Amount`), `TotalVAT`.`Base`=`TotalVAT`.`Base`+VALUES(`Base`),`TotalVAT`.`Tax`=`TotalVAT`.`Tax`+VALUES(`Tax`);
        END IF;
      END IF;

      INSERT INTO `TotalPayTickets` (`Date`, `Type`, `NetStat`, `PayMethod`, `Delivered`)
        (SELECT CURDATE(), OLD.`tckType`, OLD.`NetStat`,`PayMethod`, -`Delivered` FROM `PayTickets` WHERE `PayTickets`.`IdHTicket`=OLD.`Id`)
        ON DUPLICATE KEY UPDATE
          `TotalPayTickets`.`Delivered`=`TotalPayTickets`.`Delivered`+VALUES(`Delivered`);

      UPDATE `Customers` SET `Customers`.`Points`=GREATEST(`Customers`.`Points`-(OLD.`Points`+OLD.`PointsExtra`)+(OLD.`PointsDiscount`+OLD.`PointsChanged`),0) WHERE `Customers`.`TIN`=NEW.`Customer`;

      IF(OLD.`tckType`!='U') THEN


        UPDATE `TotalScaleFamilies`,
          (SELECT CONCAT(YEAR(NEW.`DatTim`),'-',MONTH(NEW.`DatTim`), '-01') AS `fdt`,
          `Family`, SUM(IF(`Saleform`=1,`Weight`,0)) AS `fwght`, SUM(IF(`Saleform`=0,`Weight`,0)) AS `funits` FROM `LTickets` WHERE (`IdHTicket`=OLD.`Id` AND `LTickets`.`lineType`=1) GROUP BY `Family`) AS `VT_F`
          SET `TotalWeight`=`TotalWeight`-`VT_F`.`fwght` , `TotalUnits`=`TotalUnits`+ `VT_F`.`funits` WHERE (`Date`=`VT_F`.`fdt` AND `Scale`=NEW.`Scale` AND `TotalScaleFamilies`.`Family`=`VT_F`.`Family`);

        IF(OLD.`OrderNumber`!='') THEN
          UPDATE `HCustomerOrders` SET `HCustomerOrders`.`AddedLines`=`HCustomerOrders`.`AddedLines`-OLD.`AddedLines`, `HCustomerOrders`.`NetAmount`=`HCustomerOrders`.`NetAmount`-OLD.`NetAmount`,
            `HCustomerOrders`.`TotalWeight`=`HCustomerOrders`.`TotalWeight`-OLD.`TotalWeight`, `HCustomerOrders`.`TotalUnits`=`HCustomerOrders`.`TotalUnits`-OLD.`TotalUnits`, `HCustomerOrders`.`ReopenDateTime`=NOW()
            WHERE `HCustomerOrders`.`IdHTicket`=OLD.`Id` AND `HCustomerOrders`.`Status`=2;
        END IF;

      END IF;


    END IF;


    IF(OLD.`OrderNumber`!='') THEN
      IF(NEW.`Status`='C') THEN

        UPDATE `HCustomerOrders` SET `HCustomerOrders`.`NumberHTicket`=NEW.`Number`,`HCustomerOrders`.`Status`=3 WHERE `HCustomerOrders`.`IdHTicket`=OLD.`Id` AND `HCustomerOrders`.`Status`=2;
      ELSEIF(OLD.`Status`='O' AND NEW.`Status`='z') THEN

        UPDATE `HCustomerOrders` SET `HCustomerOrders`.`Vendor`=0,
          `HCustomerOrders`.`DatTim`=ADDDATE(`HCustomerOrders`.`DatTim`, INTERVAL TIME_TO_SEC(TIMEDIFF(NOW(),`HCustomerOrders`.`ReopenDateTime`)) SECOND)
          WHERE `HCustomerOrders`.`Number`=OLD.`OrderNumber` AND `HCustomerOrders`.`IdHTicket`=OLD.`Id` AND `HCustomerOrders`.`Status`=2;
      ELSEIF(OLD.`Status`='z' AND NEW.`Status`='O') THEN

        UPDATE `HCustomerOrders` SET `HCustomerOrders`.`Vendor`=NEW.`Vendor`, `HCustomerOrders`.`Scale`=NEW.`Scale`,`HCustomerOrders`.`Counter`=NEW.`Counter`,`HCustomerOrders`.`ReopenDateTime`=NOW()
          WHERE `HCustomerOrders`.`Number`=OLD.`OrderNumber` AND `HCustomerOrders`.`IdHTicket`=OLD.`Id` AND (`HCustomerOrders`.`Status`=2 OR `HCustomerOrders`.`Status`=4 OR `HCustomerOrders`.`Status`=5);
     END IF;
    END IF;


    IF(NEW.`Status` IN ('X','R')) THEN
      UPDATE `Stock`,
        (SELECT `Item`, SUM(IF(`Saleform`=1,IF(`Price`<0,-`Weight`,`Weight`),0)) AS `lwght`, SUM(IF(`Saleform`=0,IF(`Price`<0,-`Weight`,`Weight`),0)) AS `lunits` FROM `LTickets` WHERE (`IdHTicket`=OLD.`Id` AND ((`LTickets`.`lineType`&1)=1)) GROUP BY `Item`) AS `VT_L`
        SET `Stock`.`Weight`=(`Stock`.`Weight`+`VT_L`.`lwght`), `Stock`.`Units`=(`Stock`.`Units`+`VT_L`.`lunits`) WHERE `Stock`.`Code` = `VT_L`.`Item`;
    END IF;


  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `HTicketsDelete` AFTER DELETE ON `HTickets`
FOR EACH ROW BEGIN
  IF (OLD.`Counter`= GLOBAL_GET("current_counter")) THEN
    REPLACE INTO `LocalVendorChanges` VALUES ((OLD.`Vendor`*10)+1, OLD.`Vendor`,'1');
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `RemoveInvoice` AFTER DELETE ON `Invoices`
FOR EACH ROW BEGIN
  IF (@delete_tickets_from_invoices=1) THEN
    DELETE `InvoiceDetails`, `HTickets` FROM `InvoiceDetails` INNER JOIN `HTickets` WHERE IdHTicket=HTickets.Id AND IdInvoice=OLD.`Id`;
  ELSE
    UPDATE `HTickets` LEFT JOIN `InvoiceDetails` ON HTickets.Id=InvoiceDetails.IdHTicket SET HTickets.Invoice=DEFAULT(HTickets.Invoice), HTickets.InvoiceDate=DEFAULT(HTickets.InvoiceDate) WHERE IdInvoice=OLD.`Id`;
    DELETE FROM `InvoiceDetails` WHERE IdInvoice=OLD.`Id`;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertItemGroupKeys` AFTER INSERT ON `ItemGroupKeys`
FOR EACH ROW BEGIN
  INSERT INTO `LocalItemGroupKeysChanges` (`NumKey`) VALUES (NEW.`NumKey`) ON DUPLICATE KEY UPDATE `NumKey`=VALUES(`NumKey`);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateItemGroupKeys` AFTER UPDATE ON `ItemGroupKeys`
FOR EACH ROW BEGIN
  INSERT INTO `LocalItemGroupKeysChanges` (`NumKey`) VALUES (OLD.`NumKey`) ON DUPLICATE KEY UPDATE `NumKey`=VALUES(`NumKey`);
  INSERT INTO `LocalItemGroupKeysChanges` (`NumKey`) VALUES (NEW.`NumKey`) ON DUPLICATE KEY UPDATE `NumKey`=VALUES(`NumKey`);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteItemGroupKeys` AFTER DELETE ON `ItemGroupKeys`
FOR EACH ROW BEGIN
  INSERT INTO `LocalItemGroupKeysChanges` (`NumKey`) VALUES (OLD.`NumKey`) ON DUPLICATE KEY UPDATE `NumKey`=VALUES(`NumKey`);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertItemGroupKeysText` AFTER INSERT ON `ItemGroupKeysText`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckItemGroupKeysText`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateItemGroupKeysText` AFTER UPDATE ON `ItemGroupKeysText`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckItemGroupKeysText`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteItemGroupKeysText` AFTER DELETE ON `ItemGroupKeysText`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckItemGroupKeysText`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemHabitualInserted` AFTER INSERT ON `ItemHabitual`
FOR EACH ROW BEGIN
  SET @toffer := IFNULL (GLOBAL_GET("table-offer"),0);
  SET @thabitual := IFNULL (GLOBAL_GET("table-habitual"),0);
  IF (@thabitual!=0) THEN
    IF ((SELECT IF(`Items`.`PLU`!=0 AND (`Items`.`Offer`=0 OR @toffer=0) ,0,1) FROM `Items` WHERE `Items`.`Code`=NEW.`Code`)=0) THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (GLOBAL_GET("current_group"),@thabitual,NEW.`Position`,NEW.`Code`)
        ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemHabitualUpdated` AFTER UPDATE ON `ItemHabitual`
FOR EACH ROW BEGIN
  SET @toffer := IFNULL (GLOBAL_GET("table-offer"),0);
  SET @thabitual := IFNULL (GLOBAL_GET("table-habitual"),0);
  IF (@thabitual!=0) THEN
    INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (GLOBAL_GET("current_group"),@thabitual,OLD.`Position`,0)
      ON DUPLICATE KEY UPDATE `Code`=0;
    IF ((SELECT IF(`Items`.`PLU`!=0 AND (`Items`.`Offer`=0 OR @toffer=0) ,0,1) FROM `Items` WHERE `Items`.`Code`=NEW.`Code`)=0) THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (GLOBAL_GET("current_group"),@thabitual,NEW.`Position`,NEW.`Code`)
        ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemHabitualDeleted` AFTER DELETE ON `ItemHabitual`
FOR EACH ROW BEGIN
  SET @thabitual := IFNULL (GLOBAL_GET("table-habitual"),0);
  IF (@thabitual!=0) THEN
    INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (GLOBAL_GET("current_group"),@thabitual,OLD.`Position`,0)
    ON DUPLICATE KEY UPDATE `Code`=0;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertMiddleWeight` AFTER INSERT ON `ItemMiddleWeights`
FOR EACH ROW BEGIN
  INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,`Code` FROM `PLUKeys`
    WHERE `Code`=NEW.`Code` AND (`PLUKeys`.`Section`=GLOBAL_GET("current_group") OR (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard")) )
    ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateMiddleWeight` AFTER UPDATE ON `ItemMiddleWeights`
FOR EACH ROW BEGIN
  INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,`Code` FROM `PLUKeys`
    WHERE `Code`=NEW.`Code` AND (`PLUKeys`.`Section`=GLOBAL_GET("current_group") OR (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard")) )
    ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteMiddleWeight` AFTER DELETE ON `ItemMiddleWeights`
FOR EACH ROW BEGIN
  INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,`Code` FROM `PLUKeys`
    WHERE `Code`=OLD.`Code` AND (`PLUKeys`.`Section`=GLOBAL_GET("current_group") OR (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard")) )
    ON DUPLICATE KEY UPDATE `Code`=OLD.`Code`;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertItemOfferDates` AFTER INSERT ON `ItemOfferDates`
FOR EACH ROW BEGIN
  IF(NEW.StartDate<=CURDATE() AND NEW.EndDate>=CURDATE()) THEN
    UPDATE `Items` SET `Items`.`Price`=`Items`.`Price` WHERE `Items`.`Code`=NEW.`Code`;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateItemOfferDates` AFTER UPDATE ON `ItemOfferDates`
FOR EACH ROW BEGIN
  IF((NEW.StartDate<=CURDATE() AND NEW.EndDate>=CURDATE()) OR (OLD.StartDate<=CURDATE() AND OLD.EndDate>=CURDATE())) THEN
    UPDATE `Items` SET `Items`.`Price`=`Items`.`Price` WHERE (`Items`.`Code`=NEW.`Code`) OR (`Items`.`Code`=OLD.`Code`);
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteItemOfferDates` AFTER DELETE ON `ItemOfferDates`
FOR EACH ROW BEGIN
    UPDATE `Items` SET `Items`.`Price`=`Items`.`Price` WHERE `Items`.`Code`=OLD.`Code`;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertItemOfferPricerates` AFTER INSERT ON `ItemOfferPricerates`
FOR EACH ROW BEGIN
  IF(NEW.Rate=0 AND NEW.Step=0) THEN
    UPDATE `Items` SET `Items`.`Price`=`Items`.`Price` WHERE (`Items`.`Code`=NEW.`Code`);
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateItemOfferPricerates` AFTER UPDATE ON `ItemOfferPricerates`
FOR EACH ROW BEGIN
  IF((NEW.Rate=0 AND NEW.Step=0) OR (OLD.Rate=0 AND OLD.Step=0)) THEN
    UPDATE `Items` SET `Items`.`Price`=`Items`.`Price` WHERE (`Items`.`Code`=NEW.`Code`) OR (`Items`.`Code`=OLD.`Code`);
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteItemOfferPricerates` AFTER DELETE ON `ItemOfferPricerates`
FOR EACH ROW BEGIN
  IF(OLD.Rate=0 AND OLD.Step=0) THEN
    UPDATE `Items` SET `Items`.`Price`=`Items`.`Price` WHERE (`Items`.`Code`=OLD.`Code`);
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemsInsertedB` BEFORE INSERT ON `Items`
FOR EACH ROW BEGIN
  IF(NEW.`FamilyOrder`=0) THEN
    SET NEW.`FamilyOrder`=IFNULL(
      (SELECT t1.`FamilyOrder`+1 as _id FROM (SELECT `FamilyOrder` FROM `Items` WHERE `Family`=NEW.`Family`) AS t1 
      LEFT JOIN (SELECT `FamilyOrder` FROM `Items` WHERE `Family`=NEW.`Family`) AS t2 ON t2.`FamilyOrder`=t1.`FamilyOrder`+1 
      WHERE t2.`FamilyOrder` IS NULL LIMIT 1), 1);
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemsInserted` AFTER INSERT ON `Items`
FOR EACH ROW BEGIN
  IF(NEW.`EAN13`!='') THEN
    INSERT INTO ItemsEAN13 (`Code`, `EAN13`) VALUES (NEW.`Code`, NEW.`EAN13`) ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
  END IF;
  SET @loadfunc := IFNULL (GLOBAL_GET("PLUload-func"),99);
  CASE @loadfunc

    WHEN 0 THEN
      IF (NEW.`Inactive`=FALSE) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,`Code` FROM `PLUKeys`
          WHERE `Code`=NEW.`Code` AND (`PLUKeys`.`Section`=GLOBAL_GET("current_group") OR (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard")) )
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
     END IF;

    WHEN 1 THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,`Code` FROM `PLUKeys`
        WHERE `Code`=NEW.`Code` AND (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard"))
        ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,NEW.`Family`,`PLUKey`,`Code` FROM `PLUKeys`
        WHERE `Code`=NEW.`Code` AND `PLUKeys`.`Section`=GLOBAL_GET("current_group")
        ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);

    WHEN 2 THEN
      SET @famor := (SELECT `FamilyIndex` FROM `CounterFamilies` WHERE `CounterCode`=GLOBAL_GET("current_counter") AND `FamilyCode`=NEW.`Family`);
      IF ((NEW.`OnKey`=TRUE) AND (NEW.`Inactive`=FALSE)) THEN
        IF (@famor IS NOT NULL) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES(GLOBAL_GET("current_group"),@famor,NEW.`FamilyOrder`,NEW.`Code`)
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
        END IF;
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,`Code` FROM `PLUKeys`
          WHERE `Code`=NEW.`Code` AND (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard"))
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;

    WHEN 3 THEN
      IF (NEW.`Counter`!=0) AND (NEW.`PLU`!=0) AND (NEW.`Counter`=GLOBAL_GET("current_counter")) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (NEW.`Counter`,0,NEW.`PLU`, NEW.`Code`)
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;

    WHEN 100 THEN
      IF (NEW.`Counter`!=0) AND (NEW.`PLU`!=0) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Counter`,board_idx,NEW.`PLU`, NEW.`Code`
        FROM (SELECT IF(Code=GLOBAL_GET("current_counter"),1,@a:=@a+1) AS board_idx, Code FROM (SELECT @a:=1) AS ct, Counters) AS tt100 WHERE NEW.`Counter`=tt100.Code
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;

    WHEN 101 THEN
      IF (NEW.`Counter`!=0) AND (NEW.`PLU`!=0) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Counter`,board_idx,NEW.`PLU`, NEW.`Code`
        FROM (SELECT @a:=@a+1 AS board_idx, Code FROM (SELECT @a:=0) AS ct, Counters) AS tt100 WHERE NEW.`Counter`=tt100.Code
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;

    WHEN 4 THEN
      IF ((NEW.`PLU`!=0) AND (NEW.`Code`!=0)) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
          SELECT GLOBAL_GET("current_group"),`ItemGroupKeys`.`NumKey`,NEW.`PLU`,NEW.`Code` FROM `ItemGroupKeys`
          WHERE ((`ItemGroupKeys`.`Abovesection`!=0 AND `ItemGroupKeys`.`Abovesection`=NEW.`Abovesection`) OR (`ItemGroupKeys`.`Abovesection`=0))
          AND ((`ItemGroupKeys`.`Section`!=0 AND `ItemGroupKeys`.`Section`=NEW.`Section`) OR (`ItemGroupKeys`.`Section`=0))
          AND ((`ItemGroupKeys`.`SubSection`!=0 AND `ItemGroupKeys`.`SubSection`=NEW.`SubSection`) OR (`ItemGroupKeys`.`SubSection`=0))
          AND ((`ItemGroupKeys`.`Family`!=0 AND `ItemGroupKeys`.`Family`=NEW.`Family`) OR (`ItemGroupKeys`.`Family`=0))
          AND ((`ItemGroupKeys`.`SubFamily`!=0 AND `ItemGroupKeys`.`SubFamily`=NEW.`SubFamily`) OR (`ItemGroupKeys`.`SubFamily`=0))
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;

    WHEN 5 THEN

      IF (SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_name LIKE 'CFKeys') IS NOT NULL THEN
        IF ((NEW.`Code`!=0) AND (NEW.`OnKey`=TRUE)) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
            SELECT GLOBAL_GET("current_group"),`LocalTreeBoard`.`Board`, (`CFKeys`.`KeyCode`*10000)+(IF(`CFKeys`.`Level3`=0, `CFKeys`.`Level2`, `CFKeys`.`Level3`)), `CFKeys`.`Item` FROM `CFKeys`
            LEFT JOIN `LocalTreeBoard` ON `LocalTreeBoard`.`Level1`=`CFKeys`.`Level1` AND `LocalTreeBoard`.`Level2`=IF(`CFKeys`.`Level3`=0,0,`CFKeys`.`Level2`)
            WHERE `CFKeys`.`Item`=NEW.`Code` AND `CFKeys`.`Keyboard`=GLOBAL_GET("PLUload-kbd_db") AND (`CFKeys`.`EAN`!='00000000000000' AND `CFKeys`.`Item`!=0) AND Board IS NOT NULL
            ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
        END IF;

      ELSE


        IF (NEW.`PLU`!=0) THEN
          SET @src1 := NULL;
          SET @src2 := NULL;
          SET @src3 := NULL;
          SET @src4 := NULL;
          SET @src5 := NULL;
          SET @board := (SELECT `Board` FROM
            (SELECT @src1:=`Source1` AS `Source1`,@src2:=`Source2` AS `Source2`,@src3:=`Source3` AS `Source3`,@src4:=`Source4` AS `Source4`,@src5:=`Source5` AS `Source5` FROM `PLUKeysFile`
              WHERE `PLUKeysFile`.`PLU`=NEW.`PLU` AND NEW.`OnKey`=TRUE) AS puk
            LEFT JOIN `LocalTreeBoard` AS ltb ON
              ((puk.`Source5`!=0) AND (puk.`Source4`=ltb.`Source4` AND puk.`Source3`=ltb.`Source3` AND puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`!=0) AND (puk.`Source3`=ltb.`Source3` AND puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`=0 AND puk.`Source3`!=0) AND (puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`=0 AND puk.`Source3`=0 AND puk.`Source2`!=0) AND (puk.`Source1`=ltb.`Source1`)));
          IF(@src1 IS NOT NULL) THEN

            IF (@board IS NULL) THEN
              UPDATE `LocalStatus` SET `ResizeTouch`=TRUE;
            ELSE
              INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
                VALUES(GLOBAL_GET("current_group"),@board, 100000*(IF(@src5!=0, @src5, IF(@src4!=0, @src4, IF(@src3!=0, @src3, IF(@src2!=0, @src2, @src1)))))+NEW.`PLU`, NEW.`Code`)
                ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
            END IF;
          END IF;
        END IF;
      END IF;




    ELSE BEGIN END;
  END CASE;

  SET @toffer := IFNULL (GLOBAL_GET("table-offer"),0);
  SET @thabitual := IFNULL (GLOBAL_GET("table-habitual"),0);
  IF ((NEW.`Code`!=0) AND (NEW.`PLU`!=0)) THEN
    IF ((NEW.`Offer`=1) AND (@toffer!=0)) THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (GLOBAL_GET("current_group"),@toffer,NEW.`PLU`,NEW.`Code`)
        ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
    ELSE
      IF (@thabitual!=0) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
          SELECT GLOBAL_GET("current_group"),@thabitual,`ItemHabitual`.`Position`,NEW.`Code` FROM `ItemHabitual`
          WHERE `ItemHabitual`.`Code`=NEW.`Code`
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemsUpdated` AFTER UPDATE ON `Items`
FOR EACH ROW BEGIN
  IF(NEW.`EAN13`!=OLD.`EAN13`) THEN
    IF(NEW.`EAN13`!='') THEN
      INSERT INTO ItemsEAN13 (`Code`, `EAN13`) VALUES (NEW.`Code`, NEW.`EAN13`) ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
    END IF;
    IF(OLD.`EAN13`!='') THEN
      DELETE FROM ItemsEAN13 WHERE `Code`=OLD.`Code` AND `EAN13`=OLD.`EAN13`;
    END IF;
  END IF;
  SET @loadfunc := IFNULL (GLOBAL_GET("PLUload-func"),99);
  CASE @loadfunc

    WHEN 0 THEN
      IF (OLD.`Code`!=NEW.`Code`) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
          SELECT `Section`,`Board`,`PLUKey`,0 FROM `PLUKeys`
            WHERE `Code`=OLD.`Code` AND (`PLUKeys`.`Section`=GLOBAL_GET("current_group") OR (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard")) )
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
        SELECT `Section`,`Board`,`PLUKey`,IF(NEW.`Inactive`=FALSE, NEW.`Code`, 0) FROM `PLUKeys`
          WHERE `Code`=NEW.`Code` AND (`PLUKeys`.`Section`=GLOBAL_GET("current_group") OR (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard")) )
        ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);

    WHEN 1 THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,`Code` FROM `PLUKeys`
        WHERE `Code`=NEW.`Code` AND (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard"))
        ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;
      IF(NEW.`Family`!=OLD.`Family`) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,OLD.`Family`,`PLUKey`,0 FROM `PLUKeys`
          WHERE `Code`=NEW.`Code` AND `PLUKeys`.`Section`=GLOBAL_GET("current_group")
          ON DUPLICATE KEY UPDATE `Code`=0;
      END IF;

      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,NEW.`Family`,`PLUKey`,`Code` FROM `PLUKeys`
        WHERE `Code`=NEW.`Code` AND `PLUKeys`.`Section`=GLOBAL_GET("current_group")
        ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;

    WHEN 2 THEN
      IF(OLD.`Family`!=NEW.`Family`) THEN
        SET @famor := (SELECT `FamilyIndex` FROM `CounterFamilies` WHERE `CounterCode`=GLOBAL_GET("current_counter") AND `FamilyCode`=OLD.`Family`);
        IF(@famor IS NOT NULL) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES(GLOBAL_GET("current_group"),@famor,OLD.`FamilyOrder`,0)
          ON DUPLICATE KEY UPDATE `Code`=0;
        END IF;
      END IF;
      SET @famor := (SELECT `FamilyIndex` FROM `CounterFamilies` WHERE `CounterCode`=GLOBAL_GET("current_counter") AND `FamilyCode`=NEW.`Family`);
      IF (@famor IS NOT NULL) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES(GLOBAL_GET("current_group"),@famor,NEW.`FamilyOrder`,
         IF(((NEW.`OnKey`=TRUE) AND (NEW.`Inactive`=FALSE)), NEW.`Code`, 0))
        ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;

      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,IF(((NEW.`OnKey`=TRUE) AND (NEW.`Inactive`=FALSE)), `Code`, 0) FROM `PLUKeys`
        WHERE `Code`=NEW.`Code` AND (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard"))
        ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;

    WHEN 3 THEN
      IF (OLD.`Counter`!=NEW.`Counter`) AND (OLD.`Counter`=GLOBAL_GET("current_counter")) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (OLD.`Counter`,0,OLD.`PLU`, 0)
        ON DUPLICATE KEY UPDATE `Code`=0;
      END IF;
      IF (NEW.`Counter`!=0) AND (NEW.`PLU`!=0) AND (NEW.`Counter`=GLOBAL_GET("current_counter")) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (NEW.`Counter`,0,NEW.`PLU`, NEW.`Code`)
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;

    WHEN 100 THEN
       IF (OLD.`Counter`!=NEW.`Counter`) THEN
        IF (OLD.`Counter`!=0) AND (OLD.`PLU`!=0) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT OLD.`Counter`,board_idx,OLD.`PLU`, 0
          FROM (SELECT IF(Code=GLOBAL_GET("current_counter"),1,@a:=@a+1) AS board_idx, Code FROM (SELECT @a:=1) AS ct, Counters) AS tt100 WHERE OLD.`Counter`=tt100.Code
         ON DUPLICATE KEY UPDATE `Code`=0;
        END IF;
        IF (NEW.`Counter`!=0) AND (NEW.`PLU`!=0) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Counter`,board_idx,NEW.`PLU`, NEW.`Code`
             FROM (SELECT IF(Code=GLOBAL_GET("current_counter"),1,@a:=@a+1) AS board_idx, Code FROM (SELECT @a:=1) AS ct, Counters) AS tt100 WHERE NEW.`Counter`=tt100.Code
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
        END IF;
      ELSE
        IF (NEW.`Counter`!=0) THEN
          IF (OLD.`PLU`!=0) THEN
            INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Counter`,board_idx,OLD.`PLU`, 0
              FROM (SELECT IF(Code=GLOBAL_GET("current_counter"),1,@a:=@a+1) AS board_idx, Code FROM (SELECT @a:=1) AS ct, Counters) AS tt100 WHERE NEW.`Counter`=tt100.Code
            ON DUPLICATE KEY UPDATE `Code`=`LocalPLUKeysChanges`.`Code`;
          END IF;
          IF (NEW.`PLU`!=0) THEN
            INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Counter`,board_idx,NEW.`PLU`, NEW.`Code`
              FROM (SELECT IF(Code=GLOBAL_GET("current_counter"),1,@a:=@a+1) AS board_idx, Code FROM (SELECT @a:=1) AS ct, Counters) AS tt100 WHERE NEW.`Counter`=tt100.Code
            ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
          END IF;
        END IF;
      END IF;

    WHEN 101 THEN
      IF (OLD.`Counter`!=NEW.`Counter`) THEN
        IF (OLD.`Counter`!=0) AND (OLD.`PLU`!=0) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT OLD.`Counter`,board_idx,OLD.`PLU`, 0
            FROM (SELECT @a:=@a+1 AS board_idx, Code FROM (SELECT @a:=0) AS ct, Counters) AS tt100 WHERE OLD.`Counter`=tt100.Code
         ON DUPLICATE KEY UPDATE `Code`=0;
        END IF;
        IF (NEW.`Counter`!=0) AND (NEW.`PLU`!=0) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Counter`,board_idx,NEW.`PLU`, NEW.`Code`
             FROM (SELECT @a:=@a+1 AS board_idx, Code FROM (SELECT @a:=0) AS ct, Counters) AS tt100 WHERE NEW.`Counter`=tt100.Code
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
        END IF;
      ELSE
        IF (NEW.`Counter`!=0) THEN
           IF (OLD.`PLU`!=0) THEN
            INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Counter`,board_idx,OLD.`PLU`, 0
              FROM (SELECT @a:=@a+1 AS board_idx, Code FROM (SELECT @a:=0) AS ct, Counters) AS tt100 WHERE NEW.`Counter`=tt100.Code
            ON DUPLICATE KEY UPDATE `Code`=`LocalPLUKeysChanges`.`Code`;
          END IF;
          IF (NEW.`PLU`!=0) THEN
            INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Counter`,board_idx,NEW.`PLU`, NEW.`Code`
              FROM (SELECT @a:=@a+1 AS board_idx, Code FROM (SELECT @a:=0) AS ct, Counters) AS tt100 WHERE NEW.`Counter`=tt100.Code
            ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
          END IF;
        END IF;
      END IF;

      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,IF(NEW.`OnKey`=TRUE, `Code`, 0) FROM `PLUKeys`
        WHERE `Code`=NEW.`Code` AND (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard"))
        ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;

    WHEN 4 THEN
      IF ((OLD.`PLU`!=0) AND (OLD.`Code`!=0)) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
          SELECT GLOBAL_GET("current_group"),`ItemGroupKeys`.`NumKey`,OLD.`PLU`,0 FROM `ItemGroupKeys`
          WHERE ((`ItemGroupKeys`.`Abovesection`!=0 AND `ItemGroupKeys`.`Abovesection`=OLD.`Abovesection`) OR (`ItemGroupKeys`.`Abovesection`=0))
          AND ((`ItemGroupKeys`.`Section`!=0 AND `ItemGroupKeys`.`Section`=OLD.`Section`) OR (`ItemGroupKeys`.`Section`=0))
          AND ((`ItemGroupKeys`.`SubSection`!=0 AND `ItemGroupKeys`.`SubSection`=OLD.`SubSection`) OR (`ItemGroupKeys`.`SubSection`=0))
          AND ((`ItemGroupKeys`.`Family`!=0 AND `ItemGroupKeys`.`Family`=OLD.`Family`) OR (`ItemGroupKeys`.`Family`=0))
          AND ((`ItemGroupKeys`.`SubFamily`!=0 AND `ItemGroupKeys`.`SubFamily`=OLD.`SubFamily`) OR (`ItemGroupKeys`.`SubFamily`=0))
          ON DUPLICATE KEY UPDATE `Code`=0;
      END IF;
      IF ((NEW.`PLU`!=0) AND (NEW.`Code`!=0)) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
          SELECT GLOBAL_GET("current_group"),`ItemGroupKeys`.`NumKey`,NEW.`PLU`,NEW.`Code` FROM `ItemGroupKeys`
          WHERE ((`ItemGroupKeys`.`Abovesection`!=0 AND `ItemGroupKeys`.`Abovesection`=NEW.`Abovesection`) OR (`ItemGroupKeys`.`Abovesection`=0))
          AND ((`ItemGroupKeys`.`Section`!=0 AND `ItemGroupKeys`.`Section`=NEW.`Section`) OR (`ItemGroupKeys`.`Section`=0))
          AND ((`ItemGroupKeys`.`SubSection`!=0 AND `ItemGroupKeys`.`SubSection`=NEW.`SubSection`) OR (`ItemGroupKeys`.`SubSection`=0))
          AND ((`ItemGroupKeys`.`Family`!=0 AND `ItemGroupKeys`.`Family`=NEW.`Family`) OR (`ItemGroupKeys`.`Family`=0))
          AND ((`ItemGroupKeys`.`SubFamily`!=0 AND `ItemGroupKeys`.`SubFamily`=NEW.`SubFamily`) OR (`ItemGroupKeys`.`SubFamily`=0))
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;

    WHEN 5 THEN

      IF (SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_name LIKE 'CFKeys') IS NOT NULL THEN
        IF ((OLD.`Code`!=NEW.`Code`)  AND (OLD.`OnKey`=TRUE)) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
            SELECT GLOBAL_GET("current_group"),`LocalTreeBoard`.`Board`, (`CFKeys`.`KeyCode`*10000)+(IF(`CFKeys`.`Level3`=0, `CFKeys`.`Level2`, `CFKeys`.`Level3`)), 0 FROM `CFKeys`
            LEFT JOIN `LocalTreeBoard` ON `LocalTreeBoard`.`Level1`=`CFKeys`.`Level1` AND `LocalTreeBoard`.`Level2`=IF(`CFKeys`.`Level3`=0,0,`CFKeys`.`Level2`)
            WHERE `CFKeys`.`Item`=OLD.`Code` AND `CFKeys`.`Keyboard`=GLOBAL_GET("PLUload-kbd_db") AND (`CFKeys`.`EAN`!='00000000000000' AND `CFKeys`.`Item`!=0) AND Board IS NOT NULL
            ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
        END IF;
        IF (NEW.`Code`!=0) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
            SELECT GLOBAL_GET("current_group"),`LocalTreeBoard`.`Board`, (`CFKeys`.`KeyCode`*10000)+(IF(`CFKeys`.`Level3`=0, `CFKeys`.`Level2`, `CFKeys`.`Level3`)), IF(NEW.`OnKey`=TRUE, NEW.`Code`, 0) FROM `CFKeys`
            LEFT JOIN `LocalTreeBoard` ON `LocalTreeBoard`.`Level1`=`CFKeys`.`Level1` AND `LocalTreeBoard`.`Level2`=IF(`CFKeys`.`Level3`=0,0,`CFKeys`.`Level2`)
            WHERE `CFKeys`.`Item`=NEW.`Code` AND `CFKeys`.`Keyboard`=GLOBAL_GET("PLUload-kbd_db") AND (`CFKeys`.`EAN`!='00000000000000' AND `CFKeys`.`Item`!=0) AND Board IS NOT NULL
            ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
        END IF;

      ELSE


        IF ((OLD.`PLU`!=0) AND ((OLD.`PLU`!=NEW.`PLU`) OR (OLD.`Code`!=NEW.`Code`))) THEN
          SET @src1 := NULL;
          SET @src2 := NULL;
          SET @src3 := NULL;
          SET @src4 := NULL;
          SET @src5 := NULL;
          SET @board := (SELECT `Board` FROM
            (SELECT @src1:=`Source1` AS `Source1`,@src2:=`Source2` AS `Source2`,@src3:=`Source3` AS `Source3`,@src4:=`Source4` AS `Source4`,@src5:=`Source5` AS `Source5` FROM `PLUKeysFile`
              WHERE `PLUKeysFile`.`PLU`=OLD.`PLU` AND OLD.`OnKey`=TRUE) AS puk
            LEFT JOIN `LocalTreeBoard` AS ltb ON
              ((puk.`Source5`!=0) AND (puk.`Source4`=ltb.`Source4` AND puk.`Source3`=ltb.`Source3` AND puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`!=0) AND (puk.`Source3`=ltb.`Source3` AND puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`=0 AND puk.`Source3`!=0) AND (puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`=0 AND puk.`Source3`=0 AND puk.`Source2`!=0) AND (puk.`Source1`=ltb.`Source1`)));

          IF((@src1 IS NOT NULL) AND (@board IS NOT NULL)) THEN
              INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
                VALUES(GLOBAL_GET("current_group"),@board, 100000*(IF(@src5!=0, @src5, IF(@src4!=0, @src4, IF(@src3!=0, @src3, IF(@src2!=0, @src2, @src1)))))+OLD.`PLU`, 0)
                ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
          END IF;
        END IF;
        IF (NEW.`PLU`!=0) THEN
          SET @src1 := NULL;
          SET @src2 := NULL;
          SET @src3 := NULL;
          SET @src4 := NULL;
          SET @src5 := NULL;
          SET @board := (SELECT `Board` FROM
            (SELECT @src1:=`Source1` AS `Source1`,@src2:=`Source2` AS `Source2`,@src3:=`Source3` AS `Source3`,@src4:=`Source4` AS `Source4`,@src5:=`Source5` AS `Source5` FROM `PLUKeysFile`
              WHERE `PLUKeysFile`.`PLU`=NEW.`PLU` AND NEW.`OnKey`=TRUE) AS puk
            LEFT JOIN `LocalTreeBoard` AS ltb ON
              ((puk.`Source5`!=0) AND (puk.`Source4`=ltb.`Source4` AND puk.`Source3`=ltb.`Source3` AND puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`!=0) AND (puk.`Source3`=ltb.`Source3` AND puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`=0 AND puk.`Source3`!=0) AND (puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`=0 AND puk.`Source3`=0 AND puk.`Source2`!=0) AND (puk.`Source1`=ltb.`Source1`)));
          IF(@src1 IS NOT NULL) THEN

            IF (@board IS NULL) THEN
              UPDATE `LocalStatus` SET `ResizeTouch`=TRUE;
            ELSE
              INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
                VALUES(GLOBAL_GET("current_group"),@board, 100000*(IF(@src5!=0, @src5, IF(@src4!=0, @src4, IF(@src3!=0, @src3, IF(@src2!=0, @src2, @src1)))))+NEW.`PLU`, NEW.`Code`)
                ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
            END IF;
          END IF;
        END IF;
      END IF;




    ELSE BEGIN END;
  END CASE;


  SET @toffer := IFNULL (GLOBAL_GET("table-offer"),0);
  SET @thabitual := IFNULL (GLOBAL_GET("table-habitual"),0);
  IF ((OLD.`Code`!=0) AND (OLD.`PLU`!=0)) THEN
    IF ((OLD.`Offer`=1) AND (@toffer!=0)) THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (GLOBAL_GET("current_group"),@toffer,OLD.`PLU`,0)
        ON DUPLICATE KEY UPDATE `Code`=0;
    ELSE
      IF (@thabitual!=0) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
          SELECT GLOBAL_GET("current_group"),@thabitual,`ItemHabitual`.`Position`,0 FROM `ItemHabitual`
          WHERE `ItemHabitual`.`Code`=OLD.`Code`
          ON DUPLICATE KEY UPDATE `Code`=0;
      END IF;
    END IF;
  END IF;
  IF ((NEW.`Code`!=0) AND (NEW.`PLU`!=0)) THEN
    IF ((NEW.`Offer`=1) AND (@toffer!=0)) THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (GLOBAL_GET("current_group"),@toffer,NEW.`PLU`,NEW.`Code`)
        ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
    ELSE
      IF (@thabitual!=0) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
          SELECT GLOBAL_GET("current_group"),@thabitual,`ItemHabitual`.`Position`,NEW.`Code` FROM `ItemHabitual`
            WHERE `ItemHabitual`.`Code`=NEW.`Code`
            ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemsDeleted` BEFORE DELETE ON `Items`
FOR EACH ROW BEGIN
  SET @loadfunc := IFNULL (GLOBAL_GET("PLUload-func"),99);
  CASE @loadfunc

    WHEN 0 THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,0 FROM `PLUKeys`
        WHERE `Code`=OLD.`Code` AND (`PLUKeys`.`Section`=GLOBAL_GET("current_group") OR (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard")) )
        ON DUPLICATE KEY UPDATE `Code`=0;

    WHEN 1 THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,0 FROM `PLUKeys`
        WHERE `Code`=OLD.`Code` AND (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard"))
        ON DUPLICATE KEY UPDATE `Code`=0;
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,OLD.`Family`,`PLUKey`,0 FROM `PLUKeys`
        WHERE `Code`=OLD.`Code` AND `PLUKeys`.`Section`=GLOBAL_GET("current_group")
        ON DUPLICATE KEY UPDATE `Code`=0;

    WHEN 2 THEN
      SET @famor := (SELECT `FamilyIndex` FROM `CounterFamilies` WHERE `CounterCode`=GLOBAL_GET("current_counter") AND `FamilyCode`=OLD.`Family`);
      IF (@famor IS NOT NULL) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES(GLOBAL_GET("current_group"),@famor,OLD.`FamilyOrder`,0)
        ON DUPLICATE KEY UPDATE `Code`=0;
      END IF;
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT `Section`,`Board`,`PLUKey`,0 FROM `PLUKeys`
        WHERE `Code`=OLD.`Code` AND (`PLUKeys`.`Section`=0 AND `PLUKeys`.`Board`=GLOBAL_GET("current_mupboard"))
        ON DUPLICATE KEY UPDATE `Code`=0;

     WHEN 3 THEN
      IF (OLD.`Counter`!=0) AND (OLD.`PLU`!=0) AND (OLD.`Counter`=GLOBAL_GET("current_counter")) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (OLD.`Counter`,0,OLD.`PLU`, 0)
          ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
      END IF;

      WHEN 100 THEN
        IF (OLD.`Counter`!=0) AND (OLD.`PLU`!=0) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT OLD.`Counter`,board_idx,OLD.`PLU`, 0
            FROM (SELECT IF(Code=GLOBAL_GET("current_counter"),1,@a:=@a+1) AS board_idx, Code FROM (SELECT @a:=1) AS ct, Counters) AS tt100 WHERE OLD.`Counter`=tt100.Code
          ON DUPLICATE KEY UPDATE `Code`=0;
        END IF;

    WHEN 101 THEN
        IF (OLD.`Counter`!=0) AND (OLD.`PLU`!=0) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT OLD.`Counter`,board_idx,OLD.`PLU`, 0
            FROM (SELECT @a:=@a+1 AS board_idx, Code FROM (SELECT @a:=0) AS ct, Counters) AS tt100 WHERE OLD.`Counter`=tt100.Code
          ON DUPLICATE KEY UPDATE `Code`=0;
        END IF;

    WHEN 4 THEN
      IF ((OLD.`PLU`!=0) AND (OLD.`Code`!=0)) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
          SELECT GLOBAL_GET("current_group"),`ItemGroupKeys`.`NumKey`,OLD.`PLU`,0 FROM `ItemGroupKeys`
          WHERE ((`ItemGroupKeys`.`Abovesection`!=0 AND `ItemGroupKeys`.`Abovesection`=OLD.`Abovesection`) OR (`ItemGroupKeys`.`Abovesection`=0))
          AND ((`ItemGroupKeys`.`Section`!=0 AND `ItemGroupKeys`.`Section`=OLD.`Section`) OR (`ItemGroupKeys`.`Section`=0))
          AND ((`ItemGroupKeys`.`SubSection`!=0 AND `ItemGroupKeys`.`SubSection`=OLD.`SubSection`) OR (`ItemGroupKeys`.`SubSection`=0))
          AND ((`ItemGroupKeys`.`Family`!=0 AND `ItemGroupKeys`.`Family`=OLD.`Family`) OR (`ItemGroupKeys`.`Family`=0))
          AND ((`ItemGroupKeys`.`SubFamily`!=0 AND `ItemGroupKeys`.`SubFamily`=OLD.`SubFamily`) OR (`ItemGroupKeys`.`SubFamily`=0))
          ON DUPLICATE KEY UPDATE `Code`=0;
      END IF;

    WHEN 5 THEN

      IF (SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_name LIKE 'CFKeys') IS NOT NULL THEN
        IF ((OLD.`Code`!=0) AND (OLD.`OnKey`=TRUE)) THEN
          INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
            SELECT GLOBAL_GET("current_group"),`LocalTreeBoard`.`Board`, (`CFKeys`.`KeyCode`*10000)+(IF(`CFKeys`.`Level3`=0, `CFKeys`.`Level2`, `CFKeys`.`Level3`)), 0 FROM `CFKeys`
            LEFT JOIN `LocalTreeBoard` ON `LocalTreeBoard`.`Level1`=`CFKeys`.`Level1` AND `LocalTreeBoard`.`Level2`=IF(`CFKeys`.`Level3`=0,0,`CFKeys`.`Level2`)
            WHERE `CFKeys`.`Item`=OLD.`Code` AND `CFKeys`.`Keyboard`=GLOBAL_GET("PLUload-kbd_db") AND (`CFKeys`.`EAN`!='00000000000000' AND `CFKeys`.`Item`!=0) AND Board IS NOT NULL
            ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
        END IF;

      ELSE


        IF (OLD.`PLU`!=0) THEN
          SET @src1 := NULL;
          SET @src2 := NULL;
          SET @src3 := NULL;
          SET @src4 := NULL;
          SET @src5 := NULL;
          SET @board := (SELECT `Board` FROM
            (SELECT @src1:=`Source1` AS `Source1`,@src2:=`Source2` AS `Source2`,@src3:=`Source3` AS `Source3`,@src4:=`Source4` AS `Source4`,@src5:=`Source5` AS `Source5` FROM `PLUKeysFile`
              WHERE `PLUKeysFile`.`PLU`=OLD.`PLU` AND OLD.`OnKey`=TRUE) AS puk
            LEFT JOIN `LocalTreeBoard` AS ltb ON
              ((puk.`Source5`!=0) AND (puk.`Source4`=ltb.`Source4` AND puk.`Source3`=ltb.`Source3` AND puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`!=0) AND (puk.`Source3`=ltb.`Source3` AND puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`=0 AND puk.`Source3`!=0) AND (puk.`Source2`=ltb.`Source2` AND puk.`Source1`=ltb.`Source1`)) OR
              ((puk.`Source5`=0 AND puk.`Source4`=0 AND puk.`Source3`=0 AND puk.`Source2`!=0) AND (puk.`Source1`=ltb.`Source1`)));

          IF((@src1 IS NOT NULL) AND (@board IS NOT NULL)) THEN
              INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
                VALUES(GLOBAL_GET("current_group"),@board, 100000*(IF(@src5!=0, @src5, IF(@src4!=0, @src4, IF(@src3!=0, @src3, IF(@src2!=0, @src2, @src1)))))+OLD.`PLU`, 0)
                ON DUPLICATE KEY UPDATE `Code`=VALUES(`Code`);
          END IF;
        END IF;
      END IF;




    ELSE BEGIN END;
  END CASE;

  SET @toffer := IFNULL (GLOBAL_GET("table-offer"),0);
  SET @thabitual := IFNULL (GLOBAL_GET("table-habitual"),0);
  IF ((OLD.`Code`!=0) AND (OLD.`PLU`!=0)) THEN
    IF ((OLD.`Offer`=1) AND (@toffer!=0)) THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (GLOBAL_GET("current_group"),@toffer,OLD.`PLU`,0)
        ON DUPLICATE KEY UPDATE `Code`=0;
    ELSE
      IF (@thabitual!=0) THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`)
          SELECT GLOBAL_GET("current_group"),@thabitual,`ItemHabitual`.`Position`,0 FROM `ItemHabitual` WHERE `ItemHabitual`.`Code`=OLD.`Code`
          ON DUPLICATE KEY UPDATE `Code`=0;
      END IF;
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemsExtraPointsInserted` AFTER INSERT ON `ItemsExtraPoints`
FOR EACH ROW BEGIN
  UPDATE `Items` SET `Items`.`Code`=`Items`.`Code` WHERE `Items`.`Code`=NEW.`Code`;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemsExtraPointsUpdated` AFTER UPDATE ON `ItemsExtraPoints`
FOR EACH ROW BEGIN
  IF(OLD.`Code`!=NEW.`Code`) THEN
    UPDATE `Items` SET `Items`.`Code`=`Items`.`Code` WHERE `Items`.`Code`=OLD.`Code`;
  END IF;
  UPDATE `Items` SET `Items`.`Code`=`Items`.`Code` WHERE `Items`.`Code`=NEW.`Code`;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ItemsExtraPointsDeleted` AFTER DELETE ON `ItemsExtraPoints`
FOR EACH ROW BEGIN
  UPDATE `Items` SET `Items`.`Code`=`Items`.`Code` WHERE `Items`.`Code`=OLD.`Code`;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LCorderInserted` AFTER INSERT ON `LCustomerOrders`
FOR EACH ROW BEGIN

  UPDATE `HCustomerOrders` SET `HCustomerOrders`.`DatTim`=NOW(),
    `HCustomerOrders`.`AddedLines`=`HCustomerOrders`.`AddedLines`+IF(NEW.`Status`!=7,1,0),
    `HCustomerOrders`.`NetAmount`=`HCustomerOrders`.`NetAmount`+NEW.`Amount`,
    `HCustomerOrders`.`TotalWeight`=`HCustomerOrders`.`TotalWeight`+NEW.`Weight`, `HCustomerOrders`.`TotalUnits`=`HCustomerOrders`.`TotalUnits`+NEW.`Units`
    WHERE (`HCustomerOrders`.`Number`=NEW.`OrderNumber` AND `HCustomerOrders`.`Section`=NEW.`Section`) AND ((`HCustomerOrders`.`Status`>1) AND (`HCustomerOrders`.`Status`!=3));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LCorderUpdated` AFTER UPDATE ON `LCustomerOrders`
FOR EACH ROW BEGIN
  UPDATE `HCustomerOrders` SET `HCustomerOrders`.`DatTim`=NOW(),
    `HCustomerOrders`.`AddedLines`=`HCustomerOrders`.`AddedLines`+
      IF(((NEW.`Status`=5 AND OLD.`Status`=0) OR (NEW.`Status`=0 AND OLD.`Status`=5) OR (NEW.`Status`=7 AND OLD.`Status`=2) OR (NEW.`Status`=2 AND OLD.`Status`=7)), 0,
      IF((OLD.`Weight`=0 AND OLD.`Units`=0), 1, IF(NEW.`Weight`=0 AND NEW.`Units`=0, -1, 0))),
    `HCustomerOrders`.`NetAmount`=`HCustomerOrders`.`NetAmount`-OLD.`Amount`+NEW.`Amount`,
    `HCustomerOrders`.`TotalWeight`=`HCustomerOrders`.`TotalWeight`-OLD.`Weight`+NEW.`Weight`, `HCustomerOrders`.`TotalUnits`=`HCustomerOrders`.`TotalUnits`-OLD.`Units`+NEW.`Units`
    WHERE (`HCustomerOrders`.`Number`=OLD.`OrderNumber` AND `HCustomerOrders`.`Section`=OLD.`Section`) AND ((`HCustomerOrders`.`Status`>1) AND (`HCustomerOrders`.`Status`!=3));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalCfgInserted` AFTER INSERT ON `LocalCfgScale`
FOR EACH ROW BEGIN
  SET @trx := (SELECT trx_new("BUTTON_UPDATE", "GUI"));
  SET @ret := (SELECT trx_set_param(@trx, "KEYNAME", CONCAT("LOCALCFGSCALE_", NEW.`ParamKey`)));
  SET @ret := (SELECT trx_set_param(@trx, "PARAMVALUE", NEW.`ParamValue`));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalCfgUpdated` AFTER UPDATE ON `LocalCfgScale`
FOR EACH ROW BEGIN
  IF(OLD.`ParamValue`!=NEW.`ParamValue`) THEN
    SET @trx := (SELECT trx_new("BUTTON_UPDATE", "GUI"));
    SET @ret := (SELECT trx_set_param(@trx, "KEYNAME", CONCAT("LOCALCFGSCALE_", NEW.`ParamKey`)));
    SET @ret := (SELECT trx_set_param(@trx, "PARAMVALUE", NEW.`ParamValue`));
    SET @ret := (SELECT trx_send(@trx));
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalCfgDeleted` AFTER DELETE ON `LocalCfgScale`
FOR EACH ROW BEGIN
  SET @trx := (SELECT trx_new("BUTTON_UPDATE", "GUI"));
  SET @ret := (SELECT trx_set_param(@trx, "KEYNAME", CONCAT("LOCALCFGSCALE_", OLD.`ParamKey`)));
  SET @ret := (SELECT trx_set_param(@trx, "PARAMVALUE", ""));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalCommInserted` AFTER INSERT ON `LocalComm`
FOR EACH ROW BEGIN
  SET @trx := (SELECT trx_new("RELOAD", "COMM"));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalCommUpdated` AFTER UPDATE ON `LocalComm`
FOR EACH ROW BEGIN
    SET @trx := (SELECT trx_new("RELOAD", "COMM"));
    SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalCommDeleted` AFTER DELETE ON `LocalComm`
FOR EACH ROW BEGIN
  SET @trx := (SELECT trx_new("RELOAD", "COMM"));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalVendorTicketNew` AFTER INSERT ON `LocalHTickets`
FOR EACH ROW BEGIN
	REPLACE INTO `LocalVendorChanges` VALUES (NEW.`Vendor`*10, NEW.`Vendor`,'0');
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalHTicketsUpdateB` BEFORE UPDATE ON `LocalHTickets`
FOR EACH ROW BEGIN
  IF(NEW.`NetStat`='L') THEN
    SET @frac_digits := IFNULL(GLOBAL_GET("frac_digits"), 2);

    IF(OLD.`PointsDiscount`!=NEW.`PointsDiscount`) THEN
      SET @lypoints = (SELECT IFNULL(`ParamValue`,0) FROM `CfgSystem` WHERE `ParamKey`='loyalty-points-discount-currency');
      SET NEW.`PointsAmount`= IF(@lypoints,ROUND(NEW.`PointsDiscount`/@lypoints, @frac_digits),0);
      SET NEW.`NetAmount`=`pcs_net`(NEW.`GrossAmount`, NEW.`tckDiscount`, NEW.`PointsAmount`);
    END IF;
    IF((OLD.`GrossAmount`!=NEW.`GrossAmount`) OR (OLD.`tckDiscount`!=NEW.`tckDiscount`) OR (OLD.`Customer`!=NEW.`Customer`)) THEN
      SET NEW.`PointsDiscount`=0;
      SET NEW.`PointsAmount`= 0;
      SET NEW.`NetAmount`=`pcs_net`(NEW.`GrossAmount`, NEW.`tckDiscount`, NEW.`PointsAmount`);
    END IF;
    IF(OLD.`NetAmount`!=NEW.`NetAmount`) THEN
      SET @points = (SELECT IFNULL(`ParamValue`,0) FROM `CfgSystem` WHERE `ParamKey`='loyalty-currency-give-point');
      SET NEW.`Points`=IF(@points,FLOOR(NEW.`NetAmount`/@points),0);
    END IF;
    IF(OLD.`Status`!=NEW.`Status`) AND ((NEW.`Status`='C') OR (NEW.`Status`='X') OR (NEW.`Status`='D') OR (NEW.`Status`='R')) THEN
      SET NEW.`NeedCopy`=TRUE;
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalHTicketsUpdate` AFTER UPDATE ON `LocalHTickets`
FOR EACH ROW BEGIN

  IF(NEW.`ReloadTo`!=0) AND (OLD.`Status`!= NEW.`Status`) THEN
    UPDATE `LTickets` SET `LTickets`.`ReloadTo`=NEW.`ReloadTo` WHERE `LTickets`.`IdHTicket`=NEW.`Id`;
  END IF;
  REPLACE INTO `LocalVendorChanges` VALUES (NEW.`Vendor`*10, NEW.`Vendor`,'0');
  IF(OLD.`Number`!= NEW.`Number`) THEN
    IF((SELECT IFNULL(`ParamValue`, 0) FROM `CfgSystem` WHERE `ParamKey`='prices-without-taxes')=1) THEN
      UPDATE `LocalLTickets` AS `lt` SET `lt`.`PrintScale`=NEW.`Scale`, `lt`.`PrintDateTime`=NEW.`DatTim`, `lt`.`PrintTicketNumber`=NEW.`Number`,
        `lt`.`PrinttckType`=NEW.`tckType`, `lt`.`TicketDiscount`=NEW.`tckDiscount`, `lt`.`BaseAmount`=`lt`.`Amount`
        WHERE `lt`.`IdHTicket`=NEW.`Id`;
    ELSE
      UPDATE `LocalLTickets` AS `lt` SET `lt`.`PrintScale`=NEW.`Scale`, `lt`.`PrintDateTime`=NEW.`DatTim`, `lt`.`PrintTicketNumber`=NEW.`Number`,
        `lt`.`PrinttckType`=NEW.`tckType`, `lt`.`TicketDiscount`=NEW.`tckDiscount`, `lt`.`BaseAmount`=(`lt`.`Amount`*(100-NEW.`tckDiscount`))/(100+`lt`.`VATPercent`)
        WHERE `lt`.`IdHTicket`=NEW.`Id`;
    END IF;
  END IF;
  IF(NEW.`NetStat`='L') THEN
    UPDATE `LocalStatus` SET `LocalTickets` = TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalLTicketsInsertB` BEFORE INSERT ON `LocalLTickets`
FOR EACH ROW BEGIN
  SET @HTStatus:=(SELECT Status FROM `LocalHTickets` WHERE `LocalHTickets`.`Id`=NEW.`IdHTicket`);

  IF (@HTStatus!='?') THEN

    IF ((NEW.`NetStat`='L') AND  (NEW.`lineType`=1)) THEN
      IF (@HTStatus='O') THEN
        SET NEW.`LineDateTime`=NOW();
        IF ((SELECT IFNULL(`ParamValue`,0) FROM `CfgSystem` WHERE `ParamKey`='loyalty-items-extra-points')!=0) THEN
          SET NEW.`Points`=IFNULL((SELECT
            IF(`ItemsExtraPoints`.`FromQuantity`,

              IF(`ItemsExtraPoints`.`Quantity`,

                IF(`ItemsExtraPoints`.`Proportional`,

                  IF(NEW.`Weight`>=`ItemsExtraPoints`.`FromQuantity`,(((NEW.`Weight`-`ItemsExtraPoints`.`FromQuantity`)/`ItemsExtraPoints`.`Quantity`) +1)*`ItemsExtraPoints`.`Points`, 0),

                    IF(NEW.`Weight`>=`ItemsExtraPoints`.`FromQuantity`,(((NEW.`Weight`-`ItemsExtraPoints`.`FromQuantity`)/`ItemsExtraPoints`.`Quantity`) DIV 1 +1)*`ItemsExtraPoints`.`Points`, 0)),

                IF(NEW.`Weight`>=`ItemsExtraPoints`.`FromQuantity`,`ItemsExtraPoints`.`Points`,0)),

              IF(`ItemsExtraPoints`.`Quantity`,

                IF(`ItemsExtraPoints`.`Proportional`,

                  (NEW.`Weight`/`ItemsExtraPoints`.`Quantity`)*`ItemsExtraPoints`.`Points`,

                    IF(NEW.`Weight`>=`ItemsExtraPoints`.`Quantity`,(((NEW.`Weight`-`ItemsExtraPoints`.`Quantity`)/`ItemsExtraPoints`.`Quantity`) DIV 1 +1)*`ItemsExtraPoints`.`Points`, 0)),

                `ItemsExtraPoints`.`Points`))
          FROM `ItemsExtraPoints` WHERE `ItemsExtraPoints`.`Code`=NEW.`Item`), 0);
        END IF;

      ELSE
        UPDATE `PCScaleErrorTag` SET x=1;
      END IF;
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalLTicketsInserted` AFTER INSERT ON `LocalLTickets`
FOR EACH ROW BEGIN

  IF(NEW.`NetStat`='L') THEN
    SET @wgt = IF(NEW.`SaleForm`=1,NEW.`Weight`,0);
    SET @units = IF(NEW.`SaleForm`=0,NEW.`Weight`,0);
    CASE(NEW.`lineType`)

      WHEN 0 THEN
        UPDATE `LocalHTickets` SET `NumLines`=`NumLines`+1, `CanceledLines`=`CanceledLines`+1, `CanceledAmount`=`CanceledAmount`+NEW.`Amount`,
          `DatTim`=NOW(), `SectionItem`=NEW.`Section` WHERE `LocalHTickets`.`Id`=NEW.`IdHTicket` AND `LocalHTickets`.`Status`='O';

      WHEN 1 THEN
        UPDATE `LocalHTickets` SET `NumLines`=`NumLines`+1, `AddedLines`=`AddedLines`+1, `GrossAmount`=`GrossAmount`+NEW.`Amount`,
               `NegativeLines`=`NegativeLines`+IF(NEW.`Price`<0,1,0), `NegativeAmount` = `NegativeAmount`+IF(NEW.`Price`<0,-NEW.`Amount`,0),
               `TotalWeight`=`TotalWeight`+IF(NEW.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`+IF(NEW.`Price`<0,0,@units),
               `LocalHTickets`.`PointsExtra`=`LocalHTickets`.`PointsExtra`+IF(NEW.`Price`>0,NEW.`Points`,0),
               `DatTim`=NOW(), `SectionItem`=NEW.`Section` WHERE `LocalHTickets`.`Id`=NEW.`IdHTicket` AND `LocalHTickets`.`Status`='O' AND `LocalHTickets`.`NetStat`='L';

      WHEN 3 THEN
        IF(NEW.`SaleForm`=0) THEN
          UPDATE `LocalHTickets` SET `TotalWeight`=`TotalWeight`+@wgt, `TotalUnits`=`TotalUnits`+@units, `PointsChanged`=`PointsChanged`+NEW.`Price`, `DatTim`=NOW()
            WHERE `LocalHTickets`.`Id`=NEW.`IdHTicket` AND `LocalHTickets`.`Status`='O' ;
        END IF;

      ELSE BEGIN END;
    END CASE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalLTicketsUpdated` AFTER UPDATE ON `LocalLTickets`
FOR EACH ROW BEGIN
  IF((NEW.`Amount`!=OLD.`Amount`) OR (NEW.`VATCode`!=OLD.`VATCode`) OR (NEW.`VATPercent`!=OLD.`VATPercent`)
    OR (NEW.`SaleForm`!=OLD.`SaleForm`) OR (NEW.`Weight`!=OLD.`Weight`) OR (NEW.`Price`!=OLD.`Price`) OR (NEW.`lineDiscount`!=OLD.`lineDiscount`)
    OR ((NEW.`lineType`!=OLD.`lineType`) AND (NEW.`IdHTicket`!=OLD.`IdHTicket`))) THEN
    CALL `manipulate_protected_field`;
  END IF;

  IF((NEW.`lineType`!=OLD.`lineType`) AND (NEW.`IdHTicket`=OLD.`IdHTicket`)) THEN
    SET @wgt = IF(OLD.`SaleForm`=1,OLD.`Weight`,0);
    SET @units = IF(NEW.`SaleForm`=0,NEW.`Weight`,0);
    CASE(NEW.`lineType`)

      WHEN 0 THEN
        IF(OLD.`lineType`=1) THEN
          UPDATE `LocalHTickets` AS ht SET `AddedLines`=`AddedLines`-1, `GrossAmount`=`GrossAmount`-OLD.`Amount`,
            `NegativeLines`=`NegativeLines`-IF(OLD.`Price`<0,1,0), `NegativeAmount` = `NegativeAmount`-IF(OLD.`Price`<0,-OLD.`Amount`,0),
            `CanceledLines`=`CanceledLines`+1, `CanceledAmount` = `CanceledAmount`+OLD.`Amount`,
            `TotalWeight`=`TotalWeight`-IF(OLD.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`-IF(NEW.`Price`<0,0,@units),
            ht.`PointsExtra`=ht.`PointsExtra`-IF(OLD.`Price`>0,OLD.`Points`,0), `DatTim`=NOW()
          WHERE ht.`Id`=OLD.`IdHTicket`;
        END IF;

      WHEN 1 THEN
        IF(OLD.`lineType`=0) THEN
          UPDATE `LocalHTickets` AS ht SET `AddedLines`=`AddedLines`+1, `GrossAmount`=`GrossAmount`+OLD.`Amount`,
            `NegativeLines`=`NegativeLines`+IF(OLD.`Price`<0,1,0), `NegativeAmount`=`NegativeAmount`+IF(OLD.`Price`<0,-OLD.`Amount`,0),
            `CanceledLines`=`CanceledLines`-1, `CanceledAmount`=`CanceledAmount`-OLD.`Amount`,
            `TotalWeight`=`TotalWeight`+IF(OLD.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`+IF(NEW.`Price`<0,0,@units),
            ht.`PointsExtra`=ht.`PointsExtra`+IF(OLD.`Price`>0,OLD.`Points`,0), `DatTim`=NOW()
          WHERE ht.`Id`=OLD.`IdHTicket`;
        END IF;

      WHEN 2 THEN
        IF((NEW.`SaleForm`=0) AND (OLD.`lineType`=3)) THEN
          UPDATE `LocalHTickets` AS ht SET `TotalWeight`=`TotalWeight`-@wgt, `TotalUnits`=`TotalUnits`-@units, `PointsChanged`=`PointsChanged`-OLD.`Price`, `DatTim`=NOW() WHERE ht.`Id`=OLD.`IdHTicket`;
        END IF;

      WHEN 3 THEN
        IF((NEW.`SaleForm`=0) AND (OLD.`lineType`=2)) THEN
          UPDATE `LocalHTickets` AS ht SET `TotalWeight`=`TotalWeight`+@wgt, `TotalUnits`=`TotalUnits`+@units, `PointsChanged`=`PointsChanged`+OLD.`Price`, `DatTim`=NOW() WHERE ht.`Id`=OLD.`IdHTicket`;
        END IF;

      ELSE BEGIN END;
    END CASE;


  ELSEIF((NEW.`lineType`=OLD.`lineType`) AND (NEW.`IdHTicket`!=OLD.`IdHTicket`)) THEN
    SET @wgt = IF(NEW.`SaleForm`=1,NEW.`Weight`,0);
    SET @units = IF(NEW.`SaleForm`=0,NEW.`Weight`,0);
    SET @src_stck = ' ';
    SET @src_norder = 0;
    SET @dst_stck = ' ';
    SET @dst_norder = 0;
    SELECT `Status`, `OrderNumber`INTO @src_stck,@src_norder FROM `LocalHTickets` AS ht WHERE ht.`Id`=OLD.`IdHTicket`;
    SELECT `Status`, `OrderNumber`INTO @dst_stck,@dst_norder FROM `LocalHTickets` AS ht WHERE ht.`Id`=NEW.`IdHTicket`;
    IF ((@src_stck='O' OR @src_stck='P') AND (@dst_stck='O') AND (@src_norder='') AND (@dst_norder='')) THEN
      CASE(NEW.`lineType`)

        WHEN 0 THEN
          UPDATE `LocalHTickets` AS ht SET `NumLines`=`NumLines`+1, `CanceledLines`=`CanceledLines`+1, `CanceledAmount`=`CanceledAmount`+NEW.`Amount` WHERE ht.`Id`=NEW.`IdHTicket`;
          UPDATE `LocalHTickets` AS ht SET `NumLines`=`NumLines`-1, `CanceledLines`=`CanceledLines`-1, `CanceledAmount`=`CanceledAmount`-NEW.`Amount` WHERE ht.`Id`=OLD.`IdHTicket`;

        WHEN 1 THEN
          UPDATE `LocalHTickets` AS ht SET `NumLines`=`NumLines`+1, `AddedLines`=`AddedLines`+1, `GrossAmount`=`GrossAmount`+NEW.`Amount`,
            `NegativeLines`=`NegativeLines`+IF(NEW.`Price`<0,1,0), `NegativeAmount` = `NegativeAmount`+IF(NEW.`Price`<0,-NEW.`Amount`,0),
            `TotalWeight`=`TotalWeight`+IF(NEW.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`+IF(NEW.`Price`<0,0,@units)
             WHERE ht.`Id`=NEW.`IdHTicket`;
          UPDATE `LocalHTickets` AS ht SET `NumLines`=`NumLines`-1, `AddedLines`=`AddedLines`-1, `GrossAmount`=`GrossAmount`-NEW.`Amount`,
            `NegativeLines`=`NegativeLines`-IF(NEW.`Price`<0,1,0), `NegativeAmount` = `NegativeAmount`-IF(NEW.`Price`<0,-NEW.`Amount`,0),
            `TotalWeight`=`TotalWeight`-IF(NEW.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`-IF(NEW.`Price`<0,0,@units)
             WHERE ht.`Id`=OLD.`IdHTicket`;

        WHEN 3 THEN
          IF(NEW.`SaleForm`=0) THEN
            UPDATE `LocalHTickets` AS ht SET `TotalWeight`=`TotalWeight`+@wgt, `TotalUnits`=`TotalUnits`+@units WHERE ht.`Id`=NEW.`IdHTicket`;
            UPDATE `LocalHTickets` AS ht SET `TotalWeight`=`TotalWeight`-@wgt, `TotalUnits`=`TotalUnits`-@units WHERE ht.`Id`=OLD.`IdHTicket`;
          END IF;

        ELSE BEGIN END;
      END CASE;
    ELSE
      CALL `manipulate_protected_field1`;
    END IF;

  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertLocalVendorKey` AFTER INSERT ON `LocalVendorKeys`
FOR EACH ROW BEGIN
  IF (NEW.`Counter`= GLOBAL_GET("current_counter")) THEN
    REPLACE INTO `LocalVendorKeysChanges` (`VendorKey`, `Vendor`, `VendorRelease`,`Name`, `Icon`) 
     SELECT NEW.`VendorKey`, NEW.`Vendor`, 8880, `Vendors`.`Name`, `Vendors`.`Icon` 
     FROM `Vendors` WHERE `Vendors`.`Code`=NEW.`Vendor`;
    IF @disable_localregister IS NULL THEN
      INSERT INTO `LocalVendorRegister` (`Vendor`,`RegisterDateTime`) VALUES (NEW.`Vendor`,NOW());
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateLocalVendorKey` AFTER UPDATE ON `LocalVendorKeys`
FOR EACH ROW BEGIN
  SET @counter := GLOBAL_GET("current_counter");
  IF (OLD.`Counter`= @counter) THEN
    INSERT INTO `LocalVendorKeysChanges` (`VendorKey`, `VendorRelease`) VALUE (OLD.`VendorKey`, OLD.`Vendor` )
    ON DUPLICATE KEY UPDATE `LocalVendorKeysChanges`.`VendorRelease`=OLD.`Vendor`;
  END IF;
  IF (NEW.`Counter`= @counter) THEN
    INSERT INTO `LocalVendorKeysChanges` (`VendorKey`, `Vendor`, `VendorRelease`, `Name`, `Icon`) 
      SELECT NEW.`VendorKey`, NEW.`Vendor`, OLD.`Vendor`, `Vendors`.`Name`, `Vendors`.`Icon` FROM `Vendors` WHERE `Vendors`.`Code`=NEW.`Vendor` 
    ON DUPLICATE KEY UPDATE `LocalVendorKeysChanges`.`Vendor`=NEW.`Vendor`, `LocalVendorKeysChanges`.`Name`=VALUES(`Name`), `LocalVendorKeysChanges`.`Icon`=VALUES(`Icon`);
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteLocalVendorKey` AFTER DELETE ON `LocalVendorKeys`
FOR EACH ROW BEGIN
  IF (OLD.`Counter`= GLOBAL_GET("current_counter")) THEN
    REPLACE INTO `LocalVendorKeysChanges` (`VendorKey`, `Vendor`, `VendorRelease`) VALUE (OLD.`VendorKey`, 0, OLD.`Vendor` );
    IF @disable_localregister IS NULL THEN
      UPDATE `LocalVendorRegister` SET `ReleaseDateTime`=NOW() WHERE `Vendor`=OLD.`Vendor` AND `ReleaseDateTime`<='1970-01-01 00:00:00';
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalWMInserted` AFTER INSERT ON `LocalWorkingModes`
FOR EACH ROW BEGIN
  IF(NEW.`WorkingMode`=(SELECT `ParamValue` FROM `LocalWorkingModes` WHERE `ParamName`="working-mode" AND `WorkingMode`="")) THEN
    SET @trx := (SELECT trx_new("BUTTON_UPDATE", "CORE"));
    SET @ret := (SELECT trx_set_param(@trx, "WORKINGMODE", NEW.`WorkingMode`));
    SET @ret := (SELECT trx_set_param(@trx, "PARAMNAME", CONCAT("WORKINGMODES_", NEW.`ParamName`)));
    SET @ret := (SELECT trx_set_param(@trx, "PARAMVALUE", NEW.`ParamValue`));
    SET @ret := (SELECT trx_send(@trx));
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalWMUpdated` AFTER UPDATE ON `LocalWorkingModes`
FOR EACH ROW BEGIN
  IF(NEW.`WorkingMode`=(SELECT `ParamValue` FROM `LocalWorkingModes` WHERE `ParamName`="working-mode" AND `WorkingMode`="")) THEN
    IF(OLD.`ParamValue`!=NEW.`ParamValue`) THEN
      SET @trx := (SELECT trx_new("BUTTON_UPDATE", "CORE"));
      SET @ret := (SELECT trx_set_param(@trx, "WORKINGMODE", NEW.`WorkingMode`));
      SET @ret := (SELECT trx_set_param(@trx, "PARAMNAME", CONCAT("WORKINGMODES_", NEW.`ParamName`)));
      SET @ret := (SELECT trx_set_param(@trx, "PARAMVALUE", NEW.`ParamValue`));
      SET @ret := (SELECT trx_send(@trx));
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LocalWMDeleted` AFTER DELETE ON `LocalWorkingModes`
FOR EACH ROW BEGIN
  IF(OLD.`WorkingMode`=(SELECT `ParamValue` FROM `LocalWorkingModes` WHERE `ParamName`="working-mode" AND `WorkingMode`="")) THEN
    SET @trx := (SELECT trx_new("BUTTON_UPDATE", "CORE"));
    SET @ret := (SELECT trx_set_param(@trx, "WORKINGMODE", OLD.`WorkingMode`));
    SET @ret := (SELECT trx_set_param(@trx, "PARAMNAME", CONCAT("WORKINGMODES_", OLD.`ParamName`)));
    SET @ret := (SELECT trx_set_param(@trx, "PARAMVALUE", ""));
    SET @ret := (SELECT trx_send(@trx));
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LTicketsInsertB` BEFORE INSERT ON `LTickets`
FOR EACH ROW BEGIN

  SET @HTStatus:=(SELECT Status FROM `HTickets` WHERE `HTickets`.`Id`=NEW.`IdHTicket`);

  IF(NEW.`NetStat`='N') THEN

    IF(@HTStatus='v') THEN
      SET NEW.`Weight`=-NEW.`Weight`;
      SET NEW.`Amount`=-NEW.`Amount`;
    END IF;

    IF(@HTStatus IN ('O','v')) THEN
     IF(NEW.`lineType`=1) THEN
        SET NEW.`LineDateTime`=NOW();
        IF ((SELECT IFNULL(`ParamValue`,0) FROM `CfgSystem` WHERE `ParamKey`='loyalty-items-extra-points')!=0) THEN
          SET NEW.`Points`=IFNULL((SELECT
            IF(`ItemsExtraPoints`.`FromQuantity`,

              IF(`ItemsExtraPoints`.`Quantity`,

                IF(`ItemsExtraPoints`.`Proportional`,

                  IF(NEW.`Weight`>=`ItemsExtraPoints`.`FromQuantity`,(((NEW.`Weight`-`ItemsExtraPoints`.`FromQuantity`)/`ItemsExtraPoints`.`Quantity`) +1)*`ItemsExtraPoints`.`Points`, 0),

                    IF(NEW.`Weight`>=`ItemsExtraPoints`.`FromQuantity`,(((NEW.`Weight`-`ItemsExtraPoints`.`FromQuantity`)/`ItemsExtraPoints`.`Quantity`) DIV 1 +1)*`ItemsExtraPoints`.`Points`, 0)),

                IF(NEW.`Weight`>=`ItemsExtraPoints`.`FromQuantity`,`ItemsExtraPoints`.`Points`,0)),

              IF(`ItemsExtraPoints`.`Quantity`,

                IF(`ItemsExtraPoints`.`Proportional`,

                  (NEW.`Weight`/`ItemsExtraPoints`.`Quantity`)*`ItemsExtraPoints`.`Points`,

                    IF(NEW.`Weight`>=`ItemsExtraPoints`.`Quantity`,(((NEW.`Weight`-`ItemsExtraPoints`.`Quantity`)/`ItemsExtraPoints`.`Quantity`) DIV 1 +1)*`ItemsExtraPoints`.`Points`, 0)),

                `ItemsExtraPoints`.`Points`))
          FROM `ItemsExtraPoints` WHERE `ItemsExtraPoints`.`Code`=NEW.`Item`), 0);
        END IF;
      END IF;

    ELSE
      UPDATE `PCScaleErrorTag` SET x=1;
    END IF;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LTicketsInserted` AFTER INSERT ON `LTickets`
FOR EACH ROW BEGIN

  IF(NEW.`NetStat`='N') THEN


    IF(@HTStatus IN ('O','v')) THEN
      SET @wgt = IF(NEW.`SaleForm`=1,NEW.`Weight`,0);
      SET @units = IF(NEW.`SaleForm`=0,NEW.`Weight`,0);
      CASE(NEW.`lineType`)

        WHEN 0 THEN
          UPDATE `HTickets` SET `NumLines`=`NumLines`+1, `CanceledLines`=`CanceledLines`+1, `CanceledAmount`=`CanceledAmount`+NEW.`Amount`,
            `DatTim`=NOW(), `SectionItem`=NEW.`Section` WHERE `HTickets`.`Id`=NEW.`IdHTicket`;

        WHEN 1 THEN
          UPDATE `HTickets` SET `NumLines`=`NumLines`+1, `AddedLines`=`AddedLines`+1, `GrossAmount`=`GrossAmount`+NEW.`Amount`,
            `NegativeLines`=`NegativeLines`+IF(NEW.`Price`<0,1,0), `NegativeAmount` = `NegativeAmount`+IF(NEW.`Price`<0,-NEW.`Amount`,0),
            `TotalWeight`=`TotalWeight`+IF(NEW.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`+IF(NEW.`Price`<0,0,@units),
            `HTickets`.`PointsExtra`=`HTickets`.`PointsExtra`+IF(NEW.`Price`>0,NEW.`Points`,0),
            `DatTim`=NOW(), `SectionItem`=NEW.`Section` WHERE `HTickets`.`Id`=NEW.`IdHTicket`;
          SET @norder = '';
          SELECT `HCustomerOrders`.`Number`,`HCustomerOrders`.`Section` INTO @norder, @secorder FROM `HCustomerOrders`
            WHERE `HCustomerOrders`.`IdHTicket`=NEW.`IdHTicket` AND ((`HCustomerOrders`.`Status`>1) AND (`HCustomerOrders`.`Status`!=3));
          IF(@norder!='') THEN
            INSERT INTO `LCustomerOrders` (`OrderNumber`, `Section`, `Item`, `ItemFormat`, `Price`,`Status`,`Weight`,`Units`,`Amount`,`DatTim`)
              VALUES (@norder, @secorder, NEW.`Item`, NEW.`ItemFormat`, NEW.`Price`, 3, @wgt, @units, NEW.`Amount`,NOW())
              ON DUPLICATE KEY UPDATE `LCustomerOrders`.`Weight`=`LCustomerOrders`.`Weight`+@wgt, `LCustomerOrders`.`Units`=`LCustomerOrders`.`Units`+@units,
              `LCustomerOrders`.`Amount`=`LCustomerOrders`.`Amount`+VALUES(`Amount`),`LCustomerOrders`.`DatTim`=NOW(),
              `LCustomerOrders`.`ReplacedBy`=IF(@wgt=0 AND @units=0, 0, `LCustomerOrders`.`ReplacedBy`),
              `LCustomerOrders`.`Status`=IF((@wgt=0 AND @units=0 AND `LCustomerOrders`.`Status`=0), 5, ((CAST(Status AS UNSIGNED) & CAST(b'00000010' AS UNSIGNED)) | CAST(b'00000001' AS UNSIGNED)));
          END IF;

        WHEN 3 THEN
          IF(NEW.`SaleForm`=0) THEN
            UPDATE `HTickets` SET `TotalWeight`=`TotalWeight`+@wgt, `TotalUnits`=`TotalUnits`+@units, `PointsChanged`=`PointsChanged`+NEW.`Price`, `DatTim`=NOW()
              WHERE `HTickets`.`Id`=NEW.`IdHTicket`;
          END IF;

        ELSE BEGIN END;
      END CASE;
    END IF;
  END IF;

  CASE(NEW.`lineType`)
    WHEN 1 THEN

      UPDATE `Stock` SET
        `Stock`.`Weight`=(`Stock`.`Weight`-(IF(NEW.`Saleform`=1,IF(NEW.`Price`<0,-NEW.`Weight`,NEW.`Weight`),0))),
        `Stock`.`Units`=(`Stock`.`Units`-(IF(NEW.`Saleform`=0,IF(NEW.`Price`<0,-NEW.`Weight`,NEW.`Weight`),0)))
      WHERE `Stock`.`Code` = NEW.`Item`;
    WHEN 3 THEN

      IF(NEW.`SaleForm`=0) THEN
        UPDATE `Stock` SET `Stock`.`Units`=(`Stock`.`Units`-NEW.`Weight`) WHERE `Stock`.`Code` = NEW.`Item`;
      END IF;

    ELSE BEGIN END;
  END CASE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `LTicketsUpdated` AFTER UPDATE ON `LTickets`
FOR EACH ROW BEGIN
  IF((NEW.`Amount`!=OLD.`Amount`) OR (NEW.`VATCode`!=OLD.`VATCode`) OR (NEW.`VATPercent`!=OLD.`VATPercent`)
    OR (NEW.`SaleForm`!=OLD.`SaleForm`) OR (NEW.`Weight`!=OLD.`Weight`) OR (NEW.`Price`!=OLD.`Price`) OR (NEW.`lineDiscount`!=OLD.`lineDiscount`)
    OR ((NEW.`lineType`!=OLD.`lineType`) AND (NEW.`IdHTicket`!=OLD.`IdHTicket`))) THEN
    CALL `manipulate_protected_field`;
  END IF;

  IF((NEW.`lineType`!=OLD.`lineType`) AND (NEW.`IdHTicket`=OLD.`IdHTicket`)) THEN
    SET @wgt = IF(OLD.`SaleForm`=1,OLD.`Weight`,0);
    SET @units = IF(OLD.`SaleForm`=0,OLD.`Weight`,0);
    SET @stck = ' ';
    SET @norder = 0;
    SELECT `Status`, `OrderNumber`INTO @stck,@norder FROM `HTickets` AS ht WHERE ht.`Id`=OLD.`IdHTicket`;
    IF(@stck='O') THEN
      CASE(NEW.`lineType`)

        WHEN 0 THEN
          IF(OLD.`lineType`=1) THEN
            UPDATE `HTickets` AS ht SET `AddedLines`=`AddedLines`-1, `GrossAmount`=`GrossAmount`-OLD.`Amount`,
              `NegativeLines`=`NegativeLines`-IF(OLD.`Price`<0,1,0), `NegativeAmount` = `NegativeAmount`-IF(OLD.`Price`<0,-OLD.`Amount`,0),
              `CanceledLines`=`CanceledLines`+1, `CanceledAmount` = `CanceledAmount`+OLD.`Amount`,
              `TotalWeight`=`TotalWeight`-IF(OLD.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`-IF(NEW.`Price`<0,0,@units),
              ht.`PointsExtra`=ht.`PointsExtra`-IF(OLD.`Price`>0,OLD.`Points`,0), `DatTim`=NOW()
            WHERE ht.`Id`=OLD.`IdHTicket`;
            IF(@norder!=0) THEN 
              UPDATE `LCustomerOrders` SET `LCustomerOrders`.`Weight`=`LCustomerOrders`.`Weight`-@wgt, `LCustomerOrders`.`Units`=`LCustomerOrders`.`Units`-@units,
                `LCustomerOrders`.`Amount`=`LCustomerOrders`.`Amount`-OLD.`Amount`,`LCustomerOrders`.`DatTim`=NOW(),
                `LCustomerOrders`.`ReplacedBy`=IF(`LCustomerOrders`.`Weight`!=0 OR `LCustomerOrders`.`Units`!=0, 0, `LCustomerOrders`.`ReplacedBy`),
                `LCustomerOrders`.`Status`=IF((`LCustomerOrders`.`Weight`=0 AND `LCustomerOrders`.`Units`=0), CASE `LCustomerOrders`.`Status` WHEN 1 THEN 0 WHEN 3 THEN 2 ELSE `LCustomerOrders`.`Status` END, `LCustomerOrders`.`Status`)
              WHERE `LCustomerOrders`.`OrderNumber`=@norder AND `LCustomerOrders`.`Item`=OLD.`Item` AND `LCustomerOrders`.`ItemFormat`=OLD.`ItemFormat`;
           END IF;

            UPDATE `Stock` SET
              `Stock`.`Weight`=(`Stock`.`Weight`-(IF(NEW.`Saleform`=1,IF(NEW.`Price`<0,NEW.`Weight`,-NEW.`Weight`),0))),
              `Stock`.`Units`=(`Stock`.`Units`-(IF(NEW.`Saleform`=0,IF(NEW.`Price`<0,NEW.`Weight`,-NEW.`Weight`),0)))
            WHERE `Stock`.`Code` = NEW.`Item`;
          END IF;

        WHEN 1 THEN
          IF(OLD.`lineType`=0) THEN
            UPDATE `HTickets` AS ht SET `AddedLines`=`AddedLines`+1, `GrossAmount`=`GrossAmount`+OLD.`Amount`,
              `NegativeLines`=`NegativeLines`+IF(OLD.`Price`<0,1,0), `NegativeAmount` = `NegativeAmount`+IF(OLD.`Price`<0,-OLD.`Amount`,0),
              `CanceledLines`=`CanceledLines`-1, `CanceledAmount` = `CanceledAmount`-OLD.`Amount`,
              `TotalWeight`=`TotalWeight`+IF(OLD.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`+IF(NEW.`Price`<0,0,@units),
              ht.`PointsExtra`=ht.`PointsExtra`+IF(OLD.`Price`>0,OLD.`Points`,0), `DatTim`=NOW()
            WHERE ht.`Id`=OLD.`IdHTicket`;
            IF(@norder!=0) THEN 
              UPDATE `LCustomerOrders` SET `LCustomerOrders`.`Weight`=`LCustomerOrders`.`Weight`+@wgt, `LCustomerOrders`.`Units`=`LCustomerOrders`.`Units`+@units,
               `LCustomerOrders`.`Amount`=`LCustomerOrders`.`Amount`+OLD.`Amount`,`LCustomerOrders`.`DatTim`=NOW(),
                `LCustomerOrders`.`Status`=IF(`LCustomerOrders`.`Status`=0, 1, `LCustomerOrders`.`Status`)
              WHERE `LCustomerOrders`.`OrderNumber`=@norder AND `LCustomerOrders`.`Item`=OLD.`Item` AND `LCustomerOrders`.`ItemFormat`=OLD.`ItemFormat`;
            END IF;

            UPDATE `Stock` SET
              `Stock`.`Weight`=(`Stock`.`Weight`-(IF(NEW.`Saleform`=1,IF(NEW.`Price`<0,-NEW.`Weight`,NEW.`Weight`),0))),
              `Stock`.`Units`=(`Stock`.`Units`-(IF(NEW.`Saleform`=0,IF(NEW.`Price`<0,-NEW.`Weight`,NEW.`Weight`),0)))
            WHERE `Stock`.`Code` = NEW.`Item`;
          END IF;

        WHEN 2 THEN
          IF((NEW.`SaleForm`=0) AND (OLD.`lineType`=3)) THEN
            UPDATE `HTickets` AS ht SET `TotalWeight`=`TotalWeight`-@wgt, `TotalUnits`=`TotalUnits`-@units, `PointsChanged`=`PointsChanged`-OLD.`Price`, `DatTim`=NOW() WHERE ht.`Id`=OLD.`IdHTicket`;

            UPDATE `Stock` SET `Stock`.`Units`=(`Stock`.`Units`+NEW.`Weight`) WHERE `Stock`.`Code` = NEW.`Item`;
          END IF;

        WHEN 3 THEN
          IF((NEW.`SaleForm`=0) AND (OLD.`lineType`=2)) THEN
            UPDATE `HTickets` AS ht SET `TotalWeight`=`TotalWeight`+@wgt, `TotalUnits`=`TotalUnits`+@units, `PointsChanged`=`PointsChanged`+OLD.`Price`, `DatTim`=NOW() WHERE ht.`Id`=OLD.`IdHTicket`;

            UPDATE `Stock` SET `Stock`.`Units`=(`Stock`.`Units`-NEW.`Weight`) WHERE `Stock`.`Code` = NEW.`Item`;
          END IF;

        ELSE BEGIN END;
      END CASE;
    END IF; 


  ELSEIF((NEW.`lineType`=OLD.`lineType`) AND (NEW.`IdHTicket`!=OLD.`IdHTicket`)) THEN
    SET @wgt = IF(NEW.`SaleForm`=1,NEW.`Weight`,0);
    SET @units = IF(NEW.`SaleForm`=0,NEW.`Weight`,0);
    SET @src_stck = ' ';
    SET @src_norder = 0;
    SET @dst_stck = ' ';
    SET @dst_norder = 0;
    SELECT `Status`, `OrderNumber`INTO @src_stck,@src_norder FROM `HTickets` AS ht WHERE ht.`Id`=OLD.`IdHTicket`;
    SELECT `Status`, `OrderNumber`INTO @dst_stck,@dst_norder FROM `HTickets` AS ht WHERE ht.`Id`=NEW.`IdHTicket`;

    IF ((@src_stck='O' OR @src_stck='P') AND (@dst_stck='O')) THEN
      CASE(NEW.`lineType`)

        WHEN 0 THEN
          UPDATE `HTickets` AS ht SET `NumLines`=`NumLines`+1, `CanceledLines`=`CanceledLines`+1, `CanceledAmount`=`CanceledAmount`+NEW.`Amount` WHERE ht.`Id`=NEW.`IdHTicket`;
          UPDATE `HTickets` AS ht SET `NumLines`=`NumLines`-1, `CanceledLines`=`CanceledLines`-1, `CanceledAmount`=`CanceledAmount`-NEW.`Amount` WHERE ht.`Id`=OLD.`IdHTicket`;

        WHEN 1 THEN
          UPDATE `HTickets` AS ht SET `NumLines`=`NumLines`+1, `AddedLines`=`AddedLines`+1, `GrossAmount`=`GrossAmount`+NEW.`Amount`,
            `NegativeLines`=`NegativeLines`+IF(NEW.`Price`<0,1,0), `NegativeAmount` = `NegativeAmount`+IF(NEW.`Price`<0,-NEW.`Amount`,0),
            `TotalWeight`=`TotalWeight`+IF(NEW.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`+IF(NEW.`Price`<0,0,@units)
             WHERE ht.`Id`=NEW.`IdHTicket`;
          UPDATE `HTickets` AS ht SET `NumLines`=`NumLines`-1, `AddedLines`=`AddedLines`-1, `GrossAmount`=`GrossAmount`-NEW.`Amount`,
            `NegativeLines`=`NegativeLines`-IF(NEW.`Price`<0,1,0), `NegativeAmount` = `NegativeAmount`-IF(NEW.`Price`<0,-NEW.`Amount`,0),
            `TotalWeight`=`TotalWeight`-IF(NEW.`Price`<0,0,@wgt), `TotalUnits`=`TotalUnits`-IF(NEW.`Price`<0,0,@units)
             WHERE ht.`Id`=OLD.`IdHTicket`;

        WHEN 3 THEN
          IF(NEW.`SaleForm`=0) THEN
            UPDATE `HTickets` AS ht SET `TotalWeight`=`TotalWeight`+@wgt, `TotalUnits`=`TotalUnits`+@units WHERE ht.`Id`=NEW.`IdHTicket`;
            UPDATE `HTickets` AS ht SET `TotalWeight`=`TotalWeight`-@wgt, `TotalUnits`=`TotalUnits`-@units WHERE ht.`Id`=OLD.`IdHTicket`;
          END IF;

        ELSE BEGIN END;
      END CASE;
    ELSE
      CALL `manipulate_protected_field1`;
    END IF;

  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `PLUKeysInserted` AFTER INSERT ON `PLUKeys`
FOR EACH ROW BEGIN
  IF (NEW.`Section`=0 AND NEW.`Board`=GLOBAL_GET("current_mupboard")) THEN
    INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (0, NEW.`Board`, NEW.`PLUKey`, NEW.`Code`)
      ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;
  ELSEIF (NEW.`Section`=GLOBAL_GET("current_group")) THEN
    CASE GLOBAL_GET("PLUload-func")

      WHEN 0 THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (NEW.`Section`, NEW.`Board`, NEW.`PLUKey`, NEW.`Code`)
        ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;

      WHEN 1 THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Section`, `Family`, NEW.`PLUKey`, NEW.`Code` FROM `Items` WHERE `Items`.`Code`=NEW.`Code`
        ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;

      WHEN 2 THEN BEGIN END;




      ELSE BEGIN END;
    END CASE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `PLUKeysUpdated` AFTER UPDATE ON `PLUKeys`
FOR EACH ROW BEGIN
  SET @mygroup := GLOBAL_GET("current_group");
  SET @mupboard := GLOBAL_GET("current_mupboard");
  IF (OLD.`Section`=0 AND OLD.`Board`=@mupboard) THEN
      INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (0, @mupboard, OLD.`PLUKey`, 0)
      ON DUPLICATE KEY UPDATE `Code`=0;
  ELSEIF (OLD.`Section`=@mygroup) THEN
    CASE GLOBAL_GET("PLUload-func")

      WHEN 0 THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (OLD.`Section`, OLD.`Board`, OLD.`PLUKey`, 0)
        ON DUPLICATE KEY UPDATE `Code`=0;

      WHEN 1 THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT OLD.`Section`, `Family`, OLD.`PLUKey`, 0 FROM `Items` WHERE `Items`.`Code`=OLD.`Code`
        ON DUPLICATE KEY UPDATE `Code`=0;

      WHEN 2 THEN BEGIN END;




      ELSE BEGIN END;
   END CASE;
  END IF;
  IF (NEW.`Section`=0 AND NEW.`Board`=@mupboard) THEN
    INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (0, @mupboard, NEW.`PLUKey`, NEW.`Code`)
          ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;
  ELSEIF (NEW.`Section`=@mygroup) THEN
    CASE GLOBAL_GET("PLUload-func")

      WHEN 0 THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (NEW.`Section`, NEW.`Board`, NEW.`PLUKey`, NEW.`Code`)
        ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;

      WHEN 1 THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT NEW.`Section`, `Family`, NEW.`PLUKey`, NEW.`Code` FROM `Items` WHERE `Items`.`Code`=NEW.`Code`
        ON DUPLICATE KEY UPDATE `Code`=NEW.`Code`;

      WHEN 2 THEN BEGIN END;




      ELSE BEGIN END;
    END CASE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `PLUKeysDeleted` AFTER DELETE ON `PLUKeys`
FOR EACH ROW BEGIN
  IF (OLD.`Section`=0 AND OLD.`Board`=GLOBAL_GET("current_mupboard")) THEN
    INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (0, OLD.`Board`, OLD.`PLUKey`, 0)
    ON DUPLICATE KEY UPDATE `Code`=0;
  ELSEIF (OLD.`Section`=GLOBAL_GET("current_group")) THEN
    CASE GLOBAL_GET("PLUload-func")

      WHEN 0 THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) VALUES (OLD.`Section`, OLD.`Board`, OLD.`PLUKey`, 0)
        ON DUPLICATE KEY UPDATE `Code`=0;

      WHEN 1 THEN
        INSERT INTO `LocalPLUKeysChanges` (`Section`,`Board`,`PLUKey`,`Code`) SELECT OLD.`Section`, `Family`, OLD.`PLUKey`, 0 FROM `Items` WHERE `Items`.`Code`=OLD.`Code`
        ON DUPLICATE KEY UPDATE `Code`=0;

      WHEN 2 THEN BEGIN END;




      ELSE BEGIN END;
    END CASE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `PLUKeysFileInserted` AFTER INSERT ON `PLUKeysFile`
FOR EACH ROW BEGIN
  SET @loadfunc := IFNULL (GLOBAL_GET("PLUload-func"),99);
  IF (@loadfunc=5) THEN

    UPDATE `LocalStatus` SET `ResizeTouch`=TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `PLUKeysFilesUpdated` AFTER UPDATE ON `PLUKeysFile`
FOR EACH ROW BEGIN
  SET @loadfunc := IFNULL (GLOBAL_GET("PLUload-func"),99);
  IF (@loadfunc=5) THEN

    UPDATE `LocalStatus` SET `ResizeTouch`=TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `PLUKeysFileDeleted` BEFORE DELETE ON `PLUKeysFile`
FOR EACH ROW BEGIN
  SET @loadfunc := IFNULL (GLOBAL_GET("PLUload-func"),99);
  IF (@loadfunc=5) THEN

    UPDATE `LocalStatus` SET `ResizeTouch`=TRUE;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertQuickKeys` AFTER INSERT ON `QuickKeys`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckQuickKeys`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateQuickKeys` AFTER UPDATE ON `QuickKeys`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckQuickKeys`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteQuickKeys` AFTER DELETE ON `QuickKeys`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckQuickKeys`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `JoinScale` AFTER INSERT ON `Scales`
FOR EACH ROW BEGIN
	UPDATE `LocalStatus` SET `RemoveScale`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `ChangeScale` AFTER UPDATE ON `Scales`
FOR EACH ROW BEGIN
	UPDATE `LocalStatus` SET `RemoveScale`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `RemoveScale` AFTER DELETE ON `Scales`
FOR EACH ROW BEGIN
	UPDATE `LocalStatus` SET `RemoveScale`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertScripts` AFTER INSERT ON `Scripts`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckScripts`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateScripts` AFTER UPDATE ON `Scripts`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckScripts`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteScripts` AFTER DELETE ON `Scripts`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckScripts`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertSection` AFTER INSERT ON `Sections`
FOR EACH ROW BEGIN
	UPDATE `LocalStatus` SET `CheckSections`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateSection` AFTER UPDATE ON `Sections`
FOR EACH ROW BEGIN
	UPDATE `LocalStatus` SET `CheckSections`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteSection` AFTER DELETE ON `Sections`
FOR EACH ROW BEGIN
	UPDATE `LocalStatus` SET `CheckSections`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertShortcuts` AFTER INSERT ON `Shortcuts`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckShortcuts`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateShortcuts` AFTER UPDATE ON `Shortcuts`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckShortcuts`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteShortcuts` AFTER DELETE ON `Shortcuts`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckShortcuts`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertStock` AFTER INSERT ON `Stock`
FOR EACH ROW BEGIN
  UPDATE `Items` SET `Items`.`Price`=`Items`.`Price` WHERE `Items`.`Code`=NEW.`Code`;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateStock` AFTER UPDATE ON `Stock`
FOR EACH ROW BEGIN
  UPDATE `Items` SET `Items`.`Price`=`Items`.`Price` WHERE (`Items`.`Code`=NEW.`Code`) OR (`Items`.`Code`=OLD.`Code`);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteStock` AFTER DELETE ON `Stock`
FOR EACH ROW BEGIN
  UPDATE `Items` SET `Items`.`Price`=`Items`.`Price` WHERE `Items`.`Code`=OLD.`Code`;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertCounterTareCodes` AFTER INSERT ON `TareCodes`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckTareCodes`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateCounterTareCodes` AFTER UPDATE ON `TareCodes`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckTareCodes`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteCounterTareCodes` AFTER DELETE ON `TareCodes`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckTareCodes`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertTotalDaily` AFTER INSERT ON `TotalDaily`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckTotalDaily`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateBTotalDaily` BEFORE UPDATE ON `TotalDaily`
FOR EACH ROW BEGIN
  IF((@DailyUnlock IS NULL) OR (@DailyUnlock!='451')) THEN 
    CALL `manipulate_protected_field`;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateBTotalPayTickets` BEFORE UPDATE ON `TotalPayTickets`
FOR EACH ROW BEGIN
  IF((@DailyUnlock IS NULL) OR (@DailyUnlock!='451')) THEN 
    CALL `manipulate_protected_field`;  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertTotalScaleFamilies` AFTER INSERT ON `TotalScaleFamilies`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckTotalScaleFamilies`=TRUE;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateBTotalVAT` BEFORE UPDATE ON `TotalVAT`
FOR EACH ROW BEGIN
  IF((@DailyUnlock IS NULL) OR (@DailyUnlock!='451')) THEN 
    CALL `manipulate_protected_field`;
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TrademarkInsertedB` BEFORE INSERT ON `Trademark`
FOR EACH ROW BEGIN
  SET NEW.`Id`=1;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TrademarkInserted` AFTER INSERT ON `Trademark`
FOR EACH ROW BEGIN
  SET @trx := (SELECT trx_new("TIN_UPDATE", "CORE-DATA"));
  SET @ret := (SELECT trx_set_param(@trx, "TIN", NEW.`TIN`));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TrademarkUpdated` AFTER UPDATE ON `Trademark`
FOR EACH ROW BEGIN
  IF(OLD.`TIN`!=NEW.`TIN`) THEN
    SET @trx := (SELECT trx_new("TIN_UPDATE", "CORE-DATA"));
    SET @ret := (SELECT trx_set_param(@trx, "TIN", NEW.`TIN`));
    SET @ret := (SELECT trx_send(@trx));
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TrademarkDeleted` AFTER DELETE ON `Trademark`
FOR EACH ROW BEGIN
  SET @trx := (SELECT trx_new("TIN_UPDATE", "CORE-DATA"));
  SET @ret := (SELECT trx_set_param(@trx, "TIN", ""));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `bTurnInsert` BEFORE INSERT ON `Turn`
FOR EACH ROW BEGIN
  SET NEW.`LastResetDate`=NOW();
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TurnInserted` AFTER INSERT ON `Turn`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckTurn` = TRUE;
  SET @trx := (SELECT trx_new("TURN_RELOAD", "NETWORK"));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TurnUpdated` AFTER UPDATE ON `Turn`
FOR EACH ROW BEGIN
  IF ((NEW.`Enabled`!=OLD.`Enabled`) OR (NEW.`Status`!=OLD.`Status`)) THEN
    UPDATE `LocalStatus` SET `CheckTurn` = TRUE;
  END IF;
  IF ((NEW.`Enabled`!=OLD.`Enabled`) OR (NEW.`IP`!=OLD.`IP`) OR (NEW.`URL`!=OLD.`URL`) OR (NEW.`User`!=OLD.`User`) OR (NEW.`Password`!=OLD.`Password`) OR (NEW.`Name`!=OLD.`Name`) OR (NEW.`ShopId`!=OLD.`ShopId`)) THEN
    SET @trx := (SELECT trx_new("TURN_RELOAD", "NETWORK"));
    SET @ret := (SELECT trx_send(@trx));
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TurnDeleted` AFTER DELETE ON `Turn`
FOR EACH ROW BEGIN
  UPDATE `LocalStatus` SET `CheckTurn` = TRUE;
  SET @trx := (SELECT trx_new("TURN_RELOAD", "NETWORK"));
  SET @ret := (SELECT trx_send(@trx));
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `bTurnsInsert` BEFORE INSERT ON `Turns`
FOR EACH ROW BEGIN
  SET NEW.`ServeDatetime`=NOW();
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TurnsInsert` AFTER INSERT ON `Turns`
FOR EACH ROW BEGIN
  UPDATE `Counters` SET `TurnsPending`=(SELECT COUNT(`Turns`.`Id`) FROM `Turns` WHERE (`Turns`.`Counter`=NEW.`Counter`) AND DATE(`Turns`.`ServeDatetime`)=CURDATE() AND (`Turns`.`Status`=0))
    WHERE (`Counters`.`Code`=NEW.`Counter`) OR (`Counters`.`MyGroup`=NEW.`Counter`);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TurnsUpdate` AFTER UPDATE ON `Turns`
FOR EACH ROW BEGIN
  UPDATE `Counters` SET `TurnsPending`=(SELECT COUNT(`Turns`.`Id`) FROM `Turns` WHERE (`Turns`.`Counter`=NEW.`Counter`) AND DATE(`Turns`.`ServeDatetime`)=CURDATE() AND (`Turns`.`Status`=0))
    WHERE (`Counters`.`Code`=NEW.`Counter`) OR (`Counters`.`MyGroup`=NEW.`Counter`);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `TurnsDelete` AFTER DELETE ON `Turns`
FOR EACH ROW BEGIN
  UPDATE `Counters` SET `TurnsPending`=0 WHERE (`Code`=OLD.`Counter`) OR (`Counters`.`MyGroup`=OLD.`Counter`);
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertVendorKey` AFTER INSERT ON `VendorKeys`
FOR EACH ROW BEGIN
  SET @disable_localregister = 1;
  REPLACE INTO `LocalVendorKeys` (`Counter`, `VendorKey`, `Vendor`) VALUES( NEW.`Counter`, NEW.`VendorKey`, NEW.`Vendor`);
  IF @disable_netregister IS NULL THEN
    INSERT INTO `VendorRegister` (`Vendor`,`RegisterDateTime`) VALUES (NEW.`Vendor`,NOW());
  END IF;
  SET @disable_localregister = NULL;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteVendorKey` AFTER DELETE ON `VendorKeys`
FOR EACH ROW BEGIN
  DELETE FROM `LocalVendorKeys` WHERE `Vendor`=OLD.`Vendor`;
  UPDATE `VendorRegister` SET `ReleaseDateTime`=NOW() WHERE `Vendor`=OLD.`Vendor` AND `ReleaseDateTime`<='1970-01-01 00:00:00';
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `InsertVendor` AFTER INSERT ON `Vendors`
FOR EACH ROW BEGIN
  IF (SELECT `Counter` FROM `VendorKeys` WHERE `VendorKeys`.`Vendor`=NEW.`Code`AND `VendorKeys`.`Counter`=GLOBAL_GET("current_counter")) IS NOT NULL THEN
	REPLACE INTO `LocalVendorChanges` VALUES (NEW.`Code`*10, NEW.`Code`,'0');
  END IF;
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `UpdateVendor` AFTER UPDATE ON `Vendors`
FOR EACH ROW BEGIN
  IF (OLD.`Code`!=NEW.`Code`) THEN
      REPLACE INTO `LocalVendorChanges` VALUES ((OLD.`Code`*10)+1, OLD.`Code`,'1');
  END IF;
  REPLACE INTO `LocalVendorChanges` VALUES (NEW.`Code`*10, NEW.`Code`,'0');
END */;;
DELIMITER ;
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`pcscale`@`%`*/ /*!50003 TRIGGER `DeleteVendor` AFTER DELETE ON `Vendors`
FOR EACH ROW BEGIN
  IF (SELECT `Counter` FROM `VendorKeys` WHERE `VendorKeys`.`Vendor`=OLD.`Code`AND `VendorKeys`.`Counter`=GLOBAL_GET("current_counter")) IS NOT NULL THEN
    REPLACE INTO `LocalVendorChanges` VALUES ((OLD.`Code`*10)+1, OLD.`Code`,'1');
  END IF;
END */;;
DELIMITER ;

--
-- Dumping routines for database 'pcscale'
--
/*!50003 DROP FUNCTION IF EXISTS `gs1_checkdigit` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` FUNCTION `gs1_checkdigit`(base VARCHAR(17)) RETURNS char(1) CHARSET utf8
    DETERMINISTIC
BEGIN
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    DECLARE odds INTEGER DEFAULT 0;     
    DECLARE evens INTEGER DEFAULT 0;    
    DECLARE total INTEGER DEFAULT 0;    
    DECLARE len INTEGER;                
    DECLARE pos INTEGER DEFAULT 0;      
    DECLARE digit INTEGER;              
    DECLARE cd INTEGER;                 
    
    
    SET len = LENGTH(base);
    mainloop: LOOP
        
        
        SET digit = CAST(SUBSTRING(base, len-pos, 1) AS SIGNED INTEGER);
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        
        IF (pos % 2 = 0)
        THEN
            SET evens = evens + digit;
        ELSE
            SET odds = odds + digit;
        END IF;
        
        
        SET pos = pos + 1;
        IF (pos < LEN)
        THEN
            ITERATE mainloop;
        END IF;
        LEAVE mainloop;
    END LOOP mainloop;
    
    
    SET total = odds + (3 * evens);
    SET cd = total % 10;
    IF (cd <> 0)
    THEN
        SET cd = 10 - cd;
    END IF;
    
    RETURN (CAST(cd AS CHAR));
END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `pcs_net` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` FUNCTION `pcs_net`(gross DECIMAL(10,2), discount DECIMAL(4,2), points DECIMAL(10,2)) RETURNS decimal(10,2)
    DETERMINISTIC
BEGIN
  DECLARE net DECIMAL(10,2);

  SET @amount_round := IFNULL(GLOBAL_GET("amount_round"), 0);
  SET @frac_digits := IFNULL(GLOBAL_GET("frac_digits"), 2);
  SET net=gross - ROUND((gross*discount)/100, @frac_digits) - points;
  IF(@amount_round=5) THEN
    SET net=(ROUND(net/5, @frac_digits) * 5);
  END IF;

  RETURN net;

END ;;
DELIMITER ;
/*!50003 DROP FUNCTION IF EXISTS `pcs_total_to_pay` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` FUNCTION `pcs_total_to_pay`(id_ticket INTEGER, src_db TINYTEXT) RETURNS decimal(10,2)
    DETERMINISTIC
BEGIN
  DECLARE total DECIMAL(10,2);
  DECLARE without_taxes BOOLEAN DEFAULT FALSE;	
  SET without_taxes = (SELECT (IFNULL((SELECT `ParamValue` FROM `CfgSystem` WHERE `ParamKey`='prices-without-taxes'), 0)=1));
  IF(without_taxes=0) THEN
    IF(src_db='HTickets') THEN
      SET total = (SELECT `NetAmount` FROM `HTickets` WHERE `Id`=id_ticket);
    ELSE  
      SET total = (SELECT `NetAmount` FROM `LocalHTickets` WHERE `Id`=id_ticket);
    END IF;

  ELSE
    IF(src_db='HTickets') THEN
      SET total = (SELECT SUM(V_VAT.Amount) + SUM(CAST(((V_VAT.Amount*Percentage)/100) AS DECIMAL(10,2))) FROM
        (SELECT lt.`VATPercent`+'0' AS Percentage, CAST((SUM(lt.`Amount`)*(ht.`NetAmount`/ht.`GrossAmount`)) AS DECIMAL(10,2)) AS Amount
         FROM `HTickets` AS ht
         LEFT JOIN `LTickets` AS lt ON ht.`Id`=lt.`IdHTicket`
         WHERE ht.`Id`=id_ticket AND `lineType`=1 GROUP BY lt.`VATCode`) AS V_VAT);
    ELSE  
      SET total = (SELECT SUM(V_VAT.Amount) + SUM(CAST(((V_VAT.Amount*Percentage)/100) AS DECIMAL(10,2))) FROM
        (SELECT lt.`VATPercent`+'0' AS Percentage, CAST((SUM(lt.`Amount`)*(ht.`NetAmount`/ht.`GrossAmount`)) AS DECIMAL(10,2)) AS Amount
         FROM `LocalHTickets` AS ht
         LEFT JOIN `LocalLTickets` AS lt ON ht.`Id`=lt.`IdHTicket`
         WHERE ht.`Id`=id_ticket AND `lineType`=1 GROUP BY lt.`VATCode`) AS V_VAT);
    END IF;
  END IF;

  RETURN total;

END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `DataloggerFiscalChange` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` PROCEDURE `DataloggerFiscalChange`(OldName VARCHAR(32), NewName VARCHAR(32), OldEnabled BOOLEAN, NewEnabled BOOLEAN )
BEGIN
  DECLARE msg VARCHAR(255) DEFAULT '';
  IF ((NewName!=OldName) OR (NewEnabled!=OldEnabled)) THEN
    SELECT (SELECT COUNT(*) FROM information_schema.global_status WHERE variable_name='SLAVE_RUNNING' AND VARIABLE_VALUE='ON'), (SELECT COUNT(*) FROM information_schema.processlist WHERE INFO='SELECT trx_get()') INTO @_slave_,@_app_running_;
    IF (@_slave_ = 0) THEN
      IF (NewName = OldName) THEN
        SET msg := CONCAT('Fiscal module ', NewName, IF(NewEnabled, ' enabled', ' disabled'));
      ELSEIF (NewName = '') THEN
        SET msg := CONCAT('Fiscal module ', OldName, ' dropped.');
      ELSEIF (OldName = '') THEN
        SET msg := CONCAT('Fiscal module ', NewName, ' raised. ',IF(NewEnabled, 'Enabled', 'Disabled'));
      ELSE
        SET msg := CONCAT('Fiscal module ', OldName, ' changed to ', NewName, IF(NewEnabled, '. Enabled', '. Disabled'));
      END IF;
    END IF;
    IF (@_app_running_ = 0) THEN
      INSERT INTO `LocalDataLogger` SET Type=134, DatTim=NOW(), Message=msg;
    ELSE
      SET @trx := (SELECT trx_new("FISCAL_RELOAD", "NETWORK"));
      SET @ret := (SELECT trx_set_param(@trx, "LOG", msg));
      SET @ret := (SELECT trx_send(@trx));
    END IF;
  END IF;
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `dbTrigger` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` PROCEDURE `dbTrigger`(IN `tbname` VARCHAR (40), `function` VARCHAR (10), `masterkey` VARCHAR (40))
BEGIN
    SET @trx := (SELECT trx_new("DBTRIGGER", "CORE"));
    SET @ret := (SELECT trx_set_param(@trx, "TABLE", `tbname`));
    SET @ret := (SELECT trx_set_param(@trx, "FUNCTION", `function`));
    SET @ret := (SELECT trx_set_param(@trx, "KEY", `masterkey`));
    SET @ret := (SELECT trx_send(@trx));
END ;;
DELIMITER ;
/*!50003 DROP PROCEDURE IF EXISTS `LocalTreeBoardFromPLUKeysFile` */;
DELIMITER ;;
CREATE DEFINER=`pcscale`@`%` PROCEDURE `LocalTreeBoardFromPLUKeysFile`()
BEGIN


  DELETE FROM `LocalTreeBoard`;
  SET @rownumber:=100000;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`,`Source2`,`Source3`,`Source4`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1`, puk.`Source2`, puk.`Source3`, puk.`Source4` FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`!=0  AND puk.`Source4`!=0 AND puk.`Source5`!=0) AS VT;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`,`Source2`,`Source3`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1`, puk.`Source2`, puk.`Source3` FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`!=0  AND puk.`Source4`!=0 AND puk.`Source5`=0) AS VT;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`,`Source2`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1`, puk.`Source2` AS kl FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`!=0  AND puk.`Source4`=0 AND puk.`Source5`=0) AS VT;

  INSERT INTO `LocalTreeBoard` (`Board`,`Source1`)
	SELECT @rownumber:=(@rownumber+1), VT.* FROM
    (SELECT DISTINCT puk.`Source1` FROM `PLUKeysFile` AS puk
    LEFT JOIN `Items` USING (`PLU`)
    WHERE (`Items`.`Code` IS NOT NULL AND `Items`.`OnKey`=TRUE) AND puk.`PLU`!=0 AND puk.`Source2`!=0 AND puk.`Source3`=0  AND puk.`Source4`=0 AND puk.`Source5`=0) AS VT;

  SET @rownumber:=0;
  UPDATE `LocalTreeBoard` SET Board=(@rownumber:=@rownumber+1) ORDER BY `Source1`,`Source2`,`Source3`,`Source4`,`Source5`;

 UPDATE `LocalTreeBoard` AS T1 LEFT JOIN
 (SELECT `Board`,
    IF(@src1!=`Source1`, @lv1:=@lv1+1, @lv1) AS lv1,
    IF(@src1!=`Source1`, IF(`Source2`!=0, @lv2:=1, @lv2:=0), IF(@src2!=`Source2`, @lv2:=@lv2+1, @lv2)) AS lv2,
    IF(@src1!=`Source1` OR @src2!=`Source2`, IF(`Source3`!=0, @lv3:=1, @lv3:=0), IF(@src3!=`Source3`, @lv3:=@lv3+1, @lv3)) AS lv3,
    IF(@src1!=`Source1` OR @src2!=`Source2` OR @src3!=`Source3`, IF(`Source4`!=0, @lv4:=1, @lv4:=0), IF(@src4!=`Source4`, @lv4:=@lv4+1, @lv4)) AS lv4,
    IF(@src1!=`Source1` OR @src2!=`Source2` OR @src3!=`Source3` OR @src4!=`Source4`, IF(`Source5`!=0, @lv5:=1, @lv5:=0), IF(@src5!=`Source5`, @lv5:=@lv5+1, @lv5)) AS lv5,
    @src1:=`Source1`, @src2:=`Source2`, @src3:=`Source3`, @src4:=`Source4`, @src5:=`Source5`
	FROM `LocalTreeBoard`, (SELECT @src1:=0, @lv1:=0, @src2:=0, @lv2:=0, @src3:=0, @lv3:=0, @src4:=0, @lv4:=0, @src5:=0, @lv5:=0) AS TT
    ORDER BY `Board`) AS T2 ON T1.`Board`=T2.`Board`
 SET T1.`Level1`=T2.lv1, T1.`Level2`=T2.lv2, T1.`Level3`=T2.lv3, T1.`Level4`=T2.lv4, T1.`Level5`=T2.lv5;
END ;;
DELIMITER ;


