diff --git a/README-FR.md b/README-FR.md index 8d3d7f36aa9..3f1819f6370 100644 --- a/README-FR.md +++ b/README-FR.md @@ -21,8 +21,9 @@ vous devez vous réorienter vers DoliWamp (la version tout-en-un de Dolibarr pour Windows), DoliDeb (la version tout-en-un pour Debian ou Ubuntu) ou DoliRpm (la version tout-en-un de Dolibarr pour Fedora, Redhat, OpenSuse, Mandriva ou Mageia). -Vous pouvez les télécharger à l'adresse: -http://www.dolibarr.org/downloads/ + +Vous pouvez les télécharger depuis la rubrique *download* du portail officiel: +http://www.dolibarr.org/ Si vous avez déjà installé un serveur Web avec PHP et une base de donnée (Mysql), vous pouvez installer Dolibarr avec cette version de la manière suivante: diff --git a/README.md b/README.md index 93b9d275beb..b97c14501ab 100644 --- a/README.md +++ b/README.md @@ -15,7 +15,7 @@ Dolibarr is released under the terms of the GNU General Public License as publis If you have no technical knowledge, and you are looking for an autoinstaller to install Dolibarr ERP/CRM in few clicks, you must download DoliWamp (the all-in-one package of Dolibarr for Windows), DoliDeb (the all-in-one package of Dolibarr for Debian or Ubuntu) or DoliRpm (the all-in-one package of Dolibarr for Fedora, Redhat, Opensuse, Mandriva or Mageia). -You can download this at: [Official website] () +You can download this from the download area of [Official website] () If you already have installed a Web server and a Mysql database, you can install the standard version like this: diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index b9d3b9209f9..8125f6ef14d 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -103,9 +103,7 @@ $sql .= " FROM " . MAIN_DB_PREFIX . "bank as b"; $sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid"; -// To isolate the cash of the other accounts -$sql .= " WHERE ba.courant <> 2"; -$sql .= " AND ba.rowid=".$id_accountancy_journal; +$sql .= " WHERE ba.rowid=".$id_accountancy_journal; if (! empty($conf->multicompany->enabled)) { $sql .= " AND ba.entity = " . $conf->entity; } @@ -218,6 +216,7 @@ if ($result) { $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid"; $sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid; + dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); $resultmid = $db->query($sqlmid); if ($resultmid) @@ -237,6 +236,7 @@ if ($result) { { $paymentsalstatic->id = $links[$key]['url_id']; $paymentsalstatic->ref = $links[$key]['url_id']; + $paymentsalstatic->label = $links[$key]['label']; $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2); $tabtp[$obj->rowid][$accountancy_account_salary] += $obj->amount; } @@ -421,6 +421,7 @@ if ($action == 'export_csv') foreach ( $tabpay as $key => $val ) { $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); + $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; @@ -438,21 +439,44 @@ if ($action == 'export_csv') } // Third party - foreach ( $tabtp[$key] as $k => $mt ) { - if ($mt) { - print $date . $sep; - print $bank_journal . $sep; - if ($val["lib"] == '(SupplierInvoicePayment)') { - print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep; - } else { - print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep; + if (is_array ( $tabtp[$key])) + { + foreach ( $tabtp[$key] as $k => $mt ) + { + if ($mt) + { + print $date . $sep; + print $bank_journal . $sep; + if ($val["lib"] == '(SupplierInvoicePayment)') { + print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep; + } else { + print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep; + } + print length_accounta(html_entity_decode($k)) . $sep; + print ($mt < 0 ? 'D' : 'C') . $sep; + print ($mt <= 0 ? price(- $mt) : $mt) . $sep; + print $val["type_payment"] . $sep; + print $val["ref"] . $sep; + print "\n"; + } + } + } + else + { + foreach ( $tabbq[$key] as $k => $mt ) + { + if (1) + { + print $date . $sep; + print $bank_journal . $sep; + print $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE . $sep; + print $sep; + print ($mt < 0 ? 'D' : 'C') . $sep; + print ($mt <= 0 ? price(- $mt) : $mt) . $sep; + print $val["type_payment"] . $sep; + print $val["ref"] . $sep; + print "\n"; } - print length_accounta(html_entity_decode($k)) . $sep; - print ($mt < 0 ? 'D' : 'C') . $sep; - print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print $val["type_payment"] . $sep; - print $val["ref"] . $sep; - print "\n"; } } } @@ -476,15 +500,35 @@ if ($action == 'export_csv') } // Third party - foreach ( $tabtp[$key] as $k => $mt ) { - if ($mt) { - print '"' . $date . '"' . $sep; - print '"' . $val["type_payment"] . '"' . $sep; - print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; - print '"' . $companystatic->name . '"' . $sep; - print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; - print '"' . ($mt >= 0 ? price($mt) : '') . '"'; - print "\n"; + if (is_array ( $tabtp[$key])) + { + foreach ( $tabtp[$key] as $k => $mt ) + { + if ($mt) { + print '"' . $date . '"' . $sep; + print '"' . $val["type_payment"] . '"' . $sep; + print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; + print '"' . $companystatic->name . '"' . $sep; + print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; + print '"' . ($mt >= 0 ? price($mt) : '') . '"'; + print "\n"; + } + } + } + else + { + foreach ( $tabbq[$key] as $k => $mt ) + { + if (1) + { + print '"' . $date . '"' . $sep; + print '"' . $val["ref"] . '"' . $sep; + print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE . '"' . $sep; + print '"' . $langs->trans("Bank") . '"' . $sep; + print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; + print '"' . ($mt >= 0 ? price($mt) : '') . '"'; + print "\n"; + } } } } @@ -498,14 +542,54 @@ else llxHeader('', $langs->trans("BankJournal")); $namereport = $langs->trans("BankJournal"); - $namelink = ''; - $periodlink = ''; - $exportlink = ''; - $builddate = time(); - $description = $langs->trans("DescBankJournal") . '
'; + $description = $langs->trans("DescBankJournal"); $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1); - report_header($namereport, $namelink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => '')); + // Report + $h=0; + $head[$h][0] = $_SERVER["PHP_SELF"].'?id_account='.$id_accountancy_journal; + $head[$h][1] = $langs->trans("Report"); + $head[$h][2] = 'report'; + + dol_fiche_head($head, $hselected); + + print '
'; + print ''; + + // Title + print ''; + print ''; + print ''; + print ''; + print ''; + + // Period report + print ''; + print ''; + if (! $periodlink) print ''; + print ''; + + // Description + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + + print '
'.$langs->trans("ReportName").''.$namereport.'
'.$langs->trans("ReportPeriod").''; + else print ''; + if ($period) print $period; + if ($periodlink) print ''.$periodlink; + print '
'.$langs->trans("ReportDescription").''.$description.'
'; + + print '
'; + + print ''; + // End report + print ''; print ''; @@ -565,20 +649,36 @@ else } // Third party - foreach ( $tabtp[$key] as $k => $mt ) { - if ($k != 'type') { + if (is_array ( $tabtp[$key])) + { + foreach ( $tabtp[$key] as $k => $mt ) { + if ($k != 'type') { + print ""; + print "" . $date . ""; + print "" . $val["soclib"] . ""; + print "" . length_accounta($k) . ""; + print "" . $langs->trans('ThirdParty') . " (" . $val['soclib'] . ")"; + print "" . $val["type_payment"] . ""; + print "" . ($mt < 0 ? price(- $mt) : '') . ""; + print "" . ($mt >= 0 ? price($mt) : '') . ""; + print ""; + } + } + } + else + { + foreach ( $tabbq[$key] as $k => $mt ) + { print ""; print "" . $date . ""; - print "" . $val["soclib"] . ""; - print "" . length_accounta($k) . ""; - print "" . $langs->trans('ThirdParty') . " (" . $val['soclib'] . ")"; - print "" . $val["type_payment"] . ""; + print "" . $reflabel . ""; + print "" . $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE . ""; + print "" . $langs->trans('ThirdParty') . ""; print "" . ($mt < 0 ? price(- $mt) : '') . ""; print "" . ($mt >= 0 ? price($mt) : '') . ""; print ""; } } - $var = ! $var; } diff --git a/htdocs/accountancy/journal/cashjournal.php b/htdocs/accountancy/journal/cashjournal.php deleted file mode 100644 index bbd74a8c29c..00000000000 --- a/htdocs/accountancy/journal/cashjournal.php +++ /dev/null @@ -1,533 +0,0 @@ - - * Copyright (C) 2007-2010 Jean Heimburger - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013 Christophe Battarel - * Copyright (C) 2013-2015 Alexandre Spangaro - * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2013-2014 Olivier Geffroy - * - * 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 . - */ - -/** - * \file htdocs/accountancy/journal/cashjournal.php - * \ingroup Accounting Expert - * \brief Page with cash journal - */ - -require '../../main.inc.php'; - -// Class -require_once DOL_DOCUMENT_ROOT.'/core/lib/report.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/bank.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; -require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/sociales/class/chargesociales.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; -require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; - -// Langs -$langs->load("companies"); -$langs->load("other"); -$langs->load("compta"); -$langs->load("bank"); -$langs->load("accountancy"); - -$date_startmonth = GETPOST('date_startmonth'); -$date_startday = GETPOST('date_startday'); -$date_startyear = GETPOST('date_startyear'); -$date_endmonth = GETPOST('date_endmonth'); -$date_endday = GETPOST('date_endday'); -$date_endyear = GETPOST('date_endyear'); - -// Security check -if ($user->societe_id > 0) - accessforbidden(); - -$action = GETPOST('action'); - -/* - * View - */ - -$year_current = strftime("%Y", dol_now()); -$pastmonth = strftime("%m", dol_now()) - 1; -$pastmonthyear = $year_current; -if ($pastmonth == 0) { - $pastmonth = 12; - $pastmonthyear --; -} - -$date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); -$date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); - -if (empty($date_start) || empty($date_end)) // We define date_start and date_end -{ - $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false); - $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false); -} - -$p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY); -$idpays = $p[0]; - -$sql = "SELECT b.rowid , b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type, soc.code_compta, ba.courant,"; -$sql .= " soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, ba.account_number, bu1.type as typeop"; -$sql .= " FROM " . MAIN_DB_PREFIX . "bank as b"; -$sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid"; -$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'"; -$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid"; - -// Code opération type caisse -$sql .= " WHERE ba.courant = 2"; -if (! empty($conf->multicompany->enabled)) { - $sql .= " AND ba.entity = " . $conf->entity; -} - -if ($date_start && $date_end) - $sql .= " AND b.dateo >= '" . $db->idate($date_start) . "' AND b.dateo <= '" . $db->idate($date_end) . "'"; -$sql .= " ORDER BY b.datev"; - -$object = new Account($db); -$paymentstatic = new Paiement($db); -$paymentsupplierstatic = new PaiementFourn($db); -$societestatic = new Societe($db); -$chargestatic = new ChargeSociales($db); -$paymentvatstatic = new TVA($db); - -dol_syslog("accountancy/journal/cashjournal.php:: sql=" . $sql, LOG_DEBUG); -$result = $db->query($sql); -if ($result) { - - $num = $db->num_rows($result); - // les variables - $cptfour = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef")); - $cptcli = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef")); - $cpttva = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) ? $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE : $langs->trans("CodeNotDef")); - $cptsociale = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) ? $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE : $langs->trans("CodeNotDef")); - - $tabpay = array (); - $tabbq = array (); - $tabtp = array (); - $tabcompany = array (); - $tabtype = array (); - - $i = 0; - while ( $i < $num ) { - $obj = $db->fetch_object($result); - - // controls - $compta_bank = $obj->account_number; - if ($obj->label == '(SupplierInvoicePayment)') - $compta_soc = (! empty($obj->code_compta_fournisseur) ? $obj->code_compta_fournisseur : $cptfour); - if ($obj->label == '(CustomerInvoicePayment)') - $compta_soc = (! empty($obj->code_compta) ? $obj->code_compta : $cptcli); - if ($obj->typeop == '(BankTransfert)') - $compta_soc = $conf->global->ACCOUNTING_ACCOUNT_TRANSFER_CASH; - - // variable bookkeeping - - $tabpay[$obj->rowid]["date"] = $obj->do; - $tabpay[$obj->rowid]["ref"] = $obj->label; - $tabpay[$obj->rowid]["fk_bank"] = $obj->rowid; - if (preg_match('/^\((.*)\)$/i', $obj->label, $reg)) { - $tabpay[$obj->rowid]["lib"] = $langs->trans($reg[1]); - } else { - $tabpay[$obj->rowid]["lib"] = dol_trunc($obj->label, 60); - } - $links = $object->get_url($obj->rowid); - - foreach ( $links as $key => $val ) { - - $tabtype[$obj->rowid] = $links[$key]['type']; - - if ($links[$key]['type'] == 'payment') { - $paymentstatic->id = $links[$key]['url_id']; - $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentstatic->getNomUrl(2); - } else if ($links[$key]['type'] == 'payment_supplier') { - $paymentsupplierstatic->id = $links[$key]['url_id']; - $paymentsupplierstatic->ref = $links[$key]['url_id']; - $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsupplierstatic->getNomUrl(2); - } else if ($links[$key]['type'] == 'company') { - - $societestatic->id = $links[$key]['url_id']; - $societestatic->name = $links[$key]['label']; - $tabpay[$obj->rowid]["soclib"] = $societestatic->getNomUrl(1, '', 30); - $tabtp[$obj->rowid][$compta_soc] += $obj->amount; - } else if ($links[$key]['type'] == 'sc') { - - $chargestatic->id = $links[$key]['url_id']; - $chargestatic->ref = $links[$key]['url_id']; - - $tabpay[$obj->rowid]["lib"] .= ' ' . $chargestatic->getNomUrl(2); - if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) { - if ($reg[1] == 'socialcontribution') - $reg[1] = 'SocialContribution'; - $chargestatic->lib = $langs->trans($reg[1]); - } else { - $chargestatic->lib = $links[$key]['label']; - } - $chargestatic->ref = $chargestatic->lib; - $tabpay[$obj->rowid]["soclib"] = $chargestatic->getNomUrl(1, 30); - - $sqlmid = 'SELECT cchgsoc.accountancy_code'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid"; - $sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid; - dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $tabtp[$obj->rowid][$objmid->accountancy_code] += $obj->amount; - } - } else if ($links[$key]['type'] == 'payment_vat') { - - $paymentvatstatic->id = $links[$key]['url_id']; - $paymentvatstatic->ref = $links[$key]['url_id']; - $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2); - $tabtp[$obj->rowid][$cpttva] += $obj->amount; - } else if ($links[$key]['type'] == 'banktransfert') { - $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2); - $tabtp[$obj->rowid][$cpttva] += $obj->amount; - } - /*else { - $tabtp [$obj->rowid] [$cptsociale] += $obj->amount; - }*/ - } - $tabbq[$obj->rowid][$compta_bank] += $obj->amount; - - // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount; - - $i ++; - } -} else { - dol_print_error($db); -} - -/* - * Actions -*/ - -// write bookkeeping -if ($action == 'writeBookKeeping') { - $error = 0; - foreach ( $tabpay as $key => $val ) { - // cash - foreach ( $tabbq[$key] as $k => $mt ) { - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->doc_type = 'cash'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = $val["fk_bank"]; - $bookkeeping->code_tiers = $tabcompany[$key]['code_client']; - $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = $compte->label; - $bookkeeping->montant = ($mt < 0 ? - $mt : $mt); - $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; - $bookkeeping->debit = ($mt >= 0 ? $mt : 0); - $bookkeeping->credit = ($mt < 0 ? - $mt : 0); - $bookkeeping->code_journal = $conf->global->ACCOUNTING_CASH_JOURNAL; - - if ($tabtype[$key] == 'payment') { - - $sqlmid = 'SELECT fac.facnumber'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; - $sqlmid .= " WHERE pay.fk_bank=" . $key; - dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; - } - } else if ($tabtype[$key] == 'payment_supplier') { - - $sqlmid = 'SELECT facf.facnumber'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; - $sqlmid .= " WHERE payf.fk_bank=" . $key; - dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; - } - } - - $result = $bookkeeping->create(); - if ($result < 0) { - $error ++; - setEventMessage($object->errors, 'errors'); - } - } - // third party - foreach ( $tabtp[$key] as $k => $mt ) { - - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->doc_type = 'cash'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = $val["fk_bank"]; - $bookkeeping->label_compte = $tabcompany[$key]['name']; - $bookkeeping->montant = ($mt < 0 ? - $mt : $mt); - $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; - $bookkeeping->debit = ($mt < 0 ? - $mt : 0); - $bookkeeping->credit = ($mt >= 0 ? $mt : 0); - $bookkeeping->code_journal = $conf->global->ACCOUNTING_CASH_JOURNAL; - - if ($tabtype[$key] == 'sc') { - $bookkeeping->code_tiers = ''; - $bookkeeping->numero_compte = $k; - } else if ($tabtype[$key] == 'payment') { - - $sqlmid = 'SELECT fac.facnumber'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; - $sqlmid .= " WHERE pay.fk_bank=" . $key; - dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; - } - $bookkeeping->code_tiers = $k; - $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; - } else if ($tabtype[$key] == 'payment_supplier') { - - $sqlmid = 'SELECT facf.facnumber'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; - $sqlmid .= " WHERE payf.fk_bank=" . $key; - dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; - } - $bookkeeping->code_tiers = $k; - $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; - } else if ($tabtype[$key] == 'company') { - - $sqlmid = 'SELECT fac.facnumber'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; - $sqlmid .= " WHERE pay.fk_bank=" . $key; - dol_syslog("accountancy/journal/cashjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; - } - $bookkeeping->code_tiers = $k; - $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; - } else { - - $bookkeeping->doc_ref = $k; - $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; - } - - $result = $bookkeeping->create(); - if ($result < 0) { - $error ++; - setEventMessage($object->errors, 'errors'); - } - } - } - - if (empty($error)) { - setEventMessage($langs->trans('Success'), 'mesgs'); - } -} -// Export -if ($action == 'export_csv') { - $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; - $cash_journal = $conf->global->ACCOUNTING_CASH_JOURNAL; - - header('Content-Type: text/csv'); - header('Content-Disposition:attachment;filename=journal_caisse.csv'); - - if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) // Model Cegid Expert Export - { - $sep = ";"; - - foreach ( $tabpay as $key => $val ) { - $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); - - // Cash - foreach ( $tabbq[$key] as $k => $mt ) { - print $date . $sep; - print $cash_journal . $sep; - print length_accountg(html_entity_decode($k)) . $sep; - print $sep; - print ($mt < 0 ? 'C' : 'D') . $sep; - print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print $val["type_payment"] . $sep; - print $val["ref"] . $sep; - print "\n"; - } - - // Third party - foreach ( $tabtp[$key] as $k => $mt ) { - if ($mt) { - print $date . $sep; - print $cash_journal . $sep; - if ($val["lib"] == '(SupplierInvoicePayment)') { - print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep; - } else { - print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep; - } - print length_accounta(html_entity_decode($k)) . $sep; - print ($mt < 0 ? 'D' : 'C') . $sep; - print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print $val["type_payment"] . $sep; - print $val["ref"] . $sep; - print "\n"; - } - } - } - } else // Model Classic Export - { - foreach ( $tabpay as $key => $val ) { - $date = dol_print_date($db->jdate($val["date"]), 'day'); - - // Cash - foreach ( $tabbq[$key] as $k => $mt ) { - print '"' . $date . '"' . $sep; - print '"' . $val["ref"] . '"' . $sep; - print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print '"' . $langs->trans("Cash") . '"' . $sep; - print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; - print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; - print "\n"; - } - - // Third party - foreach ( $tabtp[$key] as $k => $mt ) { - if ($mt) { - print '"' . $date . '"' . $sep; - print '"' . $val["ref"] . '"' . $sep; - print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; - print '"' . $langs->trans("ThirdParty") . '"' . $sep; - print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; - print '"' . ($mt >= 0 ? price($mt) : '') . '"'; - print "\n"; - } - } - } - } -} else { - - $form = new Form($db); - - llxHeader('', $langs->trans("CashJournal"), ''); - - $name = $langs->trans("CashJournal"); - $nomlink = ''; - $periodlink = ''; - $exportlink = ''; - $builddate = time(); - $description = $langs->trans("DescCashJournal") . '
'; - $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1); - report_header($name, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => '')); - - print ''; - - print ''; - - print ' - '; - - /* - * Show result array - */ - print '

