<?php

/**
 * @version		$Id$
 * @package		ARTIO Booking
 * @copyright		Copyright (C) 2010 ARTIO s.r.o.. All rights reserved.
 * @author 			ARTIO s.r.o., http://www.artio.net
 * @license     	GNU/GPL http://www.gnu.org/copyleft/gpl.html
 * @link        	http://www.artio.net Official website
 */
defined('_JEXEC') or die('Restricted access');

/* @var $this BookingModelUpgrade */

require_once dirname(__FILE__) . '/reinstall.php';

$db = JFactory::getDbo();

$db->setQuery('SHOW FIELDS FROM #__booking_supplement WHERE Field = ' . $db->quote('volume_discount'));
if (!$db->loadObject()) {
    $this->_addSQL('ALTER TABLE `#__booking_supplement` ADD `volume_discount` text NOT NULL');
}
$db->setQuery('SHOW FIELDS FROM #__booking_supplement WHERE Field = ' . $db->quote('volume_type'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_supplement` ADD `volume_type` tinyint(1) NOT NULL DEFAULT '0'");
}

$db->setQuery('SHOW FIELDS FROM #__booking_reservation_supplement WHERE Field = ' . $db->quote('discount'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_reservation_supplement` ADD `discount` float NOT NULL DEFAULT '0'");
}

$db->setQuery('SHOW FIELDS FROM #__booking_price WHERE Field = ' . $db->quote('discount_include_supplements'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_price` ADD `discount_include_supplements` tinyint(1) NOT NULL DEFAULT '0'");
}
$db->setQuery('SHOW FIELDS FROM #__booking_price WHERE Field = ' . $db->quote('volume_type'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_price` ADD `volume_type` tinyint(1) NOT NULL DEFAULT '0'");
}

$db->setQuery('SHOW FIELDS FROM #__booking_reservation_items WHERE Field = ' . $db->quote('fullDiscount'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_reservation_items` ADD `fullDiscount` float NOT NULL DEFAULT '0'");
}
$db->setQuery('SHOW FIELDS FROM #__booking_reservation_items WHERE Field = ' . $db->quote('discount'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_reservation_items` ADD `discount` float NOT NULL DEFAULT '0'");
}

$db->setQuery('SHOW FIELDS FROM #__booking_price WHERE Field = ' . $db->quote('self_pickup_deposit'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_price` ADD `self_pickup_deposit` float NOT NULL DEFAULT '0'");
}
$db->setQuery('SHOW FIELDS FROM #__booking_price WHERE Field = ' . $db->quote('self_pickup_deposit_type'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_price` ADD `self_pickup_deposit_type` tinyint(1) NOT NULL DEFAULT '0'");
}

$db->setQuery('SHOW FIELDS FROM #__booking_reservation_items WHERE Field = ' . $db->quote('postage'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_reservation_items` ADD `postage` float NOT NULL DEFAULT '0'");
}
$db->setQuery('SHOW FIELDS FROM #__booking_reservation_items WHERE Field = ' . $db->quote('shipping'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_reservation_items` ADD `shipping` tinyint(1) NOT NULL DEFAULT '0'");
}
$db->setQuery('SHOW FIELDS FROM #__booking_reservation_items WHERE Field = ' . $db->quote('takeback'));
if (!$db->loadObject()) {
    $this->_addSQL("ALTER TABLE `#__booking_reservation_items` ADD `takeback` tinyint(1) NOT NULL DEFAULT '0'");
}
