1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450 |
- <?php
- /* Copyright (C) 2001-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
- * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
- * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
- * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
- * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
- * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
- * Copyright (C) 2010-2020 Juanjo Menent <jmenent@2byte.es>
- * Copyright (C) 2013 Alexandre Spangaro <aspangaro@open-dsi.fr>
- * Copyright (C) 2015-2021 Frédéric France <frederic.france@netlogic.fr>
- * Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
- * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
- *
- * 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 3 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, see <https://www.gnu.org/licenses/>.
- */
- /**
- * \file htdocs/comm/card.php
- * \ingroup commercial compta
- * \brief Page to show customer card of a third party
- */
- require '../main.inc.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
- require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
- require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
- require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
- require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
- if (!empty($conf->facture->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
- }
- if (!empty($conf->facture->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
- }
- if (!empty($conf->propal->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
- }
- if (!empty($conf->commande->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
- }
- if (!empty($conf->expedition->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
- }
- if (!empty($conf->contrat->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
- }
- if (!empty($conf->adherent->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
- }
- if (!empty($conf->ficheinter->enabled)) {
- require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
- }
- // Load translation files required by the page
- $langs->loadLangs(array('companies', 'banks'));
- if (!empty($conf->contrat->enabled)) {
- $langs->load("contracts");
- }
- if (!empty($conf->commande->enabled)) {
- $langs->load("orders");
- }
- if (!empty($conf->expedition->enabled)) {
- $langs->load("sendings");
- }
- if (!empty($conf->facture->enabled)) {
- $langs->load("bills");
- }
- if (!empty($conf->projet->enabled)) {
- $langs->load("projects");
- }
- if (!empty($conf->ficheinter->enabled)) {
- $langs->load("interventions");
- }
- if (!empty($conf->notification->enabled)) {
- $langs->load("mails");
- }
- $action = GETPOST('action', 'aZ09');
- $id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int'));
- $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
- $sortfield = GETPOST('sortfield', 'aZ09comma');
- $sortorder = GETPOST('sortorder', 'aZ09comma');
- $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
- if (empty($page) || $page == -1) {
- $page = 0;
- } // If $page is not defined, or '' or -1
- $offset = $limit * $page;
- $pageprev = $page - 1;
- $pagenext = $page + 1;
- if (!$sortorder) {
- $sortorder = "ASC";
- }
- if (!$sortfield) {
- $sortfield = "nom";
- }
- $cancel = GETPOST('cancel', 'alpha');
- $object = new Client($db);
- $extrafields = new ExtraFields($db);
- // fetch optionals attributes and labels
- $extrafields->fetch_name_optionals_label($object->table_element);
- // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
- $hookmanager->initHooks(array('thirdpartycomm', 'globalcard'));
- $now = dol_now();
- if ($id > 0 && empty($object->id)) {
- // Load data of third party
- $res = $object->fetch($id);
- if ($object->id < 0) {
- dol_print_error($db, $object->error, $object->errors);
- }
- }
- if ($object->id > 0) {
- if (!($object->client > 0) || empty($user->rights->societe->lire)) {
- accessforbidden();
- }
- }
- // Security check
- if ($user->socid > 0) {
- $id = $user->socid;
- }
- $result = restrictedArea($user, 'societe', $object->id, '&societe', '', 'fk_soc', 'rowid', 0);
- /*
- * Actions
- */
- $parameters = array('id' => $id, 'socid' => $id);
- $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some
- if ($reshook < 0) {
- setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
- }
- if (empty($reshook)) {
- if ($cancel) {
- $action = "";
- }
- // set accountancy code
- if ($action == 'setcustomeraccountancycode') {
- $result = $object->fetch($id);
- $object->code_compta = GETPOST("customeraccountancycode");
- $result = $object->update($object->id, $user, 1, 1, 0);
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // terms of the settlement
- if ($action == 'setconditions' && $user->rights->societe->creer) {
- $object->fetch($id);
- $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // mode de reglement
- if ($action == 'setmode' && $user->rights->societe->creer) {
- $object->fetch($id);
- $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // transport mode
- if ($action == 'settransportmode' && $user->rights->societe->creer) {
- $object->fetch($id);
- $result = $object->setTransportMode(GETPOST('transport_mode_id', 'alpha'));
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // Bank account
- if ($action == 'setbankaccount' && $user->rights->societe->creer) {
- $object->fetch($id);
- $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // customer preferred shipping method
- if ($action == 'setshippingmethod' && $user->rights->societe->creer) {
- $object->fetch($id);
- $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int'));
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // assujetissement a la TVA
- if ($action == 'setassujtva' && $user->rights->societe->creer) {
- $object->fetch($id);
- $object->tva_assuj = $_POST['assujtva_value'];
- $result = $object->update($object->id);
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // set prospect level
- if ($action == 'setprospectlevel' && $user->rights->societe->creer) {
- $object->fetch($id);
- $object->fk_prospectlevel = GETPOST('prospect_level_id', 'alpha');
- $result = $object->update($object->id, $user);
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // set communication status
- if ($action == 'setstcomm') {
- $object->fetch($id);
- $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcomm');
- $result = $object->update($object->id, $user);
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- } else {
- $result = $object->fetch($object->id);
- }
- }
- // update outstandng limit
- if ($action == 'setoutstanding_limit') {
- $object->fetch($id);
- $object->outstanding_limit = GETPOST('outstanding_limit');
- $result = $object->update($object->id, $user);
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // update order min amount
- if ($action == 'setorder_min_amount') {
- $object->fetch($id);
- $object->order_min_amount = price2num(GETPOST('order_min_amount', 'alpha'));
- $result = $object->update($object->id, $user);
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- }
- }
- // Set sales representatives
- if ($action == 'set_salesrepresentatives' && $user->rights->societe->creer) {
- $object->fetch($id);
- $result = $object->setSalesRep(GETPOST('commercial', 'array'));
- }
- if ($action == 'update_extras') {
- $object->fetch($id);
- $object->oldcopy = dol_clone($object);
- // Fill array 'array_options' with data from update form
- $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
- if ($ret < 0) {
- $error++;
- }
- if (!$error) {
- $result = $object->insertExtraFields('COMPANY_MODIFY');
- if ($result < 0) {
- setEventMessages($object->error, $object->errors, 'errors');
- $error++;
- }
- }
- if ($error) {
- $action = 'edit_extras';
- }
- }
- // warehouse
- if ($action == 'setwarehouse' && $user->rights->societe->creer) {
- $result = $object->setWarehouse(GETPOST('fk_warehouse', 'int'));
- }
- }
- /*
- * View
- */
- $contactstatic = new Contact($db);
- $userstatic = new User($db);
- $form = new Form($db);
- $formcompany = new FormCompany($db);
- $title = $langs->trans("ThirdParty")." - ".$langs->trans('Customer');
- if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
- $title = $object->name." - ".$langs->trans('Customer');
- }
- $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas|DE:Modul_Geschäftspartner';
- llxHeader('', $title, $help_url);
- if ($object->id > 0) {
- $head = societe_prepare_head($object);
- print dol_get_fiche_head($head, 'customer', $langs->trans("ThirdParty"), -1, 'company');
- $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
- dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');
- print '<div class="fichecenter"><div class="fichehalfleft">';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border centpercent tableforfield">';
- // Type Prospect/Customer/Supplier
- print '<tr><td class="titlefield">'.$langs->trans('NatureOfThirdParty').'</td><td>';
- print $object->getTypeUrl(1);
- print '</td></tr>';
- // Prefix
- if (!empty($conf->global->SOCIETE_USEPREFIX)) { // Old not used prefix field
- print '<tr><td>'.$langs->trans("Prefix").'</td><td>';
- print ($object->prefix_comm ? $object->prefix_comm : ' ');
- print '</td></tr>';
- }
- if ($object->client) {
- $langs->load("compta");
- print '<tr><td>';
- print $langs->trans('CustomerCode').'</td><td>';
- print showValueWithClipboardCPButton(dol_escape_htmltag($object->code_client));
- $tmpcheck = $object->check_codeclient();
- if ($tmpcheck != 0 && $tmpcheck != -5) {
- print ' <span class="error">('.$langs->trans("WrongCustomerCode").')</span>';
- }
- print '</td></tr>';
- print '<tr>';
- print '<td>';
- print $form->editfieldkey("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer);
- print '</td><td>';
- print $form->editfieldval("CustomerAccountancyCode", 'customeraccountancycode', $object->code_compta, $object, $user->rights->societe->creer);
- print '</td>';
- print '</tr>';
- }
- // 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.
- // We don't need them into customer profile.
- // Except for spain and localtax where localtax depends on buyer and not seller
- // VAT is used
- /*
- print '<tr>';
- print '<td class="nowrap">';
- print $form->textwithpicto($langs->trans('VATIsUsed'),$langs->trans('VATIsUsedWhenSelling'));
- print '</td>';
- print '<td>';
- print yn($object->tva_assuj);
- print '</td>';
- print '</tr>';
- */
- if ($mysoc->country_code == 'ES') {
- // Local Taxes
- if ($mysoc->localtax1_assuj == "1") {
- print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).'</td><td>';
- print yn($object->localtax1_assuj);
- print '</td></tr>';
- }
- if ($mysoc->localtax1_assuj == "1") {
- print '<tr><td class="nowrap">'.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).'</td><td>';
- print yn($object->localtax2_assuj);
- print '</td></tr>';
- }
- }
- // TVA Intra
- print '<tr><td class="nowrap">'.$langs->trans('VATIntra').'</td><td>';
- print showValueWithClipboardCPButton(dol_escape_htmltag($object->tva_intra));
- print '</td></tr>';
- // default terms of the settlement
- $langs->load('bills');
- print '<tr><td>';
- print '<table width="100%" class="nobordernopadding"><tr><td>';
- print $langs->trans('PaymentConditions');
- print '<td>';
- if (($action != 'editconditions') && $user->rights->societe->creer) {
- print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'editconditions') {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'cond_reglement_id', 1);
- } else {
- $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->cond_reglement_id, 'none');
- }
- print "</td>";
- print '</tr>';
- // Mode de reglement par defaut
- print '<tr><td class="nowrap">';
- print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans('PaymentMode');
- print '<td>';
- if (($action != 'editmode') && $user->rights->societe->creer) {
- print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'editmode') {
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
- } else {
- $form->form_modes_reglement($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->mode_reglement_id, 'none');
- }
- print "</td>";
- print '</tr>';
- if (!empty($conf->banque->enabled)) {
- // Compte bancaire par défaut
- print '<tr><td class="nowrap">';
- print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans('PaymentBankAccount');
- print '<td>';
- if (($action != 'editbankaccount') && $user->rights->societe->creer) {
- print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'editbankaccount') {
- $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_account, 'fk_account', 1);
- } else {
- $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_account, 'none');
- }
- print "</td>";
- print '</tr>';
- }
- $isCustomer = ($object->client == 1 || $object->client == 3);
- // Relative discounts (Discounts-Drawbacks-Rebates)
- if ($isCustomer) {
- print '<tr><td class="nowrap">';
- print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans("CustomerRelativeDiscountShort");
- print '<td><td class="right">';
- if ($user->rights->societe->creer && !$user->socid > 0) {
- print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'&action=create&token='.newToken().'">'.img_edit($langs->trans("Modify")).'</a>';
- }
- print '</td></tr></table>';
- print '</td><td>'.($object->remise_percent ? '<a href="'.DOL_URL_ROOT.'/comm/remise.php?id='.$object->id.'">'.$object->remise_percent.'%</a>' : '').'</td>';
- print '</tr>';
- // Absolute discounts (Discounts-Drawbacks-Rebates)
- print '<tr><td class="nowrap">';
- print '<table width="100%" class="nobordernopadding">';
- print '<tr><td class="nowrap">';
- print $langs->trans("CustomerAbsoluteDiscountShort");
- print '<td><td class="right">';
- if ($user->rights->societe->creer && !$user->socid > 0) {
- print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'&action=create&token='.newToken().'">'.img_edit($langs->trans("Modify")).'</a>';
- }
- print '</td></tr></table>';
- print '</td>';
- print '<td>';
- $amount_discount = $object->getAvailableDiscounts();
- if ($amount_discount < 0) {
- dol_print_error($db, $object->error);
- }
- if ($amount_discount > 0) {
- print '<a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$object->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"].'?socid='.$object->id).'&action=create&token='.newToken().'">'.price($amount_discount, 1, $langs, 1, -1, -1, $conf->currency).'</a>';
- }
- //else print $langs->trans("DiscountNone");
- print '</td>';
- print '</tr>';
- }
- // Max outstanding bill
- if ($object->client) {
- print '<tr class="nowrap">';
- print '<td>';
- print $form->editfieldkey("OutstandingBill", 'outstanding_limit', $object->outstanding_limit, $object, $user->rights->societe->creer);
- print '</td><td>';
- $limit_field_type = (!empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount';
- print $form->editfieldval("OutstandingBill", 'outstanding_limit', $object->outstanding_limit, $object, $user->rights->societe->creer, $limit_field_type, ($object->outstanding_limit != '' ? price($object->outstanding_limit) : ''));
- print '</td>';
- print '</tr>';
- }
- if ($object->client) {
- if (!empty($conf->commande->enabled) && !empty($conf->global->ORDER_MANAGE_MIN_AMOUNT)) {
- print '<!-- Minimim amount for orders -->'."\n";
- print '<tr class="nowrap">';
- print '<td>';
- print $form->editfieldkey("OrderMinAmount", 'order_min_amount', $object->order_min_amount, $object, $user->rights->societe->creer);
- print '</td><td>';
- 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) : ''));
- print '</td>';
- print '</tr>';
- }
- }
- // Multiprice level
- if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) {
- print '<tr><td class="nowrap">';
- print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans("PriceLevel");
- print '<td><td class="right">';
- if ($user->rights->societe->creer) {
- print '<a class="editfielda" href="'.DOL_URL_ROOT.'/comm/multiprix.php?id='.$object->id.'">'.img_edit($langs->trans("Modify")).'</a>';
- }
- print '</td></tr></table>';
- print '</td><td>';
- print $object->price_level;
- $keyforlabel = 'PRODUIT_MULTIPRICES_LABEL'.$object->price_level;
- if (!empty($conf->global->$keyforlabel)) {
- print ' - '.$langs->trans($conf->global->$keyforlabel);
- }
- print "</td>";
- print '</tr>';
- }
- // Warehouse
- if (!empty($conf->stock->enabled) && !empty($conf->global->SOCIETE_ASK_FOR_WAREHOUSE)) {
- $langs->load('stocks');
- require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
- $formproduct = new FormProduct($db);
- print '<tr class="nowrap">';
- print '<td>';
- print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $user->rights->societe->creer);
- print '</td><td>';
- if ($action == 'editwarehouse') {
- $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'fk_warehouse', 1);
- } else {
- if ($object->fk_warehouse > 0) {
- print img_picto('', 'stock', 'class="paddingrightonly"');
- }
- $formproduct->formSelectWarehouses($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_warehouse, 'none');
- }
- print '</td>';
- print '</tr>';
- }
- // Preferred shipping Method
- if (!empty($conf->global->SOCIETE_ASK_FOR_SHIPPING_METHOD)) {
- print '<tr><td class="nowrap">';
- print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans('SendingMethod');
- print '<td>';
- if (($action != 'editshipping') && $user->rights->societe->creer) {
- print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editshipping&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'editshipping') {
- $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->shipping_method_id, 'shipping_method_id', 1);
- } else {
- $form->formSelectShippingMethod($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->shipping_method_id, 'none');
- }
- print "</td>";
- print '</tr>';
- }
- if (!empty($conf->intracommreport->enabled)) {
- // Transport mode by default
- print '<tr><td class="nowrap">';
- print '<table class="centpercent nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans('IntracommReportTransportMode');
- print '<td>';
- if (($action != 'edittransportmode') && $user->rights->societe->creer) {
- print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edittransportmode&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'edittransportmode') {
- $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?socid='.$object->id, (!empty($object->transport_mode_id) ? $object->transport_mode_id : ''), 'transport_mode_id', 1);
- } else {
- $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?socid='.$object->id, (!empty($object->transport_mode_id) ? $object->transport_mode_id : ''), 'none');
- }
- print "</td>";
- print '</tr>';
- }
- // Categories
- if (!empty($conf->categorie->enabled) && !empty($user->rights->categorie->lire)) {
- $langs->load("categories");
- print '<tr><td>'.$langs->trans("CustomersCategoriesShort").'</td>';
- print '<td>';
- print $form->showCategories($object->id, Categorie::TYPE_CUSTOMER, 1);
- print "</td></tr>";
- }
- // Other attributes
- $parameters = array('socid'=>$object->id);
- include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
- // Sales representative
- include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php';
- // Module Adherent
- if (!empty($conf->adherent->enabled)) {
- $langs->load("members");
- $langs->load("users");
- print '<tr><td class="titlefield">'.$langs->trans("LinkedToDolibarrMember").'</td>';
- print '<td>';
- $adh = new Adherent($db);
- $result = $adh->fetch('', '', $object->id);
- if ($result > 0) {
- $adh->ref = $adh->getFullName($langs);
- print $adh->getNomUrl(-1);
- } else {
- print '<span class="opacitymedium">'.$langs->trans("ThirdpartyNotLinkedToMember").'</span>';
- }
- print '</td>';
- print "</tr>\n";
- }
- print "</table>";
- // Prospection level and status
- if ($object->client == 2 || $object->client == 3) {
- print '<br>';
- print '<div class="underbanner clearboth"></div>';
- print '<table class="border centpercent tableforfield">';
- // Level of prospection
- print '<tr><td class="titlefield nowrap">';
- print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
- print $langs->trans('ProspectLevel');
- print '<td>';
- if ($action != 'editlevel' && $user->rights->societe->creer) {
- print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editlevel&token='.newToken().'&socid='.$object->id.'">'.img_edit($langs->trans('Modify'), 1).'</a></td>';
- }
- print '</tr></table>';
- print '</td><td>';
- if ($action == 'editlevel') {
- $formcompany->form_prospect_level($_SERVER['PHP_SELF'].'?socid='.$object->id, $object->fk_prospectlevel, 'prospect_level_id', 1);
- } else {
- print $object->getLibProspLevel();
- }
- print "</td>";
- print '</tr>';
- // Status of prospection
- $object->loadCacheOfProspStatus();
- print '<tr><td>'.$langs->trans("StatusProsp").'</td><td>'.$object->getLibProspCommStatut(4, $object->cacheprospectstatus[$object->stcomm_id]['label']);
- print ' ';
- print '<div class="floatright">';
- foreach ($object->cacheprospectstatus as $key => $val) {
- $titlealt = 'default';
- if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
- $titlealt = $val['label'];
- }
- 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>';
- }
- }
- print '</div></td></tr>';
- print "</table>";
- }
- print '</div><div class="fichehalfright">';
- print '<div class="underbanner clearboth"></div>';
- $boxstat = '';
- // Nbre max d'elements des petites listes
- $MAXLIST = $conf->global->MAIN_SIZE_SHORTLIST_LIMIT;
- // Lien recap
- $boxstat .= '<div class="box">';
- $boxstat .= '<table summary="'.dol_escape_htmltag($langs->trans("DolibarrStateBoard")).'" class="border boxtable boxtablenobottom boxtablenotop" width="100%">';
- $boxstat .= '<tr class="impair nohover"><td colspan="2" class="tdboxstats nohover">';
- if (!empty($conf->propal->enabled) && $user->rights->propal->lire) {
- // Box proposals
- $tmp = $object->getOutstandingProposals();
- $outstandingOpened = $tmp['opened'];
- $outstandingTotal = $tmp['total_ht'];
- $outstandingTotalIncTax = $tmp['total_ttc'];
- $text = $langs->trans("OverAllProposals");
- $link = DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id;
- $icon = 'bill';
- if ($link) {
- $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
- }
- $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
- $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
- $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
- $boxstat .= '</div>';
- if ($link) {
- $boxstat .= '</a>';
- }
- }
- if (!empty($conf->commande->enabled) && $user->rights->commande->lire) {
- // Box commandes
- $tmp = $object->getOutstandingOrders();
- $outstandingOpened = $tmp['opened'];
- $outstandingTotal = $tmp['total_ht'];
- $outstandingTotalIncTax = $tmp['total_ttc'];
- $text = $langs->trans("OverAllOrders");
- $link = DOL_URL_ROOT.'/commande/list.php?socid='.$object->id;
- $icon = 'bill';
- if ($link) {
- $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
- }
- $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
- $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
- $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
- $boxstat .= '</div>';
- if ($link) {
- $boxstat .= '</a>';
- }
- }
- if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
- // Box factures
- $tmp = $object->getOutstandingBills('customer', 0);
- $outstandingOpened = $tmp['opened'];
- $outstandingTotal = $tmp['total_ht'];
- $outstandingTotalIncTax = $tmp['total_ttc'];
- $text = $langs->trans("OverAllInvoices");
- $link = DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id;
- $icon = 'bill';
- if ($link) {
- $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
- }
- $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
- $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
- $boxstat .= '<span class="boxstatsindicator">'.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).'</span>';
- $boxstat .= '</div>';
- if ($link) {
- $boxstat .= '</a>';
- }
- // Box outstanding bill
- $warn = '';
- if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened) {
- $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
- }
- $text = $langs->trans("CurrentOutstandingBill");
- $link = DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
- $icon = 'bill';
- if ($link) {
- $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
- }
- $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
- $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
- $boxstat .= '<span class="boxstatsindicator'.($outstandingOpened > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpened, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
- $boxstat .= '</div>';
- if ($link) {
- $boxstat .= '</a>';
- }
- $tmp = $object->getOutstandingBills('customer', 1);
- $outstandingOpenedLate = $tmp['opened'];
- if ($outstandingOpened != $outstandingOpenedLate && !empty($outstandingOpenedLate)) {
- $warn = '';
- if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpenedLate) {
- $warn = ' '.img_warning($langs->trans("OutstandingBillReached"));
- }
- $text = $langs->trans("CurrentOutstandingBillLate");
- $link = DOL_URL_ROOT.'/compta/recap-compta.php?socid='.$object->id;
- $icon = 'bill';
- if ($link) {
- $boxstat .= '<a href="'.$link.'" class="boxstatsindicator thumbstat nobold nounderline">';
- }
- $boxstat .= '<div class="boxstats" title="'.dol_escape_htmltag($text).'">';
- $boxstat .= '<span class="boxstatstext">'.img_object("", $icon).' <span>'.$text.'</span></span><br>';
- $boxstat .= '<span class="boxstatsindicator'.($outstandingOpenedLate > 0 ? ' amountremaintopay' : '').'">'.price($outstandingOpenedLate, 1, $langs, 1, -1, -1, $conf->currency).$warn.'</span>';
- $boxstat .= '</div>';
- if ($link) {
- $boxstat .= '</a>';
- }
- }
- }
- $parameters = array();
- $reshook = $hookmanager->executeHooks('addMoreBoxStatsCustomer', $parameters, $object, $action);
- if (empty($reshook)) {
- $boxstat .= $hookmanager->resPrint;
- }
- $boxstat .= '</td></tr>';
- $boxstat .= '</table>';
- $boxstat .= '</div>';
- print $boxstat;
- /*
- * Latest proposals
- */
- if (!empty($conf->propal->enabled) && $user->rights->propal->lire) {
- $langs->load("propal");
- $sql = "SELECT s.nom, s.rowid, p.rowid as propalid, p.fk_statut, p.total_ht";
- $sql .= ", p.total_tva";
- $sql .= ", p.total_ttc";
- $sql .= ", p.ref, p.ref_client, p.remise";
- $sql .= ", p.datep as dp, p.fin_validite as date_limit";
- $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c";
- $sql .= " WHERE p.fk_soc = s.rowid AND p.fk_statut = c.id";
- $sql .= " AND s.rowid = ".((int) $object->id);
- $sql .= " AND p.entity IN (".getEntity('propal').")";
- $sql .= " ORDER BY p.datep DESC";
- $resql = $db->query($sql);
- if ($resql) {
- $propal_static = new Propal($db);
- $num = $db->num_rows($resql);
- if ($num > 0) {
- print '<div class="div-table-responsive-no-min">';
- print '<table class="noborder centpercent lastrecordtable">';
- print '<tr class="liste_titre">';
- 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>';
- 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>';
- print '</tr></table></td>';
- print '</tr>';
- }
- $i = 0;
- while ($i < $num && $i < $MAXLIST) {
- $objp = $db->fetch_object($resql);
- print '<tr class="oddeven">';
- print '<td class="nowraponall">';
- $propal_static->id = $objp->propalid;
- $propal_static->ref = $objp->ref;
- $propal_static->ref_client = $objp->ref_client;
- $propal_static->total_ht = $objp->total_ht;
- $propal_static->total_tva = $objp->total_tva;
- $propal_static->total_ttc = $objp->total_ttc;
- print $propal_static->getNomUrl(1);
- if (($db->jdate($objp->date_limit) < ($now - $conf->propal->cloture->warning_delay)) && $objp->fk_statut == $propal_static::STATUS_VALIDATED) {
- print " ".img_warning();
- }
- print '</td><td class="right" width="80px">'.dol_print_date($db->jdate($objp->dp), 'day')."</td>\n";
- print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
- print '<td class="right" style="min-width: 60px" class="nowrap">'.$propal_static->LibStatut($objp->fk_statut, 5).'</td></tr>';
- $i++;
- }
- $db->free($resql);
- if ($num > 0) {
- print "</table>";
- print '</div>';
- }
- } else {
- dol_print_error($db);
- }
- }
- /*
- * Latest orders
- */
- if (!empty($conf->commande->enabled) && $user->rights->commande->lire) {
- $sql = "SELECT s.nom, s.rowid";
- $sql .= ", c.rowid as cid, c.total_ht";
- $sql .= ", c.total_tva";
- $sql .= ", c.total_ttc";
- $sql .= ", c.ref, c.ref_client, c.fk_statut, c.facture";
- $sql .= ", c.date_commande as dc";
- $sql .= ", c.facture as billed";
- $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c";
- $sql .= " WHERE c.fk_soc = s.rowid ";
- $sql .= " AND s.rowid = ".((int) $object->id);
- $sql .= " AND c.entity IN (".getEntity('commande').')';
- $sql .= " ORDER BY c.date_commande DESC";
- $resql = $db->query($sql);
- if ($resql) {
- $commande_static = new Commande($db);
- $num = $db->num_rows($resql);
- if ($num > 0) {
- // Check if there are orders billable
- $sql2 = 'SELECT s.nom, s.rowid as socid, s.client, c.rowid, c.ref, c.total_ht, c.ref_client,';
- $sql2 .= ' c.date_valid, c.date_commande, c.date_livraison, c.fk_statut, c.facture as billed';
- $sql2 .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
- $sql2 .= ', '.MAIN_DB_PREFIX.'commande as c';
- $sql2 .= ' WHERE c.fk_soc = s.rowid';
- $sql2 .= ' AND s.rowid = '.((int) $object->id);
- // Show orders with status validated, shipping started and delivered (well any order we can bill)
- $sql2 .= " AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))";
- $resql2 = $db->query($sql2);
- $orders2invoice = $db->num_rows($resql2);
- $db->free($resql2);
- print '<div class="div-table-responsive-no-min">';
- print '<table class="noborder centpercent lastrecordtable">';
- print '<tr class="liste_titre">';
- 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>';
- 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>';
- print '</tr></table></td>';
- print '</tr>';
- }
- $i = 0;
- while ($i < $num && $i < $MAXLIST) {
- $objp = $db->fetch_object($resql);
- $commande_static->id = $objp->cid;
- $commande_static->ref = $objp->ref;
- $commande_static->ref_client = $objp->ref_client;
- $commande_static->total_ht = $objp->total_ht;
- $commande_static->total_tva = $objp->total_tva;
- $commande_static->total_ttc = $objp->total_ttc;
- $commande_static->billed = $objp->billed;
- print '<tr class="oddeven">';
- print '<td class="nowraponall">';
- print $commande_static->getNomUrl(1);
- print '</td><td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day')."</td>\n";
- print '<td class="right" style="min-width: 60px">'.price($objp->total_ht).'</td>';
- print '<td class="right" style="min-width: 60px" class="nowrap">'.$commande_static->LibStatut($objp->fk_statut, $objp->facture, 5).'</td></tr>';
- $i++;
- }
- $db->free($resql);
- if ($num > 0) {
- print "</table>";
- print '</div>';
- }
- } else {
- dol_print_error($db);
- }
- }
- /*
- * Latest shipments
- */
- if (!empty($conf->expedition->enabled) && $user->rights->expedition->lire) {
- $sql = 'SELECT e.rowid as id';
- $sql .= ', e.ref';
- $sql .= ', e.date_creation';
- $sql .= ', e.fk_statut as statut';
- $sql .= ', s.nom';
- $sql .= ', s.rowid as socid';
- $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e";
- $sql .= " WHERE e.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
- $sql .= " AND e.entity IN (".getEntity('expedition').")";
- $sql .= ' GROUP BY e.rowid';
- $sql .= ', e.ref';
- $sql .= ', e.date_creation';
- $sql .= ', e.fk_statut';
- $sql .= ', s.nom';
- $sql .= ', s.rowid';
- $sql .= " ORDER BY e.date_creation DESC";
- $resql = $db->query($sql);
- if ($resql) {
- $sendingstatic = new Expedition($db);
- $num = $db->num_rows($resql);
- if ($num > 0) {
- print '<div class="div-table-responsive-no-min">';
- print '<table class="noborder centpercent lastrecordtable">';
- print '<tr class="liste_titre">';
- 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>';
- 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>';
- print '</tr></table></td>';
- print '</tr>';
- }
- $i = 0;
- while ($i < $num && $i < $MAXLIST) {
- $objp = $db->fetch_object($resql);
- $sendingstatic->id = $objp->id;
- $sendingstatic->ref = $objp->ref;
- print '<tr class="oddeven">';
- print '<td class="nowraponall">';
- print $sendingstatic->getNomUrl(1);
- print '</td>';
- if ($objp->date_creation > 0) {
- print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_creation), 'day').'</td>';
- } else {
- print '<td class="right"><b>!!!</b></td>';
- }
- print '<td class="nowrap right" width="100" >'.$sendingstatic->LibStatut($objp->statut, 5).'</td>';
- print "</tr>\n";
- $i++;
- }
- $db->free($resql);
- if ($num > 0) {
- print "</table>";
- print '</div>';
- }
- } else {
- dol_print_error($db);
- }
- }
- /*
- * Latest contracts
- */
- if (!empty($conf->contrat->enabled) && $user->rights->contrat->lire) {
- $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";
- $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c";
- $sql .= " WHERE c.fk_soc = s.rowid ";
- $sql .= " AND s.rowid = ".((int) $object->id);
- $sql .= " AND c.entity IN (".getEntity('contract').")";
- $sql .= " ORDER BY c.datec DESC";
- $resql = $db->query($sql);
- if ($resql) {
- $contrat = new Contrat($db);
- $num = $db->num_rows($resql);
- if ($num > 0) {
- print '<div class="div-table-responsive-no-min">';
- print '<table class="noborder centpercent lastrecordtable">';
- print '<tr class="liste_titre">';
- print '<td colspan="5"><table width="100%" class="nobordernopadding"><tr><td>'.$langs->trans("LastContracts", ($num <= $MAXLIST ? "" : $MAXLIST)).'</td>';
- 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>';
- //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>';
- print '</tr></table></td>';
- print '</tr>';
- }
- $i = 0;
- while ($i < $num && $i < $MAXLIST) {
- $objp = $db->fetch_object($resql);
- $contrat->id = $objp->id;
- $contrat->ref = $objp->ref ? $objp->ref : $objp->id;
- $contrat->ref_customer = $objp->refcus;
- $contrat->ref_supplier = $objp->refsup;
- $contrat->statut = $objp->contract_status;
- $contrat->fetch_lines();
- $late = '';
- foreach ($contrat->lines as $line) {
- if ($contrat->statut == Contrat::STATUS_VALIDATED && $line->statut == ContratLigne::STATUS_OPEN) {
- if (((!empty($line->date_fin_validite) ? $line->date_fin_validite : 0) + $conf->contrat->services->expires->warning_delay) < $now) {
- $late = img_warning($langs->trans("Late"));
- }
- }
- }
- print '<tr class="oddeven">';
- print '<td class="nowraponall">';
- print $contrat->getNomUrl(1, 12);
- print $late;
- print "</td>\n";
- print '<td class="nowrap">'.dol_trunc($objp->refsup, 12)."</td>\n";
- //print '<td class="right" width="80px"><span title="'.$langs->trans("DateCreation").'">'.dol_print_date($db->jdate($objp->dc), 'day')."</span></td>\n";
- print '<td class="right" width="80px"><span title="'.$langs->trans("DateContract").'">'.dol_print_date($db->jdate($objp->dcon), 'day')."</span></td>\n";
- print '<td width="20"> </td>';
- print '<td class="nowraponall right">';
- print $contrat->getLibStatut(4);
- print "</td>\n";
- print '</tr>';
- $i++;
- }
- $db->free($resql);
- if ($num > 0) {
- print "</table>";
- print '</div>';
- }
- } else {
- dol_print_error($db);
- }
- }
- /*
- * Latest interventions
- */
- if (!empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire) {
- $sql = "SELECT s.nom, s.rowid, f.rowid as id, f.ref, f.fk_statut, f.duree as duration, f.datei as startdate";
- $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."fichinter as f";
- $sql .= " WHERE f.fk_soc = s.rowid";
- $sql .= " AND s.rowid = ".((int) $object->id);
- $sql .= " AND f.entity IN (".getEntity('intervention').")";
- $sql .= " ORDER BY f.tms DESC";
- $resql = $db->query($sql);
- if ($resql) {
- $fichinter_static = new Fichinter($db);
- $num = $db->num_rows($resql);
- if ($num > 0) {
- print '<div class="div-table-responsive-no-min">';
- print '<table class="noborder centpercent lastrecordtable">';
- print '<tr class="liste_titre">';
- 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>';
- 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>';
- print '</tr></table></td>';
- print '</tr>';
- }
- $i = 0;
- while ($i < $num && $i < $MAXLIST) {
- $objp = $db->fetch_object($resql);
- $fichinter_static->id = $objp->id;
- $fichinter_static->ref = $objp->ref;
- $fichinter_static->statut = $objp->fk_statut;
- print '<tr class="oddeven">';
- print '<td class="nowraponall">';
- print $fichinter_static->getNomUrl(1);
- print '</td>'."\n";
- //print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->startdate)).'</td>'."\n";
- print '<td class="right" style="min-width: 60px">'.convertSecondToTime($objp->duration).'</td>'."\n";
- print '<td class="nowrap right" style="min-width: 60px">'.$fichinter_static->getLibStatut(5).'</td>'."\n";
- print '</tr>';
- $i++;
- }
- $db->free($resql);
- if ($num > 0) {
- print "</table>";
- print '</div>';
- }
- } else {
- dol_print_error($db);
- }
- }
- /*
- * Latest invoices templates
- */
- if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
- $sql = 'SELECT f.rowid as id, f.titre as ref';
- $sql .= ', f.total_ht';
- $sql .= ', f.total_tva';
- $sql .= ', f.total_ttc';
- $sql .= ', f.datec as dc';
- $sql .= ', f.date_last_gen, f.date_when';
- $sql .= ', f.frequency';
- $sql .= ', f.unit_frequency';
- $sql .= ', f.suspended as suspended';
- $sql .= ', s.nom, s.rowid as socid';
- $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f";
- $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
- $sql .= " AND f.entity IN (".getEntity('invoice').")";
- $sql .= ' GROUP BY f.rowid, f.titre, f.total_ht, f.total_tva, f.total_ttc,';
- $sql .= ' f.date_last_gen, f.datec, f.frequency, f.unit_frequency,';
- $sql .= ' f.suspended, f.date_when,';
- $sql .= ' s.nom, s.rowid';
- $sql .= " ORDER BY f.date_last_gen, f.datec DESC";
- $resql = $db->query($sql);
- if ($resql) {
- $invoicetemplate = new FactureRec($db);
- $num = $db->num_rows($resql);
- if ($num > 0) {
- print '<div class="div-table-responsive-no-min">';
- print '<table class="noborder centpercent lastrecordtable">';
- print '<tr class="liste_titre">';
- 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>';
- print '</tr></table></td>';
- print '</tr>';
- }
- $i = 0;
- while ($i < $num && $i < $MAXLIST) {
- $objp = $db->fetch_object($resql);
- $invoicetemplate->id = $objp->id;
- $invoicetemplate->ref = $objp->ref;
- $invoicetemplate->suspended = $objp->suspended;
- $invoicetemplate->frequency = $objp->frequency;
- $invoicetemplate->unit_frequency = $objp->unit_frequency;
- $invoicetemplate->total_ht = $objp->total_ht;
- $invoicetemplate->total_tva = $objp->total_tva;
- $invoicetemplate->total_ttc = $objp->total_ttc;
- $invoicetemplate->date_last_gen = $objp->date_last_gen;
- $invoicetemplate->date_when = $objp->date_when;
- print '<tr class="oddeven">';
- print '<td class="nowrap">';
- print $invoicetemplate->getNomUrl(1);
- print '</td>';
- if ($objp->frequency && $objp->date_last_gen > 0) {
- print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->date_last_gen), 'day').'</td>';
- } else {
- if ($objp->dc > 0) {
- print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->dc), 'day').'</td>';
- } else {
- print '<td class="right"><b>!!!</b></td>';
- }
- }
- print '<td class="right" style="min-width: 60px">';
- print price($objp->total_ht);
- print '</td>';
- if (!empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES)) {
- print '<td class="right" style="min-width: 60px">';
- print price($objp->total_ttc);
- print '</td>';
- }
- print '<td class="nowrap right" style="min-width: 60px">';
- print $langs->trans('FrequencyPer_'.$invoicetemplate->unit_frequency, $invoicetemplate->frequency).' - ';
- print ($invoicetemplate->LibStatut($invoicetemplate->frequency, $invoicetemplate->suspended, 5, 0));
- print '</td>';
- print "</tr>\n";
- $i++;
- }
- $db->free($resql);
- if ($num > 0) {
- print "</table>";
- print '</div>';
- }
- } else {
- dol_print_error($db);
- }
- }
- /*
- * Latest invoices
- */
- if (!empty($conf->facture->enabled) && $user->rights->facture->lire) {
- $sql = 'SELECT f.rowid as facid, f.ref, f.type';
- $sql .= ', f.total_ht';
- $sql .= ', f.total_tva';
- $sql .= ', f.total_ttc';
- $sql .= ', f.datef as df, f.datec as dc, f.paye as paye, f.fk_statut as status';
- $sql .= ', s.nom, s.rowid as socid';
- $sql .= ', SUM(pf.amount) as am';
- $sql .= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture as f";
- $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON f.rowid=pf.fk_facture';
- $sql .= " WHERE f.fk_soc = s.rowid AND s.rowid = ".((int) $object->id);
- $sql .= " AND f.entity IN (".getEntity('invoice').")";
- $sql .= ' GROUP BY f.rowid, f.ref, f.type, f.total_ht, f.total_tva, f.total_ttc,';
- $sql .= ' f.datef, f.datec, f.paye, f.fk_statut,';
- $sql .= ' s.nom, s.rowid';
- $sql .= " ORDER BY f.datef DESC, f.datec DESC";
- $resql = $db->query($sql);
- if ($resql) {
- $facturestatic = new Facture($db);
- $num = $db->num_rows($resql);
- if ($num > 0) {
- print '<div class="div-table-responsive-no-min">';
- print '<table class="noborder centpercent lastrecordtable">';
- print '<tr class="liste_titre">';
- 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>';
- 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>';
- print '</tr></table></td>';
- print '</tr>';
- }
- $i = 0;
- while ($i < $num && $i < $MAXLIST) {
- $objp = $db->fetch_object($resql);
- $facturestatic->id = $objp->facid;
- $facturestatic->ref = $objp->ref;
- $facturestatic->type = $objp->type;
- $facturestatic->total_ht = $objp->total_ht;
- $facturestatic->total_tva = $objp->total_tva;
- $facturestatic->total_ttc = $objp->total_ttc;
- $facturestatic->statut = $objp->status;
- print '<tr class="oddeven">';
- print '<td class="nowraponall">';
- print $facturestatic->getNomUrl(1);
- print '</td>';
- if ($objp->df > 0) {
- print '<td class="right" width="80px">'.dol_print_date($db->jdate($objp->df), 'day').'</td>';
- } else {
- print '<td class="right"><b>!!!</b></td>';
- }
- print '<td class="right" style="min-width: 60px">';
- print price($objp->total_ht);
- print '</td>';
- if (!empty($conf->global->MAIN_SHOW_PRICE_WITH_TAX_IN_SUMMARIES)) {
- print '<td class="right" style="min-width: 60px">';
- print price($objp->total_ttc);
- print '</td>';
- }
- print '<td class="nowrap right" style="min-width: 60px">'.($facturestatic->LibStatut($objp->paye, $objp->status, 5, $objp->am)).'</td>';
- print "</tr>\n";
- $i++;
- }
- $db->free($resql);
- if ($num > 0) {
- print "</table>";
- print '</div>';
- }
- } else {
- dol_print_error($db);
- }
- }
- // Allow external modules to add their own shortlist of recent objects
- $parameters = array();
- $reshook = $hookmanager->executeHooks('addMoreRecentObjects', $parameters, $object, $action);
- if ($reshook < 0) {
- setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
- } else {
- print $hookmanager->resPrint;
- }
- print '</div></div>';
- print '<div style="clear:both"></div>';
- print dol_get_fiche_end();
- /*
- * Action bar
- */
- print '<div class="tabsAction">';
- $parameters = array();
- $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
- if (empty($reshook)) {
- if ($object->status != 1) {
- print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyIsClosed")).'" href="#">'.$langs->trans("ThirdPartyIsClosed").'</a></div>';
- }
- if (!empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status == 1) {
- $langs->load("propal");
- 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>';
- }
- if (!empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status == 1) {
- $langs->load("orders");
- 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>';
- }
- if (!empty($user->rights->contrat->creer) && $object->status == 1) {
- $langs->load("contracts");
- 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>';
- }
- if (!empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status == 1) {
- $langs->load("fichinter");
- 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>';
- }
- // Add invoice
- if ($user->socid == 0) {
- if (!empty($conf->deplacement->enabled) && $object->status == 1) {
- $langs->load("trips");
- 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>';
- }
- if (!empty($conf->facture->enabled) && $object->status == 1) {
- if (empty($user->rights->facture->creer)) {
- print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
- } else {
- $langs->loadLangs(array("orders", "bills"));
- if (!empty($conf->commande->enabled)) {
- if ($object->client != 0 && $object->client != 2) {
- 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>';
- } else {
- print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("NoOrdersToInvoice")).'" href="#">'.$langs->trans("CreateInvoiceForThisCustomer").'</a></div>';
- }
- } else {
- print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
- }
- }
- 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>';
- } else {
- print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" title="'.dol_escape_js($langs->trans("ThirdPartyMustBeEditAsCustomer")).'" href="#">'.$langs->trans("AddBill").'</a></div>';
- }
- }
- }
- }
- // Add action
- if (!empty($conf->agenda->enabled) && !empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status == 1) {
- if ($user->rights->agenda->myactions->create) {
- 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>';
- } else {
- print '<div class="inline-block divButAction"><a class="butAction" title="'.dol_escape_js($langs->trans("NotAllowed")).'" href="#">'.$langs->trans("AddAction").'</a></div>';
- }
- }
- }
- print '</div>';
- if (!empty($conf->global->MAIN_DUPLICATE_CONTACTS_TAB_ON_CUSTOMER_CARD)) {
- // List of contacts
- show_contacts($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id);
- }
- if (!empty($conf->global->MAIN_REPEATTASKONEACHTAB)) {
- print load_fiche_titre($langs->trans("ActionsOnCompany"), '', '');
- // List of todo actions
- show_actions_todo($conf, $langs, $db, $object);
- // List of done actions
- show_actions_done($conf, $langs, $db, $object);
- }
- } else {
- $langs->load("errors");
- print $langs->trans('ErrorRecordNotFound');
- }
- // End of page
- llxFooter();
- $db->close();
|