'; - - $i = 0; - print ""; - print ""; - print ""; - print ""; - print ""; - print ""; - print "\n"; - - $var = true; - $r = ''; - - foreach ( $tabpay as $key => $val ) { - $date = dol_print_date($db->jdate($val["date"]), 'day'); - - // Cash - foreach ( $tabbq[$key] as $k => $mt ) { - if (1) { - print ""; - print ""; - print ""; - print ""; - print '"; - print '"; - print ""; - } - } - - // third party - foreach ( $tabtp[$key] as $k => $mt ) { - if ($k != 'type') { - print ""; - - print ""; - print ""; - - print ""; - print '"; - print '"; - } - } - - $var = ! $var; - } - - print "
" . $langs->trans("Date") . "" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")" . $langs->trans("Account") . "" . $langs->trans("Debit") . "" . $langs->trans("Credit") . "
" . $date . "" . $val["lib"] . "" . length_accountg($k) . "' . ($mt >= 0 ? price($mt) : '') . "' . ($mt < 0 ? price(- $mt) : '') . "
" . $date . "" . $val["soclib"] . "" . length_accounta($k) . "' . ($mt < 0 ? price(- $mt) : '') . "' . ($mt >= 0 ? price($mt) : '') . "
"; - - // End of page - llxFooter(); -} -$db->close(); \ No newline at end of file diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index d8a1a85debf..94f12a61f8b 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -302,6 +302,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; // Check if we need to also synchronize user information $nosyncuser=0; @@ -471,6 +472,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; // Check parameters if (empty($morphy) || $morphy == "-1") { diff --git a/htdocs/adherents/type.php b/htdocs/adherents/type.php index 96e13561825..ea39a200c97 100644 --- a/htdocs/adherents/type.php +++ b/htdocs/adherents/type.php @@ -89,6 +89,7 @@ if ($action == 'add' && $user->rights->adherent->configurer) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$adht); + if ($ret < 0) $error++; if ($adht->libelle) { @@ -126,6 +127,7 @@ if ($action == 'update' && $user->rights->adherent->configurer) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$adht); + if ($ret < 0) $error++; $adht->update($user); diff --git a/htdocs/admin/notification.php b/htdocs/admin/notification.php index 14aeba65c29..695174f3303 100644 --- a/htdocs/admin/notification.php +++ b/htdocs/admin/notification.php @@ -33,6 +33,7 @@ $langs->load("orders"); $langs->load("propal"); $langs->load("bills"); $langs->load("errors"); +$langs->load("mails"); // Security check if (!$user->admin) @@ -76,7 +77,9 @@ if ($action == 'setvalue' && $user->admin) * View */ -llxHeader(); +$form=new Form($db); + +llxHeader('',$langs->trans("NotificationSetup")); $linkback=''.$langs->trans("BackToModuleList").''; print_fiche_titre($langs->trans("NotificationSetup"),$linkback,'setup'); @@ -132,9 +135,19 @@ foreach($listofnotifiedevents as $notifiedevent) print ''.$elementLabel.''; print ''.$notifiedevent['code'].''; print ''.$label.''; + print ''; $param='NOTIFICATION_FIXEDEMAIL_'.$notifiedevent['code']; - print ''; - if (! empty($conf->global->$param) && ! isValidEmail($conf->global->$param)) print ' '.img_warning($langs->trans("ErrorBadEMail")); + $value=GETPOST($param)?GETPOST($param,'alpha'):$conf->global->$param; + $s=''; // Do not use type="email" here, we must be able to enter a list of email with , separator. + $arrayemail=explode(',',$value); + $showwarning=0; + foreach($arrayemail as $key=>$valuedet) + { + $valuedet=trim($valuedet); + if (! empty($valuedet) && ! isValidEmail($valuedet)) $showwarning++; + } + if ((! empty($conf->global->$param)) && $showwarning) $s.=' '.img_warning($langs->trans("ErrorBadEMail")); + print $form->textwithpicto($s,$langs->trans("YouCanUseCommaSeparatorForSeveralRecipients")); print ''; print ''; } diff --git a/htdocs/admin/supplierinvoice_extrafields.php b/htdocs/admin/supplierinvoice_extrafields.php index 79dc0637b46..755a68b338e 100644 --- a/htdocs/admin/supplierinvoice_extrafields.php +++ b/htdocs/admin/supplierinvoice_extrafields.php @@ -31,6 +31,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; +$langs->load("orders"); if (!$user->admin) accessforbidden(); diff --git a/htdocs/categories/card.php b/htdocs/categories/card.php index 672c92b9508..8a587d7de32 100644 --- a/htdocs/categories/card.php +++ b/htdocs/categories/card.php @@ -127,6 +127,7 @@ if ($action == 'add' && $user->rights->categorie->creer) if ($parent != "-1") $object->fk_parent = $parent; $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! $object->label) { diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index aa82fdb455d..a105d104036 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -90,7 +90,8 @@ if ($action == 'update' && $user->rights->categorie->creer) if (empty($categorie->error)) { $ret = $extrafields->setOptionalsFromPost($extralabels,$categorie); - + if ($ret < 0) $error++; + if ($categorie->update($user) > 0) { header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id.'&type='.$type); diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 0a4b255884a..c15b1fe4f32 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -274,6 +274,7 @@ if ($action == 'add') // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! $error) { @@ -429,6 +430,7 @@ if ($action == 'update') // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! $error) { diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index c879f50b346..9a9417a4dac 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -184,12 +184,12 @@ class ActionComm extends CommonObject $now=dol_now(); // Check parameters - if (empty($this->userownerid)) + if (empty($this->userownerid)) { $this->errors[]='ErrorPropertyUserowneridNotDefined'; return -1; } - + // Clean parameters $this->label=dol_trunc(trim($this->label),128); $this->location=dol_trunc(trim($this->location),128); @@ -214,7 +214,7 @@ class ActionComm extends CommonObject $userdoneid=$this->userdoneid; // Be sure assigned user is defined as an array of array('id'=>,'mandatory'=>,...). - if (empty($this->userassigned) || count($this->userassigned) == 0 || ! is_array($this->userassigned)) + if (empty($this->userassigned) || count($this->userassigned) == 0 || ! is_array($this->userassigned)) $this->userassigned = array($userownerid=>array('id'=>$userownerid)); if (! $this->type_id || ! $this->type_code) @@ -306,9 +306,9 @@ class ActionComm extends CommonObject { $val=array('id'=>$val); } - + $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; - $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".($val['mandatory']?$val['mandatory']:'0').", ".($val['transparency']?$val['transparency']:'0').", ".($val['answer_status']?$val['answer_status']:'0').")"; + $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".(empty($val['mandatory'])?'0':$val['mandatory']).", ".(empty($val['transparency'])?'0':$val['transparency']).", ".(empty($val['answer_status'])?'0':$val['answer_status']).")"; $resql = $this->db->query($sql); if (! $resql) @@ -672,7 +672,7 @@ class ActionComm extends CommonObject foreach($this->userassigned as $key => $val) { $sql ="INSERT INTO ".MAIN_DB_PREFIX."actioncomm_resources(fk_actioncomm, element_type, fk_element, mandatory, transparency, answer_status)"; - $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".($val['manadatory']?$val['manadatory']:'0').", ".($val['transparency']?$val['transparency']:'0').", ".($val['answer_status']?$val['answer_status']:'0').")"; + $sql.=" VALUES(".$this->id.", 'user', ".$val['id'].", ".(empty($val['manadatory'])?'0':$val['manadatory']).", ".(empty($val['transparency'])?'0':$val['transparency']).", ".(empty($val['answer_status'])?'0':$val['answer_status']).")"; $resql = $this->db->query($sql); if (! $resql) diff --git a/htdocs/comm/mailing/class/mailing.class.php b/htdocs/comm/mailing/class/mailing.class.php index 2f8f7f18e4e..69a3520d1e8 100644 --- a/htdocs/comm/mailing/class/mailing.class.php +++ b/htdocs/comm/mailing/class/mailing.class.php @@ -57,7 +57,7 @@ class Mailing extends CommonObject var $date_creat; var $date_valid; - + var $extraparams=array(); public $statut_dest=array(); @@ -78,12 +78,12 @@ class Mailing extends CommonObject $this->statuts[1] = 'MailingStatusValidated'; $this->statuts[2] = 'MailingStatusSentPartialy'; $this->statuts[3] = 'MailingStatusSentCompletely'; - + $this->statut_dest[-1] = 'MailingStatusError'; $this->statut_dest[1] = 'MailingStatusSent'; $this->statut_dest[2] = 'MailingStatusRead'; $this->statut_dest[3] = 'MailingStatusNotContact'; - + } /** @@ -186,7 +186,7 @@ class Mailing extends CommonObject function fetch($rowid) { global $conf; - + $sql = "SELECT m.rowid, m.titre, m.sujet, m.body, m.bgcolor, m.bgimage"; $sql.= ", m.email_from, m.email_replyto, m.email_errorsto"; $sql.= ", m.statut, m.nbemail"; @@ -211,14 +211,14 @@ class Mailing extends CommonObject $this->statut = $obj->statut; $this->nbemail = $obj->nbemail; $this->titre = $obj->titre; - - $this->sujet = $obj->sujet; + + $this->sujet = $obj->sujet; if (!empty($conf->global->FCKEDITOR_ENABLE_MAILING) && dol_textishtml(dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401))) { $this->body = dol_html_entity_decode($obj->body, ENT_COMPAT | ENT_HTML401); }else { $this->body = $obj->body; } - + $this->bgcolor = $obj->bgcolor; $this->bgimage = $obj->bgimage; @@ -232,7 +232,7 @@ class Mailing extends CommonObject $this->date_creat = $this->db->jdate($obj->date_creat); $this->date_valid = $this->db->jdate($obj->date_valid); $this->date_envoi = $this->db->jdate($obj->date_envoi); - + $this->extraparams = (array) json_decode($obj->extraparams, true); return 1; @@ -267,6 +267,8 @@ class Mailing extends CommonObject $object=new Mailing($this->db); + $object->context['createfromclone']='createfromclone'; + $this->db->begin(); // Load source object @@ -313,13 +315,13 @@ class Mailing extends CommonObject { //Clone target if (!empty($option2)) { - + require_once DOL_DOCUMENT_ROOT .'/core/modules/mailings/modules_mailings.php'; - + $mailing_target = new MailingTargets($this->db); - + $target_array=array(); - + $sql = "SELECT fk_contact, "; $sql.=" lastname, "; $sql.=" firstname,"; @@ -330,7 +332,7 @@ class Mailing extends CommonObject $sql.=" source_type "; $sql.= " FROM ".MAIN_DB_PREFIX."mailing_cibles "; $sql.= " WHERE fk_mailing = ".$fromid; - + dol_syslog(get_class($this)."::createFromClone", LOG_DEBUG); $result=$this->db->query($sql); if ($result) @@ -338,17 +340,17 @@ class Mailing extends CommonObject if ($this->db->num_rows($result)) { while ($obj = $this->db->fetch_object($result)) { - + $target_array[]=array('fk_contact'=>$obj->fk_contact, 'lastname'=>$obj->lastname, 'firstname'=>$obj->firstname, - 'email'=>$obj->email, + 'email'=>$obj->email, 'other'=>$obj->other, 'source_url'=>$obj->source_url, 'source_id'=>$obj->source_id, 'source_type'=>$obj->source_type); } - + } } else @@ -356,12 +358,14 @@ class Mailing extends CommonObject $this->error=$this->db->lasterror(); return -1; } - + $mailing_target->add_to_target($object->id, $target_array); } } + unset($object->context['createfromclone']); + // End if (! $error) { @@ -514,7 +518,7 @@ class Mailing extends CommonObject } } - + /** * Renvoi le libelle d'un statut donne * @@ -526,7 +530,7 @@ class Mailing extends CommonObject { global $langs; $langs->load('mails'); - + if ($mode == 0) { return $langs->trans($this->statut_dest[$statut]); @@ -563,10 +567,10 @@ class Mailing extends CommonObject if ($statut==2) return $langs->trans("MailingStatusRead").' '.img_picto($langs->trans("MailingStatusRead"),'statut6'); if ($statut==3) return $langs->trans("MailingStatusNotContact").' '.img_picto($langs->trans("MailingStatusNotContact"),'statut8'); } - - - - + + + + } } diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 030aff46434..3739b59c338 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1080,10 +1080,10 @@ if (empty($reshook)) // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; - if (! $error) { + if (! $error) + { // Actions on extra fields (by external module or standard code) // FIXME le hook fait double emploi avec le trigger !! $hookmanager->initHooks(array('propaldao')); diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index ca4c51c3f4c..b18ff15331f 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -239,27 +239,30 @@ class Propal extends CommonObject return -5; } - $propalligne=new PropaleLigne($this->db); - $propalligne->fk_propal=$this->id; - $propalligne->fk_remise_except=$remise->id; - $propalligne->desc=$remise->description; // Description ligne - $propalligne->tva_tx=$remise->tva_tx; - $propalligne->subprice=-$remise->amount_ht; - $propalligne->fk_product=0; // Id produit predefini - $propalligne->qty=1; - $propalligne->remise=0; - $propalligne->remise_percent=0; - $propalligne->rang=-1; - $propalligne->info_bits=2; + $line=new PropaleLigne($this->db); + + $this->line->context = $this->context; + + $line->fk_propal=$this->id; + $line->fk_remise_except=$remise->id; + $line->desc=$remise->description; // Description ligne + $line->tva_tx=$remise->tva_tx; + $line->subprice=-$remise->amount_ht; + $line->fk_product=0; // Id produit predefini + $line->qty=1; + $line->remise=0; + $line->remise_percent=0; + $line->rang=-1; + $line->info_bits=2; // TODO deprecated - $propalligne->price=-$remise->amount_ht; + $line->price=-$remise->amount_ht; - $propalligne->total_ht = -$remise->amount_ht; - $propalligne->total_tva = -$remise->amount_tva; - $propalligne->total_ttc = -$remise->amount_ttc; + $line->total_ht = -$remise->amount_ht; + $line->total_tva = -$remise->amount_tva; + $line->total_ttc = -$remise->amount_ttc; - $result=$propalligne->insert(); + $result=$line->insert(); if ($result > 0) { $result=$this->update_price(1); @@ -276,7 +279,7 @@ class Propal extends CommonObject } else { - $this->error=$propalligne->error; + $this->error=$line->error; $this->db->rollback(); return -2; } @@ -393,6 +396,8 @@ class Propal extends CommonObject // Insert line $this->line=new PropaleLigne($this->db); + $this->line->context = $this->context; + $this->line->fk_propal=$this->id; $this->line->label=$label; $this->line->desc=$desc; @@ -545,6 +550,8 @@ class Propal extends CommonObject // Update line $this->line=new PropaleLigne($this->db); + $this->line->context = $this->context; + // Stock previous line records $staticline=new PropaleLigne($this->db); $staticline->fetch($rowid); @@ -953,6 +960,8 @@ class Propal extends CommonObject { global $user,$langs,$conf,$hookmanager; + $this->context['createfromclone']='createfromclone'; + $error=0; $now=dol_now(); @@ -1046,6 +1055,8 @@ class Propal extends CommonObject // End call triggers } + unset($this->context['createfromclone']); + // End if (! $error) { @@ -3088,6 +3099,7 @@ class PropaleLigne extends CommonObject if (empty($this->special_code)) $this->special_code=0; if (empty($this->fk_parent_line)) $this->fk_parent_line=0; if (empty($this->fk_fournprice)) $this->fk_fournprice=0; + if (empty($this->subprice)) $this->subprice=0; if (empty($this->pa_ht)) $this->pa_ht=0; diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 5b76dd59323..eb5767b173a 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -271,8 +271,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; if (! $error) { @@ -365,10 +364,10 @@ if (empty($reshook)) } else { // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; - if (! $error) { + if (! $error) + { $object_id = $object->create($user); // If some invoice's lines already known @@ -1124,8 +1123,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; if (! $error) { // Actions on extra fields (by external module or standard code) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 35834419a74..1cdd57b1b6a 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -878,6 +878,8 @@ class Commande extends CommonOrder $error=0; + $this->context['createfromclone'] = 'createfromclone'; + $this->db->begin(); // get extrafields so they will be clone @@ -942,6 +944,8 @@ class Commande extends CommonOrder // End call triggers } + unset($this->context['createfromclone']); + // End if (! $error) { @@ -1201,6 +1205,8 @@ class Commande extends CommonOrder // Insert line $this->line=new OrderLine($this->db); + $this->line->context = $this->context; + $this->line->fk_commande=$this->id; $this->line->label=$label; $this->line->desc=$desc; @@ -1315,6 +1321,8 @@ class Commande extends CommonOrder $line=new OrderLine($this->db); + $line->context = $this->context; + $line->fk_product=$idproduct; $line->desc=$prod->description; $line->qty=$qty; @@ -2397,6 +2405,8 @@ class Commande extends CommonOrder // Update line $this->line=new OrderLine($this->db); + $this->line->context = $this->context; + // Stock previous line records $staticline=new OrderLine($this->db); $staticline->fetch($rowid); diff --git a/htdocs/compta/bank/class/bankcateg.class.php b/htdocs/compta/bank/class/bankcateg.class.php index fb796b219ee..5004d13caf1 100644 --- a/htdocs/compta/bank/class/bankcateg.class.php +++ b/htdocs/compta/bank/class/bankcateg.class.php @@ -300,7 +300,9 @@ class BankCateg // extends CommonObject $object=new BankCateg($this->db); - $this->db->begin(); + $object->context['createfromclone'] = 'createfromclone'; + + $this->db->begin(); // Load source object $object->fetch($fromid); @@ -327,6 +329,8 @@ class BankCateg // extends CommonObject } + unset($object->context['createfromclone']); + // End if (! $error) { diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 5f1f3998b5d..3d7a71f8133 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -585,7 +585,7 @@ if (empty($reshook)) $discount->fk_facture_source = $object->id; $error = 0; - + foreach ($amount_ht as $tva_tx => $xxx) { $discount->amount_ht = abs($amount_ht [$tva_tx]); $discount->amount_tva = abs($amount_tva [$tva_tx]); @@ -636,7 +636,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) $error ++; + if ($ret < 0) $error++; // Replacement invoice if ($_POST['type'] == Facture::TYPE_REPLACEMENT) @@ -1676,8 +1676,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; if (! $error) { // Actions on extra fields (by external module or standard code) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index d50079f78c8..ec41b0a99c2 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -607,6 +607,8 @@ class Facture extends CommonInvoice $error=0; + $this->context['createfromclone'] = 'createfromclone'; + $this->db->begin(); // get extrafields so they will be clone @@ -693,6 +695,8 @@ class Facture extends CommonInvoice // End call triggers } + unset($this->context['createfromclone']); + // End if (! $error) { @@ -2043,6 +2047,9 @@ class Facture extends CommonInvoice // Insert line $this->line=new FactureLigne($this->db); + + $this->line->context = $this->context; + $this->line->fk_facture=$this->id; $this->line->label=$label; // deprecated $this->line->desc=$desc; @@ -2181,7 +2188,9 @@ class Facture extends CommonInvoice // Update line into database $this->line=new FactureLigne($this->db); - // Stock previous line records + $this->line->context = $this->context; + + // Stock previous line records $staticline=new FactureLigne($this->db); $staticline->fetch($rowid); $this->line->oldline = $staticline; @@ -2294,6 +2303,8 @@ class Facture extends CommonInvoice $line=new FactureLigne($this->db); + $line->context = $this->context; + // For triggers $line->fetch($rowid); diff --git a/htdocs/compta/facture/class/paymentterm.class.php b/htdocs/compta/facture/class/paymentterm.class.php index b75bb056e03..d524c501698 100644 --- a/htdocs/compta/facture/class/paymentterm.class.php +++ b/htdocs/compta/facture/class/paymentterm.class.php @@ -33,6 +33,7 @@ class PaymentTerm // extends CommonObject var $errors=array(); //!< To return several error codes (or messages) //public $element='c_payment_term'; //!< Id that identify managed objects //public $table_element='c_payment_term'; //!< Name of table without prefix where object is stored + var $context =array(); var $id; @@ -409,6 +410,8 @@ class PaymentTerm // extends CommonObject $object=new PaymentTerm($this->db); + $object->context['createfromclone'] = 'createfromclone'; + $this->db->begin(); // Load source object @@ -436,6 +439,8 @@ class PaymentTerm // extends CommonObject } + unset($this->context['createfromclone']); + // End if (! $error) { diff --git a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php index 395932de69f..10f856cf858 100644 --- a/htdocs/compta/sociales/class/paymentsocialcontribution.class.php +++ b/htdocs/compta/sociales/class/paymentsocialcontribution.class.php @@ -384,6 +384,8 @@ class PaymentSocialContribution extends CommonObject $object=new PaymentSocialContribution($this->db); + $object->context['createfromclone'] = 'createfromclone'; + $this->db->begin(); // Load source object @@ -411,6 +413,8 @@ class PaymentSocialContribution extends CommonObject } + unset($this->context['createfromclone']); + // End if (! $error) { diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index af07cbb9a62..248352dfee3 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -200,6 +200,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! GETPOST("lastname")) { @@ -303,6 +304,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; $result = $object->update($contactid, $user); diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index fdd0acfec74..6d10442caf7 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -355,6 +355,7 @@ if ($action == 'add' && $user->rights->contrat->creer) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); + if ($ret < 0) $error++; $result = $object->create($user); if ($result > 0) @@ -702,19 +703,20 @@ else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contra // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); - if ($ret < 0) - $error ++; + if ($ret < 0) $error++; - if (! $error) { + if (! $error) + { + $result = $object->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + else if ($reshook < 0) $error++; - $result = $object->insertExtraFields(); - if ($result < 0) { - $error ++; - } - } else if ($reshook < 0) - $error ++; - - if ($error) { + if ($error) + { $action = 'edit_extras'; setEventMessage($object->error,'errors'); } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 8a8258ca641..46d280f8763 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -38,6 +38,7 @@ abstract class CommonObject public $error; public $errors; public $canvas; // Contains canvas name if it is + public $context=array(); // Use to pass context information public $name; public $lastname; @@ -3456,7 +3457,8 @@ abstract class CommonObject /** * Add/Update all extra fields values for the current object. - * All data to describe values to insert are stored into $this->array_options=array('keyextrafield'=>'valueextrafieldtoadd') + * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) + * This function delte record with all extrafields and insert them again from the array $this->array_options. * * @return int -1=error, O=did nothing, 1=OK */ diff --git a/htdocs/core/class/ctypent.class.php b/htdocs/core/class/ctypent.class.php index 027dda53dd3..c7894c7c848 100644 --- a/htdocs/core/class/ctypent.class.php +++ b/htdocs/core/class/ctypent.class.php @@ -148,9 +148,10 @@ class Ctypent // extends CommonObject * * @param int $id Id object * @param string $code Code + * @param string $label Label * @return int <0 if KO, >0 if OK */ - function fetch($id,$code='') + function fetch($id,$code='',$label='') { global $langs; $sql = "SELECT"; @@ -163,8 +164,8 @@ class Ctypent // extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."c_typent as t"; if ($id) $sql.= " WHERE t.id = ".$id; elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; + elseif ($label) $sql.= " WHERE t.libelle = '".$this->db->escape($label)."'"; - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 544619892b5..cc602d08ed5 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -1061,9 +1061,9 @@ class ExtraFields * Fill array_options property of object by extrafields value (using for data sent by forms) * * @param array $extralabels $array of extrafields - * @param object $object Object - * @param string $onlykey Only following key is filled - * @return int 1 if array_options set / 0 if no value + * @param object $object Object + * @param string $onlykey Only following key is filled. When we make update of only one extrafield ($action = 'update_extras'), calling page must must set this to avoid to have other extrafields being reset. + * @return int 1 if array_options set, 0 if no value, -1 if error (field required missing for example) */ function setOptionalsFromPost($extralabels,&$object,$onlykey='') { diff --git a/htdocs/core/modules/import/import_csv.modules.php b/htdocs/core/modules/import/import_csv.modules.php index 14de889d9ce..cd3a35e4060 100644 --- a/htdocs/core/modules/import/import_csv.modules.php +++ b/htdocs/core/modules/import/import_csv.modules.php @@ -354,6 +354,7 @@ class ImportCsv extends ModeleImports } else { + $last_insert_id_array = array(); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id (eg: extrafields fk_object will be set with the last inserted object's id) // For each table to insert, me make a separate insert foreach($objimport->array_import_tables[0] as $alias => $tablename) { @@ -414,21 +415,34 @@ class ImportCsv extends ModeleImports if (! empty($objimport->array_import_convertvalue[0][$val])) { //print 'Must convert '.$newval.' with rule '.join(',',$objimport->array_import_convertvalue[0][$val]).'. '; - if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid' || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref') + if ($objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeid' + || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromref' + || $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel' + ) { if (! is_numeric($newval) && $newval != '') // If value into input import file is not a numeric, we apply the function defined into descriptor { $file=$objimport->array_import_convertvalue[0][$val]['classfile']; $class=$objimport->array_import_convertvalue[0][$val]['class']; $method=$objimport->array_import_convertvalue[0][$val]['method']; - if (empty($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval])) + if ($this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval] != '') { + $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; + } + else + { dol_include_once($file); $classinstance=new $class($this->db); + // Try the fetch from code or ref call_user_func_array(array($classinstance, $method),array('', $newval)); + // If not found, try the fetch from label + if (! ($classinstance->id != '') && $objimport->array_import_convertvalue[0][$val]['rule']=='fetchidfromcodeorlabel') + { + call_user_func_array(array($classinstance, $method),array('', '', $newval)); + } $this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]=$classinstance->id; //print 'We have made a '.$class.'->'.$method.' to get id from code '.$newval.'. '; - if (! empty($classinstance->id)) + if ($classinstance->id != '') // id may be 0, it is a found value { $newval=$classinstance->id; } @@ -442,10 +456,6 @@ class ImportCsv extends ModeleImports $error++; } } - else - { - $newval=$this->cacheconvert[$file.'_'.$class.'_'.$method.'_'][$newval]; - } } } @@ -581,7 +591,7 @@ class ImportCsv extends ModeleImports elseif (preg_match('/^lastrowid-/',$val)) { $tmp=explode('-',$val); - $lastinsertid=$this->db->last_insert_id($tmp[1]); + $lastinsertid=(isset($last_insert_id_array[$tmp[1]]))?$last_insert_id_array[$tmp[1]]:0; $listfields.=preg_replace('/^'.preg_quote($alias).'\./','',$key); $listvalues.=$lastinsertid; //print $key."-".$val."-".$listfields."-".$listvalues."
";exit; @@ -623,6 +633,7 @@ class ImportCsv extends ModeleImports if ($sql) { $resql=$this->db->query($sql); + $last_insert_id_array[$tablename] = $this->db->last_insert_id($tablename); // store the last inserted auto_increment id for each table, so that dependent tables can be inserted with the appropriate id. This must be done just after the INSERT request, else we risk losing the id (because another sql query will be issued somewhere in Dolibarr). if ($resql) { //print '.'; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index 63cb9c610b4..3a2bcefe8b2 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -382,7 +382,7 @@ class modSociete extends DolibarrModules $this->import_icon[$r]='company'; $this->import_entities_array[$r]=array(); // We define here only fields that use another icon that the one defined into import_icon $this->import_tables_array[$r]=array('s'=>MAIN_DB_PREFIX.'societe','extra'=>MAIN_DB_PREFIX.'societe_extrafields'); // List of tables to insert into (insert done in same order) - $this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.code_compta'=>"CustomerAccountancyCode",'s.code_compta_fournisseur'=>"SupplierAccountancyCode",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'s.fk_departement'=>"StateId",'s.fk_pays'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siren'=>"ProfId1",'s.siret'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note_private'=>"NotePrivate",'s.note_public'=>"NotePublic",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Staff","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.barcode'=>'BarCode','s.datec'=>"DateCreation"); + $this->import_fields_array[$r]=array('s.nom'=>"Name*",'s.status'=>"Status",'s.client'=>"Customer*",'s.fournisseur'=>"Supplier*",'s.code_client'=>"CustomerCode",'s.code_fournisseur'=>"SupplierCode",'s.code_compta'=>"CustomerAccountancyCode",'s.code_compta_fournisseur'=>"SupplierAccountancyCode",'s.address'=>"Address",'s.zip'=>"Zip",'s.town'=>"Town",'s.fk_departement'=>"StateId",'s.fk_pays'=>"CountryCode",'s.phone'=>"Phone",'s.fax'=>"Fax",'s.url'=>"Url",'s.email'=>"Email",'s.siren'=>"ProfId1",'s.siret'=>"ProfId2",'s.ape'=>"ProfId3",'s.idprof4'=>"ProfId4",'s.idprof5'=>"ProfId5",'s.idprof6'=>"ProfId6",'s.tva_intra'=>"VATIntraShort",'s.capital'=>"Capital",'s.note_private'=>"NotePrivate",'s.note_public'=>"NotePublic",'s.fk_typent'=>"ThirdPartyType",'s.fk_effectif'=>"Staff","s.fk_forme_juridique"=>"JuridicalStatus",'s.fk_prospectlevel'=>'ProspectLevel','s.fk_stcomm'=>'ProspectStatus','s.default_lang'=>'DefaultLanguage','s.barcode'=>'BarCode','s.datec'=>"DateCreation"); // Add extra fields $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'societe' AND entity = ".$conf->entity; $resql=$this->db->query($sql); @@ -398,7 +398,7 @@ class modSociete extends DolibarrModules // End add extra fields $this->import_fieldshidden_array[$r]=array('s.fk_user_creat'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'societe'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) $this->import_convertvalue_array[$r]=array( - 's.fk_typent'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionaryCompanyType'), + 's.fk_typent'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctypent.class.php','class'=>'Ctypent','method'=>'fetch','dict'=>'DictionaryCompanyType'), 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'), 's.fk_stcomm'=>array('rule'=>'zeroifnull'), 's.code_client'=>array('rule'=>'getcustomercodeifauto'), @@ -407,8 +407,8 @@ class modSociete extends DolibarrModules 's.code_compta_fournisseur'=>array('rule'=>'getsupplieraccountancycodeifauto') ); //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); - $this->import_regex_array[$r]=array('s.status'=>'^[0|1]','s.client'=>'^[0|1|2|3]','s.fournisseur'=>'^[0|1]','s.fk_typent'=>'id@'.MAIN_DB_PREFIX.'c_typent','s.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); - $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(dol_now(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001 or empty or 'auto'",'s.code_fournisseur'=>"SU01-0001 or empty or 'auto'",'s.address'=>"61 jump street",'s.zip'=>"123456",'s.town'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.phone'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note_private'=>"This is an example of private note for record",'s.note_public'=>"This is an example of public note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'0','s.default_lang'=>'en_US','s.barcode'=>'123456789'); + $this->import_regex_array[$r]=array('s.status'=>'^[0|1]','s.client'=>'^[0|1|2|3]','s.fournisseur'=>'^[0|1]','s.fk_typent'=>'id@'.MAIN_DB_PREFIX.'c_typent','s.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$'); + $this->import_examplevalues_array[$r]=array('s.nom'=>"MyBigCompany",'s.status'=>"0 (closed) or 1 (active)",'s.client'=>'0 (no customer no prospect)/1 (customer)/2 (prospect)/3 (customer and prospect)','s.fournisseur'=>'0 or 1','s.datec'=>dol_print_date(dol_now(),'%Y-%m-%d'),'s.code_client'=>"CU01-0001 or empty or 'auto'",'s.code_fournisseur'=>"SU01-0001 or empty or 'auto'",'s.address'=>"61 jump street",'s.zip'=>"123456",'s.town'=>"Big town",'s.fk_pays'=>'US, FR, DE...','s.phone'=>"0101010101",'s.fax'=>"0101010102",'s.url'=>"http://mycompany.com",'s.email'=>"test@mycompany.com",'s.siret'=>"",'s.siren'=>"",'s.ape'=>"",'s.idprof4'=>"",'s.idprof5'=>"",'s.idprof6'=>"",'s.tva_intra'=>"FR0123456789",'s.capital'=>"10000",'s.note_private'=>"This is an example of private note for record",'s.note_public'=>"This is an example of public note for record",'s.fk_typent'=>"2",'s.fk_effectif'=>"3","s.fk_forme_juridique"=>"1",'s.fk_prospectlevel'=>'PL_MEDIUM','s.fk_stcomm'=>'0','s.default_lang'=>'en_US','s.barcode'=>'123456789','s.datec'=>"2015-01-01 or 2015-01-01 12:30:00"); // Import list of contact and attributes $r++; @@ -437,7 +437,7 @@ class modSociete extends DolibarrModules 's.fk_pays'=>array('rule'=>'fetchidfromcodeid','classfile'=>'/core/class/ccountry.class.php','class'=>'Ccountry','method'=>'fetch','dict'=>'DictionaryCountry'), ); //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); - $this->import_regex_array[$r]=array('s.birthday'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','s.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$'); + $this->import_regex_array[$r]=array('s.birthday'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]$','s.datec'=>'^[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]( [0-9][0-9]:[0-9][0-9]:[0-9][0-9])?$'); $this->import_examplevalues_array[$r]=array('s.fk_soc'=>'MyBigCompany','s.civility'=>"MR",'s.lastname'=>"Smith",'s.firstname'=>'John','s.address'=>'61 jump street','s.zip'=>'75000','s.town'=>'Bigtown','s.fk_pays'=>'US, FR, DE...','s.datec'=>'1972-10-10','s.poste'=>"Director",'s.phone'=>"5551122",'s.phone_perso'=>"5551133",'s.phone_mobile'=>"5551144",'s.fax'=>"5551155",'s.email'=>"johnsmith@email.com",'s.note_private'=>"My private note",'s.note_public'=>"My public note"); // Import Bank Accounts diff --git a/htdocs/cron/class/cronjob.class.php b/htdocs/cron/class/cronjob.class.php index 723660f1d9c..5f2ef68b194 100644 --- a/htdocs/cron/class/cronjob.class.php +++ b/htdocs/cron/class/cronjob.class.php @@ -718,6 +718,8 @@ class Cronjob extends CommonObject $object=new Cronjob($this->db); + $object->context['createfromclone'] = 'createfromclone'; + $this->db->begin(); // Load source object @@ -744,6 +746,8 @@ class Cronjob extends CommonObject } + unset($this->context['createfromclone']); + // End if (! $error) { diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 9051ab0bb27..95c8c1801a7 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -887,7 +887,7 @@ class CommandeFournisseur extends CommonOrder $sql.= ", entity"; $sql.= ", fk_soc"; $sql.= ", date_creation"; - //$sql.= ", date_livraison"; + $sql.= ", date_livraison"; $sql.= ", fk_user_author"; $sql.= ", fk_statut"; $sql.= ", source"; @@ -899,12 +899,12 @@ class CommandeFournisseur extends CommonOrder $sql.= " VALUES ("; $sql.= "''"; $sql.= ", '".$this->ref_supplier."'"; - $sql.= ", '".$this->note_private."'"; - $sql.= ", '".$this->note_public."'"; + $sql.= ", '".$this->db->escape($this->note_private)."'"; + $sql.= ", '".$this->db->escape($this->note_public)."'"; $sql.= ", ".$conf->entity; $sql.= ", ".$this->socid; $sql.= ", '".$this->db->idate($now)."'"; - //$sql.= ", '".$this->db->idate($now)."'"; + $sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null"); $sql.= ", ".$user->id; $sql.= ", 0"; $sql.= ", " . $this->source; @@ -1024,7 +1024,9 @@ class CommandeFournisseur extends CommonOrder $error=0; - $this->db->begin(); + $this->context['createfromclone'] = 'createfromclone'; + + $this->db->begin(); // Load source object $objFrom = dol_clone($this); @@ -1060,7 +1062,9 @@ class CommandeFournisseur extends CommonOrder // End call triggers } - // End + unset($this->context['createfromclone']); + + // End if (! $error) { $this->db->commit(); diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 96e00aba182..7f2697d7c0c 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -1699,7 +1699,9 @@ class FactureFournisseur extends CommonInvoice $object=new FactureFournisseur($this->db); - $this->db->begin(); + $object->context['createfromclone'] = 'createfromclone'; + + $this->db->begin(); // Load source object $object->fetch($fromid); @@ -1745,6 +1747,8 @@ class FactureFournisseur extends CommonInvoice } + unset($object->context['createfromclone']); + // End if (! $error) { diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 75ac674e877..3d12352903f 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -447,12 +447,18 @@ class ProductFournisseur extends Product * * @param int $prodid Product id * @param int $qty Minimum quantity - * @return int <0 if KO, >0 if OK + * @return int <0 if KO, 0=Not found of no product id provided, >0 if OK */ function find_min_price_product_fournisseur($prodid, $qty=0) { global $conf; + if (empty($prodid)) + { + dol_syslog("Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING); + return 0; + } + $this->product_fourn_price_id = ''; $this->product_fourn_id = ''; $this->fourn_ref = ''; @@ -500,7 +506,7 @@ class ProductFournisseur extends Product return 1; } else - { + { $this->error=$this->db->error(); return -1; } diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index ef78a9981c1..0257b51c946 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -69,6 +69,8 @@ $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0)); $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0)); +$datelivraison=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), GETPOST('liv_sec','int'), GETPOST('liv_month','int'), GETPOST('liv_day','int'),GETPOST('liv_year','int')); + // Security check if ($user->societe_id) $socid=$user->societe_id; @@ -144,8 +146,6 @@ if ($action == 'setbankaccount' && $user->rights->fournisseur->commande->creer) // date de livraison if ($action == 'setdate_livraison' && $user->rights->fournisseur->commande->creer) { - $datelivraison=dol_mktime(GETPOST('liv_hour','int'), GETPOST('liv_min','int'), GETPOST('liv_sec','int'), GETPOST('liv_month','int'), GETPOST('liv_day','int'),GETPOST('liv_year','int')); - $result=$object->set_date_livraison($user,$datelivraison); if ($result < 0) { @@ -780,11 +780,10 @@ if ($action == 'update_extras') { // Fill array 'array_options' with data from add form $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); + if ($ret < 0) $error++; - if($ret < 0) $error++; - - if (!$error) + if (! $error) { // Actions on extra fields (by external module or standard code) // FIXME le hook fait double emploi avec le trigger !! @@ -797,7 +796,6 @@ if ($action == 'update_extras') { if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used { - $result=$object->insertExtraFields(); if ($result < 0) @@ -841,21 +839,29 @@ if ($action == 'add' && $user->rights->fournisseur->commande->creer) $object->fk_account = GETPOST('fk_account', 'int'); $object->note_private = GETPOST('note_private'); $object->note_public = GETPOST('note_public'); + $object->date_livraison = $datelivraison; // Fill array 'array_options' with data from add form - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if (! $error) + { + $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; + } - $id = $object->create($user); - if ($id < 0) - { - $error++; - } + if (! $error) + { + $id = $object->create($user); + if ($id < 0) + { + $error++; + setEventMessage($langs->trans($object->error), 'errors'); + } + } if ($error) { $langs->load("errors"); $db->rollback(); - setEventMessage($langs->trans($object->error), 'errors'); $action='create'; $_GET['socid']=$_POST['socid']; } @@ -1272,6 +1278,16 @@ if ($action=="create") $form->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id'); print ''; + // Planned delivery date + print ''; + print $langs->trans('DateDeliveryPlanned'); + print ''; + print ''; + $usehourmin=0; + if (! empty($conf->global->SUPPLIER_ORDER_USE_HOUR_FOR_DELIVERY_DATE)) $usehourmin=1; + $form->select_date($datelivraison?$datelivraison:-1,'liv_',$usehourmin,$usehourmin,'',"set"); + print ''; + // Bank Account if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_SUPPLIER_ORDER) && ! empty($conf->banque->enabled)) { diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index d5ace69a09f..c88886de649 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -347,28 +347,41 @@ if ($id > 0 || ! empty($ref)) print ''.$objp->qty.''; print ''.$products_dispatched[$objp->rowid].''; - if ( !(empty($conf->productbatch->enabled)) && $objp->tobatch==1) { - print ''.img_picto_common($langs->trans('AddDispatchBatchLine'),'treemenu/plustop2.gif','onClick="AddLineBatch('.$i.')"').''; + if (! empty($conf->productbatch->enabled) && $objp->tobatch==1) + { + print ''.img_picto($langs->trans('AddDispatchBatchLine'),'split.png','onClick="addLineBatch('.$i.')"').''; // Dispatch column + print ''; // Warehouse column print ''; - print ''; - print ''; - print ''; - print ''; - $form->select_date('','dlc'.$suffix,'','',1,""); - print ''; - $form->select_date('','dluo'.$suffix,'','',1,""); - print ''; - print ''; - print ''; - print ' '; - } else { - print ''; + + print ''; + print ''; print ''; + print ''; print ''; + print ''; + + print ''; + $form->select_date('','dlc'.$suffix,'','',1,""); + print ''; + print ''; + $form->select_date('','dluo'.$suffix,'','',1,""); + print ''; + print ''; + print ''; + print ''; + print ' '; // Qty ordered + qty already dispatached } // Dispatch - print ''; + print ''; + if (empty($conf->productbatch->enabled) || $objp->tobatch!=1) + { + print ''; + print ''; + print ''; + } + print ''; + print ''; // Warehouse print ''; diff --git a/htdocs/fourn/commande/list.php b/htdocs/fourn/commande/list.php index 54cc7b1964a..69db321b72e 100644 --- a/htdocs/fourn/commande/list.php +++ b/htdocs/fourn/commande/list.php @@ -43,7 +43,7 @@ $search_company=GETPOST('search_company'); $search_user=GETPOST('search_user'); $search_ttc=GETPOST('search_ttc'); $sall=GETPOST('search_all'); -$search_status=GETPOST('search_status','int'); +$search_status=(GETPOST('search_status','int')!=''?GETPOST('search_status','int'):GETPOST('statut','int')); $page = GETPOST('page','int'); $socid = GETPOST('socid','int'); diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 26aeffad655..54ef660f6aa 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -308,7 +308,7 @@ elseif ($action == 'add' && $user->rights->fournisseur->facture->creer) $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object); - if ($ret < 0) $error ++; + if ($ret < 0) $error++; $tmpproject = GETPOST('projectid', 'int'); @@ -1070,9 +1070,8 @@ elseif ($action == 'update_extras') { // Fill array 'array_options' with data from add form $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); - $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - - if($ret < 0) $error++; + $ret = $extrafields->setOptionalsFromPost($extralabels,$object,GETPOST('attribute')); + if ($ret < 0) $error++; if (!$error) { diff --git a/htdocs/imports/import.php b/htdocs/imports/import.php index 125b8dc0285..c6ab76dff41 100644 --- a/htdocs/imports/import.php +++ b/htdocs/imports/import.php @@ -33,6 +33,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/import.lib.php'; $langs->load("exports"); +$langs->load("compta"); $langs->load("errors"); // Security check diff --git a/htdocs/index.php b/htdocs/index.php index ebc6760252c..7e922c7059a 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -317,7 +317,7 @@ if (! empty($conf->agenda->enabled) && $user->rights->agenda->myactions->read) $board->load_board($user); $board->warning_delay=$conf->actions->warning_delay/60/60/24; $board->label=$langs->trans("ActionsToDo"); - $board->url=DOL_URL_ROOT.'/comm/action/listactions.php?status=todo&mainmenu=agenda'; + $board->url=DOL_URL_ROOT.'/comm/action/listactions.php?status=todo&usertodo=-1&mainmenu=agenda'; $board->img=img_object($langs->trans("Actions"),"action"); $rowspan++; $dashboardlines[]=$board; diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index dc912be4286..2efb6996993 100755 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1161,4 +1161,4 @@ ALTER TABLE llx_product ADD CONSTRAINT fk_product_barcode_type FOREIGN KEY (fk_b UPDATE llx_bank_url set url = REPLACE( url, 'fiche.php', 'card.php'); -- Add id commandefourndet in llx_commande_fournisseur_dispatch to correct /fourn/commande/dispatch.php display when several times same product in supplier order -ALTER TABLE llx_commande_fournisseur_dispatch ADD COLUMN fk_commandefourndet INT(11) NOT NULL DEFAULT '0' AFTER fk_product; +ALTER TABLE llx_commande_fournisseur_dispatch ADD COLUMN fk_commandefourndet INTEGER NOT NULL DEFAULT 0 AFTER fk_product; diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index a2d73817bf1..fbfd55b9a9a 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -79,7 +79,7 @@ ErrorModuleRequireJavascript=Javascript must not be disabled to have this featur ErrorPasswordsMustMatch=Both typed passwords must match each other ErrorContactEMail=A technical error occured. Please, contact administrator to following email %s en provide the error code %s in your message, or even better by adding a screen copy of this page. ErrorWrongValueForField=Wrong value for field number %s (value '%s' does not match regex rule %s) -ErrorFieldValueNotIn=Wrong value for field number %s (value '%s' is not a value available into field %s of table %s) +ErrorFieldValueNotIn=Wrong value for field number %s (value '%s' is not a value available into field %s of table %s = %s) ErrorFieldRefNotIn=Wrong value for field number %s (value '%s' is not a %s existing ref) ErrorsOnXLines=Errors on %s source record(s) ErrorFileIsInfectedWithAVirus=The antivirus program was not able to validate the file (file might be infected by a virus) diff --git a/htdocs/langs/en_US/projects.lang b/htdocs/langs/en_US/projects.lang index 84624b219f9..52f4376d57b 100644 --- a/htdocs/langs/en_US/projects.lang +++ b/htdocs/langs/en_US/projects.lang @@ -8,8 +8,10 @@ SharedProject=Everybody PrivateProject=Contacts of project MyProjectsDesc=This view is limited to projects you are a contact for (whatever is the type). ProjectsPublicDesc=This view presents all projects you are allowed to read. +ProjectsPublicTaskDesc=This view presents all projects and tasks you are allowed to read. ProjectsDesc=This view presents all projects (your user permissions grant you permission to view everything). MyTasksDesc=This view is limited to projects or tasks you are a contact for (whatever is the type). +OnlyOpenedProject=Only opened projects are visible (projects with draft or closed status are not visible). TasksPublicDesc=This view presents all projects and tasks you are allowed to read. TasksDesc=This view presents all projects and tasks (your user permissions grant you permission to view everything). ProjectsArea=Projects area diff --git a/htdocs/product/card.php b/htdocs/product/card.php index a4c4e4ee92e..b5f34e20a8d 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -262,8 +262,12 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; - $id = $object->create($user); + if (! $error) + { + $id = $object->create($user); + } if ($id > 0) { @@ -339,8 +343,9 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; - if ($object->check()) + if (! $error && $object->check()) { if ($object->update($object->id, $user) > 0) { diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index a4df7a95829..839dce77fed 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -327,7 +327,9 @@ class Productbatch extends CommonObject $object=new Productbatch($this->db); - $this->db->begin(); + $object->context['createfromclone']='createfromclone'; + + $this->db->begin(); // Load source object $object->fetch($fromid); @@ -353,6 +355,8 @@ class Productbatch extends CommonObject } + unset($object->context['createfromclone']); + // End if (! $error) { diff --git a/htdocs/product/class/productcustomerprice.class.php b/htdocs/product/class/productcustomerprice.class.php index 4cc6e7feb49..62d9bb0a406 100644 --- a/htdocs/product/class/productcustomerprice.class.php +++ b/htdocs/product/class/productcustomerprice.class.php @@ -75,9 +75,9 @@ class Productcustomerprice extends CommonObject global $conf, $langs; $error = 0; - + // Clean parameters - + if (isset($this->entity)) $this->entity = trim($this->entity); if (isset($this->fk_product)) @@ -106,16 +106,16 @@ class Productcustomerprice extends CommonObject $this->fk_user = trim($this->fk_user); if (isset($this->import_key)) $this->import_key = trim($this->import_key); - + // Check parameters // Put here code to add control on parameters values - + if ($this->price != '' || $this->price == 0) { if ($this->price_base_type == 'TTC') { $this->price_ttc = price2num($this->price, 'MU'); $this->price = price2num($this->price) / (1 + ($this->tva_tx / 100)); $this->price = price2num($this->price, 'MU'); - + if ($this->price_min != '' || $this->price_min == 0) { $this->price_min_ttc = price2num($this->price_min, 'MU'); $this->price_min = price2num($this->price_min) / (1 + ($this->tva_tx / 100)); @@ -128,7 +128,7 @@ class Productcustomerprice extends CommonObject $this->price = price2num($this->price, 'MU'); $this->price_ttc = ($this->recuperableonly != 1) ? price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price; $this->price_ttc = price2num($this->price_ttc, 'MU'); - + if ($this->price_min != '' || $this->price_min == 0) { $this->price_min = price2num($this->price_min, 'MU'); $this->price_min_ttc = price2num($this->price_min) * (1 + ($this->tva_tx / 100)); @@ -140,10 +140,10 @@ class Productcustomerprice extends CommonObject } } } - + // Insert request $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_customer_price("; - + $sql .= "entity,"; $sql .= "datec,"; $sql .= "fk_product,"; @@ -159,9 +159,9 @@ class Productcustomerprice extends CommonObject $sql .= "localtax2_tx,"; $sql .= "fk_user,"; $sql .= "import_key"; - + $sql .= ") VALUES ("; - + $sql .= " " . $conf->entity . ","; $sql .= " '" . $this->db->idate(dol_now()) . "',"; $sql .= " " . (! isset($this->fk_product) ? 'NULL' : "'" . $this->fk_product . "'") . ","; @@ -177,25 +177,25 @@ class Productcustomerprice extends CommonObject $sql .= " " . (! isset($this->localtax2_tx) ? 'NULL' : "'" . $this->localtax2_tx . "'") . ","; $sql .= " " . $user->id . ","; $sql .= " " . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ""; - + $sql .= ")"; - + $this->db->begin(); - + dol_syslog(get_class($this) . "::create", LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors [] = "Error " . $this->db->lasterror(); } - + if (! $error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . "product_customer_price"); - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; // $interface=new Interfaces($this->db); @@ -204,14 +204,14 @@ class Productcustomerprice extends CommonObject // // End call triggers } } - + if (! $error) { $result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate); if ($result < 0) { $error ++; } } - + // Commit or rollback if ($error) { foreach ( $this->errors as $errmsg ) { @@ -237,7 +237,7 @@ class Productcustomerprice extends CommonObject global $langs; $sql = "SELECT"; $sql .= " t.rowid,"; - + $sql .= " t.entity,"; $sql .= " t.datec,"; $sql .= " t.tms,"; @@ -254,18 +254,18 @@ class Productcustomerprice extends CommonObject $sql .= " t.localtax2_tx,"; $sql .= " t.fk_user,"; $sql .= " t.import_key"; - + $sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t"; $sql .= " WHERE t.rowid = " . $id; - + dol_syslog(get_class($this) . "::fetch", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { if ($this->db->num_rows($resql)) { $obj = $this->db->fetch_object($resql); - + $this->id = $obj->rowid; - + $this->entity = $obj->entity; $this->datec = $this->db->jdate($obj->datec); $this->tms = $this->db->jdate($obj->tms); @@ -284,7 +284,7 @@ class Productcustomerprice extends CommonObject $this->import_key = $obj->import_key; } $this->db->free($resql); - + return 1; } else { $this->error = "Error " . $this->db->lasterror(); @@ -307,7 +307,7 @@ class Productcustomerprice extends CommonObject global $langs; $sql = "SELECT"; $sql .= " t.rowid,"; - + $sql .= " t.entity,"; $sql .= " t.datec,"; $sql .= " t.tms,"; @@ -332,7 +332,7 @@ class Productcustomerprice extends CommonObject $sql .= " WHERE soc.rowid=t.fk_soc "; $sql .= " AND prod.rowid=t.fk_product "; $sql .= " AND prod.entity IN (" . getEntity('product', 1) . ")"; - + // Manage filter if (count($filter) > 0) { foreach ( $filter as $key => $value ) { @@ -346,27 +346,27 @@ class Productcustomerprice extends CommonObject } } } - + if (! empty($sortfield)) { $sql .= " ORDER BY " . $sortfield . ' ' . $sortorder; } if (! empty($limit)) { $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } - + dol_syslog(get_class($this) . "::fetch_all", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - + $this->lines = array (); $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { - + $line = new PriceByCustomerLine(); - + $line->id = $obj->rowid; - + $line->entity = $obj->entity; $line->datec = $this->db->jdate($obj->datec); $line->tms = $this->db->jdate($obj->tms); @@ -385,11 +385,11 @@ class Productcustomerprice extends CommonObject $line->import_key = $obj->import_key; $line->socname = $obj->socname; $line->prodref = $obj->prodref; - + $this->lines [] = $line; } $this->db->free($resql); - + return $num; } else { $this->error = "Error " . $this->db->lasterror(); @@ -412,7 +412,7 @@ class Productcustomerprice extends CommonObject global $langs; $sql = "SELECT"; $sql .= " t.rowid,"; - + $sql .= " t.entity,"; $sql .= " t.datec,"; $sql .= " t.fk_product,"; @@ -436,7 +436,7 @@ class Productcustomerprice extends CommonObject $sql .= " WHERE soc.rowid=t.fk_soc "; $sql .= " AND prod.rowid=t.fk_product "; $sql .= " AND prod.entity IN (" . getEntity('product', 1) . ")"; - + // Manage filter if (count($filter) > 0) { foreach ( $filter as $key => $value ) { @@ -450,27 +450,27 @@ class Productcustomerprice extends CommonObject } } } - + if (! empty($sortfield)) { $sql .= " ORDER BY " . $sortfield . ' ' . $sortorder; } if (! empty($limit)) { $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } - + dol_syslog(get_class($this) . "::fetch_all_log", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - + $this->lines = array (); $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { - + $line = new PriceByCustomerLine(); - + $line->id = $obj->rowid; - + $line->entity = $obj->entity; $line->datec = $this->db->jdate($obj->datec); $line->tms = $this->db->jdate($obj->tms); @@ -489,11 +489,11 @@ class Productcustomerprice extends CommonObject $line->import_key = $obj->import_key; $line->socname = $obj->socname; $line->prodref = $obj->prodref; - + $this->lines [] = $line; } $this->db->free($resql); - + return $num; } else { $this->error = "Error " . $this->db->lasterror(); @@ -513,9 +513,9 @@ class Productcustomerprice extends CommonObject global $conf, $langs; $error = 0; - + // Clean parameters - + if (isset($this->entity)) $this->entity = trim($this->entity); if (isset($this->fk_product)) @@ -544,16 +544,16 @@ class Productcustomerprice extends CommonObject $this->fk_user = trim($this->fk_user); if (isset($this->import_key)) $this->import_key = trim($this->import_key); - + // Check parameters // Put here code to add a control on parameters values - + if ($this->price != '' || $this->price == 0) { if ($this->price_base_type == 'TTC') { $this->price_ttc = price2num($this->price, 'MU'); $this->price = price2num($this->price) / (1 + ($this->tva_tx / 100)); $this->price = price2num($this->price, 'MU'); - + if ($this->price_min != '' || $this->price_min == 0) { $this->price_min_ttc = price2num($this->price_min, 'MU'); $this->price_min = price2num($this->price_min) / (1 + ($this->tva_tx / 100)); @@ -566,7 +566,7 @@ class Productcustomerprice extends CommonObject $this->price = price2num($this->price, 'MU'); $this->price_ttc = ($this->recuperableonly != 1) ? price2num($this->price) * (1 + ($this->tva_tx / 100)) : $this->price; $this->price_ttc = price2num($this->price_ttc, 'MU'); - + if ($this->price_min != '' || $this->price_min == 0) { $this->price_min = price2num($this->price_min, 'MU'); $this->price_min_ttc = price2num($this->price_min) * (1 + ($this->tva_tx / 100)); @@ -578,11 +578,11 @@ class Productcustomerprice extends CommonObject } } } - + // Do a copy of current record into log table // Insert request $sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_customer_price_log("; - + $sql .= "entity,"; $sql .= "datec,"; $sql .= "fk_product,"; @@ -598,10 +598,10 @@ class Productcustomerprice extends CommonObject $sql .= "localtax2_tx,"; $sql .= "fk_user,"; $sql .= "import_key"; - + $sql .= ") "; $sql .= "SELECT"; - + $sql .= " t.entity,"; $sql .= " t.datec,"; $sql .= " t.fk_product,"; @@ -617,10 +617,10 @@ class Productcustomerprice extends CommonObject $sql .= " t.localtax2_tx,"; $sql .= " t.fk_user,"; $sql .= " t.import_key"; - + $sql .= " FROM " . MAIN_DB_PREFIX . "product_customer_price as t"; $sql .= " WHERE t.rowid = " . $this->id; - + $this->db->begin(); dol_syslog(get_class($this) . "::update", LOG_DEBUG); $resql = $this->db->query($sql); @@ -628,10 +628,10 @@ class Productcustomerprice extends CommonObject $error ++; $this->errors [] = "Error " . $this->db->lasterror(); } - + // Update request $sql = "UPDATE " . MAIN_DB_PREFIX . "product_customer_price SET"; - + $sql .= " entity=" . $conf->entity . ","; $sql .= " datec='" . $this->db->idate(dol_now()) . "',"; $sql .= " tms=" . (dol_strlen($this->tms) != 0 ? "'" . $this->db->idate($this->tms) . "'" : 'null') . ","; @@ -648,21 +648,21 @@ class Productcustomerprice extends CommonObject $sql .= " localtax2_tx=" . (isset($this->localtax2_tx) ? $this->localtax2_tx : "null") . ","; $sql .= " fk_user=" . $user->id . ","; $sql .= " import_key=" . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . ""; - + $sql .= " WHERE rowid=" . $this->id; - + dol_syslog(get_class($this) . "::update", LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors [] = "Error " . $this->db->lasterror(); } - + if (! $error) { if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; // $interface=new Interfaces($this->db); @@ -671,14 +671,14 @@ class Productcustomerprice extends CommonObject // // End call triggers } } - + if (! $error) { $result = $this->setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate); if ($result < 0) { $error ++; } } - + // Commit or rollback if ($error) { foreach ( $this->errors as $errmsg ) { @@ -703,50 +703,50 @@ class Productcustomerprice extends CommonObject function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate) { $error = 0; - + // Find all susidiaries $sql = "SELECT s.rowid"; $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; $sql .= " WHERE s.parent = " . $this->fk_soc; $sql .= " AND s.entity IN (" . getEntity('societe', 1) . ")"; - + dol_syslog(get_class($this) . "::setPriceOnAffiliateThirdparty", LOG_DEBUG); $resql = $this->db->query($sql); - + if ($resql) { - + $this->lines = array (); $num = $this->db->num_rows($resql); - + while ( ($obj = $this->db->fetch_object($resql)) && (empty($error)) ) { - + // find if there is an existing line for the product and the subsidiaries $prodsocprice = new Productcustomerprice($this->db); - + $filter = array ( - 't.fk_product' => $this->fk_product,'t.fk_soc' => $obj->rowid + 't.fk_product' => $this->fk_product,'t.fk_soc' => $obj->rowid ); - + $result = $prodsocprice->fetch_all('', '', 0, 0, $filter); if ($result < 0) { $error ++; $this->error = $prodsocprice->error; } else { - + // There is one line if (count($prodsocprice->lines) > 0) { // If force update => Update if (! empty($forceupdateaffiliate)) { - + $prodsocpriceupd = new Productcustomerprice($this->db); $prodsocpriceupd->fetch($prodsocprice->lines [0]->id); - + $prodsocpriceupd->price = $this->price; $prodsocpriceupd->price_min = $this->price_min; $prodsocpriceupd->price_base_type = $this->price_base_type; $prodsocpriceupd->tva_tx = $this->tva_tx; $prodsocpriceupd->recuperableonly = $this->recuperableonly; - + $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate); if ($result < 0) { $error ++; @@ -763,7 +763,7 @@ class Productcustomerprice extends CommonObject $prodsocpricenew->price_base_type = $this->price_base_type; $prodsocpricenew->tva_tx = $this->tva_tx; $prodsocpricenew->recuperableonly = $this->recuperableonly; - + $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate); if ($result < 0) { $error ++; @@ -773,7 +773,7 @@ class Productcustomerprice extends CommonObject } } $this->db->free($resql); - + if (empty($error)) { return 1; } else { @@ -796,14 +796,14 @@ class Productcustomerprice extends CommonObject global $conf, $langs; $error = 0; - + $this->db->begin(); - + if (! $error) { if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; // $interface=new Interfaces($this->db); @@ -812,11 +812,11 @@ class Productcustomerprice extends CommonObject // // End call triggers } } - + if (! $error) { $sql = "DELETE FROM " . MAIN_DB_PREFIX . "product_customer_price"; $sql .= " WHERE rowid=" . $this->id; - + dol_syslog(get_class($this) . "::delete", LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { @@ -824,7 +824,7 @@ class Productcustomerprice extends CommonObject $this->errors [] = "Error " . $this->db->lasterror(); } } - + // Commit or rollback if ($error) { foreach ( $this->errors as $errmsg ) { @@ -848,33 +848,37 @@ class Productcustomerprice extends CommonObject function createFromClone($fromid) { global $user, $langs; - + $error = 0; - + $object = new Productcustomerprice($this->db); - + + $object->context['createfromclone']='createfromclone'; + $this->db->begin(); - + // Load source object $object->fetch($fromid); $object->id = 0; $object->statut = 0; - + // Clear fields // ... - + // Create clone $result = $object->create($user); - + // Other options if ($result < 0) { $this->error = $object->error; $error ++; } - + if (! $error) { } - + + unset($object->context['createfromclone']); + // End if (! $error) { $this->db->commit(); @@ -894,7 +898,7 @@ class Productcustomerprice extends CommonObject function initAsSpecimen() { $this->id = 0; - + $this->entity = ''; $this->datec = ''; $this->tms = ''; diff --git a/htdocs/product/list.php b/htdocs/product/list.php index a5cc97defa7..c060ef424e6 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -456,8 +456,11 @@ else if (empty($conf->global->PRODUIT_MULTIPRICES)) { print ''; - if ($objp->price_base_type == 'TTC') print price($objp->price_ttc).' '.$langs->trans("TTC"); - else print price($objp->price).' '.$langs->trans("HT"); + if ($objp->tosell) + { + if ($objp->price_base_type == 'TTC') print price($objp->price_ttc).' '.$langs->trans("TTC"); + else print price($objp->price).' '.$langs->trans("HT"); + } print ''; } @@ -465,7 +468,7 @@ else if ($user->rights->fournisseur->lire) { print ''; - if ($objp->minsellprice != '') + if ($objp->tobuy && $objp->minsellprice != '') { //print price($objp->minsellprice).' '.$langs->trans("HT"); if ($product_fourn->find_min_price_product_fournisseur($objp->rowid) > 0) diff --git a/htdocs/projet/activity/list.php b/htdocs/projet/activity/list.php index 692e4ab08b4..af569d3351f 100644 --- a/htdocs/projet/activity/list.php +++ b/htdocs/projet/activity/list.php @@ -125,7 +125,8 @@ if ($id) $project->fetch_thirdparty(); } -$tasksarray=$taskstatic->getTasksArray(0,0,($project->id?$project->id:$projectsListId),$socid,0); // We want to see all task of project i am allowed to see, not only mine. Later only mine will be editable later. +$onlyopened=1; // or -1 +$tasksarray=$taskstatic->getTasksArray(0,0,($project->id?$project->id:$projectsListId),$socid,0,'',$onlyopened); // We want to see all task of opened project i am allowed to see, not only mine. Later only mine will be editable later. $projectsrole=$taskstatic->getUserRolesForProjectsOrTasks($user,0,($project->id?$project->id:$projectsListId),0); $tasksrole=$taskstatic->getUserRolesForProjectsOrTasks(0,$user,($project->id?$project->id:$projectsListId),0); //var_dump($tasksarray); @@ -138,11 +139,11 @@ llxHeader("",$title,""); print_barre_liste($title, $page, $_SERVER["PHP_SELF"], "", $sortfield, $sortorder, "", $num); // Show description of content -if ($mine) print $langs->trans("MyTasksDesc").'

