89 global $conf, $langs, $db, $user, $mysoc, $canvas;
90 global $form, $formadmin, $formcompany;
92 if ($action ==
'add' || $action ==
'update') {
96 if ($_GET[
"type"] ==
'f') {
97 $this->
object->fournisseur = 1;
99 if ($_GET[
"type"] ==
'c') {
100 $this->
object->client = 1;
102 if ($_GET[
"type"] ==
'p') {
103 $this->
object->client = 2;
105 if ($_GET[
"type"] ==
'cp') {
106 $this->
object->client = 3;
108 if ($_REQUEST[
"private"] == 1) {
109 $this->
object->particulier = 1;
112 foreach ($this->
object as $key => $value) {
113 $this->tpl[$key] = $value;
117 if (is_array($GLOBALS[
'errors'])) {
121 if ($action ==
'create') {
122 if ($conf->use_javascript_ajax) {
123 $this->tpl[
'ajax_selecttype'] =
"\n".
'<script type="text/javascript">
124 $(document).ready(function () {
125 $("#radiocompany").click(function() {
126 document.formsoc.action.value="create";
127 document.formsoc.canvas.value="company";
128 document.formsoc.private.value=0;
129 document.formsoc.submit();
131 $("#radioprivate").click(function() {
132 document.formsoc.action.value="create";
133 document.formsoc.canvas.value="individual";
134 document.formsoc.private.value=1;
135 document.formsoc.submit();
142 if ($action ==
'create' || $action ==
'edit') {
143 if ($conf->use_javascript_ajax) {
144 $this->tpl[
'ajax_selectcountry'] =
"\n".
'<script type="text/javascript">
145 $(document).ready(function () {
146 $("#selectcountry_id").change(function() {
147 document.formsoc.action.value="'.$action.
'";
148 document.formsoc.canvas.value="'.$canvas.
'";
149 document.formsoc.submit();
156 $module = (!empty($conf->global->SOCIETE_CODECLIENT_ADDON) ? $conf->global->SOCIETE_CODECLIENT_ADDON :
'mod_codeclient_leopard');
157 if (substr($module, 0, 15) ==
'mod_codeclient_' && substr($module, -3) ==
'php') {
158 $module = substr($module, 0,
dol_strlen($module) - 4);
160 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
161 foreach ($dirsociete as $dirroot) {
167 $modCodeClient =
new $module($db);
168 $this->tpl[
'auto_customercode'] = $modCodeClient->code_auto;
170 if ($modCodeClient->code_auto) {
171 $this->tpl[
'prefix_customercode'] = $modCodeClient->verif_prefixIsUsed();
176 0 => $langs->trans(
'NorProspectNorCustomer'),
177 1 => $langs->trans(
'Customer'),
178 2 => $langs->trans(
'Prospect'),
179 3 => $langs->trans(
'ProspectCustomer')
180 ), $this->object->client);
183 $this->tpl[
'customercode'] = $this->
object->code_client;
184 if ((!$this->object->code_client || $this->object->code_client == -1) && $modCodeClient->code_auto) {
185 $this->tpl[
'customercode'] = $modCodeClient->getNextValue($this->
object, 0);
187 $this->tpl[
'ismodifiable_customercode'] = $this->
object->codeclient_modifiable();
188 $s = $modCodeClient->getToolTip($langs, $this->
object, 0);
189 $this->tpl[
'help_customercode'] = $form->textwithpicto(
'', $s, 1);
191 if (isModEnabled(
"supplier_order") || isModEnabled(
"supplier_invoice")) {
192 $this->tpl[
'supplier_enabled'] = 1;
195 $module = $conf->global->SOCIETE_CODECLIENT_ADDON;
196 if (substr($module, 0, 15) ==
'mod_codeclient_' && substr($module, -3) ==
'php') {
197 $module = substr($module, 0,
dol_strlen($module) - 4);
199 $dirsociete = array_merge(array(
'/core/modules/societe/'), $conf->modules_parts[
'societe']);
200 foreach ($dirsociete as $dirroot) {
206 $modCodeFournisseur =
new $module;
207 $this->tpl[
'auto_suppliercode'] = $modCodeFournisseur->code_auto;
209 if ($modCodeFournisseur->code_auto) {
210 $this->tpl[
'prefix_suppliercode'] = $modCodeFournisseur->verif_prefixIsUsed();
214 $this->tpl[
'yn_supplier'] = $form->selectyesno(
"fournisseur", $this->object->fournisseur, 1);
215 $this->tpl[
'suppliercode'] = $this->
object->code_fournisseur;
216 if ((!$this->object->code_fournisseur || $this->object->code_fournisseur == -1) && $modCodeFournisseur->code_auto) {
217 $this->tpl[
'suppliercode'] = $modCodeFournisseur->getNextValue($this->
object, 1);
219 $this->tpl[
'ismodifiable_suppliercode'] = $this->
object->codefournisseur_modifiable();
220 $s = $modCodeFournisseur->getToolTip($langs, $this->
object, 1);
221 $this->tpl[
'help_suppliercode'] = $form->textwithpicto(
'', $s, 1);
223 $this->
object->LoadSupplierCateg();
224 $this->tpl[
'suppliercategory'] = $this->
object->SupplierCategories;
228 $this->tpl[
'select_zip'] = $formcompany->select_ziptown($this->object->zip,
'zipcode', array(
'town',
'selectcountry_id',
'state_id'), 6);
231 $this->tpl[
'select_town'] = $formcompany->select_ziptown($this->object->town,
'town', array(
'zipcode',
'selectcountry_id',
'state_id'));
234 $this->
object->country_id = ($this->
object->country_id ? $this->
object->country_id : $mysoc->country_id);
235 $this->
object->country_code = ($this->
object->country_code ? $this->
object->country_code : $mysoc->country_code);
236 $this->tpl[
'select_country'] = $form->select_country($this->object->country_id,
'country_id');
237 $countrynotdefined = $langs->trans(
"ErrorSetACountryFirst").
' ('.$langs->trans(
"SeeAbove").
')';
240 $this->tpl[
'info_admin'] =
info_admin($langs->trans(
"YouCanChangeValuesForThisListFromDictionarySetup"), 1);
244 if ($this->object->country_id) {
245 $this->tpl[
'select_state'] = $formcompany->select_state($this->object->state_id, $this->object->country_code);
247 $this->tpl[
'select_state'] = $countrynotdefined;
252 $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);
256 $this->tpl[
'yn_assujtva'] = $form->selectyesno(
'assujtva_value', $this->tpl[
'tva_assuj'], 1);
259 $this->tpl[
'select_users'] = $form->select_dolusers($this->object->commercial_id,
'commercial_id', 1,
'', 0,
'',
'', 0, 0, 0,
'', 0,
'',
'maxwidth300');
263 if ($mysoc->country_code ==
'ES') {
264 $this->tpl[
'localtax'] =
'';
266 if ($mysoc->localtax1_assuj ==
"1" && $mysoc->localtax2_assuj ==
"1") {
267 $this->tpl[
'localtax'] .=
'<tr><td>'.$langs->trans(
"LocalTax1IsUsedES").
'</td><td>';
268 $this->tpl[
'localtax'] .= $form->selectyesno(
'localtax1assuj_value', $this->object->localtax1_assuj, 1);
269 $this->tpl[
'localtax'] .=
'</td><td>'.$langs->trans(
"LocalTax2IsUsedES").
'</td><td>';
270 $this->tpl[
'localtax'] .= $form->selectyesno(
'localtax2assuj_value', $this->object->localtax1_assuj, 1);
271 $this->tpl[
'localtax'] .=
'</td></tr>';
272 } elseif ($mysoc->localtax1_assuj ==
"1") {
273 $this->tpl[
'localtax'] .=
'<tr><td>'.$langs->trans(
"LocalTax1IsUsedES").
'</td><td colspan="3">';
274 $this->tpl[
'localtax'] .= $form->selectyesno(
'localtax1assuj_value', $this->object->localtax1_assuj, 1);
275 $this->tpl[
'localtax'] .=
'</td><tr>';
276 } elseif ($mysoc->localtax2_assuj ==
"1") {
277 $this->tpl[
'localtax'] .=
'<tr><td>'.$langs->trans(
"LocalTax2IsUsedES").
'</td><td colspan="3">';
278 $this->tpl[
'localtax'] .= $form->selectyesno(
'localtax2assuj_value', $this->object->localtax1_assuj, 1);
279 $this->tpl[
'localtax'] .=
'</td><tr>';
288 $this->tpl[
'showrefnav'] = $form->showrefnav($this->
object,
'socid',
'', ($user->socid ? 0 : 1),
'rowid',
'nom');
290 $this->tpl[
'checkcustomercode'] = $this->
object->check_codeclient();
291 $this->tpl[
'checksuppliercode'] = $this->
object->check_codefournisseur();
292 $this->tpl[
'address'] =
dol_nl2br($this->object->address);
295 if ($this->object->isInEEC()) {
296 $this->tpl[
'country'] = $form->textwithpicto(($img ? $img.
' ' :
'').$this->object->country, $langs->trans(
"CountryIsInEEC"), 1, 0);
298 $this->tpl[
'country'] = ($img ? $img.
' ' :
'').$this->object->country;
300 $this->tpl[
'phone'] =
dol_print_phone($this->object->phone, $this->object->country_code, 0, $this->object->id,
'AC_TEL');
301 $this->tpl[
'fax'] =
dol_print_phone($this->object->fax, $this->object->country_code, 0, $this->object->id,
'AC_FAX');
302 $this->tpl[
'email'] =
dol_print_email($this->object->email, 0, $this->object->id,
'AC_EMAIL');
305 $this->tpl[
'tva_assuj'] =
yn($this->object->tva_assuj);
308 $arr = $formcompany->typent_array(1);
309 $this->tpl[
'typent'] = $arr[$this->
object->typent_code];
312 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
315 $langs->load(
"languages");
316 $this->tpl[
'default_lang'] = (empty($this->object->default_lang) ?
'' : $langs->trans(
'Language_'.$this->object->default_lang));
319 $this->tpl[
'image_edit'] =
img_edit();
321 $this->tpl[
'display_rib'] = $this->
object->display_rib();
324 $this->tpl[
'sales_representatives'] =
'';
325 $listsalesrepresentatives = $this->
object->getSalesRepresentatives($user);
326 $nbofsalesrepresentative = count($listsalesrepresentatives);
327 if ($nbofsalesrepresentative > 3) {
328 $this->tpl[
'sales_representatives'] .= $nbofsalesrepresentative;
329 } elseif ($nbofsalesrepresentative > 0) {
330 $userstatic =
new User($this->db);
332 foreach ($listsalesrepresentatives as $val) {
333 $userstatic->id = $val[
'id'];
334 $userstatic->lastname = $val[
'name'];
335 $userstatic->firstname = $val[
'firstname'];
336 $this->tpl[
'sales_representatives'] .= $userstatic->getNomUrl(1);
338 if ($i < $nbofsalesrepresentative) {
339 $this->tpl[
'sales_representatives'] .=
', ';
343 $this->tpl[
'sales_representatives'] .= $langs->trans(
"NoSalesRepresentativeAffected");
347 if (isModEnabled(
'adherent')) {
348 $langs->load(
"members");
350 $result = $adh->fetch(
'',
'', $this->object->id);
352 $adh->ref = $adh->getFullName($langs);
353 $this->tpl[
'linked_member'] = $adh->getNomUrl(1);
355 $this->tpl[
'linked_member'] = $langs->trans(
"ThirdpartyNotLinkedToMember");
361 if ($mysoc->country_code ==
'ES') {
362 $this->tpl[
'localtax'] =
'';
364 if ($mysoc->localtax1_assuj ==
"1" && $mysoc->localtax2_assuj ==
"1") {
365 $this->tpl[
'localtax'] .=
'<tr><td>'.$langs->trans(
"LocalTax1IsUsedES").
'</td>';
366 $this->tpl[
'localtax'] .=
'<td>'.yn($this->object->localtax1_assuj).
'</td>';
367 $this->tpl[
'localtax'] .=
'<td>'.$langs->trans(
"LocalTax2IsUsedES").
'</td>';
368 $this->tpl[
'localtax'] .=
'<td>'.yn($this->object->localtax2_assuj).
'</td></tr>';
369 } elseif ($mysoc->localtax1_assuj ==
"1") {
370 $this->tpl[
'localtax'] .=
'<tr><td>'.$langs->trans(
"LocalTax1IsUsedES").
'</td>';
371 $this->tpl[
'localtax'] .=
'<td colspan="3">'.yn($this->object->localtax1_assuj).
'</td></tr>';
372 } elseif ($mysoc->localtax2_assuj ==
"1") {
373 $this->tpl[
'localtax'] .=
'<tr><td>'.$langs->trans(
"LocalTax2IsUsedES").
'</td>';
374 $this->tpl[
'localtax'] .=
'<td colspan="3">'.yn($this->object->localtax2_assuj).
'</td></tr>';