--
-- Host: localhost    Database: josm_web
-- ------------------------------------------------------


--
-- Table structure for table `objlistaJosm`
--

CREATE TABLE `objlistaJosm` (
  `ObjListaNr` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `ObjektNr` int(10) unsigned NOT NULL,
  `ListNr` int(10) unsigned NOT NULL DEFAULT '0',
  `AuktionsTyp` char(60) DEFAULT NULL,
  `Lagerort` char(60) DEFAULT NULL,
  `Fabrikat` char(30) DEFAULT NULL,
  `Modell` char(75) DEFAULT NULL,
  `Arsmodell` int(11) DEFAULT NULL,
  `Reservationspris` int(11) DEFAULT NULL,
  `WebBud` char(5) NOT NULL DEFAULT '0',
  `Marknadspris` int(11) DEFAULT NULL,
  `Status` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `HogstaBudBelopp` int(11) DEFAULT NULL,
  `HogstaBudAlias` char(30) DEFAULT NULL,
  `Budnr` int(11) DEFAULT NULL,
  `Handlaggare` char(5) DEFAULT NULL,
  `LagstaPris` int(11) DEFAULT NULL,
  `HogstaPris` int(11) DEFAULT NULL,
  `LagstaHojning` int(11) DEFAULT NULL,
  `Visas` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `SlagAvgift` int(11) DEFAULT NULL,
  `SlagAvgiftHandlare` int(11) DEFAULT NULL,
  `SlagAvgiftMoms` char(20) DEFAULT NULL,
  `MomsBudgivning` varchar(95) DEFAULT NULL,
  `UppdatKastor` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `UppdatKastorVad` char(80) DEFAULT NULL,
  `MomsText` varchar(95) DEFAULT NULL,
  `AuktionStanger` datetime DEFAULT NULL,
  `AuktionForlangSek` int(10) unsigned DEFAULT NULL,
  `AuktionNedrakning` datetime DEFAULT NULL,
  `HogstaBudTid` datetime DEFAULT NULL,
  `AuktionStangdTid` datetime DEFAULT NULL,
  `SlagavgiftText` varchar(255) DEFAULT NULL,
  `Export` varchar(45) DEFAULT NULL,
  `Losenord` varchar(45) DEFAULT NULL,
  `LosenordKrav` tinyint(3) unsigned NOT NULL DEFAULT '0',
  `Grupp` varchar(8) DEFAULT NULL,
  `TimeStamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `Ikon` smallint(5) unsigned NOT NULL DEFAULT '0',
  `Villkor` varchar(90) DEFAULT NULL,
  `Valuta` varchar(45) DEFAULT NULL,
  `ObjektUrl` varchar(255) DEFAULT NULL,
  `ListBenamning` varchar(90) DEFAULT NULL,
  `VisaObjektJOSM` int(10) unsigned NOT NULL DEFAULT '0',
  `VisaObjektExport` int(10) unsigned NOT NULL DEFAULT '0',
  `VisaObjektNorge` int(10) unsigned NOT NULL DEFAULT '0',
  `VisaObjektJOSMPro` int(10) NOT NULL DEFAULT '0',
  `ArendeTyp` varchar(45) DEFAULT NULL,
  `Finansiering` tinyint(3) unsigned NOT NULL DEFAULT '0' COMMENT 'Erbjud ej finansiering när värde = 0. (False)',
  `Mall` smallint(5) unsigned DEFAULT NULL,
  `BildObjektNr` int(10) unsigned DEFAULT NULL,
  `AvtalspartNamn` varchar(95) DEFAULT NULL,
  `Dragkrok` varchar(255) DEFAULT NULL,
  `Objektstyp` varchar(255) DEFAULT NULL,
  `Vaxellada` varchar(255) DEFAULT NULL,
  `Matarstallning` varchar(255) DEFAULT NULL,
  `importerad` tinyint(1) NOT NULL DEFAULT '0',
  `MatarstallningEnhet` varchar(45) DEFAULT NULL,
  `Drivmedel` varchar(45) DEFAULT NULL,
  `VLAkod` varchar(15) DEFAULT NULL,
  `AlternativtDrivmedel` varchar(45) DEFAULT NULL,
  `AccepterarAutobud` tinyint(1) unsigned NOT NULL DEFAULT '0',
  `business_system_id` int(10) unsigned NOT NULL DEFAULT '1',
  `countdown_override` varchar(45) DEFAULT NULL,
  `marketPrice_To` int(10) NOT NULL DEFAULT '0',
  `marketPrice_From` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`ObjListaNr`),
  UNIQUE KEY `unique_ObjektNr` (`ObjektNr`),
  KEY `FabrikatModell` (`Fabrikat`,`Modell`),
  KEY `Reservationspris` (`Reservationspris`),
  KEY `Lagerort` (`Lagerort`),
  KEY `Marknadspris` (`Marknadspris`),
  KEY `Nedrakning` (`AuktionNedrakning`),
  KEY `AuktionStanger` (`AuktionStanger`),
  KEY `ListaSok` (`ListNr`,`Visas`,`Status`,`AuktionNedrakning`,`Grupp`) USING BTREE,
  KEY `Fabrikat` (`Fabrikat`),
  KEY `Modell` (`Modell`),
  KEY `Visas` (`Visas`),
  KEY `Grupp` (`Grupp`),
  KEY `Status` (`Status`),
  KEY `AuktionStangdTid` (`AuktionStangdTid`),
  KEY `ListNr` (`ListNr`),
  KEY `TimeStamp` (`TimeStamp`),
  KEY `HogstaBudAlias` (`HogstaBudAlias`),
  KEY `business_system_id` (`business_system_id`),
  KEY `Avslutade` (`Status`,`importerad`,`UppdatKastor`,`business_system_id`)
) ENGINE=InnoDB AUTO_INCREMENT=240018 DEFAULT CHARSET=latin1 ROW_FORMAT=COMPRESSED;

--
-- Dumping data for table `objlistaJosm`
--

INSERT INTO `objlistaJosm` VALUES (240017,708877,0,'Personbilar V.6','Sundsvall','BMW','Drive20d (Aut+GPS+190hk)',2015,355000,'1',401600,0,NULL,NULL,NULL,NULL,NULL,NULL,500,0,NULL,NULL,NULL,NULL,0,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'Ja',NULL,0,NULL,'2016-02-02 15:26:27',0,'','SEK','/objekt/nr/7433/Drive20d_(Aut+GPS+190hk).html','BMW (Aut+GPS+190hk)',1,1,0,0,'Personbil',1,1,808977,'foobar AB','Ja','Personbil','Automat','1305',0,'mil','Diesel','7.1','',1,1,NULL,365456,285136);
DELIMITER ;;
/*!50003 CREATE*/ /*!50017 DEFINER=`root`@`%`*/ /*!50003 TRIGGER `afterUpdateOnObjlistaJosm` AFTER UPDATE ON `objlistaJosm` FOR EACH ROW BEGIN



IF IFNULL(NEW.Budnr,0) != IFNULL(OLD.Budnr,0) THEN UPDATE JosmWeb.Auction t1 JOIN JosmWeb.AuctionHasAuctionItems t2 ON t1.id = t2.auctionId SET t1.bidId = IFNULL(NEW.Budnr,0) WHERE t2.auctionItemId = OLD.Objektnr;


END IF;

IF IFNULL(NEW.HogstaBudBelopp,0) != IFNULL(OLD.HogstaBudBelopp,0) THEN UPDATE JosmWeb.Auction t1 JOIN JosmWeb.AuctionHasAuctionItems t2 ON t1.id = t2.auctionId SET t1.bid = IFNULL(NEW.HogstaBudBelopp,0) WHERE t2.auctionItemId = OLD.Objektnr;
END IF;

IF IFNULL(NEW.HogstaBudTid,'0000-00-00 00:00:00') != IFNULL(OLD.HogstaBudTid,'0000-00-00 00:00:00') 
  THEN UPDATE JosmWeb.Auction t1 
  JOIN JosmWeb.AuctionHasAuctionItems t2 
    ON t1.id = t2.auctionId 
  SET t1.bidTime = IFNULL(NEW.HogstaBudTid,'0000-00-00 00:00:00') 
  WHERE t2.auctionItemId = OLD.Objektnr;
END IF;

IF IFNULL(NEW.AuktionStangdTid,'0000-00-00 00:00:00') != IFNULL(OLD.AuktionStangdTid,'0000-00-00 00:00:00') 
   THEN UPDATE JosmWeb.Auction t1 
   JOIN JosmWeb.AuctionHasAuctionItems t2 
     ON t1.id = t2.auctionId 
   SET t1.auctionEnded = IFNULL(NEW.AuktionStangdTid,'0000-00-00 00:00:00'), t1.status = 2 
   WHERE t2.auctionItemId = OLD.Objektnr;
END IF;

IF IFNULL(NEW.`status`,'0') != IFNULL(OLD.`status`,'0') THEN UPDATE JosmWeb.Auction t1 JOIN JosmWeb.AuctionHasAuctionItems t2 ON t1.id = t2.auctionId SET t1.`status` = NEW.status WHERE t2.auctionItemId = OLD.Objektnr;
END IF;


IF IFNULL(NEW.visas,'0') != IFNULL(OLD.visas,'0') THEN UPDATE JosmWeb.Auction t1 JOIN JosmWeb.AuctionHasAuctionItems t2 ON t1.id = t2.auctionId SET t1.`status` = IF(IFNULL(NEW.visas,'0') = 0,0,NEW.`status`) WHERE t2.auctionItemId = OLD.Objektnr;
END IF;


END */;;
DELIMITER ;