'; +if ($mine) print $langs->trans("MyTasksDesc").($onlyopened?' '.$langs->trans("OnlyOpenedProject"):'').'

'; else { - if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").'

'; - else print $langs->trans("ProjectsPublicTakDesc").'

'; + if ($user->rights->projet->all->lire && ! $socid) print $langs->trans("ProjectsDesc").($onlyopened?' '.$langs->trans("OnlyOpenedProject"):'').'

'; + else print $langs->trans("ProjectsPublicTaskDesc").($onlyopened?' '.$langs->trans("AlsoOnlyOpenedProject"):'').'

'; } diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index b376133699b..1c971ef9e35 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -147,6 +147,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; $result = $object->create($user); if ($result > 0) @@ -222,10 +223,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - if ($ret < 0) - { - $error++; - } + if ($ret < 0) $error++; } if (! $error) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 5c54cae4174..a52a9f133e9 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -56,7 +56,7 @@ class Project extends CommonObject var $note_private; var $note_public; var $statuts_short; - var $statuts; + var $statuts; // 0=draft, 1=opened, 2=closed var $oldcopy; @@ -1017,6 +1017,8 @@ class Project extends CommonObject $clone_project=new Project($this->db); + $clone_project->context['createfromclone']='createfromclone'; + $this->db->begin(); // Load source object @@ -1068,8 +1070,6 @@ class Project extends CommonObject if (! $error) { - $this->db->commit(); - //Get the new project id $clone_project_id=$clone_project->id; @@ -1223,23 +1223,19 @@ class Project extends CommonObject } } } + } + unset($clone_project->context['createfromclone']); - - if (! $error) - { - return $clone_project_id; - } - else - { - dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR); - return -1; - } - + if (! $error) + { + $this->db->commit(); + return $clone_project_id; } else { $this->db->rollback(); + dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR); return -1; } } diff --git a/htdocs/projet/class/task.class.php b/htdocs/projet/class/task.class.php index 0f9645fe237..017e2b782ec 100644 --- a/htdocs/projet/class/task.class.php +++ b/htdocs/projet/class/task.class.php @@ -1092,6 +1092,8 @@ class Task extends CommonObject $clone_task=new Task($this->db); $origin_task=new Task($this->db); + $clone_task->context['createfromclone']='createfromclone'; + $this->db->begin(); // Load source object @@ -1158,8 +1160,6 @@ class Task extends CommonObject // End if (! $error) { - $this->db->commit(); - $clone_task_id=$clone_task->id; $clone_task_ref = $clone_task->ref; @@ -1279,20 +1279,19 @@ class Task extends CommonObject { //TODO clone time of affectation } + } - if (! $error) - { - return $clone_task_id; - } - else - { - dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR); - return -1; - } + unset($clone_task->context['createfromclone']); + + if (! $error) + { + $this->db->commit(); + return $clone_task_id; } else { $this->db->rollback(); + dol_syslog(get_class($this)."::createFromClone nbError: ".$error." error : " . $this->error, LOG_ERR); return -1; } } diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index d43af94ee71..6860ff1479f 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2012 Juanjo Menent * @@ -57,7 +57,7 @@ $dates=dol_mktime(0, 0, 0, GETPOST('datesmonth'), GETPOST('datesday'), GETPOST(' $datee=dol_mktime(23, 59, 59, GETPOST('dateemonth'), GETPOST('dateeday'), GETPOST('dateeyear')); if (empty($dates) && ! empty($datesrfc)) $dates=dol_stringtotime($datesrfc); if (empty($datee) && ! empty($dateerfc)) $datee=dol_stringtotime($dateerfc); -if (! isset($_POST['datesrfc']) && ! isset($_POST['datesday'])) +if (! isset($_POST['datesrfc']) && ! isset($_POST['datesday']) && ! empty($conf->global->PROJECT_LINKED_ELEMENT_DEFAULT_FILTER_YEAR)) { $new=dol_now(); $tmp=dol_getdate($new); diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 11bc8ffea09..a9cd64e33b5 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -91,12 +91,15 @@ if ($action == 'update' && ! $_POST["cancel"] && $user->rights->projet->creer) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; - $result=$object->update($user); - - if ($result < 0) + if (! $error) { - setEventMessages($object->error,$object->errors,'errors'); + $result=$object->update($user); + if ($result < 0) + { + setEventMessages($object->error,$object->errors,'errors'); + } } } else diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index c8628bd26a0..255e7fe9134 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -250,6 +250,7 @@ if ($action == 'add') // Fill array 'array_options' with data from add form $extralabels=$extrafields->fetch_name_optionals_label($adh->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels,$adh); + if ($ret < 0) $error++; $result=$adh->create($user); if ($result > 0) diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index 72e249ce542..065bbbc0ac8 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -195,7 +195,7 @@ if (empty($reshook)) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); - + if ($ret < 0) $error++; if (GETPOST('deletephoto')) $object->logo = ''; else if (! empty($_FILES['photo']['name'])) $object->logo = dol_sanitizeFileName($_FILES['photo']['name']); diff --git a/htdocs/user/card.php b/htdocs/user/card.php index cf10d93fe4e..0bcba1caca8 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -1,7 +1,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo - * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2005 Lionel Cousteix @@ -211,27 +211,28 @@ if ($action == 'add' && $canadduser) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; // If multicompany is off, admin users must all be on entity 0. + $entity=GETPOST('entity','int'); if (! empty($conf->multicompany->enabled)) { - $entity=GETPOST('entity','int'); if (! empty($_POST["superadmin"])) { $object->entity = 0; } else if ($conf->multicompany->transverse_mode) { - $object->entity = 1; // all users in master entity + $object->entity = 1; // all users are forced into master entity } else { - $object->entity = (empty($entity) ? 0 : $entity); + $object->entity = ($entity == '' ? 1 : $entity); } } else { - $object->entity = (empty($entity) ? 0 : $entity); + $object->entity = ($entity == '' ? 1 : $entity); } $db->begin(); @@ -358,6 +359,7 @@ if ($action == 'update' && ! $_POST["cancel"]) // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! empty($conf->multicompany->enabled)) { @@ -382,20 +384,22 @@ if ($action == 'update' && ! $_POST["cancel"]) if (GETPOST('deletephoto')) $object->photo=''; if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); - $ret=$object->update($user); - - if ($ret < 0) + if (! $error) { - $error++; - if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') - { - $langs->load("errors"); - setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors'); - } - else - { - setEventMessage($object->error, 'errors'); - } + $ret=$object->update($user); + if ($ret < 0) + { + $error++; + if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') + { + $langs->load("errors"); + setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors'); + } + else + { + setEventMessage($object->error, 'errors'); + } + } } if (! $error && isset($_POST['contactid'])) diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index a1930f7c027..56cfc5d9ee8 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -101,6 +101,7 @@ if ($action == 'add') // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"]; @@ -183,6 +184,7 @@ if ($action == 'update') // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels,$object); + if ($ret < 0) $error++; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $object->entity = 0; else $object->entity = $_POST["entity"];