diff --git a/ChangeLog b/ChangeLog index 31ddbd56bdd..3eb284ccc80 100644 --- a/ChangeLog +++ b/ChangeLog @@ -13,7 +13,9 @@ Following changes may create regression for some external modules, but were nece * The page compta/facture.php was renamed into compta/facture/card.php to match page naming conventions. * The signature of method ->delete() of class Product and PriceExpression was changed from ->delete($id, notrigger) to ->delete(User, notrigger) to match standard dev rules. - +* Removed CommonObject::displayMarginInfos (was deprecated in 3.8). Use same method into + html.formmargin.class.php +* Removed Societe::set_commnucation_level (was deprecated in 4.0). Was not used. ***** ChangeLog for 5.0.1 compared to 5.0.0 ***** FIX: #6503: SQL error in "Last pending payment invoices" diff --git a/build/debian/README.howto b/build/debian/README.howto index 705899d47c4..399c4f07a1f 100644 --- a/build/debian/README.howto +++ b/build/debian/README.howto @@ -385,13 +385,14 @@ http://packages.qa.debian.org * Package will be into release when test will be moved as stable. -##### Send an unblock request + +##### Send an unblock request to make a full update of a stable package Use this to move from unstable to testing. reportbug -B debian --smtphost=smtp.gmail.com:587 --smtpuser=xxxx --smtppasswd=yyyy --tls Choose package "release.debian.org" -Then "unblock" +Then usertag "unblock" Then name of package "dolibarr" Fill message, for example: "Please unblock package dolibarr @@ -400,12 +401,11 @@ Note that package 3.5.7 contains not only fixed for bugs reported to debian. It so it is a better solution to validate this maintenance release than applying a patch of the only CVE-2015-3935. After discussion with ..., it appears that security holes are enough to request this unblock request." - -Use this to request an update of a stable package +Use this to request an full update of a stable package reportbug -B debian --smtphost=smtp.gmail.com:587 --smtpuser=xxxx --smtppasswd=yyyy --tls Choose package "release.debian.org" -Then "unblock" +Then usertag "unblock" Then name of package "dolibarr" Fill message, for example: " @@ -417,11 +417,26 @@ Pro are: - It fixes also stability bugs - Patches were already tested because deployed and used by several thousands of users. - It is easier for package maintener to include this official set of fixes than applying one patch after one patch for each debian report or backported each patch into a dedicated version. -- Debian maintenance version matches with official project maintenance version (better when all fixes are not related to the way the software is packaged) +- Debian maintenance version is inline with official project maintenance version (better when all fixes are not related to the way the software is packaged) Cons are: -- The patch include more than the only one security reported fxes +- The patch include more than the only one security reported fixes So I just need to know if it's ok to push such a version 3.5.7 (fixes for 3.5.* branch) instead of only one fix for only the few (the only) reported debian bugs, since it provides more stability and is for me a more secured process. " +##### Send an request to ask a simple fix of a stable package + +Use this to ask to apply patches on a stable version. + +reportbug -B debian --smtphost=smtp.gmail.com:587 --smtpuser=xxxx --smtppasswd=yyyy --tls +Choose package "release.debian.org" +Then usertag "jessie-pu" +Then name of package "dolibarr" +Fill message, for example: +"Please unblock package dolibarr +A security error CVE-2015-3935 was reported and is fixed into package 3.5.7. +Note that package 3.5.7 contains not only fixed for bugs reported to debian. It includes other fixes, but they are all related to stability or security, +so it is a better solution to validate this maintenance release than applying a patch of the only CVE-2015-3935. +After discussion with ..., it appears that security holes are enough to request this unblock request." + diff --git a/build/debian/install.forced.php.install b/build/debian/install.forced.php.install index 56eef3287a6..e55ffae138e 100644 --- a/build/debian/install.forced.php.install +++ b/build/debian/install.forced.php.install @@ -7,7 +7,7 @@ // $force_install_packager='deb'; -$force_install_noedit=2; +$force_install_noedit=1; $force_install_message='KeepDefaultValuesDeb'; #$force_install_main_data_root='/usr/share/dolibarr/documents'; $force_install_main_data_root='/var/lib/dolibarr/documents'; diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index d287afe4b86..b1282719cda 100755 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -509,7 +509,7 @@ if ($nboftargetok) { $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/documents`; # Removed known external modules to avoid any error when packaging from env where external modules are tested - $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/custom/*`; # For custom we want to keep dir + #$ret=`find $BUILDROOT/$PROJECT/htdocs/custom/* -type d -exec rm -fr {} \;`; # For custom we want to keep dir $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/allscreens*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/ancotec*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/cabinetmed*`; @@ -550,6 +550,7 @@ if ($nboftargetok) { $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/mike42/escpos-php/doc`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/mike42/escpos-php/example`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/mike42/escpos-php/test`; + $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/mobiledetect/mobiledetectlib/.gitmodules`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/nusoap/lib/Mail`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/nusoap/samples`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/includes/php-iban/docs`; diff --git a/htdocs/accountancy/admin/accountmodel.php b/htdocs/accountancy/admin/accountmodel.php index d2b039a28e0..55c194cd416 100644 --- a/htdocs/accountancy/admin/accountmodel.php +++ b/htdocs/accountancy/admin/accountmodel.php @@ -757,8 +757,7 @@ if ($id) { print '* '.$langs->trans("AvailableVariables").": "; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; - $formmail=new FormMail($db); - $tmp=$formmail->getAvailableSubstitKey('form'); + $tmp=FormMail::getAvailableSubstitKey('formemail'); print implode(', ', $tmp); print ''; } @@ -901,8 +900,8 @@ if ($id) if ($id == 4) print ''; print ''; print ''; - $searchpitco=$form->showFilterAndCheckAddButtons(0); - print $searchpitco; + $searchpicto=$form->showFilterAndCheckAddButtons(0); + print $searchpicto; print ''; print ''; diff --git a/htdocs/accountancy/admin/export.php b/htdocs/accountancy/admin/export.php index f7bbbb97969..eaf69f34f1f 100644 --- a/htdocs/accountancy/admin/export.php +++ b/htdocs/accountancy/admin/export.php @@ -130,7 +130,7 @@ print '
'; print ''; print ''; -dol_fiche_head($head, 'export', $langs->trans("Configuration"), 0, 'cron'); +dol_fiche_head($head, 'export', $langs->trans("Configuration"), -1, 'cron'); $var = true; diff --git a/htdocs/accountancy/admin/index.php b/htdocs/accountancy/admin/index.php index 3ea77a24b43..899aaa1a3d2 100644 --- a/htdocs/accountancy/admin/index.php +++ b/htdocs/accountancy/admin/index.php @@ -171,7 +171,7 @@ print ''; print ''; print ''; -dol_fiche_head($head, 'general', $langs->trans("Configuration"), 0, 'cron'); +dol_fiche_head($head, 'general', $langs->trans("Configuration"), -1, 'cron'); // Default mode for calculating turnover (parameter ACCOUNTING_MODE) @@ -299,7 +299,7 @@ print '
transnoentitiesnoconv("Home").'-'.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy")); +print '
'.$langs->trans("AccountancySetupDoneFromAccountancyMenu", $langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy")).'
'; print '
'; print ''; diff --git a/htdocs/accountancy/admin/journals.php b/htdocs/accountancy/admin/journals.php index 03b51089d9a..677f2a743e5 100644 --- a/htdocs/accountancy/admin/journals.php +++ b/htdocs/accountancy/admin/journals.php @@ -94,7 +94,7 @@ print load_fiche_titre($langs->trans('ConfigAccountingExpert'), $linkback, 'titl $head = admin_accounting_prepare_head(null); -dol_fiche_head($head, 'journal', $langs->trans("Configuration"), 0, 'cron'); +dol_fiche_head($head, 'journal', $langs->trans("Configuration"), -1, 'cron'); $sql = "SELECT j.rowid, j.code, j.label, j.nature, j.active"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_journal as j"; diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 116e071e42f..ce0bd4d3aa2 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -305,6 +305,8 @@ if ($action == 'create') { dol_fiche_head(); + print '
'; + print ''; print ''; print ''; @@ -328,6 +330,8 @@ if ($action == 'create') { print ''; print '
' . $langs->trans("NumMvts") . '
'; + print '
'; + dol_fiche_end(); print '
'; @@ -427,8 +431,8 @@ if ($action == 'create') { print $formventilation->select_auxaccount($code_tiers, 'code_tiers', 1); print ''; print ''; - print ''; - print ''; + print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 9cd649ce4be..75d0a63bf39 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -360,7 +360,7 @@ if (count($filter)) $button.= $langs->trans("ExportFilteredList"); else $button.= $langs->trans("ExportList"); $button.= ''; -$groupby = ' ' . $langs->trans("GroupByAccountAccounting") . ''; +$groupby = ' ' . $langs->trans("GroupByAccountAccounting") . ''; print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $button, $result, $nbtotalofrecords, 'title_accountancy', 0, $groupby, '', $limit); @@ -437,7 +437,7 @@ foreach ($object->lines as $line ) { print '' . $line->piece_num . ''; print '' . dol_print_date($line->doc_date, 'day') . ''; - print '' . $line->doc_ref . ''; + print '' . $line->doc_ref . ''; print '' . length_accountg($line->numero_compte) . ''; print '' . length_accounta($line->code_tiers) . ''; print '' . $line->label_compte . ''; diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index cbb83ba269e..2323f3afcb8 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -207,7 +207,7 @@ if ($action == 'delbookkeepingyear') { print '
'; -$viewflat = ' ' . $langs->trans("ViewFlatList") . ''; +$viewflat = ' ' . $langs->trans("ViewFlatList") . ''; print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords,'title_accountancy',0,$viewflat,'',$limit); @@ -222,17 +222,6 @@ print '
'; -print ''; -print '' . $langs->trans("AccountAccounting") . ''; -print_liste_field_titre($langs->trans("TransactionNumShort"), $_SERVER['PHP_SELF'], "t.piece_num", "", $options, 'align="right"', $sortfield, $sortorder); -print_liste_field_titre($langs->trans("Docdate"), $_SERVER['PHP_SELF'], "t.doc_date", "", $options, 'align="center"', $sortfield, $sortorder); -print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "t.doc_ref", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre($langs->trans("SuppliersInvoices") . ' / ' . $langs->trans("CustomersInvoices")); -print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder); -print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder); -print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="right"', $sortfield, $sortorder); -print_liste_field_titre('', $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); -print "\n"; print ''; print '' . $object->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '') . ''; @@ -254,6 +243,18 @@ $searchpitco=$form->showFilterAndCheckAddButtons(0); print $searchpitco; print ''; +print ''; +print_liste_field_titre($langs->trans("AccountAccountingShort"), $_SERVER['PHP_SELF']); +print_liste_field_titre($langs->trans("TransactionNumShort"), $_SERVER['PHP_SELF'], "t.piece_num", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Docdate"), $_SERVER['PHP_SELF'], "t.doc_date", "", $options, 'align="center"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "t.doc_ref", "", $options, "", $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Label")); +print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre('', $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); +print "\n"; + print ''; $var = True; @@ -277,9 +278,10 @@ foreach ( $object->lines as $line ) { // Affiche un Sous-Total par compte comptable if (isset($displayed_account_number)) { - print ''.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).''; - print " \n"; - print ''; + print ''.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).''; + print " \n"; + print " \n"; + print ''; } // Show the break account @@ -299,17 +301,18 @@ foreach ( $object->lines as $line ) { print ''; print ' '; - print ''.$line->piece_num.''; + print ''.$line->piece_num.''; print '' . dol_print_date($line->doc_date, 'day') . ''; - print '' . $line->doc_ref . ''; + + // TODO Add a link according to doc_type and fk_doc + print ''; + //if ($line->doc_type == 'supplier_invoice') + //if ($line->doc_type == 'customer_invoice') + print $line->doc_ref; + print ''; // Affiche un lien vers la facture client/fournisseur $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref); - if ($line->doc_type == 'supplier_invoice') - print strlen(length_accounta($line->code_tiers)) == 0 ? '' . $line->label_compte . '' : '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')'; - elseif ($line->doc_type == 'customer_invoice') - print strlen(length_accounta($line->code_tiers)) == 0 ? '' . $line->label_compte . '' : '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')'; - else print strlen(length_accounta($line->code_tiers)) == 0 ? '' . $line->label_compte . '' : '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')'; @@ -332,6 +335,7 @@ foreach ( $object->lines as $line ) { print ''; print ''.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).''; print " \n"; +print " \n"; print ''; diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 754dd262369..8f31b40bc54 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -169,7 +169,15 @@ class BookKeeping extends CommonObject if (empty($this->numero_compte) || $this->numero_compte == '-1') { $langs->load("errors"); - $this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet); + if (in_array($this->doc_type, array('bank', 'expense_report'))) + { + $this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForBankLine', $this->fk_docdet, $this->doc_type); + } + else + { + $this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForInvoiceLine', $this->fk_doc, $this->doc_type); + } + return -1; } @@ -178,11 +186,12 @@ class BookKeeping extends CommonObject $this->piece_num = 0; - // first check if line not yet in bookkeeping + // First check if line not yet already in bookkeeping $sql = "SELECT count(*) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE doc_type = '" . $this->doc_type . "'"; - $sql .= " AND fk_docdet = " . $this->fk_docdet; + $sql .= " AND fk_doc = " . $this->fk_doc; + $sql .= " AND fk_docdet = " . $this->fk_docdet; // This field can be 0 is record is for several lines $sql .= " AND numero_compte = '" . $this->numero_compte . "'"; $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index a015fa05929..428e490aff7 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -43,6 +43,7 @@ $langs->load("productbatch"); $account_parent = GETPOST('account_parent'); $changeaccount = GETPOST('changeaccount'); // Search Getpost +$search_lineid = GETPOST('search_lineid', 'int'); $search_ref = GETPOST('search_ref', 'alpha'); $search_invoice = GETPOST('search_invoice', 'alpha'); $search_label = GETPOST('search_label', 'alpha'); @@ -86,6 +87,7 @@ $formventilation = new FormVentilation($db); // Purge search criteria if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers { + $search_lineid = ''; $search_ref = ''; $search_invoice = ''; $search_label = ''; @@ -151,7 +153,7 @@ print ''."\n"; } diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 53035dca96f..03a7759e52c 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -255,7 +255,7 @@ class Paiement extends CommonObject { if (! empty($conf->prelevement->enabled)) { - // TODO Check if this payment has a withdraw request + // FIXME Check if this invoice has a withdraw request // if not, $mustwait++; // This will disable automatic close on invoice to allow to process } } @@ -275,11 +275,61 @@ class Paiement extends CommonObject else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more."); else { - $result=$invoice->set_paid($user,'',''); - if ($result<0) + // If invoice is a down payment, we also convert down payment to discount + if ($invoice->type == Facture::TYPE_DEPOSIT) { - $this->error=$invoice->error; - $error++; + $amount_ht = $amount_tva = $amount_ttc = array(); + + // Loop on each vat rate + $i = 0; + foreach ($invoice->lines as $line) + { + if ($line->total_ht!=0) + { // no need to create discount if amount is null + $amount_ht[$line->tva_tx] += $line->total_ht; + $amount_tva[$line->tva_tx] += $line->total_tva; + $amount_ttc[$line->tva_tx] += $line->total_ttc; + $i ++; + } + } + + // Insert one discount by VAT rate category + $discount = new DiscountAbsolute($this->db); + $discount->description = '(DEPOSIT)'; + $discount->fk_soc = $invoice->socid; + $discount->fk_facture_source = $invoice->id; + + foreach ($amount_ht as $tva_tx => $xxx) + { + $discount->amount_ht = abs($amount_ht[$tva_tx]); + $discount->amount_tva = abs($amount_tva[$tva_tx]); + $discount->amount_ttc = abs($amount_ttc[$tva_tx]); + $discount->tva_tx = abs($tva_tx); + + $result = $discount->create($user); + if ($result < 0) + { + $error++; + break; + } + } + + if ($error) + { + setEventMessages($discount->error, $discount->errors, 'errors'); + $error++; + } + } + + // Set invoice to paid + if (! $error) + { + $result=$invoice->set_paid($user,'',''); + if ($result<0) + { + $this->error=$invoice->error; + $error++; + } } } } diff --git a/htdocs/core/ajax/check_notifications.php b/htdocs/core/ajax/check_notifications.php index 4db67aef939..fa3edd7a4be 100644 --- a/htdocs/core/ajax/check_notifications.php +++ b/htdocs/core/ajax/check_notifications.php @@ -21,7 +21,6 @@ if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); -if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); require '../../main.inc.php'; @@ -88,9 +87,11 @@ if ($time >= $_SESSION['auto_check_events_not_before']) while ($obj = $db->fetch_object($resql)) { $langs->load("agenda"); + $langs->load("commercial"); $actionmod->fetch($obj->id); + // Message must be formated and translated to be used with javascript directly $event = array(); $event['type'] = 'agenda'; $event['id'] = $actionmod->id; @@ -101,6 +102,10 @@ if ($time >= $_SESSION['auto_check_events_not_before']) $eventfound[] = $event; } } + else + { + dol_syslog("Error sql = ".$db->lasterror(), LOG_ERR); + } } diff --git a/htdocs/core/boxes/box_external_rss.php b/htdocs/core/boxes/box_external_rss.php index 71b643665b3..14e542ff101 100644 --- a/htdocs/core/boxes/box_external_rss.php +++ b/htdocs/core/boxes/box_external_rss.php @@ -80,8 +80,11 @@ class box_external_rss extends ModeleBoxes // documents/externalrss is created by module activation // documents/externalrss/tmp is created by rssparser + $keyforparamurl="EXTERNAL_RSS_URLRSS_".$site; + $keyforparamtitle="EXTERNAL_RSS_TITLE_".$site; + // Get RSS feed - $url=@constant("EXTERNAL_RSS_URLRSS_".$site); + $url=$conf->global->$keyforparamurl; $rssparser=new RssParser($this->db); $result = $rssparser->parser($url, $this->max, $cachedelay, $conf->externalrss->dir_temp); @@ -90,7 +93,7 @@ class box_external_rss extends ModeleBoxes $description=$rssparser->getDescription(); $link=$rssparser->getLink(); - $title=$langs->trans("BoxTitleLastRssInfos",$max, @constant("EXTERNAL_RSS_TITLE_". $site)); + $title=$langs->trans("BoxTitleLastRssInfos", $max, $conf->global->$keyforparamtitle); if ($result < 0 || ! empty($rssparser->error)) { // Show warning diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index 3e9d56f8f8c..4d9fa7a72af 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -51,7 +51,8 @@ abstract class CommonInvoice extends CommonObject const TYPE_DEPOSIT = 3; /** - * Proforma invoice + * Proforma invoice. + * @deprectad Remove this. A "proforma invoice" is an order with a look of invoice, not an invoice ! */ const TYPE_PROFORMA = 4; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index e03db1b4773..16bff11b5fd 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -11,6 +11,7 @@ * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2015 Alexandre Spangaro * Copyright (C) 2016 Bahfir abbes + * Copyright (C) 2017 ATM Consulting * * 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 @@ -238,6 +239,7 @@ abstract class CommonObject /** * @var int Delivery address ID + * @deprecated * @see setDeliveryAddress() */ public $fk_delivery_address; @@ -1623,7 +1625,8 @@ abstract class CommonObject /** * Define delivery address - * + * @deprecated + * * @param int $id Address id * @return int <0 si ko, >0 si ok */ @@ -3223,51 +3226,14 @@ abstract class CommonObject /** * Return if a country is inside the EEC (European Economic Community) - * TODO Add a field into dictionary + * @deprecated * * @return boolean true = country inside EEC, false = country outside EEC */ function isInEEC() { - // List of all country codes that are in europe for european vat rules - // List found on http://ec.europa.eu/taxation_customs/common/faq/faq_1179_en.htm#9 - $country_code_in_EEC=array( - 'AT', // Austria - 'BE', // Belgium - 'BG', // Bulgaria - 'CY', // Cyprus - 'CZ', // Czech republic - 'DE', // Germany - 'DK', // Danemark - 'EE', // Estonia - 'ES', // Spain - 'FI', // Finland - 'FR', // France - 'GB', // United Kingdom - 'GR', // Greece - 'HR', // Croatia - 'NL', // Holland - 'HU', // Hungary - 'IE', // Ireland - 'IM', // Isle of Man - Included in UK - 'IT', // Italy - 'LT', // Lithuania - 'LU', // Luxembourg - 'LV', // Latvia - 'MC', // Monaco - Included in France - 'MT', // Malta - //'NO', // Norway - 'PL', // Poland - 'PT', // Portugal - 'RO', // Romania - 'SE', // Sweden - 'SK', // Slovakia - 'SI', // Slovenia - 'UK', // United Kingdom - //'CH', // Switzerland - No. Swizerland in not in EEC - ); - //print "dd".$this->country_code; - return in_array($this->country_code,$country_code_in_EEC); + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + return isInEEC($this); } @@ -3754,21 +3720,6 @@ abstract class CommonObject } - /** - * Show the array with all margin infos - * - * @param bool $force_price Force price - * @return void - * @deprecated 3.8 Load FormMargin class and make a direct call to displayMarginInfos - */ - function displayMarginInfos($force_price=false) - { - include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmargin.class.php'; - $formmargin=new FormMargin($this->db); - $formmargin->displayMarginInfos($this, $force_price); - } - - /** * Add resources to the current object : add entry into llx_element_resources * Need $this->element & $this->id @@ -4711,4 +4662,364 @@ abstract class CommonObject } return $buyPrice; } + + /** + * Function test if type is date + * + * @param array $info content informations of field + * @return bool + */ + protected function isDate($info) + { + if(isset($info['type']) && $info['type']=='date') return true; + else return false; + } + + /** + * Function test if type is array + * + * @param array $info content informations of field + * @return bool + */ + protected function isArray($info) + { + if(is_array($info)) + { + if(isset($info['type']) && $info['type']=='array') return true; + else return false; + } + else return false; + } + + /** + * Function test if type is null + * + * @param array $info content informations of field + * @return bool + */ + protected function isNull($info) + { + if(is_array($info)) + { + if(isset($info['type']) && $info['type']=='null') return true; + else return false; + } + else return false; + } + + /** + * Function test if type is integer + * + * @param array $info content informations of field + * @return bool + */ + protected function isInt($info) + { + if(is_array($info)) + { + if(isset($info['type']) && ($info['type']=='int' || $info['type']=='integer' )) return true; + else return false; + } + else return false; + } + + /** + * Function test if type is float + * + * @param array $info content informations of field + * @return bool + */ + protected function isFloat($info) + { + if(is_array($info)) + { + if(isset($info['type']) && $info['type']=='float') return true; + else return false; + } + else return false; + } + + /** + * Function test if type is text + * + * @param array $info content informations of field + * @return bool + */ + protected function isText($info) + { + if(is_array($info)) + { + if(isset($info['type']) && $info['type']=='text') return true; + else return false; + } + else return false; + } + + /** + * Function test if is indexed + * + * @param array $info content informations of field + * @return bool + */ + protected function isIndex($info) + { + if(is_array($info)) + { + if(isset($info['index']) && $info['index']==true) return true; + else return false; + } + else return false; + } + + /** + * Function to prepare the values to insert + * + * @return array + */ + private function set_save_query() + { + $query=array(); + foreach ($this->fields as $field=>$info) + { + if($this->isDate($info)) + { + if(empty($this->{$field})) + { + $query[$field] = NULL; + } + else + { + $query[$field] = $this->db->idate($this->{$field}); + } + } + else if($this->isArray($info)) + { + $query[$field] = serialize($this->{$field}); + } + else if($this->isInt($info)) + { + $query[$field] = (int) price2num($this->{$field}); + } + else if($this->isFloat($info)) + { + $query[$field] = (double) price2num($this->{$field}); + } + elseif($this->isNull($info)) + { + $query[$field] = (is_null($this->{$field}) || (empty($this->{$field}) && $this->{$field}!==0 && $this->{$field}!=='0') ? null : $this->{$field}); + } + else + { + $query[$field] = $this->{$field}; + } + } + + return $query; + } + + /** + * Create object into database + * + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, Id of created object if OK + */ + public function createCommon(User $user, $notrigger = false) + { + + $fields = array_merge(array('datec'=>$this->db->idate(dol_now())), $this->set_save_query()); + + foreach ($fields as $k => $v) { + + $keys[] = $k; + $values[] = $this->quote($v); + + } + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.' + ( '.implode( ",", $keys ).' ) + VALUES ( '.implode( ",", $values ).' ) '; + $res = $this->db->query( $sql ); + if($res===false) { + + return false; + } + + // TODO Add triggers + + return true; + + } + + /** + * Function to load data into current object this + * + * @param stdClass $obj Contain data of object from database + */ + private function set_vars_by_db(&$obj) + { + foreach ($this->fields as $field => $info) + { + if($this->isDate($info)) + { + if(empty($obj->{$field}) || $obj->{$field} === '0000-00-00 00:00:00' || $obj->{$field} === '1000-01-01 00:00:00') $this->{$field} = 0; + else $this->{$field} = strtotime($obj->{$field}); + } + elseif($this->isArray($info)) + { + $this->{$field} = @unserialize($obj->{$field}); + // Hack for data not in UTF8 + if($this->{$field } === FALSE) @unserialize(utf8_decode($obj->{$field})); + } + elseif($this->isInt($info)) + { + $this->{$field} = (int) $obj->{$field}; + } + elseif($this->isFloat($info)) + { + $this->{$field} = (double) $obj->{$field}; + } + elseif($this->isNull($info)) + { + $val = $obj->{$field}; + // zero is not null + $this->{$field} = (is_null($val) || (empty($val) && $val!==0 && $val!=='0') ? null : $val); + } + else + { + $this->{$field} = $obj->{$field}; + } + + } + } + + /** + * Function to concat keys of fields + * + * @return string + */ + private function get_field_list() + { + $keys = array_keys($this->fields); + return implode(',', $keys); + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @param string $ref Ref + * + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetchCommon($id, $ref = null) + { + + if (empty($id) && empty($ref)) return false; + + $sql = 'SELECT '.$this->get_field_list().', datec, tms'; + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; + + if(!empty($id)) $sql.= ' WHERE rowid = '.$id; + else $sql.= ' WHERE ref = \''.$this->quote($ref).'\''; + + $res = $this->db->query($sql); + if($obj = $this->db->fetch_object($res)) + { + $this->id = $id; + $this->set_vars_by_db($obj); + + $this->datec = $this->db->idate($obj->datec); + $this->tms = $this->db->idate($obj->tms); + + return $this->id; + } + else + { + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + return -1; + } + + } + + /** + * Update object into database + * + * @param User $user User that modifies + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, >0 if OK + */ + public function updateCommon(User $user, $notrigger = false) + { + $fields = $this->set_save_query(); + + foreach ($fields as $k => $v) { + + if (is_array($key)){ + $i=array_search($k, $key); + if ( $i !== false) { + $where[] = $key[$i].'=' . $this->quote( $v ) ; + continue; + } + } else { + if ( $k == $key) { + $where[] = $k.'=' .$this->quote( $v ) ; + continue; + } + } + + $tmp[] = $k.'='.$this->quote($v); + } + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode( ',', $tmp ).' WHERE rowid='.$this->id ; + $res = $this->db->query( $sql ); + + if($res===false) { + //error + return false; + } + + // TODO Add triggers + + return true; + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, >0 if OK + */ + public function deleteCommon(User $user, $notrigger = false) + { + $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.$this->id; + + $res = $this->db->query( $sql ); + if($res===false) { + return false; + } + + // TODO Add triggers + + return true; + } + + /** + * Add quote to field value if necessary + * + * @param string|int $value value to protect + * @return string|int + */ + protected function quote($value) { + + if(is_null($value)) return 'NULL'; + else if(is_numeric($value)) return $value; + else return "'".$this->db->escape( $value )."'"; + + } + } + diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 9446020e3ff..28a287971a8 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -210,7 +210,7 @@ class Conf $file=dol_sanitizeFileName($file); include_once DOL_DOCUMENT_ROOT . "/".$file."/".$file."_consts.php"; foreach ($file2bddconsts as $key=>$value) { - $this->global->$key=constant($value); + $this->global->$key=$value; } } } @@ -358,8 +358,8 @@ class Conf $this->supplier_order->dir_temp=$rootfordata."/fournisseur/commande/temp"; $this->supplier_invoice=new stdClass(); $this->supplier_invoice->enabled=1; - $this->supplier_order->dir_output=$rootfordata."/fournisseur/facture"; - $this->supplier_order->dir_temp=$rootfordata."/fournisseur/facture/temp"; + $this->supplier_invoice->dir_output=$rootfordata."/fournisseur/facture"; + $this->supplier_invoice->dir_temp=$rootfordata."/fournisseur/facture/temp"; } } diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php new file mode 100644 index 00000000000..021213594f7 --- /dev/null +++ b/htdocs/core/class/coreobject.class.php @@ -0,0 +1,440 @@ + + * + * 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/core/class/coreobject.class.php + * \ingroup core + * \brief File of class to manage all object. Might be replace or merge into commonobject + */ + +require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; + +class CoreObject extends CommonObject +{ + public $withChild = true; + + /** + * @var Array $_fields Fields to synchronize with Database + */ + protected $fields=array(); + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct(DoliDB &$db) + { + $this->db = $db; + } + + /** + * Function to init fields + * + * @return bool + */ + protected function init() + { + $this->id = 0; + $this->datec = 0; + $this->tms = 0; + + if (!empty($this->fields)) + { + foreach ($this->fields as $field=>$info) + { + if ($this->isDate($info)) $this->{$field} = time(); + elseif ($this->isArray($info)) $this->{$field} = array(); + elseif ($this->isInt($info)) $this->{$field} = (int) 0; + elseif ($this->isFloat($info)) $this->{$field} = (double) 0; + else $this->{$field} = ''; + } + + $this->to_delete=false; + $this->is_clone=false; + + return true; + } + else + { + return false; + } + + } + + /** + * Test type of field + * + * @param string $field name of field + * @param string $type type of field to test + * @return value of field or false + */ + private function checkFieldType($field, $type) + { + if (isset($this->fields[$field]) && method_exists($this, 'is_'.$type)) + { + return $this->{'is_'.$type}($this->fields[$field]); + } + else + { + return false; + } + } + + /** + * Get object and children from database + * + * @param int $id Id of object to load + * @param bool $loadChild used to load children from database + * @return int >0 if OK, <0 if KO, 0 if not found + */ + public function fetch($id, $loadChild = true) + { + + $res = $this->fetchCommon($id); + if($res>0) { + if ($loadChild) $this->fetchChild(); + } + + return $res; + + } + + + /** + * Function to instantiate a new child + * + * @param string $tabName Table name of child + * @param int $id If id is given, we try to return his key if exist or load if we try_to_load + * @param string $key Attribute name of the object id + * @param bool $try_to_load Force the fetch if an id is given + * @return int + */ + public function addChild($tabName, $id=0, $key='id', $try_to_load = false) + { + if(!empty($id)) + { + foreach($this->{$tabName} as $k=>&$object) + { + if($object->{$key} === $id) return $k; + } + } + + $k = count($this->{$tabName}); + + $className = ucfirst($tabName); + $this->{$tabName}[$k] = new $className($this->db); + if($id>0 && $key==='id' && $try_to_load) + { + $this->{$tabName}[$k]->fetch($id); + } + + return $k; + } + + + /** + * Function to set a child as to delete + * + * @param string $tabName Table name of child + * @param int $id Id of child to set as to delete + * @param string $key Attribute name of the object id + * @return bool + */ + public function removeChild($tabName, $id, $key='id') + { + foreach ($this->{$tabName} as &$object) + { + if ($object->{$key} == $id) + { + $object->to_delete = true; + return true; + } + } + return false; + } + + + /** + * Function to fetch children objects + */ + public function fetchChild() + { + if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) + { + foreach($this->childtables as &$childTable) + { + $className = ucfirst($childTable); + + $this->{$className}=array(); + + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.$childTable.' WHERE '.$this->fk_element.' = '.$this->id; + $res = $this->db->query($sql); + + if($res) + { + while($obj = $this->db->fetch_object($res)) + { + $o=new $className($this->db); + $o->fetch($obj->rowid); + + $this->{$className}[] = $o; + } + } + else + { + $this->errors[] = $this->db->lasterror(); + } + } + } + } + + /** + * Function to update children data + * + * @param User $user user object + */ + public function saveChild(User &$user) + { + if($this->withChild && !empty($this->childtables) && !empty($this->fk_element)) + { + foreach($this->childtables as &$childTable) + { + $className = ucfirst($childTable); + if(!empty($this->{$className})) + { + foreach($this->{$className} as $i => &$object) + { + $object->{$this->fk_element} = $this->id; + + $object->update($user); + if($this->unsetChildDeleted && isset($object->to_delete) && $object->to_delete==true) unset($this->{$className}[$i]); + } + } + } + } + } + + + /** + * Function to update object or create or delete if needed + * + * @param User $user user object + * @return < 0 if ko, > 0 if ok + */ + public function update(User &$user) + { + if (empty($this->id)) return $this->create($user); // To test, with that, no need to test on high level object, the core decide it, update just needed + elseif (isset($this->to_delete) && $this->to_delete==true) return $this->delete($user); + + $error = 0; + $this->db->begin(); + + $res = $this->updateCommon($user); + if ($res) + { + $result = $this->call_trigger(strtoupper($this->element). '_UPDATE', $user); + if ($result < 0) $error++; + else $this->saveChild($user); + } + else + { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + } + + if (empty($error)) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1; + } + + } + + /** + * Function to create object in database + * + * @param User $user user object + * @return < 0 if ko, > 0 if ok + */ + public function create(User &$user) + { + if($this->id > 0) return $this->update($user); + + $error = 0; + $this->db->begin(); + + $res = $this->createCommon($user); + if($res) + { + $this->id = $this->db->last_insert_id($this->table_element); + + $result = $this->call_trigger(strtoupper($this->element). '_CREATE', $user); + if ($result < 0) $error++; + else $this->saveChild($user); + } + else + { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + } + + if (empty($error)) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + /** + * Function to delete object in database + * + * @param User $user user object + * @return < 0 if ko, > 0 if ok + */ + public function delete(User &$user) + { + if ($this->id <= 0) return 0; + + $error = 0; + $this->db->begin(); + + $result = $this->call_trigger(strtoupper($this->element). '_DELETE', $user); + if ($result < 0) $error++; + + if (!$error) + { + $this->deleteCommon($user); + if($this->withChild && !empty($this->childtables)) + { + foreach($this->childtables as &$childTable) + { + $className = ucfirst($childTable); + if (!empty($this->{$className})) + { + foreach($this->{$className} as &$object) + { + $object->delete($user); + } + } + } + } + } + + if (empty($error)) + { + $this->db->commit(); + return 1; + } + else + { + $this->error = $this->db->lasterror(); + $this->errors[] = $this->error; + $this->db->rollback(); + return -1; + } + } + + + /** + * Function to get a formatted date + * + * @param string $field Attribute to return + * @param string $format Output date format + * @return string + */ + public function getDate($field, $format='') + { + if(empty($this->{$field})) return ''; + else + { + return dol_print_date($this->{$field}, $format); + } + } + + /** + * Function to set date in field + * + * @param string $field field to set + * @param string $date formatted date to convert + * @return mixed + */ + public function setDate($field, $date) + { + if (empty($date)) + { + $this->{$field} = 0; + } + else + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; + $this->{$field} = dol_stringtotime($date); + } + + return $this->{$field}; + } + + + /** + * Function to update current object + * + * @param array $Tab Array of values + * @return int + */ + public function setValues(&$Tab) + { + foreach ($Tab as $key => $value) + { + if($this->checkFieldType($key, 'date')) + { + $this->setDate($key, $value); + } + else if( $this->checkFieldType($key, 'array')) + { + $this->{$key} = $value; + } + else if( $this->checkFieldType($key, 'float') ) + { + $this->{$key} = (double) price2num($value); + } + else if( $this->checkFieldType($key, 'int') ) { + $this->{$key} = (int) price2num($value); + } + else + { + $this->{$key} = $value; + } + } + + return 1; + } + +} diff --git a/htdocs/core/class/ctyperesource.class.php b/htdocs/core/class/ctyperesource.class.php new file mode 100644 index 00000000000..1de616210e4 --- /dev/null +++ b/htdocs/core/class/ctyperesource.class.php @@ -0,0 +1,500 @@ + + * Copyright (C) 2014-2016 Juanjo Menent + * Copyright (C) 2016 Florian Henry + * Copyright (C) 2015 Raphaël Doursenaud + * + * 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 resource/ctyperesource.class.php + * \ingroup resource + */ + +/** + * Class Ctyperesource + * + * Put here description of your class + * + * @see CommonObject + */ +class Ctyperesource +{ + /** + * @var string Id to identify managed objects + */ + public $element = 'ctyperesource'; + /** + * @var string Name of table without prefix where object is stored + */ + public $table_element = 'c_type_resource'; + + /** + * @var CtyperesourceLine[] Lines + */ + public $lines = array(); + + /** + */ + + public $code; + public $label; + public $active; + + /** + */ + + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + public function __construct(DoliDB $db) + { + $this->db = $db; + } + + /** + * Create object into database + * + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, Id of created object if OK + */ + public function create(User $user, $notrigger = false) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $error = 0; + + // Clean parameters + + if (isset($this->code)) { + $this->code = trim($this->code); + } + if (isset($this->label)) { + $this->label = trim($this->label); + } + if (isset($this->active)) { + $this->active = trim($this->active); + } + + + + // Check parameters + // Put here code to add control on parameters values + + // Insert request + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; + + $sql.= 'code,'; + $sql.= 'label'; + $sql.= 'active'; + + + $sql .= ') VALUES ('; + + $sql .= ' '.(! isset($this->code)?'NULL':"'".$this->db->escape($this->code)."'").','; + $sql .= ' '.(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").','; + $sql .= ' '.(! isset($this->active)?'NULL':$this->active); + + + $sql .= ')'; + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + } + + if (!$error) { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); + + if (!$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action to call a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_CREATE',$user); + //if ($result < 0) $error++; + //// End call triggers + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return $this->id; + } + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @param string $code code + * @param string $label Label + * + * @return int <0 if KO, 0 if not found, >0 if OK + */ + public function fetch($id,$code='',$label='') + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.code,"; + $sql .= " t.label,"; + $sql .= " t.active"; + + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + if ($id) $sql.= " WHERE t.id = ".$id; + elseif ($code) $sql.= " WHERE t.code = '".$this->db->escape($code)."'"; + elseif ($label) $sql.= " WHERE t.label = '".$this->db->escape($label)."'"; + + + $resql = $this->db->query($sql); + if ($resql) { + $numrows = $this->db->num_rows($resql); + if ($numrows) { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->code = $obj->code; + $this->label = $obj->label; + $this->active = $obj->active; + + + } + + // Retrieve all extrafields for invoice + // fetch optionals attributes and labels + /* + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields=new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label($this->table_element,true); + $this->fetch_optionals($this->id,$extralabels); + */ + + // $this->fetch_lines(); + + $this->db->free($resql); + + if ($numrows) { + return 1; + } else { + return 0; + } + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * + * @return int <0 if KO, >0 if OK + */ + public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.code,"; + $sql .= " t.label,"; + $sql .= " t.active"; + + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; + + // Manage filter + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { + $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } + } + + if (count($sqlwhere) > 0) { + $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); + } + if (!empty($sortfield)) { + $sql .= $this->db->order($sortfield,$sortorder); + } + if (!empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit, $offset); + } + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + while ($obj = $this->db->fetch_object($resql)) { + $line = new self($this->db); + + $line->id = $obj->rowid; + + $line->code = $obj->code; + $line->label = $obj->label; + $line->active = $obj->active; + + + } + $this->db->free($resql); + + return $num; + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + /** + * Update object into database + * + * @param User $user User that modifies + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, >0 if OK + */ + public function update(User $user, $notrigger = false) + { + $error = 0; + + dol_syslog(__METHOD__, LOG_DEBUG); + + // Clean parameters + + if (isset($this->code)) { + $this->code = trim($this->code); + } + if (isset($this->label)) { + $this->label = trim($this->label); + } + if (isset($this->active)) { + $this->active = trim($this->active); + } + + // Check parameters + // Put here code to add a control on parameters values + + // Update request + $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; + + $sql .= ' code = '.(isset($this->code)?"'".$this->db->escape($this->code)."'":"null").','; + $sql .= ' label = '.(isset($this->label)?"'".$this->db->escape($this->label)."'":"null").','; + $sql .= ' active = '.(isset($this->active)?$this->active:"null"); + + + $sql .= ' WHERE rowid=' . $this->id; + + $this->db->begin(); + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + } + + if (!$error && !$notrigger) { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //$result=$this->call_trigger('MYOBJECT_MODIFY',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return 1; + } + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param bool $notrigger false=launch triggers after, true=disable triggers + * + * @return int <0 if KO, >0 if OK + */ + public function delete(User $user, $notrigger = false) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $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 + //$result=$this->call_trigger('MYOBJECT_DELETE',$user); + //if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} + //// End call triggers + } + } + + // If you need to delete child tables to, you can insert them here + + if (!$error) { + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; + $sql .= ' WHERE rowid=' . $this->id; + + $resql = $this->db->query($sql); + if (!$resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + } + } + + // Commit or rollback + if ($error) { + $this->db->rollback(); + + return - 1 * $error; + } else { + $this->db->commit(); + + return 1; + } + } + + /** + * Load an object from its id and create a new one in database + * + * @param int $fromid Id of object to clone + * + * @return int New id of clone + */ + public function createFromClone($fromid) + { + dol_syslog(__METHOD__, LOG_DEBUG); + + global $user; + $error = 0; + $object = new Ctyperesource($this->db); + + $this->db->begin(); + + // Load source object + $object->fetch($fromid); + // Reset object + $object->id = 0; + + // Clear fields + // ... + + // Create clone + $result = $object->create($user); + + // Other options + if ($result < 0) { + $error ++; + $this->errors = $object->errors; + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + } + + // End + if (!$error) { + $this->db->commit(); + + return $object->id; + } else { + $this->db->rollback(); + + return - 1; + } + } + + /** + * Initialise object with example values + * Id must be 0 if object instance is a specimen + * + * @return void + */ + public function initAsSpecimen() + { + $this->id = 0; + + $this->code = ''; + $this->label = ''; + $this->active = ''; + } + +} + +/** + * Class CtyperesourceLine + */ +class CtyperesourceLine +{ + /** + * @var int ID + */ + public $id; + /** + * @var mixed Sample line property 1 + */ + + public $code; + public $label; + public $active; + + /** + * @var mixed Sample line property 2 + */ + +} diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index a2ce21a8971..f86f786e0fb 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -727,6 +727,10 @@ class ExtraFields { $showsize='minwidth400imp'; } + elseif ($type == 'boolean') + { + $showsize=''; + } else { if (round($size) < 12) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index b839e46dc8b..cab420fe888 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -492,10 +492,11 @@ class Form */ function textwithpicto($text, $htmltext, $direction = 1, $type = 'help', $extracss = '', $noencodehtmltext = 0, $notabs = 2, $tooltiptrigger='') { - global $conf; + global $conf, $langs; $alt = ''; - + if ($tooltiptrigger) $alt=$langs->trans("ClickToShowHelp"); + //For backwards compatibility if ($type == '0') $type = 'info'; elseif ($type == '1') $type = 'help'; @@ -994,7 +995,7 @@ class Form print img_picto($langs->trans("Search"), 'search'); } } - print 'global->THIRDPARTY_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />'; + print 'global->THIRDPARTY_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />'; if ($hidelabel == 3) { print img_picto($langs->trans("Search"), 'search'); } diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index d7ab17e60c4..ab58854f2c4 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -1059,18 +1059,18 @@ class FormMail extends Form } /** - * Set substit array from object + * Get list of substition keys available. * - * @param string $mode 'form', 'formwithlines', 'formforlines' or 'emailing' + * @param string $mode 'formemail', 'formemailwithlines', 'formemailforlines', 'emailing', ... * @return void */ - function getAvailableSubstitKey($mode='form') + static function getAvailableSubstitKey($mode='formemail') { - global $conf; + global $conf, $langs; $vars=array(); - if ($mode == 'form' || $mode == 'formwithlines' || $mode == 'formforlines') + if ($mode == 'formemail' || $mode == 'formemailwithlines' || $mode == 'formemailforlines') { $vars=array( '__REF__', @@ -1133,6 +1133,15 @@ class FormMail extends Form $vars['__SECUREKEYPAYPAL_MEMBER__']=''; } } + + $tmparray=array(); + $parameters=array('mode'=>$mode); + complete_substitutions_array($tmparray, $langs, null, $parameters); + foreach($tmparray as $key => $val) + { + $vars[$key]=$key; + } + return $vars; } diff --git a/htdocs/core/class/html.formmailing.class.php b/htdocs/core/class/html.formmailing.class.php index 0c63049f9d8..9fb4e4eea86 100644 --- a/htdocs/core/class/html.formmailing.class.php +++ b/htdocs/core/class/html.formmailing.class.php @@ -32,9 +32,9 @@ class FormMailing extends Form /** * Output a select with destinaries status * - * @param string $selectedid the selected id - * @param string $htmlname name of controm - * @param integer $show_empty show empty option + * @param string $selectedid The selected id + * @param string $htmlname Name of controm + * @param integer $show_empty Show empty option * @return string HTML select */ public function selectDestinariesStatus($selectedid='',$htmlname='dest_status', $show_empty=0) { @@ -46,13 +46,13 @@ class FormMailing extends Form $mailing = new Mailing($this->db); $options = array(); - + if ($show_empty) { - $options[''] = ''; + $options[-2] = ''; // Note -1 is used for error } - $options = array_merge($options, $mailing->statut_dest); + $options = $options + $mailing->statut_dest; - return Form::selectarray($htmlname, $options, $selectedid, 0, 0, 0, '', 1); + return Form::selectarray($htmlname, $options, $selectedid, 0, 0, 0, '', 1); } } diff --git a/htdocs/core/db/DoliDB.class.php b/htdocs/core/db/DoliDB.class.php index c63227e1601..9fc1739334c 100644 --- a/htdocs/core/db/DoliDB.class.php +++ b/htdocs/core/db/DoliDB.class.php @@ -220,9 +220,9 @@ abstract class DoliDB implements Database /** * Define sort criteria of request * - * @param string $sortfield List of sort fields, separated by comma. Example: 't1.fielda, t2.fieldb' + * @param string $sortfield List of sort fields, separated by comma. Example: 't1.fielda, t2.fieldb' * @param 'ASC'|'DESC' $sortorder Sort order - * @return string String to provide syntax of a sort sql string + * @return string String to provide syntax of a sort sql string */ function order($sortfield=null,$sortorder=null) { @@ -230,18 +230,25 @@ abstract class DoliDB implements Database { $return=''; $fields=explode(',',$sortfield); + $orders=explode(',',$sortorder); + $i=0; foreach($fields as $val) { if (! $return) $return.=' ORDER BY '; - else $return.=','; + else $return.=', '; $return.=preg_replace('/[^0-9a-z_\.]/i','',$val); + + $tmpsortorder = trim($orders[$i]); + // Only ASC and DESC values are valid SQL - if (strtoupper($sortorder) === 'ASC') { + if (strtoupper($tmpsortorder) === 'ASC') { $return .= ' ASC'; - } elseif (strtoupper($sortorder) === 'DESC') { + } elseif (strtoupper($tmpsortorder) === 'DESC') { $return .= ' DESC'; } + + $i++; } return $return; } diff --git a/htdocs/core/js/lib_notification.js.php b/htdocs/core/js/lib_notification.js.php index af4452dfb39..a3b90a35db6 100644 --- a/htdocs/core/js/lib_notification.js.php +++ b/htdocs/core/js/lib_notification.js.php @@ -65,7 +65,7 @@ if (! ($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/' || $_SERVER['H // We set a delay before launching first test so next check will arrive after the time_auto_update compared to previous one. var time_first_execution = (time_auto_update - (nowtime - time_js_next_test)) * 1000; //need milliseconds if (login != '') { - console.log("Launch browser notif check: setTimeout to wait time_first_execution="+time_first_execution+" before first check - nowtime = "+nowtime+" auto_check_events_not_before = "+auto_check_events_not_before+" time_js_next_test = "+time_js_next_test+" time_auto_update="+time_auto_update); + console.log("Launch browser notif check: setTimeout is set to launch 'first_execution' function after a wait of time_first_execution="+time_first_execution+". nowtime (time php page generation) = "+nowtime+" auto_check_events_not_before (val in session)= "+auto_check_events_not_before+" time_js_next_test (max now,auto_check_events_not_before) = "+time_js_next_test+" time_auto_update="+time_auto_update); setTimeout(first_execution, time_first_execution); } //first run auto check @@ -79,17 +79,18 @@ if (! ($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/' || $_SERVER['H function check_events() { if (Notification.permission === "granted") { - console.log("Call check_events time_js_next_test="+time_js_next_test); - $.ajax("", { - type: "post", // Usually post o get + console.log("Call check_events time_js_next_test = date we are looking for event after ="+time_js_next_test); + $.ajax("", { + type: "post", // Usually post or get async: true, data: {time: time_js_next_test}, success: function (result) { var arr = JSON.parse(result); if (arr.length > 0) { + var audio = null; global->AGENDA_NOTIFICATION_SOUND)) { - print 'var audio = new Audio(\''.DOL_URL_ROOT.'/theme/common/sound/notification_agenda.wav'.'\');'; + print 'audio = new Audio(\''.DOL_URL_ROOT.'/theme/common/sound/notification_agenda.wav'.'\');'; } ?> @@ -136,6 +137,7 @@ if (! ($_SERVER['HTTP_REFERER'] === $dolibarr_main_url_root . '/' || $_SERVER['H } time_js_next_test += time_auto_update; + console.log('Updated time_js_next_test. New value is '+time_js_next_test); } +// +// 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 . +// or see http://www.gnu.org/ + +// +// \file htdocs/core/js/listview.js +// \brief File that include javascript functions for lists +// +var Listview_include = true; + +function Listview_OrderDown(idListe, column) { + var base_url = document.location.href; + + base_url = Listview_recup_form_param(idListe,base_url); + base_url = Listview_removeParam(base_url,'Listview['+encodeURIComponent(idListe)+'][orderBy]'); + + base_url = Listview_removeParam(base_url,'get-all-for-export'); + + document.location.href=Listview_modifyUrl(base_url,"Listview["+encodeURIComponent(idListe)+"][orderBy]["+encodeURIComponent(column)+"]","DESC"); +} +function Listview_OrderUp(idListe, column) { + + var base_url = document.location.href; + + base_url = Listview_recup_form_param(idListe,base_url); + base_url = Listview_removeParam(base_url,'Listview['+encodeURIComponent(idListe)+'][orderBy]'); + + base_url = Listview_removeParam(base_url,'get-all-for-export'); + + document.location.href=Listview_modifyUrl(base_url,"Listview["+encodeURIComponent(idListe)+"][orderBy]["+encodeURIComponent(column)+"]","ASC"); +} +function Listview_modifyUrl(strURL,paramName,paramNewValue){ + if (strURL.indexOf(paramName+'=')!=-1){ + + var strFirstPart=strURL.substring(0,strURL.indexOf(paramName+'=',0))+paramName+'='; + var strLastPart=""; + if (strURL.indexOf('&',strFirstPart.length-1)>0) + strLastPart=strURL.substring(strURL.indexOf('&',strFirstPart.length-1),strURL.length); + strURL=strFirstPart+paramNewValue+strLastPart; + } + else{ + if (strURL.search('=')!=-1) // permet de verifier s'il y a dej� des param�tres dans l'URL + strURL+='&'+paramName+'='+paramNewValue; + else + strURL+='?'+paramName+'='+paramNewValue; + } + + return strURL; +} +function Listview_removeParam(strURL, paramMask) { + var cpt=0; + var url = ''; + + while(strURL.indexOf(paramMask)!=-1 && cpt++ <50){ + var strFirstPart= strURL.substring(0,strURL.indexOf(paramMask)-1); + + var strLastPart=''; + if (strURL.indexOf('&',strFirstPart.length+1)>0) { + strLastPart = strURL.substring(strURL.indexOf('&',strFirstPart.length+1),strURL.length); + } + + url = strFirstPart+strLastPart; + + } + + if(url=='')url = strURL; + + return url; +} + +function Listview_recup_form_param(idListe,base_url) { + + $('#'+idListe+' tr.barre-recherche [listviewtbs],#'+idListe+' tr.barre-recherche-head input,#'+idListe+' tr.barre-recherche-head select,#'+idListe+' div.tabsAction input[listviewtbs]').each(function(i,item) { + if($(item).attr("name")) { + base_url = Listview_modifyUrl(base_url, $(item).attr("name") , $(item).val()); + } + + }); + + return base_url; +} + +function Listview_GoToPage(idListe,pageNumber){ + + var base_url = document.location.href; + + base_url = Listview_recup_form_param(idListe,base_url); + base_url =Listview_modifyUrl(base_url,"Listview["+encodeURIComponent(idListe)+"][page]",pageNumber); + + base_url = Listview_removeParam(base_url,'get-all-for-export'); + + document.location.href=base_url; +} +function Listview_submitSearch(obj) { + + $form = $(obj).closest('form'); + console.log($form); + if($form.length>0){ + $form.submit(); + } +} +function Listview_launch_downloadAs(mode,url,token,session_name) { + $('#listviewdAS_export_form').remove(); + + $form = $(''); + $form.append(''); + $form.append(''); + $form.append(''); + + $('body').append($form); + + $('#listviewdAS_export_form').submit(); + +} + +function Listview_downloadAs(obj, mode,url,token,session_name) { + + $form = $(obj).closest('form'); + $div = $form.find('div.tabsAction'); + $div.append(''); + $div.append(''); + $div.append(''); + $div.append(''); + $div.append(''); + + Listview_submitSearch(obj); +} + +$(document).ready(function() { + $('tr.barre-recherche input').keypress(function(e) { + if(e.which == 13) { + + var id_list = $(this).closest('table').attr('id'); + + $('#'+id_list+' .list-search-link').click(); + + } + }); + + var $_GET = {}; + + document.location.search.replace(/\??(?:([^=]+)=([^&]*)&?)/g, function () { + function decode(s) { + return decodeURIComponent(s.split("+").join(" ")); + } + + $_GET[decode(arguments[1])] = decode(arguments[2]); + }); + + if(typeof $_GET["get-all-for-export"] != "undefined") { + Listview_launch_downloadAs($_GET['mode'],$_GET['url'],$_GET['token'],$_GET['session_name']); + } + +}); diff --git a/htdocs/core/lib/accounting.lib.php b/htdocs/core/lib/accounting.lib.php index 56fdc8e6de9..b7ceaa0982e 100644 --- a/htdocs/core/lib/accounting.lib.php +++ b/htdocs/core/lib/accounting.lib.php @@ -202,3 +202,95 @@ function length_accounta($accounta) return $accounta; } } + + + +/** + * Show header of a VAT report + * + * @param string $nom Name of report + * @param string $variante Link for alternate report + * @param string $period Period of report + * @param string $periodlink Link to switch period + * @param string $description Description + * @param timestamp|integer $builddate Date generation + * @param string $exportlink Link for export or '' + * @param array $moreparam Array with list of params to add into form + * @param string $calcmode Calculation mode + * @param string $varlink Add a variable into the address of the page + * @return void + */ +function journalHead($nom,$variante,$period,$periodlink,$description,$builddate,$exportlink='',$moreparam=array(),$calcmode='', $varlink='') +{ + global $langs; + + if (empty($hselected)) $hselected='report'; + + print "\n\n\n"; + + if(! empty($varlink)) $varlink = '?'.$varlink; + + $h=0; + $head[$h][0] = $_SERVER["PHP_SELF"].$varlink; + $head[$h][1] = $langs->trans("Journalization"); + $head[$h][2] = 'journal'; + + dol_fiche_head($head, 'journal'); + + print '
'; + foreach($moreparam as $key => $value) + { + print ''; + } + print ''; + + // Ligne de titre + print ''; + print ''; + if (! $variantexxx) print ''; + print ''; + + // Calculation mode + if ($calcmode) + { + print ''; + print ''; + if (! $variante) print ''; + print ''; + } + + // Ligne de la periode d'analyse du rapport + print ''; + print ''; + if (! $periodlink) print ''; + print ''; + + // Ligne de description + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("Name").''; + else print ''; + print $nom; + if ($variantexxx) print ''.$variantexxx; + print '
'.$langs->trans("CalculationMode").''; + else print ''; + print $calcmode; + if ($variante) print ''.$variante; + print '
'.$langs->trans("ReportPeriod").''; + else print ''; + if ($period) print $period; + if ($periodlink) print ''.$periodlink; + print '
'.$langs->trans("ReportDescription").''.$description.'
'; + + print '
'; + + print '
'; + + dol_fiche_end(); + + print "\n\n\n"; +} + diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index 942c17f5df9..49218ddf141 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -349,7 +349,7 @@ function ajax_dialog($title,$message,$w=350,$h=150) /** - * Make a input box content all selected + * Make content of an input box selected when we click into input field. * * @param string $htmlname Id of html object * @param int $addlink Add a link to after diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 809a045bacf..6847cd7b9c2 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -496,6 +496,55 @@ function getFormeJuridiqueLabel($code) } } +/** + * Return if a country is inside the EEC (European Economic Community) + * TODO Add a field into country dictionary. + * + * @param Object $object Object + * @return boolean true = country inside EEC, false = country outside EEC + */ +function isInEEC($object) +{ + // List of all country codes that are in europe for european vat rules + // List found on http://ec.europa.eu/taxation_customs/common/faq/faq_1179_en.htm#9 + $country_code_in_EEC=array( + 'AT', // Austria + 'BE', // Belgium + 'BG', // Bulgaria + 'CY', // Cyprus + 'CZ', // Czech republic + 'DE', // Germany + 'DK', // Danemark + 'EE', // Estonia + 'ES', // Spain + 'FI', // Finland + 'FR', // France + 'GB', // United Kingdom + 'GR', // Greece + 'HR', // Croatia + 'NL', // Holland + 'HU', // Hungary + 'IE', // Ireland + 'IM', // Isle of Man - Included in UK + 'IT', // Italy + 'LT', // Lithuania + 'LU', // Luxembourg + 'LV', // Latvia + 'MC', // Monaco - Included in France + 'MT', // Malta + //'NO', // Norway + 'PL', // Poland + 'PT', // Portugal + 'RO', // Romania + 'SE', // Sweden + 'SK', // Slovakia + 'SI', // Slovenia + 'UK', // United Kingdom + //'CH', // Switzerland - No. Swizerland in not in EEC + ); + //print "dd".$this->country_code; + return in_array($object->country_code, $country_code_in_EEC); +} /** diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 6d90a1afed3..18f1e30edc7 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -1495,10 +1495,10 @@ function dol_uncompress($inputfile,$outputdir) { global $conf, $langs; - if (defined('ODTPHP_PATHTOPCLZIP')) + if (! empty($conf->global->ODTPHP_PATHTOPCLZIP)) { - dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".constant('ODTPHP_PATHTOPCLZIP').", so we use Pclzip to unzip into ".$outputdir); - include_once ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; + dol_syslog("Constant ODTPHP_PATHTOPCLZIP for pclzip library is set to ".$conf->global->ODTPHP_PATHTOPCLZIP.", so we use Pclzip to unzip into ".$outputdir); + include_once $conf->global->ODTPHP_PATHTOPCLZIP.'/pclzip.lib.php'; $archive = new PclZip($inputfile); $result=$archive->extract(PCLZIP_OPT_PATH, $outputdir); //var_dump($result); @@ -1584,7 +1584,7 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu $sqlprotectagainstexternals=''; $ret=array(); - // find the subdirectory name as the reference + // Find the subdirectory name as the reference. For exemple original_file='10/myfile.pdf' -> refname='10' if (empty($refname)) $refname=basename(dirname($original_file)."/"); $relative_original_file = $original_file; @@ -1628,8 +1628,14 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu // Wrapping pour les apercu intervention elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output)) { - if ($fuser->rights->ficheinter->lire) $accessallowed=1; - $original_file=$conf->ficheinter->dir_output.'/'.$original_file; + if ($fuser->rights->ficheinter->lire) $accessallowed=1; + $original_file=$conf->ficheinter->dir_output.'/'.$original_file; + } + // Wrapping pour les apercu commande + elseif (($modulepart == 'apercusupplier_order' || $modulepart == 'apercusupplier_order') && !empty($conf->fournisseur->commande->dir_output)) + { + if ($fuser->rights->fournisseur->commande->lire) $accessallowed=1; + $original_file=$conf->fournisseur->commande->dir_output.'/'.$original_file; } // Wrapping pour les images des stats propales elseif ($modulepart == 'propalstats' && !empty($conf->propal->dir_temp)) @@ -1752,6 +1758,18 @@ function dol_check_secure_access_document($modulepart,$original_file,$entity,$fu $original_file=$conf->fckeditor->dir_output.'/'.$original_file; } + // Wrapping for users + else if ($modulepart == 'user' && !empty($conf->user->dir_output)) + { + $canreaduser=(! empty($fuser->admin) || $fuser->rights->user->user->lire); + if ($fuser->id == (int) $refname) { $canreaduser=1; } // A user can always read its own card + if ($canreaduser || preg_match('/^specimen/i',$original_file)) + { + $accessallowed=1; + } + $original_file=$conf->user->dir_output.'/'.$original_file; + } + // Wrapping for third parties else if (($modulepart == 'company' || $modulepart == 'societe') && !empty($conf->societe->dir_output)) { diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index d430a8ea53b..da0a33e7ef1 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -246,24 +246,64 @@ function dol_shutdown() * @param mixed $options Options to pass to filter_var when $check is set to custom * @return string|string[] Value found (string or array), or '' if check fails */ -function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL) +function GETPOST($paramname, $check='', $method=0, $filter=NULL, $options=NULL) { if (empty($method)) { $out = isset($_GET[$paramname])?$_GET[$paramname]:(isset($_POST[$paramname])?$_POST[$paramname]:''); - + // Management of default values - if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname])) + if (! isset($_GET['sortfield'])) // If we did a click on a field to sort, we do no apply default values { - $relativepathstring = preg_replace('/\.[a-z]+$/', '', $_SERVER["PHP_SELF"]); - if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring); - $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring); - $relativepathstring = preg_replace('/^\//', '', $relativepathstring); - $relativepathstring=dol_string_nospecial($relativepathstring, '-'); - // $relativepathstring is now string that identify the page: '_societe_card', '_agenda_card', ... - $keyfordefaultvalue = 'MAIN_DEFAULT_FOR_'.$relativepathstring.'_'.$paramname; - global $conf; - if (isset($conf->global->$keyfordefaultvalue)) $out = $conf->global->$keyfordefaultvalue; + if (! empty($_GET['action']) && $_GET['action'] == 'create' && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname])) + { + $relativepathstring = $_SERVER["PHP_SELF"]; + if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring); + $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring); + $relativepathstring = preg_replace('/^\//', '', $relativepathstring); + global $user; + if (! empty($user->default_values)) // $user->default_values defined from menu default values, and values loaded not at first + { + //var_dump($user->default_values[$relativepathstring]['createform']); + if (isset($user->default_values[$relativepathstring]['createform'][$paramname])) $out = $user->default_values[$relativepathstring]['createform'][$paramname]; + } + } + // Management of default search_filters and sort order + elseif (preg_match('/list.php$/', $_SERVER["PHP_SELF"]) && ! empty($paramname) && ! isset($_GET[$paramname]) && ! isset($_POST[$paramname])) + { + $relativepathstring = $_SERVER["PHP_SELF"]; + if (constant('DOL_URL_ROOT')) $relativepathstring = preg_replace('/^'.preg_quote(constant('DOL_URL_ROOT'),'/').'/', '', $relativepathstring); + $relativepathstring = preg_replace('/^custom\//', '', $relativepathstring); + $relativepathstring = preg_replace('/^\//', '', $relativepathstring); + global $user; + if (! empty($user->default_values)) // $user->default_values defined from menu default values, and values loaded not at first + { + //var_dump($user->default_values[$relativepathstring]); + if ($paramname == 'sortfield') + { + if (isset($user->default_values[$relativepathstring]['sortorder'])) + { + foreach($user->default_values[$relativepathstring]['sortorder'] as $key => $val) + { + if ($out) $out.=', '; + $out.=$key; + } + } + } + elseif ($paramname == 'sortorder') + { + if (isset($user->default_values[$relativepathstring]['sortorder'])) + { + foreach($user->default_values[$relativepathstring]['sortorder'] as $key => $val) + { + if ($out) $out.=', '; + $out.=$val; + } + } + } + elseif (isset($user->default_values[$relativepathstring]['filters'][$paramname])) $out = $user->default_values[$relativepathstring]['filters'][$paramname]; + } + } } } elseif ($method==1) $out = isset($_GET[$paramname])?$_GET[$paramname]:''; @@ -303,6 +343,11 @@ function GETPOST($paramname,$check='',$method=0,$filter=NULL,$options=NULL) global $user; $out = $user->id; } + elseif ($reg[1] == 'SUPERVISORID') + { + global $user; + $out = $user->fk_user; + } elseif ($reg[1] == 'ENTITYID') { global $conf; @@ -1020,11 +1065,11 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->lire_advance)) $showbarcode=0; $modulepart='unknown'; - if ($object->element == 'societe') $modulepart='societe'; - if ($object->element == 'contact') $modulepart='contact'; - if ($object->element == 'member') $modulepart='memberphoto'; - if ($object->element == 'user') $modulepart='userphoto'; - if ($object->element == 'product') $modulepart='product'; + if ($object->element == 'societe') $modulepart='societe'; + if ($object->element == 'contact') $modulepart='contact'; + if ($object->element == 'member') $modulepart='memberphoto'; + if ($object->element == 'user') $modulepart='userphoto'; + if ($object->element == 'product') $modulepart='product'; if (class_exists("Imagick")) { if ($object->element == 'propal') $modulepart='propal'; @@ -1032,6 +1077,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r if ($object->element == 'facture') $modulepart='facture'; if ($object->element == 'fichinter') $modulepart='ficheinter'; if ($object->element == 'contrat') $modulepart='contract'; + if ($object->element == 'order_supplier') $modulepart='supplier_order'; } if ($object->element == 'product') @@ -1057,12 +1103,11 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r { if ($showimage) { - if ($modulepart != 'unknown') + if ($modulepart != 'unknown') { $phototoshow=''; - // Check if a preview file is available - if (in_array($modulepart, array('propal', 'commande', 'facture', 'ficheinter', 'contract')) && class_exists("Imagick")) + if (in_array($modulepart, array('propal', 'commande', 'facture', 'ficheinter', 'contract', 'supplier_order')) && class_exists("Imagick")) { $objectref = dol_sanitizeFileName($object->ref); $dir_output = $conf->$modulepart->dir_output . "/"; @@ -1092,7 +1137,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r if (file_exists($fileimage)) { $phototoshow = '
'; - $phototoshow.= ''; + $phototoshow.= ''; $phototoshow.= '
'; } // Si fichier png PDF de plus d'1 page trouve @@ -1100,7 +1145,7 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r { $preview = preg_replace('/\.png/','',$relativepathimage) . "-0.png"; $phototoshow = '
'; - $phototoshow.= '

'; + $phototoshow.= '

'; $phototoshow.= '

'; } } @@ -1126,7 +1171,6 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r $width=80; $cssclass='photorefcenter'; $nophoto=img_picto('', 'title_agenda', '', false, 1); - $morehtmlleft.='
No photo
'; } else { @@ -1134,8 +1178,8 @@ function dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='r $picto = $object->picto; if ($object->element == 'project' && ! $object->public) $picto = 'project'; // instead of projectpub $nophoto=img_picto('', 'object_'.$picto, '', false, 1); - $morehtmlleft.='
No photo
'; } + $morehtmlleft.='
No photo
'; $morehtmlleft.='
'; } } @@ -3155,6 +3199,9 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m $tag='th'; if ($thead==2) $tag='div'; + $tmpsortfield=explode(',',$sortfield); + $sortfield=trim($tmpsortfield[0]); + // If field is used as sort criteria we use a specific class // Example if (sortfield,field)=("nom","xxx.nom") or (sortfield,field)=("nom","nom") if ($field && ($sortfield == $field || $sortfield == preg_replace("/^[^\.]+\./","",$field))) $out.= '<'.$tag.' class="'.$prefix.'liste_titre_sel" '. $moreattrib.'>'; @@ -3169,13 +3216,13 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m if ($field != $sortfield) { - if ($sortorder == 'DESC') $out.= ''; - if ($sortorder == 'ASC' || ! $sortorder) $out.= ''; + if (preg_match('/^DESC/', $sortorder)) $out.= ''; + else $out.= ''; } else { - if ($sortorder == 'DESC' || ! $sortorder) $out.= ''; - if ($sortorder == 'ASC') $out.= ''; + if (preg_match('/^ASC/', $sortorder)) $out.= ''; + else $out.= ''; } } @@ -3204,12 +3251,12 @@ function getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $m } else { - if ($sortorder == 'DESC' ) { + if (preg_match('/^DESC/', $sortorder)) { //$out.= ''.img_down("A-Z",0).''; //$out.= ''.img_up("Z-A",1).''; $sortimg.= ''.img_up("Z-A",0).''; } - if ($sortorder == 'ASC' ) { + if (preg_match('/^ASC/', $sortorder)) { //$out.= ''.img_down("A-Z",1).''; //$out.= ''.img_up("Z-A",0).''; $sortimg.= ''.img_down("A-Z",0).''; @@ -3280,7 +3327,7 @@ function load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $return.= "\n"; $return.= ''; - if ($picto) $return.= ''; + if ($picto) $return.= ''; $return.= ''; @@ -3522,14 +3569,14 @@ function vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0) $morelabel=' ('.$reg[1].')'; $rate=preg_replace('/\s*'.preg_quote($morelabel,'/').'/','',$rate); } - if (preg_match('/\*/',$rate) || preg_match('/'.constant('MAIN_LABEL_MENTION_NPR').'/i',$rate)) + if (preg_match('/\*/',$rate)) { $rate=str_replace('*','',$rate); $info_bits |= 1; } $ret=price($rate,0,'',0,0).($addpercent?'%':''); - if ($info_bits & 1) $ret.=' '.($usestarfornpr?'*':constant('MAIN_LABEL_MENTION_NPR')); + if ($info_bits & 1) $ret.=' *'; $ret.=$morelabel; return $ret; } @@ -4905,7 +4952,8 @@ function make_substitutions($text, $substitutionarray, $outputlangs=null) } /** - * Complete the $substitutionarray with more entries + * Complete the $substitutionarray with more entries. + * Can also add substitution keys coming from external module that had set the "substitutions=1" into module_part array. In this case, method completesubstitutionarray provided by module is called. * * @param array $substitutionarray Array substitution old value => new value value * @param Translate $outputlangs Output language diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index dc0541e39ef..66d66ec7c8f 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -5,6 +5,7 @@ * Copyright (C) 2014-2016 Marcos García * Copyright (C) 2015 Ferran Marcet * Copyright (C) 2015-2016 Raphaël Doursenaud + * Copyright (C) 2017 Juanjo Menent * * 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 @@ -1439,7 +1440,7 @@ function dol_print_reduction($reduction,$langs) } else { - $string = $reduction.'%'; + $string = price($reduction).'%'; } return $string; diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 282bdec690e..e83faee6c8d 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -599,7 +599,14 @@ function pdf_getSubstitutionArray($outputlangs) $substitutionarray=array( '__MYCOMPANY_NAME__' => $mysoc->name, '__MYCOMPANY_EMAIL__' => $mysoc->email, - '__USER_ID__' => $user->id, + '__MYCOMPANY_PROFID1__' => $mysoc->idprof1, + '__MYCOMPANY_PROFID2__' => $mysoc->idprof2, + '__MYCOMPANY_PROFID3__' => $mysoc->idprof3, + '__MYCOMPANY_PROFID4__' => $mysoc->idprof4, + '__MYCOMPANY_PROFID5__' => $mysoc->idprof5, + '__MYCOMPANY_PROFID6__' => $mysoc->idprof6, + '__MYCOMPANY_CAPITAL__' => $mysoc->capital, + '__USER_ID__' => $user->id, '__USER_LOGIN__' => $user->login, '__USER_LASTNAME__' => $user->lastname, '__USER_FIRSTNAME__' => $user->firstname, @@ -1808,8 +1815,17 @@ function pdf_getlineprogress($object, $i, $outputlangs, $hidedetails = 0, $hookm } if (empty($reshook)) { - if ($object->lines[$i]->special_code == 3) return ''; - if (empty($hidedetails) || $hidedetails > 1) $result.=$object->lines[$i]->situation_percent . '%'; + if ($object->lines[$i]->special_code == 3) return ''; + if (empty($hidedetails) || $hidedetails > 1) + { + if($conf->global->SITUATION_DISPLAY_DIFF_ON_PDF) + { + $prev_progress = $object->lines[$i]->get_prev_progress($object->id); + $result = ( $object->lines[$i]->situation_percent - $prev_progress) . '%'; + } + else + $result = $object->lines[$i]->situation_percent . '%'; + } } return $result; } @@ -1844,7 +1860,7 @@ function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0) if(!empty($hookmanager->resPrint)) $result.=$hookmanager->resPrint; } if (empty($reshook)) - { + { if ($object->lines[$i]->special_code == 3) { return $outputlangs->transnoentities("Option"); @@ -1852,9 +1868,16 @@ function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0) if (empty($hidedetails) || $hidedetails > 1) { $total_ht = ($conf->multicurrency->enabled && $object->multicurrency_tx != 1 ? $object->lines[$i]->multicurrency_total_ht : $object->lines[$i]->total_ht); + if ($object->lines[$i]->situation_percent > 0 ) + { + $prev_progress = $object->lines[$i]->get_prev_progress($object->id); + $progress = ( $object->lines[$i]->situation_percent - $prev_progress) /100; + $result.=price($sign * ($total_ht/($object->lines[$i]->situation_percent/100)) * $progress, 0, $outputlangs); + } + else $result.=price($sign * $total_ht, 0, $outputlangs); - } } + } return $result; } diff --git a/htdocs/core/lib/report.lib.php b/htdocs/core/lib/report.lib.php index f58aa180d88..2c13485d0e9 100644 --- a/htdocs/core/lib/report.lib.php +++ b/htdocs/core/lib/report.lib.php @@ -24,20 +24,20 @@ /** -* Show header of a VAT report -* -* @param string $nom Name of report -* @param string $variante Link for alternate report -* @param string $period Period of report -* @param string $periodlink Link to switch period -* @param string $description Description -* @param timestamp|integer $builddate Date generation -* @param string $exportlink Link for export or '' -* @param array $moreparam Array with list of params to add into form -* @param string $calcmode Calculation mode -* @param string $varlink Add a variable into the address of the page -* @return void -*/ + * Show header of a VAT report + * + * @param string $nom Name of report + * @param string $variante Link for alternate report + * @param string $period Period of report + * @param string $periodlink Link to switch period + * @param string $description Description + * @param timestamp|integer $builddate Date generation + * @param string $exportlink Link for export or '' + * @param array $moreparam Array with list of params to add into form + * @param string $calcmode Calculation mode + * @param string $varlink Add a variable into the address of the page + * @return void + */ function report_header($nom,$variante,$period,$periodlink,$description,$builddate,$exportlink='',$moreparam=array(),$calcmode='', $varlink='') { global $langs; diff --git a/htdocs/core/lib/security2.lib.php b/htdocs/core/lib/security2.lib.php index cadf133169d..5139128a5d8 100644 --- a/htdocs/core/lib/security2.lib.php +++ b/htdocs/core/lib/security2.lib.php @@ -150,9 +150,9 @@ function dol_loginfunction($langs,$conf,$mysoc) // Title $appli=constant('DOL_APPLICATION_TITLE'); - $title=$appli.' '.DOL_VERSION; + $title=$appli.' '.constant('DOL_VERSION'); if (! empty($conf->global->MAIN_APPLICATION_TITLE)) $title=$conf->global->MAIN_APPLICATION_TITLE; - $titletruedolibarrversion=DOL_VERSION; // $title used by login template after the @ to inform of true Dolibarr version + $titletruedolibarrversion=constant('DOL_VERSION'); // $title used by login template after the @ to inform of true Dolibarr version // Note: $conf->css looks like '/theme/eldy/style.css.php' $conf->css = "/theme/".(GETPOST('theme')?GETPOST('theme','alpha'):$conf->theme)."/style.css.php"; diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index f85885def1d..dffc5f9af1b 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -545,7 +545,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/admin/ihm.php?mainmenu=home", $langs->trans("GUISetup"),1); $newmenu->add("/admin/translation.php?mainmenu=home", $langs->trans("Translation"),1); - $newmenu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"),1, $conf->global->MAIN_FEATURES_LEVEL); + $newmenu->add("/admin/defaultvalues.php?mainmenu=home", $langs->trans("DefaultValues"),1); $newmenu->add("/admin/boxes.php?mainmenu=home", $langs->trans("Boxes"),1); $newmenu->add("/admin/delais.php?mainmenu=home",$langs->trans("MenuWarnings"),1); $newmenu->add("/admin/security_other.php?mainmenu=home", $langs->trans("Security"),1); @@ -800,9 +800,9 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if (! empty($conf->facture->enabled)) { $langs->load("bills"); - $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("BillsCustomers"),0,$user->rights->facture->lire); + $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("BillsCustomers"),0,$user->rights->facture->lire, '', $mainmenu, 'customers_bills'); $newmenu->add("/compta/facture/card.php?action=create",$langs->trans("NewBill"),1,$user->rights->facture->creer); - $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("List"),1,$user->rights->facture->lire); + $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills",$langs->trans("List"),1,$user->rights->facture->lire, '', $mainmenu, 'customers_bills'); if ($usemenuhider || empty($leftmenu) || preg_match('/customers_bills/', $leftmenu)) { @@ -1252,6 +1252,18 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if ($conf->supplier_order->enabled) $newmenu->add("/product/stock/replenish.php", $langs->trans("Replenishment"), 1, $user->rights->stock->mouvement->creer && $user->rights->fournisseur->lire); } + // Inventory + if ($conf->global->MAIN_LEVEL_FEATURES >= 2) + { + if (! empty($conf->stock->enabled)) + { + $langs->load("stocks"); + $newmenu->add("/product/inventory/list.php?leftmenu=stock", $langs->trans("Inventory"), 0, $user->rights->stock->lire, '', $mainmenu, 'stock'); + $newmenu->add("/product/inventory/card.php?action=create", $langs->trans("NewInventory"), 1, $user->rights->stock->creer); + $newmenu->add("/product/inventory/list.php", $langs->trans("List"), 1, $user->rights->stock->lire); + } + } + // Expeditions if (! empty($conf->expedition->enabled)) { diff --git a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php index dab925eef1d..3f7a73a650c 100644 --- a/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php +++ b/htdocs/core/modules/expedition/doc/pdf_rouget.modules.php @@ -49,7 +49,7 @@ class pdf_rouget extends ModelePdfExpedition $this->db = $db; $this->name = "rouget"; - $this->description = $langs->trans("DocumentModelSimple"); + $this->description = $langs->trans("DocumentModelStandardPDF"); $this->type = 'pdf'; $formatarray=pdf_getFormat(); @@ -69,19 +69,18 @@ class pdf_rouget extends ModelePdfExpedition // Define position of columns $this->posxdesc=$this->marge_gauche+1; - $this->posxweightvol=$this->page_largeur - $this->marge_droite - 76; + $this->posxweightvol=$this->page_largeur - $this->marge_droite - 78; $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 56; $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 28; $this->posxpuht=$this->page_largeur - $this->marge_droite; - if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) { + if (!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) { - $this->posxweightvol=$this->page_largeur - $this->marge_droite - 130; - $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 100; - $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 70; + $this->posxweightvol=$this->page_largeur - $this->marge_droite - 118; + $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 96; + $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 68; $this->posxpuht=$this->page_largeur - $this->marge_droite - 40; $this->posxtotalht=$this->page_largeur - $this->marge_droite - 20; - } $this->posxpicture=$this->posxweightvol - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images @@ -344,7 +343,7 @@ class pdf_rouget extends ModelePdfExpedition // Rect prend une longueur en 3eme param $pdf->SetDrawColor(192,192,192); $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); - + $tab_height = $tab_height - $height_note; $tab_top = $nexY+6; } @@ -459,16 +458,17 @@ class pdf_rouget extends ModelePdfExpedition $weighttxt=''; if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight) { - $weighttxt=$object->lines[$i]->weight*$object->lines[$i]->qty_shipped.' '.measuring_units_string($object->lines[$i]->weight_units,"weight"); + $weighttxt=round($object->lines[$i]->weight * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->weight_units,"weight"); } $voltxt=''; if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume) { - $voltxt=$object->lines[$i]->volume*$object->lines[$i]->qty_shipped.' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0,"volume"); + $voltxt=round($object->lines[$i]->volume * $object->lines[$i]->qty_shipped, 5).' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0,"volume"); } - - $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?', ':'').$voltxt,'','C'); - + + $pdf->writeHTMLCell($this->posxqtyordered - $this->posxweightvol + 2, 3, $this->posxweightvol - 1, $curY, $weighttxt.(($weighttxt && $voltxt)?'
':'').$voltxt, 0, 0, false, true, 'C'); + //$pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?'
':'').$voltxt,'','C'); + if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) { $pdf->SetXY($this->posxqtyordered, $curY); @@ -479,27 +479,27 @@ class pdf_rouget extends ModelePdfExpedition $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C'); if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) -{ + { $pdf->SetXY($this->posxpuht, $curY); $pdf->MultiCell(($this->posxtotalht - $this->posxpuht-1), 3, price($object->lines[$i]->subprice, 0, $outputlangs),'','R'); $pdf->SetXY($this->posxtotalht, $curY); $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs),'','R'); - } + $nexY+=3; + if ($weighttxt && $voltxt) $nexY+=2; + // Add line if (! empty($conf->global->MAIN_PDF_DASH_BETWEEN_LINES) && $i < ($nblignes - 1)) { $pdf->setPage($pageposafter); $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80))); //$pdf->SetDrawColor(190,190,200); - $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1); + $pdf->line($this->marge_gauche, $nexY-1, $this->page_largeur - $this->marge_droite, $nexY-1); $pdf->SetLineStyle(array('dash'=>0)); } - $nexY+=2; // Passe espace entre les lignes - // Detect if some page were added automatically and output _tableau for past pages while ($pagenb < $pageposafter) { @@ -650,7 +650,7 @@ class pdf_rouget extends ModelePdfExpedition $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1); - if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) { + if(!empty($conf->global->MAIN_PDF_SHIPPING_DISPLAY_AMOUNT_HT)) { $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1); @@ -658,20 +658,20 @@ class pdf_rouget extends ModelePdfExpedition $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index); $pdf->MultiCell($this->page_largeur - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1); - } + } // Total Weight if ($totalWeighttoshow) { - $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($largcol2+20, $tab2_hl, $totalWeighttoshow, 0, 'R', 1); + $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalWeighttoshow, 0, 'C', 1); $index++; } if ($totalVolumetoshow) { - $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); - $pdf->MultiCell($largcol2+20, $tab2_hl, $totalVolumetoshow, 0, 'R', 1); + $pdf->SetXY($this->posxweightvol, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), $tab2_hl, $totalVolumetoshow, 0, 'C', 1); $index++; } @@ -949,6 +949,7 @@ class pdf_rouget extends ModelePdfExpedition $pdf->SetFillColor(230,230,230); $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1); $pdf->SetTextColor(0,0,60); + $pdf->SetFillColor(255,255,255); // Show sender name $pdf->SetXY($posx+2,$posy+3); diff --git a/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php b/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php index 83306b95adb..4d889f84902 100644 --- a/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php +++ b/htdocs/core/modules/fichinter/doc/pdf_soleil.modules.php @@ -65,7 +65,7 @@ class pdf_soleil extends ModelePDFFicheinter $this->db = $db; $this->name = 'soleil'; - $this->description = $langs->trans("DocumentModelStandard"); + $this->description = $langs->trans("DocumentModelStandardPDF"); // Dimension page pour format A4 $this->type = 'pdf'; diff --git a/htdocs/core/modules/import/import_xlsx.modules.php b/htdocs/core/modules/import/import_xlsx.modules.php index 627fcfd6fd9..917760dc900 100644 --- a/htdocs/core/modules/import/import_xlsx.modules.php +++ b/htdocs/core/modules/import/import_xlsx.modules.php @@ -31,7 +31,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/modules/import/modules_import.php'; /** * Class to import Excel files */ -class Importxlsx extends ModeleImports +class ImportXlsx extends ModeleImports { var $db; var $datatoimport; diff --git a/htdocs/core/modules/modProduct.class.php b/htdocs/core/modules/modProduct.class.php index b2349ab77a0..30e64b5de2c 100644 --- a/htdocs/core/modules/modProduct.class.php +++ b/htdocs/core/modules/modProduct.class.php @@ -53,7 +53,7 @@ class modProduct extends DolibarrModules $this->module_position = 20; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i','',get_class($this)); - $this->description = "Gestion des produits"; + $this->description = "Product management"; // Possible values for version are: 'development', 'experimental', 'dolibarr' or version $this->version = 'dolibarr'; @@ -83,7 +83,14 @@ class modProduct extends DolibarrModules $this->const[$r][3] = 'Module to control product codes'; $this->const[$r][4] = 0; $r++; - + + /*$this->const[$r][0] = "PRODUCT_ADDON_PDF"; + $this->const[$r][1] = "chaine"; + $this->const[$r][2] = "standard"; + $this->const[$r][3] = 'Default module for document generation'; + $this->const[$r][4] = 0; + $r++;*/ + // Boxes $this->boxes = array( 0=>array('file'=>'box_produits.php','enabledbydefaulton'=>'Home'), diff --git a/htdocs/core/modules/modResource.class.php b/htdocs/core/modules/modResource.class.php index d3aa3405d0b..f6674bdcfd7 100644 --- a/htdocs/core/modules/modResource.class.php +++ b/htdocs/core/modules/modResource.class.php @@ -201,22 +201,6 @@ class modResource extends DolibarrModules $this->menu = 1; // This module add menu entries. They are coded into menu manager. - // Add here list of permission defined by - // an id, a label, a boolean and two constant strings. - // Example: - //// Permission id (must not be already used) - //$this->rights[$r][0] = 2000; - //// Permission label - //$this->rights[$r][1] = 'Permision label'; - //// Permission by default for new user (0/1) - //$this->rights[$r][3] = 0; - //// In php code, permission will be checked by test - //// if ($user->rights->permkey->level1->level2) - //$this->rights[$r][4] = 'level1'; - //// In php code, permission will be checked by test - //// if ($user->rights->permkey->level1->level2) - //$this->rights[$r][5] = 'level2'; - //$r++; // Main menu entries $this->menu = array(); // List of menus to add $r = 0; @@ -267,98 +251,63 @@ class modResource extends DolibarrModules 'user'=> 0 ); - // Exports - $r = 1; - // Example: - //$this->export_code[$r]=$this->rights_class.'_'.$r; - //// Translation key (used only if key ExportDataset_xxx_z not found) - //$this->export_label[$r]='CustomersInvoicesAndInvoiceLines'; - //// Condition to show export in list (ie: '$user->id==3'). - //// Set to 1 to always show when module is enabled. - //$this->export_enabled[$r]='1'; - //$this->export_permission[$r]=array(array("facture","facture","export")); - //$this->export_fields_array[$r]=array( - // 's.rowid'=>"IdCompany", - // 's.nom'=>'CompanyName', - // 's.address'=>'Address', - // 's.cp'=>'Zip', - // 's.ville'=>'Town', - // 's.fk_pays'=>'Country', - // 's.tel'=>'Phone', - // 's.siren'=>'ProfId1', - // 's.siret'=>'ProfId2', - // 's.ape'=>'ProfId3', - // 's.idprof4'=>'ProfId4', - // 's.code_compta'=>'CustomerAccountancyCode', - // 's.code_compta_fournisseur'=>'SupplierAccountancyCode', - // 'f.rowid'=>"InvoiceId", - // 'f.facnumber'=>"InvoiceRef", - // 'f.datec'=>"InvoiceDateCreation", - // 'f.datef'=>"DateInvoice", - // 'f.total'=>"TotalHT", - // 'f.total_ttc'=>"TotalTTC", - // 'f.tva'=>"TotalVAT", - // 'f.paye'=>"InvoicePaid", - // 'f.fk_statut'=>'InvoiceStatus', - // 'f.note'=>"InvoiceNote", - // 'fd.rowid'=>'LineId', - // 'fd.description'=>"LineDescription", - // 'fd.price'=>"LineUnitPrice", - // 'fd.tva_tx'=>"LineVATRate", - // 'fd.qty'=>"LineQty", - // 'fd.total_ht'=>"LineTotalHT", - // 'fd.total_tva'=>"LineTotalTVA", - // 'fd.total_ttc'=>"LineTotalTTC", - // 'fd.date_start'=>"DateStart", - // 'fd.date_end'=>"DateEnd", - // 'fd.fk_product'=>'ProductId', - // 'p.ref'=>'ProductRef' - //); - //$this->export_entities_array[$r]=array('s.rowid'=>"company", - // 's.nom'=>'company', - // 's.address'=>'company', - // 's.cp'=>'company', - // 's.ville'=>'company', - // 's.fk_pays'=>'company', - // 's.tel'=>'company', - // 's.siren'=>'company', - // 's.siret'=>'company', - // 's.ape'=>'company', - // 's.idprof4'=>'company', - // 's.code_compta'=>'company', - // 's.code_compta_fournisseur'=>'company', - // 'f.rowid'=>"invoice", - // 'f.facnumber'=>"invoice", - // 'f.datec'=>"invoice", - // 'f.datef'=>"invoice", - // 'f.total'=>"invoice", - // 'f.total_ttc'=>"invoice", - // 'f.tva'=>"invoice", - // 'f.paye'=>"invoice", - // 'f.fk_statut'=>'invoice', - // 'f.note'=>"invoice", - // 'fd.rowid'=>'invoice_line', - // 'fd.description'=>"invoice_line", - // 'fd.price'=>"invoice_line", - // 'fd.total_ht'=>"invoice_line", - // 'fd.total_tva'=>"invoice_line", - // 'fd.total_ttc'=>"invoice_line", - // 'fd.tva_tx'=>"invoice_line", - // 'fd.qty'=>"invoice_line", - // 'fd.date_start'=>"invoice_line", - // 'fd.date_end'=>"invoice_line", - // 'fd.fk_product'=>'product', - // 'p.ref'=>'product' - //); - //$this->export_sql_start[$r] = 'SELECT DISTINCT '; - //$this->export_sql_end[$r] = ' FROM (' . MAIN_DB_PREFIX . 'facture as f, ' - // . MAIN_DB_PREFIX . 'facturedet as fd, ' . MAIN_DB_PREFIX . 'societe as s)'; - //$this->export_sql_end[$r] .= ' LEFT JOIN ' . MAIN_DB_PREFIX - // . 'product as p on (fd.fk_product = p.rowid)'; - //$this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid ' - // . 'AND f.rowid = fd.fk_facture'; - //$r++; + // Exports + //-------- + $r=0; + + $r++; + $this->export_code[$r]=$this->rights_class.'_'.$r; + $this->export_label[$r]="ResourceSingular"; // Translation key (used only if key ExportDataset_xxx_z not found) + $this->export_permission[$r]=array(array("resource","read")); + $this->export_fields_array[$r]=array('r.rowid'=>'IdResource','r.ref'=>'ResourceFormLabel_ref','c.code'=>'ResourceTypeCode','c.label'=>'ResourceType','r.description'=>'ResourceFormLabel_description','r.note_private'=>"NotePrivate",'r.note_public'=>"NotePublic",'r.asset_number'=>'AssetNumber','r.datec'=>"DateCreation",'r.tms'=>"DateLastModification"); + $this->export_TypeFields_array[$r]=array('r.rowid'=>'List:resource:ref','r.ref'=>'Text','r.asset_number'=>'Text','r.description'=>'Text','c.code'=>'Text','c.label'=>'List:c_type_resource:label','r.datec'=>'Date','r.tms'=>'Date','r.note_private'=>'Text','r.note_public'=>'Text'); + $this->export_entities_array[$r]=array('r.rowid'=>'resource','r.ref'=>'resource','c.code'=>'resource','c.label'=>'resource','r.description'=>'resource','r.note_private'=>"resource",'r.resource'=>"resource",'r.asset_number'=>'resource','r.datec'=>"resource",'r.tms'=>"resource"); + $keyforselect='resource'; $keyforelement='resource'; $keyforaliasextra='extra'; + include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; + + $this->export_dependencies_array[$r]=array('resource'=>array('r.rowid')); // We must keep this until the aggregate_array is used. To add unique key if we ask a field of a child to avoid the DISTINCT to discard them. + $this->export_sql_start[$r]='SELECT DISTINCT '; + $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'resource as r '; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_resource as c ON c.rowid=r.fk_code_type_resource'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'resource_extrafields as extra ON extra.fk_object = c.rowid'; + $this->export_sql_end[$r] .=' AND r.entity IN ('.getEntity('resource',1).')'; + + + // Imports + //-------- + $r=0; + + // Import list of third parties and attributes + $r++; + $this->import_code[$r]=$this->rights_class.'_'.$r; + $this->import_label[$r]='ImportDataset_resource_1'; + $this->import_icon[$r]='resource'; + $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('r'=>MAIN_DB_PREFIX.'resource','extra'=>MAIN_DB_PREFIX.'resource_extrafields'); // List of tables to insert into (insert done in same order) + $this->import_fields_array[$r]=array('r.ref'=>"ResourceFormLabel_ref*",'r.fk_code_type_resource'=>'ResourceTypeCode','r.description'=>'ResourceFormLabel_description','r.note_private'=>"NotePrivate",'r.note_public'=>"NotePublic",'r.asset_number'=>'AssetNumber','r.datec'=>'DateCreation'); + // Add extra fields + $sql="SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE elementtype = 'resource' AND entity = ".$conf->entity; + $resql=$this->db->query($sql); + if ($resql) // This can fail when class is used on old database (during migration for example) + { + while ($obj=$this->db->fetch_object($resql)) + { + $fieldname='extra.'.$obj->name; + $fieldlabel=ucfirst($obj->label); + $this->import_fields_array[$r][$fieldname]=$fieldlabel.($obj->fieldrequired?'*':''); + } + } + // End add extra fields + $this->import_fieldshidden_array[$r]=array('r.fk_user_author'=>'user->id','extra.fk_object'=>'lastrowid-'.MAIN_DB_PREFIX.'resource'); // aliastable.field => ('user->id' or 'lastrowid-'.tableparent) + $this->import_convertvalue_array[$r]=array( + 'r.fk_code_type_resource'=>array('rule'=>'fetchidfromcodeorlabel','classfile'=>'/core/class/ctyperesource.class.php','class'=>'Ctyperesource','method'=>'fetch','dict'=>'DictionaryResourceType'), + ); + //$this->import_convertvalue_array[$r]=array('s.fk_soc'=>array('rule'=>'lastrowid',table='t'); + $this->import_regex_array[$r]=array('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('r.ref'=>"REF1",'r.fk_code_type_resource'=>"Code from dictionnary resource type",'r.datec'=>"2017-01-01 or 2017-01-01 12:30:00"); + $this->import_updatekeys_array[$r]=array('r.rf'=>'ResourceFormLabel_ref'); + } /** diff --git a/htdocs/core/modules/modService.class.php b/htdocs/core/modules/modService.class.php index 7a5db7fcffd..c385ece4b26 100644 --- a/htdocs/core/modules/modService.class.php +++ b/htdocs/core/modules/modService.class.php @@ -51,7 +51,7 @@ class modService extends DolibarrModules $this->module_position = 30; // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) $this->name = preg_replace('/^mod/i','',get_class($this)); - $this->description = "Gestion des services"; + $this->description = "Service management"; // Possible values for version are: 'development', 'experimental', 'dolibarr' or version $this->version = 'dolibarr'; diff --git a/htdocs/core/modules/modStock.class.php b/htdocs/core/modules/modStock.class.php index 8fe4eb52abe..e80966afb81 100644 --- a/htdocs/core/modules/modStock.class.php +++ b/htdocs/core/modules/modStock.class.php @@ -117,6 +117,38 @@ class modStock extends DolibarrModules $this->rights[4][4] = 'mouvement'; $this->rights[4][5] = 'creer'; + if ($conf->global->MAIN_LEVEL_FEATURES >= 2) { + + $this->rights[5][0] = 1006; + $this->rights[5][1] = 'inventoryReadPermission'; // Permission label + $this->rights[5][3] = 0; // Permission by default for new user (0/1) + $this->rights[5][4] = 'read'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + + $this->rights[6][0] = 1007; + $this->rights[6][1] = 'inventoryCreatePermission'; // Permission label + $this->rights[6][3] = 0; // Permission by default for new user (0/1) + $this->rights[6][4] = 'create'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + + $this->rights[7][0] = 1008; + $this->rights[7][1] = 'inventoryWritePermission'; // Permission label + $this->rights[7][3] = 0; // Permission by default for new user (0/1) + $this->rights[7][4] = 'write'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + + $this->rights[7][0] = 1009; + $this->rights[7][1] = 'inventoryValidatePermission'; // Permission label + $this->rights[7][3] = 0; // Permission by default for new user (0/1) + $this->rights[7][4] = 'validate'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + + $this->rights[7][0] = 1010; + $this->rights[7][1] = 'inventoryChangePMPPermission'; // Permission label + $this->rights[7][3] = 0; // Permission by default for new user (0/1) + $this->rights[7][4] = 'changePMP'; // In php code, permission will be checked by test if ($user->rights->permkey->level1->level2) + + } + + // Main menu entries + $this->menu = array(); // List of menus to add + $r=0; // Menus //------- diff --git a/htdocs/core/modules/product/doc/pdf_standard.modules.php b/htdocs/core/modules/product/doc/pdf_standard.modules.php index 5dca2b8378e..29df1127242 100644 --- a/htdocs/core/modules/product/doc/pdf_standard.modules.php +++ b/htdocs/core/modules/product/doc/pdf_standard.modules.php @@ -92,8 +92,8 @@ class pdf_standard extends ModelePDFProduct $langs->load("companies"); $this->db = $db; - $this->name = "PDF template"; - $this->description = $langs->trans("DocumentModelPdf"); + $this->name = "standard"; + $this->description = $langs->trans("DocumentModelStandardPDF"); // Dimension page pour format A4 $this->type = 'pdf'; @@ -107,15 +107,9 @@ class pdf_standard extends ModelePDFProduct $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; $this->option_logo = 1; // Affiche logo - $this->option_tva = 0; // Gere option tva PRODUCT_TVAOPTION - $this->option_modereg = 0; // Affiche mode reglement - $this->option_condreg = 0; // Affiche conditions reglement $this->option_codeproduitservice = 0; // Affiche code produit-service $this->option_multilang = 1; // Dispo en plusieurs langues - $this->option_escompte = 0; // Affiche si il y a eu escompte - $this->option_credit_note = 0; // Support credit notes - $this->option_freetext = 1; // Support add of a personalised text - $this->option_draft_watermark = 1; // Support add of a watermark on drafts + $this->option_freetext = 0; // Support add of a personalised text // Recupere emetteur $this->emetteur=$mysoc; @@ -262,7 +256,7 @@ class pdf_standard extends ModelePDFProduct } if ($object->weight) { - $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").': '.$object->length.'x'.$object->width.'x'.$object->height, 0, 1); + $pdf->writeHTMLCell(190, 3, $this->marge_gauche, $nexY, $langs->trans("Length").' x '.$langs->trans("Width").' x '.$langs->trans("Height").': '.($object->length != ''?$object->length:'?').' x '.($object->width != ''?$object->width:'?').' x '.($object->height != ''?$object->height:'?'), 0, 1); $nexY = $pdf->GetY(); } if ($object->surface) diff --git a/htdocs/core/modules/syslog/mod_syslog_chromephp.php b/htdocs/core/modules/syslog/mod_syslog_chromephp.php index 42a660ab0ae..a9b9ccd5836 100644 --- a/htdocs/core/modules/syslog/mod_syslog_chromephp.php +++ b/htdocs/core/modules/syslog/mod_syslog_chromephp.php @@ -48,7 +48,7 @@ class mod_syslog_chromephp extends LogHandler implements LogHandlerInterface { global $langs; - return $this->isActive()?'':$langs->trans('ClassNotFoundIntoPathWarning','ChromePhp.class.php'); + return ($this->isActive() == 1)?'':$langs->trans('ClassNotFoundIntoPathWarning','ChromePhp.class.php'); } /** @@ -73,7 +73,7 @@ class mod_syslog_chromephp extends LogHandler implements LogHandlerInterface if ($res) { - return 1; + return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_CHROMEPHP)?1:0; // Set SYSLOG_DISABLE_LOGHANDLER_CHROMEPHP to 1 to disable this loghandler } else { diff --git a/htdocs/core/modules/syslog/mod_syslog_file.php b/htdocs/core/modules/syslog/mod_syslog_file.php index 91af81ef178..68493fd4eb4 100644 --- a/htdocs/core/modules/syslog/mod_syslog_file.php +++ b/htdocs/core/modules/syslog/mod_syslog_file.php @@ -51,7 +51,8 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface */ public function isActive() { - return 1; + global $conf; + return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_FILE)?1:0; // Set SYSLOG_DISABLE_LOGHANDLER_FILE to 1 to disable this loghandler } /** @@ -104,8 +105,10 @@ class mod_syslog_file extends LogHandler implements LogHandlerInterface private function getFilename($suffixinfilename='') { global $conf; - if (! empty($conf->global->SYSLOG_FILE)) $tmp=str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE); - else $tmp='dolibarr.log'; + + if (empty($conf->global->SYSLOG_FILE)) $tmp=DOL_DATA_ROOT.'/dolibarr.log'; + else $tmp=str_replace('DOL_DATA_ROOT', DOL_DATA_ROOT, $conf->global->SYSLOG_FILE); + return $suffixinfilename?preg_replace('/\.log$/i', $suffixinfilename.'.log', $tmp):$tmp; } diff --git a/htdocs/core/modules/syslog/mod_syslog_firephp.php b/htdocs/core/modules/syslog/mod_syslog_firephp.php index fa6111c80a3..69bc98230af 100644 --- a/htdocs/core/modules/syslog/mod_syslog_firephp.php +++ b/htdocs/core/modules/syslog/mod_syslog_firephp.php @@ -56,7 +56,7 @@ class mod_syslog_firephp extends LogHandler implements LogHandlerInterface { global $langs; - return $this->isActive()?'':$langs->trans('ClassNotFoundIntoPathWarning', self::$firephp_class_path); + return ($this->isActive() == 1)?'':$langs->trans('ClassNotFoundIntoPathWarning', self::$firephp_class_path); } /** @@ -76,7 +76,7 @@ class mod_syslog_firephp extends LogHandler implements LogHandlerInterface $res = @include_once self::$firephp_class_path; restore_include_path(); if ($res) { - return 1; + return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_FIREPHP)?1:0; // Set SYSLOG_DISABLE_LOGHANDLER_FIREPHP to 1 to disable this loghandler } else { return 0; } diff --git a/htdocs/core/modules/syslog/mod_syslog_syslog.php b/htdocs/core/modules/syslog/mod_syslog_syslog.php index c2885f1c89a..e0283ac9a9f 100644 --- a/htdocs/core/modules/syslog/mod_syslog_syslog.php +++ b/htdocs/core/modules/syslog/mod_syslog_syslog.php @@ -48,10 +48,12 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface */ public function isActive() { + global $conf; + // This function does not exists on some ISP (Ex: Free in France) if (!function_exists('openlog')) return 0; - return 1; + return empty($conf->global->SYSLOG_DISABLE_LOGHANDLER_SYSLOG)?1:0; // Set SYSLOG_DISABLE_LOGHANDLER_SYSLOG to 1 to disable this loghandler } /** @@ -111,11 +113,11 @@ class mod_syslog_syslog extends LogHandler implements LogHandlerInterface if (! empty($conf->global->MAIN_SYSLOG_DISABLE_SYSLOG)) return; // Global option to disable output of this handler - if (! empty($conf->global->SYSLOG_FACILITY)) + if (! empty($conf->global->SYSLOG_FACILITY)) // Example LOG_USER { $facility = constant($conf->global->SYSLOG_FACILITY); } - else $facility = LOG_USER; + else $facility = constant('LOG_USER'); // (int) is required to avoid error parameter 3 expected to be long openlog('dolibarr', LOG_PID | LOG_PERROR, (int) $facility); diff --git a/htdocs/core/tpl/admin_extrafields_view.tpl.php b/htdocs/core/tpl/admin_extrafields_view.tpl.php index c33d79d062b..3242a388a3d 100644 --- a/htdocs/core/tpl/admin_extrafields_view.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_view.tpl.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2017 Laurent Destailleur * Copyright (C) 2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -34,7 +34,7 @@ print '
'; $extrafields->fetch_name_optionals_label($elementtype); print '
'; -print "
'.img_picto('',$picto, 'id="pictotitle"', $pictoisfullpath).''.img_picto('',$picto, 'class="valignmiddle" id="pictotitle"', $pictoisfullpath).''; $return.= '
'.$titre.'
'; $return.= '
"; +print '
'; print ''; print ''; @@ -49,23 +49,36 @@ if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print ''; print "\n"; -$var=True; -foreach($extrafields->attribute_type as $key => $value) +if (count($extrafields->attribute_type)) { + foreach($extrafields->attribute_type as $key => $value) + { + + print ''; + print "\n"; + print "\n"; + print "\n"; + print "\n"; + print '\n"; + print '\n"; + print '\n"; + print '\n"; + if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print '\n"; // Add hidden option on not working feature. Why hide if user can't see it. + print '\n"; + print ""; + } +} +else +{ + $colspan=9; + if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) $colspan++; print ''; - print "\n"; - print "\n"; - print "\n"; - print "\n"; - print '\n"; - print '\n"; - print '\n"; - print '\n"; - if (! empty($conf->global->MAIN_CAN_HIDE_EXTRAFIELDS)) print '\n"; // Add hidden option on not working feature. Why hide if user can't see it. - print '\n"; - print ""; + print ''; + print ''; } print "
'.$langs->trans("Position").' 
".$extrafields->attribute_pos[$key]."".$extrafields->attribute_label[$key]."".$key."".$type2label[$extrafields->attribute_type[$key]]."'.$extrafields->attribute_size[$key]."'.yn($extrafields->attribute_unique[$key])."'.yn($extrafields->attribute_required[$key])."'.yn($extrafields->attribute_alwayseditable[$key])."'.yn($extrafields->attribute_hidden[$key])."'.img_edit().''; + print "  ".img_delete()."
".$extrafields->attribute_pos[$key]."".$extrafields->attribute_label[$key]."".$key."".$type2label[$extrafields->attribute_type[$key]]."'.$extrafields->attribute_size[$key]."'.yn($extrafields->attribute_unique[$key])."'.yn($extrafields->attribute_required[$key])."'.yn($extrafields->attribute_alwayseditable[$key])."'.yn($extrafields->attribute_hidden[$key])."'.img_edit().''; - print "  ".img_delete()."
'; + print $langs->trans("None"); + print '
"; diff --git a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php index 84517e36c08..9da1ada59ad 100644 --- a/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php +++ b/htdocs/core/triggers/interface_50_modAgenda_ActionsAuto.class.php @@ -48,7 +48,7 @@ class InterfaceActionsAuto extends DolibarrTriggers * $object->actionmsg (note, long text) * $object->actionmsg2 (label, short text) * $object->sendtoid (id of contact or array of ids) - * $object->socid + * $object->socid (id of thirdparty) * $object->fk_project * $object->fk_element * $object->elementtype @@ -87,7 +87,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("NewCompanyToDolibarr",$object->name); $object->actionmsg=$langs->transnoentities("NewCompanyToDolibarr",$object->name); if (! empty($object->prefix)) $object->actionmsg.=" (".$object->prefix.")"; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; $object->socid=$object->id; @@ -100,7 +99,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actiontypecode)) $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) dol_syslog('Trigger called with property actionmsg2 on object not defined', LOG_ERR); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; @@ -114,7 +112,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ContractValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("ContractValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -127,7 +124,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("PropalValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -142,7 +138,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg)) { $object->actionmsg=$langs->transnoentities("ProposalSentByEMail",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; } // Parameters $object->sendtoid defined by caller @@ -157,7 +152,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("PropalClosedSignedInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -170,7 +164,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClassifiedBilledInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("PropalClassifiedBilledInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -183,7 +176,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("PropalClosedRefusedInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -195,7 +187,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -208,7 +199,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderDeliveredInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("OrderDeliveredInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -221,7 +211,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderBilledInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("OrderBilledInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -234,7 +223,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderCanceledInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("OrderCanceledInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -249,7 +237,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg)) { $object->actionmsg=$langs->transnoentities("OrderSentByEMail",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; } // Parameters $object->sendtoid defined by caller @@ -264,7 +251,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -277,7 +263,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -292,7 +277,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg)) { $object->actionmsg=$langs->transnoentities("InvoiceSentByEMail",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; } // Parameters $object->sendtoid defined by caller @@ -308,7 +292,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -321,7 +304,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -334,7 +316,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionCreatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InterventionCreatedInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; $object->fk_element=0; @@ -349,7 +330,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("InterventionValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; $object->fk_element=0; @@ -364,7 +344,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionModifiedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InterventionModifiedInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; $object->fk_element=0; @@ -379,7 +358,7 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionSentByEMail",$object->ref); $object->actionmsg=$langs->transnoentities("InterventionSentByEMail",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + // Parameters $object->sendtoid defined by caller //$object->sendtoid=0; } @@ -392,7 +371,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InterventionClassifiedBilledInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -405,7 +383,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InterventionClassifiedUnbilledInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -418,7 +395,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InterventionDeletedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InterventionDeletedInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; $object->fk_element=0; @@ -435,7 +411,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg)) { $object->actionmsg=$langs->transnoentities("ShippingValidated",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; } // Parameters $object->sendtoid defined by caller @@ -452,7 +427,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg)) { $object->actionmsg=$langs->transnoentities("ShippingSentByEMail",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; } // Parameters $object->sendtoid defined by caller @@ -467,7 +441,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderCreatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("OrderCreatedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -480,7 +453,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("OrderValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -493,7 +465,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("OrderApprovedInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -506,7 +477,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("OrderRefusedInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -519,7 +489,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderSubmitedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("SupplierOrderSubmitedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -532,7 +501,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("SupplierOrderReceivedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("SupplierOrderReceivedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -548,7 +516,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg)) { $object->actionmsg=$langs->transnoentities("SupplierOrderSentByEMail",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; } // Parameters $object->sendtoid defined by caller @@ -566,7 +533,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg)) { $object->actionmsg=$langs->transnoentities("SupplierOrderClassifiedBilled",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; } $object->sendtoid=0; @@ -580,7 +546,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg=$langs->transnoentities("InvoiceValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -593,7 +558,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InvoiceBackToDraftInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -609,7 +573,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg)) { $object->actionmsg=$langs->transnoentities("SupplierInvoiceSentByEMail",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; } // Parameters $object->sendtoid defined by caller @@ -624,7 +587,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InvoicePaidInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -637,7 +599,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actiontypecode='AC_OTH_AUTO'; if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("InvoiceCanceledInDolibarr",$object->ref); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -654,7 +615,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg=$langs->transnoentities("MemberValidatedInDolibarr",($object->newref?$object->newref:$object->ref)); $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -669,7 +629,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg=$langs->transnoentities("MemberModifiedInDolibarr",$object->ref); $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -686,7 +645,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; $object->actionmsg.="\n".$langs->transnoentities("Amount").': '.$object->last_subscription_amount; $object->actionmsg.="\n".$langs->transnoentities("Period").': '.dol_print_date($object->last_subscription_date_start,'day').' - '.dol_print_date($object->last_subscription_date_end,'day'); - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -701,7 +659,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg=$langs->transnoentities("MemberResiliatedInDolibarr",$object->ref); $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -716,7 +673,6 @@ class InterfaceActionsAuto extends DolibarrTriggers $object->actionmsg=$langs->transnoentities("MemberDeletedInDolibarr",$object->ref); $object->actionmsg.="\n".$langs->transnoentities("Member").': '.$object->getFullName($langs); $object->actionmsg.="\n".$langs->transnoentities("Type").': '.$object->type; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -732,7 +688,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("ProjectCreatedInDolibarr",$object->ref); $object->actionmsg.="\n".$langs->transnoentities("Project").': '.$object->ref; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -746,7 +701,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectValidatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("ProjectValidatedInDolibarr",$object->ref); $object->actionmsg.="\n".$langs->transnoentities("Project").': '.$object->ref; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -759,7 +713,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("ProjectModifiedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("ProjectModifieddInDolibarr",$object->ref); $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -775,7 +728,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("TaskCreatedInDolibarr",$object->ref); $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -789,7 +741,6 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskModifiedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("TaskModifieddInDolibarr",$object->ref); $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } @@ -803,18 +754,24 @@ class InterfaceActionsAuto extends DolibarrTriggers if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref); $object->actionmsg=$langs->transnoentities("TaskDeletedInDolibarr",$object->ref); $object->actionmsg.="\n".$langs->transnoentities("Task").': '.$object->ref; - $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; $object->sendtoid=0; } - - // The trigger was enabled but we are missing the implementation, let the log know - else - { - dol_syslog("Trigger '".$this->name."' for action '$action' was ran by ".__FILE__." but no handler found for this action.", LOG_WARNING); - return 0; + // TODO Merge all previous cases into this generic one + else { + // Note: We are here only if $conf->global->MAIN_AGENDA_ACTIONAUTO_action is on (tested at begining of this function) + $langs->load("agenda"); + $langs->load("other"); + + $object->actiontypecode='AC_OTH_AUTO'; + if (empty($object->actionmsg2)) $object->actionmsg2=$langs->transnoentities($action."InDolibarr",$object->ref); + $object->actionmsg=$langs->transnoentities($action."InDolibarr",$object->ref); + + $object->sendtoid=0; } - + + $object->actionmsg.="\n".$langs->transnoentities("Author").': '.$user->login; + dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); // Add entry in event table diff --git a/htdocs/expedition/contact.php b/htdocs/expedition/contact.php index 1354b3d49f1..7c721d7cf47 100644 --- a/htdocs/expedition/contact.php +++ b/htdocs/expedition/contact.php @@ -123,13 +123,13 @@ else if ($action == 'deletecontact' && $user->rights->expedition->creer) dol_print_error($db); } } - +/* else if ($action == 'setaddress' && $user->rights->expedition->creer) { $object->fetch($id); $result=$object->setDeliveryAddress($_POST['fk_address']); if ($result < 0) dol_print_error($db,$object->error); -} +}*/ /* diff --git a/htdocs/expedition/shipment.php b/htdocs/expedition/shipment.php index 57ad04a8a1a..ede1cc6bec9 100644 --- a/htdocs/expedition/shipment.php +++ b/htdocs/expedition/shipment.php @@ -113,7 +113,7 @@ if (empty($reshook)) if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - + /* if ($action == 'setdeliveryaddress' && $user->rights->commande->creer) { $object = new Commande($db); @@ -122,7 +122,7 @@ if (empty($reshook)) if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - + */ if ($action == 'setmode' && $user->rights->commande->creer) { $object = new Commande($db); diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index db2328cdfb4..9a2433994bd 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -444,14 +444,16 @@ if (empty($reshook)) $destinataire->fetch($object->fk_user_validator); $emailTo = $destinataire->email; - if ($emailTo) - { - // FROM - $expediteur = new User($db); - $expediteur->fetch($object->fk_user_author); - $emailFrom = $expediteur->email; + // FROM + $expediteur = new User($db); + $expediteur->fetch($object->fk_user_author); + $emailFrom = $expediteur->email; - // SUBJECT + if ($emailFrom && $emailTo) + { + $filename=array(); $filedir=array(); $mimetype=array(); + + // SUBJECT $subject = $langs->transnoentities("ExpenseReportWaitingForReApproval"); // CONTENT @@ -561,73 +563,83 @@ if (empty($reshook)) // CC $emailCC = $conf->global->NDF_CC_EMAILS; + if (empty($emailTo)) $emailTo=$emailCC; // FROM $expediteur = new User($db); $expediteur->fetch($object->fk_user_valid); $emailFrom = $expediteur->email; - // SUBJECT - $subject = $langs->transnoentities("ExpenseReportApproved"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; - $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); - - // Rebuilt pdf - /* - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - - if($resultPDF - { - // ATTACHMENT + if ($emailFrom && $emailTo) + { $filename=array(); $filedir=array(); $mimetype=array(); - array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); - array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf"); - array_push($mimetype,"application/pdf"); - } - */ + + // SUBJECT + $subject = $langs->transnoentities("ExpenseReportApproved"); + + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $message = $langs->transnoentities("ExpenseReportApprovedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); + + // Rebuilt pdf + /* + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + + if($resultPDF + { + // ATTACHMENT + $filename=array(); $filedir=array(); $mimetype=array(); + array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); + array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf"); + array_push($mimetype,"application/pdf"); + } + */ - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - - if ($mailfile) - { - // SEND - $result=$mailfile->sendfile(); - if ($result) - { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); - setEventMessages($mesg, null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } - else - { - $langs->load("other"); - if ($mailfile->error) - { - $mesg=''; - $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); - $mesg.='
'.$mailfile->error; - setEventMessages($mesg, null, 'errors'); - } - else - { - setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); - } - } + $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + + if ($mailfile) + { + // SEND + $result=$mailfile->sendfile(); + if ($result) + { + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); + setEventMessages($mesg, null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg=''; + $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); + $mesg.='
'.$mailfile->error; + setEventMessages($mesg, null, 'errors'); + } + else + { + setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); + } + } + } + else + { + setEventMessages($mailfile->error,$mailfile->errors,'errors'); + $action=''; + } } - else - { - setEventMessages($mailfile->error,$mailfile->errors,'errors'); - $action=''; - } - } + else + { + setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + $action=''; + } + } else { - setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + setEventMessages($langs->trans("FailedtoSetToApprove"), null, 'warnings'); $action=''; } } @@ -677,68 +689,78 @@ if (empty($reshook)) $expediteur->fetch($object->fk_user_refuse); $emailFrom = $expediteur->email; - // SUBJECT - $subject = $langs->transnoentities("ExpenseReportRefused"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; - $message = $langs->transnoentities("ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_refuse'], $link); - - // Rebuilt pdf - /* - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - - if($resultPDF - { - // ATTACHMENT + if ($emailFrom && $emailTo) + { $filename=array(); $filedir=array(); $mimetype=array(); - array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); - array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf"); - array_push($mimetype,"application/pdf"); - } - */ + + // SUBJECT + $subject = $langs->transnoentities("ExpenseReportRefused"); - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $message = $langs->transnoentities("ExpenseReportRefusedMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_refuse'], $link); - if ($mailfile) - { - // SEND - $result=$mailfile->sendfile(); - if ($result) + // Rebuilt pdf + /* + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + + if($resultPDF { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); - setEventMessages($mesg, null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; + // ATTACHMENT + $filename=array(); $filedir=array(); $mimetype=array(); + array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); + array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf"); + array_push($mimetype,"application/pdf"); } - else - { - $langs->load("other"); - if ($mailfile->error) - { - $mesg=''; - $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); - $mesg.='
'.$mailfile->error; - setEventMessages($mesg, null, 'errors'); - } - else - { - setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); - } - } - } - else - { - setEventMessages($mailfile->error,$mailfile->errors,'errors'); - $action=''; - } + */ + + // PREPARE SEND + $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + + if ($mailfile) + { + // SEND + $result=$mailfile->sendfile(); + if ($result) + { + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); + setEventMessages($mesg, null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg=''; + $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); + $mesg.='
'.$mailfile->error; + setEventMessages($mesg, null, 'errors'); + } + else + { + setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); + } + } + } + else + { + setEventMessages($mailfile->error,$mailfile->errors,'errors'); + $action=''; + } + } + else + { + setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + $action=''; + } } else { - setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); - $action=''; + setEventMessages($langs->trans("FailedtoSetToDeny"), null, 'warnings'); + $action=''; } } else @@ -790,67 +812,77 @@ if (empty($reshook)) $expediteur->fetch($object->fk_user_cancel); $emailFrom = $expediteur->email; - // SUBJECT - $subject = $langs->transnoentities("ExpenseReportCanceled"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; - $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_cancel'], $link); - - // Rebuilt pdf - /* - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - - if($resultPDF - { - // ATTACHMENT - $filename=array(); $filedir=array(); $mimetype=array(); - array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); - array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf"); - array_push($mimetype,"application/pdf"); - } - */ - - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - - if ($mailfile) + if ($emailFrom && $emailTo) { - // SEND - $result=$mailfile->sendfile(); - if ($result) + $filename=array(); $filedir=array(); $mimetype=array(); + + // SUBJECT + $subject = $langs->transnoentities("ExpenseReportCanceled"); + + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $message = $langs->transnoentities("ExpenseReportCanceledMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $_POST['detail_cancel'], $link); + + // Rebuilt pdf + /* + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + + if($resultPDF { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); - setEventMessages($mesg, null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } - else - { - $langs->load("other"); - if ($mailfile->error) - { - $mesg=''; - $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); - $mesg.='
'.$mailfile->error; - setEventMessages($mesg, null, 'errors'); - } - else - { - setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); - } + // ATTACHMENT + $filename=array(); $filedir=array(); $mimetype=array(); + array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); + array_push($filedir, $conf->expensereport->dir_output."/".dol_sanitizeFileName($object->ref)."/".dol_sanitizeFileName($object->ref).".pdf"); + array_push($mimetype,"application/pdf"); } + */ + + // PREPARE SEND + $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + + if ($mailfile) + { + // SEND + $result=$mailfile->sendfile(); + if ($result) + { + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); + setEventMessages($mesg, null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg=''; + $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); + $mesg.='
'.$mailfile->error; + setEventMessages($mesg, null, 'errors'); + } + else + { + setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); + } + } + } + else + { + setEventMessages($mailfile->error,$mailfile->errors,'errors'); + $action=''; + } } else { - setEventMessages($mailfile->error,$mailfile->errors,'errors'); - $action=''; - } + setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + $action=''; + } } else { - setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + setEventMessages($langs->trans("FailedToSetToCancel"), null, 'warnings'); $action=''; } } @@ -945,63 +977,73 @@ if (empty($reshook)) $expediteur->fetch($user->id); $emailFrom = $expediteur->email; - // SUBJECT - $subject = $langs->transnoentities("ExpenseReportPaid"); - - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; - $message = $langs->transnoentities("ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); - - // CONTENT - $message = "Bonjour {$destinataire->firstname},\n\n"; - $message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n"; - $message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n"; - $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; - $message.= "Bien cordialement,\n' SI"; - - // Generate pdf before attachment - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - - if ($mailfile) + if ($emailFrom && $emailTo) { - // SEND - $result=$mailfile->sendfile(); - if ($result) - { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); - setEventMessages($mesg, null, 'mesgs'); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } - else - { - $langs->load("other"); - if ($mailfile->error) - { - $mesg=''; - $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); - $mesg.='
'.$mailfile->error; - setEventMessages($mesg, null, 'errors'); - } - else - { - setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); - } - } + $filename=array(); $filedir=array(); $mimetype=array(); + + // SUBJECT + $subject = $langs->transnoentities("ExpenseReportPaid"); + + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $message = $langs->transnoentities("ExpenseReportPaidMessage", $object->ref, $destinataire->getFullName($langs), $expediteur->getFullName($langs), $link); + + // CONTENT + $message = "Bonjour {$destinataire->firstname},\n\n"; + $message.= "Votre note de frais \"{$object->ref}\" vient d'être payée.\n"; + $message.= "- Payeur : {$expediteur->firstname} {$expediteur->lastname}\n"; + $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; + $message.= "Bien cordialement,\n' SI"; + + // Generate pdf before attachment + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + + // PREPARE SEND + $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + + if ($mailfile) + { + // SEND + $result=$mailfile->sendfile(); + if ($result) + { + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); + setEventMessages($mesg, null, 'mesgs'); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $langs->load("other"); + if ($mailfile->error) + { + $mesg=''; + $mesg.=$langs->trans('ErrorFailedToSendMail', $emailFrom, $emailTo); + $mesg.='
'.$mailfile->error; + setEventMessages($mesg, null, 'errors'); + } + else + { + setEventMessages('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', null, 'warnings'); + } + } + } + else + { + setEventMessages($mailfile->error,$mailfile->errors,'errors'); + $action=''; + } } else { - setEventMessages($mailfile->error,$mailfile->errors,'errors'); - $action=''; + setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + $action=''; } } else { - setEventMessages($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), null, 'warnings'); + setEventMessages($langs->trans("FailedToSetPaid"), null, 'warnings'); $action=''; } } diff --git a/htdocs/fichinter/admin/fichinter_extrafields.php b/htdocs/fichinter/admin/fichinter_extrafields.php index b7b809d277d..bab7572e60a 100644 --- a/htdocs/fichinter/admin/fichinter_extrafields.php +++ b/htdocs/fichinter/admin/fichinter_extrafields.php @@ -71,7 +71,7 @@ print load_fiche_titre($langs->trans("InterventionsSetup"),$linkback,'title_setu $head=fichinter_admin_prepare_head(); -dol_fiche_head($head, 'attributes', $langs->trans("Interventions"), 0, 'intervention'); +dol_fiche_head($head, 'attributes', $langs->trans("Interventions"), -1, 'intervention'); require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; diff --git a/htdocs/fichinter/admin/fichinterdet_extrafields.php b/htdocs/fichinter/admin/fichinterdet_extrafields.php index 776229a4c29..5fadc3f4c2c 100644 --- a/htdocs/fichinter/admin/fichinterdet_extrafields.php +++ b/htdocs/fichinter/admin/fichinterdet_extrafields.php @@ -72,7 +72,7 @@ print load_fiche_titre($langs->trans("InterventionsSetup"),$linkback,'title_setu $head=fichinter_admin_prepare_head(); -dol_fiche_head($head, 'attributesdet', $langs->trans("Interventions"), 0, 'intervention'); +dol_fiche_head($head, 'attributesdet', $langs->trans("Interventions"), -1, 'intervention'); require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index a9ba1ef80aa..4c2716e311a 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -753,7 +753,6 @@ if ($object->id > 0) print '
'; - print '
'; if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB)) { diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 04f50e9fbcb..c326d033de8 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2669,21 +2669,22 @@ class CommandeFournisseur extends CommonOrder $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_method'; $sql.= " WHERE active=1 AND rowid = ".$db->escape($this->methode_commande_id); - $query = $db->query($sql); - if ($query && $db->num_rows($query)) + $resql = $db->query($sql); + if ($resql) { - $obj = $db->fetch_object($query); - - $string = $langs->trans($obj->code); - if ($string == $obj->code) + if ($db->num_rows($query)) { - $string = $obj->label != '-' ? $obj->label : ''; - } - - return $string; + $obj = $db->fetch_object($query); + + $string = $langs->trans($obj->code); + if ($string == $obj->code) + { + $string = $obj->label != '-' ? $obj->label : ''; + } + return $string; + } } - - dol_print_error($db); + else dol_print_error($db); } return ''; @@ -2817,7 +2818,7 @@ class CommandeFournisseur extends CommonOrder /** - * Calc status regarding dispatch stock + * Calc status regarding to dispatched stock * * @param User $user User action * @param int $closeopenorder Close if received diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index c87b3a62bed..b7e3830ad5c 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -467,16 +467,14 @@ if ($id > 0 || ! empty($ref)) { if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) { $nbproduct++; - $var = ! $var; - // To show detail cref and description value, we must make calculation by cref // print ($objp->cref?' ('.$objp->cref.')':''); // if ($objp->description) print '
'.nl2br($objp->description); $suffix = '_0_' . $i; print "\n"; - print '' . "\n"; - print ""; + print '' . "\n"; + print ''; $linktoprod = '' . img_object($langs->trans("ShowProduct"), 'product') . ' ' . $objp->ref . ''; $linktoprod .= ' - ' . $objp->label . "\n"; @@ -500,7 +498,7 @@ if ($id > 0 || ! empty($ref)) { print ""; } - $var = ! $var; + // Define unit price for PMP calculation $up_ht_disc = $objp->subprice; if (! empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU'); @@ -517,11 +515,21 @@ if ($id > 0 || ! empty($ref)) { print ''; // Warehouse column print ''; - print ''; + print ''; print ''; print ''; print ''; - print ''; + + print ''; + if (! empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) // Not tested ! + { + print $langs->trans("BuyingPrice").': '; + } + else + { + print ''; + } + // hidden fields for js function print ''; print ''; @@ -544,11 +552,22 @@ if ($id > 0 || ! empty($ref)) { print '' . img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"') . ''; // Dispatch column print ''; print ''; - print ''; + + print ''; print ''; print ''; print ''; - print ''; + + print ''; + if (! empty($conf->global->SUPPLIER_ORDER_EDIT_BUYINGPRICE_DURING_RECEIPT)) // Not tested ! + { + print $langs->trans("BuyingPrice").': '; + } + else + { + print ''; + } + // hidden fields for js function print ''; print ''; diff --git a/htdocs/fourn/paiement/card.php b/htdocs/fourn/paiement/card.php index 339fc1cb6fd..40037dce274 100644 --- a/htdocs/fourn/paiement/card.php +++ b/htdocs/fourn/paiement/card.php @@ -268,9 +268,8 @@ if ($result > 0) print ''.$langs->trans('BankAccount').''; print ''; $accountstatic=new Account($db); - $accountstatic->id=$bankline->fk_account; - $accountstatic->label=$bankline->bank_account_ref.' - '.$bankline->bank_account_label; - print $accountstatic->getNomUrl(0); + $accountstatic->fetch($bankline->fk_account); + print $accountstatic->getNomUrl(1); print ''; print ''; } diff --git a/htdocs/ftp/admin/ftpclient.php b/htdocs/ftp/admin/ftpclient.php index 158d9fed3da..845760c26b7 100644 --- a/htdocs/ftp/admin/ftpclient.php +++ b/htdocs/ftp/admin/ftpclient.php @@ -247,40 +247,46 @@ else print ''; print ""; - + $keyforname="FTP_NAME_" . $idrss; + $keyforserver="FTP_SERVER_" . $idrss; + $keyforport="FTP_PORT_" . $idrss; + $keyforuser="FTP_USER_" . $idrss; + $keyforpassword="FTP_PASSWORD_" . $idrss; + $keyforpassive="FTP_PASSIVE_" . $idrss; + print ''; print "".$langs->trans("Name").""; - print ""; + print "global->$keyforname . "\" size=\"64\">"; print ""; print ''; print "".$langs->trans("Server").""; - print ""; + print "global->$keyforserver . "\" size=\"64\">"; print ""; print ''; print "".$langs->trans("Port").""; - print ""; + print "global->$keyforport . "\" size=\"64\">"; print ""; print ''; print "".$langs->trans("User").""; - print ""; + print "global->$keyforuser . "\" size=\"24\">"; print ""; print ''; print "".$langs->trans("Password").""; - print ""; + print "global->$keyforpassword . "\" size=\"24\">"; print ""; print ''; print "".$langs->trans("FTPPassiveMode").""; - print ''.$form->selectyesno('FTP_PASSIVE_'.$idrss, @constant("FTP_PASSIVE_" . $idrss), 1).''; + print ''.$form->selectyesno('FTP_PASSIVE_'.$idrss, $conf->global->$keyforpassive, 1).''; print ""; print ""; diff --git a/htdocs/includes/odtphp/Segment.php b/htdocs/includes/odtphp/Segment.php index 39761aa4d04..81e9dad9f97 100644 --- a/htdocs/includes/odtphp/Segment.php +++ b/htdocs/includes/odtphp/Segment.php @@ -139,6 +139,8 @@ class Segment implements IteratorAggregate, Countable } $reg = "/\[!--\sBEGIN\s$this->name\s--\](.*)\[!--\sEND\s$this->name\s--\]/sm"; $this->xmlParsed = preg_replace($reg, '$1', $this->xmlParsed); + // Miguel Erill 09704/2017 - Add macro replacement to invoice lines + $this->xmlParsed = $this->macroReplace($this->xmlParsed); $this->file->open($this->odf->getTmpfile()); foreach ($this->images as $imageKey => $imageValue) { if ($this->file->getFromName('Pictures/' . $imageValue) === false) { @@ -152,6 +154,29 @@ class Segment implements IteratorAggregate, Countable return $this->xmlParsed; } + /** + * Function to replace macros for invoice short and long month, invoice year + * + * Substitution occur when the invoice is generated, not considering the invoice date + * so do not (re)generate in a diferent date than the one that the invoice belongs to + * Perhaps it would be better to use the invoice issued date but I still do not know + * how to get it here + * + * Miguel Erill 09/04/2017 + * + * @param string $value String to convert + */ + public function macroReplace($text) + { + global $langs; + + $patterns=array( '__CURRENTDAY__','__CURRENTDAYTEXT__','__CURRENTMONTHSHORT__','__CURRENTMONTH__','__CURRENTYEAR__' ); + $values=array( date('j'), $langs->trans(date('l')), $langs->trans(date('M')), $langs->trans(date('F')), date('Y') ); + + $text=preg_replace($patterns, $values, $text); + + return $text; + } /** * Analyse the XML code in order to find children * diff --git a/htdocs/includes/swiftmailer/lib/swiftmailer_generate_mimes_config.php b/htdocs/includes/swiftmailer/lib/swiftmailer_generate_mimes_config.php old mode 100644 new mode 100755 diff --git a/htdocs/install/check.php b/htdocs/install/check.php index b37837df663..bc7082b8d9d 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -363,7 +363,7 @@ else // Show first install line $choice = ''.$langs->trans("FreshInstall").''; $choice .= ''; - $choice .= ''; + $choice .= ''; $choice .= $langs->trans("FreshInstallDesc"); if (empty($dolibarr_main_db_host)) // This means install process was not run { @@ -459,7 +459,7 @@ else $choice .= ''; $choice .= ''.$langs->trans("Upgrade").'
'.$newversionfrom.$newversionfrombis.' -> '.$newversionto.'
'; - $choice .= ''; + $choice .= ''; $choice .= $langs->trans("UpgradeDesc"); if ($recommended_choice) diff --git a/htdocs/install/default.css b/htdocs/install/default.css index 257f2d99af8..9725b06b8bc 100644 --- a/htdocs/install/default.css +++ b/htdocs/install/default.css @@ -1,5 +1,5 @@ /* Copyright (C) 2004 Rodolphe Quiedeville - * Copyright (C) 2009-2016 Laurent Destailleur + * Copyright (C) 2009-2017 Laurent Destailleur * * 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 @@ -210,7 +210,9 @@ table.listofchoices, tr.listofchoices, td.listofchoices { tr.listofchoices { height: 42px; } - +.listofchoicesdesc { + color: #999 !important; +} .blinkwait { font-weight: bold; text-decoration:blink !important; @@ -244,9 +246,8 @@ font.warning { div.error { color: #550000; font-weight: bold; - padding: 0.2em 0.2em 0.2em 0.2em; + padding: 0.2em 0.2em 0.2em 0; margin: 0.5em 0 0.5em 0; - border: 1px solid #6C7C8B; } font.error { color: #550000; diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php index 2b8f57d9d3c..cdd639ad50b 100644 --- a/htdocs/install/fileconf.php +++ b/htdocs/install/fileconf.php @@ -45,13 +45,13 @@ dolibarr_install_syslog("--- fileconf: entering fileconf.php page"); // install.forced.php into directory htdocs/install (This is the case with some wizard // installer like DoliWamp, DoliMamp or DoliBuntu). // We first init "forced values" to nothing. -if (! isset($force_install_noedit)) $force_install_noedit=''; // 1=To block var specific to distrib, 2 to block all technical parameters +if (! isset($force_install_noedit)) $force_install_noedit=''; // 1=To block vars specific to distrib, 2 to block all technical parameters if (! isset($force_install_type)) $force_install_type=''; if (! isset($force_install_dbserver)) $force_install_dbserver=''; if (! isset($force_install_port)) $force_install_port=''; if (! isset($force_install_database)) $force_install_database=''; -if (! isset($force_install_prefix)) $force_install_prefix=''; -if (! isset($force_install_createdatabase)) $force_install_createdatabase=''; +if (! isset($force_install_prefix)) $force_install_prefix=''; +if (! isset($force_install_createdatabase)) $force_install_createdatabase=''; if (! isset($force_install_databaselogin)) $force_install_databaselogin=''; if (! isset($force_install_databasepass)) $force_install_databasepass=''; if (! isset($force_install_databaserootlogin)) $force_install_databaserootlogin=''; @@ -324,7 +324,7 @@ if (! empty($force_install_message)) ?> '; + + dol_fiche_head(); + + $formproduct = new FormProduct($db); + + ?> + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
trans('Title') ?>
trans('Date') ?>select_date(time(),'date_inventory'); ?>
trans('inventorySelectWarehouse') ?>selectWarehouses('', 'fk_warehouse') ?>
trans('SelectCategory') ?>select_all_categories(0,'', 'fk_category') ?>
trans('SelectFournisseur') ?>select_thirdparty('','fk_supplier','s.fournisseur = 1') ?>
trans('OnlyProdsInStock') ?>
+ '; + print ''; + print '     '; + print ''; + print ''; + + echo ''; + +} + +if ($action == 'view' || $action == 'edit' || empty($action)) +{ + $object = new Inventory($db); + $object->fetch($id); + + if($action == 'changePMP') + { + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ApplyNewPMP'), $langs->trans('ConfirmApplyNewPMP', $object->getTitle()), 'confirm_changePMP', array(),'no',1); + } + else if($action == 'flush') + { + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('FlushInventory'),$langs->trans('ConfirmFlushInventory',$object->getTitle()),'confirm_flush',array(),'no',1); + } + else if($action == 'delete') + { + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('Delete'),$langs->trans('ConfirmDelete',$object->getTitle()),'confirm_delete',array(),'no',1); + } + else if($action == 'delete_line') + { + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&rowid='.GETPOST('rowid'),$langs->trans('DeleteLine'),$langs->trans('ConfirmDeleteLine',$object->getTitle()),'confirm_delete_line',array(),'no',1); + } + else if($action == 'regulate') + { + print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('RegulateStock'),$langs->trans('ConfirmRegulateStock',$object->getTitle()),'confirm_regulate',array(),'no',1); + } + + $warehouse = new Entrepot($db); + $warehouse->fetch($object->fk_warehouse); + + print dol_get_fiche_head(inventoryPrepareHead($object, $langs->trans('inventoryOfWarehouse', $warehouse->libelle), empty($action) ? '': '&action='.$action)); + + $lines = array(); + card_line($object, $lines, $action); + + print ''.$langs->trans('inventoryOnDate')." ".$object->getDate('date_inventory').'

'; + + $objectTPL = array( + 'id'=> $object->id + ,'date_cre' => $object->getDate('date_cre', 'd/m/Y') + ,'date_maj' => $object->getDate('date_maj', 'd/m/Y H:i') + ,'fk_warehouse' => $object->fk_warehouse + ,'status' => $object->status + ,'entity' => $object->entity + ,'amount' => price( round($object->amount,2) ) + ,'amount_actual'=>price (round($object->amount_actual,2)) + + ); + + $can_validate = !empty($user->rights->stock->validate); + $view_url = dol_buildpath('/product/inventory/card.php', 1); + + $view = array( + 'mode' => $action + ,'url' => dol_buildpath('/product/inventory/card.php', 1) + ,'can_validate' => (int) $user->rights->stock->validate + ,'is_already_validate' => (int) $object->status + ,'token'=>$_SESSION['newtoken'] + ); + + include './tpl/inventory.tpl.php'; +} + +// End of page +llxFooter(); +$db->close(); + + + +function card_line(&$inventory, &$lines, $mode) +{ + global $db,$langs,$user,$conf; + $inventory->amount_actual = 0; + + $TCacheEntrepot = array(); + + foreach ($inventory->Inventorydet as $k => $Inventorydet) + { + $product = & $Inventorydet->product; + $stock = $Inventorydet->qty_stock; + + $pmp = $Inventorydet->pmp; + $pmp_actual = $pmp * $stock; + $inventory->amount_actual+=$pmp_actual; + + $last_pa = $Inventorydet->pa; + $current_pa = $Inventorydet->current_pa; + + $e = new Entrepot($db); + if(!empty($TCacheEntrepot[$Inventorydet->fk_warehouse])) $e = $TCacheEntrepot[$Inventorydet->fk_warehouse]; + elseif($e->fetch($Inventorydet->fk_warehouse) > 0) $TCacheEntrepot[$e->id] = $e; + + $qtytoadd = GETPOST('qty_to_add', 'array'); + $qty = (float) $qtytoadd[$k]; + + $lines[]=array( + 'produit' => $product->getNomUrl(1).' - '.$product->label, + 'entrepot'=>$e->getNomUrl(1), + 'barcode' => $product->barcode, + 'qty' =>($mode == 'edit' ? ' '.img_picto($langs->trans('Add'), 'edit_add').'' : '' ), + 'qty_view' => ($Inventorydet->qty_view ? $Inventorydet->qty_view : 0), + 'qty_stock' => $stock, + 'qty_regulated' => ($Inventorydet->qty_regulated ? $Inventorydet->qty_regulated : 0), + 'action' => ($user->rights->stock->write && $mode=='edit' ? ''.img_picto($langs->trans('inventoryDeleteLine'), 'delete').'' : ''), + 'pmp_stock'=>round($pmp_actual,2), + 'pmp_actual'=> round($pmp * $Inventorydet->qty_view,2), + 'pmp_new'=>(!empty($user->rights->stock->changePMP) && $mode == 'edit' ? ' '.img_picto($langs->trans('Save'), 'bt-save.png@inventory').'' : price($Inventorydet->new_pmp)), + 'pa_stock'=>round($last_pa * $stock,2), + 'pa_actual'=>round($last_pa * $Inventorydet->qty_view,2), + 'current_pa_stock'=>round($current_pa * $stock,2), + 'current_pa_actual'=>round($current_pa * $Inventorydet->qty_view,2), + 'k'=>$k, + 'id'=>$Inventorydet->id + ); + } + +} + + +/* +function _exportCSV(&$inventory) +{ + global $conf; + + header('Content-Type: application/octet-stream'); + header('Content-disposition: attachment; filename=inventory-'. $inventory->getId().'-'.date('Ymd-His').'.csv'); + header('Pragma: no-cache'); + header('Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0'); + header('Expires: 0'); + + echo 'Ref;Label;barcode;qty theorique;PMP;dernier PA;'; + if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) echo 'PA courant;'; + echo 'qty réelle;PMP;dernier PA;'; + if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) echo 'PA courant;'; + echo 'qty regulée;'."\r\n"; + + foreach ($inventory->Inventorydet as $k => $Inventorydet) + { + $product = & $Inventorydet->product; + $stock = $Inventorydet->qty_stock; + + $pmp = $Inventorydet->pmp; + $pmp_actual = $pmp * $stock; + $inventory->amount_actual+=$pmp_actual; + + $last_pa = $Inventorydet->pa; + $current_pa = $Inventorydet->current_pa; + + if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) { + $row=array( + 'produit' => $product->ref + ,'label'=>$product->label + ,'barcode' => $product->barcode + ,'qty_stock' => $stock + ,'pmp_stock'=>round($pmp_actual,2) + ,'pa_stock'=>round($last_pa * $stock,2) + ,'current_pa_stock'=>round($current_pa * $stock,2) + ,'qty_view' => $Inventorydet->qty_view ? $Inventorydet->qty_view : 0 + ,'pmp_actual'=>round($pmp * $Inventorydet->qty_view,2) + ,'pa_actual'=>round($last_pa * $Inventorydet->qty_view,2) + ,'current_pa_actual'=>round($current_pa * $Inventorydet->qty_view,2) + ,'qty_regulated' => $Inventorydet->qty_regulated ? $Inventorydet->qty_regulated : 0 + + ); + + } + else{ + $row=array( + 'produit' => $product->ref + ,'label'=>$product->label + ,'barcode' => $product->barcode + ,'qty_stock' => $stock + ,'pmp_stock'=>round($pmp_actual,2) + ,'pa_stock'=>round($last_pa * $stock,2) + ,'qty_view' => $Inventorydet->qty_view ? $Inventorydet->qty_view : 0 + ,'pmp_actual'=>round($pmp * $Inventorydet->qty_view,2) + ,'pa_actual'=>round($last_pa * $Inventorydet->qty_view,2) + + ,'qty_regulated' => $Inventorydet->qty_regulated ? $Inventorydet->qty_regulated : 0 + + ); + + } + + + echo '"'.implode('";"', $row).'"'."\r\n"; + + } + + exit; +} +*/ + +function _footerList($view,$total_pmp,$total_pmp_actual,$total_pa,$total_pa_actual, $total_current_pa,$total_current_pa_actual) +{ + global $conf,$user,$langs; + + if ($view['can_validate'] == 1) { ?> + +   + barcode->enabled)) { ?> +   + + + + global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ + echo ''.price($total_current_pa).''; + } + ?> +   + + rights->stock->changePMP)) { + echo ' '; + } + ?> + + global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ + echo ''.price($total_current_pa_actual).''; + } + ?> + +   + +   + + + + +   Produit + trans('Warehouse'); ?> + barcode->enabled)) { ?> + trans('Barcode'); ?> + + + trans('TheoricalQty'); ?> + global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ + echo ''.$langs->trans('TheoricalValue').''; + } + else { + echo ''.$langs->trans('TheoricalValue').''; + } + + ?> + + + trans('RealQty'); ?> + + + global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) $colspan++; + if(!empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) $colspan++; + + echo ''.$langs->trans('RealValue').''; + + ?> + + trans('RegulatedQty'); ?> + + + # + + + + + +   + trans('PMP'); ?> + trans('LastPA'); ?> + global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ + echo ''.$langs->trans('CurrentPA').''; + } + + ?> +   + trans('PMP'); ?> + rights->stock->changePMP)) { + echo ''.$langs->trans('ColumnNewPMP').''; + } + ?> + trans('LastPA'); ?> + global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ + echo ''.$langs->trans('CurrentPA').''; + } + + ?> +   + +   + + + + * + * 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/inventory/class/product.class.php + * \ingroup product + * \brief File of class to manage predefined products stock + */ + +require_once DOL_DOCUMENT_ROOT.'/core/class/coreobject.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + +/** + * Class to manage inventories + */ +class Inventory extends CoreObject +{ + public $element='inventory'; + public $table_element='inventory'; + public $fk_element='fk_inventory'; + protected $childtables=array('inventorydet'); // To test if we can delete object + protected $isnolinkedbythird = 1; // No field fk_soc + protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + + /** + * Warehouse Id + * @var int + */ + public $fk_warehouse; + /** + * Entity Id + * @var int + */ + public $entity; + + /** + * Status + * @var int + */ + public $status; + /** + * Inventory Date + * @var date + */ + public $date_inventory; + /** + * Inventory Title + * @var string + */ + public $title; + + /** + * Attribute object linked with database + * @var array + */ + protected $fields=array( + 'fk_warehouse'=>array('type'=>'integer','index'=>true) + ,'entity'=>array('type'=>'integer','index'=>true) + ,'status'=>array('type'=>'integer','index'=>true) + ,'date_inventory'=>array('type'=>'date') + ,'title'=>array('type'=>'string') + ); + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct(DoliDB &$db) + { + global $conf; + + parent::__construct($db); + parent::init(); + + $this->status = 0; + $this->entity = $conf->entity; + $this->errors = array(); + $this->amount = 0; + } + + /** + * Function to sort children object + */ + public function sortDet() + { + if(!empty($this->Inventorydet)) usort($this->Inventorydet, array('Inventory', 'customSort')); + } + + /** + * Get object and children from database + * + * @param int $id Id of object to load + * @param bool $loadChild used to load children from database + * @return int >0 if OK, <0 if KO, 0 if not found + */ + public function fetch($id, $loadChild = true) + { + if(!$loadChild) $this->withChild = false; + + $res = parent::fetch($id, $loadChild); + if($res > 0) + { + $this->sortDet(); + $this->amount = 0; + if(!empty($this->Inventorydet )) + { + foreach($this->Inventorydet as &$det) + { + $this->amount += $det->qty_view * $det->pmp; + } + } + } + + return $res; + } + + /** + * Custom function call by usort + * + * @param Inventorydet $objA first Inventorydet object + * @param Inventorydet $objB second Inventorydet object + * @return int + */ + private function customSort(&$objA, &$objB) + { + $r = strcmp(strtoupper(trim($objA->product->ref)), strtoupper(trim($objB->product->ref))); + + if ($r < 0) $r = -1; + elseif ($r > 0) $r = 1; + else $r = 0; + + return $r; + } + + /** + * @param User $user user object + * @return int + */ + public function changePMP(User &$user) + { + $error = 0; + $this->db->begin(); + + if(!empty($this->Inventorydet)) + { + foreach ($this->Inventorydet as $k => &$Inventorydet) + { + if($Inventorydet->new_pmp>0) + { + $Inventorydet->pmp = $Inventorydet->new_pmp; + $Inventorydet->new_pmp = 0; + + $res = $this->db->query('UPDATE '.MAIN_DB_PREFIX.'product as p SET pmp = '.$Inventorydet->pmp.' WHERE rowid = '.$Inventorydet->fk_product ); + if (!$res) + { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->db->lasterror(); + } + } + } + } + + $res = parent::update($user); + if (!$res) + { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->db->lasterror(); + } + + + if (!$error) + { + $this->db->commit(); + return 1; + } + else + { + $this->db->rollback(); + return -1; + } + } + + /** + * Function to update object or create or delete if needed + * + * @param User $user user object + * @return < 0 if ko, > 0 if ok + */ + public function update(User &$user) + { + $error = 0; + $this->db->begin(); + + // if we valid the inventory we save the stock at the same time + if ($this->status) + { + $res = $this->regulate(); + if ($res < 0) + { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->db->lasterror(); + } + } + + $res = parent::update($user); + if (!$res) + { + $error++; + $this->error = $this->db->lasterror(); + $this->errors[] = $this->db->lasterror(); + } + + if (!$error) + { + $this->db->commit(); + return $this->id; + } + else + { + $this->db->rollback(); + return -1; + } + } + + /** + * Function to update current object + * + * @param array $Tab Array of values + * @return int + */ + public function setValues(&$Tab) + { + global $langs; + + if (isset($Tab['qty_to_add'])) + { + foreach ($Tab['qty_to_add'] as $k => $qty) + { + $qty = (float) price2num($qty); + + if ($qty < 0) + { + $this->errors[] = $langs->trans('inventoryErrorQtyAdd'); + return -1; + } + + $product = new Product($this->db); + $product->fetch($this->Inventorydet[$k]->fk_product); + + $this->Inventorydet[$k]->pmp = $product->pmp; + $this->Inventorydet[$k]->qty_view += $qty; + } + } + + return parent::setValues($Tab); + } + + /** + * Function to delete all Inventorydet + * + * @param User $user user object + * @return < 0 if ko, > 0 if ok + */ + public function deleteAllLine(User &$user) + { + foreach($this->Inventorydet as &$det) + { + $det->to_delete = true; + } + + $res = $this->update($user); + + if ($res > 0) $this->Inventorydet = array(); + else return -1; + } + + /** + * Function to add Inventorydet + * + * @param int $fk_product fk_product of Inventorydet + * @param int $fk_warehouse fk_warehouse target + * @return bool + */ + public function addProduct($fk_product, $fk_warehouse=0) + { + $k = $this->addChild('Inventorydet'); + $det = &$this->Inventorydet[$k]; + + $det->fk_inventory = $this->id; + $det->fk_product = $fk_product; + $det->fk_warehouse = empty($fk_warehouse) ? $this->fk_warehouse : $fk_warehouse; + + $det->load_product(); + + $date = $this->getDate('date_inventory', 'Y-m-d'); + if(empty($date)) $date = $this->getDate('datec', 'Y-m-d'); + $det->setStockDate($date, $fk_warehouse); + + return true; + } + + /** + * Duplication method product to add datem + * Adjust stock in a warehouse for product + * + * @param int $fk_product id of product + * @param int $fk_warehouse id of warehouse + * @param double $nbpiece nb of units + * @param int $movement 0 = add, 1 = remove + * @param string $label Label of stock movement + * @param double $price Unit price HT of product, used to calculate average weighted price (PMP in french). If 0, average weighted price is not changed. + * @param string $inventorycode Inventory code + * @return int <0 if KO, >0 if OK + */ + public function correctStock($fk_product, $fk_warehouse, $nbpiece, $movement, $label='', $price=0, $inventorycode='') + { + global $conf, $user; + + if ($fk_warehouse) + { + $this->db->begin(); + + require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php'; + + $op[0] = "+".trim($nbpiece); + $op[1] = "-".trim($nbpiece); + + $datem = empty($conf->global->INVENTORY_USE_INVENTORY_DATE_FROM_DATEMVT) ? dol_now() : $this->date_inventory; + + $movementstock=new MouvementStock($this->db); + $movementstock->origin = new stdClass(); + $movementstock->origin->element = 'inventory'; + $movementstock->origin->id = $this->id; + $result=$movementstock->_create($user,$fk_product,$fk_warehouse,$op[$movement],$movement,$price,$label,$inventorycode, $datem); + + if ($result >= 0) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$movementstock->error; + $this->errors=$movementstock->errors; + + $this->db->rollback(); + return -1; + } + } + } + + /** + * Function to regulate stock + * + * @return int + */ + public function regulate() + { + global $langs,$conf; + + if($conf->global->INVENTORY_DISABLE_VIRTUAL) + { + $pdt_virtuel = false; + // Test if virtual product is enabled + if($conf->global->PRODUIT_SOUSPRODUITS) + { + $pdt_virtuel = true; + $conf->global->PRODUIT_SOUSPRODUITS = 0; + } + } + + foreach ($this->Inventorydet as $k => $Inventorydet) + { + $product = new Product($this->db); + $product->fetch($Inventorydet->fk_product); + + if ($Inventorydet->qty_view != $Inventorydet->qty_stock) + { + $Inventorydet->qty_regulated = $Inventorydet->qty_view - $Inventorydet->qty_stock; + $nbpiece = abs($Inventorydet->qty_regulated); + $movement = (int) ($Inventorydet->qty_view < $Inventorydet->qty_stock); // 0 = add ; 1 = remove + + //$href = dol_buildpath('/inventory/inventory.php?id='.$this->id.'&action=view', 1); + + $res = $this->correctStock($product->id, $Inventorydet->fk_warehouse, $nbpiece, $movement, $langs->trans('inventoryMvtStock')); + if ($res < 0) return -1; + } + } + + if($conf->global->INVENTORY_DISABLE_VIRTUAL) + { + // Test if virtual product was enabled before regulate + if($pdt_virtuel) $conf->global->PRODUIT_SOUSPRODUITS = 1; + } + + return 1; + } + + /** + * Get the title + * @return string + */ + public function getTitle() + { + global $langs; + + return !empty($this->title) ? $this->title : $langs->trans('inventoryTitle').' '.$this->id; + } + + + /** + * Return clicable link of object (with eventually picto) + * + * @param int $withpicto Add picto into link + * @return string + */ + public function getNomUrl($withpicto = 1) + { + return ''.($withpicto ? img_picto('','object_list.png','',0).' ' : '').$this->getTitle().''; + } + + /** + * Function to add products by default from warehouse and children + * + * @param int $fk_warehouse id of warehouse + * @param int $fk_category id of category + * @param int $fk_supplier id of supplier + * @param int $only_prods_in_stock only product with stock + * + * @return int + */ + public function addProductsFor($fk_warehouse,$fk_category=0,$fk_supplier=0,$only_prods_in_stock=0) + { + $warehouse = new Entrepot($this->db); + $warehouse->fetch($fk_warehouse); + $TChildWarehouses = array($fk_warehouse); + $warehouse->get_children_warehouses($fk_warehouse, $TChildWarehouses); + + $sql = 'SELECT ps.fk_product, ps.fk_entrepot'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'product_stock ps'; + $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'product p ON (p.rowid = ps.fk_product)'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product cp ON (cp.fk_product = p.rowid)'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_fournisseur_price pfp ON (pfp.fk_product = p.rowid)'; + $sql.= ' WHERE ps.fk_entrepot IN ('.implode(', ', $TChildWarehouses).')'; + + if ($fk_category>0) $sql.= ' AND cp.fk_categorie='.$fk_category; + if ($fk_supplier>0) $sql.= ' AND pfp.fk_soc = '.$fk_supplier; + if (!empty($only_prods_in_stock)) $sql.= ' AND ps.reel > 0'; + + $sql.=' GROUP BY ps.fk_product, ps.fk_entrepot ORDER BY p.ref ASC,p.label ASC'; + + $res = $this->db->query($sql); + if($res) + { + while($obj = $this->db->fetch_object($res)) + { + $this->addProduct($obj->fk_product, $obj->fk_entrepot); + } + + return 1; + } + else + { + $this->error = $this->db->lasterror(); + $this->errors[] = $this->db->lasterror(); + return -1; + } + } + + /** + * Return clicable link of inventory object + * + * @param int $id id of inventory + * @param int $withpicto Add picto into link + * @return string + */ + static function getLink($id, $withpicto=1) + { + global $langs,$db; + + $inventory = new Inventory($db); + if($inventory->fetch($id, false) > 0) return $inventory->getNomUrl($withpicto); + else return $langs->trans('InventoryUnableToFetchObject'); + } + + /** + * Function to get the sql select of inventory + * + * @param string $type 'All' to get all data + * @return string + */ + static function getSQL($type) + { + global $conf; + + $sql = ''; + if($type == 'All') + { + $sql = 'SELECT i.rowid,i.title, e.label, i.date_inventory, i.fk_warehouse, i.datec, i.tms, i.status'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'inventory i'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'entrepot e ON (e.rowid = i.fk_warehouse)'; + $sql.= ' WHERE i.entity IN ('.getEntity('inventory', 1).')'; + } + + return $sql; + } +} + +class Inventorydet extends CoreObject +{ + public $element='inventorydet'; + public $table_element='inventorydet'; + protected $isnolinkedbythird = 1; // No field fk_soc + protected $ismultientitymanaged = 0; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe + + public $fk_inventory; + public $fk_warehouse; + public $fk_product; + public $entity; + public $qty_view; + public $qty_stock; + public $qty_regulated; + public $pmp; + public $pa; + public $new_pmp; + + protected $fields=array( + 'fk_inventory'=>array('type'=>'int') + ,'fk_warehouse'=>array('type'=>'int') + ,'fk_product'=>array('type'=>'int') + ,'entity'=>array('type'=>'int') + ,'qty_view'=>array('type'=>'float') + ,'qty_stock'=>array('type'=>'float') + ,'qty_regulated'=>array('type'=>'float') + ,'pmp'=>array('type'=>'float') + ,'pa'=>array('type'=>'float') + ,'new_pmp'=>array('type'=>'float') + ); + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct(DoliDB &$db) + { + global $conf; + + parent::__construct($db); + parent::init(); + + $this->entity = $conf->entity; + $this->errors = array(); + + $this->product = null; + $this->current_pa = 0; + } + + /** + * Get object and children from database + * + * @param int $id id of inventorydet object + * @param bool $loadChild load children + * @return int + */ + function fetch($id, $loadChild = true) + { + $res = parent::fetch($id); + $this->load_product(); + $this->fetch_current_pa(); + + return $res; + } + + /** + * Function to get the unit buy price + * + * @return bool + */ + function fetch_current_pa() + { + global $db,$conf; + + if(empty($conf->global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)) return false; + + if($this->pa > 0) + { + $this->current_pa = $this->pa; + } + else + { + dol_include_once('/fourn/class/fournisseur.product.class.php'); + $p= new ProductFournisseur($db); + $p->find_min_price_product_fournisseur($this->fk_product); + + if($p->fourn_qty>0) $this->current_pa = $p->fourn_price / $p->fourn_qty; + } + + return true; + } + + /** + * Function to set pa attribute from date en fk_warehouse + * + * @param date $date date value + * @param int $fk_warehouse fk_warehouse target + */ + function setStockDate($date, $fk_warehouse) + { + list($pmp, $stock) = $this->getPmpStockFromDate($date, $fk_warehouse); + + $this->qty_stock = $stock; + $this->pmp = $pmp; + + $last_pa = 0; + $sql = 'SELECT price FROM '.MAIN_DB_PREFIX.'stock_mouvement'; + $sql.= ' WHERE fk_entrepot = '.$fk_warehouse; + $sql.= ' AND fk_product = '.$this->fk_product; + $sql.= ' AND (origintype=\'order_supplier\' || origintype=\'invoice_supplier\')'; + $sql.= ' AND price > 0'; + $sql.= ' AND datem <= \''.$date.' 23:59:59\''; + $sql.= ' ORDER BY datem DESC LIMIT 1'; + + $res = $this->db->query($sql); + if($res && $obj = $this->db->fetch_object($res)) + { + $last_pa = $obj->price; + } + + $this->pa = $last_pa; + } + + + /** + * Get the last pmp and last stock from date and warehouse + * + * @param date $date date to check + * @param int $fk_warehouse id of warehouse + * @return array + */ + function getPmpStockFromDate($date, $fk_warehouse) + { + $res = $this->product->load_stock(); + + if($res>0) + { + $stock = isset($this->product->stock_warehouse[$fk_warehouse]->real) ? $this->product->stock_warehouse[$fk_warehouse]->real : 0; + $pmp = $this->product->pmp; + } + + //All Stock mouvement between now and inventory date + $sql = 'SELECT value, price'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'stock_mouvement'; + $sql.= ' WHERE fk_product = '.$this->product->id; + $sql.= ' AND fk_entrepot = '.$fk_warehouse; + $sql.= ' AND datem > \''.date('Y-m-d 23:59:59', strtotime($date)).'\''; + $sql.= ' ORDER BY datem DESC'; + + $res = $this->db->query($sql); + + $laststock = $stock; + $lastpmp = $pmp; + + if($res) + { + while($mouvement = $this->db->fetch_object($res)) + { + $price = ($mouvement->price > 0 && $mouvement->value > 0) ? $mouvement->price : $lastpmp; + $stock_value = $laststock * $lastpmp; + $laststock -= $mouvement->value; + $last_stock_value = $stock_value - ($mouvement->value * $price); + $lastpmp = ($laststock != 0) ? $last_stock_value / $laststock : $lastpmp; + } + } + + return array($lastpmp, $laststock); + } + + /** + * Fetch the product linked with the line + * @return void + */ + function load_product() + { + global $db; + + if($this->fk_product>0) + { + $this->product = new Product($db); + $this->product->fetch($this->fk_product); + } + } +} diff --git a/htdocs/product/inventory/img/bt-save.png b/htdocs/product/inventory/img/bt-save.png new file mode 100644 index 00000000000..f20d292ca91 Binary files /dev/null and b/htdocs/product/inventory/img/bt-save.png differ diff --git a/htdocs/product/inventory/img/inventory.png b/htdocs/product/inventory/img/inventory.png new file mode 100644 index 00000000000..e54ad0eef7d Binary files /dev/null and b/htdocs/product/inventory/img/inventory.png differ diff --git a/htdocs/product/inventory/img/plus.png b/htdocs/product/inventory/img/plus.png new file mode 100644 index 00000000000..b7072a96960 Binary files /dev/null and b/htdocs/product/inventory/img/plus.png differ diff --git a/htdocs/product/inventory/img/plus16.png b/htdocs/product/inventory/img/plus16.png new file mode 100644 index 00000000000..ad17ac89391 Binary files /dev/null and b/htdocs/product/inventory/img/plus16.png differ diff --git a/htdocs/product/inventory/lib/inventory.lib.php b/htdocs/product/inventory/lib/inventory.lib.php new file mode 100644 index 00000000000..aa8c9c9677d --- /dev/null +++ b/htdocs/product/inventory/lib/inventory.lib.php @@ -0,0 +1,104 @@ + + * Copyright (C) 2015 ATM Consulting + * + * 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 lib/inventory.lib.php + * \ingroup inventory + * \brief This file is an example module library + */ + +/** + * Define head array for tabs of inventory tools setup pages + * + * @return Array of head + */ +function inventoryAdminPrepareHead() +{ + global $langs, $conf; + + $langs->load("inventory"); + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT."/admin/inventory.php"; + $head[$h][1] = $langs->trans("Parameters"); + $head[$h][2] = 'settings'; + $h++; + + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + //$this->tabs = array( + // 'entity:+tabname:Title:@inventory:/inventory/mypage.php?id=__ID__' + //); // to add new tab + //$this->tabs = array( + // 'entity:-tabname:Title:@inventory:/inventory/mypage.php?id=__ID__' + //); // to remove a tab + complete_head_from_modules($conf, $langs, $object, $head, $h, 'inventory'); + + return $head; +} + +function inventoryPrepareHead(&$inventory, $title='Inventory', $get='') +{ + global $langs; + + return array( + array(dol_buildpath('/product/inventory/card.php?id='.$inventory->id.$get, 1), $langs->trans($title),'inventory') + ); +} + + + +function inventorySelectProducts(&$inventory) +{ + global $conf,$db,$langs; + + $except_product_id = array(); + + foreach ($inventory->Inventorydet as $Inventorydet) + { + $except_product_id[] = $Inventorydet->fk_product; + } + + ob_start(); + $form = new Form($db); + $form->select_produits(-1, 'fk_product'); + + $TChildWarehouses = array($inventory->fk_warehouse); + $e = new Entrepot($db); + $e->fetch($inventory->fk_warehouse); + if(method_exists($e, 'get_children_warehouses')) $e->get_children_warehouses($e->id, $TChildWarehouses); + + $Tab = array(); + $sql = 'SELECT rowid, label + FROM '.MAIN_DB_PREFIX.'entrepot WHERE rowid IN('.implode(', ', $TChildWarehouses).')'; + if(method_exists($e, 'get_children_warehouses')) $sql.= ' ORDER BY fk_parent'; + $resql = $db->query($sql); + while($res = $db->fetch_object($resql)) { + $Tab[$res->rowid] = $res->label; + } + print '   '; + print $langs->trans('Warehouse').' : '.$form::selectarray('fk_warehouse', $Tab); + + $select_html = ob_get_clean(); + + return $select_html; +} + diff --git a/htdocs/product/inventory/list.php b/htdocs/product/inventory/list.php new file mode 100644 index 00000000000..57545b07948 --- /dev/null +++ b/htdocs/product/inventory/list.php @@ -0,0 +1,134 @@ + + * + * 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/inventory/list.php + * \ingroup product + * \brief File of class to manage inventory + */ + +require_once '../../main.inc.php'; + +require_once DOL_DOCUMENT_ROOT.'/product/inventory/listview.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/inventory/class/inventory.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/inventory/lib/inventory.lib.php'; + +$langs->load("stock"); +$langs->load("inventory"); + +$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = (GETPOST("page",'int')?GETPOST("page", 'int'):0); +if ($page == -1) { $page = 0; } +$offset = $limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortfield) $sortfield="i.title"; +if (! $sortorder) $sortorder="ASC"; + +if (empty($user->rights->stock->lire)) accessforbidden(); + + +/* + * Actions + */ + +// None + + +/* + * View + */ + +llxHeader('',$langs->trans('inventoryListTitle'),'',''); + +echo '
'; + +$inventory = new Inventory($db); +$list = new ListView($db, 'listInventory'); + +$THide = array('label','title'); + +echo $list->render(Inventory::getSQL('All'), array( + 'param' => array( + 'limit' => $limit, + 'offset' => $offset, + 'sortfield' => $sortfield, + 'sortorder'=> $sortorder, + 'page'=>$page + ), + 'limit' => array( + 'nbLine' => $limit, + ), + 'allow-field-select' => true, + 'link'=>array( + 'fk_warehouse'=>''.img_picto('','object_stock.png','',0).' @label@' + ), + 'translate'=>array(), + 'hide'=>$THide, + 'type'=>array( + 'datec'=>'date', + 'tms'=>'datetime', + 'date_inventory'=>'date' + ), + 'list'=>array( + 'title'=>$langs->trans('inventoryListTitle'), + 'messageNothing'=>$langs->trans('inventoryListEmpty'), + 'image' => 'title_products.png' + ), + 'title'=>array( + 'rowid'=>$langs->trans('Title'), + 'date_inventory'=>$langs->trans('InventoryDate'), + 'fk_warehouse'=>$langs->trans('Warehouse'), + 'datec'=>$langs->trans('DateCreation'), + 'tms'=>$langs->trans('DateModification'), + 'status'=>$langs->trans('Status') + ), + 'eval'=>array( + 'status' => '(@val@ ? img_picto("'.$langs->trans("inventoryValidate").'", "statut4") : img_picto("'.$langs->trans("inventoryDraft").'", "statut3"))', + 'rowid'=>'Inventory::getLink(@val@)' + ), + 'position' => array( + 'text-align' => array('status' => 'right') + + ), + 'search'=>array( + 'rowid' => array('search_type' => true, 'table' => array('i'), 'field' => array('title')), + 'date_inventory'=>array('search_type' => 'calendars', 'table' => array('i'), 'field' => array('date_inventory')), + 'status'=>array('search_type' => array(1=>$langs->trans("inventoryValidate"), 0=>$langs->trans("inventoryDraft"))) + ) +)); + + +/*if (!empty($user->rights->stock->create)) +{ + print '
'; + print ''.$langs->trans('inventoryCreate').''; + print '
'; +}*/ + +echo '
'; + +llxFooter(''); +$db->close(); \ No newline at end of file diff --git a/htdocs/product/inventory/listview.class.php b/htdocs/product/inventory/listview.class.php new file mode 100644 index 00000000000..51855629686 --- /dev/null +++ b/htdocs/product/inventory/listview.class.php @@ -0,0 +1,1032 @@ + + + This program and all files within this directory and sub directory + 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 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 . + */ + +/** + * Class to manage the lists view + */ +class Listview +{ + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $id html id + */ + function __construct(&$db, $id) + { + $this->db = &$db; + $this->id = $id; + $this->TTotalTmp=array(); + $this->sql = ''; + $this->form = null; + $this->totalRowToShow=0; + $this->totalRow=0; + } + + /** + * Function to init fields + * + * @param array $TParam array of configuration of list + * @return bool + */ + private function init(&$TParam) + { + global $conf, $langs, $user; + + if(!isset($TParam['hide'])) $TParam['hide']=array(); + if(!isset($TParam['link'])) $TParam['link']=array(); + if(!isset($TParam['type'])) $TParam['type']=array(); + if(!isset($TParam['orderby']['noOrder'])) $TParam['orderby']['noOrder']=array(); + if(!isset($TParam['allow-fields-select'])) $TParam['allow-fields-select'] = 0; + + if(!isset($TParam['list']))$TParam['list']=array(); + $TParam['list'] = array_merge(array( + 'messageNothing'=>$langs->trans('ListMessageNothingToShow') + ,'noheader'=>0 + ,'useBottomPagination'=>0 + ,'image'=>'' + ,'title'=>$langs->trans('List') + ,'orderDown'=>'' + ,'orderUp'=>'' + ,'id'=>$this->id + ,'head_search'=>'' + ,'export'=>array() + ,'view_type'=>'' + ),$TParam['list']); + + if (empty($TParam['limit'])) $TParam['limit'] = array(); + + $page = GETPOST('page'); + if (!empty($page)) $TParam['limit']['page'] = $page+1; // TODO dolibarr start page at 0 instead 1 + + $TParam['limit'] = array_merge(array('page'=>1, 'nbLine' => $conf->liste_limit, 'global'=>0), $TParam['limit']); + + if (GETPOST('sortfield')) + { + $TParam['sortfield'] = GETPOST('sortfield'); + $TParam['sortorder'] = GETPOST('sortorder'); + } + + include_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; + $this->form = new Form($this->db); + } + + + /** + * Function to know if we can search on null value + * @param string $key field name + * @param array $TParam array of configuration + * @return bool + */ + private function getSearchNull($key, &$TParam) + { + return !empty($TParam['search'][$key]['allow_is_null']); + } + + /** + * @param string $key field name + * @param string $TParam array of configuration + * @return array + */ + private function getSearchKey($key, &$TParam) + { + $TPrefixe = array(); + if(!empty($TParam['search'][$key]['table'])) + { + if (!is_array($TParam['search'][$key]['table'])) $TParam['search'][$key]['table'] = array($TParam['search'][$key]['table']); + + foreach ($TParam['search'][$key]['table'] as $prefix_table) + { + $TPrefixe[] = $prefix_table.'.'; + } + } + + $TKey=array(); + if(!empty($TParam['search'][$key]['field'])) + { + if (!is_array($TParam['search'][$key]['field'])) $TParam['search'][$key]['field'] = array($TParam['search'][$key]['field']); + + foreach ($TParam['search'][$key]['field'] as $i => $field) + { + $prefixe = !empty($TPrefixe[$i]) ? $TPrefixe[$i] : $TPrefixe[0]; + $TKey[] = $prefixe. $field ; + } + } + else + { + $TKey[] = $TPrefixe[0].$key; + } + + return $TKey; + } + + /** + * @param timestamp $date date to convert + * @return int|string Date TMS or '' + */ + private function dateToSQLDate($date) + { + return $this->db->idate($date); + } + + + /** + * @param string $TSQLMore contain some additional sql instructions + * @param string $value date with read format + * @param string $sKey field name + */ + private function addSqlFromTypeDate(&$TSQLMore, &$value, $sKey) + { + if(is_array($value)) + { + $TSQLDate=array(); + if(!empty($value['start'])) + { +// $valueDeb = $this->dateToSQLDate($value['start'].' 00:00:00'); + $TSQLDate[]=$sKey." >= '".$value['start']."'" ; + } + + if(!empty($value['end'])) + { +// $valueFin = $this->dateToSQLDate($value['end'].' 23:59:59'); + $TSQLDate[]=$sKey." <= '".$value['end']."'" ; + } + + if(!empty($TSQLDate)) $TSQLMore[] = implode(' AND ', $TSQLDate); + } + else + { +// $value = $this->dateToSQLDate($value); + $TSQLMore[]=$sKey." LIKE '".$value."%'" ; + } + } + + + /** + * @param string $TSQLMore contain some additional sql instructions + * @param string $value value to filter + * @param string $TParam array of configuration + * @param string $sKey field name + * @param string $key reference of sKey to find value into TParam + * @return bool + */ + private function addSqlFromOther(&$TSQLMore, &$value, &$TParam, $sKey, $key) + { + // Do not use empty() function, statut 0 exist + if ($value == '') return false; + elseif($value==-1) return false; + + if(isset($TParam['operator'][$key])) + { + if($TParam['operator'][$key] == '<' || $TParam['operator'][$key] == '>' || $TParam['operator'][$key]=='=') + { + $TSQLMore[] = $sKey . ' ' . $TParam['operator'][$key] . ' "' . $value . '"'; + } + elseif ($TParam['operator'][$key]=='IN') + { + $TSQLMore[] = $sKey . ' ' . $TParam['operator'][$key] . ' (' . $value . ')'; + } + else + { + if(strpos($value,'%')===false) $value = '%'.$value.'%'; + $TSQLMore[]=$sKey." LIKE '".addslashes($value)."'" ; + } + } + else + { + if(strpos($value,'%')===false) $value = '%'.$value.'%'; + $TSQLMore[]=$sKey." LIKE '".addslashes($value)."'" ; + } + + return true; + } + + + /** + * @param string $sql standard select sql + * @param string $TParam array of configuration + * @return string + */ + private function search($sql, &$TParam) + { + $ListPOST = GETPOST('Listview'); + + if (!GETPOST("button_removefilter_x") && !GETPOST("button_removefilter.x") && !GETPOST("button_removefilter")) + { + foreach ($TParam['search'] as $field => $info) + { + $TsKey = $this->getSearchKey($field, $TParam); + $TSQLMore = array(); + $allow_is_null = $this->getSearchNull($field,$TParam); + + foreach ($TsKey as $i => &$sKey) + { + $value = ''; + if (isset($ListPOST[$this->id]['search'][$field])) $value = $ListPOST[$this->id]['search'][$field]; + + if ($allow_is_null && !empty($ListPOST[$this->id]['search_on_null'][$field])) + { + $TSQLMore[] = $sKey.' IS NULL '; + $value = ''; + } + + if (isset($TParam['type'][$field]) && ($TParam['type'][$field]==='date' || $TParam['type'][$field]==='datetime')) + { + $k = 'Listview_'.$this->id.'_search_'.$field; + if ($info['search_type'] === 'calendars') + { + $value = array(); + + $timestart = dol_mktime(0, 0, 0, GETPOST($k.'_startmonth'), GETPOST($k.'_startday'), GETPOST($k.'_startyear')); + if ($timestart) $value['start'] = date('Y-m-d', $timestart); + + $timeend = dol_mktime(23, 59, 59, GETPOST($k.'_endmonth'), GETPOST($k.'_endday'), GETPOST($k.'_endyear')); + if ($timeend) $value['end'] = date('Y-m-d', $timeend); + } + else + { + $time = dol_mktime(12, 0, 0, GETPOST($k.'month'), GETPOST($k.'day'), GETPOST($k.'year')); + if ($time) $value = date('Y-m-d', $time); + } + + if (!empty($value)) $this->addSqlFromTypeDate($TSQLMore, $value, $sKey); + } + else + { + $this->addSqlFromOther($TSQLMore, $value, $TParam, $sKey, $field); + } + } + + if (!empty($TSQLMore)) + { + $sql.=' AND ( '.implode(' OR ',$TSQLMore).' ) '; + } + } + } + + if ($sqlGROUPBY!='') $sql.=' GROUP BY '.$sqlGROUPBY; + + return $sql; + } + + /** + * @param string $sql standard select sql + * @param string $TParam array of configuration + * @return string + */ + public function render($sql, $TParam=array()) + { + global $conf; + + $TField=array(); + + $this->init($TParam); + + $THeader = $this->initHeader($TParam); + + $sql = $this->search($sql,$TParam); + $sql.= $this->db->order($TParam['param']['sortfield'], $TParam['param']['sortorder']); + + $nbtotalofrecords = ''; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) + { + $result = $this->db->query($sql); + $nbtotalofrecords = $this->db->num_rows($result); + } + $sql.= $this->db->plimit($TParam['param']['limit'] + 1, $TParam['param']['offset']); + + $this->parse_sql($THeader, $TField, $TParam, $sql); + + list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam); + + return $this->renderList($THeader, $TField, $TTotal, $TTotalGroup, $TParam); + } + + /** + * @param string $THeader the configuration of header + * @param string $TParam array of configuration + * @return array + */ + private function setSearch(&$THeader, &$TParam) + { + global $langs, $form; + + if(empty($TParam['search'])) return array(); + + $TSearch=array(); + + $nb_search_in_bar = 0; + + if(!empty($TParam['search'])) + { + foreach($THeader as $key => $libelle) + { + if(empty($TSearch[$key]))$TSearch[$key]=''; + } + } + + $ListPOST = GETPOST('Listview'); + $removeFilter = (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")); + foreach($TParam['search'] as $key => $param_search) + { + $value = isset($ListPOST[$this->id]['search'][$key]) ? $ListPOST[$this->id]['search'][$key] : ''; + if ($removeFilter) $value = ''; + + $typeRecherche = (is_array($param_search) && isset($param_search['search_type'])) ? $param_search['search_type'] : $param_search; + + if(is_array($typeRecherche)) + { + $fsearch=$form->selectarray('Listview['.$this->id.'][search]['.$key.']', $typeRecherche,$value,1); + } + else if($typeRecherche==='calendar') + { + if (!$removeFilter) $value = GETPOST('Listview_'.$this->id.'_search_'.$key) ? mktime(0,0,0, (int) GETPOST('Listview_'.$this->id.'_search_'.$key.'month'), (int) GETPOST('Listview_'.$this->id.'_search_'.$key.'day'), (int) GETPOST('Listview_'.$this->id.'_search_'.$key.'year') ) : ''; + + $fsearch = $form->select_date($value, 'Listview_'.$this->id.'_search_'.$key,0, 0, 1, "", 1, 0, 1); + } + else if($typeRecherche==='calendars') + { + $value_start = $value_end = ''; + if (!$removeFilter) + { + $value_start = GETPOST('Listview_'.$this->id.'_search_'.$key.'_start') ? mktime(0,0,0, (int) GETPOST('Listview_'.$this->id.'_search_'.$key.'_startmonth'), (int) GETPOST('Listview_'.$this->id.'_search_'.$key.'_startday'), (int) GETPOST('Listview_'.$this->id.'_search_'.$key.'_startyear') ) : ''; + $value_end = GETPOST('Listview_'.$this->id.'_search_'.$key.'_end') ? mktime(0,0,0, (int) GETPOST('Listview_'.$this->id.'_search_'.$key.'_endmonth'), (int) GETPOST('Listview_'.$this->id.'_search_'.$key.'_endday'), (int) GETPOST('Listview_'.$this->id.'_search_'.$key.'_endyear') ) : ''; + } + + $fsearch = $form->select_date($value_start, 'Listview_'.$this->id.'_search_'.$key.'_start',0, 0, 1, "", 1, 0, 1) + . $form->select_date($value_end, 'Listview_'.$this->id.'_search_'.$key.'_end',0, 0, 1, "", 1, 0, 1); + + } + else if(is_string($typeRecherche)) + { + $fsearch=$TParam['search'][$key]; + } + else + { + $fsearch=''; + } + + if(!empty($param_search['allow_is_null'])) + { + $valueNull = isset($ListPOST[$this->id]['search_on_null'][$key]) ? 1 : 0; + $fsearch.=' '.$form->checkbox1('', 'Listview['.$this->id.'][search_on_null]['.$key.']',1, $valueNull,' onclick=" if($(this).is(\':checked\')){ $(this).prev().val(\'\'); }" ').img_help(1, $langs->trans('SearchOnNUllValue')); + } + + if(!empty($THeader[$key])) + { + $TSearch[$key] = $fsearch; + $nb_search_in_bar++; + } + else + { + $label = !empty($TParam['title'][$key]) ? $TParam['title'][$key] : $key ; + $TParam['list']['head_search'].= ''.$label.''; +// $TParam['list']['head_search'].='
'.$label.' '.$fsearch.'
'; + } + } + + $search_button = ' '.img_search().''; + + if(!empty($TParam['list']['head_search'])) + { + $TParam['list']['head_search']='
'.$search_button.'
'.$TParam['list']['head_search']; + } + + if($nb_search_in_bar>0) + { + end($TSearch); + list($key,$v) = each($TSearch); + $TSearch[$key].=$search_button; + } + else + { + $TSearch=array(); + } + + return $TSearch; + } + + /** + * Function to analyse and calculate the total from a column + * + * @param string $TField TField + * @param string $TParam TParam + * @return array + */ + private function get_total(&$TField, &$TParam) + { + $TTotal=$TTotalGroup=array(); + + if(!empty($TParam['math']) && !empty($TField[0])) + { + foreach($TField[0] as $field=>$value) + { + $TTotal[$field]=''; + $TTotalGroup[$field] = ''; + } + + foreach($TParam['math'] as $field=>$typeMath) + { + if(is_array($typeMath)) + { + $targetField = $typeMath[1]; + $typeMath = $typeMath[0]; + } + else + { + $targetField = $field; + } + + if($typeMath == 'groupsum') + { + $TTotalGroup[$field] = array('target'=>$targetField, 'values'=> $this->TTotalTmp['@groupsum'][$targetField]); + } + else if($typeMath=='average') + { + $TTotal[$field]=array_sum($this->TTotalTmp[$targetField]) / count($this->TTotalTmp[$targetField]); + } + elseif($typeMath=='count') + { + $TTotal[$field]=count($this->TTotalTmp[$targetField]); + } + else + { + $TTotal[$field]=array_sum($this->TTotalTmp[$targetField]); + } + } + } + + return array($TTotal,$TTotalGroup); + } + + /** + * @return string + */ + /* + private function getJS() + { + $javaScript = ''; + + return $javaScript; + } + */ + + /** + * @param string $TParam TParam + * @param string $TField TField + * @param string $THeader THeader + * @return array + */ + private function setExport(&$TParam, $TField, $THeader) + { + global $langs; + + $Tab=array(); + if(!empty($TParam['export'])) + { + $token = GETPOST('token'); + if(empty($token)) $token = md5($this->id.time().rand(1,9999)); + + $_SESSION['token_list_'.$token] = gzdeflate( serialize( array( + 'title'=>$this->title, + 'sql'=>$this->sql, + 'TBind'=>$this->TBind, + 'TChamps'=>$TField, + 'TEntete'=>$THeader + ))); + + foreach($TParam['export'] as $mode_export) + { + $Tab[] = array( + 'label'=>$langs->trans('Export'.$mode_export), + 'url'=>dol_buildpath('/abricot/downlist.php',1), + 'mode'=>$mode_export, + 'token'=>$token, + 'session_name'=>session_name() + ); + } + + } + + return $Tab; + } + + /** + * @param string $TField TField + * @param string $TTotalGroup TTotalGroup + * @return array + */ + private function addTotalGroup($TField, $TTotalGroup) + { + global $langs; + + $Tab=array(); + $proto_total_line = array(); + $tagbase = $old_tagbase = null; + $addGroupLine = false; + + foreach($TField as $k=>&$line) + { + if(empty($proto_total_line)) + { + foreach($line as $field=>$value) + { + $proto_total_line[$field] = ''; + } + $group_line = $proto_total_line; + } + + $addGroupLine = false; + + $tagbase = ''; + foreach($line as $field=>$value) + { + if(!empty($TTotalGroup[$field])) + { + $tagbase.=$value.'|'; + $group_line[$field] = '
'.(empty($value) ? $langs->trans('Empty') : $value ).' :
'; + $group_line[$TTotalGroup[$field]['target']] = '
'.price($TTotalGroup[$field]['values'][$value]).'
'; + $addGroupLine = true; + } + } + + if(!is_null($old_tagbase) && $old_tagbase!=$tagbase && $addGroupLine) + { + $Tab[] = $previous_group_line; + } + + $old_tagbase = $tagbase; + $previous_group_line = $group_line; + $group_line = $proto_total_line; + + $Tab[] = $line; + } + + if($addGroupLine) + { + $Tab[] = $previous_group_line; + } + + return $Tab; + } + + /** + * @param string $THeader THeader + * @param string $TField TField + * @param string $TTotal TTotal + * @param string $TTotalGroup TTotalGroup + * @param string $TParam TParam + * @return string + */ + private function renderList(&$THeader, &$TField, &$TTotal, &$TTotalGroup, &$TParam) + { + global $bc; + + $TSearch = $this->setSearch($THeader, $TParam); + $TExport = $this->setExport($TParam, $TField, $THeader); + $TField = $this->addTotalGroup($TField,$TTotalGroup); + + //$out = $this->getJS(); + + $dolibarr_decalage = $this->totalRow > $this->totalRowToShow ? 1 : 0; + ob_start(); + print_barre_liste($TParam['list']['title'], $TParam['limit']['page']-1, $_SERVER["PHP_SELF"], '&'.$TParam['list']['param_url'], $TParam['sortfield'], $TParam['sortorder'], '', $this->totalRowToShow+$dolibarr_decalage, $this->totalRow, $TParam['list']['image'], 0, '', '', $TParam['limit']['nbLine']); + $out .= ob_get_clean(); + + + $out.= ''; + + if(count($TSearch)>0) + { + $out.=''; + + foreach ($THeader as $field => $head) + { + if ($field === 'selectedfields') + { + $out.= ''; + } + else + { + $moreattrib = 'style="width:'.$head['width'].';text-align:'.$head['text-align'].'"'; + $out .= ''; + } + } + + $out.=''; + } + + $out.= ''; + foreach($THeader as $field => $head) + { + $moreattrib = ''; + $search = ''; + $prefix = ''; + + if ($field === 'selectedfields') + { + $moreattrib = 'align="right" '; + $prefix = 'maxwidthsearch '; + } + + if (empty($head['width'])) $head['width'] = 'auto'; + if (!empty($head['width']) && !empty($head['text-align'])) $moreattrib .= 'style="width:'.$head['width'].';text-align:'.$head['text-align'].'"'; + + if (isset($TParam['search'][$field]['search_type']) && $TParam['search'][$field]['search_type'] !== false) + { + $TsKey = $this->getSearchKey($field, $TParam); + if (!empty($TsKey)) $search = implode(',', $TsKey); + else $search = $field; + } + + $out .= getTitleFieldOfList($head['label'], 0, $_SERVER["PHP_SELF"], $search, '', $moreparam, $moreattrib, $TParam['sortfield'], $TParam['sortorder'], $prefix); + $out .= $head['more']; + } + + //$out .= ''; + $out .= ''; + + $out.=''; + + if(empty($TField)) + { + if (!empty($TParam['list']['messageNothing'])) $out .= ''; + } + else + { + $var=true; + $line_number = 0; + foreach($TField as $fields) + { + if($this->in_view($TParam, $line_number)) + { + $var=!$var; + $out.=''; + + foreach ($THeader as $field => $head) + { + $moreattrib = 'style="width:'.$head['width'].';text-align:'.$head['text-align'].'"'; + $out.=''; + } + + $out.=''; + } + + $line_number++; + } + + $out.=''; + + if (!empty($TParam['list']['haveTotal'])) + { + $out.=''; + + foreach ($THeader as $field => $head) + { + if (isset($TTotal[$field])) + { + $moreattrib = 'style="width:'.$head['width'].';text-align:'.$head['text-align'].'"'; + $out.=''; + } + } + + $out.=''; + } + } + + $out .= '
--
'.$TParam['list']['messageNothing'].'
'.$fields[$field].'
'.price($TTotal[$field]).'
'; + + return $out; + } + + /** + * @param string $db Db + * @param string $TField TField + * @param string $TParam TParam + */ + public function renderArray(&$db, $TField, $TParam=array()) + { + $this->typeRender = 'array'; + + $TField=array(); + + $this->init($TParam); + $THeader = $this->initHeader($TParam); + + $this->parse_array($THeader, $TField, $TParam); + list($TTotal, $TTotalGroup)=$this->get_total($TField, $TParam); + + $this->renderList($THeader, $TField, $TTotal, $TTotalGroup, $TParam); + } + + + /** + * @param string $THeader THeader + * @param string $TField TField + * @param string $TParam TParam + * @return bool + */ + private function parse_array(&$THeader, &$TField, &$TParam) + { + $this->totalRow = count($TField); + + $this->THideFlip = array_flip($TParam['hide']); + $this->TTotalTmp=array(); + + if (empty($TField)) return false; + + foreach($TField as $row) + { + $this->set_line($TField, $TParam, $row); + } + } + + + private function initHeader(&$TParam) + { + global $user,$conf; + + $THeader = array(); + + $TField=$TFieldVisibility=array(); + foreach ($TParam['title'] as $field => $value) + { + $TField[$field]=true; + } + + $contextpage=md5($_SERVER['PHP_SELF']); + if(!empty($TParam['allow-field-select'])) + { + $selectedfields = GETPOST('Listview'.$this->id.'_selectedfields'); + + if(!empty($selectedfields)) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; + $tabparam['MAIN_SELECTEDFIELDS_'.$contextpage] = $selectedfields; + $result=dol_set_user_param($this->db, $conf, $user, $tabparam); + } + + $tmpvar='MAIN_SELECTEDFIELDS_'.$contextpage; + if (! empty($user->conf->{$tmpvar})) + { + $tmparray = explode(',', $user->conf->{$tmpvar}); + $TParam['hide'] = array(); + foreach($TField as $field => $dummy) + { + $label = $TParam['title'][$field]; + if(!in_array($field, $tmparray)) + { + $TParam['hide'][] = $field; + $visible = 0; + } + else + { + $visible = 1; + } + + $TFieldVisibility[$field] = array( + 'label'=>$label + ,'checked'=>$visible + ); + } + } + else + { + foreach($TField as $field=>$dummy) + { + $label = isset($TParam['title'][$field]) ? $TParam['title'][$field] : $field; + $visible = (!in_array($field, $TParam['hide'])) ? 1 : 0; + $TFieldVisibility[$field]=array( + 'label'=>$label, + 'checked'=>$visible + ); + } + } + + $selectedfields = $this->form->multiSelectArrayWithCheckbox('Listview'.$this->id.'_selectedfields', $TFieldVisibility, $contextpage); // This also change content of $arrayfields_0 + } + + foreach ($TParam['title'] as $field => $label) + { + $visible = (!in_array($field, $TParam['hide'])) ? 1 : 0; + if($visible) + { + $THeader[$field] = array( + 'label'=>$label, + 'order'=>(in_array($field, $TParam['orderby']['noOrder']) ? 0 : 1), + 'width'=>(!empty($TParam['size']['width'][$field]) ? $TParam['size']['width'][$field] : 'auto'), + 'text-align'=>(!empty($TParam['position']['text-align'][$field]) ? $TParam['position']['text-align'][$field] : 'auto'), + 'more'=>'' + ); + } + } + + if(!empty($selectedfields)) + { + $THeader['selectedfields']['label']='
'.$selectedfields.'
'; + } + + return $THeader; + } + + /** + * @param string $TParam TParam + * @param string $line_number aaa + * @return bool + */ + private function in_view(&$TParam, $line_number) + { + global $conf; + + if(!empty($_REQUEST['get-all-for-export'])) return true; + + $page_number = !empty($TParam['limit']['page']) ? $TParam['limit']['page'] : 1; + $line_per_page = !empty($TParam['limit']['nbLine']) ? $TParam['limit']['nbLine'] : $conf->liste_limit; + + $start = ($page_number-1) * $line_per_page; + $end = ($page_number* $line_per_page) -1; + + if($line_number>=$start && $line_number<=$end) return true; + else return false; + } + + /** + * @param string $TField TField + * @param string $TParam TParam + * @param string $currentLine aaa + */ + private function set_line(&$TField, &$TParam, $currentLine) + { + global $conf; + + $line_number = count($TField); + + if($this->in_view($TParam,$line_number)) + { + $this->totalRowToShow++; + $row=array(); $trans = array(); + foreach($currentLine as $field=>$value) + { + if(is_object($value)) + { + if(get_class($value)=='stdClass') {$value=print_r($value, true);} + else $value=(string) $value; + } + + $trans['@'.$field.'@'] = $value; + + if(!empty($TParam['math'][$field])) + { + $float_value = (double) strip_tags($value); + $this->TTotalTmp[$field][] = $float_value; + } + + if(!in_array($field,$TParam['hide'])) + { + $row[$field]=$value; + + if(isset($TParam['eval'][$field]) && in_array($field,array_keys($row))) + { + $strToEval = 'return '.strtr( $TParam['eval'][$field], array_merge( $trans, array('@val@'=>$row[$field]) )).';'; + $row[$field] = eval($strToEval); + } + + if(isset($TParam['type'][$field]) && !isset($TParam['eval'][$field])) + { + if($TParam['type'][$field]=='date' || $TParam['type'][$field]=='datetime' ) + { + if($row[$field] != '0000-00-00 00:00:00' && $row[$field] != '1000-01-01 00:00:00' && $row[$field] != '0000-00-00' && !empty($row[$field])) + { + if($TParam['type'][$field]=='datetime')$row[$field] = dol_print_date(strtotime($row[$field]),'dayhoursec'); + else $row[$field] = dol_print_date(strtotime($row[$field]),'day'); + } + else + { + $row[$field] = ''; + } + } + + if($TParam['type'][$field]=='hour') { $row[$field] = date('H:i', strtotime($row[$field])); } + if($TParam['type'][$field]=='money') { $row[$field] = '
'.price($row[$field],0,'',1,-1,2).'
'; } + if($TParam['type'][$field]=='number') { $row[$field] = '
'.price($row[$field]).'
'; } + if($TParam['type'][$field]=='integer') { $row[$field] = '
'.((int) $row[$field]).'
'; } + } + + if(isset($TParam['link'][$field])) + { + if(empty($row[$field]) && $row[$field]!==0 && $row[$field]!=='0')$row[$field]='(vide)'; + $row[$field]= strtr( $TParam['link'][$field], array_merge( $trans, array('@val@'=>$row[$field]))) ; + } + + if(isset($TParam['translate'][$field])) + { + if(isset($TParam['translate'][$field][''])) unset($TParam['translate'][$field]['']); + + $row[$field] = strtr( $row[$field], $TParam['translate'][$field]); + } + } + } + } + else + { + $row = array(); + + foreach($currentLine as $field=>&$value) + { + if(!isset($this->THideFlip[$field])) + { + if(isset($TParam['math'][$field]) && !empty($TParam['math'][$field])) + { + $float_value = (double) strip_tags($value); + $this->TTotalTmp[$field][] = $float_value; + } + + $row[$field] = $value; + } + } + } + + if(!empty($TParam['math'][$field])) + { + foreach($row as $field=>$value) + { + if(!empty($TParam['math'][$field]) && is_array($TParam['math'][$field])) + { + $toField = $TParam['math'][$field][1]; + $float_value = (double) strip_tags($row[$toField]); + $this->TTotalTmp['@groupsum'][$toField][ $row[$field] ] += $float_value; + } + } + } + + $TField[] = $row; + } + + /** + * @param string $sql sql + * @param string $TParam TParam + * @return string + */ + private function limitSQL($sql, &$TParam) + { + if(!empty($TParam['limit']['global']) && strpos($sql,'LIMIT ')===false ) + { + $sql.=' LIMIT '.(int) $TParam['limit']['global']; + } + + return $sql; + } + + /** + * @param string $THeader THeader + * @param string $TField TField + * @param string $TParam TParam + * @param string $sql sql + */ + private function parse_sql(&$THeader, &$TField, &$TParam, $sql) + { + $this->sql = $this->limitSQL($sql, $TParam); + + $this->TTotalTmp=array(); + $this->THideFlip = array_flip($TParam['hide']); + + $res = $this->db->query($this->sql); + if($res!==false) + { + $this->totalRow = $this->db->num_rows($res); + dol_syslog(get_class($this)."::parse_sql id=".$this->id." sql=".$this->sql, LOG_DEBUG); + + while($currentLine = $this->db->fetch_object($res)) + { + $this->set_line($TField, $TParam, $currentLine); + } + } + else + { + dol_syslog(get_class($this)."::parse_sql id=".$this->id." sql=".$this->sql, LOG_ERR); + } + } +} diff --git a/htdocs/product/inventory/tpl/inventory.tpl.php b/htdocs/product/inventory/tpl/inventory.tpl.php new file mode 100644 index 00000000000..2a1c3bc3ee4 --- /dev/null +++ b/htdocs/product/inventory/tpl/inventory.tpl.php @@ -0,0 +1,205 @@ + + +status != 1) { ?> + trans('AddInventoryProduct'); ?> : +
+ + + + + + +
+ + +
+ + +
Cet inventaire est validé
+ + + + + + + $row) { + + $total_pmp+=$row['pmp_stock']; + $total_pa+=$row['pa_stock']; + $total_pmp_actual+=$row['pmp_actual']; + $total_pa_actual+=$row['pa_actual']; + + if($i%20 === 0) + { + _headerList($view); + } // Fin IF principal + ?> + + + + barcode->enabled)) { ?> + + + + + + + global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ + echo ''; + $total_current_pa+=$row['current_pa_stock']; + } + + ?> + + + + + rights->stock->changePMP)) { + echo ''; + } + ?> + + global->INVENTORY_USE_MIN_PA_IF_NO_LAST_PA)){ + echo ''; + $total_current_pa_actual+=$row['current_pa_actual']; + } + + ?> + + + + + + + +
  '.price($row['current_pa_stock']).'   + + '.$row['pmp_new'].''.price($row['current_pa_actual']).'
+ + status != 1) { ?> +
+ + + trans('Modify') ?> + rights->stock->changePMP)) { + echo ''.$langs->trans('ApplyPMP').''; + } + + if ($can_validate == 1) { ?> + trans('RegulateStock') ?> + + + + + + + trans('Flush'); ?> +     + trans('Delete') ?> + +
+ + status == 1) { ?> +
+ + + + trans('Delete') ?> + + +
+ +
+

Date de création : getDate('datec') ?> +
Dernière mise à jour : getDate('tms') ?>

+ + + diff --git a/htdocs/societe/agenda.php b/htdocs/societe/agenda.php index e1dc1c12671..32d13356654 100644 --- a/htdocs/societe/agenda.php +++ b/htdocs/societe/agenda.php @@ -83,7 +83,7 @@ if (empty($reshook)) } // Purge search criteria - if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers + if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers { $actioncode=''; $search_agenda_label=''; @@ -180,12 +180,6 @@ if ($socid > 0) print load_fiche_titre($langs->trans("ActionsOnCompany"),'',''); - // List of todo actions - //show_actions_todo($conf,$langs,$db,$object,null,0,$actioncode); - - // List of done actions - //show_actions_done($conf,$langs,$db,$object,null,0,$actioncode); - // List of all actions $filters=array(); $filters['search_agenda_label']=$search_agenda_label; diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 74aef09e7a9..0581ed1960e 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3326,18 +3326,6 @@ class Societe extends CommonObject return "Error, mode/status not found"; } - /** - * Set commnunication level - * - * @param User $user User making change - * @return int <0 if KO, >0 if OK - * @deprecated Use update function instead - */ - function set_commnucation_level($user) - { - return $this->update($this->id, $user); - } - /** * Set outstanding value * diff --git a/htdocs/societe/societecontact.php b/htdocs/societe/societecontact.php index 2bda75867dc..b5ffc87517f 100644 --- a/htdocs/societe/societecontact.php +++ b/htdocs/societe/societecontact.php @@ -107,13 +107,14 @@ else if ($action == 'deletecontact' && $user->rights->societe->creer) dol_print_error($db); } } - +/* else if ($action == 'setaddress' && $user->rights->societe->creer) { $object->fetch($id); $result=$object->setDeliveryAddress($_POST['fk_address']); if ($result < 0) dol_print_error($db,$object->error); -} +}*/ + /* * View diff --git a/htdocs/theme/eldy/img/save.png b/htdocs/theme/eldy/img/save.png new file mode 100644 index 00000000000..eca2d92eccc Binary files /dev/null and b/htdocs/theme/eldy/img/save.png differ diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 5c7f1f446ae..d0fae6d89a8 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -253,7 +253,7 @@ a.tab { font-weight: bold !important; } a:link, a:visited, a:hover, a:active { font-family: ; font-weight: normal; color: rgb(); text-decoration: none; } a:hover { text-decoration: underline; color: rgb(); } a.commonlink { color: rgb() !important; text-decoration: none; } - +th.liste_titre a div div:hover, th.liste_titre_sel a div div:hover { text-decoration: underline; } input, input.flat, textarea, textarea.flat, form.flat select, select, select.flat, .dataTables_length label select { background-color: #FFF; } @@ -1973,6 +1973,10 @@ div.tabBar { width: auto; background: rgb(); } +div.tabBar div.titre { + padding-top: 10px; +} + div.tabBarWithBottom { padding-bottom: 18px; border-bottom: 1px solid #aaa; @@ -2490,6 +2494,10 @@ div.pagination li.pagination .active { text-decoration: underline; box-shadow: none; } +.paginationafterarrows .nohover { + box-shadow: none !important; +} + div.pagination li.paginationafterarrows { margin-left: 10px; } @@ -2994,6 +3002,9 @@ td.legendLabel { padding: 2px 2px 2px 0 !important; } margin-bottom: 2px; margin-top: 10px; } +.photowithborder { + border: 1px solid #f0f0f0; +} .photointooltip { margin-top: 6px; margin-bottom: 6px; diff --git a/htdocs/theme/md/img/save.png b/htdocs/theme/md/img/save.png new file mode 100644 index 00000000000..eca2d92eccc Binary files /dev/null and b/htdocs/theme/md/img/save.png differ diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 8cc95628561..48670ffb637 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -1992,6 +1992,9 @@ div.tabBar { padding-bottom: 12px; border-bottom: 1px solid #aaa; } +div.tabBar div.titre { + padding-top: 10px; +} div.tabBarWithBottom { padding-bottom: 18px; border-bottom: 1px solid #aaa; @@ -2561,6 +2564,9 @@ div.pagination li.pagination .active { text-decoration: underline; box-shadow: none; } +.paginationafterarrows .nohover { + box-shadow: none !important; +} div.pagination li.paginationafterarrows { margin-left: 10px; } @@ -3109,10 +3115,8 @@ td.legendLabel { padding: 2px 2px 2px 0 !important; } margin-bottom: 2px; margin-top: 2px; } -.photowithmargin { -/* -webkit-box-shadow: 0px 0px 3px #777; - -moz-box-shadow: 0px 0px 3px #777; - box-shadow: 0px 0px 3px #777;*/ +.photowithborder { + border: 1px solid #f0f0f0; } .photointoolitp { margin-top: 8px; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a3006d6ebcd..f23c8aca0b6 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -376,7 +376,7 @@ class User extends CommonObject { if (! empty($obj->page) && ! empty($obj->type) && ! empty($obj->param)) { - $user->default_values[$obj->page][$obj->type][$obj->param]=$obj->value; + $this->default_values[$obj->page][$obj->type][$obj->param]=$obj->value; } } $this->db->free($resql); @@ -387,7 +387,7 @@ class User extends CommonObject return -3; } } - + return 1; } diff --git a/htdocs/user/param_ihm.php b/htdocs/user/param_ihm.php index 473c06e7368..9ffeb05f280 100644 --- a/htdocs/user/param_ihm.php +++ b/htdocs/user/param_ihm.php @@ -181,7 +181,7 @@ if ($action == 'edit') if ($action == 'edit') { - dol_fiche_head($head, 'guisetup', $title, 0, 'user'); + dol_fiche_head($head, 'guisetup', $title, -1, 'user'); $linkback = ''; diff --git a/htdocs/websites/class/website.class.php b/htdocs/websites/class/website.class.php index 51a61d90112..a77079c94a6 100644 --- a/htdocs/websites/class/website.class.php +++ b/htdocs/websites/class/website.class.php @@ -73,10 +73,6 @@ class Website extends CommonObject * @var mixed */ public $date_creation; - /** - * @var mixed - */ - public $date_modification; /** * @var mixed */ @@ -123,7 +119,6 @@ class Website extends CommonObject $error = 0; // Clean parameters - if (isset($this->entity)) { $this->entity = trim($this->entity); } @@ -136,36 +131,30 @@ class Website extends CommonObject if (isset($this->status)) { $this->status = trim($this->status); } - - + if (empty($this->date_creation)) $this->date_creation = dol_now(); // Check parameters // Put here code to add control on parameters values // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - $sql.= 'entity,'; $sql.= 'ref,'; $sql.= 'description,'; $sql.= 'status,'; $sql.= 'fk_default_home,'; $sql.= 'virtualhost,'; - $sql.= 'date_creation,'; - $sql.= 'date_modification'; - + $sql.= 'fk_user_create'; + $sql.= 'date_creation'; $sql .= ') VALUES ('; - $sql .= ' '.(! isset($this->entity)?'NULL':$this->entity).','; $sql .= ' '.(! isset($this->ref)?'NULL':"'".$this->db->escape($this->ref)."'").','; $sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").','; $sql .= ' '.(! isset($this->status)?'NULL':$this->status).','; $sql .= ' '.(! isset($this->fk_default_home)?'NULL':$this->fk_default_home).','; $sql .= ' '.(! isset($this->virtualhost)?'NULL':$this->virtualhost).','; - $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").','; - $sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_modification)."'"); - - + $sql .= ' '.(! isset($this->fk_user_create)?$user->id:$this->fk_user_create).','; + $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'"); $sql .= ')'; $this->db->begin(); @@ -223,8 +212,9 @@ class Website extends CommonObject $sql .= " t.status,"; $sql .= " t.fk_default_home,"; $sql .= " t.virtualhost,"; + $sql .= " t.fk_user_create,"; + $sql .= " t.fk_user_modif,"; $sql .= " t.date_creation,"; - $sql .= " t.date_modification,"; $sql .= " t.tms"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; if (null !== $ref) { @@ -247,11 +237,10 @@ class Website extends CommonObject $this->status = $obj->status; $this->fk_default_home = $obj->fk_default_home; $this->virtualhost = $obj->virtualhost; + $this->fk_user_create = $obj->fk_user_create; + $this->fk_user_modif = $obj->fk_user_modif; $this->date_creation = $this->db->jdate($obj->date_creation); - $this->date_modification = $this->db->jdate($obj->date_modification); $this->tms = $this->db->jdate($obj->tms); - - } $this->db->free($resql); @@ -292,8 +281,9 @@ class Website extends CommonObject $sql .= " t.status,"; $sql .= " t.fk_default_home,"; $sql .= " t.virtualhost,"; + $sql .= " t.fk_user_create,"; + $sql .= " t.fk_user_modif,"; $sql .= " t.date_creation,"; - $sql .= " t.date_modification,"; $sql .= " t.tms"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; @@ -331,8 +321,9 @@ class Website extends CommonObject $line->status = $obj->status; $line->fk_default_home = $obj->fk_default_home; $line->virtualhost = $obj->virtualhost; + $this->fk_user_create = $obj->fk_user_create; + $this->fk_user_modif = $obj->fk_user_modif; $line->date_creation = $this->db->jdate($obj->date_creation); - $line->date_modification = $this->db->jdate($obj->date_modification); $line->tms = $this->db->jdate($obj->tms); $this->records[$line->id] = $line; @@ -377,25 +368,20 @@ class Website extends CommonObject $this->status = trim($this->status); } - - // Check parameters // Put here code to add a control on parameters values // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - $sql .= ' entity = '.(isset($this->entity)?$this->entity:"null").','; $sql .= ' ref = '.(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").','; $sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").','; $sql .= ' status = '.(isset($this->status)?$this->status:"null").','; $sql .= ' fk_default_home = '.(($this->fk_default_home > 0)?$this->fk_default_home:"null").','; $sql .= ' virtualhost = '.(($this->virtualhost != '')?"'".$this->db->escape($this->virtualhost)."'":"null").','; + $sql .= ' fk_user_modif = '.(! isset($this->fk_user_modif) ? $user->id : $this->fk_user_modif).','; $sql .= ' date_creation = '.(! isset($this->date_creation) || dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').','; - $sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').','; $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'"); - - $sql .= ' WHERE rowid=' . $this->id; $this->db->begin(); @@ -631,6 +617,8 @@ class Website extends CommonObject */ public function initAsSpecimen() { + global $user; + $this->id = 0; $this->entity = 1; @@ -639,8 +627,9 @@ class Website extends CommonObject $this->status = ''; $this->fk_default_home = null; $this->virtualhost = 'http://myvirtualhost'; + $this->fk_user_create = $user->id; + $this->fk_user_modif = $user->id; $this->date_creation = dol_now(); - $this->date_modification = dol_now(); $this->tms = dol_now(); diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index 883b6495c53..c80d20fe44b 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -181,7 +181,7 @@ class WebsitePage extends CommonObject /** * Load object in memory from the database * - * @param int $id Id object + * @param int $id Id object. If this is 0, the default page of website_id will be used, if not defined, the first one. found * @param string $website_id Web site id * @param string $page Page name * @@ -205,13 +205,16 @@ class WebsitePage extends CommonObject $sql .= " t.tms as date_modification"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + //$sql .= ' WHERE entity IN ('.getEntity('website', 1).')'; // entity is on website level + $sql .= ' WHERE 1 = 1'; if (null !== $website_id) { - $sql .= ' WHERE t.fk_website = ' . '\'' . $website_id . '\''; - $sql .= ' AND t.pageurl = ' . '\'' . $page . '\''; + $sql .= " AND t.fk_website = '" . $this->db->escape($website_id) . "'"; + if ($page) $sql .= " AND t.pageurl = '" . $this->db->escape($page) . "'"; } else { - $sql .= ' WHERE t.rowid = ' . $id; + $sql .= ' AND t.rowid = ' . $id; } - + $sql .= $this->db->plimit(1); + $resql = $this->db->query($sql); if ($resql) { $numrows = $this->db->num_rows($resql); diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index b55f81f5b7f..b78a172e01f 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -438,16 +438,34 @@ if ($action == 'updatemeta') // Update page if ($action == 'updatecontent' || GETPOST('refreshsite') || GETPOST('refreshpage') || GETPOST('preview')) { - $db->begin(); $object->fetch(0, $website); + /*if (GETPOST('savevirtualhost') && $object->virtualhost != GETPOST('previewsite')) + { + $object->virtualhost = GETPOST('previewsite', 'alpha'); + $object->update($user); + }*/ + $objectpage->fk_website = $object->id; - $res = $objectpage->fetch($pageid, $object->fk_website); + if ($pageid > 0) + { + $res = $objectpage->fetch($pageid); + } + else + { + $res = $objectpage->fetch($object->fk_default_home); + if (! $res > 0) + { + $res = $objectpage->fetch(0, $object->fk_website); + } + } if ($res > 0) { if ($action == 'updatecontent') { + $db->begin(); + $objectpage->content = GETPOST('PAGE_CONTENT'); // Clean data. We remove all the head section. @@ -632,7 +650,7 @@ if (count($object->records) > 0) // List of websites print '
'; $out=''; - $out.=''; if (empty($object->records)) $out.=''; // Loop on each sites $i=0; @@ -654,9 +672,9 @@ if (count($object->records) > 0) if ($website) { - $realurl=$urlwithroot.'/public/websites/index.php?website='.$website; + $virtualurl=''; $dataroot=DOL_DATA_ROOT.'/websites/'.$website; - if (! empty($object->virtualhost)) $realurl=$object->virtualhost; + if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost; } if ($website && $action == 'preview') @@ -680,20 +698,23 @@ if (count($object->records) > 0) if ($action == 'preview') { print '
'; - print ''; + print ''; //print ''; $htmltext=$langs->trans("SetHereVirtualHost", $dataroot); print $form->textwithpicto('', $htmltext); print '
'; - $urlext=$realurl; - $urlint=DOL_URL_ROOT.'/public/websites/index.php?website='.$website; - print ''; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $urlext), 1, 'preview_ext'); - print ''; + $urlext=$virtualurl; + $urlint=$urlwithroot.'/public/websites/index.php?website='.$website; + //if (! empty($object->virtualhost)) + //{ + print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); + print ''; + //} - print ''; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $urlint), 1, 'preview'); + print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview'); print ''; } @@ -803,13 +824,22 @@ if (count($object->records) > 0) print $form->textwithpicto('', $htmltext); print '
'; - $urlext=$realurl.'/'.$pagealias.'.php'; - print ''; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $urlext), 1, 'preview_ext'); - print ''; + if (! empty($object->virtualhost)) + { + $urlext=$virtualurl.'/'.$pagealias.'.php'; + print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); + print ''; + } + else + { + print ''; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); + print ''; + } - print ''; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage), 1, 'preview'); + print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage)).'">'; + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot), 1, 'preview'); print ''; // View page in new Tab //print ''; diff --git a/scripts/emailings/mailing-send.php b/scripts/emailings/mailing-send.php index 27cc22448e6..6465e765cfe 100755 --- a/scripts/emailings/mailing-send.php +++ b/scripts/emailings/mailing-send.php @@ -41,11 +41,12 @@ if (! isset($argv[1]) || ! $argv[1]) { exit(-1); } $id=$argv[1]; -if (! isset($argv[2]) || !empty($argv[2])) $login = $argv[2]; +if (isset($argv[2]) || !empty($argv[2])) $login = $argv[2]; else $login = ''; require_once ($path."../../htdocs/master.inc.php"); require_once (DOL_DOCUMENT_ROOT."/core/class/CMailFile.class.php"); +require_once (DOL_DOCUMENT_ROOT."/comm/mailing/class/mailing.class.php"); // Global variables @@ -70,9 +71,8 @@ $user = new User($db); // for signature, we use user send as parameter if (! empty($login)) $user->fetch('',$login); -// We get list of emailing to process -$sql = "SELECT m.rowid, m.titre, m.sujet, m.body,"; -$sql.= " m.email_from, m.email_replyto, m.email_errorsto"; +// We get list of emailing id to process +$sql = "SELECT m.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."mailing as m"; $sql.= " WHERE m.statut IN (1,2)"; if ($id != 'all') @@ -96,12 +96,15 @@ if ($resql) dol_syslog("Process mailing with id ".$obj->rowid); print "Process mailing with id ".$obj->rowid."\n"; - $id = $obj->rowid; - $subject = $obj->sujet; - $message = $obj->body; - $from = $obj->email_from; - $replyto = $obj->email_replyto; - $errorsto = $obj->email_errorsto; + $emailing = new Mailing($db); + $emailing->fetch($obj->rowid); + + $id = $emailing->id; + $subject = $emailing->sujet; + $message = $emailing->body; + $from = $emailing->email_from; + $replyto = $emailing->email_replyto; + $errorsto = $emailing->email_errorsto; // Le message est-il en html $msgishtml=-1; // Unknown by default if (preg_match('/[\s\t]*/i',$message)) $msgishtml=1; @@ -232,6 +235,24 @@ if ($resql) dol_syslog("ok for emailing id ".$id." #".$i.($mail->error?' - '.$mail->error:''), LOG_DEBUG); + // Note: If emailing is 100 000 targets, 100 000 entries are added, so we don't enter events for each target here + // We must union table llx_mailing_taget for event tab OR enter 1 event with a special table link (id of email in event) + // Run trigger + /* + if ($obj2->source_type == 'contact') + { + $emailing->sendtoid = $obj2->source_id; + } + if ($obj2->source_type == 'thirdparty') + { + $emailing->socid = $obj2->source_id; + } + // Call trigger + $result=$emailing->call_trigger('EMAILING_SENTBYMAIL',$user); + if ($result < 0) $error++; + // End call triggers + */ + $sqlok ="UPDATE ".MAIN_DB_PREFIX."mailing_cibles"; $sqlok.=" SET statut=1, date_envoi='".$db->idate($now)."' WHERE rowid=".$obj2->rowid; $resqlok=$db->query($sqlok);