From 4eb9edf698630d16b4d8a30b2ef06149497c9727 Mon Sep 17 00:00:00 2001 From: jBreux Date: Thu, 22 Dec 2011 15:30:21 +0000 Subject: [PATCH] [+] Project : B2B Features --- .../template/outstanding/_print_pdf_icon.tpl | 30 ++ cache/class_index.php | 8 +- classes/Customer.php | 53 ++++ classes/FrontController.php | 1 + classes/Product.php | 8 + classes/Risk.php | 81 +++++ classes/Tab.php | 70 +++++ classes/Validate.php | 31 ++ classes/pdf/HTMLTemplateInvoice.php | 8 +- .../admin/AdminCustomersController.php | 87 ++++++ controllers/admin/AdminInvoicesController.php | 24 ++ .../admin/AdminOutstandingController.php | 175 +++++++++++ .../admin/AdminPreferencesController.php | 28 ++ install-dev/sql/db.sql | 23 ++ install-dev/sql/db_settings_lite.sql | 51 ++- install-dev/sql/upgrade/1.5.0.2.sql | 11 +- themes/default/authentication.tpl | 21 ++ themes/default/pdf/invoice-b2b.tpl | 293 ++++++++++++++++++ 18 files changed, 984 insertions(+), 19 deletions(-) create mode 100644 admin-dev/themes/template/outstanding/_print_pdf_icon.tpl create mode 100644 classes/Risk.php create mode 100644 controllers/admin/AdminOutstandingController.php create mode 100755 themes/default/pdf/invoice-b2b.tpl diff --git a/admin-dev/themes/template/outstanding/_print_pdf_icon.tpl b/admin-dev/themes/template/outstanding/_print_pdf_icon.tpl new file mode 100644 index 000000000..ee6ab9593 --- /dev/null +++ b/admin-dev/themes/template/outstanding/_print_pdf_icon.tpl @@ -0,0 +1,30 @@ +{* +* 2007-2011 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 9589 $ +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +{* Generate HTML code for printing Invoice Icon with link *} + + invoice + \ No newline at end of file diff --git a/cache/class_index.php b/cache/class_index.php index 0cb7825ae..7fefd49a9 100644 --- a/cache/class_index.php +++ b/cache/class_index.php @@ -150,8 +150,6 @@ 'Notification' => 'override/classes/Notification.php', 'ObjectModelCore' => 'classes/ObjectModel.php', 'ObjectModel' => 'override/classes/ObjectModel.php', - 'PDFCore' => 'classes/pdf/PDF.php', - 'PDF' => 'override/classes/pdf/PDF.php', 'PackCore' => 'classes/Pack.php', 'Pack' => 'override/classes/Pack.php', 'PageCore' => 'classes/Page.php', @@ -182,6 +180,8 @@ 'RequestSql' => 'override/classes/RequestSql.php', 'RijndaelCore' => 'classes/Rijndael.php', 'Rijndael' => 'override/classes/Rijndael.php', + 'RiskCore' => 'classes/Risk.php', + 'Risk' => '', 'SceneCore' => 'classes/Scene.php', 'Scene' => 'override/classes/Scene.php', 'SearchCore' => 'classes/Search.php', @@ -292,6 +292,8 @@ 'HTMLTemplateOrderSlip' => 'override/classes/pdf/HTMLTemplateOrderSlip.php', 'HTMLTemplateSupplyOrderFormCore' => 'classes/pdf/HTMLTemplateSupplyOrderForm.php', 'HTMLTemplateSupplyOrderForm' => 'override/classes/pdf/HTMLTemplateSupplyOrderForm.php', + 'PDFCore' => 'classes/pdf/PDF.php', + 'PDF' => 'override/classes/pdf/PDF.php', 'PDFGeneratorCore' => 'classes/pdf/PDFGenerator.php', 'PDFGenerator' => 'override/classes/pdf/PDFGenerator.php', 'GroupShopCore' => 'classes/shop/GroupShop.php', @@ -315,6 +317,7 @@ 'StockMvt' => 'override/classes/stock/StockMvt.php', 'StockMvtReasonCore' => 'classes/stock/StockMvtReason.php', 'StockMvtReason' => 'override/classes/stock/StockMvtReason.php', + 'StockMvtWS' => 'classes/stock/StockMvtWS.php', 'SupplyOrderCore' => 'classes/stock/SupplyOrder.php', 'SupplyOrder' => 'override/classes/stock/SupplyOrder.php', 'SupplyOrderDetailCore' => 'classes/stock/SupplyOrderDetail.php', @@ -463,6 +466,7 @@ 'AdminOrderMessageController' => 'override/controllers/admin/AdminOrderMessageController.php', 'AdminOrdersControllerCore' => 'controllers/admin/AdminOrdersController.php', 'AdminOrdersController' => 'override/controllers/admin/AdminOrdersController.php', + 'AdminOutstandingController' => 'controllers/admin/AdminOutstandingController.php', 'AdminPPreferencesControllerCore' => 'controllers/admin/AdminPPreferencesController.php', 'AdminPPreferencesController' => 'override/controllers/admin/AdminPPreferencesController.php', 'AdminPaymentControllerCore' => 'controllers/admin/AdminPaymentController.php', diff --git a/classes/Customer.php b/classes/Customer.php index 7fa966954..ca2828d24 100644 --- a/classes/Customer.php +++ b/classes/Customer.php @@ -69,6 +69,30 @@ class CustomerCore extends ObjectModel /** @var boolean Opt-in subscription */ public $optin; + /** @var string WebSite **/ + public $website; + + /** @var string Company */ + public $company; + + /** @var string SIRET */ + public $siret; + + /** @var string APE */ + public $ape; + + /** @var float Outstanding allow amount (B2B opt) */ + public $outstanding_allow_amount = 0; + + /** @var integer Show public prices (B2B opt) */ + public $show_public_prices = 0; + + /** @var int Risk ID (B2B opt) */ + public $id_risk; + + /** @var integer Max payment day */ + public $max_payment_days = 0; + /** @var integer Password */ public $passwd; @@ -140,6 +164,14 @@ class CustomerCore extends ObjectModel 'newsletter_date_add' => array('type' => self::TYPE_DATE), 'ip_registration_newsletter' => array('type' => self::TYPE_STRING), 'optin' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), + 'website' => array('type' => self::TYPE_STRING, 'validate' => 'isUrl'), + 'company' => array('type' => self::TYPE_STRING, 'validate' => 'isName'), + 'siret' => array('type' => self::TYPE_STRING, 'validate' => 'isSiret'), + 'ape' => array('type' => self::TYPE_STRING, 'validate' => 'isApe'), + 'outstanding_allow_amount' => array('type' => self::TYPE_INT, 'validate' => 'isFloat'), + 'show_public_prices' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), + 'id_risk' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), + 'max_payment_days' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'), 'active' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'deleted' => array('type' => self::TYPE_BOOL, 'validate' => 'isBool'), 'note' => array('type' => self::TYPE_STRING, 'validate' => 'isCleanHtml', 'size' => 65000), @@ -693,4 +725,25 @@ class CustomerCore extends ObjectModel $cart = new Cart((int)$cart['id_cart']); return ($cart->nbProducts() === 0 ? (int)$cart->id : false); } + + public function getOutstanding() + { + $query = new DbQuery(); + $query->select('SUM(oi.total_paid_tax_incl)') + ->from('order_invoice', 'oi') + ->leftJoin('orders', 'o', 'oi.id_order = o.id_order') + ->groupBy('o.id_customer') + ->where('o.id_customer = '.(int)$this->id); + $total_paid = (float)Db::getInstance()->getValue($query->build()); + + $query = new DbQuery(); + $query->select('SUM(op.amount)') + ->from('order_payment', 'op') + ->leftJoin('orders', 'o', 'op.id_order = o.id_order') + ->groupBy('o.id_customer') + ->where('o.id_customer = '.(int)$this->id); + $total_rest = (float)Db::getInstance()->getValue($query->build()); + + return $total_paid - $total_rest; + } } \ No newline at end of file diff --git a/classes/FrontController.php b/classes/FrontController.php index aca4b6263..a34a2b09d 100755 --- a/classes/FrontController.php +++ b/classes/FrontController.php @@ -285,6 +285,7 @@ class FrontControllerCore extends Controller 'vat_management' => (int)Configuration::get('VATNUMBER_MANAGEMENT'), 'opc' => (bool)Configuration::get('PS_ORDER_PROCESS_TYPE'), 'PS_CATALOG_MODE' => (bool)Configuration::get('PS_CATALOG_MODE') OR !(bool)Group::getCurrent()->show_prices, + 'b2b_enable' => (bool)Configuration::get('PS_B2B_ENABLE') )); // Deprecated diff --git a/classes/Product.php b/classes/Product.php index fba48f80c..792d99ef1 100644 --- a/classes/Product.php +++ b/classes/Product.php @@ -2531,6 +2531,14 @@ class ProductCore extends ObjectModel return Product::getPriceStatic((int)$this->id, $tax, $id_product_attribute, $decimals, $divisor, $only_reduc, $usereduc, $quantity); } + public function getPublicPrice($tax = true, $id_product_attribute = null, $decimals = 6, + $divisor = null, $only_reduc = false, $usereduc = true, $quantity = 1) + { + $specific_price_output = null; + return Product::getPriceStatic((int)$this->id, $tax, $id_product_attribute, $decimals, $divisor, $only_reduc, $usereduc, $quantity, + false, null, null, null, $specific_price_output, true, true, null, false); + } + public function getIdProductAttributeMostExpensive() { if (!Combination::isFeatureActive()) diff --git a/classes/Risk.php b/classes/Risk.php new file mode 100644 index 000000000..bfeb6144c --- /dev/null +++ b/classes/Risk.php @@ -0,0 +1,81 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 11158 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +/** + * @since 1.5.0 + */ +class RiskCore extends ObjectModel +{ + public $id_risk; + public $name; + public $color; + public $percent; + + protected $fieldsRequired = array('percent'); + protected $fieldsSize = array(); + protected $fieldsValidate = array(); + protected $fieldsRequiredLang = array('name'); + protected $fieldsSizeLang = array('name' => 20); + protected $fieldsValidateLang = array('name' => 'isString'); + + public static $definition = array( + 'table' => 'risk', + 'primary' => 'id_risk', + 'multilang' => true, + ); + + public function getFields() + { + $this->validateFields(); + $fields['id_risk'] = (int)$this->id_risk; + $fields['color'] = pSQL($this->color); + $fields['percent'] = (int)$this->percent; + return $fields; + } + + /** + * Check then return multilingual fields for database interaction + * + * @return array Multilingual fields + */ + public function getTranslationsFieldsChild() + { + $this->validateFieldsLang(); + return $this->getTranslationsFields(array( + 'name', + )); + } + + public static function getRisks($id_lang = null) + { + if (is_null($id_lang)) + $id_lang = Context::getContext()->language->id; + + $risks = new Collection('Risk', $id_lang); + return $risks; + } +} \ No newline at end of file diff --git a/classes/Tab.php b/classes/Tab.php index f933604b6..c93f1af44 100644 --- a/classes/Tab.php +++ b/classes/Tab.php @@ -226,6 +226,76 @@ class TabCore extends ObjectModel return (isset(self::$_getIdFromClassName[$class_name]) ? (int)self::$_getIdFromClassName[$class_name] : false); } + /** + * Get collection from module name + * @static + * @param $module string Module name + * @param null $id_lang integer Language ID + * @return array|Collection Collection of tabs (or empty array) + */ + public static function getCollectionFromModule($module, $id_lang = null) + { + if (is_null($id_lang)) + $id_lang = Context::getContext()->language->id; + + if (!Validate::isModuleName($module)) + return array(); + + $tabs = new Collection('Tab', (int)$id_lang); + $tabs->where('module', '=', $module); + return $tabs; + } + + /** + * Enabling tabs for module + * @static + * @param $module string Module Name + * @return bool Status + */ + public static function enablingForModule($module) + { + $tabs = self::getCollectionFromModule($module); + if (!empty($tabs)) { + foreach ($tabs as $tab) { + $tab->active = 1; + $tab->save(); + } + return true; + } + return false; + } + + /** + * Disabling tabs for module + * @static + * @param $module string Module name + * @return bool Status + */ + public static function disablingForModule($module) + { + $tabs = self::getCollectionFromModule($module); + if (!empty($tabs)) { + foreach ($tabs as $tab) { + $tab->active = 0; + $tab->save(); + } + return true; + } + return false; + } + + /** + * Get Instance from tab class name + * @static + * @param $class_name Name of tab class + * @return Tab Tab object (empty if bad id or class name) + */ + public static function getInstanceFromClassName($class_name) + { + $id_tab = (int)self::getIdFromClassName($class_name); + return new self($id_tab); + } + public static function getNbTabs($id_parent = null) { return (int)Db::getInstance()->getValue(' diff --git a/classes/Validate.php b/classes/Validate.php index eb12317c3..afd45ba0e 100644 --- a/classes/Validate.php +++ b/classes/Validate.php @@ -934,5 +934,36 @@ class ValidateCore return false; return true; } + + /** + * Validate SIRET Code + * @static + * @param $siret SIRET Code + * @return boolean Return true if is valid + */ + public static function isSiret($siret) + { + if (Tools::strlen($siret) != 14) + return false; + $sum = 0; + for($i=0; $i != 14; $i++) { + $tmp = ((($i + 1) % 2) + 1) * intval($siret[$i]); + if ($tmp >= 10) + $tmp -= 9; + $sum += $tmp; + } + return ($sum % 10 === 0); + } + + /** + * Validate APE Code + * @static + * @param $ape APE Code + * @return boolean Return true if is valid + */ + public static function isApe($ape) + { + return (bool)preg_match('/^[0-9]{3,4}[a-zA-Z]{1}$/s', $ape); + } } diff --git a/classes/pdf/HTMLTemplateInvoice.php b/classes/pdf/HTMLTemplateInvoice.php index de4d76ef3..85e360d31 100755 --- a/classes/pdf/HTMLTemplateInvoice.php +++ b/classes/pdf/HTMLTemplateInvoice.php @@ -74,7 +74,8 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate 'delivery_address' => $formatted_delivery_address, 'invoice_address' => $formatted_invoice_address, 'tax_excluded_display' => Group::getPriceDisplayMethod($customer->id_default_group), - 'tax_tab' => $this->getTaxTabContent() + 'tax_tab' => $this->getTaxTabContent(), + 'customer' => $customer )); return $this->smarty->fetch($this->getTemplate($country->iso_code)); @@ -109,9 +110,10 @@ class HTMLTemplateInvoiceCore extends HTMLTemplate */ protected function getTemplate($iso_country) { - $template = _PS_THEME_DIR_.'/pdf/invoice.tpl'; + $file = Configuration::get('PS_INVOICE_MODEL'); + $template = _PS_THEME_DIR_.'/pdf/'.$file.'.tpl'; - $iso_template = _PS_THEME_DIR_.'/pdf/invoice.'.$iso_country.'.tpl'; + $iso_template = _PS_THEME_DIR_.'/pdf/'.$file.'.'.$iso_country.'.tpl'; if (file_exists($iso_template)) $template = $iso_template; diff --git a/controllers/admin/AdminCustomersController.php b/controllers/admin/AdminCustomersController.php index 2b377746b..7288433ee 100644 --- a/controllers/admin/AdminCustomersController.php +++ b/controllers/admin/AdminCustomersController.php @@ -375,6 +375,93 @@ class AdminCustomersControllerCore extends AdminController ); } + if (Configuration::get('PS_B2B_ENABLE')) { + $risks = Risk::getRisks(); + + $list_risks = array(); + foreach ($risks as $key => $risk) + { + $list_risks[$key]['id_risk'] = (int) $risk->id; + $list_risks[$key]['name'] = $risk->name; + } + + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Company:'), + 'name' => 'company', + 'size' => 33 + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('SIRET:'), + 'name' => 'siret', + 'size' => 14 + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('APE:'), + 'name' => 'ape', + 'size' => 5 + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Website:'), + 'name' => 'website', + 'size' => 33 + ); + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Outstanding allow:'), + 'name' => 'outstanding_allow_amount', + 'size' => 10, + 'hint' => $this->l('Valid characters:').' 0-9', + 'suffix' => '¤' + ); + /* + @todo RC Version + $this->fields_form['input'][] = array( + 'type' => 'radio', + 'label' => $this->l('Show public prices:'), + 'name' => 'show_public_prices', + 'required' => false, + 'class' => 't', + 'is_bool' => true, + 'values' => array( + array( + 'id' => 'show_public_prices_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'show_public_prices_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ), + 'desc' => $this->l('Show public prices on the front office if specific prices have been set ') + ); + */ + $this->fields_form['input'][] = array( + 'type' => 'text', + 'label' => $this->l('Max payment days:'), + 'name' => 'max_payment_days', + 'size' => 10, + 'hint' => $this->l('Valid characters:').' 0-9' + ); + $this->fields_form['input'][] = array( + 'type' => 'select', + 'label' => $this->l('Risk:'), + 'name' => 'id_risk', + 'required' => false, + 'class' => 't', + 'options' => array( + 'query' => $list_risks, + 'id' => 'id_risk', + 'name' => 'name' + ), + ); + } + $this->fields_form['submit'] = array( 'title' => $this->l(' Save '), 'class' => 'button' diff --git a/controllers/admin/AdminInvoicesController.php b/controllers/admin/AdminInvoicesController.php index 5321e9cde..965909377 100644 --- a/controllers/admin/AdminInvoicesController.php +++ b/controllers/admin/AdminInvoicesController.php @@ -62,6 +62,13 @@ class AdminInvoicesControllerCore extends AdminController 'type' => 'textareaLang', 'cols' => 40, 'rows' => 8 + ), + 'PS_INVOICE_MODEL' => array( + 'title' => $this->l('Invoice model:'), + 'desc' => $this->l('Choose an invoice model'), + 'type' => 'select', + 'identifier' => 'value', + 'list' => $this->getInvoicesModels() ) ), 'submit' => array() @@ -240,4 +247,21 @@ class AdminInvoicesControllerCore extends AdminController if ((int)Tools::getValue('PS_INVOICE_START_NUMBER') != 0 && (int)Tools::getValue('PS_INVOICE_START_NUMBER') <= Order::getLastInvoiceNumber()) $this->_errors[] = $this->l('Invalid invoice number (must be > ').Order::getLastInvoiceNumber().')'; } + + protected function getInvoicesModels() + { + $models = array(array('value'=>'invoice', 'name'=>'invoice')); + $d = dir(_PS_THEME_DIR_.'/pdf/'); + while (false !== ($entry = $d->read())) + { + if (preg_match('`^(invoice-[a-z0-9]+)\.tpl$`', $entry, $matches)) { + $models[] = array( + 'value' => $matches[1], + 'name' => $matches[1] + ); + } + } + $d->close(); + return $models; + } } diff --git a/controllers/admin/AdminOutstandingController.php b/controllers/admin/AdminOutstandingController.php new file mode 100644 index 000000000..1a70f6586 --- /dev/null +++ b/controllers/admin/AdminOutstandingController.php @@ -0,0 +1,175 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 6844 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminOutstandingController extends AdminController +{ + public function __construct() + { + $this->table = 'order_invoice'; + $this->className = 'OrderInvoice'; + $this->addRowAction('view'); + + $this->context = Context::getContext(); + + $this->_select = '`id_order_invoice` AS `id_invoice`, + `id_order_invoice` AS `outstanding`, + CONCAT(LEFT(c.`firstname`, 1), \'. \', c.`lastname`) AS `customer`, + c.`outstanding_allow_amount`, + r.`color`, + rl.`name` AS `risk`'; + $this->_join = 'LEFT JOIN `'._DB_PREFIX_.'orders` o ON (o.`id_order` = a.`id_order`) + LEFT JOIN `'._DB_PREFIX_.'customer` c ON (c.`id_customer` = o.`id_customer`) + LEFT JOIN `'._DB_PREFIX_.'risk` r ON (r.`id_risk` = c.`id_risk`) + LEFT JOIN `'._DB_PREFIX_.'risk_lang` rl ON (r.`id_risk` = rl.`id_risk` AND rl.`id_lang` = '.(int)$this->context->language->id.')'; + + $risks = array(); + foreach (Risk::getRisks() as $risk) + { + $risks[$risk->id] = $risk->name; + } + + $this->fieldsDisplay = array( + 'number' => array( + 'title' => $this->l('Invoice Number'), + 'align' => 'center', + 'width' => 20 + ), + 'date_add' => array( + 'title' => $this->l('Date'), + 'width' => 150, + 'type' => 'date', + 'align' => 'right' + ), + 'customer' => array( + 'title' => $this->l('Customer'), + 'filter_key' => 'customer', + 'tmpTableFilter' => true + ), + 'company' => array( + 'title' => $this->l('Company'), + 'align' => 'center', + 'width' => 20 + ), + 'risk' => array( + 'title' => $this->l('Risk'), + 'align' => 'center', + 'width' => 100, + 'orderby' => false, + 'type' => 'select', + 'color' => 'color', + 'list' => $risks, + 'filter_key' => 'r!id_risk', + 'filter_type' => 'int' + ), + 'outstanding_allow_amount' => array( + 'title' => $this->l('Outstanding Allow'), + 'align' => 'center', + 'width' => 50, + 'prefix' => '', + 'suffix' => '', + 'type' => 'price' + ), + 'outstanding' => array( + 'title' => $this->l('Current Outstanding'), + 'align' => 'center', + 'width' => 50, + 'callback' => 'printOutstandingCalculation', + 'orderby' => false, + 'search' => false + ), + 'id_invoice' => array( + 'title' => $this->l('PDF'), + 'width' => 35, + 'align' => 'center', + 'callback' => 'printPDFIcons', + 'orderby' => false, + 'search' => false + ) + ); + + parent::__construct(); + } + + /** + * Toolbar initialisation + * @return bool Force true (Hide New button) + */ + public function initToolbar() + { + return true; + } + + /** + * Column callback for print PDF incon + * @param $id_invoice integer Invoice ID + * @param $tr array Row data + * @return string HTML content + */ + public function printPDFIcons($id_invoice, $tr) + { + $this->context->smarty->assign(array( + 'id_invoice' => $id_invoice + )); + + return $this->context->smarty->fetch('outstanding/_print_pdf_icon.tpl'); + } + + public function printOutstandingCalculation($id_invoice, $tr) + { + $order_invoice = new OrderInvoice($id_invoice); + if (!Validate::isLoadedObject($order_invoice)) + throw new PrestashopException('object OrderInvoice can\'t be loaded'); + $order = new Order($order_invoice->id_order); + if (!Validate::isLoadedObject($order)) + throw new PrestashopException('object Order can\'t be loaded'); + $customer = new Customer((int)$order->id_customer); + if (!Validate::isLoadedObject($order_invoice)) + throw new PrestashopException('object Customer can\'t be loaded'); + + return ''.$customer->getOutstanding().''; + } + + /** + * View render + * @throws PrestashopException Invalid objects + */ + public function renderView() + { + $order_invoice = new OrderInvoice((int) Tools::getValue('id_order_invoice')); + if (!Validate::isLoadedObject($order_invoice)) + throw new PrestashopException('object OrderInvoice can\'t be loaded'); + $order = new Order($order_invoice->id_order); + if (!Validate::isLoadedObject($order)) + throw new PrestashopException('object Order can\'t be loaded'); + + $link = $this->context->link->getAdminLink('AdminOrders'); + $link .= '&vieworder&id_order='.$order->id; + $this->redirect_after = $link; + $this->redirect(); + } +} + diff --git a/controllers/admin/AdminPreferencesController.php b/controllers/admin/AdminPreferencesController.php index 4538f166c..ed64aa344 100644 --- a/controllers/admin/AdminPreferencesController.php +++ b/controllers/admin/AdminPreferencesController.php @@ -156,6 +156,13 @@ class AdminPreferencesControllerCore extends AdminController 'default' => '480', 'visibility' => Shop::CONTEXT_ALL ), + 'PS_B2B_ENABLE' => array( + 'title' => $this->l('Enable B2B mode'), + 'desc' => $this->l('Activate or deactivate B2B mode. When this option is enable some features about B2B appear.'), + 'validation' => 'isBool', + 'cast' => 'intval', + 'type' => 'bool' + ), 'PS_ORDER_PROCESS_TYPE' => array( 'title' => $this->l('Order process type'), 'desc' => $this->l('You can choose the order process type as either standard (5 steps) or One Page Checkout'), @@ -389,4 +396,25 @@ class AdminPreferencesControllerCore extends AdminController $value = ($max_size < Tools::getValue('PS_ATTACHMENT_MAXIMUM_SIZE')) ? $max_size : Tools::getValue('PS_ATTACHMENT_MAXIMUM_SIZE'); Configuration::update('PS_ATTACHMENT_MAXIMUM_SIZE', $value); } + + /** + * Update PS_B2B_ENABLE and enables / disables the associated tabs + * @param $value integer Value of option + */ + public function updateOptionPsB2bEnable($value) + { + $value = (int)$value; + + $tabs_class_name = array('AdminOutstanding'); + if (!empty($tabs_class_name)) { + foreach ($tabs_class_name as $tab_class_name) { + $tab = Tab::getInstanceFromClassName($tab_class_name); + if (Validate::isLoadedObject($tab)) { + $tab->active = $value; + $tab->save(); + } + } + } + Configuration::updateValue('PS_B2B_ENABLE', $value); + } } diff --git a/install-dev/sql/db.sql b/install-dev/sql/db.sql index b5196c3ef..53c736b39 100644 --- a/install-dev/sql/db.sql +++ b/install-dev/sql/db.sql @@ -516,6 +516,10 @@ CREATE TABLE `PREFIX_customer` ( `id_shop` INT(11) UNSIGNED NOT NULL DEFAULT '1', `id_gender` int(10) unsigned NOT NULL, `id_default_group` int(10) unsigned NOT NULL DEFAULT '1', + `id_risk` int(10) unsigned NOT NULL DEFAULT '1', + `company` varchar(64), + `siret` varchar(14), + `ape` varchar(5), `firstname` varchar(32) NOT NULL, `lastname` varchar(32) NOT NULL, `email` varchar(128) NOT NULL, @@ -526,6 +530,10 @@ CREATE TABLE `PREFIX_customer` ( `ip_registration_newsletter` varchar(15) default NULL, `newsletter_date_add` datetime default NULL, `optin` tinyint(1) unsigned NOT NULL default '0', + `website` varchar(128), + `outstanding_allow_amount` DECIMAL( 10,6 ) NOT NULL default '0.00', + `show_public_prices` tinyint(1) unsigned NOT NULL default '0', + `max_payment_days` int(10) unsigned NOT NULL default '60', `secure_key` varchar(32) NOT NULL default '-1', `note` text, `active` tinyint(1) unsigned NOT NULL default '0', @@ -2339,3 +2347,18 @@ CREATE TABLE `PREFIX_specific_price_rule_condition` ( PRIMARY KEY (`id_specific_price_rule_condition`), INDEX (`id_specific_price_rule_condition_group`) ) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `PREFIX_risk` ( + `id_risk` int(11) NOT NULL AUTO_INCREMENT, + `percent` tinyint(3) NOT NULL, + `color` varchar(32) NULL, + PRIMARY KEY (`id_risk`) +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `PREFIX_risk_lang` ( + `id_risk` int(10) unsigned NOT NULL, + `id_lang` int(10) unsigned NOT NULL, + `name` varchar(20) NOT NULL, + PRIMARY KEY (`id_risk`,`id_lang`), + KEY `id_risk` (`id_risk`) +) ENGINE=ENGINE_TYPE DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/install-dev/sql/db_settings_lite.sql b/install-dev/sql/db_settings_lite.sql index 7de4b5e5c..5cce602b2 100644 --- a/install-dev/sql/db_settings_lite.sql +++ b/install-dev/sql/db_settings_lite.sql @@ -339,7 +339,9 @@ INSERT INTO `PREFIX_configuration` (`id_configuration`, `name`, `value`, `date_a (162, 'PS_UNIDENTIFIED_GROUP', '1', NOW(), NOW()), (163, 'PS_GUEST_GROUP', '2', NOW(), NOW()), (164, 'PS_CUSTOMER_GROUP', '3', NOW(), NOW()), -(165, 'PS_SMARTY_CONSOLE', 0, NOW(), NOW()); +(165, 'PS_SMARTY_CONSOLE', 0, NOW(), NOW()), +(166, 'PS_B2B_ENABLE', '0', NOW(), NOW()), +(167, 'PS_INVOICE_MODEL', 'invoice', NOW(), NOW()); INSERT INTO `PREFIX_configuration_lang` (`id_configuration`, `id_lang`, `value`, `date_upd`) VALUES (36, 1, 'IN', NOW()),(36, 2, 'FA', NOW()),(36, 3, 'CU', NOW()),(36, 4, 'FA', NOW()),(36, 5, 'FA', NOW()), @@ -931,6 +933,7 @@ INSERT INTO `PREFIX_contact_lang` (`id_contact`, `id_lang`, `name`, `description INSERT INTO `PREFIX_profile` (`id_profile`) VALUES (1); INSERT INTO `PREFIX_profile_lang` (`id_profile`, `id_lang`, `name`) VALUES (1, 1, 'SuperAdmin'),(1, 2, 'SuperAdmin'),(1, 3, 'SuperAdmin'),(1, 4, 'SuperAdmin'),(1, 5, 'SuperAdmin'); +/* Active tabs */ INSERT INTO `PREFIX_tab` (`id_tab`, `class_name`, `id_parent`, `position`) VALUES (1, 'AdminCatalog', 0, 1),(2, 'AdminCustomers', 0, 2),(3, 'AdminOrders', 0, 3), (4, 'AdminPayment', 0, 4),(5, 'AdminShipping', 0, 5),(6, 'AdminStats', 0, 6),(7, 'AdminModules', 0, 7),(29, 'AdminEmployees', 0, 8),(8, 'AdminPreferences', 0, 9), (9, 'AdminTools', 0, 10),(82, 'AdminStores', 9, 11),(60, 'AdminTracking', 1, 3),(10, 'AdminManufacturers', 1, 4),(34, 'AdminSuppliers', 1, 5),(11, 'AdminAttributesGroups', 1, 6), @@ -966,6 +969,9 @@ INSERT INTO `PREFIX_tab` (`id_tab`, `class_name`, `id_parent`, `position`) VALUE (108, 'AdminStockConfiguration', 95, 7), (109, 'AdminSpecificPriceRule', 1, 11); +/* Inactive tabs */ +INSERT INTO `PREFIX_tab` (`id_tab`, `class_name`, `id_parent`, `position`, `active`) VALUES (110, 'AdminOutstanding', 2, 5, 0); + INSERT INTO `PREFIX_access` (`id_profile`, `id_tab`, `view`, `add`, `edit`, `delete`) (SELECT 1, id_tab, 1, 1, 1, 1 FROM `PREFIX_tab`); INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES @@ -997,7 +1003,8 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (1, 105, 'CMS categories'), (1, 106, 'CMS pages'), (1, 108, 'Configuration'), -(1, 109, 'Catalog price rules'); +(1, 109, 'Catalog price rules'), +(1, 110, 'Outstanding'); INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (2, 1, 'Catalogue'),(2, 2, 'Clients'),(2, 3, 'Commandes'),(2, 4, 'Paiement'),(2, 5, 'Transport'), @@ -1028,7 +1035,8 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (2, 105, 'Catégories CMS'), (2, 106, 'Pages CMS'), (2, 108, 'Configuration'), -(2, 109, 'Règles de prix catalogue'); +(2, 109, 'Règles de prix catalogue'), +(2, 110, 'Encours'); INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (3, 1, 'Catálogo'),(3, 2, 'Clientes'),(3, 3, 'Pedidos'),(3, 4, 'Pago'),(3, 5, 'Transporte'), @@ -1058,7 +1066,8 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (3, 105, 'CMS categories'), (3, 106, 'CMS pages'), (3, 108, 'Configuration'), -(3, 110, 'Catalog price rules'); +(3, 109, 'Catalog price rules'), +(3, 110, 'Outstanding'); INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (4, 1, 'Katalog'),(4, 2, 'Kunden'),(4, 3, 'Bestellungen'),(4, 4, 'Zahlung'), @@ -1089,7 +1098,8 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (4, 105, 'CMS categories'), (4, 106, 'CMS pages'), (4, 108, 'Configuration'), -(4, 109, 'Catalog price rules'); +(4, 109, 'Catalog price rules'), +(4, 110, 'Outstanding'); INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (5, 1, 'Catalogo'),(5, 2, 'Clienti'),(5, 3, 'Ordini'),(5, 4, 'Pagamento'), @@ -1120,7 +1130,8 @@ INSERT INTO `PREFIX_tab_lang` (`id_lang`, `id_tab`, `name`) VALUES (5, 105, 'CMS categories'), (5, 106, 'CMS pages'), (5, 108, 'Configuration'), -(5, 109, 'Catalog price rules'); +(5, 109, 'Catalog price rules'), +(5, 110, 'Outstanding'); INSERT IGNORE INTO `PREFIX_tab_lang` (`id_tab`, `id_lang`, `name`) (SELECT `id_tab`, id_lang, (SELECT tl.`name` @@ -1606,3 +1617,31 @@ INSERT INTO `PREFIX_supply_order_state_lang` (`id_supply_order_state`, `id_lang` (6, 3, 'order fenced'), (6, 4, 'order fenced'), (6, 5, 'order fenced'); + +INSERT INTO `PREFIX_risk` (`id_risk`, `percent`, `color`) VALUES +(1, 0, 'LimeGreen'), +(2, 35, 'DarkOrange'), +(3, 75, 'Crimson'), +(4, 100, '#ec2e15'); + +INSERT INTO `PREFIX_risk_lang` (`id_risk`, `id_lang`, `name`) VALUES +(1, 1, 'None'), +(2, 1, 'Low'), +(3, 1, 'Middle'), +(4, 1, 'Hight'), +(1, 2, 'Aucun'), +(2, 2, 'Faible'), +(3, 2, 'Moyen'), +(4, 2, 'Élevé'), +(1, 3, 'None'), +(2, 3, 'Low'), +(3, 3, 'Middle'), +(4, 3, 'Hight'), +(1, 4, 'None'), +(2, 4, 'Low'), +(3, 4, 'Middle'), +(4, 4, 'Hight'), +(1, 5, 'None'), +(2, 5, 'Low'), +(3, 5, 'Middle'), +(4, 5, 'Hight'); \ No newline at end of file diff --git a/install-dev/sql/upgrade/1.5.0.2.sql b/install-dev/sql/upgrade/1.5.0.2.sql index 52b2d9abd..dc09174b9 100644 --- a/install-dev/sql/upgrade/1.5.0.2.sql +++ b/install-dev/sql/upgrade/1.5.0.2.sql @@ -295,7 +295,7 @@ DELETE FROM `PREFIX_configuration` WHERE `name` = 'PS_PDF_FONT'; ALTER TABLE `PREFIX_order_detail` ADD `reduction_amount_tax_incl` FLOAT( 20.6 ) NOT NULL AFTER `reduction_amount` , ADD `reduction_amount_tax_excl` FLOAT( 20.6 ) NOT NULL AFTER `reduction_amount_tax_incl`, -ADD `total_price_tax_incl` DECIMAL(20, 6) NOT NULL AFTER `download_deadline`, +ADD `total_price_tax_incl` DECIMAL(20, 6) NOT NULL AFTER `download_deadline`,, ADD `total_price_tax_excl` DECIMAL(20, 6) NOT NULL AFTER `total_price_tax_incl`, ADD `unit_price_tax_incl` DECIMAL(20, 6) NOT NULL AFTER `total_price_tax_excl`, ADD `unit_price_tax_excl` DECIMAL(20, 6) NOT NULL AFTER `unit_price_tax_incl`, @@ -391,12 +391,11 @@ INSERT INTO `PREFIX_order_payment` (`id_order_invoice`, `id_order`, `id_currency ) INSERT INTO `PREFIX_configuration` (`name`, `value`, `date_add`, `date_upd`) VALUES -('PS_SMARTY_CONSOLE', '0', NOW(), NOW()); +('PS_SMARTY_CONSOLE', '0', NOW(), NOW(),('PS_INVOICE_MODEL', 'invoice', NOW(), NOW()); ALTER TABLE `PREFIX_specific_price` ADD `id_cart` INT(11) UNSIGNED NOT NULL AFTER `id_specific_price_rule`; ALTER TABLE `PREFIX_specific_price` ADD INDEX `id_cart` (`id_cart`); /* PHP:update_modules_multishop.php; */; - UPDATE `PREFIX_tab` SET `position` = ( SELECT MAX(`position`)+1 @@ -411,8 +410,4 @@ SET `position` = ( FROM `PREFIX_tab` WHERE `id_parent` = 0 ) -WHERE `class_name` = 'AdminAccounting'; - -ALTER TABLE `PREFIX_order_slip_detail` CHANGE `amount` `amount_tax_excl` DECIMAL( 10, 2 ) NOT NULL; -ALTER TABLE `PREFIX_order_slip_detail` ADD COLUMN `amount_tax_incl` DECIMAL(10,2) NOT NULL AFTER `amount_tax_excl`; - +WHERE `class_name` = 'AdminAccounting'; \ No newline at end of file diff --git a/themes/default/authentication.tpl b/themes/default/authentication.tpl index 02eb41420..019ee6617 100644 --- a/themes/default/authentication.tpl +++ b/themes/default/authentication.tpl @@ -450,6 +450,27 @@ $(function(){ldelim}

{/if} + {if $b2b_enable} + + {/if} {if isset($PS_REGISTRATION_PROCESS_TYPE) && $PS_REGISTRATION_PROCESS_TYPE}