diff --git a/.travis.yml b/.travis.yml index bf34c86bd58..db0f3196cf8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ # from Dolibarr GitHub repository. # For syntax, see http://about.travis-ci.org/docs/user/languages/php/ +dist: precise sudo: required language: php @@ -10,23 +11,29 @@ php: - '5.3' - '5.4' - '5.5' -- '5.6' +- '5.6.29' - '7.0' - '7.1' - nightly addons: mariadb: '10.0' - # FIXME: find a way to import a MySQL dump into PostgreSQL - #postgresql: '9.3' + postgresql: '9.3' apt: + sources: + # To use the last version of pgloader, we add repo of postgresql + - postgresql + - sourceline: 'deb http://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main' + - key_url: 'https://www.postgresql.org/media/keys/ACCC4CF8.asc' packages: # We need a webserver to test the webservices # Let's install Apache with. - apache2 # mod_php is not supported by Travis. Add fcgi. We install FPM later on. - libapache2-mod-fastcgi - + # We need pgloader for import mysql database into pgsql + - pgloader + # Start on every boot services: - memcached @@ -39,8 +46,7 @@ env: # MariaDB overrides MySQL installation so it's not possible to test both yet #- DB=mysql - DB=mariadb - # FIXME: find a way to import a MySQL dump into PostgreSQL - #- DB=postgresql + - DB=postgresql # TODO #- DB=sqlite # See https://docs.travis-ci.com/user/languages/php/#Apache-%2B-PHP @@ -53,7 +59,6 @@ matrix: allow_failures: - php: 7.1 - php: nightly - # FIXME #- env: DB=postgresql # TODO #- env: DB=sqlite @@ -77,6 +82,13 @@ before_install: phpenv config-rm xdebug.ini echo +- | + if [ "$DB" = 'postgresql' ]; then + echo "Check pgloader version" + pgloader --version + echo + fi + install: - | echo "Updating Composer" @@ -132,10 +144,10 @@ before_script: echo "Set timezone" echo 'date.timezone = "Europe/Paris"' >> ~/.phpenv/versions/$PHP_VERSION_NAME/etc/php.ini if [ "$TRAVIS_PHP_VERSION" = '5.3' ] || [ "$TRAVIS_PHP_VERSION" = '5.4' ]; then - echo - echo "Enabling APC for PHP <= 5.4" + #echo + #echo "Enabling APC for PHP <= 5.4" # Documentation says it should be available for PHP <= 5.6 but it's not for 5.5 and 5.6! - echo 'extension = apc.so' >> ~/.phpenv/versions/$PHP_VERSION_NAME/etc/php.ini + #echo 'extension = apc.so' >> ~/.phpenv/versions/$PHP_VERSION_NAME/etc/php.ini echo echo "Enabling Memcached for PHP <= 5.4" # Documentation says it should be available for all PHP versions but it's not for 5.5 and 5.6, 7.0, 7.1 and nightly! @@ -164,16 +176,19 @@ before_script: - | echo "Setting up database" - if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ]; then + if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ] || [ "$DB" = 'postgresql' ]; then echo "MySQL" mysql -e 'DROP DATABASE IF EXISTS travis;' mysql -e 'CREATE DATABASE IF NOT EXISTS travis;' + mysql -e 'GRANT ALL PRIVILEGES ON travis.* TO travis@127.0.0.1;' + mysql -e 'FLUSH PRIVILEGES;' mysql -D travis < dev/initdemo/mysqldump_dolibarr_3.5.0.sql fi - # FIXME: find a way to import a MySQL dump into PostgreSQL - #if [ "$DB" = 'postgresql' ]; then - # pgsql travis < dev/initdemo/mysqldump_dolibarr_3.5.0.sql - #fi + if [ "$DB" = 'postgresql' ]; then + #pgsql travis < dev/initdemo/mysqldump_dolibarr_3.5.0.sql + #pgloader mysql://root:pass@127.0.0.1/base postgresql://dolibarrowner@127.0.0.1/dolibarr + pgloader mysql://root@127.0.0.1/travis postgresql:///travis + fi # TODO: SQLite echo @@ -190,10 +205,9 @@ before_script: if [ "$DB" = 'mysql' ] || [ "$DB" = 'mariadb' ]; then echo '$'dolibarr_main_db_type=\'mysqli\'';' >> $CONF_FILE fi - # FIXME - #if [ "$DB" = 'postgresql' ]; then - # echo '$'dolibarr_main_db_type=\'pgsql\'';' >> $CONF_FILE - #fi + if [ "$DB" = 'postgresql' ]; then + echo '$'dolibarr_main_db_type=\'pgsql\'';' >> $CONF_FILE + fi # TODO: SQLite echo '$'dolibarr_main_authentication=\'dolibarr\'';' >> $CONF_FILE cat $CONF_FILE @@ -252,8 +266,6 @@ script: set +e echo -# TODO: dev/* checks - - | echo "Checking coding style" # Ensure we catch errors @@ -267,8 +279,6 @@ script: # TODO: Check CSS (csslint?) -# TODO: check SQL syntax (pgsanity?) - - | echo "Upgrading Dolibarr" # Ensure we catch errors diff --git a/.tx/config b/.tx/config index 1839523f114..89d123b0362 100644 --- a/.tx/config +++ b/.tx/config @@ -224,13 +224,13 @@ source_file = htdocs/langs/en_US/members.lang source_lang = en_US type = MOZILLAPROPERTIES -[dolibarr.members] +[dolibarr.modulebuilder] file_filter = htdocs/langs//modulebuilder.lang source_file = htdocs/langs/en_US/modulebuilder.lang source_lang = en_US type = MOZILLAPROPERTIES -[dolibarr.members] +[dolibarr.multicurrency] file_filter = htdocs/langs//multicurrency.lang source_file = htdocs/langs/en_US/multicurrency.lang source_lang = en_US diff --git a/ChangeLog b/ChangeLog index c76617b2f8a..9cd6f11d1b8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,8 @@ English Dolibarr ChangeLog For developers: NEW: Add a lot of API REST: dictionaryevents, memberstypes, ... +NEW: Big refactorization of multicompany transverse mode. +NEW: getEntity function use true $shared value by default. WARNING: @@ -15,12 +17,64 @@ Following changes may create regression for some external modules, but were nece * The page societe/soc.php was renamed into societe/card.php to match page naming conventions. * 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. + ->delete(id, notrigger) to ->delete(User, notrigger) to match standard dev rules. +* The signature of method ->delete() of class Adherent was changed from + ->delete(id) to ->delete(id, 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. * Removed the trigger file of PAYPAL module that stored data that was not used by Dolibarr. The trigger event still exists, but if an external module need action on it, it must provides itself its trigger file. +* Use $conf->global->MULTICOMPANY_TRANSVERSE_MODE instead $conf->multicompany->transverse_mode +* Use getEntity('xxx') instead getEntity('xxx', 1) and use getEntity('xxx', 0) instead getEntity('xxx') +* The hook formObjectOptions was not implemented correctly in previous version. Sometimes, you had to return output +content by doing a print into function, sometimes by returning content into "resprint". This has been fixed to follow +hook specifications so you must return output into "resprint". + + +***** ChangeLog for 5.0.4 compared to 5.0.3 ***** +FIX: #5640 Prices of a predefined product/service were incorrect under certain circumstances +FIX: #6541 since 4.0.4 to 5.0.0 autofill zip/town not working +FIX: #6880 #6925 +FIX: #6885 +FIX: #6926 +FIX: #7003 +FIX: #7012 +FIX: #7040 +FIX: #7048 #6075 +FIX: Can set supplier invoice to billed. +FIX: Can't create invoice if PO disapproved +FIX: contratligne update +FIX: CVE-2017-7886 +FIX: default param +FIX: Line of invoices not inserted when using POS module and VAT NPR. +FIX: origin & originid on supplierproposal +FIX: Redirect to payment page from member subscription page failed if a unique security key was defined. +FIX: REST api to get project when user has permission to read all. +FIX: situation_progress param default value must be 100 and not 0 +FIX: SQL injection on user/index.php parameter search_statut. +FIX: vat code not saved during product creation. +FIX: Warnings + +***** ChangeLog for 5.0.3 compared to 5.0.2 ***** +FIX: #6677 Expired contracts dashboard box does not show the name of the thirdparty +FIX: #6813 +FIX: 6863 +FIX: #6877 +FIX: #6881 +FIX: Better sanitizing of search all parameter. +FIX: Correction with author and validator user on orders +FIX: dialog window with md theme must not be hidden by left menu part. +FIX: doactions hook missing in invoice model page +FIX: Fullname when member is a moral entity with no name. +FIX: Link to files on bank account tab broken with multicompany FIX: Link to preview on thirdparty broken with multicompany +FIX: New vat code not correctly implemented if "1 price per customer". +FIX: Pagination of invoices +FIX: pagination on resources +FIX: REST API not possible to add agendaevents +FIX: situation invoice broken due to the all percent application form inside addline form +FIX: SQL injection on user/index.php parameter search_statut. +FIX: XSS ***** ChangeLog for 5.0.2 compared to 5.0.1 ***** FIX: #6468 + Fix missing translation @@ -234,7 +288,29 @@ Dolibarr better: - Method commande->set_availability(user, availability_id) removed from commande class, use method commande->availability(availability_id, notrigger). Dolibarr 5.0 was frozen before PHP 7.1 was released. Unit tests are successful on PHP 7.1 but we don't have enough -feedback to confirm all application is compatible. Current officiel supported PHP versions are PHP 5.3 to 7.0. +feedback to confirm whole application is compatible. Current officiel supported PHP versions are PHP 5.3 to 7.0. + + +***** ChangeLog for 4.0.6 to 4.0.5 ***** +FIX: #6613 Default subject for Supplier proposal emails is filled with a non-existing key +FIX: #6623 User card shows "Return to list" link even if the user has no rights to list users +FIX: #6636 Complete fix +FIX: #6669 User with no permission to edit customer invoices can see a edit button in project entry +FIX: #6671 Cannot remove thirdparty type with "#" in its name +FIX: #6673 Missing "nature" table header in thirdparty list +FIX: #6675 Restricted user with no agenda permissions can see a button to create appointment in thirdparty contact list +FIX: #6677 Expired contracts dashboard box does not show the name of the thirdparty +FIX: #6679 User with restricted supplier invoice permissions can edit project, payment conditions, payment mode +FIX: #6680 User with restricted supplier invoice permissions sees "reopen" button even if he has no permission to do it +FIX: #6813 +FIX: Correction with author and validator user on orders +FIX: doactions hook missing in invoice model page +FIX: dont get empty "Incoterms : - " string if no incoterm +FIX: dont lose supplier ref if no supplier price in database +FIX: forgotten parameter for right multicompany use +FIX: global $dateSelector isn't the good one, then date selector on objectline_create tpl was hidden +FIX: limit+1 dosn't show Total line +FIX: supplier order line were always created with rang = 0 ***** ChangeLog for 4.0.5 to 4.0.4 ***** diff --git a/README-FR.md b/README-FR.md index 1c097e7914e..8e6a2c5aac0 100644 --- a/README-FR.md +++ b/README-FR.md @@ -98,34 +98,58 @@ Voir fichier ChangeLog. - Rapports - Imports/Exports des données - Connectivité LDAP -- De nombreuses autres fonctionnalités issues de modules officiels ou non (AWStats, Bittorrent, Gravatar, Google, Webcalendar...) +- Intégratn de ClickToDial +- Intégration RSS +- Intégation Skype +- Intégration de système de paiements (Paypal, Strip, Paybox...) - … ### Divers: -- Application multi-utilisateurs avec différents niveaux de permissions par module. +- Multi-langue. +- Multi-utilisateurs avec différents niveaux de permissions par module. +- Multi-devise. - Peux être multi-société par ajout du module externe multi-société. -- Peux-être multi-devise par ajout du module externe multi-devise. -- Plusieurs gestionnaires de menus (possibilité de différencier les menus pour les utilisateurs internes ou externes comme les clients ou fournisseurs). -- Application simple à utiliser. - Plusieurs thèmes visuels. -- Code simple et facilement personnalisable. -- Requiert PHP et MariaDb, Mysql ou Postgresql (Voir versions exactes sur http://wiki.dolibarr.org/index.php/Prérequis). +- Application simple à utiliser. +- Requiert PHP et MariaDb, Mysql ou Postgresql (Voir versions exactes sur https://wiki.dolibarr.org/index.php/Prérequis). - Compatible avec toutes les offres Cloud du marché respectant les prérequis de base de données et PHP. -- Export PDF de tous les éléments (factures, propositions commerciales, commandes, bons expéditions, etc...) +- Code simple et facilement personnalisable (pas de framework lourd; mécanisme de hook et triggers). +- APIs. +- Génération PDF et ODT des éléments (factures, propositions commerciales, commandes, bons expéditions, etc...) +- … + +### Extension + +Dolibarr peut aussi être étendu à volonté avec l'ajout de module/applications externes développées par des développeus tiers, disponible sur [DoliStore](https://www.dolistore.com). -## CE QUE DOLIBARR NE PEUT PAS FAIRE (TACHES A FAIRE) +## CE QUE DOLIBARR NE PEUT PAS (ENCORE) FAIRE Voici un liste de fonctionnalites pas encore gérées par Dolibarr: -- Pas encore de compta analytique double-partie (uniquement gestion de trésorerie). -- Dolibarr ne gère qu'une seule monnaie à la fois (mono-devise). - Dolibarr ne contient pas de module de Gestion de la paie. -- Les tâches du module de gestion de projets n'ont pas de dépendance entre elle. -- Dolibarr ne contient pas de Webmail. +- Les tâches du module de gestion de projets n'ont pas de dépendances entre elle. +- Dolibarr n'embarque pas de Webmail intégré nativement. - Dolibarr ne fait pas le café (pas encore). +## DOCUMENTATION + +Les documentations utilisateur, développeur et traducteur sont disponible sous forme de ressources de la communautés via la site [Wiki](https://wiki.dolibarr.org). + + +## CONTRIBUTING + +Voir le fichier [CONTRIBUTING](https://github.com/Dolibarr/dolibarr/blob/develop/.github/CONTRIBUTING.md) + + +## CREDITS + +Dolibarr est le résultat du travail de nombreux contributeurs depuis des années et utilise des librairies d'autres contributeurs. + +Voir le fichier [COPYRIGHT](https://github.com/Dolibarr/dolibarr/blob/develop/COPYRIGHT) + + ## ACTUALITES ET RESEAUX SOCIAUX Suivez le projet Dolibarr project sur les réseaux francophones diff --git a/README.md b/README.md index eda6b8b642e..fbbbdddf665 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,7 @@ You can use it as a standalone application or as a web application to be able to ![ScreenShot](https://www.dolibarr.org/images/dolibarr_screenshot1_640x400.png) + ## LICENSE Dolibarr is released 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 (GPL-3+). @@ -20,6 +21,7 @@ See the [COPYING](https://github.com/Dolibarr/dolibarr/blob/develop/COPYING) fil Other licenses apply for some included dependencies. See [COPYRIGHT](https://github.com/Dolibarr/dolibarr/blob/develop/COPYRIGHT) for a full list. + ## INSTALLING ### Download @@ -67,6 +69,7 @@ You can use a Web server and a supported database (MariaDb, MySql or Postgresql) - Follow the installer instructions + ## UPGRADING - Overwrite all old files from 'dolibarr' directory with files provided into the new version's package. @@ -75,13 +78,15 @@ You can use a Web server and a supported database (MariaDb, MySql or Postgresql) *Note: migration process can safely be done multiple times by calling the page /install/index.php* + ## WHAT'S NEW See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog) file. + ## FEATURES -### Main modules (all optional) +### Main application/modules (all optional) - Customers, Prospects and/or Suppliers directory - Products and/or Services catalog @@ -107,7 +112,7 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog) - Point of Sale - … -### Other modules +### Other application/modules - Bookmarks management - Donations management @@ -120,56 +125,63 @@ See the [ChangeLog](https://github.com/Dolibarr/dolibarr/blob/develop/ChangeLog) - ClickToDial integration - RSS integration - Skype integration -- Payment platforms integration (PayBox, PayPal) +- Payment platforms integration (PayPal, Stripe, Paybox...) - … ### Other general features -- Multi-Users and groups with finely grained rights -- Localization in most major languages -- Can manage several companies by adding external module multi-company. -- Can manage several currencies by adding external module multi-currency. -- Very user friendly and easy to use + +- Localization in most major languages. +- Multi-Users and groups with finely grained rights. +- Multi-currency. +- Multi-company by adding of an external module. +- Very user friendly and easy to use. - Highly customizable: enable only the modules you need, add user personalized fields, choose your skin, several menu managers (can be used by internal users as a back-office with a particular menu, or by external users as a front-office with another one) -- Works with PHP 5.3+ and MariaDB 5.0.3+, MySQL 5.0.3+ or PostgreSQL 8.1.4+ (See requirements on the [Wiki](http://wiki.dolibarr.org/index.php/Prerequisite)) +- Works with PHP 5.3+ and MariaDB 5.0.3+, MySQL 5.0.3+ or PostgreSQL 8.1.4+ (See requirements on the [Wiki](https://wiki.dolibarr.org/index.php/Prerequisite)) - Compatible with all Cloud solutions that match MySQL, PHP or PostgreSQL prerequisites. -- An easy to understand, maintain and code interfaces with your own information system (PHP with no heavy framework; trigger and hook architecture) +- APIs. +- An easy to understand, maintain and develop code (PHP with no heavy framework; trigger and hook architecture) - Support for country specific features: - Spanish Tax RE and ISPF - French NPR VAT rate (VAT called "Non Perçue Récupérable" for DOM-TOM) - Canadian double taxes (federal/province) and other countries using cumulative VAT - Tunisian tax stamp + - Argentina invoice numbering using A,B,C... - Compatible with [European directives](http://europa.eu/legislation_summaries/taxation/l31057_en.htm) (2006/112/CE ... 2010/45/UE) - PDF or ODT generation for invoice, proposals, orders... - … ### Extending -Dolibarr can be extended with a lot of other external modules from third party developers available at the [DoliStore](https://www.dolistore.com). +Dolibarr can be extended with a lot of other external application or modules from third party developers available at the [DoliStore](https://www.dolistore.com). + ## FUTURE These are features that Dolibarr does **not** yet fully support: -- Double-entry bookkeeping yet (only bank and treasury management) - Tasks dependencies in projects - Payroll module -- Webmail +- No native embedded Webmail - Dolibarr can't do coffee (yet) + ## DOCUMENTATION Administrator, user, developer and translator's documentations are available along with other community resources on the [Wiki](https://wiki.dolibarr.org). + ## CONTRIBUTING See file [CONTRIBUTING](https://github.com/Dolibarr/dolibarr/blob/develop/.github/CONTRIBUTING.md) + ## CREDITS Dolibarr is the work of many contributors over the years and uses some fine libraries. See [COPYRIGHT](https://github.com/Dolibarr/dolibarr/blob/develop/COPYRIGHT) file. + ## NEWS AND SOCIAL NETWORKS Follow Dolibarr project on: diff --git a/build/debian/README.howto b/build/debian/README.howto index c94309ec2ef..52239176c60 100644 --- a/build/debian/README.howto +++ b/build/debian/README.howto @@ -174,7 +174,7 @@ or Puis pour se connecter et préparer l'environnement > schroot -c name_of_chroot (exemple schroot -c unstable-amd64-sbuild) > cat /etc/debian_chroot to check which debian branch we are into -> apt-get install vi dialog +> apt-get install vim dialog > vi /usr/sbin/policy-rc.d and replace return code 101 (not allowed) into 0 (ok) > apt-get update > apt-get upgrade @@ -444,3 +444,4 @@ 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." +Note: If there is a response to ask more information, don't forget to remove the tag during answer. diff --git a/build/debian/source/lintian-overrides b/build/debian/source/lintian-overrides index b4c0956e90f..e64eae84887 100644 --- a/build/debian/source/lintian-overrides +++ b/build/debian/source/lintian-overrides @@ -4,7 +4,14 @@ dolibarr: source-contains-prebuilt-javascript-object htdocs/includes/jsgantt/* dolibarr: source-contains-prebuilt-javascript-object htdocs/includes/jstz/* # Those are false positives, the files are their own sources since # they are not minified -source-is-missing htdocs/includes/jsgantt/jsgantt.js * -source-is-missing htdocs/includes/jquery/plugins/colorpicker/jquery.colorpicker.js * -source-is-missing htdocs/includes/jquery/plugins/select2/select2.js * -source-is-missing htdocs/includes/jquery/plugins/select2/select2_locale_ar.js * +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/a11yhelp/dialogs/lang/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/specialchar/dialogs/lang/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/lang/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/*/dialogs/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/*/filter/*.js +source-is-missing htdocs/includes/ckeditor/ckeditor/plugins/templates/templates/default.js +source-is-missing htdocs/includes/restler/framework/Luracast/Restler/explorer/lib/*.js +# Those are false positives, the files are their own sources since +# they are data files +source-is-missing htdocs/includes/mobiledetect/mobiledetectlib/Mobile_Detect.json + diff --git a/build/exe/doliwamp/install.forced.php.install b/build/exe/doliwamp/install.forced.php.install index fd98dbf3984..5b186c17268 100644 --- a/build/exe/doliwamp/install.forced.php.install +++ b/build/exe/doliwamp/install.forced.php.install @@ -5,7 +5,7 @@ // during install process to be used. // // -$force_install_noedit=2; +$force_install_noedit=2; // 1=To block vars specific to distrib, 2 to block all technical parameters $force_install_message='KeepDefaultValuesWamp'; $force_install_main_data_root='WAMPROOT/dolibarr_documents'; $force_install_type='mysqli'; diff --git a/build/generate_filelist_xml.php b/build/generate_filelist_xml.php index c1a56beacd7..94df2206579 100755 --- a/build/generate_filelist_xml.php +++ b/build/generate_filelist_xml.php @@ -43,7 +43,7 @@ require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); $includecustom=0; $includeconstants=array(); -if (empty($argv[1])) +if (empty($argv[1])) { print "Usage: ".$script_file." release=x.y.z[-...] [includecustom=1] [includeconstant=CC:MY_CONF_NAME:value]\n"; print "Example: ".$script_file." release=6.0.0 includecustom=1 includeconstant=FR:INVOICE_CAN_ALWAYS_BE_REMOVED:0 includeconstant=all:MAILING_NO_USING_PHPMAIL:1\n"; @@ -56,7 +56,7 @@ while ($i < $argc) if (preg_match('/includeconstant=/',$argv[$i])) { $tmp=explode(':', $includeconstant, 3); - if (count($tmp) != 3) + if (count($tmp) != 3) { print "Error: Bad parameter includeconstant ".$includeconstant."\n"; exit -1; @@ -85,9 +85,9 @@ else } } -print "Release : ".$release."\n"; -print "Include custom : ".$includecustom."\n"; -print "Include constants: "; +print "Release : ".$release."\n"; +print "Include custom in signature : ".$includecustom."\n"; +print "Include constants in signature : "; foreach ($includeconstants as $countrycode => $tmp) { foreach($tmp as $constname => $constvalue) diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index ff9e0878750..c2d983653cb 100755 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -14,7 +14,7 @@ #---------------------------------------------------------------------------- use Cwd; - +use Term::ANSIColor; # Change this to defined target for option 98 and 99 $PROJECT="dolibarr"; @@ -313,20 +313,6 @@ foreach my $target (sort keys %CHOOSEDTARGET) { print "\n"; -# Build xml check file -#----------------------- -if ($CHOOSEDTARGET{'-CHKSUM'}) -{ - print 'Create xml check file with md5 checksum with command php '.$SOURCE.'/build/generate_filecheck_xml.php release='.$MAJOR.'.'.$MINOR.'.'.$BUILD."\n"; - $ret=`php $SOURCE/build/generate_filelist_xml.php release=$MAJOR.$MINOR.$BUILD`; - print $ret."\n"; - # Copy to final dir - $NEWDESTI=$DESTI; - print "Copy \"$SOURCE/htdocs/install/filelist-$MAJOR.$MINOR.$BUILD.xml\" to $NEWDESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml\n"; - use File::Copy qw(copy); - copy "$SOURCE/htdocs/install/filelist-$MAJOR.$MINOR.$BUILD.xml", "$NEWDESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml"; -} - #print join(',',sort keys %CHOOSEDTARGET)."\n"; @@ -335,7 +321,10 @@ if ($CHOOSEDTARGET{'-CHKSUM'}) $nboftargetok=0; $nboftargetneedbuildroot=0; $nbofpublishneedtag=0; +$nbofpublishneedchangelog=0; + foreach my $target (sort keys %CHOOSEDTARGET) { + if ($target eq '-CHKSUM') { $nbofpublishneedchangelog++; } if ($CHOOSEDTARGET{$target} < 0) { next; } if ($target ne 'EXE' && $target ne 'EXEDOLIWAMP' && $target ne '-CHKSUM') { @@ -345,34 +334,31 @@ foreach my $target (sort keys %CHOOSEDTARGET) { } foreach my $target (sort keys %CHOOSEDPUBLISH) { if ($CHOOSEDPUBLISH{$target} < 0) { next; } - if ($target eq 'ASSO') { $nbofpublishneedtag++; } - if ($target eq 'SF') { $nbofpublishneedtag++; } + if ($target eq 'ASSO') { $nbofpublishneedchangelog++; $nbofpublishneedtag++; } + if ($target eq 'SF') { $nbofpublishneedchangelog++; $nbofpublishneedtag++; } $nboftargetok++; } + if ($nboftargetok) { - # Update GIT tag if required - #--------------------------- - if ($nbofpublishneedtag) + # Check Changelog + #---------------- + if ($nbofpublishneedchangelog) { - print "Go to directory $SOURCE\n"; - $olddir=getcwd(); - chdir("$SOURCE"); - # Test that the ChangeLog is ok $TMPBUILDTOCHECKCHANGELOG=$BUILD; $TMPBUILDTOCHECKCHANGELOG =~ s/\-rc\d*//; $TMPBUILDTOCHECKCHANGELOG =~ s/\-beta\d*//; - print "Check if ChangeLog is ok for version $MAJOR.$MINOR\.$TMPBUILDTOCHECKCHANGELOG\n"; + print "\nCheck if ChangeLog is ok for version $MAJOR.$MINOR\.$TMPBUILDTOCHECKCHANGELOG\n"; $ret=`grep "ChangeLog for $MAJOR.$MINOR\.$TMPBUILDTOCHECKCHANGELOG" "$SOURCE/ChangeLog" 2>&1`; if (! $ret) { - print "Error: The ChangeLogFile was not updated. Run the following command before building package for $MAJOR.$MINOR.$BUILD:\n"; + print color("yellow"), "Error: The ChangeLogFile was not updated. Run the following command before building package for $MAJOR.$MINOR.$BUILD:\n", color('reset'); } else { - print "ChangeLog for $MAJOR.$MINOR\.$BUILD was found into '$SOURCE/ChangeLog. But you can regenerate it with commande:'\n"; + print "ChangeLog for $MAJOR.$MINOR\.$BUILD was found into '$SOURCE/ChangeLog. But you can regenerate it with command:'\n"; } if (! $BUILD || $BUILD eq '0-rc') # For a major version { @@ -385,9 +371,39 @@ if ($nboftargetok) { print "\n"; if (! $ret) { - exit; + print "\nPress F to force and continue anyway (or other key to stop)... "; + my $WAITKEY=; + chomp($WAITKEY); + if ($WAITKEY ne 'F') + { + print "Canceled.\n"; + exit; + } } - + } + + # Build xml check file + #----------------------- + if ($CHOOSEDTARGET{'-CHKSUM'}) + { + print 'Create xml check file with md5 checksum with command php '.$SOURCE.'/build/generate_filecheck_xml.php release='.$MAJOR.'.'.$MINOR.'.'.$BUILD."\n"; + $ret=`php $SOURCE/build/generate_filelist_xml.php release=$MAJOR.$MINOR.$BUILD`; + print $ret."\n"; + # Copy to final dir + $NEWDESTI=$DESTI; + print "Copy \"$SOURCE/htdocs/install/filelist-$MAJOR.$MINOR.$BUILD.xml\" to $NEWDESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml\n"; + use File::Copy qw(copy); + copy "$SOURCE/htdocs/install/filelist-$MAJOR.$MINOR.$BUILD.xml", "$NEWDESTI/signatures/filelist-$MAJOR.$MINOR.$BUILD.xml"; + } + + # Update GIT tag if required + #--------------------------- + if ($nbofpublishneedtag) + { + print "Go to directory $SOURCE\n"; + $olddir=getcwd(); + chdir("$SOURCE"); + print 'Run git tag -a -m "'.$MAJOR.'.'.$MINOR.'.'.$BUILD.'" "'.$MAJOR.'.'.$MINOR.'.'.$BUILD.'"'."\n"; $ret=`git tag -a -m "$MAJOR.$MINOR.$BUILD" "$MAJOR.$MINOR.$BUILD" 2>&1`; if ($ret =~ /(already exists|existe déjà)/) @@ -517,6 +533,7 @@ if ($nboftargetok) { $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/dolimed*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/dolimod*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/factory*`; + $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/forceproject*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/lead*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/management*`; $ret=`rm -fr $BUILDROOT/$PROJECT/htdocs/multicompany*`; @@ -574,7 +591,7 @@ if ($nboftargetok) { print "Remove subdir of custom dir\n"; print "find $BUILDROOT/$PROJECT/htdocs/custom/* -type d -exec rm -fr {} \\;\n"; - $ret=`find $BUILDROOT/$PROJECT/htdocs/custom/* -type d -exec rm -fr {} \\; >/dev/null 2>&1`; # For custom we want to keep dir + $ret=`find $BUILDROOT/$PROJECT/htdocs/custom/* -type d -exec rm -fr {} \\; >/dev/null 2>&1`; # For custom we want to remove all subdirs but not files } # Build package for each target @@ -955,13 +972,12 @@ if ($nboftargetok) { $ret=`$cmd`; $ret=`chmod 755 $BUILDROOT/$PROJECT.tmp/debian/rules`; $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/dev/translation/autotranslator.class.php`; - $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/dev/skeletons/modMyModule.class.php`; - $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/dev/skeletons/skeleton_api_class.class.php`; - $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/dev/skeletons/skeleton_card.php`; - $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/dev/skeletons/skeleton_class.class.php`; - $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/dev/skeletons/skeleton_list.php`; - $ret=`chmod -R 755 $BUILDROOT/$PROJECT.tmp/dev/skeletons/skeleton_script.php`; - $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/dev/skeletons/skeleton_webservice_server.php`; + $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/htdocs/modulebuilder/template/class/myobject.class.php`; + $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/htdocs/modulebuilder/template/class/myobject_api_class.class.php`; + $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/htdocs/modulebuilder/template/core/modules/modMyModule.class.php`; + $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/htdocs/modulebuilder/template/myobject_card.php`; + $ret=`chmod -R 644 $BUILDROOT/$PROJECT.tmp/htdocs/modulebuilder/template/myobject_list.php`; + $ret=`chmod -R 755 $BUILDROOT/$PROJECT.tmp/htdocs/modulebuilder/template/scripts/myobject.php`; $cmd="find $BUILDROOT/$PROJECT.tmp/scripts -name '*.php' -type f -exec chmod 755 {} \\; "; $ret=`$cmd`; $cmd="find $BUILDROOT/$PROJECT.tmp/scripts -name '*.sh' -type f -exec chmod 755 {} \\; "; diff --git a/build/rpm/dolibarr_fedora.spec b/build/rpm/dolibarr_fedora.spec index a0f981b8c11..33dc951309d 100755 --- a/build/rpm/dolibarr_fedora.spec +++ b/build/rpm/dolibarr_fedora.spec @@ -194,6 +194,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/loan %_datadir/dolibarr/htdocs/mailmanspip %_datadir/dolibarr/htdocs/margin +%_datadir/dolibarr/htdocs/modulebuilder %_datadir/dolibarr/htdocs/multicurrency %_datadir/dolibarr/htdocs/opensurvey %_datadir/dolibarr/htdocs/paybox @@ -209,6 +210,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/support %_datadir/dolibarr/htdocs/theme %_datadir/dolibarr/htdocs/user +%_datadir/dolibarr/htdocs/variants %_datadir/dolibarr/htdocs/webservices %_datadir/dolibarr/htdocs/websites %_datadir/dolibarr/htdocs/*.ico diff --git a/build/rpm/dolibarr_generic.spec b/build/rpm/dolibarr_generic.spec index 446e0e0d5f7..42a89675abf 100755 --- a/build/rpm/dolibarr_generic.spec +++ b/build/rpm/dolibarr_generic.spec @@ -274,6 +274,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/loan %_datadir/dolibarr/htdocs/mailmanspip %_datadir/dolibarr/htdocs/margin +%_datadir/dolibarr/htdocs/modulebuilder %_datadir/dolibarr/htdocs/multicurrency %_datadir/dolibarr/htdocs/opensurvey %_datadir/dolibarr/htdocs/paybox @@ -289,6 +290,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/support %_datadir/dolibarr/htdocs/theme %_datadir/dolibarr/htdocs/user +%_datadir/dolibarr/htdocs/variants %_datadir/dolibarr/htdocs/webservices %_datadir/dolibarr/htdocs/websites %_datadir/dolibarr/htdocs/*.ico diff --git a/build/rpm/dolibarr_mandriva.spec b/build/rpm/dolibarr_mandriva.spec index 1fb1b7fcc75..9dd2100b02c 100755 --- a/build/rpm/dolibarr_mandriva.spec +++ b/build/rpm/dolibarr_mandriva.spec @@ -190,6 +190,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/loan %_datadir/dolibarr/htdocs/mailmanspip %_datadir/dolibarr/htdocs/margin +%_datadir/dolibarr/htdocs/modulebuilder %_datadir/dolibarr/htdocs/multicurrency %_datadir/dolibarr/htdocs/opensurvey %_datadir/dolibarr/htdocs/paybox @@ -205,6 +206,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/support %_datadir/dolibarr/htdocs/theme %_datadir/dolibarr/htdocs/user +%_datadir/dolibarr/htdocs/variants %_datadir/dolibarr/htdocs/webservices %_datadir/dolibarr/htdocs/websites %_datadir/dolibarr/htdocs/*.ico diff --git a/build/rpm/dolibarr_opensuse.spec b/build/rpm/dolibarr_opensuse.spec index 1bb7ef061e6..d780c47da99 100755 --- a/build/rpm/dolibarr_opensuse.spec +++ b/build/rpm/dolibarr_opensuse.spec @@ -202,6 +202,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/loan %_datadir/dolibarr/htdocs/mailmanspip %_datadir/dolibarr/htdocs/margin +%_datadir/dolibarr/htdocs/modulebuilder %_datadir/dolibarr/htdocs/multicurrency %_datadir/dolibarr/htdocs/opensurvey %_datadir/dolibarr/htdocs/paybox @@ -217,6 +218,7 @@ done >>%{name}.lang %_datadir/dolibarr/htdocs/support %_datadir/dolibarr/htdocs/theme %_datadir/dolibarr/htdocs/user +%_datadir/dolibarr/htdocs/variants %_datadir/dolibarr/htdocs/webservices %_datadir/dolibarr/htdocs/websites %_datadir/dolibarr/htdocs/*.ico diff --git a/build/rpm/install.forced.php.fedora b/build/rpm/install.forced.php.fedora index 108455a9403..a8db3e25c9e 100644 --- a/build/rpm/install.forced.php.fedora +++ b/build/rpm/install.forced.php.fedora @@ -1,7 +1,7 @@ societe_id > 0) accessforbidden(); if (! $user->rights->accounting->chartofaccount) accessforbidden(); // Load variable for pagination -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield", 'alpha'); $sortorder = GETPOST("sortorder", 'sortorder'); $page = GETPOST("page", 'int'); diff --git a/htdocs/accountancy/admin/accountmodel.php b/htdocs/accountancy/admin/accountmodel.php index e63e44b4f80..94e16738bf4 100644 --- a/htdocs/accountancy/admin/accountmodel.php +++ b/htdocs/accountancy/admin/accountmodel.php @@ -8,7 +8,7 @@ * Copyright (C) 2011 Remy Younes * Copyright (C) 2012-2015 Marcos García * Copyright (C) 2012 Christophe Battarel - * Copyright (C) 2011-2016 Alexandre Spangaro + * Copyright (C) 2011-2016 Alexandre Spangaro * Copyright (C) 2015 Ferran Marcet * Copyright (C) 2016 Raphaël Doursenaud * @@ -54,6 +54,7 @@ $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view'; $confirm=GETPOST('confirm','alpha'); $id=GETPOST('id','int'); $rowid=GETPOST('rowid','alpha'); +$code=GETPOST('code','alpha'); $acts[0] = "activate"; $acts[1] = "disable"; @@ -67,7 +68,7 @@ $active = 1; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0 ; } +if ($page == -1 || $page == null) { $page = 0 ; } $offset = $listlimit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; @@ -80,7 +81,7 @@ if ($user->societe_id > 0) accessforbidden(); if (! $user->rights->accounting->chartofaccount) accessforbidden(); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('admin')); // This page is a generic page to edit dictionaries @@ -225,7 +226,7 @@ if ($id == 25) if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x')) { - $search_country_id = ''; + $search_country_id = ''; } // Actions add or modify an entry into a dictionary @@ -459,8 +460,8 @@ if ($action == $acts[0]) if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -479,8 +480,8 @@ if ($action == $acts[1]) if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -499,8 +500,8 @@ if ($action == 'activate_favorite') if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -519,8 +520,8 @@ if ($action == 'disable_favorite') if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -556,7 +557,7 @@ print "
\n"; // Confirmation de la suppression de la ligne if ($action == 'delete') { - print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$_GET["code"].'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1); + print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1); } //var_dump($elementList); @@ -574,7 +575,7 @@ if ($id) else $sql.=" WHERE "; $sql.= " c.rowid = ".$search_country_id; } - + if ($sortfield) { // If sort order is "country", we use country_code instead @@ -600,7 +601,7 @@ if ($id) print '
'; print ''; - + print ''; // Form to add a new line @@ -773,7 +774,7 @@ if ($id) $paramwithsearch = $param; if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder; if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield; - + // There is several pages if ($num > $listlimit) { @@ -865,9 +866,9 @@ if ($id) foreach ($fieldlist as $field => $value) { $showfield=1; // By defaut - + if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; } - + if ($showfield) { if ($value == 'country') @@ -889,7 +890,7 @@ if ($id) print $searchpicto; print ''; print ''; - + if ($num) { // Lines with values @@ -927,7 +928,7 @@ if ($id) { foreach ($fieldlist as $field => $value) { - + $showfield=1; $align="left"; $valuetoshow=$obj->{$fieldlist[$field]}; @@ -1147,7 +1148,6 @@ else * Show list of dictionary to show */ - $var=true; $lastlineisempty=false; print '
'; print ''; @@ -1169,7 +1169,7 @@ else $showemptyline=0; } - + $value=$tabname[$i]; print ''; - + if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO) && ($key == 'ACCOUNTING_LENGTH_GACCOUNT' || $key == 'ACCOUNTING_LENGTH_AACCOUNT')) continue; // Param @@ -279,7 +280,7 @@ foreach ($list as $key) print ''; - + print ''; } diff --git a/htdocs/accountancy/admin/journals_list.php b/htdocs/accountancy/admin/journals_list.php index 1421d71be97..dca29fd28b8 100644 --- a/htdocs/accountancy/admin/journals_list.php +++ b/htdocs/accountancy/admin/journals_list.php @@ -38,6 +38,7 @@ $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view'; $confirm=GETPOST('confirm','alpha'); $id=GETPOST('id','int'); $rowid=GETPOST('rowid','alpha'); +$code=GETPOST('code','alpha'); // Security access if (! empty($user->rights->accountancy->chartofaccount)) @@ -57,7 +58,7 @@ $active = 1; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0 ; } +if ($page == -1 || $page == null) { $page = 0 ; } $offset = $listlimit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; @@ -66,7 +67,7 @@ if (empty($sortorder)) $sortorder='ASC'; $error = 0; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('admin')); // This page is a generic page to edit dictionaries @@ -127,7 +128,7 @@ complete_dictionary_with_modules($taborder,$tabname,$tablib,$tabsql,$tabsqlsort, // Define elementList and sourceList (used for dictionary type of contacts "llx_c_type_contact") $elementList = array(); - // Must match ids defined into eldy.lib.php + // Must match ids defined into eldy.lib.php $sourceList = array( '1' => $langs->trans('AccountingJournalType1'), '2' => $langs->trans('AccountingJournalType2'), @@ -142,7 +143,7 @@ $elementList = array(); if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x')) { - $search_country_id = ''; + $search_country_id = ''; } // Actions add or modify an entry into a dictionary @@ -321,8 +322,8 @@ if ($action == $acts[0]) if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -341,8 +342,8 @@ if ($action == $acts[1]) if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -371,18 +372,11 @@ if ($id) print load_fiche_titre($titre,$linkback,$titlepicto); -if (empty($id)) -{ - print $langs->trans("DictionaryDesc"); - print " ".$langs->trans("OnlyActiveElementsAreShown")."
\n"; -} -print "
\n"; - // Confirmation de la suppression de la ligne if ($action == 'delete') { - print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$_GET["code"].'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1); + print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1); } //var_dump($elementList); @@ -400,7 +394,7 @@ if ($id) else $sql.=" WHERE "; $sql.= " c.rowid = ".$search_country_id; } - + if ($sortfield) { // If sort order is "country", we use country_code instead @@ -427,7 +421,7 @@ if ($id) print ''; print ''; print ''; - + print '
'; if (! empty($tabcond[$i])) diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 73e3fdf6dd9..fa3adf1301b 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2013-2017 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/accountancy/admin/categories_list.php b/htdocs/accountancy/admin/categories_list.php index e78737c3fb9..cb852d82e0c 100644 --- a/htdocs/accountancy/admin/categories_list.php +++ b/htdocs/accountancy/admin/categories_list.php @@ -8,7 +8,7 @@ * Copyright (C) 2011 Remy Younes * Copyright (C) 2012-2015 Marcos García * Copyright (C) 2012 Christophe Battarel - * Copyright (C) 2011-2016 Alexandre Spangaro + * Copyright (C) 2011-2016 Alexandre Spangaro * Copyright (C) 2015 Ferran Marcet * Copyright (C) 2016 Raphaël Doursenaud * @@ -54,6 +54,7 @@ $action=GETPOST('action','alpha')?GETPOST('action','alpha'):'view'; $confirm=GETPOST('confirm','alpha'); $id=GETPOST('id','int'); $rowid=GETPOST('rowid','alpha'); +$code=GETPOST('code','alpha'); // Security access if (! empty($user->rights->accountancy->chartofaccount)) @@ -73,14 +74,14 @@ $active = 1; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0 ; } +if ($page == -1 || $page == null) { $page = 0 ; } $offset = $listlimit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; $search_country_id = GETPOST('search_country_id','int'); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('admin')); // This page is a generic page to edit dictionaries @@ -151,7 +152,7 @@ $sourceList=array(); if (GETPOST('button_removefilter') || GETPOST('button_removefilter.x') || GETPOST('button_removefilter_x')) { - $search_country_id = ''; + $search_country_id = ''; } // Actions add or modify an entry into a dictionary @@ -370,8 +371,8 @@ if ($action == $acts[0]) if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET active = 1 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -390,8 +391,8 @@ if ($action == $acts[1]) if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET active = 0 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -410,8 +411,8 @@ if ($action == 'activate_favorite') if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET favorite = 1 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -430,8 +431,8 @@ if ($action == 'disable_favorite') if ($rowid) { $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE ".$rowidcol."='".$rowid."'"; } - elseif ($_GET["code"]) { - $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$_GET["code"]."'"; + elseif ($code) { + $sql = "UPDATE ".$tabname[$id]." SET favorite = 0 WHERE code='".$code."'"; } $result = $db->query($sql); @@ -461,7 +462,7 @@ print load_fiche_titre($titre,$linkback,$titlepicto); // Confirmation de la suppression de la ligne if ($action == 'delete') { - print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$_GET["code"].'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1); + print $form->formconfirm($_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.$rowid.'&code='.$code.'&id='.$id, $langs->trans('DeleteLine'), $langs->trans('ConfirmDeleteLine'), 'confirm_delete','',0,1); } //var_dump($elementList); @@ -479,7 +480,7 @@ if ($id) else $sql.=" WHERE "; $sql.= " c.rowid = ".$search_country_id; } - + if ($sortfield) { // If sort order is "country", we use country_code instead @@ -506,7 +507,7 @@ if ($id) print ''; print ''; print ''; - + print ''; // Form to add a new line @@ -546,9 +547,9 @@ if ($id) if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); } if ($fieldlist[$field]=='pcg_version' || $fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); } if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); } - if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); } + if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Direction"); } if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); } - + if ($valuetoshow != '') { print ''; print ''; - + // Title of lines print ''; foreach ($fieldlist as $field => $value) @@ -700,7 +701,7 @@ if ($id) if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); } if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); } if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); } - if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); } + if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Direction"); } if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); } // Affiche nom du champ if ($showfield) @@ -754,7 +755,7 @@ if ($id) { foreach ($fieldlist as $field => $value) { - + $showfield=1; $align="left"; $valuetoshow=$obj->{$fieldlist[$field]}; diff --git a/htdocs/accountancy/admin/defaultaccounts.php b/htdocs/accountancy/admin/defaultaccounts.php index aaf98a0fa8b..9cf4d2977fd 100644 --- a/htdocs/accountancy/admin/defaultaccounts.php +++ b/htdocs/accountancy/admin/defaultaccounts.php @@ -1,11 +1,11 @@ - * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2013-2016 Alexandre Spangaro - * Copyright (C) 2014-2015 Ari Elbaz (elarifr) +/* Copyright (C) 2013-2014 Olivier Geffroy + * Copyright (C) 2013-2014 Florian Henry + * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2014-2015 Ari Elbaz (elarifr) * Copyright (C) 2014 Marcos García - * Copyright (C) 2014 Juanjo Menent - * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2015 Jean-François Ferry * * 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 @@ -23,7 +23,7 @@ */ /** - * \file htdocs/accountancy/admin/index.php + * \file htdocs/accountancy/admin/defaultaccounts.php * \ingroup Advanced accountancy * \brief Setup page to configure accounting expert module */ @@ -50,23 +50,26 @@ if (! empty($user->rights->accountancy->chartofaccount)) $action = GETPOST('action', 'alpha'); +$list_account_main = array ( + 'ACCOUNTING_ACCOUNT_CUSTOMER', + 'ACCOUNTING_ACCOUNT_SUPPLIER', + 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', +); + $list_account = array ( - 'ACCOUNTING_ACCOUNT_SUPPLIER', - 'ACCOUNTING_ACCOUNT_CUSTOMER', - 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', - 'ACCOUNTING_PRODUCT_BUY_ACCOUNT', - 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', - 'ACCOUNTING_SERVICE_BUY_ACCOUNT', - 'ACCOUNTING_SERVICE_SOLD_ACCOUNT', - 'ACCOUNTING_VAT_BUY_ACCOUNT', - 'ACCOUNTING_VAT_SOLD_ACCOUNT', - 'ACCOUNTING_VAT_PAY_ACCOUNT', - 'ACCOUNTING_ACCOUNT_SUSPENSE', - 'ACCOUNTING_ACCOUNT_TRANSFER_CASH', - 'DONATION_ACCOUNTINGACCOUNT', - 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL', - 'LOAN_ACCOUNTING_ACCOUNT_INTEREST', - 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE' + 'ACCOUNTING_PRODUCT_BUY_ACCOUNT', + 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', + 'ACCOUNTING_SERVICE_BUY_ACCOUNT', + 'ACCOUNTING_SERVICE_SOLD_ACCOUNT', + 'ACCOUNTING_VAT_BUY_ACCOUNT', + 'ACCOUNTING_VAT_SOLD_ACCOUNT', + 'ACCOUNTING_VAT_PAY_ACCOUNT', + 'ACCOUNTING_ACCOUNT_SUSPENSE', + 'ACCOUNTING_ACCOUNT_TRANSFER_CASH', + 'DONATION_ACCOUNTINGACCOUNT', + 'LOAN_ACCOUNTING_ACCOUNT_CAPITAL', + 'LOAN_ACCOUNTING_ACCOUNT_INTEREST', + 'LOAN_ACCOUNTING_ACCOUNT_INSURANCE' ); @@ -93,15 +96,23 @@ if (GETPOST('change_chart')) if ($action == 'update') { $error = 0; - - foreach ( $list_account as $constname ) { + + foreach ( $list_account_main as $constname ) { $constvalue = GETPOST($constname, 'alpha'); - + if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { $error ++; } } - + + foreach ( $list_account as $constname ) { + $constvalue = GETPOST($constname, 'alpha'); + + if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { + $error ++; + } + } + if (! $error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { @@ -114,11 +125,11 @@ if ($action == 'update') { * View */ -llxHeader(); - $form = new Form($db); $formaccounting = new FormAccounting($db); +llxHeader(); + $linkback = ''; print load_fiche_titre($langs->trans('MenuDefaultAccounts'), $linkback, 'title_accountancy'); @@ -129,18 +140,47 @@ print ''; print ''; print ''; -// Define Chart of accounts + +// Define main accounts for thirdparty print '
'; @@ -617,7 +618,7 @@ if ($id) if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder; if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield; if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha'); - + // There is several pages if ($num > $listlimit) { @@ -632,9 +633,9 @@ if ($id) foreach ($fieldlist as $field => $value) { $showfield=1; // By defaut - + if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; } - + if ($showfield) { if ($value == 'country') @@ -661,7 +662,7 @@ if ($id) } print '
'; -foreach ( $list_account as $key ) { - +foreach ($list_account_main as $key) { + + print ''; + // Param + $label = $langs->trans($key); + $keydesc=$key.'_Desc'; + + $htmltext = $langs->trans($keydesc); + print ''; + // Value + print ''; + print ''; +} + + +print "
'; + print $form->textwithpicto($label, $htmltext); + print ''; // Do not force align=right, or it align also the content of the select box + print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1); + print '
\n"; + + +print '
'; + +// Define default accounts + +print ''; + +foreach ($list_account as $key) { + print ''; // Param $label = $langs->trans($key); - print ''; + print ''; // Value - print ''; print ''; diff --git a/htdocs/accountancy/admin/export.php b/htdocs/accountancy/admin/export.php index eaf69f34f1f..7a209be45b1 100644 --- a/htdocs/accountancy/admin/export.php +++ b/htdocs/accountancy/admin/export.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2015 Alexandre Spangaro + * Copyright (C) 2013-2015 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * Copyright (C) 2014 Marcos García * Copyright (C) 2014 Juanjo Menent @@ -47,7 +47,7 @@ $action = GETPOST('action', 'alpha'); // Parameters ACCOUNTING_EXPORT_* $main_option = array ( - 'ACCOUNTING_EXPORT_PREFIX_SPEC' + 'ACCOUNTING_EXPORT_PREFIX_SPEC' ); $model_option = array ( @@ -67,10 +67,10 @@ $model_option = array ( */ if ($action == 'update') { $error = 0; - + $format = GETPOST('format', 'alpha'); $modelcsv = GETPOST('modelcsv', 'int'); - + if (! empty($format)) { if (! dolibarr_set_const($db, 'ACCOUNTING_EXPORT_FORMAT', $format, 'chaine', 0, '', $conf->entity)) { $error ++; @@ -78,7 +78,7 @@ if ($action == 'update') { } else { $error ++; } - + if (! empty($modelcsv)) { if (! dolibarr_set_const($db, 'ACCOUNTING_EXPORT_MODELCSV', $modelcsv, 'chaine', 0, '', $conf->entity)) { $error ++; @@ -89,23 +89,23 @@ if ($action == 'update') { } else { $error ++; } - + foreach ( $main_option as $constname ) { $constvalue = GETPOST($constname, 'alpha'); - + if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { $error ++; } } - + foreach ( $model_option as $constname ) { $constvalue = GETPOST($constname, 'alpha'); - + if (! dolibarr_set_const($db, $constname, $constvalue, 'chaine', 0, '', $conf->entity)) { $error ++; } } - + if (! $error) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } else { @@ -148,13 +148,13 @@ $var = ! $var; $num = count($main_option); if ($num) { foreach ( $main_option as $key ) { - + print ''; - + // Param $label = $langs->trans($key); print ''; - + // Value print ''; } print ""; @@ -205,12 +205,12 @@ if ($num2) { print ''; print ''; print "\n"; - - if ($conf->global->ACCOUNTING_EXPORT_MODELCSV > 1) + + if ($conf->global->ACCOUNTING_EXPORT_MODELCSV > AccountancyExport::$EXPORT_TYPE_NORMAL) { print ''; } - + print ''; print ''; if (! $conf->use_javascript_ajax) { @@ -224,24 +224,24 @@ if ($num2) { 'txt' => $langs->trans("txt") ); print $form->selectarray("format", $listformat, $conf->global->ACCOUNTING_EXPORT_FORMAT, 0); - + print ''; } print ""; - - foreach ( $model_option as $key ) { + + foreach ( $model_option as $key ) { print ''; - + // Param $label = $langs->trans($key); print ''; - + // Value print ''; } - + print "
' . $label . '' . $label . ''; // Do not force align=right, or it align also the content of the select box + print ''; // Do not force align=right, or it align also the content of the select box print $formaccounting->select_account($conf->global->$key, $key, 1, '', 1, 1); print '
' . $label . ''; print ''; @@ -187,7 +187,7 @@ if (! $conf->use_javascript_ajax) { print ''; $listmodelcsv = AccountancyExport::getType(); print $form->selectarray("modelcsv", $listmodelcsv, $conf->global->ACCOUNTING_EXPORT_MODELCSV, 0); - + print '
' . $langs->trans('OtherOptions') . '
' . $langs->trans('OptionsDeactivatedForThisExportModel') . '
' . $langs->trans("Selectformat") . '
' . $label . ''; print ''; print '
\n"; } diff --git a/htdocs/accountancy/admin/fiscalyear.php b/htdocs/accountancy/admin/fiscalyear.php index 16e11225d49..bf26348b50a 100644 --- a/htdocs/accountancy/admin/fiscalyear.php +++ b/htdocs/accountancy/admin/fiscalyear.php @@ -28,11 +28,11 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/fiscalyear.class.php'; $action = GETPOST('action','aZ09'); // Load variable for pagination -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/accountancy/admin/fiscalyear_info.php b/htdocs/accountancy/admin/fiscalyear_info.php index 3596d73d751..baadbdc0828 100644 --- a/htdocs/accountancy/admin/fiscalyear_info.php +++ b/htdocs/accountancy/admin/fiscalyear_info.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2014-2016 Alexandre Spangaro * * 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 diff --git a/htdocs/accountancy/admin/importaccounts.php b/htdocs/accountancy/admin/importaccounts.php index 1bb1bf178b3..93d41b3cbc6 100644 --- a/htdocs/accountancy/admin/importaccounts.php +++ b/htdocs/accountancy/admin/importaccounts.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2013-2017 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * * This program is free software; you can redistribute it and/or modify @@ -39,11 +39,11 @@ $langs->load("accountancy"); if (! $user->admin) accessforbidden(); -$limit = GETPOST("limit")?GETPOST("limit","int"):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$limit = GETPOST('limit','int')?GETPOST('limit','int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/accountancy/admin/index.php b/htdocs/accountancy/admin/index.php index 0e1f67a0e61..ead997a5d8c 100644 --- a/htdocs/accountancy/admin/index.php +++ b/htdocs/accountancy/admin/index.php @@ -31,6 +31,7 @@ require '../../main.inc.php'; // Class require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; $langs->load("compta"); $langs->load("bills"); @@ -50,8 +51,8 @@ $action = GETPOST('action', 'alpha'); $list = array ( 'ACCOUNTING_LENGTH_GACCOUNT', 'ACCOUNTING_LENGTH_AACCOUNT' , - 'ACCOUNTING_LENGTH_DESCRIPTION', // adjust size displayed for lines description for dol_trunc - 'ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT', // adjust size displayed for select account description for dol_trunc +// 'ACCOUNTING_LENGTH_DESCRIPTION', // adjust size displayed for lines description for dol_trunc +// 'ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT', // adjust size displayed for select account description for dol_trunc ); @@ -64,28 +65,28 @@ $accounting_mode = defined('ACCOUNTING_MODE') ? ACCOUNTING_MODE : 'RECETTES-DEPE if ($action == 'update') { $error = 0; - + $accounting_modes = array ( 'RECETTES-DEPENSES', - 'CREANCES-DETTES' + 'CREANCES-DETTES' ); - + $accounting_mode = GETPOST('accounting_mode', 'alpha'); - + if (in_array($accounting_mode, $accounting_modes)) { - + if (! dolibarr_set_const($db, 'ACCOUNTING_MODE', $accounting_mode, 'chaine', 0, '', $conf->entity)) { $error ++; } } else { $error ++; } - + if ($error) { setEventMessages($langs->trans("Error"), null, 'errors'); } - foreach ($list as $constname) + foreach ($list as $constname) { $constvalue = GETPOST($constname, 'alpha'); @@ -266,10 +267,10 @@ if (! empty($user->admin)) // Param a user $user->rights->accountancy->chartofaccount can access -foreach ($list as $key) +foreach ($list as $key) { print '
'; print ''; print '
'; // Form to add a new line @@ -453,7 +447,7 @@ if ($id) $valuetoshow=$langs->trans("Label"); } if ($fieldlist[$field]=='nature') { $valuetoshow=$langs->trans("Nature"); } - + if ($valuetoshow != '') { print ''; print ''; - + if ($num) { // Lines with values @@ -621,7 +615,7 @@ if ($id) { foreach ($fieldlist as $field => $value) { - + $showfield=1; $align="left"; $valuetoshow=$obj->{$fieldlist[$field]}; @@ -682,10 +676,10 @@ if ($id) else print ''; print ''; - + print ''; } - + print "\n"; $i++; } diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php index fcb44c6f858..311aab692ff 100644 --- a/htdocs/accountancy/admin/productaccount.php +++ b/htdocs/accountancy/admin/productaccount.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2016 Alexandre Spangaro * Copyright (C) 2014 Florian Henry * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2015 Ari Elbaz (elarifr) @@ -70,11 +70,11 @@ $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha'); $btn_changeaccount = GETPOST('changeaccount'); $btn_changetype = GETPOST('changetype'); -$limit = GETPOST("limit")?GETPOST("limit","int"):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$limit = GETPOST('limit','int')?GETPOST('limit','int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -111,16 +111,16 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP if ($action == 'update') { if (! empty($btn_changetype)) { $error = 0; - + $accounting_product_modes = array ( 'ACCOUNTANCY_SELL', - 'ACCOUNTANCY_BUY' + 'ACCOUNTANCY_BUY' ); - + $accounting_product_mode = GETPOST('accounting_product_mode', 'alpha'); - + if (in_array($accounting_product_mode, $accounting_product_modes)) { - + if (! dolibarr_set_const($db, 'ACCOUNTING_PRODUCT_MODE', $accounting_product_mode, 'chaine', 0, '', $conf->entity)) { $error ++; } @@ -128,26 +128,26 @@ if ($action == 'update') { $error ++; } } - + if (! empty($btn_changeaccount)) { //$msg = '
' . $langs->trans("Processing") . '...
'; if (! empty($chk_prod)) { - + $accounting = new AccountingAccount($db); - + //$msg .= '
' . count($chk_prod) . ' ' . $langs->trans("SelectedLines") . '
'; - + $cpt = 0; $ok = 0; $ko = 0; foreach ( $chk_prod as $productid ) { - + $accounting_account_id = GETPOST('codeventil_' . $productid); - + $result = $accounting->fetch($accounting_account_id, null, 1); if ($result < 0) { // setEventMessages(null, $accounting->errors, 'errors'); $msg .= '
' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Product") . ' ' . $productid . ' ' . $langs->trans("NotVentilatedinAccount") . ' : id=' . $accounting_account_id . '
' . $sql . '
'; } else { - + $sql = " UPDATE " . MAIN_DB_PREFIX . "product"; if ($accounting_product_mode == 'ACCOUNTANCY_BUY') { $sql .= " SET accountancy_code_buy = " . $accounting->account_number; @@ -156,7 +156,7 @@ if ($action == 'update') { $sql .= " SET accountancy_code_sell = " . $accounting->account_number; } $sql .= " WHERE rowid = " . $productid; - + dol_syslog("/accountancy/admin/productaccount.php sql=" . $sql, LOG_DEBUG); if ($db->query($sql)) { $ok++; @@ -166,7 +166,7 @@ if ($action == 'update') { //$msg .= '
' . $langs->trans("ErrorDB") . ' : ' . $langs->trans("Product") . ' ' . $productid . ' ' . $langs->trans("NotVentilatedinAccount") . ' : ' . length_accountg($accounting->account_number) . '
' . $sql . '
'; } } - + $cpt ++; } } else { @@ -218,7 +218,7 @@ else { $sql.=" p.accountancy_code_sell = aa.account_number AND aa.fk_pcg_version = '" . $pcgvercode . "'"; } -$sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')'; +$sql.= ' WHERE p.entity IN ('.getEntity('product').')'; if ($accounting_product_mode == 'ACCOUNTANCY_BUY') { if (strlen(trim($search_current_account))) { $sql .= natural_search("p.accountancy_code_buy",$search_current_account); @@ -258,11 +258,11 @@ $sql .= $db->plimit($limit + 1, $offset); dol_syslog("/accountancy/admin/productaccount.php:: sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); -if ($result) +if ($result) { $num = $db->num_rows($result); $i = 0; - + $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; @@ -271,7 +271,7 @@ if ($result) if ($search_desc > 0) $param.="&search_desc=".urlencode($search_desc); if ($search_current_account > 0) $param.="&search_current_account=".urlencode($search_current_account); if ($search_current_account_valid && $search_current_account_valid != '-1') $param.="&search_current_account_valid=".urlencode($search_current_account_valid); - + print ''; if ($optioncss != '') print ''; print ''; @@ -280,14 +280,14 @@ if ($result) print ''; print ''; print ''; - + print load_fiche_titre($langs->trans("ProductsBinding"), '', 'title_accountancy'); print '
'; - + print $langs->trans("InitAccountancyDesc") . '
'; print '
'; - - // Select mode + + // Select mode print '
'; @@ -522,7 +516,7 @@ if ($id) if ($sortorder) $paramwithsearch.= '&sortorder='.$sortorder; if ($sortfield) $paramwithsearch.= '&sortfield='.$sortfield; if (GETPOST('from')) $paramwithsearch.= '&from='.GETPOST('from','alpha'); - + // There is several pages if ($num > $listlimit) { @@ -582,7 +576,7 @@ if ($id) } print '
 
'; print ''; print ''; @@ -298,20 +298,20 @@ if ($result) print ''; print '\n"; print "
' . $langs->trans('Options') . '' . $langs->trans('Description') . '
' . $langs->trans('OptionModeProductBuy') . ''.$langs->trans('OptionModeProductBuyDesc')."
\n"; - + print '
'; - + print "
\n"; - + // Filter on categories $moreforfilter=''; $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields - + $texte=$langs->trans("ListOfProductsServices"); print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit); - + print ''; print ''; @@ -334,7 +334,7 @@ if ($result) print $searchpicto; print ''; print ''; - + print ''; print_liste_field_titre($langs->trans("Ref"), $_SERVER["PHP_SELF"], "p.ref", "", $param, '', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Label"), $_SERVER["PHP_SELF"], "p.label", "", $param, '', $sortfield, $sortorder); @@ -350,9 +350,9 @@ if ($result) $clickpitco=$form->showCheckAddButtons('checkforselect', 1); print_liste_field_titre($clickpitco, '', '', '', '', 'align="center"'); print ''; - + $product_static = new Product($db); - + $var = true; $i=0; while ($i < min($num,$limit)) @@ -367,7 +367,7 @@ if ($result) $product_static->description = $obj->description; $product_static->status = $obj->tosell; $product_static->status_buy = $obj->tobuy; - + if ($obj->product_type == 0) { $compta_prodsell = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); $compta_prodsell_id = $aarowid_prodsell; @@ -375,7 +375,7 @@ if ($result) $compta_prodsell = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef")); $compta_prodsell_id = $aarowid_servsell; } - + if ($obj->product_type == 0) { $compta_prodbuy = (! empty($conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_PRODUCT_BUY_ACCOUNT : $langs->trans("CodeNotDef")); $compta_prodbuy_id = $aarowid_prodbuy; @@ -383,41 +383,41 @@ if ($result) $compta_prodbuy = (! empty($conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT) ? $conf->global->ACCOUNTING_SERVICE_BUY_ACCOUNT : $langs->trans("CodeNotDef")); $compta_prodbuy_id = $aarowid_servbuy; } - + print ''; - + print ''; - + print ''; - - if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) + + if (! empty($conf->global->ACCOUNTANCY_SHOW_PROD_DESC)) { // TODO ADJUST DESCRIPTION SIZE // print ''; // TODO: we shoul set a user defined value to adjust user square / wide screen size - $trunclengh = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 64; + $trunclengh = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION; print ''; } - + print ''; - + print ''; - + // Current accounting account print ''; - + // Dedicated account $defaultvalue=''; if ($accounting_product_mode == 'ACCOUNTANCY_BUY') { @@ -440,7 +440,7 @@ if ($result) print $form->select_account($defaultvalue, 'codeventil_' . $product_static->id, 1, array(), 1); print ''; } - + // Checkbox select print ''; @@ -448,7 +448,7 @@ if ($result) $i ++; } print '
'; print $product_static->getNomUrl(1); print ''.$obj->label.'' . $obj->description . '' . nl2br(dol_trunc($obj->description, $trunclengh)) . ''.$product_static->getLibStatut(3, 0).''.$product_static->getLibStatut(3, 1).''; if ($accounting_product_mode == 'ACCOUNTANCY_BUY') { print length_accountg($obj->accountancy_code_buy); - if ($obj->accountancy_code_buy && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount")); + if ($obj->accountancy_code_buy && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount")); } else { print length_accountg($obj->accountancy_code_sell); - if ($obj->accountancy_code_sell && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount")); + if ($obj->accountancy_code_sell && empty($obj->aaid)) print ' '.img_warning($langs->trans("ValueNotIntoChartOfAccount")); } print ''; print '
'; - + // Example : Adding jquery code print ''; - - + + print '
'; - + print '
'; - + $db->free($result); } else { dol_print_error($db); diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 34db60f7a0f..e742f4651cf 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -1,7 +1,7 @@ - * Copyright (C) 2016 Florian Henry - * Copyright (C) 2016 Alexandre Spangaro +/* Copyright (C) 2016 Olivier Geffroy + * Copyright (C) 2016 Florian Henry + * Copyright (C) 2016 Alexandre Spangaro * * 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 @@ -51,11 +51,11 @@ if ($search_accountancy_code_end == - 1) { $search_accountancy_code_end = ''; } -if (GETPOST("button_export_csv_x") || GETPOST("button_export_csv")) { +if (GETPOST("button_export_csv_x") || GETPOST("button_export_csv.x") || GETPOST("button_export_csv")) { $action = 'export_csv'; } -$limit = GETPOST('limit') ? GETPOST('limit', 'int') : $conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):$conf->liste_limit; $offset = $limit * $page; @@ -100,10 +100,10 @@ if (! empty($search_accountancy_code_end)) { if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers { - $search_accountancy_code_start = ''; - $search_accountancy_code_end = ''; - $search_date_start = ''; - $search_date_end = ''; + $search_accountancy_code_start = ''; + $search_accountancy_code_end = ''; + $search_date_start = ''; + $search_date_end = ''; } @@ -112,7 +112,10 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP */ if ($action == 'export_csv') { + $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; + if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == AccountancyExport::$EXPORT_TYPE_CEGID) $sep = ";"; // For CEGID, we force separator. + $journal = 'bookkepping'; include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; @@ -122,11 +125,7 @@ if ($action == 'export_csv') { setEventMessages($object->error, $object->errors, 'errors'); } - foreach ( $object->lines as $line ) { - - if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) { - $sep = ";"; - } + foreach ($object->lines as $line) { print length_accountg($line->numero_compte) . $sep; print $line->debit . $sep; print $line->credit . $sep; @@ -137,140 +136,137 @@ if ($action == 'export_csv') { } else { - $title_page = $langs->trans("AccountBalance") . (($search_date_start || $search_date_end) ? ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end) : ''); - - llxHeader('', $title_page); - - // List + $title_page = $langs->trans("AccountBalance") . (($search_date_start || $search_date_end) ? ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end) : ''); - $nbtotalofrecords = ''; - if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { - $nbtotalofrecords = $object->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter); - if ($nbtotalofrecords < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - } - - $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, $offset, $filter); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } - - - print '
'; - - $button = ''; - print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $result, 'title_accountancy', 0, $button); - - - $moreforfilter = ''; - - $moreforfilter .= '
'; - $moreforfilter .= $langs->trans('DateStart') . ': '; - $moreforfilter .= $form->select_date($search_date_start, 'date_start', 0, 0, 1, '', 1, 0, 1); - $moreforfilter .= $langs->trans('DateEnd') . ': '; - $moreforfilter .= $form->select_date($search_date_end, 'date_end', 0, 0, 1, '', 1, 0, 1); - $moreforfilter .= '
'; - - if (! empty($moreforfilter)) { - print '
'; - print $moreforfilter; - $parameters = array(); - $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - print '
'; - } - - print ''; + llxHeader('', $title_page); - print ''; - print ''; - print ''; + + print ''; + + print ''; + print_liste_field_titre($langs->trans("AccountAccounting"), $_SERVER['PHP_SELF'], "t.numero_compte", "", $options, "", $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Label"), $_SERVER['PHP_SELF'], "t.label_operation", "", $options, "", $sortfield, $sortorder); + 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("Solde"), $_SERVER["PHP_SELF"], "", $options, "", 'align="right"', $sortfield, $sortorder); + print_liste_field_titre('', $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); + print "\n"; + + $total_debit = 0; + $total_credit = 0; + $sous_total_debit = 0; + $sous_total_credit = 0; + $displayed_account = ""; + + foreach ($object->lines as $line) { + $link = ''; + $total_debit += $line->debit; + $total_credit += $line->credit; + $description = $object->get_compte_desc($line->numero_compte); // Search description of the account + $root_account_description = $object->get_compte_racine($line->numero_compte); + if (empty($description)) { + $link = '' . img_edit_add() . ''; + } + print ''; + + // Permet d'afficher le compte comptable + if ($root_account_description != $displayed_account) { + + // Affiche un Sous-Total par compte comptable + if ($displayed_account != "") { + print ''; + print "\n"; + print ''; + } + + // Affiche le compte comptable en d�but de ligne + print ""; + print ''; + print ''; + + $displayed_account = $root_account_description; + $sous_total_debit = 0; + $sous_total_credit = 0; + } + + // $object->get_compte_racine($line->numero_compte); + + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print "\n"; + + // Comptabilise le sous-total + $sous_total_debit += $line->debit; + $sous_total_credit += $line->credit; + } + + print ''; + print "\n"; + print ''; + + print ''; + print "\n"; + print ''; + + print "
'; - print $langs->trans('From'); - print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, ''); - print ' '; - print $langs->trans('to'); - print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array(), 1, 1, ''); - print ''; + // List + $nbtotalofrecords = ''; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $nbtotalofrecords = $object->fetchAllBalance($sortorder, $sortfield, 0, 0, $filter); + if ($nbtotalofrecords < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + } + + $result = $object->fetchAllBalance($sortorder, $sortfield, $limit, $offset, $filter); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + + print ''; + + $button = 'global->ACCOUNTING_EXPORT_FORMAT.')" />'; + print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $result, 'title_accountancy', 0, $button); + + $moreforfilter = ''; + + $moreforfilter .= '
'; + $moreforfilter .= $langs->trans('DateStart') . ': '; + $moreforfilter .= $form->select_date($search_date_start, 'date_start', 0, 0, 1, '', 1, 0, 1); + $moreforfilter .= $langs->trans('DateEnd') . ': '; + $moreforfilter .= $form->select_date($search_date_end, 'date_end', 0, 0, 1, '', 1, 0, 1); + $moreforfilter .= '
'; + + if (! empty($moreforfilter)) { + print '
'; + print $moreforfilter; + $parameters = array(); + $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + print '
'; + } + + print ''; + + print ''; + print ''; + print ''; - - print ''; - - print ''; - print_liste_field_titre($langs->trans("AccountAccounting"), $_SERVER['PHP_SELF'], "t.numero_compte", "", $options, "", $sortfield, $sortorder); - print_liste_field_titre($langs->trans("Label"), $_SERVER['PHP_SELF'], "t.label_compte", "", $options, "", $sortfield, $sortorder); - 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("Solde"), $_SERVER["PHP_SELF"], "", $options, "", 'align="right"', $sortfield, $sortorder); - print_liste_field_titre('', $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); - print "\n"; - - $total_debit = 0; - $total_credit = 0; - $sous_total_debit = 0; - $sous_total_credit = 0; - $displayed_account = ""; - - foreach ($object->lines as $line) { - $link = ''; - $total_debit += $line->debit; - $total_credit += $line->credit; - $description = $object->get_compte_desc($line->numero_compte); // Search description of the account - $root_account_description = $object->get_compte_racine($line->numero_compte); - if (empty($description)) { - $link = '' . img_edit_add() . ''; - } - print ''; - - // Permet d'afficher le compte comptable - if ($root_account_description != $displayed_account) { - - // Affiche un Sous-Total par compte comptable - if ($displayed_account != "") { - print ''; - print "\n"; - print ''; - } - - // Affiche le compte comptable en d�but de ligne - print ""; - print ''; - print ''; - - $displayed_account = $root_account_description; - $sous_total_debit = 0; - $sous_total_credit = 0; - } - - // $object->get_compte_racine($line->numero_compte); - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - // Comptabilise le sous-total - $sous_total_debit += $line->debit; - $sous_total_credit += $line->credit; - } - - print ''; - print "\n"; - print ''; - - print ''; - print "\n"; - print ''; - - print "
'; + print $langs->trans('From'); + print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array(), 1, 1, ''); + print ' '; + print $langs->trans('to'); + print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array(), 1, 1, ''); + print ''; $searchpicto=$form->showFilterAndCheckAddButtons(0); print $searchpicto; - print '
' . $langs->trans("SubTotal") . ':' . price($sous_total_debit) . '' . price($sous_total_credit) . '' . price($sous_total_credit - $sous_total_debit) . ' 
' . $root_account_description . '
' . length_accountg($line->numero_compte) . '' . $description . '' . price($line->debit) . '' . price($line->credit) . '' . price($line->credit - $line->debit) . '' . $link; - print '
' . $langs->trans("SubTotal") . ':' . price($sous_total_debit) . '' . price($sous_total_credit) . '' . price($sous_total_credit - $sous_total_debit) . ' 
' . $langs->trans("AccountBalance") . ':' . price($total_debit) . '' . price($total_credit) . '' . price($total_credit - $total_debit) . ' 
"; - print ''; - - llxFooter(); + print '
' . $langs->trans("SubTotal") . ':' . price($sous_total_debit) . '' . price($sous_total_credit) . '' . price($sous_total_credit - $sous_total_debit) . ' 
' . $root_account_description . '
' . length_accountg($line->numero_compte) . '' . $description . '' . price($line->debit) . '' . price($line->credit) . '' . price($line->credit - $line->debit) . '' . $link; + print '
' . $langs->trans("SubTotal") . ':' . price($sous_total_debit) . '' . price($sous_total_credit) . '' . price($sous_total_credit - $sous_total_debit) . ' 
' . $langs->trans("AccountBalance") . ':' . price($total_debit) . '' . price($total_credit) . '' . price($total_credit - $total_debit) . ' 
"; + print ''; + + llxFooter(); } $db->close(); \ No newline at end of file diff --git a/htdocs/accountancy/bookkeeping/balancebymonth.php b/htdocs/accountancy/bookkeeping/balancebymonth.php index 83908f72172..1d746b4d4df 100644 --- a/htdocs/accountancy/bookkeeping/balancebymonth.php +++ b/htdocs/accountancy/bookkeeping/balancebymonth.php @@ -1,8 +1,8 @@ - * Copyright (C) 2013-2014 Alexandre Spangaro - * Copyright (C) 2014 Florian Henry - * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2013-2014 Alexandre Spangaro + * Copyright (C) 2014 Florian Henry + * Copyright (C) 2015 Jean-François Ferry * * 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 diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 4443fb959b2..9be65e7261a 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -1,7 +1,7 @@ - * Copyright (C) 2013-2016 Florian Henry - * Copyright (C) 2013-2017 Alexandre Spangaro +/* Copyright (C) 2013-2017 Olivier Geffroy + * Copyright (C) 2013-2017 Florian Henry + * Copyright (C) 2013-2017 Alexandre Spangaro * * 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 @@ -16,43 +16,40 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ - /** - * \file htdocs/accountancy/bookkeeping/card.php - * \ingroup Advanced accountancy - * \brief Page to show book-entry + * \file htdocs/accountancy/bookkeeping/card.php + * \ingroup Advanced accountancy + * \brief Page to show book-entry */ require '../../main.inc.php'; -// Class require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; -require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; +require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; -// Langs $langs->load("accountancy"); -$langs->load("bank"); -$langs->load("bills"); -$langs->load("trips"); // Security check $id = GETPOST('id', 'int'); if ($user->societe_id > 0) { accessforbidden(); } - $action = GETPOST('action','aZ09'); +$mode = GETPOST('mode'); $piece_num = GETPOST("piece_num"); $mesg = ''; $account_number = GETPOST('account_number'); -$code_tiers = GETPOST('code_tiers'); -if ($code_tiers == - 1) { - $code_tiers = null; +$subledger_account = GETPOST('subledger_account'); +if ($subledger_account == - 1) { + $subledger_account = null; } $label_compte = GETPOST('label_compte'); +$label_operation= GETPOST('label_operation'); $debit = price2num(GETPOST('debit')); $credit = price2num(GETPOST('credit')); @@ -64,7 +61,7 @@ $update = GETPOST('update'); if (! empty($update)) { $action = 'confirm_update'; } - +$object = new BookKeeping($db); if ($action == "confirm_update") { $error = 0; @@ -77,13 +74,14 @@ if ($action == "confirm_update") { if (empty($error)) { $book = new BookKeeping($db); - $result = $book->fetch($id); + $result = $book->fetch($id, null, $mode); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { $book->numero_compte = $account_number; - $book->code_tiers = $code_tiers; + $book->subledger_account = $subledger_account; $book->label_compte = $label_compte; + $book->label_operation= $label_operation; $book->debit = $debit; $book->credit = $credit; @@ -96,7 +94,7 @@ if ($action == "confirm_update") { $book->sens = 'C'; } - $result = $book->update($user); + $result = $book->update($user, false, $mode); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { @@ -119,8 +117,9 @@ else if ($action == "add") { $book = new BookKeeping($db); $book->numero_compte = $account_number; - $book->code_tiers = $code_tiers; + $book->subledger_account = $subledger_account; $book->label_compte = $label_compte; + $book->label_operation= $label_operation; $book->debit = $debit; $book->credit = $credit; $book->doc_date = GETPOST('doc_date'); @@ -141,7 +140,7 @@ else if ($action == "add") { $book->sens = 'C'; } - $result = $book->createStd($user); + $result = $book->createStd($user, false, $mode); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { @@ -154,14 +153,13 @@ else if ($action == "add") { else if ($action == "confirm_delete") { $book = new BookKeeping($db); - $result = $book->fetch($id); - + $result = $book->fetch($id, null, $mode); $piece_num = $book->piece_num; if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { - $result = $book->delete($user); + $result = $book->delete($user, false, $mode); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } @@ -170,57 +168,102 @@ else if ($action == "confirm_delete") { } else if ($action == "confirm_create") { - $error = 0; - - $book = new BookKeeping($db); + $error = 0; + + $book = new BookKeeping($db); if (! GETPOST('next_num_mvt')) { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumPiece")), null, 'errors'); - $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("NumPiece")), null, 'errors'); + $error++; } - + if (! $error) { - $book->label_compte = ''; - $book->debit = 0; - $book->credit = 0; - $book->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth'), GETPOST('doc_dateday'), GETPOST('doc_dateyear')); - $book->doc_type = GETPOST('doc_type'); - $book->piece_num = GETPOST('next_num_mvt'); - $book->doc_ref = GETPOST('doc_ref'); - $book->code_journal = GETPOST('code_journal'); - $book->fk_doc = 0; - $book->fk_docdet = 0; - - $book->montant = 0; - - $result = $book->createStd($user); - if ($result < 0) { - setEventMessages($book->error, $book->errors, 'errors'); - } else { - setEventMessages($langs->trans('Saved'), null, 'mesgs'); - $action = ''; - $piece_num = $book->piece_num; - } + $book->label_compte = ''; + $book->debit = 0; + $book->credit = 0; + $book->doc_date = $date_start = dol_mktime(0, 0, 0, GETPOST('doc_datemonth'), GETPOST('doc_dateday'), GETPOST('doc_dateyear')); + $book->doc_type = GETPOST('doc_type'); + $book->piece_num = GETPOST('next_num_mvt'); + $book->doc_ref = GETPOST('doc_ref'); + $book->code_journal = GETPOST('code_journal'); + $book->fk_doc = 0; + $book->fk_docdet = 0; + $book->montant = 0; + + $result = $book->createStd($user,0, $mode); + if ($result < 0) { + setEventMessages($book->error, $book->errors, 'errors'); + } else { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + $action = 'update'; + $id=$book->id; + $piece_num = $book->piece_num; + } } } +if ($action == 'setdate') { + $datedoc = dol_mktime(0, 0, 0, GETPOST('doc_datemonth'), GETPOST('doc_dateday'), GETPOST('doc_dateyear')); + $result = $object->updateByMvt($piece_num,'doc_date',$db->idate($datedoc),$mode); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + $action = ''; + } +} + +if ($action == 'setjournal') { + $journaldoc = trim(GETPOST('code_journal')); + if (!empty($journaldoc)) { + $journaldoc='\''.$journaldoc.'\''; + } + $result = $object->updateByMvt($piece_num,'code_journal',$journaldoc,$mode); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + $action = ''; + } +} + +if ($action == 'setdocref') { + $refdoc = trim(GETPOST('doc_ref')); + if (!empty($refdoc)) { + $refdoc='\''.$refdoc.'\''; + } + $result = $object->updateByMvt(doc_ref,'code_journal',$refdoc,$mode); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + $action = ''; + } +} + +if ($action == 'valid') { + $result = $object->transformTransaction(0,$piece_num); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } else { + header("Location: list.php?sortfield=t.piece_num&sortorder=asc"); + exit; + } +} /* * View */ - llxHeader(); - $html = new Form($db); -$formaccountancy = new FormAccounting($db); +$formaccounting = new FormAccounting($db); +$accountjournal = new AccountingJournal($db); -/* - * Confirmation to delete the command - */ +// Confirmation to delete the command if ($action == 'delete') { - $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $id, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'confirm_delete', '', 0, 1); + $formconfirm = $html->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $id.'&mode='. $mode, $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'confirm_delete', '', 0, 1); print $formconfirm; } @@ -228,15 +271,17 @@ if ($action == 'create') { print load_fiche_titre($langs->trans("CreateMvts")); $book = new BookKeeping($db); - $next_num_mvt = $book->getNextNumMvt(); - if (empty($next_num_mvt)) - { - dol_print_error('', 'Failed to get next piece number'); - } + $next_num_mvt = $book->getNextNumMvt('_tmp'); + + if (empty($next_num_mvt)) + { + dol_print_error('', 'Failed to get next piece number'); + } print '
'; print '' . "\n"; print '' . "\n"; + print '' . "\n"; dol_fiche_head(); @@ -254,10 +299,9 @@ if ($action == 'create') { print ''; print ''; - print ''.$langs->trans("AccountancyJournal").''; - print ''; - print $formaccountancy->select_journal('', 'code_journal', '', 0, '', 1, 1, 1, 1); - print ''; + print '' . $langs->trans("Codejournal") . ''; + print '' . $formaccounting->select_journal(GETPOST('code_journal'),'code_journal',0,0,array(),1,1) . ''; + print ''; print ''; print '' . $langs->trans("Docref") . ''; @@ -266,7 +310,7 @@ if ($action == 'create') { print ''; print '' . $langs->trans("Doctype") . ''; - print ''; + print ''; print ''; print ''; @@ -280,7 +324,7 @@ if ($action == 'create') { print '
'; } else { $book = new BookKeeping($db); - $result = $book->fetchPerMvt($piece_num); + $result = $book->fetchPerMvt($piece_num, $mode); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } @@ -289,60 +333,139 @@ if ($action == 'create') { print load_fiche_titre($langs->trans("UpdateMvts"), '' . $langs->trans('BackToList') . ''); dol_fiche_head(); - - print '
'; - + + print '
'; + print '
'; print ''; + // account movement print ''; print ''; print ''; print ''; - print ''; - print ''; - print ''; + // date + print ''; print ''; - - print ''; - print ''; - print ''; - - print ''; - print ''; - print ''; + //journal + print ''; print ''; - - $typelabel = $book->doc_type; - if ($typelabel == 'bank') { - $typelabel = $langs->trans('Bank'); - } - if ($typelabel == 'customer_invoice') { - $typelabel = $langs->trans('CustomerInvoice'); - } - if ($typelabel == 'supplier_invoice') { - $typelabel = $langs->trans('SupplierInvoice'); - } - if ($typelabel == 'expense_report') { - $typelabel = $langs->trans('ExpenseReport'); + //docref + print ''; + print ''; + //doctype print ''; print ''; - print ''; + print ''; print ''; print '
' . $langs->trans("NumMvts") . '' . $book->piece_num . '
' . $langs->trans("Docdate") . '' . dol_print_date($book->doc_date, 'daytextshort') . '
'; + print ''; + if ($action != 'editdate') + print 'piece_num .'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('SetDate'),1).''; + print '
'; + print $langs->trans('Docdate'); + print '
'; + print '
'; + if ($action == 'editdate') { + print '
'; + print ''; + print ''; + print ''; + $form->select_date($book->doc_date ? $book->doc_date : - 1, 'doc_date', '', '', '', "setdate"); + print ''; + print '
'; + } else { + print $book->doc_date ? dol_print_date($book->doc_date, 'daytext') : ' '; + } + print '
' . $langs->trans("Codejournal") . ''; - $accountingjournal = new AccountingJournal($db); - $accountingjournal->fetch('',$book->code_journal); - print $accountingjournal->getNomUrl(0,1,1,'',1); - print '
' . $langs->trans("Docref") . '' . $book->doc_ref . '
'; + print ''; + if ($action != 'editjournal') + print 'piece_num.'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).''; + print '
'; + print $langs->trans('Codejournal'); + print '
'; + print '
'; + if ($action == 'editjournal') { + print '
'; + print ''; + print ''; + print ''; + print $formaccounting->select_journal($book->code_journal,'code_journal',0,0,array(),1,1); + print ''; + print '
'; + } else { + print $book->code_journal ; + } + print '
'; + print ''; + if ($action != 'editdocref') + print 'piece_num.'&mode='. $mode .'">'.img_edit($langs->transnoentitiesnoconv('Edit'),1).''; + print '
'; + print $langs->trans('Docref'); + print '
'; + print '
'; + if ($action == 'editdocref') { + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print '
'; + } else { + print $book->doc_ref ; } + print '
' . $langs->trans("Doctype") . '' . $typelabel . '' . $book->doc_type . '
'; - - print '
'; - - dol_fiche_end(); + print '
'; + + print '
'; + print '
'; + print ''; + + // Validate + print ''; + print ''; + print ''; + print ''; + // check data + print ''; + print ''; + /* + if ($book->doc_type == 'customer_invoice') + { + $sqlmid = 'SELECT rowid as ref'; + $sqlmid .= " FROM ".MAIN_DB_PREFIX."facture as fac"; + $sqlmid .= " WHERE fac.rowid=" . $book->fk_doc; + dol_syslog("accountancy/bookkeeping/card.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $invoicestatic = new Facture($db); + $invoicestatic->fetch($objmid->ref); + $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1); + } + else dol_print_error($db); + } + */ + print ''; + print "
' . $langs->trans("Status") . ''; + if (empty($book->validated)) { + print ''; + print img_picto($langs->trans("Disabled"), 'switch_off'); + print ''; + } else { + print ''; + print img_picto($langs->trans("Activated"), 'switch_on'); + print ''; + } + print '
' . $langs->trans("Control") . '' . $ref .'
\n"; + print '
'; + print '
'; + print '
'; print '
'; - - $result = $book->fetch_all_per_mvt($piece_num); + + $result = $book->fetchAllPerMvt($piece_num, $mode); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { @@ -356,9 +479,8 @@ if ($action == 'create') { print '' . "\n"; print '' . "\n"; print '' . "\n"; + print '' . "\n"; - $var=False; - print ""; if (count($book->linesmvt) > 0) { @@ -368,62 +490,57 @@ if ($action == 'create') { print ''; print_liste_field_titre($langs->trans("AccountAccountingShort")); - print_liste_field_titre($langs->trans("Code_tiers")); + print_liste_field_titre($langs->trans("Subledger_account")); print_liste_field_titre($langs->trans("Labelcompte")); - print_liste_field_titre($langs->trans("Debit"), "", "", "", "", 'align="right"'); - print_liste_field_titre($langs->trans("Credit"), "", "", "", "", 'align="right"'); - print_liste_field_titre($langs->trans("Amount"), "", "", "", "", 'align="right"'); - print_liste_field_titre($langs->trans("Sens"), "", "", "", "", 'align="center"'); + print_liste_field_titre($langs->trans("Labeloperation")); + print_liste_field_titre($langs->trans("Debit"), "", "", "", "", 'align="center"'); + print_liste_field_titre($langs->trans("Credit"), "", "", "", "", 'align="center"'); print_liste_field_titre($langs->trans("Action"), "", "", "", "", 'width="60" align="center"'); print "\n"; - foreach ($book->linesmvt as $line) { + foreach ( $book->linesmvt as $line ) { print ''; - $total_debit += $line->debit; $total_credit += $line->credit; if ($action == 'update' && $line->id == $id) { - print ''; print ''; print ''; + print ''; print ''; print ''; - print ''; - print ''; print ''; } else { print ''; - print ''; + print ''; print ''; + print ''; print ''; print ''; - print ''; - print ''; print ''; } print "\n"; } - if ($total_debit != $total_credit) + if ($total_debit != $total_credit) { setEventMessages(null, array($langs->trans('MvtNotCorrectlyBalanced', $total_credit, $total_debit)), 'warnings'); } @@ -434,17 +551,21 @@ if ($action == 'create') { print $formaccounting->select_account($account_number, 'account_number', 0, array (), 1, 1, ''); print ''; print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; print ''; print ''; } print '
'; print $formaccounting->select_account($line->numero_compte, 'account_number', 0, array (), 1, 1, ''); print ''; - print $formaccounting->select_auxaccount($line->code_tiers, 'code_tiers', 1); + print $formaccounting->select_auxaccount($line->subledger_account, 'subledger_account', 1); print '' . price($line->montant) . '' . $line->sens . ''; print '' . "\n"; print ''; print '' . length_accountg($line->numero_compte) . '' . length_accounta($line->code_tiers) . '' . length_accounta($line->subledger_account) . '' . $line->label_compte . '' . $line->label_operation. '' . price($line->debit) . '' . price($line->credit) . '' . price($line->montant) . '' . $line->sens . ''; - print ''; + print 'id . '&piece_num=' . $line->piece_num . '&mode='.$mode.'">'; print img_edit(); print ' '; - print ''; + print 'id . '&piece_num=' . $line->piece_num . '&mode='.$mode.'">'; print img_delete(); - print ''; + print ''; print '
'; - print $formaccounting->select_auxaccount($code_tiers, 'code_tiers', 1); + print $formaccounting->select_auxaccount($subledger_account, 'subledger_account', 1); print '
'; + if ($mode=='_tmp' && $total_debit == $total_credit && $action=='') { + print '"; + } print ''; } } @@ -453,5 +574,6 @@ if ($action == 'create') { } } +dol_fiche_end(); llxFooter(); $db->close(); diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 369dd7afcec..6f994eb1110 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -2,7 +2,7 @@ /* Copyright (C) 2013-2016 Olivier Geffroy * Copyright (C) 2013-2016 Florian Henry * Copyright (C) 2013-2017 Alexandre Spangaro - * Copyright (C) 2016 Laurent Destailleur + * Copyright (C) 2016 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 @@ -25,8 +25,7 @@ * \brief List operation of book keeping */ require '../../main.inc.php'; - -// Class +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancyexport.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; @@ -47,11 +46,11 @@ $search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETP $search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); $search_doc_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int')); -if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt")) { +if (GETPOST("button_delmvt_x") || GETPOST("button_delmvt.x") || GETPOST("button_delmvt")) { $action = 'delbookkeepingyear'; } -if (GETPOST("button_export_csv_x") || GETPOST("button_export_csv")) { - $action = 'export_csv'; +if (GETPOST("button_export_file_x") || GETPOST("button_export_file.x") || GETPOST("button_export_file")) { + $action = 'export_file'; } $search_accountancy_code = GETPOST("search_accountancy_code"); @@ -80,7 +79,7 @@ $search_direction = GETPOST('search_direction', 'alpha'); $search_ledger_code = GETPOST('search_ledger_code', 'alpha'); // Load variable for pagination -$limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page','int'); @@ -99,7 +98,7 @@ $formother = new FormOther($db); $form = new Form($db); -if ($action != 'export_csv' && ! isset($_POST['begin']) && ! isset($_GET['begin']) && ! isset($_POST['formfilteraction'])) { +if ($action != 'export_file' && ! isset($_POST['begin']) && ! isset($_GET['begin']) && ! isset($_POST['formfilteraction']) && empty($page)) { $search_date_start = dol_mktime(0, 0, 0, 1, 1, dol_print_date(dol_now(), '%Y')); $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_print_date(dol_now(), '%Y')); } @@ -171,19 +170,19 @@ if (! empty($search_accountancy_code_end)) { $param .= '&search_accountancy_code_end=' . $search_accountancy_code_end; } if (! empty($search_accountancy_aux_code)) { - $filter['t.code_tiers'] = $search_accountancy_aux_code; + $filter['t.subledger_account'] = $search_accountancy_aux_code; $param .= '&search_accountancy_aux_code=' . $search_accountancy_aux_code; } if (! empty($search_accountancy_aux_code_start)) { - $filter['t.code_tiers>='] = $search_accountancy_aux_code_start; + $filter['t.subledger_account>='] = $search_accountancy_aux_code_start; $param .= '&search_accountancy_aux_code_start=' . $search_accountancy_aux_code_start; } if (! empty($search_accountancy_aux_code_end)) { - $filter['t.code_tiers<='] = $search_accountancy_aux_code_end; + $filter['t.subledger_account<='] = $search_accountancy_aux_code_end; $param .= '&search_accountancy_aux_code_end=' . $search_accountancy_aux_code_end; } if (! empty($search_mvt_label)) { - $filter['t.label_compte'] = $search_mvt_label; + $filter['t.label_operation'] = $search_mvt_label; $param .= '&search_mvt_label=' . $search_mvt_label; } if (! empty($search_direction)) { @@ -223,7 +222,7 @@ if ($action == 'delbookkeepingyearconfirm') { $deljournal=0; } - if (! empty($delyear) || ! empty($deljournal)) + if (! empty($delyear) || ! empty($deljournal)) { $result = $object->deleteByYearAndJournal($delyear,$deljournal); if ($result < 0) { @@ -261,9 +260,8 @@ if ($action == 'delmouvconfirm') { } } -if ($action == 'export_csv') { - - include DOL_DOCUMENT_ROOT . '/accountancy/class/accountancyexport.class.php'; +// Export into a file with format defined into setup +if ($action == 'export_file') { $result = $object->fetchAll($sortorder, $sortfield, 0, 0, $filter); @@ -322,7 +320,7 @@ if ($action == 'delbookkeepingyear') { $delyear = dol_print_date(dol_now(), '%Y'); } $year_array = $formaccounting->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array'); - $journal_array = $formaccounting->selectjournal($deljournal, 'deljournal', '', 1, 'array', 1, 1); + $journal_array = $formaccounting->select_journal($deljournal, 'deljournal', '', 1, 1, 1, '', 0, 1); $form_question['delyear'] = array ( 'name' => 'delyear', @@ -333,9 +331,9 @@ if ($action == 'delbookkeepingyear') { ); $form_question['deljournal'] = array ( 'name' => 'deljournal', - 'type' => 'select', + 'type' => 'other', // We don't use select here, the journal_array is already a select html component 'label' => $langs->trans('DelJournal'), - 'values' => $journal_array, + 'value' => $journal_array, 'default' => $deljournal ); @@ -356,16 +354,18 @@ print ''; print ''; print ''; -$button = ''; +$listofformat=AccountancyExport::getType(); +$button = ''; if (count($filter)) $button.= $langs->trans("ExportFilteredList"); else $button.= $langs->trans("ExportList"); +$button.=' ('.$listofformat[$conf->global->ACCOUNTING_EXPORT_MODELCSV].')'; $button.= ''; $groupby = ' ' . $langs->trans("GroupByAccountAccounting") . ''; print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $button, $result, $nbtotalofrecords, 'title_accountancy', 0, $groupby, '', $limit); -print '
' . "\n"; +print '
' . "\n"; print ''; print ''; @@ -376,26 +376,35 @@ print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print ''; $accountingjournal = new AccountingJournal($db); - $accountingjournal->fetch('',$line->code_journal); - print ''; + $result = $accountingjournal->fetch('',$line->code_journal); + $journaltoshow = (($result > 0)?$accountingjournal->getNomUrl(0,0,0,'',0) : $line->code_journal); + print ''; print ''; print ''; -print ''; -print ''; +print ''; print ''; print "
'; +print '
'; print $langs->trans('From') . ': '; print $form->select_date($search_date_start, 'date_start', 0, 0, 1); -print '
'; +print '
'; +print '
'; print $langs->trans('to') . ': '; print $form->select_date($search_date_end, 'date_end', 0, 0, 1); +print '
'; print '
'; +print '
'; print $langs->trans('From'); -print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, ''); -print '
'; +print $formaccounting->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, 'maxwidth200'); +print '
'; +print '
'; print $langs->trans('to'); -print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, ''); +print $formaccounting->select_account($search_accountancy_code_end, 'search_accountancy_code_end', 1, array (), 1, 1, 'maxwidth200'); +print '
'; print '
'; +print '
'; print $langs->trans('From'); print $formaccounting->select_auxaccount($search_accountancy_aux_code_start, 'search_accountancy_aux_code_start', 1); -print '
'; +print '
'; +print '
'; print $langs->trans('to'); print $formaccounting->select_auxaccount($search_accountancy_aux_code_end, 'search_accountancy_aux_code_end', 1); +print '
'; print '
'; print ''; @@ -414,8 +423,8 @@ print_liste_field_titre($langs->trans("TransactionNumShort"), $_SERVER['PHP_SELF print_liste_field_titre($langs->trans("Docdate"), $_SERVER['PHP_SELF'], "t.doc_date", "", $param, 'align="center"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "t.doc_ref", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("AccountAccountingShort"), $_SERVER['PHP_SELF'], "t.numero_compte", "", $param, "", $sortfield, $sortorder); -print_liste_field_titre($langs->trans("Code_tiers"), $_SERVER['PHP_SELF'], "t.code_tiers", "", $param, "", $sortfield, $sortorder); -print_liste_field_titre($langs->trans("Label"), $_SERVER['PHP_SELF'], "t.label_compte", "", $param, "", $sortfield, $sortorder); +print_liste_field_titre($langs->trans("SubledgerAccount"), $_SERVER['PHP_SELF'], "t.subledger_account", "", $param, "", $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Label"), $_SERVER['PHP_SELF'], "t.label_operation", "", $param, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $param, 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $param, 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $param, 'align="center"', $sortfield, $sortorder); @@ -429,7 +438,6 @@ $total_debit = 0; $total_credit = 0; foreach ($object->lines as $line ) { - $var = ! $var; $total_debit += $line->debit; $total_credit += $line->credit; @@ -440,14 +448,15 @@ foreach ($object->lines as $line ) { print '' . dol_print_date($line->doc_date, 'day') . '' . $line->doc_ref . '' . length_accountg($line->numero_compte) . '' . length_accounta($line->code_tiers) . '' . $line->label_compte . '' . price($line->debit) . '' . price($line->credit) . '' . length_accounta($line->subledger_account) . '' . $line->label_operation . '' . ($line->debit ? price($line->debit) : ''). '' . ($line->credit ? price($line->credit) : '') . '' . $accountingjournal->getNomUrl(0,0,0,'',0) . '' . $journaltoshow . ''; print '' . img_edit() . ' '; @@ -463,10 +472,10 @@ print ''; print price($total_debit); print ''; +print ''; print price($total_credit); print '
"; diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index 6b329e421ad..a1398df6fb2 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -1,9 +1,8 @@ largely based on the great work of : - * - Copyright (C) 2013-2016 Olivier Geffroy - * - Copyright (C) 2013-2016 Florian Henry - * - Copyright (C) 2013-2016 Alexandre Spangaro +/* Copyright (C) 2016 Neil Orley + * Copyright (C) 2013-2016 Olivier Geffroy + * Copyright (C) 2013-2016 Florian Henry + * Copyright (C) 2013-2017 Alexandre Spangaro * * 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 @@ -59,7 +58,7 @@ $search_direction = GETPOST('search_direction', 'alpha'); $search_ledger_code = GETPOST('search_ledger_code', 'alpha'); // Load variable for pagination -$limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page','int'); @@ -75,10 +74,6 @@ if (empty($search_date_end)) $search_date_end = dol_mktime(0, 0, 0, 12, 31, dol_ $object = new BookKeeping($db); -$formaccounting = new FormAccounting($db); -$formother = new FormOther($db); -$form = new Form($db); - $options = ''; $filter = array (); @@ -104,11 +99,11 @@ if (!GETPOST("button_removefilter_x") && !GETPOST("button_removefilter")) // Bot $options .= '&search_accountancy_code_start=' . $search_accountancy_code_start; } if (! empty($search_label_account)) { - $filter['t.label_compte'] = $search_label_account; + $filter['t.label_operation'] = $search_label_account; $options .= '&search_label_account=' . $search_label_account; } if (! empty($search_mvt_label)) { - $filter['t.label_compte'] = $search_mvt_label; + $filter['t.label_operation'] = $search_mvt_label; $options .= '&search_mvt_label=' . $search_mvt_label; } if (! empty($search_direction)) { @@ -126,7 +121,7 @@ if (!GETPOST("button_removefilter_x") && !GETPOST("button_removefilter")) // Bot * Action */ -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 { $search_doc_date = ''; $search_accountancy_code = ''; @@ -156,6 +151,10 @@ if ($action == 'delmouvconfirm') { * View */ +$formaccounting = new FormAccounting($db); +$formother = new FormOther($db); +$form = new Form($db); + $title_page = $langs->trans("Bookkeeping") . ' ' . strtolower($langs->trans("By")) . ' ' . $langs->trans("AccountAccounting"); llxHeader('', $title_page); @@ -217,7 +216,7 @@ if ( preg_match('/^asc/i', $sortorder) ) else $sortorder = "desc"; -print '
' . "\n"; +print ''; @@ -257,13 +256,12 @@ print "\n"; print ''; -$var = True; $total_debit = 0; $total_credit = 0; $sous_total_debit = 0; $sous_total_credit = 0; -$displayed_account_number = null; // Start with undefined to be able to distinguish with empty +$displayed_account_number = null; // Start with undefined to be able to distinguish with empty foreach ( $object->lines as $line ) { @@ -272,10 +270,10 @@ foreach ( $object->lines as $line ) { $accountg = length_accountg($line->numero_compte); //if (empty($accountg)) $accountg = '-'; - + // Is it a break ? if ($accountg != $displayed_account_number || ! isset($displayed_account_number)) { - + // Affiche un Sous-Total par compte comptable if (isset($displayed_account_number)) { print ''.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).''; @@ -283,7 +281,7 @@ foreach ( $object->lines as $line ) { print " \n"; print ''; } - + // Show the break account $colspan = 9; print ""; @@ -292,7 +290,7 @@ foreach ( $object->lines as $line ) { else print ''.$langs->trans("Unknown").''; print ''; print ''; - + $displayed_account_number = $accountg; //if (empty($displayed_account_number)) $displayed_account_number='-'; $sous_total_debit = 0; @@ -303,24 +301,24 @@ foreach ( $object->lines as $line ) { print ' '; print ''.$line->piece_num.''; print '' . dol_print_date($line->doc_date, 'day') . ''; - + // 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); - print strlen(length_accounta($line->code_tiers)) == 0 ? '' . $line->label_compte . '' : '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')'; + print strlen(length_accounta($line->subledger_account)) == 0 ? '' . $line->label_operation . '' : '' . $line->label_operation . '
(' . length_accounta($line->subledger_account) . ')'; - print '' . price($line->debit) . ''; - print '' . price($line->credit) . ''; + print '' . ($line->debit ? price($line->debit) :''). ''; + print '' . ($line->credit ? price($line->credit) : '') . ''; print '' . $line->code_journal . ''; print ''; - print '' . img_edit() . ' '; + print '' . img_edit() . ' '; print '' . img_delete() . ''; print ''; print "\n"; @@ -355,6 +353,4 @@ print ""; print ''; llxFooter(); - - $db->close(); diff --git a/htdocs/accountancy/bookkeeping/listbyyear.php b/htdocs/accountancy/bookkeeping/listbyyear.php index 5fba55f2eba..becb700761a 100644 --- a/htdocs/accountancy/bookkeeping/listbyyear.php +++ b/htdocs/accountancy/bookkeeping/listbyyear.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2017 Alexandre Spangaro * Copyright (C) 2013-2016 Florian Henry * * This program is free software; you can redistribute it and/or modify @@ -37,7 +37,7 @@ $langs->load("accountancy"); $page = GETPOST("page"); $sortorder = GETPOST("sortorder"); $sortfield = GETPOST("sortfield"); -$limit = GETPOST('limit') ? GETPOST('limit', 'int') : $conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):$conf->liste_limit; $search_date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); $search_date_end = dol_mktime(0, 0, 0, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); $search_doc_type = GETPOST('search_doc_type', 'alpha'); @@ -52,16 +52,16 @@ $search_numero_compte_end = GETPOST('search_numero_compte_end', 'alpha'); if ($search_numero_compte_end == - 1) { $search_numero_compte_end = ''; } -$search_code_tiers = GETPOST('search_code_tiers', 'alpha'); -$search_code_tiers_start = GETPOST('search_code_tiers_start', 'alpha'); -if ($search_code_tiers_start == - 1) { - $search_code_tiers_start = ''; +$search_subledger_account = GETPOST('search_subledger_account', 'alpha'); +$search_subledger_account_start = GETPOST('search_subledger_account_start', 'alpha'); +if ($search_subledger_account_start == - 1) { + $search_subledger_account_start = ''; } -$search_code_tiers_end = GETPOST('search_code_tiers_end', 'alpha'); -if ($search_code_tiers_end == - 1) { - $search_code_tiers_end = ''; +$search_subledger_account_end = GETPOST('search_subledger_account_end', 'alpha'); +if ($search_subledger_account_end == - 1) { + $search_subledger_account_end = ''; } -$search_label_compte = GETPOST('search_label_compte', 'alpha'); +$search_label_operation = GETPOST('search_label_operation', 'alpha'); $search_sens = GETPOST('search_sens', 'alpha'); $search_code_journal = GETPOST('search_code_journal', 'alpha'); @@ -81,16 +81,19 @@ if ($sortfield == "") $offset = $limit * $page; -llxHeader('', $langs->trans("Bookkeeping")); -if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +/* + * Actions + */ + +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All tests are required to be compatible with all browsers { $search_doc_type = ""; $search_doc_date = ""; $search_doc_ref = ""; $search_numero_compte = ""; - $search_code_tiers = ""; - $search_label_compte = ""; + $search_subledger_account = ""; + $search_label_operation = ""; $search_sens = ""; $search_code_journal = ""; } @@ -129,21 +132,21 @@ if (! empty($search_numero_compte_end)) { $filter['t.numero_compte<='] = $search_numero_compte_end; $options .= '&search_numero_compte_end=' . $search_numero_compte_end; } -if (! empty($search_code_tiers)) { - $filter['t.code_tiers'] = $search_code_tiers; - $options .= '&search_code_tiers=' . $search_code_tiers; +if (! empty($search_subledger_account)) { + $filter['t.subledger_account'] = $search_subledger_account; + $options .= '&search_subledger_account=' . $search_subledger_account; } -if (! empty($search_code_tiers_start)) { - $filter['t.code_tiers>='] = $search_code_tiers_start; - $options .= '&search_code_tiers_start=' . $search_code_tiers_start; +if (! empty($search_subledger_account_start)) { + $filter['t.subledger_account>='] = $search_subledger_account_start; + $options .= '&search_subledger_account_start=' . $search_subledger_account_start; } -if (! empty($search_code_tiers_end)) { - $filter['t.code_tiers<='] = $search_code_tiers_end; - $options .= '&search_code_tiers_end=' . $search_code_tiers_end; +if (! empty($search_subledger_account_end)) { + $filter['t.subledger_account<='] = $search_subledger_account_end; + $options .= '&search_subledger_account_end=' . $search_subledger_account_end; } -if (! empty($search_label_compte)) { - $filter['t.label_compte'] = $search_label_compte; - $options .= '&search_label_compte=' . $search_label_compte; +if (! empty($search_label_operation)) { + $filter['t.label_operation'] = $search_label_operation; + $options .= '&search_label_operation=' . $search_label_operation; } if (! empty($search_sens)) { $filter['t.sens'] = $search_sens; @@ -154,10 +157,13 @@ if (! empty($search_code_journal)) { $options .= '&search_code_journal=' . $search_code_journal; } + /* - * Mode List + * Actions */ +llxHeader('', $langs->trans("Bookkeeping")); + $nbtotalofrecords = ''; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $nbtotalofrecords = $object->fetchAll($sortorder, $sortfield, 0, 0); @@ -188,9 +194,9 @@ print $formaccounting->select_account($search_numero_compte_end, 'search_numero_ print '
'; print '
'; print $langs->trans('From') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; -print $formaccounting->select_auxaccount($search_code_tiers_start, 'search_code_tiers_start', 1); +print $formaccounting->select_auxaccount($search_subledger_account_start, 'search_subledger_account_start', 1); print $langs->trans('To') . ' ' . $langs->trans('ThirdPartyAccount') . ': '; -print $formaccounting->select_auxaccount($search_code_tiers_end, 'searchcode_tiers_end', 1); +print $formaccounting->select_auxaccount($search_subledger_account_end, 'search_subledger_account_end', 1); print '
'; print ""; @@ -200,8 +206,8 @@ print_liste_field_titre($langs->trans("Doctype"), $_SERVER['PHP_SELF'], "t.doc_t print_liste_field_titre($langs->trans("Date"), $_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("AccountAccounting"), $_SERVER['PHP_SELF'], "t.numero_compte", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre($langs->trans("ThirdPartyAccount"), $_SERVER['PHP_SELF'], "t.code_tiers", "", $options, "", $sortfield, $sortorder); -print_liste_field_titre($langs->trans("Label"), $_SERVER['PHP_SELF'], "t.label_compte", "", $options, "", $sortfield, $sortorder); +print_liste_field_titre($langs->trans("ThirdPartyAccount"), $_SERVER['PHP_SELF'], "t.subledger_account", "", $options, "", $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Label"), $_SERVER['PHP_SELF'], "t.label_operation", "", $options, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, "", $sortfield, $sortorder); print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="center"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Amount"), $_SERVER['PHP_SELF'], "t.montant", "", $options, 'align="center"', $sortfield, $sortorder); @@ -232,11 +238,11 @@ print ''; print ''; print ''; print ''; print "\n"; -$var = True; - foreach ( $object->lines as $line ) { print ''; @@ -274,8 +278,8 @@ foreach ( $object->lines as $line ) { print ''; print ''; print ''; - print ''; - print ''; + print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index 139498bd0b2..66f72ea9bf6 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -92,7 +92,7 @@ class AccountancyCategory public function getCptBK($id) { global $conf; - $sql = "SELECT t.numero_compte, t.label_compte, t.doc_ref"; + $sql = "SELECT t.numero_compte, t.label_operation, t.doc_ref"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; $sql .= " WHERE t.numero_compte NOT IN ("; $sql .= " SELECT t.account_number"; @@ -104,7 +104,7 @@ class AccountancyCategory $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " AND aa.active = 1)"; - $sql .= " GROUP BY t.numero_compte, t.label_compte, t.doc_ref"; + $sql .= " GROUP BY t.numero_compte, t.label_operation, t.doc_ref"; $sql .= " ORDER BY t.numero_compte"; $this->lines_CptBk = array (); @@ -138,7 +138,7 @@ class AccountancyCategory */ public function getAccountsWithNoCategory($id) { global $conf; - + $sql = "SELECT aa.account_number as numero_compte, aa.label as label_compte"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; @@ -147,9 +147,9 @@ class AccountancyCategory $sql .= " AND aa.active = 1"; $sql .= " GROUP BY aa.account_number, aa.label"; $sql .= " ORDER BY aa.account_number, aa.label"; - + $this->lines_CptBk = array (); - + dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -159,17 +159,17 @@ class AccountancyCategory $this->lines_cptbk[] = $obj; } } - + return $num; } else { $this->error = "Error " . $this->db->lasterror(); $this->errors[] = $this->error; dol_syslog(__METHOD__ . " " . implode(',' . $this->errors), LOG_ERR); - + return - 1; } } - + /** * Function to add an accounting account in an accounting category * @@ -191,7 +191,7 @@ class AccountancyCategory $sql .= " AND aa.active = 1"; $this->db->begin(); - + dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { @@ -201,9 +201,9 @@ class AccountancyCategory return -1; } - while ( $obj = $this->db->fetch_object($resql)) + while ( $obj = $this->db->fetch_object($resql)) { - if (array_key_exists(length_accountg($obj->account_number), $cpts)) + if (array_key_exists(length_accountg($obj->account_number), $cpts)) { $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account"; $sql .= " SET fk_accounting_category=" . $id_cat; @@ -332,7 +332,7 @@ class AccountancyCategory } /** - * Function to show result of an accounting account from the general ledger with a sens and a period + * Function to show result of an accounting account from the ledger with a direction and a period * * @param int $cpt Id accounting account * @param string $month Specifig month - Can be empty @@ -429,4 +429,159 @@ class AccountancyCategory return - 1; } } + + public function getCats() { + global $db, $langs, $user, $mysoc; + + if (empty($mysoc->country_id) && empty($mysoc->country_code)) { + dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined'); + exit(); + } + + if (! empty($mysoc->country_id)) { + $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type"; + $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c"; + $sql .= " WHERE c.active = 1 "; + $sql .= " AND c.fk_country = " . $mysoc->country_id; + $sql .= " ORDER BY c.position ASC"; + } else { + $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position, c.category_type"; + $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c, " . MAIN_DB_PREFIX . "c_country as co"; + $sql .= " WHERE c.active = 1 AND c.fk_country = co.rowid"; + $sql .= " AND co.code = '" . $mysoc->country_code . "'"; + $sql .= " ORDER BY c.position ASC"; + } + + dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $i = 0; + $obj = ''; + $num = $this->db->num_rows($resql); + $data = array (); + if ($num) { + while ( $i < $num ) { + $obj = $this->db->fetch_object($resql); + + $data[] = array ( + 'rowid' => $obj->rowid, + 'code' => $obj->code, + 'position' => $obj->position, + 'label' => $obj->label, + 'formula' => $obj->formula, + 'category_type' => $obj->category_type + ); + $i ++; + } + } + return $data; + } else { + $this->error = "Error " . $this->db->lasterror(); + $this->errors[] = $this->error; + dol_syslog(__METHOD__ . " " . implode(',', $this->errors), LOG_ERR); + + return - 1; + } + } + + + // calcule + + const PATTERN = '/(?:\-?\d+(?:\.?\d+)?[\+\-\*\/])+\-?\d+(?:\.?\d+)?/'; + + const PARENTHESIS_DEPTH = 10; + + public function calculate($input){ + if(strpos($input, '+') != null || strpos($input, '-') != null || strpos($input, '/') != null || strpos($input, '*') != null){ + // Remove white spaces and invalid math chars + $input = str_replace(',', '.', $input); + $input = preg_replace('[^0-9\.\+\-\*\/\(\)]', '', $input); + + // Calculate each of the parenthesis from the top + $i = 0; + while(strpos($input, '(') || strpos($input, ')')){ + $input = preg_replace_callback('/\(([^\(\)]+)\)/', 'self::callback', $input); + + $i++; + if($i > self::PARENTHESIS_DEPTH){ + break; + } + } + + // Calculate the result + if(preg_match(self::PATTERN, $input, $match)){ + return $this->compute($match[0]); + } + + return 0; + } + + return $input; + } + + private function compute($input){ + $compute = create_function('', 'return '.$input.';'); + + return 0 + $compute(); + } + + private function callback($input){ + if(is_numeric($input[1])){ + return $input[1]; + } + elseif(preg_match(self::PATTERN, $input[1], $match)){ + return $this->compute($match[0]); + } + + return 0; + } + + /** + * get cpts of category + * + * @param int $cat_id Category id + * @return array Result in table + */ + public function getCptsCat($cat_id) { + global $mysoc; + $sql = ""; + + if (empty($mysoc->country_id) && empty($mysoc->country_code)) { + dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined'); + exit(); + } + + $sql = "SELECT t.rowid, t.account_number, t.label as name_cpt"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t"; + $sql .= " WHERE t.fk_accounting_category = ".$cat_id; + $sql .= " ORDER BY t.account_number "; + + //echo $sql; + + $resql = $this->db->query($sql); + if ($resql) { + $i = 0; + $obj = ''; + $num = $this->db->num_rows($resql); + $data = array (); + if ($num) { + while ( $obj = $this->db->fetch_object($resql) ) { + $name_cat = $obj->name_cat; + $data[] = array ( + 'id' => $obj->rowid, + 'account_number' => $obj->account_number, + 'name_cpt' => $obj->name_cpt, + ); + $i ++; + } + } + return $data; + } else { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); + + return -1; + } + } + } diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 1af9e5d1a6b..e9ad42858aa 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -5,7 +5,7 @@ * Copyright (C) 2015 Florian Henry * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) 2016 Pierre-Henry Favre - * Copyright (C) 2016 Alexandre Spangaro + * Copyright (C) 2016-2017 Alexandre Spangaro * * 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 @@ -32,14 +32,15 @@ * * Manage the different format accountancy export */ + require_once DOL_DOCUMENT_ROOT . '/core/lib/functions.lib.php'; + class AccountancyExport { /** - * - * @var Type of export + * @var Type of export. Defined by $conf->global->ACCOUNTING_EXPORT_MODELCSV */ - public static $EXPORT_TYPE_NORMAL = 1; + public static $EXPORT_TYPE_NORMAL = 1; // Classic CSV public static $EXPORT_TYPE_CEGID = 2; public static $EXPORT_TYPE_COALA = 3; public static $EXPORT_TYPE_BOB50 = 4; @@ -81,7 +82,7 @@ class AccountancyExport } /** - * Get all export type are available + * Array wit all export type available (key + label) * * @return array of type */ @@ -172,7 +173,7 @@ class AccountancyExport print $date . $this->separator; print $line->doc_ref . $this->separator; print length_accountg($line->numero_compte) . $this->separator; - print length_accounta($line->code_tiers) . $this->separator; + print length_accounta($line->subledger_account) . $this->separator; print price($line->debit) . $this->separator; print price($line->credit) . $this->separator; print $line->code_journal . $this->separator; @@ -195,10 +196,10 @@ class AccountancyExport print $date . $separator; print $line->code_journal . $separator; print length_accountg($line->numero_compte) . $separator; - print length_accounta($line->code_tiers) . $separator; + print length_accounta($line->subledger_account) . $separator; print $line->sens . $separator; print price($line->montant) . $separator; - print $line->label_compte . $separator; + print $line->label_operation . $separator; print $line->doc_ref; print $this->end_line; } @@ -220,7 +221,7 @@ class AccountancyExport print $line->piece_num . $this->separator; print length_accountg($line->numero_compte) . $this->separator; print '' . $this->separator; - print $line->label_compte . $this->separator; + print $line->label_operation . $this->separator; print $date . $this->separator; if ($line->sens=='D') { print price($line->montant) . $this->separator; @@ -230,7 +231,7 @@ class AccountancyExport print price($line->montant) . $this->separator; } print $line->doc_ref . $this->separator; - print $line->label_compte . $this->separator; + print $line->label_operation . $this->separator; print $this->end_line; } } @@ -254,7 +255,7 @@ class AccountancyExport print price($line->debit) . $this->separator; print price($line->credit) . $this->separator; print 'E' . $this->separator; - print length_accountg($line->code_tiers) . $this->separator; + print length_accountg($line->subledger_account) . $this->separator; print $this->end_line; } } @@ -274,7 +275,7 @@ class AccountancyExport $date = dol_print_date($line->doc_date, '%d/%m/%Y'); print $date . $this->separator; - if (empty($line->code_tiers)) { + if (empty($line->subledger_account)) { print 'G' . $this->separator; print length_accounta($line->numero_compte) . $this->separator; } else { @@ -284,12 +285,12 @@ class AccountancyExport if (substr($line->numero_compte, 0, 3) == '401') { print 'F' . $this->separator; } - print length_accountg($line->code_tiers) . $this->separator; + print length_accountg($line->subledger_account) . $this->separator; } print price($line->debit) . $this->separator; print price($line->credit) . $this->separator; - print dol_trunc($line->label_compte, 32) . $this->separator; + print dol_trunc($line->label_operation, 32) . $this->separator; print $this->end_line; } } @@ -307,11 +308,11 @@ class AccountancyExport $this->end_line ="\r\n"; $i = 1; - $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be yyyymmdd + $date_ecriture = dol_print_date(dol_now(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be yyyymmdd foreach ( $TData as $data ) { $code_compta = $data->numero_compte; - if (! empty($data->code_tiers)) - $code_compta = $data->code_tiers; + if (! empty($data->subledger_account)) + $code_compta = $data->subledger_account; $Tab = array (); $Tab['num_ecriture'] = str_pad($i, 5); @@ -320,11 +321,11 @@ class AccountancyExport $Tab['date_ope'] = dol_print_date($data->doc_date, $conf->global->ACCOUNTING_EXPORT_DATE); $Tab['num_piece'] = str_pad(self::trunc($data->piece_num, 12), 12); $Tab['num_compte'] = str_pad(self::trunc($code_compta, 11), 11); - $Tab['libelle_ecriture'] = str_pad(self::trunc($data->doc_ref . $data->label_compte, 25), 25); + $Tab['libelle_ecriture'] = str_pad(self::trunc($data->doc_ref . $data->label_operation, 25), 25); $Tab['montant'] = str_pad(abs($data->montant), 13, ' ', STR_PAD_LEFT); $Tab['type_montant'] = str_pad($data->sens, 1); $Tab['vide'] = str_repeat(' ', 18); - $Tab['intitule_compte'] = str_pad(self::trunc($data->label_compte, 34), 34); + $Tab['intitule_compte'] = str_pad(self::trunc($data->label_operation, 34), 34); $Tab['end'] = 'O2003'; $Tab['end_line'] = $this->end_line; @@ -349,8 +350,8 @@ class AccountancyExport $date_ecriture = dol_print_date(time(), $conf->global->ACCOUNTING_EXPORT_DATE); // format must be ddmmyy foreach ( $TData as $data ) { $code_compta = $data->numero_compte; - if (! empty($data->code_tiers)) - $code_compta = $data->code_tiers; + if (! empty($data->subledger_account)) + $code_compta = $data->subledger_account; $Tab = array (); $Tab['type_ligne'] = 'M'; @@ -359,7 +360,7 @@ class AccountancyExport $Tab['folio'] = '000'; $Tab['date_ecriture'] = $date_ecriture; $Tab['filler'] = ' '; - $Tab['libelle_ecriture'] = str_pad(self::trunc($data->doc_ref . ' ' . $data->label_compte, 20), 20); + $Tab['libelle_ecriture'] = str_pad(self::trunc($data->doc_ref . ' ' . $data->label_operation, 20), 20); $Tab['sens'] = $data->sens; // C or D $Tab['signe_montant'] = '+'; $Tab['montant'] = str_pad(abs($data->montant), 12, '0', STR_PAD_LEFT); // TODO manage negative amount @@ -375,7 +376,7 @@ class AccountancyExport $Tab['devis'] = str_pad($conf->currency, 3); $Tab['code_journal2'] = str_pad(self::trunc($data->code_journal, 3), 3); $Tab['filler3'] = str_repeat(' ', 3); - $Tab['libelle_ecriture2'] = str_pad(self::trunc($data->doc_ref . ' ' . $data->label_compte, 32), 32); + $Tab['libelle_ecriture2'] = str_pad(self::trunc($data->doc_ref . ' ' . $data->label_operation, 32), 32); $Tab['num_piece3'] = str_pad(self::trunc($data->piece_num, 10), 10); $Tab['filler4'] = str_repeat(' ', 73); @@ -406,7 +407,7 @@ class AccountancyExport print $line->code_journal . $this->separator; print length_accountg($line->numero_compte) . $this->separator; print substr(length_accountg($line->numero_compte),0,2) . $this->separator; - print '"'.dol_trunc($line->label_compte,40,'right','UTF-8',1).'"' . $this->separator; + print '"'.dol_trunc($line->label_operation,40,'right','UTF-8',1).'"' . $this->separator; print '"'.dol_trunc($line->piece_num,15,'right','UTF-8',1).'"'.$this->separator; print price2num($line->montant).$this->separator; print $line->sens.$this->separator; @@ -436,19 +437,21 @@ class AccountancyExport print '"'.dol_trunc($line->piece_num,15,'right','UTF-8',1).'"'.$this->separator; print $date . $this->separator; print '"'.dol_trunc($line->piece_num,15,'right','UTF-8',1).'"'.$this->separator; - - if (empty($line->code_tiers)) { + + if (empty($line->subledger_account)) { print length_accountg($line->numero_compte) . $this->separator; } else { + // FIXME Because the subledger_account is already an accounting account, does we really need + // to concat 4011 or 401 to it ? if (substr($line->numero_compte, 0, 1) == 'C' || substr($line->numero_compte, 0, 1) == '9') { - print '411' . substr(str_replace(" ", "", $line->code_tiers), 0, 5) . $this->separator; + print '411' . substr(str_replace(" ", "", $line->subledger_account), 0, 5) . $this->separator; } if (substr($line->numero_compte, 0, 1) == 'F' || substr($line->numero_compte, 0, 1) == '0') { - print '401' . substr(str_replace(" ", "", $line->code_tiers), 0, 5) . $this->separator; + print '401' . substr(str_replace(" ", "", $line->subledger_account), 0, 5) . $this->separator; } } - - print length_accounta($line->code_tiers) . $this->separator; + + print length_accounta($line->subledger_account) . $this->separator; print price($line->debit) . $this->separator; print price($line->credit) . $this->separator; print price($line->montant).$this->separator; diff --git a/htdocs/accountancy/class/accountancysystem.class.php b/htdocs/accountancy/class/accountancysystem.class.php index a1c90a97b5b..87d1ccd663c 100644 --- a/htdocs/accountancy/class/accountancysystem.class.php +++ b/htdocs/accountancy/class/accountancysystem.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2014 Alexandre Spangaro + * Copyright (C) 2013-2014 Alexandre Spangaro * Copyright (C) 2013-2014 Florian Henry * * This program is free software; you can redistribute it and/or modify diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index a526f9171a6..1dad83512e3 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2016 Alexandre Spangaro * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2014 Juanjo Menent * Copyright (C) 2015 Ari Elbaz (elarifr) diff --git a/htdocs/accountancy/class/accountingjournal.class.php b/htdocs/accountancy/class/accountingjournal.class.php index 168934ee5a5..cb72c321118 100644 --- a/htdocs/accountancy/class/accountingjournal.class.php +++ b/htdocs/accountancy/class/accountingjournal.class.php @@ -33,10 +33,12 @@ class AccountingJournal extends CommonObject var $rowid; - var $code; - var $label; - var $nature; // 0:various operations, 1:sale, 2:purchase, 3:bank, 9: has-new - var $active; + public $code; + public $label; + public $nature; // 0:various operations, 1:sale, 2:purchase, 3:bank, 4:expense-report, 9: has-new + public $active; + + public $lines; /** * Constructor @@ -46,7 +48,7 @@ class AccountingJournal extends CommonObject function __construct($db) { $this->db = $db; } - + /** * Load an object from database * @@ -62,9 +64,9 @@ class AccountingJournal extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; $sql .= " WHERE"; if ($rowid) { - $sql .= " rowid = '" . $rowid . "'"; + $sql .= " rowid = " . (int) $rowid; } elseif ($journal_code) { - $sql .= " code = '" . $journal_code . "'"; + $sql .= " code = '" . $this->db->escape($journal_code) . "'"; } dol_syslog(get_class($this)."::fetch sql=" . $sql, LOG_DEBUG); @@ -80,7 +82,7 @@ class AccountingJournal extends CommonObject $this->code = $obj->code; $this->ref = $obj->code; $this->label = $obj->label; - $this->nature = $obj->nature; + $this->nature = $obj->nature; $this->active = $obj->active; return $this->id; @@ -96,7 +98,75 @@ class AccountingJournal extends CommonObject } 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 + */ + function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + $sql = "SELECT rowid, code, label, nature, active"; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + // Manage filter + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ( $filter as $key => $value ) { + if ($key == 't.code' || $key == 't.label' || $key == 't.nature') { + $sqlwhere[] = $key . '\'' . $this->db->escape($value) . '\''; + } elseif ($key == 't.rowid' || $key == 't.active') { + $sqlwhere[] = $key . '=' . $value; + } + } + } + $sql .= ' WHERE 1 = 1'; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; + if (count($sqlwhere) > 0) { + $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere); + } + + if (! empty($sortfield)) { + $sql .= $this->db->order($sortfield, $sortorder); + } + if (! empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); + } + $this->lines = array(); + + dol_syslog(get_class($this) . "::fetch sql=" . $sql, LOG_DEBUG); + $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->nature = $obj->nature; + $line->active = $obj->active; + + $this->lines[] = $line; + } + + $this->db->free($resql); + + return $num; + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + + return - 1; + } + } + /** * Return clicable name (with picto eventually) * @@ -130,24 +200,24 @@ class AccountingJournal extends CommonObject $linkclose=''; if (empty($notooltip)) { - if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label=$langs->trans("ShowAccoutingJournal"); - $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose.=' class="classfortooltip"'; + if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label=$langs->trans("ShowAccoutingJournal"); + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose.=' class="classfortooltip"'; } - $linkstart=''; + $linkstart=''; $linkend=''; if ($nourl) { $linkstart = ''; $linkclose = ''; - $linkend = ''; + $linkend = ''; } $label_link = $this->code; @@ -158,47 +228,49 @@ class AccountingJournal extends CommonObject if ($withpicto != 2) $result.=$linkstart . $label_link . $linkend; return $result; } - + /** * Retourne le libelle du statut d'un user (actif, inactif) * - * @param int $mode 0=libelle long, 1=libelle court - * @return string Label of type + * @param int $mode 0=libelle long, 1=libelle court + * @return string Label of type */ function getLibType($mode=0) { - return $this->LibType($this->nature,$mode); + return $this->LibType($this->nature,$mode); } - + /** * Return type of an accounting journal * - * @param int $nature Id type - * @param int $mode 0=libelle long, 1=libelle court - * @return string Label of type + * @param int $nature Id type + * @param int $mode 0=libelle long, 1=libelle court + * @return string Label of type */ function LibType($nature,$mode=0) { - global $langs; + global $langs; $langs->load("accountancy"); - - if ($mode == 0) - { - $prefix=''; + + if ($mode == 0) + { + $prefix=''; if ($nature == 9) return $langs->trans('AccountingJournalType9'); + if ($nature == 5) return $langs->trans('AccountingJournalType5'); if ($nature == 4) return $langs->trans('AccountingJournalType4'); if ($nature == 3) return $langs->trans('AccountingJournalType3'); - if ($nature == 2) return $langs->trans('AccountingJournalType2'); - if ($nature == 1) return $langs->trans('AccountingJournalType1'); - } - if ($mode == 1) - { + if ($nature == 2) return $langs->trans('AccountingJournalType2'); + if ($nature == 1) return $langs->trans('AccountingJournalType1'); + } + if ($mode == 1) + { if ($nature == 9) return $langs->trans('AccountingJournalType9'); + if ($nature == 5) return $langs->trans('AccountingJournalType5'); if ($nature == 4) return $langs->trans('AccountingJournalType4'); if ($nature == 3) return $langs->trans('AccountingJournalType3'); - if ($nature == 2) return $langs->trans('AccountingJournalType2'); - if ($nature == 1) return $langs->trans('AccountingJournalType1'); - } + if ($nature == 2) return $langs->trans('AccountingJournalType2'); + if ($nature == 1) return $langs->trans('AccountingJournalType1'); + } } } diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 5d9e7a9910a..51ef317e917 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1,7 +1,7 @@ - * Copyright (C) 2015-2016 Alexandre Spangaro - * Copyright (C) 2015-2016 Florian Henry +/* Copyright (C) 2014-2017 Olivier Geffroy + * Copyright (C) 2015-2017 Alexandre Spangaro + * Copyright (C) 2015-2017 Florian Henry * * 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 @@ -18,16 +18,16 @@ */ /** - * \file htdocs/accountancy/class/bookkeeping.class.php - * \ingroup Advanced accountancy - * \brief File of class to manage general ledger + * \file htdocs/accountancy/class/bookkeeping.class.php + * \ingroup Advanced accountancy + * \brief File of class to manage Ledger (General Ledger and Subledger) */ // Class require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php'; /** - * Class to manage general ledger + * Class to manage Ledger (General Ledger and Subledger) */ class BookKeeping extends CommonObject { @@ -53,7 +53,7 @@ class BookKeeping extends CommonObject * * @var string Name of table without prefix where object is stored */ - public $table_element = 'accounting_bookkeeping'; + public $table_element = 'accounting_bookkeeping'; public $entity = 1; @@ -75,9 +75,12 @@ class BookKeeping extends CommonObject public $doc_ref; public $fk_doc; public $fk_docdet; - public $code_tiers; + public $thirdparty_code; + public $subledger_account; + public $subledger_label; public $numero_compte; public $label_compte; + public $label_operation; public $debit; public $credit; public $montant; @@ -85,11 +88,9 @@ class BookKeeping extends CommonObject public $fk_user_author; public $import_key; public $code_journal; + public $journal_label; public $piece_num; - /** - */ - /** * Constructor * @@ -102,9 +103,9 @@ class BookKeeping extends CommonObject /** * 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 + * @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) { global $conf, $langs; @@ -126,8 +127,14 @@ class BookKeeping extends CommonObject if (isset($this->fk_docdet)) { $this->fk_docdet = trim($this->fk_docdet); } - if (isset($this->code_tiers)) { - $this->code_tiers = trim($this->code_tiers); + if (isset($this->thirdparty_code)) { + $this->thirdparty_code = trim($this->thirdparty_code); + } + if (isset($this->subledger_account)) { + $this->subledger_account = trim($this->subledger_account); + } + if (isset($this->subledger_label)) { + $this->subledger_label = trim($this->subledger_label); } if (isset($this->numero_compte)) { $this->numero_compte = trim($this->numero_compte); @@ -135,6 +142,9 @@ class BookKeeping extends CommonObject if (isset($this->label_compte)) { $this->label_compte = trim($this->label_compte); } + if (isset($this->label_operation)) { + $this->label_operation = trim($this->label_operation); + } if (isset($this->debit)) { $this->debit = trim($this->debit); } @@ -156,26 +166,35 @@ class BookKeeping extends CommonObject if (isset($this->code_journal)) { $this->code_journal = trim($this->code_journal); } + if (isset($this->journal_label)) { + $this->journal_label = trim($this->journal_label); + } if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } if (empty($this->debit)) $this->debit = 0; if (empty($this->credit)) $this->credit = 0; - + // Check parameters if (empty($this->numero_compte) || $this->numero_compte == '-1') { - $langs->load("errors"); - 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); - } + $langs->load("errors"); + 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->doc_ref, $this->label_compte); + $mesg=$this->doc_ref.', '.$langs->trans("AccountAccounting").': '.$this->numero_compte; + if ($this->subledger_account && $this->subledger_account != $this->numero_compte) + { + $mesg.=', '.$langs->trans("SubledgerAccount").': '.$this->subledger_account; + } + $this->errors[]=$langs->trans('ErrorFieldAccountNotDefinedForLine', $mesg); + } - return -1; + return -1; } $this->db->begin(); @@ -187,23 +206,23 @@ class BookKeeping extends CommonObject $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; $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 fk_docdet = " . $this->fk_docdet; // This field can be 0 is record is for several lines $sql .= " AND numero_compte = '" . $this->db->escape($this->numero_compte) . "'"; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; $resql = $this->db->query($sql); if ($resql) { $row = $this->db->fetch_object($resql); - if ($row->nb == 0) + if ($row->nb == 0) { // Determine piece_num $sqlnum = "SELECT piece_num"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - $sqlnum .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; // For example doc_type = 'bank' - $sqlnum .= " AND fk_docdet = " . $this->db->escape($this->fk_docdet); // fk_docdet is rowid into llx_bank or llx_facturedet or llx_facturefourndet, or ... + $sqlnum .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; // For example doc_type = 'bank' + $sqlnum .= " AND fk_docdet = " . $this->db->escape($this->fk_docdet); // fk_docdet is rowid into llx_bank or llx_facturedet or llx_facturefourndet, or ... $sqlnum .= " AND doc_ref = '" . $this->db->escape($this->doc_ref) . "'"; // ref of source object - $sqlnum .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sqlnum .= " AND entity IN (" . getEntity('accountancy') . ")"; dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); @@ -215,7 +234,7 @@ class BookKeeping extends CommonObject if (empty($this->piece_num)) { $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - $sqlnum .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; + $sqlnum .= " WHERE entity IN (" . getEntity('accountancy') . ")"; dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); @@ -240,35 +259,43 @@ class BookKeeping extends CommonObject $sql .= ", doc_ref"; $sql .= ", fk_doc"; $sql .= ", fk_docdet"; - $sql .= ", code_tiers"; + $sql .= ", thirdparty_code"; + $sql .= ", subledger_account"; + $sql .= ", subledger_label"; $sql .= ", numero_compte"; $sql .= ", label_compte"; + $sql .= ", label_operation"; $sql .= ", debit"; $sql .= ", credit"; $sql .= ", montant"; $sql .= ", sens"; $sql .= ", fk_user_author"; - $sql .= ", import_key"; + $sql .= ", date_creation"; $sql .= ", code_journal"; + $sql .= ", journal_label"; $sql .= ", piece_num"; - $sql .= ', entity'; + $sql .= ', entity'; $sql .= ") VALUES ("; $sql .= "'" . $this->db->idate($this->doc_date) . "'"; - $sql .= ",'" . $this->doc_type . "'"; - $sql .= ",'" . $this->doc_ref . "'"; + $sql .= ",'" . $this->db->escape($this->doc_type) . "'"; + $sql .= ",'" . $this->db->escape($this->doc_ref) . "'"; $sql .= "," . $this->fk_doc; $sql .= "," . $this->fk_docdet; - $sql .= ",'" . $this->code_tiers . "'"; - $sql .= ",'" . $this->numero_compte . "'"; + $sql .= ",'" . $this->db->escape($this->thirdparty_code) . "'"; + $sql .= ",'" . $this->db->escape($this->subledger_account) . "'"; + $sql .= ",'" . $this->db->escape($this->subledger_label) . "'"; + $sql .= ",'" . $this->db->escape($this->numero_compte) . "'"; $sql .= ",'" . $this->db->escape($this->label_compte) . "'"; + $sql .= ",'" . $this->db->escape($this->label_operation) . "'"; $sql .= "," . $this->debit; $sql .= "," . $this->credit; $sql .= "," . $this->montant; - $sql .= ",'" . $this->sens . "'"; - $sql .= ",'" . $this->fk_user_author . "'"; + $sql .= ",'" . $this->db->escape($this->sens) . "'"; + $sql .= ",'" . $this->db->escape($this->fk_user_author) . "'"; $sql .= ",'" . $this->db->idate($this->date_create). "'"; - $sql .= ",'" . $this->code_journal . "'"; - $sql .= "," . $this->piece_num; + $sql .= ",'" . $this->db->escape($this->code_journal) . "'"; + $sql .= ",'" . $this->db->escape($this->journal_label) . "'"; + $sql .= "," . $this->db->escape($this->piece_num); $sql .= ", " . (! isset($this->entity) ? '1' : $this->entity); $sql .= ")"; @@ -276,7 +303,7 @@ class BookKeeping extends CommonObject $resql = $this->db->query($sql); if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if ($id > 0) { $this->id = $id; $result = 0; @@ -292,7 +319,7 @@ class BookKeeping extends CommonObject $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - } else { // Already exists + } else { // Already exists $result = -3; $error++; $this->error='BookkeepingRecordAlreadyExists'; @@ -306,11 +333,11 @@ class BookKeeping extends CommonObject } if (! $error) { - + 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++; @@ -331,11 +358,12 @@ class BookKeeping extends CommonObject /** * 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 + * @param User $user User that creates + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @param string $mode Mode + * @return int <0 if KO, Id of created object if OK */ - public function createStd(User $user, $notrigger = false) { + public function createStd(User $user, $notrigger = false, $mode='') { dol_syslog(__METHOD__, LOG_DEBUG); $error = 0; @@ -354,8 +382,14 @@ class BookKeeping extends CommonObject if (isset($this->fk_docdet)) { $this->fk_docdet = trim($this->fk_docdet); } - if (isset($this->code_tiers)) { - $this->code_tiers = trim($this->code_tiers); + if (isset($this->thirdparty_code)) { + $this->thirdparty_code = trim($this->thirdparty_code); + } + if (isset($this->subledger_account)) { + $this->subledger_account = trim($this->subledger_account); + } + if (isset($this->subledger_label)) { + $this->subledger_label = trim($this->subledger_label); } if (isset($this->numero_compte)) { $this->numero_compte = trim($this->numero_compte); @@ -363,6 +397,9 @@ class BookKeeping extends CommonObject if (isset($this->label_compte)) { $this->label_compte = trim($this->label_compte); } + if (isset($this->label_operation)) { + $this->label_operation = trim($this->label_operation); + } if (isset($this->debit)) { $this->debit = trim($this->debit); } @@ -384,32 +421,44 @@ class BookKeeping extends CommonObject if (isset($this->code_journal)) { $this->code_journal = trim($this->code_journal); } + if (isset($this->journal_label)) { + $this->journal_label = trim($this->journal_label); + } if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } if (empty($this->debit)) $this->debit = 0; if (empty($this->credit)) $this->credit = 0; + $now = dol_now(); + if (empty($this->date_create)) { + $this->date_create = $now; + } + // Check parameters // Put here code to add control on parameters values // Insert request - $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . $mode.'('; $sql .= 'doc_date,'; $sql .= 'doc_type,'; $sql .= 'doc_ref,'; $sql .= 'fk_doc,'; $sql .= 'fk_docdet,'; - $sql .= 'code_tiers,'; + $sql .= 'thirdparty_code,'; + $sql .= 'subledger_account,'; + $sql .= 'subledger_label,'; $sql .= 'numero_compte,'; $sql .= 'label_compte,'; + $sql .= 'label_operation,'; $sql .= 'debit,'; $sql .= 'credit,'; $sql .= 'montant,'; $sql .= 'sens,'; $sql .= 'fk_user_author,'; - $sql .= 'import_key,'; + $sql .= 'date_creation,'; $sql .= 'code_journal,'; + $sql .= 'journal_label,'; $sql .= 'piece_num,'; $sql .= 'entity'; $sql .= ') VALUES ('; @@ -418,17 +467,21 @@ class BookKeeping extends CommonObject $sql .= ' ' . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ','; $sql .= ' ' . (empty($this->fk_doc) ? '0' : $this->fk_doc) . ','; $sql .= ' ' . (empty($this->fk_docdet) ? '0' : $this->fk_docdet) . ','; - $sql .= ' ' . (! isset($this->code_tiers) ? 'NULL' : "'" . $this->db->escape($this->code_tiers) . "'") . ','; - $sql .= ' ' . (! isset($this->numero_compte) ? "'NotDefined'" : "'" . $this->db->escape($this->numero_compte) . "'") . ','; + $sql .= ' ' . (! isset($this->thirdparty_code) ? 'NULL' : "'" . $this->db->escape($this->thirdparty_code) . "'") . ','; + $sql .= ' ' . (! isset($this->subledger_account) ? 'NULL' : "'" . $this->db->escape($this->subledger_account) . "'") . ','; + $sql .= ' ' . (! isset($this->subledger_label) ? 'NULL' : "'" . $this->db->escape($this->subledger_label) . "'") . ','; + $sql .= ' ' . (! isset($this->numero_compte) ? 'NULL' : "'" . $this->db->escape($this->numero_compte) . "'") . ','; $sql .= ' ' . (! isset($this->label_compte) ? 'NULL' : "'" . $this->db->escape($this->label_compte) . "'") . ','; + $sql .= ' ' . (! isset($this->label_operation) ? 'NULL' : "'" . $this->db->escape($this->label_operation) . "'") . ','; $sql .= ' ' . (! isset($this->debit) ? 'NULL' : $this->debit ). ','; $sql .= ' ' . (! isset($this->credit) ? 'NULL' : $this->credit ). ','; $sql .= ' ' . (! isset($this->montant) ? 'NULL' : $this->montant ). ','; $sql .= ' ' . (! isset($this->sens) ? 'NULL' : "'" . $this->db->escape($this->sens) . "'") . ','; $sql .= ' ' . $user->id . ','; - $sql .= ' ' . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ','; + $sql .= ' ' . "'" . $this->db->idate($this->date_create) . "',"; $sql .= ' ' . (empty($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; - $sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->piece_num).','; + $sql .= ' ' . (empty($this->journal_label) ? 'NULL' : "'" . $this->db->escape($this->journal_label) . "'") . ','; + $sql .= ' ' . (empty($this->piece_num) ? 'NULL' : $this->db->escape($this->piece_num)).','; $sql .= ' ' . (! isset($this->entity) ? '1' : $this->entity); $sql .= ')'; @@ -447,7 +500,7 @@ class BookKeeping extends CommonObject 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++; @@ -458,11 +511,11 @@ class BookKeeping extends CommonObject // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $this->id; } } @@ -472,13 +525,14 @@ class BookKeeping extends CommonObject * * @param int $id Id object * @param string $ref Ref - * + * @param string $mode Mode + * * @return int <0 if KO, 0 if not found, >0 if OK */ - public function fetch($id, $ref = null) { + public function fetch($id, $ref = null, $mode='') { global $conf; - dol_syslog(__METHOD__, LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $sql = 'SELECT'; $sql .= ' t.rowid,'; @@ -487,9 +541,12 @@ class BookKeeping extends CommonObject $sql .= " t.doc_ref,"; $sql .= " t.fk_doc,"; $sql .= " t.fk_docdet,"; - $sql .= " t.code_tiers,"; + $sql .= " t.thirdparty_code,"; + $sql .= " t.subledger_account,"; + $sql .= " t.subledger_label,"; $sql .= " t.numero_compte,"; $sql .= " t.label_compte,"; + $sql .= " t.label_operation,"; $sql .= " t.debit,"; $sql .= " t.credit,"; $sql .= " t.montant,"; @@ -497,10 +554,11 @@ class BookKeeping extends CommonObject $sql .= " t.fk_user_author,"; $sql .= " t.import_key,"; $sql .= " t.code_journal,"; + $sql .= " t.journal_label,"; $sql .= " t.piece_num"; - $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element.$mode. ' as t'; $sql .= ' WHERE 1 = 1'; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; if (null !== $ref) { $sql .= ' AND t.ref = ' . '\'' . $ref . '\''; } else { @@ -520,9 +578,12 @@ class BookKeeping extends CommonObject $this->doc_ref = $obj->doc_ref; $this->fk_doc = $obj->fk_doc; $this->fk_docdet = $obj->fk_docdet; - $this->code_tiers = $obj->code_tiers; + $this->thirdparty_code = $obj->thirdparty_code; + $this->subledger_account = $obj->subledger_account; + $this->subledger_label = $obj->subledger_label; $this->numero_compte = $obj->numero_compte; $this->label_compte = $obj->label_compte; + $this->label_operation = $obj->label_operation; $this->debit = $obj->debit; $this->credit = $obj->credit; $this->montant = $obj->montant; @@ -530,6 +591,7 @@ class BookKeeping extends CommonObject $this->fk_user_author = $obj->fk_user_author; $this->import_key = $obj->import_key; $this->code_journal = $obj->code_journal; + $this->journal_label = $obj->journal_label; $this->piece_num = $obj->piece_num; } $this->db->free($resql); @@ -542,12 +604,12 @@ class BookKeeping extends CommonObject } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - - /** + + /** * Load object in memory from the database * * @param string $sortorder Sort Order @@ -556,7 +618,7 @@ class BookKeeping extends CommonObject * @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 fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { @@ -571,9 +633,12 @@ class BookKeeping extends CommonObject $sql .= " t.doc_ref,"; $sql .= " t.fk_doc,"; $sql .= " t.fk_docdet,"; - $sql .= " t.code_tiers,"; + $sql .= " t.thirdparty_code,"; + $sql .= " t.subledger_account,"; + $sql .= " t.subledger_label,"; $sql .= " t.numero_compte,"; $sql .= " t.label_compte,"; + $sql .= " t.label_operation,"; $sql .= " t.debit,"; $sql .= " t.credit,"; $sql .= " t.montant,"; @@ -581,6 +646,7 @@ class BookKeeping extends CommonObject $sql .= " t.fk_user_author,"; $sql .= " t.import_key,"; $sql .= " t.code_journal,"; + $sql .= " t.journal_label,"; $sql .= " t.piece_num"; // Manage filter $sqlwhere = array (); @@ -590,33 +656,33 @@ class BookKeeping extends CommonObject $sqlwhere[] = $key . '=\'' . $this->db->idate($value) . '\''; } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') { $sqlwhere[] = $key . '\'' . $this->db->idate($value) . '\''; - } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.code_tiers>=' || $key == 't.code_tiers<=') { + } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') { $sqlwhere[] = $key . '\'' . $this->db->escape($value) . '\''; } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') { $sqlwhere[] = $key . '=' . $value; - } elseif ($key == 't.code_tiers' || $key == 't.numero_compte') { + } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') { $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; - } elseif ($key == 't.label_compte') { + } elseif ($key == 't.label_operation') { $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; - }else { + } else { $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; } } } $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; $sql .= ' WHERE 1 = 1'; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; if (count($sqlwhere) > 0) { $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - // Affichage par compte comptable - $sql .= ' ORDER BY t.numero_compte ASC'; + // Affichage par compte comptable + $sql .= ' ORDER BY t.numero_compte ASC'; if (! empty($sortfield)) { - $sql .= ', ' . $sortfield . ' ' .$sortorder; + $sql .= ', ' . $sortfield . ' ' .$sortorder; } if (! empty($limit)) { $sql .= ' ' . $this->db->plimit($limit + 1, $offset); - } + } $this->lines = array (); $resql = $this->db->query($sql); @@ -633,9 +699,12 @@ class BookKeeping extends CommonObject $line->doc_ref = $obj->doc_ref; $line->fk_doc = $obj->fk_doc; $line->fk_docdet = $obj->fk_docdet; - $line->code_tiers = $obj->code_tiers; + $line->thirdparty_code = $obj->thirdparty_code; + $line->subledger_account = $obj->subledger_account; + $line->subledger_label = $obj->subledger_label; $line->numero_compte = $obj->numero_compte; $line->label_compte = $obj->label_compte; + $line->label_operation = $obj->label_operation; $line->debit = $obj->debit; $line->credit = $obj->credit; $line->montant = $obj->montant; @@ -643,6 +712,7 @@ class BookKeeping extends CommonObject $line->fk_user_author = $obj->fk_user_author; $line->import_key = $obj->import_key; $line->code_journal = $obj->code_journal; + $line->journal_label = $obj->journal_label; $line->piece_num = $obj->piece_num; $this->lines[] = $line; @@ -657,8 +727,7 @@ class BookKeeping extends CommonObject return - 1; } } - - + /** * Load object in memory from the database * @@ -668,13 +737,13 @@ class BookKeeping extends CommonObject * @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') { global $conf; - dol_syslog(__METHOD__, LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $sql = 'SELECT'; $sql .= ' t.rowid,'; @@ -683,9 +752,12 @@ class BookKeeping extends CommonObject $sql .= " t.doc_ref,"; $sql .= " t.fk_doc,"; $sql .= " t.fk_docdet,"; - $sql .= " t.code_tiers,"; + $sql .= " t.thirdparty_code,"; + $sql .= " t.subledger_account,"; + $sql .= " t.subledger_label,"; $sql .= " t.numero_compte,"; $sql .= " t.label_compte,"; + $sql .= " t.label_operation,"; $sql .= " t.debit,"; $sql .= " t.credit,"; $sql .= " t.montant,"; @@ -693,6 +765,7 @@ class BookKeeping extends CommonObject $sql .= " t.fk_user_author,"; $sql .= " t.import_key,"; $sql .= " t.code_journal,"; + $sql .= " t.journal_label,"; $sql .= " t.piece_num"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; // Manage filter @@ -703,11 +776,11 @@ class BookKeeping extends CommonObject $sqlwhere[] = $key . '=\'' . $this->db->idate($value) . '\''; } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') { $sqlwhere[] = $key . '\'' . $this->db->idate($value) . '\''; - } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.code_tiers>=' || $key == 't.code_tiers<=') { + } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') { $sqlwhere[] = $key . '\'' . $this->db->escape($value) . '\''; } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') { $sqlwhere[] = $key . '=' . $value; - } elseif ($key == 't.code_tiers' || $key == 't.numero_compte') { + } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') { $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; } else { $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; @@ -715,7 +788,7 @@ class BookKeeping extends CommonObject } } $sql.= ' WHERE 1 = 1'; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; if (count($sqlwhere) > 0) { $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere); } @@ -742,9 +815,12 @@ class BookKeeping extends CommonObject $line->doc_ref = $obj->doc_ref; $line->fk_doc = $obj->fk_doc; $line->fk_docdet = $obj->fk_docdet; - $line->code_tiers = $obj->code_tiers; + $line->thirdparty_code = $obj->thirdparty_code; + $line->subledger_account = $obj->subledger_account; + $line->subledger_label = $obj->subledger_label; $line->numero_compte = $obj->numero_compte; $line->label_compte = $obj->label_compte; + $line->label_operation = $obj->label_operation; $line->debit = $obj->debit; $line->credit = $obj->credit; $line->montant = $obj->montant; @@ -752,6 +828,7 @@ class BookKeeping extends CommonObject $line->fk_user_author = $obj->fk_user_author; $line->import_key = $obj->import_key; $line->code_journal = $obj->code_journal; + $line->journal_label = $obj->journal_label; $line->piece_num = $obj->piece_num; $this->lines[] = $line; @@ -782,7 +859,7 @@ class BookKeeping extends CommonObject public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { global $conf; - dol_syslog(__METHOD__, LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $sql = 'SELECT'; $sql .= " t.numero_compte,"; @@ -797,11 +874,13 @@ class BookKeeping extends CommonObject $sqlwhere[] = $key . '=\'' . $this->db->idate($value) . '\''; } elseif ($key == 't.doc_date>=' || $key == 't.doc_date<=') { $sqlwhere[] = $key . '\'' . $this->db->idate($value) . '\''; - } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.code_tiers>=' || $key == 't.code_tiers<=') { + } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') { $sqlwhere[] = $key . '\'' . $this->db->escape($value) . '\''; } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') { $sqlwhere[] = $key . '=' . $value; - } elseif ($key == 't.code_tiers' || $key == 't.numero_compte') { + } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') { + $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; + } elseif ($key == 't.subledger_label') { $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; } else { $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; @@ -809,7 +888,7 @@ class BookKeeping extends CommonObject } } $sql.= ' WHERE 1 = 1'; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; if (count($sqlwhere) > 0) { $sql .= ' AND ' . implode(' ' . $filtermode . ' ', $sqlwhere); } @@ -817,7 +896,7 @@ class BookKeeping extends CommonObject $sql .= ' GROUP BY t.numero_compte'; if (! empty($sortfield)) { - $sql .= $this->db->order($sortfield, $sortorder); + $sql .= $this->db->order($sortfield, $sortorder); } if (! empty($limit)) { $sql .= ' ' . $this->db->plimit($limit + 1, $offset); @@ -850,12 +929,12 @@ class BookKeeping extends CommonObject /** * 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 + * @param User $user User that modifies + * @param bool $notrigger false=launch triggers after, true=disable triggers + * @param string $mode Mode + * @return int <0 if KO, >0 if OK */ - public function update(User $user, $notrigger = false) { + public function update(User $user, $notrigger = false, $mode='') { $error = 0; dol_syslog(__METHOD__, LOG_DEBUG); @@ -873,8 +952,14 @@ class BookKeeping extends CommonObject if (isset($this->fk_docdet)) { $this->fk_docdet = trim($this->fk_docdet); } - if (isset($this->code_tiers)) { - $this->code_tiers = trim($this->code_tiers); + if (isset($this->thirdparty_code)) { + $this->thirdparty_code = trim($this->thirdparty_code); + } + if (isset($this->subledger_account)) { + $this->subledger_account = trim($this->subledger_account); + } + if (isset($this->subledger_label)) { + $this->subledger_label = trim($this->subledger_label); } if (isset($this->numero_compte)) { $this->numero_compte = trim($this->numero_compte); @@ -882,6 +967,9 @@ class BookKeeping extends CommonObject if (isset($this->label_compte)) { $this->label_compte = trim($this->label_compte); } + if (isset($this->label_operation)) { + $this->label_operation = trim($this->label_operation); + } if (isset($this->debit)) { $this->debit = trim($this->debit); } @@ -903,6 +991,9 @@ class BookKeeping extends CommonObject if (isset($this->code_journal)) { $this->code_journal = trim($this->code_journal); } + if (isset($this->journal_label)) { + $this->journal_label = trim($this->journal_label); + } if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } @@ -911,15 +1002,18 @@ class BookKeeping extends CommonObject // Put here code to add a control on parameters values // Update request - $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; + $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . $mode.' SET'; $sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ','; $sql .= ' doc_type = ' . (isset($this->doc_type) ? "'" . $this->db->escape($this->doc_type) . "'" : "null") . ','; $sql .= ' doc_ref = ' . (isset($this->doc_ref) ? "'" . $this->db->escape($this->doc_ref) . "'" : "null") . ','; $sql .= ' fk_doc = ' . (isset($this->fk_doc) ? $this->fk_doc : "null") . ','; $sql .= ' fk_docdet = ' . (isset($this->fk_docdet) ? $this->fk_docdet : "null") . ','; - $sql .= ' code_tiers = ' . (isset($this->code_tiers) ? "'" . $this->db->escape($this->code_tiers) . "'" : "null") . ','; + $sql .= ' thirdparty_code = ' . (isset($this->thirdparty_code) ? "'" . $this->db->escape($this->thirdparty_code) . "'" : "null") . ','; + $sql .= ' subledger_account = ' . (isset($this->subledger_account) ? "'" . $this->db->escape($this->subledger_account) . "'" : "null") . ','; + $sql .= ' subledger_label = ' . (isset($this->subledger_label) ? "'" . $this->db->escape($this->subledger_label) . "'" : "null") . ','; $sql .= ' numero_compte = ' . (isset($this->numero_compte) ? "'" . $this->db->escape($this->numero_compte) . "'" : "null") . ','; $sql .= ' label_compte = ' . (isset($this->label_compte) ? "'" . $this->db->escape($this->label_compte) . "'" : "null") . ','; + $sql .= ' label_operation = ' . (isset($this->label_operation) ? "'" . $this->db->escape($this->label_operation) . "'" : "null") . ','; $sql .= ' debit = ' . (isset($this->debit) ? $this->debit : "null") . ','; $sql .= ' credit = ' . (isset($this->credit) ? $this->credit : "null") . ','; $sql .= ' montant = ' . (isset($this->montant) ? $this->montant : "null") . ','; @@ -927,6 +1021,7 @@ class BookKeeping extends CommonObject $sql .= ' fk_user_author = ' . (isset($this->fk_user_author) ? $this->fk_user_author : "null") . ','; $sql .= ' import_key = ' . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . ','; $sql .= ' code_journal = ' . (isset($this->code_journal) ? "'" . $this->db->escape($this->code_journal) . "'" : "null") . ','; + $sql .= ' journal_label = ' . (isset($this->journal_label) ? "'" . $this->db->escape($this->journal_label) . "'" : "null") . ','; $sql .= ' piece_num = ' . (isset($this->piece_num) ? $this->piece_num : "null"); $sql .= ' WHERE rowid=' . $this->id; @@ -942,7 +1037,7 @@ class BookKeeping extends CommonObject 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} @@ -961,15 +1056,47 @@ class BookKeeping extends CommonObject } } + /** + * Update movement + * + * @param string $piece_num Piece num + * @param string $field Field + * @param string $value Value + * @param string $mode Mode + * @return number <0 if KO, >0 if OK + */ + public function updateByMvt($piece_num='', $field='', $value='', $mode='') { + $this->db->begin(); + $sql = "UPDATE " . MAIN_DB_PREFIX . $this->table_element . $mode . " as ab"; + $sql .= ' SET ab.' . $field . '=' . $value; + $sql .= ' WHERE ab.piece_num=' . $piece_num ; + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + 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 - * + * @param string $mode Mode + * * @return int <0 if KO, >0 if OK */ - public function delete(User $user, $notrigger = false) { + public function delete(User $user, $notrigger = false, $mode='') { dol_syslog(__METHOD__, LOG_DEBUG); $error = 0; @@ -989,7 +1116,7 @@ class BookKeeping extends CommonObject } if (! $error) { - $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element.$mode; $sql .= ' WHERE rowid=' . $this->id; $resql = $this->db->query($sql); @@ -1015,7 +1142,7 @@ class BookKeeping extends CommonObject /** * Delete bookkepping by importkey * - * @param string $importkey Import key + * @param string $importkey Import key * @return int Result */ function deleteByImportkey($importkey) { @@ -1042,27 +1169,28 @@ class BookKeeping extends CommonObject /** * Delete bookkepping by year * - * @param string $delyear Year to delete - * @param string $journal Journal to delete - * @return int <0 if KO, >0 if OK + * @param string $delyear Year to delete + * @param string $journal Journal to delete + * @param string $mode Mode + * @return int <0 if KO, >0 if OK */ - function deleteByYearAndJournal($delyear='', $journal='') { - global $conf; + function deleteByYearAndJournal($delyear='', $journal='', $mode='') { + global $conf; - if (empty($delyear) && empty($journal)) - { - return -1; - } + if (empty($delyear) && empty($journal)) + { + return -1; + } $this->db->begin(); // first check if line not yet in bookkeeping $sql = "DELETE"; - $sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element; + $sql.= " FROM " . MAIN_DB_PREFIX . $this->table_element.$mode; $sql.= " WHERE 1 = 1"; - if (! empty($delyear)) $sql.= " AND YEAR(doc_date) = " . $delyear; // FIXME Must use between + if (! empty($delyear)) $sql.= " AND YEAR(doc_date) = " . $delyear; // FIXME Must use between if (! empty($journal)) $sql.= " AND code_journal = '".$journal."'"; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; $resql = $this->db->query($sql); if (! $resql) { @@ -1083,18 +1211,19 @@ class BookKeeping extends CommonObject * Delete bookkepping by piece number * * @param int $piecenum peicenum to delete + * @param string $mode Mode * @return int Result */ - function deleteMvtNum($piecenum) { - global $conf; + function deleteMvtNum($piecenum, $mode) { + global $conf; $this->db->begin(); // first check if line not yet in bookkeeping $sql = "DELETE"; - $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; + $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element. $mode; $sql .= " WHERE piece_num = " . $piecenum; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; $resql = $this->db->query($sql); @@ -1116,7 +1245,7 @@ class BookKeeping extends CommonObject * 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) { @@ -1175,16 +1304,20 @@ class BookKeeping extends CommonObject $this->doc_ref = ''; $this->fk_doc = ''; $this->fk_docdet = ''; - $this->code_tiers = ''; - $this->numero_compte = ''; - $this->label_compte = ''; + $this->thirdparty_code = 'CU001'; + $this->subledger_account = '41100001'; + $this->subledger_label = 'My customer company'; + $this->numero_compte = '411'; + $this->label_compte = 'Customer'; + $this->label_operation = 'Sales of pea'; $this->debit = 99.9; $this->credit = ''; $this->montant = ''; - $this->sens = ''; + $this->sens = 'D'; $this->fk_user_author = $user->id; $this->import_key = ''; - $this->code_journal = ''; + $this->code_journal = 'VT'; + $this->journal_label = 'Journal de vente'; $this->piece_num = ''; } @@ -1192,15 +1325,16 @@ class BookKeeping extends CommonObject * Load an accounting document into memory from database * * @param int $piecenum Accounting document to get + * @param string $mode Mode * @return int <0 if KO, >0 if OK */ - public function fetchPerMvt($piecenum) { + public function fetchPerMvt($piecenum, $mode='') { global $conf; - $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type"; - $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; + $sql = "SELECT piece_num,doc_date,code_journal,journal_label,doc_ref,doc_type"; + $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element.$mode; $sql .= " WHERE piece_num = " . $piecenum; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); @@ -1209,6 +1343,7 @@ class BookKeeping extends CommonObject $this->piece_num = $obj->piece_num; $this->code_journal = $obj->code_journal; + $this->journal_label = $obj->journal_label; $this->doc_date = $this->db->jdate($obj->doc_date); $this->doc_ref = $obj->doc_ref; $this->doc_type = $obj->doc_type; @@ -1224,14 +1359,15 @@ class BookKeeping extends CommonObject /** * Return next number movement * - * @return string Next numero to use + * @param string $mode Mode + * @return string Next numero to use */ - public function getNextNumMvt() + public function getNextNumMvt($mode='') { global $conf; - $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element; - $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; + $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element.$mode; + $sql .= " WHERE entity IN (" . getEntity('accountancy') . ")"; dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); @@ -1251,19 +1387,20 @@ class BookKeeping extends CommonObject /** * Load all informations of accountancy document * - * @param int $piecenum id of line to get - * @return int <0 if KO, >0 if OK + * @param int $piecenum Id of line to get + * @param string $mode Mode + * @return int <0 if KO, >0 if OK */ - function fetch_all_per_mvt($piecenum) { + function fetchAllPerMvt($piecenum, $mode='') { global $conf; $sql = "SELECT rowid, doc_date, doc_type,"; - $sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,"; - $sql .= " numero_compte, label_compte, debit, credit,"; - $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; - $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; + $sql .= " doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,"; + $sql .= " numero_compte, label_compte, label_operation, debit, credit,"; + $sql .= " montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num"; + $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element.$mode; $sql .= " WHERE piece_num = " . $piecenum; - $sql .= " AND entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " AND entity IN (" . getEntity('accountancy') . ")"; dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); @@ -1280,14 +1417,18 @@ class BookKeeping extends CommonObject $line->doc_ref = $obj->doc_ref; $line->fk_doc = $obj->fk_doc; $line->fk_docdet = $obj->fk_docdet; - $line->code_tiers = $obj->code_tiers; + $line->thirdparty_code = $obj->thirdparty_code; + $line->subledger_account = $obj->subledger_account; + $line->subledger_label = $obj->subledger_label; $line->numero_compte = $obj->numero_compte; $line->label_compte = $obj->label_compte; + $line->label_operation = $obj->label_operation; $line->debit = $obj->debit; $line->credit = $obj->credit; $line->montant = $obj->montant; $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; + $line->journal_label = $obj->journal_label; $line->piece_num = $obj->piece_num; $this->linesmvt[] = $line; @@ -1304,18 +1445,18 @@ class BookKeeping extends CommonObject /** * Export bookkeping * - * @param string $model Model - * @return int Result + * @param string $model Model + * @return int Result */ function export_bookkeping($model = 'ebp') { global $conf; $sql = "SELECT rowid, doc_date, doc_type,"; - $sql .= " doc_ref, fk_doc, fk_docdet, code_tiers,"; - $sql .= " numero_compte, label_compte, debit, credit,"; + $sql .= " doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,"; + $sql .= " numero_compte, label_compte, label_operation, debit, credit,"; $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - $sql .= " WHERE entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " WHERE entity IN (" . getEntity('accountancy') . ")"; dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG); @@ -1335,9 +1476,12 @@ class BookKeeping extends CommonObject $line->doc_ref = $obj->doc_ref; $line->fk_doc = $obj->fk_doc; $line->fk_docdet = $obj->fk_docdet; - $line->code_tiers = $obj->code_tiers; + $line->thirdparty_code = $obj->thirdparty_code; + $line->subledger_account = $obj->subledger_account; + $line->subledger_label = $obj->subledger_label; $line->numero_compte = $obj->numero_compte; $line->label_compte = $obj->label_compte; + $line->label_operation = $obj->label_operation; $line->debit = $obj->debit; $line->credit = $obj->credit; $line->montant = $obj->montant; @@ -1356,107 +1500,189 @@ class BookKeeping extends CommonObject return - 1; } } - - - - /** - * Return list of accounts with label by chart of accounts - * - * @param string $selectid Preselected chart of accounts - * @param string $htmlname Name of field in html form - * @param int $showempty Add an empty field - * @param array $event Event options - * @param int $select_in Value is a aa.rowid (0 default) or aa.account_number (1) - * @param int $select_out Set value returned by select 0=rowid (default), 1=account_number - * @param int $aabase Set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by this number - * @return string String with HTML select - */ - function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '') { - global $conf; - - require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; - - $pcgver = $conf->global->CHARTOFACCOUNTS; - - $sql = "SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = ab.numero_compte"; - $sql .= " AND aa.active = 1"; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; - $sql .= " AND asy.rowid = " . $pcgver; - $sql .= " AND ab.entity IN (" . getEntity("accountancy", 1) . ")"; - $sql .= " ORDER BY account_number ASC"; - - dol_syslog(get_class($this) . "::select_account", LOG_DEBUG); - $resql = $this->db->query($sql); - - if (! $resql) { - $this->error = "Error " . $this->db->lasterror(); - dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR); - return - 1; - } - - $out = ajax_combobox($htmlname, $event); - - $options = array(); - $selected = null; - - while ($obj = $this->db->fetch_object($resql)) { - $label = length_accountg($obj->account_number) . ' - ' . $obj->label; - - $select_value_in = $obj->rowid; - $select_value_out = $obj->rowid; - - if ($select_in == 1) { - $select_value_in = $obj->account_number; - } - if ($select_out == 1) { - $select_value_out = $obj->account_number; - } - - // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number - // Because same account_number can be share between different accounting_system and do have the same meaning - if (($selectid != '') && $selectid == $select_value_in) { - $selected = $select_value_out; - } - - $options[$select_value_out] = $label; - } - - $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', 'maxwidth300'); - $this->db->free($resql); - return $out; - } - /** - * Description of a root accounting account + * Transform transaction + * + * @param number $direction If 0 tmp => real, if 1 real => tmp + * @param string $piece_num Piece num + * @return void + */ + public function transformTransaction($direction=0,$piece_num='') { + $this->db->begin(); + if ($direction==0) { + $next_piecenum=$this->getNextNumMvt(); + if ($result < 0) { + $error++; + } + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element.'(doc_date, doc_type,'; + $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,'; + $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; + $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)'; + $sql .= 'SELECT doc_date, doc_type,'; + $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,'; + $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; + $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, '.$next_piecenum.''; + $sql .= ' FROM '.MAIN_DB_PREFIX . $this->table_element.'_tmp WHERE piece_num = '.$piece_num; + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + $sql = 'DELETE FROM '.MAIN_DB_PREFIX . $this->table_element.'_tmp WHERE piece_num = '.$piece_num; + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + } + if ($direction==1) { + $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element.'_tmp WHERE piece_num = '.$piece_num; + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element.'_tmp(doc_date, doc_type,'; + $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,'; + $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; + $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num)'; + $sql .= 'SELECT doc_date, doc_type,'; + $sql .= ' doc_ref, fk_doc, fk_docdet, thirdparty_code, subledger_account, subledger_label,'; + $sql .= ' numero_compte, label_compte, label_operation, debit, credit,'; + $sql .= ' montant, sens, fk_user_author, import_key, code_journal, journal_label, piece_num'; + $sql .= ' FROM '.MAIN_DB_PREFIX . $this->table_element.' WHERE piece_num = '.$piece_num; + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + $sql = 'DELETE FROM '.MAIN_DB_PREFIX . $this->table_element.'_tmp WHERE piece_num = '.$piece_num; + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + } + } + if (! $error) { + $this->db->commit(); + return 1; + } else { + $this->db->rollback(); + return - 1; + } + $sql = "DELETE FROM "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = ab.numero_compte"; + $sql .= " AND aa.active = 1"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND asy.rowid = " . $pcgver; + $sql .= " AND ab.entity IN (" . getEntity('accountancy') . ")"; + $sql .= " ORDER BY account_number ASC"; + } + + /** + * Return list of accounts with label by chart of accounts * - * @param string $account Accounting account - * @return string Root account + * @param string $selectid Preselected chart of accounts + * @param string $htmlname Name of field in html form + * @param int $showempty Add an empty field + * @param array $event Event options + * @param int $select_in Value is a aa.rowid (0 default) or aa.account_number (1) + * @param int $select_out Set value returned by select 0=rowid (default), 1=account_number + * @param int $aabase Set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by this number + * @return string String with HTML select */ + function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '') { + global $conf; + + require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; + + $pcgver = $conf->global->CHARTOFACCOUNTS; + + $sql = "SELECT DISTINCT ab.numero_compte as account_number, aa.label as label, aa.rowid as rowid, aa.fk_pcg_version"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.account_number = ab.numero_compte"; + $sql .= " AND aa.active = 1"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND asy.rowid = " . $pcgver; + $sql .= " AND ab.entity IN (" . getEntity('accountancy') . ")"; + $sql .= " ORDER BY account_number ASC"; + + dol_syslog(get_class($this) . "::select_account", LOG_DEBUG); + $resql = $this->db->query($sql); + + if (! $resql) { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(get_class($this) . "::select_account " . $this->error, LOG_ERR); + return - 1; + } + + $out = ajax_combobox($htmlname, $event); + + $options = array(); + $selected = null; + + while ($obj = $this->db->fetch_object($resql)) { + $label = length_accountg($obj->account_number) . ' - ' . $obj->label; + + $select_value_in = $obj->rowid; + $select_value_out = $obj->rowid; + + if ($select_in == 1) { + $select_value_in = $obj->account_number; + } + if ($select_out == 1) { + $select_value_out = $obj->account_number; + } + + // Remember guy's we store in database llx_facturedet the rowid of accounting_account and not the account_number + // Because same account_number can be share between different accounting_system and do have the same meaning + if (($selectid != '') && $selectid == $select_value_in) { + $selected = $select_value_out; + } + + $options[$select_value_out] = $label; + } + + $out .= Form::selectarray($htmlname, $options, $selected, $showempty, 0, 0, '', 0, 0, 0, '', 'maxwidth300'); + $this->db->free($resql); + return $out; + } + + /** + * Description of a root accounting account + * + * @param string $account Accounting account + * @return string Root account + */ function get_compte_racine($account = null) { global $conf; $pcgver = $conf->global->CHARTOFACCOUNTS; - $sql = "SELECT root.account_number, root.label as label"; - $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; - $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; - $sql .= " AND asy.rowid = " . $pcgver; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as parent ON aa.account_parent = parent.rowid"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as root ON parent.account_parent = root.rowid"; - $sql .= " WHERE aa.account_number = '" . $account . "'"; - $sql .= " AND parent.active = 1"; - $sql .= " AND root.active = 1"; - $sql .= " AND aa.entity IN (" . getEntity("accountancy", 1) . ")"; + $sql = "SELECT root.account_number, root.label as label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND asy.rowid = " . $pcgver; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as parent ON aa.account_parent = parent.rowid"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as root ON parent.account_parent = root.rowid"; + $sql .= " WHERE aa.account_number = '" . $account . "'"; + $sql .= " AND parent.active = 1"; + $sql .= " AND root.active = 1"; + $sql .= " AND aa.entity IN (" . getEntity('accountancy') . ")"; dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $obj = ''; if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); + $obj = $this->db->fetch_object($resql); } return $obj->label; @@ -1468,14 +1694,13 @@ class BookKeeping extends CommonObject return -1; } } - - - /** - * Description of accounting account - * - * @param string $account Accounting account - * @return string Account desc - */ + + /** + * Description of accounting account + * + * @param string $account Accounting account + * @return string Account desc + */ function get_compte_desc($account = null) { global $conf; @@ -1488,14 +1713,14 @@ class BookKeeping extends CommonObject $sql .= " AND asy.rowid = " . $pcgver; $sql .= " AND aa.active = 1"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_accounting_category as cat ON aa.fk_accounting_category = cat.rowid"; - $sql .= " WHERE aa.entity IN (" . getEntity("accountancy", 1) . ")"; + $sql .= " WHERE aa.entity IN (" . getEntity('accountancy') . ")"; dol_syslog(get_class($this) . "::select_account sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $obj = ''; if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); + $obj = $this->db->fetch_object($resql); } if(empty($obj->category)){ return $obj->label; @@ -1508,10 +1733,8 @@ class BookKeeping extends CommonObject return -1; } } - } - /** * Class BookKeepingLine */ @@ -1523,9 +1746,12 @@ class BookKeepingLine public $doc_ref; public $fk_doc; public $fk_docdet; - public $code_tiers; + public $thirdparty_code; + public $subledger_account; + public $subledger_label; public $numero_compte; public $label_compte; + public $label_operation; public $debit; public $credit; public $montant; @@ -1533,5 +1759,6 @@ class BookKeepingLine public $fk_user_author; public $import_key; public $code_journal; + public $journal_label; public $piece_num; -} +} \ No newline at end of file diff --git a/htdocs/accountancy/customer/card.php b/htdocs/accountancy/customer/card.php index eca3be1d477..a10cd24adc4 100644 --- a/htdocs/accountancy/customer/card.php +++ b/htdocs/accountancy/customer/card.php @@ -1,7 +1,7 @@ * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2013-2017 Alexandre Spangaro * * 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 @@ -93,7 +93,7 @@ if (! empty($id)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON l.fk_code_ventilation = aa.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = l.fk_facture"; $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id; - $sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy + $sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy dol_syslog("/accounting/customer/card.php sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index 82a406d4a0b..f1bea3bd4a1 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -1,9 +1,9 @@ +/* Copyright (C) 2013 Olivier Geffroy * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2016 Alexandre Spangaro * Copyright (C) 2014 Juanjo Menent - * Copyright (C) 2015 Jean-François Ferry + * Copyright (C) 2015 Jean-François Ferry * * 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 @@ -23,7 +23,7 @@ /** * \file htdocs/accountancy/customer/index.php * \ingroup Advanced accountancy - * \brief Home customer ventilation + * \brief Home customer journalization page */ require '../../main.inc.php'; @@ -40,7 +40,7 @@ $langs->load("accountancy"); // Security check if (empty($conf->accounting->enabled)) { - accessforbidden(); + accessforbidden(); } if ($user->societe_id > 0) accessforbidden(); @@ -58,7 +58,7 @@ if ($year == 0) { } // Validate History -$action = GETPOST('action','alpha'); +$action = GETPOST('action','aZ09'); @@ -73,7 +73,7 @@ if ($action == 'validatehistory') { // First clean corrupted data $sqlclean = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; - $sqlclean .= " SET fd.fk_code_ventilation = 0"; + $sqlclean .= " SET fk_code_ventilation = 0"; $sqlclean .= ' WHERE fd.fk_code_ventilation NOT IN '; $sqlclean .= ' (SELECT accnt.rowid '; $sqlclean .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; @@ -91,13 +91,13 @@ if ($action == 'validatehistory') { $sql1 .= " AND " . MAIN_DB_PREFIX . "facturedet.fk_code_ventilation = 0"; } else { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; - $sql1 .= " SET fd.fk_code_ventilation = accnt.rowid"; + $sql1 .= " SET fk_code_ventilation = accnt.rowid"; $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_sell=accnt.account_number"; $sql1 .= " AND fd.fk_code_ventilation = 0"; } - dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG); + dol_syslog('htdocs/accountancy/customer/index.php'); $resql1 = $db->query($sql1); if (! $resql1) { @@ -113,7 +113,7 @@ if ($action == 'validatehistory') { $db->begin(); $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; - $sql1 .= " SET fd.fk_code_ventilation = 0"; + $sql1 .= " SET fk_code_ventilation = 0"; $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN '; $sql1 .= ' (SELECT accnt.rowid '; $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; @@ -134,16 +134,16 @@ if ($action == 'validatehistory') { } elseif ($action == 'cleanaccountancycode') { $error = 0; $db->begin(); - + // Now clean $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; - $sql1.= " SET fd.fk_code_ventilation = 0"; + $sql1.= " SET fk_code_ventilation = 0"; $sql1.= " WHERE fd.fk_facture IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture as f"; $sql1.= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'"; $sql1.= " AND f.datef <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "'"; - $sql1.= " AND f.entity IN (" . getEntity("accountancy", 1) . ")"; + $sql1.= " AND f.entity IN (" . getEntity('accountancy') . ")"; $sql1.=")"; - + dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); $resql1 = $db->query($sql1); @@ -173,7 +173,7 @@ print $langs->trans("DescVentilCustomer") . '
'; print $langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; print '
'; //print '
'; -// TODO Remove this. Should be done into the repair.php script +// TODO Remove this. Should be done always or into the repair.php script. if ($conf->global->MAIN_FEATURES_LEVEL > 1) print '' . $langs->trans("CleanFixHistory", $year_current) . ''; //print '
'; @@ -187,9 +187,9 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { } else { $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; } -$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy +$sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy -dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG); +dol_syslog('htdocs/accountancy/customer/index.php'); $result = $db->query($sql); if ($result) { $row = $db->fetch_row($result); @@ -203,10 +203,6 @@ $buttonbind = '' . $langs->trans("CleanHistory", $year_current) . ''; - - -$var = true; - print_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, ''); print '
'; -print ''; +print ''; print ''; -print ''; +print ''; print ''; @@ -264,8 +270,6 @@ print '
' . dol_print_date($line->doc_date) . '' . $line->doc_ref . '' . length_accountg($line->numero_compte) . '' . length_accounta($line->code_tiers) . '' . $line->label_compte . '' . length_accounta($line->subledger_account) . '' . $line->label_operation . '' . price($line->debit) . '' . price($line->credit) . '' . price($line->montant) . '
'; @@ -228,7 +224,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_factu $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation"; $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; -$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy +$sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NULL"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; @@ -237,7 +233,7 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { } $sql .= " GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label"; -dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG); +dol_syslog('htdocs/accountancy/customer/index.php sql=' . $sql, LOG_DEBUG); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -269,14 +265,14 @@ print '
'; print ''; print ''; for($i = 1; $i <= 12; $i ++) { - print ''; + print ''; } print ''; $sql = "SELECT " . $db->ifsql('aa.account_number IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.account_number') . " AS codecomptable,"; $sql .= " " . $db->ifsql('aa.label IS NULL', "'".$langs->trans('NotMatch')."'", 'aa.label') . " AS intitule,"; for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, 'fd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, 'fd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; } $sql .= " SUM(fd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; @@ -284,7 +280,7 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_factu $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation"; $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; -$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy +$sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; } else { @@ -293,25 +289,25 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND aa.account_number IS NOT NULL"; $sql .= " GROUP BY fd.fk_code_ventilation,aa.account_number,aa.label"; -dol_syslog("htdocs/accountancy/customer/index.php sql=" . $sql, LOG_DEBUG); +dol_syslog('htdocs/accountancy/customer/index.php'); $resql = $db->query($sql); if ($resql) { - $num = $db->num_rows($resql); + $num = $db->num_rows($resql); - while ( $row = $db->fetch_row($resql)) { + while ( $row = $db->fetch_row($resql)) { - print ''; - print ''; - for($i = 2; $i <= 12; $i ++) { - print ''; - } - print ''; - print ''; - print ''; - } - $db->free($resql); + print ''; + print ''; + for($i = 2; $i <= 12; $i ++) { + print ''; + } + print ''; + print ''; + print ''; + } + $db->free($resql); } else { - print $db->lasterror(); // Show last sql error + print $db->lasterror(); // Show last sql error } print "
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . length_accountg($row[0]) . '' . $row[1] . '' . price($row[$i]) . '' . price($row[13]) . '' . price($row[14]) . '
' . length_accountg($row[0]) . '' . $row[1] . '' . price($row[$i]) . '' . price($row[13]) . '' . price($row[14]) . '
\n"; @@ -319,101 +315,100 @@ print "\n"; if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. Why showing a report that should rely on result of this step ? { - print '
'; - print '
'; - - print_fiche_titre($langs->trans("OtherInfo"), '', ''); - - print "
\n"; - print ''; - print ''; - for($i = 1; $i <= 12; $i ++) { - print ''; - } - print ''; - - $sql = "SELECT '" . $langs->trans("TotalVente") . "' AS total,"; - for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, 'fd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; - } - $sql .= " SUM(fd.total_ht) as total"; - $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; - $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; - $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; - $sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; - } else { - $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; - } - - dol_syslog('htdocs/accountancy/customer/index.php'); - $resql = $db->query($sql); - if ($resql) { - $i = 0; - $num = $db->num_rows($resql); - - while ($row = $db->fetch_row($resql)) { - print ''; - for($i = 1; $i <= 12; $i ++) { - print ''; - } - print ''; - print ''; - $i ++; - } - $db->free($resql); - } else { - print $db->lasterror(); // Show last sql error - } - print "
' . $langs->trans("TotalVente") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . $row[0] . '' . price($row[$i]) . '' . price($row[13]) . '
\n"; - - if (! empty($conf->margin->enabled)) { - print "
\n"; - print ''; - print ''; - for($i = 1; $i <= 12; $i ++) { - print ''; - } - print ''; - - $sql = "SELECT '" . $langs->trans("Vide") . "' AS marge,"; - for($i = 1; $i <= 12; $i ++) { - $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, '(fd.total_ht-(fd.qty * fd.buy_price_ht))', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; - } - $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total"; - $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; - $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; - $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; - $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; - $sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; - } else { - $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; - } - - dol_syslog('htdocs/accountancy/customer/index.php:: $sql=' . $sql); - $resql = $db->query($sql); - if ($resql) { - $num = $db->num_rows($resql); - - while ($row = $db->fetch_row($resql)) { - - print ''; - for($i = 1; $i <= 12; $i ++) { - print ''; - } - print ''; - print ''; - } - $db->free($resql); - } else { - print $db->lasterror(); // Show last sql error - } - print "
' . $langs->trans("TotalMarge") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . $row[0] . '' . price(price2num($row[$i])) . '' . price(price2num($row[13])) . '
\n"; - } + print '
'; + print '
'; + + print_fiche_titre($langs->trans("OtherInfo"), '', ''); + + print "
\n"; + print ''; + print ''; + for($i = 1; $i <= 12; $i ++) { + print ''; + } + print ''; + + $sql = "SELECT '" . $langs->trans("TotalVente") . "' AS total,"; + for($i = 1; $i <= 12; $i ++) { + $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, 'fd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + } + $sql .= " SUM(fd.total_ht) as total"; + $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; + $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; + $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; + $sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { + $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; + } else { + $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; + } + + dol_syslog('htdocs/accountancy/customer/index.php'); + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + + while ($row = $db->fetch_row($resql)) { + print ''; + for($i = 1; $i <= 12; $i ++) { + print ''; + } + print ''; + print ''; + } + $db->free($resql); + } else { + print $db->lasterror(); // Show last sql error + } + print "
' . $langs->trans("TotalVente") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . $row[0] . '' . price($row[$i]) . '' . price($row[13]) . '
\n"; + + + if (! empty($conf->margin->enabled)) { + print "
\n"; + print ''; + print ''; + for($i = 1; $i <= 12; $i ++) { + print ''; + } + print ''; + + $sql = "SELECT '" . $langs->trans("Vide") . "' AS marge,"; + for($i = 1; $i <= 12; $i ++) { + $sql .= " SUM(" . $db->ifsql('MONTH(f.datef)=' . $i, '(fd.total_ht-(fd.qty * fd.buy_price_ht))', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; + } + $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total"; + $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; + $sql .= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; + $sql .= " AND f.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; + $sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { + $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; + } else { + $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; + } + + dol_syslog('htdocs/accountancy/customer/index.php'); + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + + while ($row = $db->fetch_row($resql)) { + + print ''; + for($i = 1; $i <= 12; $i ++) { + print ''; + } + print ''; + print ''; + } + $db->free($resql); + } else { + print $db->lasterror(); // Show last sql error + } + print "
' . $langs->trans("TotalMarge") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . $row[0] . '' . price(price2num($row[$i])) . '' . price(price2num($row[13])) . '
\n"; + } } diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index f3763dd9ca0..d6d006c6556 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2016 Alexandre Spangaro * Copyright (C) 2014-2015 Ari Elbaz (elarifr) * Copyright (C) 2014-2016 Florian Henry * Copyright (C) 2014 Juanjo Menent @@ -55,7 +55,7 @@ $search_country = GETPOST('search_country', 'alpha'); $search_tvaintra = GETPOST('search_tvaintra', 'alpha'); // Load variable for pagination -$limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page', 'int'); @@ -121,7 +121,7 @@ if (is_array($changeaccount) && count($changeaccount) > 0) { $db->rollback(); setEventMessages($db->lasterror(), null, 'errors'); } - + $account_parent = ''; // Protection to avoid to mass apply it a second time } @@ -164,7 +164,7 @@ $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_factu $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_country as co ON co.rowid = s.fk_pays "; $sql .= " WHERE fd.fk_code_ventilation > 0 "; -$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy +$sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy $sql .= " AND f.fk_statut > 0"; if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; @@ -201,7 +201,7 @@ if (strlen(trim($search_country))) { if (strlen(trim($search_tvaintra))) { $sql .= natural_search("s.tva_intra", $search_tva_intra); } -$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy +$sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy $sql .= $db->order($sortfield, $sortorder); // Count total nb of records @@ -240,7 +240,7 @@ if ($result) { if ($search_tvaintra) $param .= "&search_tvaintra=" . $search_tvaintra; - + print '
' . "\n"; print ''; if ($optioncss != '') print ''; @@ -249,7 +249,7 @@ if ($result) { print ''; print ''; print ''; - + print_barre_liste($langs->trans("InvoiceLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit); print $langs->trans("DescVentilDoneCustomer") . '
'; @@ -317,7 +317,7 @@ if ($result) { print '' . $facture_static->getNomUrl(1) . ''; print '' . dol_print_date($db->jdate($objp->datef), 'day') . ''; - + // Ref Product print ''; if ($product_static->id) @@ -327,7 +327,7 @@ if ($result) { print ''; $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description)); - $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32; + $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION; print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description); print ''; @@ -355,7 +355,7 @@ if ($result) { if ($nbtotalofrecords > $limit) { print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1); } - + print '
'; } else { print $db->lasterror(); diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 8af289f2c99..75c1a59aa30 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -1,6 +1,6 @@ - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2016 Alexandre Spangaro * Copyright (C) 2014-2015 Ari Elbaz (elarifr) * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2014 Juanjo Menent @@ -63,7 +63,7 @@ $search_vat = GETPOST('search_vat', 'alpha'); $btn_ventil = GETPOST('ventil', 'alpha'); // Load variable for pagination -$limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page','int'); @@ -144,10 +144,10 @@ if ($massaction == 'ventil') { $sql = " UPDATE " . MAIN_DB_PREFIX . "facturedet"; $sql .= " SET fk_code_ventilation = " . $monCompte; $sql .= " WHERE rowid = " . $monId; - + $accountventilated = new AccountingAccount($db); $accountventilated->fetch($monCompte, ''); - + dol_syslog("/accountancy/customer/list.php sql=" . $sql, LOG_DEBUG); if ($db->query($sql)) { $msg.= '
' . $langs->trans("Lineofinvoice") . ' ' . $monId . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '
'; @@ -157,7 +157,7 @@ if ($massaction == 'ventil') { $ko++; } } - + $cpt++; } $msg.='
'; @@ -220,7 +220,7 @@ if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { } else { $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_STANDARD . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; } -$sql .= " AND f.entity IN (" . getEntity("facture", 0) . ")"; // We don't share object for accountancy +$sql .= " AND f.entity IN (" . getEntity('facture', 0) . ")"; // We don't share object for accountancy $sql .= $db->order($sortfield, $sortorder); @@ -375,10 +375,10 @@ if ($result) { print ''; $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->description)); - $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32; + $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION; print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->description); print ''; - + print ''; print price($objp->total_ht); print ''; @@ -404,7 +404,7 @@ if ($result) { print ''; print $formaccounting->select_account($objp->aarowid_suggest, 'codeventil'.$objp->rowid, 1, array(), 0, 0, 'maxwidth300 maxwidthonsmartphone', 'cachewithshowemptyone'); print ''; - + print ''; print 'aarowid ? "checked" : "") . '/>'; print ''; diff --git a/htdocs/accountancy/expensereport/card.php b/htdocs/accountancy/expensereport/card.php index e37b35f1003..1c94b0b649a 100644 --- a/htdocs/accountancy/expensereport/card.php +++ b/htdocs/accountancy/expensereport/card.php @@ -96,7 +96,7 @@ if (! empty($id)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON erd.fk_code_ventilation = aa.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport"; $sql .= " WHERE er.fk_statut > 0 AND erd.rowid = " . $id; - $sql .= " AND er.entity IN (" . getEntity("expensereport", 0) . ")"; // We don't share object for accountancy + $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy dol_syslog("/accounting/expensereport/card.php sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); diff --git a/htdocs/accountancy/expensereport/index.php b/htdocs/accountancy/expensereport/index.php index c062d4e09c2..b17aeedb4bd 100644 --- a/htdocs/accountancy/expensereport/index.php +++ b/htdocs/accountancy/expensereport/index.php @@ -69,7 +69,7 @@ if ($action == 'validatehistory') { // First clean corrupted data $sqlclean = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd"; - $sqlclean .= " SET erd.fk_code_ventilation = 0"; + $sqlclean .= " SET fk_code_ventilation = 0"; $sqlclean .= ' WHERE erd.fk_code_ventilation NOT IN '; $sqlclean .= ' (SELECT accnt.rowid '; $sqlclean .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; @@ -93,6 +93,8 @@ if ($action == 'validatehistory') { $sql1 .= " AND erd.fk_code_ventilation = 0"; } + dol_syslog('htdocs/accountancy/expensereport/index.php'); + $resql1 = $db->query($sql1); if (! $resql1) { $error ++; @@ -107,7 +109,7 @@ if ($action == 'validatehistory') { $db->begin(); $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd"; - $sql1 .= " SET erd.fk_code_ventilation = 0"; + $sql1 .= " SET fk_code_ventilation = 0"; $sql1 .= ' WHERE erd.fk_code_ventilation NOT IN '; $sql1 .= ' (SELECT accnt.rowid '; $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; @@ -129,12 +131,13 @@ if ($action == 'validatehistory') { $error = 0; $db->begin(); + // Now clean $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd"; - $sql1.= " SET erd.fk_code_ventilation = 0"; + $sql1.= " SET fk_code_ventilation = 0"; $sql1.= " WHERE erd.fk_expensereport IN ( SELECT er.rowid FROM " . MAIN_DB_PREFIX . "expensereport as er"; $sql1.= " WHERE er.date_debut >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'"; $sql1.= " AND er.date_debut <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "'"; - $sql1.= " AND er.entity IN (" . getEntity("accountancy", 1) . ")"; + $sql1.= " AND er.entity IN (" . getEntity('accountancy') . ")"; $sql1.=")"; dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); @@ -166,28 +169,25 @@ print $langs->trans("DescVentilExpenseReportMore", $langs->transnoentitiesnoconv print '
'; //print '
'; -// TODO Remove this. Should be done always. +// TODO Remove this. Should be done always or into the repair.php script. if ($conf->global->MAIN_FEATURES_LEVEL > 1) print '' . $langs->trans("CleanFixHistory", $year_current) . ''; //print '
'; -$buttonbind = '' . $langs->trans("ValidateHistory") . ''; -$buttonreset = '' . $langs->trans("CleanHistory", $year_current) . ''; $y = $year_current; -$var = true; +$buttonbind = '' . $langs->trans("ValidateHistory") . ''; +$buttonreset = '' . $langs->trans("CleanHistory", $year_current) . ''; -print '
'; - print_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, ''); print ''; -print ''; +print ''; print ''; for($i = 1; $i <= 12; $i ++) { print ''; @@ -199,14 +199,14 @@ $sql .= " " . $db->ifsql('aa.label IS NULL', "'".$langs->trans('NotMatch')."'", for($i = 1; $i <= 12; $i ++) { $sql .= " SUM(" . $db->ifsql('MONTH(er.date_debut)=' . $i, 'erd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; } -$sql .= " ROUND(SUM(erd.total_ht),2) as total"; +$sql .= " SUM(erd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport_det as erd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = erd.fk_code_ventilation"; $sql .= " WHERE er.date_debut >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND er.date_debut <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; $sql .= " AND er.fk_statut > 0 "; -$sql .= " AND er.entity IN (" . getEntity("expensereport", 0) . ")"; // We don't share object for accountancy +$sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NULL"; $sql .= " GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label"; @@ -240,7 +240,7 @@ print_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), $buttonreset, ' print '
' . $langs->trans("Account") . '
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '
'; -print ''; +print ''; print ''; for($i = 1; $i <= 12; $i ++) { print ''; @@ -259,11 +259,11 @@ $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = $sql .= " WHERE er.date_debut >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND er.date_debut <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; $sql .= " AND er.fk_statut > 0 "; -$sql .= " AND er.entity IN (" . getEntity("expensereport", 0) . ")"; // We don't share object for accountancy +$sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NOT NULL"; $sql .= " GROUP BY erd.fk_code_ventilation,aa.account_number,aa.label"; -dol_syslog('/accountancy/expensereport/index.php:: sql=' . $sql); +dol_syslog('htdocs/accountancy/expensereport/index.php'); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -307,22 +307,20 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. for($i = 1; $i <= 12; $i ++) { $sql .= " SUM(" . $db->ifsql('MONTH(er.date_create)=' . $i, 'erd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; } - $sql .= " ROUND(SUM(erd.total_ht),2) as total"; + $sql .= " SUM(erd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport_det as erd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport"; $sql .= " WHERE er.date_debut >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND er.date_debut <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; $sql .= " AND er.fk_statut > 0 "; - $sql .= " AND er.entity IN (" . getEntity("expensereport", 0) . ")"; // We don't share object for accountancy + $sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy - dol_syslog('/accountancy/expensereport/index.php:: sql=' . $sql); + dol_syslog('htdocs/accountancy/expensereport/index.php'); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); while ( $row = $db->fetch_row($resql)) { - - print ''; for($i = 1; $i <= 12; $i ++) { print ''; diff --git a/htdocs/accountancy/expensereport/lines.php b/htdocs/accountancy/expensereport/lines.php index b3936bbf1a6..2237f578069 100644 --- a/htdocs/accountancy/expensereport/lines.php +++ b/htdocs/accountancy/expensereport/lines.php @@ -1,10 +1,10 @@ * Copyright (C) 2013-2017 Alexandre Spangaro - * Copyright (C) 2014-2015 Ari Elbaz (elarifr) + * Copyright (C) 2014-2015 Ari Elbaz (elarifr) * Copyright (C) 2013-2016 Florian Henry * Copyright (C) 2014 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 * the Free Software Foundation; either version 3 of the License, or @@ -52,7 +52,7 @@ $search_account = GETPOST('search_account', 'alpha'); $search_vat = GETPOST('search_vat', 'alpha'); // Load variable for pagination -$limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page', 'int'); @@ -94,13 +94,13 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP if (is_array($changeaccount) && count($changeaccount) > 0) { $error = 0; - + $db->begin(); - + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "expensereport_det as erd"; $sql1 .= " SET erd.fk_code_ventilation=" . GETPOST('account_parent'); $sql1 .= ' WHERE erd.rowid IN (' . implode(',', $changeaccount) . ')'; - + dol_syslog('accountancy/expensereport/lines.php::changeaccount sql= ' . $sql1); $resql1 = $db->query($sql1); if (! $resql1) { @@ -173,7 +173,7 @@ if (strlen(trim($search_account))) { if (strlen(trim($search_vat))) { $sql .= " AND (erd.tva_tx like '" . $search_vat . "%')"; } -$sql .= " AND er.entity IN (" . getEntity("expensereport", 0) . ")"; // We don't share object for accountancy +$sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy $sql .= $db->order($sortfield, $sortorder); @@ -193,7 +193,7 @@ $result = $db->query($sql); if ($result) { $num_lines = $db->num_rows($result); $i = 0; - + $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; @@ -210,8 +210,8 @@ if ($result) { if ($search_country) $param .= "&search_country=" . $search_country; if ($search_tvaintra) - $param .= "&search_tvaintra=" . $search_tvaintra; - + $param .= "&search_tvaintra=" . $search_tvaintra; + print '
' . "\n"; print ''; if ($optioncss != '') print ''; @@ -220,7 +220,7 @@ if ($result) { print ''; print ''; print ''; - + print_barre_liste($langs->trans("ExpenseReportLinesDone"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit); print $langs->trans("DescVentilDoneExpenseReport") . '
'; @@ -273,7 +273,7 @@ if ($result) { $expensereport_static->ref = $objp->ref; $expensereport_static->id = $objp->erid; - + print '
'; print ''; @@ -282,12 +282,12 @@ if ($result) { print ''; print ''; - + print ''; print ''; @@ -300,20 +300,20 @@ if ($result) { print ''; - + print ''; - + print ""; $i ++; } - + print "
' . $langs->trans("Account") . '
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '
' . $row[0] . '' . price($row[$i]) . '
' . $objp->rowid . '' . $expensereport_static->getNomUrl(1) . '' . dol_print_date($db->jdate($objp->date), 'day') . '' . ($langs->trans($objp->type_fees_code) == $objp->type_fees_code ? $objp->type_fees_label : $langs->trans(($objp->type_fees_code))) . ''; $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments)); - $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32; + $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION; print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->comments); print ''; print img_edit(); print '
"; print "
"; - + if ($nbtotalofrecords > $limit) { print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num_lines, $nbtotalofrecords, '', 0, '', '', $limit, 1); } - + print ''; } else { print $db->error(); diff --git a/htdocs/accountancy/expensereport/list.php b/htdocs/accountancy/expensereport/list.php index b1a86c96838..8e7b9c60c92 100644 --- a/htdocs/accountancy/expensereport/list.php +++ b/htdocs/accountancy/expensereport/list.php @@ -61,7 +61,7 @@ $search_vat = GETPOST('search_vat', 'alpha'); $btn_ventil = GETPOST('ventil', 'alpha'); // Load variable for pagination -$limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page','int'); @@ -139,10 +139,10 @@ if ($massaction == 'ventil') { $sql = " UPDATE " . MAIN_DB_PREFIX . "expensereport_det"; $sql .= " SET fk_code_ventilation = " . $monCompte; $sql .= " WHERE rowid = " . $monId; - + $accountventilated = new AccountingAccount($db); $accountventilated->fetch($monCompte, ''); - + dol_syslog('accountancy/expensereport/list.php:: sql=' . $sql, LOG_DEBUG); if ($db->query($sql)) { $msg.= '
' . $langs->trans("LineOfExpenseReport") . ' ' . $monId . ' - ' . $langs->trans("VentilatedinAccount") . ' : ' . length_accountg($accountventilated->account_number) . '
'; @@ -152,7 +152,7 @@ if ($massaction == 'ventil') { $ko++; } } - + $cpt++; } $msg.=''; @@ -203,7 +203,7 @@ if (strlen(trim($search_account))) { if (strlen(trim($search_vat))) { $sql .= natural_search("erd.tva_tx",$search_vat,1); } -$sql .= " AND er.entity IN (" . getEntity("expensereport", 0) . ")"; // We don't share object for accountancy +$sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy $sql .= $db->order($sortfield, $sortorder); @@ -224,7 +224,7 @@ if ($result) { $i = 0; $arrayofselected=is_array($toselect)?$toselect:array(); - + $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; @@ -237,8 +237,8 @@ if ($result) { //if ($user->rights->mymodule->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete"); //if ($massaction == 'presend') $arrayofmassactions=array(); $massactionbutton=$form->selectMassAction('ventil', $arrayofmassactions, 1); - - + + print '
' . "\n"; print ''; if ($optioncss != '') print ''; @@ -247,7 +247,7 @@ if ($result) { print ''; print ''; print ''; - + print_barre_liste($langs->trans("ExpenseReportLines"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num_lines, $nbtotalofrecords, 'title_accountancy', 0, '', '', $limit); print $langs->trans("DescVentilTodoExpenseReport") . '

'; @@ -290,8 +290,8 @@ if ($result) { if ($massactionbutton) $checkpicto=$form->showCheckAddButtons('checkforselect', 1); print_liste_field_titre($checkpicto, '', '', '', '', 'align="center"'); print "\n"; - - + + $expensereport_static = new ExpenseReport($db); $form = new Form($db); @@ -323,7 +323,7 @@ if ($result) { // Fees description -- Can be null print ''; $text = dolGetFirstLineOfText(dol_string_nohtmltag($objp->comments)); - $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION') ? ACCOUNTING_LENGTH_DESCRIPTION : 32; + $trunclength = empty($conf->global->ACCOUNTING_LENGTH_DESCRIPTION) ? 32 : $conf->global->ACCOUNTING_LENGTH_DESCRIPTION; print $form->textwithtooltip(dol_trunc($text,$trunclength), $objp->comments); print ''; @@ -356,7 +356,7 @@ if ($result) { print ''; print ""; - + print '
'; } else { print $db->error(); diff --git a/htdocs/accountancy/index.php b/htdocs/accountancy/index.php index c7caa5daac3..bf3e80fe866 100644 --- a/htdocs/accountancy/index.php +++ b/htdocs/accountancy/index.php @@ -45,10 +45,13 @@ $langs->load("compta"); $langs->load("banks"); $langs->load("loans"); + /* * Actions */ +// None + /* * View @@ -60,8 +63,6 @@ print load_fiche_titre($langs->trans("AccountancyArea"), '', 'title_accountancy' $step = 0; -print "
\n"; - print $langs->trans("AccountancyAreaDescIntro")."
\n"; print "
\n";print "
\n"; @@ -73,35 +74,31 @@ print "
\n"; $step++; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescJournalSetup", $step, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("AccountingJournals").''); print "
\n"; -print "
\n"; $step++; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescChartModel", $step, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("Pcg_version").''); print "
\n"; -print "
\n"; $step++; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescChart", $step, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("Chartofaccounts").''); print "
\n"; -print "
\n"; +print "
\n"; print $langs->trans("AccountancyAreaDescActionOnceBis"); print "
\n"; print "
\n"; $step++; -print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescMisc", $step, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'')."
\n"; +print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescMisc", $step, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").'')."\n"; print "
\n"; $step++; $textlink = ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup").'-'.$langs->transnoentitiesnoconv("MenuVatAccounts").''; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescVat", $step, $textlink); print "
\n"; -print "
\n"; if (! empty($conf->tax->enabled)) { $textlink = ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup").'-'.$langs->transnoentitiesnoconv("MenuTaxAccounts").''; $step++; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescContrib", $step, $textlink); print "
\n"; - print "
\n"; } /*if (! empty($conf->salaries->enabled)) { @@ -116,7 +113,6 @@ if (! empty($conf->expensereport->enabled)) // TODO Move this in the default ac $step++; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescExpenseReport", $step, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuExpenseReportAccounts").''); print "
\n"; - print "
\n"; } /* if (! empty($conf->loan->enabled)) @@ -124,26 +120,22 @@ if (! empty($conf->loan->enabled)) $step++; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescLoan", $step, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuSpecialExpenses").'-'.$langs->transnoentitiesnoconv("Loans").' '.$langs->transnoentitiesnoconv("or").' '.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); print "
\n"; - print "
\n"; } if (! empty($conf->don->enabled)) { $step++; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescDonation", $step, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDonationAccounts").''); print "
\n"; - print "
\n"; }*/ $step++; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescProd", $step, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("ProductsBinding").''); print "
\n"; -print "
\n"; $step++; $textlink=''.$langs->transnoentitiesnoconv("MenuBankCash").''; print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescBank", $step, $textlink); print "
\n"; -print "
\n"; print "
\n"; @@ -155,19 +147,19 @@ $step = 0; $langs->loadLangs(array('bills', 'trips')); $step++; -print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescBind", chr(64+$step), $langs->transnoentitiesnoconv("BillsCustomers"), ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy")."-".$langs->transnoentitiesnoconv("CustomersVentilation").'')."
\n"; +print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescBind", chr(64+$step), $langs->transnoentitiesnoconv("BillsCustomers"), ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy")."-".$langs->transnoentitiesnoconv("CustomersVentilation").'')."\n"; print "
\n"; $step++; -print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescBind", chr(64+$step), $langs->transnoentitiesnoconv("BillsSuppliers"), ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy")."-".$langs->transnoentitiesnoconv("SuppliersVentilation").'')."
\n"; +print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescBind", chr(64+$step), $langs->transnoentitiesnoconv("BillsSuppliers"), ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy")."-".$langs->transnoentitiesnoconv("SuppliersVentilation").'')."\n"; print "
\n"; $step++; -print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescBind", chr(64+$step), $langs->transnoentitiesnoconv("ExpenseReports"), ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy")."-".$langs->transnoentitiesnoconv("ExpenseReportsVentilation").'')."
\n"; +print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescBind", chr(64+$step), $langs->transnoentitiesnoconv("ExpenseReports"), ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy")."-".$langs->transnoentitiesnoconv("ExpenseReportsVentilation").'')."\n"; print "
\n"; $step++; -print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescWriteRecords", chr(64+$step), $langs->transnoentitiesnoconv("Journalization"), $langs->transnoentitiesnoconv("WriteBookKeeping"))."
\n"; +print img_picto('', 'puce').' '.$langs->trans("AccountancyAreaDescWriteRecords", chr(64+$step), $langs->transnoentitiesnoconv("Journalization"), $langs->transnoentitiesnoconv("WriteBookKeeping"))."\n"; print "
\n"; $step++; diff --git a/htdocs/accountancy/journal/bankjournal.php b/htdocs/accountancy/journal/bankjournal.php index ea98d678671..ed8d1d7501a 100644 --- a/htdocs/accountancy/journal/bankjournal.php +++ b/htdocs/accountancy/journal/bankjournal.php @@ -28,8 +28,6 @@ * \brief Page with bank journal */ require '../../main.inc.php'; - -// Class require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/bank.lib.php'; @@ -40,6 +38,7 @@ require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT . '/adherents/class/adherent.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/sociales/class/chargesociales.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/paiement/class/paiement.class.php'; +require_once DOL_DOCUMENT_ROOT . '/don/class/don.class.php'; require_once DOL_DOCUMENT_ROOT . '/don/class/paymentdonation.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/salaries/class/paymentsalary.class.php'; @@ -51,9 +50,8 @@ require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; require_once DOL_DOCUMENT_ROOT . '/societe/class/client.class.php'; require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT . '/expensereport/class/paymentexpensereport.class.php'; +require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/paymentvarious.class.php'; - -// Langs $langs->load("companies"); $langs->load("other"); $langs->load("compta"); @@ -62,12 +60,11 @@ $langs->load('bills'); $langs->load('donations'); $langs->load("accountancy"); $langs->load("trips"); +$langs->load("salaries"); $langs->load("hrm"); -// Old system menu -$id_bank_account = GETPOST('id_account', 'int'); // Multi journal -$code_journal = GETPOST('code_journal', 'alpha'); +$id_journal = GETPOST('id_journal', 'int'); $date_startmonth = GETPOST('date_startmonth'); $date_startday = GETPOST('date_startday'); @@ -75,12 +72,13 @@ $date_startyear = GETPOST('date_startyear'); $date_endmonth = GETPOST('date_endmonth'); $date_endday = GETPOST('date_endday'); $date_endyear = GETPOST('date_endyear'); -$action = GETPOST('action','aZ09'); +$in_bookkeeping = GETPOST('in_bookkeeping'); $now = dol_now(); +$action = GETPOST('action','alpha'); // Security check -if ($user->societe_id > 0 && empty($id_bank_account)) +if ($user->societe_id > 0 && empty($id_journal)) accessforbidden(); @@ -107,23 +105,24 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false); } -$p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY); -$idpays = $p[0]; +$idpays = $mysoc->country_id; $sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro, b.num_releve, b.num_chq, b.fk_type,"; -$sql .= " ba.courant, ba.ref as baref, ba.account_number,"; +$sql .= " ba.courant, ba.ref as baref, ba.account_number, ba.fk_accountancy_journal,"; $sql .= " soc.code_compta, soc.code_compta_fournisseur, soc.rowid as socid, soc.nom as name, bu1.type as typeop,"; -$sql .= " u.accountancy_code, u.rowid as userid, u.lastname as name, u.firstname as firstname, bu2.type as typeop"; +$sql .= " u.accountancy_code, u.rowid as userid, u.lastname as lastname, u.firstname as firstname, bu2.type as typeop"; $sql .= " FROM " . MAIN_DB_PREFIX . "bank as b"; $sql .= " JOIN " . MAIN_DB_PREFIX . "bank_account as ba on b.fk_account=ba.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu1 ON bu1.fk_bank = b.rowid AND bu1.type='company'"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "bank_url as bu2 ON bu2.fk_bank = b.rowid AND bu2.type='user'"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as soc on bu1.url_id=soc.rowid"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "user as u on bu2.url_id=u.rowid"; -$sql .= " WHERE ba.rowid=" . $id_bank_account; -$sql .= ' AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy +$sql .= " WHERE ba.fk_accountancy_journal=" . $id_journal; +$sql .= ' AND ba.entity IN ('.getEntity('bank_account', 0).')'; // We don't share object for accountancy if ($date_start && $date_end) $sql .= " AND b.dateo >= '" . $db->idate($date_start) . "' AND b.dateo <= '" . $db->idate($date_end) . "'"; +if ($in_bookkeeping == 'yes') + $sql .= " AND (b.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='bank') )"; $sql .= " ORDER BY b.datev"; $object = new Account($db); @@ -136,29 +135,20 @@ $paymentdonstatic = new PaymentDonation($db); $paymentvatstatic = new TVA($db); $paymentsalstatic = new PaymentSalary($db); $paymentexpensereportstatic = new PaymentExpenseReport($db); +$paymentvariousstatic = new PaymentVarious($db); // Get code of finance journal -$journal = ''; -$bankstatic = new Account($db); -$bankstatic->fetch($id_bank_account); -$bankstatic->rowid; -$bankstatic->number; -$bankstatic->label; -$bankstatic->fk_accountancy_journal; - $accountingjournalstatic = new AccountingJournal($db); -if(! empty($id_bank_account)) { - $accountingjournalstatic->fetch($bankstatic->fk_accountancy_journal); -} else { - $accountingjournalstatic->fetch('',$code_journal); -} +$accountingjournalstatic->fetch($id_journal); $journal = $accountingjournalstatic->code; +$journal_label = $accountingjournalstatic->label; dol_syslog("accountancy/journal/bankjournal.php", LOG_DEBUG); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); + // Variables $account_supplier = (! empty($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) ? $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER : $langs->trans("CodeNotDef")); $account_customer = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef")); @@ -179,7 +169,7 @@ if ($result) { // one line for bank jounral = tabbq // one line for thirdparty journal = tabtp $i = 0; - while ( $i < $num ) + while ( $i < $num ) { $obj = $db->fetch_object($result); @@ -193,16 +183,17 @@ if ($result) { $tabcompany[$obj->rowid] = array ( 'id' => $obj->socid, 'name' => $obj->name, - 'code_compta' => $compta_soc, + 'code_compta' => $compta_soc, ); $compta_user = (! empty($obj->accountancy_code) ? $obj->accountancy_code : $account_employee); $tabuser[$obj->rowid] = array ( 'id' => $obj->userid, + 'name' => dolGetFirstLastname($obj->firstname, $obj->lastname), 'lastname' => $obj->lastname, 'firstname' => $obj->firstname, - 'accountancy_code' => $compta_user, + 'accountancy_code' => $compta_user, ); // Variable bookkeeping @@ -219,14 +210,14 @@ if ($result) { // get_url may return -1 which is not traversable if (is_array($links)) { - // Now loop on each link of record in bank. + // Now loop on each link of record in bank. foreach ( $links as $key => $val ) { - if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert'))) // So we excluded 'company' here - { - // We save tabtype for a future use, to remember what kind of payment it is - $tabtype[$obj->rowid] = $links[$key]['type']; - } + if (in_array($links[$key]['type'], array('sc', 'payment_sc', 'payment', 'payment_supplier', 'payment_vat', 'payment_expensereport', 'banktransfert', 'payment_donation', 'payment_salary', 'payment_various'))) // So we excluded 'company' here + { + // We save tabtype for a future use, to remember what kind of payment it is + $tabtype[$obj->rowid] = $links[$key]['type']; + } if ($links[$key]['type'] == 'payment') { $paymentstatic->id = $links[$key]['url_id']; @@ -264,9 +255,9 @@ if ($result) { $sqlmid = 'SELECT cchgsoc.accountancy_code'; $sqlmid .= " FROM " . MAIN_DB_PREFIX . "c_chargesociales cchgsoc "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "chargesociales as chgsoc ON chgsoc.fk_type=cchgsoc.id"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paycharg ON paycharg.fk_charge=chgsoc.rowid"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "bank_url as bkurl ON bkurl.url_id=paycharg.rowid"; $sqlmid .= " WHERE bkurl.fk_bank=" . $obj->rowid; dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); @@ -278,25 +269,36 @@ if ($result) { } else if ($links[$key]['type'] == 'payment_donation') { $paymentdonstatic->id = $links[$key]['url_id']; $paymentdonstatic->fk_donation = $links[$key]['url_id']; - $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("PaymentDonation"); + $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentdonstatic->getNomUrl(2); + $tabpay[$obj->rowid]["paymentdonationid"] = $paymentdonstatic->id; $tabtp[$obj->rowid][$account_pay_donation] += $obj->amount; } else if ($links[$key]['type'] == 'payment_vat') { $paymentvatstatic->id = $links[$key]['url_id']; $paymentvatstatic->ref = $links[$key]['url_id']; $paymentvatstatic->label = $links[$key]['label']; - $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("PaymentVat"); + $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvatstatic->getNomUrl(2); + $tabpay[$obj->rowid]["paymentvatid"] = $paymentvatstatic->id; $tabtp[$obj->rowid][$account_pay_vat] += $obj->amount; } else if ($links[$key]['type'] == 'payment_salary') { $paymentsalstatic->id = $links[$key]['url_id']; $paymentsalstatic->ref = $links[$key]['url_id']; $paymentsalstatic->label = $links[$key]['label']; $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentsalstatic->getNomUrl(2); - // $tabtp[$obj->rowid][$account_employee] += $obj->amount; + $tabpay[$obj->rowid]["paymentsalid"] = $paymentsalstatic->id; } else if ($links[$key]['type'] == 'payment_expensereport') { $paymentexpensereportstatic->id = $links[$key]['url_id']; $paymentexpensereportstatic->fk_expensereport = $links[$key]['url_id']; $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentexpensereportstatic->getNomUrl(2); $tabpay[$obj->rowid]["fk_expensereport"] = $paymentexpensereportstatic->id; + } else if ($links[$key]['type'] == 'payment_various') { + $paymentvariousstatic->id = $links[$key]['url_id']; + $paymentvariousstatic->ref = $links[$key]['url_id']; + $paymentvariousstatic->label = $links[$key]['label']; + $tabpay[$obj->rowid]["lib"] .= ' ' . $paymentvariousstatic->getNomUrl(2); + $tabpay[$obj->rowid]["paymentvariousid"] = $paymentvariousstatic->id; + $paymentvariousstatic->fetch($paymentvariousstatic->id); + $account_various = (! empty($paymentvariousstatic->accountancy_code) ? $paymentvariousstatic->accountancy_code : $langs->trans("CodeNotDef")); + $tabtp[$obj->rowid][$account_various] += $obj->amount; } else if ($links[$key]['type'] == 'banktransfert') { $tabpay[$obj->rowid]["lib"] .= ' ' . $langs->trans("BankTransfer"); $tabtp[$obj->rowid][$account_transfer] += $obj->amount; @@ -306,26 +308,26 @@ if ($result) { $tabbq[$obj->rowid][$compta_bank] += $obj->amount; - + // Check account number is ok - /*if ($action == 'writebookkeeping') // Make test now in such a case + /*if ($action == 'writebookkeeping') // Make test now in such a case { - reset($tabbq[$obj->rowid]); - $first_key_tabbq = key($tabbq[$obj->rowid]); - if (empty($first_key_tabbq)) - { - $error++; - setEventMessages($langs->trans('ErrorAccountancyCodeOnBankAccountNotDefined', $obj->baref), null, 'errors'); - } - reset($tabtp[$obj->rowid]); - $first_key_tabtp = key($tabtp[$obj->rowid]); - if (empty($first_key_tabtp)) - { - $error++; - setEventMessages($langs->trans('ErrorAccountancyCodeOnThirdPartyNotDefined'), null, 'errors'); - } + reset($tabbq[$obj->rowid]); + $first_key_tabbq = key($tabbq[$obj->rowid]); + if (empty($first_key_tabbq)) + { + $error++; + setEventMessages($langs->trans('ErrorAccountancyCodeOnBankAccountNotDefined', $obj->baref), null, 'errors'); + } + reset($tabtp[$obj->rowid]); + $first_key_tabtp = key($tabtp[$obj->rowid]); + if (empty($first_key_tabtp)) + { + $error++; + setEventMessages($langs->trans('ErrorAccountancyCodeOnThirdPartyNotDefined'), null, 'errors'); + } }*/ - + // if($obj->socid)$tabtp[$obj->rowid][$compta_soc] += $obj->amount; $i ++; @@ -345,206 +347,271 @@ if (! $error && $action == 'writebookkeeping') { $now = dol_now(); $error = 0; - foreach ( $tabpay as $key => $val ) { // $key is rowid into llx_bank + foreach ( $tabpay as $key => $val ) { // $key is rowid into llx_bank - $errorforline = 0; + $errorforline = 0; - $db->begin(); + $db->begin(); // Bank if (! $errorforline) { - // Line into bank account - foreach ( $tabbq[$key] as $k => $mt ) - { - if ($mt) { - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->doc_type = 'bank'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = $val["fk_bank"]; - $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = $compte->label; - $bookkeeping->montant = ($mt < 0 ? - $mt : $mt); - $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; - $bookkeeping->debit = ($mt >= 0 ? $mt : 0); - $bookkeeping->credit = ($mt < 0 ? - $mt : 0); - $bookkeeping->code_journal = $journal; - $bookkeeping->fk_user_author = $user->id; - $bookkeeping->date_create = $now; - - if ($tabtype[$key] == 'payment') { - $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; - - $sqlmid = 'SELECT fac.facnumber'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; - $sqlmid .= " WHERE pay.fk_bank=" . $key; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; // Ref of invoice - } - } else if ($tabtype[$key] == 'payment_supplier') { - $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; - - $sqlmid = 'SELECT facf.ref_supplier, facf.ref'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; - $sqlmid .= " WHERE payf.fk_bank=" . $key; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; // Ref on invoice - } - } else if ($tabtype[$key] == 'payment_expensereport') { - $bookkeeping->code_tiers = $tabuser[$key]['accountancy_code']; - - $sqlmid = 'SELECT e.ref'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "expensereport as e"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_expensereport as payer ON payer.fk_expensereport=e.rowid"; - $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"]; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport - } - } - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists - { - $error++; - $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } - else - { - $error++; - $errorforline++; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } + // Line into bank account + foreach ( $tabbq[$key] as $k => $mt ) + { + if ($mt) { + $bookkeeping = new BookKeeping($db); + $bookkeeping->doc_date = $val["date"]; + $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->doc_type = 'bank'; + $bookkeeping->fk_doc = $key; + $bookkeeping->fk_docdet = $val["fk_bank"]; + $bookkeeping->numero_compte = $k; + $bookkeeping->label_operation = $val["label"]; + $bookkeeping->label_compte = $langs->trans("Bank"); + $bookkeeping->montant = ($mt < 0 ? - $mt : $mt); + $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; + $bookkeeping->debit = ($mt >= 0 ? $mt : 0); + $bookkeeping->credit = ($mt < 0 ? - $mt : 0); + $bookkeeping->code_journal = $journal; + $bookkeeping->journal_label = $journal_label; + $bookkeeping->fk_user_author = $user->id; + $bookkeeping->date_create = $now; + + if ($tabtype[$key] == 'payment') { + $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; + + $sqlmid = 'SELECT fac.facnumber'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; + $sqlmid .= " WHERE pay.fk_bank=" . $key; + dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $bookkeeping->doc_ref = $objmid->facnumber; // Ref of invoice + } + } else if ($tabtype[$key] == 'payment_supplier') { + $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; + + $sqlmid = 'SELECT facf.ref_supplier, facf.ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; + $sqlmid .= " WHERE payf.fk_bank=" . $key; + dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; // Ref on invoice + } + } else if ($tabtype[$key] == 'payment_expensereport') { + $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; + + $sqlmid = 'SELECT e.ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "expensereport as e"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_expensereport as payer ON payer.fk_expensereport=e.rowid"; + $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"]; + dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport + } + } else if ($tabtype[$key] == 'payment_vat') { + $bookkeeping->subledger_account = ''; + $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat payment + } else if ($tabtype[$key] == 'payment_donation') { + $bookkeeping->subledger_account = ''; + $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation + } else if ($tabtype[$key] == 'payment_salary') { + $bookkeeping->subledger_account = ''; + $bookkeeping->label_operation = $tabuser[$key]['name']; + $bookkeeping->doc_ref = $langs->trans("SalaryPayment") . ' (' . $val["paymentsalid"] . ')'; // Ref of salary payment + } else if ($tabtype[$key] == 'payment_various') { + $bookkeeping->subledger_account = ''; + $bookkeeping->doc_ref = $langs->trans("VariousPayment") . ' (' . $val["paymentvariousid"] . ')'; // Ref of various payment + } + + $result = $bookkeeping->create($user); + if ($result < 0) { + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } + } + } + } } - + // Third party if (! $errorforline) { - // Line into thirdparty account - foreach ( $tabtp[$key] as $k => $mt ) { - if ($mt) { - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->doc_type = 'bank'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = $val["fk_bank"]; - $bookkeeping->label_compte = $tabcompany[$key]['name']; - $bookkeeping->montant = ($mt < 0 ? - $mt : $mt); - $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; - $bookkeeping->debit = ($mt < 0 ? - $mt : 0); - $bookkeeping->credit = ($mt >= 0) ? $mt : 0; - $bookkeeping->code_journal = $journal; - $bookkeeping->fk_user_author = $user->id; - $bookkeeping->date_create = $now; - - if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution - $bookkeeping->code_tiers = ''; - $bookkeeping->numero_compte = $k; - } else if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice - $sqlmid = 'SELECT fac.facnumber'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; - $sqlmid .= " WHERE pay.fk_bank=" . $key; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { + // Line into thirdparty account + foreach ( $tabtp[$key] as $k => $mt ) { + if ($mt) { + $bookkeeping = new BookKeeping($db); + $bookkeeping->doc_date = $val["date"]; + $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->doc_type = 'bank'; + $bookkeeping->fk_doc = $key; + $bookkeeping->fk_docdet = $val["fk_bank"]; + $bookkeeping->label_operation = $tabcompany[$key]['name']; + $bookkeeping->montant = ($mt < 0 ? - $mt : $mt); + $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; + $bookkeeping->debit = ($mt < 0 ? - $mt : 0); + $bookkeeping->credit = ($mt >= 0) ? $mt : 0; + $bookkeeping->code_journal = $journal; + $bookkeeping->journal_label = $journal_label; + $bookkeeping->fk_user_author = $user->id; + $bookkeeping->date_create = $now; + + if (in_array($tabtype[$key], array('sc', 'payment_sc'))) { // If payment is payment of social contribution + $sqlmid = 'SELECT ch.libelle, t.libelle as labelc'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "chargesociales ch "; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementcharge as paych ON paych.fk_charge=ch.rowid"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "c_chargesociales as t ON ch.fk_type=t.id"; + $sqlmid .= " WHERE paych.fk_bank=" . $key; + dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->facnumber; - } - $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; - $bookkeeping->numero_compte = $k; - } else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice - - $sqlmid = 'SELECT facf.ref_supplier,facf.ref'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; - $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; - $sqlmid .= " WHERE payf.fk_bank=" . $key; - dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; - } - $bookkeeping->code_tiers = $tabcompany[$key]['code_compta']; - $bookkeeping->numero_compte = $k; - } else if ($tabtype[$key] == 'banktransfert') { - $bookkeeping->code_tiers = ''; - $bookkeeping->numero_compte = $k; - } else { - // FIXME Should be a temporary account ??? - $bookkeeping->doc_ref = $k; - //$bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; - $bookkeeping->numero_compte = 'CodeNotDef'; - } - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists - { - $error++; - $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } - else - { - $error++; - $errorforline++; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } + $bookkeeping->label_compte = $objmid->labelc; + $bookkeeping->doc_ref = $objmid->libelle ; + } + $bookkeeping->subledger_account = ''; + $bookkeeping->numero_compte = $k; + } else if ($tabtype[$key] == 'payment') { // If payment is payment of customer invoice, we get ref of invoice + $sqlmid = 'SELECT fac.facnumber'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture fac "; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement_facture as payfac ON payfac.fk_facture=fac.rowid"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiement as pay ON payfac.fk_paiement=pay.rowid"; + $sqlmid .= " WHERE pay.fk_bank=" . $key; + dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $bookkeeping->doc_ref = $objmid->facnumber; + } + $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; + $bookkeeping->subledger_label = $tabcompany[$key]['name']; + $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; + } else if ($tabtype[$key] == 'payment_supplier') { // If payment is payment of supplier invoice, we get ref of invoice + $sqlmid = 'SELECT facf.ref_supplier,facf.ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "facture_fourn facf "; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfacf ON payfacf.fk_facturefourn=facf.rowid"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "paiementfourn as payf ON payfacf.fk_paiementfourn=payf.rowid"; + $sqlmid .= " WHERE payf.fk_bank=" . $key; + dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $bookkeeping->doc_ref = $objmid->ref_supplier . ' (' . $objmid->ref . ')'; + } + $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; + $bookkeeping->subledger_label = $tabcompany[$key]['name']; + $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; + } else if ($tabtype[$key] == 'payment_expensereport') { + $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; + $bookkeeping->subledger_label = $tabuser[$key]['name']; + $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + $bookkeeping->label_operation = $tabuser[$key]['name']; + $sqlmid = 'SELECT e.ref'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "expensereport as e"; + $sqlmid .= " INNER JOIN " . MAIN_DB_PREFIX . "payment_expensereport as payer ON payer.fk_expensereport=e.rowid"; + $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"]; + dol_syslog("accountancy/journal/bankjournal.php:: sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $bookkeeping->doc_ref = $objmid->ref; // Ref of expensereport + } + } else if ($tabtype[$key] == 'payment_vat') { + $bookkeeping->subledger_account = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->doc_ref = $langs->trans("PaymentVat") . ' (' . $val["paymentvatid"] . ')'; // Rowid of vat + } else if ($tabtype[$key] == 'payment_donation') { + $bookkeeping->subledger_account = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->doc_ref = $langs->trans("Donation") . ' (' . $val["paymentdonationid"] . ')'; // Rowid of donation + } else if ($tabtype[$key] == 'payment_salary') { + $bookkeeping->subledger_account = $tabuser[$key]['accountancy_code']; + $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + $bookkeeping->label_operation = $tabuser[$key]['name']; + $bookkeeping->doc_ref = $langs->trans("SalaryPayment") . ' (' . $val["paymentsalid"] . ')'; // Rowid of salary payment + } else if ($tabtype[$key] == 'payment_various') { + $bookkeeping->subledger_account = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->doc_ref = $langs->trans("VariousPayment") . ' (' . $val["paymentvariousid"] . ')'; // Rowid of various payment + } else if ($tabtype[$key] == 'banktransfert') { + $bookkeeping->subledger_account = ''; + $bookkeeping->numero_compte = $k; + } else { + // Temporary account + $bookkeeping->doc_ref = $k; + $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUSPENSE; + } + + $result = $bookkeeping->create($user); + if ($result < 0) { + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } + } + } + } } - + if (! $errorforline) { - $db->commit(); + $db->commit(); } else { - $db->rollback(); + $db->rollback(); + + if ($error >= 10) + { + setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); + break; // Break in the foreach + } } } if (empty($error)) { - setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); + setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); } elseif (count($tabpay) == $error) { - setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); + setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); } else { - setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); + setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); } - + $action = ''; } // Export -/* if ($action == 'export_csv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; @@ -553,165 +620,101 @@ if ($action == 'export_csv') { $companystatic = new Client($db); $userstatic = new User($db); - // Model Cegid Expert Export - if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) - { - $sep = ";"; + // Bank + foreach ( $tabpay as $key => $val ) { + $date = dol_print_date($db->jdate($val["date"]), 'day'); - foreach ( $tabpay as $key => $val ) { - $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); - - $reflabel = $val["ref"]; - if ($reflabel == '(SupplierInvoicePayment)') { - $reflabel = $langs->trans('Supplier'); - } - if ($reflabel == '(CustomerInvoicePayment)') { - $reflabel = $langs->trans('Customer'); - } - if ($reflabel == '(SocialContributionPayment)') { - $reflabel = $langs->trans('SocialContribution'); - } - if ($reflabel == '(DonationPayment)') { - $reflabel = $langs->trans('Donation'); - } - if ($reflabel == '(SubscriptionPayment)') { - $reflabel = $langs->trans('Subscription'); - } - if ($reflabel == '(ExpenseReportPayment)') { - $reflabel = $langs->trans('Employee'); - } - - $companystatic->id = $tabcompany[$key]['id']; - $companystatic->name = $tabcompany[$key]['name']; - - $userstatic->id = $tabuser[$key]['id']; - $userstatic->lastname = $tabuser[$key]['lastname']; - $userstatic->firstname = $tabuser[$key]['firstname']; - - // Bank - foreach ( $tabbq[$key] as $k => $mt ) { - print $date . $sep; - print $journal . $sep; - print length_accountg(html_entity_decode($k)) . $sep; - print $sep; - print ($mt < 0 ? 'C' : 'D') . $sep; - print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - if ($companystatic->name == '') { - print $langs->trans('Bank')." - ". utf8_decode($val["ref"]) . $sep; - } else { - print $langs->trans("Bank") .' - '.utf8_decode($companystatic->name) . $sep; - } - print utf8_decode($reflabel) . $sep; - print "\n"; - } - - // Third party - if (is_array($tabtp[$key])) { - foreach ( $tabtp[$key] as $k => $mt ) { - if ($mt) { - print $date . $sep; - print $journal . $sep; - if ($tabtype[$key] == 'payment') { - print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep; - print length_accounta(html_entity_decode($k)) . $sep; - } else if ($tabtype[$key] == 'payment_supplier') { - print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUPPLIER) . $sep; - print length_accounta(html_entity_decode($k)) . $sep; - } else { - print length_accountg(html_entity_decode($k)) . $sep; - print $sep; - } - print ($mt < 0 ? 'D' : 'C') . $sep; - print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - if ($companystatic->name == '') { - print $langs->trans('ThirdParty')." - ". utf8_decode($val["ref"]) . $sep; - } else { - print $langs->trans('ThirdParty')." - ". utf8_decode($companystatic->name) . $sep; - } - print utf8_decode($reflabel) . $sep; - print "\n"; - } - } - } else { - foreach ( $tabbq[$key] as $k => $mt ) { - print $date . $sep; - print $journal . $sep; - print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . $sep; - print $sep; - print ($mt < 0 ? 'D' : 'C') . $sep; - print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - if ($companystatic->name == '') { - print $langs->trans('ThirdParty')." - ". utf8_decode($val["ref"]) . $sep; - } else { - print $langs->trans('ThirdParty')." - ". utf8_decode($companystatic->name) . $sep; - } - print utf8_decode($reflabel) . $sep; - print "\n"; - } - } + $reflabel = $val["ref"]; + if ($reflabel == '(SupplierInvoicePayment)') { + $reflabel = $langs->trans('Supplier'); + } + if ($reflabel == '(CustomerInvoicePayment)') { + $reflabel = $langs->trans('Customer'); + } + if ($reflabel == '(SocialContributionPayment)') { + $reflabel = $langs->trans('SocialContribution'); + } + if ($reflabel == '(DonationPayment)') { + $reflabel = $langs->trans('Donation'); + } + if ($reflabel == '(SubscriptionPayment)') { + $reflabel = $langs->trans('Subscription'); + } + if ($reflabel == '(ExpenseReportPayment)') { + $reflabel = $langs->trans('Employee'); } - } else { - // Model Classic Export - foreach ( $tabpay as $key => $val ) { - $date = dol_print_date($db->jdate($val["date"]), 'day'); - $companystatic->id = $tabcompany[$key]['id']; - $companystatic->name = $tabcompany[$key]['name']; + $companystatic->id = $tabcompany[$key]['id']; + $companystatic->name = $tabcompany[$key]['name']; - // Bank - foreach ( $tabbq[$key] as $k => $mt ) { - print '"' . $journal . '"' . $sep; - print '"' . $date . '"' . $sep; - print '"' . $val["type_payment"] . '"' . $sep; - print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - if ($companystatic->name == '') { - print '"' . $langs->trans('Bank') . " - " . utf8_decode($val["ref"]) . '"' . $sep; - } else { - print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep; - } - print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; - print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; - print "\n"; - } - - // Third party - if (is_array($tabtp[$key])) { - foreach ( $tabtp[$key] as $k => $mt ) { - if ($mt) { - print '"' . $journal . '"' . $sep; - print '"' . $date . '"' . $sep; - print '"' . $val["type_payment"] . '"' . $sep; - print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; - if ($companystatic->name == '') { - print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($val["ref"]) . '"' . $sep; - } else { - print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($companystatic->name) . '"' . $sep; - } - print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; - print '"' . ($mt >= 0 ? price($mt) : '') . '"'; - print "\n"; - } - } + // Bank + foreach ( $tabbq[$key] as $k => $mt ) { + print '"' . $journal . '"' . $sep; + print '"' . $date . '"' . $sep; + print '"' . $val["type_payment"] . '"' . $sep; + print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; + print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; + print " " . $sep; + if ($companystatic->name == '') { + print '"' . $langs->trans('Bank') . " - " . utf8_decode($reflabel) . '"' . $sep; } else { - foreach ( $tabbq[$key] as $k => $mt ) { + print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep; + } + print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; + print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; + print "\n"; + } + + // Third party + if (is_array($tabtp[$key])) { + foreach ( $tabtp[$key] as $k => $mt ) { + if ($mt) { print '"' . $journal . '"' . $sep; print '"' . $date . '"' . $sep; - print '"' . $val["ref"] . '"' . $sep; - print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep; - if ($companystatic->name == '') { - print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($val["ref"]) . '"' . $sep; + print '"' . $val["type_payment"] . '"' . $sep; + print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; + + if ($tabtype[$key] == 'payment_supplier') { + print '"' . $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER . '"' . $sep; + } else if($tabtype[$key] == 'payment') { + print '"' . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . '"' . $sep; } else { - print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep; + print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; + } + + + + print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; + if ($companystatic->name == '') { + print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($reflabel) . '"' . $sep; + } else { + print '"' . $langs->trans('ThirdParty') . " - " . utf8_decode($companystatic->name) . '"' . $sep; } print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"'; print "\n"; } } + } else { + foreach ( $tabbq[$key] as $k => $mt ) { + print '"' . $journal . '"' . $sep; + print '"' . $date . '"' . $sep; + print '"' . $val["ref"] . '"' . $sep; + print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep; + print '"' . length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE) . '"' . $sep; + print " " . $sep; + if ($companystatic->name == '') { + print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($reflabel) . '"' . $sep; + } else { + print '"' . $langs->trans("Bank") . ' - ' . utf8_decode($companystatic->name) . '"' . $sep; + } + print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; + print '"' . ($mt >= 0 ? price($mt) : '') . '"'; + print "\n"; + } } } } -*/ /* @@ -724,16 +727,20 @@ if (empty($action) || $action == 'view') { $invoicestatic = new Facture($db); $invoicesupplierstatic = new FactureFournisseur($db); $expensereportstatic = new ExpenseReport($db); + $vatstatic = new Tva($db); + $donationstatic = new Don($db); + $salarystatic = new PaymentSalary($db); + $variousstatic = new PaymentVarious($db); llxHeader('', $langs->trans("FinanceJournal")); - $nom = $langs->trans("FinanceJournal") . ' - ' . $bankstatic->getNomUrl(1); + $nom = $langs->trans("FinanceJournal") . ' - ' . $accountingjournalstatic->getNomUrl(1); $builddate = time(); //$description = $langs->trans("DescFinanceJournal") . '
'; $description.= $langs->trans("DescJournalOnlyBindedVisible").'
'; - $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1); + $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectyesno('in_bookkeeping',$in_bookkeeping,0); - $varlink = 'id_account=' . $id_bank_account; + $varlink = 'id_journal=' . $id_journal; journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink); @@ -743,24 +750,25 @@ if (empty($action) || $action == 'view') { print ''; }*/ - print '
'; + print '
'; print ''; - print '
'; - + print ''; + print '
'; + // TODO Avoid using js. We can use a direct link with $param print ' '; @@ -784,7 +792,7 @@ if (empty($action) || $action == 'view') { $r = ''; - foreach ( $tabpay as $key => $val ) { // $key is rowid in llx_bank + foreach ( $tabpay as $key => $val ) { // $key is rowid in llx_bank $date = dol_print_date($db->jdate($val["date"]), 'day'); $reflabel = $val["ref"]; @@ -793,7 +801,7 @@ if (empty($action) || $action == 'view') { } if ($reflabel == '(CustomerInvoicePayment)') { $reflabel = $langs->trans('Customer'); - } + } if ($reflabel == '(SocialContributionPayment)') { $reflabel = $langs->trans('SocialContribution'); } @@ -806,72 +814,130 @@ if (empty($action) || $action == 'view') { if ($reflabel == '(ExpenseReportPayment)') { $reflabel = $langs->trans('Employee'); } - + if ($reflabel == '(payment_salary)') { + $reflabel = $langs->trans('Employee'); + } + $ref=$reflabel; if ($tabtype[$key] == 'payment') { - $sqlmid = 'SELECT payfac.fk_facture as id'; - $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac"; - $sqlmid .= " WHERE payfac.fk_paiement=" . $val["paymentid"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $invoicestatic->fetch($objmid->id); - $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1); - } - else dol_print_error($db); + $sqlmid = 'SELECT payfac.fk_facture as id'; + $sqlmid .= " FROM ".MAIN_DB_PREFIX."paiement_facture as payfac"; + $sqlmid .= " WHERE payfac.fk_paiement=" . $val["paymentid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $invoicestatic->fetch($objmid->id); + $ref=$langs->trans("Invoice").' '.$invoicestatic->getNomUrl(1); + } + else dol_print_error($db); } elseif ($tabtype[$key] == 'payment_supplier') { - $sqlmid = 'SELECT payfac.fk_facturefourn as id'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfac"; - $sqlmid .= " WHERE payfac.fk_paiementfourn=" . $val["paymentsupplierid"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $invoicesupplierstatic->fetch($objmid->id); - $ref=$langs->trans("SupplierInvoice").' '.$invoicesupplierstatic->getNomUrl(1); - } - else dol_print_error($db); + $sqlmid = 'SELECT payfac.fk_facturefourn as id'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "paiementfourn_facturefourn as payfac"; + $sqlmid .= " WHERE payfac.fk_paiementfourn=" . $val["paymentsupplierid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $invoicesupplierstatic->fetch($objmid->id); + $ref=$langs->trans("SupplierInvoice").' '.$invoicesupplierstatic->getNomUrl(1); + } + else dol_print_error($db); } elseif ($tabtype[$key] == 'payment_expensereport') { - $sqlmid = 'SELECT payer.fk_expensereport as id'; - $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_expensereport as payer"; - $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"]; - dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); - $resultmid = $db->query($sqlmid); - if ($resultmid) { - $objmid = $db->fetch_object($resultmid); - $expensereportstatic->fetch($objmid->id); - $ref=$langs->trans("ExpenseReport").' '.$expensereportstatic->getNomUrl(1); - } - else dol_print_error($db); + $sqlmid = 'SELECT payer.fk_expensereport as id'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_expensereport as payer"; + $sqlmid .= " WHERE payer.fk_expensereport=" . $val["fk_expensereport"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $expensereportstatic->fetch($objmid->id); + $ref=$langs->trans("ExpenseReport").' '.$expensereportstatic->getNomUrl(1); + } + else dol_print_error($db); + } + elseif ($tabtype[$key] == 'payment_vat') + { + $sqlmid = 'SELECT v.rowid as id'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "tva as v"; + $sqlmid .= " WHERE v.rowid=" . $val["paymentvatid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $vatstatic->fetch($objmid->id); + $ref=$langs->trans("PaymentVat").' '.$vatstatic->getNomUrl(1); + } + else dol_print_error($db); + } + elseif ($tabtype[$key] == 'payment_donation') + { + $sqlmid = 'SELECT payd.fk_donation as id'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_donation as payd"; + $sqlmid .= " WHERE payd.fk_donation=" . $val["paymentdonationid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $donationstatic->fetch($objmid->id); + $ref=$langs->trans("Donation").' '.$donationstatic->getNomUrl(1); + } + else dol_print_error($db); + } + elseif ($tabtype[$key] == 'payment_salary') + { + $sqlmid = 'SELECT s.rowid as id'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_salary as s"; + $sqlmid .= " WHERE s.rowid=" . $val["paymentsalid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $salarystatic->fetch($objmid->id); + $ref=$langs->trans("SalaryPayment").' '.$salarystatic->getNomUrl(1); + } + else dol_print_error($db); + } + elseif ($tabtype[$key] == 'payment_various') + { + $sqlmid = 'SELECT v.rowid as id'; + $sqlmid .= " FROM " . MAIN_DB_PREFIX . "payment_various as v"; + $sqlmid .= " WHERE v.rowid=" . $val["paymentvariousid"]; + dol_syslog("accountancy/journal/bankjournal.php::sqlmid=" . $sqlmid, LOG_DEBUG); + $resultmid = $db->query($sqlmid); + if ($resultmid) { + $objmid = $db->fetch_object($resultmid); + $variousstatic->fetch($objmid->id); + $ref=$variousstatic->getNomUrl(1); + } + else dol_print_error($db); } - /*$invoicestatic->id = $key; $invoicestatic->ref = $val["ref"]; $invoicestatic->type = $val["type"];*/ // Bank - foreach ( $tabbq[$key] as $k => $mt ) + foreach ( $tabbq[$key] as $k => $mt ) { - print ''; - print ""; - print "" . $date . ""; + print ''; + print ""; + print "" . $date . ""; print "" . $ref . ""; print ""; $accountoshow = length_accountg($k); if (empty($accountoshow) || $accountoshow == 'NotDefined') { - print ''.$langs->trans("BankAccountNotDefined").''; + print ''.$langs->trans("BankAccountNotDefined").''; } else print $accountoshow; print ""; if ($val['soclib'] == '') { - print "" . $bankstatic->label . " - " . $val["ref"] . ""; + print "" . $bankstatic->label . " - " . $reflabel . ""; } else { print "" . $bankstatic->label . " - " . $val['soclib'] . ""; } @@ -890,12 +956,12 @@ if (empty($action) || $action == 'view') { print "" . $date . ""; print "" . $ref . ""; print ""; - $accountoshow = length_accounta($k); - if (empty($accountoshow) || $accountoshow == 'NotDefined') - { - print ''.$langs->trans("ThirdpartyAccountNotDefined").''; - } - else print $accountoshow; + $accountoshow = length_accounta($k); + if (empty($accountoshow) || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("ThirdpartyAccountNotDefined").''; + } + else print $accountoshow; print ""; print "" . $reflabel . ' ' . $val['soclib'] . ""; print "" . $val["type_payment"] . ""; @@ -911,11 +977,11 @@ if (empty($action) || $action == 'view') { print "" . $date . ""; print "" . $ref . ""; print ""; - if (empty($accountoshow) || $accountoshow == 'NotDefined') - { - print ''.$langs->trans("WaitAccountNotDefined").''; - } - else print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE); + if (empty($accountoshow) || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("WaitAccountNotDefined").''; + } + else print length_accountg($conf->global->ACCOUNTING_ACCOUNT_SUSPENSE); print ""; print "" . $reflabel . ""; print " "; diff --git a/htdocs/accountancy/journal/expensereportsjournal.php b/htdocs/accountancy/journal/expensereportsjournal.php index f67224e3996..8d6f8ca4dcd 100644 --- a/htdocs/accountancy/journal/expensereportsjournal.php +++ b/htdocs/accountancy/journal/expensereportsjournal.php @@ -3,7 +3,7 @@ * Copyright (C) 2007-2010 Jean Heimburger * Copyright (C) 2011 Juanjo Menent * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013-2016 Alexandre Spangaro + * Copyright (C) 2013-2017 Alexandre Spangaro * Copyright (C) 2013-2016 Olivier Geffroy * Copyright (C) 2013-2016 Florian Henry * @@ -22,22 +22,20 @@ */ /** - * \file htdocs/accountancy/journal/expensereportsjournal.php - * \ingroup Advanced accountancy - * \brief Page with expense reports journal + * \file htdocs/accountancy/journal/expensereportsjournal.php + * \ingroup Advanced accountancy + * \brief Page with expense reports journal */ require '../../main.inc.php'; - -// Class require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; require_once DOL_DOCUMENT_ROOT . '/expensereport/class/expensereport.class.php'; require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; -require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; -// Langs $langs->load("compta"); $langs->load("bills"); $langs->load("other"); @@ -45,12 +43,16 @@ $langs->load("main"); $langs->load("accountancy"); $langs->load("trips"); +$id_journal = GETPOST('id_journal', 'int'); +$action = GETPOST('action','aZ09'); + $date_startmonth = GETPOST('date_startmonth'); $date_startday = GETPOST('date_startday'); $date_startyear = GETPOST('date_startyear'); $date_endmonth = GETPOST('date_endmonth'); $date_endday = GETPOST('date_endday'); $date_endyear = GETPOST('date_endyear'); +$in_bookkeeping = GETPOST('in_bookkeeping'); $now = dol_now(); @@ -58,13 +60,16 @@ $now = dol_now(); if ($user->societe_id > 0) accessforbidden(); -$action = GETPOST('action','aZ09'); - - /* * Actions */ +// Get informations of journal +$accountingjournalstatic = new AccountingJournal($db); +$accountingjournalstatic->fetch($id_journal); +$journal = $accountingjournalstatic->code; +$journal_label = $accountingjournalstatic->label; + $year_current = strftime("%Y", dol_now()); $pastmonth = strftime("%m", dol_now()) - 1; $pastmonthyear = $year_current; @@ -82,31 +87,34 @@ if (empty($date_start) || empty($date_end)) // We define date_start and date_end $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false); } -$p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY); -$idpays = $p[0]; +$idpays = $mysoc->country_id; $sql = "SELECT er.rowid, er.ref, er.date_debut as de,"; -$sql .= " erd.rowid as erdid, erd.comments, erd.total_ttc, erd.tva_tx, erd.total_ht, erd.total_tva, erd.fk_code_ventilation,"; +$sql .= " erd.rowid as erdid, erd.comments, erd.total_ttc, erd.tva_tx, erd.total_ht, erd.total_tva, erd.fk_code_ventilation, erd.vat_src_code, "; $sql .= " u.rowid as uid, u.firstname, u.lastname, u.accountancy_code as user_accountancy_account,"; -$sql .= " f.accountancy_code, ct.accountancy_code_buy as account_tva, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; +$sql .= " f.accountancy_code, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; +//$sql .= " ct.accountancy_code_buy as account_tva"; $sql .= " FROM " . MAIN_DB_PREFIX . "expensereport_det as erd"; -$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON erd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'"; +//$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON erd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_type_fees as f ON f.id = erd.fk_c_type_fees"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = erd.fk_code_ventilation"; $sql .= " JOIN " . MAIN_DB_PREFIX . "expensereport as er ON er.rowid = erd.fk_expensereport"; $sql .= " JOIN " . MAIN_DB_PREFIX . "user as u ON u.rowid = er.fk_user_author"; -$sql .= " WHERE er.fk_statut > 0 "; -$sql .= " AND erd.fk_code_ventilation > 0 "; -$sql .= " AND er.entity IN (" . getEntity("expensereport", 0) . ")"; // We don't share object for accountancy +$sql .= " WHERE er.fk_statut > 0"; +$sql .= " AND erd.fk_code_ventilation > 0"; +$sql .= " AND er.entity IN (" . getEntity('expensereport', 0) . ")"; // We don't share object for accountancy if ($date_start && $date_end) $sql .= " AND er.date_debut >= '" . $db->idate($date_start) . "' AND er.date_debut <= '" . $db->idate($date_end) . "'"; +if ($in_bookkeeping == 'yes') + $sql .= " AND (er.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='expense_report') )"; $sql .= " ORDER BY er.date_debut"; dol_syslog('accountancy/journal/expensereportsjournal.php:: $sql=' . $sql); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); - // les variables + + // Variables $account_salary = (! empty($conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT)) ? $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT : $langs->trans("CodeNotDef"); $account_vat = (! empty($conf->global->ACCOUNTING_VAT_BUY_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_BUY_ACCOUNT : $langs->trans("CodeNotDef"); @@ -124,10 +132,15 @@ if ($result) { // Controls $compta_user = (! empty($obj->user_accountancy_account)) ? $obj->user_accountancy_account : $account_salary; $compta_fees = $obj->compte; - $compta_tva = (! empty($obj->account_tva) ? $obj->account_tva : $account_vat); - // Define array for display vat tx - $def_tva[$obj->rowid]=price($obj->tva_tx); + $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code?' ('.$obj->vat_src_code.')':''), $mysoc, $mysoc, 0); + $compta_tva = (! empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $account_vat); + + // Define array to display all VAT rates that use this accounting account $compta_tva + if (price2num($obj->tva_tx) || ! empty($obj->vat_src_code)) + { + $def_tva[$obj->rowid][$compta_tva][vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')]=(vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')); + } $taber[$obj->rowid]["date"] = $db->jdate($obj->de); $taber[$obj->rowid]["ref"] = $obj->ref; @@ -138,7 +151,7 @@ if ($result) { $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva; $tabuser[$obj->rowid] = array ( 'id' => $obj->uid, - 'name' => $obj->firstname.' '.$obj->lastname, + 'name' => dolGetFirstLastname($obj->firstname, $obj->lastname), 'user_accountancy_code' => $obj->user_accountancy_account ); @@ -157,161 +170,172 @@ if ($action == 'writebookkeeping') { { $errorforline = 0; - $db->begin(); - - if (! $errorforline) - { - foreach ( $tabttc[$key] as $k => $mt ) { - if ($mt) { - // get compte id and label - - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->date_create = $now; - $bookkeeping->doc_type = 'expense_report'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = $val["fk_expensereportdet"]; - $bookkeeping->code_tiers = $tabuser[$key]['user_accountancy_code']; - $bookkeeping->label_compte = $tabuser[$key]['name']; - $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; - $bookkeeping->montant = $mt; - $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D'; - $bookkeeping->debit = ($mt <= 0) ? $mt : 0; - $bookkeeping->credit = ($mt > 0) ? $mt : 0; - $bookkeeping->code_journal = $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL; - $bookkeeping->fk_user_author = $user->id; - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists - { - $error++; - $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } - else - { - $error++; - $errorforline++; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } - } - - if (! $errorforline) - { - // Fees - foreach ( $tabht[$key] as $k => $mt ) { - $accountingaccount = new AccountingAccount($db); - $accountingaccount->fetch(null, $k, true); - if ($mt) { - // get compte id and label - $accountingaccount = new AccountingAccount($db); - if ($accountingaccount->fetch(null, $k, true)) { - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->date_create = $now; - $bookkeeping->doc_type = 'expense_report'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = $val["fk_expensereportdet"]; - $bookkeeping->code_tiers = ''; - $bookkeeping->label_compte = $accountingaccount->label; - $bookkeeping->numero_compte = $k; - $bookkeeping->montant = $mt; - $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; - $bookkeeping->debit = ($mt > 0) ? $mt : 0; - $bookkeeping->credit = ($mt <= 0) ? $mt : 0; - $bookkeeping->code_journal = $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL; - $bookkeeping->fk_user_author = $user->id; - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists - { - $error++; - $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } - else - { - $error++; - $errorforline++; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } - } - } - - if (! $errorforline) - { - // VAT - // var_dump($tabtva); - foreach ( $tabtva[$key] as $k => $mt ) { - if ($mt) { - // get compte id and label - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->date_create = $now; - $bookkeeping->doc_type = 'expense_report'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = $val["fk_expensereportdet"]; - $bookkeeping->code_tiers = ''; - $bookkeeping->label_compte = $langs->trans("VAT"). ' '.$def_tva[$key]; - $bookkeeping->numero_compte = $k; - $bookkeeping->montant = $mt; - $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; - $bookkeeping->debit = ($mt > 0) ? $mt : 0; - $bookkeeping->credit = ($mt <= 0) ? $mt : 0; - $bookkeeping->code_journal = $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL; - $bookkeeping->fk_user_author = $user->id; - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists - { - $error++; - $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } - else - { - $error++; - $errorforline++; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } - } - + $db->begin(); + + // Thirdparty if (! $errorforline) { - $db->commit(); + foreach ( $tabttc[$key] as $k => $mt ) { + if ($mt) { + // get compte id and label + $bookkeeping = new BookKeeping($db); + $bookkeeping->doc_date = $val["date"]; + $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->date_create = $now; + $bookkeeping->doc_type = 'expense_report'; + $bookkeeping->fk_doc = $key; + $bookkeeping->fk_docdet = $val["fk_expensereportdet"]; + $bookkeeping->subledger_account = $tabuser[$key]['user_accountancy_code']; + $bookkeeping->subledger_label = $tabuser[$key]['user_accountancy_code']; + $bookkeeping->label_operation = $tabuser[$key]['name']; + $bookkeeping->numero_compte = $conf->global->SALARIES_ACCOUNTING_ACCOUNT_PAYMENT; + $bookkeeping->montant = $mt; + $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D'; + $bookkeeping->debit = ($mt <= 0) ? $mt : 0; + $bookkeeping->credit = ($mt > 0) ? $mt : 0; + $bookkeeping->code_journal = $journal; + $bookkeeping->journal_label = $journal_label; + $bookkeeping->fk_user_author = $user->id; + + $result = $bookkeeping->create($user); + if ($result < 0) { + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } + } + } + } + } + + // Fees + if (! $errorforline) + { + foreach ( $tabht[$key] as $k => $mt ) { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(null, $k, true); + if ($mt) { + // get compte id and label + $accountingaccount = new AccountingAccount($db); + if ($accountingaccount->fetch(null, $k, true)) { + $bookkeeping = new BookKeeping($db); + $bookkeeping->doc_date = $val["date"]; + $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->date_create = $now; + $bookkeeping->doc_type = 'expense_report'; + $bookkeeping->fk_doc = $key; + $bookkeeping->fk_docdet = $val["fk_expensereportdet"]; + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + $bookkeeping->label_operation = $accountingaccount->label; + $bookkeeping->numero_compte = $k; + $bookkeeping->montant = $mt; + $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; + $bookkeeping->debit = ($mt > 0) ? $mt : 0; + $bookkeeping->credit = ($mt <= 0) ? $mt : 0; + $bookkeeping->code_journal = $journal; + $bookkeeping->journal_label = $journal_label; + $bookkeeping->fk_user_author = $user->id; + + $result = $bookkeeping->create($user); + if ($result < 0) { + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } + } + } + } + } + } + + // VAT + if (! $errorforline) + { + // var_dump($tabtva); + foreach ( $tabtva[$key] as $k => $mt ) { + if ($mt) { + // get compte id and label + $bookkeeping = new BookKeeping($db); + $bookkeeping->doc_date = $val["date"]; + $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->date_create = $now; + $bookkeeping->doc_type = 'expense_report'; + $bookkeeping->fk_doc = $key; + $bookkeeping->fk_docdet = $val["fk_expensereportdet"]; + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + $bookkeeping->label_operation = $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]); + $bookkeeping->numero_compte = $k; + $bookkeeping->montant = $mt; + $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; + $bookkeeping->debit = ($mt > 0) ? $mt : 0; + $bookkeeping->credit = ($mt <= 0) ? $mt : 0; + $bookkeeping->code_journal = $journal; + $bookkeeping->journal_label = $journal_label; + $bookkeeping->fk_user_author = $user->id; + + $result = $bookkeeping->create($user); + if ($result < 0) { + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } + } + } + } + } + + if (! $errorforline) + { + $db->commit(); } else { - $db->rollback(); + $db->rollback(); + + if ($error >= 10) + { + setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); + break; // Break in the foreach + } } - } if (empty($error) && count($tabpay)) { - setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); + setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); } elseif (count($tabpay) == $error) { - setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); + setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); } else { - setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); + setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); } $action=''; @@ -328,7 +352,6 @@ $userstatic = new User($db); // Export /*if ($action == 'export_csv') { $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; - $journal = $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL; include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; @@ -439,16 +462,18 @@ if (empty($action) || $action == 'view') { llxHeader('', $langs->trans("ExpenseReportsJournal")); - $nom = $langs->trans("ExpenseReportsJournal"); + $nom = $langs->trans("ExpenseReportsJournal") . ' - ' . $accountingjournalstatic->getNomUrl(1); $nomlink = ''; $periodlink = ''; $exportlink = ''; $builddate = time(); $description.= $langs->trans("DescJournalOnlyBindedVisible").'
'; - $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1); + $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectyesno('in_bookkeeping',$in_bookkeeping,0); - journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => '')); + $varlink = 'id_journal=' . $id_journal; + + journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink); /*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) { print ''; @@ -456,10 +481,10 @@ if (empty($action) || $action == 'view') { print ''; }*/ - print '
'; + print '
'; print ''; - print '
'; - + print '
'; + print ' '; @@ -537,7 +538,6 @@ if (empty($action) || $action == 'view') { $i = 0; print ""; print ""; - // /print ""; print ""; print ""; print ""; @@ -574,12 +574,12 @@ if (empty($action) || $action == 'view') { print ""; print ""; print ""; $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; @@ -590,6 +590,7 @@ if (empty($action) || $action == 'view') { print ""; } } + // VAT foreach ( $tabtva[$key] as $k => $mt ) { if ($mt) { @@ -598,14 +599,14 @@ if (empty($action) || $action == 'view') { print ""; print ""; print ""; - print ""; + print ""; print '"; print '"; print ""; @@ -614,9 +615,9 @@ if (empty($action) || $action == 'view') { // Third party foreach ( $tabttc[$key] as $k => $mt ) { - print ''; - print ""; - print ""; + print ''; + print ""; + print ""; print ""; $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; @@ -624,11 +625,11 @@ if (empty($action) || $action == 'view') { $accountoshow = length_accounta($k); if (empty($accountoshow) || $accountoshow == 'NotDefined') { - print ''.$langs->trans("ThirdpartyAccountNotDefined").''; + print ''.$langs->trans("ThirdpartyAccountNotDefined").''; } else print $accountoshow; - print ""; - print ""; + print ""; + print ""; // print ""; diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index 85ce7361394..edaf3a87f27 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -1,13 +1,13 @@ - * Copyright (C) 2007-2010 Jean Heimburger - * Copyright (C) 2011 Juanjo Menent - * Copyright (C) 2012 Regis Houssin - * Copyright (C) 2013 Christophe Battarel - * Copyright (C) 2013-2016 Alexandre Spangaro - * Copyright (C) 2013-2016 Florian Henry - * Copyright (C) 2013-2016 Olivier Geffroy - * Copyright (C) 2014 Raphaël Doursenaud +/* Copyright (C) 2007-2010 Laurent Destailleur + * Copyright (C) 2007-2010 Jean Heimburger + * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2012 Regis Houssin + * Copyright (C) 2013 Christophe Battarel + * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2013-2016 Florian Henry + * Copyright (C) 2013-2016 Olivier Geffroy + * Copyright (C) 2014 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 @@ -29,17 +29,15 @@ * \brief Page with sells journal */ require '../../main.inc.php'; - -// Class require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingjournal.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT . '/societe/class/client.class.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; -require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountingaccount.class.php'; -// Langs $langs->load("commercial"); $langs->load("compta"); $langs->load("bills"); @@ -47,12 +45,16 @@ $langs->load("other"); $langs->load("main"); $langs->load("accountancy"); +$id_journal = GETPOST('id_journal', 'int'); +$action = GETPOST('action','alpha'); + $date_startmonth = GETPOST('date_startmonth'); $date_startday = GETPOST('date_startday'); $date_startyear = GETPOST('date_startyear'); $date_endmonth = GETPOST('date_endmonth'); $date_endday = GETPOST('date_endday'); $date_endyear = GETPOST('date_endyear'); +$in_bookkeeping = GETPOST('in_bookkeeping'); $now = dol_now(); @@ -60,19 +62,23 @@ $now = dol_now(); if ($user->societe_id > 0) accessforbidden(); -$action = GETPOST('action','aZ09'); - /* * Actions */ +// Get informations of journal +$accountingjournalstatic = new AccountingJournal($db); +$accountingjournalstatic->fetch($id_journal); +$journal = $accountingjournalstatic->code; +$journal_label = $accountingjournalstatic->label; + $year_current = strftime("%Y", dol_now()); $pastmonth = strftime("%m", dol_now()) - 1; $pastmonthyear = $year_current; if ($pastmonth == 0) { - $pastmonth = 12; - $pastmonthyear --; + $pastmonth = 12; + $pastmonthyear --; } $date_start = dol_mktime(0, 0, 0, $date_startmonth, $date_startday, $date_startyear); @@ -80,293 +86,313 @@ $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); if (empty($date_start) || empty($date_end)) // We define date_start and date_end { - $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false); - $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false); + $date_start = dol_get_first_day($pastmonthyear, $pastmonth, false); + $date_end = dol_get_last_day($pastmonthyear, $pastmonth, false); } -$p = explode(":", $conf->global->MAIN_INFO_SOCIETE_COUNTRY); -$idpays = $p[0]; +$idpays = $mysoc->country_id; $sql = "SELECT f.rowid, f.facnumber, f.type, f.datef as df, f.ref_client,"; -$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.total_ttc,"; +$sql .= " fd.rowid as fdid, fd.description, fd.product_type, fd.total_ht, fd.total_tva, fd.tva_tx, fd.total_ttc, fd.situation_percent, fd.vat_src_code,"; $sql .= " s.rowid as socid, s.nom as name, s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur,"; -$sql .= " p.rowid as pid, p.ref as pref, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte,"; -$sql .= " fd.situation_percent,ct.accountancy_code_sell as account_tva"; +$sql .= " p.rowid as pid, p.ref as pref, p.accountancy_code_sell, aa.rowid as fk_compte, aa.account_number as compte, aa.label as label_compte"; +//$sql .= " ct.accountancy_code_sell as account_tva"; $sql .= " FROM " . MAIN_DB_PREFIX . "facturedet as fd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = fd.fk_product"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = fd.fk_code_ventilation"; $sql .= " JOIN " . MAIN_DB_PREFIX . "facture as f ON f.rowid = fd.fk_facture"; $sql .= " JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = f.fk_soc"; -$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON fd.tva_tx = ct.taux AND ct.fk_pays = '" . $idpays . "'"; +//$sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "c_tva as ct ON ((fd.vat_src_code <> '' AND fd.vat_src_code = ct.code) OR (fd.vat_src_code = '' AND fd.tva_tx = ct.taux)) AND ct.fk_pays = '" . $idpays . "'"; $sql .= " WHERE fd.fk_code_ventilation > 0"; -$sql .= " AND f.entity IN (".getEntity('facture', 0).')'; // We don't share object for accountancy +$sql .= " AND f.entity IN (".getEntity('facture', 0).')'; // We don't share object for accountancy $sql .= " AND f.fk_statut > 0"; // TODO Facture annulée ? if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { - $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; + $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_SITUATION . ")"; } else { - $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_STANDARD . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; + $sql .= " AND f.type IN (" . Facture::TYPE_STANDARD . "," . Facture::TYPE_REPLACEMENT . "," . Facture::TYPE_CREDIT_NOTE . "," . Facture::TYPE_DEPOSIT . "," . Facture::TYPE_SITUATION . ")"; } $sql .= " AND fd.product_type IN (0,1)"; if ($date_start && $date_end) - $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'"; + $sql .= " AND f.datef >= '" . $db->idate($date_start) . "' AND f.datef <= '" . $db->idate($date_end) . "'"; +if ($in_bookkeeping == 'yes') + $sql .= " AND (f.rowid NOT IN (SELECT fk_doc FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as ab WHERE ab.doc_type='customer_invoice') )"; $sql .= " ORDER BY f.datef"; dol_syslog('accountancy/journal/sellsjournal.php', LOG_DEBUG); $result = $db->query($sql); if ($result) { - $tabfac = array (); - $tabht = array (); - $tabtva = array (); - $def_tva = array (); - $tabttc = array (); - $tabcompany = array (); + $tabfac = array (); + $tabht = array (); + $tabtva = array (); + $def_tva = array (); + $tabttc = array (); + $tabcompany = array (); - $num = $db->num_rows($result); - $i = 0; + $num = $db->num_rows($result); - $cptcli = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef"); - - while ( $i < $num ) { - $obj = $db->fetch_object($result); - - // les variables - $compta_soc = (! empty($obj->code_compta)) ? $obj->code_compta : $cptcli; + // Variables + $cptcli = (! empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)) ? $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER : $langs->trans("CodeNotDef"); + $cpttva = (! empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"); - $compta_prod = $obj->compte; - if (empty($compta_prod)) { - if ($obj->product_type == 0) - $compta_prod = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"); - else - $compta_prod = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"); - } - $cpttva = (! empty($conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_VAT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"); - $compta_tva = (! empty($obj->account_tva) ? $obj->account_tva : $cpttva); + $i = 0; + while ( $i < $num ) { + $obj = $db->fetch_object($result); + // Controls + $compta_soc = (! empty($obj->code_compta)) ? $obj->code_compta : $cptcli; - //Define array for display vat tx - $def_tva[$obj->rowid]=price($obj->tva_tx); + $compta_prod = $obj->compte; + if (empty($compta_prod)) { + if ($obj->product_type == 0) + $compta_prod = (! empty($conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_PRODUCT_SOLD_ACCOUNT : $langs->trans("CodeNotDef"); + else + $compta_prod = (! empty($conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT)) ? $conf->global->ACCOUNTING_SERVICE_SOLD_ACCOUNT : $langs->trans("CodeNotDef"); + } - // Situation invoices handling - $line = new FactureLigne($db); - $line->fetch($obj->fdid); - $prev_progress = $line->get_prev_progress($obj->fdid); - if ($obj->type == Facture::TYPE_SITUATION) { - // Avoid divide by 0 - if ($obj->situation_percent == 0) { - $situation_ratio = 0; - } else { - $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent; - } - } else { - $situation_ratio = 1; - } + $vatdata = getTaxesFromId($obj->tva_tx.($obj->vat_src_code?' ('.$obj->vat_src_code.')':''), $mysoc, $mysoc, 0); + $compta_tva = (! empty($vatdata['accountancy_code_sell']) ? $vatdata['accountancy_code_sell'] : $cpttva); - // Invoice lines - $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df); - $tabfac[$obj->rowid]["ref"] = $obj->facnumber; - $tabfac[$obj->rowid]["type"] = $obj->type; - $tabfac[$obj->rowid]["description"] = $obj->label_compte; - //$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid; - - // Avoid warnings - if (! isset($tabttc[$obj->rowid][$compta_soc])) $tabttc[$obj->rowid][$compta_soc] = 0; - if (! isset($tabht[$obj->rowid][$compta_prod])) $tabht[$obj->rowid][$compta_prod] = 0; - if (! isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0; + // Define array to display all VAT rates that use this accounting account $compta_tva + if (price2num($obj->tva_tx) || ! empty($obj->vat_src_code)) + { + $def_tva[$obj->rowid][$compta_tva][vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')]=(vatrate($obj->tva_tx).($obj->vat_src_code?' ('.$obj->vat_src_code.')':'')); + } - $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio; - $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio; - $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio; - $tabcompany[$obj->rowid] = array ( - 'id' => $obj->socid, - 'name' => $obj->name, - 'code_client' => $obj->code_client, - 'code_compta' => $compta_soc - ); + // Situation invoices handling + $line = new FactureLigne($db); + $line->fetch($obj->fdid); + $prev_progress = $line->get_prev_progress($obj->fdid); + if ($obj->type == Facture::TYPE_SITUATION) { + // Avoid divide by 0 + if ($obj->situation_percent == 0) { + $situation_ratio = 0; + } else { + $situation_ratio = ($obj->situation_percent - $prev_progress) / $obj->situation_percent; + } + } else { + $situation_ratio = 1; + } - $i ++; - } + // Invoice lines + $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df); + $tabfac[$obj->rowid]["ref"] = $obj->facnumber; + $tabfac[$obj->rowid]["type"] = $obj->type; + $tabfac[$obj->rowid]["description"] = $obj->label_compte; + //$tabfac[$obj->rowid]["fk_facturedet"] = $obj->fdid; + + // Avoid warnings + if (! isset($tabttc[$obj->rowid][$compta_soc])) $tabttc[$obj->rowid][$compta_soc] = 0; + if (! isset($tabht[$obj->rowid][$compta_prod])) $tabht[$obj->rowid][$compta_prod] = 0; + if (! isset($tabtva[$obj->rowid][$compta_tva])) $tabtva[$obj->rowid][$compta_tva] = 0; + + $tabttc[$obj->rowid][$compta_soc] += $obj->total_ttc * $situation_ratio; + $tabht[$obj->rowid][$compta_prod] += $obj->total_ht * $situation_ratio; + $tabtva[$obj->rowid][$compta_tva] += $obj->total_tva * $situation_ratio; + $tabcompany[$obj->rowid] = array ( + 'id' => $obj->socid, + 'name' => $obj->name, + 'code_client' => $obj->code_client, + 'code_compta' => $compta_soc + ); + + $i ++; + } } else { - dol_print_error($db); + dol_print_error($db); } // Bookkeeping Write if ($action == 'writebookkeeping') { - $now = dol_now(); - $error = 0; + $now = dol_now(); + $error = 0; - foreach ( $tabfac as $key => $val ) { // Loop on each invoice - - $errorforline = 0; + foreach ( $tabfac as $key => $val ) { // Loop on each invoice - $db->begin(); + $errorforline = 0; - $companystatic = new Societe($db); - $invoicestatic = new Facture($db); + $db->begin(); - $companystatic->id = $tabcompany[$key]['id']; - $companystatic->name = $tabcompany[$key]['name']; + $companystatic = new Societe($db); + $invoicestatic = new Facture($db); + + $companystatic->id = $tabcompany[$key]['id']; + $companystatic->name = $tabcompany[$key]['name']; $companystatic->code_compta = $tabcompany[$key]['code_compta']; $companystatic->code_compta_fournisseur = $tabcompany[$key]['code_compta_fournisseur']; $companystatic->code_client = $tabcompany[$key]['code_client']; $companystatic->code_fournisseur = $tabcompany[$key]['code_fournisseur']; - $companystatic->client = $tabcompany[$key]['code_client']; + $companystatic->client = $tabcompany[$key]['code_client']; - $invoicestatic->id = $key; - $invoicestatic->ref = (string) $val["ref"]; + $invoicestatic->id = $key; + $invoicestatic->ref = (string) $val["ref"]; - // Thirdparty - if (! $errorforline) - { - foreach ( $tabttc[$key] as $k => $mt ) { - if ($mt) { - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->date_create = $now; - $bookkeeping->doc_type = 'customer_invoice'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add - $bookkeeping->code_tiers = $tabcompany[$key]['code_client']; - $bookkeeping->numero_compte = $tabcompany[$key]['code_compta']; - // $bookkeeping->label_compte = $tabcompany[$key]['name']; - $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers"); - $bookkeeping->montant = $mt; - $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; - $bookkeeping->debit = ($mt >= 0) ? $mt : 0; - $bookkeeping->credit = ($mt < 0) ? $mt : 0; - $bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; - $bookkeeping->fk_user_author = $user->id; - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists - { - $error++; - $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } - else - { - $error++; - $errorforline++; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } - } - - // Product / Service - if (! $errorforline) - { - foreach ( $tabht[$key] as $k => $mt ) { - if ($mt) { - // get compte id and label - $accountingaccount = new AccountingAccount($db); - if ($accountingaccount->fetch(null, $k, true)) { - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->date_create = $now; - $bookkeeping->doc_type = 'customer_invoice'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add; - $bookkeeping->code_tiers = ''; - $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label; - $bookkeeping->montant = $mt; - $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; - $bookkeeping->debit = ($mt < 0) ? $mt : 0; - $bookkeeping->credit = ($mt >= 0) ? $mt : 0; - $bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; - $bookkeeping->fk_user_author = $user->id; - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists - { - $error++; - $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } - else - { - $error++; - $errorforline++; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } - } - } - - // VAT - // var_dump($tabtva); - if (! $errorforline) - { - foreach ( $tabtva[$key] as $k => $mt ) { - if ($mt) { - $bookkeeping = new BookKeeping($db); - $bookkeeping->doc_date = $val["date"]; - $bookkeeping->doc_ref = $val["ref"]; - $bookkeeping->date_create = $now; - $bookkeeping->doc_type = 'customer_invoice'; - $bookkeeping->fk_doc = $key; - $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add - $bookkeeping->code_tiers = ''; - $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.$def_tva[$key]; - $bookkeeping->montant = $mt; - $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; - $bookkeeping->debit = ($mt < 0) ? $mt : 0; - $bookkeeping->credit = ($mt >= 0) ? $mt : 0; - $bookkeeping->code_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; - $bookkeeping->fk_user_author = $user->id; - - $result = $bookkeeping->create($user); - if ($result < 0) { - if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists - { - $error++; - $errorforline++; - //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); - } - else - { - $error++; - $errorforline++; - setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); - } - } - } - } - } + // Thirdparty + if (! $errorforline) + { + foreach ( $tabttc[$key] as $k => $mt ) { + if ($mt) { + $bookkeeping = new BookKeeping($db); + $bookkeeping->doc_date = $val["date"]; + $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->date_create = $now; + $bookkeeping->doc_type = 'customer_invoice'; + $bookkeeping->fk_doc = $key; + $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add + $bookkeeping->thirdparty_code = $companystatic->code_client; + $bookkeeping->subledger_account = $tabcompany[$key]['code_compta']; + $bookkeeping->subledger_label = ''; // TODO To complete + $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; + $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("subledger_account"); + $bookkeeping->montant = $mt; + $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; + $bookkeeping->debit = ($mt >= 0) ? $mt : 0; + $bookkeeping->credit = ($mt < 0) ? $mt : 0; + $bookkeeping->code_journal = $journal; + $bookkeeping->journal_label = $journal_label; + $bookkeeping->fk_user_author = $user->id; - if (! $errorforline) - { - $db->commit(); - } - else - { - $db->rollback(); - } + $result = $bookkeeping->create($user); + if ($result < 0) { + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } + } + } + } + } - } + // Product / Service + if (! $errorforline) + { + foreach ( $tabht[$key] as $k => $mt ) { + if ($mt) { + // get compte id and label + $accountingaccount = new AccountingAccount($db); + if ($accountingaccount->fetch(null, $k, true)) { + $bookkeeping = new BookKeeping($db); + $bookkeeping->doc_date = $val["date"]; + $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->date_create = $now; + $bookkeeping->doc_type = 'customer_invoice'; + $bookkeeping->fk_doc = $key; + $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add; + $bookkeeping->thirdparty_code = $companystatic->code_client; + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label; + $bookkeeping->montant = $mt; + $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; + $bookkeeping->debit = ($mt < 0) ? $mt : 0; + $bookkeeping->credit = ($mt >= 0) ? $mt : 0; + $bookkeeping->code_journal = $journal; + $bookkeeping->journal_label = $journal_label; + $bookkeeping->fk_user_author = $user->id; - if (empty($error) && count($tabpay) > 0) { - setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); - } - elseif (count($tabpay) == $error) - { - setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); - } - else - { - setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); - } - - $action=''; + $result = $bookkeeping->create($user); + if ($result < 0) { + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } + } + } + } + } + } + + // VAT + // var_dump($tabtva); + if (! $errorforline) + { + foreach ( $tabtva[$key] as $k => $mt ) { + if ($mt) { + $bookkeeping = new BookKeeping($db); + $bookkeeping->doc_date = $val["date"]; + $bookkeeping->doc_ref = $val["ref"]; + $bookkeeping->date_create = $now; + $bookkeeping->doc_type = 'customer_invoice'; + $bookkeeping->fk_doc = $key; + $bookkeeping->fk_docdet = 0; // Useless, can be several lines that are source of this record to add + $bookkeeping->thirdparty_code = $companystatic->code_client; + $bookkeeping->subledger_account = ''; + $bookkeeping->subledger_label = ''; + $bookkeeping->numero_compte = $k; + $bookkeeping->label_operation = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.join(', ',$def_tva[$key][$k]); + $bookkeeping->montant = $mt; + $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; + $bookkeeping->debit = ($mt < 0) ? $mt : 0; + $bookkeeping->credit = ($mt >= 0) ? $mt : 0; + $bookkeeping->code_journal = $journal; + $bookkeeping->journal_label = $journal_label; + $bookkeeping->fk_user_author = $user->id; + + $result = $bookkeeping->create($user); + if ($result < 0) { + if ($bookkeeping->error == 'BookkeepingRecordAlreadyExists') // Already exists + { + $error++; + $errorforline++; + //setEventMessages('Transaction for ('.$bookkeeping->doc_type.', '.$bookkeeping->doc_ref.', '.$bookkeeping->fk_docdet.') were already recorded', null, 'warnings'); + } + else + { + $error++; + $errorforline++; + setEventMessages($bookkeeping->error, $bookkeeping->errors, 'errors'); + } + } + } + } + } + + if (! $errorforline) + { + $db->commit(); + } + else + { + $db->rollback(); + + if ($error >= 10) + { + setEventMessages($langs->trans("ErrorTooManyErrorsProcessStopped"), null, 'errors'); + break; // Break in the foreach + } + } + + } + + if (empty($error) && count($tabpay) > 0) { + setEventMessages($langs->trans("GeneralLedgerIsWritten"), null, 'mesgs'); + } + elseif (count($tabpay) == $error) + { + setEventMessages($langs->trans("NoNewRecordSaved"), null, 'warnings'); + } + else + { + setEventMessages($langs->trans("GeneralLedgerSomeRecordWasNotRecorded"), null, 'warnings'); + } + + $action=''; } @@ -378,134 +404,97 @@ if ($action == 'writebookkeeping') { $form = new Form($db); // Export -/*if ($action == 'export_csv') { +if ($action == 'export_csv') { - $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; - $sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; + $sep = $conf->global->ACCOUNTING_EXPORT_SEPARATORCSV; + $sell_journal = $conf->global->ACCOUNTING_SELL_JOURNAL; - include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; - $companystatic = new Client($db); + include DOL_DOCUMENT_ROOT . '/accountancy/tpl/export_journal.tpl.php'; - // Model Cegid Expert Export - if ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 2) { - $sep = ";"; + $companystatic = new Client($db); + $invoicestatic = new Facture($db); - foreach ( $tabfac as $key => $val ) { - $companystatic->id = $tabcompany[$key]['id']; - $companystatic->name = $tabcompany[$key]['name']; - $companystatic->client = $tabcompany[$key]['code_client']; + foreach ( $tabfac as $key => $val ) { + $companystatic->id = $tabcompany[$key]['id']; + $companystatic->name = $tabcompany[$key]['name']; + $companystatic->client = $tabcompany[$key]['code_client']; - $invoicestatic->id = $key; - $invoicestatic->ref = $val["ref"]; + $invoicestatic->id = $key; + $invoicestatic->ref = $val["ref"]; - $date = dol_print_date($val["date"], '%d%m%Y'); + $date = dol_print_date($val["date"], 'day'); - foreach ( $tabttc[$key] as $k => $mt ) { - print $date . $sep; - print $sell_journal . $sep; - print length_accountg($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) . $sep; - print length_accounta(html_entity_decode($k)) . $sep; - print ($mt < 0 ? 'C' : 'D') . $sep; - print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . $sep; - print $val["ref"]; - print "\n"; - } - - // Product / Service - foreach ( $tabht[$key] as $k => $mt ) { - $accountingaccount_static = new AccountingAccount($db); - if ($accountingaccount_static->fetch(null, $k, true)) { - print $date . $sep; - print $sell_journal . $sep; - print length_accountg(html_entity_decode($k)) . $sep; - print $sep; - print ($mt < 0 ? 'D' : 'C') . $sep; - print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount_static->label . $sep; - print $val["ref"]; - print "\n"; - } - } - - // TVA - foreach ( $tabtva[$key] as $k => $mt ) { - if ($mt) { - print $date . $sep; - print $sell_journal . $sep; - print length_accountg(html_entity_decode($k)) . $sep; - print $sep; - print ($mt < 0 ? 'D' : 'C') . $sep; - print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . $sep; - // print $langs->trans("VAT") . $sep; - print $val["ref"]; - print "\n"; - } - } - } - } elseif ($conf->global->ACCOUNTING_EXPORT_MODELCSV == 1) { - // Model Classic Export - foreach ( $tabfac as $key => $val ) { - $companystatic->id = $tabcompany[$key]['id']; - $companystatic->name = $tabcompany[$key]['name']; - $companystatic->client = $tabcompany[$key]['code_client']; - - $invoicestatic->id = $key; - $invoicestatic->ref = $val["ref"]; - - $date = dol_print_date($val["date"], 'day'); - - foreach ( $tabttc[$key] as $k => $mt ) { + foreach ( $tabttc[$key] as $k => $mt ) { + print '"' . $key . '"' . $sep; print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; + print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; - print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; + print '"' . $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER . '"' . $sep; + print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; + print '"' . $langs->trans("Code_tiers") . '"' . $sep; + print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; - print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; + print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; + print '"' . $sell_journal . '"' ; print "\n"; - } + } - // Product / Service - foreach ( $tabht[$key] as $k => $mt ) { - $accountingaccount = new AccountingAccount($db); - $accountingaccount->fetch(null, $k, true); + // Product / Service + foreach ( $tabht[$key] as $k => $mt ) { + $accountingaccount = new AccountingAccount($db); + $accountingaccount->fetch(null, $k, true); - if ($mt) { + + if ($mt) { + print '"' . $key . '"' . $sep; print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; + print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ) . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print '"' . dol_trunc($companystatic->name, 16) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; + print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; + print " " . $sep; + print '"' . utf8_decode ( dol_trunc($accountingaccount->label, 32) ) . '"' . $sep; + print '"' . utf8_decode (dol_trunc($companystatic->name, 16) ) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; - print '"' . ($mt >= 0 ? price($mt) : '') . '"'; + print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; + print '"' . $sell_journal . '"' ; print "\n"; - } - } + } + } - // VAT - foreach ( $tabtva[$key] as $k => $mt ) { - if ($mt) { + // VAT + foreach ( $tabtva[$key] as $k => $mt ) { + + + + if ($mt) { + print '"' . $key . '"' . $sep; print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; + print '"' . utf8_decode ( dol_trunc($companystatic->name, 32) ). '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep; + print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; + print " " . $sep; + print '"' . $langs->trans("VAT") . ' - ' . $def_tva[$key]. '"' . $sep; + print '"' . utf8_decode ( dol_trunc($companystatic->name, 16) ). ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; - print '"' . ($mt >= 0 ? price($mt) : '') . '"'; + print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; + print '"' . $sell_journal . '"' ; print "\n"; - } - } - } - } -} -*/ + } + } + } + } + if (empty($action) || $action == 'view') { llxHeader('', $langs->trans("SellsJournal")); - $nom = $langs->trans("SellsJournal"); + $nom = $langs->trans("SellsJournal") . ' - ' . $accountingjournalstatic->getNomUrl(1); $nomlink = ''; $periodlink = ''; $exportlink = ''; @@ -516,30 +505,38 @@ if (empty($action) || $action == 'view') { $description .= $langs->trans("DepositsAreNotIncluded"); else $description .= $langs->trans("DepositsAreIncluded"); - $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1); - - journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => '')); + $period = $form->select_date($date_start, 'date_start', 0, 0, 0, '', 1, 0, 1) . ' - ' . $form->select_date($date_end, 'date_end', 0, 0, 0, '', 1, 0, 1). ' - ' .$langs->trans("AlreadyInGeneralLedger").' '. $form->selectyesno('in_bookkeeping',$in_bookkeeping,0); + + $varlink = 'id_journal=' . $id_journal; + + journalHead($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => ''), '', $varlink); + + // Button to write into Ledger + if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') { + print img_warning().' '.$langs->trans("SomeMandatoryStepsOfSetupWereNotDone"); + print ' : '.$langs->trans("AccountancyAreaDescMisc", 4, ''.$langs->transnoentitiesnoconv("MenuFinancial").'-'.$langs->transnoentitiesnoconv("MenuAccountancy").'-'.$langs->transnoentitiesnoconv("Setup")."-".$langs->transnoentitiesnoconv("MenuDefaultAccounts").''); + } + print '
'; + if (empty($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER) || $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER == '-1') { + print ''; + } + else { + print ''; + } + print ''; + print '
'; - /*if ($conf->global->ACCOUNTING_EXPORT_MODELCSV != 1 && $conf->global->ACCOUNTING_EXPORT_MODELCSV != 2) { - print ''; - } else { - print ''; - }*/ - print '
'; - print ''; - print '
'; - print ' '; @@ -555,7 +552,7 @@ if (empty($action) || $action == 'view') { print "
"; print ""; print ""; - print ""; + print ""; print ""; print ""; print "\n"; @@ -581,21 +578,20 @@ if (empty($action) || $action == 'view') { $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; $companystatic->client = $tabcompany[$key]['code_client']; - $companystatic->client = $tabcompany[$key]['code_client']; print "'; - print ""; + print ""; print ""; print ""; - print ""; + print ""; } // Product / Service @@ -609,12 +605,12 @@ if (empty($action) || $action == 'view') { print ""; print ""; print ""; // print ""; print ""; @@ -632,14 +628,15 @@ if (empty($action) || $action == 'view') { print ""; print ""; print ""; + print ""; - print ""; // print ""; print ""; print ""; diff --git a/htdocs/accountancy/report/result.php b/htdocs/accountancy/report/result.php index aa31185604a..fad1fcd4b9b 100644 --- a/htdocs/accountancy/report/result.php +++ b/htdocs/accountancy/report/result.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2016/17 Jamal Elbaz * Copyright (C) 2016 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify @@ -25,6 +25,7 @@ require '../../main.inc.php'; // Class require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/report.lib.php'; require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancycategory.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; @@ -41,6 +42,8 @@ $selectcpt = GETPOST('cpt_bk'); $id = GETPOST('id', 'int'); $rowid = GETPOST('rowid', 'int'); $cancel = GETPOST('cancel'); +$simple_report = GETPOST('simple_report'); + // Filter $year = GETPOST('year','int'); @@ -77,7 +80,14 @@ $form = new Form($db); $textprevyear = '' . img_previous() . ''; $textnextyear = ' ' . img_next() . ''; -print load_fiche_titre($langs->trans('ReportInOut'), $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear, 'title_accountancy'); +$nom = $langs->trans("ReportInOut").', '.$langs->trans("ByAccounts"); +$nomlink = ''; +$periodlink = ''; +$exportlink = ''; +$builddate = time(); +$description = ''; +$period = $langs->trans("Detail").' '. $form->selectyesno('simple_report',$simple_report,0) . " " .$textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear ; +report_header($nom, $nomlink, $period, $periodlink, $description, $builddate, $exportlink, array('action' => '')); $moreforfilter=''; @@ -108,30 +118,89 @@ foreach($months as $k => $v){ } print ''; -$cats = $AccCat->getCatsCpts(); -if ($cats < 0) dol_print_error($db, $AccCat->error, $AccCat->errors); -$catsCalcule = $AccCat->getCatsCal(); + +//All categories +$cats = $AccCat->getCats(); if ($catsCalcule < 0) dol_print_error($db, $AccCat->error, $AccCat->errors); $j=1; $sommes = array(); -if (!empty($cats)) -{ - foreach ($cats as $name_cat => $cpts) - { +foreach($cats as $cat ){ + if(!empty($cat['category_type'])){ // category calculed + + $formula = $cat['formula']; + print ""; - print ''; + print ''; + + $vars = array(); + + // Previous Fiscal year (N-1) + foreach($sommes as $code => $det){ + $vars[$code] = $det['NP']; + } + + + $result = strtr($formula, $vars); + + + $r = $AccCat->calculate($result); + + print ''; + $code = $cat['code']; // code categorie de calcule + $sommes[$code]['NP'] += $r; + + // Current fiscal year (N) + if (is_array($sommes) && ! empty($sommes)){ + foreach($sommes as $code => $det){ + $vars[$code] = $det['N']; + } + } + + $result = strtr($formula, $vars); + + $r = $AccCat->calculate($result); + + print ''; + $sommes[$code]['N'] += $r; + + // Detail by month + foreach($months as $k => $v){ + foreach($sommes as $code => $det){ + $vars[$code] = $det['M'][$k]; + } + $result = strtr($formula, $vars); + $r = $AccCat->calculate($result); + print ''; + $sommes[$code]['M'][$k] += $r; + } + + print "\n"; - $position = -1; - $code = -1; + + + }else{ // normal category + + $totCat = array(); + $totCat['M'] = array(); + + // get cpts of category + $cpts = $AccCat->getCptsCat($cat['rowid']); + + + print ""; + print ''; + foreach($cpts as $i => $cpt){ + $var = ! $var; - $position = $cpt['position']; - $code = $cpt['code']; + $code = $cat['code']; + // N-1 $return = $AccCat->getResult($cpt['account_number'], 0, $year_current -1, $cpt['dc']); + if ($return < 0) { setEventMessages(null, $AccCat->errors, 'errors'); $resultNP=0; @@ -139,6 +208,7 @@ if (!empty($cats)) $resultNP=$AccCat->sdc; } + //N $return = $AccCat->getResult($cpt['account_number'], 0, $year_current, $cpt['dc']); if ($return < 0) { setEventMessages(null, $AccCat->errors, 'errors'); @@ -146,13 +216,64 @@ if (!empty($cats)) } else { $resultN=$AccCat->sdc; } + + $totCat['NP'] += $resultNP; + $totCat['N'] += $resultN; + + foreach($months as $k => $v){ + $return = $AccCat->getResult($cpt['account_number'], $k+1, $year_current, $cpt['dc']); + if ($return < 0) { + setEventMessages(null, $AccCat->errors, 'errors'); + $resultM=0; + } else { + $resultM=$AccCat->sdc; + } + $totCat['M'][$k] += $resultM; + + } + } + + print ''; + print ''; + + foreach($totCat['M'] as $k => $v){ + print ''; + } + print "\n"; + + foreach($cpts as $i => $cpt){ + $var = ! $var; + + $code = $cat['code']; + + // N-1 + $return = $AccCat->getResult($cpt['account_number'], 0, $year_current -1, $cpt['dc']); + + if ($return < 0) { + setEventMessages(null, $AccCat->errors, 'errors'); + $resultNP=0; + } else { + $resultNP=$AccCat->sdc; + } + + //N + $return = $AccCat->getResult($cpt['account_number'], 0, $year_current, $cpt['dc']); + if ($return < 0) { + setEventMessages(null, $AccCat->errors, 'errors'); + $resultN=0; + } else { + $resultN=$AccCat->sdc; + } + $sommes[$code]['NP'] += $resultNP; $sommes[$code]['N'] += $resultN; - print ''; - print ''; + print ''; + if ($simple_report == 'yes') { + print ''; print ''; - print ''; - print ''; + print ''; + print ''; + } foreach($months as $k => $v){ $return = $AccCat->getResult($cpt['account_number'], $k+1, $year_current, $cpt['dc']); @@ -163,102 +284,15 @@ if (!empty($cats)) $resultM=$AccCat->sdc; } $sommes[$code]['M'][$k] += $resultM; + if ($simple_report == 'yes') { print ''; - } - - print "\n"; - } - - // If it's a calculated catgory - $p = $position + 1; - if(array_key_exists($p, $catsCalcule)){ - $formula = $catsCalcule[$p]['formula']; - - print ""; - print ''; - - $vars = array(); - - // Previous Fiscal year (N-1) - foreach($sommes as $code => $det){ - $vars[$code] = $det['NP']; - } - $result = strtr($formula, $vars); - eval( '$result = (' . $result . ');' ); - print ''; - $code = $catsCalcule[$p]['code']; // code categorie de calcule - $sommes[$code]['NP'] += $result; - - // Current fiscal year (N) - foreach($sommes as $code => $det){ - $vars[$code] = $det['N']; - } - $result = strtr($formula, $vars); - eval( '$result = (' . $result . ');' ); - print ''; - $sommes[$code]['N'] += $result; - - // Detail by month - foreach($months as $k => $v){ - foreach($sommes as $code => $det){ - $vars[$code] = $det['M'][$k]; } - $result = strtr($formula, $vars); - eval( '$result = (' . $result . ');' ); - print ''; - $sommes[$code]['M'][$k] += $result; } - //print ''; print "\n"; - unset($catsCalcule[$p]); // j'élimine la catégorie calculée après affichage } - $j++; } - // Others calculed category - foreach($catsCalcule as $p => $catc) - { - $formula = $catsCalcule[$p]['formula']; - - print ""; - print ''; - - $vars = array(); - - // Previous Fiscal year (N-1) - foreach($sommes as $code => $det){ - $vars[$code] = $det['NP']; - } - $result = strtr($formula, $vars); - eval( '$result = (' . $result . ');' ); - print ''; - $code = $catsCalcule[$p]['code']; // code categorie de calcule - $sommes[$code]['NP'] += $result; - - // Current fiscal year (N) - foreach($sommes as $code => $det){ - $vars[$code] = $det['N']; - } - $result = strtr($formula, $vars); - eval( '$result = (' . $result . ');' ); - print ''; - $sommes[$code]['N'] += $result; - - // Detail by month - foreach($months as $k => $v){ - foreach($sommes as $code => $det){ - $vars[$code] = $det['M'][$k]; - } - $result = strtr($formula, $vars); - eval( '$result = (' . $result . ');' ); - print ''; - $sommes[$code]['M'][$k] += $result; - } - - //print ''; - print "\n"; - } } print "
".$langs->trans("JournalNum")."" . $langs->trans("Date") . "" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")" . $date . "" . $invoicestatic->getNomUrl(1) . ""; - $accountoshow = length_accountg($k); - if (empty($accountoshow) || $accountoshow == 'NotDefined') - { - print ''.$langs->trans("ProductAccountNotDefined").''; - } - else print $accountoshow; + $accountoshow = length_accountg($k); + if (empty($accountoshow) || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("ProductAccountNotDefined").''; + } + else print $accountoshow; print "
" . $date . "" . $invoicestatic->getNomUrl(1) . ""; - $accountoshow = length_accountg($k); - if (empty($accountoshow) || $accountoshow == 'NotDefined') - { - print ''.$langs->trans("VatAccountNotDefined").''; - } - else print $accountoshow; + $accountoshow = length_accountg($k); + if (empty($accountoshow) || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("VatAccountNotDefined").''; + } + else print $accountoshow; print "" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key]. "" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]). "' . ($mt >= 0 ? price($mt) : '') . "' . ($mt < 0 ? price(- $mt) : '') . "
" . $date . "
" . $date . "" . $invoicestatic->getNomUrl(1) . "" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers") . "" . $companystatic->getNomUrl(0, 'supplier', 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("subledger_account") . "" . $langs->trans("ThirdParty"); // print ' (' . $companystatic->getNomUrl(0, 'supplier', 16) . ')'; // print "" . $langs->trans("Date") . "" . $langs->trans("Piece") . ' (' . $langs->trans("InvoiceRef") . ")" . $langs->trans("AccountAccounting") . "" . $langs->trans("Type") . "" . $langs->trans("Label") . "" . $langs->trans("Debit") . "" . $langs->trans("Credit") . "
"; $accountoshow = length_accounta($k); if (empty($accountoshow) || $accountoshow == 'NotDefined') { - print ''.$langs->trans("ThirdpartyAccountNotDefined").''; + print ''.$langs->trans("ThirdpartyAccountNotDefined").''; } else print $accountoshow; // print "" . $langs->trans("ThirdParty"); // print ' (' . $companystatic->getNomUrl(0, 'customer', 16) . ')'; print '" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . "" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("subledger_account") . "" . ($mt >= 0 ? price($mt) : '') . "" . ($mt < 0 ? price(- $mt) : '') . "
" . $date . "" . $invoicestatic->getNomUrl(1) . ""; - $accountoshow = length_accountg($k); - if (empty($accountoshow) || $accountoshow == 'NotDefined') - { - print ''.$langs->trans("ProductNotDefined").''; - } - else print $accountoshow; + $accountoshow = length_accountg($k); + if (empty($accountoshow) || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("ProductNotDefined").''; + } + else print $accountoshow; print "" . $accountingaccount->label . "" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label . "" . $date . "" . $invoicestatic->getNomUrl(1) . ""; - $accountoshow = length_accountg($k); - if (empty($accountoshow) || $accountoshow == 'NotDefined') - { - print ''.$langs->trans("VATAccountNotDefined").''; - } - else print $accountoshow; + $accountoshow = length_accountg($k); + if (empty($accountoshow) || $accountoshow == 'NotDefined') + { + print ''.$langs->trans("VATAccountNotDefined").''; + } + else print $accountoshow; + print "" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT"). ' '.join(', ',$def_tva[$key][$k]); print "" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . ' '.$def_tva[$key]. "" . $langs->trans("VAT") . "" . ($mt < 0 ? price(- $mt) : '') . "" . ($mt >= 0 ? price($mt) : '') . "
' . $name_cat . '' . $cat['label'] . '' . price($r) . '' . price($r) . '' . price($r) . '
' . $cat['label'] . '' . price($totCat['NP']) . '' . price($totCat['N']) . '' . price($v) . '
' . $cpt['account_number'] . '' . length_accountg($cpt['account_number']) . '' . $cpt['name_cpt'] . '' . price($resultNP) . '' . price($resultN) . '' . price($resultNP) . '' . price($resultN) . '' . price($resultM) . '
' . $catsCalcule[$p]['label'] . '' . price($result) . '' . price($result) . '' . price($result) . '' . $catsCalcule[$p]['formula'] . '
' . $catsCalcule[$p]['label'] . '' . price($result) . '' . price($result) . '' . price($result) . '' . $catsCalcule[$p]['formula'] . '
"; diff --git a/htdocs/accountancy/supplier/card.php b/htdocs/accountancy/supplier/card.php index 47a99c88496..b73c40ced74 100644 --- a/htdocs/accountancy/supplier/card.php +++ b/htdocs/accountancy/supplier/card.php @@ -1,7 +1,7 @@ * Copyright (C) 2005 Simon TOSSER - * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2013-2017 Alexandre Spangaro * Copyright (C) 2013-2014 Olivier Geffroy * Copyright (C) 2013-2014 Florian Henry * Copyright (C) 2014 Juanjo Menent @@ -96,7 +96,7 @@ if (! empty($id)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON l.fk_code_ventilation = aa.rowid"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "facture_fourn as f ON f.rowid = l.fk_facture_fourn "; $sql .= " WHERE f.fk_statut > 0 AND l.rowid = " . $id; - $sql .= " AND f.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy + $sql .= " AND f.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy dol_syslog("/accounting/supplier/card.php sql=" . $sql, LOG_DEBUG); $result = $db->query($sql); diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index 2d36399c9b5..f862feb5ba3 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -1,7 +1,7 @@ * Copyright (C) 2013-2014 Florian Henry - * Copyright (C) 2013-2015 Alexandre Spangaro + * Copyright (C) 2013-2015 Alexandre Spangaro * Copyright (C) 2014 Juanjo Menent * * This program is free software; you can redistribute it and/or modify @@ -21,12 +21,13 @@ /** * \file htdocs/accountancy/supplier/index.php * \ingroup Advanced accountancy - * \brief Home supplier ventilation + * \brief Home supplier journalization page */ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php'; // Langs $langs->load("compta"); @@ -55,7 +56,7 @@ if ($year == 0) { } // Validate History -$action = GETPOST('action', 'alpha'); +$action = GETPOST('action', 'aZ09'); /* @@ -69,14 +70,14 @@ if ($action == 'validatehistory') { // First clean corrupted data $sqlclean = "UPDATE " . MAIN_DB_PREFIX . "facturedet as fd"; - $sqlclean .= " SET fd.fk_code_ventilation = 0"; + $sqlclean .= " SET fk_code_ventilation = 0"; $sqlclean .= ' WHERE fd.fk_code_ventilation NOT IN '; $sqlclean .= ' (SELECT accnt.rowid '; $sqlclean .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; $sqlclean .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'accounting_system as syst'; $sqlclean .= ' ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=' . $conf->global->CHARTOFACCOUNTS . ')'; $resql = $db->query($sqlclean); - + // Now make the binding. Bind automatically only for product with a dedicated account that exists into chart of account, others need a manual bind if ($db->type == 'pgsql') { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det"; @@ -87,12 +88,14 @@ if ($action == 'validatehistory') { $sql1 .= " AND " . MAIN_DB_PREFIX . "facture_fourn_det.fk_code_ventilation = 0"; } else { $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd, " . MAIN_DB_PREFIX . "product as p, " . MAIN_DB_PREFIX . "accounting_account as accnt , " . MAIN_DB_PREFIX . "accounting_system as syst"; - $sql1 .= " SET fd.fk_code_ventilation = accnt.rowid"; + $sql1 .= " SET fk_code_ventilation = accnt.rowid"; $sql1 .= " WHERE fd.fk_product = p.rowid AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid=" . $conf->global->CHARTOFACCOUNTS; $sql1 .= " AND accnt.active = 1 AND p.accountancy_code_buy=accnt.account_number"; $sql1 .= " AND fd.fk_code_ventilation = 0"; } + dol_syslog('htdocs/accountancy/supplier/index.php'); + $resql1 = $db->query($sql1); if (! $resql1) { $error ++; @@ -107,7 +110,7 @@ if ($action == 'validatehistory') { $db->begin(); $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd"; - $sql1 .= " SET fd.fk_code_ventilation = 0"; + $sql1 .= " SET fk_code_ventilation = 0"; $sql1 .= ' WHERE fd.fk_code_ventilation NOT IN '; $sql1 .= ' (SELECT accnt.rowid '; $sql1 .= ' FROM ' . MAIN_DB_PREFIX . 'accounting_account as accnt'; @@ -130,13 +133,13 @@ if ($action == 'validatehistory') { $db->begin(); $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as fd"; - $sql1.= " SET fd.fk_code_ventilation = 0"; + $sql1.= " SET fk_code_ventilation = 0"; $sql1.= " WHERE fd.fk_facture_fourn IN ( SELECT f.rowid FROM " . MAIN_DB_PREFIX . "facture_fourn as f"; $sql1.= " WHERE f.datef >= '" . $db->idate(dol_get_first_day($year_current, 1, false)) . "'"; $sql1.= " AND f.datef <= '" . $db->idate(dol_get_last_day($year_current, 12, false)) . "'"; - $sql1.= " AND f.entity IN (" . getEntity("accountancy", 1) . ")"; + $sql1.= " AND f.entity IN (" . getEntity('accountancy') . ")"; $sql1.= ")"; - + dol_syslog("htdocs/accountancy/customer/index.php fixaccountancycode", LOG_DEBUG); $resql1 = $db->query($sql1); @@ -159,33 +162,28 @@ llxHeader('', $langs->trans("SuppliersVentilation")); $textprevyear = '' . img_previous() . ''; $textnextyear = ' ' . img_next() . ''; -print load_fiche_titre($langs->trans("SuppliersVentilation") . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear, '', 'title_accountancy'); +print load_fiche_titre($langs->trans("SuppliersVentilation") . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear, '', 'title_accountancy'); print $langs->trans("DescVentilSupplier") . '
'; print $langs->trans("DescVentilMore", $langs->transnoentitiesnoconv("ValidateHistory"), $langs->transnoentitiesnoconv("ToBind")) . '
'; print '
'; //print '
'; -// TODO Remove this. Should be done always. +// TODO Remove this. Should be done always or into the repair.php script. if ($conf->global->MAIN_FEATURES_LEVEL > 1) print '' . $langs->trans("CleanFixHistory", $year_current) . ''; //print '
'; + +$y = $year_current; + $buttonbind = '' . $langs->trans("ValidateHistory") . ''; $buttonreset = '' . $langs->trans("CleanHistory", $year_current) . ''; - -$y = $year_current; - -$var = true; - - -print '
'; - print_fiche_titre($langs->trans("OverviewOfAmountOfLinesNotBound"), $buttonbind, ''); print ''; -print ''; +print ''; print ''; for($i = 1; $i <= 12; $i ++) { print ''; @@ -197,18 +195,18 @@ $sql .= " " . $db->ifsql('aa.label IS NULL', "'".$langs->trans('NotMatch')."'", for($i = 1; $i <= 12; $i ++) { $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; } -$sql .= " ROUND(SUM(ffd.total_ht),2) as total"; +$sql .= " SUM(ffd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation"; $sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND ff.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; $sql .= " AND ff.fk_statut > 0 "; -$sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy +$sql .= " AND ff.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NULL"; $sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label"; -dol_syslog('/accountancy/supplier/index.php:: sql=' . $sql); +dol_syslog('htdocs/accountancy/supplier/index.php'); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -239,7 +237,7 @@ print '
'; print_fiche_titre($langs->trans("OverviewOfAmountOfLinesBound"), $buttonreset, ''); print '
' . $langs->trans("Account") . '
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '
'; -print ''; +print ''; print ''; for($i = 1; $i <= 12; $i ++) { print ''; @@ -251,18 +249,18 @@ $sql .= " " . $db->ifsql('aa.label IS NULL', "'".$langs->trans('NotMatch')."'", for($i = 1; $i <= 12; $i ++) { $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; } -$sql .= " ROUND(SUM(ffd.total_ht),2) as total"; +$sql .= " SUM(ffd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "accounting_account as aa ON aa.rowid = ffd.fk_code_ventilation"; $sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND ff.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; $sql .= " AND ff.fk_statut > 0 "; -$sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy +$sql .= " AND ff.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy $sql .= " AND aa.account_number IS NOT NULL"; $sql .= " GROUP BY ffd.fk_code_ventilation,aa.account_number,aa.label"; -dol_syslog('/accountancy/supplier/index.php:: sql=' . $sql); +dol_syslog('htdocs/accountancy/supplier/index.php'); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); @@ -291,9 +289,9 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. { print '
'; print '
'; - + print_fiche_titre($langs->trans("OtherInfo"), '', ''); - + print "
\n"; print '
' . $langs->trans("Account") . '
' . $langs->trans("Account") . '' . $langs->trans("Label") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '
'; print ''; @@ -301,27 +299,27 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. print ''; } print ''; - + $sql = "SELECT '" . $langs->trans("CAHTF") . "' AS label,"; for($i = 1; $i <= 12; $i ++) { $sql .= " SUM(" . $db->ifsql('MONTH(ff.datef)=' . $i, 'ffd.total_ht', '0') . ") AS month" . str_pad($i, 2, '0', STR_PAD_LEFT) . ","; } - $sql .= " ROUND(SUM(ffd.total_ht),2) as total"; + $sql .= " SUM(ffd.total_ht) as total"; $sql .= " FROM " . MAIN_DB_PREFIX . "facture_fourn_det as ffd"; $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "facture_fourn as ff ON ff.rowid = ffd.fk_facture_fourn"; $sql .= " WHERE ff.datef >= '" . $db->idate(dol_get_first_day($y, 1, false)) . "'"; $sql .= " AND ff.datef <= '" . $db->idate(dol_get_last_day($y, 12, false)) . "'"; $sql .= " AND ff.fk_statut > 0 "; - $sql .= " AND ff.entity IN (" . getEntity("facture_fourn", 0) . ")"; // We don't share object for accountancy - - dol_syslog('/accountancy/supplier/index.php:: sql=' . $sql); + $sql .= " AND ff.entity IN (" . getEntity('facture_fourn', 0) . ")"; // We don't share object for accountancy + + dol_syslog('htdocs/accountancy/supplier/index.php'); $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); - + while ( $row = $db->fetch_row($resql)) { - - + + print ''; for($i = 1; $i <= 12; $i ++) { print ''; @@ -329,7 +327,7 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) // This part of code looks strange. print ''; print ''; } - + $db->free($resql); } else { print $db->lasterror(); // Show last sql error diff --git a/htdocs/accountancy/supplier/lines.php b/htdocs/accountancy/supplier/lines.php index 2757b6d8aec..398d12503ab 100644 --- a/htdocs/accountancy/supplier/lines.php +++ b/htdocs/accountancy/supplier/lines.php @@ -1,10 +1,10 @@ - * Copyright (C) 2013-2017 Alexandre Spangaro - * Copyright (C) 2014-2015 Ari Elbaz (elarifr) + * Copyright (C) 2013-2017 Alexandre Spangaro + * Copyright (C) 2014-2015 Ari Elbaz (elarifr) * Copyright (C) 2013-2016 Florian Henry * Copyright (C) 2014 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 * the Free Software Foundation; either version 3 of the License, or @@ -52,9 +52,11 @@ $search_desc = GETPOST('search_desc', 'alpha'); $search_amount = GETPOST('search_amount', 'alpha'); $search_account = GETPOST('search_account', 'alpha'); $search_vat = GETPOST('search_vat', 'alpha'); +$search_country = GETPOST('search_country', 'alpha'); +$search_tvaintra = GETPOST('search_tvaintra', 'alpha'); // Load variable for pagination -$limit = GETPOST('limit') ? GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); +$limit = GETPOST('limit','int')?GETPOST('limit', 'int'):(empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION)?$conf->liste_limit:$conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page', 'int'); @@ -94,17 +96,19 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $search_amount = ''; $search_account = ''; $search_vat = ''; + $search_country = ''; + $search_tvaintra = ''; } if (is_array($changeaccount) && count($changeaccount) > 0) { $error = 0; - + $db->begin(); - + $sql1 = "UPDATE " . MAIN_DB_PREFIX . "facture_fourn_det as l"; $sql1 .= " SET l.fk_code_ventilation=" . GETPOST('account_parent'); $sql1 .= ' WHERE l.rowid IN (' . implode(',', $changeaccount) . ')'; - + dol_syslog('accountancy/supplier/lines.php::changeaccount sql= ' . $sql1); $resql1 = $db->query($sql1); if (! $resql1) { @@ -149,13 +153,15 @@ print ' + +global->BLOCKEDLOG_USE_REMOTE_AUTHORITY) && !empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) { + +?> + + +
'; + +llxFooter(); +$db->close(); diff --git a/htdocs/blockedlog/admin/index.html b/htdocs/blockedlog/admin/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/blockedlog/ajax/authority.php b/htdocs/blockedlog/ajax/authority.php new file mode 100644 index 00000000000..929fd8401d5 --- /dev/null +++ b/htdocs/blockedlog/ajax/authority.php @@ -0,0 +1,77 @@ + + * 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 + * 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/blockedlog/ajax/authority.php + * \ingroup blockedlog + * \brief authority + */ + + +// This script is called with a POST method. +// Directory to scan (full path) is inside POST['dir']. + +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal +//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); +//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); + +$res=require '../../master.inc.php'; + +require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; +require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/authority.class.php'; + +$user=new User($db); +$user->fetch(1); //TODO conf user authority + +$auth = new BlockedLogAuthority($db); + +$signature = GETPOST('s'); +$newblock = GETPOST('b'); +$hash = GETPOST('h'); + +if($auth->fetch(0, $signature)<=0) { + $auth->signature = $signature; + $auth->create($user); +} + + +if(!empty($hash)) { + + echo $auth->checkBlockchain($hash) ? 'hashisok' : 'hashisjunk'; + +} +elseif(!empty($newblock)){ + if($auth->checkBlock($newblock)) { + $auth->addBlock($newblock); + $auth->update($user); + + echo 'blockadded'; + } + else{ + + echo 'blockalreadyadded'; + + } +} +else{ + echo 'idontunderstandwhatihavetodo'; +} + + diff --git a/htdocs/blockedlog/ajax/block-add.php b/htdocs/blockedlog/ajax/block-add.php new file mode 100644 index 00000000000..c82eac81e7b --- /dev/null +++ b/htdocs/blockedlog/ajax/block-add.php @@ -0,0 +1,49 @@ + + * 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 + * 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/blockedlog/ajax/block-add.php + * \ingroup blockedlog + * \brief Block-add + */ + + +// This script is called with a POST method. +// Directory to scan (full path) is inside POST['dir']. + +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal +//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); +//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); + +$res=require '../../main.inc.php'; + +$id = GETPOST('id','int'); +$element = GETPOST('element','alpha'); +$action = GETPOST('action','alpha'); + +if ($element === 'facture') { + require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + + $facture = new Facture($db); + if($facture->fetch($id)>0) { + $facture->call_trigger($action, $user); + } +} diff --git a/htdocs/blockedlog/ajax/block-info.php b/htdocs/blockedlog/ajax/block-info.php new file mode 100644 index 00000000000..83317f33d57 --- /dev/null +++ b/htdocs/blockedlog/ajax/block-info.php @@ -0,0 +1,47 @@ + + * 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 + * 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/blockedlog/ajax/block-info.php + * \ingroup blockedlog + * \brief block-info + */ + + +// This script is called with a POST method. +// Directory to scan (full path) is inside POST['dir']. + +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal +//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); +//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); + + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; + +$id = GETPOST('id'); + +$block = new BlockedLog($db); +if($block->fetch($id)>0) { + echo json_encode($block->object_data); +} +else { + echo json_encode(false); +} diff --git a/htdocs/blockedlog/ajax/check_signature.php b/htdocs/blockedlog/ajax/check_signature.php new file mode 100644 index 00000000000..170693a2ece --- /dev/null +++ b/htdocs/blockedlog/ajax/check_signature.php @@ -0,0 +1,63 @@ + + * 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 + * 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/blockedlog/ajax/block-info.php + * \ingroup blockedlog + * \brief block-info + */ + + +// This script is called with a POST method. +// Directory to scan (full path) is inside POST['dir']. + +if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal +//if (! defined('NOREQUIRETRAN')) define('NOREQUIRETRAN','1'); +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); +//if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); + + +require '../../main.inc.php'; + +if(empty($conf->global->BLOCKEDLOG_AUTHORITY_URL)) exit('BLOCKEDLOG_AUTHORITY_URL not set'); + +require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; +require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/authority.class.php'; + +$auth=new BlockedLogAuthority($db); +$auth->syncSignatureWithAuthority(); + +$block_static = new BlockedLog($db); + +$blocks = $block_static->getLog('just_certified', 0, 0, 1) ; + +$auth->signature = $block_static->getSignature(); + +foreach($blocks as &$b) { + $auth->blockchain.=$b->signature; + +} + +$hash = $auth->getBlockchainHash(); + +$url = $conf->global->BLOCKEDLOG_AUTHORITY_URL.'/blockedlog/ajax/authority.php?s='.$auth->signature.'&h='.$hash; + +$res = file_get_contents($url); +//echo $url; +echo $res; \ No newline at end of file diff --git a/htdocs/blockedlog/class/authority.class.php b/htdocs/blockedlog/class/authority.class.php new file mode 100644 index 00000000000..707e3b1b172 --- /dev/null +++ b/htdocs/blockedlog/class/authority.class.php @@ -0,0 +1,333 @@ + + * + * 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 . + */ + +/** + * Class to manage certif authority + */ +class BlockedLogAuthority +{ + + /** + * Id of the log + * @var int + */ + public $id; + + /** + * Unique fingerprint of the blockchain to store + * @var string + */ + public $signature = ''; + + /** + * Entire fingerprints blockchain + * @var string + */ + public $blockchain = ''; + + /** + * timestamp + * @var int + */ + public $tms = 0; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct($db) { + + $this->db = $db; + + } + + /** + * Get the blockchain + * + * @return string blockchain + */ + public function getLocalBlockChain() { + + $block_static = new BlockedLog($this->db); + + $this->signature = $block_static->getSignature(); + + $blocks = $block_static->getLog('all', 0, 0, 1) ; + + $this->blockchain = ''; + + foreach($blocks as &$b) { + $this->blockchain.=$b->signature; + + } + + return $this->blockchain; + } + + /** + * Get hash of the block chain to check + * + * @return string hash md5 of blockchain + */ + public function getBlockchainHash() { + + return md5($this->signature.$this->blockchain); + + } + + /** + * Get hash of the block chain to check + * + * @param string $hash hash md5 of blockchain to test + * @return boolean + */ + public function checkBlockchain($hash) { + + return ($hash === $this->getBlockchainHash() ); + + } + + /** + * Add a new block to the chain + * + * @param string $block new block to chain + */ + public function addBlock($block) { + + $this->blockchain.=$block; + + } + + /** + * hash already exist into chain ? + * + * @param string $block new block to chain + * @return boolean + */ + public function checkBlock($block) { + + if(strlen($block)!=64) return false; + + $blocks = str_split($this->blockchain,64); + + if(!in_array($block,$blocks)) { + return true; + } + else{ + return false; + } + } + + + /** + * Get object from database + * + * @param int $id Id of object to load + * @param string $signature Signature of object to load + * @return int >0 if OK, <0 if KO, 0 if not found + */ + public function fetch($id, $signature='') { + + global $langs; + + dol_syslog(get_class($this)."::fetch id=".$id, LOG_DEBUG); + + if (empty($id) && empty($signature)) + { + $this->error='BadParameter'; + return -1; + } + + $langs->load("blockedlog"); + + $sql = "SELECT b.rowid, b.signature, b.blockchain, b.tms"; + $sql.= " FROM ".MAIN_DB_PREFIX."blockedlog_authority as b"; + + if ($id) $sql.= " WHERE b.rowid = ". $id; + else if($signature)$sql.= " WHERE b.signature = '". $this->db->escape( $signature ) ."'" ; + + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + + $this->signature = $obj->signature; + $this->blockchain = $obj->blockchain; + + $this->tms = $this->db->jdate($obj->tms); + + return 1; + } + else + { + $this->error=$langs->trans("RecordNotFound"); + return 0; + } + } + else + { + $this->error=$this->db->error(); + return -1; + } + + } + + /** + * Create authority in database. + * + * @param User $user Object user that create + * @return int <0 if KO, >0 if OK + */ + public function create($user) { + + global $conf,$langs,$hookmanager; + + $langs->load('blockedlog'); + + $error=0; + + dol_syslog(get_class($this).'::create', LOG_DEBUG); + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."blockedlog_authority ("; + $sql.= " signature,"; + $sql.= " blockchain"; + $sql.= ") VALUES ("; + $sql.= "'".$this->db->escape($this->signature)."',"; + $sql.= "'".$this->db->escape($this->blockchain)."'"; + $sql.= ")"; + + $res = $this->db->query($sql); + if ($res) + { + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."blockedlog_authority"); + + if ($id > 0) + { + $this->id = $id; + + $this->db->commit(); + + return $this->id; + } + else + { + $this->db->rollback(); + return -2; + } + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + + } + + /** + * Create authority in database. + * + * @param User $user Object user that create + * @return int <0 if KO, >0 if OK + */ + public function update($user) { + + global $conf,$langs,$hookmanager; + + $langs->load('blockedlog'); + + $error=0; + + dol_syslog(get_class($this).'::create', LOG_DEBUG); + + $this->db->begin(); + + $sql = "UPDATE ".MAIN_DB_PREFIX."blockedlog_authority SET "; + $sql.= " blockchain='".$this->db->escape($this->blockchain)."'"; + $sql.= " WHERE rowid=".$this->id; + + $res = $this->db->query($sql); + if ($res) + { + $this->db->commit(); + + return 1; + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + + } + + /** + * For cron to sync to authority. + * + * @return int <0 if KO, >0 if OK + */ + public function syncSignatureWithAuthority() { + global $conf, $langs; + + //TODO create cron task on activation + + if(empty($conf->global->BLOCKEDLOG_AUTHORITY_URL) || empty($conf->global->BLOCKEDLOG_USE_REMOTE_AUTHORITY)) { + $this->error = $langs->trans('NoAuthorityURLDefined'); + return -2; + } + + require_once DOL_DOCUMENT_ROOT.'/blockedlog/class/blockedlog.class.php'; + + $block_static = new BlockedLog($this->db); + + $blocks = $block_static->getLog('not_certified', 0, 0, 1); + + $signature=$block_static->getSignature(); + + foreach($blocks as &$block) { + + $url = $conf->global->BLOCKEDLOG_AUTHORITY_URL.'/blockedlog/ajax/authority.php?s='.$signature.'&b='.$block->signature; + + $res = file_get_contents($url); + echo $block->signature.' '.$url. ' '.$res.'
'; + if($res === 'blockalreadyadded' || $res === 'blockadded') { + + $block->setCertified(); + + } + else { + + $this->error = $langs->trans('ImpossibleToContactAuthority ',$url); + return -1; + } + + + } + + return 1; + } + +} \ No newline at end of file diff --git a/htdocs/blockedlog/class/blockedlog.class.php b/htdocs/blockedlog/class/blockedlog.class.php new file mode 100644 index 00000000000..8a1508b7a04 --- /dev/null +++ b/htdocs/blockedlog/class/blockedlog.class.php @@ -0,0 +1,548 @@ + + * + * 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 . + */ + +/** + * Class to manage Blocked Log + */ + +class BlockedLog +{ + + /** + * Id of the log + * @var int + */ + public $id; + + /** + * Unique fingerprint of the log + * @var string + */ + public $signature = ''; + + /** + * Unique fingerprint of the line log content + * @var string + */ + public $signature_line = ''; + + public $amounts = null; + + /** + * trigger action + * @var string + */ + public $action = ''; + + /** + * Object element + * @var string + */ + public $element = ''; + + /** + * Object id + * @var int + */ + public $fk_object = 0; + + /** + * Log certified by remote authority or not + * @var boolean + */ + public $certified = false; + + /** + * Author + * @var int + */ + public $fk_user = 0; + + public $date_object = 0; + + public $ref_object = ''; + + public $object_data = null; + + public $error = 0; + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + public function __construct(DoliDB $db) + { + $this->db = $db; + + } + + /** + * try to retrieve logged object link + */ + public function getObjectLink() { + global $langs; + + if($this->element === 'facture') { + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + + $object = new Facture($this->db); + if($object->fetch($this->fk_object)>0) { + return $object->getNomUrl(1); + } + else{ + $this->error++; + } + } + else if($this->element === 'payment') { + require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; + + $object = new Paiement($this->db); + if($object->fetch($this->fk_object)>0) { + return $object->getNomUrl(1); + } + else{ + $this->error++; + } + } + + return $langs->trans('ImpossibleToReloadObject', $this->element, $this->fk_object); + + } + + /** + * try to retrieve user author + */ + public function getUser() { + global $langs, $cachedUser; + + if(empty($cachedUser))$cachedUser=array(); + + if(empty($cachedUser[$this->fk_user])) { + $u=new User($this->db); + if($u->fetch($this->fk_user)>0) { + $cachedUser[$this->fk_user] = $u; + } + } + + if(!empty($cachedUser[$this->fk_user])) { + return $cachedUser[$this->fk_user]->getNomUrl(1); + } + + return $langs->trans('ImpossibleToRetrieveUser', $this->fk_user); + } + + /** + * populate log by object + * + * @param payment|facture $object object to store + */ + public function setObjectData(&$object) { + + if($object->element=='payment') { + $this->date_object = $object->datepaye; + } + else{ + $this->date_object = $object->date; + } + + $this->ref_object = $object->ref; + $this->element = $object->element; + $this->fk_object = $object->id; + + $this->object_data=new stdClass(); + + if($this->element === 'facture') { + if(empty($object->thirdparty))$object->fetch_thirdparty(); + $this->object_data->thirdparty = new stdClass(); + + foreach($object->thirdparty as $key=>$value) { + if(!is_object($value)) $this->object_data->thirdparty->{$key} = $value; + } + + $this->object_data->total_ht = (double) $object->total_ht; + $this->object_data->total_tva = (double) $object->total_tva; + $this->object_data->total_ttc = (double) $object->total_ttc; + $this->object_data->total_localtax1= (double) $object->total_localtax1; + $this->object_data->total_localtax2= (double) $object->total_localtax2; + $this->object_data->note_public = (double) $object->note_public; + $this->object_data->note_private= (double) $object->note_private; + + } + elseif($this->element==='payment'){ + + $this->object_data->amounts = $object->amounts; + + } + + + } + + /** + * Get object from database + * + * @param int $id Id of object to load + * @return int >0 if OK, <0 if KO, 0 if not found + */ + public function fetch($id) { + + global $langs; + + dol_syslog(get_class($this)."::fetch id=".$id, LOG_DEBUG); + + if (empty($id)) + { + $this->error='BadParameter'; + return -1; + } + + $langs->load("blockedlog"); + + $sql = "SELECT b.rowid, b.signature, b.amounts, b.action, b.element, b.fk_object, b.certified, b.tms, b.fk_user, b.date_object, b.ref_object, b.object_data"; + $sql.= " FROM ".MAIN_DB_PREFIX."blockedlog as b"; + if ($id) $sql.= " WHERE b.rowid = ". $id; + + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + $this->ref = $obj->rowid; + + $this->signature = $obj->signature; + $this->amounts = (double) $obj->amounts; + $this->action = $obj->action; + $this->element = $obj->element; + + $this->fk_object = trim($obj->fk_object); + $this->date_object = $this->db->jdate($obj->date_object); + $this->ref_object = $obj->ref_object; + + $this->certified = ($obj->certified == 1); + + $this->fk_user = $obj->fk_user; + + $this->tms = $this->db->jdate($obj->tms); + + $this->object_data = unserialize($obj->object_data); + + return 1; + } + else + { + $this->error=$langs->trans("RecordNotFound"); + return 0; + } + } + else + { + $this->error=$this->db->error(); + return -1; + } + + } + + /** + * Set block certified by authority + * + * @return boolean + */ + public function setCertified() { + + $res = $this->db->query("UPDATE ".MAIN_DB_PREFIX."blockedlog SET certified=1 WHERE rowid=".$this->id); + if($res===false) return false; + + return true; + + + } + + /** + * Create blocked log in database. + * + * @param User $user Object user that create + * @return int <0 if KO, >0 if OK + */ + public function create($user) { + + global $conf,$langs,$hookmanager; + + $langs->load('blockedlog'); + + $error=0; + + dol_syslog(get_class($this).'::create', LOG_DEBUG); + + $this->getSignatureRecursive(); + + + if (is_null($this->amounts)) + { + $this->error=$langs->trans("BlockLogNeedAmountsValue"); + dol_syslog($this->error, LOG_WARNING); + return -1; + } + + if(empty($this->element)) { + $this->error=$langs->trans("BlockLogNeedElement"); + dol_syslog($this->error, LOG_WARNING); + return -2; + } + + if(empty($this->action)) { + $this->error=$langs->trans("BlockLogNeedAction"); + dol_syslog($this->error, LOG_WARNING); + return -3; + } + + $this->fk_user = $user->id; + + $this->db->begin(); + + $sql = "INSERT INTO ".MAIN_DB_PREFIX."blockedlog ("; + $sql.= "action,"; + $sql.= " amounts,"; + $sql.= " signature,"; + $sql.= " signature_line,"; + $sql.= " element,"; + $sql.= " fk_object,"; + $sql.= " date_object,"; + $sql.= " ref_object,"; + $sql.= " object_data,"; + $sql.= " certified,"; + $sql.= " fk_user,"; + $sql.= " entity"; + $sql.= ") VALUES ("; + $sql.= "'".$this->db->escape($this->action)."',"; + $sql.= "".$this->amounts.","; + $sql.= "'".$this->db->escape($this->signature)."',"; + $sql.= "'".$this->db->escape($this->signature_line)."',"; + $sql.= "'".$this->db->escape($this->element)."',"; + $sql.= "".$this->fk_object.","; + $sql.= "'".$this->db->idate($this->date_object)."',"; + $sql.= "'".$this->db->escape($this->ref_object)."',"; + $sql.= "'".$this->db->escape(serialize($this->object_data))."',"; + $sql.= "0,"; + $sql.= "".$user->id.","; + $sql.= $conf->entity; + $sql.= ")"; + + $res = $this->db->query($sql); + if ($res) + { + $id = $this->db->last_insert_id(MAIN_DB_PREFIX."blockedlog"); + + if ($id > 0) + { + $this->id = $id; + + $this->db->commit(); + + return $this->id; + } + else + { + $this->db->rollback(); + return -2; + } + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -1; + } + + } + + /** + * return crypted value. + * + * @param string $value string to crypt + * @return string crypted string + */ + private function crypt($value) { + + return hash('sha256',$value); + + } + + /** + * check if current signature still correct compare to the chain + * + * @return boolean + */ + public function checkSignature() { + + $signature_to_test = $this->signature; + + $this->getSignatureRecursive(); + + $res = ($signature_to_test === $this->signature); + + if(!$res) { + $this->error++; + } + + return $res; + } + + /** + * set current signatures + */ + private function getSignatureRecursive(){ + + $this->signature_line = $this->crypt( $this->action . $this->getSignature() . $this->amounts . print_r($this->object_data, true) ); + /*if($this->signature=='d6320580a02c1ab67fcc0a6d49d453c7d96dda0148901736f7f55725bfe1b900' || $this->signature=='ea65d435ff12ca929936a406aa9d707d99fb334c127878d256b602a5541bbbc9') { + var_dump($this->signature_line,$this->action ,$this->getSignature() , $this->amounts , $this->object_data); + }*/ + $this->signature = $this->signature_line; + + $logs = $this->getLog('all', 0, 0, 1) ; + if($logs!==false) { + foreach($logs as &$b) { + + if($this->id>0 && $b->id == $this->id) break; // on arrête sur un enregistrement précis pour recalculer une signature + + $b->getCurrentValue(); // on récupère la valeur actuelle en base de l'élément enregistré + + $this->signature = $this->crypt($this->signature. $this->action . $b->signature . $b->amounts); + } + } + + } + + /** + * return log object for a element. + * + * @param string $element element to search + * @param int $fk_object id of object to search + * @param int $limit max number of element, 0 for all + * @param string $order sort of query + * @return array array of object log + */ + public function getLog($element, $fk_object, $limit = 0, $order = -1) { + global $conf,$cachedlogs ; + + /* $cachedlogs allow fastest search */ + if(empty($cachedlogs)) $cachedlogs=array(); + + + if($element=='all') { + + $sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog + WHERE entity=".$conf->entity; + + } + else if($element=='not_certified') { + $sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog + WHERE entity=".$conf->entity." AND certified = 0"; + + } + else if($element=='just_certified') { + $sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog + WHERE entity=".$conf->entity." AND certified = 1"; + + } + else{ + $sql="SELECT rowid FROM ".MAIN_DB_PREFIX."blockedlog + WHERE element='".$element."' AND fk_object=".(int) $fk_object; + + } + + $sql.=($order<0 ? ' ORDER BY rowid DESC ' : ' ORDER BY rowid ASC '); + + if($limit > 0 )$sql.=' LIMIT '.$limit; + + $res = $this->db->query($sql); + + if($res) { + + $results=array(); + + while($obj = $this->db->fetch_object($res)) { + + if(!isset($cachedlogs[$obj->rowid])) { + $b=new BlockedLog($this->db); + $b->fetch($obj->rowid); + + $cachedlogs[$obj->rowid] = $b; + } + + $results[] = $cachedlogs[$obj->rowid]; + + } + + return $results; + } + else{ + return false; + } + } + + /** + * set amounts of log from current element value in order to compare signature. + */ + private function getCurrentValue() { + + if($this->element === 'payment') { + $sql="SELECT amount FROM ".MAIN_DB_PREFIX."paiement WHERE rowid=".$this->fk_object; + + $res = $this->db->query($sql); + + if($res && $obj = $this->db->fetch_object($res)) { + $this->amounts = (double) $obj->amount; + } + } + elseif($this->element === 'facture') { + $sql="SELECT total_ttc FROM ".MAIN_DB_PREFIX."facture WHERE rowid=".$this->fk_object; + + $res = $this->db->query($sql); + if($res && $obj = $this->db->fetch_object($res)) { + $this->amounts = (double) $obj->total_ttc; + } + } + + } + + /** + * Return and set the entity signature included into line signature + * + * @return string current entity signature + */ + public function getSignature() { + global $db,$conf,$mysoc; + + if (empty($conf->global->BLOCKEDLOG_ENTITY_FINGERPRINT)) { // creation of a unique fingerprint + + require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; + + $fingerprint = $this->crypt(print_r($mysoc,true).time().rand(0,1000)); + + dolibarr_set_const($db, 'BLOCKEDLOG_ENTITY_FINGERPRINT', $fingerprint, 'chaine',0,'Numeric Unique Fingerprint', $conf->entity); + + $conf->global->BLOCKEDLOG_ENTITY_FINGERPRINT=$fingerprint; + } + + return $conf->global->BLOCKEDLOG_ENTITY_FINGERPRINT; + } + +} + diff --git a/htdocs/blockedlog/lib/blockedlog.lib.php b/htdocs/blockedlog/lib/blockedlog.lib.php new file mode 100644 index 00000000000..cffac7cbff9 --- /dev/null +++ b/htdocs/blockedlog/lib/blockedlog.lib.php @@ -0,0 +1,57 @@ + + * + * 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/blockedlog/lib/blockedlog.lib.php + * \ingroup system + * \brief Library for common blockedlog functions + */ + +/** + * Define head array for tabs of blockedlog tools setup pages + * + * @return Array of head + */ +function blockedlogadmin_prepare_head() +{ + global $langs, $conf; + + $h = 0; + $head = array(); + + $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/blockedlog.php"; + $head[$h][1] = $langs->trans("Setup"); + $head[$h][2] = 'blockedlog'; + $h++; + + $head[$h][0] = DOL_URL_ROOT."/blockedlog/admin/fingerprints.php"; + $head[$h][1] = $langs->trans("Fingerprints"); + $head[$h][2] = 'fingerprints'; + $h++; + + $object=new stdClass(); + + // Show more tabs from modules + // Entries must be declared in modules descriptor with line + // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab + // $this->tabs = array('entity:-tabname); to remove a tab + complete_head_from_modules($conf,$langs,$object,$head,$h,'blockedlog'); + + complete_head_from_modules($conf,$langs,$object,$head,$h,'blockedlog','remove'); + + return $head; +} diff --git a/htdocs/blockedlog/lib/index.html b/htdocs/blockedlog/lib/index.html new file mode 100644 index 00000000000..e69de29bb2d diff --git a/htdocs/bookmarks/bookmarks.lib.php b/htdocs/bookmarks/bookmarks.lib.php index 4df9b56979d..8f8295f0e53 100644 --- a/htdocs/bookmarks/bookmarks.lib.php +++ b/htdocs/bookmarks/bookmarks.lib.php @@ -40,10 +40,29 @@ function printBookmarksList($aDb, $aLangs) $langs->load("bookmarks"); - $url= $_SERVER["PHP_SELF"].(! empty($_SERVER["QUERY_STRING"])?'?'.$_SERVER["QUERY_STRING"]:''); - + $url= $_SERVER["PHP_SELF"]; + + if (! empty($_SERVER["QUERY_STRING"])) + { + $url.=(dol_escape_htmltag($_SERVER["QUERY_STRING"])?'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]):''); + } + else + { + global $sortfield,$sortorder; + $tmpurl=''; + // No urlencode, all param $url will be urlencoded later + if ($sortfield) $tmpurl.=($tmpurl?'&':'').'sortfield='.$sortfield; + if ($sortorder) $tmpurl.=($tmpurl?'&':'').'sortorder='.$sortorder; + foreach($_POST as $key => $val) + { + if (preg_match('/^search_/', $key) && $val != '') $tmpurl.=($tmpurl?'&':'').$key.'='.$val; + } + + $url.=($tmpurl?'?'.$tmpurl:''); + } + $ret = ''; - + // Menu bookmark $ret.= ''."\n"; @@ -55,7 +74,8 @@ function printBookmarksList($aDb, $aLangs) // Url to go on create new bookmark page if ($user->rights->bookmark->creer) { - $urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&urlsource='.urlencode($url).'&url='.urlencode($url); + //$urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&urlsource='.urlencode($url).'&url='.urlencode($url); + $urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&url='.urlencode($url); $ret.= ''; } // Menu with all bookmarks @@ -63,7 +83,7 @@ function printBookmarksList($aDb, $aLangs) { $sql = "SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX."bookmark"; $sql.= " WHERE (fk_user = ".$user->id." OR fk_user is NULL OR fk_user = 0)"; - $sql.= " AND entity IN (".getEntity('bookmarks',1).")"; + $sql.= " AND entity IN (".getEntity('bookmarks').")"; $sql.= " ORDER BY position"; if ($resql = $db->query($sql) ) { @@ -83,12 +103,12 @@ function printBookmarksList($aDb, $aLangs) dol_print_error($db); } } - + $ret.= ''; $ret.= ''; - + $ret.=ajax_combobox('boxbookmark'); - + $ret.=''; diff --git a/htdocs/bookmarks/card.php b/htdocs/bookmarks/card.php index a9d4a39ef85..e9722669e7d 100644 --- a/htdocs/bookmarks/card.php +++ b/htdocs/bookmarks/card.php @@ -39,6 +39,7 @@ $id=GETPOST("id"); $action=GETPOST("action","alpha"); $title=GETPOST("title","alpha"); $url=GETPOST("url","alpha"); +$urlsource=GETPOST("urlsource","alpha"); $target=GETPOST("target","alpha"); $userid=GETPOST("userid","int"); $position=GETPOST("position","int"); @@ -64,7 +65,7 @@ if ($action == 'add' || $action == 'addproduct' || $action == 'update') if (GETPOST("cancel")) { - if (empty($backtopage)) $backtopage=(GETPOST("urlsource")?GETPOST("urlsource"):((! empty($url))?$url:DOL_URL_ROOT.'/bookmarks/list.php')); + if (empty($backtopage)) $backtopage=($urlsource?$urlsource:((! empty($url))?$url:DOL_URL_ROOT.'/bookmarks/list.php')); header("Location: ".$backtopage); exit; } @@ -97,7 +98,7 @@ if ($action == 'add' || $action == 'addproduct' || $action == 'update') if ($res > 0) { - if (empty($backtopage)) $backtopage=(GETPOST("urlsource")?GETPOST("urlsource"):DOL_URL_ROOT.'/bookmarks/list.php'); + if (empty($backtopage)) $backtopage=($urlsource?$urlsource:((! empty($url))?$url:DOL_URL_ROOT.'/bookmarks/list.php')); header("Location: ".$backtopage); exit; } @@ -121,6 +122,7 @@ if ($action == 'add' || $action == 'addproduct' || $action == 'update') } } + /* * View */ @@ -153,15 +155,15 @@ if ($action == 'create') print load_fiche_titre($langs->trans("NewBookmark")); - dol_fiche_head($head, $hselected, $langs->trans("Bookmark"),0,'bookmark'); + dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), 0, 'bookmark'); print '
' . $langs->trans("Total") . '' . $langs->trans('MonthShort' . str_pad($i, 2, '0', STR_PAD_LEFT)) . '' . $langs->trans("Total") . '
' . $row[0] . '' . price($row[$i]) . '' . price($row[13]) . '
'; print ''; dol_set_focus('#titlebookmark'); - + // Url - print ''; + print ''; // Target print ' - + - - +
'.$langs->trans("BookmarkTitle").''.$langs->trans("SetHereATitleForLink").'
'.$langs->trans("UrlOrLink").''.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'
'.$langs->trans("UrlOrLink").''.$langs->trans("UseAnExternalHttpLinkOrRelativeDolibarrLink").'
'.$langs->trans("BehaviourOnClick").''; @@ -219,14 +221,14 @@ if ($id > 0 && ! preg_match('/^add/i',$action)) } - dol_fiche_head($head, $hselected, $langs->trans("Bookmark"),0,'bookmark'); + dol_fiche_head($head, $hselected, $langs->trans("Bookmark"), -1, 'bookmark'); $linkback = ''.$langs->trans("BackToList").''; - + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', '', 0); print '
'; - + print '
'; print ''; @@ -304,7 +306,7 @@ if ($id > 0 && ! preg_match('/^add/i',$action)) print '
'; print '
'; - + dol_fiche_end(); if ($action == 'edit') diff --git a/htdocs/bookmarks/list.php b/htdocs/bookmarks/list.php index 40a316d881b..a192076e88a 100644 --- a/htdocs/bookmarks/list.php +++ b/htdocs/bookmarks/list.php @@ -39,11 +39,11 @@ if (! $user->rights->bookmark->lire) { } $optioncss = GETPOST('optioncss','alpha'); -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/cashdesk/affContenu.php b/htdocs/cashdesk/affContenu.php index 280f2b81908..bd778f3422e 100644 --- a/htdocs/cashdesk/affContenu.php +++ b/htdocs/cashdesk/affContenu.php @@ -34,8 +34,8 @@ if ( $_GET['id'] == 'NOUV' ) // Recuperation, s'il existe, de l'objet contenant les infos de la vente en cours ... if (isset($_SESSION['serObjFacturation'])) { - $obj_facturation = unserialize($_SESSION['serObjFacturation']); - unset($_SESSION['serObjFacturation']); + $obj_facturation = unserialize($_SESSION['serObjFacturation']); + unset($_SESSION['serObjFacturation']); } else { @@ -43,7 +43,7 @@ else $obj_facturation = new Facturation(); } - +// $obj_facturation contains data for all invoice total + selection of current product $obj_facturation->calculTotaux(); // Redefine prix_total_ttc, prix_total_ht et montant_tva from $_SESSION['poscart'] diff --git a/htdocs/cashdesk/affIndex.php b/htdocs/cashdesk/affIndex.php index b5432b94eec..a2e467a35e3 100644 --- a/htdocs/cashdesk/affIndex.php +++ b/htdocs/cashdesk/affIndex.php @@ -27,6 +27,8 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/cashdesk/include/environnement.php'; require_once DOL_DOCUMENT_ROOT.'/cashdesk/include/keypad.php'; +$error=GETPOST('error'); + // Test if already logged if ( $_SESSION['uid'] <= 0 ) { @@ -54,9 +56,7 @@ print ''."\n"; if (!empty($error)) { - print $error; - print ''; - exit; + dol_htmloutput_events(); } print '
'."\n"; diff --git a/htdocs/cashdesk/class/Facturation.class.php b/htdocs/cashdesk/class/Facturation.class.php index 579d244246b..b55524a874a 100644 --- a/htdocs/cashdesk/class/Facturation.class.php +++ b/htdocs/cashdesk/class/Facturation.class.php @@ -99,17 +99,25 @@ class Facturation $product = new Product($db); $product->fetch($this->id); - + $vatrowid = $this->tva(); - + $tmp = getTaxesFromId($vatrowid); - $vat_rate = $tmp['rate']; + $txtva = $tmp['rate'].(empty($tmp['code'])?'':' ('.$tmp['code'].')'); $vat_npr = $tmp['npr']; - + $localtaxarray = getLocalTaxesFromRate($vatrowid, 0, $societe, $mysoc, 1); - + + // Clean vat code + $vat_src_code=''; + if (preg_match('/\((.*)\)/', $txtva, $reg)) + { + $vat_src_code = $reg[1]; + $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. + } + // Define part of HT, VAT, TTC - $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $vat_rate, -1, -1, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); + $resultarray=calcul_price_total($this->qte, $this->prix(), $this->remisePercent(), $txtva, -1, -1, 0, 'HT', $use_npr, $product->type, $mysoc, $localtaxarray); // Calcul du total ht sans remise $total_ht = $resultarray[0]; @@ -136,7 +144,7 @@ class Facturation $newcartarray[$i]['label']=$product->label; $newcartarray[$i]['price']=$product->price; $newcartarray[$i]['price_ttc']=$product->price_ttc; - + if (! empty($conf->global->PRODUIT_MULTIPRICES)) { if (isset($product->multiprices[$societe->price_level])) @@ -148,7 +156,7 @@ class Facturation $newcartarray[$i]['fk_article']=$this->id; $newcartarray[$i]['qte']=$this->qte(); - $newcartarray[$i]['fk_tva']=$this->tva(); + $newcartarray[$i]['fk_tva']=$this->tva(); // Vat rowid $newcartarray[$i]['remise_percent']=$remise_percent; $newcartarray[$i]['remise']=price2num($montant_remise_ht); $newcartarray[$i]['total_ht']=price2num($total_ht,'MT'); @@ -220,7 +228,7 @@ class Facturation $this->prix_total_vat = $total_vat; $this->prix_total_localtax1 = $total_localtax1; $this->prix_total_localtax2 = $total_localtax2; - + $this->montant_tva = $total_ttc - $total_ht; //print $this->prix_total_ttc.'eeee'; exit; } diff --git a/htdocs/cashdesk/css/style.css b/htdocs/cashdesk/css/style.css index ab8d660fcf1..c34e8596f01 100644 --- a/htdocs/cashdesk/css/style.css +++ b/htdocs/cashdesk/css/style.css @@ -106,6 +106,14 @@ p { padding-right: 5px; } +/* Force values for small screen 570 */ +@media only screen and (max-width: 570px) +{ + .menu_choix0 { + max-width: 180px; + } +} + .menu_choix0 a { font-weight: normal; text-decoration: none; @@ -259,7 +267,6 @@ p.titre { /* --------------------- Combo lists ------------------- */ .select_design { - width: 370px; overflow: auto; } diff --git a/htdocs/cashdesk/facturation.php b/htdocs/cashdesk/facturation.php index dd722805eb6..f52890b68d2 100644 --- a/htdocs/cashdesk/facturation.php +++ b/htdocs/cashdesk/facturation.php @@ -35,7 +35,7 @@ $form=new Form($db); // Get list of articles (in warehouse '$conf_fkentrepot' if defined and stock module enabled) -if ( GETPOST('filtre') ) { +if ( GETPOST('filtre','alpha') ) { // Avec filtre $ret=array(); $i=0; @@ -44,25 +44,26 @@ if ( GETPOST('filtre') ) { if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$conf_fkentrepot."'"; - $sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; + $sql.= " WHERE p.entity IN (".getEntity('product').")"; $sql.= " AND p.tosell = 1"; if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0"; - $sql.= " AND (p.ref LIKE '%".$db->escape(GETPOST('filtre'))."%' OR p.label LIKE '%".$db->escape(GETPOST('filtre'))."%'"; - if (! empty($conf->barcode->enabled)) { - - $filtre = GETPOST('filtre'); + $sql.= " AND ("; + $sql.= "p.ref LIKE '%".$db->escape(GETPOST('filtre'))."%' OR p.label LIKE '%".$db->escape(GETPOST('filtre'))."%'"; + if (! empty($conf->barcode->enabled)) + { + $filtre = GETPOST('filtre','alpha'); //If the barcode looks like an EAN13 format and the last digit is included in it, //then whe look for the 12-digit too //As the twelve-digit string will also hit the 13-digit code, we only look for this one if (strlen($filtre) == 13) { $crit_12digit = substr($filtre, 0, 12); - $sql .= " OR p.barcode LIKE '%".$db->escape($crit_12digit)."%')"; + $sql .= " OR p.barcode LIKE '%".$db->escape($crit_12digit)."%'"; } else { - $sql.= " OR p.barcode LIKE '%".$db->escape($filtre)."%')"; + $sql.= " OR p.barcode LIKE '%".$db->escape($filtre)."%'"; } } - else $sql.= ")"; + $sql.= ")"; $sql.= " ORDER BY label"; dol_syslog("facturation.php", LOG_DEBUG); @@ -96,7 +97,7 @@ if ( GETPOST('filtre') ) { if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$conf_fkentrepot."'"; - $sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; + $sql.= " WHERE p.entity IN (".getEntity('product').")"; $sql.= " AND p.tosell = 1"; if(!$conf->global->CASHDESK_SERVICES) $sql.= " AND p.fk_product_type = 0"; $sql.= " ORDER BY p.label"; @@ -154,34 +155,6 @@ global $mysoc; $ret=array(); $i=0; -$sql = "SELECT t.rowid, t.taux"; -$sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t"; -$sql.= ", ".MAIN_DB_PREFIX."c_country as c"; -$sql.= " WHERE t.fk_pays = c.rowid"; -$sql.= " AND t.active = 1"; -$sql.= " AND c.code = '".$mysoc->country_code."'"; -//print $sql; - -$resql = $db->query($sql); -if ($resql) -{ - while ( $tab = $db->fetch_array($resql) ) - { - foreach ( $tab as $cle => $valeur ) - { - $ret[$i][$cle] = $valeur; - } - $i++; - } - $db->free($resql); -} -else -{ - dol_print_error($db); -} -$tab_tva = $ret; - - // Reinitialisation du mode de paiement, en cas de retour aux achats apres validation $obj_facturation->getSetPaymentMode('RESET'); $obj_facturation->montantEncaisse('RESET'); diff --git a/htdocs/cashdesk/facturation_dhtml.php b/htdocs/cashdesk/facturation_dhtml.php index 3046644c35e..72fbd509535 100644 --- a/htdocs/cashdesk/facturation_dhtml.php +++ b/htdocs/cashdesk/facturation_dhtml.php @@ -50,7 +50,7 @@ if (dol_strlen($search) >= 0) // If search criteria is on char length at least if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = '".$conf_fkentrepot."'"; - $sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; + $sql.= " WHERE p.entity IN (".getEntity('product').")"; $sql.= " AND p.tosell = 1"; $sql.= " AND p.fk_product_type = 0"; // Add criteria on ref/label diff --git a/htdocs/cashdesk/facturation_verif.php b/htdocs/cashdesk/facturation_verif.php index d4bf53e01c5..24876a0a8fb 100644 --- a/htdocs/cashdesk/facturation_verif.php +++ b/htdocs/cashdesk/facturation_verif.php @@ -39,11 +39,11 @@ switch($action) default: if ( $_POST['hdnSource'] != 'NULL' ) { - $sql = "SELECT p.rowid, p.ref, p.price, p.tva_tx, p.recuperableonly"; + $sql = "SELECT p.rowid, p.ref, p.price, p.tva_tx, p.default_vat_code, p.recuperableonly"; if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= ", ps.reel"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; if (! empty($conf->stock->enabled) && !empty($conf_fkentrepot)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON p.rowid = ps.fk_product AND ps.fk_entrepot = ".$conf_fkentrepot; - $sql.= " WHERE p.entity IN (".getEntity('product', 1).")"; + $sql.= " WHERE p.entity IN (".getEntity('product').")"; // Recuperation des donnees en fonction de la source (liste deroulante ou champ texte) ... if ( $_POST['hdnSource'] == 'LISTE' ) @@ -56,7 +56,6 @@ switch($action) } $result = $db->query($sql); - if ($result) { // ... et enregistrement dans l'objet @@ -69,62 +68,90 @@ switch($action) $ret[$key] = $value; } // Here $ret['tva_tx'] is vat rate of product but we want to not use the one into table but found by function - + $productid = $ret['rowid']; $product = new Product($db); $product->fetch($productid); + $prod = $product; $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY']; $societe = new Societe($db); $societe->fetch($thirdpartyid); - $tva_tx = get_default_tva($mysoc,$societe,$productid); - $tva_npr = get_default_npr($mysoc,$societe,$productid); + // Update if prices fields are defined + $tva_tx = get_default_tva($mysoc, $societe, $product->id); + $tva_npr = get_default_npr($mysoc, $societe, $product->id); if (empty($tva_tx)) $tva_npr=0; - dol_syslog('tva_tx='.$tva_tx.'-tva_npr='.$tva_npr); - + + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_min = $prod->price_min; + $price_base_type = $prod->price_base_type; + + // multiprix if (! empty($conf->global->PRODUIT_MULTIPRICES) && ! empty($societe->price_level)) { - if(isset($product->multiprices[$societe->price_level])) - { - $ret['price'] = $product->multiprices[$societe->price_level]; - $ret['price_ttc'] = $product->multiprices_ttc[$societe->price_level]; - // $product->multiprices_min[$societe->price_level]; - // $product->multiprices_min_ttc[$societe->price_level]; - // $product->multiprices_base_type[$societe->price_level]; - if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility - { - if (isset($prod->multiprices_tva_tx[$societe->price_level])) $tva_tx=$prod->multiprices_tva_tx[$societe->price_level]; - if (isset($prod->multiprices_recuperableonly[$societe->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$societe->price_level]; - if (empty($tva_tx)) $tva_npr=0; - } - } + $pu_ht = $prod->multiprices[$societe->price_level]; + $pu_ttc = $prod->multiprices_ttc[$societe->price_level]; + $price_min = $prod->multiprices_min[$societe->price_level]; + $price_base_type = $prod->multiprices_base_type[$societe->price_level]; + if (! empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) // using this option is a bug. kept for backward compatibility + { + if (isset($prod->multiprices_tva_tx[$societe->price_level])) $tva_tx=$prod->multiprices_tva_tx[$societe->price_level]; + if (isset($prod->multiprices_recuperableonly[$societe->price_level])) $tva_npr=$prod->multiprices_recuperableonly[$societe->price_level]; + } + } + elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) + { + require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; + + $prodcustprice = new Productcustomerprice($db); + + $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $societe->id); + + $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); + if ($result >= 0) + { + if (count($prodcustprice->lines) > 0) + { + $pu_ht = price($prodcustprice->lines [0]->price); + $pu_ttc = price($prodcustprice->lines [0]->price_ttc); + $price_base_type = $prodcustprice->lines [0]->price_base_type; + $tva_tx = $prodcustprice->lines [0]->tva_tx; + } + } + else + { + setEventMessages($prodcustprice->error, $prodcustprice->errors, 'errors'); + } + } + + $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx)); + $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx)); + + // if price ht is forced (ie: calculated by margin rate and cost price). TODO Why this ? + if (! empty($price_ht)) { + $pu_ht = price2num($price_ht, 'MU'); + $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); + } + // On reevalue prix selon taux tva car taux tva transaction peut etre different + // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). + elseif ($tmpvat != $tmpprodvat) { + if ($price_base_type != 'HT') { + $pu_ht = price2num($pu_ttc / (1 + ($tmpvat / 100)), 'MU'); + } else { + $pu_ttc = price2num($pu_ht * (1 + ($tmpvat / 100)), 'MU'); + } } - $ret['tva_tx'] = $tva_tx; - $ret['tva_npr'] = $tva_npr; - //var_dump('tva_tx='.$ret['tva_tx'].'-tva_npr='.$ret['tva_npr'].'-'.$conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL);exit; - $obj_facturation->id($ret['rowid']); $obj_facturation->ref($ret['ref']); $obj_facturation->stock($ret['reel']); $obj_facturation->prix($ret['price']); - - // Use $ret['tva_tx'] / ret['tva_npr'] to find vat id - $vatrowid = null; - $sqlfindvatid = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'c_tva'; - $sqlfindvatid.= ' WHERE taux = '.$ret['tva_tx'].' AND recuperableonly = '.(int) $ret['tva_npr']; - $sqlfindvatid.= ' AND fk_pays = '.$mysoc->country_id; - $resqlfindvatid=$db->query($sqlfindvatid); - if ($resqlfindvatid) - { - $obj = $db->fetch_object($resqlfindvatid); - if ($obj) $vatrowid = $obj->rowid; - } - else dol_print_error($db); - - dol_syslog("save vatrowid=".$vatrowid); - $obj_facturation->tva($vatrowid); // Save vat it for next use + + + $vatrate = $tva_tx; + $obj_facturation->vatrate = $vatrate; // Save vat rate (full text vat with code) // Definition du filtre pour n'afficher que le produit concerne if ( $_POST['hdnSource'] == 'LISTE' ) @@ -170,21 +197,21 @@ switch($action) { $_SESSION["CASHDESK_ID_THIRDPARTY"] = $newthirdpartyid; } - + $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation'; - break; - + break; + case 'ajout_article': // We have clicked on button "Add product" if (! empty($obj_facturation->id)) // A product was previously selected and stored in session, so we can add it { dol_syslog("facturation_verif save vat ".$_POST['selTva']); $obj_facturation->qte($_POST['txtQte']); - $obj_facturation->tva($_POST['selTva']); // Save VAT selected so we can use it for next product + $obj_facturation->tva($_POST['selTva']); // id of vat. Saved so we can use it for next product $obj_facturation->remisePercent($_POST['txtRemise']); $obj_facturation->ajoutArticle(); // This add an entry into $_SESSION['poscart'] // We update prixTotalTtc - + } $redirection = DOL_URL_ROOT.'/cashdesk/affIndex.php?menutpl=facturation'; diff --git a/htdocs/cashdesk/tpl/facturation1.tpl.php b/htdocs/cashdesk/tpl/facturation1.tpl.php index 8f74cf98626..580012847f5 100644 --- a/htdocs/cashdesk/tpl/facturation1.tpl.php +++ b/htdocs/cashdesk/tpl/facturation1.tpl.php @@ -38,7 +38,7 @@ $langs->load("cashdesk"); - +
@@ -89,51 +89,54 @@ $langs->load("cashdesk"); -
trans("FilterRefOrLabelOrBC"); ?>trans("Designation"); ?>
- - - +
trans("Qty"); ?>trans("Stock"); ?>
+ + - - - + - - - - - - + + + + + + + + + + +
trans("Qty"); ?> trans("PriceUHT"); ?> trans("Discount"); ?> (%)trans("TotalHT"); ?>  trans("VATRate"); ?>
- - - tva(); // Try to get a previously entered VAT rowid. First time, this will return empty. + + vatrate; // To get vat rate we just have selected + $buyer = new Societe($db); if ($_SESSION["CASHDESK_ID_THIRDPARTY"] > 0) $buyer->fetch($_SESSION["CASHDESK_ID_THIRDPARTY"]); - - echo $form->load_tva('selTva', (isset($_POST["selTva"])?GETPOST("selTva",'alpha',2):-1), $mysoc, $buyer, 0, 0, '', false, -1); + echo $form->load_tva('selTva', (isset($_POST["selTva"])?GETPOST("selTva",'alpha',2):$vatrate), $mysoc, $buyer, 0, 0, '', false, -1); ?>
trans("Stock"); ?> + + trans("TotalHT"); ?>
" /> @@ -149,13 +152,13 @@ $langs->load("cashdesk");
trans("TotalTicket"); ?>trans("Received"); ?>trans("Change"); ?>
+
diff --git a/htdocs/cashdesk/tpl/menu.tpl.php b/htdocs/cashdesk/tpl/menu.tpl.php index 85de5ad9ab5..fd9bcbca77c 100644 --- a/htdocs/cashdesk/tpl/menu.tpl.php +++ b/htdocs/cashdesk/tpl/menu.tpl.php @@ -79,10 +79,11 @@ print ''; /*print $langs->trans("CashDeskBankCash").': '.$bankcashLink.'
'; print $langs->trans("CashDeskBankCB").': '.$bankcbLink.'
'; print $langs->trans("CashDeskBankCheque").': '.$bankchequeLink.'
';*/ +print '
'; if (!empty($_SESSION["CASHDESK_ID_WAREHOUSE"]) && ! empty($conf->stock->enabled) && empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) { print $langs->trans("CashDeskWarehouse").': '.$warehouseLink; } -print ''; +print '
'; print ''; print "\n".''."\n"; diff --git a/htdocs/cashdesk/validation_verif.php b/htdocs/cashdesk/validation_verif.php index 5e4ed9b028e..1b870d30f73 100644 --- a/htdocs/cashdesk/validation_verif.php +++ b/htdocs/cashdesk/validation_verif.php @@ -32,7 +32,6 @@ require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; $obj_facturation = unserialize($_SESSION['serObjFacturation']); -unset ($_SESSION['serObjFacturation']); $action =GETPOST('action','aZ09'); $bankaccountid=GETPOST('cashdeskbank'); @@ -45,14 +44,14 @@ switch ($action) case 'valide_achat': $thirdpartyid = $_SESSION['CASHDESK_ID_THIRDPARTY']; - + $company=new Societe($db); $company->fetch($thirdpartyid); $invoice=new Facture($db); $invoice->date=dol_now(); $invoice->type= Facture::TYPE_STANDARD; - + // To use a specific numbering module for POS, reset $conf->global->FACTURE_ADDON and other vars here // and restore values just after $sav_FACTURE_ADDON=''; @@ -68,7 +67,7 @@ switch ($action) // To force rule only for POS with mercure //... } - + $num=$invoice->getNextNumRef($company); // Restore save values @@ -76,7 +75,7 @@ switch ($action) { $conf->global->FACTURE_ADDON = $sav_FACTURE_ADDON; } - + $obj_facturation->numInvoice($num); $obj_facturation->getSetPaymentMode($_POST['hdnChoix']); @@ -129,7 +128,7 @@ switch ($action) exit; } - switch ( $obj_facturation->getSetPaymentMode() ) + switch ($obj_facturation->getSetPaymentMode() ) { case 'DIF': $mode_reglement_id = 0; @@ -159,7 +158,6 @@ switch ($action) $note .= $_POST['txtaNotes']; dol_syslog("obj_facturation->getSetPaymentMode()=".$obj_facturation->getSetPaymentMode()." mode_reglement_id=".$mode_reglement_id." cond_reglement_id=".$cond_reglement_id); - $error=0; @@ -184,6 +182,7 @@ switch ($action) $tmp = getTaxesFromId($tab_liste[$i]['fk_tva']); $vat_rate = $tmp['rate']; $vat_npr = $tmp['npr']; + $vat_src_code = $tmp['code']; $invoiceline=new FactureLigne($db); $invoiceline->fk_product=$tab_liste[$i]['fk_article']; @@ -192,15 +191,17 @@ switch ($action) $invoiceline->remise_percent=$tab_liste[$i]['remise_percent']; $invoiceline->price=$tab_liste[$i]['price']; $invoiceline->subprice=$tab_liste[$i]['price']; - + $invoiceline->tva_tx=empty($vat_rate)?0:$vat_rate; // works even if vat_rate is '' $invoiceline->info_bits=empty($vat_npr)?0:$vat_npr; - + $invoiceline->vat_src_code=$vat_src_code; + $invoiceline->total_ht=$tab_liste[$i]['total_ht']; $invoiceline->total_ttc=$tab_liste[$i]['total_ttc']; $invoiceline->total_tva=$tab_liste[$i]['total_vat']; $invoiceline->total_localtax1=$tab_liste[$i]['total_localtax1']; $invoiceline->total_localtax2=$tab_liste[$i]['total_localtax2']; + $invoice->lines[]=$invoiceline; } @@ -224,7 +225,7 @@ switch ($action) { $warehouseidtodecrease=(isset($_SESSION["CASHDESK_ID_WAREHOUSE"])?$_SESSION["CASHDESK_ID_WAREHOUSE"]:0); if (! empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) $warehouseidtodecrease=0; // If a particular stock is defined, we disable choice - + $resultvalid=$invoice->validate($user, $obj_facturation->numInvoice(), 0); if ($warehouseidtodecrease > 0) @@ -252,19 +253,20 @@ switch ($action) } else { - $error++; + setEventMessage($invoice->error, $invoice->errors, 'errors'); + $error++; } $id = $invoice->id; } else { - $resultcreate=$invoice->create($user,0,0); + $resultcreate=$invoice->create($user,0,0); if ($resultcreate > 0) { $warehouseidtodecrease=(isset($_SESSION["CASHDESK_ID_WAREHOUSE"])?$_SESSION["CASHDESK_ID_WAREHOUSE"]:0); if (! empty($conf->global->CASHDESK_NO_DECREASE_STOCK)) $warehouseidtodecrease=0; // If a particular stock is defined, we disable choice - + $resultvalid=$invoice->validate($user, $obj_facturation->numInvoice(), 0); if ($warehouseidtodecrease > 0) @@ -284,7 +286,8 @@ switch ($action) if ($invoice->type == $invoice::TYPE_CREDIT_NOTE) $result=$mouvP->reception($user, $invoice->lines[$i]->fk_product, $warehouseidtodecrease, $invoice->lines[$i]->qty, $invoice->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarrFromPos",$invoice->newref)); else $result=$mouvP->livraison($user, $invoice->lines[$i]->fk_product, $warehouseidtodecrease, $invoice->lines[$i]->qty, $invoice->lines[$i]->subprice, $langs->trans("InvoiceValidatedInDolibarrFromPos",$invoice->newref)); if ($result < 0) { - $error++; + setEventMessages($mouvP->error, $mouvP->errors, 'errors'); + $error++; } } } @@ -328,15 +331,18 @@ switch ($action) } else { - $error++; + setEventMessages($invoice->error, $invoice->errors, 'errors'); + $error++; } } else { - $error++; + setEventMessages($invoice->error, $invoice->errors, 'errors'); + $error++; } } + if (! $error) { $db->commit(); @@ -345,14 +351,14 @@ switch ($action) else { $db->rollback(); - $redirection = 'affIndex.php?facid='.$id.'&mesg=ErrorFailedToCreateInvoice'; // Ajout de l'id de la facture, pour l'inclure dans un lien pointant directement vers celle-ci dans Dolibarr + $redirection = 'affIndex.php?facid='.$id.'&error=1&mesg=ErrorFailedToCreateInvoice'; // Ajout de l'id de la facture, pour l'inclure dans un lien pointant directement vers celle-ci dans Dolibarr } break; // End of case: valide_facture } - +unset ($_SESSION['serObjFacturation']); $_SESSION['serObjFacturation'] = serialize($obj_facturation); diff --git a/htdocs/categories/admin/categorie.php b/htdocs/categories/admin/categorie.php index d16b081e6ae..55006a8b171 100644 --- a/htdocs/categories/admin/categorie.php +++ b/htdocs/categories/admin/categorie.php @@ -37,6 +37,7 @@ $action=GETPOST('action','aZ09'); /* * Actions */ + if (preg_match('/set_(.*)/',$action,$reg)) { $code=$reg[1]; @@ -82,7 +83,7 @@ print load_fiche_titre($langs->trans("CategoriesSetup"),$linkback,'title_setup') $head=categoriesadmin_prepare_head(); -dol_fiche_head($head, 'setup', $langs->trans("Categories"), 0, 'category'); +dol_fiche_head($head, 'setup', $langs->trans("Categories"), -1, 'category'); print ''; diff --git a/htdocs/categories/admin/categorie_extrafields.php b/htdocs/categories/admin/categorie_extrafields.php index 2bc9f205334..6291d2065c2 100644 --- a/htdocs/categories/admin/categorie_extrafields.php +++ b/htdocs/categories/admin/categorie_extrafields.php @@ -68,7 +68,7 @@ print load_fiche_titre($langs->trans("CategoriesSetup"),$linkback,'title_setup') $head = categoriesadmin_prepare_head(); -dol_fiche_head($head, 'attributes_categories', $langs->trans("Categories"), 0, 'category'); +dol_fiche_head($head, 'attributes_categories', $langs->trans("Categories"), -1, 'category'); require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php'; diff --git a/htdocs/categories/card.php b/htdocs/categories/card.php index ed497cbbb7f..9f49e42f060 100644 --- a/htdocs/categories/card.php +++ b/htdocs/categories/card.php @@ -1,6 +1,6 @@ - * Copyright (C) 2006-2015 Laurent Destailleur + * Copyright (C) 2006-2017 Laurent Destailleur * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2013 Florian Henry @@ -221,9 +221,7 @@ llxHeader("",$langs->trans("Categories"),$helpurl); if ($user->rights->categorie->creer) { - /* - * Fiche en mode creation - */ + // Create or add if ($action == 'create' || $_POST["addcat"] == 'addcat') { dol_set_focus('#label'); @@ -246,7 +244,7 @@ if ($user->rights->categorie->creer) // Ref print ''; - print ''; // Description @@ -263,12 +261,14 @@ if ($user->rights->categorie->creer) // Parent category print ''; $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook)) + print $hookmanager->resPrint; + if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); } diff --git a/htdocs/categories/class/api_categories.class.php b/htdocs/categories/class/api_categories.class.php index fc7aca368f4..ed10e337f7b 100644 --- a/htdocs/categories/class/api_categories.class.php +++ b/htdocs/categories/class/api_categories.class.php @@ -114,7 +114,7 @@ class Categories extends DolibarrApi $sql = "SELECT t.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as t"; - $sql.= ' WHERE t.entity IN ('.getEntity('category', 1).')'; + $sql.= ' WHERE t.entity IN ('.getEntity('category').')'; if (!empty($type)) { $sql.= ' AND t.type='.array_search($type,Categories::$TYPES); @@ -205,7 +205,7 @@ class Categories extends DolibarrApi $sql = "SELECT s.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s"; $sql.= " , ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub "; - $sql.= ' WHERE s.entity IN ('.getEntity('category', 1).')'; + $sql.= ' WHERE s.entity IN ('.getEntity('category').')'; $sql.= ' AND s.type='.array_search($type,Categories::$TYPES); $sql.= ' AND s.rowid = sub.fk_categorie'; $sql.= ' AND sub.'.$subcol_name.' = '.$item; diff --git a/htdocs/categories/class/api_deprecated_category.class.php b/htdocs/categories/class/api_deprecated_category.class.php index efbcac82124..392005b71fe 100644 --- a/htdocs/categories/class/api_deprecated_category.class.php +++ b/htdocs/categories/class/api_deprecated_category.class.php @@ -121,7 +121,7 @@ class CategoryApi extends DolibarrApi $sql = "SELECT s.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s"; - $sql.= ' WHERE s.entity IN ('.getEntity('category', 1).')'; + $sql.= ' WHERE s.entity IN ('.getEntity('category').')'; $sql.= ' AND s.type='.array_search($type,CategoryApi::$TYPES); $nbtotalofrecords = ''; @@ -201,7 +201,7 @@ class CategoryApi extends DolibarrApi $sql = "SELECT s.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as s"; $sql.= " , ".MAIN_DB_PREFIX."categorie_".$sub_type." as sub "; - $sql.= ' WHERE s.entity IN ('.getEntity('category', 1).')'; + $sql.= ' WHERE s.entity IN ('.getEntity('category').')'; $sql.= ' AND s.type='.array_search($type,CategoryApi::$TYPES); $sql.= ' AND s.rowid = sub.fk_categorie'; $sql.= ' AND sub.'.$subcol_name.' = '.$item; diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 142cc22fe75..60ef207bb48 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -53,7 +53,7 @@ class Categorie extends CommonObject const TYPE_PROJECT = 6; const TYPE_BANK_LINE = 'bank_line'; public $picto = 'category'; - + /** * @var array ID mapping from type string @@ -195,7 +195,7 @@ class Categorie extends CommonObject } else { - $sql.= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category',1).")"; + $sql.= " WHERE label = '".$this->db->escape($label)."' AND entity IN (".getEntity('category').")"; if ($type) $sql.= " AND type = '".$this->db->escape($type)."'"; } @@ -557,7 +557,7 @@ class Categorie extends CommonObject $error++; } } - + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."categorie_lang"; @@ -814,7 +814,7 @@ class Categorie extends CommonObject $resql = $this->db->query($sql); if ($resql) { - while ($rec = $this->db->fetch_array($resql)) + while ($rec = $this->db->fetch_array($resql)) { if ($onlyids) { @@ -903,7 +903,7 @@ class Categorie extends CommonObject $sql = "SELECT fk_parent as id_parent, rowid as id_son"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; $sql.= " WHERE fk_parent != 0"; - $sql.= " AND entity IN (".getEntity('category',1).")"; + $sql.= " AND entity IN (".getEntity('category').")"; dol_syslog(get_class($this)."::load_motherof", LOG_DEBUG); $resql = $this->db->query($sql); @@ -938,7 +938,7 @@ class Categorie extends CommonObject * * @return array Array of categories. this->cats and this->motherof are set. */ - function get_full_arbo($type,$markafterid=0) + function get_full_arbo($type, $markafterid=0) { global $conf, $langs; @@ -1094,7 +1094,7 @@ class Categorie extends CommonObject function get_all_categories($type=null, $parent=false) { $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."categorie"; - $sql.= " WHERE entity IN (".getEntity('category',1).")"; + $sql.= " WHERE entity IN (".getEntity('category').")"; if (! is_null($type)) $sql.= " AND type = ".$type; if ($parent) @@ -1129,7 +1129,7 @@ class Categorie extends CommonObject { $sql = "SELECT count(rowid)"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie"; - $sql.= " WHERE entity IN (".getEntity('category',1).")"; + $sql.= " WHERE entity IN (".getEntity('category').")"; $res = $this->db->query($sql); if ($res) { @@ -1155,7 +1155,7 @@ class Categorie extends CommonObject */ $sql = "SELECT c.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."categorie as c "; - $sql.= " WHERE c.entity IN (".getEntity('category',1).")"; + $sql.= " WHERE c.entity IN (".getEntity('category').")"; $sql.= " AND c.type = ".$this->type; $sql.= " AND c.fk_parent = ".$this->fk_parent; $sql.= " AND c.label = '".$this->db->escape($this->label)."'"; @@ -1355,7 +1355,7 @@ class Categorie extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."bank_class as a, ".MAIN_DB_PREFIX."bank_categ as c"; $sql.= " WHERE a.lineid=".$id." AND a.fk_categ = c.rowid"; $sql.= " ORDER BY c.label"; - + $res = $this->db->query($sql); if ($res) { @@ -1377,7 +1377,7 @@ class Categorie extends CommonObject { dol_print_error($this->db); return -1; - } + } } else { @@ -1385,7 +1385,7 @@ class Categorie extends CommonObject $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_" . $this->MAP_CAT_TABLE[$type] . " as ct, " . MAIN_DB_PREFIX . "categorie as c"; $sql .= " WHERE ct.fk_categorie = c.rowid AND ct.fk_" . $this->MAP_CAT_FK[$type] . " = " . (int) $id . " AND c.type = " . $this->MAP_ID[$type]; $sql .= " AND c.entity IN (" . getEntity( 'category', 1 ) . ")"; - + $res = $this->db->query($sql); if ($res) { @@ -1408,7 +1408,7 @@ class Categorie extends CommonObject return -1; } } - + return $cats; } @@ -1434,7 +1434,7 @@ class Categorie extends CommonObject $cats = array(); // For backward compatibility - if (is_numeric( $type )) { + if (is_numeric($type)) { // We want to reverse lookup $map_type = array_flip( $this->MAP_ID ); $type = $map_type[$type]; @@ -1782,8 +1782,8 @@ class Categorie extends CommonObject { return ''; } - - + + /** * Initialise an instance with random values. * Used to build previews or test instances. diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php index 9981d09cda0..59bee88b75b 100644 --- a/htdocs/categories/edit.php +++ b/htdocs/categories/edit.php @@ -173,7 +173,9 @@ print ''; +$parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook +print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index b68da6fd597..ea4d60e9b5b 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -36,9 +36,8 @@ $langs->load("categories"); if (! $user->rights->categorie->lire) accessforbidden(); $id=GETPOST('id','int'); -$type=(GETPOST('type') ? GETPOST('type') : Categorie::TYPE_PRODUCT); +$type=(GETPOST('type','aZ09') ? GETPOST('type','aZ09') : Categorie::TYPE_PRODUCT); $catname=GETPOST('catname','alpha'); -$section=(GETPOST('section')?GETPOST('section'):0); /* @@ -48,14 +47,15 @@ $section=(GETPOST('section')?GETPOST('section'):0); $categstatic = new Categorie($db); $form = new Form($db); -if ($type == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductsCategoriesArea"); -elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCategoriesArea"); -elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoriesArea"); -elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoriesArea"); -elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactsCategoriesArea"); -elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesArea"); -elseif ($type == Categorie::TYPE_PROJECT) $title=$langs->trans("ProjectsCategoriesArea"); -else $title=$langs->trans("CategoriesArea"); +if ($type == Categorie::TYPE_PRODUCT) { $title=$langs->trans("ProductsCategoriesArea"); $typetext='product'; } +elseif ($type == Categorie::TYPE_SUPPLIER) { $title=$langs->trans("SuppliersCategoriesArea"); $typetext='supplier'; } +elseif ($type == Categorie::TYPE_CUSTOMER) { $title=$langs->trans("CustomersCategoriesArea"); $typetext='customer'; } +elseif ($type == Categorie::TYPE_MEMBER) { $title=$langs->trans("MembersCategoriesArea"); $typetext='member'; } +elseif ($type == Categorie::TYPE_CONTACT) { $title=$langs->trans("ContactsCategoriesArea"); $typetext='contact'; } +elseif ($type == Categorie::TYPE_ACCOUNT) { $title=$langs->trans("AccountsCategoriesArea"); $typetext='account'; } +elseif ($type == Categorie::TYPE_USER) { $title=$langs->trans("UsersCategoriesArea"); $typetext='user'; } +elseif ($type == Categorie::TYPE_PROJECT) { $title=$langs->trans("ProjectsCategoriesArea"); $typetext='project'; } +else { $title=$langs->trans("CategoriesArea"); $typetext='unknown'; } $arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js'); $arrayofcss=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.css'); @@ -104,7 +104,7 @@ print '
'; */ if ($catname || $id > 0) { - $cats = $categstatic->rechercher($id,$catname,$type); + $cats = $categstatic->rechercher($id, $catname, $typetext); print '
'.$langs->trans("Ref").''; + print ''.$langs->trans("Ref").''; print'
'.$langs->trans("AddIn").''; - print $form->select_all_categories($type, $catorigin); + print $form->select_all_categories($type, $catorigin, 'parent'); + print ajax_combobox('parent'); print '
'.$langs->trans("In").''; print $form->select_all_categories($type,$object->fk_parent,'parent',64,$object->id); print '
'; print ''; @@ -140,7 +140,7 @@ print '

'; // Charge tableau des categories -$cate_arbo = $categstatic->get_full_arbo($type); +$cate_arbo = $categstatic->get_full_arbo($typetext); // Define fulltree array $fulltree=$cate_arbo; diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index 665b033936e..11aff01dc99 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -235,11 +235,8 @@ print $langs->trans("Color").'
'; -$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook -if (empty($reshook) && ! empty($extrafields->attribute_label)) -{ - print $object->showOptionals($extrafields); -} +// Other attributes +include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print '
'.$langs->trans("FoundCats").'
'; print $formother->showColor($object->color); print '
'; print ''; @@ -290,7 +287,7 @@ else if (count($cats) > 0) { foreach ($cats as $cat) - { + { print "\t".''."\n"; print "\t\t".''; print "".$cat->label.""; @@ -359,7 +356,7 @@ if ($object->type == Categorie::TYPE_PRODUCT) if (count($prods) > 0) { foreach ($prods as $prod) - { + { print "\t".''."\n"; print ''; print $prod->getNomUrl(1); @@ -408,7 +405,7 @@ if ($object->type == Categorie::TYPE_SUPPLIER) if (count($socs) > 0) { foreach ($socs as $soc) - { + { print "\t".''."\n"; print ''; print $soc->getNomUrl(1); @@ -462,7 +459,7 @@ if($object->type == Categorie::TYPE_CUSTOMER) if ($user->societe_id > 0 && $soc->id != $user->societe_id) continue; // External user always see only themself $i++; - + print "\t".''."\n"; print ''; print $soc->getNomUrl(1); @@ -513,7 +510,7 @@ if ($object->type == Categorie::TYPE_MEMBER) if (count($prods) > 0) { foreach ($prods as $key => $member) - { + { print "\t".''."\n"; print ''; $member->ref=$member->login; @@ -567,7 +564,7 @@ if($object->type == Categorie::TYPE_CONTACT) foreach ($contacts as $key => $contact) { $i++; - + print "\t".''."\n"; print ''; print $contact->getNomUrl(1,'category'); @@ -619,7 +616,7 @@ if ($object->type == Categorie::TYPE_ACCOUNT) if (count($accounts) > 0) { foreach ($accounts as $key => $account) - { + { print "\t".''."\n"; print ''; print $account->getNomUrl(1,0); @@ -672,7 +669,7 @@ if ($object->type == Categorie::TYPE_PROJECT) if (count($projects) > 0) { foreach ($projects as $key => $project) - { + { print "\t".''."\n"; print ''; print $project->getNomUrl(1,0); diff --git a/htdocs/collab/index.php b/htdocs/collab/index.php index ea7abde4151..7f08beff955 100644 --- a/htdocs/collab/index.php +++ b/htdocs/collab/index.php @@ -49,7 +49,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, top_htmlhead($head, $title, $disablejs, $disablehead, $arrayofjs, $arrayofcss); print ''; - + // top menu and left menu area if (empty($conf->dol_hide_topmenu)) { @@ -108,7 +108,7 @@ if (empty($action)) $action='preview'; */ if (GETPOST('refreshsite')) $pageid=0; // If we change the site, we reset the pageid. -if (GETPOST('refreshpage')) $action='preview'; +if (GETPOST('refreshpage')) $action='preview'; // Add a collab page @@ -146,7 +146,7 @@ if ($action == 'add') { $db->rollback(); } - + $action = 'preview'; $id = $objectpage->id; } @@ -173,7 +173,7 @@ if ($action == 'delete') { $db->commit(); setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs'); - + header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website); exit; } @@ -218,7 +218,7 @@ print '
'; if (count($object->records) > 0) { // ***** Part for web sites - + print '
'; print $langs->trans("Website").': '; print '
'; @@ -252,20 +252,20 @@ if (count($object->records) > 0) $dataroot=DOL_DATA_ROOT.'/websites/'.$website; if (! empty($object->virtualhost)) $virtualurl=$object->virtualhost; } - + if ($website && $action == 'preview') { $disabled=''; if (empty($user->rights->websites->write)) $disabled=' disabled="disabled"'; - + print '   '; - + //print ''; print ''; print ''; print ''; } - + print '
'; // Button for websites @@ -279,7 +279,7 @@ if (count($object->records) > 0) $htmltext=$langs->trans("SetHereVirtualHost", $dataroot); print $form->textwithpicto('', $htmltext); print ''; - + $urlext=$virtualurl; $urlint=$urlwithroot.'/public/websites/index.php?website='.$website; //if (! empty($object->virtualhost)) @@ -288,7 +288,7 @@ if (count($object->records) > 0) print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); print ''; //} - + print 'transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint)).'">'; print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Site"), $langs->transnoentitiesnoconv("Site"), $urlint, $dataroot), 1, 'preview'); print ''; @@ -300,12 +300,12 @@ if (count($object->records) > 0) if (preg_match('/^create/',$action)) print ''; if (preg_match('/^edit/',$action)) print ''; } - + print ''; // ***** Part for pages - + if ($website) { print ''; @@ -313,13 +313,13 @@ if (count($object->records) > 0) $array=$objectpage->fetchAll($object->id); if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors); $atleastonepage=(is_array($array) && count($array) > 0); - + print '
'; print '
'; print $langs->trans("Page").': '; print '
'; print '
'; - + if ($action != 'add') { $out=''; @@ -336,7 +336,7 @@ if (count($object->records) > 0) } $pageid=$homepageid?$homepageid:$firstpageid; // We choose home page and if not defined yet, we take first page } - + foreach($array as $key => $valpage) { $out.='
'; print '
'; print '
'; @@ -389,17 +389,17 @@ if (count($object->records) > 0) { $websitepage = new WebSitePage($db); $websitepage->fetch($pageid); - + $realpage=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid; $pagealias = $websitepage->pageurl; - + print '
'; print ''; //print ''; $htmltext=$langs->trans("WEBSITE_PAGENAME", $pagealias); print $form->textwithpicto('', $htmltext); print '
'; - + if (! empty($object->virtualhost)) { $urlext=$virtualurl.'/'.$pagealias.'.php'; @@ -413,12 +413,12 @@ if (count($object->records) > 0) print $form->textwithpicto('', $langs->trans("PreviewSiteServedByWebServer", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $dataroot, $urlext?$urlext:$langs->trans("VirtualHostUrlNotDefined")), 1, 'preview_ext'); print ''; } - + print 'transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage)).'">'; - print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot), 1, 'preview'); + print $form->textwithpicto('', $langs->trans("PreviewSiteServedByDolibarr", $langs->transnoentitiesnoconv("Page"), $langs->transnoentitiesnoconv("Page"), $realpage, $dataroot), 1, 'preview'); print ''; // View page in new Tab //print ''; - + // TODO Add js to save alias like we save virtual host name and use dynamic virtual host for url of id=previewpageext } if (! in_array($action, array('editcss','editmenu','create'))) @@ -427,7 +427,7 @@ if (count($object->records) > 0) if (preg_match('/^create/',$action)) print ''; if (preg_match('/^edit/',$action)) print ''; } - + print '
'; if ($action == 'preview') @@ -454,7 +454,7 @@ if (count($object->records) > 0) }, context: document.body }); - + jQuery("#previewsiteext").attr("href",newurl); jQuery("#previewpageext").attr("href",newpage); }); @@ -483,15 +483,15 @@ if ($action == 'editcontent') /* * Editing global variables not related to a specific theme */ - + $csscontent = @file_get_contents($filecss); - + $contentforedit = ''; /*$contentforedit.=''."\n";*/ $contentforedit .= $objectpage->content; - + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('PAGE_CONTENT',$contentforedit,'',500,'Full','',true,true,true,ROWS_5,'90%'); $doleditor->Create(0, '', false); diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 02ee84dc2de..5e38a85898e 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2005 Rodolphe Quiedeville * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005 Simon TOSSER - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2010-2013 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2014 Cedric GROSS @@ -95,7 +95,7 @@ $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); //var_dump($_POST); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('actioncard','globalcard')); @@ -121,7 +121,7 @@ if (GETPOST('removedassigned') || GETPOST('removedassigned') == '0') $donotclearsession=1; if ($action == 'add') $action = 'create'; if ($action == 'update') $action = 'edit'; - + $listUserAssignedUpdated = true; } @@ -585,8 +585,6 @@ if ($action == 'mupdate') * View */ -$formproject=new FormProjets($db); - $help_url='EN:Module_Agenda_En|FR:Module_Agenda|ES:M&omodulodulo_Agenda'; llxHeader('',$langs->trans("Agenda"),$help_url); @@ -734,7 +732,7 @@ if ($action == 'create') print '
'; print $form->select_dolusers_forevent(($action=='create'?'add':'update'), 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0'); print '
'; - if (in_array($user->id,array_keys($listofuserid))) + if (in_array($user->id,array_keys($listofuserid))) { print '
'; print $langs->trans("MyAvailability").': '.$langs->trans("Busy"); @@ -752,8 +750,8 @@ if ($action == 'create') print ''; print '

'; - - + + print ''; // Related company @@ -830,13 +828,11 @@ if ($action == 'create') $doleditor->Create(); print ''; - // Other attributes - $parameters=array('id'=>$object->id); + $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - - - if (empty($reshook) && ! empty($extrafields->attribute_label)) + print $hookmanager->resPrint; + if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); } @@ -863,11 +859,11 @@ if ($id > 0) $result3=$object->fetch_contact(); $result4=$object->fetch_userassigned(); $result5=$object->fetch_optionals($id,$extralabels); - - if ($listUserAssignedUpdated || $donotclearsession) + + if ($listUserAssignedUpdated || $donotclearsession) { $percentage=in_array(GETPOST('status'),array(-1,100))?GETPOST('status'):(in_array(GETPOST('complete'),array(-1,100))?GETPOST('complete'):GETPOST("percentage")); // If status is -1 or 100, percentage is not defined and we must use status - + $datep=dol_mktime($fulldayevent?'00':$aphour, $fulldayevent?'00':$apmin, 0, $_POST["apmonth"], $_POST["apday"], $_POST["apyear"]); $datef=dol_mktime($fulldayevent?'23':$p2hour, $fulldayevent?'59':$p2min, $fulldayevent?'59':'0', $_POST["p2month"], $_POST["p2day"], $_POST["p2year"]); @@ -884,7 +880,7 @@ if ($id > 0) //$object->societe->id = $_POST["socid"]; // deprecated //$object->contact->id = $_POST["contactid"]; // deprecated $object->fk_project = GETPOST("projectid",'int'); - + $object->note = GETPOST("note"); } @@ -1076,11 +1072,11 @@ if ($id > 0) $listofuserid=json_decode($_SESSION['assignedtouser'], true); } } - + print '
'; print $form->select_dolusers_forevent(($action=='create'?'add':'update'), 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, 'AND u.statut != 0'); print '
'; - if (in_array($user->id,array_keys($listofuserid))) + if (in_array($user->id,array_keys($listofuserid))) { print '
'; print $langs->trans("MyAvailability").': id]['transparency']?' checked':'').'>'.$langs->trans("Busy"); @@ -1098,10 +1094,10 @@ if ($id > 0) print '
'; - + print '

'; - + print ''; if ($conf->societe->enabled) @@ -1165,9 +1161,10 @@ if ($id > 0) print ''; // Other attributes - $parameters=array('id'=>$object->id); + $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook) && ! empty($extrafields->attribute_label)) + print $hookmanager->resPrint; + if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); } @@ -1208,12 +1205,12 @@ if ($id > 0) $out.=img_picto($langs->trans("ViewCal"),'object_calendar','class="hideonsmartphone pictoactionview"'); $out.=''.$langs->trans("ViewCal").''; $out.=img_picto($langs->trans("ViewWeek"),'object_calendarweek','class="hideonsmartphone pictoactionview"'); - $out.=''.$langs->trans("ViewWeek").''; + $out.=''.$langs->trans("ViewWeek").''; $out.=img_picto($langs->trans("ViewDay"),'object_calendarday','class="hideonsmartphone pictoactionview"'); $out.=''.$langs->trans("ViewDay").''; $linkback.=$out; - - + + $morehtmlref='
'; // Thirdparty //$morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1); @@ -1253,14 +1250,14 @@ if ($id > 0) } } $morehtmlref.='
'; - - + + dol_banner_tab($object, 'id', $linkback, ($user->societe_id?0:1), 'id', 'ref', $morehtmlref); - + print '
'; - + print '
'; - + // Affichage fiche action en mode visu print '
'; @@ -1324,7 +1321,7 @@ if ($id > 0) print '
'; print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); print '
'; - if ($object->datep != $object->datef && in_array($user->id,array_keys($listofuserid))) + if ($object->datep != $object->datef && in_array($user->id,array_keys($listofuserid))) { print '
'; print $langs->trans("MyAvailability").': '.(($object->userassigned[$user->id]['transparency'] > 0)?$langs->trans("Busy"):$langs->trans("Available")); // We show nothing if event is assigned to nobody @@ -1364,7 +1361,7 @@ if ($id > 0) } } print ''; - + // Related contact print '
'; print ''; } - + // Priority print ''; // Other attributes - $parameters=array('colspan'=>' colspan="3"', 'colspanvalue'=>'3', 'id'=>$object->id); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + $cols=3; + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print '
'.$langs->trans("ActionOnContact").''; @@ -1385,7 +1382,7 @@ if ($id > 0) } print '
'.$langs->trans("Priority").''; print ($object->priority?$object->priority:''); @@ -1409,38 +1406,13 @@ if ($id > 0) print '
'; - //Extra field - if (empty($reshook) && ! empty($extrafields->attribute_label)) - { - print '

'; - print '
'; - print ''; - foreach($extrafields->attribute_label as $key=>$label) - { - if (isset($_POST["options_" . $key])) { - if (is_array($_POST["options_" . $key])) { - // $_POST["options"] is an array but following code expects a comma separated string - $value = implode(",", $_POST["options_" . $key]); - } else { - $value = $_POST["options_" . $key]; - } - } else { - $value = $object->array_options["options_" . $key]; - } - print '\n"; - } - print '
'.$label.''; - print $extrafields->showOutputField($key,$value); - print "
'; - } - print '
'; - + dol_fiche_end(); } diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index a9695abcb35..70b2acb86b7 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -38,7 +38,7 @@ class ActionComm extends CommonObject public $table_rowid = 'id'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe public $picto='action'; - + /** * Id of the event * @var int @@ -168,7 +168,7 @@ class ActionComm extends CommonObject var $email_subject; var $errors_to; - + /** * Constructor * @@ -444,7 +444,7 @@ class ActionComm extends CommonObject $u->fetch($fuser); $fuser = $u; } - else + else { $fuser = $user; } @@ -657,11 +657,11 @@ class ActionComm extends CommonObject $this->error=$this->db->lasterror(); $error++; } - + if (! $error) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."actioncomm_resources"; $sql.= " WHERE fk_actioncomm=".$this->id; - + dol_syslog(get_class($this)."::delete", LOG_DEBUG); $res=$this->db->query($sql); if ($res < 0) { @@ -669,7 +669,7 @@ class ActionComm extends CommonObject $error++; } } - + // Removed extrafields if (! $error) { $result=$this->deleteExtraFields(); @@ -870,7 +870,7 @@ class ActionComm extends CommonObject $sql = "SELECT a.id"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a"; - $sql.= " WHERE a.entity IN (".getEntity('agenda', 1).")"; + $sql.= " WHERE a.entity IN (".getEntity('agenda').")"; if (! empty($socid)) $sql.= " AND a.fk_soc = ".$socid; if (! empty($elementtype)) { @@ -921,7 +921,7 @@ class ActionComm extends CommonObject if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON a.fk_soc = sc.fk_soc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON a.fk_soc = s.rowid"; $sql.= " WHERE a.percent >= 0 AND a.percent < 100"; - $sql.= " AND a.entity IN (".getEntity('agenda', 1).")"; + $sql.= " AND a.entity IN (".getEntity('agenda').")"; if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND (a.fk_soc IS NULL OR sc.fk_user = " .$user->id . ")"; if ($user->societe_id) $sql.=" AND a.fk_soc = ".$user->societe_id; if (! $user->rights->agenda->allactions->read) $sql.= " AND (a.fk_user_author = ".$user->id . " OR a.fk_user_action = ".$user->id . " OR a.fk_user_done = ".$user->id . ")"; @@ -1091,7 +1091,7 @@ class ActionComm extends CommonObject else if ($percent > 0 && $percent < 100) return $percent.'% '.img_picto($langs->trans('StatusActionInProcess').' - '.$percent.'%','statut3'); else if ($percent >= 100) return img_picto($langs->trans('StatusActionDone'),'statut6'); } - + return ''; } @@ -1112,20 +1112,20 @@ class ActionComm extends CommonObject global $conf, $langs, $user, $hookmanager; if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips - + $label = $this->label; if (empty($label)) $label=$this->libelle; // For backward compatibility $result=''; - + // Set label of typ $labeltype = ($langs->transnoentities("Action".$this->type_code) != "Action".$this->type_code)?$langs->transnoentities("Action".$this->type_code):$this->type_label; if (empty($conf->global->AGENDA_USE_EVENT_TYPE)) { if ($this->type_code != 'AC_OTH_AUTO') $labeltype = $langs->trans('ActionAC_MANUAL'); } - - + + $tooltip = '' . $langs->trans('ShowAction'.$objp->code) . ''; if (! empty($this->ref)) $tooltip .= '
' . $langs->trans('Ref') . ': ' . $this->ref; @@ -1137,7 +1137,7 @@ class ActionComm extends CommonObject $tooltip .= '
' . $langs->trans('Location') . ': ' . $this->location; $linkclose=''; - if (! empty($conf->global->AGENDA_USE_EVENT_TYPE) && $this->type_color) + if (! empty($conf->global->AGENDA_USE_EVENT_TYPE) && $this->type_color) $linkclose = ' style="background-color:#'.$this->type_color.'"'; if (empty($notooltip)) @@ -1149,7 +1149,7 @@ class ActionComm extends CommonObject } $linkclose.=' title="'.dol_escape_htmltag($tooltip, 1).'"'; $linkclose.=' class="'.$classname.' classfortooltip"'; - + if (! is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; @@ -1161,17 +1161,17 @@ class ActionComm extends CommonObject $linkclose = ($hookmanager->resPrint ? $hookmanager->resPrint : $linkclose); } else $linkclose.=' class="'.$classname.'"'; - + $url=''; - if ($option=='birthday') + if ($option=='birthday') $url = DOL_URL_ROOT.'/contact/perso.php?id='.$this->id; - else + else $url = DOL_URL_ROOT.'/comm/action/card.php?id='.$this->id; - + $linkstart = ''; $linkend=''; - + //print 'rrr'.$this->libelle.'-'.$withpicto; if ($withpicto == 2) @@ -1279,9 +1279,9 @@ class ActionComm extends CommonObject $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author"; // Link to get author of event for export $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc"; // We must filter on assignement table - if ($filters['logint'] || $filters['login']) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; + if ($filters['logint']) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; $sql.= " WHERE a.fk_action=c.id"; - $sql.= " AND a.entity IN (".getEntity('agenda', 1).")"; + $sql.= " AND a.entity IN (".getEntity('agenda').")"; foreach ($filters as $key => $value) { if ($key == 'notolderthan' && $value != '') $sql.=" AND a.datep >= '".$this->db->idate($now-($value*24*60*60))."'"; @@ -1291,20 +1291,34 @@ class ActionComm extends CommonObject if ($key == 'idto') $sql.=" AND a.id <= ".(is_numeric($value)?$value:0); if ($key == 'project') $sql.=" AND a.fk_project=".(is_numeric($value)?$value:0); // We must filter on assignement table - if ($key == 'logint' || $key == 'login') $sql.= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'"; + if ($key == 'logint') $sql.= " AND ar.fk_actioncomm = a.id AND ar.element_type='user'"; if ($key == 'logina') { $logina=$value; + $condition='='; + if (preg_match('/^!/',$logina)) + { + $logina=preg_replace('/^!/','',$logina); + $condition='<>'; + } $userforfilter=new User($this->db); - $result=$userforfilter->fetch('',$value); - $sql.= " AND a.fk_user_author = ".$userforfilter->id; + $result=$userforfilter->fetch('',$logina); + if ($result > 0) $sql.= " AND a.fk_user_author ".$condition." ".$userforfilter->id; + elseif ($result < 0 || $condition == '=') $sql.= " AND a.fk_user_author = 0"; } - if ($key == 'logint' || $key == 'login') + if ($key == 'logint') { $logint=$value; + $condition='='; + if (preg_match('/^!/',$logint)) + { + $logint=preg_replace('/^!/','',$logint); + $condition='<>'; + } $userforfilter=new User($this->db); - $result=$userforfilter->fetch('',$value); - $sql.= " AND ar.fk_element = ".$userforfilter->id; + $result=$userforfilter->fetch('',$logint); + if ($result > 0) $sql.= " AND ar.fk_element = ".$userforfilter->id; + elseif ($result < 0 || $condition == '=') $sql.= " AND ar.fk_element = 0"; } } $sql.= " AND a.datep IS NOT NULL"; // To exclude corrupted events and avoid errors in lightning/sunbird import diff --git a/htdocs/comm/action/class/api_agendaevents.class.php b/htdocs/comm/action/class/api_agendaevents.class.php index dccd98ebe96..4edd656da53 100644 --- a/htdocs/comm/action/class/api_agendaevents.class.php +++ b/htdocs/comm/action/class/api_agendaevents.class.php @@ -63,20 +63,20 @@ class AgendaEvents extends DolibarrApi */ function get($id) { - if(! DolibarrApiAccess::$user->rights->agenda->myactions->read) { + if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) { throw new RestException(401, "Insuffisant rights to read an event"); } $result = $this->actioncomm->fetch($id); - if( ! $result ) { + if ( ! $result ) { throw new RestException(404, 'Agenda Events not found'); } - if(! DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->ownerid != DolibarrApiAccess::$user->id) { + if (! DolibarrApiAccess::$user->rights->agenda->allactions->read && $this->actioncomm->ownerid != DolibarrApiAccess::$user->id) { throw new RestException(401, "Insuffisant rights to read event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); } - if( ! DolibarrApi::_checkAccessToResource('agenda',$this->actioncomm->id)) { + if ( ! DolibarrApi::_checkAccessToResource('agenda',$this->actioncomm->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } @@ -102,6 +102,10 @@ class AgendaEvents extends DolibarrApi $obj_ret = array(); + if (! DolibarrApiAccess::$user->rights->agenda->myactions->read) { + throw new RestException(401, "Insuffisant rights to read events"); + } + // case of external user $socid = 0; if (! empty(DolibarrApiAccess::$user->socid)) $socid = DolibarrApiAccess::$user->socid; @@ -111,8 +115,11 @@ class AgendaEvents extends DolibarrApi if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) $search_sale = DolibarrApiAccess::$user->id; $sql = "SELECT t.id as rowid"; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as t"; - $sql.= ' WHERE t.entity IN ('.getEntity('agenda', 1).')'; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale + $sql.= ' WHERE t.entity IN ('.getEntity('agenda').')'; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc"; if ($user_ids) $sql.=" AND t.fk_user_action IN (".$user_ids.")"; if ($socid > 0) $sql.= " AND t.fk_soc = ".$socid; // Insert sale filter @@ -152,7 +159,7 @@ class AgendaEvents extends DolibarrApi { $obj = $db->fetch_object($result); $actioncomm_static = new ActionComm($db); - if($actioncomm_static->fetch($obj->rowid)) { + if ($actioncomm_static->fetch($obj->rowid)) { $obj_ret[] = $this->_cleanObjectDatas($actioncomm_static); } $i++; @@ -161,7 +168,7 @@ class AgendaEvents extends DolibarrApi else { throw new RestException(503, 'Error when retrieve Agenda Event list : '.$db->lasterror()); } - if( ! count($obj_ret)) { + if ( ! count($obj_ret)) { throw new RestException(404, 'No Agenda Event found'); } return $obj_ret; @@ -175,10 +182,10 @@ class AgendaEvents extends DolibarrApi */ function post($request_data = NULL) { - if(! DolibarrApiAccess::$user->rights->agenda->myactions->create) { + if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) { throw new RestException(401, "Insuffisant rights to create your Agenda Event"); } - if(! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) { + if (! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) { throw new RestException(401, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); } @@ -213,19 +220,19 @@ class AgendaEvents extends DolibarrApi */ /* function put($id, $request_data = NULL) { - if(! DolibarrApiAccess::$user->rights->agenda->myactions->create) { + if (! DolibarrApiAccess::$user->rights->agenda->myactions->create) { throw new RestException(401, "Insuffisant rights to create your Agenda Event"); } - if(! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) { + if (! DolibarrApiAccess::$user->rights->agenda->allactions->create && DolibarrApiAccess::$user->id != $request_data['userownerid']) { throw new RestException(401, "Insuffisant rights to create an Agenda Event for owner id ".$request_data['userownerid'].' Your id is '.DolibarrApiAccess::$user->id); } $result = $this->expensereport->fetch($id); - if( ! $result ) { + if ( ! $result ) { throw new RestException(404, 'expensereport not found'); } - if( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { + if ( ! DolibarrApi::_checkAccessToResource('expensereport',$this->expensereport->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } foreach($request_data as $field => $value) { @@ -233,7 +240,7 @@ class AgendaEvents extends DolibarrApi $this->expensereport->$field = $value; } - if($this->expensereport->update($id, DolibarrApiAccess::$user,1,'','','update')) + if ($this->expensereport->update($id, DolibarrApiAccess::$user,1,'','','update')) return $this->get($id); return false; @@ -298,4 +305,58 @@ class AgendaEvents extends DolibarrApi } return $event; } + + /** + * Clean sensible object datas + * + * @param object $object Object to clean + * @return array Array of cleaned object properties + */ + function _cleanObjectDatas($object) { + + $object = parent::_cleanObjectDatas($object); + + unset($object->usermod); + unset($object->libelle); + unset($object->array_options); + unset($object->context); + unset($object->canvas); + unset($object->contact); + unset($object->contact_id); + unset($object->thirdparty); + unset($object->user); + unset($object->origin); + unset($object->origin_id); + unset($object->ref_ext); + unset($object->statut); + unset($object->country); + unset($object->country_id); + unset($object->country_code); + unset($object->barcode_type); + unset($object->barcode_type_code); + unset($object->barcode_type_label); + unset($object->barcode_type_coder); + unset($object->mode_reglement_id); + unset($object->cond_reglement_id); + unset($object->cond_reglement); + unset($object->fk_delivery_address); + unset($object->shipping_method_id); + unset($object->fk_account); + unset($object->total_ht); + unset($object->total_tva); + unset($object->total_localtax1); + unset($object->total_localtax2); + unset($object->total_ttc); + unset($object->fk_incoterms); + unset($object->libelle_incoterms); + unset($object->location_incoterms); + unset($object->name); + unset($object->lastname); + unset($object->firstname); + unset($object->civility_id); + unset($object->contact); + unset($object->societe); + + return $object; + } } diff --git a/htdocs/comm/action/document.php b/htdocs/comm/action/document.php index 2caa55bcd59..1e54db9d449 100644 --- a/htdocs/comm/action/document.php +++ b/htdocs/comm/action/document.php @@ -67,7 +67,7 @@ if ($id > 0) $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -124,7 +124,7 @@ if ($object->id > 0) dol_fiche_head($head, 'documents', $langs->trans("Action"), -1, 'action'); $linkback = img_picto($langs->trans("BackToList"),'object_list','class="hideonsmartphone pictoactionview"'); - $linkback.= ''.$langs->trans("BackToList").''; + $linkback.= ''.$langs->trans("BackToList").''; // Link to other agenda views $out=''; @@ -137,7 +137,7 @@ if ($object->id > 0) $out.=''.$langs->trans("ViewWeek").''; $out.=img_picto($langs->trans("ViewDay"),'object_calendarday','class="hideonsmartphone pictoactionview"'); $out.=''.$langs->trans("ViewDay").''; - + $linkback.=$out; $morehtmlref='
'; @@ -161,13 +161,13 @@ if ($object->id > 0) } } $morehtmlref.='
'; - + dol_banner_tab($object, 'id', $linkback, ($user->societe_id?0:1), 'id', 'ref', $morehtmlref); - + print '
'; - + print '
'; - + // Affichage fiche action en mode visu print ''; @@ -228,7 +228,7 @@ if ($object->id > 0) print '
'; print $form->select_dolusers_forevent('view', 'assignedtouser', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); print '
'; - if (in_array($user->id,array_keys($listofuserid))) + if (in_array($user->id,array_keys($listofuserid))) { print '
'; print $langs->trans("MyAvailability").': '.(($object->userassigned[$user->id]['transparency'] > 0)?$langs->trans("Busy"):$langs->trans("Available")); // We show nothing if event is assigned to nobody @@ -237,7 +237,7 @@ if ($object->id > 0) print ' '; print '
'; - + print ''; // Construit liste des fichiers @@ -255,7 +255,7 @@ if ($object->id > 0) print '
'; print '
'; - + dol_fiche_end(); diff --git a/htdocs/comm/action/index.php b/htdocs/comm/action/index.php index 307d6417285..76a53924ad5 100644 --- a/htdocs/comm/action/index.php +++ b/htdocs/comm/action/index.php @@ -58,7 +58,7 @@ if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page","int"); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $offset = $limit * $page; if (! $sortorder) $sortorder="ASC"; @@ -118,7 +118,7 @@ $langs->load("agenda"); $langs->load("other"); $langs->load("commercial"); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('agenda')); @@ -423,8 +423,8 @@ else // If javascript off $newparam=$param; // newparam is for birthday links $newparam=preg_replace('/showbirthday=[0-1]/i','showbirthday='.(empty($showbirthday)?1:0),$newparam); if (! preg_match('/showbirthday=/i',$newparam)) $newparam.='&showbirthday=1'; - $link='trans("AgendaShowBirthdayEvents"); else $link.=$langs->trans("AgendaHideBirthdayEvents"); @@ -456,7 +456,7 @@ if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r"; if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; $sql.= ' WHERE a.fk_action = ca.id'; -$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; +$sql.= ' AND a.entity IN ('.getEntity('agenda').')'; // Condition on actioncode if (! empty($actioncode)) { @@ -648,7 +648,7 @@ if ($showbirthday) $sql = 'SELECT sp.rowid, sp.lastname, sp.firstname, sp.birthday'; $sql.= ' FROM '.MAIN_DB_PREFIX.'socpeople as sp'; $sql.= ' WHERE (priv=0 OR (priv=1 AND fk_user_creat='.$user->id.'))'; - $sql.= " AND sp.entity IN (".getEntity('societe', 1).")"; + $sql.= " AND sp.entity IN (".getEntity('societe').")"; if ($action == 'show_day') { $sql.= ' AND MONTH(birthday) = '.$month; @@ -1070,7 +1070,7 @@ if (empty($action) || $action == 'show_month') // View by month } echo "\n"; echo '
'; - echo ''; + echo ''; echo ''; echo '' ; echo '
'; @@ -1124,7 +1124,7 @@ elseif ($action == 'show_week') // View by week echo "\n"; echo '
'; - echo ''; + echo ''; echo ''; echo '' ; echo '
'; @@ -1188,7 +1188,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa global $cachethirdparties, $cachecontacts, $cacheusers, $colorindexused; $dateint = sprintf("%04d",$year).sprintf("%02d",$month).sprintf("%02d",$day); - + print "\n"; // Line with title of day @@ -1247,7 +1247,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa if (in_array($user->id, $keysofuserassigned)) { $nummytasks++; $cssclass='family_mytasks'; - + if (empty($cacheusers[$event->userownerid])) { $newuser=new User($db); @@ -1255,7 +1255,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa $cacheusers[$event->userownerid]=$newuser; } //var_dump($cacheusers[$event->userownerid]->color); - + // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event) if (! empty($cacheusers[$event->userownerid]->color)) $color=$cacheusers[$event->userownerid]->color; } @@ -1277,10 +1277,10 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa } else { - $numother++; + $numother++; $color=($event->icalcolor?$event->icalcolor:-1); $cssclass=(! empty($event->icalname)?'family_ext'.md5($event->icalname):'family_other'); - + if (empty($cacheusers[$event->userownerid])) { $newuser=new User($db); @@ -1288,7 +1288,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa $cacheusers[$event->userownerid]=$newuser; } //var_dump($cacheusers[$event->userownerid]->color); - + // We decide to choose color of owner of event (event->userownerid is user id of owner, event->userassigned contains all users assigned to event) if (! empty($cacheusers[$event->userownerid]->color)) $color=$cacheusers[$event->userownerid]->color; } @@ -1364,9 +1364,9 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa print '">'; print ''; print ''; - + $daterange=''; - + if ($event->type_code == 'BIRTHDAY') // It's a birthday { print $event->getNomUrl(1,$maxnbofchar,'cal_event','birthday','contact'); @@ -1426,9 +1426,9 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa // Show title $titletoshow = $daterange; $titletoshow.=($titletoshow?' ':'').$event->libelle; - + if ($event->type_code == 'ICALEVENT') print $titletoshow; - else + else { $savlabel=$event->libelle; $event->libelle=$titletoshow; @@ -1449,11 +1449,11 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa $newuser->fetch($tmpid); $cacheusers[$tmpid]=$newuser; } - + $listofusertoshow.=$cacheusers[$tmpid]->getNomUrl(-3, '', 0, 0, 0, 0, '', 'valigntextbottom'); } print $listofusertoshow; - + if ($event->type_code == 'ICALEVENT') print '
('.dol_trunc($event->icalname,$maxnbofchar).')'; // If action related to company / contact @@ -1506,7 +1506,7 @@ function show_day_events($db, $day, $month, $year, $monthshown, $style, &$eventa if ($event->type_code != 'BIRTHDAY' && $event->type_code != 'ICALEVENT') { $withstatus=1; - if ($event->percentage >= 0) $withstatus=2; + if ($event->percentage >= 0) $withstatus=2; } print ''; if ($withstatus) print $event->getLibStatut(3,1); diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index 6ed846c0ebe..13a7015059b 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -47,12 +47,12 @@ $status=GETPOST("status",'alpha'); $type=GETPOST('type'); $optioncss = GETPOST('optioncss','alpha'); // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index) -if (GETPOST('actioncode','array')) +if (GETPOST('actioncode','array')) { $actioncode=GETPOST('actioncode','array',3); if (! count($actioncode)) $actioncode='0'; } -else +else { $actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE)); } @@ -76,11 +76,11 @@ if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) $filtert=$user->id; } -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0 ; } +if ($page == -1 || $page == null) { $page = 0 ; } $offset = $limit * $page ; if (! $sortorder) { @@ -109,7 +109,7 @@ if (! $user->rights->agenda->allactions->read || $filter=='mine') // If no permi $filtert=$user->id; } -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('agendalist')); @@ -197,7 +197,7 @@ if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r"; if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; $sql.= " WHERE c.id = a.fk_action"; -$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; +$sql.= ' AND a.entity IN ('.getEntity('agenda').')'; // Condition on actioncode if (! empty($actioncode)) { @@ -337,11 +337,22 @@ if ($resql) if ($pid) $nav.=''; if ($usergroup) $nav.=''; print $nav; - + + if ($user->rights->agenda->myactions->create || $user->rights->agenda->allactions->create) + { + $newparam.='&month='.str_pad($month, 2, "0", STR_PAD_LEFT).'&year='.$year; + + //$param='month='.$monthshown.'&year='.$year; + $hourminsec='100000'; + $link = '
'; + $link.= $langs->trans("NewAction"); + $link.= ''; + } + print_barre_liste($s, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $link, $num, -1 * $nbtotalofrecords, '', 0, $nav, '', $limit); $moreforfilter=''; - + $i = 0; print '
'; print ''."\n"; @@ -369,11 +380,11 @@ if ($resql) print $searchpicto; print ''; print "\n"; - + print ''; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"a.id",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Title"),$_SERVER["PHP_SELF"],"a.label",$param,"","",$sortfield,$sortorder); - //if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) + //if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"c.libelle",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateStart"),$_SERVER["PHP_SELF"],"a.datep",$param,'','align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateEnd"),$_SERVER["PHP_SELF"],"a.datep2",$param,'','align="center"',$sortfield,$sortorder); @@ -392,7 +403,7 @@ if ($resql) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/cactioncomm.class.php'; $caction=new CActionComm($db); $arraylist=$caction->liste_array(1, 'code', '', (empty($conf->global->AGENDA_USE_EVENT_TYPE)?1:0)); - + $var=true; while ($i < min($num,$limit)) { @@ -405,15 +416,13 @@ if ($resql) continue; } - - $actionstatic->id=$obj->id; $actionstatic->ref=$obj->id; $actionstatic->type_code=$obj->type_code; $actionstatic->type_label=$obj->type_label; $actionstatic->type_picto=$obj->type_picto; $actionstatic->label=$obj->label; - + print ''; // Action (type) @@ -443,7 +452,7 @@ if ($resql) if (! empty($arraylist[$labeltype])) $labeltype=$arraylist[$labeltype]; print dol_trunc($labeltype,28); print ''; - + // Start date print ''; } - // User to do + // User owner print ''; @@ -514,7 +523,7 @@ if ($resql) print ''; print ''; - + print "\n"; $i++; } diff --git a/htdocs/comm/action/pertype.php b/htdocs/comm/action/pertype.php index 544da904cdc..cd96a4fa8ad 100644 --- a/htdocs/comm/action/pertype.php +++ b/htdocs/comm/action/pertype.php @@ -54,7 +54,7 @@ if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page","int"); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $offset = $limit * $page; if (! $sortorder) $sortorder="ASC"; @@ -140,7 +140,7 @@ $langs->load("agenda"); $langs->load("other"); $langs->load("commercial"); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('agenda')); @@ -364,7 +364,7 @@ if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r"; if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; $sql.= ' WHERE a.fk_action = ca.id'; -$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; +$sql.= ' AND a.entity IN ('.getEntity('agenda').')'; // Condition on actioncode if (! empty($actioncode)) { @@ -572,7 +572,7 @@ $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restor $newparam.='&viewweek=1'; echo ''; -echo ''; +echo ''; echo ''; echo '' ; echo ''; diff --git a/htdocs/comm/action/peruser.php b/htdocs/comm/action/peruser.php index 2a707cd2d8f..7453b84d477 100644 --- a/htdocs/comm/action/peruser.php +++ b/htdocs/comm/action/peruser.php @@ -54,7 +54,7 @@ if (empty($filtert) && empty($conf->global->AGENDA_ALL_CALENDARS)) $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page","int"); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $offset = $limit * $page; if (! $sortorder) $sortorder="ASC"; @@ -86,12 +86,12 @@ $status=GETPOST("status"); $type=GETPOST("type"); $maxprint=(isset($_GET["maxprint"])?GETPOST("maxprint"):$conf->global->AGENDA_MAX_EVENTS_DAY_VIEW); // Set actioncode (this code must be same for setting actioncode into peruser, listacton and index) -if (GETPOST('actioncode','array')) +if (GETPOST('actioncode','array')) { $actioncode=GETPOST('actioncode','array',3); if (! count($actioncode)) $actioncode='0'; } -else +else { $actioncode=GETPOST("actioncode","alpha",3)?GETPOST("actioncode","alpha",3):(GETPOST("actioncode")=='0'?'0':(empty($conf->global->AGENDA_DEFAULT_FILTER_TYPE)?'':$conf->global->AGENDA_DEFAULT_FILTER_TYPE)); } @@ -139,7 +139,7 @@ $langs->load("agenda"); $langs->load("other"); $langs->load("commercial"); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('agenda')); @@ -371,7 +371,7 @@ if ($resourceid > 0) $sql.=", ".MAIN_DB_PREFIX."element_resources as r"; if ($filtert > 0 || $usergroup > 0) $sql.=", ".MAIN_DB_PREFIX."actioncomm_resources as ar"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_user = ar.fk_element"; $sql.= ' WHERE a.fk_action = ca.id'; -$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; +$sql.= ' AND a.entity IN ('.getEntity('agenda').')'; // Condition on actioncode if (! empty($actioncode)) { @@ -579,7 +579,7 @@ $newparam=preg_replace('/showbirthday_=/i','showbirthday=',$newparam); // Restor $newparam.='&viewweek=1'; echo ''; -echo ''; +echo ''; echo ''; echo '' ; echo ''; @@ -661,7 +661,7 @@ else $sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; if ($usergroup > 0) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user"; - $sql.= " WHERE u.statut = 1 AND u.entity IN (".getEntity('user',1).")"; + $sql.= " WHERE u.statut = 1 AND u.entity IN (".getEntity('user').")"; if ($usergroup > 0) $sql.= " AND ug.fk_usergroup = ".$usergroup; //print $sql; $resql=$db->query($sql); @@ -729,8 +729,8 @@ foreach ($usernames as $username) { $var = ! $var; echo ""; - echo ''; $tmpday = $sav; diff --git a/htdocs/comm/action/rapport/index.php b/htdocs/comm/action/rapport/index.php index 125355a3386..dcda4e0cf04 100644 --- a/htdocs/comm/action/rapport/index.php +++ b/htdocs/comm/action/rapport/index.php @@ -26,6 +26,7 @@ require '../../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/modules/action/rapport.pdf.php'; @@ -41,7 +42,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0 ; } +if ($page == -1 || $page == null) { $page = 0 ; } $offset = $limit * $page ; if (! $sortorder) $sortorder="DESC"; if (! $sortfield) $sortfield="a.datep"; @@ -71,6 +72,8 @@ if ($action == 'builddoc') * View */ +$formfile=new FormFile($db); + llxHeader(); $sql = "SELECT count(*) as cc,"; @@ -80,7 +83,7 @@ $sql.= " date_format(a.datep, '%Y') as year"; $sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a,"; $sql.= " ".MAIN_DB_PREFIX."user as u"; $sql.= " WHERE a.fk_user_author = u.rowid"; -$sql.= ' AND a.entity IN ('.getEntity('agenda', 1).')'; +$sql.= ' AND a.entity IN ('.getEntity('agenda').')'; //$sql.= " AND percent = 100"; $sql.= " GROUP BY year, month, df"; $sql.= " ORDER BY year DESC, month DESC, df DESC"; @@ -103,7 +106,7 @@ if ($resql) $param=''; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - + print ''; if ($optioncss != '') print ''; print ''; @@ -112,23 +115,24 @@ if ($resql) print ''; print ''; print ''; - + print_barre_liste($langs->trans("Actions"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_agenda', 0, '', '', $limit); $moreforfilter=''; - + $i = 0; print '
'; print '
'; print dol_print_date($db->jdate($obj->dp),"dayhour"); @@ -499,12 +508,12 @@ if ($resql) print ''; if ($obj->fk_user_action > 0) { $userstatic->fetch($obj->fk_user_action); - print $userstatic->getNomUrl(1); + print $userstatic->getNomUrl(-1); } else print ' '; print ''.$actionstatic->LibStatut($obj->percent,3,1,$datep).'
'; - print $username->getNomUrl(-1,'',0,0,24,1,''); + echo ''; + print $username->getNomUrl(-1,'',0,0,20,1,''); print '
'."\n"; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; print ''; print ''; print "\n"; + $var=true; while ($i < min($num,$limit)) { @@ -136,23 +140,47 @@ if ($resql) if ($obj) { - + print ''; + // Date print "\n"; + + // Nb of events print ''; + // Button to build doc print ''; $name = "actions-".$obj->month."-".$obj->year.".pdf"; $relativepath= $name; $file = $conf->agenda->dir_temp."/".$name; + $modulepart = 'actionsreport'; + $documenturl= DOL_URL_ROOT.'/document.php'; + if (isset($conf->global->DOL_URL_ROOT_DOCUMENT_PHP)) $documenturl=$conf->global->DOL_URL_ROOT_DOCUMENT_PHP; // To use another wrapper if (file_exists($file)) { - print ''; + print ''; print ''; print ''; } @@ -169,7 +197,7 @@ if ($resql) print "
'.$langs->trans("Date").''.$langs->trans("Period").''.$langs->trans("EventsNb").''.$langs->trans("Action").''.$langs->trans("PDF").''.$langs->trans("PDF").''.$langs->trans("Date").''.$langs->trans("Size").'
".$obj->df."'.$obj->cc.''; - print 'month.'&year='.$obj->year.'">'.img_picto($langs->trans('GenerateReport'),'filenew').''; + print 'month.'&year='.$obj->year.'">'.img_picto($langs->trans('BuildDoc'),'filenew').''; print ''.img_pdf().''; + //print ''.img_pdf().''; + + $filearray=array('name'=>basename($file),'fullname'=>$file,'type'=>'file'); + $out=''; + + // Show file name with link to download + $tmp = $formfile->showPreview($filearray,$modulepart,$relativepath,0,$param); + $out.= ($tmp?$tmp.' ':''); + $out.= 'trans("File").': '.$filearray["name"]).' '.$filearray["name"]; + $out.= ''."\n"; + print $out; + + print ''.dol_print_date(dol_filemtime($file),'dayhour').''.dol_print_size(dol_filesize($file)).'
"; print '
'; print ''; - + $db->free($resql); } else diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 7599cce4cfd..a51ef902eb6 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -66,7 +66,7 @@ $mode = GETPOST("mode"); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -80,7 +80,7 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('commcard','globalcard')); @@ -131,7 +131,7 @@ if (empty($reshook)) $result=$object->setBankAccount(GETPOST('fk_account','int')); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - + // customer preferred shipping method if ($action == 'setshippingmethod' && $user->rights->societe->creer) { @@ -175,6 +175,21 @@ if (empty($reshook)) $result=$object->update($object->id, $user); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } + + if ($action == 'update_extras') { + $object->fetch($id); + + // Fill array 'array_options' with data from update form + $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); + $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); + if ($ret < 0) $error++; + if (! $error) + { + $result = $object->insertExtraFields(); + if ($result < 0) $error++; + } + if ($error) $action = 'edit_extras'; + } } @@ -207,9 +222,9 @@ if ($id > 0) dol_fiche_head($head, 'customer', $langs->trans("ThirdParty"), -1, 'company'); $linkback = ''.$langs->trans("BackToList").''; - + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); - + print '
'; print '
'; @@ -247,21 +262,23 @@ if ($id > 0) print ''; } - // Assujeti a TVA ou pas + // VAT is used print ''; - print ''.$langs->trans('VATIsUsed').''; + print ''.$langs->trans('VATIsUsed').''; + print ''; print yn($object->tva_assuj); print ''; print ''; // Local Taxes - if ($mysoc->useLocalTax(1)) + // TODO Move this on same record than VATIsUsed + if ($mysoc->localtax1_assuj=="1") { print ''.$langs->transcountry("LocalTax1IsUsed", $mysoc->country_code).''; print yn($object->localtax1_assuj); print ''; } - if ($mysoc->useLocalTax(2)) + if ($mysoc->localtax1_assuj=="1") { print ''.$langs->transcountry("LocalTax2IsUsed", $mysoc->country_code).''; print yn($object->localtax2_assuj); @@ -376,11 +393,11 @@ if ($id > 0) $limit_field_type = (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount'; print $form->editfieldval("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer,$limit_field_type,($object->outstanding_limit != '' ? price($object->outstanding_limit) : '')); //if (empty($object->outstanding_limit)) print $langs->trans("NoLimit"); - + print ''; print ''; } - + // Multiprice level if (! empty($conf->global->PRODUIT_MULTIPRICES)) { @@ -432,13 +449,8 @@ if ($id > 0) } // Other attributes - $parameters=array('socid'=>$object->id, 'colspan' => ' colspan="3"', 'colspanvalue' => '3'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) - { - print $object->showOptionals($extrafields); - } + $parameters=array('socid'=>$object->id); + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; // Sales representative include DOL_DOCUMENT_ROOT.'/societe/tpl/linesalesrepresentative.tpl.php'; @@ -471,10 +483,10 @@ if ($id > 0) if ($object->client == 2 || $object->client == 3) { print '
'; - + print '
'; print ''; - + // Level of prospect print ''; print ''; print ''; print ''; print '
'; print ''; print "
'; @@ -508,12 +520,12 @@ if ($id > 0) print '
"; } - + print '
'; $boxstat = ''; - + // Nbre max d'elements des petites listes $MAXLIST=$conf->global->MAIN_SIZE_SHORTLIST_LIMIT; @@ -521,7 +533,7 @@ if ($id > 0) $boxstat.='
'; $boxstat.=''; $boxstat.=''; $boxstat.='
'; - + if ($conf->propal->enabled) { // Box proposals @@ -557,14 +569,14 @@ if ($id > 0) $boxstat.=''; if ($link) $boxstat.=''; } - + if ($conf->facture->enabled) { $tmp = $object->getOutstandingBills(); $outstandingOpened=$tmp['opened']; $outstandingTotal=$tmp['total_ht']; $outstandingTotalIncTax=$tmp['total_ttc']; - + $text=$langs->trans("OverAllInvoices"); $link=''; $icon='bill'; @@ -574,7 +586,7 @@ if ($id > 0) $boxstat.=''.price($outstandingTotal, 1, $langs, 1, -1, -1, $conf->currency).''; $boxstat.=''; if ($link) $boxstat.=''; - + // Box outstanding bill $warn = ''; if ($object->outstanding_limit != '' && $object->outstanding_limit < $outstandingOpened) @@ -591,13 +603,13 @@ if ($id > 0) $boxstat.=''; if ($link) $boxstat.=''; } - + $boxstat.='
'; $boxstat.='
'; - + print $boxstat; - + $now=dol_now(); /* @@ -639,7 +651,7 @@ if ($id > 0) while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); - + print '
'; $propal_static->id = $objp->propalid; @@ -723,7 +735,7 @@ if ($id > 0) while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); - + print '
'; $commande_static->id = $objp->cid; @@ -762,7 +774,7 @@ if ($id > 0) $sql.= ', s.rowid as socid'; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."expedition as e"; $sql.= " WHERE e.fk_soc = s.rowid AND s.rowid = ".$object->id; - $sql.= " AND e.entity IN (".getEntity('expedition', 1).")"; + $sql.= " AND e.entity IN (".getEntity('expedition').")"; $sql.= ' GROUP BY e.rowid'; $sql.= ', e.ref'; $sql.= ', e.date_creation'; @@ -849,7 +861,7 @@ if ($id > 0) $contrat=new Contrat($db); $objp = $db->fetch_object($resql); - + print '
'; $contrat->id=$objp->id; @@ -905,7 +917,7 @@ if ($id > 0) print ''.img_picto($langs->trans("Statistics"),'stats').'
'; print ''; - + } $i = 0; while ($i < $num && $i < $MAXLIST) @@ -921,7 +933,7 @@ if ($id > 0) print ''.convertSecondToTime($objp->duration).''."\n"; print ''.$fichinter_static->getLibStatut(5).''."\n"; print ''; - + $i++; } $db->free($resql); @@ -977,7 +989,7 @@ if ($id > 0) while ($i < $num && $i < $MAXLIST) { $objp = $db->fetch_object($resql); - + print ''; print ''; $facturestatic->id = $objp->facid; @@ -1006,7 +1018,7 @@ if ($id > 0) print price($objp->total_ttc); print ''; } - + print ''.($facturestatic->LibStatut($objp->paye,$objp->statut,5,$objp->am)).''; print "\n"; $i++; @@ -1042,31 +1054,31 @@ if ($id > 0) { print ''; } - + if (! empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status==1) { $langs->load("propal"); print ''; } - + if (! empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status==1) { $langs->load("orders"); print ''; } - + if ($user->rights->contrat->creer && $object->status==1) { $langs->load("contracts"); print ''; } - + if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status==1) { $langs->load("fichinter"); print ''; } - + // Add invoice if ($user->societe_id == 0) { @@ -1075,7 +1087,7 @@ if ($id > 0) $langs->load("trips"); print ''; } - + if (! empty($conf->facture->enabled) && $object->status==1) { if (empty($user->rights->facture->creer)) @@ -1086,7 +1098,7 @@ if ($id > 0) { $langs->load("bills"); $langs->load("orders"); - + if (! empty($conf->commande->enabled)) { if ($object->client != 0 && $object->client != 2) @@ -1099,11 +1111,11 @@ if ($id > 0) if ($object->client != 0 && $object->client != 2) print ''; else print ''; - + } } } - + // Add action if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB) && $object->status==1) { @@ -1117,7 +1129,7 @@ if ($id > 0) } } } - + print '
'; if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB)) diff --git a/htdocs/comm/contact.php b/htdocs/comm/contact.php index fe66e3ac243..a13ffe61c76 100644 --- a/htdocs/comm/contact.php +++ b/htdocs/comm/contact.php @@ -78,7 +78,7 @@ if (! $user->rights->societe->client->voir && ! $socid) $sql .= " ".MAIN_DB_PREF $sql.= " ".MAIN_DB_PREFIX."socpeople as p"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc"; $sql.= " WHERE s.fk_stcomm = st.id"; -$sql.= " AND p.entity IN (".getEntity('societe', 1).")"; +$sql.= " AND p.entity IN (".getEntity('societe').")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($type == "c") $sql.= " AND s.client IN (1, 3)"; if ($type == "p") $sql.= " AND s.client IN (2, 3)"; diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 24bccbf9c9c..885be0dd37c 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -146,7 +146,7 @@ if (! empty($conf->propal->enabled) && $user->rights->propal->lire) if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_statut = 0"; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; + $sql.= " AND p.entity IN (".getEntity('propal').")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; @@ -227,7 +227,7 @@ if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_propos if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_statut = 0"; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; + $sql.= " AND p.entity IN (".getEntity('propal').")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; @@ -306,7 +306,7 @@ if (! empty($conf->commande->enabled) && $user->rights->commande->lire) if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; $sql.= " AND c.fk_statut = 0"; - $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; + $sql.= " AND c.entity IN (".getEntity('commande').")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND c.fk_soc = ".$socid; @@ -387,7 +387,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE cf.fk_soc = s.rowid"; $sql.= " AND cf.fk_statut = 0"; - $sql.= " AND cf.entity IN (".getEntity('supplier_order', 1).")"; + $sql.= " AND cf.entity IN (".getEntity('supplier_order').")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND cf.fk_soc = ".$socid; @@ -611,7 +611,7 @@ if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire && 0) // TO $sql.= ", ".MAIN_DB_PREFIX."product as p"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity IN (".getEntity('contract', 1).")"; + $sql.= " AND c.entity IN (".getEntity('contract').")"; $sql.= " AND c.fk_product = p.rowid"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; @@ -669,7 +669,7 @@ if (! empty($conf->propal->enabled) && $user->rights->propal->lire) $sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; - $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; + $sql.= " AND p.entity IN (".getEntity('propal').")"; $sql.= " AND p.fk_statut = 1"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; @@ -766,7 +766,7 @@ if (! empty($conf->commande->enabled) && $user->rights->commande->lire) $sql.= ", ".MAIN_DB_PREFIX."commande as c"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; + $sql.= " AND c.entity IN (".getEntity('commande').")"; $sql.= " AND c.fk_statut = 1"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; diff --git a/htdocs/comm/mailing/advtargetemailing.php b/htdocs/comm/mailing/advtargetemailing.php index 0a9cdca7abc..81c29f687ce 100644 --- a/htdocs/comm/mailing/advtargetemailing.php +++ b/htdocs/comm/mailing/advtargetemailing.php @@ -767,19 +767,19 @@ if ($object->fetch($id) >= 0) { } else { $std_soc = new Societe($db); $action_search = 'query'; - // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array + + // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; $hookmanager = new HookManager($db); - $hookmanager->initHooks(array ( - 'thirdpartycard' - )); + $hookmanager->initHooks(array ('thirdpartycard')); + + $parameters=array(); if (! empty($advTarget->id)) { - $parameters = array ( - 'array_query' => $advTarget->filtervalue - ); + $parameters = array('array_query' => $advTarget->filtervalue); } - // Module extrafield feature + // Other attributes $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $std_soc, $action_search); + print $hookmanager->resPrint; } // State Contact diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 0b4c3c239f9..8f4deb53edf 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -52,7 +52,7 @@ $extrafields = new ExtraFields($db); // fetch optionals attributes and labels $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('mailingcard','globalcard')); // Array of possible substitutions (See also file mailing-send.php that should manage same substitutions) @@ -231,10 +231,10 @@ if (empty($reshook)) if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); else $substitutionarray['__SECUREKEYPAYPAL_ORDER__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'order' . $obj->source_id, 2); - + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); else $substitutionarray['__SECUREKEYPAYPAL_INVOICE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'invoice' . $obj->source_id, 2); - + if (empty($conf->global->PAYPAL_SECURITY_TOKEN_UNIQUE)) $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN, 2); else $substitutionarray['__SECUREKEYPAYPAL_CONTRACTLINE__']=dol_hash($conf->global->PAYPAL_SECURITY_TOKEN . 'contractline' . $obj->source_id, 2); } @@ -700,11 +700,11 @@ if ($action == 'create') } $htmltext.=''; - + $availablelink=$form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'availvar'); //print ''.img_picto($langs->trans("ClickToShowDescription"), $imginfo).''; - - + + // Print mail form print load_fiche_titre($langs->trans("NewMailing"), $availablelink, 'title_generic'); @@ -718,6 +718,7 @@ if ($action == 'create') // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); @@ -733,14 +734,14 @@ if ($action == 'create') print ''; print ''; - + print '
'; // Editeur wysiwyg require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; $doleditor=new DolEditor('body',$_POST['body'],'',600,'dolibarr_mailings','',true,true,$conf->global->FCKEDITOR_ENABLE_MAILING,20,'90%'); $doleditor->Create(); print '
'; - + dol_fiche_end(); print '
'; @@ -809,7 +810,7 @@ else { if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings'); if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings'); - + // The feature is forbidden from GUI, we show just message to use from command line. setEventMessages($langs->trans("MailingNeedCommand"), null, 'warnings'); setEventMessages('', null, 'warnings'); @@ -823,7 +824,7 @@ else { if (! empty($conf->global->MAILING_LIMIT_WARNING_PHPMAIL) && $sendingmode == 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_PHPMAIL), null, 'warnings'); if (! empty($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL) && $sendingmode != 'mail') setEventMessages($langs->transnoentitiesnoconv($conf->global->MAILING_LIMIT_WARNING_NOPHPMAIL), null, 'warnings'); - + $text=''; if ($conf->global->MAILING_LIMIT_SENDBYCLI >= 0) { @@ -841,12 +842,12 @@ else $morehtmlright=''; if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') '; - + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright); print '
'; print '
'; - + print ''; // Description @@ -863,7 +864,7 @@ else print ''; - + // Nb of distinct emails print ''; // Other attributes - $parameters=array(); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - if (empty($reshook) && ! empty($extrafields->attribute_label)) - { - print $object->showOptionals($extrafields); - } + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print '
'.$form->editfieldkey("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string').''; print $form->editfieldval("MailErrorsTo",'email_errorsto',$object->email_errorsto,$object,$user->rights->mailing->creer && $object->statut < 3,'string'); print '
'; print $langs->trans("TotalNbOfDistinctRecipients"); @@ -895,20 +896,15 @@ else print '
'; print "
"; - + dol_fiche_end(); - + // Clone confirmation if ($action == 'clone') { @@ -1014,7 +1010,8 @@ else // Affichage formulaire de TEST if ($action == 'test') { - print load_fiche_titre($langs->trans("TestMailing")); + print '
'; + print load_fiche_titre($langs->trans("TestMailing")); // Create l'objet formulaire mail include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; @@ -1053,12 +1050,12 @@ else $htmltext.=$key.' = '.$langs->trans($val).'
'; } $htmltext.=''; - + // Print mail content print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic'); - + dol_fiche_head('', '', '', -1); - + print ''; // Subject @@ -1086,9 +1083,9 @@ else /*print '';*/ - + print '
'.$langs->trans("BackgroundColorByDefault").''; print $htmlother->selectColor($object->bgcolor,'bgcolor','edit_mailing',0); print '
'; - + // Message print '
'; if (empty($object->bgcolor) || strtolower($object->bgcolor) == 'ffffff') @@ -1103,23 +1100,23 @@ else print '
'; dol_fiche_end(); - + } else { /* * Mailing en mode edition */ - + dol_fiche_head($head, 'card', $langs->trans("Mailing"), -1, 'email'); - + $linkback = ''.$langs->trans("BackToList").''; $morehtmlright=''; if ($object->statut == 2) $morehtmlright.=' ('.$object->countNbOfTargets('alreadysent').'/'.$object->nbemail.') '; - + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', '', '', 0, '', $morehtmlright); - + print '
'; print '
'; @@ -1131,7 +1128,7 @@ else print $form->showrefnav($object,'id', $linkback); print ''; */ - + // Topic print ''.$langs->trans("MailTitle").''.$object->titre.''; // From @@ -1158,6 +1155,7 @@ else // Other attributes $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); @@ -1171,24 +1169,24 @@ else print "
\n"; - + print '
'."\n"; print ''; print ''; print ''; - + $htmltext = ''.$langs->trans("FollowingConstantsWillBeSubstituted").':
'; foreach($object->substitutionarray as $key => $val) { $htmltext.=$key.' = '.$langs->trans($val).'
'; } $htmltext.='
'; - + // Print mail content print load_fiche_titre($langs->trans("EMail"), $form->textwithpicto($langs->trans("AvailableVariables"), $htmltext, 1, 'help', '', 0, 2, 'emailsubstitionhelp'), 'title_generic'); dol_fiche_head(); - + print ''; // Subject @@ -1237,9 +1235,9 @@ else print ''; - + print '
'.$langs->trans("BackgroundColorByDefault").''; print $htmlother->selectColor($object->bgcolor,'bgcolor','edit_mailing',0); print '
'; - + // Message print '
'; // Editeur wysiwyg diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 719dba1a622..6c580cc93d6 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -39,11 +39,11 @@ if (! $user->rights->mailing->lire || $user->societe_id > 0) accessforbidden(); // Load variable for pagination -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/comm/mailing/class/advtargetemailing.class.php b/htdocs/comm/mailing/class/advtargetemailing.class.php index 453d1f75319..a36077f94db 100644 --- a/htdocs/comm/mailing/class/advtargetemailing.class.php +++ b/htdocs/comm/mailing/class/advtargetemailing.class.php @@ -466,7 +466,7 @@ class AdvanceTargetingMailing extends CommonObject $sqlwhere=array(); - $sqlwhere[]= 't.entity IN ('.getEntity('societe',1).')'; + $sqlwhere[]= 't.entity IN ('.getEntity('societe').')'; if (count($arrayquery)>0) { @@ -625,7 +625,7 @@ class AdvanceTargetingMailing extends CommonObject $sqlwhere=array(); - $sqlwhere[]= 't.entity IN ('.getEntity('socpeople',1).')'; + $sqlwhere[]= 't.entity IN ('.getEntity('socpeople').')'; if (count($arrayquery)>0) { diff --git a/htdocs/comm/mailing/list.php b/htdocs/comm/mailing/list.php index e7775a6485e..fb513c99b9b 100644 --- a/htdocs/comm/mailing/list.php +++ b/htdocs/comm/mailing/list.php @@ -34,7 +34,7 @@ $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -45,7 +45,7 @@ $sall=GETPOST('sall', 'alphanohtml'); $sref=GETPOST("sref", "alpha"); $filteremail=GETPOST('filteremail','alpha'); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('mailinglist')); $extrafields = new ExtraFields($db); diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index df86464281a..4668c6a56a4 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -107,7 +107,7 @@ if ($id > 0 || ! empty($ref)) { dol_print_error('', $object->error); } -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('propalcard','globalcard')); $permissionnote = $user->rights->propale->creer; // Used by the include of actions_setnotes.inc.php @@ -210,7 +210,7 @@ if (empty($reshook)) $outputlangs = $langs; if (! empty($conf->global->MAIN_MULTILANGS)) { $outputlangs = new Translate("", $conf); - $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); + $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang); $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records @@ -234,7 +234,7 @@ if (empty($reshook)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); @@ -499,7 +499,7 @@ if (empty($reshook)) $tva_tx = $lines[$i]->tva_tx; if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')'; - + $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->info_bits, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $date_start, $date_end, $array_options, $lines[$i]->fk_unit); if ($result > 0) { @@ -558,7 +558,7 @@ if (empty($reshook)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); @@ -663,7 +663,7 @@ if (empty($reshook)) $outputlangs = $langs; if (! empty($conf->global->MAIN_MULTILANGS)) { $outputlangs = new Translate("", $conf); - $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); + $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang); $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records @@ -755,7 +755,7 @@ if (empty($reshook)) $db->begin(); // $tva_tx can be 'x.x (XXX)' - + // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit // Ecrase $tva_tx par celui du produit @@ -770,7 +770,7 @@ if (empty($reshook)) $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id); $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id); if (empty($tva_tx)) $tva_npr=0; - + $pu_ht = $prod->price; $pu_ttc = $prod->price_ttc; $price_min = $prod->price_min; @@ -811,7 +811,7 @@ if (empty($reshook)) $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx)); $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx)); - + // if price ht is forced (ie: calculated by margin rate and cost price). TODO Why this ? if (! empty($price_ht)) { $pu_ht = price2num($price_ht, 'MU'); @@ -833,8 +833,8 @@ if (empty($reshook)) if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $outputlangs = $langs; $newlang = ''; - if (empty($newlang) && GETPOST('lang_id')) - $newlang = GETPOST('lang_id'); + if (empty($newlang) && GETPOST('lang_id','aZ09')) + $newlang = GETPOST('lang_id','aZ09'); if (empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { @@ -920,7 +920,7 @@ if (empty($reshook)) $outputlangs = $langs; if (! empty($conf->global->MAIN_MULTILANGS)) { $outputlangs = new Translate("", $conf); - $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); + $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang); $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records @@ -1065,7 +1065,7 @@ if (empty($reshook)) $outputlangs = $langs; if (! empty($conf->global->MAIN_MULTILANGS)) { $outputlangs = new Translate("", $conf); - $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); + $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang); $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records @@ -1170,27 +1170,12 @@ if (empty($reshook)) $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); if ($ret < 0) $error++; - if (! $error) { - // Actions on extra fields (by external module or standard code) - // TODO le hook fait double emploi avec le trigger !! - $hookmanager->initHooks(array('propaldao')); - $parameters = array('id' => $object->id); - $reshook = $hookmanager->executeHooks('insertExtraFields', $parameters, $object, $action); // Note that $action and $object may have been - // modified by - // some hooks - if (empty($reshook)) { - $result = $object->insertExtraFields(); - if ($result < 0) { - $error ++; - } - } else if ($reshook < 0) - $error ++; + $result = $object->insertExtraFields(); + if ($result < 0) $error++; } - - if ($error) - $action = 'edit_extras'; + if ($error) $action = 'edit_extras'; } if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propal->creer) @@ -1325,7 +1310,7 @@ if ($action == 'create') // Replicate extrafields $objectsrc->fetch_optionals($originid); $object->array_options = $objectsrc->array_options; - + if (!empty($conf->multicurrency->enabled)) { if (!empty($objectsrc->multicurrency_code)) $currency_code = $objectsrc->multicurrency_code; @@ -1355,10 +1340,10 @@ if ($action == 'create') print ''; // Reference - print ''; + print ''; // Ref customer - print ''; print ''; @@ -1366,7 +1351,7 @@ if ($action == 'create') print ''; print ''; if ($socid > 0) { - print ''; @@ -1374,8 +1359,8 @@ if ($action == 'create') $shipping_method_id = $soc->shipping_method_id; } } else { - print ''; } @@ -1404,7 +1389,7 @@ if ($action == 'create') if ($socid > 0) { // Ligne info remises tiers - print ''; // Validaty duration - print ''; + print ''; // Terms of payment - print ''; // Mode of payment - print ''; // Bank Account if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_PROPOSAL) && ! empty($conf->banque->enabled)) { - print ''; } @@ -1450,20 +1435,20 @@ if ($action == 'create') print ''; // Delivery delay - print ''; // Shipping Method if (! empty($conf->expedition->enabled)) { - print ''; } // Delivery date (or manufacturing) print ''; - print ''; - print ''; @@ -1495,7 +1480,7 @@ if ($action == 'create') { print ''; print ''; - print ''; } @@ -1503,7 +1488,7 @@ if ($action == 'create') // Template to use by default print ''; print ''; - print '"; @@ -1513,7 +1498,7 @@ if ($action == 'create') { print ''; print ''; - print ''; } @@ -1521,7 +1506,7 @@ if ($action == 'create') // Public note print ''; print ''; - print ''; print ''; - print ''; - print ''; - print '"; + print ''; + print ''; + print '"; if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0 ) // Localtax1 { - print '"; + print '"; } if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 { - print '"; + print '"; } - print '"; + print '"; } print "
' . $langs->trans('Ref') . '' . $langs->trans("Draft") . '
' . $langs->trans('Ref') . '' . $langs->trans("Draft") . '
' . $langs->trans('RefCustomer') . ''; + print '
' . $langs->trans('RefCustomer') . ''; print '
' . $langs->trans('Customer') . ''; + print ''; print $soc->getNomUrl(1); print ''; print ''; - print $form->select_company('', 'socid', '(s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1', 'SelectThirdParty'); + print ''; + print $form->select_company('', 'socid', '(s.client = 1 OR s.client = 2 OR s.client = 3) AND status=1', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); // reload page to retrieve customer informations if (!empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE)) { @@ -1396,7 +1381,7 @@ if ($action == 'create') // Contacts (ask contact only if thirdparty already defined). TODO do this also into order and invoice. if ($socid > 0) { - print "
" . $langs->trans("DefaultContact") . ''; + print "
" . $langs->trans("DefaultContact") . ''; $form->select_contacts($soc->id, $contactid, 'contactid', 1, $srccontactslist); print '
' . $langs->trans('Discounts') . ''; + print '
' . $langs->trans('Discounts') . ''; if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent); else @@ -1420,26 +1405,26 @@ if ($action == 'create') } // Date - print '
' . $langs->trans('Date') . ''; + print '
' . $langs->trans('Date') . ''; $form->select_date('', '', '', '', '', "addprop", 1, 1); print '
' . $langs->trans("ValidityDuration") . ' ' . $langs->trans("days") . '
' . $langs->trans("ValidityDuration") . ' ' . $langs->trans("days") . '
' . $langs->trans('PaymentConditionsShort') . ''; + print '
' . $langs->trans('PaymentConditionsShort') . ''; $form->select_conditions_paiements($soc->cond_reglement_id, 'cond_reglement_id'); print '
' . $langs->trans('PaymentMode') . ''; + print '
' . $langs->trans('PaymentMode') . ''; $form->select_types_paiements($soc->mode_reglement_id, 'mode_reglement_id'); print '
' . $langs->trans('BankAccount') . ''; + print '
' . $langs->trans('BankAccount') . ''; $form->select_comptes($fk_account, 'fk_account', 0, '', 1); print '
' . $langs->trans('AvailabilityPeriod') . ''; + print '
' . $langs->trans('AvailabilityPeriod') . ''; $form->selectAvailabilityDelay('', 'availability_id', '', 1); print '
' . $langs->trans('SendingMethod') . ''; + print '
' . $langs->trans('SendingMethod') . ''; print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); print '
' . $langs->trans("DeliveryDate") . ''; + print ''; if ($conf->global->DATE_LIVRAISON_WEEK_DELAY != "") { $tmpdte = time() + ((7 * $conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60); $syear = date("Y", $tmpdte); @@ -1483,7 +1468,7 @@ if ($action == 'create') $langs->load("projects"); print '
' . $langs->trans("Project") . ''; + print '' . $langs->trans("Project") . ''; $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0); print '   id).'">' . $langs->trans("AddProject") . ''; print '
'; + print ''; print $form->select_incoterms((!empty($soc->fk_incoterms) ? $soc->fk_incoterms : ''), (!empty($soc->location_incoterms)?$soc->location_incoterms:'')); print '
' . $langs->trans("DefaultModel") . ''; + print ''; $liste = ModelePDFPropales::liste_modeles($db); print $form->selectarray('model', $liste, ($conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT ? $conf->global->PROPALE_ADDON_PDF_ODT_DEFAULT : $conf->global->PROPALE_ADDON_PDF)); print "
'.fieldLabel('Currency','multicurrency_code').''; + print ''; print $form->selectMultiCurrency($currency_code, 'multicurrency_code', 0); print '
' . $langs->trans('NotePublic') . ''; + print ''; $note_public = $object->getDefaultCreateValueFor('note_public', (is_object($objectsrc)?$objectsrc->note_public:null)); $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); @@ -1531,7 +1516,7 @@ if ($action == 'create') { print '
' . $langs->trans('NotePrivate') . ''; + print ''; $note_private = $object->getDefaultCreateValueFor('note_private', ((! empty($origin) && ! empty($originid) && is_object($objectsrc))?$objectsrc->note_private:null)); $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); @@ -1540,10 +1525,9 @@ if ($action == 'create') } // Other attributes - $parameters = array('colspan' => ' colspan="3"'); - $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified - // by - // hook + $parameters = array(); + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields, 'edit'); } @@ -1578,19 +1562,19 @@ if ($action == 'create') elseif ($newclassname == 'Fichinter') $newclassname = 'Intervention'; - print '
' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . '
' . $langs->trans('TotalHT') . '' . price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency) . '
' . $langs->trans('TotalVAT') . '' . price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency) . "
' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . '
' . $langs->trans('TotalHT') . '' . price($objectsrc->total_ht, 0, $langs, 1, -1, -1, $conf->currency) . '
' . $langs->trans('TotalVAT') . '' . price($objectsrc->total_tva, 0, $langs, 1, -1, -1, $conf->currency) . "
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency) . "
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($objectsrc->total_localtax1, 0, $langs, 1, -1, -1, $conf->currency) . "
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency) . "
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($objectsrc->total_localtax2, 0, $langs, 1, -1, -1, $conf->currency) . "
' . $langs->trans('TotalTTC') . '' . price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency) . "
' . $langs->trans('TotalTTC') . '' . price($objectsrc->total_ttc, 0, $langs, 1, -1, -1, $conf->currency) . "
\n"; @@ -1618,7 +1602,7 @@ if ($action == 'create') $sql .= " FROM " . MAIN_DB_PREFIX . "propal p"; $sql .= ", " . MAIN_DB_PREFIX . "societe s"; $sql .= " WHERE s.rowid = p.fk_soc"; - $sql .= " AND p.entity IN (".getEntity('propal', 1).")"; + $sql .= " AND p.entity IN (".getEntity('propal').")"; $sql .= " AND p.fk_statut <> 0"; $sql .= " ORDER BY Id"; @@ -1755,7 +1739,7 @@ if ($action == 'create') // Proposal card - $linkback = '' . $langs->trans("BackToList") . ''; + $linkback = '' . $langs->trans("BackToList") . ''; $morehtmlref='
'; @@ -2036,43 +2020,6 @@ if ($action == 'create') print ''; } - // Project - /* - if (! empty($conf->projet->enabled)) - { - $langs->load("projects"); - print ''; - print ''; - if ($user->rights->propal->creer) - { - if ($action != 'classify') - print ''; - print '
'; - print $langs->trans('Project') . '' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '
'; - print ''; - if ($action == 'classify') { - $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1); - } else { - $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0); - } - print ''; - } else { - print ''; - if (! empty($object->fk_project)) { - print ''; - $proj = new Project($db); - $proj->fetch($object->fk_project); - print ''; - print $proj->ref; - print ''; - print ''; - } else { - print ' '; - } - } - print ''; - }*/ - if ($soc->outstanding_limit) { // Outstanding Bill @@ -2129,7 +2076,6 @@ if ($action == 'create') } // Other attributes - $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print ''; @@ -2335,7 +2281,7 @@ if ($action == 'create') // Send if ($object->statut == Propal::STATUS_VALIDATED || $object->statut == Propal::STATUS_SIGNED) { if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->propal->propal_advance->send) { - print ''; + print ''; } else print ''; } @@ -2466,6 +2412,7 @@ if ($action == 'create') $file = $fileparams['fullname']; } + print '
'; print '
'; print '
'; print load_fiche_titre($langs->trans('SendPropalByMail')); diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index 190f6cdca87..2f067f46b18 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -112,7 +112,7 @@ class Proposals extends DolibarrApi if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale - $sql.= ' WHERE t.entity IN ('.getEntity('propal', 1).')'; + $sql.= ' WHERE t.entity IN ('.getEntity('propal').')'; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc"; if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")"; if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 224cb77eee1..a59fefc7a89 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -254,7 +254,7 @@ class Propal extends CommonObject $tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id); if (empty($tva_tx)) $tva_npr=0; $vat_src_code = ''; // May be defined into tva_tx - + $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->thirdparty,$tva_npr); $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->thirdparty,$tva_npr); @@ -433,7 +433,7 @@ class Propal extends CommonObject // Check parameters if ($type < 0) return -1; - + if ($this->statut == self::STATUS_DRAFT) { $this->db->begin(); @@ -1276,7 +1276,7 @@ class Propal extends CommonObject $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON p.fk_input_reason = dr.rowid'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON p.fk_incoterms = i.rowid'; $sql.= " WHERE p.fk_statut = c.id"; - $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; + $sql.= " AND p.entity IN (".getEntity('propal').")"; if ($ref) $sql.= " AND p.ref='".$ref."'"; else $sql.= " AND p.rowid=".$rowid; @@ -1392,17 +1392,17 @@ class Propal extends CommonObject return -1; } } - + /** * Load array lines - * + * * @param int $only_product Return only physical products * @return int <0 if KO, >0 if OK */ function fetch_lines($only_product=0) { $this->lines=array(); - + $sql = 'SELECT d.rowid, d.fk_propal, d.fk_parent_line, d.label as custom_label, d.description, d.price, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,'; $sql.= ' d.info_bits, d.total_ht, d.total_tva, d.total_localtax1, d.total_localtax2, d.total_ttc, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht, d.special_code, d.rang, d.product_type,'; $sql.= ' d.fk_unit,'; @@ -1422,7 +1422,7 @@ class Propal extends CommonObject require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $num = $this->db->num_rows($result); - + $i = 0; while ($i < $num) { @@ -1489,9 +1489,9 @@ class Propal extends CommonObject //print "xx $i ".$this->lines[$i]->fk_product; $i++; } - + $this->db->free($result); - + return 1; } else @@ -1884,7 +1884,7 @@ class Propal extends CommonObject { $this->oldcopy= clone $this; $this->fk_availability = $id; - $this->availability_id = $availability_id; + $this->availability_id = $id; } if (! $notrigger && empty($error)) @@ -2305,7 +2305,7 @@ class Propal extends CommonObject if (! empty($conf->global->MAIN_MULTILANGS)) { $outputlangs = new Translate("",$conf); - $newlang=(GETPOST('lang_id') ? GETPOST('lang_id') : $this->thirdparty->default_lang); + $newlang=(GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $this->thirdparty->default_lang); $outputlangs->setDefaultLang($newlang); } //$ret=$object->fetch($id); // Reload to get new records @@ -2499,7 +2499,7 @@ class Propal extends CommonObject if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p, ".MAIN_DB_PREFIX."c_propalst as c"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE p.entity IN (".getEntity('propal', 1).")"; + $sql.= " WHERE p.entity IN (".getEntity('propal').")"; $sql.= " AND p.fk_soc = s.rowid"; $sql.= " AND p.fk_statut = c.id"; if (! $user->rights->societe->client->voir && ! $socid) //restriction @@ -2779,7 +2779,7 @@ class Propal extends CommonObject function availability($availability_id, $notrigger=0) { global $user; - + if ($this->statut >= self::STATUS_DRAFT) { $error=0; @@ -3025,7 +3025,7 @@ class Propal extends CommonObject $sql.= " WHERE sc.fk_user = " .$user->id; $clause = " AND"; } - $sql.= $clause." p.entity IN (".getEntity('propal', 1).")"; + $sql.= $clause." p.entity IN (".getEntity('propal').")"; if ($mode == 'opened') $sql.= " AND p.fk_statut = ".self::STATUS_VALIDATED; if ($mode == 'signed') $sql.= " AND p.fk_statut = ".self::STATUS_SIGNED; if ($user->societe_id) $sql.= " AND p.fk_soc = ".$user->societe_id; @@ -3096,7 +3096,7 @@ class Propal extends CommonObject $prodids = array(); $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; - $sql.= " WHERE entity IN (".getEntity('product', 1).")"; + $sql.= " WHERE entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); if ($resql) { @@ -3194,7 +3194,7 @@ class Propal extends CommonObject $sql.= " WHERE sc.fk_user = " .$user->id; $clause = "AND"; } - $sql.= " ".$clause." p.entity IN (".getEntity('propal', 1).")"; + $sql.= " ".$clause." p.entity IN (".getEntity('propal').")"; $resql=$this->db->query($sql); if ($resql) @@ -3277,13 +3277,14 @@ class Propal extends CommonObject /** * Return clicable link of object (with eventually picto) * - * @param int $withpicto Add picto into link - * @param string $option Where point the link ('expedition', 'document', ...) - * @param string $get_params Parametres added to url - * @param int $notooltip 1=Disable tooltip - * @return string String with URL + * @param int $withpicto Add picto into link + * @param string $option Where point the link ('expedition', 'document', ...) + * @param string $get_params Parametres added to url + * @param int $notooltip 1=Disable tooltip + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string String with URL */ - function getNomUrl($withpicto=0,$option='', $get_params='', $notooltip=0) + function getNomUrl($withpicto=0, $option='', $get_params='', $notooltip=0, $save_lastsearch_value=-1) { global $langs, $conf, $user; @@ -3318,6 +3319,14 @@ class Propal extends CommonObject if ($option == 'document') { $url = DOL_URL_ROOT.'/comm/propal/document.php?id='.$this->id. $get_params; } + + if ($option != 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; + if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; + } } $linkclose=''; @@ -3352,9 +3361,9 @@ class Propal extends CommonObject function getLinesArray() { // TODO Duplicate with fetch_lines ? Wich one to keep ? - + $this->lines = array(); - + $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, pt.vat_src_code, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc, pt.fk_product_fournisseur_price as fk_fournprice, pt.buy_price_ht as pa_ht, pt.special_code, pt.localtax1_tx, pt.localtax2_tx,'; diff --git a/htdocs/comm/propal/class/propalestats.class.php b/htdocs/comm/propal/class/propalestats.class.php index e38297a3377..39ef49991b6 100644 --- a/htdocs/comm/propal/class/propalestats.class.php +++ b/htdocs/comm/propal/class/propalestats.class.php @@ -86,7 +86,7 @@ class PropaleStats extends Stats $this->where.= " p.fk_statut > 0"; // Validated, accepted, refused and closed } //$this->where.= " AND p.fk_soc = s.rowid AND p.entity = ".$conf->entity; - $this->where.= " AND p.entity IN (".getEntity('propal', 1).")"; + $this->where.= " AND p.entity IN (".getEntity('propal').")"; if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND p.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if($this->socid) { diff --git a/htdocs/comm/propal/contact.php b/htdocs/comm/propal/contact.php index 3e9e5a1205d..01e851769a7 100644 --- a/htdocs/comm/propal/contact.php +++ b/htdocs/comm/propal/contact.php @@ -155,10 +155,10 @@ if ($object->id > 0) // Proposal card - - $linkback = '' . $langs->trans("BackToList") . ''; - - + + $linkback = '' . $langs->trans("BackToList") . ''; + + $morehtmlref='
'; // Ref customer $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); @@ -199,12 +199,12 @@ if ($object->id > 0) } } $morehtmlref.='
'; - + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); dol_fiche_end(); - - + + // Contacts lines (modules that overwrite templates must declare this into descriptor) $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); foreach($dirtpls as $reldir) diff --git a/htdocs/comm/propal/document.php b/htdocs/comm/propal/document.php index 82244886763..65b8eef5a66 100644 --- a/htdocs/comm/propal/document.php +++ b/htdocs/comm/propal/document.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2013 Cédric Salvador @@ -54,7 +54,7 @@ $result = restrictedArea($user, 'propal', $id); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -63,17 +63,18 @@ if (! $sortfield) $sortfield="name"; $object = new Propal($db); $object->fetch($id,$ref); -if ($object->id > 0) -{ - $object->fetch_thirdparty(); - $upload_dir = $conf->propal->dir_output.'/'.dol_sanitizeFileName($object->ref); - include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php'; -} + /* * Actions */ +if ($object->id > 0) +{ + $object->fetch_thirdparty(); + $upload_dir = $conf->propal->dir_output.'/'.dol_sanitizeFileName($object->ref); + include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php'; +} /* @@ -101,10 +102,10 @@ if ($object->id > 0) // Proposal card - - $linkback = '' . $langs->trans("BackToList") . ''; - - + + $linkback = '' . $langs->trans("BackToList") . ''; + + $morehtmlref='
'; // Ref customer $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); @@ -145,24 +146,24 @@ if ($object->id > 0) } } $morehtmlref.='
'; - + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - + + print '
'; print '
'; - + print ''; - + // Files infos print ''; print ''; - + print "
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
\n"; - + print '
'; - - + + dol_fiche_end(); $modulepart = 'propal'; diff --git a/htdocs/comm/propal/index.php b/htdocs/comm/propal/index.php index 145d1891be3..a54ceb32f0b 100644 --- a/htdocs/comm/propal/index.php +++ b/htdocs/comm/propal/index.php @@ -81,7 +81,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; -$sql.= " AND p.entity IN (".getEntity('propal', 1).")"; +$sql.= " AND p.entity IN (".getEntity('propal').")"; if ($user->societe_id) $sql.=' AND p.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " AND p.fk_statut IN (0,1,2,3,4)"; @@ -157,7 +157,7 @@ if (! empty($conf->propal->enabled)) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity IN (".getEntity('propal', 1).")"; + $sql.= " AND c.entity IN (".getEntity('propal').")"; $sql.= " AND c.fk_statut = 0"; if ($socid) $sql.= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -215,7 +215,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."propal as c"; $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; -$sql.= " AND c.entity IN (".getEntity('propal', 1).")"; +$sql.= " AND c.entity IN (".getEntity('propal').")"; //$sql.= " AND c.fk_statut > 2"; if ($socid) $sql .= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -294,7 +294,7 @@ if (! empty($conf->propal->enabled) && $user->rights->propale->lire) $sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; - $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; + $sql.= " AND p.entity IN (".getEntity('propal').")"; $sql.= " AND p.fk_statut = 1"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; diff --git a/htdocs/comm/propal/info.php b/htdocs/comm/propal/info.php index d8af8fb87a8..a94eeaa092c 100644 --- a/htdocs/comm/propal/info.php +++ b/htdocs/comm/propal/info.php @@ -66,7 +66,7 @@ $object->info($object->id); // Proposal card -$linkback = '' . $langs->trans("BackToList") . ''; +$linkback = '' . $langs->trans("BackToList") . ''; $morehtmlref='
'; @@ -122,6 +122,6 @@ dol_print_object_info($object); print '
'; dol_fiche_end(); - + llxFooter(); $db->close(); diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index d2a6c6e926f..e9626a638b8 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -80,22 +80,22 @@ $object_statut=GETPOST('propal_statut'); $sall=GETPOST('sall', 'alphanohtml'); $mesg=(GETPOST("msg") ? GETPOST("msg") : GETPOST("mesg")); -$day=GETPOST("day","int"); -$month=GETPOST("month","int"); -$year=GETPOST("year","int"); +$search_day=GETPOST("search_day","int"); +$search_month=GETPOST("search_month","int"); +$search_year=GETPOST("search_year","int"); $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortfield) $sortfield='p.ref'; if (! $sortorder) $sortorder='DESC'; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $contextpage='proposallist'; // Security check @@ -113,7 +113,7 @@ $result = restrictedArea($user, $module, $objectid, $dbtable); $diroutputmassaction=$conf->propal->dir_output . '/temp/massgeneration/'.$user->id; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('propallist')); $extrafields = new ExtraFields($db); @@ -161,7 +161,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab } } -$object = new Propal($db); // To be passed as parameter of executeHooks that need +$object = new Propal($db); // To be passed as parameter of executeHooks that need /* @@ -197,9 +197,9 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $search_type=''; $search_country=''; $search_type_thirdparty=''; - $year=''; - $month=''; - $day=''; + $search_year=''; + $search_month=''; + $search_day=''; $viewstatut=''; $object_statut=''; $toselect=''; @@ -269,49 +269,49 @@ if ($search_user > 0) $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql.= ' WHERE p.fk_soc = s.rowid'; -$sql.= ' AND p.entity IN ('.getEntity('propal', 1).')'; +$sql.= ' AND p.entity IN ('.getEntity('propal').')'; if (! $user->rights->societe->client->voir && ! $socid) //restriction { $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; } if ($search_town) $sql.= natural_search('s.town', $search_town); -if ($search_zip) $sql.= natural_search("s.zip",$search_zip); -if ($search_state) $sql.= natural_search("state.nom",$search_state); -if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')'; -if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')'; -if ($search_ref) $sql .= natural_search('p.ref', $search_ref); +if ($search_zip) $sql.= natural_search("s.zip", $search_zip); +if ($search_state) $sql.= natural_search("state.nom", $search_state); +if ($search_country) $sql .= " AND s.fk_pays IN (".$db->escape($search_country).')'; +if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$db->escape($search_type_thirdparty).')'; +if ($search_ref) $sql .= natural_search('p.ref', $search_ref); if ($search_refcustomer) $sql .= natural_search('p.ref_client', $search_refcustomer); -if ($search_societe) $sql .= natural_search('s.nom', $search_societe); -if ($search_login) $sql.= " AND u.login LIKE '%".$db->escape(trim($search_login))."%'"; +if ($search_societe) $sql .= natural_search('s.nom', $search_societe); +if ($search_login) $sql .= natural_search("u.login", $search_login); if ($search_montant_ht != '') $sql.= natural_search("p.total_ht", $search_montant_ht, 1); if ($search_montant_vat != '') $sql.= natural_search("p.tva", $search_montant_vat, 1); if ($search_montant_ttc != '') $sql.= natural_search("p.total", $search_montant_ttc, 1); if ($sall) { $sql .= natural_search(array_keys($fieldstosearchall), $sall); } -if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category; +if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$db->escape($search_product_category); if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; if ($viewstatut != '' && $viewstatut != '-1') { - $sql.= ' AND p.fk_statut IN ('.$viewstatut.')'; + $sql.= ' AND p.fk_statut IN ('.$db->escape($viewstatut).')'; } -if ($month > 0) +if ($search_month > 0) { - if ($year > 0 && empty($day)) - $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'"; - else if ($year > 0 && ! empty($day)) - $sql.= " AND p.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'"; + if ($search_year > 0 && empty($search_day)) + $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($search_year,$search_month,false))."' AND '".$db->idate(dol_get_last_day($search_year,$search_month,false))."'"; + else if ($search_year > 0 && ! empty($search_day)) + $sql.= " AND p.datep BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_month, $search_day, $search_year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_month, $search_day, $search_year))."'"; else - $sql.= " AND date_format(p.datep, '%m') = '".$month."'"; + $sql.= " AND date_format(p.datep, '%m') = '".$db->escape($search_month)."'"; } -else if ($year > 0) +else if ($search_year > 0) { - $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; + $sql.= " AND p.datep BETWEEN '".$db->idate(dol_get_first_day($search_year,1,false))."' AND '".$db->idate(dol_get_last_day($search_year,12,false))."'"; } -if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale; +if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$db->escape($search_sale); if ($search_user > 0) { - $sql.= " AND c.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal' AND c.element_id = p.rowid AND c.fk_socpeople = ".$search_user; + $sql.= " AND c.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal' AND c.element_id = p.rowid AND c.fk_socpeople = ".$db->escape($search_user); } // Add where from extra fields foreach ($search_array_options as $key => $val) @@ -359,29 +359,30 @@ if ($resql) else { $title = $langs->trans('ListOfProposals'); - } + } $num = $db->num_rows($resql); - + $arrayofselected=is_array($toselect)?$toselect:array(); - - $param='&viewstatut='.$viewstatut; - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; - if ($sall) $param.='&sall='.$sall; - if ($month) $param.='&month='.$month; - if ($year) $param.='&year='.$year; - if ($search_ref) $param.='&search_ref=' .$search_ref; - if ($search_refcustomer) $param.='&search_refcustomer=' .$search_refcustomer; - if ($search_societe) $param.='&search_societe=' .$search_societe; - if ($search_user > 0) $param.='&search_user='.$search_user; - if ($search_sale > 0) $param.='&search_sale='.$search_sale; - if ($search_montant_ht) $param.='&search_montant_ht='.$search_montant_ht; - if ($search_login) $param.='&search_login='.$search_login; - if ($search_town) $param.='&search_town='.$search_town; - if ($search_zip) $param.='&search_zip='.$search_zip; - if ($socid > 0) $param.='&socid='.$socid; - if ($optioncss != '') $param.='&optioncss='.$optioncss; + + $param='&viewstatut='.urlencode($viewstatut); + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage); + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit); + if ($sall) $param.='&sall='.urlencode($sall); + if ($search_month) $param.='&search_month='.urlencode($search_month); + if ($search_year) $param.='&search_year='.urlencode($search_year); + if ($search_ref) $param.='&search_ref='.urlencode($search_ref); + if ($search_refcustomer) $param.='&search_refcustomer='.urlencode($search_refcustomer); + if ($search_societe) $param.='&search_societe='.urlencode($search_societe); + if ($search_user > 0) $param.='&search_user='.urlencode($search_user); + if ($search_sale > 0) $param.='&search_sale='.urlencode($search_sale); + if ($search_montant_ht) $param.='&search_montant_ht='.urlencode($search_montant_ht); + if ($search_login) $param.='&search_login='.urlencode($search_login); + if ($search_town) $param.='&search_town='.urlencode($search_town); + if ($search_zip) $param.='&search_zip='.urlencode($search_zip); + if ($socid > 0) $param.='&socid='.urlencode($socid); + if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss); + // Add $param from extra fields foreach ($search_array_options as $key => $val) { @@ -389,7 +390,7 @@ if ($resql) $tmpkey=preg_replace('/search_options_/','',$key); if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } - + // List of mass actions available $arrayofmassactions = array( 'presend'=>$langs->trans("SendByMail"), @@ -398,7 +399,7 @@ if ($resql) if ($user->rights->propal->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete"); if ($massaction == 'presend') $arrayofmassactions=array(); $massactionbutton=$form->selectMassAction('', $arrayofmassactions); - + // Lignes des champs de filtre print ''; if ($optioncss != '') print ''; @@ -408,13 +409,13 @@ if ($resql) print ''; print ''; print ''; - + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit); - + if ($massaction == 'presend') { $langs->load("mails"); - + if (! GETPOST('cancel')) { $objecttmp=new Propal($db); @@ -433,17 +434,17 @@ if ($resql) } } } - + print ''; - + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); - + dol_fiche_head(null, '', ''); - + $topicmail="SendSupplierProposalRef"; $modelmail="supplier_proposal_send"; - + // Cree l'objet formulaire mail include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); @@ -496,25 +497,25 @@ if ($resql) $formmail->substit['__REFCLIENT__']='__REFCLIENT__'; // We want to keep the tag $formmail->substit['__PERSONALIZED__']=''; $formmail->substit['__CONTACTCIVNAME__']=''; - + // Tableau des parametres complementaires du post $formmail->param['action']=$action; $formmail->param['models']=$modelmail; $formmail->param['models_id']=GETPOST('modelmailselected','int'); $formmail->param['id']=join(',',$arrayofselected); //$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; - + print $formmail->get_form(); - + dol_fiche_end(); } - + if ($sall) { foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); } - + $i = 0; $moreforfilter=''; @@ -525,7 +526,7 @@ if ($resql) $langs->load("commercial"); $moreforfilter.='
'; $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': '; - $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300'); + $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200'); $moreforfilter.='
'; } // If the user can view prospects other than his' @@ -533,7 +534,7 @@ if ($resql) { $moreforfilter.='
'; $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; - $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); + $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); $moreforfilter.='
'; } // If the user can view products @@ -550,7 +551,7 @@ if ($resql) $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; else $moreforfilter = $hookmanager->resPrint; - + if (! empty($moreforfilter)) { print '
'; @@ -561,12 +562,12 @@ if ($resql) $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); - + print '
'; print ''."\n"; print ''; - if (! empty($arrayfields['p.ref']['checked'])) + if (! empty($arrayfields['p.ref']['checked'])) { print ''; } // Date - if (! empty($arrayfields['p.date']['checked'])) + if (! empty($arrayfields['p.date']['checked'])) { print ''; } // Date end - if (! empty($arrayfields['p.fin_validite']['checked'])) + if (! empty($arrayfields['p.fin_validite']['checked'])) { print ''; } @@ -703,10 +703,10 @@ if ($resql) $searchpicto=$form->showFilterButtons(); print $searchpicto; print ''; - + print "\n"; - + // Fields title print ''; if (! empty($arrayfields['p.ref']['checked'])) print_liste_field_titre($arrayfields['p.ref']['label'],$_SERVER["PHP_SELF"],'p.ref','',$param,'',$sortfield,$sortorder); @@ -726,12 +726,14 @@ if ($resql) // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach($extrafields->attribute_label as $key => $val) + foreach($extrafields->attribute_label as $key => $val) { - if (! empty($arrayfields["ef.".$key]['checked'])) + if (! empty($arrayfields["ef.".$key]['checked'])) { $align=$extrafields->getAlignFlag($key); - print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + $sortonfield = "ef.".$key; + if (! empty($extrafields->attribute_computed[$key])) $sortonfield=''; + print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); } } } @@ -744,28 +746,27 @@ if ($resql) if (! empty($arrayfields['p.fk_statut']['checked'])) print_liste_field_titre($arrayfields['p.fk_statut']['label'],$_SERVER["PHP_SELF"],"p.fk_statut","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch '); print ''."\n"; - + $now = dol_now(); $i=0; $totalarray=array(); while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); - - + $objectstatic->id=$obj->rowid; $objectstatic->ref=$obj->ref; - + print ''; - + if (! empty($arrayfields['p.ref']['checked'])) { print '\n"; if (! $i) $totalarray['nbfield']++; } - + if (! empty($arrayfields['p.ref_client']['checked'])) { // Customer ref @@ -803,12 +804,12 @@ if ($resql) print ''; if (! $i) $totalarray['nbfield']++; } - + $companystatic->id=$obj->socid; $companystatic->name=$obj->name; $companystatic->client=$obj->client; $companystatic->code_client=$obj->code_client; - + // Thirdparty if (! empty($arrayfields['s.nom']['checked'])) { @@ -817,7 +818,7 @@ if ($resql) print ''; if (! $i) $totalarray['nbfield']++; } - + // Town if (! empty($arrayfields['s.town']['checked'])) { @@ -858,7 +859,7 @@ if ($resql) print ''; if (! $i) $totalarray['nbfield']++; } - + // Date proposal if (! empty($arrayfields['p.date']['checked'])) { @@ -867,7 +868,7 @@ if ($resql) print "\n"; if (! $i) $totalarray['nbfield']++; } - + // Date end validity if (! empty($arrayfields['p.fin_validite']['checked'])) { @@ -882,7 +883,7 @@ if ($resql) } if (! $i) $totalarray['nbfield']++; } - + // Amount HT if (! empty($arrayfields['p.total_ht']['checked'])) { @@ -907,7 +908,7 @@ if ($resql) if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield']; $totalarray['totalttc'] += $obj->total_ttc; } - + $userstatic->id=$obj->fk_user_author; $userstatic->login=$obj->login; @@ -920,7 +921,7 @@ if ($resql) print "\n"; if (! $i) $totalarray['nbfield']++; } - + // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -1008,16 +1009,16 @@ if ($resql) } $db->free($resql); - + $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql); $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - + print '
'; print ''; @@ -608,19 +609,18 @@ if ($resql) print ''; //print $langs->trans('Month').': '; - if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; - print ''; + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + print ''; //print ' '.$langs->trans('Year').': '; - $syear = $year; - $formother->select_year($syear,'year',1, 20, 5); + $formother->select_year($search_year,'search_year',1, 20, 5); print ' 
'; - + print ''; // Picto + Ref print ''; // Warning $warnornote=''; @@ -790,11 +791,11 @@ if ($resql) $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir); print '
'; - print $objectstatic->getNomUrl(1); + print $objectstatic->getNomUrl(1, '', '', 0, 1); print '
'; - + print "
'."\n"; print '
'."\n"; print ''."\n"; - + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { /* @@ -1025,18 +1026,18 @@ if ($resql) */ $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; $urlsource.=str_replace('&','&',$param); - + $filedir=$diroutputmassaction; $genallowed=$user->rights->propal->lire; $delallowed=$user->rights->propal->lire; - + print $formfile->showdocuments('massfilesarea_proposals','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,'',''); } else { print '
'.$langs->trans("ShowTempMassFilesArea").''; } - + } else { diff --git a/htdocs/comm/propal/note.php b/htdocs/comm/propal/note.php index ec1dac31c24..29fc43b0899 100644 --- a/htdocs/comm/propal/note.php +++ b/htdocs/comm/propal/note.php @@ -56,7 +56,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, /* - * View + * View */ llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos'); @@ -79,13 +79,13 @@ if ($id > 0 || ! empty($ref)) $cssclass='titlefield'; //if ($action == 'editnote_public') $cssclass='titlefieldcreate'; //if ($action == 'editnote_private') $cssclass='titlefieldcreate'; - - + + // Proposal card - - $linkback = '' . $langs->trans("BackToList") . ''; - - + + $linkback = '' . $langs->trans("BackToList") . ''; + + $morehtmlref='
'; // Ref customer $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); @@ -126,17 +126,17 @@ if ($id > 0 || ! empty($ref)) } } $morehtmlref.='
'; - + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); print '
'; print '
'; - + $cssclass="titlefield"; include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; print '
'; - + dol_fiche_end(); } } diff --git a/htdocs/comm/prospect/index.php b/htdocs/comm/prospect/index.php index 2364672ccf9..0ec6f20ae46 100644 --- a/htdocs/comm/prospect/index.php +++ b/htdocs/comm/prospect/index.php @@ -120,7 +120,7 @@ if (! empty($conf->propal->enabled) && $user->rights->propale->lire) if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_statut = 0"; $sql.= " AND p.fk_soc = s.rowid"; - $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; + $sql.= " AND p.entity IN (".getEntity('propal').")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $resql=$db->query($sql); @@ -183,7 +183,7 @@ if (! empty($conf->propal->enabled) && $user->rights->propale->lire) $sql.= " WHERE p.fk_soc = s.rowid"; $sql.= " AND p.fk_statut = c.id"; $sql.= " AND p.fk_statut = 1"; - $sql.= " AND p.entity IN (".getEntity('propal', 1).")"; + $sql.= " AND p.entity IN (".getEntity('propal').")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; $sql.= " ORDER BY p.rowid DESC"; diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index ebd8864568a..13fe07f78df 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -49,7 +49,7 @@ if (! empty($conf->projet->enabled)) { require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php'; } - + require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php'; if (!empty($conf->variants->enabled)) { @@ -98,7 +98,7 @@ $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); // Load object include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be include, not include_once -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('ordercard','globalcard')); $permissionnote = $user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php @@ -116,7 +116,7 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { - if ($cancel) + if ($cancel) { if ($action != 'addlink' && $action != 'updateline') { @@ -130,7 +130,7 @@ if (empty($reshook)) } $action=''; } - + include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once @@ -208,8 +208,8 @@ if (empty($reshook)) // Define output language $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) - $newlang = GETPOST('lang_id'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) + $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { @@ -379,7 +379,7 @@ if (empty($reshook)) $tva_tx = $lines[$i]->tva_tx; if (! empty($lines[$i]->vat_src_code) && ! preg_match('/\(/', $tva_tx)) $tva_tx .= ' ('.$lines[$i]->vat_src_code.')'; - + $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $lines[$i]->remise_percent, $lines[$i]->info_bits, $lines[$i]->fk_remise_except, 'HT', 0, $date_start, $date_end, $product_type, $lines[$i]->rang, $lines[$i]->special_code, $fk_parent_line, $lines[$i]->fk_fournprice, $lines[$i]->pa_ht, $label, $array_options, $lines[$i]->fk_unit, $object->origin, $lines[$i]->rowid); if ($result < 0) { @@ -779,7 +779,7 @@ if (empty($reshook)) $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx)); $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx)); - + // if price ht is forced (ie: calculated by margin rate and cost price). TODO Why this ? if (! empty($price_ht)) { $pu_ht = price2num($price_ht, 'MU'); @@ -801,8 +801,8 @@ if (empty($reshook)) if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $outputlangs = $langs; $newlang = ''; - if (empty($newlang) && GETPOST('lang_id')) - $newlang = GETPOST('lang_id'); + if (empty($newlang) && GETPOST('lang_id','aZ09')) + $newlang = GETPOST('lang_id','aZ09'); if (empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { @@ -1015,8 +1015,8 @@ if (empty($reshook)) // Define output language $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) - $newlang = GETPOST('lang_id'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) + $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { @@ -1102,7 +1102,7 @@ if (empty($reshook)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); @@ -1155,7 +1155,7 @@ if (empty($reshook)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); @@ -1457,10 +1457,10 @@ if ($action == 'create' && $user->rights->commande->creer) print ''; // Reference - print ''; + print ''; // Reference client - print ''; else @@ -1471,13 +1471,13 @@ if ($action == 'create' && $user->rights->commande->creer) print ''; print ''; if ($socid > 0) { - print ''; } else { - print ''; // Ligne info remises tiers - print ''; } // Date - print ''; // Delivery date planed - print ""; // Conditions de reglement - print ''; // Mode de reglement - print ''; // Bank Account if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && ! empty($conf->banque->enabled)) { - print ''; } // Delivery delay - print ''; // Shipping Method if (! empty($conf->expedition->enabled)) { - print ''; } @@ -1565,13 +1565,13 @@ if ($action == 'create' && $user->rights->commande->creer) if (! empty($conf->expedition->enabled) && ! empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_ORDER)) { require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $formproduct=new FormProduct($db); - print ''; } // What trigger creation - print ''; @@ -1582,7 +1582,7 @@ if ($action == 'create' && $user->rights->commande->creer) { $langs->load("projects"); print ''; - print ''; @@ -1594,7 +1594,7 @@ if ($action == 'create' && $user->rights->commande->creer) { print ''; print ''; - print ''; - print ''; print ''; - print ''; } @@ -1635,7 +1635,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Note public print ''; print ''; - print ''; print ''; - print ''; - print ''; - print '"; + print ''; + print ''; + print '"; if ($mysoc->localtax1_assuj == "1" || $objectsrc->total_localtax1 != 0) // Localtax1 RE { - print '"; + print '"; } if ($mysoc->localtax2_assuj == "1" || $objectsrc->total_localtax2 != 0) // Localtax2 IRPF { - print '"; + print '"; } - print '"; + print '"; if (!empty($conf->multicurrency->enabled)) { - print ''; - print '"; - print '"; + print ''; + print '"; + print '"; } } @@ -1915,7 +1915,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Order card - $linkback = '' . $langs->trans("BackToList") . ''; + $linkback = '' . $langs->trans("BackToList") . ''; $morehtmlref='
'; @@ -2240,7 +2240,7 @@ if ($action == 'create' && $user->rights->commande->creer) } print ''; */ - + $tmparray=$object->getTotalWeightVolume(); $totalWeight=$tmparray['weight']; $totalVolume=$tmparray['volume']; @@ -2269,7 +2269,7 @@ if ($action == 'create' && $user->rights->commande->creer) else print ' '; print '
' . $langs->trans('Ref') . '' . $langs->trans("Draft") . '
' . $langs->trans('Ref') . '' . $langs->trans("Draft") . '
' . $langs->trans('RefCustomer') . ''; + print '
' . $langs->trans('RefCustomer') . ''; if (!empty($conf->global->MAIN_USE_PROPAL_REFCLIENT_FOR_ORDER) && ! empty($origin) && ! empty($originid)) print '
' . $langs->trans('Customer') . ''; + print ''; print $soc->getNomUrl(1); print ''; print ''; - print $form->select_company('', 'socid', 's.client = 1 OR s.client = 3', 'SelectThirdParty'); + print ''; + print $form->select_company('', 'socid', 's.client = 1 OR s.client = 3', 'SelectThirdParty', 0, 0, null, 0, 'minwidth300'); // reload page to retrieve customer informations if (!empty($conf->global->RELOAD_PAGE_ON_CUSTOMER_CHANGE)) { @@ -1497,12 +1497,12 @@ if ($action == 'create' && $user->rights->commande->creer) // Contact of order if ($socid > 0) { - print "
" . $langs->trans("DefaultContact") . ''; + print "
" . $langs->trans("DefaultContact") . ''; $form->select_contacts($soc->id, $setcontact, 'contactid', 1, $srccontactslist); print '
' . $langs->trans('Discounts') . ''; + print '
' . $langs->trans('Discounts') . ''; if ($soc->remise_percent) print $langs->trans("CompanyHasRelativeDiscount", $soc->remise_percent); else @@ -1517,12 +1517,12 @@ if ($action == 'create' && $user->rights->commande->creer) print '
' . $langs->trans('Date') . ''; + print '
' . $langs->trans('Date') . ''; $form->select_date('', 're', '', '', '', "crea_commande", 1, 1); // Always autofill date with current date print '
".$langs->trans("DateDeliveryPlanned").''; + print "
".$langs->trans("DateDeliveryPlanned").''; if (empty($datedelivery)) { if (! empty($conf->global->DATE_LIVRAISON_WEEK_DELAY)) $datedelivery = time() + ((7*$conf->global->DATE_LIVRAISON_WEEK_DELAY) * 24 * 60 * 60); @@ -1532,31 +1532,31 @@ if ($action == 'create' && $user->rights->commande->creer) print "
' . $langs->trans('PaymentConditionsShort') . ''; + print '
' . $langs->trans('PaymentConditionsShort') . ''; $form->select_conditions_paiements($cond_reglement_id, 'cond_reglement_id', - 1, 1); print '
' . $langs->trans('PaymentMode') . ''; + print '
' . $langs->trans('PaymentMode') . ''; $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id'); print '
' . $langs->trans('BankAccount') . ''; + print '
' . $langs->trans('BankAccount') . ''; $form->select_comptes($fk_account, 'fk_account', 0, '', 1); print '
' . $langs->trans('AvailabilityPeriod') . ''; + print '
' . $langs->trans('AvailabilityPeriod') . ''; $form->selectAvailabilityDelay($availability_id, 'availability_id', '', 1); print '
' . $langs->trans('SendingMethod') . ''; + print '
' . $langs->trans('SendingMethod') . ''; print $form->selectShippingMethod($shipping_method_id, 'shipping_method_id', '', 1); print '
' . $langs->trans('Warehouse') . ''; + print '
' . $langs->trans('Warehouse') . ''; print $formproduct->selectWarehouses($warehouse_id, 'warehouse_id', '', 1); print '
' . $langs->trans('Source') . ''; + print '
' . $langs->trans('Source') . ''; $form->selectInputReason($demand_reason_id, 'demand_reason_id', '', 1); print '
' . $langs->trans("Project") . ''; + print '' . $langs->trans("Project") . ''; $numprojet = $formproject->select_projects($soc->id, $projectid, 'projectid', 0); print '   id).'">' . $langs->trans("AddProject") . ''; print '
'; + print ''; $incoterm_id = GETPOST('incoterm_id'); $incoterm_location = GETPOST('location_incoterms'); if (empty($incoterm_id)) @@ -1607,16 +1607,16 @@ if ($action == 'create' && $user->rights->commande->creer) } // Other attributes - $parameters = array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"', 'socid'=>$socid); + $parameters = array('objectsrc' => $objectsrc, 'socid'=>$socid); $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by - // hook + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields, 'edit'); } // Template to use by default print '
' . $langs->trans('DefaultModel') . ''; + print ''; include_once DOL_DOCUMENT_ROOT . '/core/modules/commande/modules_commande.php'; $liste = ModelePDFCommandes::liste_modeles($db); print $form->selectarray('model', $liste, $conf->global->COMMANDE_ADDON_PDF); @@ -1627,7 +1627,7 @@ if ($action == 'create' && $user->rights->commande->creer) { print '
'.fieldLabel('Currency','multicurrency_code').''; + print ''; print $form->selectMultiCurrency($currency_code, 'multicurrency_code'); print '
' . $langs->trans('NotePublic') . ''; + print ''; $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); @@ -1646,7 +1646,7 @@ if ($action == 'create' && $user->rights->commande->creer) if (empty($user->societe_id)) { print '
' . $langs->trans('NotePrivate') . ''; + print ''; $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', 0, false, true, ROWS_3, '90%'); print $doleditor->Create(1); @@ -1689,26 +1689,26 @@ if ($action == 'create' && $user->rights->commande->creer) $newclassname = $classname; } - print '
' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . '
' . $langs->trans('TotalHT') . '' . price($objectsrc->total_ht) . '
' . $langs->trans('TotalVAT') . '' . price($objectsrc->total_tva) . "
' . $langs->trans($newclassname) . '' . $objectsrc->getNomUrl(1) . '
' . $langs->trans('TotalHT') . '' . price($objectsrc->total_ht) . '
' . $langs->trans('TotalVAT') . '' . price($objectsrc->total_tva) . "
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($objectsrc->total_localtax1) . "
' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '' . price($objectsrc->total_localtax1) . "
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($objectsrc->total_localtax2) . "
' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '' . price($objectsrc->total_localtax2) . "
' . $langs->trans('TotalTTC') . '' . price($objectsrc->total_ttc) . "
' . $langs->trans('TotalTTC') . '' . price($objectsrc->total_ttc) . "
' . $langs->trans('MulticurrencyTotalHT') . '' . price($objectsrc->multicurrency_total_ht) . '
' . $langs->trans('MulticurrencyTotalVAT') . '' . price($objectsrc->multicurrency_total_tva) . "
' . $langs->trans('MulticurrencyTotalTTC') . '' . price($objectsrc->multicurrency_total_ttc) . "
' . $langs->trans('MulticurrencyTotalHT') . '' . price($objectsrc->multicurrency_total_ht) . '
' . $langs->trans('MulticurrencyTotalVAT') . '' . price($objectsrc->multicurrency_total_tva) . "
' . $langs->trans('MulticurrencyTotalTTC') . '' . price($objectsrc->multicurrency_total_ttc) . "
'; print ''; - print ''; + print ''; if ($action != 'editincoterm') { print $form->textwithpicto($object->display_incoterms(), $object->libelle_incoterms, 1); @@ -2291,7 +2291,7 @@ if ($action == 'create' && $user->rights->commande->creer) if ($action != 'editbankaccount' && $user->rights->commande->creer) print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).''; print ''; - print ''; + print ''; if ($action == 'editbankaccount') { $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); } else { @@ -2302,7 +2302,6 @@ if ($action == 'create' && $user->rights->commande->creer) } // Other attributes - $cols = 2; include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; print ''; @@ -2320,18 +2319,18 @@ if ($action == 'create' && $user->rights->commande->creer) print '' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . ''; print '' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; print ''; - + // Multicurrency Amount VAT print '' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . ''; print '' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; print ''; - + // Multicurrency Amount TTC print '' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . ''; print '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . ''; print ''; } - + // Total HT print '' . $langs->trans('AmountHT') . ''; print '' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . ''; @@ -2444,7 +2443,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Send if ($object->statut > Commande::STATUS_DRAFT) { if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) { - print ''; + print ''; } else print ''; } @@ -2622,6 +2621,19 @@ if ($action == 'create' && $user->rights->commande->creer) $outputlangs->load('commercial'); } + // Show email form + + // By default if $action=='presend' + $titreform='SendOrderByMail'; + $topicmail=''; + if (empty($object->ref_client)) { + $topicmail = $outputlangs->trans('SendOrderRef', '__ORDERREF__'); + } else if (! empty($object->ref_client)) { + $topicmail = $outputlangs->trans('SendOrderRef', '__ORDERREF__ (__REFCLIENT__)'); + } + $action='send'; + $modelmail='order_send'; + // Build document if it not exists if (! $file || ! is_readable($file)) { $result = $object->generateDocument(GETPOST('model') ? GETPOST('model') : $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); @@ -2636,7 +2648,7 @@ if ($action == 'create' && $user->rights->commande->creer) print '
'; print '
'; print '
'; - print load_fiche_titre($langs->trans('SendOrderByMail')); + print load_fiche_titre($langs->trans($titreform)); dol_fiche_head(''); @@ -2663,11 +2675,7 @@ if ($action == 'create' && $user->rights->commande->creer) $formmail->withto = GETPOST('sendto') ? GETPOST('sendto') : $liste; $formmail->withtocc = $liste; $formmail->withtoccc = $conf->global->MAIN_EMAIL_USECCC; - if (empty($object->ref_client)) { - $formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__'); - } else if (! empty($object->ref_client)) { - $formmail->withtopic = $outputlangs->trans('SendOrderRef', '__ORDERREF__ (__REFCLIENT__)'); - } + $formmail->withtopic = $topicmail; $formmail->withfile = 2; $formmail->withbody = 1; $formmail->withdeliveryreceipt = 1; @@ -2697,8 +2705,8 @@ if ($action == 'create' && $user->rights->commande->creer) } // Tableau des parametres complementaires - $formmail->param['action'] = 'send'; - $formmail->param['models'] = 'order_send'; + $formmail->param['action'] = $action; + $formmail->param['models'] = $modelmail; $formmail->param['models_id']=GETPOST('modelmailselected','int'); $formmail->param['orderid'] = $object->id; $formmail->param['returnurl'] = $_SERVER["PHP_SELF"] . '?id=' . $object->id; diff --git a/htdocs/commande/class/api_deprecated_commande.class.php b/htdocs/commande/class/api_deprecated_commande.class.php index c0b3a634825..11d3fe7260a 100644 --- a/htdocs/commande/class/api_deprecated_commande.class.php +++ b/htdocs/commande/class/api_deprecated_commande.class.php @@ -128,7 +128,7 @@ class CommandeApi extends DolibarrApi //if ($mode == 1) $sql.= " AND s.client IN (1, 3)"; //if ($mode == 2) $sql.= " AND s.client IN (2, 3)"; - $sql.= ' WHERE s.entity IN ('.getEntity('commande', 1).')'; + $sql.= ' WHERE s.entity IN ('.getEntity('commande').')'; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc"; if ($socid) $sql.= " AND s.fk_soc = ".$socid; if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 1bd4e44a877..a1330a7be04 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -115,7 +115,7 @@ class Orders extends DolibarrApi if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale - $sql.= ' WHERE t.entity IN ('.getEntity('commande', 1).')'; + $sql.= ' WHERE t.entity IN ('.getEntity('commande').')'; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc"; if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")"; if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index fea30eda589..0910fedcb9d 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -706,10 +706,10 @@ class Commande extends CommonOrder // Clean parameters $this->brouillon = 1; // set command as draft - + // $date_commande is deprecated $date = ($this->date_commande ? $this->date_commande : $this->date); - + // Multicurrency (test on $this->multicurrency_tx because we sould take the default rate only if not using origin rate) if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code, $date); else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); @@ -1468,7 +1468,7 @@ class Commande extends CommonOrder $tva_npr = get_default_npr($mysoc,$this->thirdparty,$prod->id); if (empty($tva_tx)) $tva_npr=0; $vat_src_code = ''; // May be defined into tva_tx - + $localtax1_tx=get_localtax($tva_tx,1,$this->thirdparty,$mysoc,$tva_npr); $localtax2_tx=get_localtax($tva_tx,2,$this->thirdparty,$mysoc,$tva_npr); @@ -1564,7 +1564,7 @@ class Commande extends CommonOrder $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_availability as ca ON (c.fk_availability = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_input_reason as dr ON (c.fk_input_reason = ca.rowid)'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON c.fk_incoterms = i.rowid'; - $sql.= " WHERE c.entity IN (".getEntity('commande', 1).")"; + $sql.= " WHERE c.entity IN (".getEntity('commande').")"; if ($id) $sql.= " AND c.rowid=".$id; if ($ref) $sql.= " AND c.ref='".$this->db->escape($ref)."'"; if ($ref_ext) $sql.= " AND c.ref_ext='".$this->db->escape($ref_ext)."'"; @@ -1798,7 +1798,7 @@ class Commande extends CommonOrder $line->product_type = $objp->product_type; $line->qty = $objp->qty; - $line->vat_src_code = $objp->vat_src_code; + $line->vat_src_code = $objp->vat_src_code; $line->tva_tx = $objp->tva_tx; $line->localtax1_tx = $objp->localtax1_tx; $line->localtax2_tx = $objp->localtax2_tx; @@ -2369,7 +2369,7 @@ class Commande extends CommonOrder if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", sc.fk_soc, sc.fk_user"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande as c"; if (! $user->rights->societe->client->voir && ! $socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE c.entity IN (".getEntity('commande', 1).")"; + $sql.= " WHERE c.entity IN (".getEntity('commande').")"; $sql.= " AND c.fk_soc = s.rowid"; if (! $user->rights->societe->client->voir && ! $socid) //restriction { @@ -3106,7 +3106,7 @@ class Commande extends CommonOrder $error = 0; dol_syslog(get_class($this) . "::delete ".$this->id, LOG_DEBUG); - + $this->db->begin(); if (! $error && ! $notrigger) @@ -3222,7 +3222,7 @@ class Commande extends CommonOrder $sql.= " WHERE sc.fk_user = " .$user->id; $clause = " AND"; } - $sql.= $clause." c.entity IN (".getEntity('commande', 1).")"; + $sql.= $clause." c.entity IN (".getEntity('commande').")"; //$sql.= " AND c.fk_statut IN (1,2,3) AND c.facture = 0"; $sql.= " AND ((c.fk_statut IN (".self::STATUS_VALIDATED.",".self::STATUS_ACCEPTED.")) OR (c.fk_statut = ".self::STATUS_CLOSED." AND c.facture = 0))"; // If status is 2 and facture=1, it must be selected if ($user->societe_id) $sql.=" AND c.fk_soc = ".$user->societe_id; @@ -3369,24 +3369,33 @@ class Commande extends CommonOrder /** * Return clicable link of object (with eventually picto) * - * @param int $withpicto Add picto into link - * @param int $option Where point the link (0=> main card, 1,2 => shipment) - * @param int $max Max length to show - * @param int $short ??? - * @param int $notooltip 1=Disable tooltip - * @return string String with URL + * @param int $withpicto Add picto into link + * @param int $option Where point the link (0=> main card, 1,2 => shipment) + * @param int $max Max length to show + * @param int $short ??? + * @param int $notooltip 1=Disable tooltip + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string String with URL */ - function getNomUrl($withpicto=0,$option=0,$max=0,$short=0,$notooltip=0) + function getNomUrl($withpicto=0, $option=0, $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1) { global $conf, $langs, $user; if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips - + $result=''; if (! empty($conf->expedition->enabled) && ($option == 1 || $option == 2)) $url = DOL_URL_ROOT.'/expedition/shipment.php?id='.$this->id; else $url = DOL_URL_ROOT.'/commande/card.php?id='.$this->id; + if ($option !== 'nolink') + { + // Add param to save lastsearch_values or not + $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; + if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; + } + if ($short) return $url; $picto = 'order'; @@ -3418,7 +3427,7 @@ class Commande extends CommonOrder $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose.=' class="classfortooltip"'; } - + $linkstart = ''; $linkend=''; @@ -3506,7 +3515,7 @@ class Commande extends CommonOrder $prodids = array(); $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; - $sql.= " WHERE entity IN (".getEntity('product', 1).")"; + $sql.= " WHERE entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); if ($resql) { @@ -3598,7 +3607,7 @@ class Commande extends CommonOrder $sql.= " WHERE sc.fk_user = " .$user->id; $clause = "AND"; } - $sql.= " ".$clause." co.entity IN (".getEntity('commande', 1).")"; + $sql.= " ".$clause." co.entity IN (".getEntity('commande').")"; $resql=$this->db->query($sql); if ($resql) diff --git a/htdocs/commande/class/commandestats.class.php b/htdocs/commande/class/commandestats.class.php index 81488bdb1d6..b0c63625bb9 100644 --- a/htdocs/commande/class/commandestats.class.php +++ b/htdocs/commande/class/commandestats.class.php @@ -81,7 +81,7 @@ class CommandeStats extends Stats $this->where.= " c.fk_statut > 2"; // Only approved & ordered } //$this->where.= " AND c.fk_soc = s.rowid AND c.entity = ".$conf->entity; - $this->where.= ' AND c.entity IN ('.getEntity('commande', 1).')'; + $this->where.= ' AND c.entity IN ('.getEntity('commande').')'; if (!$user->rights->societe->client->voir && !$this->socid) $this->where .= " AND c.fk_soc = sc.fk_soc AND sc.fk_user = " .$user->id; if ($this->socid) diff --git a/htdocs/commande/contact.php b/htdocs/commande/contact.php index fe37a630c5d..0eb4ed2cd63 100644 --- a/htdocs/commande/contact.php +++ b/htdocs/commande/contact.php @@ -142,16 +142,16 @@ if ($id > 0 || ! empty($ref)) if ($object->fetch($id, $ref) > 0) { $object->fetch_thirdparty(); - + $head = commande_prepare_head($object); dol_fiche_head($head, 'contact', $langs->trans("CustomerOrder"), -1, 'order'); - + // Order card - - $linkback = '' . $langs->trans("BackToList") . ''; - - + + $linkback = '' . $langs->trans("BackToList") . ''; + + $morehtmlref='
'; // Ref customer $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); @@ -191,7 +191,7 @@ if ($id > 0 || ! empty($ref)) } } } - $morehtmlref.='
'; + $morehtmlref.='
'; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); diff --git a/htdocs/commande/customer.php b/htdocs/commande/customer.php index 431a54b9f76..8aa699fed71 100644 --- a/htdocs/commande/customer.php +++ b/htdocs/commande/customer.php @@ -45,11 +45,11 @@ accessforbidden(); $langs->load("companies"); $langs->load("orders"); -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -75,7 +75,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql.= ", sc.fk_soc, sc.fk $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."c_stcomm as st, ".MAIN_DB_PREFIX."commande as c"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fk_stcomm = st.id AND c.fk_soc = s.rowid"; -$sql.= " AND s.entity IN (".getEntity('societe', 1).")"; +$sql.= " AND s.entity IN (".getEntity('societe').")"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if (dol_strlen($stcomm)) { diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php index 0b6cb908ef3..7eea9c95877 100644 --- a/htdocs/commande/document.php +++ b/htdocs/commande/document.php @@ -53,7 +53,7 @@ $result=restrictedArea($user,'commande',$id,''); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -101,12 +101,12 @@ if ($id > 0 || ! empty($ref)) { $totalsize+=$file['size']; } - + // Order card - - $linkback = '' . $langs->trans("BackToList") . ''; - - + + $linkback = '' . $langs->trans("BackToList") . ''; + + $morehtmlref='
'; // Ref customer $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); @@ -147,25 +147,25 @@ if ($id > 0 || ! empty($ref)) } } $morehtmlref.='
'; - + // Order card - + $linkback = '' . $langs->trans("BackToList") . ''; - - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); + print '
'; print '
'; - + print ''; print ''; print ''; print "
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
\n"; - + print "
\n"; - + print dol_fiche_end(); $modulepart = 'commande'; diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php index 9f7f36f78ca..fee8e5314d1 100644 --- a/htdocs/commande/index.php +++ b/htdocs/commande/index.php @@ -85,7 +85,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."commande as c"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; -$sql.= " AND c.entity IN (".getEntity('societe', 1).")"; +$sql.= " AND c.entity IN (".getEntity('societe').")"; if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " GROUP BY c.fk_statut, c.facture"; @@ -177,7 +177,7 @@ if (! empty($conf->commande->enabled)) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; + $sql.= " AND c.entity IN (".getEntity('commande').")"; $sql.= " AND c.fk_statut = 0"; if ($socid) $sql.= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -247,7 +247,7 @@ $sql.= " FROM ".MAIN_DB_PREFIX."commande as c,"; $sql.= " ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; -$sql.= " AND c.entity IN (".getEntity('commande', 1).")"; +$sql.= " AND c.entity IN (".getEntity('commande').")"; //$sql.= " AND c.fk_statut > 2"; if ($socid) $sql .= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -328,7 +328,7 @@ if (! empty($conf->commande->enabled)) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; + $sql.= " AND c.entity IN (".getEntity('commande').")"; $sql.= " AND c.fk_statut = 1"; if ($socid) $sql.= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -410,7 +410,7 @@ if (! empty($conf->commande->enabled)) $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE c.fk_soc = s.rowid"; - $sql.= " AND c.entity IN (".getEntity('commande', 1).")"; + $sql.= " AND c.entity IN (".getEntity('commande').")"; $sql.= " AND c.fk_statut = 2 "; if ($socid) $sql.= " AND c.fk_soc = ".$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; diff --git a/htdocs/commande/info.php b/htdocs/commande/info.php index 02b631c4c8a..05adc9def54 100644 --- a/htdocs/commande/info.php +++ b/htdocs/commande/info.php @@ -65,7 +65,7 @@ dol_fiche_head($head, 'info', $langs->trans("CustomerOrder"), -1, 'order'); // Order card -$linkback = '' . $langs->trans("BackToList") . ''; +$linkback = '' . $langs->trans("BackToList") . ''; $morehtmlref='
'; // Ref customer diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index b9102e78ddc..8ce3ba7cd04 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -45,18 +45,18 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; $langs->loadLangs(array("orders",'sendings','deliveries','companies','compta','bills')); -$action=GETPOST('action','alpha'); +$action=GETPOST('action','aZ09'); $massaction=GETPOST('massaction','alpha'); $show_files=GETPOST('show_files','int'); $confirm=GETPOST('confirm','alpha'); $toselect = GETPOST('toselect', 'array'); -$orderyear=GETPOST("orderyear","int"); -$ordermonth=GETPOST("ordermonth","int"); -$orderday=GETPOST("orderday","int"); -$deliveryyear=GETPOST("deliveryyear","int"); -$deliverymonth=GETPOST("deliverymonth","int"); -$deliveryday=GETPOST("deliveryday","int"); +$search_orderyear=GETPOST("search_orderyear","int"); +$search_ordermonth=GETPOST("search_ordermonth","int"); +$search_orderday=GETPOST("search_orderday","int"); +$search_deliveryyear=GETPOST("search_deliveryyear","int"); +$search_deliverymonth=GETPOST("search_deliverymonth","int"); +$search_deliveryday=GETPOST("search_deliveryday","int"); $search_product_category=GETPOST('search_product_category','int'); $search_ref=GETPOST('search_ref','alpha')!=''?GETPOST('search_ref','alpha'):GETPOST('sref','alpha'); $search_ref_customer=GETPOST('search_ref_customer','alpha'); @@ -82,11 +82,11 @@ $result = restrictedArea($user, 'commande', $id,''); $diroutputmassaction=$conf->commande->dir_output . '/temp/massgeneration/'.$user->id; -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -96,7 +96,7 @@ if (! $sortorder) $sortorder='DESC'; // Initialize technical object to manage context to save list fields $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'orderlist'; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array($contextpage)); $extrafields = new ExtraFields($db); @@ -160,7 +160,7 @@ if (empty($reshook)) { // Selection of new fields include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; - + // 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 { @@ -180,12 +180,12 @@ if (empty($reshook)) $search_total_ht=''; $search_total_vat=''; $search_total_ttc=''; - $orderyear=''; - $ordermonth=''; - $orderday=''; - $deliveryday=''; - $deliverymonth=''; - $deliveryyear=''; + $search_orderyear=''; + $search_ordermonth=''; + $search_orderday=''; + $search_deliveryday=''; + $search_deliverymonth=''; + $search_deliveryyear=''; $viewstatut=''; $billed=''; $toselect=''; @@ -202,51 +202,51 @@ if (empty($reshook)) // TODO Move this into mass action include if ($massaction == 'confirm_createbills') { - + $orders = GETPOST('toselect'); $createbills_onebythird = GETPOST('createbills_onebythird', 'int'); $validate_invoices = GETPOST('valdate_invoices', 'int'); - + $TFact = array(); $TFactThird = array(); - + $nb_bills_created = 0; - + $db->begin(); - + foreach($orders as $id_order) { - + $cmd = new Commande($db); if($cmd->fetch($id_order) <= 0) continue; - + $object = new Facture($db); if(!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $object = $TFactThird[$cmd->socid]; // If option "one bill per third" is set, we use already created order. else { - + $object->socid = $cmd->socid; $object->type = Facture::TYPE_STANDARD; $object->cond_reglement_id = $cmd->cond_reglement_id; $object->mode_reglement_id = $cmd->mode_reglement_id; $object->fk_project = $cmd->fk_project; - + $datefacture = dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']); if (empty($datefacture)) { $datefacture = dol_mktime(date("h"), date("M"), 0, date("m"), date("d"), date("Y")); } - + $object->date = $datefacture; $object->origin = 'commande'; $object->origin_id = $id_order; - + $res = $object->create($user); - + if($res > 0) $nb_bills_created++; - + } - + if($object->id > 0) { - + $db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; $sql.= "fk_source"; @@ -259,7 +259,7 @@ if (empty($reshook)) $sql.= ", ".$object->id; $sql.= ", '".$object->element."'"; $sql.= ")"; - + if ($db->query($sql)) { $db->commit(); @@ -268,17 +268,17 @@ if (empty($reshook)) { $db->rollback(); } - + $lines = $cmd->lines; if (empty($lines) && method_exists($cmd, 'fetch_lines')) { $cmd->fetch_lines(); $lines = $cmd->lines; } - + $fk_parent_line=0; $num=count($lines); - + for ($i=0;$i<$num;$i++) { $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle); @@ -367,43 +367,43 @@ if (empty($reshook)) $fk_parent_line = $result; } } - } - + } + } - + $cmd->classifyBilled($user); - + if(!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $object; else $TFact[$object->id] = $object; } - + // Build doc with all invoices $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird; $toselect = array(); - + if(!empty($validate_invoices)) { - + $massaction = $action = 'builddoc'; - + foreach($TAllFact as &$object) { $object->validate($user); $toselect[] = $object->id; // For builddoc action - + // Fac builddoc $upload_dir = $conf->facture->dir_output; $permissioncreate=$user->rights->facture->creer; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; } - + $objectclass='Facture'; $objectlabel='Invoice'; $permtoread = $user->rights->facture->lire; $permtodelete = $user->rights->facture->supprimer; $uploaddir = $conf->facture->dir_output; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; - + } - + if (! $error) { $db->commit(); @@ -418,7 +418,7 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); $error++; } - } + } } @@ -468,7 +468,7 @@ if ($search_user > 0) $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql.= ' WHERE c.fk_soc = s.rowid'; -$sql.= ' AND c.entity IN ('.getEntity('commande', 1).')'; +$sql.= ' AND c.entity IN ('.getEntity('commande').')'; if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category; if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -499,31 +499,31 @@ if ($viewstatut <> '') $sql .= ' AND ((c.fk_statut IN (1,2)) OR (c.fk_statut = 3 AND c.facture = 0))'; // validated, in process or closed but not billed } } -if ($ordermonth > 0) +if ($search_ordermonth > 0) { - if ($orderyear > 0 && empty($orderday)) - $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($orderyear,$ordermonth,false))."' AND '".$db->idate(dol_get_last_day($orderyear,$ordermonth,false))."'"; - else if ($orderyear > 0 && ! empty($orderday)) - $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $ordermonth, $orderday, $orderyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $ordermonth, $orderday, $orderyear))."'"; + if ($search_orderyear > 0 && empty($search_orderday)) + $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($search_orderyear,$search_ordermonth,false))."' AND '".$db->idate(dol_get_last_day($search_orderyear,$search_ordermonth,false))."'"; + else if ($search_orderyear > 0 && ! empty($search_orderday)) + $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_ordermonth, $search_orderday, $search_orderyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_ordermonth, $search_orderday, $search_orderyear))."'"; else - $sql.= " AND date_format(c.date_commande, '%m') = '".$ordermonth."'"; + $sql.= " AND date_format(c.date_commande, '%m') = '".$search_ordermonth."'"; } -else if ($orderyear > 0) +else if ($search_orderyear > 0) { - $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($orderyear,1,false))."' AND '".$db->idate(dol_get_last_day($orderyear,12,false))."'"; + $sql.= " AND c.date_commande BETWEEN '".$db->idate(dol_get_first_day($search_orderyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_orderyear,12,false))."'"; } -if ($deliverymonth > 0) +if ($search_deliverymonth > 0) { - if ($deliveryyear > 0 && empty($deliveryday)) - $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,$deliverymonth,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,$deliverymonth,false))."'"; - else if ($deliveryyear > 0 && ! empty($deliveryday)) - $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $deliverymonth, $deliveryday, $deliveryyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $deliverymonth, $deliveryday, $deliveryyear))."'"; + if ($search_deliveryyear > 0 && empty($search_deliveryday)) + $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($search_deliveryyear,$search_deliverymonth,false))."' AND '".$db->idate(dol_get_last_day($search_deliveryyear,$search_deliverymonth,false))."'"; + else if ($search_deliveryyear > 0 && ! empty($search_deliveryday)) + $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $search_deliverymonth, $search_deliveryday, $search_deliveryyear))."' AND '".$db->idate(dol_mktime(23, 59, 59, $search_deliverymonth, $search_deliveryday, $search_deliveryyear))."'"; else - $sql.= " AND date_format(c.date_livraison, '%m') = '".$deliverymonth."'"; + $sql.= " AND date_format(c.date_livraison, '%m') = '".$search_deliverymonth."'"; } -else if ($deliveryyear > 0) +else if ($search_deliveryyear > 0) { - $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($deliveryyear,1,false))."' AND '".$db->idate(dol_get_last_day($deliveryyear,12,false))."'"; + $sql.= " AND c.date_livraison BETWEEN '".$db->idate(dol_get_first_day($search_deliveryyear,1,false))."' AND '".$db->idate(dol_get_last_day($search_deliveryyear,12,false))."'"; } if ($search_town) $sql.= natural_search('s.town', $search_town); if ($search_zip) $sql.= natural_search("s.zip",$search_zip); @@ -596,21 +596,21 @@ if ($resql) $title.=' - '.$langs->trans('StatusOrderValidated').', '.(empty($conf->expedition->enabled)?'':$langs->trans("StatusOrderSent").', ').$langs->trans('StatusOrderToBill'); $num = $db->num_rows($resql); - + $arrayofselected=is_array($toselect)?$toselect:array(); - + $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; if ($sall) $param.='&sall='.$sall; if ($socid > 0) $param.='&socid='.$socid; if ($viewstatut != '') $param.='&viewstatut='.$viewstatut; - if ($orderday) $param.='&orderday='.$orderday; - if ($ordermonth) $param.='&ordermonth='.$ordermonth; - if ($orderyear) $param.='&orderyear='.$orderyear; - if ($deliveryday) $param.='&deliveryday='.$deliveryday; - if ($deliverymonth) $param.='&deliverymonth='.$deliverymonth; - if ($deliveryyear) $param.='&deliveryyear='.$deliveryyear; + if ($search_orderday) $param.='&search_orderday='.$search_orderday; + if ($search_ordermonth) $param.='&search_ordermonth='.$search_ordermonth; + if ($search_orderyear) $param.='&search_orderyear='.$search_orderyear; + if ($search_deliveryday) $param.='&search_deliveryday='.$search_deliveryday; + if ($search_deliverymonth) $param.='&search_deliverymonth='.$search_deliverymonth; + if ($search_deliveryyear) $param.='&search_deliveryyear='.$search_deliveryyear; if ($search_ref) $param.='&search_ref='.$search_ref; if ($search_company) $param.='&search_company='.$search_company; if ($search_ref_customer) $param.='&search_ref_customer='.$search_ref_customer; @@ -629,7 +629,7 @@ if ($resql) $tmpkey=preg_replace('/search_options_/','',$key); if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } - + // List of mass actions available $arrayofmassactions = array( 'presend'=>$langs->trans("SendByMail"), @@ -653,12 +653,12 @@ if ($resql) print ''; print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit); - + // TODO Move this into an invluce if ($massaction == 'presend') { $langs->load("mails"); - + if (! GETPOST('cancel')) { $objecttmp=new Commande($db); @@ -677,14 +677,14 @@ if ($resql) } } } - + print ''; - + dol_fiche_head(null, '', ''); - + $topicmail="SendOrderRef"; $modelmail="order_send"; - + // Cree l'objet formulaire mail include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); @@ -737,23 +737,23 @@ if ($resql) $formmail->substit['__REFCLIENT__']='__REFCLIENT__'; // We want to keep the tag $formmail->substit['__PERSONALIZED__']=''; $formmail->substit['__CONTACTCIVNAME__']=''; - + // Tableau des parametres complementaires du post $formmail->param['action']=$action; $formmail->param['models']=$modelmail; $formmail->param['models_id']=GETPOST('modelmailselected','int'); $formmail->param['id']=join(',',$arrayofselected); //$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; - + print $formmail->get_form(); - + dol_fiche_end(); } elseif ($massaction == 'createbills') { //var_dump($_REQUEST); print ''; - + print ''; print ''; print ''; print ''; print '
'; @@ -780,7 +780,7 @@ if ($resql) print '
'; - + print '
'; print '
'; print ' '; @@ -788,13 +788,13 @@ if ($resql) print '
'; print '
'; } - + if ($sall) { foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); } - + $moreforfilter=''; // If the user can view prospects other than his' @@ -803,7 +803,7 @@ if ($resql) $langs->load("commercial"); $moreforfilter.='
'; $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': '; - $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300'); + $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200'); $moreforfilter.='
'; } // If the user can view other users @@ -811,7 +811,7 @@ if ($resql) { $moreforfilter.='
'; $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; - $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); + $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); $moreforfilter.='
'; } // If the user can view prospects other than his' @@ -821,14 +821,14 @@ if ($resql) $moreforfilter.='
'; $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': '; $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); - $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1); + $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1); $moreforfilter.='
'; } $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; else $moreforfilter = $hookmanager->resPrint; - + if (! empty($moreforfilter)) { print '
'; @@ -839,27 +839,27 @@ if ($resql) $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); - + print '
'; print ''."\n"; print ''; // Ref - if (! empty($arrayfields['c.ref']['checked'])) + if (! empty($arrayfields['c.ref']['checked'])) { print ''; } // Ref customer - if (! empty($arrayfields['c.ref_client']['checked'])) + if (! empty($arrayfields['c.ref_client']['checked'])) { print ''; } // Thirpdarty - if (! empty($arrayfields['s.nom']['checked'])) + if (! empty($arrayfields['s.nom']['checked'])) { print ''; } - if (! empty($arrayfields['c.date_delivery']['checked'])) + if (! empty($arrayfields['c.date_delivery']['checked'])) { print ''; } if (! empty($arrayfields['c.total_ht']['checked'])) @@ -972,10 +972,10 @@ if ($resql) { print ''; - + print "\n"; // Fields title @@ -1014,12 +1014,14 @@ if ($resql) // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach($extrafields->attribute_label as $key => $val) + foreach($extrafields->attribute_label as $key => $val) { - if (! empty($arrayfields["ef.".$key]['checked'])) + if (! empty($arrayfields["ef.".$key]['checked'])) { $align=$extrafields->getAlignFlag($key); - print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + $sortonfield = "ef.".$key; + if (! empty($extrafields->attribute_computed[$key])) $sortonfield=''; + print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); } } } @@ -1033,20 +1035,20 @@ if ($resql) if (! empty($arrayfields['c.facture']['checked'])) print_liste_field_titre($arrayfields['c.facture']['label'],$_SERVER["PHP_SELF"],'c.facture','',$param,'align="center"',$sortfield,$sortorder,''); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch '); print ''."\n"; - + $total=0; $subtotal=0; $productstat_cache=array(); - + $generic_commande = new Commande($db); $generic_product = new Product($db); - + $i=0; $totalarray=array(); while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); - + print ''; $notshippable=0; @@ -1054,7 +1056,7 @@ if ($resql) $text_info=''; $text_warning=''; $nbprod=0; - + // Ref if (! empty($arrayfields['c.ref']['checked'])) { @@ -1070,12 +1072,12 @@ if ($resql) $generic_commande->total_ttc = $obj->total_ttc; $generic_commande->lines=array(); $generic_commande->getLinesArray(); - + print '
'; print ''; print ''; print ''; print ''; print ''; @@ -894,17 +894,17 @@ if ($resql) if (! empty($arrayfields['c.date_commande']['checked'])) { print ''; - if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; - print ''; - $formother->select_year($orderyear?$orderyear:-1,'orderyear',1, 20, 5); + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + print ''; + $formother->select_year($search_orderyear?$search_orderyear:-1,'search_orderyear',1, 20, 5); print ''; - if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; - print ''; - $formother->select_year($deliveryyear?$deliveryyear:-1,'deliveryyear',1, 20, 5); + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + print ''; + $formother->select_year($search_deliveryyear?$search_deliveryyear:-1,'search_deliveryyear',1, 20, 5); print ''; $liststatus=array( - Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"), - Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"), - Commande::STATUS_ACCEPTED=>$langs->trans("StatusOrderSentShort"), - Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"), + Commande::STATUS_DRAFT=>$langs->trans("StatusOrderDraftShort"), + Commande::STATUS_VALIDATED=>$langs->trans("StatusOrderValidated"), + Commande::STATUS_ACCEPTED=>$langs->trans("StatusOrderSentShort"), + Commande::STATUS_CLOSED=>$langs->trans("StatusOrderDelivered"), Commande::STATUS_CANCELED=>$langs->trans("StatusOrderCanceledShort") ); print $form->selectarray('viewstatut', $liststatus, $viewstatut, -4); @@ -993,7 +993,7 @@ if ($resql) $searchpicto=$form->showFilterButtons(); print $searchpicto; print '
'; print ''; - + // Show shippable Icon (create subloop, so may be slow) if ($conf->stock->enabled) { @@ -1083,7 +1085,7 @@ if ($resql) if (($obj->fk_statut > 0) && ($obj->fk_statut < 3)) { $numlines = count($generic_commande->lines); // Loop on each line of order - for ($lig=0; $lig < $numlines; $lig++) + for ($lig=0; $lig < $numlines; $lig++) { if ($generic_commande->lines[$lig]->product_type == 0 && $generic_commande->lines[$lig]->fk_product > 0) // If line is a product and not a service { @@ -1107,8 +1109,8 @@ if ($resql) $text_info .= ' - '.$langs->trans("Stock").': '.$generic_product->stock_reel; $text_info .= ' - '.$langs->trans("VirtualStock").': '.$generic_product->stock_theorique; $text_info .= '
'; - - if ($generic_commande->lines[$lig]->qty > $generic_product->stock_reel) + + if ($generic_commande->lines[$lig]->qty > $generic_product->stock_reel) { $notshippable++; } @@ -1168,7 +1170,7 @@ if ($resql) $text_info = $langs->trans('NonShippable').'
'.$text_info; } } - + print ''; } - + // Warning late icon and note print ''; - + print ''; print '
'; - print $generic_commande->getNomUrl(1,($viewstatut != 2?0:$obj->fk_statut)); + print $generic_commande->getNomUrl(1, ($viewstatut != 2?0:$obj->fk_statut), 0, 0, 0, 1); print ''; if ($nbprod) { @@ -1179,7 +1181,7 @@ if ($resql) } print ''; if ($generic_commande->hasDelay()) { @@ -1192,7 +1194,7 @@ if ($resql) print ''; } print ''; $filename=dol_sanitizeFileName($obj->ref); $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref); @@ -1200,11 +1202,11 @@ if ($resql) print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir); print '
'; - + print ''; if (! $i) $totalarray['nbfield']++; } - + // Ref customer if (! empty($arrayfields['c.ref_client']['checked'])) { @@ -1222,7 +1224,7 @@ if ($resql) { print ''; print $companystatic->getNomUrl(1,'customer'); - + // If module invoices enabled and user with invoice creation permissions if (! empty($conf->facture->enabled) && ! empty($conf->global->ORDER_BILLING_ALL_CUSTOMER)) { @@ -1278,7 +1280,7 @@ if ($resql) print ''; if (! $i) $totalarray['nbfield']++; } - + // Order date if (! empty($arrayfields['c.date_commande']['checked'])) { @@ -1319,7 +1321,7 @@ if ($resql) if (! $i) $totalarray['totalttcfield']=$totalarray['nbfield']; $totalarray['totalttc'] += $obj->total_ttc; } - + // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -1370,7 +1372,7 @@ if ($resql) print ''.yn($obj->billed).''; if (! $i) $totalarray['nbfield']++; } - + // Action column print ''; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined @@ -1381,9 +1383,9 @@ if ($resql) } print ''; if (! $i) $totalarray['nbfield']++; - + print "\n"; - + $total+=$obj->total_ht; $subtotal+=$obj->total_ht; $i++; @@ -1416,14 +1418,14 @@ if ($resql) } $db->free($resql); - + $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql); $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - + print ''."\n"; print '
'; - + print ''."\n"; if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) @@ -1433,18 +1435,18 @@ if ($resql) */ $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; $urlsource.=str_replace('&','&',$param); - + $filedir=$diroutputmassaction; $genallowed=$user->rights->commande->lire; $delallowed=$user->rights->commande->supprimer; - + print $formfile->showdocuments('massfilesarea_orders','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); } else { print '
'.$langs->trans("ShowTempMassFilesArea").''; } - + } else { diff --git a/htdocs/commande/note.php b/htdocs/commande/note.php index 79475c75917..0d42cc69611 100644 --- a/htdocs/commande/note.php +++ b/htdocs/commande/note.php @@ -72,16 +72,16 @@ $form = new Form($db); if ($id > 0 || ! empty($ref)) { $object->fetch_thirdparty(); - + $head = commande_prepare_head($object); - + dol_fiche_head($head, 'note', $langs->trans("CustomerOrder"), -1, 'order'); // Order card - - $linkback = '' . $langs->trans("BackToList") . ''; - - + + $linkback = '' . $langs->trans("BackToList") . ''; + + $morehtmlref='
'; // Ref customer $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1); @@ -122,20 +122,20 @@ if ($id > 0 || ! empty($ref)) } } $morehtmlref.='
'; - - + + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref); - - + + print '
'; print '
'; - - + + $cssclass="titlefield"; include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; print '
'; - + dol_fiche_end(); } diff --git a/htdocs/commande/orderstoinvoice.php b/htdocs/commande/orderstoinvoice.php index b05b6658ca7..fa9f810b036 100644 --- a/htdocs/commande/orderstoinvoice.php +++ b/htdocs/commande/orderstoinvoice.php @@ -89,7 +89,7 @@ if ($action == 'create') } } -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; $hookmanager=new HookManager($db); $hookmanager->initHooks(array('orderstoinvoice')); @@ -411,17 +411,17 @@ if ($action == 'create' && !$error) print ''; // Ref - print ''; + print ''; // Third party - print ''; print ''."\n"; // Type - print ''; // Payment term - print ''; // Payment mode - print ''; // Project @@ -451,7 +451,7 @@ if ($action == 'create' && !$error) $formproject=new FormProjets($db); $langs->load('projects'); - print ''; } @@ -469,9 +469,9 @@ if ($action == 'create' && !$error) } // Other attributes - $parameters=array('objectsrc' => $objectsrc, 'idsrc' => $listoforders, 'colspan' => ' colspan="3"'); + $parameters=array('objectsrc' => $objectsrc, 'idsrc' => $listoforders); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { $object=new Facture($db); @@ -489,8 +489,8 @@ if ($action == 'create' && !$error) // Public note print ''; print ''; - print ''; } @@ -549,7 +549,7 @@ if (($action != 'create' && $action != 'add') || ($action == 'create' && $error) $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s'; $sql.= ', '.MAIN_DB_PREFIX.'commande as c'; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= ' WHERE c.entity IN ('.getEntity('commande', 1).')'; + $sql.= ' WHERE c.entity IN ('.getEntity('commande').')'; $sql.= ' AND c.fk_soc = s.rowid'; // Show orders with status validated, shipping started and delivered (well any order we can bill) @@ -622,7 +622,7 @@ if (($action != 'create' && $action != 'add') || ($action == 'create' && $error) print ''; - + //DATE ORDER print ''; - + //ALL/NONE print ''; print ''; print ''; print ''; @@ -334,7 +334,7 @@ foreach ($data as $val) print ''; } - + print ''; print ''; print ''; diff --git a/htdocs/compta/bank/annuel.php b/htdocs/compta/bank/annuel.php index cb10fd8c3c7..eb14db2d3ac 100644 --- a/htdocs/compta/bank/annuel.php +++ b/htdocs/compta/bank/annuel.php @@ -90,7 +90,7 @@ $sql.= ", date_format(b.dateo,'%Y-%m') as dm"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; +$sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.amount >= 0"; if (! empty($id)) $sql .= " AND b.fk_account IN (".$db->escape($id).")"; @@ -118,7 +118,7 @@ $sql.= ", date_format(b.dateo,'%Y-%m') as dm"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; +$sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.amount <= 0"; if (! empty($id)) $sql .= " AND b.fk_account IN (".$db->escape($id).")"; @@ -250,7 +250,7 @@ $sql = "SELECT SUM(b.amount) as total"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; +$sql.= " AND ba.entity IN (".getEntity('bank_account').")"; if (! empty($id)) $sql.= " AND b.fk_account IN (".$db->escape($id).")"; @@ -290,7 +290,7 @@ else $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; if ($id && $_GET["option"]!='all') $sql.= " AND b.fk_account IN (".$id.")"; $resql = $db->query($sql); @@ -321,7 +321,7 @@ else $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.datev >= '".($year-$annee)."-01-01 00:00:00'"; $sql.= " AND b.datev <= '".($year-$annee)."-12-31 23:59:59'"; $sql.= " AND b.amount > 0"; @@ -410,7 +410,7 @@ else $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.datev >= '".($year-$annee)."-01-01 00:00:00'"; $sql.= " AND b.datev <= '".($year-$annee)."-12-31 23:59:59'"; $sql.= " AND b.amount < 0"; diff --git a/htdocs/compta/bank/bankentries.php b/htdocs/compta/bank/bankentries.php index f98c48b1aba..2bc2242abc4 100644 --- a/htdocs/compta/bank/bankentries.php +++ b/htdocs/compta/bank/bankentries.php @@ -103,12 +103,12 @@ $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); $pageplusone = GETPOST("pageplusone",'int'); if ($pageplusone) $page = $pageplusone - 1; -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder='ASC'; -if (! $sortfield) $sortfield='b.datev'; +if (! $sortfield) $sortfield='b.datev, b.dateo, b.rowid'; $mode_balance_ok=false; //if (($sortfield == 'b.datev' || $sortfield == 'b.datev, b.dateo, b.rowid')) // TODO Manage balance when account not selected @@ -131,7 +131,7 @@ if ($id > 0 || ! empty($ref)) $contextpage='banktransactionlist'.(empty($object->ref)?'':'-'.$object->id); //var_dump($contextpage); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('banktransactionlist', $contextpage)); $extrafields = new ExtraFields($db); @@ -407,7 +407,7 @@ if ($id > 0 || ! empty($ref)) dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', '', 1); dol_fiche_end(); - + /* * Buttons actions */ @@ -436,6 +436,7 @@ if ($id > 0 || ! empty($ref)) print ''.$langs->trans("Conciliate").''; } } + print ''; } } @@ -463,7 +464,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_url as bu ON bu.fk_bank = b.rowid AND type = 'company'"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON bu.url_id = s.rowid"; $sql.= " WHERE b.fk_account = ba.rowid"; -$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; +$sql.= " AND ba.entity IN (".getEntity('bank_account').")"; if ($account > 0) $sql.=" AND b.fk_account = ".$account; // Search period criteria if (dol_strlen($search_dt_start)>0) $sql .= " AND b.dateo >= '" . $db->idate($search_dt_start) . "'"; @@ -521,10 +522,10 @@ if (($id > 0 || ! empty($ref)) && ((string) $page == '')) $offset = $limit * $page; if ($page < 0) $page = 0; } -if ($page >= $nbtotalofpages) +if ($page >= $nbtotalofpages) { // If we made a search and result has low page than the page number we were on - $page = ($nbtotalofpages -1); + $page = ($nbtotalofpages -1); $offset = $limit * $page; if ($page < 0) $page = 0; } @@ -598,7 +599,7 @@ if ($resql) print ''; print ' '.$langs->trans("or").' '; print ''; - + // Show last bank statements $nbmax=15; // We accept to show last 15 receipts (so we can have more than one year) $liste=""; @@ -636,6 +637,7 @@ if ($resql) // print '
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('Ref').''.$langs->trans('Draft').'
'.$langs->trans('Customer').''; + print '
'.$langs->trans('Customer').''; print $soc->getNomUrl(1); print ''; print '
'.$langs->trans('Type').''; + print '
'.$langs->trans('Type').''; print ''."\n"; // Standard invoice @@ -434,15 +434,15 @@ if ($action == 'create' && !$error) print '
'; // Date invoice - print '
'.$langs->trans('Date').''; + print '
'.$langs->trans('Date').''; $html->select_date('','','','','',"add",1,1); print '
'.$langs->trans('PaymentConditionsShort').''; + print '
'.$langs->trans('PaymentConditionsShort').''; $html->select_conditions_paiements(isset($_POST['cond_reglement_id'])?$_POST['cond_reglement_id']:$cond_reglement_id,'cond_reglement_id'); print '
'.$langs->trans('PaymentMode').''; + print '
'.$langs->trans('PaymentMode').''; $html->select_types_paiements(isset($_POST['mode_reglement_id'])?$_POST['mode_reglement_id']:$mode_reglement_id,'mode_reglement_id'); print '
'.$langs->trans('Project').''; + print '
'.$langs->trans('Project').''; $formproject->select_projects($soc->id, $projectid, 'projectid'); print '
'.$langs->trans('NotePublic').''; - print '
'; print ''; print ''; print $period; @@ -637,7 +637,7 @@ if (($action != 'create' && $action != 'add') || ($action == 'create' && $error) print ''; print ''; print ''; if ($conf->use_javascript_ajax) print ''.$langs->trans("All").' / '.$langs->trans("None").''; @@ -653,7 +653,7 @@ if (($action != 'create' && $action != 'add') || ($action == 'create' && $error) while ($i < $num) { $objp = $db->fetch_object($resql); - + print '
'; diff --git a/htdocs/commande/stats/index.php b/htdocs/commande/stats/index.php index 8967e22a160..ed9f8906804 100644 --- a/htdocs/commande/stats/index.php +++ b/htdocs/commande/stats/index.php @@ -76,7 +76,7 @@ if ($mode == 'customer') if ($mode == 'supplier') { $title=$langs->trans("OrdersStatisticsSuppliers").' ('.$langs->trans("SentToSuppliers").")"; - $dir=$conf->fournisseur->dir_output.'/commande/temp'; + $dir=$conf->fournisseur->commande->dir_temp; } llxHeader('', $title); @@ -322,7 +322,7 @@ foreach ($data as $val) while (! empty($year) && $oldyear > $year+1) { // If we have empty year $oldyear--; - + print '
0?'&userid='.$userid:'').'">'.$oldyear.'0
0?'&userid='.$userid:'').'">'.$year.''.$val['nb'].'
'; } + /// ajax to adjust value date with plus and less picto print ' '; - + $desc = $form->textwithpicto($tmp.$langs->trans("InvoiceDeposit"), $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3); print '
'; print $desc; @@ -2356,7 +2356,7 @@ if ($action == 'create') print '' . $langs->trans('Value') . ':'; } print '
'; - + print '
'; } } @@ -2388,7 +2388,7 @@ if ($action == 'create') } // Replacement - if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) + if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT)) { print ''; print '
'; @@ -2435,7 +2435,7 @@ if ($action == 'create') if ($socid > 0) { // Credit note - if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) + if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) { print '
'; $tmp='textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3); print $desc; - + print '
'; print '    0 ? 'checked':'').' /> "; print '
    0 ? 'checked':'').' /> "; print '
'; - + print '
'; } } @@ -2492,7 +2492,7 @@ if ($action == 'create') print '
' . "\n"; } } - + // Template invoice print '
'; $tmp=' '; @@ -2589,9 +2589,9 @@ if ($action == 'create') } // Other attributes - $parameters = array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"'); - $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by - // hook + $parameters = array('objectsrc' => $objectsrc,'colspan' => ' colspan="2"', 'cols'=>2); + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields, 'edit'); } @@ -2729,9 +2729,9 @@ if ($action == 'create') if (!empty($conf->multicurrency->enabled)) { - print '' . $langs->trans('MulticurrencyTotalHT') . '' . price($objectsrc->multicurrency_total_ht) . ''; - print '' . $langs->trans('MulticurrencyTotalVAT') . '' . price($objectsrc->multicurrency_total_tva) . ""; - print '' . $langs->trans('MulticurrencyTotalTTC') . '' . price($objectsrc->multicurrency_total_ttc) . ""; + print '' . $langs->trans('MulticurrencyAmountHT') . '' . price($objectsrc->multicurrency_total_ht) . ''; + print '' . $langs->trans('MulticurrencyAmountVAT') . '' . price($objectsrc->multicurrency_total_tva) . ""; + print '' . $langs->trans('MulticurrencyAmountTTC') . '' . price($objectsrc->multicurrency_total_ttc) . ""; } } @@ -3426,7 +3426,7 @@ else if ($id > 0 || ! empty($ref)) print $object->situation_counter; print ''; - print ''; + print ''; $prevsits_total_amount = 0; foreach ($prevsits as $situation) { @@ -3434,9 +3434,9 @@ else if ($id > 0 || ! empty($ref)) } $prevsits_total_amount += $object->total_ht; - print price($prevsits_total_amount); - print ''; - print '' . $langs->trans('Currency' . $conf->currency) . ''; + print price($prevsits_total_amount, 0, $langs, 1, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency) ); + + print ''; // Previous situation(s) deduction(s) for ($i = 0; $i < $cprevsits; $i++) { @@ -3447,10 +3447,9 @@ else if ($id > 0 || ! empty($ref)) print $prevsits[$i]->situation_counter; print ''; - print ''; - print '- ' . price($prevsits[$i]->total_ht); - print ''; - print '' . $langs->trans('Currency' . $conf->currency) . ''; + print ''; + print '- ' . price($prevsits[$i]->total_ht, 0, $langs, 1, -1, -1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency) ); + print ''; } } } @@ -3488,21 +3487,21 @@ else if ($id > 0 || ! empty($ref)) print '
'; print '
'; print '
'; - + print ''; - + if (!empty($conf->multicurrency->enabled) && ($object->multicurrency_code != $conf->currency)) { // Multicurrency Amount HT print ''; print ''; print ''; - + // Multicurrency Amount VAT print ''; print ''; print ''; - + // Multicurrency Amount TTC print ''; print ''; @@ -3584,24 +3583,23 @@ else if ($id > 0 || ! empty($ref)) $nbrows += 5; if (! empty($conf->incoterm->enabled)) $nbrows += 1; - - if ($object->type == Facture::TYPE_SITUATION && ! empty($conf->global->INVOICE_USE_SITUATION)) + + if ($object->type == Facture::TYPE_SITUATION && ! empty($conf->global->INVOICE_USE_SITUATION)) { if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) - print '
' . fieldLabel('MulticurrencyAmountHT','multicurrency_total_ht') . '' . price($object->multicurrency_total_ht, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
' . fieldLabel('MulticurrencyAmountVAT','multicurrency_total_tva') . '' . price($object->multicurrency_total_tva, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
' . fieldLabel('MulticurrencyAmountTTC','multicurrency_total_ttc') . '' . price($object->multicurrency_total_ttc, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)) . '
'; - + print '
'; + if (count($object->tab_previous_situation_invoice) > 0) { // List of previous invoices print ''; print ''; print ''; - if (! empty($conf->banque->enabled)) - print ''; + if (! empty($conf->banque->enabled)) print ''; print ''; print ''; print ''; print ''; - + $total_prev_ht = $total_prev_ttc = 0; foreach ($object->tab_previous_situation_invoice as $prev_invoice) { $totalpaye = $prev_invoice->getSommePaiement(); @@ -3610,23 +3608,24 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; - if (! empty($conf->banque->enabled)) - print ''; + if (! empty($conf->banque->enabled)) print ''; print ''; print ''; print ''; print ''; - + } - + print ''; - print ''; + print ''; + print ''; + if (! empty($conf->banque->enabled)) print ''; print ''; print ''; print ''; print ''; } - + if (count($object->tab_next_situation_invoice) > 0) { // List of next invoices print ''; @@ -3637,9 +3636,9 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; - + $total_next_ht = $total_next_ttc = 0; - + foreach ($object->tab_next_situation_invoice as $next_invoice) { $totalpaye = $next_invoice->getSommePaiement(); $total_next_ht += $next_invoice->total_ht; @@ -3652,9 +3651,9 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; - + } - + print ''; print ''; if (! empty($conf->banque->enabled)) print ''; @@ -3664,7 +3663,7 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; } - + if (count($object->tab_previous_situation_invoice) > 0 || count($object->tab_next_situation_invoice) > 0) print '
' . $langs->trans('ListOfPreviousSituationInvoices') . '' . $langs->trans('AmountHT') . '' . $langs->trans('AmountTTC') . ' 
' . $prev_invoice->getNomUrl(1) . '' . price($prev_invoice->total_ht) . '' . price($prev_invoice->total_ttc) . '' . $prev_invoice->getLibStatut(3, $totalpaye) . '
' . price($total_prev_ht) . '' . price($total_prev_ttc) . ' 
' . $langs->trans('AmountTTC') . ' 
' . price($next_invoice->total_ttc) . '' . $next_invoice->getLibStatut(3, $totalpaye) . '
 
'; } @@ -3741,7 +3740,7 @@ else if ($id > 0 || ! empty($ref)) print ''; $i ++; } - } + } /*else { print '' . $langs->trans("None") . ''; }*/ @@ -3837,7 +3836,7 @@ else if ($id > 0 || ! empty($ref)) // Billed print '' . $langs->trans("Billed") . ' :' . price($object->total_ttc) . ' '; - + // Remainder to pay print ''; if ($resteapayeraffiche >= 0) @@ -3847,11 +3846,11 @@ else if ($id > 0 || ! empty($ref)) print ' :'; print '' . price($resteapayeraffiche) . ''; print ' '; - } + } else // Credit note { $cssforamountpaymentcomplete=''; - + // Total already paid back print ''; print $langs->trans('AlreadyPaidBack'); @@ -3909,14 +3908,14 @@ else if ($id > 0 || ! empty($ref)) { if ($object->situation_cycle_ref && $object->statut == 0) { print '
'; - + print '
'; print ''; print ''; print ''; - + print ''; - + print ''; if (!empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { @@ -3954,11 +3953,11 @@ else if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; - + print '
%
'; - + print '
'; - + print '
'; } } @@ -3969,14 +3968,14 @@ else if ($id > 0 || ! empty($ref)) '; - + if (! empty($conf->use_javascript_ajax) && $object->statut == 0) { include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } - + print '
'; print ''; - + // Show object lines if (! empty($object->lines)) $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1); @@ -4037,10 +4036,10 @@ else if ($id > 0 || ! empty($ref)) } } } - + $discount = new DiscountAbsolute($db); $result = $discount->fetch(0, $object->id); - + // Reopen a standard paid invoice if ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) || ($object->type == Facture::TYPE_CREDIT_NOTE && empty($discount->id)) @@ -4071,7 +4070,7 @@ else if ($id > 0 || ! empty($ref)) print '
' . $langs->trans('SendByMail') . '
'; } else { if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send) { - print ''; + print ''; } else print ''; } @@ -4097,7 +4096,7 @@ else if ($id > 0 || ! empty($ref)) //print ''.$langs->trans("MakeWithdrawRequest").''; } } - + // Create payment if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { if ($objectidnext) { @@ -4253,7 +4252,7 @@ else if ($id > 0 || ! empty($ref)) // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - + // Link for paypal payment if (! empty($conf->paypal->enabled) && $object->statut != 0) { include_once DOL_DOCUMENT_ROOT . '/paypal/lib/paypal.lib.php'; @@ -4328,6 +4327,7 @@ else if ($id > 0 || ! empty($ref)) $file = $fileparams['fullname']; } + print '
'; print '
'; print '
'; print load_fiche_titre($langs->trans($titreform)); diff --git a/htdocs/compta/facture/class/api_deprecated_invoice.class.php b/htdocs/compta/facture/class/api_deprecated_invoice.class.php index 36aa232de9e..360c065a5f2 100644 --- a/htdocs/compta/facture/class/api_deprecated_invoice.class.php +++ b/htdocs/compta/facture/class/api_deprecated_invoice.class.php @@ -120,7 +120,7 @@ class InvoiceApi extends DolibarrApi if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale - $sql.= ' WHERE s.entity IN ('.getEntity('facture', 1).')'; + $sql.= ' WHERE s.entity IN ('.getEntity('facture').')'; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socid) || $search_sale > 0) $sql.= " AND s.fk_soc = sc.fk_soc"; if ($socid) $sql.= " AND s.fk_soc = ".$socid; if ($search_sale > 0) $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index e2842df0530..55304136ed6 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -112,7 +112,7 @@ class Invoices extends DolibarrApi if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale - $sql.= ' WHERE t.entity IN ('.getEntity('facture', 1).')'; + $sql.= ' WHERE t.entity IN ('.getEntity('facture').')'; if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.fk_soc = sc.fk_soc"; if ($socids) $sql.= " AND t.fk_soc IN (".$socids.")"; diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 927be3fa25e..6bc88e47490 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -955,7 +955,7 @@ class FactureRec extends CommonInvoice $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; - $sql.= " WHERE entity IN (".getEntity('product', 1).")"; + $sql.= " WHERE entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); if ($resql) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index e46b5718d22..ce441ee213e 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -54,7 +54,7 @@ class Facture extends CommonInvoice public $fk_element = 'fk_facture'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe public $picto='bill'; - + /** * {@inheritdoc} */ @@ -243,7 +243,7 @@ class Facture extends CommonInvoice if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; $this->brouillon = 1; if (empty($this->entity)) $this->entity = $conf->entity; - + // Multicurrency (test on $this->multicurrency_tx because we sould take the default rate only if not using origin rate) if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code); else $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code); @@ -280,7 +280,7 @@ class Facture extends CommonInvoice if ($this->fac_rec > 0) { $this->fk_fac_rec_source = $this->fac_rec; - + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; $_facrec = new FactureRec($this->db); $result=$_facrec->fetch($this->fac_rec); @@ -288,7 +288,7 @@ class Facture extends CommonInvoice $this->socid = $_facrec->socid; // Invoice created on same thirdparty than template $this->entity = $_facrec->entity; // Invoice created in same entity than template - + // Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI $this->fk_project = GETPOST('projectid','int') > 0 ? GETPOST('projectid','int') : $_facrec->fk_project; $this->note_public = GETPOST('note_public') ? GETPOST('note_public') : $_facrec->note_public; @@ -301,7 +301,7 @@ class Facture extends CommonInvoice // Set here to have this defined for substitution into notes, should be recalculated after adding lines to get same result $this->total_ht = $_facrec->total_ht; $this->total_ttc = $_facrec->total_ttc; - + // Fields always coming from template $this->remise_absolue = $_facrec->remise_absolue; $this->remise_percent = $_facrec->remise_percent; @@ -360,9 +360,10 @@ class Facture extends CommonInvoice '__INVOICE_YEAR__' => dol_print_date($this->date, '%Y'), '__INVOICE_NEXT_YEAR__' => dol_print_date(dol_time_plus_duree($this->date, 1, 'y'), '%Y'), ); - + + $substitutionisok=true; complete_substitutions_array($substitutionarray, $outputlangs); - + $this->note_public=make_substitutions($this->note_public,$substitutionarray); $this->note_private=make_substitutions($this->note_private,$substitutionarray); } @@ -472,7 +473,7 @@ class Facture extends CommonInvoice } } } - + if (! $error && $this->id && ! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && ! empty($this->origin) && ! empty($this->origin_id)) // Get contact from origin object { $originforcontact = $this->origin; @@ -483,7 +484,7 @@ class Facture extends CommonInvoice $exp = new Expedition($this->db); $exp->fetch($this->origin_id); $exp->fetchObjectLinked(); - if (count($exp->linkedObjectsIds['commande']) > 0) + if (count($exp->linkedObjectsIds['commande']) > 0) { foreach ($exp->linkedObjectsIds['commande'] as $key => $value) { @@ -493,10 +494,10 @@ class Facture extends CommonInvoice } } } - + $sqlcontact = "SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; - + $resqlcontact = $this->db->query($sqlcontact); if ($resqlcontact) { @@ -521,9 +522,12 @@ class Facture extends CommonInvoice { $newinvoiceline=$this->lines[$i]; $newinvoiceline->fk_facture=$this->id; - $newinvoiceline->origin = $this->element; // TODO This seems not used. Here we but origin 'facture' but after - $newinvoiceline->origin_id = $this->lines[$i]->id; // we put an id of object ! - if ($result >= 0 && ($newinvoiceline->info_bits & 0x01) == 0) // We keep only lines with first bit = 0 + + // TODO This seems not used. Here we put origin 'facture' but after, we put an id of object ! + $newinvoiceline->origin = $this->element; + $newinvoiceline->origin_id = $this->lines[$i]->id; + + if ($result >= 0) { // Reset fk_parent_line for no child products and special product if (($newinvoiceline->product_type != 9 && empty($newinvoiceline->fk_parent_line)) || $newinvoiceline->product_type == 9) { @@ -555,12 +559,12 @@ class Facture extends CommonInvoice foreach ($this->lines as $i => $val) { $line = $this->lines[$i]; - + // Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array //if (! is_object($line)) $line=json_decode(json_encode($line), FALSE); // convert recursively array into object. if (! is_object($line)) $line = (object) $line; - - if (($line->info_bits & 0x01) == 0) // We keep only lines with first bit = 0 + + if ($result >= 0) { // Reset fk_parent_line for no child products and special product if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) { @@ -1060,7 +1064,7 @@ class Facture extends CommonInvoice if ($this->type == self::TYPE_CREDIT_NOTE) $picto.='a'; // Credit note if ($this->type == self::TYPE_DEPOSIT) $picto.='d'; // Deposit invoice $label=''; - + if ($user->rights->facture->lire) { $label = '' . $langs->trans("ShowInvoice") . ''; if (! empty($this->ref)) @@ -1079,7 +1083,7 @@ class Facture extends CommonInvoice if ($this->type == self::TYPE_SITUATION) $label=$langs->transnoentitiesnoconv("ShowInvoiceSituation").': '.$this->ref; if ($moretitle) $label.=' - '.$moretitle; } - + $linkclose=''; if (empty($notooltip) && $user->rights->facture->lire) { @@ -1113,7 +1117,7 @@ class Facture extends CommonInvoice $result.=''; } } - + return $result; } @@ -1321,7 +1325,7 @@ class Facture extends CommonInvoice $line->qty = $objp->qty; $line->subprice = $objp->subprice; - $line->vat_src_code = $objp->vat_src_code; + $line->vat_src_code = $objp->vat_src_code; $line->tva_tx = $objp->tva_tx; $line->localtax1_tx = $objp->localtax1_tx; $line->localtax2_tx = $objp->localtax2_tx; @@ -1574,7 +1578,7 @@ class Facture extends CommonInvoice $arraytmp=$formmargin->getMarginInfosArray($srcinvoice, false); $facligne->pa_ht = $arraytmp['pa_total']; } - + $facligne->total_ht = -$remise->amount_ht; $facligne->total_tva = -$remise->amount_tva; $facligne->total_ttc = -$remise->amount_ttc; @@ -1628,7 +1632,7 @@ class Facture extends CommonInvoice function set_ref_client($ref_client, $notrigger=0) { global $user; - + $error=0; $this->db->begin(); @@ -2457,7 +2461,7 @@ class Facture extends CommonInvoice if (! isset($situation_percent) || $situation_percent > 100 || (string) $situation_percent == '') $situation_percent = 100; $localtaxes_type=getLocalTaxesFromRate($txtva, 0, $this->thirdparty, $mysoc); - + // Clean vat code $vat_src_code=''; if (preg_match('/\((.*)\)/', $txtva, $reg)) @@ -2465,7 +2469,7 @@ class Facture extends CommonInvoice $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - + $remise_percent=price2num($remise_percent); $qty=price2num($qty); $pu_ht=price2num($pu_ht); @@ -2650,7 +2654,7 @@ class Facture extends CommonInvoice * @param double $pu_ht_devise Unit price in currency * @return int < 0 if KO, > 0 if OK */ - function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type= self::TYPE_STANDARD, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=0, $fk_unit = null, $pu_ht_devise = 0) + function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type= self::TYPE_STANDARD, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=100, $fk_unit = null, $pu_ht_devise = 0) { global $conf,$user; // Deprecation warning @@ -2770,14 +2774,14 @@ class Facture extends CommonInvoice $this->line->label = $label; $this->line->desc = $desc; $this->line->qty = ($this->type==self::TYPE_CREDIT_NOTE?abs($qty):$qty); // For credit note, quantity is always positive and unit price negative - + $this->line->vat_src_code = $vat_src_code; $this->line->tva_tx = $txtva; $this->line->localtax1_tx = $txlocaltax1; $this->line->localtax2_tx = $txlocaltax2; $this->line->localtax1_type = $localtaxes_type[0]; $this->line->localtax2_type = $localtaxes_type[2]; - + $this->line->remise_percent = $remise_percent; $this->line->subprice = ($this->type==2?-abs($pu_ht):$pu_ht); // For credit note, unit price always negative, always positive otherwise $this->line->date_start = $date_start; @@ -2896,7 +2900,7 @@ class Facture extends CommonInvoice function deleteline($rowid) { global $user; - + dol_syslog(get_class($this)."::deleteline rowid=".$rowid, LOG_DEBUG); if (! $this->brouillon) @@ -2922,13 +2926,13 @@ class Facture extends CommonInvoice } $line=new FactureLigne($this->db); - + $line->context = $this->context; // For triggers $result = $line->fetch($rowid); if (! ($result > 0)) dol_print_error($db, $line->error, $line->errors); - + if ($line->delete($user) > 0) { $result=$this->update_price(1); @@ -3756,7 +3760,7 @@ class Facture extends CommonInvoice $prodids = array(); $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; - $sql.= " WHERE entity IN (".getEntity('product', 1).")"; + $sql.= " WHERE entity IN (".getEntity('product').")"; $resql = $this->db->query($sql); if ($resql) { @@ -3964,7 +3968,7 @@ class Facture extends CommonInvoice function newCycle() { $sql = 'SELECT max(situation_cycle_ref) FROM ' . MAIN_DB_PREFIX . 'facture as f'; - $sql.= " WHERE f.entity in (".getEntity('facture').")"; + $sql.= " WHERE f.entity in (".getEntity('facture', 0).")"; $resql = $this->db->query($sql); if ($resql) { if ($resql->num_rows > 0) @@ -4292,7 +4296,7 @@ class FactureLigne extends CommonInvoiceLine $this->fk_unit = $objp->fk_unit; $this->fk_user_modif = $objp->fk_user_modif; $this->fk_user_author = $objp->fk_user_author; - + $this->situation_percent = $objp->situation_percent; $this->fk_prev_id = $objp->fk_prev_id; diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php index 2d2ff5cc073..b6c77207952 100644 --- a/htdocs/compta/facture/document.php +++ b/htdocs/compta/facture/document.php @@ -58,7 +58,7 @@ $result=restrictedArea($user,'facture',$id,''); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index cb43c05680b..22306e498f2 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -76,7 +76,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; if (! $sortorder) $sortorder='DESC'; if (! $sortfield) $sortfield='f.titre'; @@ -93,7 +93,7 @@ if (($id > 0 || $ref) && $action != 'create' && $action != 'add') } } -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('invoicereccard','globalcard')); $extrafields = new ExtraFields($db); @@ -545,8 +545,8 @@ if (empty($reshook)) { $outputlangs = $langs; $newlang = ''; - if (empty($newlang) && GETPOST('lang_id')) - $newlang = GETPOST('lang_id'); + if (empty($newlang) && GETPOST('lang_id','aZ09')) + $newlang = GETPOST('lang_id','aZ09'); if (empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) @@ -625,7 +625,7 @@ if (empty($reshook)) // Define output language $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); @@ -810,8 +810,8 @@ if (empty($reshook)) // Define output language $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) - $newlang = GETPOST('lang_id'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) + $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 1ab17765d8f..513c6854eb8 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -102,7 +102,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; if (! $sortorder && ! empty($conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER) && $search_status == 1) $sortorder=$conf->global->INVOICE_DEFAULT_UNPAYED_SORT_ORDER; if (! $sortorder) $sortorder='DESC'; @@ -110,7 +110,7 @@ if (! $sortfield) $sortfield='f.datef'; $pageprev = $page - 1; $pagenext = $page + 1; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $contextpage='invoicelist'; // Security check @@ -124,7 +124,7 @@ $object=new Facture($db); $now=dol_now(); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('invoicelist')); $extrafields = new ExtraFields($db); @@ -191,7 +191,7 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; // Do we click on purge search criteria ? -if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOST("button_removefilter.x")) // Both test are required to be compatible with all browsers +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOST("button_removefilter.x")) // All tests are required to be compatible with all browsers { $search_user=''; $search_sale=''; @@ -213,7 +213,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOS $search_state=""; $search_type=''; $search_country=''; - $search_type_thirdparty=''; + $search_type_thirdparty=''; $day=''; $year=''; $month=''; @@ -239,17 +239,17 @@ if (empty($reshook)) if ($massaction == 'withdrawrequest') { $langs->load("withdrawals"); - + if (!$user->rights->prelevement->bons->creer) { $error++; setEventMessages($langs->trans("NotEnoughPermissions"), null, 'errors'); } - else + else { //Checking error $error = 0; - + $arrayofselected=is_array($toselect)?$toselect:array(); $listofbills=array(); foreach($arrayofselected as $toselectid) @@ -274,7 +274,7 @@ if ($massaction == 'withdrawrequest') $error++; setEventMessages($objecttmp->ref.' '.$langs->trans("Draft"), $objecttmp->errors, 'errors'); } - + $rsql = "SELECT pfd.rowid, pfd.traite, pfd.date_demande as date_demande"; $rsql .= " , pfd.date_traite as date_traite"; $rsql .= " , pfd.amount"; @@ -291,7 +291,7 @@ if ($massaction == 'withdrawrequest') { $numprlv = $db->num_rows($result_sql); } - + if($numprlv>0){ $error++; setEventMessages($objecttmp->ref.' '.$langs->trans("RequestAlreadyDone"), $objecttmp->errors, 'errors'); @@ -300,7 +300,7 @@ if ($massaction == 'withdrawrequest') $error++; setEventMessages($objecttmp->ref.' '.$langs->trans("BadPaymentMethod"), $objecttmp->errors, 'errors'); } - + } } @@ -327,13 +327,13 @@ if ($massaction == 'withdrawrequest') if ($nbwithdrawrequestok > 0) { setEventMessages($langs->trans("WithdrawRequestsDone", $nbwithdrawrequestok), null, 'mesgs'); - } + } } } } - + /* * View @@ -350,7 +350,7 @@ llxHeader('',$langs->trans('CustomersInvoices'),'EN:Customers_Invoices|FR:Factur $sql = 'SELECT'; if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; -$sql.= ' f.rowid as facid, f.facnumber, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,'; +$sql.= ' f.rowid as id, f.facnumber as ref, f.ref_client, f.type, f.note_private, f.note_public, f.increment, f.fk_mode_reglement, f.total as total_ht, f.tva as total_vat, f.total_ttc,'; $sql.= ' f.localtax1 as total_localtax1, f.localtax2 as total_localtax2,'; $sql.= ' f.datef as df, f.date_lim_reglement as datelimite,'; $sql.= ' f.paye as paye, f.fk_statut,'; @@ -360,7 +360,7 @@ $sql.= " typent.code as typent_code,"; $sql.= " state.code_departement as state_code, state.nom as state_name"; // We need dynamount_payed to be able to sort on status (value is surely wrong because we can count several lines several times due to other left join or link with contacts. But what we need is just 0 or > 0) // TODO Better solution to be able to sort on already payed or remain to pay is to store amount_payed in a denormalized field. -if (! $sall) $sql.= ', SUM(pf.amount) as dynamount_payed'; +if (! $sall) $sql.= ', SUM(pf.amount) as dynamount_payed'; // Add fields from extrafields foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : ''); // Add fields from hooks @@ -384,7 +384,7 @@ if ($search_user > 0) $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql.= ' WHERE f.fk_soc = s.rowid'; -$sql.= ' AND f.entity IN ('.getEntity('facture', 1).')'; +$sql.= ' AND f.entity IN ('.getEntity('facture').')'; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category; if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; @@ -424,7 +424,7 @@ if ($search_company) $sql .= natural_search('s.nom', $search_company); if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1); if ($search_montant_vat != '') $sql.= natural_search('f.tva', $search_montant_vat, 1); if ($search_montant_localtax1 != '') $sql.= natural_search('f.localtax1', $search_montant_localtax1, 1); -if ($search_montant_localtax2 != '') $sql.= natural_search('f.localtax2', $search_montant_localtax2, 1); +if ($search_montant_localtax2 != '') $sql.= natural_search('f.localtax2', $search_montant_localtax2, 1); if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1); if ($search_status != '' && $search_status >= 0) { @@ -577,7 +577,7 @@ if ($resql) $langs->load("withdrawals"); $arrayofmassactions['withdrawrequest']=$langs->trans("MakeWithdrawRequest"); } - if ($user->rights->facture->supprimer) + if ($user->rights->facture->supprimer) { //if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) || empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) if (empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED)) @@ -608,8 +608,8 @@ if ($resql) if ($massaction == 'presend') { $langs->load("mails"); - - if (! GETPOST('cancel')) + + if (! GETPOST('cancel')) { $objecttmp=new Facture($db); $listofselectedid=array(); @@ -618,7 +618,7 @@ if ($resql) foreach($arrayofselected as $toselectid) { $result=$objecttmp->fetch($toselectid); - if ($result > 0) + if ($result > 0) { $listofselectedid[$toselectid]=$toselectid; $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid; @@ -629,10 +629,10 @@ if ($resql) } print ''; - + include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail = new FormMail($db); - + dol_fiche_head(null, '', ''); $topicmail="SendBillRef"; @@ -700,7 +700,7 @@ if ($resql) //$formmail->param['returnurl']=$_SERVER["PHP_SELF"].'?id='.$object->id; print $formmail->get_form(); - + dol_fiche_end(); } @@ -709,7 +709,7 @@ if ($resql) foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); } - + // If the user can view prospects other than his' $moreforfilter=''; if ($user->rights->societe->client->voir || $socid) @@ -717,7 +717,7 @@ if ($resql) $langs->load("commercial"); $moreforfilter.='
'; $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': '; - $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth300'); + $moreforfilter.=$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, 1, 'maxwidth200'); $moreforfilter.='
'; } // If the user can view prospects other than his' @@ -725,7 +725,7 @@ if ($resql) { $moreforfilter.='
'; $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; - $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); + $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); $moreforfilter.='
'; } // If the user can view prospects other than his' @@ -735,7 +735,7 @@ if ($resql) $moreforfilter.='
'; $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': '; $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); - $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1); + $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1); $moreforfilter.='
'; } $parameters=array(); @@ -753,7 +753,7 @@ if ($resql) $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); - + print '
'; print '
'."\n"; @@ -788,7 +788,7 @@ if ($resql) print ''; } // Date invoice - if (! empty($arrayfields['f.date']['checked'])) + if (! empty($arrayfields['f.date']['checked'])) { print ''; } // Date due - if (! empty($arrayfields['f.date_lim_reglement']['checked'])) + if (! empty($arrayfields['f.date_lim_reglement']['checked'])) { print ''; } // Thirpdarty - if (! empty($arrayfields['s.nom']['checked'])) + if (! empty($arrayfields['s.nom']['checked'])) { print ''; } @@ -842,7 +842,7 @@ if ($resql) print ''; } // Payment mode - if (! empty($arrayfields['f.fk_mode_reglement']['checked'])) + if (! empty($arrayfields['f.fk_mode_reglement']['checked'])) { print '\n"; - + print "\n"; + if ($num > 0) { $i=0; @@ -998,8 +1000,8 @@ if ($resql) $obj = $db->fetch_object($resql); $datelimit=$db->jdate($obj->datelimite); - $facturestatic->id=$obj->facid; - $facturestatic->ref=$obj->facnumber; + $facturestatic->id=$obj->id; + $facturestatic->ref=$obj->ref; $facturestatic->type=$obj->type; $facturestatic->statut=$obj->fk_statut; $facturestatic->date_lim_reglement=$db->jdate($obj->datelimite); @@ -1011,28 +1013,28 @@ if ($resql) $totaldeposits = $facturestatic->getSumDepositsUsed(); $totalpay = $paiement + $totalcreditnotes + $totaldeposits; $remaintopay = $obj->total_ttc - $totalpay; - + print ''; if (! empty($arrayfields['f.facnumber']['checked'])) { print '\n"; if (! $i) $totalarray['nbfield']++; } @@ -1089,7 +1091,7 @@ if ($resql) print ''; if (! $i) $totalarray['nbfield']++; } - + // Third party if (! empty($arrayfields['s.nom']['checked'])) { @@ -1256,18 +1258,18 @@ if ($resql) print ""; if (! $i) $totalarray['nbfield']++; } - + // Action column print '' ; if (! $i) $totalarray['nbfield']++; - + print "\n"; $i++; @@ -1303,31 +1305,31 @@ if ($resql) else print ''; } print ''; - + } } $db->free($resql); - + $parameters=array('arrayfields'=>$arrayfields, 'sql'=>$sql); $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - + print "
'; if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; @@ -797,7 +797,7 @@ if ($resql) print ''; if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; @@ -812,7 +812,7 @@ if ($resql) print ''; $form->select_types_paiements($search_paymentmode, 'search_paymentmode', '', 0, 0, 1, 10); @@ -975,7 +975,9 @@ if ($resql) if (! empty($arrayfields["ef.".$key]['checked'])) { $align=$extrafields->getAlignFlag($key); - print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + $sortonfield = "ef.".$key; + if (! empty($extrafields->attribute_computed[$key])) $sortonfield=''; + print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); } } } @@ -987,8 +989,8 @@ if ($resql) if (! empty($arrayfields['f.tms']['checked'])) print_liste_field_titre($arrayfields['f.tms']['label'],$_SERVER["PHP_SELF"],"f.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); if (! empty($arrayfields['f.fk_statut']['checked'])) print_liste_field_titre($arrayfields['f.fk_statut']['label'],$_SERVER["PHP_SELF"],"fk_statut,paye,type,dynamount_payed","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch '); - print "
'; print ''; - + print ''; - + print ''; print ''; print '
'; print $facturestatic->getNomUrl(1,'',200,0,'',0,1); print empty($obj->increment)?'':' ('.$obj->increment.')'; print ''; - $filename=dol_sanitizeFileName($obj->facnumber); - $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->facnumber); - $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->facid; + $filename=dol_sanitizeFileName($obj->ref); + $filedir=$conf->facture->dir_output . '/' . dol_sanitizeFileName($obj->ref); + $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->id; print $formfile->getDocumentsLink($facturestatic->element, $filename, $filedir); print '
'; - + print "
'; if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined { $selected=0; - if (in_array($obj->facid, $arrayofselected)) $selected=1; - print ''; + if (in_array($obj->id, $arrayofselected)) $selected=1; + print ''; } print '
\n"; print '
'; - + print "\n"; - + if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) { // Show list of available documents $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder; $urlsource.=str_replace('&','&',$param); - + $filedir=$diroutputmassaction; $genallowed=$user->rights->facture->lire; $delallowed=$user->rights->facture->lire; - + print $formfile->showdocuments('massfilesarea_invoices','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,''); } else diff --git a/htdocs/compta/localtax/card.php b/htdocs/compta/localtax/card.php index 1772b6861dd..317d3ae813d 100644 --- a/htdocs/compta/localtax/card.php +++ b/htdocs/compta/localtax/card.php @@ -44,7 +44,7 @@ $result = restrictedArea($user, 'tax', '', '', 'charges'); $localtax = new Localtax($db); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('localtaxvatcard','globalcard')); @@ -158,7 +158,7 @@ if ($id) if ($action == 'create') { print load_fiche_titre($langs->transcountry($lttype==2?"newLT2Payment":"newLT1Payment",$mysoc->country_code)); - + print '
'."\n"; print ''; print ''; @@ -193,15 +193,16 @@ if ($action == 'create') $form->select_types_paiements(GETPOST("paiementtype"), "paiementtype"); print "\n"; print ""; - + // Number print ''.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print ''."\n"; } // Other attributes - $parameters=array('colspan' => ' colspan="1"'); + $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; print ''; @@ -237,20 +238,20 @@ if ($id) print ''; print ""; - print ''; print ""; - print ''; - print ''; - print ''; + print ''; if (! empty($conf->banque->enabled)) { @@ -261,7 +262,7 @@ if ($id) print ''; print ''; - print ''; print ''; @@ -269,13 +270,14 @@ if ($id) } // Other attributes - $parameters=array('colspan' => ' colspan="3"'); + $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$vatpayment,$action); // Note that $action and $object may have been modified by hook - + print $hookmanager->resPrint; + print '
'.$langs->trans("Ref").''; + print ''.$langs->trans("Ref").''; print $vatpayment->ref; print '
'.$langs->trans("DatePayment").''; + print ''.$langs->trans("DatePayment").''; print dol_print_date($vatpayment->datep,'day'); print '
'.$langs->trans("DateValue").''; + print '
'.$langs->trans("DateValue").''; print dol_print_date($vatpayment->datev,'day'); print '
'.$langs->trans("Amount").''.price($vatpayment->amount).'
'.$langs->trans("Amount").''.price($vatpayment->amount).'
'.$langs->trans('BankTransactionLine').''; + print ''; print $bankline->getNomUrl(1,0,'showall'); print '
'; dol_fiche_end(); - + /* * Boutons d'actions diff --git a/htdocs/compta/paiement/avalider.php b/htdocs/compta/paiement/avalider.php index 1f00da90a8c..0fe627cf7ac 100644 --- a/htdocs/compta/paiement/avalider.php +++ b/htdocs/compta/paiement/avalider.php @@ -42,7 +42,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/compta/paiement/cheque/card.php b/htdocs/compta/paiement/cheque/card.php index eed3a79335c..b5767a6f0bc 100644 --- a/htdocs/compta/paiement/cheque/card.php +++ b/htdocs/compta/paiement/cheque/card.php @@ -416,7 +416,7 @@ if ($action == 'new') $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON (b.fk_account = ba.rowid)"; $sql.= " WHERE b.fk_type = 'CHQ'"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.fk_bordereau = 0"; $sql.= " AND b.amount > 0"; if ($filterdate) $sql.=" AND b.dateo = '".$db->idate($filterdate)."'"; @@ -656,7 +656,7 @@ else $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON (b.fk_account = ba.rowid)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement as p ON p.fk_bank = b.rowid"; - $sql.= " WHERE ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " WHERE ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.fk_type= 'CHQ'"; $sql.= " AND b.fk_bordereau = ".$object->id; $sql.= $db->order($sortfield, $sortorder); diff --git a/htdocs/compta/paiement/cheque/class/remisecheque.class.php b/htdocs/compta/paiement/cheque/class/remisecheque.class.php index 4889693857b..20afa14e0ca 100644 --- a/htdocs/compta/paiement/cheque/class/remisecheque.class.php +++ b/htdocs/compta/paiement/cheque/class/remisecheque.class.php @@ -496,7 +496,7 @@ class RemiseCheque extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.fk_type = 'CHQ'"; $sql.= " AND b.fk_bordereau = 0"; $sql.= " AND b.amount > 0"; diff --git a/htdocs/compta/paiement/cheque/index.php b/htdocs/compta/paiement/cheque/index.php index 97dc3c1674f..e9f887e37f4 100644 --- a/htdocs/compta/paiement/cheque/index.php +++ b/htdocs/compta/paiement/cheque/index.php @@ -56,7 +56,7 @@ $sql = "SELECT count(b.rowid)"; $sql.= " FROM ".MAIN_DB_PREFIX."bank as b"; $sql.= ", ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE ba.rowid = b.fk_account"; -$sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; +$sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " AND b.fk_type = 'CHQ'"; $sql.= " AND b.fk_bordereau = 0"; $sql.= " AND b.amount > 0"; diff --git a/htdocs/compta/paiement/cheque/list.php b/htdocs/compta/paiement/cheque/list.php index a4fac965e7a..aeed72d93d1 100644 --- a/htdocs/compta/paiement/cheque/list.php +++ b/htdocs/compta/paiement/cheque/list.php @@ -47,7 +47,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -139,24 +139,14 @@ if ($resql) print ''; print ''; print ''; - + print_barre_liste($langs->trans("MenuChequeDeposits"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_bank.png', '', '', $limit); - + $moreforfilter=''; - + print '
'; print ''."\n"; - print ''; - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"bc.ref","",$param,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Account"),$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("NbOfCheques"),$_SERVER["PHP_SELF"],"bc.nbcheque","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"bc.amount","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"bc.statut","",$param,'align="right"',$sortfield,$sortorder); - print_liste_field_titre(''); - print "\n"; - // Lignes des champs de filtre print ''; print ''; print "\n"; + print ''; + print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"bc.ref","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"dp","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Account"),$_SERVER["PHP_SELF"],"ba.label","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("NbOfCheques"),$_SERVER["PHP_SELF"],"bc.nbcheque","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"bc.amount","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"bc.statut","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre(''); + print "\n"; + if ($num > 0) { $var=true; while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); - + print ''; - + // Num ref cheque print ''; - + // Date print ''; // TODO Use date hour - + // Bank print ''; - + // Number of cheques print ''; - + // Amount print ''; - + // Statut print ''; - + print ''; - + print "\n"; $i++; } diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 03a7759e52c..f4e61380a9c 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -38,7 +38,7 @@ class Paiement extends CommonObject public $element='payment'; public $table_element='paiement'; public $picto = 'payment'; - + var $facid; var $datepaye; /** @@ -65,7 +65,7 @@ class Paiement extends CommonObject // fk_paiement dans llx_paiement_facture est le rowid du paiement var $fk_paiement; // Type of paiment - + /** * Constructor * @@ -153,14 +153,14 @@ class Paiement extends CommonObject $error = 0; $way = $this->getWay(); - + $now=dol_now(); - + // Clean parameters $totalamount = 0; $totalamount_converted = 0; $atleastonepaymentnotnull = 0; - + if ($way == 'dolibarr') { $amounts = &$this->amounts; @@ -171,22 +171,22 @@ class Paiement extends CommonObject $amounts = &$this->multicurrency_amounts; $amounts_to_update = &$this->amounts; } - + foreach ($amounts as $key => $value) // How payment is dispatch { $value_converted = Multicurrency::getAmountConversionFromInvoiceRate($key, $value, $way); $totalamount_converted += $value_converted; $amounts_to_update[$key] = price2num($value_converted, 'MT'); - + $newvalue = price2num($value,'MT'); $amounts[$key] = $newvalue; $totalamount += $newvalue; if (! empty($newvalue)) $atleastonepaymentnotnull++; } - + $totalamount = price2num($totalamount); $totalamount_converted = price2num($totalamount_converted); - + // Check parameters if (empty($totalamount) && empty($atleastonepaymentnotnull)) // We accept negative amounts for withdraw reject but not empty arrays { @@ -196,7 +196,7 @@ class Paiement extends CommonObject $this->db->begin(); - $ref = $this->getNextNumRef(''); + $this->ref = $this->getNextNumRef(''); if ($way == 'dolibarr') { @@ -210,8 +210,8 @@ class Paiement extends CommonObject } $sql = "INSERT INTO ".MAIN_DB_PREFIX."paiement (entity, ref, datec, datep, amount, multicurrency_amount, fk_paiement, num_paiement, note, fk_user_creat)"; - $sql.= " VALUES (".$conf->entity.", '".$ref."', '". $this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.")"; - + $sql.= " VALUES (".$conf->entity.", '".$this->ref."', '". $this->db->idate($now)."', '".$this->db->idate($this->datepaye)."', '".$total."', '".$mtotal."', ".$this->paiementid.", '".$this->num_paiement."', '".$this->db->escape($this->note)."', ".$user->id.")"; + dol_syslog(get_class($this)."::Create insert paiement", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) @@ -227,7 +227,7 @@ class Paiement extends CommonObject $amount = price2num($amount); $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'paiement_facture (fk_facture, fk_paiement, amount, multicurrency_amount)'; $sql .= ' VALUES ('.$facid.', '. $this->id.', \''.$amount.'\', \''.$this->multicurrency_amounts[$key].'\')'; - + dol_syslog(get_class($this).'::Create Amount line '.$key.' insert paiement_facture', LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) @@ -245,21 +245,27 @@ class Paiement extends CommonObject //var_dump($invoice->total_ttc.' - '.$paiement.' -'.$creditnotes.' - '.$deposits.' - '.$remaintopay);exit; - // If there is withdrawals request to do and not done yet, we wait before closing. + /* Why this ? We can remove i think. + // If there is withdrawals request to do and not done yet on the invoice the payment is on, we wait before closing. $mustwait=0; + $sqlrequest ="SELECT COUNT(rowid) FROM ".MAIN_DB_PREFIX."prelevement_facture_demande"; + $sqlrequest.="WHERE fk_facture = ".$invoice->id." AND traite = 0"; + ... + $listofpayments=$invoice->getListOfPayments(); foreach($listofpayments as $paym) { - // This payment might be this one or a previous one + // This payment on invoice $invoice might be the one we record or another one if ($paym['type']=='PRE') { if (! empty($conf->prelevement->enabled)) { - // FIXME Check if this invoice has a withdraw request // if not, $mustwait++; // This will disable automatic close on invoice to allow to process + } } } + */ //Invoice types that are eligible for changing status to paid $affected_types = array( @@ -272,14 +278,14 @@ class Paiement extends CommonObject if (!in_array($invoice->type, $affected_types)) dol_syslog("Invoice ".$facid." is not a standard, nor replacement invoice, nor credit note, nor deposit invoice, nor situation invoice. We do nothing more."); else if ($remaintopay) dol_syslog("Remain to pay for invoice ".$facid." not null. We do nothing more."); - else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more."); + //else if ($mustwait) dol_syslog("There is ".$mustwait." differed payment to process, we do nothing more."); else { // If invoice is a down payment, we also convert down payment to discount if ($invoice->type == Facture::TYPE_DEPOSIT) { $amount_ht = $amount_tva = $amount_ttc = array(); - + // Loop on each vat rate $i = 0; foreach ($invoice->lines as $line) @@ -292,20 +298,20 @@ class Paiement extends CommonObject $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) { @@ -313,14 +319,14 @@ class Paiement extends CommonObject break; } } - + if ($error) { setEventMessages($discount->error, $discount->errors, 'errors'); $error++; - } + } } - + // Set invoice to paid if (! $error) { @@ -520,13 +526,13 @@ class Paiement extends CommonObject $acc = new Account($this->db); $result=$acc->fetch($this->fk_account); - + $totalamount=$this->amount; if (empty($totalamount)) $totalamount=$this->total; // For backward compatibility - + // if dolibarr currency != bank currency then we received an amount in customer currency (currently I don't manage the case : my currency is USD, the customer currency is EUR and he paid me in GBP. Seems no sense for me) if (!empty($conf->multicurrency->enabled) && $conf->currency != $acc->currency_code) $totalamount=$this->multicurrency_amount; - + if ($mode == 'payment_supplier') $totalamount=-$totalamount; // Insert payment into llx_bank @@ -796,7 +802,7 @@ class Paiement extends CommonObject /** * Information sur l'objet - * + * * @param int $id id du paiement dont il faut afficher les infos * @return void */ @@ -962,13 +968,13 @@ class Paiement extends CommonObject /** * get the right way of payment - * + * * @return string 'dolibarr' if standard comportment or paid in dolibarr currency, 'customer' if payment received from multicurrency inputs */ function getWay() { global $conf; - + $way = 'dolibarr'; if (!empty($conf->multicurrency->enabled)) { @@ -981,10 +987,10 @@ class Paiement extends CommonObject } } } - + return $way; } - + /** * Initialise an instance with random values. * Used to build previews or test instances. diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index daf70556213..ec2bbc78fc6 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -61,14 +61,14 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortorder) $sortorder="DESC"; if (! $sortfield) $sortfield="p.rowid"; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('paymentlist')); $extrafields = new ExtraFields($db); diff --git a/htdocs/compta/paiement/rapport.php b/htdocs/compta/paiement/rapport.php index a185f0aba6e..3e6427f6ac2 100644 --- a/htdocs/compta/paiement/rapport.php +++ b/htdocs/compta/paiement/rapport.php @@ -56,10 +56,10 @@ if ($action == 'builddoc') $rap = new pdf_paiement($db); $outputlangs = $langs; - if (GETPOST('lang_id')) + if (GETPOST('lang_id','aZ09')) { $outputlangs = new Translate("",$conf); - $outputlangs->setDefaultLang(GETPOST('lang_id')); + $outputlangs->setDefaultLang(GETPOST('lang_id','aZ09')); } // We save charset_output to restore it because write_file can change it if needed for diff --git a/htdocs/compta/prelevement/bons.php b/htdocs/compta/prelevement/bons.php index 302e1e9e59c..9a5585c2513 100644 --- a/htdocs/compta/prelevement/bons.php +++ b/htdocs/compta/prelevement/bons.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2008 Laurent Destailleur + * Copyright (C) 2005-2017 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2010-2012 Juanjo Menent * @@ -41,7 +41,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -107,33 +107,32 @@ if ($result) print ''; print ''; print ''; - + print_barre_liste($langs->trans("WithdrawalsReceipts"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_generic', 0, '', '', $limit); $moreforfilter=''; - + print '
'; print '
'; @@ -181,15 +171,25 @@ if ($resql) print '
'; $checkdepositstatic->id=$objp->rowid; @@ -197,29 +197,29 @@ if ($resql) $checkdepositstatic->statut=$objp->statut; print $checkdepositstatic->getNomUrl(1); print ''.dol_print_date($db->jdate($objp->dp),'day').''; if ($objp->bid) print ''.img_object($langs->trans("ShowAccount"),'account').' '.$objp->label.''; else print ' '; print ''.$objp->nbcheque.''.price($objp->amount).''; print $checkdepositstatic->LibStatut($objp->statut,5); print '
'."\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print_liste_field_titre($langs->trans("WithdrawalsReceipts"),$_SERVER["PHP_SELF"],"p.ref",'','','class="liste_titre"'); print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"p.datec","","",'class="liste_titre" align="center"'); print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"","","",'align="center"'); print "\n"; - print ''; - print ''; - print ''; - print ''; - print ''; - - while ($i < min($num,$limit)) { - $obj = $db->fetch_object($result); + $obj = $db->fetch_object($result); print '
 '; + $searchpicto=$form->showFilterButtons(); + print $searchpicto; + print '
 '; - $searchpicto=$form->showFilterAndCheckAddButtons(0); - print $searchpicto; - print '
'; @@ -151,9 +150,9 @@ if ($result) } print "
"; print '
'; - + print '
'; - + $db->free($result); } else diff --git a/htdocs/compta/prelevement/card.php b/htdocs/compta/prelevement/card.php index 62e57813886..1a0435862ea 100644 --- a/htdocs/compta/prelevement/card.php +++ b/htdocs/compta/prelevement/card.php @@ -48,11 +48,11 @@ $id = GETPOST('id','int'); $socid = GETPOST('socid','int'); -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 90ba6a22431..ab04278ea84 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -252,7 +252,7 @@ class BonPrelevement extends CommonObject function getErrorString($error) { global $langs; - + $errors = array(); $errors[1027] = $langs->trans("DateInvalid"); @@ -813,7 +813,7 @@ class BonPrelevement extends CommonObject dol_syslog(__METHOD__."::Read invoices error ".$this->db->error(), LOG_ERR); } } - + if (! $error) { require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php'; @@ -834,7 +834,7 @@ class BonPrelevement extends CommonObject { $bac = new CompanyBankAccount($this->db); $bac->fetch(0,$soc->id); - + if ($bac->verif() >= 1) //if (true) { @@ -867,7 +867,7 @@ class BonPrelevement extends CommonObject } $ok=0; - + // Withdraw invoices in factures_prev array $out=count($factures_prev)." invoices will be withdrawn."; //print $out."\n"; @@ -920,7 +920,7 @@ class BonPrelevement extends CommonObject $dir=$conf->prelevement->dir_output.'/receipts'; if (! is_dir($dir)) dol_mkdir($dir); - + $this->filename = $dir.'/'.$ref.'.xml'; // Create withdraw receipt in database @@ -1028,7 +1028,7 @@ class BonPrelevement extends CommonObject $this->emetteur_bic = $account->bic; $this->emetteur_ics = $conf->global->PRELEVEMENT_ICS; // Ex: PRELEVEMENT_ICS = "FR78ZZZ123456"; - + $this->raison_sociale = $account->proprio; } @@ -1272,16 +1272,6 @@ class BonPrelevement extends CommonObject * section Debiteur (sepa Debiteurs bloc lines) */ - /*$tmp_invoices = array(); - - $sql = "SELECT f.facnumber as fac FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl, ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."prelevement_facture as pf, ".MAIN_DB_PREFIX."societe as soc, ".MAIN_DB_PREFIX."c_country as p, ".MAIN_DB_PREFIX."societe_rib as rib WHERE pl.fk_prelevement_bons = ".$this->id." AND pl.rowid = pf.fk_prelevement_lignes AND pf.fk_facture = f.rowid AND soc.fk_pays = p.rowid AND soc.rowid = f.fk_soc AND rib.fk_soc = f.fk_soc AND rib.default_rib = 1"; - $resql=$this->db->query($sql); - if ($resql) { - while ($objfac = $this->db->fetch_object($resql)) { - $tmp_invoices[] = $objfac->fac; - } - }*/ - $sql = "SELECT soc.code_client as code, soc.address, soc.zip, soc.town, c.code as country_code,"; $sql.= " pl.client_nom as nom, pl.code_banque as cb, pl.code_guichet as cg, pl.number as cc, pl.amount as somme,"; $sql.= " f.facnumber as fac, pf.fk_facture as idfac, rib.datec, rib.iban_prefix as iban, rib.bic as bic, rib.rowid as drum"; @@ -1365,35 +1355,6 @@ class BonPrelevement extends CommonObject fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$CrLf); fputs($this->file, ''.$CrLf); - - /*$sql = "SELECT pl.amount"; - $sql.= " FROM"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_lignes as pl,"; - $sql.= " ".MAIN_DB_PREFIX."facture as f,"; - $sql.= " ".MAIN_DB_PREFIX."prelevement_facture as pf"; - $sql.= " WHERE pl.fk_prelevement_bons = ".$this->id; - $sql.= " AND pl.rowid = pf.fk_prelevement_lignes"; - $sql.= " AND pf.fk_facture = f.rowid"; - - //Lines - $i = 0; - $resql=$this->db->query($sql); - if ($resql) - { - $num = $this->db->num_rows($resql); - - while ($i < $num) - { - $obj = $this->db->fetch_object($resql); - $this->total = $this->total + $obj->amount; - $i++; - } - } - else - { - $result = -2; - }*/ - } // Build file for Other Countries with unknow format @@ -1580,11 +1541,11 @@ class BonPrelevement extends CommonObject $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; - $XML_DEBITOR .=' '.strtoupper(dol_string_unaccent($row_nom)).''.$CrLf; + $XML_DEBITOR .=' '.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$row_country_code.''.$CrLf; - $XML_DEBITOR .=' '.dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""))).''.$CrLf; - $XML_DEBITOR .=' '.dol_string_unaccent($row_zip.' '.$row_town).''.$CrLf; + $XML_DEBITOR .=' '.dolEscapeXML(dol_trunc(dol_string_unaccent(strtr($row_address, array(CHR(13) => ", ", CHR(10) => ""))),70,'right','UTF-8',true)).''.$CrLf; + $XML_DEBITOR .=' '.dolEscapeXML(dol_string_unaccent($row_zip.' '.$row_town)).''.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; $XML_DEBITOR .=' '.$CrLf; @@ -1679,7 +1640,7 @@ class BonPrelevement extends CommonObject * @return string String with SEPA Sender */ function EnregEmetteurSEPA($configuration, $ladate, $nombre, $total, $CrLf='\n') - { + { // SEPA INITIALISATION global $conf; @@ -1698,12 +1659,12 @@ class BonPrelevement extends CommonObject $this->emetteur_number_key = $account->cle_rib; $this->emetteur_iban = $account->iban; $this->emetteur_bic = $account->bic; - + $this->emetteur_ics = $conf->global->PRELEVEMENT_ICS; // Ex: PRELEVEMENT_ICS = "FR78ZZZ123456"; - + $this->raison_sociale = $account->proprio; } - + // Récupération info demandeur $sql = "SELECT rowid, ref"; $sql.= " FROM"; diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php index 5d77a9b9771..0834b3500a7 100644 --- a/htdocs/compta/prelevement/create.php +++ b/htdocs/compta/prelevement/create.php @@ -94,9 +94,7 @@ llxHeader('', $langs->trans("NewStandingOrder")); if (prelevement_check_config() < 0) { $langs->load("errors"); - print '
'; - print $langs->trans("ErrorModuleSetupNotComplete"); - print '
'; + setEventMessages($langs->trans("ErrorModuleSetupNotComplete"), null, 'errors'); } /*$h=0; @@ -148,7 +146,7 @@ if ($nb) } else { - print ''.$langs->trans("CreateAll")."\n"; + print 'transnoentitiesnoconv("StandingOrders"))).'">'.$langs->trans("CreateAll")."\n"; } print "
\n"; @@ -194,7 +192,7 @@ if ($resql) while ($i < $num && $i < 20) { $obj = $db->fetch_object($resql); - + print ''; print ''; $invoicestatic->id=$obj->rowid; @@ -268,7 +266,7 @@ if ($result) while ($i < min($num,$limit)) { $obj = $db->fetch_object($result); - + print ''; diff --git a/htdocs/compta/prelevement/demandes.php b/htdocs/compta/prelevement/demandes.php index e619b28e994..dd453bd7f4e 100644 --- a/htdocs/compta/prelevement/demandes.php +++ b/htdocs/compta/prelevement/demandes.php @@ -45,11 +45,11 @@ $page = GETPOST('page','int'); $sortorder = GETPOST('sortorder','alpha'); $sortfield = GETPOST('sortfield','alpha'); -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/compta/prelevement/factures.php b/htdocs/compta/prelevement/factures.php index 6136ee48499..996a1aabe88 100644 --- a/htdocs/compta/prelevement/factures.php +++ b/htdocs/compta/prelevement/factures.php @@ -44,11 +44,11 @@ if ($user->societe_id > 0) accessforbidden(); $prev_id = GETPOST('id','int'); $socid = GETPOST('socid','int'); -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/compta/prelevement/index.php b/htdocs/compta/prelevement/index.php index 32257a71a0f..271ce4da7fe 100644 --- a/htdocs/compta/prelevement/index.php +++ b/htdocs/compta/prelevement/index.php @@ -129,7 +129,7 @@ if ($resql) $invoicestatic->type=$obj->type; $alreadypayed=$invoicestatic->getSommePaiement(); - + print ''; print $invoicestatic->getNomUrl(1,'withdraw'); print ''; @@ -157,7 +157,7 @@ if ($resql) } else { - print ''.$langs->trans("NoInvoiceToWithdraw").''; + print ''.$langs->trans("NoInvoiceToWithdraw", $langs->transnoentitiesnoconv("StandingOrders")).''; } print "
"; } @@ -197,7 +197,7 @@ if ($result) while ($i < min($num,$limit)) { $obj = $db->fetch_object($result); - + print ''; diff --git a/htdocs/compta/prelevement/ligne.php b/htdocs/compta/prelevement/ligne.php index 933c23b0e7e..20ac3d18082 100644 --- a/htdocs/compta/prelevement/ligne.php +++ b/htdocs/compta/prelevement/ligne.php @@ -251,7 +251,7 @@ if ($id) - if ($page == -1) { $page = 0 ; } + if ($page == -1 || $page == null) { $page = 0 ; } $offset = $conf->liste_limit * $page ; $pageprev = $page - 1; diff --git a/htdocs/compta/prelevement/list.php b/htdocs/compta/prelevement/list.php index 9b1f1ff461e..208be88aeae 100644 --- a/htdocs/compta/prelevement/list.php +++ b/htdocs/compta/prelevement/list.php @@ -44,7 +44,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -130,10 +130,24 @@ if ($result) print '
'; $moreforfilter=''; - + print '
'; print ''."\n"; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print_liste_field_titre($langs->trans("Line"),$_SERVER["PHP_SELF"]); print_liste_field_titre($langs->trans("WithdrawalsReceipts"),$_SERVER["PHP_SELF"],"p.ref"); @@ -144,24 +158,10 @@ if ($result) print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"pl.amount","","",'align="right"'); print_liste_field_titre(''); print "\n"; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; while ($i < min($num,$limit)) { - $obj = $db->fetch_object($result); + $obj = $db->fetch_object($result); print '
   '; + $searchpicto=$form->showFilterButtons(); + print $searchpicto; + print '
   '; - $searchpicto=$form->showFilterAndCheckAddButtons(0); - print $searchpicto; - print '
'; @@ -199,9 +199,9 @@ if ($result) } print "
"; print '
'; - + print '
'; - + $db->free($result); } else diff --git a/htdocs/compta/recap-compta.php b/htdocs/compta/recap-compta.php index a383f841a47..c3231ecccdd 100644 --- a/htdocs/compta/recap-compta.php +++ b/htdocs/compta/recap-compta.php @@ -40,11 +40,11 @@ $object = new Societe($db); if ($id > 0) $object->fetch($id); // Load variable for pagination -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 1b5a232b812..62ee285d70b 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -52,11 +52,11 @@ if ($user->societe_id > 0) $socid = $user->societe_id; if (! empty($conf->comptabilite->enabled)) $result=restrictedArea($user,'compta','','','resultat'); if (! empty($conf->accounting->enabled)) $result=restrictedArea($user,'accounting','','','comptarapport'); -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -263,7 +263,7 @@ if ($modecompta != 'CREANCES-DETTES') $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; if (! empty($date_start) && ! empty($date_end)) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " GROUP BY name, idp"; @@ -654,7 +654,7 @@ if (! empty($conf->expensereport->enabled)) $sql = "SELECT p.rowid, p.ref, u.rowid as userid, u.firstname, u.lastname, date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; - $sql.= " WHERE p.entity = ".getEntity('expensereport',1); + $sql.= " WHERE p.entity = ".getEntity('expensereport'); $sql.= " AND p.fk_statut>=5"; $column='p.date_valid'; @@ -664,7 +664,7 @@ if (! empty($conf->expensereport->enabled)) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; - $sql.= " WHERE p.entity = ".getEntity('expensereport',1); + $sql.= " WHERE p.entity = ".getEntity('expensereport'); $sql.= " AND p.fk_statut>=5"; $column='pe.datep'; @@ -745,7 +745,7 @@ if (! empty($conf->don->enabled)) $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; - $sql.= " WHERE p.entity = ".getEntity('donation',1); + $sql.= " WHERE p.entity = ".getEntity('donation'); $sql.= " AND fk_statut >= 2"; } if (! empty($date_start) && ! empty($date_end)) diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index fe64bb7b999..6043a7cbec5 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -164,7 +164,7 @@ if ($modecompta != 'CREANCES-DETTES') $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " GROUP BY dm"; $sql.= " ORDER BY dm"; @@ -492,14 +492,14 @@ if (! empty($conf->salaries->enabled)) } else { $column = 'p.datep'; } - + $subtotal_ht = 0; $subtotal_ttc = 0; $sql = "SELECT p.label as nom, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as p"; $sql.= " WHERE p.entity = ".$conf->entity; $sql.= " GROUP BY p.label, dm"; - + dol_syslog("get social salaries payments"); $result=$db->query($sql); if ($result) @@ -512,13 +512,13 @@ if (! empty($conf->salaries->enabled)) while ($i < $num) { $obj = $db->fetch_object($result); - + if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; $decaiss[$obj->dm] += $obj->amount; - + if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; $decaiss_ttc[$obj->dm] += $obj->amount; - + $i++; } } @@ -536,7 +536,7 @@ if (! empty($conf->expensereport->enabled)) $sql = "SELECT date_format(date_valid,'%Y-%m') as dm, sum(p.total_ht) as amount_ht,sum(p.total_ttc) as amount_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; - $sql.= " WHERE p.entity = ".getEntity('expensereport',1); + $sql.= " WHERE p.entity = ".getEntity('expensereport'); $sql.= " AND p.fk_statut>=5"; $column='p.date_valid'; @@ -547,7 +547,7 @@ if (! empty($conf->expensereport->enabled)) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=p.fk_user_author"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_expensereport as pe ON pe.fk_expensereport = p.rowid"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; - $sql.= " WHERE p.entity = ".getEntity('expensereport',1); + $sql.= " WHERE p.entity = ".getEntity('expensereport'); $sql.= " AND p.fk_statut>=5"; $column='pe.datep'; @@ -568,7 +568,7 @@ if (! empty($conf->expensereport->enabled)) { if (! isset($decaiss[$obj->dm])) $decaiss[$obj->dm]=0; $decaiss[$obj->dm] += $obj->amount_ht; - + if (! isset($decaiss_ttc[$obj->dm])) $decaiss_ttc[$obj->dm]=0; $decaiss_ttc[$obj->dm] += $obj->amount_ttc; @@ -588,7 +588,7 @@ if (! empty($conf->don->enabled)) { $subtotal_ht = 0; $subtotal_ttc = 0; - + if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT p.societe as nom, p.firstname, p.lastname, date_format(p.datedon,'%Y-%m') as dm, sum(p.amount) as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; @@ -600,7 +600,7 @@ if (! empty($conf->don->enabled)) $sql.= " FROM ".MAIN_DB_PREFIX."don as p"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."payment_donation as pe ON pe.fk_donation = p.rowid"; $sql.= " INNER JOIN ".MAIN_DB_PREFIX."c_paiement as c ON pe.fk_typepayment = c.id"; - $sql.= " WHERE p.entity = ".getEntity('donation',1); + $sql.= " WHERE p.entity = ".getEntity('donation'); $sql.= " AND fk_statut >= 2"; } $sql.= " GROUP BY p.societe, p.firstname, p.lastname, dm"; @@ -617,13 +617,13 @@ if (! empty($conf->don->enabled)) while ($i < $num) { $obj = $db->fetch_object($result); - + if (! isset($encaiss[$obj->dm])) $encaiss[$obj->dm]=0; $encaiss[$obj->dm] += $obj->amount; - + if (! isset($encaiss_ttc[$obj->dm])) $encaiss_ttc[$obj->dm]=0; $encaiss_ttc[$obj->dm] += $obj->amount; - + $i++; } } @@ -671,7 +671,7 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) { $mois_modulo = $mois; if($mois>12) {$mois_modulo = $mois-12;} - + print ''; print "".dol_print_date(dol_mktime(12,0,0,$mois_modulo,1,$annee),"%B").""; for ($annee = $year_start ; $annee <= $year_end ; $annee++) @@ -680,7 +680,7 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) if($mois>12) {$annee_decalage=$annee+1;} $case = strftime("%Y-%m",dol_mktime(12,0,0,$mois_modulo,1,$annee_decalage)); - print ' '; + print ' '; if (isset($decaiss_ttc[$case]) && $decaiss_ttc[$case] != 0) { print ''.price(price2num($decaiss_ttc[$case],'MT')).''; @@ -689,7 +689,7 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++) } print ""; - print ' '; + print ' '; //if (isset($encaiss_ttc[$case]) && $encaiss_ttc[$case] != 0) if (isset($encaiss_ttc[$case])) { diff --git a/htdocs/compta/salaries/card.php b/htdocs/compta/salaries/card.php index 68f59d03cfa..45bde4bcd32 100644 --- a/htdocs/compta/salaries/card.php +++ b/htdocs/compta/salaries/card.php @@ -1,8 +1,8 @@ +/* Copyright (C) 2011-2017 Alexandre Spangaro * Copyright (C) 2014 Laurent Destailleur * Copyright (C) 2015 Jean-François Ferry - * Copyright (C) 2015 Charlie BENKE + * Copyright (C) 2015 Charlie BENKE * * 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 @@ -19,9 +19,9 @@ */ /** - * \file htdocs/compta/salaries/card.php - * \ingroup salaries - * \brief Page of salaries payments + * \file htdocs/compta/salaries/card.php + * \ingroup salaries + * \brief Page of salaries payments */ require '../../main.inc.php'; @@ -48,7 +48,7 @@ $result = restrictedArea($user, 'salaries', '', '', ''); $object = new PaymentSalary($db); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('salarycard','globalcard')); @@ -72,7 +72,7 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) $datesp=dol_mktime(12,0,0, $_POST["datespmonth"], $_POST["datespday"], $_POST["datespyear"]); $dateep=dol_mktime(12,0,0, $_POST["dateepmonth"], $_POST["dateepday"], $_POST["dateepyear"]); if (empty($datev)) $datev=$datep; - + $object->accountid=GETPOST("accountid") > 0 ? GETPOST("accountid","int") : 0; $object->fk_user=GETPOST("fk_user") > 0 ? GETPOST("fk_user","int") : 0; $object->datev=$datev; @@ -116,7 +116,7 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("BankAccount")), null, 'errors'); $error++; } - + if (! $error) { $db->begin(); @@ -229,7 +229,7 @@ if ($action == 'create') print load_fiche_titre($langs->trans("NewSalaryPayment"),'', 'title_accountancy.png'); dol_fiche_head('', ''); - + print ''; // Date payment @@ -300,8 +300,9 @@ if ($action == 'create') } // Other attributes - $parameters=array('colspan' => ' colspan="1"'); + $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; print '
'; @@ -340,35 +341,35 @@ if ($id) $morehtmlref.=$langs->trans('Employee') . ' : ' . $userstatic->getNomUrl(1); $morehtmlref.='
'; - dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', ''); + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', ''); - print '
'; + print '
'; print '
'; - print ''; + print '
'; // Label print ''; print ""; - print ''; - print ''; print ""; - print ''; - print ''; - print ''; + print ''; if (! empty($conf->banque->enabled)) { @@ -379,7 +380,7 @@ if ($id) print ''; print ''; - print ''; print ''; @@ -387,8 +388,9 @@ if ($id) } // Other attributes - $parameters=array('colspan' => ' colspan="3"'); + $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; print '
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("DateStartPeriod").''; + print ''.$langs->trans("DateStartPeriod").''; print dol_print_date($object->datesp,'day'); print '
'.$langs->trans("DateEndPeriod").''; + print '
'.$langs->trans("DateEndPeriod").''; print dol_print_date($object->dateep,'day'); print '
'.$langs->trans("DatePayment").''; + print ''.$langs->trans("DatePayment").''; print dol_print_date($object->datep,'day'); print '
'.$langs->trans("DateValue").''; + print '
'.$langs->trans("DateValue").''; print dol_print_date($object->datev,'day'); print '
'.$langs->trans("Amount").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Amount").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans('BankTransactionLine').''; + print ''; print $bankline->getNomUrl(1,0,'showall'); print '
'; @@ -396,7 +398,7 @@ if ($id) dol_fiche_end(); - + /* * Action buttons */ @@ -405,7 +407,7 @@ if ($id) { if (! empty($user->rights->salaries->delete)) { - print ''.$langs->trans("Delete").''; + print ''.$langs->trans("Delete").''; } else { diff --git a/htdocs/compta/salaries/document.php b/htdocs/compta/salaries/document.php index 03a69a764cf..03cef9c07e8 100644 --- a/htdocs/compta/salaries/document.php +++ b/htdocs/compta/salaries/document.php @@ -55,7 +55,7 @@ $result = restrictedArea($user, 'salaries', $id, ''); $sortfield = GETPOST('sortfield','alpha'); $sortorder = GETPOST('sortorder','alpha'); $page = GETPOST('page','int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -91,7 +91,7 @@ if ($object->id) $head=salaries_prepare_head($object); - dol_fiche_head($head, 'documents', $langs->trans("SalaryPayment"), 0, 'payment'); + dol_fiche_head($head, 'documents', $langs->trans("SalaryPayment"), -1, 'payment'); // Construit liste des fichiers $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); diff --git a/htdocs/compta/salaries/index.php b/htdocs/compta/salaries/index.php index dc95b06bc52..baf99182993 100644 --- a/htdocs/compta/salaries/index.php +++ b/htdocs/compta/salaries/index.php @@ -48,7 +48,7 @@ $search_account = GETPOST('search_account','int'); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -73,6 +73,12 @@ else $typeid=$_REQUEST['typeid']; } + + +/* + * Actions + */ + if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers { $search_ref=""; @@ -82,6 +88,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $typeid=""; } + /* * View */ @@ -151,23 +158,23 @@ if ($result) print ''; print ''; print ''; - + print_barre_liste($langs->trans("SalariesPayments"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $totalnboflines, 'title_accountancy.png', 0, '', '', $limit); - + print '
'; print ''."\n"; print ''; // Ref print ''; // Employee print ''; // Label - print ''; + print ''; // Date print ''; // Type @@ -182,13 +189,13 @@ if ($result) print ''; } // Amount - print ''; + print ''; print ''; - + print ''; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"s.rowid","",$param,"",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Employee"),$_SERVER["PHP_SELF"],"u.rowid","",$param,"",$sortfield,$sortorder); @@ -199,13 +206,13 @@ if ($result) print_liste_field_titre($langs->trans("PayedByThisPayment"),$_SERVER["PHP_SELF"],"s.amount","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); print "\n"; - + print "\n"; while ($i < min($num,$limit)) { $obj = $db->fetch_object($result); - + print ''; $userstatic->id=$obj->uid; @@ -238,11 +245,11 @@ if ($result) $accountstatic->id=$obj->bid; $accountstatic->ref=$obj->bref; $accountstatic->number=$obj->bnumber; - + if (! empty($conf->accounting->enabled)) { $accountstatic->account_number=$obj->account_number; - + $accountingjournal = new AccountingJournal($db); $accountingjournal->fetch($obj->fk_accountancy_journal); diff --git a/htdocs/compta/salaries/info.php b/htdocs/compta/salaries/info.php index 05dc7835b68..ddb79845748 100644 --- a/htdocs/compta/salaries/info.php +++ b/htdocs/compta/salaries/info.php @@ -55,7 +55,7 @@ $object->info($id); $head = salaries_prepare_head($object); -dol_fiche_head($head, 'info', $langs->trans("SalaryPayment"), 0, 'payment'); +dol_fiche_head($head, 'info', $langs->trans("SalaryPayment"), -1, 'payment'); $linkback = ''.$langs->trans("BackToList").''; @@ -72,6 +72,8 @@ dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, print '
'; print '
'; +print '
'; + print '
'; - print ''; + print ''; print ''; - print ''; + print ''; print ' '; $searchpicto=$form->showFilterAndCheckAddButtons(0); print $searchpicto; print '
'; dol_print_object_info($object); print '
'; diff --git a/htdocs/compta/sociales/index.php b/htdocs/compta/sociales/index.php index 194c3f38d99..2ab2cb1c172 100644 --- a/htdocs/compta/sociales/index.php +++ b/htdocs/compta/sociales/index.php @@ -46,7 +46,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/compta/sociales/payments.php b/htdocs/compta/sociales/payments.php index ae7240c204a..6c88305f72e 100644 --- a/htdocs/compta/sociales/payments.php +++ b/htdocs/compta/sociales/payments.php @@ -49,7 +49,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -413,7 +413,7 @@ if (! empty($conf->salaries->enabled) && $user->rights->salaries->read) $sql = "SELECT s.rowid, s.amount, s.label, s.datep as datep, s.datev as datev, s.datesp, s.dateep, s.salary, u.salary as current_salary"; $sql.= " FROM ".MAIN_DB_PREFIX."payment_salary as s, ".MAIN_DB_PREFIX."user as u"; - $sql.= " WHERE s.entity IN (".getEntity('user',1).")"; + $sql.= " WHERE s.entity IN (".getEntity('user').")"; $sql.= " AND u.rowid = s.fk_user"; if ($year > 0) { diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php index fff94c898c2..ad9a8fbd346 100644 --- a/htdocs/compta/stats/cabyuser.php +++ b/htdocs/compta/stats/cabyuser.php @@ -237,7 +237,7 @@ if ($modecompta != 'CREANCES-DETTES') { $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; if ($date_start && $date_end) { $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php index 548809f4317..fdba026ac6f 100644 --- a/htdocs/compta/stats/casoc.php +++ b/htdocs/compta/stats/casoc.php @@ -201,7 +201,7 @@ if ($modecompta == 'CREANCES-DETTES') { $sql = "SELECT DISTINCT s.rowid as socid, s.nom as name, s.zip, s.town, s.fk_pays,"; $sql.= " sum(f.total) as amount, sum(f.total_ttc) as amount_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."societe as s"; - if ($selected_cat === -2) // Without any category + if ($selected_cat === -2) // Without any category { $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; } @@ -219,7 +219,7 @@ if ($modecompta == 'CREANCES-DETTES') { if ($date_start && $date_end) { $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } - if ($selected_cat === -2) // Without any category + if ($selected_cat === -2) // Without any category { $sql.=" AND cs.fk_soc is null"; } @@ -239,7 +239,7 @@ if ($modecompta == 'CREANCES-DETTES') { $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf"; $sql.= ", ".MAIN_DB_PREFIX."paiement as p"; $sql.= ", ".MAIN_DB_PREFIX."societe as s"; - if ($selected_cat === -2) // Without any category + if ($selected_cat === -2) // Without any category { $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; } @@ -253,7 +253,7 @@ if ($modecompta == 'CREANCES-DETTES') { if ($date_start && $date_end) { $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } - if ($selected_cat === -2) // Without any category + if ($selected_cat === -2) // Without any category { $sql.=" AND cs.fk_soc is null"; } @@ -306,7 +306,7 @@ if ($modecompta != 'CREANCES-DETTES') { $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; $sql.= " GROUP BY socid, name"; $sql.= " ORDER BY name"; @@ -360,7 +360,28 @@ print ''; print ''; print ''; print ''; - // Array titles + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print $form->select_country($search_country, 'search_country'); +//print ''; +print ''; +print ' '; +print ' '; +print ' '; +print ' '; +print ''; + +// Array titles print ""; print_liste_field_titre( $langs->trans("Company"), @@ -442,27 +463,6 @@ print_liste_field_titre( ); print "\n"; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print ''; -print $form->select_country($search_country, 'search_country'); -//print ''; -print ''; -print ' '; -print ' '; -print ' '; -print ' '; -print ''; - -$var=true; if (count($amount)) { $arrayforsort=$name; @@ -517,7 +517,7 @@ if (count($amount)) { } foreach($arrayforsort as $key=>$value) { - + print ''; // Third party diff --git a/htdocs/compta/stats/index.php b/htdocs/compta/stats/index.php index 2bb9a7d50a0..19c106a44dc 100644 --- a/htdocs/compta/stats/index.php +++ b/htdocs/compta/stats/index.php @@ -151,7 +151,7 @@ if ($modecompta != 'CREANCES-DETTES') $sql.= " WHERE pf.rowid IS NULL"; $sql.= " AND p.fk_bank = b.rowid"; $sql.= " AND b.fk_account = ba.rowid"; - $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; + $sql.= " AND ba.entity IN (".getEntity('bank_account').")"; $sql.= " GROUP BY dm"; $sql.= " ORDER BY dm"; diff --git a/htdocs/compta/tva/card.php b/htdocs/compta/tva/card.php index cb80f49e790..6f7e250f4f5 100644 --- a/htdocs/compta/tva/card.php +++ b/htdocs/compta/tva/card.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003 Rodolphe Quiedeville * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005-2013 Regis Houssin - * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2015-2017 Alexandre Spangaro * * 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 @@ -45,7 +45,7 @@ $result = restrictedArea($user, 'tax', '', '', 'charges'); $object = new Tva($db); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('taxvatcard','globalcard')); @@ -65,7 +65,7 @@ if ($action == 'setdatev' && $user->rights->tax->charges->creer) $object->datev=dol_mktime(12,0,0,$_POST['datevmonth'],$_POST['datevday'],$_POST['datevyear']); $result=$object->update($user); if ($result < 0) dol_print_error($db,$object->error); - + $action=''; } @@ -81,7 +81,7 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) $object->num_payment=GETPOST("num_payment"); $object->datev=$datev; $object->datep=$datep; - + $amount = price2num(GETPOST("amount")); if ($refund == 1) { $amount= -$amount; @@ -89,7 +89,7 @@ if ($action == 'add' && $_POST["cancel"] <> $langs->trans("Cancel")) $object->amount= $amount; $object->label=GETPOST("label"); $object->note=GETPOST("note"); - + if (empty($object->datev)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateValue")), null, 'errors'); @@ -207,11 +207,11 @@ if ($action == 'create') print '$(document).ready(function () { $("#radiopayment").click(function() { $("#label").val($(this).data("label")); - + }); $("#radiorefund").click(function() { $("#label").val($(this).data("label")); - + }); });'; print ''."\n"; @@ -282,8 +282,9 @@ if ($action == 'create') print ''."\n"; // Other attributes - $parameters=array('colspan' => ' colspan="1"'); + $parameters=array(); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; print ''; @@ -305,16 +306,17 @@ if ($id) dol_fiche_head($head, 'card', $langs->trans("VATPayment"), 0, 'payment'); + $linkback = ''.$langs->trans("BackToList").''; + + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', ''); + + print '
'; + print '
'; print ''; - print ""; - print ''; - // Label - print ''; + print ''; print ""; print ''; - print ''; + print ''; + print ''; print ''; - print ''; + print ''; + print ''; } } - // Other attributes - $reshook=$hookmanager->executeHooks('formObjectOptions','',$object,$action); // Note that $action and $object may have been modified by hook + // Other attributes + $parameters=array(); + $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; print '
'.$langs->trans("Ref").''; - print $object->ref; - print '
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("Label").''.$object->label.'
'.$langs->trans("DatePayment").''; @@ -335,23 +337,27 @@ if ($id) { if ($object->fk_account > 0) { - $bankline=new AccountLine($db); - $bankline->fetch($object->fk_bank); + $bankline=new AccountLine($db); + $bankline->fetch($object->fk_bank); - print '
'.$langs->trans('BankTransactionLine').'
'.$langs->trans('BankTransactionLine').''; print $bankline->getNomUrl(1,0,'showall'); - print '
'; + print '
'; + dol_fiche_end(); /* diff --git a/htdocs/compta/tva/class/tva.class.php b/htdocs/compta/tva/class/tva.class.php index 5cf8b6566bd..045284bd47c 100644 --- a/htdocs/compta/tva/class/tva.class.php +++ b/htdocs/compta/tva/class/tva.class.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2008 Laurent Destailleur - * Copyright (C) 2011-2015 Alexandre Spangaro + * Copyright (C) 2011-2017 Alexandre Spangaro * * 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 @@ -34,6 +34,7 @@ class Tva extends CommonObject { //public $element='tva'; //!< Id that identify managed objects //public $table_element='tva'; //!< Name of table without prefix where object is stored + public $picto='payment'; var $tms; var $datep; @@ -73,6 +74,7 @@ class Tva extends CommonObject global $conf, $langs; $error=0; + $now=dol_now(); // Clean parameters $this->amount=trim($this->amount); @@ -89,7 +91,7 @@ class Tva extends CommonObject // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."tva("; - $sql.= "tms,"; + $sql.= "datec,"; $sql.= "datep,"; $sql.= "datev,"; $sql.= "amount,"; @@ -101,7 +103,7 @@ class Tva extends CommonObject $sql.= ") VALUES ("; - $sql.= " '".$this->db->idate($this->tms)."',"; + $sql.= " '".$this->db->idate($now)."',"; $sql.= " '".$this->db->idate($this->datep)."',"; $sql.= " '".$this->db->idate($this->datev)."',"; $sql.= " '".$this->amount."',"; @@ -677,46 +679,70 @@ class Tva extends CommonObject * @param int $id Id of vat payment * @return int <0 if KO, >0 if OK */ - function info($id) - { - $sql = "SELECT t.rowid, t.tms as datec, t.fk_user_creat"; - $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; - $sql.= " WHERE t.rowid = ".$id; + function info($id) + { + $sql = "SELECT t.rowid, t.tms, t.datec, t.fk_user_creat"; + $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; + $sql.= " WHERE t.rowid = ".$id; - dol_syslog(get_class($this)."::info", LOG_DEBUG); - $result=$this->db->query($sql); - if ($result) - { - if ($this->db->num_rows($result)) - { - $obj = $this->db->fetch_object($result); + dol_syslog(get_class($this)."::info", LOG_DEBUG); + $result=$this->db->query($sql); + if ($result) + { + if ($this->db->num_rows($result)) + { + $obj = $this->db->fetch_object($result); - $this->id = $obj->rowid; + $this->id = $obj->rowid; - if ($obj->fk_user_creat) { - $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_creat); - $this->user_creation = $cuser; - } + if ($obj->fk_user_creat) { + $cuser = new User($this->db); + $cuser->fetch($obj->fk_user_creat); + $this->user_creation = $cuser; + } - if ($obj->fk_user_modif) { - $muser = new User($this->db); - $muser->fetch($obj->fk_user_modif); - $this->user_modification = $muser; - } + if ($obj->fk_user_modif) { + $muser = new User($this->db); + $muser->fetch($obj->fk_user_modif); + $this->user_modification = $muser; + } - $this->date_creation = $this->db->jdate($obj->datec); - $this->date_modification = $this->db->jdate($obj->datec); - $this->import_key = $obj->import_key; - } + $this->date_creation = $this->db->jdate($obj->datec); + $this->date_modification = $this->db->jdate($obj->tms); + $this->import_key = $obj->import_key; + } - $this->db->free($result); + $this->db->free($result); - } - else - { - dol_print_error($this->db); - } - } + } + else + { + dol_print_error($this->db); + } + } + /** + * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle + */ + function getLibStatut($mode=0) + { + return $this->LibStatut($this->statut,$mode); + } + + /** + * Renvoi le libelle d'un statut donne + * + * @param int $status Statut + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle du statut + */ + function LibStatut($status,$mode=0) + { + global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage + + return ''; + } } diff --git a/htdocs/compta/tva/info.php b/htdocs/compta/tva/info.php index 0c6ce29475a..fb932f0f983 100644 --- a/htdocs/compta/tva/info.php +++ b/htdocs/compta/tva/info.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2016-2017 Alexandre Spangaro * * 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 @@ -53,12 +53,21 @@ $head = vat_prepare_head($object); dol_fiche_head($head, 'info', $langs->trans("VATPayment"), 0, 'payment'); +$linkback = ''.$langs->trans("BackToList").''; + +dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref, '', 0, '', ''); + +print '
'; +print '
'; + print '
'; dol_print_object_info($object); print '
'; print '
'; +dol_fiche_end(); + llxFooter(); $db->close(); diff --git a/htdocs/compta/tva/reglement.php b/htdocs/compta/tva/reglement.php index 076978a86fb..44c45a65dc7 100644 --- a/htdocs/compta/tva/reglement.php +++ b/htdocs/compta/tva/reglement.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2003 Rodolphe Quiedeville * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2011-2014 Alexandre Spangaro + * Copyright (C) 2011-2017 Alexandre Spangaro * * 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 @@ -29,6 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/compta/tva/class/tva.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; +require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php'; $langs->load("compta"); $langs->load("bills"); @@ -49,7 +50,7 @@ $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -94,10 +95,10 @@ llxHeader('', $langs->trans("VATPayments")); $form = new Form($db); $formother=new FormOther($db); $tva_static = new Tva($db); -$accountstatic = new Account($db); +$bankstatic = new Account($db); $sql = "SELECT t.rowid, t.amount, t.label, t.datev as dv, t.datep as dp, t.fk_typepayment as type, t.num_payment, t.fk_bank, pst.code as payment_code,"; -$sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.accountancy_journal, ba.label as blabel"; +$sql.= " ba.rowid as bid, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.fk_accountancy_journal, ba.label as blabel"; $sql.= " FROM ".MAIN_DB_PREFIX."tva as t"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as pst ON t.fk_typepayment = pst.id"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank as b ON t.fk_bank = b.rowid"; @@ -227,19 +228,22 @@ if ($result) { print ''; if ($obj->fk_bank > 0) - { - //$accountstatic->fetch($obj->fk_bank); - $accountstatic->id=$obj->bid; - $accountstatic->ref=$obj->bref; - $accountstatic->number=$obj->bnumber; - $accountstatic->accountancy_number=$obj->account_number; - $accountstatic->accountancy_journal=$obj->accountancy_journal; - $accountstatic->label=$obj->blabel; - print $accountstatic->getNomUrl(1); - } - else print ' '; - print ''; - } + { + $bankstatic->id=$obj->bid; + $bankstatic->ref=$obj->bref; + $bankstatic->number=$obj->bnumber; + $bankstatic->account_number=$obj->account_number; + + $accountingjournal = new AccountingJournal($db); + $accountingjournal->fetch($obj->fk_accountancy_journal); + $bankstatic->accountancy_journal = $accountingjournal->getNomUrl(0,1,1,'',1); + + $bankstatic->label=$obj->blabel; + print $bankstatic->getNomUrl(1); + } + else print ' '; + print ''; + } // Amount $total = $total + $obj->amount; print "".price($obj->amount).""; diff --git a/htdocs/conf/conf.php.example b/htdocs/conf/conf.php.example index 89e1458d4fd..356e76ba374 100644 --- a/htdocs/conf/conf.php.example +++ b/htdocs/conf/conf.php.example @@ -324,14 +324,4 @@ $dolibarr_nocsrfcheck='0'; // External module //############################## -// multicompany_transverse_mode -// Prerequisite: Need external module "multicompany" -// Pyramidal (0): The rights and groups are managed in each entity. Each user belongs to the entity he was created into. -// Transversal (1): The user is created and managed only into master entity but can login to all entities if he is admmin -// of entity or belongs to at least one user group created into entity. - -// Default value: 0 (pyramidal) -// Examples: -// $multicompany_transverse_mode='1'; - diff --git a/htdocs/contact/agenda.php b/htdocs/contact/agenda.php index f57e088e00e..74ec89bf5d1 100644 --- a/htdocs/contact/agenda.php +++ b/htdocs/contact/agenda.php @@ -89,18 +89,18 @@ $search_agenda_label=GETPOST('search_agenda_label'); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', $objcanvas); // If we create a contact with no company (shared contacts), no check on write permission -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; if (! $sortfield) $sortfield='a.datep, a.id'; if (! $sortorder) $sortorder='DESC'; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('contactcard','globalcard')); diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index fde2e428169..fbd27b0d841 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -76,7 +76,7 @@ if (! empty($canvas)) if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', $objcanvas); // If we create a contact with no company (shared contacts), no check on write permission -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('contactcard','globalcard')); @@ -316,7 +316,7 @@ if (empty($reshook)) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']); // Create thumbs - $object->addThumbs($newfile); + $object->addThumbs($newfile); } } } @@ -664,8 +664,9 @@ else } // Other attributes - $parameters=array('colspan' => ' colspan="3"'); + $parameters=array('colspan' => ' colspan="3"','cols'=>3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); @@ -674,7 +675,7 @@ else print "
"; print '
'; - + // Add personnal information print load_fiche_titre('
'.$langs->trans("PersonalInformations").'
','',''); @@ -787,7 +788,7 @@ else print $object->ref; print ''; } - + // Lastname print ''; print 'lastname).'" autofocus="autofocus">'; @@ -932,8 +933,9 @@ else } // Other attributes - $parameters=array('colspan' => ' colspan="3"'); + $parameters=array('colspan' => ' colspan="3"', 'cols'=>3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; if (empty($reshook) && ! empty($extrafields->attribute_label)) { print $object->showOptionals($extrafields,'edit'); @@ -1054,7 +1056,7 @@ else } $linkback = ''.$langs->trans("BackToList").''; - + $morehtmlref='
'; if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { @@ -1064,14 +1066,14 @@ else if ($objsoc->id > 0) $morehtmlref.=$objsoc->getNomUrl(1); else $morehtmlref.=$langs->trans("ContactNotLinkedToCompany"); } - $morehtmlref.='
'; - + $morehtmlref.='
'; + dol_banner_tab($object, 'id', $linkback, 1, 'rowid', 'ref', $morehtmlref); - - + + print '
'; print '
'; - + print '
'; print ''; @@ -1102,26 +1104,14 @@ else print $object->LibPubPriv($object->priv); print ''; - // Note Public - /* - print ''; - - // Note Private - print ''; - */ - print '
'.$langs->trans("NotePublic").''; - print nl2br($object->note_public); - print '
'.$langs->trans("NotePrivate").''; - print nl2br($object->note_private); - print '
'; - + print '
'; print '
'; - + print '
'; print ''; - + // Categories if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) { print ''; @@ -1130,14 +1120,10 @@ else print ''; } - // Other attributes - $parameters=array('socid'=>$socid, 'colspan' => ' colspan="3"'); - $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - if (empty($reshook) && ! empty($extrafields->attribute_label)) - { - print $object->showOptionals($extrafields); - } + // Other attributes + $cols = 3; + $parameyers=array('socid'=>$socid); + include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_view.tpl.php'; $object->load_ref_elements(); @@ -1193,10 +1179,10 @@ else print ''; print "
' . $langs->trans("Categories") . '
"; - + print '
'; print '
'; - + print dol_fiche_end(); // Barre d'actions diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index 9bcfee7ccae..1293a258fab 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -74,7 +74,7 @@ $optioncss = GETPOST('optioncss','alpha'); $type=GETPOST("type"); $view=GETPOST("view"); -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST('sortfield', 'alpha'); $sortorder = GETPOST('sortorder', 'alpha'); $page = GETPOST('page', 'int'); @@ -114,7 +114,7 @@ else if ($type == "o") $urlfiche=""; } -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array($contextpage)); $extrafields = new ExtraFields($db); @@ -247,7 +247,7 @@ if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_conta if (! empty($search_categ_thirdparty)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; // We need this table joined to the select in order to filter by categ if (! empty($search_categ_supplier)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs2 ON s.rowid = cs2.fk_soc"; // We need this table joined to the select in order to filter by categ if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; -$sql.= ' WHERE p.entity IN ('.getEntity('societe', 1).')'; +$sql.= ' WHERE p.entity IN ('.getEntity('societe').')'; if (!$user->rights->societe->client->voir && !$socid) //restriction { $sql .= " AND (sc.fk_user = " .$user->id." OR p.fk_soc IS NULL)"; @@ -682,6 +682,7 @@ print "\n"; $i = 0; +$totalarray=array(); while ($i < min($num,$limit)) { $obj = $db->fetch_object($result); @@ -706,56 +707,67 @@ while ($i < min($num,$limit)) print ''; print $contactstatic->getNomUrl(1,'',0); print ''; + if (! $i) $totalarray['nbfield']++; } // Firstname if (! empty($arrayfields['p.firstname']['checked'])) { print ''.$obj->firstname.''; + if (! $i) $totalarray['nbfield']++; } // Zip if (! empty($arrayfields['p.zip']['checked'])) { print ''.$obj->zip.''; + if (! $i) $totalarray['nbfield']++; } // Town if (! empty($arrayfields['p.town']['checked'])) { print ''.$obj->town.''; + if (! $i) $totalarray['nbfield']++; } // Function if (! empty($arrayfields['p.poste']['checked'])) { print ''.dol_trunc($obj->poste,20).''; + if (! $i) $totalarray['nbfield']++; } // Phone if (! empty($arrayfields['p.phone']['checked'])) { print ''.dol_print_phone($obj->phone_pro,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').''; + if (! $i) $totalarray['nbfield']++; } // Phone perso if (! empty($arrayfields['p.phone_perso']['checked'])) { print ''.dol_print_phone($obj->phone_perso,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').''; + if (! $i) $totalarray['nbfield']++; } // Phone mobile if (! empty($arrayfields['p.phone_mobile']['checked'])) { print ''.dol_print_phone($obj->phone_mobile,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').''; + if (! $i) $totalarray['nbfield']++; } // Fax if (! empty($arrayfields['p.fax']['checked'])) { print ''.dol_print_phone($obj->fax,$obj->country_code,$obj->rowid,$obj->socid,'AC_TEL').''; + if (! $i) $totalarray['nbfield']++; } // EMail if (! empty($arrayfields['p.email']['checked'])) { print ''.dol_print_email($obj->email,$obj->rowid,$obj->socid,'AC_EMAIL',18).''; + if (! $i) $totalarray['nbfield']++; } // Skype if (! empty($arrayfields['p.skype']['checked'])) { if (! empty($conf->skype->enabled)) { print ''.dol_print_skype($obj->skype,$obj->rowid,$obj->socid,'AC_SKYPE',18).''; } + if (! $i) $totalarray['nbfield']++; } // Company if (! empty($arrayfields['p.thirdparty']['checked'])) @@ -770,12 +782,14 @@ while ($i < min($num,$limit)) else print ' '; print ''; + if (! $i) $totalarray['nbfield']++; } // Private/Public if (! empty($arrayfields['p.priv']['checked'])) { print ''.$contactstatic->LibPubPriv($obj->priv).''; + if (! $i) $totalarray['nbfield']++; } // Extra fields @@ -792,6 +806,7 @@ while ($i < min($num,$limit)) $tmpkey='options_'.$key; print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1); print ''; + if (! $i) $totalarray['nbfield']++; } } } @@ -805,6 +820,7 @@ while ($i < min($num,$limit)) print ''; print dol_print_date($db->jdate($obj->date_creation), 'dayhour'); print ''; + if (! $i) $totalarray['nbfield']++; } // Date modification if (! empty($arrayfields['p.tms']['checked'])) @@ -812,11 +828,13 @@ while ($i < min($num,$limit)) print ''; print dol_print_date($db->jdate($obj->date_update), 'dayhour'); print ''; + if (! $i) $totalarray['nbfield']++; } // Status if (! empty($arrayfields['p.statut']['checked'])) { print ''.$contactstatic->getLibStatut(3).''; + if (! $i) $totalarray['nbfield']++; } // Action column @@ -829,7 +847,7 @@ while ($i < min($num,$limit)) } print ''; if (! $i) $totalarray['nbfield']++; - + print "\n"; $i++; } diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 31e5d6f3094..c13571dd6cb 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -68,7 +68,7 @@ $usehm=(! empty($conf->global->MAIN_USE_HOURMIN_IN_DATE_RANGE)?$conf->global->MA if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'contrat',$id); -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('contractcard','globalcard')); $object = new Contrat($db); @@ -104,13 +104,13 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once - + include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once - + if ($action == 'confirm_active' && $confirm == 'yes' && $user->rights->contrat->activer) { $result = $object->active_line($user, GETPOST('ligne'), GETPOST('date'), GETPOST('dateend'), GETPOST('comment')); - + if ($result > 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); @@ -136,13 +136,13 @@ if (empty($reshook)) header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); exit; } - else + else { setEventMessages($object->error, $object->errors, 'errors'); } } } - + // Si ajout champ produit predefini if (GETPOST('mode')=='predefined') { @@ -157,7 +157,7 @@ if (empty($reshook)) $date_end=dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), 0, GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear')); } } - + // Si ajout champ produit libre if (GETPOST('mode')=='libre') { @@ -172,7 +172,7 @@ if (empty($reshook)) $date_end_sl=dol_mktime(GETPOST('date_end_slhour'), GETPOST('date_end_slmin'), 0, GETPOST('date_end_slmonth'), GETPOST('date_end_slday'), GETPOST('date_end_slyear')); } } - + // Param dates $date_contrat=''; $date_start_update=''; @@ -199,7 +199,7 @@ if (empty($reshook)) { $datecontrat = dol_mktime(GETPOST('rehour'), GETPOST('remin'), 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); } - + // Add contract if ($action == 'add' && $user->rights->contrat->creer) { @@ -210,29 +210,29 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors'); $action='create'; } - + if ($socid<1) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ThirdParty")), null, 'errors'); $action='create'; $error++; } - + // Fill array 'array_options' with data from add form $ret = $extrafields->setOptionalsFromPost($extralabels, $object); if ($ret < 0) { $error ++; $action = 'create'; } - + if (! $error) { $object->socid = $socid; $object->date_contrat = $datecontrat; - + $object->commercial_suivi_id = GETPOST('commercial_suivi_id','int'); $object->commercial_signature_id = GETPOST('commercial_signature_id','int'); - + $object->note_private = GETPOST('note_private','alpha'); $object->note_public = GETPOST('note_public','alpha'); $object->fk_project = GETPOST('projectid','int'); @@ -251,33 +251,33 @@ if (empty($reshook)) $element = $regs[1]; $subelement = $regs[2]; } - + // For compatibility if ($element == 'order') { $element = $subelement = 'commande'; } if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } - + $object->origin = $origin; $object->origin_id = $originid; - + // Possibility to add external linked objects with hooks $object->linked_objects[$object->origin] = $object->origin_id; if (is_array($_POST['other_linked_objects']) && ! empty($_POST['other_linked_objects'])) { $object->linked_objects = array_merge($object->linked_objects, $_POST['other_linked_objects']); } - + $id = $object->create($user); if ($id < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - + if ($id > 0) { dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); - + $classname = ucfirst($subelement); $srcobject = new $classname($db); - + dol_syslog("Try to find source object origin=".$object->origin." originid=".$object->origin_id." to add lines"); $result=$srcobject->fetch($object->origin_id); if ($result > 0) @@ -289,44 +289,44 @@ if (empty($reshook)) $srcobject->fetch_lines(); $lines = $srcobject->lines; } - + $fk_parent_line=0; $num=count($lines); - + for ($i=0;$i<$num;$i++) { $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0); - + if ($product_type == 1 || (! empty($conf->global->CONTRACT_SUPPORT_PRODUCTS) && in_array($product_type, array(0,1)))) { // TODO Exclude also deee // service prédéfini if ($lines[$i]->fk_product > 0) { $product_static = new Product($db); - + // Define output language if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) { $prod = new Product($db); $prod->id=$lines[$i]->fk_product; $prod->getMultiLangs(); - + $outputlangs = $langs; $newlang=''; - if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); if (empty($newlang)) $newlang=$srcobject->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("",$conf); $outputlangs->setDefaultLang($newlang); } - + $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["libelle"])) ? $prod->multilangs[$outputlangs->defaultlang]["libelle"] : $lines[$i]->product_label; } else { $label = $lines[$i]->product_label; } - + $desc .= ($lines[$i]->desc && $lines[$i]->desc!=$lines[$i]->libelle)?dol_htmlentitiesbr($lines[$i]->desc):''; } else { @@ -338,7 +338,7 @@ if (empty($reshook)) // View third's localtaxes for now $localtax1_tx = get_localtax($txtva, 1, $object->thirdparty); $localtax2_tx = get_localtax($txtva, 2, $object->thirdparty); - + $result = $object->addline( $desc, $lines[$i]->subprice, @@ -358,7 +358,7 @@ if (empty($reshook)) array(), $lines[$i]->fk_unit ); - + if ($result < 0) { $error++; @@ -372,13 +372,13 @@ if (empty($reshook)) setEventMessages($srcobject->error, $srcobject->errors, 'errors'); $error++; } - + // Hooks $parameters = array('objFrom' => $srcobject); $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook if ($reshook < 0) - $error++; + $error++; } else { @@ -401,12 +401,12 @@ if (empty($reshook)) } } } - + else if ($action == 'classin' && $user->rights->contrat->creer) { $object->setProject(GETPOST('projectid')); } - + // Add a new line else if ($action == 'addline' && $user->rights->contrat->creer) { @@ -425,10 +425,10 @@ if (empty($reshook)) $idprod=GETPOST('idprod', 'int'); $tva_tx = ''; } - + $qty = GETPOST('qty'.$predef); $remise_percent = GETPOST('remise_percent'.$predef); - + if ($qty == '') { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Qty")), null, 'errors'); @@ -439,7 +439,7 @@ if (empty($reshook)) setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Description")), null, 'errors'); $error++; } - + // Extrafields $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); @@ -458,7 +458,7 @@ if (empty($reshook)) $date_start=dol_mktime(GETPOST('date_start'.$predef.'hour'), GETPOST('date_start'.$predef.'min'), GETPOST('date_start'.$predef.'sec'), GETPOST('date_start'.$predef.'month'), GETPOST('date_start'.$predef.'day'), GETPOST('date_start'.$predef.'year')); $date_end=dol_mktime(GETPOST('date_end'.$predef.'hour'), GETPOST('date_end'.$predef.'min'), GETPOST('date_end'.$predef.'sec'), GETPOST('date_end'.$predef.'month'), GETPOST('date_end'.$predef.'day'), GETPOST('date_end'.$predef.'year')); $price_base_type = (GETPOST('price_base_type', 'alpha')?GETPOST('price_base_type', 'alpha'):'HT'); - + // Ecrase $pu par celui du produit // Ecrase $desc par celui du produit // Ecrase $tva_tx par celui du produit @@ -467,17 +467,17 @@ if (empty($reshook)) { $prod = new Product($db); $prod->fetch($idprod); - + // Update if prices fields are defined $tva_tx = get_default_tva($mysoc,$object->thirdparty,$prod->id); $tva_npr = get_default_npr($mysoc,$object->thirdparty,$prod->id); if (empty($tva_tx)) $tva_npr=0; - + $pu_ht = $prod->price; $pu_ttc = $prod->price_ttc; $price_min = $prod->price_min; $price_base_type = $prod->price_base_type; - + // On defini prix unitaire if ($conf->global->PRODUIT_MULTIPRICES && $object->thirdparty->price_level) { @@ -489,11 +489,11 @@ if (empty($reshook)) elseif (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php'; - + $prodcustprice = new Productcustomerprice($db); - + $filter = array('t.fk_product' => $prod->id,'t.fk_soc' => $object->thirdparty->id); - + $result = $prodcustprice->fetch_all('', '', 0, 0, $filter); if ($result) { if (count($prodcustprice->lines) > 0) { @@ -504,10 +504,10 @@ if (empty($reshook)) } } } - + $tmpvat = price2num(preg_replace('/\s*\(.*\)/', '', $tva_tx)); $tmpprodvat = price2num(preg_replace('/\s*\(.*\)/', '', $prod->tva_tx)); - + // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). if ($tmpvat != $tmpprodvat) @@ -521,7 +521,7 @@ if (empty($reshook)) $pu_ttc = price2num($pu_ht * (1 + ($tmpvat/100)), 'MU'); } } - + $desc=$prod->description; $desc=dol_concatdesc($desc,$product_desc); $fk_unit = $prod->fk_unit; @@ -535,20 +535,20 @@ if (empty($reshook)) $desc=$product_desc; $fk_unit= GETPOST('units', 'alpha'); } - + $localtax1_tx=get_localtax($tva_tx,1,$object->thirdparty,$mysoc,$tva_npr); $localtax2_tx=get_localtax($tva_tx,2,$object->thirdparty,$mysoc,$tva_npr); - + // ajout prix achat $fk_fournprice = $_POST['fournprice']; if ( ! empty($_POST['buying_price']) ) $pa_ht = $_POST['buying_price']; else $pa_ht = null; - + $info_bits=0; if ($tva_npr) $info_bits |= 0x01; - + if($price_min && (price2num($pu_ht)*(1-price2num($remise_percent)/100) < price2num($price_min))) { $object->error = $langs->trans("CantBeLessThanMinPrice",price(price2num($price_min,'MU'),0,$langs,0,0,-1,$conf->currency)); @@ -577,7 +577,7 @@ if (empty($reshook)) $fk_unit ); } - + if ($result > 0) { // Define output language @@ -585,20 +585,20 @@ if (empty($reshook)) { $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); $outputlangs->setDefaultLang($newlang); } - + $ret = $object->fetch($id); // Reload to get new records - + $object->generateDocument($object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); } - + unset($_POST ['prod_entry_mode']); - + unset($_POST['qty']); unset($_POST['type']); unset($_POST['remise_percent']); @@ -615,7 +615,7 @@ if (empty($reshook)) unset($_POST ['np_markRate']); unset($_POST['dp_desc']); unset($_POST['idprod']); - + unset($_POST['date_starthour']); unset($_POST['date_startmin']); unset($_POST['date_startsec']); @@ -635,30 +635,30 @@ if (empty($reshook)) } } } - + else if ($action == 'updateline' && $user->rights->contrat->creer && ! GETPOST('cancel')) { $objectline = new ContratLigne($db); if ($objectline->fetch(GETPOST('elrowid'))) { $db->begin(); - + if ($date_start_real_update == '') $date_start_real_update=$objectline->date_ouverture; if ($date_end_real_update == '') $date_end_real_update=$objectline->date_cloture; - + $vat_rate = GETPOST('eltva_tx'); // Define info_bits $info_bits = 0; if (preg_match('/\*/', $vat_rate)) $info_bits |= 0x01; - + // Define vat_rate $vat_rate = str_replace('*', '', $vat_rate); $localtax1_tx=get_localtax($vat_rate, 1, $object->thirdparty, $mysoc); $localtax2_tx=get_localtax($vat_rate, 2, $object->thirdparty, $mysoc); - + $txtva = $vat_rate; - + // Clean vat code $vat_src_code=''; if (preg_match('/\((.*)\)/', $txtva, $reg)) @@ -666,16 +666,16 @@ if (empty($reshook)) $vat_src_code = $reg[1]; $txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate. } - + // ajout prix d'achat $fk_fournprice = $_POST['fournprice']; if ( ! empty($_POST['buying_price']) ) $pa_ht = $_POST['buying_price']; else $pa_ht = null; - + $fk_unit = GETPOST('unit', 'alpha'); - + $objectline->description=GETPOST('product_desc'); $objectline->price_ht=GETPOST('elprice'); $objectline->subprice=GETPOST('elprice'); @@ -692,21 +692,21 @@ if (empty($reshook)) $objectline->fk_user_cloture=$user->id; $objectline->fk_fournprice=$fk_fournprice; $objectline->pa_ht=$pa_ht; - + if ($fk_unit > 0) { $objectline->fk_unit = GETPOST('unit'); } else { $objectline->fk_unit = null; } - + // Extrafields $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($objectline->table_element); $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); $objectline->array_options=$array_options; - + // TODO verifier price_min si fk_product et multiprix - + $result=$objectline->update($user); if ($result > 0) { @@ -723,11 +723,11 @@ if (empty($reshook)) setEventMessages($objectline->error, $objectline->errors, 'errors'); } } - + else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->contrat->creer) { $result = $object->deleteline(GETPOST('lineid'),$user); - + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); @@ -738,23 +738,23 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + else if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->contrat->creer) { $result = $object->validate($user); } - + else if ($action == 'reopen' && $user->rights->contrat->creer) { $result = $object->reopen($user); } - + // Close all lines else if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->contrat->creer) { $object->cloture($user); } - + else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->contrat->supprimer) { $result=$object->delete($user); @@ -768,7 +768,7 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - + else if ($action == 'confirm_move' && $confirm == 'yes' && $user->rights->contrat->creer) { if (GETPOST('newcid') > 0) @@ -791,39 +791,39 @@ if (empty($reshook)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentities("RefNewContract")), null, 'errors'); } - } - else if ($action == 'update_extras') + } + else if ($action == 'update_extras') { // Fill array 'array_options' with data from update form $extralabels = $extrafields->fetch_name_optionals_label($object->table_element); $ret = $extrafields->setOptionalsFromPost($extralabels, $object, GETPOST('attribute')); if ($ret < 0) $error ++; - + if (! $error) { - + $result = $object->insertExtraFields(); if ($result < 0) { $error ++; } } else if ($reshook < 0) $error ++; - + if ($error) { $action = 'edit_extras'; setEventMessages($object->error, $object->errors, 'errors'); } - } - elseif ($action=='setref_supplier') + } + elseif ($action=='setref_supplier') { $cancelbutton = GETPOST('cancel'); if (!$cancelbutton) { - + $result = $object->fetch($id); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - + $result = $object->setValueFrom('ref_supplier', GETPOST('ref_supplier','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -838,17 +838,17 @@ if (empty($reshook)) exit; } } - elseif ($action=='setref_customer') + elseif ($action=='setref_customer') { $cancelbutton = GETPOST('cancel'); - + if (!$cancelbutton) { $result = $object->fetch($id); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - + $result = $object->setValueFrom('ref_customer', GETPOST('ref_customer','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -863,16 +863,16 @@ if (empty($reshook)) exit; } } - elseif ($action=='setref') + elseif ($action=='setref') { $cancelbutton = GETPOST('cancel'); - + if (!$cancelbutton) { $result = $object->fetch($id); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } - + $result = $object->setValueFrom('ref', GETPOST('ref','alpha'), '', null, 'text', '', $user, 'CONTRACT_MODIFY'); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -886,11 +886,11 @@ if (empty($reshook)) header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); exit; } - } - elseif ($action=='setdate_contrat') + } + elseif ($action=='setdate_contrat') { $cancelbutton = GETPOST('cancel'); - + if (!$cancelbutton) { $result = $object->fetch($id); if ($result < 0) { @@ -911,18 +911,18 @@ if (empty($reshook)) exit; } } - + // Generation doc (depuis lien ou depuis cartouche doc) else if ($action == 'builddoc' && $user->rights->contrat->creer) { if (GETPOST('model')) { $object->setDocModel($user, GETPOST('model')); } - + // Define output language $outputlangs = $langs; if (! empty($conf->global->MAIN_MULTILANGS)) { $outputlangs = new Translate("", $conf); - $newlang = (GETPOST('lang_id') ? GETPOST('lang_id') : $object->thirdparty->default_lang); + $newlang = (GETPOST('lang_id','aZ09') ? GETPOST('lang_id','aZ09') : $object->thirdparty->default_lang); $outputlangs->setDefaultLang($newlang); } $ret = $object->fetch($id); // Reload to get new records @@ -933,12 +933,12 @@ if (empty($reshook)) $action=''; } } - + // Remove file in doc form else if ($action == 'remove_file' && $user->rights->contrat->creer) { if ($object->id > 0) { require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - + $langs->load("other"); $upload_dir = $conf->contrat->dir_output; $file = $upload_dir . '/' . GETPOST('file'); @@ -965,7 +965,7 @@ if (empty($reshook)) { $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid')); $result = $object->add_contact($contactid, GETPOST('type'), GETPOST('source')); - + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); @@ -984,18 +984,18 @@ if (empty($reshook)) } } } - + // bascule du statut d'un contact else if ($action == 'swapstatut') { $result=$object->swapContactStatus(GETPOST('ligne')); } - + // Efface un contact else if ($action == 'deletecontact') { $result = $object->delete_contact(GETPOST('lineid')); - + if ($result >= 0) { header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); @@ -1040,7 +1040,7 @@ llxHeader('',$langs->trans("Contract"),""); $form = new Form($db); $formfile = new FormFile($db); if (! empty($conf->projet->enabled)) $formproject = new FormProjets($db); - + $objectlignestatic=new ContratLigne($db); // Load object modContract @@ -1209,8 +1209,9 @@ if ($action == 'create') } // Other attributes - $parameters=array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"'); + $parameters=array('objectsrc' => $objectsrc,'colspan' => ' colspan="3"', 'cols'=>3); $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; // Other attributes if (empty($reshook) && ! empty($extrafields->attribute_label)) { @@ -1333,7 +1334,7 @@ else $linkback = ''.$langs->trans("BackToList").''; - + $morehtmlref=''; if (! empty($modCodeContract->code_auto)) { $morehtmlref.=$object->ref; @@ -1341,7 +1342,7 @@ else $morehtmlref.=$form->editfieldkey("",'ref',$object->ref,$object,$user->rights->contrat->creer,'string','',0,3); $morehtmlref.=$form->editfieldval("",'ref',$object->ref,$object,$user->rights->contrat->creer,'string','',0,2); } - + $morehtmlref.='
'; // Ref customer $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_customer', $object->ref_customer, $object, $user->rights->contrat->creer, 'string', '', 0, 1); @@ -1392,10 +1393,10 @@ else print '
'; print '
'; - - + + print ''; - + // Ligne info remises tiers print '
'.$langs->trans('Discount').''; if ($object->thirdparty->remise_percent) print $langs->trans("CompanyHasRelativeDiscount",$object->thirdparty->remise_percent); @@ -1423,7 +1424,7 @@ else print "
"; print '
'; - + if (! empty($object->brouillon) && $user->rights->contrat->creer) { print ''; @@ -1615,7 +1616,7 @@ else { print dol_print_date($db->jdate($objp->date_debut)); // Warning si date prevu passee et pas en service - if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) { + if ($objp->statut == 0 && $db->jdate($objp->date_debut) < ($now - $conf->contrat->services->inactifs->warning_delay)) { $warning_delay=$conf->contrat->services->inactifs->warning_delay / 3600 / 24; $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); print " ".img_warning($textlate); @@ -1627,7 +1628,7 @@ else if ($objp->date_fin) { print dol_print_date($db->jdate($objp->date_fin)); - if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) { + if ($objp->statut == 4 && $db->jdate($objp->date_fin) < ($now - $conf->contrat->services->expires->warning_delay)) { $warning_delay=$conf->contrat->services->expires->warning_delay / 3600 / 24; $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); print " ".img_warning($textlate); @@ -1781,7 +1782,7 @@ else { $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - $comment = GETPOST('comment'); + $comment = GETPOST('comment','alpha'); $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment),$langs->trans("ActivateService"),$langs->trans("ConfirmActivateService",dol_print_date($dateactstart,"%A %d %B %Y")),"confirm_active", '', 0, 1); print '
'; } @@ -1793,8 +1794,16 @@ else { $dateactstart = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $dateactend = dol_mktime(12, 0, 0, GETPOST('endmonth'), GETPOST('endday'), GETPOST('endyear')); - $comment = GETPOST('comment'); - $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")), "confirm_closeline", '', 0, 1); + $comment = GETPOST('comment','alpha'); + + if (empty($dateactend)) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DateEndReal")), null, 'errors'); + } + else + { + $form->form_confirm($_SERVER["PHP_SELF"]."?id=".$object->id."&ligne=".GETPOST('ligne','int')."&date=".$dateactstart."&dateend=".$dateactend."&comment=".urlencode($comment), $langs->trans("CloseService"), $langs->trans("ConfirmCloseService",dol_print_date($dateactend,"%A %d %B %Y")), "confirm_closeline", '', 0, 1); + } print '
'; } @@ -1814,13 +1823,13 @@ else $tmpaction='activateline'; $tmpactionpicto='play'; $tmpactiontext=$langs->trans("Activate"); - if ($objp->statut == 4) + if ($objp->statut == 4) { $tmpaction='unactivateline'; $tmpactionpicto='playstop'; $tmpactiontext=$langs->trans("Unactivate"); } - if (($tmpaction=='activateline' && $user->rights->contrat->activer) || ($tmpaction=='unactivateline' && $user->rights->contrat->desactiver)) + if (($tmpaction=='activateline' && $user->rights->contrat->activer) || ($tmpaction=='unactivateline' && $user->rights->contrat->desactiver)) { print ''; print img_picto($tmpactiontext, $tmpactionpicto); @@ -1917,9 +1926,11 @@ else /** * Disable a contract line */ - print '
'; + print ''."\n"; + print ''; print ''; + print ''; print ''; @@ -1956,13 +1967,13 @@ else print ''; print ''; - print ''; + print ''; print ''; print ''; - + print '
'.$langs->trans("Comment").''.$langs->trans("Comment").''; print '   '; print ''; print '
'; print '
'; @@ -1997,7 +2008,7 @@ else $var = true; $forcetoshowtitlelines=1; - + // Add free products/services $object->formAddObjectLine(1, $mysoc, $soc); @@ -2037,7 +2048,7 @@ else if ($user->rights->contrat->creer) print '
'; else print ''; } - + if (! empty($conf->facture->enabled) && $object->statut > 0 && $object->nbofservicesclosed < $nbofservices) { $langs->load("bills"); @@ -2051,7 +2062,7 @@ else if ($user->rights->commande->creer) print ''; else print ''; } - + // Clone if ($user->rights->contrat->creer) { print ''; @@ -2083,16 +2094,16 @@ else print "
"; } - + // Select mail models is same action as presend if (GETPOST('modelselected')) { $action = 'presend'; } - + if ($action != 'presend') { print '
'; - + /* * Documents generes */ @@ -2101,25 +2112,25 @@ else $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; $genallowed = $user->rights->contrat->creer; $delallowed = $user->rights->contrat->supprimer; - + $var = true; - + print $formfile->showdocuments('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); - - + + // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('contrat')); $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem); - - + + print '
'; - + // List of actions on element include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions = new FormActions($db); $somethingshown = $formactions->showactions($object, 'contract', $socid); - + print '
'; } @@ -2161,6 +2172,7 @@ else $file = $fileparams['fullname']; } + print '
'; print '
'; print '
'; print load_fiche_titre($langs->trans('SendContractByMail')); diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index db6464edb6a..608f5614cd8 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -46,7 +46,7 @@ class Contrat extends CommonObject public $fk_element='fk_contrat'; protected $ismultientitymanaged = 1; // 0=No test on entity, 1=Test with field entity, 2=Test with link by societe public $picto='contract'; - + /** * {@inheritdoc} */ @@ -504,7 +504,7 @@ class Contrat extends CommonObject if ($ref) { $sql.= " WHERE ref='".$this->db->escape($ref)."'"; - $sql.= " AND entity IN (".getEntity('contract').")"; + $sql.= " AND entity IN (".getEntity('contract', 0).")"; } else $sql.= " WHERE rowid=".$id; @@ -530,7 +530,7 @@ class Contrat extends CommonObject $this->fin_validite = $this->db->jdate($result["fin_validite"]); $this->date_cloture = $this->db->jdate($result["date_cloture"]); - + $this->user_author_id = $result["fk_user_author"]; $this->commercial_signature_id = $result["fk_commercial_signature"]; @@ -613,7 +613,7 @@ class Contrat extends CommonObject $this->lines=array(); $pos = 0; - + // Selectionne les lignes contrats liees a un produit $sql = "SELECT p.label as product_label, p.description as product_desc, p.ref as product_ref,"; $sql.= " d.rowid, d.fk_contrat, d.statut, d.description, d.price_ht, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.remise_percent, d.subprice, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht,"; @@ -1858,7 +1858,7 @@ class Contrat extends CommonObject $url = DOL_URL_ROOT.'/contrat/card.php?id='.$this->id; $picto = 'contract'; $label = ''; - + if ($user->rights->contrat->lire) { $label = ''.$langs->trans("ShowContract").''; $label .= '
'.$langs->trans('Ref').': '.$this->ref; @@ -1874,7 +1874,7 @@ class Contrat extends CommonObject $label .= '
'.$langs->trans('AmountTTC').': '.price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency); } } - + $linkclose=''; if (empty($notooltip) && $user->rights->contrat->lire) { @@ -1890,7 +1890,7 @@ class Contrat extends CommonObject $linkstart = ''; $linkend=''; - + if ($withpicto) $result.=($linkstart.img_object(($notooltip?'':$label), $picto, ($notooltip?'':'class="classfortooltip"'), 0, 0, $notooltip?0:1).$linkend); if ($withpicto && $withpicto != 2) $result.=' '; $result.=$linkstart.$this->ref.$linkend; @@ -2180,7 +2180,7 @@ class Contrat extends CommonObject $prodids = array(); $sql = "SELECT rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."product"; - $sql.= " WHERE entity IN (".getEntity('product', 1).")"; + $sql.= " WHERE entity IN (".getEntity('product').")"; $sql.= " AND tosell = 1"; $resql = $this->db->query($sql); if ($resql) @@ -2225,7 +2225,11 @@ class Contrat extends CommonObject $line->total_ht=90; $line->total_ttc=107.64; // 90 * 1.196 $line->total_tva=17.64; - if ($num_prods > 0) + $line->date_ouverture = dol_now() - 200000; + $line->date_ouverture_prevue = dol_now() - 500000; + $line->date_fin_validite = dol_now() + 500000; + $line->date_cloture = dol_now() - 100000; + if ($num_prods > 0) { $prodid = mt_rand(1, $num_prods); $line->fk_product=$prodids[$prodid]; @@ -2233,11 +2237,6 @@ class Contrat extends CommonObject $this->lines[$xnbp]=$line; $xnbp++; } - - $this->amount_ht = $xnbp*100; - $this->total_ht = $xnbp*100; - $this->total_tva = $xnbp*19.6; - $this->total_ttc = $xnbp*119.6; } /** @@ -2750,6 +2749,8 @@ class ContratLigne extends CommonObjectLine if (empty($this->total_ht)) $this->total_ht = 0; if (empty($this->total_tva)) $this->total_tva = 0; if (empty($this->total_ttc)) $this->total_ttc = 0; + if (empty($this->localtax1_tx)) $this->localtax1_tx = 0; + if (empty($this->localtax2_tx)) $this->localtax2_tx = 0; // Check parameters // Put here code to add control on parameters values @@ -2916,7 +2917,7 @@ class ContratLigne extends CommonObjectLine // Insertion dans la base $sql = "INSERT INTO ".MAIN_DB_PREFIX."contratdet"; - $sql.= " (fk_contrat, label, description, fk_product, qty, tva_tx,"; + $sql.= " (fk_contrat, label, description, fk_product, qty, vat_src_code, tva_tx,"; $sql.= " localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice,"; $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,"; $sql.= " info_bits,"; diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php index 7c0263f8376..132ab187777 100644 --- a/htdocs/contrat/document.php +++ b/htdocs/contrat/document.php @@ -55,7 +55,7 @@ $result = restrictedArea($user, 'contrat', $id); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php index 924958319a4..509467cc822 100644 --- a/htdocs/contrat/index.php +++ b/htdocs/contrat/index.php @@ -107,7 +107,7 @@ $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid"; $sql.= " AND (cd.statut != 4 OR (cd.statut = 4 AND (cd.date_fin_validite is null or cd.date_fin_validite >= '".$db->idate($now)."')))"; -$sql.= " AND c.entity IN (".getEntity('contract').")"; +$sql.= " AND c.entity IN (".getEntity('contract', 0).")"; if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " GROUP BY cd.statut"; @@ -144,7 +144,7 @@ $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd, ".MAIN_DB_PREFIX."contrat as c"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE cd.fk_contrat = c.rowid AND c.fk_soc = s.rowid"; $sql.= " AND (cd.statut = 4 AND cd.date_fin_validite < '".$db->idate($now)."')"; -$sql.= " AND c.entity IN (".getEntity('contract').")"; +$sql.= " AND c.entity IN (".getEntity('contract', 0).")"; if ($user->societe_id) $sql.=' AND c.fk_soc = '.$user->societe_id; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; $sql.= " GROUP BY cd.statut"; @@ -230,7 +230,7 @@ if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire) $sql .= " FROM ".MAIN_DB_PREFIX."contrat as c, ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.rowid = c.fk_soc"; - $sql.= " AND c.entity IN (".getEntity('contract').")"; + $sql.= " AND c.entity IN (".getEntity('contract', 0).")"; $sql.= " AND c.statut = 0"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND c.fk_soc = ".$socid; @@ -302,7 +302,7 @@ if (!$user->rights->societe->client->voir && !$socid) $sql.= " ".MAIN_DB_PREFIX. $sql.= " ".MAIN_DB_PREFIX."contrat as c"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat"; $sql.= " WHERE c.fk_soc = s.rowid"; -$sql.= " AND c.entity IN (".getEntity('contract').")"; +$sql.= " AND c.entity IN (".getEntity('contract', 0).")"; $sql.= " AND c.statut > 0"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; @@ -372,7 +372,7 @@ $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= ") LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; -$sql.= " WHERE c.entity IN (".getEntity('contract').")"; +$sql.= " WHERE c.entity IN (".getEntity('contract', 0).")"; $sql.= " AND cd.fk_contrat = c.rowid"; $sql.= " AND c.fk_soc = s.rowid"; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -450,7 +450,7 @@ $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; -$sql.= " WHERE c.entity IN (".getEntity('contract').")"; +$sql.= " WHERE c.entity IN (".getEntity('contract', 0).")"; $sql.= " AND c.statut = 1"; $sql.= " AND cd.statut = 0"; $sql.= " AND cd.fk_contrat = c.rowid"; @@ -529,7 +529,7 @@ $sql.= ", ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= ", ".MAIN_DB_PREFIX."contratdet as cd"; $sql.= " ) LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid"; -$sql.= " WHERE c.entity IN (".getEntity('contract').")"; +$sql.= " WHERE c.entity IN (".getEntity('contract', 0).")"; $sql.= " AND c.statut = 1"; $sql.= " AND cd.statut = 4"; $sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'"; diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 43cce90bd1c..a526a9bd78c 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -65,11 +65,11 @@ $month=GETPOST("month","int"); $optioncss = GETPOST('optioncss','alpha'); -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -86,10 +86,10 @@ $staticcontratligne=new ContratLigne($db); if ($search_status == '') $search_status=1; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $contextpage='contractlist'; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array($contextpage)); $extrafields = new ExtraFields($db); @@ -222,7 +222,7 @@ if ($search_user > 0) $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc"; } $sql.= " WHERE c.fk_soc = s.rowid "; -$sql.= ' AND c.entity IN ('.getEntity('contract', 1).')'; +$sql.= ' AND c.entity IN ('.getEntity('contract').')'; if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category; if ($socid) $sql.= " AND s.rowid = ".$db->escape($socid); if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; @@ -305,7 +305,7 @@ if ($resql) $i = 0; $arrayofselected=is_array($toselect)?$toselect:array(); - + $param=''; if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; @@ -323,7 +323,7 @@ if ($resql) $tmpkey=preg_replace('/search_options_/','',$key); if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } - + // List of mass actions available $arrayofmassactions = array( //'presend'=>$langs->trans("SendByMail"), @@ -332,7 +332,7 @@ if ($resql) if ($user->rights->contrat->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete"); if ($massaction == 'presend') $arrayofmassactions=array(); $massactionbutton=$form->selectMassAction('', $arrayofmassactions); - + print '
'; if ($optioncss != '') print ''; print ''; @@ -341,7 +341,7 @@ if ($resql) print ''; print ''; print ''; - + print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $totalnboflines, 'title_commercial.png', 0, '', '', $limit); if ($sall) @@ -349,16 +349,16 @@ if ($resql) foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); } - + $moreforfilter=''; - + // If the user can view prospects other than his' if ($user->rights->societe->client->voir || $socid) { $langs->load("commercial"); $moreforfilter.='
'; $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': '; - $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user,0,1,'maxwidth300'); + $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user,0,1,'maxwidth200'); $moreforfilter.='
'; } // If the user can view other users @@ -366,7 +366,7 @@ if ($resql) { $moreforfilter.='
'; $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; - $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300'); + $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200'); $moreforfilter.='
'; } // If the user can view categories of products @@ -376,15 +376,15 @@ if ($resql) $moreforfilter.='
'; $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': '; $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); - $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1); + $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1); $moreforfilter.='
'; } - + $parameters=array(); $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; else $moreforfilter = $hookmanager->resPrint; - + if (! empty($moreforfilter)) { print '
'; @@ -395,7 +395,7 @@ if ($resql) $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1); - + print '
'; print ''."\n"; @@ -514,7 +514,7 @@ if ($resql) print $searchpicto; print ''; print "\n"; - + print ''; if (! empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref","","$param",'',$sortfield,$sortorder); if (! empty($arrayfields['c.ref_customer']['checked'])) print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer","","$param",'',$sortfield,$sortorder); @@ -530,12 +530,14 @@ if ($resql) // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - foreach($extrafields->attribute_label as $key => $val) + foreach($extrafields->attribute_label as $key => $val) { - if (! empty($arrayfields["ef.".$key]['checked'])) + if (! empty($arrayfields["ef.".$key]['checked'])) { $align=$extrafields->getAlignFlag($key); - print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + $sortonfield = "ef.".$key; + if (! empty($extrafields->attribute_computed[$key])) $sortonfield=''; + print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); } } } @@ -558,12 +560,12 @@ if ($resql) while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); - + $contracttmp->ref=$obj->ref; $contracttmp->id=$obj->rowid; $contracttmp->ref_customer=$obj->ref_customer; $contracttmp->ref_supplier=$obj->ref_supplier; - + print ''; if (! empty($arrayfields['c.ref']['checked'])) { @@ -578,15 +580,15 @@ if ($resql) } print ''; } - if (! empty($arrayfields['c.ref_customer']['checked'])) + if (! empty($arrayfields['c.ref_customer']['checked'])) { print ''; } - if (! empty($arrayfields['c.ref_supplier']['checked'])) + if (! empty($arrayfields['c.ref_supplier']['checked'])) { print ''; } - if (! empty($arrayfields['s.nom']['checked'])) + if (! empty($arrayfields['s.nom']['checked'])) { print ''; } @@ -629,7 +631,7 @@ if ($resql) print $typenArray[$obj->typent_code]; print ''; if (! $i) $totalarray['nbfield']++; - } + } if (! empty($arrayfields['sale_representative']['checked'])) { // Sales representatives @@ -713,7 +715,7 @@ if ($resql) if (! $i) $totalarray['nbfield']++; } // Status - if (! empty($arrayfields['status']['checked'])) + if (! empty($arrayfields['status']['checked'])) { print ''; print ''; @@ -730,7 +732,7 @@ if ($resql) } print ''; if (! $i) $totalarray['nbfield']++; - + print "\n"; $i++; } @@ -738,7 +740,7 @@ if ($resql) print '
'.$obj->ref_customer.''.$obj->ref_supplier.''.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.''.($obj->nb_initial>0?$obj->nb_initial:'').''.($obj->nb_running>0?$obj->nb_running:'').'
'; print '
'; - + print ''; } else diff --git a/htdocs/contrat/services.php b/htdocs/contrat/services.php index adac837f3e0..aea03a73df5 100644 --- a/htdocs/contrat/services.php +++ b/htdocs/contrat/services.php @@ -33,11 +33,11 @@ $langs->load("products"); $langs->load("contracts"); $langs->load("companies"); -$limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit; +$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); -if ($page == -1) { $page = 0; } +if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -77,7 +77,7 @@ $filter_opcloture=GETPOST('filter_opcloture'); // Initialize context for list $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'servicelist'.$mode; -// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array($contextpage)); $extrafields = new ExtraFields($db); @@ -372,7 +372,9 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab if (! empty($arrayfields["ef.".$key]['checked'])) { $align=$extrafields->getAlignFlag($key); - print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + $sortonfield = "ef.".$key; + if (! empty($extrafields->attribute_computed[$key])) $sortonfield=''; + print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); } } } @@ -516,23 +518,23 @@ $var=True; $i=0; while ($i < min($num,$limit)) { $obj = $db->fetch_object($resql); - + $contractstatic->id=$obj->cid; $contractstatic->ref=$obj->ref?$obj->ref:$obj->cid; - - + + print ''; - + // Ref - if (! empty($arrayfields['c.ref']['checked'])) + if (! empty($arrayfields['c.ref']['checked'])) { print ''; print $contractstatic->getNomUrl(1,16); print ''; } // Service - if (! empty($arrayfields['p.description']['checked'])) + if (! empty($arrayfields['p.description']['checked'])) { print ''; if ($obj->pid) @@ -552,9 +554,9 @@ while ($i < min($num,$limit)) } print ''; } - + // Third party - if (! empty($arrayfields['s.nom']['checked'])) + if (! empty($arrayfields['s.nom']['checked'])) { print ''; $companystatic->id=$obj->socid; @@ -563,9 +565,9 @@ while ($i < min($num,$limit)) print $companystatic->getNomUrl(1,'customer',28); print ''; } - + // Start date - if (! empty($arrayfields['cd.date_ouverture_prevue']['checked'])) + if (! empty($arrayfields['cd.date_ouverture_prevue']['checked'])) { print ''; print ($obj->date_ouverture_prevue?dol_print_date($db->jdate($obj->date_ouverture_prevue)):' '); @@ -574,15 +576,15 @@ while ($i < min($num,$limit)) else print '    '; print ''; } - if (! empty($arrayfields['cd.date_ouverture']['checked'])) + if (! empty($arrayfields['cd.date_ouverture']['checked'])) { print ''.($obj->date_ouverture?dol_print_date($db->jdate($obj->date_ouverture)):' ').''; } // End date - if (! empty($arrayfields['cd.date_fin_validite']['checked'])) + if (! empty($arrayfields['cd.date_fin_validite']['checked'])) { print ''.($obj->date_fin_validite?dol_print_date($db->jdate($obj->date_fin_validite)):' '); - if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5) + if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5) { $warning_delay=$conf->contrat->services->expires->warning_delay / 3600 / 24; $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days"); @@ -591,7 +593,7 @@ while ($i < min($num,$limit)) else print '    '; print ''; } - if (! empty($arrayfields['cd.date_cloture']['checked'])) + if (! empty($arrayfields['cd.date_cloture']['checked'])) { print ''.dol_print_date($db->jdate($obj->date_cloture)).''; } @@ -658,7 +660,7 @@ while ($i < min($num,$limit)) } print ''; if (! $i) $totalarray['nbfield']++; - + print "\n"; $i++; } diff --git a/htdocs/core/actions_builddoc.inc.php b/htdocs/core/actions_builddoc.inc.php index 94f4229e0db..076a7a6a035 100644 --- a/htdocs/core/actions_builddoc.inc.php +++ b/htdocs/core/actions_builddoc.inc.php @@ -68,7 +68,7 @@ if ($action == 'builddoc' && $permissioncreate) $outputlangs = $langs; $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->thirdparty->default_lang)) $newlang=$object->thirdparty->default_lang; // for proposal, order, invoice, ... if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($object->default_lang)) $newlang=$object->default_lang; // for thirdparty if (! empty($newlang)) diff --git a/htdocs/core/actions_dellink.inc.php b/htdocs/core/actions_dellink.inc.php index 63218dde739..7d20f124277 100644 --- a/htdocs/core/actions_dellink.inc.php +++ b/htdocs/core/actions_dellink.inc.php @@ -30,15 +30,15 @@ $dellinkid = GETPOST('dellinkid','int'); $addlinkid = GETPOST('idtolinkto','int'); // Link invoice to order -if ($action == 'addlink' && ! empty($permissiondellink) && ! GETPOST('cancel') && $id > 0 && $addlinkid > 0) +if ($action == 'addlink' && ! empty($permissiondellink) && ! GETPOST('cancel','alpha') && $id > 0 && $addlinkid > 0) { $object->fetch($id); $object->fetch_thirdparty(); - $result = $object->add_object_linked(GETPOST('addlink'), $addlinkid); + $result = $object->add_object_linked(GETPOST('addlink','alpha'), $addlinkid); } // Delete link -if ($action == 'dellink' && ! empty($permissiondellink) && ! GETPOST('cancel') && $dellinkid > 0) +if ($action == 'dellink' && ! empty($permissiondellink) && ! GETPOST('cancel','alpha') && $dellinkid > 0) { $result=$object->deleteObjectLinked(0, '', 0, '', $dellinkid); if ($result < 0) setEventMessages($object->error,$object->errors,'errors'); diff --git a/htdocs/core/actions_lineupdown.inc.php b/htdocs/core/actions_lineupdown.inc.php index 825bdac1615..bcf251e0763 100644 --- a/htdocs/core/actions_lineupdown.inc.php +++ b/htdocs/core/actions_lineupdown.inc.php @@ -35,7 +35,7 @@ if ($action == 'up' && $permissiontoedit) // Define output language $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); @@ -57,7 +57,7 @@ if ($action == 'down' && $permissiontoedit) // Define output language $outputlangs = $langs; $newlang = ''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; if (! empty($newlang)) { $outputlangs = new Translate("", $conf); diff --git a/htdocs/core/actions_linkedfiles.inc.php b/htdocs/core/actions_linkedfiles.inc.php index 018baab0cc0..f21c41d828d 100644 --- a/htdocs/core/actions_linkedfiles.inc.php +++ b/htdocs/core/actions_linkedfiles.inc.php @@ -73,7 +73,7 @@ if ($action == 'confirm_deletefile' && $confirm == 'yes') $ret = dol_delete_file($file, 0, 0, 0, $object); if (! empty($fileold)) dol_delete_file($fileold, 0, 0, 0, $object); // Delete file using old path - + // Si elle existe, on efface la vignette if (preg_match('/(\.jpg|\.jpeg|\.bmp|\.gif|\.png|\.tiff)$/i',$file,$regs)) { @@ -152,19 +152,28 @@ elseif ($action == 'renamefile' && GETPOST('renamefilesave')) { $filenamefrom=dol_sanitizeFileName(GETPOST('renamefilefrom')); $filenameto=dol_sanitizeFileName(GETPOST('renamefileto')); + + // Security: + // Disallow file with some extensions. We rename them. + // Because if we put the documents directory into a directory inside web root (very bad), this allows to execute on demand arbitrary code. + if (preg_match('/\.htm|\.html|\.php|\.pl|\.cgi$/i',$filenameto) && empty($conf->global->MAIN_DOCUMENT_IS_OUTSIDE_WEBROOT_SO_NOEXE_NOT_REQUIRED)) + { + $filenameto.= '.noexe'; + } + if ($filenamefrom && $filenameto) { $srcpath = $upload_dir.'/'.$filenamefrom; $destpath = $upload_dir.'/'.$filenameto; - + $result = dol_move($srcpath, $destpath); - if ($result) + if ($result) { $object->addThumbs($destpath); - + // TODO Add revert function of addThumbs //$object->delThumbs($srcpath); - + setEventMessages($langs->trans("FileRenamed"), null); } else diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 92d1011b923..5313b79dc04 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -24,20 +24,22 @@ // $massaction must be defined // $objectclass and $$objectlabel must be defined -// $uploaddir (example $conf->projet->dir_output . "/";) +// $parameters, $object, $action must be defined for the hook. + +// $uploaddir may be defined (example to $conf->projet->dir_output."/";) // $toselect may be defined // Protection -if (empty($objectclass) || empty($uploaddir)) +if (empty($objectclass) || empty($uploaddir)) { dol_print_error(null, 'include of actions_massactions.inc.php is done but var $massaction or $objectclass or $uploaddir was not defined'); exit; } -// Mass actions. Controls on number of lines checked -$maxformassaction=1000; +// Mass actions. Controls on number of lines checked. +$maxformassaction=(empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS)?1000:$conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS); if (! empty($massaction) && count($toselect) < 1) { $error++; @@ -87,7 +89,7 @@ if (! $error && $massaction == 'confirm_presend') } } //var_dump($listofobjectthirdparties);exit; - + foreach ($listofobjectthirdparties as $thirdpartyid) { $result = $thirdparty->fetch($thirdpartyid); @@ -144,7 +146,7 @@ if (! $error && $massaction == 'confirm_presend') { //var_dump($object); //var_dump($thirdpartyid.' - '.$objectid.' - '.$object->statut); - + if ($objectclass == 'Facture' && $object->statut != Facture::STATUS_VALIDATED) { $nbignored++; @@ -157,7 +159,7 @@ if (! $error && $massaction == 'confirm_presend') $resaction.='
'.$langs->trans('ErrorOnlyOrderNotDraftCanBeSentInMassAction',$object->ref).'

'; continue; } - + // Read document // TODO Use future field $object->fullpathdoc to know where is stored default file // TODO If not defined, use $object->modelpdf (or defaut invoice config) to know what is template to use to regenerate doc. @@ -202,7 +204,7 @@ if (! $error && $massaction == 'confirm_presend') dol_syslog('Failed to read file: '.$file, LOG_WARNING); continue; } - + //var_dump($listofqualifiedref); } @@ -252,9 +254,9 @@ if (! $error && $massaction == 'confirm_presend') $filepath = $attachedfiles['paths']; $filename = $attachedfiles['names']; $mimetype = $attachedfiles['mimes']; - + //var_dump($filepath); - + // Send mail require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'); $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,$sendtobcc,$deliveryreceipt,-1); @@ -280,7 +282,7 @@ if (! $error && $massaction == 'confirm_presend') if ($objectclass == 'Supplier_Proposal') $actiontypecode='AC_SUP_PRO'; if ($objectclass == 'CommandeFournisseur') $actiontypecode='AC_SUP_ORD'; if ($objectclass == 'FactureFournisseur') $actiontypecode='AC_SUP_INV';*/ - + $actionmsg=$langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto; if ($message) { @@ -290,7 +292,7 @@ if (! $error && $massaction == 'confirm_presend') $actionmsg = dol_concatdesc($actionmsg, $message); } $actionmsg2=''; - + // Initialisation donnees $object->sendtoid = 0; $object->actionmsg = $actionmsg; // Long text @@ -335,7 +337,7 @@ if (! $error && $massaction == 'confirm_presend') $resaction.=$langs->trans("NbSelected").': '.count($toselect)."\n
"; $resaction.=$langs->trans("NbIgnored").': '.($nbignored?$nbignored:0)."\n
"; $resaction.=$langs->trans("NbSent").': '.($nbsent?$nbsent:0)."\n
"; - + if ($nbsent) { $action=''; // Do not show form post if there was at least one successfull sent @@ -359,7 +361,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; - + $objecttmp=new $objectclass($db); $listofobjectid=array(); $listofobjectthirdparties=array(); @@ -398,7 +400,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se // Define output language (Here it is not used because we do only merging existing PDF) $outputlangs = $langs; $newlang=''; - if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->thirdparty->default_lang; if (! empty($newlang)) { @@ -425,21 +427,21 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se if (count($files)>0) { - + $now=dol_now(); $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf'; - + $input_files = ''; foreach($files as $f) { $input_files.=' '.escapeshellarg($f); } - + $cmd = 'pdftk '.$input_files.' cat output '.escapeshellarg($file); exec($cmd); - + if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK)); - + $langs->load("exports"); setEventMessages($langs->trans('FileSuccessfullyBuilt',$filename.'_'.dol_print_date($now,'dayhourlog')), null, 'mesgs'); } @@ -447,7 +449,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se { setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); } - + } else { // Create empty PDF @@ -481,7 +483,7 @@ if (! $error && $massaction == "builddoc" && $permtoread && ! GETPOST('button_se // Defined name of merged file $filename=strtolower(dol_sanitizeFileName($langs->transnoentities($objectlabel))); $filename=preg_replace('/\s/','_',$filename); - + // Save merged file if ($filter=='paye:0') { @@ -534,7 +536,7 @@ if (! $error && $massaction == 'delete' && $permtodelete) $result=$objecttmp->fetch($toselectid); if ($result > 0) { - if ($objecttmp->element == 'societe') $result = $objecttmp->delete($objecttmp->id, $user, 1); + if (in_array($objecttmp->element, array('societe','member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1); else $result = $objecttmp->delete($user); if ($result <= 0) { @@ -565,6 +567,11 @@ if (! $error && $massaction == 'delete' && $permtodelete) //var_dump($listofobjectthirdparties);exit; } +$parameters['toselect']=$toselect; +$parameters['uploaddir']=$uploaddir; + +$reshook=$hookmanager->executeHooks('doMassActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index dded23e6cbf..a796a94c68c 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -31,8 +31,8 @@ /* * Add file in email form -*/ -if (GETPOST('addfile')) + */ +if (GETPOST('addfile','alpha')) { $trackid = GETPOST('trackid','aZ09'); @@ -68,7 +68,7 @@ if (! empty($_POST['removedfile']) && empty($_POST['removAll'])) /* * Remove all files in email form */ -if (GETPOST('removAll')) +if (GETPOST('removAll','alpha')) { $trackid = GETPOST('trackid','aZ09'); @@ -137,7 +137,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO { $sendtosocid=$possibleaccounts[1]['id']; $result=$object->fetch($sendtosocid); - + setEventMessages($langs->trans('ErrorFoundMoreThanOneRecordWithEmail',$_POST['sendto'],$object->name), null, 'mesgs'); } else @@ -229,7 +229,12 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO if (dol_strlen($sendto)) { - require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; + // Define $urlwithroot + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + + require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php'; $langs->load("commercial"); @@ -254,11 +259,17 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>'; $message = $_POST['message']; - + + // Make a change into HTML code to allow to include images from medias directory with an external reabable URL. + // + // become + // + $message=preg_replace('/()/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message); + $sendtobcc= GETPOST('sendtoccc'); - if ($mode == 'emailfromproposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); - if ($mode == 'emailfromorder') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)); - if ($mode == 'emailfrominvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)); + if ($mode == 'emailfromproposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); + if ($mode == 'emailfromorder') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)); + if ($mode == 'emailfrominvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)); if ($mode == 'emailfromsupplierproposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO)); if ($mode == 'emailfromsupplierorder') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO)); if ($mode == 'emailfromsupplierinvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO)); @@ -371,7 +382,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO if (is_object($object)) { if (empty($actiontypecode)) $actiontypecode='AC_OTH_AUTO'; // Event insert into agenda automatically - + $object->socid = $sendtosocid; // To link to a company $object->sendtoid = $sendtoid; // To link to contacts/addresses. This is an array. $object->actiontypecode = $actiontypecode; // Type of event ('AC_OTH', 'AC_OTH_AUTO', 'AC_XXX'...) @@ -392,7 +403,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO } } } - + if ($error) { dol_print_error($db); @@ -403,7 +414,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO // This avoid sending mail twice if going out and then back to page $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); setEventMessages($mesg, null, 'mesgs'); - if ($conf->dolimail->enabled) + if ($conf->dolimail->enabled) { header('Location: '.$_SERVER["PHP_SELF"].'?'.($paramname?$paramname:'id').'='.(is_object($object)?$object->id:'').'&'.($paramname2?$paramname2:'mid').'='.$parm2val); exit; @@ -436,7 +447,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO { $langs->load("errors"); setEventMessages($langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("MailTo")), null, 'warnings'); - dol_syslog('Try to send email with no recipiend defined', LOG_WARNING); + dol_syslog('Try to send email with no recipient defined', LOG_WARNING); $action = 'presend'; } } diff --git a/htdocs/core/actions_setmoduleoptions.inc.php b/htdocs/core/actions_setmoduleoptions.inc.php new file mode 100644 index 00000000000..03b33b19eb1 --- /dev/null +++ b/htdocs/core/actions_setmoduleoptions.inc.php @@ -0,0 +1,86 @@ + + * + * 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/actions_setnotes.inc.php + * \brief Code for actions on setting notes of object page + */ + + +// $action must be defined +// $_FILES may be defined +// $nomessageinsetmoduleoptions can be set to 1 + +// Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) +if ($action == 'setModuleOptions') +{ + $db->begin(); + + // Process common param fields + foreach($_POST as $key => $val) + { + if (preg_match('/^param(\d*)$/', $key, $reg)) // Works for POST['param'], POST['param1'], POST['param2'], ... + { + $param=GETPOST("param".$reg[1],'alpha'); + $value=GETPOST("value".$reg[1],'alpha'); + if ($param) + { + $res = dolibarr_set_const($db,$param,$value,'chaine',0,'',$conf->entity); + if (! $res > 0) $error++; + } + } + } + + // Process upload fields + if (GETPOST('upload','alpha') && GETPOST('keyforuploaddir','aZ09')) + { + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $keyforuploaddir=GETPOST('keyforuploaddir','aZ09'); + $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->$keyforuploaddir))); + foreach($listofdir as $key=>$tmpdir) + { + $tmpdir=trim($tmpdir); + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); + if (! $tmpdir) { + unset($listofdir[$key]); continue; + } + if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); + else + { + $upload_dir=$tmpdir; + } + } + if ($upload_dir) + { + $result = dol_add_file_process($upload_dir, 0, 1, 'uploadfile', ''); + if ($result <= 0) $error++; + } + } + + if (! $error) + { + $db->commit(); + if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + $db->rollback(); + if (empty($nomessageinsetmoduleoptions)) setEventMessages($langs->trans("SetupNotSaved"), null, 'errors'); + } +} + diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php index 8d8f48ec141..709d07c0832 100644 --- a/htdocs/core/ajax/ajaxdirpreview.php +++ b/htdocs/core/ajax/ajaxdirpreview.php @@ -49,7 +49,7 @@ if (! isset($mode) || $mode != 'noajax') // For ajax call $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); - if ($page == -1) { $page = 0; } + if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; @@ -139,7 +139,7 @@ if (! dol_is_dir($upload_dir)) } print ''."\n"; -print ''."\n"; +//print ''."\n"; $param=($sortfield?'&sortfield='.$sortfield:'').($sortorder?'&sortorder='.$sortorder:''); @@ -162,21 +162,13 @@ if ($type == 'directory') // Auto area for suppliers invoices else if ($module == 'invoice') $upload_dir = $conf->facture->dir_output; // Auto area for suppliers invoices - else if ($module == 'invoice_supplier') - { - $relativepath='facture'; - $upload_dir = $conf->fournisseur->dir_output.'/'.$relativepath; - } + else if ($module == 'invoice_supplier') $upload_dir = $conf->fournisseur->facture->dir_output; // Auto area for customers orders else if ($module == 'propal') $upload_dir = $conf->propal->dir_output; // Auto area for customers orders else if ($module == 'order') $upload_dir = $conf->commande->dir_output; // Auto area for suppliers orders - else if ($module == 'order_supplier') - { - $relativepath='commande'; - $upload_dir = $conf->fournisseur->dir_output.'/'.$relativepath; - } + else if ($module == 'order_supplier') $upload_dir = $conf->fournisseur->commande->dir_output; // Auto area for suppliers invoices else if ($module == 'contract') $upload_dir = $conf->contrat->dir_output; // Auto area for products @@ -198,6 +190,8 @@ if ($type == 'directory') $param.='&module='.$module; $textifempty=($section?$langs->trans("NoFileFound"):($showonrightsize=='featurenotyetavailable'?$langs->trans("FeatureNotYetAvailable"):$langs->trans("NoFileFound"))); + if ($module == 'company') $excludefiles[]='^contact$'; // The subdir 'contact' contains files of contacts with no id of thirdparty. + $filearray=dol_dir_list($upload_dir,"files",1,'', $excludefiles, $sortfield, $sorting,1); $formfile->list_of_autoecmfiles($upload_dir,$filearray,$module,$param,1,'',$user->rights->ecm->upload,1,$textifempty,$maxlengthname,$url); } diff --git a/htdocs/core/ajax/bankconciliate.php b/htdocs/core/ajax/bankconciliate.php index 24318be6cf8..65620c5429c 100644 --- a/htdocs/core/ajax/bankconciliate.php +++ b/htdocs/core/ajax/bankconciliate.php @@ -45,7 +45,7 @@ $action=GETPOST('action','aZ09'); //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header. top_httphead(); -//print ''."\n"; +//print ''."\n"; if (($user->rights->banque->modifier || $user->rights->banque->consolidate) && $action == 'dvnext') { diff --git a/htdocs/core/ajax/box.php b/htdocs/core/ajax/box.php index 7826747769b..612f38bb05b 100644 --- a/htdocs/core/ajax/box.php +++ b/htdocs/core/ajax/box.php @@ -50,7 +50,7 @@ $userid=GETPOST('userid','int'); //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header. top_httphead(); -print ''."\n"; +print ''."\n"; // Add a box if ($boxid > 0 && $zone !='' && $userid > 0) diff --git a/htdocs/core/ajax/constantonoff.php b/htdocs/core/ajax/constantonoff.php index 331a5e87513..f79753260d7 100644 --- a/htdocs/core/ajax/constantonoff.php +++ b/htdocs/core/ajax/constantonoff.php @@ -45,7 +45,7 @@ $name=GETPOST('name','alpha'); //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header. top_httphead(); -print ''."\n"; +//print ''."\n"; // Registering the location of boxes if (! empty($action) && ! empty($name)) diff --git a/htdocs/core/ajax/contacts.php b/htdocs/core/ajax/contacts.php index c3788a8baeb..1c7c7a56e4b 100644 --- a/htdocs/core/ajax/contacts.php +++ b/htdocs/core/ajax/contacts.php @@ -41,20 +41,20 @@ $showempty = GETPOST('showempty','int'); top_httphead(); -//print ''."\n"; +//print ''."\n"; // Load original field value if (! empty($id) && ! empty($action) && ! empty($htmlname)) { $form = new Form($db); - + $return=array(); if (empty($showempty)) $showempty=0; - + $return['value'] = $form->selectcontacts($id,'',$htmlname,$showempty,'','',0,'',true); $return['num'] = $form->num; $return['error'] = $form->error; - + echo json_encode($return); } diff --git a/htdocs/core/ajax/extraparams.php b/htdocs/core/ajax/extraparams.php index 510ef8a1cf8..f8a636e52a5 100644 --- a/htdocs/core/ajax/extraparams.php +++ b/htdocs/core/ajax/extraparams.php @@ -40,17 +40,17 @@ $type = GETPOST('type', 'alpha'); top_httphead(); -print ''."\n"; +print ''."\n"; if(! empty($id) && ! empty($element) && ! empty($htmlelement) && ! empty($type)) { $value = GETPOST('value','alpha'); $params=array(); - + dol_syslog("AjaxSetExtraParameters id=".$id." element=".$element." htmlelement=".$htmlelement." type=".$type." value=".$value, LOG_DEBUG); - + $classpath = $subelement = $element; - + // For compatibility if ($element == 'order' || $element == 'commande') { $classpath = $subelement = 'commande'; } else if ($element == 'propal') { $classpath = 'comm/propal'; $subelement = 'propal'; } @@ -60,19 +60,19 @@ if(! empty($id) && ! empty($element) && ! empty($htmlelement) && ! empty($type)) else if ($element == 'deplacement') { $classpath = 'compta/deplacement'; $subelement = 'deplacement'; } else if ($element == 'order_supplier') { $classpath = 'fourn'; $subelement = 'fournisseur.commande'; } else if ($element == 'invoice_supplier') { $classpath = 'fourn'; $subelement = 'fournisseur.facture'; } - + dol_include_once('/'.$classpath.'/class/'.$subelement.'.class.php'); - + if ($element == 'order_supplier') { $classname = 'CommandeFournisseur'; } else if ($element == 'invoice_supplier') { $classname = 'FactureFournisseur'; } else $classname = ucfirst($subelement); - + $object = new $classname($db); $object->fetch($id); - + $params[$htmlelement] = array($type => $value); $object->extraparams = array_merge($object->extraparams, $params); - + $result=$object->setExtraParameters(); } diff --git a/htdocs/core/ajax/loadinplace.php b/htdocs/core/ajax/loadinplace.php index de3a4e57d19..7e9e541c768 100644 --- a/htdocs/core/ajax/loadinplace.php +++ b/htdocs/core/ajax/loadinplace.php @@ -41,7 +41,7 @@ $fk_element = GETPOST('fk_element','alpha'); top_httphead(); -//print ''."\n"; +//print ''."\n"; // Load original field value if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($fk_element)) diff --git a/htdocs/core/ajax/objectonoff.php b/htdocs/core/ajax/objectonoff.php index 6ac5abd3bbb..37173ed9943 100644 --- a/htdocs/core/ajax/objectonoff.php +++ b/htdocs/core/ajax/objectonoff.php @@ -42,7 +42,7 @@ $object = new GenericObject($db); top_httphead(); -print ''."\n"; +print ''."\n"; // Registering new values if (($action == 'set') && ! empty($id)) diff --git a/htdocs/core/ajax/price.php b/htdocs/core/ajax/price.php index 5c891df14d5..d4a101fb497 100644 --- a/htdocs/core/ajax/price.php +++ b/htdocs/core/ajax/price.php @@ -39,7 +39,7 @@ $tva_tx = str_replace('*','',GETPOST('tva_tx','alpha')); top_httphead(); -//print ''."\n"; +//print ''."\n"; // Load original field value if (! empty($output) && isset($amount) && isset($tva_tx)) diff --git a/htdocs/core/ajax/row.php b/htdocs/core/ajax/row.php index 331b4ceaac8..6e358bdbd88 100644 --- a/htdocs/core/ajax/row.php +++ b/htdocs/core/ajax/row.php @@ -18,8 +18,8 @@ /** * \file htdocs/core/ajax/row.php - * \brief File to return Ajax response on Row move. - * This ajax page is called when doing an up or down drag and drop. + * \brief File to return Ajax response on Row move. + * This ajax page is called when doing an up or down drag and drop. */ if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disable token renewal @@ -40,7 +40,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/genericobject.class.php'; top_httphead(); -print ''."\n"; +print ''."\n"; // Registering the location of boxes if ((isset($_POST['roworder']) && ! empty($_POST['roworder'])) && (isset($_POST['table_element_line']) && ! empty($_POST['table_element_line'])) diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 48797dd0432..eb04379a778 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -54,7 +54,7 @@ savemethodname: top_httphead(); -//print ''."\n"; +//print ''."\n"; //print_r($_POST); // Load original field value diff --git a/htdocs/core/ajax/security.php b/htdocs/core/ajax/security.php index 28a53a87679..cc7335618d0 100644 --- a/htdocs/core/ajax/security.php +++ b/htdocs/core/ajax/security.php @@ -17,8 +17,8 @@ /** * \file htdocs/core/ajax/security.php - * \brief This ajax component is used to generated has keys for security purposes - * like key to use into URL to protect them. + * \brief This ajax component is used to generated has keys for security purposes + * like key to use into URL to protect them. */ if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL','1'); // Disables token renewal @@ -38,7 +38,7 @@ require '../../main.inc.php'; //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header. top_httphead(); -//print ''."\n"; +//print ''."\n"; // Registering the location of boxes if (isset($_GET['action']) && ! empty($_GET['action'])) diff --git a/htdocs/core/ajax/vatrates.php b/htdocs/core/ajax/vatrates.php index fc30a13afec..ac9691bfa25 100644 --- a/htdocs/core/ajax/vatrates.php +++ b/htdocs/core/ajax/vatrates.php @@ -41,7 +41,7 @@ $productid = (GETPOST('productid','int')?GETPOST('productid','int'):0); top_httphead(); -//print ''."\n"; +//print ''."\n"; // Load original field value if (! empty($id) && ! empty($action) && ! empty($htmlname)) diff --git a/htdocs/core/ajax/ziptown.php b/htdocs/core/ajax/ziptown.php index 30e0211ece1..9fa475039d9 100644 --- a/htdocs/core/ajax/ziptown.php +++ b/htdocs/core/ajax/ziptown.php @@ -45,7 +45,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; //top_htmlhead("", "", 1); // Replaced with top_httphead. An ajax page does not need html header. top_httphead(); -//print ''."\n"; +//print ''."\n"; dol_syslog("GET is ".join(',',$_GET).', MAIN_USE_ZIPTOWN_DICTIONNARY='.(empty($conf->global->MAIN_USE_ZIPTOWN_DICTIONNARY)?'':$conf->global->MAIN_USE_ZIPTOWN_DICTIONNARY)); //var_dump($_GET); diff --git a/htdocs/core/boxes/box_actions.php b/htdocs/core/boxes/box_actions.php index e856d52c2b6..f6d9d03dccf 100644 --- a/htdocs/core/boxes/box_actions.php +++ b/htdocs/core/boxes/box_actions.php @@ -44,6 +44,21 @@ class box_actions extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param='') + { + global $user; + + $this->db = $db; + + $this->hidden = ! ($user->rights->agenda->myactions->read); + } + /** * Load data for box to show them later * @@ -156,8 +171,8 @@ class box_actions extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'align' => 'left', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -173,8 +188,8 @@ class box_actions extends ModeleBoxes function showBox($head = null, $contents = null, $nooutput=0) { global $langs, $conf; - parent::showBox($this->info_box_head, $this->info_box_contents); - $out=''; + $out = parent::showBox($this->info_box_head, $this->info_box_contents); + if (! empty($conf->global->SHOW_DIALOG_HOMEPAGE)) { $actioncejour=false; @@ -191,7 +206,7 @@ class box_actions extends ModeleBoxes // on affiche que les évènement du jours ou passé // qui ne sont pas à 100% $actioncejour=true; - + // TR $logo=$contents[$line][0]['logo']; $label=$contents[$line][1]['text']; diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index 96a451f70f8..8d8b2962688 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -51,11 +51,17 @@ class box_activity extends ModeleBoxes */ function __construct($db,$param) { - global $conf; + global $conf, $user; $this->db=$db; + // FIXME: Pb into some status - $this->enabled=$conf->global->MAIN_FEATURES_LEVEL; // Not enabled by default due to bugs (see previous comments) + $this->enabled=($conf->global->MAIN_FEATURES_LEVEL); // Not enabled by default due to bugs (see previous comments) + + $this->hidden= ! ((! empty($conf->facture->enabled) && $user->rights->facture->lire) + || (! empty($conf->commande->enabled) && $user->rights->commande->lire) + || (! empty($conf->propal->enabled) && $user->rights->propale->lire) + ); } /** @@ -352,7 +358,7 @@ class box_activity extends ModeleBoxes } // list the summary of the propals - if (! empty($conf->propal->enabled) && $user->rights->propal->lire) + if (! empty($conf->propal->enabled) && $user->rights->propale->lire) { include_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; $propalstatic=new Propal($db); @@ -456,10 +462,10 @@ class box_activity extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_bookmarks.php b/htdocs/core/boxes/box_bookmarks.php index b6df56f52a2..34cf15497c6 100644 --- a/htdocs/core/boxes/box_bookmarks.php +++ b/htdocs/core/boxes/box_bookmarks.php @@ -40,6 +40,21 @@ class box_bookmarks extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->bookmark->lire); + } + /** * Load data for box to show them later * @@ -124,8 +139,8 @@ class box_bookmarks extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'align' => 'left', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -136,11 +151,11 @@ class box_bookmarks extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_clients.php b/htdocs/core/boxes/box_clients.php index 0649d43a049..a293b5166a2 100644 --- a/htdocs/core/boxes/box_clients.php +++ b/htdocs/core/boxes/box_clients.php @@ -58,6 +58,8 @@ class box_clients extends ModeleBoxes // disable box for such cases if (! empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled=0; // disabled by this option + + $this->hidden = ! ($user->rights->societe->lire && empty($user->socid)); } /** @@ -90,7 +92,7 @@ class box_clients extends ModeleBoxes $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.client IN (1, 3)"; - $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; + $sql.= " AND s.entity IN (".getEntity('societe').")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($user->societe_id) $sql.= " AND s.rowid = $user->societe_id"; $sql.= " ORDER BY s.tms DESC"; @@ -146,8 +148,10 @@ class box_clients extends ModeleBoxes } } else { - $this->info_box_contents[0][0] = array('align' => 'left', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -158,11 +162,11 @@ class box_clients extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_commandes.php b/htdocs/core/boxes/box_commandes.php index be9a868109d..9e1e89d60fc 100644 --- a/htdocs/core/boxes/box_commandes.php +++ b/htdocs/core/boxes/box_commandes.php @@ -44,6 +44,21 @@ class box_commandes extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->commande->lire); + } + /** * Load data for box to show them later * @@ -165,8 +180,8 @@ class box_commandes extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'align' => 'left', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -177,11 +192,11 @@ class box_commandes extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_comptes.php b/htdocs/core/boxes/box_comptes.php index 2372a31f035..f68393df6a5 100644 --- a/htdocs/core/boxes/box_comptes.php +++ b/htdocs/core/boxes/box_comptes.php @@ -61,6 +61,8 @@ class box_comptes extends ModeleBoxes // disable module for such cases $listofmodulesforexternal=explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL); if (! in_array('banque',$listofmodulesforexternal) && ! empty($user->societe_id)) $this->enabled=0; // disabled for external users + + $this->hidden = ! ($user->rights->banque->lire); } /** @@ -158,8 +160,8 @@ class box_comptes extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } @@ -171,11 +173,11 @@ class box_comptes extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_contacts.php b/htdocs/core/boxes/box_contacts.php index d6c38a9fce8..a67d2c3ac02 100644 --- a/htdocs/core/boxes/box_contacts.php +++ b/htdocs/core/boxes/box_contacts.php @@ -45,6 +45,21 @@ class box_contacts extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->societe->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -69,7 +84,7 @@ class box_contacts extends ModeleBoxes $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON sp.fk_soc = s.rowid"; if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; - $sql.= " WHERE sp.entity IN (".getEntity('societe', 1).")"; + $sql.= " WHERE sp.entity IN (".getEntity('societe').")"; if (! $user->rights->societe->client->voir && ! $user->societe_id) $sql.= " AND sp.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($user->societe_id) $sql.= " AND sp.fk_soc = ".$user->societe_id; $sql.= " ORDER BY sp.tms DESC"; @@ -151,8 +166,8 @@ class box_contacts extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'align' => 'left', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } @@ -164,11 +179,11 @@ class box_contacts extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_contracts.php b/htdocs/core/boxes/box_contracts.php index 7585c5d931c..59db96b08aa 100644 --- a/htdocs/core/boxes/box_contracts.php +++ b/htdocs/core/boxes/box_contracts.php @@ -43,6 +43,21 @@ class box_contracts extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->contrat->lire); + } + /** * Load data for box to show them later * @@ -134,7 +149,7 @@ class box_contracts extends ModeleBoxes if ($num==0) $this->info_box_contents[$line][0] = array( - 'td' => 'align="center"', + 'td' => 'align="center opacitymedium"', 'text'=>$langs->trans("NoRecordedContracts"), ); @@ -148,8 +163,8 @@ class box_contracts extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -160,11 +175,11 @@ class box_contracts extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_external_rss.php b/htdocs/core/boxes/box_external_rss.php index 14e542ff101..264f05b1f03 100644 --- a/htdocs/core/boxes/box_external_rss.php +++ b/htdocs/core/boxes/box_external_rss.php @@ -188,11 +188,11 @@ class box_external_rss extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_factures.php b/htdocs/core/boxes/box_factures.php index b7c9dfa0e91..a5da051d9d7 100644 --- a/htdocs/core/boxes/box_factures.php +++ b/htdocs/core/boxes/box_factures.php @@ -42,6 +42,21 @@ class box_factures extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->facture->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -169,8 +184,8 @@ class box_factures extends ModeleBoxes } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -181,11 +196,11 @@ class box_factures extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_factures_fourn.php b/htdocs/core/boxes/box_factures_fourn.php index 4f88d99bb09..0dd0ceb22ba 100644 --- a/htdocs/core/boxes/box_factures_fourn.php +++ b/htdocs/core/boxes/box_factures_fourn.php @@ -43,6 +43,21 @@ class box_factures_fourn extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->fournisseur->facture->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -178,8 +193,8 @@ class box_factures_fourn extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->transnoentities("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->transnoentities("ReadPermissionNotAllowed") ); } } @@ -190,11 +205,11 @@ class box_factures_fourn extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_factures_fourn_imp.php b/htdocs/core/boxes/box_factures_fourn_imp.php index 3313b4cbd50..1f894be3309 100644 --- a/htdocs/core/boxes/box_factures_fourn_imp.php +++ b/htdocs/core/boxes/box_factures_fourn_imp.php @@ -42,6 +42,21 @@ class box_factures_fourn_imp extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->fournisseur->facture->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -168,8 +183,8 @@ class box_factures_fourn_imp extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } @@ -181,11 +196,11 @@ class box_factures_fourn_imp extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_factures_imp.php b/htdocs/core/boxes/box_factures_imp.php index 14a21d9712d..ea483e223c1 100644 --- a/htdocs/core/boxes/box_factures_imp.php +++ b/htdocs/core/boxes/box_factures_imp.php @@ -45,6 +45,21 @@ class box_factures_imp extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->facture->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -172,8 +187,8 @@ class box_factures_imp extends ModeleBoxes } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -184,11 +199,11 @@ class box_factures_imp extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_ficheinter.php b/htdocs/core/boxes/box_ficheinter.php index 9fcd8ec6cd7..f62745437a6 100644 --- a/htdocs/core/boxes/box_ficheinter.php +++ b/htdocs/core/boxes/box_ficheinter.php @@ -43,6 +43,21 @@ class box_ficheinter extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->ficheinter->lire); + } + /** * Load data for box to show them later * @@ -134,8 +149,10 @@ class box_ficheinter extends ModeleBoxes } else { - $this->info_box_contents[0][0] = array('td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -145,11 +162,11 @@ class box_ficheinter extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_fournisseurs.php b/htdocs/core/boxes/box_fournisseurs.php index 432d34897d0..32ffd1f5618 100644 --- a/htdocs/core/boxes/box_fournisseurs.php +++ b/htdocs/core/boxes/box_fournisseurs.php @@ -43,6 +43,21 @@ class box_fournisseurs extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->societe->lire && empty($user->socid)); + } + /** * Load data into info_box_contents array to show array later. * @@ -71,7 +86,7 @@ class box_fournisseurs extends ModeleBoxes $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.fournisseur = 1"; - $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; + $sql.= " AND s.entity IN (".getEntity('societe').")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= " ORDER BY s.tms DESC "; @@ -127,8 +142,8 @@ class box_fournisseurs extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } @@ -140,11 +155,11 @@ class box_fournisseurs extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_goodcustomers.php b/htdocs/core/boxes/box_goodcustomers.php index 73208b1423a..8e4ec988144 100644 --- a/htdocs/core/boxes/box_goodcustomers.php +++ b/htdocs/core/boxes/box_goodcustomers.php @@ -59,7 +59,9 @@ class box_goodcustomers extends ModeleBoxes // disable box for such cases if (! empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) $this->enabled=0; // disabled by this option - if (empty($conf->global->MAIN_BOX_ENABLE_BEST_CUSTOMERS)) $this->enabled=0; // not enabled by default. Very slow on large database + if (empty($conf->global->MAIN_BOX_ENABLE_BEST_CUSTOMERS)) $this->enabled=0; // not enabled by default. Very slow on large database + + $this->hidden = ! ($user->rights->societe->lire); } /** @@ -86,7 +88,7 @@ class box_goodcustomers extends ModeleBoxes $sql = "SELECT s.rowid, s.nom as name, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms as datem, s.status as status,"; $sql.= " count(*) as nbfact, sum(". $db->ifsql('f.paye=1','1','0').") as nbfactpaye"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; - $sql.= ' WHERE s.entity IN ('.getEntity('societe', 1).')'; + $sql.= ' WHERE s.entity IN ('.getEntity('societe').')'; $sql.= ' AND s.rowid = f.fk_soc'; $sql.= " GROUP BY s.rowid, s.nom, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms, s.status"; $sql.= $db->order("nbfact","DESC"); @@ -148,8 +150,10 @@ class box_goodcustomers extends ModeleBoxes } } else { - $this->info_box_contents[0][0] = array('align' => 'left', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -160,11 +164,11 @@ class box_goodcustomers extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index 8d8fea71411..639db28637d 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -47,9 +47,11 @@ class box_graph_invoices_permonth extends ModeleBoxes */ function __construct($db,$param) { - global $conf; + global $user; $this->db=$db; + + $this->hidden = ! ($user->rights->facture->lire); } /** @@ -133,7 +135,7 @@ class box_graph_invoices_permonth extends ModeleBoxes if (! $mesg) { $langs->load("bills"); - + $px1->SetData($data1); unset($data1); $px1->SetPrecisionY(0); @@ -255,8 +257,10 @@ class box_graph_invoices_permonth extends ModeleBoxes } else { - $this->info_box_contents[0][0] = array('td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -266,11 +270,11 @@ class box_graph_invoices_permonth extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php index e7ece7a2a53..ca26f1392a8 100644 --- a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php @@ -47,9 +47,11 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes */ function __construct($db,$param) { - global $conf; + global $user; $this->db=$db; + + $this->hidden = ! ($user->rights->fournisseur->facture->lire); } /** @@ -132,7 +134,7 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes if (! $mesg) { $langs->load("bills"); - + $px1->SetData($data1); unset($data1); $px1->SetPrecisionY(0); @@ -254,8 +256,10 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes } else { - $this->info_box_contents[0][0] = array('td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -265,11 +269,11 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_orders_permonth.php b/htdocs/core/boxes/box_graph_orders_permonth.php index ec45cc3dde7..d192805782e 100644 --- a/htdocs/core/boxes/box_graph_orders_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_permonth.php @@ -47,9 +47,11 @@ class box_graph_orders_permonth extends ModeleBoxes */ function __construct($db,$param) { - global $conf; + global $user; $this->db=$db; + + $this->hidden = ! ($user->rights->commande->lire); } /** @@ -253,8 +255,10 @@ class box_graph_orders_permonth extends ModeleBoxes } else { - $this->info_box_contents[0][0] = array('td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -264,11 +268,11 @@ class box_graph_orders_permonth extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php index 28335c79b62..18b85b2ae80 100644 --- a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php @@ -47,9 +47,11 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes */ function __construct($db,$param) { - global $conf; + global $user; $this->db=$db; + + $this->hidden = ! ($user->rights->fournisseur->commande->lire); } /** @@ -252,8 +254,10 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes } else { - $this->info_box_contents[0][0] = array('td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -263,11 +267,11 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_product_distribution.php b/htdocs/core/boxes/box_graph_product_distribution.php index 44d5d0b0c15..bac56d8006b 100644 --- a/htdocs/core/boxes/box_graph_product_distribution.php +++ b/htdocs/core/boxes/box_graph_product_distribution.php @@ -48,9 +48,15 @@ class box_graph_product_distribution extends ModeleBoxes */ function __construct($db,$param) { - global $conf; + global $user, $conf; $this->db=$db; + + $this->hidden = ! ( + (! empty($conf->facture->enabled) && ! empty($user->rights->facture->lire)) + || (! empty($conf->commande->enabled) && ! empty($user->rights->commande->lire)) + || (! empty($conf->propal->enabled) && ! empty($user->rights->propale->lire)) + ); } /** @@ -93,12 +99,16 @@ class box_graph_product_distribution extends ModeleBoxes } if (empty($showinvoicenb) && empty($showpropalnb) && empty($showordernb)) { $showpropalnb=1; $showinvoicenb=1; $showordernb=1; } if (empty($conf->facture->enabled) || empty($user->rights->facture->lire)) $showinvoicenb=0; - if (empty($conf->propal->enabled) || empty($user->rights->propal->lire)) $showpropalnb=0; + if (empty($conf->propal->enabled) || empty($user->rights->propale->lire)) $showpropalnb=0; if (empty($conf->commande->enabled) || empty($user->rights->commande->lire)) $showordernb=0; $nowarray=dol_getdate(dol_now(),true); if (empty($year)) $year=$nowarray['year']; + $nbofgraph=0; + if ($showinvoicenb) $nbofgraph++; + if ($showpropalnb) $nbofgraph++; + if ($showordernb) $nbofgraph++; $text = $langs->trans("BoxProductDistribution",$max).' - '.$langs->trans("Year").': '.$year; $this->info_box_head = array( @@ -113,11 +123,6 @@ class box_graph_product_distribution extends ModeleBoxes ); - $nbofgraph=0; - if ($showinvoicenb) $nbofgraph++; - if ($showpropalnb) $nbofgraph++; - if ($showordernb) $nbofgraph++; - $paramtitle=$langs->transnoentitiesnoconv("Products").'/'.$langs->transnoentitiesnoconv("Services"); if (empty($conf->produit->enabled)) $paramtitle=$langs->transnoentitiesnoconv("Services"); if (empty($conf->service->enabled)) $paramtitle=$langs->transnoentitiesnoconv("Products"); @@ -188,7 +193,7 @@ class box_graph_product_distribution extends ModeleBoxes } } - if (! empty($conf->propal->enabled) && ! empty($user->rights->propal->lire)) + if (! empty($conf->propal->enabled) && ! empty($user->rights->propale->lire)) { // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...) if ($showpropalnb) @@ -250,7 +255,7 @@ class box_graph_product_distribution extends ModeleBoxes if (! empty($conf->commande->enabled) && ! empty($user->rights->commande->lire)) { $langs->load("orders"); - + // Build graphic number of object. $data = array(array('Lib',val1,val2,val3),...) if ($showordernb) { @@ -309,6 +314,11 @@ class box_graph_product_distribution extends ModeleBoxes } } + if (empty($nbofgraph)) + { + $langs->load("errors"); + $mesg=$langs->trans("ReadPermissionNotAllowed"); + } if (empty($conf->use_javascript_ajax)) { $langs->load("errors"); @@ -334,7 +344,7 @@ class box_graph_product_distribution extends ModeleBoxes $stringtoshow.=' '.$langs->trans("ForCustomersInvoices"); $stringtoshow.='   '; } - if (! empty($conf->propal->enabled) || ! empty($user->rights->propal->lire)) + if (! empty($conf->propal->enabled) || ! empty($user->rights->propale->lire)) { $stringtoshow.=' '.$langs->trans("ForProposals"); $stringtoshow.=' '; @@ -380,9 +390,11 @@ class box_graph_product_distribution extends ModeleBoxes } else { - $this->info_box_contents[0][0] = array( 'td' => 'align="left" class="nohover"', - 'maxlength'=>500, - 'text' => $mesg); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'maxlength'=>500, + 'text' => $mesg + ); } } @@ -393,11 +405,11 @@ class box_graph_product_distribution extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_propales_permonth.php b/htdocs/core/boxes/box_graph_propales_permonth.php index ccce8372d1f..a0a15cae59a 100644 --- a/htdocs/core/boxes/box_graph_propales_permonth.php +++ b/htdocs/core/boxes/box_graph_propales_permonth.php @@ -47,9 +47,11 @@ class box_graph_propales_permonth extends ModeleBoxes */ function __construct($db,$param) { - global $conf; + global $user; $this->db=$db; + + $this->hidden=! ($user->rights->propale->lire); } /** @@ -87,7 +89,7 @@ class box_graph_propales_permonth extends ModeleBoxes if ($user->societe_id) $socid=$user->societe_id; if (! $user->rights->societe->client->voir || $socid) $prefix.='private-'.$user->id.'-'; // If user has no permission to see all, output dir is specific to user - if ($user->rights->propal->lire) + if ($user->rights->propale->lire) { $param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year'; $param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb'; @@ -254,8 +256,10 @@ class box_graph_propales_permonth extends ModeleBoxes } else { - $this->info_box_contents[0][0] = array('td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -265,11 +269,11 @@ class box_graph_propales_permonth extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_members.php b/htdocs/core/boxes/box_members.php index 1bbcec45881..bbf7cd8ad48 100644 --- a/htdocs/core/boxes/box_members.php +++ b/htdocs/core/boxes/box_members.php @@ -60,6 +60,8 @@ class box_members extends ModeleBoxes // disable module for such cases $listofmodulesforexternal=explode(',',$conf->global->MAIN_MODULES_FOR_EXTERNAL); if (! in_array('adherent',$listofmodulesforexternal) && ! empty($user->societe_id)) $this->enabled=0; // disabled for external users + + $this->hidden=! ($user->rights->adherent->lire); } /** @@ -157,8 +159,8 @@ class box_members extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'align' => 'left', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } @@ -170,11 +172,11 @@ class box_members extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_produits.php b/htdocs/core/boxes/box_produits.php index e606e6570f3..a6727d4bb06 100644 --- a/htdocs/core/boxes/box_produits.php +++ b/htdocs/core/boxes/box_produits.php @@ -45,6 +45,21 @@ class box_produits extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->produit->lire || $user->rights->service->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -53,7 +68,7 @@ class box_produits extends ModeleBoxes */ function loadBox($max=5) { - global $user, $langs, $db, $conf; + global $user, $langs, $db, $conf, $hookmanager; $this->max=$max; @@ -69,6 +84,13 @@ class box_produits extends ModeleBoxes $sql.= ' WHERE p.entity IN ('.getEntity($productstatic->element, 1).')'; if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0'; if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1'; + // Add where from hooks + if (is_object($hookmanager)) + { + $parameters=array('boxproductlist'=>1); + $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook + $sql.=$hookmanager->resPrint; + } $sql.= $db->order('p.datec', 'DESC'); $sql.= $db->plimit($max, 0); @@ -106,7 +128,7 @@ class box_produits extends ModeleBoxes $productstatic->entity = $objp->entity; $this->info_box_contents[$line][] = array( - 'td' => '', + 'td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"', 'text' => $productstatic->getNomUrl(1), 'asis' => 1, ); @@ -155,12 +177,14 @@ class box_produits extends ModeleBoxes $this->info_box_contents[$line][] = array( 'td' => 'align="right" width="18"', - 'text' => $productstatic->LibStatut($objp->tosell,3,0), + 'text' => ''.$productstatic->LibStatut($objp->tosell,3,0).'', + 'asis' => 1 ); $this->info_box_contents[$line][] = array( 'td' => 'align="right" width="18"', - 'text' => $productstatic->LibStatut($objp->tobuy,3,1), + 'text' => ''.$productstatic->LibStatut($objp->tobuy,3,1).'', + 'asis' => 1 ); $line++; @@ -181,8 +205,8 @@ class box_produits extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -193,11 +217,11 @@ class box_produits extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_produits_alerte_stock.php b/htdocs/core/boxes/box_produits_alerte_stock.php index 55e70f62f96..43297d6954a 100644 --- a/htdocs/core/boxes/box_produits_alerte_stock.php +++ b/htdocs/core/boxes/box_produits_alerte_stock.php @@ -47,6 +47,21 @@ class box_produits_alerte_stock extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param='') + { + global $user; + + $this->db = $db; + + $this->hidden = ! (($user->rights->produit->lire || $user->rights->service->lire) && $user->rights->stock->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -55,7 +70,7 @@ class box_produits_alerte_stock extends ModeleBoxes */ function loadBox($max=5) { - global $user, $langs, $db, $conf; + global $user, $langs, $db, $conf, $hookmanager; $this->max=$max; @@ -64,7 +79,7 @@ class box_produits_alerte_stock extends ModeleBoxes $this->info_box_head = array('text' => $langs->trans("BoxTitleProductsAlertStock",$max)); - if ($user->rights->produit->lire || $user->rights->service->lire) + if (($user->rights->produit->lire || $user->rights->service->lire) && $user->rights->stock->lire) { $sql = "SELECT p.rowid, p.label, p.price, p.ref, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.seuil_stock_alerte, p.entity,"; $sql.= " SUM(".$db->ifsql("s.reel IS NULL","0","s.reel").") as total_stock"; @@ -74,7 +89,14 @@ class box_produits_alerte_stock extends ModeleBoxes $sql.= " AND p.tosell = 1 AND p.seuil_stock_alerte > 0"; if (empty($user->rights->produit->lire)) $sql.=' AND p.fk_product_type != 0'; if (empty($user->rights->service->lire)) $sql.=' AND p.fk_product_type != 1'; - $sql.= " GROUP BY p.rowid, p.ref, p.label, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.seuil_stock_alerte, p.entity"; + // Add where from hooks + if (is_object($hookmanager)) + { + $parameters=array('boxproductalertstocklist'=>1); + $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook + $sql.=$hookmanager->resPrint; + } + $sql.= " GROUP BY p.rowid, p.ref, p.label, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.seuil_stock_alerte, p.entity"; $sql.= " HAVING SUM(".$db->ifsql("s.reel IS NULL","0","s.reel").") < p.seuil_stock_alerte"; $sql.= $db->order('p.seuil_stock_alerte', 'DESC'); $sql.= $db->plimit($max, 0); @@ -157,15 +179,22 @@ class box_produits_alerte_stock extends ModeleBoxes 'text' => $price_base_type, ); - $this->info_box_contents[$line][] = array('td' => 'align="center"', + $this->info_box_contents[$line][] = array( + 'td' => 'align="center"', 'text' => $objp->total_stock . ' / '.$objp->seuil_stock_alerte, 'text2'=>img_warning($langs->transnoentitiesnoconv("StockLowerThanLimit", $objp->seuil_stock_alerte))); - $this->info_box_contents[$line][] = array('td' => 'align="right" width="18"', - 'text' => $productstatic->LibStatut($objp->tosell,3,0)); + $this->info_box_contents[$line][] = array( + 'td' => 'align="right" width="18"', + 'text' => ''.$productstatic->LibStatut($objp->tosell,3,0).'', + 'asis' => 1 + ); - $this->info_box_contents[$line][] = array('td' => 'align="right" width="18"', - 'text' => $productstatic->LibStatut($objp->tobuy,3,1)); + $this->info_box_contents[$line][] = array( + 'td' => 'align="right" width="18"', + 'text' => ''.$productstatic->LibStatut($objp->tobuy,3,0).'', + 'asis' => 1 + ); $line++; } @@ -188,8 +217,8 @@ class box_produits_alerte_stock extends ModeleBoxes } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -200,11 +229,11 @@ class box_produits_alerte_stock extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_project.php b/htdocs/core/boxes/box_project.php index 4c4e8085592..9422f228530 100644 --- a/htdocs/core/boxes/box_project.php +++ b/htdocs/core/boxes/box_project.php @@ -48,12 +48,14 @@ class box_project extends ModeleBoxes */ function __construct($db,$param='') { - global $langs; + global $user, $langs; $langs->load("boxes"); $langs->load("projects"); $this->db = $db; $this->boxlabel="Projects"; + + $this->hidden=! ($user->rights->projet->lire); } /** @@ -77,26 +79,26 @@ class box_project extends ModeleBoxes // list the summary of the orders if ($user->rights->projet->lire) { - + include_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'); $projectstatic = new Project($this->db); - + $socid=$user->societe_id; - + // Get list of project id allowed to user (in a string list separated by coma) $projectsListId=''; if (! $user->rights->projet->all->lire) $projectsListId = $projectstatic->getProjectsAuthorizedForUser($user,0,1,$socid); - + $sql = "SELECT p.rowid, p.ref, p.title, p.fk_statut, p.public"; $sql.= " FROM ".MAIN_DB_PREFIX."projet as p"; if($user->socid) $sql.= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=p.fk_soc"; - $sql.= " WHERE p.entity IN (".getEntity('project',1).')'; + $sql.= " WHERE p.entity IN (".getEntity('project').')'; if (! $user->rights->projet->all->lire) $sql.= " AND p.rowid IN (".$projectsListId.")"; // public and assigned to, or restricted to company for external users if ($user->socid) $sql.= " AND s.rowid = ".$user->socid; $sql.= " AND p.fk_statut = 1"; // Seulement les projets ouverts if ($socid) $sql.= " AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")"; if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND ((s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id.") OR (s.rowid IS NULL))"; - + $sql.= " ORDER BY p.datec DESC"; //$sql.= $db->plimit($max, 0); @@ -130,7 +132,7 @@ class box_project extends ModeleBoxes $sql ="SELECT count(*) as nb, sum(progress) as totprogress"; $sql.=" FROM ".MAIN_DB_PREFIX."projet as p LEFT JOIN ".MAIN_DB_PREFIX."projet_task as pt on pt.fk_projet = p.rowid"; - $sql.= " WHERE p.entity IN (".getEntity('project',1).')'; + $sql.= " WHERE p.entity IN (".getEntity('project').')'; $sql.=" AND p.rowid = ".$objp->rowid; $resultTask = $db->query($sql); if ($resultTask) { @@ -156,7 +158,7 @@ class box_project extends ModeleBoxes } if ($max < $num) { - $this->info_box_contents[$i][0] = array('td' => 'colspan="5"', 'text' => '...'); + $this->info_box_contents[$i][0] = array('td' => 'colspan="5"', 'text' => '...'); $i++; } } @@ -195,11 +197,11 @@ class box_project extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_propales.php b/htdocs/core/boxes/box_propales.php index 3f7b37f186a..a94ee0c1f08 100644 --- a/htdocs/core/boxes/box_propales.php +++ b/htdocs/core/boxes/box_propales.php @@ -44,6 +44,21 @@ class box_propales extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->propale->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -155,8 +170,8 @@ class box_propales extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -167,11 +182,11 @@ class box_propales extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_prospect.php b/htdocs/core/boxes/box_prospect.php index 1acd77addfc..3186d0d30ce 100644 --- a/htdocs/core/boxes/box_prospect.php +++ b/htdocs/core/boxes/box_prospect.php @@ -60,6 +60,8 @@ class box_prospect extends ModeleBoxes // disable box for such cases if (! empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) $this->enabled=0; // disabled by this option + + $this->hidden=! ($user->rights->societe->lire && empty($user->socid)); } /** @@ -90,7 +92,7 @@ class box_prospect extends ModeleBoxes $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE s.client IN (2, 3)"; - $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; + $sql.= " AND s.entity IN (".getEntity('societe').")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($user->societe_id) $sql.= " AND s.rowid = ".$user->societe_id; $sql.= " ORDER BY s.tms DESC"; @@ -156,8 +158,8 @@ class box_prospect extends ModeleBoxes } } else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -168,11 +170,11 @@ class box_prospect extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_services_contracts.php b/htdocs/core/boxes/box_services_contracts.php index 0151ba24966..ccdcfbdbe5a 100644 --- a/htdocs/core/boxes/box_services_contracts.php +++ b/htdocs/core/boxes/box_services_contracts.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2011 Laurent Destailleur + * Copyright (C) 2005-2017 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -20,7 +20,7 @@ /** * \file htdocs/core/boxes/box_services_contracts.php * \ingroup produits,services - * \brief Module de generation de l'affichage de la box services_vendus + * \brief Widget of sells products */ include_once DOL_DOCUMENT_ROOT.'/core/boxes/modules_boxes.php'; @@ -43,6 +43,21 @@ class box_services_contracts extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->service->lire && $user->rights->contrat->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -109,7 +124,7 @@ class box_services_contracts extends ModeleBoxes $thirdpartytmp->id = $objp->socid; // Multilangs - if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active + if (! empty($conf->global->MAIN_MULTILANGS) && $objp->product_id > 0) // if option multilang is on { $sqld = "SELECT label"; $sqld.= " FROM ".MAIN_DB_PREFIX."product_lang"; @@ -161,8 +176,10 @@ class box_services_contracts extends ModeleBoxes } } else { - $this->info_box_contents[0][0] = array('td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -173,11 +190,11 @@ class box_services_contracts extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_services_expired.php b/htdocs/core/boxes/box_services_expired.php index 2754a4cece6..4f3a2817549 100644 --- a/htdocs/core/boxes/box_services_expired.php +++ b/htdocs/core/boxes/box_services_expired.php @@ -42,6 +42,21 @@ class box_services_expired extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->contrat->lire); + } + /** * Load data for box to show them later * @@ -84,7 +99,7 @@ class box_services_expired extends ModeleBoxes $i = 0; $thirdpartytmp = new Societe($this->db); - + while ($i < $num) { $late=''; @@ -140,8 +155,10 @@ class box_services_expired extends ModeleBoxes } else { - $this->info_box_contents[0][0] = array('td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed")); + $this->info_box_contents[0][0] = array( + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") + ); } } @@ -151,11 +168,11 @@ class box_services_expired extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_supplier_orders.php b/htdocs/core/boxes/box_supplier_orders.php index 29b6009b367..34734d9dd5a 100644 --- a/htdocs/core/boxes/box_supplier_orders.php +++ b/htdocs/core/boxes/box_supplier_orders.php @@ -43,6 +43,21 @@ class box_supplier_orders extends ModeleBoxes var $info_box_contents = array(); + /** + * Constructor + * + * @param DoliDB $db Database handler + * @param string $param More parameters + */ + function __construct($db,$param) + { + global $user; + + $this->db=$db; + + $this->hidden=! ($user->rights->fournisseur->commande->lire); + } + /** * Load data into info_box_contents array to show array later. * @@ -160,8 +175,8 @@ class box_supplier_orders extends ModeleBoxes else { $this->info_box_contents[0][0] = array( - 'td' => '', - 'text' => $langs->trans("ReadPermissionNotAllowed"), + 'td' => 'align="left" class="nohover opacitymedium"', + 'text' => $langs->trans("ReadPermissionNotAllowed") ); } } @@ -172,11 +187,11 @@ class box_supplier_orders extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_task.php b/htdocs/core/boxes/box_task.php index ed02e2fc6eb..3a665243073 100644 --- a/htdocs/core/boxes/box_task.php +++ b/htdocs/core/boxes/box_task.php @@ -42,6 +42,7 @@ class box_task extends ModeleBoxes var $info_box_head = array(); var $info_box_contents = array(); + /** * Constructor * @@ -50,11 +51,13 @@ class box_task extends ModeleBoxes */ function __construct($db,$param='') { - global $langs; + global $user, $langs; $langs->load("boxes"); $langs->load("projects"); $this->boxlabel="Tasks"; $this->db = $db; + + $this->hidden = ! ($user->rights->projet->lire); } /** @@ -138,10 +141,10 @@ class box_task extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @return void + * @return string */ function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); + return parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/modules_boxes.php b/htdocs/core/boxes/modules_boxes.php index f5fa32e590d..d83f0e80cba 100644 --- a/htdocs/core/boxes/modules_boxes.php +++ b/htdocs/core/boxes/modules_boxes.php @@ -49,10 +49,15 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" public $max = 5; /** - * @var int Status + * @var int Condition to have widget enabled */ public $enabled=1; + /** + * @var int Condition to have widget visible (in most cases, permissions) + */ + public $hidden=0; + /** * @var int Box definition database ID */ @@ -168,29 +173,29 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" } } - + /** * Standard method to get content of a box * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * - * @return string + * @return string */ function outputBox($head = null, $contents = null) { global $langs, $user, $conf; - + // Trick to get result into a var from a function that makes print instead of return // TODO Replace ob_start with param nooutput=1 into showBox ob_start(); $result = $this->showBox($head, $contents); $output = ob_get_contents(); ob_end_clean(); - + return $output; } - + /** * Standard method to show a box (usage by boxes not mandatory, a box can still use its own showBox function) * @@ -203,6 +208,8 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" { global $langs, $user, $conf; + if (! empty($this->hidden)) return '\n\n'; // Nothing done if hidden (for example when user has no permission) + require_once DOL_DOCUMENT_ROOT .'/core/lib/files.lib.php'; $MAXLENGTHBOX=60; // Mettre 0 pour pas de limite @@ -248,14 +255,14 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" $out.= $s; } $out.= ''; - + if (! empty($conf->use_javascript_ajax)) { $sublink=''; if (! empty($head['sublink'])) $sublink.= ''; if (! empty($head['subpicto'])) $sublink.= img_picto($head['subtext'], $head['subpicto'], 'class="'.(empty($head['subclass'])?'':$head['subclass']).'" id="idsubimg'.$this->boxcode.'"'); if (! empty($head['sublink'])) $sublink.= ''; - + $out.= ''; $out.=$sublink; // The image must have the class 'boxhandle' beause it's value used in DOM draggable objects to define the area used to catch the full object @@ -266,7 +273,7 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" $out.= ''; $out.= ''; } - + $out.= "\n"; } @@ -278,10 +285,8 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" { if (isset($contents[$i])) { - - // TR - if (isset($contents[$i][0]['tr'])) $out.= ''; + if (isset($contents[$i][0]['tr'])) $out.= ''; else $out.= ''; // Loop on each TD @@ -363,13 +368,13 @@ class ModeleBoxes // Can't be abtract as it is instantiated to build "empty" $out = ""; $out.= dol_readcachefile($cachedir, $filename); } - + if ($nooutput) return $out; else print $out; - + return ''; } - + } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index fe93387cadb..1339512b3af 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -89,13 +89,13 @@ abstract class CommonObject * @var Object To store a cloned copy of object before to edit it and keep track of old properties */ public $oldcopy; - + /** * @var string Column name of the ref field. */ protected $table_ref_field = ''; - + // Following vars are used by some objects only. We keep this property here in CommonObject to be able to provide common method using them. @@ -330,10 +330,10 @@ abstract class CommonObject public $firstname; public $civility_id; - + // No constructor as it is an abstract class - + /** * Check an object id/ref exists * If you don't need/want to instantiate object and just need to know if object exists, use this method instead of fetch @@ -398,7 +398,7 @@ abstract class CommonObject $lastname=$this->lastname; $firstname=$this->firstname; if (empty($lastname)) $lastname=(isset($this->lastname)?$this->lastname:(isset($this->name)?$this->name:(isset($this->nom)?$this->nom:(isset($this->societe)?$this->societe:(isset($this->company)?$this->company:''))))); - + $ret=''; if ($option && $this->civility_id) { @@ -597,11 +597,11 @@ abstract class CommonObject dol_syslog("CODE_NOT_VALID_FOR_THIS_ELEMENT"); return -3; } - + $datecreate = dol_now(); $this->db->begin(); - + // Insertion dans la base $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; @@ -959,7 +959,7 @@ abstract class CommonObject $sql.= " WHERE ec.element_id = ".$id; $sql.= " AND ec.fk_socpeople = c.rowid"; if ($source == 'internal') $sql.= " AND c.entity IN (0,".$conf->entity.")"; - if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe', 1).")"; + if ($source == 'external') $sql.= " AND c.entity IN (".getEntity('societe').")"; $sql.= " AND ec.fk_c_type_contact = tc.rowid"; $sql.= " AND tc.element = '".$element."'"; $sql.= " AND tc.source = '".$source."'"; @@ -1238,19 +1238,19 @@ abstract class CommonObject function setValueFrom($field, $value, $table='', $id=null, $format='', $id_field='', $fuser=null, $trigkey='') { global $user,$langs,$conf; - + if (empty($table)) $table=$this->table_element; if (empty($id)) $id=$this->id; if (empty($format)) $format='text'; if (empty($id_field)) $id_field='rowid'; $error=0; - + $this->db->begin(); // Special case if ($table == 'product' && $field == 'note_private') $field='note'; - + $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; if ($format == 'text') $sql.= $field." = '".$this->db->escape($value)."'"; else if ($format == 'int') $sql.= $field." = ".$this->db->escape($value); @@ -1292,7 +1292,7 @@ abstract class CommonObject /** * Load properties id_previous and id_next * - * @param string $filter Optional filter + * @param string $filter Optional filter. Example: " AND (t.field1 = 'aa' OR t.field2 = 'bb')" * @param int $fieldid Name of field to use for the select MAX and MIN * @param int $nodbprefix Do not include DB prefix to forge table name * @return int <0 if KO, >0 if OK @@ -1318,11 +1318,15 @@ abstract class CommonObject if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; $sql.= " WHERE te.".$fieldid." < '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id; - if (! empty($filter)) $sql.=" AND ".$filter; + if (! empty($filter)) + { + if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility + $sql.=$filter; + } if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')'; - //print $sql."
"; + //print $filter.' '.$sql."
"; $result = $this->db->query($sql); if (! $result) { @@ -1339,7 +1343,11 @@ abstract class CommonObject if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$alias.".rowid = sc.fk_soc"; $sql.= " WHERE te.".$fieldid." > '".$this->db->escape($this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) if (empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir) $sql.= " AND sc.fk_user = " .$user->id; - if (! empty($filter)) $sql.=" AND ".$filter; + if (! empty($filter)) + { + if (! preg_match('/^\s*AND/i', $filter)) $sql.=" AND "; // For backward compatibility + $sql.=$filter; + } if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 2 || ($this->element != 'societe' && empty($this->isnolinkedbythird) && !$user->rights->societe->client->voir)) $sql.= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to entity if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql.= ' AND te.entity IN ('.getEntity($this->element, 1).')'; // Rem: Bug in some mysql version: SELECT MIN(rowid) FROM llx_socpeople WHERE rowid > 1 when one row in database with rowid=1, returns 1 instead of null @@ -1396,13 +1404,13 @@ abstract class CommonObject } $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - if ($this->table_element == 'actioncomm') + if ($this->table_element == 'actioncomm') { if ($projectid) $sql.= ' SET fk_project = '.$projectid; else $sql.= ' SET fk_project = NULL'; - $sql.= ' WHERE id = '.$this->id; + $sql.= ' WHERE id = '.$this->id; } - else + else { if ($projectid) $sql.= ' SET fk_projet = '.$projectid; else $sql.= ' SET fk_projet = NULL'; @@ -1478,7 +1486,7 @@ abstract class CommonObject $fieldname = 'multicurrency_code'; $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql .= ' SET '.$fieldname.' = "'.$this->db->escape($code).'"'; + $sql .= ' SET '.$fieldname." = '".$this->db->escape($code)."'"; $sql .= ' WHERE rowid='.$this->id; if ($this->db->query($sql)) @@ -1535,7 +1543,7 @@ abstract class CommonObject if($mode == 1) { $line->subprice = 0; } - + switch ($this->element) { case 'propal': $this->updateline($line->id, $line->subprice, $line->qty, $line->remise_percent, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->desc, 'HT', $line->info_bits, $line->special_code, $line->fk_parent_line, $line->skip_update_total, $line->fk_fournprice, $line->pa_ht, $line->label, $line->product_type, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice); @@ -1626,7 +1634,7 @@ abstract class CommonObject /** * Define delivery address * @deprecated - * + * * @param int $id Address id * @return int <0 si ko, >0 si ok */ @@ -1950,7 +1958,7 @@ abstract class CommonObject { $fieldposition = 'rang'; if ($this->table_element_line == 'ecm_files') $fieldposition = 'position'; - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element_line.' SET '.$fieldposition.' = '.$rang; $sql.= ' WHERE rowid = '.$rowid; @@ -2163,7 +2171,7 @@ abstract class CommonObject function update_note($note,$suffix='') { global $user; - + if (! $this->table_element) { dol_syslog(get_class($this)."::update_note was called on objet with property table_element not defined", LOG_ERR); @@ -2177,7 +2185,7 @@ abstract class CommonObject // Special cas //var_dump($this->table_element);exit; if ($this->table_element == 'product') $suffix=''; - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql.= " SET note".$suffix." = ".(!empty($note)?("'".$this->db->escape($note)."'"):"NULL"); $sql.= " ,".(in_array($this->table_element, array('actioncomm', 'adherent', 'advtargetemailing', 'cronjob', 'establishment'))?"fk_user_mod":"fk_user_modif")." = ".$user->id; @@ -2188,7 +2196,7 @@ abstract class CommonObject { if ($suffix == '_public') $this->note_public = $note; else if ($suffix == '_private') $this->note_private = $note; - else + else { $this->note = $note; // deprecated $this->note_private = $note; @@ -2437,7 +2445,7 @@ abstract class CommonObject // Special case if ($origin == 'order') $origin='commande'; if ($origin == 'invoice') $origin='facture'; - + $this->db->begin(); $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_element ("; @@ -2470,10 +2478,10 @@ abstract class CommonObject * Fetch array of objects linked to current object. Links are loaded into this->linkedObjects array and this->linkedObjectsIds * Possible usage for parameters: * - all parameters empty -> we look all link to current object (current object can be source or target) - * - source id+type -> will get target list linked to source - * - target id+type -> will get source list linked to target - * - source id+type + target type -> will get target list of the type - * - target id+type + target source -> will get source list of the type + * - source id+type -> will get target list linked to source + * - target id+type -> will get source list linked to target + * - source id+type + target type -> will get target list of the type + * - target id+type + target source -> will get source list of the type * * @param int $sourceid Object source id (if not defined, id of object) * @param string $sourcetype Object source type (if not defined, element name of object) @@ -2791,7 +2799,7 @@ abstract class CommonObject global $user,$langs,$conf; $savElementId=$elementId; // To be used later to know if we were using the method using the id of this or not. - + $elementId = (!empty($elementId)?$elementId:$this->id); $elementTable = (!empty($elementType)?$elementType:$this->table_element); @@ -2821,7 +2829,7 @@ abstract class CommonObject if ($this->element == 'fichinter' && $status == 3) $trigkey='FICHINTER_CLASSIFY_DONE'; if ($this->element == 'fichinter' && $status == 2) $trigkey='FICHINTER_CLASSIFY_BILLED'; if ($this->element == 'fichinter' && $status == 1) $trigkey='FICHINTER_CLASSIFY_UNBILLED'; - + if ($trigkey) { // Appel des triggers @@ -2837,7 +2845,7 @@ abstract class CommonObject if (! $error) { $this->db->commit(); - + if (empty($savElementId)) // If the element we update was $this (so $elementId is null) { $this->statut = $status; @@ -2932,7 +2940,7 @@ abstract class CommonObject function isObjectUsed($id=0) { if (empty($id)) $id=$this->id; - + // Check parameters if (! isset($this->childtables) || ! is_array($this->childtables) || count($this->childtables) == 0) { @@ -3049,12 +3057,12 @@ abstract class CommonObject foreach ($this->lines as $line) { - if (isset($line->qty_asked)) + if (isset($line->qty_asked)) { if (empty($totalOrdered)) $totalOrdered=0; // Avoid warning because $totalOrdered is '' $totalOrdered+=$line->qty_asked; // defined for shipment only } - if (isset($line->qty_shipped)) + if (isset($line->qty_shipped)) { if (empty($totalToShip)) $totalToShip=0; // Avoid warning because $totalToShip is '' $totalToShip+=$line->qty_shipped; // defined for shipment only @@ -3082,16 +3090,25 @@ abstract class CommonObject if (empty($totalWeight)) $totalWeight=0; // Avoid warning because $totalWeight is '' if (empty($totalVolume)) $totalVolume=0; // Avoid warning because $totalVolume is '' - + //var_dump($line->volume_units); if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) { $trueWeightUnit=pow(10, $weightUnit); $totalWeight += $weight * $qty * $trueWeightUnit; } - else - { - $totalWeight += $weight * $qty; // This may be wrong if we mix different units + else { + if ($weight_units == 99) { + // conversion 1 Pound = 0.45359237 KG + $trueWeightUnit = 0.45359237; + $totalWeight += $weight * $qty * $trueWeightUnit; + } elseif ($weight_units == 98) { + // conversion 1 Ounce = 0.0283495 KG + $trueWeightUnit = 0.0283495; + $totalWeight += $weight * $qty * $trueWeightUnit; + } + else + $totalWeight += $weight * $qty; // This may be wrong if we mix different units } if ($volume_units < 50) // >50 means a standard unit (power of 10 of official unit), > 50 means an exotic unit (like inch) { @@ -3318,54 +3335,54 @@ abstract class CommonObject if (! empty($conf->margin->enabled) && ! empty($this->element) && in_array($this->element,array('facture','propal','commande'))) $usemargins=1; $num = count($this->lines); - + //Line extrafield require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafieldsline = new ExtraFields($this->db); $extralabelslines=$extrafieldsline->fetch_name_optionals_label($this->table_element_line); - + $parameters = array('num'=>$num,'i'=>$i,'dateSelector'=>$dateSelector,'seller'=>$seller,'buyer'=>$buyer,'selected'=>$selected, 'extrafieldsline'=>$extrafieldsline); $reshook = $hookmanager->executeHooks('printObjectLineTitle', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks if (empty($reshook)) { print ''; - + if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) print ' '; - + // Description print ''.$langs->trans('Description').''; - + if ($this->element == 'supplier_proposal') { print ''.$langs->trans("SupplierProposalRefFourn").''; } - + // VAT print ''.$langs->trans('VAT').''; - + // Price HT print ''.$langs->trans('PriceUHT').''; - + // Multicurrency if (!empty($conf->multicurrency->enabled)) print ''.$langs->trans('PriceUHTCurrency', $this->multicurrency_code).''; - + if ($inputalsopricewithtax) print ''.$langs->trans('PriceUTTC').''; - + // Qty print ''.$langs->trans('Qty').''; - + if($conf->global->PRODUCT_USE_UNITS) { print ''.$langs->trans('Unit').''; } - + // Reduction short print ''.$langs->trans('ReductionShort').''; - + if ($this->situation_cycle_ref) { print '' . $langs->trans('Progress') . ''; } - + if ($usemargins && ! empty($conf->margin->enabled) && empty($user->societe_id)) { if (!empty($user->rights->margins->creer)) @@ -3373,32 +3390,32 @@ abstract class CommonObject if ($conf->global->MARGIN_TYPE == "1") print ''.$langs->trans('BuyingPrice').''; else - print ''.$langs->trans('CostPrice').''; + print ''.$langs->trans('CostPrice').''; } - + if (! empty($conf->global->DISPLAY_MARGIN_RATES) && $user->rights->margins->liretous) print ''.$langs->trans('MarginRate').''; if (! empty($conf->global->DISPLAY_MARK_RATES) && $user->rights->margins->liretous) print ''.$langs->trans('MarkRate').''; } - + // Total HT print ''.$langs->trans('TotalHTShort').''; - + // Multicurrency if (!empty($conf->multicurrency->enabled)) print ''.$langs->trans('TotalHTShortCurrency', $this->multicurrency_code).''; - + if ($outputalsopricetotalwithtax) print ''.$langs->trans('TotalTTCShort').''; - + print ''; // No width to allow autodim - + print ''; - + print ''; - + print "\n"; } - + $var = true; $i = 0; @@ -3407,7 +3424,7 @@ abstract class CommonObject //Line extrafield $line->fetch_optionals($line->id,$extralabelslines); - + //if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) if (is_object($hookmanager)) // Old code is commented on preceding line. @@ -3493,7 +3510,7 @@ abstract class CommonObject $outputlangs = $langs; $newlang=''; - if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); + if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); if (! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE) && empty($newlang)) $newlang=$this->thirdparty->default_lang; // For language to language of customer if (! empty($newlang)) { @@ -3588,7 +3605,7 @@ abstract class CommonObject foreach ($this->lines as $line) { - + if (is_object($hookmanager) && (($line->product_type == 9 && ! empty($line->special_code)) || ! empty($line->fk_parent_line))) { @@ -3868,7 +3885,7 @@ abstract class CommonObject $modele=$tmp[0]; $srctemplatepath=$tmp[1]; } - + // Search template files $file=''; $classname=''; $filefound=0; @@ -3897,7 +3914,7 @@ abstract class CommonObject if ($filefound) { global $db; // Required to solve a conception default in commonstickergenerator.class.php making an include of code using $db - + require_once $file; $obj = new $classname($this->db); @@ -3956,7 +3973,7 @@ abstract class CommonObject // output format that does not support UTF8. $sav_charset_output=$outputlangs->charset_output; - if (in_array(get_class($this), array('Adherent'))) + if (in_array(get_class($this), array('Adherent'))) { $arrayofrecords = array(); // The write_file of templates of adherent class need this $resultwritefile = $obj->write_file($this, $outputlangs, $srctemplatepath, 'member', 1, $moreparams); @@ -4104,25 +4121,36 @@ abstract class CommonObject * Function to get extra fields of a member into $this->array_options * This method is in most cases called by method fetch of objects but you can call it separately. * - * @param int $rowid Id of line - * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label() + * @param int $rowid Id of line. Use the id of object if not defined. Deprecated. Function must be called without parameters. + * @param array $optionsArray Array resulting of call of extrafields->fetch_name_optionals_label(). Deprecated. Function must be called without parameters. * @return int <0 if error, 0 if no optionals to find nor found, 1 if a line is found and optional loaded */ function fetch_optionals($rowid=null,$optionsArray=null) { if (empty($rowid)) $rowid=$this->id; - //To avoid SQL errors. Probably not the better solution though + // To avoid SQL errors. Probably not the better solution though if (!$this->table_element) { return 0; } if (! is_array($optionsArray)) { - // optionsArray not already loaded, so we load it - require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; - $extrafields = new ExtraFields($this->db); - $optionsArray = $extrafields->fetch_name_optionals_label($this->table_element); + // $extrafields is not a known object, we initialize it. Best practice is to have $extrafields defined into card.php or list.php page. + // TODO Use of existing extrafield is not yet ready (must mutualize code that use extrafields in form first) + // global $extrafields; + //if (! is_object($extrafields)) + //{ + require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; + $extrafields = new ExtraFields($this->db); + //} + + // Load array of extrafields for elementype = $this->table_element + if (empty($extrafields->attributes[$this->table_element]['loaded'])) + { + $extrafields->fetch_name_optionals_label($this->table_element); + } + $optionsArray = $extrafields->attributes[$this->table_element]['label']; } // Request to get complementary values @@ -4131,12 +4159,15 @@ abstract class CommonObject $sql = "SELECT rowid"; foreach ($optionsArray as $name => $label) { - $sql.= ", ".$name; + if (empty($extrafields->attributes[$this->table_element]['type'][$name]) || $extrafields->attributes[$this->table_element]['type'][$name] != 'separate') + { + $sql.= ", ".$name; + } } $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields"; $sql.= " WHERE fk_object = ".$rowid; - dol_syslog(get_class($this)."::fetch_optionals", LOG_DEBUG); + dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -4217,7 +4248,7 @@ abstract class CommonObject require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); - + //Eliminate copied source object extra_fields that do not exist in target object $new_array_options=array(); foreach ($this->array_options as $key => $value) { @@ -4266,7 +4297,7 @@ abstract class CommonObject { if (is_numeric($value)) $res=$object->fetch($value); else $res=$object->fetch('',$value); - + if ($res > 0) $this->array_options[$key]=$object->id; else { @@ -4678,7 +4709,7 @@ abstract class CommonObject } return $buyPrice; } - + /** * Function test if type is date * @@ -4690,7 +4721,7 @@ abstract class CommonObject if(isset($info['type']) && $info['type']=='date') return true; else return false; } - + /** * Function test if type is array * @@ -4706,7 +4737,7 @@ abstract class CommonObject } else return false; } - + /** * Function test if type is null * @@ -4722,7 +4753,7 @@ abstract class CommonObject } else return false; } - + /** * Function test if type is integer * @@ -4738,7 +4769,7 @@ abstract class CommonObject } else return false; } - + /** * Function test if type is float * @@ -4754,7 +4785,7 @@ abstract class CommonObject } else return false; } - + /** * Function test if type is text * @@ -4770,7 +4801,7 @@ abstract class CommonObject } else return false; } - + /** * Function test if is indexed * @@ -4786,7 +4817,7 @@ abstract class CommonObject } else return false; } - + /** * Function to prepare the values to insert * @@ -4829,7 +4860,7 @@ abstract class CommonObject $query[$field] = $this->{$field}; } } - + return $query; } @@ -4843,30 +4874,30 @@ abstract class CommonObject */ 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 * @@ -4905,10 +4936,10 @@ abstract class CommonObject { $this->{$field} = $obj->{$field}; } - + } } - + /** * Function to concat keys of fields * @@ -4919,7 +4950,7 @@ abstract class CommonObject $keys = array_keys($this->fields); return implode(',', $keys); } - + /** * Load object in memory from the database * @@ -4930,12 +4961,12 @@ abstract class CommonObject */ 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).'\''; @@ -4946,10 +4977,10 @@ abstract class CommonObject { $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 @@ -4978,9 +5009,9 @@ abstract class CommonObject 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) { @@ -4993,22 +5024,22 @@ abstract class CommonObject 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 * @@ -5020,14 +5051,14 @@ abstract class CommonObject 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; } @@ -5038,12 +5069,12 @@ abstract class CommonObject * @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 578ed17049e..77c24ff4109 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2007 Rodolphe Quiedeville * Copyright (C) 2003 Xavier Dutoit * Copyright (C) 2004-2016 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2006 Jean Heimburger * * This program is free software; you can redistribute it and/or modify @@ -132,14 +132,7 @@ class Conf $sql = "SELECT ".$db->decrypt('name')." as name,"; $sql.= " ".$db->decrypt('value')." as value, entity"; $sql.= " FROM ".MAIN_DB_PREFIX."const"; - if (! empty($this->multicompany->transverse_mode)) - { - $sql.= " WHERE entity IN (0,1,".$this->entity.")"; - } - else - { - $sql.= " WHERE entity IN (0,".$this->entity.")"; - } + $sql.= " WHERE entity IN (0,".$this->entity.")"; $sql.= " ORDER BY entity"; // This is to have entity 0 first, then entity 1 that overwrite. $resql = $db->query($sql); @@ -320,7 +313,7 @@ class Conf // For backward compatibility $this->user->dir_output=$rootforuser."/users"; $this->user->dir_temp=$rootforuser."/users/temp"; - + // UserGroup $this->usergroup->dir_output=$rootforuser."/usergroups"; $this->usergroup->dir_temp=$rootforuser."/usergroups/temp"; @@ -332,9 +325,9 @@ class Conf // Exception: Some dir are not the name of module. So we keep exception here for backward compatibility. // Sous module bons d'expedition - $this->expedition_bon->enabled=$this->global->MAIN_SUBMODULE_EXPEDITION?$this->global->MAIN_SUBMODULE_EXPEDITION:0; + $this->expedition_bon->enabled=(! empty($this->global->MAIN_SUBMODULE_EXPEDITION)?$this->global->MAIN_SUBMODULE_EXPEDITION:0); // Sous module bons de livraison - $this->livraison_bon->enabled=$this->global->MAIN_SUBMODULE_LIVRAISON?$this->global->MAIN_SUBMODULE_LIVRAISON:0; + $this->livraison_bon->enabled=(! empty($this->global->MAIN_SUBMODULE_LIVRAISON)?$this->global->MAIN_SUBMODULE_LIVRAISON:0); // Module fournisseur if (! empty($this->fournisseur)) @@ -386,13 +379,13 @@ class Conf $this->global->MAIN_ACTIVATE_HTML5=1; $this->global->MAIN_MAIL_USE_MULTI_PART=1; - + // societe if (empty($this->global->SOCIETE_CODECLIENT_ADDON)) $this->global->SOCIETE_CODECLIENT_ADDON="mod_codeclient_leopard"; if (empty($this->global->SOCIETE_CODECOMPTA_ADDON)) $this->global->SOCIETE_CODECOMPTA_ADDON="mod_codecompta_panicum"; if (empty($this->global->CHEQUERECEIPTS_ADDON)) $this->global->CHEQUERECEIPTS_ADDON='mod_chequereceipt_mint'; - + // Security if (empty($this->global->USER_PASSWORD_GENERATED)) $this->global->USER_PASSWORD_GENERATED='standard'; // Default password generator if (empty($this->global->MAIN_UMASK)) $this->global->MAIN_UMASK='0664'; // Default mask @@ -425,7 +418,7 @@ class Conf $this->currency=$this->global->MAIN_MONNAIE; if (empty($conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY)) $conf->global->MAIN_BROWSER_NOTIFICATION_FREQUENCY = 30; // Less than 1 minutes to be sure - + // conf->global->ACCOUNTING_MODE = Option des modules Comptabilites (simple ou expert). Defini le mode de calcul des etats comptables (CA,...) if (empty($this->global->ACCOUNTING_MODE)) $this->global->ACCOUNTING_MODE='RECETTES-DEPENSES'; // By default. Can be 'RECETTES-DEPENSES' ou 'CREANCES-DETTES' @@ -434,7 +427,7 @@ class Conf // MAIN_HTML_TITLE if (! isset($this->global->MAIN_HTML_TITLE)) $this->global->MAIN_HTML_TITLE='noapp,thirdpartynameonly,contactnameonly,projectnameonly'; - + // conf->liste_limit = constante de taille maximale des listes if (empty($this->global->MAIN_SIZE_LISTE_LIMIT)) $this->global->MAIN_SIZE_LISTE_LIMIT=25; $this->liste_limit=$this->global->MAIN_SIZE_LISTE_LIMIT; @@ -461,7 +454,7 @@ class Conf $this->mailing->email_from=$this->email_from; if (! empty($this->global->MAILING_EMAIL_FROM)) $this->mailing->email_from=$this->global->MAILING_EMAIL_FROM; if (! isset($this->global->MAIN_EMAIL_ADD_TRACK_ID)) $this->global->MAIN_EMAIL_ADD_TRACK_ID=1; - + // Format for date (used by default when not found or not searched in lang) $this->format_date_short="%d/%m/%Y"; // Format of day with PHP/C tags (strftime functions) $this->format_date_short_java="dd/MM/yyyy"; // Format of day with Java tags @@ -485,7 +478,7 @@ class Conf // Default pdf option if (! isset($this->global->MAIN_PDF_DASH_BETWEEN_LINES)) $this->global->MAIN_PDF_DASH_BETWEEN_LINES=1; // use dash between lines if (! isset($this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT)) $this->global->PDF_ALLOW_HTML_FOR_FREE_TEXT=1; // allow html content into free footer text - + // Set default value to MAIN_SHOW_LOGO if (! isset($this->global->MAIN_SHOW_LOGO)) $this->global->MAIN_SHOW_LOGO=1; @@ -495,12 +488,12 @@ class Conf // By default, we propagate contacts if (! isset($this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) $this->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN='*'; // Can be also '*' or '^(BILLING|SHIPPING|CUSTOMER|.*)$' (regex not yet implemented) - // By default, we use the zip town autofill - if (! isset($this->global->MAIN_USE_ZIPTOWN_DICTIONNARY)) $this->global->MAIN_USE_ZIPTOWN_DICTIONNARY=1; + // By default, we do not use the zip town table but the table of third parties + if (! isset($this->global->MAIN_USE_ZIPTOWN_DICTIONNARY)) $this->global->MAIN_USE_ZIPTOWN_DICTIONNARY=0; // By default, we open card if one found if (! isset($this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE)) $this->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE=1; - + // Define list of limited modules (value must be key found for "name" property of module, so for example 'supplierproposal' for Module "Supplier Proposal" if (! isset($this->global->MAIN_MODULES_FOR_EXTERNAL)) $this->global->MAIN_MODULES_FOR_EXTERNAL='user,societe,propal,commande,facture,categorie,supplierproposal,fournisseur,contact,projet,contrat,ficheinter,expedition,agenda,resource,adherent'; // '' means 'all'. Note that contact is added here as it should be a module later. @@ -568,12 +561,12 @@ class Conf $this->expensereport->payment = new stdClass(); $this->expensereport->payment->warning_delay=(isset($this->global->MAIN_DELAY_EXPENSEREPORTS_TO_PAY)?$this->global->MAIN_DELAY_EXPENSEREPORTS_TO_PAY:0)*24*60*60; } - + if (! empty($this->global->PRODUIT_MULTIPRICES) && empty($this->global->PRODUIT_MULTIPRICES_LIMIT)) { $this->global->PRODUIT_MULTIPRICES_LIMIT = 5; } - + // For modules that want to disable top or left menu if (! empty($this->global->MAIN_HIDE_TOP_MENU)) $this->dol_hide_topmenu=$this->global->MAIN_HIDE_TOP_MENU; if (! empty($this->global->MAIN_HIDE_LEFT_MENU)) $this->dol_hide_leftmenu=$this->global->MAIN_HIDE_LEFT_MENU; @@ -581,11 +574,11 @@ class Conf if (empty($this->global->MAIN_SIZE_SHORTLIST_LIMIT)) $this->global->MAIN_SIZE_SHORTLIST_LIMIT=3; // Save inconsistent option - if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && $conf->global->AGENDA_DEFAULT_FILTER_TYPE == 'AC_NON_AUTO') + if (empty($conf->global->AGENDA_USE_EVENT_TYPE) && (! isset($conf->global->AGENDA_DEFAULT_FILTER_TYPE) || $conf->global->AGENDA_DEFAULT_FILTER_TYPE == 'AC_NON_AUTO')) { $conf->global->AGENDA_DEFAULT_FILTER_TYPE='0'; // 'AC_NON_AUTO' does not exists when AGENDA_DEFAULT_FILTER_TYPE is not on. } - + // For backward compatibility if (isset($this->product)) $this->produit=$this->product; if (isset($this->facture)) $this->invoice=$this->facture; @@ -633,7 +626,7 @@ class Conf $this->loghandlers[$handler] = $loghandlerinstance; } } - + } } diff --git a/htdocs/core/class/dolgraph.class.php b/htdocs/core/class/dolgraph.class.php index 4fb973160d4..4fad0149a5b 100644 --- a/htdocs/core/class/dolgraph.class.php +++ b/htdocs/core/class/dolgraph.class.php @@ -24,7 +24,18 @@ /** - * Parent class of graph classes + * Class to build graphs. + * Usage is: + * $dolgraph=new DolGraph(); + * $dolgraph->SetTitle($langs->transnoentities('Tracking_Projects_Pourcent').'
'.$langs->transnoentities('Tracking_IndicatorDefGraph').'%'); + * $dolgraph->SetMaxValue(50); + * $dolgraph->SetData($data); + * $dolgraph->setShowLegend(1); + * $dolgraph->setShowPercent(1); + * $dolgraph->SetType(array('pie')); + * $dolgraph->setWidth('100%'); + * $dolgraph->draw('idofgraph'); + * print $dolgraph->show(); */ class DolGraph { @@ -780,9 +791,9 @@ class DolGraph /** * Build a graph using JFlot library. Input when calling this method should be: - * $this->data = array(array( 0=>'labelxA', 1=>yA), array('labelxB',yB)); or + * $this->data = array(array(0=>'labelxA',1=>yA), array('labelxB',yB)); + * $this->data = array(array(0=>'labelxA',1=>yA1,...,n=>yAn), array('labelxB',yB1,...yBn)); // or when there is n series to show for each x * $this->data = array(array('label'=>'labelxA','data'=>yA), array('labelxB',yB)); // TODO Syntax not supported. Removed when dol_print_graph_removed - * $this->data = array(array(0=>'labelxA',1=>yA1,...,n=>yAn), array('labelxB',yB1,...yBn)); // when there is n series to show for each x * $this->legend= array("Val1",...,"Valn"); // list of n series name * $this->type = array('bars',...'lines'); or array('pie') * $this->mode = 'depth' ??? @@ -798,7 +809,7 @@ class DolGraph { global $artichow_defaultfont; - dol_syslog(get_class($this)."::draw_jflot this->type=".join(',',$this->type)); + dol_syslog(get_class($this)."::draw_jflot this->type=".join(',',$this->type)." this->MaxValue=".$this->MaxValue); if (empty($this->width) && empty($this->height)) { @@ -808,7 +819,7 @@ class DolGraph $legends=array(); $nblot=count($this->data[0])-1; // -1 to remove legend - if ($nblot < 0) dol_print_error('Bad value for property ->data. Must be set by mydolgraph->SetData before callinf mydolgrapgh->draw'); + if ($nblot < 0) dol_print_error('', 'Bad value for property ->data. Must be set by mydolgraph->SetData before calling mydolgrapgh->draw'); $firstlot=0; // Works with line but not with bars //if ($nblot > 2) $firstlot = ($nblot - 2); // We limit nblot to 2 because jflot can't manage more than 2 bars on same x diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index c89fc593745..4b5f151ec72 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -39,7 +39,7 @@ class ExtraFields // type of element (for what object is the extrafield) var $attribute_elementtype; - + // Array with type of the extra field var $attribute_type; // Array with label of extra field @@ -68,7 +68,10 @@ class ExtraFields var $attribute_list; // Array to store if extra field is hidden var $attribute_hidden; // warning, do not rely on this. If your module need a hidden data, it must use its own table. - + + // New array to store extrafields definition + var $attributes; + var $error; var $errno; @@ -95,7 +98,7 @@ class ExtraFields 'separate' => 'ExtrafieldSeparator', ); - + /** * Constructor * @@ -149,7 +152,7 @@ class ExtraFields // Create field into database except for separator type which is not stored in database if ($type != 'separate') { - $result=$this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $copmputed); + $result=$this->create($attrname, $type, $size, $elementtype, $unique, $required, $default_value, $param, $perms, $list, $computed); } $err1=$this->errno; if ($result > 0 || $err1 == 'DB_ERROR_COLUMN_ALREADY_EXISTS' || $type == 'separate') @@ -349,7 +352,7 @@ class ExtraFields $table=$elementtype.'_extrafields'; $error=0; - + if (! empty($attrname) && preg_match("/^\w[a-zA-Z0-9-_]*$/",$attrname)) { $result=$this->delete_label($attrname,$elementtype); @@ -381,7 +384,7 @@ class ExtraFields } } } - + return $result; } else @@ -640,26 +643,29 @@ class ExtraFields /** - * Load array this->attribute_xxx like attribute_label, attribute_type, ... + * Load array this->attributes, or old this->attribute_xxx like attribute_label, attribute_type, ... * - * @param string $elementtype Type of element ('adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...) - * @param boolean $forceload Force load of extra fields whatever is option MAIN_EXTRAFIELDS_DISABLED - * @return array Array of attributes for all extra fields + * @param string $elementtype Type of element ('adherent', 'commande', 'thirdparty', 'facture', 'propal', 'product', ...). + * @param boolean $forceload Force load of extra fields whatever is option MAIN_EXTRAFIELDS_DISABLED. Deprecated. Should not be required. + * @return array Array of attributes keys+label for all extra fields. */ function fetch_name_optionals_label($elementtype,$forceload=false) { global $conf; - if ( empty($elementtype) ) return array(); + if (empty($elementtype) ) return array(); if ($elementtype == 'thirdparty') $elementtype='societe'; if ($elementtype == 'contact') $elementtype='socpeople'; $array_name_label=array(); - // For avoid conflicts with external modules + // To avoid conflicts with external modules. TODO Remove this. if (!$forceload && !empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return $array_name_label; + // We should not have several time this log. If we have, there is some optimization to do by calling a simple $object->fetch_optionals() that include cache management. + dol_syslog("fetch_name_optionals_label elementtype=".$elementtype); + $sql = "SELECT rowid,name,label,type,size,elementtype,fieldunique,fieldrequired,param,pos,alwayseditable,perms,list,ishidden,fielddefault,fieldcomputed"; $sql.= " FROM ".MAIN_DB_PREFIX."extrafields"; $sql.= " WHERE entity IN (0,".$conf->entity.")"; @@ -673,12 +679,13 @@ class ExtraFields { while ($tab = $this->db->fetch_object($resql)) { - // we can add this attribute to adherent object + // We can add this attribute to object. TODO Remove this and return $this->attributes[$elementtype]['label'] if ($tab->type != 'separate') { $array_name_label[$tab->name]=$tab->label; } + // Old usage $this->attribute_type[$tab->name]=$tab->type; $this->attribute_label[$tab->name]=$tab->label; $this->attribute_size[$tab->name]=$tab->size; @@ -693,8 +700,25 @@ class ExtraFields $this->attribute_perms[$tab->name]=$tab->perms; $this->attribute_list[$tab->name]=$tab->list; $this->attribute_hidden[$tab->name]=$tab->ishidden; + + // New usage + $this->attributes[$tab->elementtype]['type'][$tab->name]=$tab->type; + $this->attributes[$tab->elementtype]['label'][$tab->name]=$tab->label; + $this->attributes[$tab->elementtype]['size'][$tab->name]=$tab->size; + $this->attributes[$tab->elementtype]['elementtype'][$tab->name]=$tab->elementtype; + $this->attributes[$tab->elementtype]['default'][$tab->name]=$tab->fielddefault; + $this->attributes[$tab->elementtype]['computed'][$tab->name]=$tab->fieldcomputed; + $this->attributes[$tab->elementtype]['unique'][$tab->name]=$tab->fieldunique; + $this->attributes[$tab->elementtype]['required'][$tab->name]=$tab->fieldrequired; + $this->attributes[$tab->elementtype]['param'][$tab->name]=($tab->param ? unserialize($tab->param) : ''); + $this->attributes[$tab->elementtype]['pos'][$tab->name]=$tab->pos; + $this->attributes[$tab->elementtype]['alwayseditable'][$tab->name]=$tab->alwayseditable; + $this->attributes[$tab->elementtype]['perms'][$tab->name]=$tab->perms; + $this->attributes[$tab->elementtype]['list'][$tab->name]=$tab->list; + $this->attributes[$tab->elementtype]['ishidden'][$tab->name]=$tab->ishidden; } } + if ($elementtype) $this->attributes[$elementtype]['loaded']=1; } else { @@ -735,8 +759,12 @@ class ExtraFields $list=$this->attribute_list[$key]; $hidden=$this->attribute_hidden[$key]; - if ($computed) return ''.$langs->trans("AutomaticallyCalculated").''; - + if ($computed) + { + if ($keysuffix != 'search_') return ''.$langs->trans("AutomaticallyCalculated").''; + else return ''; + } + if (empty($showsize)) { if ($type == 'date') @@ -772,14 +800,14 @@ class ExtraFields { $showsize = 'minwidth200imp'; } - else + else { //$showsize=48; $showsize = 'minwidth400imp'; } } } - + if (in_array($type,array('date','datetime'))) { $tmp=explode(',',$size); @@ -1029,7 +1057,7 @@ class ExtraFields { require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; $form = new Form($db); - + $value_arr=explode(',',$value); $out=$form->multiselectarray($keysuffix.'options_'.$key.$keyprefix, $param['options'], $value_arr, '', 0, '', 0, '100%'); @@ -1124,9 +1152,9 @@ class ExtraFields if ($resql) { $num = $this->db->num_rows($resql); $i = 0; - + $data=array(); - + while ( $i < $num ) { $labeltoshow = ''; $obj = $this->db->fetch_object($resql); @@ -1152,9 +1180,9 @@ class ExtraFields $labeltoshow = dol_trunc($obj->$field_toshow, 18) . ' '; } } - + $data[$obj->rowid]=$labeltoshow; - + } else { if (! $notrans) { $translabel = $langs->trans($obj->{$InfoFieldList[1]}); @@ -1177,16 +1205,16 @@ class ExtraFields $data[$obj->rowid]=$labeltoshow; } - + $i ++; } $this->db->free($resql); - + require_once DOL_DOCUMENT_ROOT.'/core/class/html.form.class.php'; $form = new Form($db); - + $out=$form->multiselectarray($keysuffix.'options_'.$key.$keyprefix, $data, $value_arr, '', 0, '', 0, '100%'); - + } else { print 'Error in request ' . $sql . ' ' . $this->db->lasterror() . '. Check setup of extra parameters.
'; } @@ -1205,11 +1233,11 @@ class ExtraFields if ($InfoFieldList[0] && class_exists($InfoFieldList[0])) { $valuetoshow=$value; - if (!empty($value)) + if (!empty($value)) { $object = new $InfoFieldList[0]($this->db); $resfetch=$object->fetch($value); - if ($resfetch > 0) + if ($resfetch > 0) { $valuetoshow=$object->ref; if ($object->element == 'societe') $valuetoshow=$object->name; // Special case for thirdparty because ->ref is not name but id (because name is not unique) @@ -1269,7 +1297,7 @@ class ExtraFields //var_dump($computed); $value = dol_eval($computed, 1, 0); } - + $showsize=0; if ($type == 'date') { @@ -1477,7 +1505,7 @@ class ExtraFields } } $value='
    '.implode(' ', $toprint).'
'; - + } else { dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); } @@ -1681,7 +1709,7 @@ class ExtraFields // Clean parameters $value_key=dol_mktime($_POST[$keysuffix."options_".$key.$keyprefix."hour"], $_POST[$keysuffix."options_".$key.$keyprefix."min"], 0, $_POST[$keysuffix."options_".$key.$keyprefix."month"], $_POST[$keysuffix."options_".$key.$keyprefix."day"], $_POST[$keysuffix."options_".$key.$keyprefix."year"]); } - else if (in_array($key_type,array('checkbox'))) + else if (in_array($key_type,array('checkbox', 'chkbxlst'))) { $value_arr=GETPOST($keysuffix."options_".$key.$keyprefix); // Make sure we get an array even if there's only one checkbox diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 22b26983bcc..a273443ef7c 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -275,7 +275,7 @@ class Fiscalyear extends CommonObject if ($mode == 5) { if ($statut==0 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut4'); - if ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut8'); + if ($statut==1 && ! empty($this->statuts_short[$statut])) return $langs->trans($this->statuts_short[$statut]).' '.img_picto($langs->trans($this->statuts_short[$statut]),'statut6'); } } diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 590f8060296..31833c113b4 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -43,6 +43,8 @@ class HookManager var $resArray=array(); // Printable result var $resPrint=''; + // Nb of qualified hook ran + var $resNbOfHooks=0; /** * Constructor @@ -57,15 +59,14 @@ class HookManager /** * Init array $this->hooks with instantiated action controlers. - * First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS - * with value 'nameofcontext1:nameofcontext2:...' into $this->const of module descriptor file. + * First, a hook is declared by a module by adding a constant MAIN_MODULE_MYMODULENAME_HOOKS with value 'nameofcontext1:nameofcontext2:...' into $this->const of module descriptor file. * This makes $conf->hooks_modules loaded with an entry ('modulename'=>array(nameofcontext1,nameofcontext2,...)) * When initHooks function is called, with initHooks(list_of_contexts), an array $this->hooks is defined with instance of controler * class found into file /mymodule/class/actions_mymodule.class.php (if module has declared the context as a managed context). * Then when a hook executeHooks('aMethod'...) is called, the method aMethod found into class will be executed. * * @param string[] $arraycontext Array list of searched hooks tab/features. For example: 'thirdpartycard' (for hook methods into page card thirdparty), 'thirdpartydao' (for hook methods into Societe), ... - * @return int Always 1 + * @return int Always 1 */ function initHooks($arraycontext) { @@ -121,7 +122,7 @@ class HookManager * All types can also return some values into an array ->results that will be finaly merged into this->resArray for caller. * $this->error or this->errors are also defined by class called by this function if error. */ - function executeHooks($method, $parameters=false, &$object='', &$action='') + function executeHooks($method, $parameters=array(), &$object='', &$action='') { if (! is_array($this->hooks) || empty($this->hooks)) return ''; @@ -133,11 +134,14 @@ class HookManager if (in_array( $method, array( - 'addMoreActionsButtons', + 'addCalendarChoice', + 'addMoreActionsButtons', + 'addMoreMassActions', 'addSearchEntry', 'addStatisticLine', - 'deleteFile', + 'deleteFile', 'doActions', + 'doMassActions', 'formCreateThirdpartyOptions', 'formObjectOptions', 'formattachOptions', @@ -169,7 +173,6 @@ class HookManager 'printSearchForm', 'printTabsHead', 'formatEvent', - 'addCalendarChoice', 'printObjectLine', 'printObjectSubLine', 'createDictionaryFieldList', @@ -181,14 +184,16 @@ class HookManager if ($method == 'insertExtraFields') { - $hooktype='returnvalue'; // deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available. + $hooktype='returnvalue'; // @deprecated. TODO Remove all code with "executeHooks('insertExtraFields'" as soon as there is a trigger available. dol_syslog("Warning: The hook 'insertExtraFields' is deprecated and must not be used. Use instead trigger on CRUD event (ask it to dev team if not implemented)", LOG_WARNING); } + // Init return properties + $this->resPrint=''; $this->resArray=array(); $this->resNbOfHooks=0; + // Loop on each hook to qualify modules that have declared context $modulealreadyexecuted=array(); $resaction=0; $error=0; $result=''; - $this->resPrint=''; $this->resArray=array(); foreach($this->hooks as $context => $modules) // $this->hooks is an array with context as key and value is an array of modules that handle this context { if (! empty($modules)) @@ -197,14 +202,16 @@ class HookManager { //print "Before hook ".get_class($actionclassinstance)." method=".$method." hooktype=".$hooktype." results=".count($actionclassinstance->results)." resprints=".count($actionclassinstance->resprints)." resaction=".$resaction." result=".$result."
\n"; + // test to avoid running twice a hook, when a module implements several active contexts + if (in_array($module,$modulealreadyexecuted)) continue; + // jump to next module/class if method does not exist if (! method_exists($actionclassinstance,$method)) continue; - // test to avoid running twice a hook, when a module implements several active contexts - if (in_array($module,$modulealreadyexecuted)) continue; - + $this->resNbOfHooks++; + dol_syslog(get_class($this).'::executeHooks a qualified hook was found for method='.$method.' module='.$module." action=".$action." context=".$context); - + $modulealreadyexecuted[$module]=$module; // Use the $currentcontext in method to avoid running twice // Clean class (an error may have been set from a previous call of another method for same module/hook) @@ -231,7 +238,7 @@ class HookManager // Generic hooks that return a string or array (printLeftBlock, formAddObjectLine, formBuilddocOptions, ...) else { - // TODO. this should be done into the method of hook by returning nothing + // TODO. this test should be done into the method of hook by returning nothing if (is_array($parameters) && ! empty($parameters['special_code']) && $parameters['special_code'] > 3 && $parameters['special_code'] != $actionclassinstance->module_number) continue; //dol_syslog("Call method ".$method." of class ".get_class($actionclassinstance).", module=".$module.", hooktype=".$hooktype, LOG_DEBUG); @@ -239,7 +246,7 @@ class HookManager if (! empty($actionclassinstance->results) && is_array($actionclassinstance->results)) $this->resArray =array_merge($this->resArray, $actionclassinstance->results); if (! empty($actionclassinstance->resprints)) $this->resPrint.=$actionclassinstance->resprints; - // TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string. we must use $actionclassinstance->resprints to return a string + // TODO dead code to remove (do not enable this, but fix hook instead): result must not be a string but an int. you must use $actionclassinstance->resprints to return a string if (! is_array($resaction) && ! is_numeric($resaction)) { dol_syslog('Error: Bug into hook '.$method.' of module class '.get_class($actionclassinstance).'. Method must not return a string but an int (0=OK, 1=Replace, -1=KO) and set string into ->resprints', LOG_ERR); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 640c784436a..e291277d8e4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -545,11 +545,20 @@ class Form $disabled=0; $ret='
'; $ret.=''; // Warning: if you set submit button to disabled, post using 'Enter' will no more work. $ret.=''; @@ -975,6 +984,7 @@ class Form if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->COMPANY_USE_SEARCH_TO_SELECT) && ! $forcecombo) { + // No immediate load of all database $placeholder=''; if ($selected && empty($selected_input_value)) { @@ -985,7 +995,7 @@ class Form unset($societetmp); } // mode 1 - $urloption='htmlname='.$htmlname.'&outjson=1&filter='.$filter; + $urloption='htmlname='.$htmlname.'&outjson=1&filter='.$filter.($showtype?'&showtype='.$showtype:''); $out.= ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/societe/ajax/company.php', $urloption, $conf->global->COMPANY_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); $out.=' - + '; - + if (empty($user->societe_id)) // If internal user or not defined { @@ -182,7 +194,7 @@ if (! class_exists('MenuManager')) } $menumanager = new MenuManager($db, empty($user->societe_id)?0:1); $menumanager->loadMenu('all','all'); -//var_dump($menumanager->tabMenu);exit; +//var_dump($menumanager);exit; $menumanager->showmenu('jmobile'); print ''; diff --git a/htdocs/core/js/timesheet.js b/htdocs/core/js/timesheet.js index ea0e0782767..5541f348c9f 100644 --- a/htdocs/core/js/timesheet.js +++ b/htdocs/core/js/timesheet.js @@ -1,5 +1,5 @@ -/* Copyright (C) 2014 delcroip - * Laurent Destailleur 2015 +/* Copyright (C) 2014 delcroip + * Copyright (C) 2015-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 diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index 6a0336aab38..e90f006ac7e 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -756,7 +756,7 @@ function purgeSessions($mysessionid) */ function activateModule($value,$withdeps=1) { - global $db, $modules, $langs, $conf; + global $db, $modules, $langs, $conf, $mysoc; // Check parameters if (empty($value)) { @@ -813,7 +813,7 @@ function activateModule($value,$withdeps=1) } $result=$objMod->init(); // Enable module - if ($result <= 0) + if ($result <= 0) { $ret['errors'][]=$objMod->error; } @@ -825,7 +825,7 @@ function activateModule($value,$withdeps=1) { // Activation of modules this module depends on // this->depends may be array('modModule1', 'mmodModule2') or array('always'=>"modModule1", 'FR'=>'modModule2') - foreach ($objMod->depend as $key => $modulestring) + foreach ($objMod->depends as $key => $modulestring) { if ((! is_numeric($key)) && $key != 'always' && $key != $mysoc->country_code) { @@ -848,19 +848,19 @@ function activateModule($value,$withdeps=1) break; } } - + if ($activate) { $ret['nbmodules']+=$resarray['nbmodules']; $ret['nbperms']+=$resarray['nbperms']; } - else + else { $ret['errors'][] = $langs->trans('activateModuleDependNotSatisfied', $objMod->name, $modulestring); } } } - + if (isset($objMod->conflictwith) && is_array($objMod->conflictwith) && ! empty($objMod->conflictwith)) { // Desactivation des modules qui entrent en conflit @@ -879,12 +879,12 @@ function activateModule($value,$withdeps=1) } } - if (! count($ret['errors'])) + if (! count($ret['errors'])) { $ret['nbmodules']++; $ret['nbperms']+=count($objMod->rights); } - + return $ret; } @@ -1221,7 +1221,7 @@ function form_constantes($tableau, $strictw3c=0, $helptext='') if ($result) { $obj = $db->fetch_object($result); // Take first result of select - + // For avoid warning in strict mode if (empty($obj)) { @@ -1360,7 +1360,7 @@ function showModulesExludedForExternal($modules) //if (empty($conf->global->$moduleconst)) continue; if (! in_array($modulename,$listofmodules)) continue; //var_dump($modulename.'eee'.$langs->trans('Module'.$module->numero.'Name')); - + if ($i > 0) $text.=', '; else $text.=' '; $i++; @@ -1391,7 +1391,7 @@ function addDocumentModel($name, $type, $label='', $description='') $sql.= ($label?"'".$db->escape($label)."'":'null').", "; $sql.= (! empty($description)?"'".$db->escape($description)."'":"null"); $sql.= ")"; - + dol_syslog("admin.lib::addDocumentModel", LOG_DEBUG); $resql=$db->query($sql); if ($resql) diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index 4e9b458c3d0..5ac0982a3a0 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -85,7 +85,7 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh { include_once DOL_DOCUMENT_ROOT . '/resource/class/html.formresource.class.php'; $formresource=new FormResource($db); - + // Resource print ''; print ''; @@ -94,7 +94,7 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh print $formresource->select_resource_list($resourceid, "resourceid", '', 1, 0, 0, null, '', 2); print ''; } - + include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php'; $formactions=new FormActions($db); @@ -251,7 +251,7 @@ function show_array_actions_to_do($max=5) while ($i < $num) { $obj = $db->fetch_object($resql); - + print ''; @@ -347,7 +347,7 @@ function show_array_last_actions_done($max=5) while ($i < $num) { $obj = $db->fetch_object($resql); - + print ''; @@ -458,7 +458,7 @@ function actions_prepare_head($object) { include_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; $resource=new DolResource($db); - + $head[$h][0] = DOL_URL_ROOT.'/resource/element_resource.php?element=action&element_id='.$object->id; $listofresourcelinked = $resource->getElementResources($object->element, $object->id); $nbResources=count($listofresourcelinked); @@ -506,6 +506,11 @@ function calendars_prepare_head($param) $h = 0; $head = array(); + $head[$h][0] = DOL_URL_ROOT.'/comm/action/listactions.php'.($param?'?'.$param:''); + $head[$h][1] = $langs->trans("ViewList"); + $head[$h][2] = 'cardlist'; + $h++; + $head[$h][0] = DOL_URL_ROOT.'/comm/action/index.php?action=show_day'.($param?'&'.$param:''); $head[$h][1] = $langs->trans("ViewDay"); $head[$h][2] = 'cardday'; @@ -529,16 +534,12 @@ function calendars_prepare_head($param) $head[$h][2] = 'cardpertype'; $h++; } - + $head[$h][0] = DOL_URL_ROOT.'/comm/action/peruser.php'.($param?'?'.$param:''); $head[$h][1] = $langs->trans("ViewPerUser"); $head[$h][2] = 'cardperuser'; $h++; - $head[$h][0] = DOL_URL_ROOT.'/comm/action/listactions.php'.($param?'?'.$param:''); - $head[$h][1] = $langs->trans("ViewList"); - $head[$h][2] = 'cardlist'; - $h++; $object=new stdClass(); diff --git a/htdocs/core/lib/ajax.lib.php b/htdocs/core/lib/ajax.lib.php index d278f29b897..705bcf6deab 100644 --- a/htdocs/core/lib/ajax.lib.php +++ b/htdocs/core/lib/ajax.lib.php @@ -37,9 +37,9 @@ * @param int $autoselect Automatic selection if just one value * @param array $ajaxoptions Multiple options array * Ex: array('update'=>array('field1','field2'...)) will reset field1 and field2 once select done - * Ex: array('disabled'=> - * Ex: array('show'=> - * Ex: array('update_textarea'=> + * Ex: array('disabled'=> ) + * Ex: array('show'=> ) + * Ex: array('update_textarea'=> ) * @return string Script */ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array()) @@ -181,12 +181,12 @@ function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLengt }); } console.log("ajax_autocompleter new value selected, we trigger change on original component so field #search_'.$htmlname.'"); - + $("#search_'.$htmlname.'").trigger("change"); // We have changed value of the combo select, we must be sure to trigger all js hook binded on this event. This is required to trigger other javascript change method binded on original field by other code. } ,delay: 500 }).data("ui-autocomplete")._renderItem = function( ul, item ) { - + return $("
  • ") .data( "ui-autocomplete-item", item ) // jQuery UI > 1.10.0 .append( \'\' + item.label + "" ) @@ -352,8 +352,8 @@ function ajax_dialog($title,$message,$w=350,$h=150) /** * Make content of an input box selected when we click into input field. - * - * @param string $htmlname Id of html object + * + * @param string $htmlname Id of html object * @param string $addlink Add a 'link to' after */ function ajax_autoselect($htmlname, $addlink='') @@ -383,7 +383,7 @@ function ajax_autoselect($htmlname, $addlink='') function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve') { global $conf; - + if (! empty($conf->browser->phone)) return ''; // select2 disabled for smartphones with standard browser (does not works, popup appears outside screen) if (! empty($conf->dol_use_jmobile)) return ''; // select2 works with jmobile but it breaks the autosize feature of jmobile. if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return ''; @@ -392,13 +392,13 @@ function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $ if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0; $tmpplugin='select2'; - $msg=' + $msg=' '."\n"; + print "\n".''."\n"; + print ''."\n"; } diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index 69ee228504d..72f27a16602 100755 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -98,7 +98,7 @@ function dolGetModulesDirs($subdir='') while (($file = readdir($handle))!==false) { if (preg_match('/disabled/',$file)) continue; // We discard module if it contains disabled into name. - + if (is_dir($dirroot.'/'.$file) && substr($file, 0, 1) <> '.' && substr($file, 0, 3) <> 'CVS' && $file != 'includes') { if (is_dir($dirroot . '/' . $file . '/core/modules'.$subdir.'/')) @@ -207,7 +207,7 @@ function dol_print_object_info($object, $usetable=0) //print "x".$deltadateforserver." - ".$deltadateforclient." - ".$deltadateforuser; if ($usetable) print ''; - + // Import key if (! empty($object->import_key)) { @@ -378,7 +378,7 @@ function dol_print_object_info($object, $usetable=0) if ($usetable) print ''; else print '
    '; } - + // Date approve if (! empty($object->date_approve2)) { @@ -391,7 +391,7 @@ function dol_print_object_info($object, $usetable=0) if ($usetable) print ''; else print '
    '; } - + // User close if (! empty($object->user_cloture)) { @@ -476,7 +476,7 @@ function dol_print_object_info($object, $usetable=0) if ($usetable) print ''; else print '
    '; } - + if ($usetable) print '
    '; } @@ -790,16 +790,16 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m $maskpersonew[$regKey[1]]=str_pad('', '_', $regKey[2], STR_PAD_RIGHT); $tmpmask=preg_replace('/\{'.$regKey[1].'\-'.$regKey[2].'\}/i', $maskpersonew, $tmpmask); }*/ - - if(strstr($mask,'extra_')){ - $start = "{extra_"; + if (strstr($mask,'user_extra_')) + { + $start = "{user_extra_"; $end = "\}"; - $extra= get_string_between($mask, "extra_", "}"); + $extra= get_string_between($mask, "user_extra_", "}"); if(!empty($user->array_options['options_'.$extra])){ - $mask = preg_replace('#('.($start).')(.*?)('.($end).')#si', $user->array_options['options_'.$extra], $mask); + $mask = preg_replace('#('.$start.')(.*?)('.$end.')#si', $user->array_options['options_'.$extra], $mask); } - } + } $maskwithonlyymcode=$mask; $maskwithonlyymcode=preg_replace('/\{(0+)([@\+][0-9\-\+\=]+)?([@\+][0-9\-\+\=]+)?\}/i',$maskcounter,$maskwithonlyymcode); $maskwithonlyymcode=preg_replace('/\{dd\}/i','dd',$maskwithonlyymcode); @@ -928,11 +928,11 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m //print "masktri=".$masktri." maskcounter=".$maskcounter." maskraz=".$maskraz." maskoffset=".$maskoffset."
    \n"; // Define $sqlstring - if (function_exists('mb_strrpos')) + if (function_exists('mb_strrpos')) { $posnumstart=mb_strrpos($maskwithnocode,$maskcounter, 'UTF-8'); - } - else + } + else { $posnumstart=strrpos($maskwithnocode,$maskcounter); } // Pos of counter in final string (from 0 to ...) @@ -1123,7 +1123,7 @@ function get_string_between($string, $start, $end){ $string = " ".$string; $ini = strpos($string,$start); if ($ini == 0) return ""; - $ini += strlen($start); + $ini += strlen($start); $len = strpos($string,$end,$ini) - $ini; return substr($string,$ini,$len); } @@ -1539,9 +1539,9 @@ function getListOfModels($db,$type,$maxfilenamelength=0) $sql = "SELECT nom as id, nom as lib, libelle as label, description as description"; $sql.= " FROM ".MAIN_DB_PREFIX."document_model"; $sql.= " WHERE type = '".$type."'"; - $sql.= " AND entity IN (0,".(! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)?"1,":"").$conf->entity.")"; + $sql.= " AND entity IN (0,".$conf->entity.")"; $sql.= " ORDER BY description DESC"; - + dol_syslog('/core/lib/function2.lib.php::getListOfModels', LOG_DEBUG); $resql = $db->query($sql); if ($resql) @@ -1625,7 +1625,7 @@ function getListOfModels($db,$type,$maxfilenamelength=0) /** * This function evaluates a string that should be a valid IPv4 * Note: For ip 169.254.0.0, it returns 0 with some PHP (5.6.24) and 2 with some minor patchs of PHP (5.6.25). See https://github.com/php/php-src/pull/1954. - * + * * @param string $ip IP Address * @return int 0 if not valid or reserved range, 1 if valid and public IP, 2 if valid and private range IP */ @@ -2121,8 +2121,8 @@ function colorStringToArray($stringcolor,$colorifnotfound=array(88,88,88)) * Applies the Cartesian product algorithm to an array * Source: http://stackoverflow.com/a/15973172 * - * @param array $input Array of products - * @return array Array of combinations + * @param array $input Array of products + * @return array Array of combinations */ function cartesianArray(array $input) { // filter out empty values @@ -2145,3 +2145,70 @@ function cartesianArray(array $input) { return $result; } + + +/** + * Get name of directory where the api_...class.php file is stored + * + * @param string $module Module name + * @return string Directory name + */ +function getModuleDirForApiClass($module) +{ + $moduledirforclass=$module; + + if (in_array($module, array('login', 'access', 'status', 'documents'))) { + $moduledirforclass = 'api'; + } + if (preg_match('/^dictionary/', $module)) { + $moduledirforclass = 'api'; + } + + if ($module == 'contact' || $module == 'contacts' || $module == 'customer' || $module == 'thirdparty' || $module == 'thirdparties') { + $moduledirforclass = 'societe'; + } + if ($module == 'propale' || $module == 'proposals') { + $moduledirforclass = 'comm/propal'; + } + elseif ($module == 'agenda' || $module == 'agendaevents') { + $moduledirforclass = 'comm/action'; + } + elseif ($module == 'adherent' || $module == 'members' || $module == 'memberstypes' || $module == 'subscriptions') { + $moduledirforclass = 'adherents'; + } + elseif ($module == 'banque' || $module == 'bankaccounts') { + $moduledirforclass = 'compta/bank'; + } + elseif ($module == 'category' || $module == 'categorie') { + $moduledirforclass = 'categories'; + } + elseif ($module == 'order' || $module == 'orders') { + $moduledirforclass = 'commande'; + } + elseif ($module == 'facture' || $module == 'invoice' || $module == 'invoices') { + $moduledirforclass = 'compta/facture'; + } + elseif ($module == 'products') { + $moduledirforclass = 'product'; + } + elseif ($module == 'project' || $module == 'projects' || $module == 'tasks') { + $moduledirforclass = 'projet'; + } + elseif ($module == 'task') { + $moduledirforclass = 'projet'; + } + elseif ($module == 'stock' || $module == 'stockmovements' || $module == 'warehouses') { + $moduledirforclass = 'product/stock'; + } + elseif ($module == 'fournisseur' || $module == 'supplierinvoices') { + $moduledirforclass = 'fourn'; + } + elseif ($module == 'expensereports') { + $moduledirforclass = 'expensereport'; + } + elseif ($module == 'users') { + $moduledirforclass = 'user'; + } + + return $moduledirforclass; +} diff --git a/htdocs/core/lib/images.lib.php b/htdocs/core/lib/images.lib.php index acfa917720e..d9d7d0d9730 100644 --- a/htdocs/core/lib/images.lib.php +++ b/htdocs/core/lib/images.lib.php @@ -38,7 +38,7 @@ $quality = 80; function image_format_supported($file) { $regeximgext='\.gif|\.jpg|\.jpeg|\.png|\.bmp|\.xpm|\.xbm'; // See also into product.class.php - + // Case filename is not a format image if (! preg_match('/('.$regeximgext.')$/i',$file,$reg)) return -1; @@ -90,7 +90,7 @@ function dol_getImageSize($file, $url = false) $ret['width']=$infoImg[0]; // Largeur de l'image $ret['height']=$infoImg[1]; // Hauteur de l'image } - + return $ret; } @@ -438,6 +438,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $ dol_mkdir($dirthumb); // Initialisation des variables selon l'extension de l'image + $img=null; switch($infoImg[2]) { case IMAGETYPE_GIF: // 1 diff --git a/htdocs/core/lib/json.lib.php b/htdocs/core/lib/json.lib.php index 6b868663aa7..7388ba47806 100644 --- a/htdocs/core/lib/json.lib.php +++ b/htdocs/core/lib/json.lib.php @@ -49,12 +49,15 @@ function dol_json_encode($elements) { dol_syslog('dol_json_encode() is deprecated. Please update your code to use native json_encode().', LOG_WARNING); - $num=count($elements); + $num=0; if (is_object($elements)) // Count number of properties for an object { - $num=0; foreach($elements as $key => $value) $num++; } + else + { + $num=count($elements); + } //var_dump($num); // determine type diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index e83faee6c8d..614379a2900 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -588,38 +588,26 @@ function pdf_pagehead(&$pdf,$outputlangs,$page_height) /** - * Return array of possible substitutions + * Return array of possible substitutions for PDF content (without external module substitutions). * * @param Translate $outputlangs Output language + * @param array $exclude Array of family keys we want to exclude. For example array('mycompany', 'object', 'date', 'user', ...) + * @param Object $object Object * @return array Array of substitutions */ -function pdf_getSubstitutionArray($outputlangs) +function pdf_getSubstitutionArray($outputlangs, $exclude=null, $object=null) { - global $conf, $mysoc, $user; - $substitutionarray=array( - '__MYCOMPANY_NAME__' => $mysoc->name, - '__MYCOMPANY_EMAIL__' => $mysoc->email, - '__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, - '__USER_FULLNAME__' => $user->getFullName($outputlangs) - ); - return $substitutionarray; + $substitutionarray = getCommonSubstitutionArray($outputlangs, 0, $exclude, $object); + $substitutionarray['__FROM_NAME__']='__FROM_NAME__'; + $substitutionarray['__FROM_EMAIL__']='__FROM_EMAIL__'; + return $substitutionarray; } /** * Add a draft watermark on PDF files * - * @param TCPDF $pdf Object PDF + * @param TCPDF $pdf Object PDF * @param Translate $outputlangs Object lang * @param int $h Height of PDF * @param int $w Width of PDF @@ -630,7 +618,7 @@ function pdf_getSubstitutionArray($outputlangs) function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text) { global $langs, $mysoc, $user; - + // Print Draft Watermark if ($unit=='pt') $k=1; elseif ($unit=='mm') $k=72/25.4; @@ -638,11 +626,11 @@ function pdf_watermark(&$pdf, $outputlangs, $h, $w, $unit, $text) elseif ($unit=='in') $k=72; // Make substitution - $substitutionarray=pdf_getSubstitutionArray($outputlangs); - complete_substitutions_array($substitutionarray,$outputlangs,$object); - $text=make_substitutions($text,$substitutionarray,$outputlangs); + $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, null); + complete_substitutions_array($substitutionarray, $outputlangs, null); + $text=make_substitutions($text, $substitutionarray, $outputlangs); $text=$outputlangs->convToOutputCharset($text); - + $savx=$pdf->getX(); $savy=$pdf->getY(); $watermark_angle=atan($h/$w)/2; @@ -867,15 +855,19 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass // Line of free text if (empty($hidefreetext) && ! empty($conf->global->$paramfreetext)) { - $substitutionarray=pdf_getSubstitutionArray($outputlangs); + $substitutionarray=pdf_getSubstitutionArray($outputlangs, null, $object); // More substitution keys $substitutionarray['__FROM_NAME__']=$fromcompany->name; $substitutionarray['__FROM_EMAIL__']=$fromcompany->email; - $substitutionarray['__TOTAL_TTC__']=$object->total_ttc; - $substitutionarray['__TOTAL_HT__']=$object->total_ht; - $substitutionarray['__TOTAL_VAT__']=$object->total_vat; - complete_substitutions_array($substitutionarray,$outputlangs,$object); - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray,$outputlangs); + complete_substitutions_array($substitutionarray, $outputlangs, $object); + $newfreetext=make_substitutions($conf->global->$paramfreetext, $substitutionarray, $outputlangs); + + // Make a change into HTML code to allow to include images from medias directory. + // + // become + // + $newfreetext=preg_replace('/()/', '\1'.DOL_DATA_ROOT.'/medias/\2\3', $newfreetext); + $line.=$outputlangs->convToOutputCharset($newfreetext); } @@ -1076,10 +1068,10 @@ function pdf_pagefoot(&$pdf,$outputlangs,$paramfreetext,$fromcompany,$marge_bass // Show page nb only on iso languages (so default Helvetica font) if (strtolower(pdf_getPDFFont($outputlangs)) == 'helvetica') { - $pdf->SetXY(-20,-$posy); + $pdf->SetXY($dims['wk']-$dims['rm']-15, -$posy); //print 'xxx'.$pdf->PageNo().'-'.$pdf->getAliasNbPages().'-'.$pdf->getAliasNumPage();exit; - if (empty($conf->global->MAIN_USE_FPDF)) $pdf->MultiCell(13, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0); - else $pdf->MultiCell(13, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0); + if (empty($conf->global->MAIN_USE_FPDF)) $pdf->MultiCell(15, 2, $pdf->PageNo().'/'.$pdf->getAliasNbPages(), 0, 'R', 0); + else $pdf->MultiCell(15, 2, $pdf->PageNo().'/{nb}', 0, 'R', 0); } return $marginwithfooter; @@ -1289,16 +1281,16 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl if (empty($hideref)) { - if ($issupplierline) + if ($issupplierline) { if ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 1) $ref_prodserv = $ref_supplier; elseif ($conf->global->PDF_HIDE_PRODUCT_REF_IN_SUPPLIER_LINES == 2) - $ref_prodserv = $ref_supplier. ' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')'; - else + $ref_prodserv = $ref_supplier. ' ('.$outputlangs->transnoentitiesnoconv("InternalRef").' '.$prodser->ref.')'; + else $ref_prodserv = $prodser->ref.' ('.$outputlangs->transnoentitiesnoconv("SupplierRef").' '.$ref_supplier.')'; } - else + else $ref_prodserv = $prodser->ref; // Show local ref only if (! empty($libelleproduitservice)) $ref_prodserv .= " - "; diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php index 5aec64f3ce0..7048b8570c6 100644 --- a/htdocs/core/lib/product.lib.php +++ b/htdocs/core/lib/product.lib.php @@ -441,7 +441,8 @@ function measuring_units_string($unit,$measuring_style='') $measuring_units[0] = $langs->transnoentitiesnoconv("WeightUnitkg"); $measuring_units[-3] = $langs->transnoentitiesnoconv("WeightUnitg"); $measuring_units[-6] = $langs->transnoentitiesnoconv("WeightUnitmg"); - $measuring_units[99] = $langs->transnoentitiesnoconv("WeightUnitpound"); + $measuring_units[98] = $langs->transnoentitiesnoconv("WeightUnitounce"); + $measuring_units[99] = $langs->transnoentitiesnoconv("WeightUnitpound"); } else if ($measuring_style == 'size') { diff --git a/htdocs/core/lib/project.lib.php b/htdocs/core/lib/project.lib.php index 38f78dd8333..c3583e72ac8 100644 --- a/htdocs/core/lib/project.lib.php +++ b/htdocs/core/lib/project.lib.php @@ -35,7 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; function project_prepare_head($object) { global $db, $langs, $conf, $user; - + $h = 0; $head = array(); @@ -119,7 +119,7 @@ function project_prepare_head($object) } $head[$h][2] = 'agenda'; $h++; - + complete_head_from_modules($conf,$langs,$object,$head,$h,'project','remove'); return $head; @@ -163,7 +163,7 @@ function task_prepare_head($object) if ($obj) $nbTimeSpent=1; } else dol_print_error($db); - + $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':''); $head[$h][1] = $langs->trans("TimeSpent"); if ($nbTimeSpent > 0) $head[$h][1].= ' ...'; @@ -208,9 +208,10 @@ function task_prepare_head($object) * Prepare array with list of tabs * * @param string $mode Mode + * @param string $fuser Filter on user * @return array Array of tabs to show */ -function project_timesheet_prepare_head($mode) +function project_timesheet_prepare_head($mode, $fuser=null) { global $langs, $conf, $user; $h = 0; @@ -218,9 +219,13 @@ function project_timesheet_prepare_head($mode) $h = 0; + $param=''; + $param.=($mode?'&mode='.$mode:''); + if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) $param.='&search_usertoprocessid='.$fuser->id; + if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK)) { - $head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($mode?'?mode='.$mode:''); + $head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($param?'?'.$param:''); $head[$h][1] = $langs->trans("InputPerWeek"); $head[$h][2] = 'inputperweek'; $h++; @@ -228,7 +233,7 @@ function project_timesheet_prepare_head($mode) if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERTIME)) { - $head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($mode?'?mode='.$mode:''); + $head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($param?'?'.$param:''); $head[$h][1] = $langs->trans("InputPerDay"); $head[$h][2] = 'inputperday'; $h++; @@ -507,7 +512,7 @@ function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$t if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick); $level--; } - + $total_projectlinesa_spent += $lines[$i]->duration; $total_projectlinesa_planned += $lines[$i]->planned_workload; if ($lines[$i]->planned_workload) $total_projectlinesa_spent_if_planned += $lines[$i]->duration; @@ -571,9 +576,9 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr $lastprojectid=0; $workloadforid=array(); $lineswithoutlevel0=array(); - + $numlines=count($lines); - + // Create a smaller array with sublevels only to be used later. This increase dramatically performances. if ($parent == 0) // Always and only if at first level { @@ -581,7 +586,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr { if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i]; } - } + } //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0)); for ($i = 0 ; $i < $numlines ; $i++) @@ -594,7 +599,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr if (empty($mine) || ! empty($tasksrole[$lines[$i]->id])) { //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project); - + // Break on a new project if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) { @@ -604,7 +609,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr $projectstatic->id = $lines[$i]->fk_project; } } - + if (empty($workloadforid[$projectstatic->id])) { if ($preselectedday) @@ -613,7 +618,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr $workloadforid[$projectstatic->id]=1; } } - + $projectstatic->id=$lines[$i]->fk_project; $projectstatic->ref=$lines[$i]->projectref; $projectstatic->title=$lines[$i]->projectlabel; @@ -621,7 +626,12 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr $taskstatic->id=$lines[$i]->id; - print "\n"; + print ''."\n"; + + // User + print ''; + print $fuser->getNomUrl(1, 'withproject', 'time'); + print ''; // Ref print ''; @@ -656,7 +666,7 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr print $thirdpartystatic->getNomUrl(1, 'project', 10); print ''; } - + // Planned Workload print ''; if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin'); @@ -707,7 +717,10 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr print ''; $tableCell=$form->select_date($preselectedday,$lines[$i]->id,1,1,2,"addtime",0,0,1,$disabledtask); print $tableCell; - print ''; + print ''; + + // Duration + print ''; $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id]; $alreadyspent=''; @@ -723,24 +736,25 @@ function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsr print ''; print ''; - if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("YouAreNotContactOfProject")); - else if ($disabledtask) print $form->textwithpicto('',$langs->trans("TaskIsNotAffectedToYou")); - print ''; - - print ''; - print ''; print ''; - + + // Warning + print ''; + if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject")); + else if ($disabledtask) print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $langs->transnoentitiesnoconv("AssignTaskToUser", '...'))); + print ''; + print "\n"; } $inc++; $level++; - if ($lines[$i]->id > 0) + if ($lines[$i]->id > 0) { if ($parent == 0) projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var); - else projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var); + else projectLinesPerDay($inc, $lines[$i]->id, $fuser, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $var); } $level--; } @@ -781,7 +795,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ $lastprojectid=0; $workloadforid=array(); $lineswithoutlevel0=array(); - + // Create a smaller array with sublevels only to be used later. This increase dramatically performances. if ($parent == 0) // Always and only if at first level { @@ -792,18 +806,18 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ } //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0)); - + for ($i = 0 ; $i < $numlines ; $i++) { if ($parent == 0) $level = 0; - + if ($lines[$i]->fk_task_parent == $parent) { // If we want all or we have a role on task, we show it if (empty($mine) || ! empty($tasksrole[$lines[$i]->id])) { //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project); - + // Break on a new project if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid) { @@ -811,14 +825,19 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ $lastprojectid=$lines[$i]->fk_project; $projectstatic->id = $lines[$i]->fk_project; } - + if (empty($workloadforid[$projectstatic->id])) { $projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week $workloadforid[$projectstatic->id]=1; } - - print "\n"; + + print ''."\n"; + + // User + print ''; + print $fuser->getNomUrl(1, 'withproject', 'time'); + print ''; // Ref print ''; @@ -842,7 +861,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ print "\n"; // Project - print ''.$var; + print ''; $projectstatic->id=$lines[$i]->fk_project; $projectstatic->ref=$lines[$i]->projectref; $projectstatic->title=$lines[$i]->projectlabel; @@ -860,7 +879,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ print $thirdpartystatic->getNomUrl(1, 'project'); print ''; } - + // Planned Workload print ''; if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin'); @@ -908,7 +927,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ } //var_dump($projectstatic->weekWorkLoadPerTask); - + // Fields to show current time $tableCell=''; $modeinput='hours'; for ($idw = 0; $idw < 7; $idw++) @@ -919,7 +938,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ $alreadyspent=''; if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin'); $alttitle=$langs->trans("AddHereTimeSpentForDay",$tmparray['day'],$tmparray['mon']); - + $tableCell =''; if ($alreadyspent) { @@ -934,10 +953,11 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ $tableCell.=''; print $tableCell; } - + + // Warning print ''; - if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("YouAreNotContactOfProject")); - else if ($disabledtask) print $form->textwithpicto('',$langs->trans("TaskIsNotAffectedToYou")); + if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject")); + else if ($disabledtask) print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $langs->transnoentitiesnoconv("AssignTaskToUser", '...'))); print ''; print "\n"; @@ -946,7 +966,7 @@ function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$ // Call to show task with a lower level (task under the current task) $inc++; $level++; - if ($lines[$i]->id > 0) + if ($lines[$i]->id > 0) { if ($parent == 0) projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lineswithoutlevel0, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $var); else projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, $lines, $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $var); @@ -1020,7 +1040,7 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= $projectstatic=new Project($db); $thirdpartystatic=new Societe($db); - + $sortfield=''; $sortorder=''; $project_year_filter=0; @@ -1029,7 +1049,7 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= if (strcmp($statut, '') && $statut >= 0) $title=$langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$statut]); $arrayidtypeofcontact=array(); - + print ''; $sql.= " FROM ".MAIN_DB_PREFIX."projet as p"; @@ -1072,11 +1092,11 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= $sql.= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter,1,false)).")"; } } - + // Get id of project we must show tasks $arrayidofprojects=array(); $sql1 = "SELECT p.rowid as projectid"; - $sql1.= $sql; + $sql1.= $sql; $resql = $db->query($sql1); if ($resql) { @@ -1091,7 +1111,7 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= } else dol_print_error($db); if (empty($arrayidofprojects)) $arrayidofprojects[0]=-1; - + // Get list of project with calculation on tasks $sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc, s.nom as socname, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount,"; $sql2.= " p.dateo, p.datee,"; @@ -1122,7 +1142,7 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= print_liste_field_titre($langs->trans("OpportunityAmount"),"","","","",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("OpportunityStatus"),"","","","",'align="right"',$sortfield,$sortorder); } - if (empty($conf->global->PROJECT_HIDE_TASKS)) + if (empty($conf->global->PROJECT_HIDE_TASKS)) { print_liste_field_titre($langs->trans("Tasks"),"","","","",'align="right"',$sortfield,$sortorder); if (! in_array('plannedworkload', $hiddenfields)) print_liste_field_titre($langs->trans("PlannedWorkload"),"","","","",'align="right"',$sortfield,$sortorder); @@ -1130,7 +1150,7 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= } print_liste_field_titre($langs->trans("Status"),"","","","",'align="right"',$sortfield,$sortorder); print "\n"; - + while ($i < $num) { $objp = $db->fetch_object($resql); @@ -1148,8 +1168,8 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= $projectstatic->title = $objp->title; $projectstatic->datee = $db->jdate($objp->datee); $projectstatic->dateo = $db->jdate($objp->dateo); - - + + print ''; print ''; } - if (empty($conf->global->PROJECT_HIDE_TASKS)) + if (empty($conf->global->PROJECT_HIDE_TASKS)) { print ''; - + $plannedworkload=$objp->planned_workload; $total_plannedworkload+=$plannedworkload; if (! in_array('plannedworkload', $hiddenfields)) { print ''; } - if (! in_array('declaredprogress', $hiddenfields)) + if (! in_array('declaredprogress', $hiddenfields)) { $declaredprogressworkload=$objp->declared_progess_workload; $total_declaredprogressworkload+=$declaredprogressworkload; @@ -1194,7 +1214,7 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= print ''; } } - + print ''; print "\n"; @@ -1213,7 +1233,7 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= print ''; print ''; } - if (empty($conf->global->PROJECT_HIDE_TASKS)) + if (empty($conf->global->PROJECT_HIDE_TASKS)) { print ''; if (! in_array('plannedworkload', $hiddenfields)) print ''; @@ -1221,7 +1241,7 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= } print ''; print ''; - + $db->free($resql); } else diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 6993ad496ea..d3250263a6f 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -147,7 +147,9 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu $readok=1; $nbko=0; foreach ($featuresarray as $feature) // first we check nb of test ko { - if (! empty($user->societe_id) && ! empty($conf->global->MAIN_MODULES_FOR_EXTERNAL) && ! in_array($feature,$listofmodules)) // If limits on modules for external users, module must be into list of modules for external users + $featureforlistofmodule=$feature; + if ($featureforlistofmodule == 'produit') $featureforlistofmodule='product'; + if (! empty($user->societe_id) && ! empty($conf->global->MAIN_MODULES_FOR_EXTERNAL) && ! in_array($featureforlistofmodule,$listofmodules)) // If limits on modules for external users, module must be into list of modules for external users { $readok=0; $nbko++; continue; @@ -345,7 +347,7 @@ function restrictedArea($user, $features, $objectid=0, $tableandshare='', $featu * This function is also called by restrictedArea * * @param User $user User to check - * @param array $featuresarray Features/modules to check. Example: ('user','service') + * @param array $featuresarray Features/modules to check. Example: ('user','service','member','project','task',...) * @param int $objectid Object ID if we want to check a particular record (optional) is linked to a owned thirdparty (optional). * @param string $tableandshare 'TableName&SharedElement' with Tablename is table where object is stored. SharedElement is an optional key to define where to check entity for multicompany modume. Param not used if objectid is null (optional). * @param string $feature2 Feature to check, second level of permission (optional). Can be or check with 'level1|level2'. @@ -369,11 +371,14 @@ function checkUserAccessToObject($user, $featuresarray, $objectid=0, $tableandsh // For backward compatibility if ($feature == 'member') $feature='adherent'; + if ($feature == 'project') $feature='projet'; + if ($feature == 'task') $feature='projet_task'; $check = array('adherent','banque','user','usergroup','produit','service','produit|service','categorie'); // Test on entity only (Objects with no link to company) $checksoc = array('societe'); // Test for societe object $checkother = array('contact'); // Test on entity and link to societe. Allowed if link is empty (Ex: contacts...). - $checkproject = array('projet'); // Test for project object + $checkproject = array('projet','project'); // Test for project object + $checktask = array('projet_task'); $nocheck = array('barcode','stock','fournisseur'); // No test $checkdefault = 'all other not already defined'; // Test on entity and link to third party. Not allowed if link is empty (Ex: invoice, orders...). @@ -398,9 +403,9 @@ function checkUserAccessToObject($user, $featuresarray, $objectid=0, $tableandsh else if (in_array($feature,$checksoc)) // We check feature = checksoc { // If external user: Check permission for external users - if ($user->societe_id > 0) + if ($user->socid > 0) { - if ($user->societe_id <> $objectid) return false; + if ($user->socid <> $objectid) return false; } // If internal user: Check permission for internal users that are restricted on their objects else if (! empty($conf->societe->enabled) && ($user->rights->societe->lire && ! $user->rights->societe->client->voir)) @@ -453,7 +458,7 @@ function checkUserAccessToObject($user, $featuresarray, $objectid=0, $tableandsh } else if (in_array($feature,$checkproject)) { - if (! empty($conf->projet->enabled) && ! $user->rights->projet->all->lire) + if (! empty($conf->projet->enabled) && empty($user->rights->projet->all->lire)) { include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; $projectstatic=new Project($db); @@ -469,6 +474,27 @@ function checkUserAccessToObject($user, $featuresarray, $objectid=0, $tableandsh $sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")"; } } + else if (in_array($feature,$checktask)) + { + if (! empty($conf->projet->enabled) && empty($user->rights->projet->all->lire)) + { + $task = new Task($db); + $task->fetch($objectid); + + include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + $projectstatic=new Project($db); + $tmps=$projectstatic->getProjectsAuthorizedForUser($user,0,1,0); + $tmparray=explode(',',$tmps); + if (! in_array($task->fk_project,$tmparray)) return false; + } + else + { + $sql = "SELECT dbt.".$dbt_select; + $sql.= " FROM ".MAIN_DB_PREFIX.$dbtablename." as dbt"; + $sql.= " WHERE dbt.".$dbt_select." = ".$objectid; + $sql.= " AND dbt.entity IN (".getEntity($sharedelement, 1).")"; + } + } else if (! in_array($feature,$nocheck)) // By default we check with link to third party { // If external user: Check permission for external users diff --git a/htdocs/core/lib/security2.lib.php b/htdocs/core/lib/security2.lib.php index 3f41e74b7f6..248c3bde43e 100644 --- a/htdocs/core/lib/security2.lib.php +++ b/htdocs/core/lib/security2.lib.php @@ -144,10 +144,6 @@ function dol_loginfunction($langs,$conf,$mysoc) $dol_url_root = DOL_URL_ROOT; - $php_self = $_SERVER['PHP_SELF']; - $php_self.= $_SERVER["QUERY_STRING"]?'?'.$_SERVER["QUERY_STRING"]:''; - if (! preg_match('/mainmenu=/',$php_self)) $php_self.=(preg_match('/\?/',$php_self)?'&':'?').'mainmenu=home'; - // Title $appli=constant('DOL_APPLICATION_TITLE'); $title=$appli.' '.constant('DOL_VERSION'); @@ -265,15 +261,11 @@ function dol_loginfunction($langs,$conf,$mysoc) $main_home=''; if (! empty($conf->global->MAIN_HOME)) { - $i=0; - while (preg_match('/__\(([a-zA-Z|@]+)\)__/i',$conf->global->MAIN_HOME,$reg) && $i < 100) - { - $tmp=explode('|',$reg[1]); - if (! empty($tmp[1])) $langs->load($tmp[1]); - $conf->global->MAIN_HOME=preg_replace('/__\('.preg_quote($reg[1]).'\)__/i',$langs->trans($tmp[0]),$conf->global->MAIN_HOME); - $i++; - } - $main_home=dol_htmlcleanlastbr($conf->global->MAIN_HOME); + $substitutionarray=getCommonSubstitutionArray($langs); + complete_substitutions_array($substitutionarray, $langs); + $texttoshow = make_substitutions($conf->global->MAIN_HOME, $substitutionarray, $langs); + + $main_home=dol_htmlcleanlastbr($texttoshow); } // Google AD @@ -415,7 +407,7 @@ function encodedecode_dbpassconf($level=0) fflush($fp); fclose($fp); clearstatcache(); - + // It's config file, so we set read permission for creator only. // Should set permission to web user and groups for users used by batch //@chmod($file, octdec('0600')); diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php index 3455979afbe..78de61a729f 100644 --- a/htdocs/core/lib/sendings.lib.php +++ b/htdocs/core/lib/sendings.lib.php @@ -184,7 +184,7 @@ function show_list_sending_receive($origin,$origin_id,$filter='') //if ($conf->livraison_bon->enabled) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.fk_expedition = e.rowid LEFT JOIN ".MAIN_DB_PREFIX."livraisondet as ld ON ld.fk_livraison = l.rowid AND obj.rowid = ld.fk_origin_line"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON obj.fk_product = p.rowid"; //TODO Add link to expeditiondet_batch - $sql.= " WHERE e.entity IN (".getEntity('expedition', 1).")"; + $sql.= " WHERE e.entity IN (".getEntity('expedition').")"; $sql.= " AND obj.fk_".$origin." = ".$origin_id; $sql.= " AND obj.rowid = ed.fk_origin_line"; $sql.= " AND ed.fk_expedition = e.rowid"; diff --git a/htdocs/core/lib/treeview.lib.php b/htdocs/core/lib/treeview.lib.php index db0fcd07fae..944520d04d5 100644 --- a/htdocs/core/lib/treeview.lib.php +++ b/htdocs/core/lib/treeview.lib.php @@ -110,15 +110,15 @@ function tree_showpad(&$fulltree,$key,$silent=0) * @param int $rang Level of element * @param string $iddivjstree Id to use for parent ul element * @param int $donoresetalreadyloaded Do not reset global array $donoresetalreadyloaded used to avoid to go down on an aleady processed record - * @param int $showfk Show fk links to parent into label + * @param int $showfk 1=show fk_links to parent into label (used by menu editor only) * @return void */ function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetalreadyloaded=0, $showfk=0) { global $tree_recur_alreadyadded; - + if ($rang == 0 && empty($donoresetalreadyloaded)) $tree_recur_alreadyadded=array(); - + if ($rang == 0) { // Test also done with jstree and dynatree (not able to have inside label) @@ -138,8 +138,8 @@ function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetal print '
      '; } - - if ($rang > 50) + + if ($rang > 50) { return; // Protect against infinite loop. Max 50 depth } @@ -154,19 +154,31 @@ function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetal if ($tab[$x]['fk_menu'] != -1 && $tab[$x]['fk_menu'] == $pere['rowid']) { //print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."
      \n"; - if (empty($ulprinted) && ! empty($pere['rowid'])) - { + if (empty($ulprinted) && ! empty($pere['rowid'])) + { if (! empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) { dol_syslog('Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.', LOG_WARNING); continue; } - + print ''; $ulprinted++; } print "\n".'
    • '; - print $tab[$x]['entry']; - if ($showfk) print '  (fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')'; + if ($showfk) + { + print '
    '; print $projectstatic->getNomUrl(1); @@ -1174,17 +1194,17 @@ function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks= if ($code) print $langs->trans("OppStatus".$code); print ''.$objp->nb.''.($plannedworkload?convertSecondToTime($plannedworkload):'').''.$projectstatic->getLibStatut(3).'
    '.price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency).''.$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1).''.$total_task.''.($total_plannedworkload?convertSecondToTime($total_plannedworkload):'').'
    '; + print '   '; + print $tab[$x]['title']; + print '  (fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')'; + print ''; + print $tab[$x]['buttons']; + print '
    '; + } + else + { + print $tab[$x]['entry']; + } //print ' -> A '.$tab[$x]['rowid'].' mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].'
    '."\n"; $tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1); // And now we search all its sons of lower level @@ -176,7 +188,7 @@ function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetal elseif (! empty($tab[$x]['rowid']) && $tab[$x]['fk_menu'] == -1 && $tab[$x]['fk_mainmenu'] == $pere['mainmenu'] && $tab[$x]['fk_leftmenu'] == $pere['leftmenu']) { //print 'rang='.$rang.'-x='.$x." rowid=".$tab[$x]['rowid']." tab[x]['fk_leftmenu'] = ".$tab[$x]['fk_leftmenu']." leftmenu pere = ".$pere['leftmenu']."
    \n"; - if (empty($ulprinted) && ! empty($pere['rowid'])) + if (empty($ulprinted) && ! empty($pere['rowid'])) { if (! empty($tree_recur_alreadyadded[$tab[$x]['rowid']])) { @@ -184,12 +196,25 @@ function tree_recur($tab, $pere, $rang, $iddivjstree='iddivjstree', $donoresetal //print 'Error, record with id '.$tab[$x]['rowid'].' seems to be a child of record with id '.$pere['rowid'].' but it was already output. Complete field "leftmenu" and "mainmenu" on ALL records to avoid ambiguity.'; continue; } - + print ''; $ulprinted++; } print "\n".'
  • '; - print $tab[$x]['entry']; - if ($showfk) print '  (fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')'; + if ($showfk) + { + print '
    '; + print '   '; + print $tab[$x]['title']; + print ''; + print '  (fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].')'; + print ''; + print $tab[$x]['buttons']; + print '
    '; + } + else + { + print $tab[$x]['entry']; + } //print ' -> B '.$tab[$x]['rowid'].' mainmenu='.$tab[$x]['mainmenu'].' leftmenu='.$tab[$x]['leftmenu'].' fk_mainmenu='.$tab[$x]['fk_mainmenu'].' fk_leftmenu='.$tab[$x]['fk_leftmenu'].'
    '."\n"; $tree_recur_alreadyadded[$tab[$x]['rowid']]=($rang + 1); // And now we search all its sons of lower level diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php index 1c919237f44..f39e6ecd628 100644 --- a/htdocs/core/lib/usergroups.lib.php +++ b/htdocs/core/lib/usergroups.lib.php @@ -1,6 +1,6 @@ - * Copyright (C) 2010-2012 Regis Houssin + * Copyright (C) 2010-2017 Regis Houssin * Copyright (C) 2015 Alexandre Spangaro * * This program is free software; you can redistribute it and/or modify @@ -76,7 +76,7 @@ function user_prepare_head($object) { if (empty($conf->global->AGENDA_EXT_NB)) $conf->global->AGENDA_EXT_NB=5; $MAXAGENDA=$conf->global->AGENDA_EXT_NB; - + $i=1; $nbagenda = 0; while ($i <= $MAXAGENDA) @@ -87,10 +87,10 @@ function user_prepare_head($object) $offsettz='AGENDA_EXT_OFFSETTZ_'.$object->id.'_'.$key; $color='AGENDA_EXT_COLOR_'.$object->id.'_'.$key; $i++; - + if (! empty($object->conf->$name)) $nbagenda++; } - + $head[$h][0] = DOL_URL_ROOT.'/user/agenda_extsites.php?id='.$object->id; $head[$h][1] = $langs->trans("ExtSites").($nbagenda ? ' '.$nbagenda.'' : ''); $head[$h][2] = 'extsites'; @@ -238,8 +238,6 @@ function group_prepare_head($object) return $head; } - - /** * Prepare array with list of tabs * @@ -283,32 +281,6 @@ function user_admin_prepare_head() return $head; } - - -/** - * Prepare array with list of tabs - * - * @param Object $object Object related to tabs - * @param array $aEntities Entities array - * @return array Array of tabs - */ -function entity_prepare_head($object, $aEntities) -{ - global $mc; - - $head = array(); - - foreach($aEntities as $entity) - { - $mc->getInfo($entity); - $head[$entity][0] = $_SERVER['PHP_SELF'].'?id='.$object->id.'&entity='.$entity; - $head[$entity][1] = $mc->label; - $head[$entity][2] = $entity; - } - - return $head; -} - /** * Show list of themes. Show all thumbs of themes * @@ -485,7 +457,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis")); print ''; } - + // Background color THEME_ELDY_BACKBODY if ($foruserprofile) { @@ -508,7 +480,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) else print ''; } if ($edit) print '
    ('.$langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis").')'; - print '';*/ + print '';*/ } else { @@ -530,7 +502,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis")); print ''; } - + // TopMenuBackgroundColor if ($foruserprofile) { @@ -553,13 +525,13 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) else print ''; } if ($edit) print '
    ('.$langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis").')'; - print '';*/ + print '';*/ } else { $default='5a6482'; if ($conf->theme == 'md') $default='5a3278'; - + print ''; print ''.$langs->trans("TopMenuBackgroundColor").''; print ''; @@ -577,15 +549,15 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis")); print ''; } - + // BackgroundTableTitleColor if ($foruserprofile) { - - + + } else - { + { print ''; print ''.$langs->trans("BackgroundTableTitleColor").''; print ''; @@ -613,7 +585,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) { $default='ffffff'; if ($conf->theme == 'md') $default='ffffff'; - + print ''; print ''.$langs->trans("BackgroundTableLineOddColor").''; print ''; @@ -631,17 +603,17 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis")); print ''; } - + // BackgroundTableLineEvenColor if ($foruserprofile) { - + } else { $default='f8f8f8'; if ($conf->theme == 'md') $default='f8f8f8'; - + print ''; print ''.$langs->trans("BackgroundTableLineEvenColor").''; print ''; @@ -659,12 +631,12 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis")); print ''; } - + // TextTitleColor if ($foruserprofile) { - - + + } else { @@ -681,12 +653,12 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) } print '   ('.$langs->trans("Default").': 3c3c14) '; print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis")); - + print ''; - + print ''; } - + // Text LinkColor if ($foruserprofile) { @@ -724,7 +696,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) { $color = colorArrayToHex(colorStringToArray($conf->global->THEME_ELDY_TEXTLINK,array()),''); if ($color) print ''; - else + else { //print ''; //print ''.$langs->trans("Default").''; @@ -735,7 +707,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) print $form->textwithpicto('', $langs->trans("NotSupportedByAllThemes").', '.$langs->trans("PressF5AfterChangingThis")); print ''; } - + // Use Hover if ($foruserprofile) { @@ -767,7 +739,7 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) { if ($conf->global->THEME_ELDY_USE_HOVER == '1') $color='edf4fb'; else $color = colorArrayToHex(colorStringToArray($conf->global->THEME_ELDY_USE_HOVER,array()),''); - if ($color) + if ($color) { if ($color != 'edf4fb') print ''; else print $langs->trans("Default"); @@ -779,7 +751,6 @@ function show_theme($fuser,$edit=0,$foruserprofile=false) print ''; print ''; } - + print ''; } - diff --git a/htdocs/core/lib/website.lib.php b/htdocs/core/lib/website.lib.php index ebbd261984e..37f01a0ffe3 100644 --- a/htdocs/core/lib/website.lib.php +++ b/htdocs/core/lib/website.lib.php @@ -31,21 +31,36 @@ function dolWebsiteOutput($content) { global $db, $langs, $conf, $user; + global $dolibarr_main_url_root; dol_syslog("dolWebsiteOutput start"); - + if (! defined('USEDOLIBARRSERVER')) { - // Replace link of Dolibarr medias with direct link for virtual server - - - - - + // Define $urlwithroot + $urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); + $urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file + //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + + $symlinktomediaexists=1; + + // Make a change into HTML code to allow to include images from medias directory correct with direct link for virtual server + // + // become + // + $nbrep=0; + if (! $symlinktomediaexists) + { + $content=preg_replace('/()/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $content, -1, $nbrep); + } + else + { + $content=preg_replace('/()/', '\1medias/\4\5', $content, -1, $nbrep); + } } - + dol_syslog("dolWebsiteOutput end"); - + print $content; } diff --git a/htdocs/core/login/functions_dolibarr.php b/htdocs/core/login/functions_dolibarr.php index daf82b2f995..d8cf78747b8 100644 --- a/htdocs/core/login/functions_dolibarr.php +++ b/htdocs/core/login/functions_dolibarr.php @@ -39,7 +39,7 @@ function check_user_password_dolibarr($usertotest,$passwordtotest,$entitytotest= // Force master entity in transversal mode $entity=$entitytotest; - if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $entity=1; + if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; $login=''; @@ -60,7 +60,7 @@ function check_user_password_dolibarr($usertotest,$passwordtotest,$entitytotest= $sql.=') AND '.$entitycol." IN (0," . ($entity ? $entity : 1) . ")"; $sql.=' AND statut = 1'; // Required to first found the user into entity, then the superadmin. - // For the case (TODO and that we must avoid) a user has renamed its login with same value than a user in entity 0. + // For the case (TODO and that we must avoid) a user has renamed its login with same value than a user in entity 0. $sql.=' ORDER BY entity DESC'; $resql=$db->query($sql); @@ -78,6 +78,7 @@ function check_user_password_dolibarr($usertotest,$passwordtotest,$entitytotest= // Check crypted password $cryptType=''; if (! empty($conf->global->DATABASE_PWD_ENCRYPTED)) $cryptType=$conf->global->DATABASE_PWD_ENCRYPTED; + // By default, we used MD5 if (! in_array($cryptType,array('md5'))) $cryptType='md5'; // Check crypted password according to crypt algorithm diff --git a/htdocs/core/login/functions_ldap.php b/htdocs/core/login/functions_ldap.php index c94312c8aa2..129bbcedf38 100644 --- a/htdocs/core/login/functions_ldap.php +++ b/htdocs/core/login/functions_ldap.php @@ -45,7 +45,7 @@ function check_user_password_ldap($usertotest,$passwordtotest,$entitytotest) // Force master entity in transversal mode $entity=$entitytotest; - if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $entity=1; + if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) $entity=1; $login=''; $resultFetchUser=''; diff --git a/htdocs/core/menus/init_menu_auguria.sql b/htdocs/core/menus/init_menu_auguria.sql index 9106c345fda..193c74d3ee3 100644 --- a/htdocs/core/menus/init_menu_auguria.sql +++ b/htdocs/core/menus/init_menu_auguria.sql @@ -63,9 +63,9 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left -- Home - Menu users and groups insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '1', __HANDLER__, 'left', 400__+MAX_llx_menu__, 'home', 'users', 1__+MAX_llx_menu__, '/user/home.php?leftmenu=users', 'MenuUsersAndGroups', 0, 'users', '', '', 2, 4, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="users"', __HANDLER__, 'left', 401__+MAX_llx_menu__, 'home', '', 400__+MAX_llx_menu__, '/user/index.php?leftmenu=users', 'Users', 1, 'users', '$user->rights->user->user->lire || $user->admin', '', 2, 0, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="users"', __HANDLER__, 'left', 402__+MAX_llx_menu__, 'home', '', 401__+MAX_llx_menu__, '/user/card.php?leftmenu=users&action=create', 'NewUser', 2, 'users', '$user->rights->user->user->creer || $user->admin', '', 2, 0, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="users"', __HANDLER__, 'left', 403__+MAX_llx_menu__, 'home', '', 400__+MAX_llx_menu__, '/user/group/index.php?leftmenu=users', 'Groups', 1, 'users', '($conf->global->MAIN_USE_ADVANCED_PERMS?$user->rights->user->group_advance->read:$user->rights->user->user->lire) || $user->admin', '', 2, 1, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="users"', __HANDLER__, 'left', 404__+MAX_llx_menu__, 'home', '', 403__+MAX_llx_menu__, '/user/group/card.php?leftmenu=users&action=create', 'NewGroup', 2, 'users', '($conf->global->MAIN_USE_ADVANCED_PERMS?$user->rights->user->group_advance->write:$user->rights->user->user->creer) || $user->admin', '', 2, 0, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="users"', __HANDLER__, 'left', 402__+MAX_llx_menu__, 'home', '', 401__+MAX_llx_menu__, '/user/card.php?leftmenu=users&action=create', 'NewUser', 2, 'users', '($user->rights->user->user->creer || $user->admin) && !(! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)', '', 2, 0, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="users"', __HANDLER__, 'left', 403__+MAX_llx_menu__, 'home', '', 400__+MAX_llx_menu__, '/user/group/index.php?leftmenu=users', 'Groups', 1, 'users', '(($conf->global->MAIN_USE_ADVANCED_PERMS?$user->rights->user->group_advance->read:$user->rights->user->user->lire) || $user->admin) && !(! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)', '', 2, 1, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$leftmenu=="users"', __HANDLER__, 'left', 404__+MAX_llx_menu__, 'home', '', 403__+MAX_llx_menu__, '/user/group/card.php?leftmenu=users&action=create', 'NewGroup', 2, 'users', '(($conf->global->MAIN_USE_ADVANCED_PERMS?$user->rights->user->group_advance->write:$user->rights->user->user->creer) || $user->admin) && !(! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)', '', 2, 0, __ENTITY__); -- Third parties insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 500__+MAX_llx_menu__, 'companies', 'thirdparties', 2__+MAX_llx_menu__, '/societe/index.php?leftmenu=thirdparties', 'ThirdParty', 0, 'companies', '$user->rights->societe->lire', '', 2, 0, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->societe->enabled', __HANDLER__, 'left', 501__+MAX_llx_menu__, 'companies', '', 500__+MAX_llx_menu__, '/societe/card.php?action=create', 'MenuNewThirdParty', 1, 'companies', '$user->rights->societe->lire', '', 2, 0, __ENTITY__); @@ -166,8 +166,9 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left -- Accountancy - Supplier invoice insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->supplier_invoice->enabled', __HANDLER__, 'left', 1600__+MAX_llx_menu__, 'accountancy', 'supplier_bills', 6__+MAX_llx_menu__, '/fourn/facture/list.php?leftmenu=suppliers_bills', 'BillsSuppliers', 0, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 3, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->supplier_invoice->enabled', __HANDLER__, 'left', 1601__+MAX_llx_menu__, 'accountancy', '', 1600__+MAX_llx_menu__, '/fourn/facture/card.php?action=create&leftmenu=suppliers_bills', 'NewBill', 1, 'bills', '$user->rights->fournisseur->facture->creer', '', 2, 0, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->supplier_invoice->enabled', __HANDLER__, 'left', 1602__+MAX_llx_menu__, 'accountancy', '', 1600__+MAX_llx_menu__, '/fourn/facture/impayees.php?leftmenu=suppliers_bills', 'Unpaid', 1, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 1, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->supplier_invoice->enabled', __HANDLER__, 'left', 1602__+MAX_llx_menu__, 'accountancy', '', 1600__+MAX_llx_menu__, '/fourn/facture/list.php?leftmenu=suppliers_bills', 'List', 1, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->supplier_invoice->enabled', __HANDLER__, 'left', 1603__+MAX_llx_menu__, 'accountancy', '', 1600__+MAX_llx_menu__, '/fourn/facture/paiement.php?leftmenu=suppliers_bills', 'Payments', 1, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 2, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->supplier_invoice->enabled', __HANDLER__, 'left', 1605__+MAX_llx_menu__, 'accountancy', '', 1603__+MAX_llx_menu__, '/fourn/facture/rapport.php?leftmenu=suppliers_bills', 'Reporting', 2, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->supplier_invoice->enabled', __HANDLER__, 'left', 1604__+MAX_llx_menu__, 'accountancy', '', 1600__+MAX_llx_menu__, '/compta/facture/stats/index.php?leftmenu=customers_bills&mode=supplier', 'Statistics', 1, 'bills', '$user->rights->fournisseur->facture->lire', '', 2, 8, __ENTITY__); -- Accountancy - Customer invoice insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->facture->enabled', __HANDLER__, 'left', 1700__+MAX_llx_menu__, 'accountancy', 'customer_bills', 6__+MAX_llx_menu__, '/compta/facture/list.php?leftmenu=customers_bills', 'BillsCustomers', 0, 'bills', '$user->rights->facture->lire', '', 2, 3, __ENTITY__); @@ -211,15 +212,18 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2400__+MAX_llx_menu__, 'accountancy', 'accounting', 6__+MAX_llx_menu__, '/accountancy/index.php?leftmenu=accountancy', 'MenuAccountancy', 0, 'accountancy', '! empty($conf->accounting->enabled) || $user->rights->accounting->bind->write || $user->rights->accounting->bind->write || $user->rights->compta->resultat->lire', '', 0, 7, __ENTITY__); -- Setup insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2451__+MAX_llx_menu__, 'accountancy', 'accountancy_admin', 2400__+MAX_llx_menu__, '/accountancy/index.php?mainmenu=accountancy&leftmenu=accountancy_admin', 'Setup', 1, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 1, __ENTITY__); - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2457__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_journal', 2451__+MAX_llx_menu__, '/accountancy/admin/journals_list.php?id=35&mainmenu=accountancy&leftmenu=accountancy_admin', 'AccountingJournals', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 10, __ENTITY__); + + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2454__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_journal', 2451__+MAX_llx_menu__, '/accountancy/admin/journals_list.php?id=35&mainmenu=accountancy&leftmenu=accountancy_admin', 'AccountingJournals', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 10, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2455__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_chartmodel', 2451__+MAX_llx_menu__, '/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', 'Pcg_version', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 20, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2456__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_chart', 2451__+MAX_llx_menu__, '/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', 'Chartofaccounts', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 30, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2457__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_chart_group', 2451__+MAX_llx_menu__, '/accountancy/admin/categories_list.php?id=32&mainmenu=accountancy&leftmenu=accountancy_admin', 'AccountingCategory', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 40, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2458__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_default', 2451__+MAX_llx_menu__, '/accountancy/admin/defaultaccounts.php?mainmenu=accountancy&leftmenu=accountancy_admin', 'MenuDefaultAccounts', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 50, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2459__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_vat', 2451__+MAX_llx_menu__, '/admin/dict.php?id=10&from=accountancy&search_country_id=__MYCOUNTRYID__&mainmenu=accountancy&leftmenu=accountancy_admin', 'MenuVatAccounts', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 60, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2460__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_tax', 2451__+MAX_llx_menu__, '/admin/dict.php?id=7&from=accountancy&search_country_id=__MYCOUNTRYID__&mainmenu=accountancy&leftmenu=accountancy_admin', 'MenuTaxAccounts', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 70, __ENTITY__); - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2461__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_expensereport', 2451__+MAX_llx_menu__, '/admin/dict.php?id=17&from=accountancy&mainmenu=accountancy&leftmenu=accountancy_admin', 'MenuExpenseReportAccounts', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 80, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $conf->expensereport->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2461__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_expensereport', 2451__+MAX_llx_menu__, '/admin/dict.php?id=17&from=accountancy&mainmenu=accountancy&leftmenu=accountancy_admin', 'MenuExpenseReportAccounts', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 80, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin"', __HANDLER__, 'left', 2462__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_product', 2451__+MAX_llx_menu__, '/accountancy/admin/productaccount.php?mainmenu=accountancy&leftmenu=accountancy_admin', 'MenuProductsAccounts', 2, 'accountancy', '$user->rights->accounting->chartofaccount', '', 0, 90, __ENTITY__); + -- Accounting period + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy_admin" && $conf->global->MAIN_FEATURES_LEVEL > 0', __HANDLER__, 'left', 2450__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_period', 2451__+MAX_llx_menu__, '/accountancy/admin/fiscalyear.php?mainmenu=accountancy&leftmenu=accountancy_admin', 'FiscalPeriod', 1, 'admin', '', '', 2, 80, __ENTITY__); -- Binding insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2401__+MAX_llx_menu__, 'accountancy', 'dispatch_customer', 2400__+MAX_llx_menu__, '/accountancy/customer/index.php?leftmenu=dispatch_customer', 'CustomersVentilation', 1, 'accountancy', '$user->rights->accounting->bind->write', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="dispatch_customer"', __HANDLER__, 'left', 2402__+MAX_llx_menu__, 'accountancy', '', 2401__+MAX_llx_menu__, '/accountancy/customer/list.php', 'ToDispatch', 2, 'accountancy', '$user->rights->accounting->bind->write', '', 0, 3, __ENTITY__); @@ -231,32 +235,32 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $conf->expensereport->enabled && $leftmenu=="dispatch_expensereport"', __HANDLER__, 'left', 2421__+MAX_llx_menu__, 'accountancy', '', 2420__+MAX_llx_menu__, '/accountancy/expensereport/list.php', 'ToDispatch', 2, 'accountancy', '$user->rights->accounting->bind->write', '', 0, 6, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $conf->expensereport->enabled && $leftmenu=="dispatch_expensereport"', __HANDLER__, 'left', 2422__+MAX_llx_menu__, 'accountancy', '', 2420__+MAX_llx_menu__, '/accountancy/expensereport/lines.php', 'Dispatched', 2, 'accountancy', '$user->rights->accounting->bind->write', '', 0, 7, __ENTITY__); -- Journals - -- insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2420__+MAX_llx_menu__, 'accountancy', 'journal', 2400__+MAX_llx_menu__, '/accountancy/journal/index.php?leftmenu=journal', 'Journaux', 1, 'accountancy', '$user->rights->accounting->comptarapport->lire', '', 0, 7, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2705__+MAX_llx_menu__, 'accountancy', '', 2400__+MAX_llx_menu__, '', 'Journalization', 1, 'main', '$user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2707__+MAX_llx_menu__, 'accountancy', '', 2705__+MAX_llx_menu__, '/accountancy/journal/bankjournal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal=3', 'BankJournal', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2708__+MAX_llx_menu__, 'accountancy', '', 2705__+MAX_llx_menu__, '/accountancy/journal/expensereportsjournal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal=6', 'ExpenseReportJournal', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 2, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2709__+MAX_llx_menu__, 'accountancy', '', 2705__+MAX_llx_menu__, '/accountancy/journal/purchasesjournal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal=2', 'PurchasesJournal', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 3, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2706__+MAX_llx_menu__, 'accountancy', '', 2705__+MAX_llx_menu__, '/accountancy/journal/sellsjournal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal=1', 'SellsJournal', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 4, __ENTITY__); -- General Ledger insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2430__+MAX_llx_menu__, 'accountancy', 'bookkeeping', 2400__+MAX_llx_menu__, '/accountancy/bookkeeping/list.php', 'Bookkeeping', 1, 'accountancy', '$user->rights->accounting->mouvements->lire', '', 0, 15, __ENTITY__); -- Balance insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2435__+MAX_llx_menu__, 'accountancy', 'balance', 2400__+MAX_llx_menu__, '/accountancy/bookkeeping/balance.php', 'AccountBalance', 1, 'accountancy', '$user->rights->accounting->mouvements->lire', '', 0, 16, __ENTITY__); -- Reports - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2440__+MAX_llx_menu__, 'accountancy', 'report', 2400__+MAX_llx_menu__, '/accountancy/report/result.php?leftmenu=ca&mainmenu=accountancy', 'Reportings', 1, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 17, __ENTITY__); - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2441__+MAX_llx_menu__, 'accountancy', '', 2440__+MAX_llx_menu__, '/accountancy/report/result.php?leftmenu=ca', 'ReportInOut', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 18, __ENTITY__); - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2442__+MAX_llx_menu__, 'accountancy', '', 2440__+MAX_llx_menu__, '/compta/resultat/index.php?leftmenu=ca', 'ByExpenseIncome', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 19, __ENTITY__); - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2443__+MAX_llx_menu__, 'accountancy', '', 2440__+MAX_llx_menu__, '/compta/resultat/clientfourn.php?leftmenu=ca', 'ByCompanies', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 20, __ENTITY__); - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2444__+MAX_llx_menu__, 'accountancy', '', 2440__+MAX_llx_menu__, '/compta/stats/index.php?leftmenu=ca', 'ReportTurnover', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 21, __ENTITY__); - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2445__+MAX_llx_menu__, 'accountancy', '', 2440__+MAX_llx_menu__, '/compta/stats/casoc.php?leftmenu=ca', 'ByCompanies', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 22, __ENTITY__); - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2446__+MAX_llx_menu__, 'accountancy', '', 2440__+MAX_llx_menu__, '/compta/stats/cabyuser.php?leftmenu=ca', 'ByUsers', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 23, __ENTITY__); - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2447__+MAX_llx_menu__, 'accountancy', '', 2440__+MAX_llx_menu__, '/compta/stats/cabyprodserv.php?leftmenu=ca', 'ByProductsAndServices', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 24, __ENTITY__); - -- Accounting period - insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2450__+MAX_llx_menu__, 'accountancy', 'accountancy_admin_period', 2400__+MAX_llx_menu__, '/accountancy/admin/fiscalyear.php?mainmenu=setup', 'FiscalPeriod', 1, 'admin', '', '', 2, 4, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled', __HANDLER__, 'left', 2440__+MAX_llx_menu__, 'accountancy', 'report', 2400__+MAX_llx_menu__, '/accountancy/report/result.php?mainmenu=accountancy&leftmenu=accountancy', 'Reportings', 1, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 17, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy"', __HANDLER__, 'left', 2441__+MAX_llx_menu__, 'accountancy', '', 2440__+MAX_llx_menu__, '/compta/resultat/index.php?mainmenu=accountancy&leftmenu=accountancy', 'ReportInOut', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 19, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy"', __HANDLER__, 'left', 2442__+MAX_llx_menu__, 'accountancy', '', 2441__+MAX_llx_menu__, '/accountancy/report/result.php?mainmenu=accountancy&leftmenu=accountancy', 'ByAccounts', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 18, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy"', __HANDLER__, 'left', 2443__+MAX_llx_menu__, 'accountancy', '', 2441__+MAX_llx_menu__, '/compta/resultat/clientfourn.php?mainmenu=accountancy&leftmenu=accountancy', 'ByCompanies', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 20, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy"', __HANDLER__, 'left', 2444__+MAX_llx_menu__, 'accountancy', '', 2440__+MAX_llx_menu__, '/compta/stats/index.php?mainmenu=accountancy&leftmenu=accountancy', 'ReportTurnover', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 21, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy"', __HANDLER__, 'left', 2445__+MAX_llx_menu__, 'accountancy', '', 2444__+MAX_llx_menu__, '/compta/stats/casoc.php?mainmenu=accountancy&leftmenu=accountancy', 'ByCompanies', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 22, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy"', __HANDLER__, 'left', 2446__+MAX_llx_menu__, 'accountancy', '', 2444__+MAX_llx_menu__, '/compta/stats/cabyuser.php?mainmenu=accountancy&leftmenu=accountancy', 'ByUsers', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 23, __ENTITY__); + insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->accounting->enabled && $leftmenu=="accountancy"', __HANDLER__, 'left', 2447__+MAX_llx_menu__, 'accountancy', '', 2444__+MAX_llx_menu__, '/compta/stats/cabyprodserv.php?mainmenu=accountancy&leftmenu=accountancy', 'ByProductsAndServices', 3, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 24, __ENTITY__); -- Rapports compta simple insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled', __HANDLER__, 'left', 2700__+MAX_llx_menu__, 'accountancy', 'ca', 6__+MAX_llx_menu__, '/compta/resultat/index.php?leftmenu=ca&mainmenu=accountancy', 'Reportings', 0, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 11, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2701__+MAX_llx_menu__, 'accountancy', '', 2700__+MAX_llx_menu__, '/compta/resultat/index.php?leftmenu=ca', 'ReportInOut', 1, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 0, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2702__+MAX_llx_menu__, 'accountancy', '', 2701__+MAX_llx_menu__, '/compta/resultat/clientfourn.php?leftmenu=ca', 'ByCompanies', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 0, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2703__+MAX_llx_menu__, 'accountancy', '', 2700__+MAX_llx_menu__, '/compta/stats/index.php?leftmenu=ca', 'ReportTurnover', 1, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2704__+MAX_llx_menu__, 'accountancy', '', 2703__+MAX_llx_menu__, '/compta/stats/casoc.php?leftmenu=ca', 'ByCompanies', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 0, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2705__+MAX_llx_menu__, 'accountancy', '', 2703__+MAX_llx_menu__, '/compta/stats/cabyuser.php?leftmenu=ca', 'ByUsers', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2708__+MAX_llx_menu__, 'accountancy', '', 2703__+MAX_llx_menu__, '/compta/stats/cabyprodserv.php?leftmenu=ca', 'ByProductsAndServices', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2706__+MAX_llx_menu__, 'accountancy', '', 2700__+MAX_llx_menu__, '/compta/journal/sellsjournal.php?leftmenu=ca', 'SellsJournal', 1, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2707__+MAX_llx_menu__, 'accountancy', '', 2700__+MAX_llx_menu__, '/compta/journal/purchasesjournal.php?leftmenu=ca', 'PurchasesJournal', 1, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2711__+MAX_llx_menu__, 'accountancy', '', 2700__+MAX_llx_menu__, '/compta/resultat/index.php?leftmenu=ca', 'ReportInOut', 1, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 0, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2712__+MAX_llx_menu__, 'accountancy', '', 2701__+MAX_llx_menu__, '/compta/resultat/clientfourn.php?leftmenu=ca', 'ByCompanies', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 0, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2713__+MAX_llx_menu__, 'accountancy', '', 2700__+MAX_llx_menu__, '/compta/stats/index.php?leftmenu=ca', 'ReportTurnover', 1, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2714__+MAX_llx_menu__, 'accountancy', '', 2703__+MAX_llx_menu__, '/compta/stats/casoc.php?leftmenu=ca', 'ByCompanies', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 0, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2715__+MAX_llx_menu__, 'accountancy', '', 2703__+MAX_llx_menu__, '/compta/stats/cabyuser.php?leftmenu=ca', 'ByUsers', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->comptabilite->enabled && $leftmenu=="ca"', __HANDLER__, 'left', 2716__+MAX_llx_menu__, 'accountancy', '', 2703__+MAX_llx_menu__, '/compta/stats/cabyprodserv.php?leftmenu=ca', 'ByProductsAndServices', 2, 'main', '$user->rights->compta->resultat->lire || $user->rights->accounting->comptarapport->lire', '', 0, 1, __ENTITY__); -- Check deposit insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'empty($conf->global->BANK_DISABLE_CHECK_DEPOSIT) && ! empty($conf->banque->enabled) && (! empty($conf->facture->enabled) || ! empty($conf->global->MAIN_MENU_CHEQUE_DEPOSIT_ON))', __HANDLER__, 'left', 1711__+MAX_llx_menu__, 'accountancy', 'checks', 14__+MAX_llx_menu__, '/compta/paiement/cheque/index.php?leftmenu=checks&mainmenu=bank', 'MenuChequeDeposits', 0, 'bills', '$user->rights->banque->lire', '', 2, 9, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', 'empty($conf->global->BANK_DISABLE_CHECK_DEPOSIT) && ! empty($conf->banque->enabled) && (! empty($conf->facture->enabled) || ! empty($conf->global->MAIN_MENU_CHEQUE_DEPOSIT_ON))', __HANDLER__, 'left', 1712__+MAX_llx_menu__, 'accountancy', '', 1711__+MAX_llx_menu__, '/compta/paiement/cheque/card.php?leftmenu=checks&action=new', 'NewCheckDeposit', 1, 'compta', '$user->rights->banque->lire', '', 2, 0, __ENTITY__); @@ -275,9 +279,9 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->banque->enabled && ($leftmenu=="bank" || $leftmenu=="checks" || $leftmenu=="withdraw")', __HANDLER__, 'left', 2603__+MAX_llx_menu__, 'accountancy', '', 2600__+MAX_llx_menu__, '/compta/bank/bankentries.php?leftmenu=bank', 'ListTransactions', 1, 'banks', '$user->rights->banque->lire', '', 0, 2, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->banque->enabled && ($leftmenu=="bank" || $leftmenu=="checks" || $leftmenu=="withdraw")', __HANDLER__, 'left', 2604__+MAX_llx_menu__, 'accountancy', '', 2600__+MAX_llx_menu__, '/compta/bank/budget.php?leftmenu=bank', 'ListTransactionsByCategory', 1, 'banks', '$user->rights->banque->lire', '', 0, 3, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->banque->enabled && ($leftmenu=="bank" || $leftmenu=="checks" || $leftmenu=="withdraw")', __HANDLER__, 'left', 2606__+MAX_llx_menu__, 'accountancy', '', 2600__+MAX_llx_menu__, '/compta/bank/transfer.php?leftmenu=bank', 'BankTransfers', 1, 'banks', '$user->rights->banque->transfer', '', 0, 5, __ENTITY__); --- Account - Categories -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 2650__+MAX_llx_menu__, 'accountancy', 'cat', 14__+MAX_llx_menu__, '/categories/index.php?leftmenu=cat&type=5', 'Categories', 0, 'categories', '$user->rights->categorie->lire', '', 2, 4, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 2651__+MAX_llx_menu__, 'accountancy', '', 2650__+MAX_llx_menu__, '/categories/card.php?action=create&type=5', 'NewCategory', 1, 'categories', '$user->rights->categorie->creer', '', 2, 0, __ENTITY__); +-- Bank - Categories +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 2650__+MAX_llx_menu__, 'accountancy', 'cat', 14__+MAX_llx_menu__, '/categories/index.php?leftmenu=bank&type=5', 'Categories', 0, 'categories', '$user->rights->categorie->lire', '', 2, 4, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 2651__+MAX_llx_menu__, 'accountancy', '', 2650__+MAX_llx_menu__, '/categories/card.php?leftmenu=bank&action=create&type=5', 'NewCategory', 1, 'categories', '$user->rights->categorie->creer', '', 2, 0, __ENTITY__); -- Project insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3600__+MAX_llx_menu__, 'project', 'projects', 7__+MAX_llx_menu__, '/projet/index.php?leftmenu=projects', 'Projects', 0, 'projects', '$user->rights->projet->lire', '', 2, 0, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3601__+MAX_llx_menu__, 'project', '', 3600__+MAX_llx_menu__, '/projet/card.php?leftmenu=projects&action=create', 'NewProject', 1, 'projects', '$user->rights->projet->creer', '', 2, 1, __ENTITY__); @@ -287,7 +291,9 @@ insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, left insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3700__+MAX_llx_menu__, 'project', '', 7__+MAX_llx_menu__, '/projet/activity/index.php?leftmenu=projects', 'Activities', 0, 'projects', '$user->rights->projet->lire', '', 2, 0, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3701__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/tasks.php?leftmenu=projects&action=create', 'NewTask', 1, 'projects', '$user->rights->projet->creer', '', 2, 1, __ENTITY__); insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3702__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/tasks/list.php?leftmenu=projects', 'List', 1, 'projects', '$user->rights->projet->lire', '', 2, 2, __ENTITY__); -insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3703__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/activity/perweek.php?leftmenu=projects', 'NewTimeSpent', 1, 'projects', '$user->rights->projet->lire', '', 2, 3, __ENTITY__); +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3704__+MAX_llx_menu__, 'project', '', 3700__+MAX_llx_menu__, '/projet/tasks/stats/index.php?leftmenu=projects', 'Statistics', 1, 'projects', '$user->rights->projet->lire', '', 2, 4, __ENTITY__); + +insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->projet->enabled', __HANDLER__, 'left', 3400__+MAX_llx_menu__, 'project', '', 7__+MAX_llx_menu__, '/projet/activity/perweek.php?leftmenu=projects', 'NewTimeSpent', 0, 'projects', '$user->rights->projet->lire', '', 2, 3, __ENTITY__); -- Project - Categories insert into llx_menu (module, enabled, menu_handler, type, rowid, mainmenu, leftmenu, fk_menu, url, titre, level, langs, perms, target, usertype, position, entity) values ('', '$conf->categorie->enabled', __HANDLER__, 'left', 3804__+MAX_llx_menu__, 'project', 'cat', 3__+MAX_llx_menu__, '/categories/index.php?leftmenu=cat&type=6', 'Categories', 0, 'categories', '$user->rights->categorie->lire', '', 2, 4, __ENTITY__); diff --git a/htdocs/core/menus/standard/auguria.lib.php b/htdocs/core/menus/standard/auguria.lib.php index 3cc9c569120..6b42e7ad500 100644 --- a/htdocs/core/menus/standard/auguria.lib.php +++ b/htdocs/core/menus/standard/auguria.lib.php @@ -54,20 +54,17 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m if (empty($noout)) print_start_menu_array_auguria(); $usemenuhider = (GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)); - + // Show/Hide vertical menu if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { $showmode=1; $classname = 'class="tmenu menuhider"'; $idsel='menu'; - - if (empty($noout)) print_start_menu_entry_auguria($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry_auguria('', 1, '#', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry_auguria($showmode); - $menu->add('#', '', 0, $showmode, $atarget, "xxx", ''); + + $menu->add('#', '', 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname); } - + $num = count($newTabMenu); for($i = 0; $i < $num; $i++) { @@ -77,25 +74,28 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m if ($showmode == 1) { $url = $shorturl = $newTabMenu[$i]['url']; - + if (! preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url'])) { $tmp=explode('?',$newTabMenu[$i]['url'],2); $url = $shorturl = $tmp[0]; $param = (isset($tmp[1])?$tmp[1]:''); - // Complete param to force leftmenu to '' to closed opend menu when we click on a link with no leftmenu defined. - if ((! preg_match('/mainmenu/i',$param)) && (! preg_match('/leftmenu/i',$param)) && ! empty($newTabMenu[$i]['url'])) + // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined. + if ((! preg_match('/mainmenu/i',$param)) && (! preg_match('/leftmenu/i',$param)) && ! empty($newTabMenu[$i]['url'])) { - $param.=($param?'&':'').'mainmenu='.$newTabMenu[$i]['url'].'&leftmenu='; + $param.=($param?'&':'').'mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu='; } - if ((! preg_match('/mainmenu/i',$param)) && (! preg_match('/leftmenu/i',$param)) && empty($newTabMenu[$i]['url'])) + if ((! preg_match('/mainmenu/i',$param)) && (! preg_match('/leftmenu/i',$param)) && empty($newTabMenu[$i]['url'])) { $param.=($param?'&':'').'leftmenu='; } //$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad $url = dol_buildpath($url,1).($param?'?'.$param:''); - $shorturl = $shorturl.($param?'?'.$param:''); + //$shorturl = $shorturl.($param?'?'.$param:''); + $shorturl = $url; + + if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT,'/').'/','',$shorturl); } $url=preg_replace('/__LOGIN__/',$user->login,$url); @@ -110,7 +110,7 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m if ($search_project_user) $shorturl=preg_replace('/search_project_user=__search_project_user__/', 'search_project_user='.$search_project_user, $shorturl); else $shorturl=preg_replace('/search_project_user=__search_project_user__/', '', $shorturl); } - + // Define the class (top menu selected or not) if (! empty($_SESSION['idmenu']) && $newTabMenu[$i]['rowid'] == $_SESSION['idmenu']) $classname='class="tmenusel"'; else if (! empty($_SESSION["mainmenu"]) && $newTabMenu[$i]['mainmenu'] == $_SESSION["mainmenu"]) $classname='class="tmenusel"'; @@ -118,10 +118,18 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m } else if ($showmode == 2) $classname='class="tmenu"'; - if (empty($noout)) print_start_menu_entry_auguria($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry_auguria($newTabMenu[$i]['titre'], $showmode, $url, $id, $idsel, $classname, ($newTabMenu[$i]['target']?$newTabMenu[$i]['target']:$atarget)); - if (empty($noout)) print_end_menu_entry_auguria($showmode); - $menu->add($shorturl, $newTabMenu[$i]['titre'], 0, $showmode, ($newTabMenu[$i]['target']?$newTabMenu[$i]['target']:$atarget), ($newTabMenu[$i]['mainmenu']?$newTabMenu[$i]['mainmenu']:$newTabMenu[$i]['rowid']), ''); + $menu->add($shorturl, $newTabMenu[$i]['titre'], 0, $showmode, ($newTabMenu[$i]['target']?$newTabMenu[$i]['target']:$atarget), ($newTabMenu[$i]['mainmenu']?$newTabMenu[$i]['mainmenu']:$newTabMenu[$i]['rowid']), ($newTabMenu[$i]['leftmenu']?$newTabMenu[$i]['leftmenu']:''), $newTabMenu[$i]['position'], $id, $idsel, $classname); + } + + // Sort on position + $menu->liste = dol_sort_array($menu->liste, 'position'); + + // Output menu entries + foreach($menu->liste as $menkey => $menuval) + { + if (empty($noout)) print_start_menu_entry_auguria($menuval['idsel'],$menuval['classname'],$menuval['enabled']); + if (empty($noout)) print_text_menu_entry_auguria($menuval['titre'], $menuval['enabled'], ($menuval['url']!='#'?DOL_URL_ROOT:'').$menuval['url'], $menuval['id'], $menuval['idsel'], $menuval['classname'], ($menuval['target']?$menuval['target']:$atarget)); + if (empty($noout)) print_end_menu_entry_auguria($menuval['enabled']); } $showmode=1; @@ -144,7 +152,7 @@ function print_auguria_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$m function print_start_menu_array_auguria() { global $conf; - + print '
    '; print '
      global->MAIN_OPTIMIZEFORTEXTBROWSER)?'':' title="Top menu"').'>'; } @@ -258,7 +266,7 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM $usemenuhider = (GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)); global $usemenuhider; - + // Show logo company if (empty($noout) && ! empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { @@ -292,7 +300,17 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM print '
    '."\n"; print "\n"; } - + + if (is_array($moredata) && ! empty($moredata['bookmarks'])) + { + print "\n"; + print "\n"; + print '
    '."\n"; + print $moredata['bookmarks']; + print '
    '."\n"; + print "\n"; + } + // We update newmenu with entries found into database $menuArbo = new Menubase($db,'auguria'); $newmenu = $menuArbo->menuLeftCharger($newmenu,$mainmenu,$leftmenu,($user->societe_id?1:0),'auguria',$tabMenu); @@ -300,6 +318,8 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM // We update newmenu for special dynamic menus if ($conf->banque->enabled && $user->rights->banque->lire && $mainmenu == 'bank') // Entry for each bank account { + include_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Required for to get Account::TYPE_CASH for example + $sql = "SELECT rowid, label, courant, rappro, courant"; $sql.= " FROM ".MAIN_DB_PREFIX."bank_account"; $sql.= " WHERE entity = ".$conf->entity; @@ -331,8 +351,58 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM if (! empty($conf->accounting->enabled) && !empty($user->rights->accounting->mouvements->lire) && $mainmenu == 'accountancy') // Entry in accountancy journal for each bank account { - $newmenu->add('',$langs->trans("Journalization"),0,$user->rights->accounting->comptarapport->lire,'','accountancy','accountancy'); + if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add('',$langs->trans("Journalization"),0,$user->rights->accounting->comptarapport->lire,'','accountancy','accountancy'); + // Multi journal + $sql = "SELECT rowid, code, label, nature"; + $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; + $sql.= " WHERE entity = ".$conf->entity; + $sql.= " ORDER BY label"; + + $resql = $db->query($sql); + if ($resql) + { + $numr = $db->num_rows($resql); + $i = 0; + + if ($numr > 0) + { + while ($i < $numr) + { + $objp = $db->fetch_object($resql); + + $nature=''; + // Must match array $sourceList defined into journals_list.php + if ($objp->nature == 2) $nature="sells"; + if ($objp->nature == 3) $nature="purchases"; + if ($objp->nature == 4) $nature="bank"; + if ($objp->nature == 5) $nature="expensereports"; + if ($objp->nature == 1) $nature="various"; + if ($objp->nature == 9) $nature="hasnew"; + + // To enable when page exists + if (empty($conf->global->MAIN_FEATURES_LEVEL)) + { + if ($nature == 'various' || $nature == 'hasnew') $nature=''; + } + + if ($nature) + { + if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal='.$objp->rowid,dol_trunc($objp->label,25),2,$user->rights->accounting->comptarapport->lire); + } + $i++; + } + } + else + { + // Should not happend. Entries are added + $newmenu->add('',$langs->trans("NoJournalDefined"), 2, $user->rights->accounting->comptarapport->lire); + } + } + else dol_print_error($db); + $db->free($resql); + + /* $sql = "SELECT rowid, label, accountancy_journal"; $sql.= " FROM ".MAIN_DB_PREFIX."bank_account"; $sql.= " WHERE entity = ".$conf->entity; @@ -360,6 +430,7 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM $newmenu->add("/accountancy/journal/sellsjournal.php?leftmenu=journal",$langs->trans("SellsJournal"),1,$user->rights->accounting->comptarapport->lire,'','accountancy','accountancy_journal'); $newmenu->add("/accountancy/journal/purchasesjournal.php?leftmenu=journal",$langs->trans("PurchasesJournal"),1,$user->rights->accounting->comptarapport->lire,'','accountancy','accountancy_journal'); $newmenu->add("/accountancy/journal/expensereportsjournal.php?leftmenu=journal",$langs->trans("ExpenseReportsJournal"),1,$user->rights->accounting->comptarapport->lire,'','accountancy','accountancy_journal'); + */ } if ($conf->ftp->enabled && $mainmenu == 'ftp') // Entry for FTP @@ -393,14 +464,14 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM // Show menu if (empty($noout)) { - $alt=0; $altok=0; $blockvmenuopened=false; + $altok=0; $blockvmenuopened=false; $lastlevel0=''; $num=count($menu_array); - for ($i = 0; $i < $num; $i++) + for ($i = 0; $i < $num; $i++) // Loop on each menu entry { $showmenu=true; if (! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($menu_array[$i]['enabled'])) $showmenu=false; - $alt++; + // Begin of new left menu block if (empty($menu_array[$i]['level']) && $showmenu) { $altok++; @@ -409,7 +480,7 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM for($j = ($i + 1); $j < $num; $j++) { if (empty($menu_array[$j]['level'])) $lastopened=false; - } + } if ($altok % 2 == 0) { print '
    '."\n"; @@ -420,14 +491,14 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM } } - // Place tabulation + // Add tabulation $tabstring=''; $tabul=($menu_array[$i]['level'] - 1); if ($tabul > 0) { for ($j=0; $j < $tabul; $j++) { - $tabstring.='   '; + $tabstring.='   '; } } @@ -445,26 +516,37 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM print ''."\n"; - // Menu niveau 0 + // Menu level 0 if ($menu_array[$i]['level'] == 0) { - if ($menu_array[$i]['enabled']) + if ($menu_array[$i]['enabled']) // Enabled so visible { print ''; + $lastlevel0='enabled'; } - else if ($showmenu) + else if ($showmenu) // Not enabled but visible (so greyed) { print ''."\n"; + $lastlevel0='greyed'; + } + else + { + $lastlevel0='hidden'; } if ($showmenu) + { print ''."\n"; + } } - // Menu niveau > 0 + // Menu level > 0 if ($menu_array[$i]['level'] > 0) { - if ($menu_array[$i]['enabled']) + $cssmenu = ''; + if ($menu_array[$i]['url']) $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/','',$menu_array[$i]['url'])); + + if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') // Enabled so visible, except if parent was not enabled. { - print '\n"; $blockvmenuopened=false; } + if ($blockvmenuopened) { print '
    '."\n"; $blockvmenuopened=false; } } } - - if ($altok) print '
    '; + + if ($altok) print '
    '; // End menu block } - if (is_array($moredata) && ! empty($moredata['bookmarks'])) - { - print "\n"; - print "\n"; - print '
    '."\n"; - print $moredata['bookmarks']; - print '
    '."\n"; - print "\n"; - } - return count($menu_array); } diff --git a/htdocs/core/menus/standard/auguria_menu.php b/htdocs/core/menus/standard/auguria_menu.php index 4b19ffd5f3b..bd762083d2f 100644 --- a/htdocs/core/menus/standard/auguria_menu.php +++ b/htdocs/core/menus/standard/auguria_menu.php @@ -115,7 +115,7 @@ class MenuManager /** * Show menu * - * @param string $mode 'top', 'left', 'jmobile' + * @param string $mode 'top', 'left', 'jmobile' (used to get full xml ul/li menu) * @param array $moredata An array with more data to output * @return int 0 or nb of top menu entries if $mode = 'topnb' */ @@ -136,17 +136,20 @@ class MenuManager if ($mode == 'top') print_auguria_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,0,$mode); if ($mode == 'left') print_left_auguria_menu($this->db,$this->menu_array,$this->menu_array_after,$this->tabMenu,$this->menu,0,'','',$moredata); - + if ($mode == 'topnb') { print_auguria_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,1,$mode); return $this->menu->getNbOfVisibleMenuEntries(); } - - if ($mode == 'jmobile') + + if ($mode == 'jmobile') // Used to get menu in xml ul/li { print_auguria_menu($this->db,$this->atarget,$this->type_user,$this->tabMenu,$this->menu,1,$mode); + // $this->menu->liste is top menu + //var_dump($this->menu->liste);exit; + $lastlevel = array(); print ''."\n"; foreach($this->menu->liste as $key => $val) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu' { @@ -157,9 +160,17 @@ class MenuManager $relurl=dol_buildpath($val['url'],1); $relurl=preg_replace('/__LOGIN__/',$user->login,$relurl); $relurl=preg_replace('/__USERID__/',$user->id,$relurl); + $canonurl=preg_replace('/\?.*$/','',$val['url']); - print '
    '.$val['titre'].''."\n"; - // Search submenu fot this entry + print ''; + + // Add font-awesome + if ($val['level'] == 0 && $val['mainmenu'] == 'home') print ''; + + print $val['titre']; + print ''."\n"; + + // Search submenu fot this mainmenu entry $tmpmainmenu=$val['mainmenu']; $tmpleftmenu='all'; $submenu=new Menu(); @@ -177,21 +188,50 @@ class MenuManager // We add sub entry print str_pad('',1).'
  • '; // ui-btn to highlight on clic print ''; - if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") // No translation + if ($langs->trans(ucfirst($val['mainmenu'])."Dashboard") == ucfirst($val['mainmenu'])."Dashboard") // No translation { - if ($val['mainmenu'] == 'cashdesk') print $langs->trans("Access"); - else print $langs->trans("Dashboard"); + if (in_array($val['mainmenu'], array('cashdesk', 'websites'))) print $langs->trans("Access"); + else print $langs->trans("Dashboard"); } else print $langs->trans(ucfirst($val['mainmenu'])."Dashboard"); print ''; print '
  • '."\n"; } - foreach($submenu->liste as $key2 => $val2) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu' + + if ($val['level']==0) + { + if ($val['enabled']) + { + $lastlevel[0]='enabled'; + } + else if ($showmenu) // Not enabled but visible (so greyed) + { + $lastlevel[0]='greyed'; + } + else + { + $lastlevel[0]='hidden'; + } + } + + $lastlevel2 = array(); + foreach($submenu->liste as $key2 => $val2) // $val['url','titre','level','enabled'=0|1|2,'target','mainmenu','leftmenu' { $showmenu=true; if (! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($val2['enabled'])) $showmenu=false; - if ($showmenu) // Visible (option to hide when not allowed is off or allowed) + // If at least one parent is not enabled, we do not show any menu of all children + if ($val2['level'] > 0) + { + $levelcursor = $val2['level']-1; + while ($levelcursor >= 0) + { + if ($lastlevel2[$levelcursor] != 'enabled') $showmenu=false; + $levelcursor--; + } + } + + if ($showmenu) // Visible (option to hide when not allowed is off or allowed) { $relurl2=dol_buildpath($val2['url'],1); $relurl2=preg_replace('/__LOGIN__/',$user->login,$relurl2); @@ -199,8 +239,17 @@ class MenuManager $canonurl2=preg_replace('/\?.*$/','',$val2['url']); //var_dump($val2['url'].' - '.$canonurl2.' - '.$val2['level']); if (in_array($canonurl2,array('/admin/index.php','/admin/tools/index.php','/core/tools.php'))) $relurl2=''; - if ($val2['level']==0) print str_pad('',$val2['level']+1).'
  • '; // ui-btn to highlight on clic - else print str_pad('',$val2['level']+1).'
  • '; // ui-btn to highlight on clic + + $disabled=''; + if (! $val2['enabled']) + { + $disabled=" vsmenudisabled"; + } + + print str_pad('',$val2['level']+1); + print '
  • '; // ui-btn to highlight on clic if ($relurl2) { if ($val2['enabled']) // Allowed @@ -208,12 +257,25 @@ class MenuManager print ''; + $lastlevel2[$val2['level']]='enabled'; } else // Not allowed but visible (greyed) { print ''; + $lastlevel2[$val2['level']]='greyed'; } } + else + { + if ($val2['enabled']) // Allowed + { + $lastlevel2[$val2['level']]='enabled'; + } + else + { + $lastlevel2[$val2['level']]='greyed'; + } + } print $val2['titre']; if ($relurl2) { diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index 6248f294476..66bfdcbce87 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -52,7 +52,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode if (empty($noout)) print_start_menu_array(); $usemenuhider = (GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)); - + // Show/Hide vertical menu if ($mode != 'jmobile' && $mode != 'topnb' && $usemenuhider && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { @@ -60,10 +60,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode $classname = 'class="tmenu menuhider"'; $idsel='menu'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry('', 1, '#', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('#', '', 0, $showmode, $atarget, "xxx", ''); + $menu->add('#', '', 0, $showmode, $atarget, "xxx", '', 0, $id, $idsel, $classname); } // Home @@ -73,10 +70,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode else $classname = 'class="tmenu"'; $idsel='home'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($langs->trans("Home"), 1, DOL_URL_ROOT.'/index.php?mainmenu=home&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/index.php?mainmenu=home&leftmenu=home', $langs->trans("Home"), 0, $showmode, $atarget, "home", ''); + $menu->add('/index.php?mainmenu=home&leftmenu=home', $langs->trans("Home"), 0, $showmode, $atarget, "home", '', 10, $id, $idsel, $classname); // Third parties $tmpentry=array('enabled'=>(( ! empty($conf->societe->enabled) && (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))) || ! empty($conf->fournisseur->enabled)), 'perms'=>(! empty($user->rights->societe->lire) || ! empty($user->rights->fournisseur->lire)), 'module'=>'societe|fournisseur'); @@ -91,10 +85,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode else $classname = 'class="tmenu"'; $idsel='companies'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($langs->trans("ThirdParties"), $showmode, DOL_URL_ROOT.'/societe/index.php?mainmenu=companies&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/societe/index.php?mainmenu=companies&leftmenu=', $langs->trans("ThirdParties"), 0, $showmode, $atarget, "companies", ''); + $menu->add('/societe/index.php?mainmenu=companies&leftmenu=', $langs->trans("ThirdParties"), 0, $showmode, $atarget, "companies", '', 20, $id, $idsel, $classname); } // Products-Services @@ -120,10 +111,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode $chaine.=$langs->trans("TMenuServices"); } - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($chaine, $showmode, DOL_URL_ROOT.'/product/index.php?mainmenu=products&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/product/index.php?mainmenu=products&leftmenu=', $chaine, 0, $showmode, $atarget, "products", ''); + $menu->add('/product/index.php?mainmenu=products&leftmenu=', $chaine, 0, $showmode, $atarget, "products", '', 30, $id, $idsel, $classname); } // Commercial @@ -147,10 +135,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode else $classname = 'class="tmenu"'; $idsel='commercial'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($langs->trans("Commercial"), $showmode, DOL_URL_ROOT.'/comm/index.php?mainmenu=commercial&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/comm/index.php?mainmenu=commercial&leftmenu=', $langs->trans("Commercial"), 0, $showmode, $atarget, "commercial", ""); + $menu->add('/comm/index.php?mainmenu=commercial&leftmenu=', $langs->trans("Commercial"), 0, $showmode, $atarget, "commercial", "", 40, $id, $idsel, $classname); } // Financial @@ -177,10 +162,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode else $classname = 'class="tmenu"'; $idsel='accountancy'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($langs->trans("MenuFinancial"), $showmode, DOL_URL_ROOT.'/compta/index.php?mainmenu=accountancy&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/compta/index.php?mainmenu=accountancy&leftmenu=', $langs->trans("MenuFinancial"), 0, $showmode, $atarget, "accountancy", ''); + $menu->add('/compta/index.php?mainmenu=accountancy&leftmenu=', $langs->trans("MenuFinancial"), 0, $showmode, $atarget, "accountancy", '', 50, $id, $idsel, $classname); } // Bank @@ -198,10 +180,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode else $classname = 'class="tmenu"'; $idsel='bank'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($langs->trans("MenuBankCash"), $showmode, DOL_URL_ROOT.'/compta/bank/index.php?mainmenu=bank&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/compta/bank/index.php?mainmenu=bank&leftmenu=', $langs->trans("MenuBankCash"), 0, $showmode, $atarget, "bank", ''); + $menu->add('/compta/bank/index.php?mainmenu=bank&leftmenu=', $langs->trans("MenuBankCash"), 0, $showmode, $atarget, "bank", '', 60, $id, $idsel, $classname); } // Projects @@ -218,10 +197,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode else $classname = 'class="tmenu"'; $idsel='project'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($langs->trans("Projects"), $showmode, DOL_URL_ROOT.'/projet/index.php?mainmenu=project&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/projet/index.php?mainmenu=project&leftmenu=', $langs->trans("Projects"), 0, $showmode, $atarget, "project", ''); + $menu->add('/projet/index.php?mainmenu=project&leftmenu=', $langs->trans("Projects"), 0, $showmode, $atarget, "project", '', 70, $id, $idsel, $classname); } // HRM @@ -238,10 +214,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode else $classname = 'class="tmenu"'; $idsel='hrm'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($langs->trans("HRM"), $showmode, DOL_URL_ROOT.'/hrm/index.php?mainmenu=hrm&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/hrm/index.php?mainmenu=hrm&leftmenu=', $langs->trans("HRM"), 0, $showmode, $atarget, "hrm", ''); + $menu->add('/hrm/index.php?mainmenu=hrm&leftmenu=', $langs->trans("HRM"), 0, $showmode, $atarget, "hrm", '', 80, $id, $idsel, $classname); } @@ -260,10 +233,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode else $classname = 'class="tmenu"'; $idsel='tools'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($langs->trans("TMenuTools"), $showmode, DOL_URL_ROOT.'/core/tools.php?mainmenu=tools&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/core/tools.php?mainmenu=tools&leftmenu=', $langs->trans("Tools"), 0, $showmode, $atarget, "tools", ''); + $menu->add('/core/tools.php?mainmenu=tools&leftmenu=', $langs->trans("Tools"), 0, $showmode, $atarget, "tools", '', 90, $id, $idsel, $classname); } // Members @@ -278,10 +248,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode else $classname = 'class="tmenu"'; $idsel='members'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($langs->trans("MenuMembers"), $showmode, DOL_URL_ROOT.'/adherents/index.php?mainmenu=members&leftmenu=', $id, $idsel, $classname, $atarget); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add('/adherents/index.php?mainmenu=members&leftmenu=', $langs->trans("MenuMembers"), 0, $showmode, $atarget, "members", ''); + $menu->add('/adherents/index.php?mainmenu=members&leftmenu=', $langs->trans("MenuMembers"), 0, $showmode, $atarget, "members", '', 100, $id, $idsel, $classname); } @@ -297,6 +264,7 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode $showmode=dol_eldy_showmenu($type_user,$newTabMenu[$i],$listofmodulesforexternal); if ($showmode == 1) { + // url = url from host, shorturl = relative path into dolibarr sources $url = $shorturl = $newTabMenu[$i]['url']; if (! preg_match("/^(http:\/\/|https:\/\/)/i",$newTabMenu[$i]['url'])) { @@ -307,7 +275,9 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode if (! preg_match('/mainmenu/i',$param) || ! preg_match('/leftmenu/i',$param)) $param.=($param?'&':'').'mainmenu='.$newTabMenu[$i]['mainmenu'].'&leftmenu='; //$url.="idmenu=".$newTabMenu[$i]['rowid']; // Already done by menuLoad $url = dol_buildpath($url,1).($param?'?'.$param:''); - $shorturl = $shorturl.($param?'?'.$param:''); + //$shorturl = $shorturl.($param?'?'.$param:''); + $shorturl = $url; + if (DOL_URL_ROOT) $shorturl = preg_replace('/^'.preg_quote(DOL_URL_ROOT,'/').'/','',$shorturl); } $url=preg_replace('/__LOGIN__/',$user->login,$url); $shorturl=preg_replace('/__LOGIN__/',$user->login,$shorturl); @@ -321,10 +291,18 @@ function print_eldy_menu($db,$atarget,$type_user,&$tabMenu,&$menu,$noout=0,$mode } else if ($showmode == 2) $classname='class="tmenu"'; - if (empty($noout)) print_start_menu_entry($idsel,$classname,$showmode); - if (empty($noout)) print_text_menu_entry($newTabMenu[$i]['titre'], $showmode, $url, $id, $idsel, $classname, ($newTabMenu[$i]['target']?$newTabMenu[$i]['target']:$atarget)); - if (empty($noout)) print_end_menu_entry($showmode); - $menu->add($shorturl, $newTabMenu[$i]['titre'], 0, $showmode, ($newTabMenu[$i]['target']?$newTabMenu[$i]['target']:$atarget), ($newTabMenu[$i]['mainmenu']?$newTabMenu[$i]['mainmenu']:$newTabMenu[$i]['rowid']), ''); + $menu->add($shorturl, $newTabMenu[$i]['titre'], 0, $showmode, ($newTabMenu[$i]['target']?$newTabMenu[$i]['target']:$atarget), ($newTabMenu[$i]['mainmenu']?$newTabMenu[$i]['mainmenu']:$newTabMenu[$i]['rowid']), ($newTabMenu[$i]['leftmenu']?$newTabMenu[$i]['leftmenu']:''), $newTabMenu[$i]['position'], $id, $idsel, $classname); + } + + // Sort on position + $menu->liste = dol_sort_array($menu->liste, 'position'); + + // Output menu entries + foreach($menu->liste as $menkey => $menuval) + { + if (empty($noout)) print_start_menu_entry($menuval['idsel'],$menuval['classname'],$menuval['enabled']); + if (empty($noout)) print_text_menu_entry($menuval['titre'], $menuval['enabled'], ($menuval['url']!='#'?DOL_URL_ROOT:'').$menuval['url'], $menuval['id'], $menuval['idsel'], $menuval['classname'], ($menuval['target']?$menuval['target']:$atarget)); + if (empty($noout)) print_end_menu_entry($menuval['enabled']); } $showmode=1; @@ -437,7 +415,7 @@ function print_end_menu_array() /** * Core function to output left menu eldy * Fill &$menu (example with $forcemainmenu='home' $forceleftmenu='all', return left menu tree of Home) - * + * * @param DoliDB $db Database handler * @param array $menu_array_before Table of menu entries to show before entries of menu handler (menu->liste filled with menu->add) * @param array $menu_array_after Table of menu entries to show after entries of menu handler (menu->liste filled with menu->add) @@ -445,7 +423,7 @@ function print_end_menu_array() * @param Menu $menu Object Menu to return back list of menu entries * @param int $noout Disable output (Initialise &$menu only). * @param string $forcemainmenu 'x'=Force mainmenu to mainmenu='x' - * @param string $forceleftmenu 'all'=Force leftmenu to '' (= all). If value come being '', we change it to value in session and 'none' if not efined in session. + * @param string $forceleftmenu 'all'=Force leftmenu to '' (= all). If value come being '', we change it to value in session and 'none' if not defined in session. * @param array $moredata An array with more data to output * @return int nb of menu entries */ @@ -459,7 +437,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $leftmenu=($forceleftmenu?'':(empty($_SESSION["leftmenu"])?'none':$_SESSION["leftmenu"])); $usemenuhider = (GETPOST('testmenuhider','int') || ! empty($conf->global->MAIN_TESTMENUHIDER)); - + // Show logo company if (empty($conf->global->MAIN_MENU_INVERT) && empty($noout) && ! empty($conf->global->MAIN_SHOW_LOGO) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { @@ -503,7 +481,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu print '
  • '."\n"; print "\n"; } - + /** * We update newmenu with entries found into database * -------------------------------------------------- @@ -597,15 +575,15 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if ($usemenuhider || empty($leftmenu) || $leftmenu=="users") { $newmenu->add("", $langs->trans("Users"), 1, $user->rights->user->user->lire || $user->admin); - $newmenu->add("/user/card.php?leftmenu=users&action=create", $langs->trans("NewUser"),2, $user->rights->user->user->creer || $user->admin, '', 'home'); + $newmenu->add("/user/card.php?leftmenu=users&action=create", $langs->trans("NewUser"),2, ($user->rights->user->user->creer || $user->admin) && !(! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE), '', 'home'); $newmenu->add("/user/index.php?leftmenu=users", $langs->trans("ListOfUsers"), 2, $user->rights->user->user->lire || $user->admin); $newmenu->add("/user/hierarchy.php?leftmenu=users", $langs->trans("HierarchicView"), 2, $user->rights->user->user->lire || $user->admin); - $newmenu->add("", $langs->trans("Groups"), 1, $user->rights->user->user->lire || $user->admin); - $newmenu->add("/user/group/card.php?leftmenu=users&action=create", $langs->trans("NewGroup"), 2, ($conf->global->MAIN_USE_ADVANCED_PERMS?$user->rights->user->group_advance->write:$user->rights->user->user->creer) || $user->admin); - $newmenu->add("/user/group/index.php?leftmenu=users", $langs->trans("ListOfGroups"), 2, ($conf->global->MAIN_USE_ADVANCED_PERMS?$user->rights->user->group_advance->read:$user->rights->user->user->lire) || $user->admin); + $newmenu->add("", $langs->trans("Groups"), 1, ($user->rights->user->user->lire || $user->admin) && !(! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)); + $newmenu->add("/user/group/card.php?leftmenu=users&action=create", $langs->trans("NewGroup"), 2, (($conf->global->MAIN_USE_ADVANCED_PERMS?$user->rights->user->group_advance->write:$user->rights->user->user->creer) || $user->admin) && !(! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)); + $newmenu->add("/user/group/index.php?leftmenu=users", $langs->trans("ListOfGroups"), 2, (($conf->global->MAIN_USE_ADVANCED_PERMS?$user->rights->user->group_advance->read:$user->rights->user->user->lire) || $user->admin) && !(! empty($conf->multicompany->enabled) && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE)); } } - + } @@ -811,7 +789,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills_paid&search_status=2",$langs->trans("BillShortStatusPaid"),2,$user->rights->facture->lire); $newmenu->add("/compta/facture/list.php?leftmenu=customers_bills_canceled&search_status=3",$langs->trans("BillShortStatusCanceled"),2,$user->rights->facture->lire); } - $newmenu->add("/compta/facture/fiche-rec.php",$langs->trans("ListOfTemplates"),1,$user->rights->facture->lire); + $newmenu->add("/compta/facture/fiche-rec.php",$langs->trans("ListOfTemplates"),1,$user->rights->facture->creer); // No need to see recurring invoices, if user has no permission to create invoice. $newmenu->add("/compta/paiement/list.php",$langs->trans("Payments"),1,$user->rights->facture->lire); @@ -839,7 +817,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu } $newmenu->add("/fourn/facture/paiement.php", $langs->trans("Payments"),1,$user->rights->fournisseur->facture->lire); - + $newmenu->add("/fourn/facture/rapport.php",$langs->trans("Reportings"),2,$user->rights->fournisseur->facture->lire); $newmenu->add("/compta/facture/stats/index.php?mode=supplier", $langs->trans("Statistics"),1,$user->rights->fournisseur->facture->lire); @@ -957,29 +935,35 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("Chartofaccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_chart', 30); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/categories_list.php?id=32&search_country_id=".$mysoc->country_id."&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("AccountingCategory"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_chart', 31); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/defaultaccounts.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuDefaultAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 40); - if (! empty($conf->facture->enabled) || ! empty($conf->fournisseur->enabled)) + if (! empty($conf->facture->enabled) || ! empty($conf->fournisseur->enabled)) { if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/admin/dict.php?id=10&from=accountancy&search_country_id=".$mysoc->country_id."&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuVatAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 50); } - if (! empty($conf->tax->enabled)) + if (! empty($conf->tax->enabled)) { if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/admin/dict.php?id=7&from=accountancy&search_country_id=".$mysoc->country_id."&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuTaxAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 50); } - if (! empty($conf->expensereport->enabled)) + if (! empty($conf->expensereport->enabled)) { if (preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/admin/dict.php?id=17&from=accountancy&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuExpenseReportAccounts"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_default', 50); } /* not required yet, already supported by default account - if (! empty($conf->loan->enabled)) + if (! empty($conf->loan->enabled)) { if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/admin/loan.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuLoanAccounts"), 2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_loan', 45); } - if (! empty($conf->don->enabled)) + if (! empty($conf->don->enabled)) { if (preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/don/admin/donation.php?from=accountancy&mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuDonationAccounts"), 2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_donation', 47); }*/ - if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/productaccount.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuProductsAccounts"), 2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_product', 60); - + if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/productaccount.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("MenuProductsAccounts"), 2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_product', 60); + + // Fiscal year + if ($conf->global->MAIN_FEATURES_LEVEL > 0) // Not yet used. In a future will lock some periods. + { + if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/fiscalyear.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("FiscalPeriod"), 2, $user->rights->accounting->fiscalyear, '', $mainmenu, 'fiscalyear'); + } + // Binding if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add("/accountancy/customer/index.php?leftmenu=accountancy_dispatch_customer&mainmenu=accountancy",$langs->trans("CustomersVentilation"),1,$user->rights->accounting->bind->write, '', $mainmenu, 'dispatch_customer'); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_dispatch_customer/',$leftmenu)) $newmenu->add("/accountancy/customer/list.php?mainmenu=accountancy&leftmenu=accountancy_dispatch_customer",$langs->trans("ToBind"),2,$user->rights->accounting->bind->write); @@ -1008,7 +992,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $sql = "SELECT rowid, code, label, nature"; $sql.= " FROM ".MAIN_DB_PREFIX."accounting_journal"; $sql.= " WHERE entity = ".$conf->entity; - $sql.= " ORDER BY nature"; + $sql.= " ORDER BY label"; $resql = $db->query($sql); if ($resql) @@ -1018,30 +1002,32 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if ($numr > 0) { - while ($i < $numr) - { - $objp = $db->fetch_object($resql); + while ($i < $numr) + { + $objp = $db->fetch_object($resql); - $nature=''; - // Must match array $sourceList defined into journals_list.php - if ($objp->nature == 2) $nature="sells"; - if ($objp->nature == 3) $nature="purchases"; - if ($objp->nature == 4) $nature="bank"; - if ($objp->nature == 1) $nature="various"; - if ($objp->nature == 9) $nature="hasnew"; - - // To enable when page exists - if (empty($conf->global->MAIN_FEATURES_LEVEL)) - { - if ($nature == 'various' || $nature == 'hasnew') $nature=''; - } - - if ($nature) - { - if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&code_journal='.$objp->code,dol_trunc($objp->label,25),2,$user->rights->accounting->comptarapport->lire); - } - $i++; - } + $nature=''; + + // Must match array $sourceList defined into journals_list.php + if ($objp->nature == 2 && ! empty($conf->facture->enabled)) $nature="sells"; + if ($objp->nature == 3 && ! empty($conf->fournisseur->enabled)) $nature="purchases"; + if ($objp->nature == 4 && ! empty($conf->banque->enabled)) $nature="bank"; + if ($objp->nature == 5 && ! empty($conf->expensereport->enabled)) $nature="expensereports"; + if ($objp->nature == 1) $nature="various"; + if ($objp->nature == 9) $nature="hasnew"; + + // To enable when page exists + if (empty($conf->global->MAIN_FEATURES_LEVEL)) + { + if ($nature == 'various' || $nature == 'hasnew') $nature=''; + } + + if ($nature) + { + if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add('/accountancy/journal/'.$nature.'journal.php?mainmenu=accountancy&leftmenu=accountancy_journal&id_journal='.$objp->rowid, dol_trunc($objp->label,25), 2, $user->rights->accounting->comptarapport->lire); + } + $i++; + } } else { @@ -1094,19 +1080,13 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add("/accountancy/report/result.php?mainmenu=accountancy&leftmenu=accountancy_report",$langs->trans("Reportings"),1,$user->rights->accounting->comptarapport->lire, '', $mainmenu, 'ca'); - if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/',$leftmenu)) $newmenu->add("/accountancy/report/result.php?leftmenu=accountancy_report",$langs->trans("ReportInOut"),2,$user->rights->accounting->comptarapport->lire); - if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/',$leftmenu)) $newmenu->add("/compta/resultat/index.php?leftmenu=accountancy_report",$langs->trans("ByExpenseIncome"),3,$user->rights->accounting->comptarapport->lire); + if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/',$leftmenu)) $newmenu->add("/compta/resultat/index.php?leftmenu=accountancy_report",$langs->trans("ReportInOut"),2,$user->rights->accounting->comptarapport->lire); + if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/',$leftmenu)) $newmenu->add("/accountancy/report/result.php?leftmenu=accountancy_report",$langs->trans("ByAccounts"),3,$user->rights->accounting->comptarapport->lire); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/',$leftmenu)) $newmenu->add("/compta/resultat/clientfourn.php?leftmenu=accountancy_report",$langs->trans("ByCompanies"),3,$user->rights->accounting->comptarapport->lire); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/',$leftmenu)) $newmenu->add("/compta/stats/index.php?leftmenu=accountancy_report",$langs->trans("ReportTurnover"),2,$user->rights->accounting->comptarapport->lire); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/',$leftmenu)) $newmenu->add("/compta/stats/casoc.php?leftmenu=accountancy_report",$langs->trans("ByCompanies"),3,$user->rights->accounting->comptarapport->lire); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/',$leftmenu)) $newmenu->add("/compta/stats/cabyuser.php?leftmenu=accountancy_report",$langs->trans("ByUsers"),3,$user->rights->accounting->comptarapport->lire); if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_report/',$leftmenu)) $newmenu->add("/compta/stats/cabyprodserv.php?leftmenu=accountancy_report", $langs->trans("ByProductsAndServices"),3,$user->rights->accounting->comptarapport->lire); - - // Fiscal year - if ($conf->global->MAIN_FEATURES_LEVEL > 0) // Not yet used. In a future will lock some periods. - { - if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy/',$leftmenu)) $newmenu->add("/accountancy/admin/fiscalyear.php?mainmenu=accountancy&leftmenu=accountancy_periods", $langs->trans("FiscalPeriod"),1,$user->rights->accounting->fiscalyear, '', $mainmenu, 'fiscalyear'); - } } // Accountancy (simple) @@ -1275,7 +1255,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/product/inventory/list.php", $langs->trans("List"), 1, $user->rights->stock->lire); } } - + // Expeditions if (! empty($conf->expedition->enabled)) { @@ -1299,9 +1279,9 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if (! empty($conf->projet->enabled)) { $langs->load("projects"); - + $search_project_user = GETPOST('search_project_user','int'); - + // Project affected to user $newmenu->add("/projet/index.php?leftmenu=projects".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("Projects"), 0, $user->rights->projet->lire, '', $mainmenu, 'projects'); $newmenu->add("/projet/card.php?leftmenu=projects&action=create".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("NewProject"), 1, $user->rights->projet->creer); @@ -1314,14 +1294,16 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/projet/list.php?leftmenu=projects&search_status=99", $langs->trans("List"), 1, $user->rights->projet->lire && $user->rights->projet->lire); */ $newmenu->add("/projet/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire); - + if (empty($conf->global->PROJECT_HIDE_TASKS)) { // Project affected to user $newmenu->add("/projet/activity/index.php?leftmenu=tasks".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("Activities"), 0, $user->rights->projet->lire); $newmenu->add("/projet/tasks.php?leftmenu=tasks&action=create", $langs->trans("NewTask"), 1, $user->rights->projet->creer); $newmenu->add("/projet/tasks/list.php?leftmenu=tasks".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("List"), 1, $user->rights->projet->lire); - $newmenu->add("/projet/activity/perweek.php?leftmenu=tasks".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("NewTimeSpent"), 1, $user->rights->projet->lire); + $newmenu->add("/projet/tasks/stats/index.php?leftmenu=projects", $langs->trans("Statistics"), 1, $user->rights->projet->lire); + + $newmenu->add("/projet/activity/perweek.php?leftmenu=tasks".($search_project_user?'&search_project_user='.$search_project_user:''), $langs->trans("NewTimeSpent"), 0, $user->rights->projet->lire); // All project i have permission on /*$newmenu->add("/projet/activity/index.php", $langs->trans("Activities"), 0, $user->rights->projet->lire && $user->rights->projet->lire); @@ -1445,7 +1427,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $newmenu->add("/adherents/stats/index.php?leftmenu=members",$langs->trans("MenuMembersStats"),1,$user->rights->adherent->lire); if (! empty($conf->global->MEMBER_LINK_TO_HTPASSWDFILE) && ($usemenuhider || empty($leftmenu) || $leftmenu=="export")) $newmenu->add("/adherents/htpasswd.php?leftmenu=export",$langs->trans("Filehtpasswd"),1,$user->rights->adherent->export); if ($usemenuhider || empty($leftmenu) || $leftmenu=="export") $newmenu->add("/adherents/cartes/carte.php?leftmenu=export",$langs->trans("MembersCards"),1,$user->rights->adherent->export); - + $newmenu->add("/adherents/index.php?leftmenu=members&mainmenu=members",$langs->trans("Subscriptions"),0,$user->rights->adherent->cotisation->lire); $newmenu->add("/adherents/list.php?leftmenu=members&statut=-1,1&mainmenu=members",$langs->trans("NewSubscription"),1,$user->rights->adherent->cotisation->creer); $newmenu->add("/adherents/subscription/list.php?leftmenu=members",$langs->trans("List"),1,$user->rights->adherent->cotisation->lire); @@ -1556,14 +1538,14 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $invert=empty($conf->global->MAIN_MENU_INVERT)?"":"invert"; if (empty($noout)) { - $alt=0; $altok=0; $blockvmenuopened=false; + $altok=0; $blockvmenuopened=false; $lastlevel0=''; $num=count($menu_array); - for ($i = 0; $i < $num; $i++) + for ($i = 0; $i < $num; $i++) // Loop on each menu entry { $showmenu=true; if (! empty($conf->global->MAIN_MENU_HIDE_UNAUTHORIZED) && empty($menu_array[$i]['enabled'])) $showmenu=false; - $alt++; + // Begin of new left menu block if (empty($menu_array[$i]['level']) && $showmenu) { $altok++; @@ -1583,7 +1565,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu } } - // Place tabulation + // Add tabulation $tabstring=''; $tabul=($menu_array[$i]['level'] - 1); if ($tabul > 0) @@ -1602,7 +1584,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu $url = $shorturl = $tmp[0]; $param = (isset($tmp[1])?$tmp[1]:''); // params in url of the menu link - // Complete param to force leftmenu to '' to closed opend menu when we click on a link with no leftmenu defined. + // Complete param to force leftmenu to '' to close open menu when we click on a link with no leftmenu defined. if ((! preg_match('/mainmenu/i',$param)) && (! preg_match('/leftmenu/i',$param)) && ! empty($menu_array[$i]['mainmenu'])) { $param.=($param?'&':'').'mainmenu='.$menu_array[$i]['mainmenu'].'&leftmenu='; @@ -1623,26 +1605,37 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu print ''."\n"; - // Menu niveau 0 + // Menu level 0 if ($menu_array[$i]['level'] == 0) { - if ($menu_array[$i]['enabled']) + if ($menu_array[$i]['enabled']) // Enabled so visible { print ''."\n"; + $lastlevel0='enabled'; } - else if ($showmenu) + else if ($showmenu) // Not enabled but visible (so greyed) { print ''."\n"; + $lastlevel0='greyed'; + } + else + { + $lastlevel0='hidden'; } if ($showmenu) + { print ''."\n"; + } } - // Menu niveau > 0 + // Menu level > 0 if ($menu_array[$i]['level'] > 0) { - if ($menu_array[$i]['enabled']) + $cssmenu = ''; + if ($menu_array[$i]['url']) $cssmenu = ' menu_contenu'.dol_string_nospecial(preg_replace('/\.php.*$/','',$menu_array[$i]['url'])); + + if ($menu_array[$i]['enabled'] && $lastlevel0 == 'enabled') // Enabled so visible, except if parent was not enabled. { - print '