1<?php 2/* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net> 4 * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com> 5 * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> 6 * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com> 7 * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr> 8 * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es> 9 * Copyright (C) 2013 Alexandre Spangaro <aspangaro@open-dsi.fr> 10 * Copyright (C) 2015-2019 Frédéric France <frederic.france@netlogic.fr> 11 * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com> 12 * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr> 13 * 14 * This program is free software; you can redistribute it and/or modify 15 * it under the terms of the GNU General Public License as published by 16 * the Free Software Foundation; either version 3 of the License, or 17 * (at your option) any later version. 18 * 19 * This program is distributed in the hope that it will be useful, 20 * but WITHOUT ANY WARRANTY; without even the implied warranty of 21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 * GNU General Public License for more details. 23 * 24 * You should have received a copy of the GNU General Public License 25 * along with this program. If not, see <https://www.gnu.org/licenses/>. 26 */ 27 28/** 29 * \file htdocs/comm/card.php 30 * \ingroup commercial compta 31 * \brief Page to show customer card of a third party 32 */ 33 34require '../main.inc.php'; 35require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; 36require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; 37require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php'; 38require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; 39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; 40require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; 41if (!empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; 42if (!empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; 43if (!empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; 44if (!empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; 45if (!empty($conf->expedition->enabled)) require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php'; 46if (!empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; 47if (!empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; 48if (!empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; 49 50// Load translation files required by the page 51$langs->loadLangs(array('companies', 'banks')); 52 53if (!empty($conf->contrat->enabled)) $langs->load("contracts"); 54if (!empty($conf->commande->enabled)) $langs->load("orders"); 55if (!empty($conf->expedition->enabled)) $langs->load("sendings"); 56if (!empty($conf->facture->enabled)) $langs->load("bills"); 57if (!empty($conf->projet->enabled)) $langs->load("projects"); 58if (!empty($conf->ficheinter->enabled)) $langs->load("interventions"); 59if (!empty($conf->notification->enabled)) $langs->load("mails"); 60 61// Security check 62$id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int')); 63if ($user->socid > 0) $id = $user->socid; 64$result = restrictedArea($user, 'societe', $id, '&societe'); 65 66$action = GETPOST('action', 'aZ09'); 67 68$limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; 69$sortfield = GETPOST("sortfield", 'alpha'); 70$sortorder = GETPOST("sortorder", 'alpha'); 71$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); 72if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 73$offset = $limit * $page; 74$pageprev = $page - 1; 75$pagenext = $page + 1; 76if (!$sortorder) $sortorder = "ASC"; 77if (!$sortfield) $sortfield = "nom"; 78$cancelbutton = GETPOST('cancel', 'alpha'); 79 80$object = new Client($db); 81$extrafields = new ExtraFields($db); 82 83// fetch optionals attributes and labels 84$extrafields->fetch_name_optionals_label($object->table_element); 85 86// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context 87$hookmanager->initHooks(array('thirdpartycomm', 'globalcard')); 88 89// Security check 90$result = restrictedArea($user, 'societe', $socid, '&societe', '', 'fk_soc', 'rowid', 0); 91 92if ($object->id > 0) { 93 if (!($object->client > 0) || empty($user->rights->societe->lire)) { 94 accessforbidden(); 95 } 96} 97 98$now = dol_now(); 99 100 101/* 102 * Actions 103 */ 104 105$parameters = array('id' => $id, 'socid' => $id); 106$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some 107if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); 108 109if (empty($reshook)) 110{ 111 if ($cancelbutton) 112 { 113 $action = ""; 114 } 115 116 // set accountancy code 117 if ($action == 'setcustomeraccountancycode') 118 { 119 $result = $object->fetch($id); 120 $object->code_compta = $_POST["customeraccountancycode"]; 121 $result = $object->update($object->id, $user, 1, 1, 0); 122 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 123 } 124 125 // terms of the settlement 126 if ($action == 'setconditions' && $user->rights->societe->creer) 127 { 128 $object->fetch($id); 129 $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); 130 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 131 } 132 133 // mode de reglement 134 if ($action == 'setmode' && $user->rights->societe->creer) 135 { 136 $object->fetch($id); 137 $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); 138 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 139 } 140 141 // Bank account 142 if ($action == 'setbankaccount' && $user->rights->societe->creer) 143 { 144 $object->fetch($id); 145 $result = $object->setBankAccount(GETPOST('fk_account', 'int')); 146 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 147 } 148 149 // customer preferred shipping method 150 if ($action == 'setshippingmethod' && $user->rights->societe->creer) 151 { 152 $object->fetch($id); 153 $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); 154 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 155 } 156 157 // assujetissement a la TVA 158 if ($action == 'setassujtva' && $user->rights->societe->creer) 159 { 160 $object->fetch($id); 161 $object->tva_assuj = $_POST['assujtva_value']; 162 $result = $object->update($object->id); 163 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 164 } 165 166 // set prospect level 167 if ($action == 'setprospectlevel' && $user->rights->societe->creer) 168 { 169 $object->fetch($id); 170 $object->fk_prospectlevel = GETPOST('prospect_level_id', 'alpha'); 171 $result = $object->update($object->id, $user); 172 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 173 } 174 175 // set communication status 176 if ($action == 'setstcomm') 177 { 178 $object->fetch($id); 179 $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcomm'); 180 $result = $object->update($object->id, $user); 181 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 182 else $result = $object->fetch($object->id); 183 } 184 185 // update outstandng limit 186 if ($action == 'setoutstanding_limit') 187 { 188 $object->fetch($id); 189 $object->outstanding_limit = GETPOST('outstanding_limit'); 190 $result = $object->update($object->id, $user); 191 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 192 } 193 194 // update order min amount 195 if ($action == 'setorder_min_amount') 196 { 197 $object->fetch($id); 198 $object->order_min_amount = price2num(GETPOST('order_min_amount', 'alpha')); 199 $result = $object->update($object->id, $user); 200 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); 201 } 202 203 // Set sales representatives 204 if ($action == 'set_salesrepresentatives' && $user->rights->societe->creer) 205 { 206 $object->fetch($id); 207 $result = $object->setSalesRep(GETPOST('commercial', 'array')); 208 } 209 210 if ($action == 'update_extras') { 211 $object->fetch($id); 212 213 $object->oldcopy = dol_clone($object); 214 215 // Fill array 'array_options' with data from update form 216 $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml')); 217 if ($ret < 0) $error++; 218 if (!$error) 219 { 220 $result = $object->insertExtraFields('COMPANY_MODIFY'); 221 if ($result < 0) 222 { 223 setEventMessages($object->error, $object->errors, 'errors'); 224 $error++; 225 } 226 } 227 if ($error) $action = 'edit_extras'; 228 } 229} 230 231 232/* 233 * View 234 */ 235 236$contactstatic = new Contact($db); 237$userstatic = new User($db); 238$form = new Form($db); 239$formcompany = new FormCompany($db); 240 241if ($id > 0 && empty($object->id)) 242{ 243 // Load data of third party 244 $res = $object->fetch($id); 245 if ($object->id < 0) dol_print_error($db, $object->error, $object->errors); 246} 247 248$title = $langs->trans("CustomerCard"); 249if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name; 250$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; 251llxHeader('', $title, $help_url); 252 253 254if ($object->id > 0) 255{ 256 $head = societe_prepare_head($object); 257 258 print dol_get_fiche_head($head, 'customer', $langs->trans("ThirdParty"), -1, 'company'); 259 260 $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; 261 262 dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom'); 263 264 print '<div class="fichecenter"><div class="fichehalfleft">'; 265 266 print '<div class="underbanner clearboth"></div>'; 267 print '<table class="border centpercent tableforfield">'; 268 269 // Prospect/Customer 270 print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>'; 271 print $object->getLibCustProspStatut(); 272 print '</td></tr>'; 273 274 // Prefix 275 if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field 276 { 277 print '<tr><td>'.$langs->trans("Prefix").'</td><td>'; 278 print ($object->prefix_comm ? $object->prefix_comm : ' '); 279 print '</td></tr>'; 280 } 281 282 if ($object->client) 283 { 284 $langs->load("compta"); 285 286 print '<tr><td>'; 287 print $langs->trans('CustomerCode').'</td><td>'; 288 print $object->code_client; 289 $tmpcheck = $object->check_codeclient(); 290 if ($tmpcheck != 0 && $tmpcheck != -5) { 291 print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; 292 } 293 print '</td></tr>'; 294 295 print '<tr>'; 296 print '<td>'; 297 print $form->editfieldkey("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer); 298 print '</td><td>'; 299 print $form->editfieldval("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer); 300 print '</td>'; 301 print '</tr>'; 302 } 303 304 // This fields are used to know VAT to include in an invoice when the thirdparty is making a sale, so when it is a supplier. 305 // We don't need them into customer profile. 306 // Except for spain and localtax where localtax depends on buyer and not seller 307 308 // VAT is used 309 /* 310 print '<tr>'; 311 print '<td class="nowrap">'; 312 print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling')); 313 print '</td>'; 314 print '<td>'; 315 print yn($object->tva_assuj); 316 print '</td>'; 317 print '</tr>'; 318 */ 319 320 if ($mysoc->country_code == 'ES') 321 { 322 // Local Taxes 323 if ($mysoc->localtax1_assuj == "1") 324 { 325 print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>'; 326 print yn($object->localtax1_assuj); 327 print '</td></tr>'; 328 } 329 if ($mysoc->localtax1_assuj == "1") 330 { 331 print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>'; 332 print yn($object->localtax2_assuj); 333 print '</td></tr>'; 334 } 335 } 336 337 // TVA Intra 338 print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>'; 339 print $object->tva_intra; 340 print '</td></tr>'; 341 342 // default terms of the settlement 343 $langs->load('bills'); 344 print '<tr><td>'; 345 print '<table width="100%" class="nobordernopadding"><tr><td>'; 346 print $langs->trans('PaymentConditions'); 347 print '<td>'; 348 if (($action != 'editconditions') && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>'; 349 print '</tr></table>'; 350 print '</td><td>'; 351 if ($action == 'editconditions') 352 { 353 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1); 354 } else { 355 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none'); 356 } 357 print "</td>"; 358 print '</tr>'; 359 360 // Mode de reglement par defaut 361 print '<tr><td class="nowrap">'; 362 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; 363 print $langs->trans('PaymentMode'); 364 print '<td>'; 365 if (($action != 'editmode') && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>'; 366 print '</tr></table>'; 367 print '</td><td>'; 368 if ($action == 'editmode') 369 { 370 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1); 371 } else { 372 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'none'); 373 } 374 print "</td>"; 375 print '</tr>'; 376 377 if (!empty($conf->banque->enabled)) 378 { 379 // Compte bancaire par défaut 380 print '<tr><td class="nowrap">'; 381 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; 382 print $langs->trans('PaymentBankAccount'); 383 print '<td>'; 384 if (($action != 'editbankaccount') && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&socid='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>'; 385 print '</tr></table>'; 386 print '</td><td>'; 387 if ($action == 'editbankaccount') 388 { 389 $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_account, 'fk_account', 1); 390 } else { 391 $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_account, 'none'); 392 } 393 print "</td>"; 394 print '</tr>'; 395 } 396 397 $isCustomer = ($object->client == 1 || $object->client == 3); 398 399 // Relative discounts (Discounts-Drawbacks-Rebates) 400 if ($isCustomer) 401 { 402 print '<tr><td class="nowrap">'; 403 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; 404 print $langs->trans("CustomerRelativeDiscountShort"); 405 print '<td><td class="right">'; 406 if ($user->rights->societe->creer && !$user->socid > 0) 407 { 408 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>'; 409 } 410 print '</td></tr></table>'; 411 print '</td><td>'.($object->remise_percent ? '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_percent.'%</a>' : '').'</td>'; 412 print '</tr>'; 413 414 // Absolute discounts (Discounts-Drawbacks-Rebates) 415 print '<tr><td class="nowrap">'; 416 print '<table width="100%" class="nobordernopadding">'; 417 print '<tr><td class="nowrap">'; 418 print $langs->trans("CustomerAbsoluteDiscountShort"); 419 print '<td><td class="right">'; 420 if ($user->rights->societe->creer && !$user->socid > 0) 421 { 422 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.img_edit($langs->trans("Modify")).'</a>'; 423 } 424 print '</td></tr></table>'; 425 print '</td>'; 426 print '<td>'; 427 $amount_discount = $object->getAvailableDiscounts(); 428 if ($amount_discount < 0) dol_print_error($db, $object->error); 429 if ($amount_discount > 0) print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'">'.price($amount_discount, 1, $langs, 1, -1, -1, $conf->currency).'</a>'; 430 //else print $langs->trans("DiscountNone"); 431 print '</td>'; 432 print '</tr>'; 433 } 434 435 // Max outstanding bill 436 if ($object->client) 437 { 438 print '<tr class="nowrap">'; 439 print '<td>'; 440 print $form->editfieldkey("OutstandingBill", 'outstanding_limit', $object->outstanding_limit, $object, $user->rights->societe->creer); 441 print '</td><td>'; 442 $limit_field_type = (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount'; 443 print $form->editfieldval("OutstandingBill", 'outstanding_limit', $object->outstanding_limit, $object, $user->rights->societe->creer, $limit_field_type, ($object->outstanding_limit != '' ? price($object->outstanding_limit) : '')); 444 print '</td>'; 445 print '</tr>'; 446 } 447 448 if ($object->client) 449 { 450 if (!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)) 451 { 452 print '<!-- Minimim amount for orders -->'."\n"; 453 print '<tr class="nowrap">'; 454 print '<td>'; 455 print $form->editfieldkey("OrderMinAmount", 'order_min_amount', $object->order_min_amount, $object, $user->rights->societe->creer); 456 print '</td><td>'; 457 print $form->editfieldval("OrderMinAmount", 'order_min_amount', $object->order_min_amount, $object, $user->rights->societe->creer, $limit_field_type, ($object->order_min_amount != '' ? price($object->order_min_amount) : '')); 458 print '</td>'; 459 print '</tr>'; 460 } 461 } 462 463 464 // Multiprice level 465 if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) 466 { 467 print '<tr><td class="nowrap">'; 468 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; 469 print $langs->trans("PriceLevel"); 470 print '<td><td class="right">'; 471 if ($user->rights->societe->creer) 472 { 473 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>'; 474 } 475 print '</td></tr></table>'; 476 print '</td><td>'; 477 print $object->price_level; 478 $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$object->price_level; 479 if (!empty($conf->global->$keyforlabel)) print ' - '.$langs->trans($conf->global->$keyforlabel); 480 print "</td>"; 481 print '</tr>'; 482 } 483 484 // Preferred shipping Method 485 if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD)) { 486 print '<tr><td class="nowrap">'; 487 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; 488 print $langs->trans('SendingMethod'); 489 print '<td>'; 490 if (($action != 'editshipping') && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshipping&socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>'; 491 print '</tr></table>'; 492 print '</td><td>'; 493 if ($action == 'editshipping') 494 { 495 $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1); 496 } else { 497 $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->shipping_method_id, 'none'); 498 } 499 print "</td>"; 500 print '</tr>'; 501 } 502 503 if (!empty($conf->intracommreport->enabled)) 504 { 505 // Transport mode by default 506 print '<tr><td class="nowrap">'; 507 print '<table class="centpercent nobordernopadding"><tr><td class="nowrap">'; 508 print $langs->trans('IntracommReportTransportMode'); 509 print '<td>'; 510 if (($action != 'edittransportmode') && $user->rights->societe->creer) print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edittransportmode&socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>'; 511 print '</tr></table>'; 512 print '</td><td>'; 513 if ($action == 'edittransportmode') 514 { 515 $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_transport_mode, 'fk_transport_mode', 1); 516 } 517 else { 518 $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_transport_mode, 'none'); 519 } 520 print "</td>"; 521 print '</tr>'; 522 } 523 524 // Categories 525 if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) { 526 $langs->load("categories"); 527 print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>'; 528 print '<td>'; 529 print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1); 530 print "</td></tr>"; 531 } 532 533 // Other attributes 534 $parameters = array('socid'=>$object->id); 535 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php'; 536 537 // Sales representative 538 include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php'; 539 540 // Module Adherent 541 if (!empty($conf->adherent->enabled)) 542 { 543 $langs->load("members"); 544 $langs->load("users"); 545 546 print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>'; 547 print '<td>'; 548 $adh = new Adherent($db); 549 $result = $adh->fetch('', '', $object->id); 550 if ($result > 0) 551 { 552 $adh->ref = $adh->getFullName($langs); 553 print $adh->getNomUrl(1); 554 } else { 555 print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>'; 556 } 557 print '</td>'; 558 print "</tr>\n"; 559 } 560 561 print "</table>"; 562 563 // Prospection level and status 564 if ($object->client == 2 || $object->client == 3) 565 { 566 print '<br>'; 567 568 print '<div class="underbanner clearboth"></div>'; 569 print '<table class="border centpercent tableforfield">'; 570 571 // Level of prospection 572 print '<tr><td class="titlefield nowrap">'; 573 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">'; 574 print $langs->trans('ProspectLevel'); 575 print '<td>'; 576 if ($action != 'editlevel' && $user->rights->societe->creer) print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editlevel&socid='.$object->id.'">'.img_edit($langs->trans('Modify'), 1).'</a></td>'; 577 print '</tr></table>'; 578 print '</td><td>'; 579 if ($action == 'editlevel') 580 { 581 $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_prospectlevel, 'prospect_level_id', 1); 582 } else { 583 print $object->getLibProspLevel(); 584 } 585 print "</td>"; 586 print '</tr>'; 587 588 // Status of prospection 589 $object->loadCacheOfProspStatus(); 590 print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']); 591 print ' '; 592 print '<div class="floatright">'; 593 foreach ($object->cacheprospectstatus as $key => $val) 594 { 595 $titlealt = 'default'; 596 if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) $titlealt = $val['label']; 597 if ($object->stcomm_id != $val['id']) print '<a class="pictosubstatus reposition" href="'.$_SERVER["PHP_SELF"].'?socid='.$object->id.'&stcomm='.$val['code'].'&action=setstcomm&token='.newToken().'">'.img_action($titlealt, $val['code'], $val['picto']).'</a>'; 598 } 599 print '</div></td></tr>'; 600 print "</table>"; 601 } 602 603 print '</div><div class="fichehalfright"><div class="ficheaddleft">'; 604 print '<div class="underbanner clearboth"></div>'; 605 606 $boxstat = ''; 607 608 // Nbre max d'elements des petites listes 609 $MAXLIST = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT; 610 611 // Lien recap 612 $boxstat .= '<div class="box">'; 613 $boxstat .= '<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">'; 614 $boxstat .= '<tr class="impair nohover"><td colspan="2" class="tdboxstats nohover">'; 615 616 if (!empty($conf->propal->enabled) && $user->rights->propal->lire) 617 { 618 // Box proposals 619 $tmp = $object->getOutstandingProposals(); 620 $outstandingOpened = $tmp['opened']; 621 $outstandingTotal = $tmp['total_ht']; 622 $outstandingTotalIncTax = $tmp['total_ttc']; 623 $text = $langs->trans("OverAllProposals"); 624 $link = DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id; 625 $icon = 'bill'; 626 if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">'; 627 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">'; 628 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>'; 629 $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>'; 630 $boxstat .= '</div>'; 631 if ($link) $boxstat .= '</a>'; 632 } 633 634 if (!empty($conf->commande->enabled) && $user->rights->commande->lire) 635 { 636 // Box commandes 637 $tmp = $object->getOutstandingOrders(); 638 $outstandingOpened = $tmp['opened']; 639 $outstandingTotal = $tmp['total_ht']; 640 $outstandingTotalIncTax = $tmp['total_ttc']; 641 $text = $langs->trans("OverAllOrders"); 642 $link = DOL_URL_ROOT.'/commande/list.php?socid='.$object->id; 643 $icon = 'bill'; 644 if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">'; 645 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">'; 646 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>'; 647 $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>'; 648 $boxstat .= '</div>'; 649 if ($link) $boxstat .= '</a>'; 650 } 651 652 if (!empty($conf->facture->enabled) && $user->rights->facture->lire) 653 { 654 // Box factures 655 $tmp = $object->getOutstandingBills('customer', 0); 656 $outstandingOpened = $tmp['opened']; 657 $outstandingTotal = $tmp['total_ht']; 658 $outstandingTotalIncTax = $tmp['total_ttc']; 659 660 $text = $langs->trans("OverAllInvoices"); 661 $link = DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id; 662 $icon = 'bill'; 663 if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">'; 664 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">'; 665 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>'; 666 $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>'; 667 $boxstat .= '</div>'; 668 if ($link) $boxstat .= '</a>'; 669 670 // Box outstanding bill 671 $warn = ''; 672 if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened) 673 { 674 $warn = ' '.img_warning($langs->trans("OutstandingBillReached")); 675 } 676 $text = $langs->trans("CurrentOutstandingBill"); 677 $link = DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id; 678 $icon = 'bill'; 679 if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">'; 680 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">'; 681 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>'; 682 $boxstat .= '<span class="boxstatsindicator'.($outstandingOpened > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>'; 683 $boxstat .= '</div>'; 684 if ($link) $boxstat .= '</a>'; 685 686 $tmp = $object->getOutstandingBills('customer', 1); 687 $outstandingOpenedLate = $tmp['opened']; 688 if ($outstandingOpened != $outstandingOpenedLate && !empty($outstandingOpenedLate)) { 689 $warn = ''; 690 if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpenedLate) { 691 $warn = ' '.img_warning($langs->trans("OutstandingBillReached")); 692 } 693 $text = $langs->trans("CurrentOutstandingBillLate"); 694 $link = DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id; 695 $icon = 'bill'; 696 if ($link) $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">'; 697 $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">'; 698 $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>'; 699 $boxstat .= '<span class="boxstatsindicator'.($outstandingOpenedLate > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpenedLate, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>'; 700 $boxstat .= '</div>'; 701 if ($link) $boxstat .= '</a>'; 702 } 703 } 704 705 $parameters = array(); 706 $reshook = $hookmanager->executeHooks('addMoreBoxStatsCustomer', $parameters, $object, $action); 707 if (empty($reshook)) { 708 $boxstat .= $hookmanager->resPrint; 709 } 710 711 $boxstat .= '</td></tr>'; 712 $boxstat .= '</table>'; 713 $boxstat .= '</div>'; 714 715 print $boxstat; 716 717 718 /* 719 * Latest proposals 720 */ 721 if (!empty($conf->propal->enabled) && $user->rights->propal->lire) 722 { 723 $langs->load("propal"); 724 725 $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht"; 726 $sql .= ", p.tva as total_tva"; 727 $sql .= ", p.total as total_ttc"; 728 $sql .= ", p.ref, p.ref_client, p.remise"; 729 $sql .= ", p.datep as dp, p.fin_validite as date_limit"; 730 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; 731 $sql .= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id"; 732 $sql .= " AND s.rowid = ".$object->id; 733 $sql .= " AND p.entity IN (".getEntity('propal').")"; 734 $sql .= " ORDER BY p.datep DESC"; 735 736 $resql = $db->query($sql); 737 if ($resql) 738 { 739 $propal_static = new Propal($db); 740 741 $num = $db->num_rows($resql); 742 if ($num > 0) 743 { 744 print '<div class="div-table-responsive-no-min">'; 745 print '<table class="noborder centpercent lastrecordtable">'; 746 747 print '<tr class="liste_titre">'; 748 print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastPropals", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id.'">'.$langs->trans("AllPropals").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>'; 749 print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/comm/propal/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"), 'stats').'</a></td>'; 750 print '</tr></table></td>'; 751 print '</tr>'; 752 } 753 754 $i = 0; 755 while ($i < $num && $i < $MAXLIST) 756 { 757 $objp = $db->fetch_object($resql); 758 759 print '<tr class="oddeven">'; 760 print '<td class="nowrap">'; 761 $propal_static->id = $objp->propalid; 762 $propal_static->ref = $objp->ref; 763 $propal_static->ref_client = $objp->ref_client; 764 $propal_static->total_ht = $objp->total_ht; 765 $propal_static->total_tva = $objp->total_tva; 766 $propal_static->total_ttc = $objp->total_ttc; 767 print $propal_static->getNomUrl(1); 768 if (($db->jdate($objp->date_limit) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == $propal_static::STATUS_VALIDATED) { 769 print " ".img_warning(); 770 } 771 print '</td><td class="right" width="80px">'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n"; 772 print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>'; 773 print '<td class="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut, 5).'</td></tr>'; 774 $i++; 775 } 776 $db->free($resql); 777 778 if ($num > 0) 779 { 780 print "</table>"; 781 print '</div>'; 782 } 783 } else { 784 dol_print_error($db); 785 } 786 } 787 788 /* 789 * Latest orders 790 */ 791 if (!empty($conf->commande->enabled) && $user->rights->commande->lire) 792 { 793 $sql = "SELECT s.nom, s.rowid"; 794 $sql .= ", c.rowid as cid, c.total_ht"; 795 $sql .= ", c.tva as total_tva"; 796 $sql .= ", c.total_ttc"; 797 $sql .= ", c.ref, c.ref_client, c.fk_statut, c.facture"; 798 $sql .= ", c.date_commande as dc"; 799 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; 800 $sql .= " WHERE c.fk_soc = s.rowid "; 801 $sql .= " AND s.rowid = ".$object->id; 802 $sql .= " AND c.entity IN (".getEntity('commande').')'; 803 $sql .= " ORDER BY c.date_commande DESC"; 804 805 $resql = $db->query($sql); 806 if ($resql) 807 { 808 $commande_static = new Commande($db); 809 810 $num = $db->num_rows($resql); 811 if ($num > 0) 812 { 813 // Check if there are orders billable 814 $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,'; 815 $sql2 .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as billed'; 816 $sql2 .= ' FROM '.MAIN_DB_PREFIX.'societe as s'; 817 $sql2 .= ', '.MAIN_DB_PREFIX.'commande as c'; 818 $sql2 .= ' WHERE c.fk_soc = s.rowid'; 819 $sql2 .= ' AND s.rowid = '.$object->id; 820 // Show orders with status validated, shipping started and delivered (well any order we can bill) 821 $sql2 .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))"; 822 823 $resql2 = $db->query($sql2); 824 $orders2invoice = $db->num_rows($resql2); 825 $db->free($resql2); 826 827 print '<div class="div-table-responsive-no-min">'; 828 print '<table class="noborder centpercent lastrecordtable">'; 829 830 print '<tr class="liste_titre">'; 831 print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomerOrders", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->id.'">'.$langs->trans("AllOrders").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>'; 832 print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/commande/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"), 'stats').'</a></td>'; 833 print '</tr></table></td>'; 834 print '</tr>'; 835 } 836 837 $i = 0; 838 while ($i < $num && $i < $MAXLIST) 839 { 840 $objp = $db->fetch_object($resql); 841 842 $commande_static->id = $objp->cid; 843 $commande_static->ref = $objp->ref; 844 $commande_static->ref_client = $objp->ref_client; 845 $commande_static->total_ht = $objp->total_ht; 846 $commande_static->total_tva = $objp->total_tva; 847 $commande_static->total_ttc = $objp->total_ttc; 848 $commande_static->billed = $objp->billed; 849 850 print '<tr class="oddeven">'; 851 print '<td class="nowrap">'; 852 print $commande_static->getNomUrl(1); 853 print '</td><td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day')."</td>\n"; 854 print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>'; 855 print '<td class="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut, $objp->facture, 5).'</td></tr>'; 856 $i++; 857 } 858 $db->free($resql); 859 860 if ($num > 0) 861 { 862 print "</table>"; 863 print '</div>'; 864 } 865 } else { 866 dol_print_error($db); 867 } 868 } 869 870 /* 871 * Latest shipments 872 */ 873 if (!empty($conf->expedition->enabled) && $user->rights->expedition->lire) 874 { 875 $sql = 'SELECT e.rowid as id'; 876 $sql .= ', e.ref'; 877 $sql .= ', e.date_creation'; 878 $sql .= ', e.fk_statut as statut'; 879 $sql .= ', s.nom'; 880 $sql .= ', s.rowid as socid'; 881 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e"; 882 $sql .= " WHERE e.fk_soc = s.rowid AND s.rowid = ".$object->id; 883 $sql .= " AND e.entity IN (".getEntity('expedition').")"; 884 $sql .= ' GROUP BY e.rowid'; 885 $sql .= ', e.ref'; 886 $sql .= ', e.date_creation'; 887 $sql .= ', e.fk_statut'; 888 $sql .= ', s.nom'; 889 $sql .= ', s.rowid'; 890 $sql .= " ORDER BY e.date_creation DESC"; 891 892 $resql = $db->query($sql); 893 if ($resql) 894 { 895 $sendingstatic = new Expedition($db); 896 897 $num = $db->num_rows($resql); 898 if ($num > 0) { 899 print '<div class="div-table-responsive-no-min">'; 900 print '<table class="noborder centpercent lastrecordtable">'; 901 902 print '<tr class="liste_titre">'; 903 print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastSendings", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/expedition/list.php?socid='.$object->id.'">'.$langs->trans("AllSendings").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>'; 904 print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/expedition/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"), 'stats').'</a></td>'; 905 print '</tr></table></td>'; 906 print '</tr>'; 907 } 908 909 $i = 0; 910 while ($i < $num && $i < $MAXLIST) 911 { 912 $objp = $db->fetch_object($resql); 913 914 $sendingstatic->id = $objp->id; 915 $sendingstatic->ref = $objp->ref; 916 917 print '<tr class="oddeven">'; 918 print '<td class="nowrap">'; 919 print $sendingstatic->getNomUrl(1); 920 print '</td>'; 921 if ($objp->date_creation > 0) { 922 print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation), 'day').'</td>'; 923 } else { 924 print '<td class="right"><b>!!!</b></td>'; 925 } 926 927 print '<td class="nowrap right" width="100" >'.$sendingstatic->LibStatut($objp->statut, 5).'</td>'; 928 print "</tr>\n"; 929 $i++; 930 } 931 $db->free($resql); 932 933 if ($num > 0) 934 { 935 print "</table>"; 936 print '</div>'; 937 } 938 } else { 939 dol_print_error($db); 940 } 941 } 942 943 /* 944 * Latest contracts 945 */ 946 if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire) 947 { 948 $sql = "SELECT s.nom, s.rowid, c.rowid as id, c.ref as ref, c.statut as contract_status, c.datec as dc, c.date_contrat as dcon, c.ref_customer as refcus, c.ref_supplier as refsup"; 949 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c"; 950 $sql .= " WHERE c.fk_soc = s.rowid "; 951 $sql .= " AND s.rowid = ".$object->id; 952 $sql .= " AND c.entity IN (".getEntity('contract').")"; 953 $sql .= " ORDER BY c.datec DESC"; 954 955 $resql = $db->query($sql); 956 if ($resql) 957 { 958 $contrat = new Contrat($db); 959 960 $num = $db->num_rows($resql); 961 if ($num > 0) 962 { 963 print '<div class="div-table-responsive-no-min">'; 964 print '<table class="noborder centpercent lastrecordtable">'; 965 966 print '<tr class="liste_titre">'; 967 print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td>'; 968 print '<td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/contrat/list.php?socid='.$object->id.'">'.$langs->trans("AllContracts").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>'; 969 //print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/contract/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"),'stats').'</a></td>'; 970 print '</tr></table></td>'; 971 print '</tr>'; 972 } 973 974 $i = 0; 975 while ($i < $num && $i < $MAXLIST) 976 { 977 $objp = $db->fetch_object($resql); 978 979 $contrat->id = $objp->id; 980 $contrat->ref = $objp->ref ? $objp->ref : $objp->id; 981 $contrat->ref_customer = $objp->refcus; 982 $contrat->ref_supplier = $objp->refsup; 983 $contrat->statut = $objp->contract_status; 984 $contrat->fetch_lines(); 985 986 $late = ''; 987 foreach ($contrat->lines as $line) { 988 if ($contrat->statut == Contrat::STATUS_VALIDATED && $line->statut == ContratLigne::STATUS_OPEN) { 989 if (((!empty($line->date_fin_validite) ? $line->date_fin_validite : 0) + $conf->contrat->services->expires->warning_delay) < $now) $late = img_warning($langs->trans("Late")); 990 } 991 } 992 993 print '<tr class="oddeven">'; 994 print '<td class="nowrap">'; 995 print $contrat->getNomUrl(1, 12); 996 print $late; 997 print "</td>\n"; 998 print '<td class="nowrap">'.dol_trunc($objp->refsup, 12)."</td>\n"; 999 //print '<td class="right" width="80px"><span title="'.$langs->trans("DateCreation").'">'.dol_print_date($db->jdate($objp->dc), 'day')."</span></td>\n"; 1000 print '<td class="right" width="80px"><span title="'.$langs->trans("DateContract").'">'.dol_print_date($db->jdate($objp->dcon), 'day')."</span></td>\n"; 1001 print '<td width="20"> </td>'; 1002 print '<td class="nowraponall right">'; 1003 print $contrat->getLibStatut(4); 1004 print "</td>\n"; 1005 print '</tr>'; 1006 $i++; 1007 } 1008 $db->free($resql); 1009 1010 if ($num > 0) 1011 { 1012 print "</table>"; 1013 print '</div>'; 1014 } 1015 } else { 1016 dol_print_error($db); 1017 } 1018 } 1019 1020 /* 1021 * Latest interventions 1022 */ 1023 if (!empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire) 1024 { 1025 $sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.fk_statut, f.duree as duration, f.datei as startdate"; 1026 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f"; 1027 $sql .= " WHERE f.fk_soc = s.rowid"; 1028 $sql .= " AND s.rowid = ".$object->id; 1029 $sql .= " AND f.entity IN (".getEntity('intervention').")"; 1030 $sql .= " ORDER BY f.tms DESC"; 1031 1032 $resql = $db->query($sql); 1033 if ($resql) 1034 { 1035 $fichinter_static = new Fichinter($db); 1036 1037 $num = $db->num_rows($resql); 1038 if ($num > 0) 1039 { 1040 print '<div class="div-table-responsive-no-min">'; 1041 print '<table class="noborder centpercent lastrecordtable">'; 1042 1043 print '<tr class="liste_titre">'; 1044 print '<td colspan="3"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastInterventions", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/fichinter/list.php?socid='.$object->id.'">'.$langs->trans("AllInterventions").'<span class="badge marginleftonlyshort">'.$num.'</span></td>'; 1045 print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/fichinter/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"), 'stats').'</a></td>'; 1046 print '</tr></table></td>'; 1047 print '</tr>'; 1048 } 1049 1050 $i = 0; 1051 while ($i < $num && $i < $MAXLIST) 1052 { 1053 $objp = $db->fetch_object($resql); 1054 1055 $fichinter_static->id = $objp->id; 1056 $fichinter_static->statut = $objp->fk_statut; 1057 1058 print '<tr class="oddeven">'; 1059 print '<td class="nowrap"><a href="'.DOL_URL_ROOT.'/fichinter/card.php?id='.$objp->id.'">'.img_object($langs->trans("ShowPropal"), "propal").' '.$objp->ref.'</a></td>'."\n"; 1060 //print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n"; 1061 print '<td class="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n"; 1062 print '<td class="nowrap right" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n"; 1063 print '</tr>'; 1064 1065 $i++; 1066 } 1067 $db->free($resql); 1068 1069 if ($num > 0) 1070 { 1071 print "</table>"; 1072 print '</div>'; 1073 } 1074 } else { 1075 dol_print_error($db); 1076 } 1077 } 1078 1079 /* 1080 * Latest invoices templates 1081 */ 1082 if (!empty($conf->facture->enabled) && $user->rights->facture->lire) 1083 { 1084 $sql = 'SELECT f.rowid as id, f.titre as ref'; 1085 $sql .= ', f.total as total_ht'; 1086 $sql .= ', f.tva as total_tva'; 1087 $sql .= ', f.total_ttc'; 1088 $sql .= ', f.datec as dc'; 1089 $sql .= ', f.date_last_gen, f.date_when'; 1090 $sql .= ', f.frequency'; 1091 $sql .= ', f.unit_frequency'; 1092 $sql .= ', f.suspended as suspended'; 1093 $sql .= ', s.nom, s.rowid as socid'; 1094 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f"; 1095 $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id; 1096 $sql .= " AND f.entity IN (".getEntity('invoice').")"; 1097 $sql .= ' GROUP BY f.rowid, f.titre, f.total, f.tva, f.total_ttc,'; 1098 $sql .= ' f.date_last_gen, f.datec, f.frequency, f.unit_frequency,'; 1099 $sql .= ' f.suspended, f.date_when,'; 1100 $sql .= ' s.nom, s.rowid'; 1101 $sql .= " ORDER BY f.date_last_gen, f.datec DESC"; 1102 1103 $resql = $db->query($sql); 1104 if ($resql) 1105 { 1106 $invoicetemplate = new FactureRec($db); 1107 1108 $num = $db->num_rows($resql); 1109 if ($num > 0) 1110 { 1111 print '<div class="div-table-responsive-no-min">'; 1112 print '<table class="noborder centpercent lastrecordtable">'; 1113 1114 print '<tr class="liste_titre">'; 1115 print '<td colspan="4"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LatestCustomerTemplateInvoices", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/compta/facture/invoicetemplate_list.php?socid='.$object->id.'">'.$langs->trans("AllCustomerTemplateInvoices").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>'; 1116 print '</tr></table></td>'; 1117 print '</tr>'; 1118 } 1119 1120 $i = 0; 1121 while ($i < $num && $i < $MAXLIST) 1122 { 1123 $objp = $db->fetch_object($resql); 1124 1125 $invoicetemplate->id = $objp->id; 1126 $invoicetemplate->ref = $objp->ref; 1127 $invoicetemplate->suspended = $objp->suspended; 1128 $invoicetemplate->frequency = $objp->frequency; 1129 $invoicetemplate->unit_frequency = $objp->unit_frequency; 1130 $invoicetemplate->total_ht = $objp->total_ht; 1131 $invoicetemplate->total_tva = $objp->total_tva; 1132 $invoicetemplate->total_ttc = $objp->total_ttc; 1133 $invoicetemplate->date_last_gen = $objp->date_last_gen; 1134 $invoicetemplate->date_when = $objp->date_when; 1135 1136 print '<tr class="oddeven">'; 1137 print '<td class="nowrap">'; 1138 print $invoicetemplate->getNomUrl(1); 1139 print '</td>'; 1140 if ($objp->frequency && $objp->date_last_gen > 0) 1141 { 1142 print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_last_gen), 'day').'</td>'; 1143 } else { 1144 if ($objp->dc > 0) 1145 { 1146 print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day').'</td>'; 1147 } else { 1148 print '<td class="right"><b>!!!</b></td>'; 1149 } 1150 } 1151 print '<td class="right" style="min-width: 60px">'; 1152 print price($objp->total_ht); 1153 print '</td>'; 1154 1155 if (!empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES)) 1156 { 1157 print '<td class="right" style="min-width: 60px">'; 1158 print price($objp->total_ttc); 1159 print '</td>'; 1160 } 1161 1162 print '<td class="nowrap right" style="min-width: 60px">'; 1163 print $langs->trans('FrequencyPer_'.$invoicetemplate->unit_frequency, $invoicetemplate->frequency).' - '; 1164 print ($invoicetemplate->LibStatut($invoicetemplate->frequency, $invoicetemplate->suspended, 5, 0)); 1165 print '</td>'; 1166 print "</tr>\n"; 1167 $i++; 1168 } 1169 $db->free($resql); 1170 1171 if ($num > 0) 1172 { 1173 print "</table>"; 1174 print '</div>'; 1175 } 1176 } else { 1177 dol_print_error($db); 1178 } 1179 } 1180 1181 /* 1182 * Latest invoices 1183 */ 1184 if (!empty($conf->facture->enabled) && $user->rights->facture->lire) 1185 { 1186 $sql = 'SELECT f.rowid as facid, f.ref, f.type'; 1187 $sql .= ', f.total as total_ht'; 1188 $sql .= ', f.tva as total_tva'; 1189 $sql .= ', f.total_ttc'; 1190 $sql .= ', f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as statut'; 1191 $sql .= ', s.nom, s.rowid as socid'; 1192 $sql .= ', SUM(pf.amount) as am'; 1193 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f"; 1194 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture'; 1195 $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".$object->id; 1196 $sql .= " AND f.entity IN (".getEntity('invoice').")"; 1197 $sql .= ' GROUP BY f.rowid, f.ref, f.type, f.total, f.tva, f.total_ttc,'; 1198 $sql .= ' f.datef, f.datec, f.paye, f.fk_statut,'; 1199 $sql .= ' s.nom, s.rowid'; 1200 $sql .= " ORDER BY f.datef DESC, f.datec DESC"; 1201 1202 $resql = $db->query($sql); 1203 if ($resql) 1204 { 1205 $facturestatic = new Facture($db); 1206 1207 $num = $db->num_rows($resql); 1208 if ($num > 0) 1209 { 1210 print '<div class="div-table-responsive-no-min">'; 1211 print '<table class="noborder centpercent lastrecordtable">'; 1212 1213 print '<tr class="liste_titre">'; 1214 print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastCustomersBills", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td><td class="right"><a class="notasortlink" href="'.DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id.'">'.$langs->trans("AllBills").'<span class="badge marginleftonlyshort">'.$num.'</span></a></td>'; 1215 print '<td width="20px" class="right"><a href="'.DOL_URL_ROOT.'/compta/facture/stats/index.php?socid='.$object->id.'">'.img_picto($langs->trans("Statistics"), 'stats').'</a></td>'; 1216 print '</tr></table></td>'; 1217 print '</tr>'; 1218 } 1219 1220 $i = 0; 1221 while ($i < $num && $i < $MAXLIST) 1222 { 1223 $objp = $db->fetch_object($resql); 1224 1225 $facturestatic->id = $objp->facid; 1226 $facturestatic->ref = $objp->ref; 1227 $facturestatic->type = $objp->type; 1228 $facturestatic->total_ht = $objp->total_ht; 1229 $facturestatic->total_tva = $objp->total_tva; 1230 $facturestatic->total_ttc = $objp->total_ttc; 1231 1232 print '<tr class="oddeven">'; 1233 print '<td class="nowrap">'; 1234 print $facturestatic->getNomUrl(1); 1235 print '</td>'; 1236 if ($objp->df > 0) 1237 { 1238 print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->df), 'day').'</td>'; 1239 } else { 1240 print '<td class="right"><b>!!!</b></td>'; 1241 } 1242 print '<td class="right" style="min-width: 60px">'; 1243 print price($objp->total_ht); 1244 print '</td>'; 1245 1246 if (!empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES)) 1247 { 1248 print '<td class="right" style="min-width: 60px">'; 1249 print price($objp->total_ttc); 1250 print '</td>'; 1251 } 1252 1253 print '<td class="nowrap right" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye, $objp->statut, 5, $objp->am)).'</td>'; 1254 print "</tr>\n"; 1255 $i++; 1256 } 1257 $db->free($resql); 1258 1259 if ($num > 0) 1260 { 1261 print "</table>"; 1262 print '</div>'; 1263 } 1264 } else { 1265 dol_print_error($db); 1266 } 1267 } 1268 1269 print '</div></div></div>'; 1270 print '<div style="clear:both"></div>'; 1271 1272 print dol_get_fiche_end(); 1273 1274 1275 /* 1276 * Barre d'actions 1277 */ 1278 1279 print '<div class="tabsAction">'; 1280 1281 $parameters = array(); 1282 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been 1283 1284 if (empty($reshook)) 1285 { 1286 if ($object->status != 1) 1287 { 1288 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>'; 1289 } 1290 1291 if (!empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status == 1) 1292 { 1293 $langs->load("propal"); 1294 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/propal/card.php?socid='.$object->id.'&action=create">'.$langs->trans("AddProp").'</a></div>'; 1295 } 1296 1297 if (!empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status == 1) 1298 { 1299 $langs->load("orders"); 1300 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/card.php?socid='.$object->id.'&action=create">'.$langs->trans("AddOrder").'</a></div>'; 1301 } 1302 1303 if ($user->rights->contrat->creer && $object->status == 1) 1304 { 1305 $langs->load("contracts"); 1306 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/contrat/card.php?socid='.$object->id.'&action=create">'.$langs->trans("AddContract").'</a></div>'; 1307 } 1308 1309 if (!empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status == 1) 1310 { 1311 $langs->load("fichinter"); 1312 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/fichinter/card.php?socid='.$object->id.'&action=create">'.$langs->trans("AddIntervention").'</a></div>'; 1313 } 1314 1315 // Add invoice 1316 if ($user->socid == 0) 1317 { 1318 if (!empty($conf->deplacement->enabled) && $object->status == 1) 1319 { 1320 $langs->load("trips"); 1321 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/deplacement/card.php?socid='.$object->id.'&action=create">'.$langs->trans("AddTrip").'</a></div>'; 1322 } 1323 1324 if (!empty($conf->facture->enabled) && $object->status == 1) 1325 { 1326 if (empty($user->rights->facture->creer)) 1327 { 1328 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>'; 1329 } else { 1330 $langs->loadLangs(array("orders", "bills")); 1331 1332 if (!empty($conf->commande->enabled)) 1333 { 1334 if ($object->client != 0 && $object->client != 2) { 1335 if (!empty($orders2invoice) && $orders2invoice > 0) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/commande/list.php?socid='.$object->id.'&search_billed=0&autoselectall=1">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>'; 1336 else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>'; 1337 } else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>'; 1338 } 1339 1340 if ($object->client != 0 && $object->client != 2) print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/compta/facture/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddBill").'</a></div>'; 1341 else print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>'; 1342 } 1343 } 1344 } 1345 1346 // Add action 1347 if (!empty($conf->agenda->enabled) && !empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status == 1) 1348 { 1349 if ($user->rights->agenda->myactions->create) 1350 { 1351 print '<div class="inline-block divButAction"><a class="butAction" href="'.DOL_URL_ROOT.'/comm/action/card.php?action=create&socid='.$object->id.'">'.$langs->trans("AddAction").'</a></div>'; 1352 } else { 1353 print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>'; 1354 } 1355 } 1356 } 1357 1358 print '</div>'; 1359 1360 if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_CUSTOMER_CARD)) 1361 { 1362 // List of contacts 1363 show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id); 1364 } 1365 1366 if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB)) 1367 { 1368 print load_fiche_titre($langs->trans("ActionsOnCompany"), '', ''); 1369 1370 // List of todo actions 1371 show_actions_todo($conf, $langs, $db, $object); 1372 1373 // List of done actions 1374 show_actions_done($conf, $langs, $db, $object); 1375 } 1376} else { 1377 $langs->load("errors"); 1378 print $langs->trans('ErrorRecordNotFound'); 1379} 1380 1381// End of page 1382llxFooter(); 1383$db->close(); 1384