diff --git a/classes/Customer.php b/classes/Customer.php index 752fd9605..7c4937eca 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -147,6 +147,7 @@ class CustomerCore extends ObjectModel 'fields' => array( 'id_default_group' => array('xlink_resource' => 'groups'), 'id_lang' => array('xlink_resource' => 'languages'), + 'id_country' => array('xlink_resource' => 'countries'), 'newsletter_date_add' => array(), 'ip_registration_newsletter' => array(), 'last_passwd_gen' => array('setter' => null), diff --git a/classes/Product.php b/classes/Product.php index 573ab13d9..4f280c742 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -427,6 +427,7 @@ class ProductCore extends ObjectModel // ) // ), 'id_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')), + 'id_tourism_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')), 'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => 'setWsPositionInCategory'), // 'manufacturer_name' => array( // 'getter' => 'getWsManufacturerName', @@ -523,6 +524,7 @@ class ProductCore extends ObjectModel ) ), 'id_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')), + 'id_tourism_tax_rules_group' => array('xlink_resource' => array('resourceName' => 'tax_rule_groups')), 'position_in_category' => array('getter' => 'getWsPositionInCategory', 'setter' => 'setWsPositionInCategory'), // 'manufacturer_name' => array( // 'getter' => 'getWsManufacturerName', diff --git a/classes/RoomTypeSellingObject.php b/classes/RoomTypeSellingObject.php index 61b98b6be..3d93ccc6b 100644 --- a/classes/RoomTypeSellingObject.php +++ b/classes/RoomTypeSellingObject.php @@ -37,11 +37,65 @@ class RoomTypeSellingObjectCore extends ObjectModel 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), - 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), - 'plural_name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), + 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), + 'plural_name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), ), ); + protected $webserviceParameters = array( + 'objectsNodeName' => 'room_type_selling_objects', + 'objectNodeName' => 'room_type_selling_object', + 'objectMethods' => array('update' => 'updateWs', 'delete' => 'deleteWs'), + 'fields' => array( + 'name' => array('required' => true), + 'plural_name' => array('required' => true), + 'active' => array('required' => false), + ), + ); + + /** + * Webservice: update, refusing to disable a selling object that is in use. + * + * @param bool $nullValues + * + * @return bool + * + * @throws WebserviceException + */ + public function updateWs($nullValues = false) + { + if (!$this->active && $this->id) { + $objOld = new RoomTypeSellingObject((int) $this->id); + if (Validate::isLoadedObject($objOld) && $objOld->active && $objOld->isUsed()) { + throw new WebserviceException( + Tools::displayError('You cannot disable this selling object because it is currently assigned.'), + array(400, 400) + ); + } + } + + return $this->update($nullValues); + } + + /** + * Webservice: delete, refusing to delete a selling object that is in use. + * + * @return bool + * + * @throws WebserviceException + */ + public function deleteWs() + { + if ($this->isUsed()) { + throw new WebserviceException( + Tools::displayError('You cannot delete this selling object because it is currently assigned.'), + array(400, 400) + ); + } + + return $this->delete(); + } + public function isUsed() { return (bool) Db::getInstance()->getValue( diff --git a/classes/tax/TaxConfiguration.php b/classes/tax/TaxConfiguration.php index 141761ee9..24e0fd68c 100644 --- a/classes/tax/TaxConfiguration.php +++ b/classes/tax/TaxConfiguration.php @@ -40,6 +40,9 @@ class TaxConfigurationCore extends ObjectModel public $has_multiple_valid_ranges; public $special_days; + /** @var string Tax name, webservice only (stored in tax_lang) */ + public $name; + public static $definition = array( 'table' => 'tax_configuration', 'primary' => 'id_tax', @@ -57,6 +60,145 @@ class TaxConfigurationCore extends ObjectModel ), ); + protected $webserviceParameters = array( + 'objectsNodeName' => 'tourism_taxes', + 'objectNodeName' => 'tourism_tax', + 'objectMethods' => array( + 'add' => 'addWs', + 'update' => 'updateWs', + 'delete' => 'deleteWs', + ), + 'fields' => array( + 'name' => array('i18n' => false, 'getter' => 'getWsName'), + ), + 'associations' => array( + 'price_tiers' => array( + 'resource' => 'price_tier', + 'fields' => array('min_amount' => array(), 'max_amount' => array(), 'tax_value' => array()), + ), + 'child_ranges' => array( + 'resource' => 'child_range', + 'fields' => array('min_age' => array(), 'max_age' => array(), 'tax_value' => array()), + ), + 'validity_ranges' => array( + 'resource' => 'validity_range', + 'fields' => array('valid_from' => array(), 'valid_to' => array()), + ), + ), + ); + + /** + * Webservice: add a tourism tax. The tax row is created first, the configuration reuses its id. + * + * @return bool + * @throws WebserviceException + */ + public function addWs() + { + $tax = new Tax(); + $tax->is_tourism_tax = 1; + $tax->rate = 0; + $tax->active = 1; + foreach (Language::getIDs(false) as $idLang) { + $tax->name[$idLang] = (string) $this->name; + } + if (($error = $tax->validateFieldsLang(false, true)) !== true) { + throw new WebserviceException(sprintf(Tools::displayError('Validation error: "%s"'), $error), array(400, 400)); + } + if (!$tax->add()) { + return false; + } + $this->id = (int) $tax->id; + + return $this->add(); + } + + /** + * Webservice: update the configuration. Like in the admin, Tax::update() historizes a tax already used in + * orders; the tax then gets a new id, so the configuration and its ranges move to it. + * + * @param bool $nullValues + * @return bool + */ + public function updateWs($nullValues = false) + { + $idOldTax = (int) $this->id; + $tax = new Tax($idOldTax); + if (!$tax->update()) { + return false; + } + if ((int) $tax->id === $idOldTax) { + return $this->update($nullValues); + } + + $this->id = (int) $tax->id; + $tiers = TaxPriceTier::getByTaxId($idOldTax); + TaxPriceTier::saveAll($this->id, array_column($tiers, 'min_amount'), array_column($tiers, 'max_amount'), array_column($tiers, 'tax_value')); + $childRanges = TaxChildRange::getByTaxId($idOldTax); + TaxChildRange::saveAll($this->id, array_column($childRanges, 'min_age'), array_column($childRanges, 'max_age'), array_column($childRanges, 'tax_value')); + $validityRanges = TaxValidityRange::getByTaxId($idOldTax); + TaxValidityRange::saveAll($this->id, array_column($validityRanges, 'valid_from'), array_column($validityRanges, 'valid_to')); + + return $this->add(); + } + + /** + * Webservice: delete the tax. Tax::delete() only historizes a tax used in orders, so keep its configuration then. + * + * @return bool + */ + public function deleteWs() + { + $tax = new Tax((int) $this->id); + $isUsed = $tax->isUsed(); + + return $tax->delete() && ($isUsed || $this->delete()); + } + + /** + * @return string tax name in the default language + */ + public function getWsName() + { + return (new Tax((int) $this->id, (int) Configuration::get('PS_LANG_DEFAULT')))->name; + } + + public function getWsPriceTiers() + { + return TaxPriceTier::getByTaxId((int) $this->id); + } + + public function setWsPriceTiers($rows) + { + TaxPriceTier::saveAll((int) $this->id, array_column($rows, 'min_amount'), array_column($rows, 'max_amount'), array_column($rows, 'tax_value')); + + return true; + } + + public function getWsChildRanges() + { + return TaxChildRange::getByTaxId((int) $this->id); + } + + public function setWsChildRanges($rows) + { + TaxChildRange::saveAll((int) $this->id, array_column($rows, 'min_age'), array_column($rows, 'max_age'), array_column($rows, 'tax_value')); + + return true; + } + + public function getWsValidityRanges() + { + return TaxValidityRange::getByTaxId((int) $this->id); + } + + public function setWsValidityRanges($rows) + { + TaxValidityRange::saveAll((int) $this->id, array_column($rows, 'valid_from'), array_column($rows, 'valid_to')); + + return true; + } + /** * Override add() because id_tax is a FK-as-PK — the base ObjectModel::add() never writes the primary key column, which would default to 0 and create phantom rows. * diff --git a/classes/webservice/WebserviceRequest.php b/classes/webservice/WebserviceRequest.php index ff62a66e5..b5f51e991 100644 --- a/classes/webservice/WebserviceRequest.php +++ b/classes/webservice/WebserviceRequest.php @@ -267,6 +267,7 @@ class WebserviceRequestCore 'contacts' => array('description' => 'Shop contacts','class' => 'Contact'), 'countries' => array('description' => 'The countries','class' => 'Country'), 'currencies' => array('description' => 'The currencies', 'class' => 'Currency'), + 'room_type_selling_objects' => array('description' => 'The room type selling objects', 'class' => 'RoomTypeSellingObject'), 'customers' => array('description' => 'The e-shop\'s customers','class' => 'Customer'), 'customer_threads' => array('description' => 'Customer services threads','class' => 'CustomerThread'), 'customer_messages' => array('description' => 'Customer services messages','class' => 'CustomerMessage'), @@ -306,6 +307,7 @@ class WebserviceRequestCore 'shops' => array('description' => 'Shops from multi-shop feature', 'class' => 'Shop'), 'shop_groups' => array('description' => 'Shop groups from multi-shop feature', 'class' => 'ShopGroup'), 'taxes' => array('description' => 'The tax rate', 'class' => 'Tax'), + 'tourism_taxes' => array('description' => 'The tourism taxes with their configuration, price tiers, child ranges and validity ranges', 'class' => 'TaxConfiguration'), 'stock_movements' => array('description' => 'Stock movements', 'class' => 'StockMvtWS', 'forbidden_method' => array('PUT', 'POST', 'DELETE')), 'stock_movement_reasons' => array('description' => 'Stock movement reason', 'class' => 'StockMvtReason'), 'warehouses' => array('description' => 'Warehouses', 'class' => 'Warehouse', 'forbidden_method' => array('DELETE')), diff --git a/modules/hotelreservationsystem/classes/HotelBranchInformation.php b/modules/hotelreservationsystem/classes/HotelBranchInformation.php index c32f4679c..5d33d64a9 100644 --- a/modules/hotelreservationsystem/classes/HotelBranchInformation.php +++ b/modules/hotelreservationsystem/classes/HotelBranchInformation.php @@ -106,6 +106,10 @@ class HotelBranchInformation extends ObjectModel 'required' => true, 'xlink_resource'=> 'countries', ), + 'id_property_type' => array( + 'required' => true, + 'xlink_resource'=> 'hotel_property_types', + ), 'id_state' => array( 'xlink_resource'=> 'states', ), diff --git a/modules/hotelreservationsystem/classes/HotelPropertyType.php b/modules/hotelreservationsystem/classes/HotelPropertyType.php index cbe87d79b..14dde5724 100644 --- a/modules/hotelreservationsystem/classes/HotelPropertyType.php +++ b/modules/hotelreservationsystem/classes/HotelPropertyType.php @@ -36,10 +36,63 @@ class HotelPropertyType extends ObjectModel 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), 'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate', 'copy_post' => false), - 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true), + 'name' => array('type' => self::TYPE_STRING, 'lang' => true, 'validate' => 'isGenericName', 'required' => true, 'size' => 255), ), ); + protected $webserviceParameters = array( + 'objectsNodeName' => 'property_types', + 'objectNodeName' => 'property_type', + 'objectMethods' => array('update' => 'updateWs', 'delete' => 'deleteWs'), + 'fields' => array( + 'name' => array('required' => true), + 'active' => array('required' => false), + ), + ); + + /** + * Webservice: update, refusing to disable a property type that is in use. + * + * @param bool $nullValues + * + * @return bool + * + * @throws WebserviceException + */ + public function updateWs($nullValues = false) + { + if (!$this->active && $this->id) { + $objOld = new HotelPropertyType((int) $this->id); + if (Validate::isLoadedObject($objOld) && $objOld->active && $objOld->isUsed()) { + throw new WebserviceException( + Tools::displayError('You cannot disable this property type because it is currently assigned.'), + array(400, 400) + ); + } + } + + return $this->update($nullValues); + } + + /** + * Webservice: delete, refusing to delete a property type that is in use. + * + * @return bool + * + * @throws WebserviceException + */ + public function deleteWs() + { + if ($this->isUsed()) { + throw new WebserviceException( + Tools::displayError('You cannot delete this property type because it is currently assigned.'), + array(400, 400) + ); + } + + return $this->delete(); + } + /** * Check if this property type is currently assigned to any property. * diff --git a/modules/hotelreservationsystem/classes/HotelRoomType.php b/modules/hotelreservationsystem/classes/HotelRoomType.php index 79518b0c9..8667d8d28 100644 --- a/modules/hotelreservationsystem/classes/HotelRoomType.php +++ b/modules/hotelreservationsystem/classes/HotelRoomType.php @@ -72,6 +72,11 @@ class HotelRoomType extends ObjectModel 'resourceName' => 'hotels', ) ), + 'id_selling_object' => array( + 'xlink_resource' => array( + 'resourceName' => 'room_type_selling_objects', + ) + ), ), 'associations' => array( 'hotel_rooms' => array( diff --git a/modules/hotelreservationsystem/hotelreservationsystem.php b/modules/hotelreservationsystem/hotelreservationsystem.php index f3530c665..ad105af85 100644 --- a/modules/hotelreservationsystem/hotelreservationsystem.php +++ b/modules/hotelreservationsystem/hotelreservationsystem.php @@ -48,6 +48,7 @@ class HotelReservationSystem extends Module $resources = array( 'hotels' => array('description' => 'Hotel Branch Information','class' => 'HotelBranchInformation'), 'hotel_room_types' => array('description' => 'Hotel room types','class' => 'HotelRoomType'), + 'property_types' => array('description' => 'Hotel property types', 'class' => 'HotelPropertyType'), 'hotel_amenities' => array('description' => 'The hotel amenities', 'class' => 'HotelAmenities'), 'hotel_refund_rules' => array('description' => 'The hotel refund rules','class' => 'HotelOrderRefundRules'), 'hotel_rooms' => array('description' => 'The hotel rooms','class' => 'HotelRoomInformation'),