[+] Project : B2B Features

This commit is contained in:
jBreux
2011-12-22 15:30:21 +00:00
parent 171d7c61cb
commit 4eb9edf698
18 changed files with 984 additions and 19 deletions
+53
View File
@@ -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;
}
}
+1
View File
@@ -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
+8
View File
@@ -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())
+81
View File
@@ -0,0 +1,81 @@
<?php
/*
* 2007-2011 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
* @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;
}
}
+70
View File
@@ -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('
+31
View File
@@ -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);
}
}
+5 -3
View File
@@ -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;