*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/**
* \file htdocs/societe/canvas/actions_card_common.class.php
* \ingroup thirdparty
* \brief Fichier de la classe Thirdparty card controller (common)
* \version $Id$
*/
/**
* \class ActionsCardCommon
* \brief Classe permettant la gestion des tiers par defaut
*/
class ActionsCardCommon
{
var $db;
//! Numero d'erreur Plage 1280-1535
var $errno = 0;
//! Template container
var $tpl = array();
//! Object container
var $object;
//! Canvas
var $canvas;
//! Error string
var $error;
//! Error array
var $errors=array();
/**
* Constructeur de la classe
* @param DB Handler acces base de donnees
*/
function ActionsCardCommon($DB)
{
$this->db = $DB;
}
/**
* Assigne les valeurs par defaut pour le canvas
* @param action Type of template
*/
function assign_values($action='')
{
global $conf, $langs, $user, $mysoc, $canvas;
global $form, $formadmin, $formcompany;
if ($_GET["type"]=='f') { $this->object->fournisseur=1; }
if ($_GET["type"]=='c') { $this->object->client=1; }
if ($_GET["type"]=='p') { $this->object->client=2; }
if ($_GET["type"]=='cp') { $this->object->client=3; }
if ($_REQUEST["private"]==1) { $this->object->particulier=1; }
foreach($this->object as $key => $value)
{
$this->tpl[$key] = $value;
}
if ($action == 'create')
{
if ($conf->use_javascript_ajax)
{
$this->tpl['ajax_selecttype'] = "\n".''."\n";
}
}
if ($action == 'create' || $action == 'edit')
{
if ($conf->use_javascript_ajax)
{
$this->tpl['ajax_selectcountry'] = "\n".''."\n";
}
// Load object modCodeClient
$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
if (! $module) dolibarr_error('',$langs->trans("ErrorModuleThirdPartyCodeInCompanyModuleNotDefined"));
if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
{
$module = substr($module, 0, dol_strlen($module)-4);
}
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$module.".php");
$modCodeClient = new $module;
$this->tpl['auto_customercode'] = $modCodeClient->code_auto;
// We verified if the tag prefix is used
if ($modCodeClient->code_auto) $this->tpl['prefix_customercode'] = $modCodeClient->verif_prefixIsUsed();
// TODO create a function
$this->tpl['select_customertype'] = '';
// Customer
$this->tpl['customercode'] = $this->object->code_client;
if ((!$this->object->code_client || $this->object->code_client == -1) && $modCodeClient->code_auto) $this->tpl['customercode'] = $modCodeClient->getNextValue($this->object,0);
$this->tpl['ismodifiable_customercode'] = $this->object->codeclient_modifiable();
$s=$modCodeClient->getToolTip($langs,$this->object,0);
$this->tpl['help_customercode'] = $form->textwithpicto('',$s,1);
if ($conf->fournisseur->enabled)
{
$this->tpl['supplier_enabled'] = 1;
// Load object modCodeFournisseur
$module=$conf->global->SOCIETE_CODEFOURNISSEUR_ADDON;
if (! $module) $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
if (substr($module, 0, 15) == 'mod_codeclient_' && substr($module, -3) == 'php')
{
$module = substr($module, 0, dol_strlen($module)-4);
}
require_once(DOL_DOCUMENT_ROOT ."/includes/modules/societe/".$module.".php");
$modCodeFournisseur = new $module;
$this->tpl['auto_suppliercode'] = $modCodeFournisseur->code_auto;
// We verified if the tag prefix is used
if ($modCodeFournisseur->code_auto) $this->tpl['prefix_suppliercode'] = $modCodeFournisseur->verif_prefixIsUsed();
// Supplier
$this->tpl['yn_supplier'] = $form->selectyesno("fournisseur",$this->object->fournisseur,1);
$this->tpl['suppliercode'] = $this->object->code_fournisseur;
if ((!$this->object->code_fournisseur || $this->object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) $this->tpl['suppliercode'] = $modCodeFournisseur->getNextValue($this->object,1);
$this->tpl['ismodifiable_suppliercode'] = $this->object->codefournisseur_modifiable();
$s=$modCodeFournisseur->getToolTip($langs,$this->object,1);
$this->tpl['help_suppliercode'] = $form->textwithpicto('',$s,1);
$this->object->LoadSupplierCateg();
$this->tpl['suppliercategory'] = $this->object->SupplierCategories;
$this->tpl['select_suppliercategory'] = $form->selectarray("fournisseur_categorie",$this->object->SupplierCategories,$_POST["fournisseur_categorie"],1);
}
// Zip
$this->tpl['select_zip'] = $formcompany->select_ziptown($this->object->cp,'zipcode',array('town','selectpays_id','departement_id'),6);
// Town
$this->tpl['select_town'] = $formcompany->select_ziptown($this->object->ville,'town',array('zipcode','selectpays_id','departement_id'));
// Country
$this->tpl['select_country'] = $form->select_country($this->object->pays_id,'pays_id');
$countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')';
if ($user->admin) $this->tpl['info_admin'] = info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionnarySetup"),1);
// State
if ($this->object->pays_id) $this->tpl['select_state'] = $formcompany->select_state($this->object->departement_id,$this->object->pays_code);
else $this->tpl['select_state'] = $countrynotdefined;
// Language
if ($conf->global->MAIN_MULTILANGS) $this->tpl['select_lang'] = $formadmin->select_language(($this->object->default_lang?$this->object->default_lang:$conf->global->MAIN_LANG_DEFAULT),'default_lang',0,0,1);
// VAT
$this->tpl['yn_assujtva'] = $form->selectyesno('assujtva_value',$this->tpl['tva_assuj'],1); // Assujeti par defaut en creation
// Select users
$this->tpl['select_users'] = $form->select_dolusers($this->object->commercial_id,'commercial_id',1);
// Local Tax
// TODO mettre dans une classe propre au pays
if($mysoc->pays_code=='ES')
{
$this->tpl['localtax'] = '';
if($mysoc->localtax1_assuj=="1" && $mysoc->localtax2_assuj=="1")
{
$this->tpl['localtax'].= '