diff --git a/.travis.yml b/.travis.yml index 8655b27d4ed..8e1aa2aa10b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -287,10 +287,13 @@ script: php upgrade.php 3.9.0 4.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade390400.log php upgrade2.php 3.9.0 4.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade390400-2.log php step5.php 3.9.0 4.0.0 > $TRAVIS_BUILD_DIR/upgrade390400-3.log + php upgrade.php 4.0.0 5.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade400500.log + php upgrade2.php 4.0.0 5.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade400500-2.log + php step5.php 4.0.0 5.0.0 > $TRAVIS_BUILD_DIR/upgrade400500-3.log cd - set +e echo - #cat $TRAVIS_BUILD_DIR/upgrade390400-2.log + #cat $TRAVIS_BUILD_DIR/upgrade400500-2.log #cat /tmp/dolibarr_install.log - | diff --git a/ChangeLog b/ChangeLog index 42ce301dced..5d36a236738 100644 --- a/ChangeLog +++ b/ChangeLog @@ -163,6 +163,41 @@ So if you included it into your module, change your code like this to be compati +***** ChangeLog for 3.9.3 compared to 3.9.2 ***** +FIX: #4383 $userid not defined +FIX: #4448 $filebonprev is not used, $this->filename now +FIX: #4455 +FIX: #4749 +FIX: #4756 +FIX: #4828 +FIX: #4926 +FIX: #4964 buyprice in customer from shipping buyprice wasn't load in expedition::fetch_lines +FIX: #5004 +FIX: #5068 +FIX: #5170 tva sign with INVOICE_POSITIVE_CREDIT_NOTE option +FIX: #5338 use of not initialized var $aphour, $apmin, etc +FIX: #5343 +FIX: #5380 +FIX: #5383 bad object id on don delete +FIX: #5414 +FIX: #5470 User of expense report in bank transactions page is not correct +FIX: a case of corrupted ODT by Word that insert when it should not. +FIX: Can't create thirdparty or validate invoice if profid is mandatory and profid does not exists for other countries +FIX: dasboard wrong for late invoice +FIX: duplicate jquery.js files +FIX: extrafield cloned on project clone +FIX: Failed to open file +FIX: Filter on opportunity amount and budget +FIX: form_confirm to delete payment on supplier invoice +FIX: javascript error with german-switzerland language +FIX: large expense note +FIX: Missing original .js file (license violation if sources are not provided) +FIX: Option strict mode compatibility +FIX: product stats all bloc module without enbaled test +FIX: receiving link never works +FIX: task ODT company object not correctly retrieved +FIX: Translate group perms as it is done into user perms +FIX: We must take the last recent defined price when using price level ***** ChangeLog for 3.9.2 compared to 3.9.1 ***** FIX: #4813 Won translation for the key OppStatusWON instead OppStatusWIN diff --git a/README.md b/README.md index a3a542b194e..cb5f7e61c70 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ Dolibarr ERP & CRM is a modern software to manage your organization's activity (contacts, suppliers, invoices, orders, stocks, agenda, ...). -It's an Open Source software (wrote in PHP language) designed for small and medium companies, foundation and freelances. +It's an Open Source software (wrote in PHP language) designed for small, medium or large companies, foundations and freelances. You can freely use, study, modify or distribute it according to its Free Software licence. diff --git a/build/debian/README.howto b/build/debian/README.howto index 6632d6e8e84..6f57894a960 100644 --- a/build/debian/README.howto +++ b/build/debian/README.howto @@ -288,11 +288,11 @@ from origin/upstream and origin/pristine. > debian/get-orig-source.sh If script fails with error Bad certificate, you can set "export PERL_LWP_SSL_VERIFY_HOSTNAME=0" to solve this. -* Edit tgz file to remove +* Edit orig.tar.gz file to remove +- debian - htdocs/includes/ckeditor -- htdocs/includes/jquery/plugins/datatables/extras/TableTools/swf -- htdocs/includes/phpexcel -- htdocs/includes/tcpdf +- htdocs/includes/phpexcel or htdocs/includes/phpoffice +- htdocs/includes/tcpdf or htdocs/includes/tecnickom And rename file into dolibarr-x.y.z+dfsgw.tgz (x.y.z = version, w start from 1 and is increased for each new git-import-orig already done) diff --git a/build/debian/control b/build/debian/control index d25c752c14c..9a76856505a 100755 --- a/build/debian/control +++ b/build/debian/control @@ -13,7 +13,7 @@ Architecture: all Depends: libapache2-mod-php5 | libapache2-mod-php5filter | php5-cgi | php5-fpm | php5, php5-cli, # Required PHP extensions - php5-mysql | php5-mysqli, php5-curl, php5-gd, php5-ldap, php5-geoip, + php5-mysql | php5-mysqli, php5-curl, php5-gd, php5-ldap, # Required PHP libraries php-pear, php-mail-mime, # php-tcpdf, libfpdi-php, @@ -31,10 +31,10 @@ Depends: libapache2-mod-php5 | libapache2-mod-php5filter | php5-cgi | php5-fpm | ${misc:Depends}, ${perl:Depends} Recommends: apache2 | lighttpd | httpd -Suggests: www-browser +Suggests: www-browser, php5-geoip Description: Web based software to manage a company or foundation - Dolibarr ERP & CRM is an easy to use open source/free software for small - and medium companies, foundations or freelances. It includes different + Dolibarr ERP & CRM is an easy to use open source/free software package for + companies, foundations or freelances. It includes different features for Enterprise Resource Planning (ERP) and Customer Relationship Management (CRM) but also for different other activities. . diff --git a/build/debian/dolibarr.docs b/build/debian/dolibarr.docs index 5d4b554ef74..b43bf86b50f 100644 --- a/build/debian/dolibarr.docs +++ b/build/debian/dolibarr.docs @@ -1,2 +1 @@ README.md -README-FR.md diff --git a/build/debian/watch b/build/debian/watch index a5b736c1f65..8206a7f8b7a 100644 --- a/build/debian/watch +++ b/build/debian/watch @@ -2,4 +2,4 @@ version=3 #http://sf.net/dolibarr/dolibarr-(.+)\.tgz -http://www.dolibarr.org/files/stable/standard/dolibarr-(.+)\.tgz +http://www.dolibarr.org/files/stable/package_debian-ubuntu/dolibarr_(.+)\.orig\.tar\.gz diff --git a/build/doxygen/doxygen_footer.html b/build/doxygen/doxygen_footer.html index e11df270ddc..410e57e8c2a 100644 --- a/build/doxygen/doxygen_footer.html +++ b/build/doxygen/doxygen_footer.html @@ -4,17 +4,14 @@ File added into doxygen generated documentation - @@ -41,5 +38,14 @@ google_ad_height = 60;
+ + + + + + \ No newline at end of file diff --git a/build/doxygen/doxygen_header.html b/build/doxygen/doxygen_header.html index 0c2e189136b..fe316d2081e 100644 --- a/build/doxygen/doxygen_header.html +++ b/build/doxygen/doxygen_header.html @@ -1,6 +1,4 @@ - + @@ -14,7 +12,23 @@ File added into doxygen generated documentation + + + + + +
diff --git a/build/exe/doliwamp/Languages/MyCatalan.isl b/build/exe/doliwamp/Languages/MyCatalan.isl index a78042e795b..d8b86eae5ba 100644 --- a/build/exe/doliwamp/Languages/MyCatalan.isl +++ b/build/exe/doliwamp/Languages/MyCatalan.isl @@ -20,7 +20,7 @@ DoYouWantToStart=Vol iniciar el proc TechnicalParameters=Paràmetres tècnics IfFirstInstall=Si es tracta de la primera instal lació, haurà d'especificar alguns paràmetres tècnics. Si no els entén, no sabeu o va a procedir a una actualització, deixi els camps amb els valors proposats per defecte. -; WARNING !!! STRINGS HERE MUST BE LOWER THAN 60 CHARACTERS +; WARNING !!! STRINGS HERE MUST BE LOWER THAN 70 CHARACTERS SMTPServer=Servidor SMTP (El seu o el del seu ISP, únicament primera instal.lació) : ApachePort=Puerto Apache (únicament primera instal.lació, normalment és el 80) : MySqlPort=Puerto Mysql (únicament primera instal.lació, normalment és el 3306) : @@ -31,6 +31,7 @@ FailedToDeleteLock=FailedToDeleteLock=Error en l'eliminaci PortAlreadyInUse=Sembla que el port %1 ja està sent utilitzat. Es recomana cancel·lar, tornar enrere i especificar un altre valor per al port% 2. Cancel·lar i escollir un altre valor? FirefoxDetected=S'ha detectat Firefox al seu ordinador. Voleu activar per defecte com a navegador per Dolibarr? +ChromeDetected=S'ha detectat Chrome al seu ordinador. Voleu activar per defecte com a navegador per Dolibarr? ChooseDefaultBrowser=Esculli el seu navegador per defecte. Si no està segur, simplement feu clic a Obrir: LaunchNow=Llançar ara Dolibarr diff --git a/build/exe/doliwamp/Languages/MyEnglish.isl b/build/exe/doliwamp/Languages/MyEnglish.isl index ed85010db1b..6e70f3c12f3 100644 --- a/build/exe/doliwamp/Languages/MyEnglish.isl +++ b/build/exe/doliwamp/Languages/MyEnglish.isl @@ -31,6 +31,7 @@ FailedToDeleteLock=Failed to delete the file %1/www/dolibarr/install.lock. You c PortAlreadyInUse=Port %1 seems to be already in use. You should cancel to go back and choose another value for %2 port. Cancel choice and choose another value ? FirefoxDetected=Firefox has been detected on your computer. Would you like to use it as the default browser for Dolibarr ? +ChromeDetected=Chrome has been detected on your computer. Would you like to use it as the default browser for Dolibarr ? ChooseDefaultBrowser=Please choose your default browser. If you are not sure, just click Open : LaunchNow=Launch Dolibarr now diff --git a/build/exe/doliwamp/Languages/MyFrench.isl b/build/exe/doliwamp/Languages/MyFrench.isl index 6c1b859a318..1daf4425e68 100644 --- a/build/exe/doliwamp/Languages/MyFrench.isl +++ b/build/exe/doliwamp/Languages/MyFrench.isl @@ -32,6 +32,7 @@ FailedToDeleteLock=Echec de la suppression du fichier %1/www/dolibarr/install.lo PortAlreadyInUse=Le port %1 semble déjà utilisé. Il est recommandé d'annuler pour revenir en arrière et spécifier une autre valeur pour le port %2. Annuler le choix et choisir une autre valeur ? FirefoxDetected=Firefox a été détecté sur votre ordinateur. Voulez-vous en faire votre navigateur par défaut pour Dolibarr ? +ChromeDetected=Chrome a été détecté sur votre ordinateur. Voulez-vous en faire votre navigateur par défaut pour Dolibarr ? ChooseDefaultBrowser=Merci de choisir votre navigateur par défaut. Si vous n'êtes pas sûr, cliquez simplement sur Ouvrir : LaunchNow=Lancer Dolibarr maintenant diff --git a/build/exe/doliwamp/Languages/MySpanish.isl b/build/exe/doliwamp/Languages/MySpanish.isl index 24a0c981e09..63c0136f351 100644 --- a/build/exe/doliwamp/Languages/MySpanish.isl +++ b/build/exe/doliwamp/Languages/MySpanish.isl @@ -20,7 +20,7 @@ DoYouWantToStart= TechnicalParameters=Parámetros técnicos IfFirstInstall=Si se trata de la primera instalación, deberá especificar algunos parámetros técnicos. Si no los entiende, no está seguro o va a proceder a una actualización, deje los campos con los valores propuestos por defecto. -; WARNING !!! STRINGS HERE MUST BE LOWER THAN 60 CHARACTERS +; WARNING !!! STRINGS HERE MUST BE LOWER THAN 70 CHARACTERS SMTPServer=Servidor SMTP (El suyo o el de su ISP, únicamente primera instalación) : ApachePort=Puerto Apache (únicamente primera instalación, normalmente es el 80) : MySqlPort=Puerto Mysql (únicamente primera instalación, normalmente es el 3306) : @@ -31,6 +31,7 @@ FailedToDeleteLock=Error en la eliminaci PortAlreadyInUse=Parece que el puerto %1 ya esta siendo usado. Se recomienda cancelar, volver atras y especificar otro valor para el puerto %2. ¿Cancelar y escojer otro valor? FirefoxDetected=Se ha detectado Firefox en su ordenador. Desea activarlo por defecto como navegador para Dolibarr ? +ChromeDetected=Se ha detectado Chrome en su ordenador. Desea activarlo por defecto como navegador para Dolibarr ? ChooseDefaultBrowser=Escoja su navegador por defecto. Si no está seguro, simplementa haga clic en Abrir : LaunchNow=Lanzar ahora Dolibarr diff --git a/build/exe/doliwamp/doliwamp.iss b/build/exe/doliwamp/doliwamp.iss index dfe7febf2db..242f7ac30ef 100644 --- a/build/exe/doliwamp/doliwamp.iss +++ b/build/exe/doliwamp/doliwamp.iss @@ -540,13 +540,29 @@ begin begin //navigateur browser := 'iexplore.exe'; - if FileExists (pfPath+'/Mozilla Firefox/firefox.exe') then + + if browser = 'iexplore.exe' then begin - if MsgBox(CustomMessage('FirefoxDetected'),mbConfirmation,MB_YESNO) = IDYES then + if FileExists (pfPath+'/Google/Chrome/Application/chrome.exe') then begin - browser := pfPath+'/Mozilla Firefox/firefox.exe'; + if MsgBox(CustomMessage('ChromeDetected'),mbConfirmation,MB_YESNO) = IDYES then + begin + browser := pfPath+'/Google/Chrome/Application/chrome.exe'; + end; end; end; + + if browser = 'iexplore.exe' then + begin + if FileExists (pfPath+'/Mozilla Firefox/firefox.exe') then + begin + if MsgBox(CustomMessage('FirefoxDetected'),mbConfirmation,MB_YESNO) = IDYES then + begin + browser := pfPath+'/Mozilla Firefox/firefox.exe'; + end; + end; + end; + if browser = 'iexplore.exe' then begin if FileExists (pfPath+'/Internet Explorer/iexplore.exe') then @@ -611,14 +627,28 @@ begin destFile := pathWithSlashes+'/alias/dolibarr.conf'; srcFile := pathWithSlashes+'/alias/dolibarr.conf.install'; - if not FileExists (destFile) and FileExists(srcFile) then + if FileExists(srcFile) then begin - LoadStringFromFile (srcFile, srcContents); + if not FileExists (destFile) then + begin + LoadStringFromFile (srcFile, srcContents); - StringChangeEx (srcContents, 'WAMPROOT', pathWithSlashes, True); - StringChangeEx (srcContents, 'WAMPMYSQLNEWPASSWORD', mypass, True); + StringChangeEx (srcContents, 'WAMPROOT', pathWithSlashes, True); + StringChangeEx (srcContents, 'WAMPMYSQLNEWPASSWORD', mypass, True); - SaveStringToFile(destFile, srcContents, False); + SaveStringToFile(destFile, srcContents, False); + end + else + begin + // We must replace to use format 2.4 of apache + DeleteFile(destFile); + LoadStringFromFile (srcFile, srcContents); + + StringChangeEx (srcContents, 'WAMPROOT', pathWithSlashes, True); + StringChangeEx (srcContents, 'WAMPMYSQLNEWPASSWORD', mypass, True); + + SaveStringToFile(destFile, srcContents, False); + end end DeleteFile(srcFile); @@ -632,13 +662,24 @@ begin destFile := pathWithSlashes+'/apps/phpmyadmin'+phpmyadminVersion+'/config.inc.php'; srcFile := pathWithSlashes+'/apps/phpmyadmin'+phpmyadminVersion+'/config.inc.php.install'; - if not FileExists (destFile) and FileExists (srcFile) then + if FileExists(srcFile) then begin - // sinon on prends le fichier par defaut - LoadStringFromFile (srcFile, srcContents); - StringChangeEx (srcContents, 'WAMPMYSQLNEWPASSWORD', mypass, True); - StringChangeEx (srcContents, 'WAMPMYSQLPORT', myport, True); - SaveStringToFile(destFile,srcContents, False); + if not FileExists (destFile) then + begin + LoadStringFromFile (srcFile, srcContents); + StringChangeEx (srcContents, 'WAMPMYSQLNEWPASSWORD', mypass, True); + StringChangeEx (srcContents, 'WAMPMYSQLPORT', myport, True); + SaveStringToFile(destFile,srcContents, False); + end + else + begin + // We must replace to use format 2.4 of apache + DeleteFile(destFile); + LoadStringFromFile (srcFile, srcContents); + StringChangeEx (srcContents, 'WAMPMYSQLNEWPASSWORD', mypass, True); + StringChangeEx (srcContents, 'WAMPMYSQLPORT', myport, True); + SaveStringToFile(destFile,srcContents, False); + end end diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index b6c86a7a119..ab33706e868 100755 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -173,6 +173,7 @@ $build =~ s/-.*$//g; # now build is 0+nmu1 for example $FILENAMEDEBNATIVE="${PROJECT}_${MAJOR}.${MINOR}.${build}"; $FILENAMEDEB="${PROJECT}_${MAJOR}.${MINOR}.${newbuild}"; +$FILENAMEDEBSHORT="${PROJECT}_${MAJOR}.${MINOR}.${build}"; my $copyalreadydone=0; @@ -389,10 +390,15 @@ if ($nboftargetok) { { print 'Run git tag -a -f -m "'.$MAJOR.'.'.$MINOR.'.'.$BUILD.'" "'.$MAJOR.'.'.$MINOR.'.'.$BUILD.'"'."\n"; $ret=`git tag -a -f -m "$MAJOR.$MINOR.$BUILD" "$MAJOR.$MINOR.$BUILD"`; + print 'Run git push -f --tags'."\n"; + $ret=`git push -f --tags`; } } - print 'Run git push --tags'."\n"; - $ret=`git push --tags`; + else + { + print 'Run git push --tags'."\n"; + $ret=`git push --tags`; + } chdir("$olddir"); } @@ -824,7 +830,7 @@ if ($nboftargetok) { $ret=`$cmd`; print "Remove other files\n"; - $ret=`rm -f $BUILDROOT/$PROJECT.tmp/README-FR`; + $ret=`rm -f $BUILDROOT/$PROJECT.tmp/README-FR.md`; $ret=`rm -f $BUILDROOT/$PROJECT.tmp/build/README`; $ret=`rm -f $BUILDROOT/$PROJECT.tmp/build/README-FR`; $ret=`rm -fr $BUILDROOT/$PROJECT.tmp/build/aps`; @@ -1127,6 +1133,7 @@ if ($nboftargetok) { %filestoscansf=( "$DESTI/package_rpm_generic/$FILENAMERPM"=>'Dolibarr installer for Fedora-Redhat-Mandriva-Opensuse (DoliRpm)', "$DESTI/package_debian-ubuntu/${FILENAMEDEB}_all.deb"=>'Dolibarr installer for Debian-Ubuntu (DoliDeb)', + "$DESTI/package_debian-ubuntu/${FILENAMEDEBSHORT}.orig.tar.gz"=>'none', "$DESTI/package_windows/$FILENAMEEXEDOLIWAMP.exe"=>'Dolibarr installer for Windows (DoliWamp)', "$DESTI/standard/$FILENAMETGZ.tgz"=>'Dolibarr ERP-CRM', "$DESTI/standard/$FILENAMETGZ.zip"=>'Dolibarr ERP-CRM' @@ -1134,6 +1141,7 @@ if ($nboftargetok) { %filestoscanstableasso=( "$DESTI/package_rpm_generic/$FILENAMERPM"=>'package_rpm_generic', "$DESTI/package_debian-ubuntu/${FILENAMEDEB}_all.deb"=>'package_debian-ubuntu', + "$DESTI/package_debian-ubuntu/${FILENAMEDEBSHORT}.orig.tar.gz"=>'package_debian-ubuntu', "$DESTI/package_windows/$FILENAMEEXEDOLIWAMP.exe"=>'package_windows', "$DESTI/standard/$FILENAMETGZ.tgz"=>'standard', "$DESTI/standard/$FILENAMETGZ.zip"=>'standard' @@ -1195,7 +1203,7 @@ if ($nboftargetok) { print "\n"; - if ($target eq 'SF') { + if ($target eq 'SF' && $filestoscan{$file} ne 'none') { $destFolder="$NEWPUBLISH/$filestoscan{$file}/".$MAJOR.'.'.$MINOR.'.'.$BUILD; } elsif ($target eq 'ASSO' and $NEWPUBLISH =~ /stable/) { diff --git a/dev/initdata/generate-invoice.php b/dev/initdata/generate-invoice.php index e7c274040de..716060f0379 100755 --- a/dev/initdata/generate-invoice.php +++ b/dev/initdata/generate-invoice.php @@ -31,8 +31,8 @@ if (substr($sapi_type, 0, 3) == 'cgi') { } // Recupere root dolibarr -$path=preg_replace('/generate-facture.php/i','',$_SERVER["PHP_SELF"]); -require ($path."../../htdocs/master.inc.php"); +//$path=preg_replace('/generate-produit.php/i','',$_SERVER["PHP_SELF"]); +require (__DIR__. '/../../htdocs/master.inc.php'); require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/societe/class/societe.class.php"); diff --git a/dev/initdata/generate-order.php b/dev/initdata/generate-order.php index 9e96bbd781b..0bba1c5af5b 100755 --- a/dev/initdata/generate-order.php +++ b/dev/initdata/generate-order.php @@ -32,8 +32,8 @@ if (substr($sapi_type, 0, 3) == 'cgi') { } // Recupere root dolibarr -$path=preg_replace('/generate-commande.php/i','',$_SERVER["PHP_SELF"]); -require ($path."../../htdocs/master.inc.php"); +//$path=preg_replace('/generate-commande.php/i','',$_SERVER["PHP_SELF"]); +require (__DIR__. '/../../htdocs/master.inc.php'); include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; diff --git a/dev/initdata/generate-product.php b/dev/initdata/generate-product.php index fbdde96f95a..3ae44b00b3a 100755 --- a/dev/initdata/generate-product.php +++ b/dev/initdata/generate-product.php @@ -32,8 +32,8 @@ if (substr($sapi_type, 0, 3) == 'cgi') { } // Recupere root dolibarr -$path=preg_replace('/generate-produit.php/i','',$_SERVER["PHP_SELF"]); -require ($path."../../htdocs/master.inc.php"); +//$path=preg_replace('/generate-produit.php/i','',$_SERVER["PHP_SELF"]); +require (__DIR__. '/../../htdocs/master.inc.php'); include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; diff --git a/dev/initdata/generate-proposal.php b/dev/initdata/generate-proposal.php index 071efc0298f..713f1ca4069 100755 --- a/dev/initdata/generate-proposal.php +++ b/dev/initdata/generate-proposal.php @@ -32,8 +32,8 @@ if (substr($sapi_type, 0, 3) == 'cgi') { } // Recupere root dolibarr -$path=preg_replace('/generate-propale.php/i','',$_SERVER["PHP_SELF"]); -require ($path."../../htdocs/master.inc.php"); +//$path=preg_replace('/generate-propale.php/i','',$_SERVER["PHP_SELF"]); +require (__DIR__. '/../../htdocs/master.inc.php'); require_once(DOL_DOCUMENT_ROOT."/compta/facture/class/facture.class.php"); require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/commande/class/commande.class.php"); diff --git a/dev/initdata/generate-thirdparty.php b/dev/initdata/generate-thirdparty.php index 8c3a6e3e86e..992ab61f4ef 100755 --- a/dev/initdata/generate-thirdparty.php +++ b/dev/initdata/generate-thirdparty.php @@ -32,8 +32,8 @@ if (substr($sapi_type, 0, 3) == 'cgi') { } // Recupere root dolibarr -$path=preg_replace('/generate-societe.php/i','',$_SERVER["PHP_SELF"]); -require ($path."../../htdocs/master.inc.php"); +//$path=preg_replace('/generate-societe.php/i','',$_SERVER["PHP_SELF"]); +require (__DIR__. '/../../htdocs/master.inc.php'); include_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; diff --git a/dev/initdata/import-products.php b/dev/initdata/import-products.php index 3c467fbfff5..a08e3b6066e 100755 --- a/dev/initdata/import-products.php +++ b/dev/initdata/import-products.php @@ -1,6 +1,7 @@ #!/usr/bin/env php + * Copyright (C) 2016 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 @@ -56,7 +57,7 @@ $error=0; @set_time_limit(0); print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; -dol_syslog($script_file." launched with arg ".join(',',$argv)); +dol_syslog($script_file." launched with arg ".implode(',',$argv)); $mode = $argv[1]; $filepath = $argv[2]; diff --git a/dev/initdata/import-thirdparties.php b/dev/initdata/import-thirdparties.php index 199807473f8..08ad248ecc0 100755 --- a/dev/initdata/import-thirdparties.php +++ b/dev/initdata/import-thirdparties.php @@ -1,6 +1,7 @@ #!/usr/bin/env php + * Copyright (C) 2016 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 @@ -56,7 +57,7 @@ $error=0; @set_time_limit(0); print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; -dol_syslog($script_file." launched with arg ".join(',',$argv)); +dol_syslog($script_file." launched with arg ".implode(',',$argv)); $mode = $argv[1]; $filepath = $argv[2]; diff --git a/dev/initdata/import-users.php b/dev/initdata/import-users.php index 355f41e9886..3aaa9c11a4a 100755 --- a/dev/initdata/import-users.php +++ b/dev/initdata/import-users.php @@ -1,6 +1,7 @@ #!/usr/bin/env php + * Copyright (C) 2016 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 @@ -56,7 +57,7 @@ $error=0; @set_time_limit(0); print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; -dol_syslog($script_file." launched with arg ".join(',',$argv)); +dol_syslog($script_file." launched with arg ".implode(',',$argv)); $mode = $argv[1]; $filepath = $argv[2]; diff --git a/dev/initdata/purge-data.php b/dev/initdata/purge-data.php index 232ab1b5c41..f89a3ba2698 100755 --- a/dev/initdata/purge-data.php +++ b/dev/initdata/purge-data.php @@ -1,7 +1,7 @@ #!/usr/bin/env php - * + * Copyright (C) 2016 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 @@ -146,7 +146,7 @@ $sqls=array( @set_time_limit(0); print "***** ".$script_file." (".$version.") pid=".dol_getmypid()." *****\n"; -dol_syslog($script_file." launched with arg ".join(',',$argv)); +dol_syslog($script_file." launched with arg ".implode(',',$argv)); $mode = $argv[1]; $option = $argv[2]; @@ -154,14 +154,14 @@ $option = $argv[2]; if (empty($mode) || ! in_array($mode,array('test','confirm'))) { print "Usage: $script_file (test|confirm) (all|option)\n"; print "\n"; - print "option can be ".join(',',array_keys($sqls))."\n"; + print "option can be ".implode(',',array_keys($sqls))."\n"; exit(-1); } if (empty($option) || ! in_array($option, array_merge(array('all'),array_keys($sqls))) ) { print "Usage: $script_file (test|confirm) (all|option)\n"; print "\n"; - print "option can be ".join(',',array_keys($sqls))."\n"; + print "option can be ".implode(',',array_keys($sqls))."\n"; exit(-1); } diff --git a/dev/skeletons/skeleton_class.class.php b/dev/skeletons/skeleton_class.class.php index 2858e791ce8..080a2c5220e 100644 --- a/dev/skeletons/skeleton_class.class.php +++ b/dev/skeletons/skeleton_class.class.php @@ -1,6 +1,6 @@ - * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2014-2016 Juanjo Menent * Copyright (C) 2015 Florian Henry * Copyright (C) 2015 Raphaël Doursenaud * Copyright (C) ---Put here your own copyright and developer email--- @@ -116,7 +116,7 @@ class Skeleton_Class extends CommonObject if (!$resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); } if (!$error) { @@ -189,7 +189,7 @@ class Skeleton_Class extends CommonObject } } else { $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); return - 1; } @@ -256,7 +256,7 @@ class Skeleton_Class extends CommonObject return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); return - 1; } @@ -301,7 +301,7 @@ class Skeleton_Class extends CommonObject if (!$resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); } if (!$error && !$notrigger) { @@ -362,7 +362,7 @@ class Skeleton_Class extends CommonObject if (!$resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); } } @@ -410,7 +410,7 @@ class Skeleton_Class extends CommonObject if ($result < 0) { $error ++; $this->errors = $object->errors; - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); } // End diff --git a/dev/skeletons/skeleton_list.php b/dev/skeletons/skeleton_list.php index f1413bb3712..4a2e26856dc 100644 --- a/dev/skeletons/skeleton_list.php +++ b/dev/skeletons/skeleton_list.php @@ -1,6 +1,6 @@ - * Copyright (C) ---Put here your own copyright and developer email--- + * Copyright (C) 2014-2016 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 @@ -292,7 +292,7 @@ if ($resql) if ($sall) { foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); - print $langs->trans("FilterOnInto", $all) . join(', ',$fieldstosearchall); + print $langs->trans("FilterOnInto", $all) . implode(', ',$fieldstosearchall); } $moreforfilter = ''; diff --git a/dev/translation/autotranslator.class.php b/dev/translation/autotranslator.class.php index 584d3971b3f..47d6a25ec15 100644 --- a/dev/translation/autotranslator.class.php +++ b/dev/translation/autotranslator.class.php @@ -300,7 +300,7 @@ class autoTranslator //setting language pair $lang_pair = $src_lang.'|'.$dest_lang; - $src_text_to_translate=preg_replace('/%s/','SSSSS',join('',$src_texts)); + $src_text_to_translate=preg_replace('/%s/','SSSSS',implode('',$src_texts)); $src_text_to_translate=preg_replace('/'.preg_quote('\n\n').'/',' NNNNN ',$src_text_to_translate); // Define GET URL v1 diff --git a/dev/translation/sanity_check_en_langfiles.php b/dev/translation/sanity_check_en_langfiles.php index 6d63c415981..e4fdbf47c43 100755 --- a/dev/translation/sanity_check_en_langfiles.php +++ b/dev/translation/sanity_check_en_langfiles.php @@ -1,7 +1,8 @@ #!/usr/bin/env php - * Copyright (c) 2015 Laurent Destailleur +/* Copyright (c) 2015 Tommaso Basilici + * Copyright (c) 2015 Laurent Destailleur + * Copyright (C) 2014-2016 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 @@ -293,6 +294,10 @@ if ((! empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($a if (preg_match('/^Language_/', $value)) $qualifiedforclean=0; if (preg_match('/^DescADHERENT_/', $value)) $qualifiedforclean=0; if (preg_match('/^SubmitTranslation/', $value)) $qualifiedforclean=0; + if (preg_match('/^ModuleCompanyCode/', $value)) $qualifiedforclean=0; + // boxes.lang + if (preg_match('/^BoxTitleLast/', $value)) $qualifiedforclean=0; + if (preg_match('/^BoxTitleLatest/', $value)) $qualifiedforclean=0; // main.lang if (preg_match('/^Duration/', $value)) $qualifiedforclean=0; if (preg_match('/^FormatDate/', $value)) $qualifiedforclean=0; @@ -357,7 +362,7 @@ if ((! empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($a { $filetosave='/tmp/'.($argv[2]?$argv[2]:"").'notused.lang'; print "Strings in en_US that are never used are saved into file ".$filetosave.":\n"; - file_put_contents($filetosave, join("",$unused)); + file_put_contents($filetosave, implode("",$unused)); print "To remove from original file, run command :\n"; if (($argv[2]?$argv[2]:"")) print 'cd htdocs/langs/en_US; mv '.($argv[2]?$argv[2]:"")." ".($argv[2]?$argv[2]:"").".tmp; "; print "diff ".($argv[2]?$argv[2]:"").".tmp ".$filetosave." | grep \< | cut -b 3- > ".($argv[2]?$argv[2]:""); diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 736aec48644..736581e9248 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -23,6 +23,7 @@ * \ingroup Advanced accountancy * \brief Balance of book keeping */ + require '../../main.inc.php'; // Class @@ -184,7 +185,7 @@ else { print_liste_field_titre($langs->trans("Labelcompte"), $_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, "", 'width="60" align="center"', $sortfield, $sortorder); + print_liste_field_titre($langs->trans("Solde"), $_SERVER["PHP_SELF"], "", $options, "", 'align="right"', $sortfield, $sortorder); print_liste_field_titre($langs->trans("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); print "\n"; @@ -213,6 +214,9 @@ else { $total_debit = 0; $total_credit = 0; + $sous_total_debit = 0; + $sous_total_credit = 0; + $displayed_account = ""; foreach ( $object->lines as $line ) { $var = ! $var; @@ -220,33 +224,59 @@ else { $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 ''.$langs->trans("SubTotal") . ':'.price($sous_total_debit).''.price($sous_total_credit).''.price($sous_total_credit-$sous_total_debit).''; + print " \n"; + print ''; + } + + // Affiche le compte comptable en début de ligne + print ""; + print ''. $root_account_description .''; + print ''; + + $displayed_account = $root_account_description; + $sous_total_debit = 0; + $sous_total_credit = 0; + } + + // $object->get_compte_racine($line->numero_compte); + + print '' . length_accountg($line->numero_compte) . ''; print '' . $description . ''; print '' . number_format($line->debit, 2, ',', ' ') . ''; - print '' . number_format($line->credit, 2, ',', ' ') . ''; - print '' . number_format($line->credit - $line->debit, 2, ',', ' ') . ''; + print '' . number_format($line->credit, 2, ',', ' ') . ''; + print '' . number_format($line->credit - $line->debit, 2, ',', ' ') . ''; print '' . $link; print ''; print "\n"; + + // Comptabilise le sous-total + $sous_total_debit += $line->debit; + $sous_total_credit += $line->credit; + } - print ''; - print ''; - print ''; - print ''; - print price($total_debit); - print ''; - print ''; - print price($total_credit); - print ''; - print '' . price($total_credit - $total_debit) . ''; - print ''; - print ''; + print ''.$langs->trans("SubTotal") . ':'.price($sous_total_debit).''.price($sous_total_credit).''.price($sous_total_credit-$sous_total_debit).''; + print " \n"; + print ''; + + print ''.$langs->trans("AccountBalance") . ':'.price($total_debit).''.price($total_credit).''.price($total_credit-$total_debit).''; + print " \n"; + print ''; + print ""; print ''; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 23148213aa0..5eafa920973 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -258,7 +258,6 @@ if ($action == 'export_csv') { */ $title_page = $langs->trans("Bookkeeping") . ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end); - llxHeader('', $title_page); // List @@ -315,6 +314,7 @@ print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield print '
'; print '
' . "\n"; +print ''; print '
'; print ''; print '
'; diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php new file mode 100644 index 00000000000..ce62655465d --- /dev/null +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -0,0 +1,348 @@ + + * 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 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +/** + * \file htdocs/accountancy/bookkeeping/listbyaccount.php + * \ingroup Advanced accountancy + * \brief List operation of book keeping ordered by account number + */ + +require '../../main.inc.php'; + +// Class +require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/bookkeeping.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; + +// Langs +$langs->load("accountancy"); + +$page = GETPOST("page"); +$sortorder = GETPOST("sortorder"); +$sortfield = GETPOST("sortfield"); +$action = GETPOST('action', 'alpha'); +$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_date = dol_mktime(0, 0, 0, GETPOST('doc_datemonth', 'int'), GETPOST('doc_dateday', 'int'), GETPOST('doc_dateyear', 'int')); + + + +$search_accountancy_code = GETPOST("search_accountancy_code"); + +$search_accountancy_code_start = GETPOST('search_accountancy_code_start', 'alpha'); +if ($search_accountancy_code_start == - 1) { + $search_accountancy_code_start = ''; +} +$search_label_account = GETPOST('search_label_account', 'alpha'); + +$search_mvt_label = GETPOST('search_mvt_label', 'alpha'); +$search_direction = GETPOST('search_direction', 'alpha'); +$search_ledger_code = GETPOST('search_ledger_code', 'alpha'); + +$limit = GETPOST('limit') ? GETPOST('limit', 'int') : $conf->liste_limit; +if ($page == -1) { $page = 0 ; } +$offset = $limit * $page ; +$pageprev = $page - 1; +$pagenext = $page + 1; + +$object = new BookKeeping($db); + +$formventilation = new FormVentilation($db); +$formother = new FormOther($db); +$form = new Form($db); + + + + +if (empty($search_date_start)) { + $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')); +} +if ($sortorder == "") + $sortorder = "ASC"; +if ($sortfield == "") + $sortfield = "t.rowid"; + + +$options = ''; +$filter = array (); + +if (! empty($search_date_start)) { + $filter['t.doc_date>='] = $search_date_start; + $options .= '&date_startmonth=' . GETPOST('date_startmonth', 'int') . '&date_startday=' . GETPOST('date_startday', 'int') . '&date_startyear=' . GETPOST('date_startyear', 'int'); +} +if (! empty($search_date_end)) { + $filter['t.doc_date<='] = $search_date_end; + $options .= '&date_endmonth=' . GETPOST('date_endmonth', 'int') . '&date_endday=' . GETPOST('date_endday', 'int') . '&date_endyear=' . GETPOST('date_endyear', 'int'); +} +if (! empty($search_doc_date)) { + $filter['t.doc_date'] = $search_doc_date; + $options .= '&doc_datemonth=' . GETPOST('doc_datemonth', 'int') . '&doc_dateday=' . GETPOST('doc_dateday', 'int') . '&doc_dateyear=' . GETPOST('doc_dateyear', 'int'); +} + + +if (!GETPOST("button_removefilter_x") && !GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + if (! empty($search_accountancy_code_start)) { + $filter['t.numero_compte'] = $search_accountancy_code_start; + $options .= '&search_accountancy_code_start=' . $search_accountancy_code_start; + } + if (! empty($search_label_account)) { + $filter['t.label_compte'] = $search_label_account; + $options .= '&search_label_account=' . $search_label_account; + } + if (! empty($search_mvt_label)) { + $filter['t.label_compte'] = $search_mvt_label; + $options .= '&search_mvt_label=' . $search_mvt_label; + } + if (! empty($search_direction)) { + $filter['t.sens'] = $search_direction; + $options .= '&search_direction=' . $search_direction; + } + if (! empty($search_ledger_code)) { + $filter['t.code_journal'] = $search_ledger_code; + $options .= '&search_ledger_code=' . $search_ledger_code; + } +} + +/* + * Action + */ + +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + $search_doc_date = ''; + $search_accountancy_code = ''; + $search_accountancy_code_start = ''; + $search_label_account = ''; + $search_mvt_label = ''; + $search_direction = ''; + $search_ledger_code = ''; +} + +if ($action == 'delmouvconfirm') { + + $mvt_num = GETPOST('mvt_num', 'int'); + + if (! empty($mvt_num)) { + $result = $object->deleteMvtNum($mvt_num); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } + Header("Location: listbyaccount.php"); + exit(); + } +} + + +/* + * View + */ + +$title_page = $langs->trans("Bookkeeping") . ' ' . strtolower($langs->trans("By")) . ' ' . $langs->trans("AccountAccounting") . ' ' . dol_print_date($search_date_start) . '-' . dol_print_date($search_date_end); + +llxHeader('', $title_page); + +// List + +$nbtotalofrecords = 0; +if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { + $nbtotalofrecords = $object->fetchAllByAccount($sortorder, $sortfield, 0, 0, $filter); + if ($nbtotalofrecords < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + +$result = $object->fetchAllByAccount($sortorder, $sortfield, $limit, $offset, $filter); +if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); +} +$nbtotalofrecords = $result; + +if ($action == 'delmouv') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?mvt_num=' . GETPOST('mvt_num'), $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delmouvconfirm', '', 0, 1); + print $formconfirm; +} +if ($action == 'delbookkeepingyear') { + + $form_question = array (); + $delyear = GETPOST('delyear'); + + if (empty($delyear)) { + $delyear = dol_print_date(dol_now(), '%Y'); + } + $year_array = $formventilation->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array'); + + $form_question['delyear'] = array ( + 'name' => 'delyear', + 'type' => 'select', + 'label' => $langs->trans('DelYear'), + 'values' => $year_array, + 'default' => $delyear + ); + + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delbookkeepingyearconfirm', $form_question, 0, 1); + print $formconfirm; +} + + + + +print ''; + +print_barre_liste($title_page, $page, $_SERVER["PHP_SELF"], $options, $sortfield, $sortorder, '', $result, $nbtotalofrecords,'',0,'','',$limit); + +// Reverse sort order +if ( preg_match('/^asc/i', $sortorder) ) + $sortorder = "asc"; +else + $sortorder = "desc"; + +print '
' . "\n"; +print ''; +print '
'; + +print ''; +print ''; +print ''; +print_liste_field_titre($langs->trans("Docdate"), $_SERVER['PHP_SELF'], "t.doc_date", "", $options, "", $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Docref"), $_SERVER['PHP_SELF'], "t.doc_ref", "", $options, "", $sortfield, $sortorder); +print ''; +print_liste_field_titre($langs->trans("Debit"), $_SERVER['PHP_SELF'], "t.debit", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Credit"), $_SERVER['PHP_SELF'], "t.credit", "", $options, 'align="right"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Codejournal"), $_SERVER['PHP_SELF'], "t.code_journal", "", $options, 'align="center"', $sortfield, $sortorder); +print_liste_field_titre($langs->trans("Action"), $_SERVER["PHP_SELF"], "", $options, "", 'width="60" align="center"', $sortfield, $sortorder); +print "\n"; + +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print ''; + +$var = True; + +$total_debit = 0; +$total_credit = 0; +$sous_total_debit = 0; +$sous_total_credit = 0; +$displayed_account_number = ""; + +foreach ( $object->lines as $line ) { + $var = ! $var; + + $total_debit += $line->debit; + $total_credit += $line->credit; + + // Permet d'afficher le compte comptable + if (length_accountg($line->numero_compte) != $displayed_account_number) { + + // Affiche un Sous-Total par compte comptable + if ($displayed_account_number != "") { + print ''; + print "\n"; + print ''; + } + + // Affiche le compte comptable en début de ligne + print ""; + print ''; + print ''; + + $displayed_account_number = length_accountg($line->numero_compte); + $sous_total_debit = 0; + $sous_total_credit = 0; + } + + print ''; + print ''; + print ''; + print ''; + + // Affiche un lien vers la facture client/fournisseur + $doc_ref = preg_replace('/\(.*\)/', '', $line->doc_ref); + if ($line->doc_type == 'supplier_invoice') + print strlen(length_accounta($line->code_tiers)) == 0 ? '' : ''; + elseif ($line->doc_type == 'customer_invoice') + print strlen(length_accounta($line->code_tiers)) == 0 ? '' : ''; + else + print strlen(length_accounta($line->code_tiers)) == 0 ? '' : ''; + + + print ''; + print ''; + print ''; + print ''; + print "\n"; + + // Comptabilise le sous-total + $sous_total_debit += $line->debit; + $sous_total_credit += $line->credit; + +} + +// Affiche un Sous-Total du dernier compte comptable affiché +print ''; +print "\n"; +print ''; + + +// Affiche le Total +print ''; +print ''; +print ''; +print ''; +print ''; +print ''; + +print "
' . $langs->trans("AccountAccounting") . '' . $langs->trans("SuppliersInvoices") . ' / ' . $langs->trans("CustomersInvoices") . '
' . $object->select_account($search_accountancy_code_start, 'search_accountancy_code_start', 1, array (), 1, 1, '') . ''; +print $langs->trans('From') . ': '; +print $form->select_date($search_date_start, 'date_start', 0, 0, 1); +print '
'; +print $langs->trans('to') . ': '; +print $form->select_date($search_date_end, 'date_end', 0, 0, 1); +print '
  '; +$searchpitco=$form->showFilterAndCheckAddButtons(0); +print $searchpitco; +print '
'.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).' 
'.length_accountg($line->numero_compte) . ' : ' . $object->get_compte_desc($line->numero_compte).'
 ' . dol_print_date($line->doc_date, 'day') . '' . $line->doc_ref . '' . $line->label_compte . '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')
' . $line->label_compte . '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')
' . $line->label_compte . '' . $line->label_compte . '
(' . length_accounta($line->code_tiers) . ')
' . price($line->debit) . '' . price($line->credit) . '' . $line->code_journal . ''; + print '' . img_edit() . ' '; + print '' . img_delete() . ''; + print '
'.$langs->trans("SubTotal").':'.price($sous_total_debit).''.price($sous_total_credit).' 
'.$langs->trans("Total").':'; +print price($total_debit); +print ''; +print price($total_credit); +print '
"; +print ''; + +llxFooter(); + + +$db->close(); diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 79e66ab7cce..5832d44cd52 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -53,14 +53,14 @@ 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'; + /** * * @var BookKeepingLine[] Lines */ public $lines = array (); - + /** * * @var int ID @@ -84,10 +84,10 @@ class BookKeeping extends CommonObject public $import_key; public $code_journal; public $piece_num; - + /** */ - + /** * Constructor * @@ -97,24 +97,22 @@ class BookKeeping extends CommonObject $this->db = $db; return 1; } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function create(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - - global $langs; - + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -160,32 +158,32 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + $this->db->begin(); - + $this->piece_num = 0; - + // first check if line not yet in bookkeeping $sql = "SELECT count(*) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - $sql .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; + $sql .= " WHERE doc_type = '" . $this->doc_type . "'"; $sql .= " AND fk_docdet = " . $this->fk_docdet; - $sql .= " AND numero_compte = '" . $this->db->escape($this->numero_compte) . "'"; - - dol_syslog(get_class($this) . ":: create ", LOG_DEBUG); + $sql .= " AND numero_compte = '" . $this->numero_compte . "'"; + + dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); - + if ($resql) { $row = $this->db->fetch_object($resql); if ($row->nb == 0) { - + // Determine piece_num $sqlnum = "SELECT piece_num"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'"; $sqlnum .= " AND fk_docdet = '" . $this->fk_docdet . "'"; $sqlnum .= " AND doc_ref = '" . $this->doc_ref . "'"; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -196,7 +194,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; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -204,19 +202,18 @@ class BookKeeping extends CommonObject $this->piece_num = $objnum->maxpiecenum; } } + dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); if (empty($this->piece_num)) { $this->piece_num = 1; } - - dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); - + $now = dol_now(); if (empty($this->date_create)) { $this->date_create = $now; } - + $sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " ("; - + $sql .= "doc_date"; $sql .= ", doc_type"; $sql .= ", doc_ref"; @@ -233,33 +230,33 @@ class BookKeeping extends CommonObject $sql .= ", import_key"; $sql .= ", code_journal"; $sql .= ", piece_num"; - + $sql .= ") VALUES ("; - - $sql .= "'" . $this->db->idate($this->doc_date) . "'"; - $sql .= ",'" . $this->db->escape($this->doc_type) . "'"; - $sql .= ",'" . $this->db->escape($this->doc_ref) . "'"; + + $sql .= "'" . $this->doc_date . "'"; + $sql .= ",'" . $this->doc_type . "'"; + $sql .= ",'" . $this->doc_ref . "'"; $sql .= "," . $this->fk_doc; $sql .= "," . $this->fk_docdet; - $sql .= ",'" . $this->db->escape($this->code_tiers) . "'"; - $sql .= ",'" . $this->db->escape($this->numero_compte) . "'"; + $sql .= ",'" . $this->code_tiers . "'"; + $sql .= ",'" . $this->numero_compte . "'"; $sql .= ",'" . $this->db->escape($this->label_compte) . "'"; $sql .= "," . $this->debit; $sql .= "," . $this->credit; $sql .= "," . $this->montant; - $sql .= ",'" . $this->db->escape($this->sens) . "'"; + $sql .= ",'" . $this->sens . "'"; $sql .= ",'" . $this->fk_user_author . "'"; $sql .= ",'" . $this->date_create . "'"; - $sql .= ",'" . $this->db->escape($this->code_journal) . "'"; + $sql .= ",'" . $this->code_journal . "'"; $sql .= "," . $this->piece_num; - + $sql .= ")"; - - dol_syslog(get_class($this) . ":: create", LOG_DEBUG); + + dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); $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; @@ -267,67 +264,67 @@ class BookKeeping extends CommonObject $result = - 2; $error ++; $this->errors[] = 'Error Create Error ' . $result . ' lecture ID'; - dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { $result = - 1; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { $result = - 3; $error ++; - $this->errors[] = $langs->trans('BookeppingLineAlreayExists'); - dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } else { $result = - 5; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' $result='.$result.' '. implode(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + 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++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $result; } } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function createStd(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -373,13 +370,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add control on parameters values - + // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - + $sql .= 'doc_date,'; $sql .= 'doc_type,'; $sql .= 'doc_ref,'; @@ -396,9 +393,9 @@ class BookKeeping extends CommonObject $sql .= 'import_key,'; $sql .= 'code_journal,'; $sql .= 'piece_num'; - + $sql .= ') VALUES ('; - + $sql .= ' ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->doc_date) . "'") . ','; $sql .= ' ' . (! isset($this->doc_type) ? 'NULL' : "'" . $this->db->escape($this->doc_type) . "'") . ','; $sql .= ' ' . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ','; @@ -415,58 +412,58 @@ class BookKeeping extends CommonObject $sql .= ' ' . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ','; $sql .= ' ' . (! isset($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; $sql .= ' ' . (! isset($this->piece_num) ? 'NULL' : $this->piece_num); - + $sql .= ')'; - + $this->db->begin(); - + $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->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_CREATE',$user); // if ($result < 0) $error++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $this->id; } } - + /** * Load object in memory from the database * * @param int $id Id object * @param string $ref Ref - * + * * @return int <0 if KO, 0 if not found, >0 if OK */ public function fetch($id, $ref = null) { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -483,22 +480,22 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; if (null !== $ref) { $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; } else { $sql .= ' WHERE t.rowid = ' . $id; } - + $resql = $this->db->query($sql); if ($resql) { $numrows = $this->db->num_rows($resql); if ($numrows) { $obj = $this->db->fetch_object($resql); - + $this->id = $obj->rowid; - + $this->doc_date = $this->db->jdate($obj->doc_date); $this->doc_type = $obj->doc_type; $this->doc_ref = $obj->doc_ref; @@ -517,7 +514,7 @@ class BookKeeping extends CommonObject $this->piece_num = $obj->piece_num; } $this->db->free($resql); - + if ($numrows) { return 1; } else { @@ -526,12 +523,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 @@ -540,15 +537,15 @@ 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') { + public function fetchAllByAccount($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -565,9 +562,9 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -582,33 +579,36 @@ class BookKeeping extends CommonObject $sqlwhere[] = $key . '=' . $value; } elseif ($key == 't.code_tiers' || $key == 't.numero_compte') { $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; - } else { + } elseif ($key == 't.label_compte') { + $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; + }else { $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - + // Affichage par compte comptable + $sql .= ' ORDER BY t.numero_compte ASC'; if (! empty($sortfield)) { - $sql .= $this->db->order($sortfield, $sortorder); + $sql .= ', ' . $sortfield . ' ' .$sortorder; } if (! empty($limit)) { $sql .= ' ' . $this->db->plimit($limit + 1, $offset); - } + } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -625,20 +625,21 @@ class BookKeeping extends CommonObject $line->import_key = $obj->import_key; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $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; } } - + + /** * Load object in memory from the database * @@ -648,20 +649,34 @@ 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 fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; + $sql .= ' t.rowid,'; + + $sql .= " t.doc_date,"; + $sql .= " t.doc_type,"; + $sql .= " t.doc_ref,"; + $sql .= " t.fk_doc,"; + $sql .= " t.fk_docdet,"; + $sql .= " t.code_tiers,"; $sql .= " t.numero_compte,"; - $sql .= " SUM(t.debit) as debit,"; - $sql .= " SUM(t.credit) as credit"; - - + $sql .= " t.label_compte,"; + $sql .= " t.debit,"; + $sql .= " t.credit,"; + $sql .= " t.montant,"; + $sql .= " t.sens,"; + $sql .= " t.fk_user_author,"; + $sql .= " t.import_key,"; + $sql .= " t.code_journal,"; + $sql .= " t.piece_num"; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -681,13 +696,11 @@ class BookKeeping extends CommonObject } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - - $sql .= ' GROUP BY t.numero_compte'; - + if (! empty($sortfield)) { $sql .= $this->db->order($sortfield, $sortorder); } @@ -695,45 +708,141 @@ class BookKeeping extends CommonObject $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + + $line->id = $obj->rowid; + + $line->doc_date = $this->db->jdate($obj->doc_date); + $line->doc_type = $obj->doc_type; + $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->numero_compte = $obj->numero_compte; + $line->label_compte = $obj->label_compte; + $line->debit = $obj->debit; + $line->credit = $obj->credit; + $line->montant = $obj->montant; + $line->sens = $obj->sens; + $line->fk_user_author = $obj->fk_user_author; + $line->import_key = $obj->import_key; + $line->code_journal = $obj->code_journal; + $line->piece_num = $obj->piece_num; + + $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; + } + } + + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * + * @return int <0 if KO, >0 if OK + */ + public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = 'SELECT'; + $sql .= " t.numero_compte,"; + $sql .= " SUM(t.debit) as debit,"; + $sql .= " SUM(t.credit) as credit"; + + + $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.doc_date') { + $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<=') { + $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') { + $sqlwhere[] = $key . ' LIKE \'' . $this->db->escape($value) . '%\''; + } else { + $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } + } + } + + if (count($sqlwhere) > 0) { + $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); + } + + $sql .= ' GROUP BY t.numero_compte'; + + if (! empty($sortfield)) { + $sql .= $this->db->order($sortfield, $sortorder); + } + if (! empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); + } + $this->lines = array (); + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + while ( $obj = $this->db->fetch_object($resql) ) { + $line = new BookKeepingLine(); + $line->numero_compte = $obj->numero_compte; $line->debit = $obj->debit; $line->credit = $obj->credit; $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; } } - + /** * Update object into database * * @param User $user User that modifies * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function update(User $user, $notrigger = false) { $error = 0; - + dol_syslog(__METHOD__, LOG_DEBUG); - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -779,13 +888,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add a control on parameters values - + // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' 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") . ','; @@ -802,71 +911,71 @@ class BookKeeping extends CommonObject $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 .= ' piece_num = ' . (isset($this->piece_num) ? $this->piece_num : "null"); - + $sql .= ' WHERE rowid=' . $this->id; - + $this->db->begin(); - + $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error && ! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_MODIFY',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete object in database * * @param User $user User that deletes * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function delete(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + $this->db->begin(); - + if (! $error) { if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_DELETE',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } } - + if (! $error) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; $sql .= ' WHERE rowid=' . $this->id; - + $resql = $this->db->query($sql); if (! $resql) { $error ++; @@ -874,19 +983,19 @@ class BookKeeping extends CommonObject dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete bookkepping by importkey * @@ -895,14 +1004,14 @@ class BookKeeping extends CommonObject */ function deleteByImportkey($importkey) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE import_key = '" . $importkey . "'"; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -912,11 +1021,11 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Delete bookkepping by year * @@ -925,14 +1034,14 @@ class BookKeeping extends CommonObject */ function deleteByYear($delyear) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE YEAR(doc_date) = " . $delyear; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -942,54 +1051,11 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - - /** - * Delete bookkepping by year - * - * @param string $delyear year to delete - * @param string $deljournal journal to delete - * @return int Result - */ - function deleteByYearAndJournal($delyear,$deljournal) { - $this->db->begin(); - - $sqlwhere=array(); - - // first check if line not yet in bookkeeping - $sql = "DELETE"; - $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - if (!empty($delyear)) { - $sqlwhere[] .= " YEAR(doc_date) = " . $delyear; - } - if (!empty($deljournal)) { - $sqlwhere[] .= " code_journal = '" . $this->db->escape($deljournal)."'"; - } - - if (count($sqlwhere)>0) { - $sql.=" WHERE ".implode(' AND ', $sqlwhere); - - $resql = $this->db->query($sql); - - if (! $resql) { - $this->errors[] = "Error " . $this->db->lasterror(); - foreach ( $this->errors as $errmsg ) { - dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); - $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); - } - $this->db->rollback(); - return - 1; - } - - $this->db->commit(); - - } - return 1; - } - + /** * Delete bookkepping by piece number * @@ -998,14 +1064,14 @@ class BookKeeping extends CommonObject */ function deleteMvtNum($piecenum) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -1015,57 +1081,57 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone - * + * * @return int New id of clone */ public function createFromClone($fromid) { dol_syslog(__METHOD__, LOG_DEBUG); - + global $user; $error = 0; $object = new Accountingbookkeeping($this->db); - + $this->db->begin(); - + // Load source object $object->fetch($fromid); // Reset object $object->id = 0; - + // Clear fields // ... - + // Create clone $result = $object->create($user); - + // Other options if ($result < 0) { $error ++; $this->errors = $object->errors; dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + // End if (! $error) { $this->db->commit(); - + return $object->id; } else { $this->db->rollback(); - + return - 1; } } - + /** * Initialise object with example values * Id must be 0 if object instance is a specimen @@ -1074,7 +1140,7 @@ class BookKeeping extends CommonObject */ public function initAsSpecimen() { $this->id = 0; - + $this->doc_date = ''; $this->doc_type = ''; $this->doc_ref = ''; @@ -1092,7 +1158,7 @@ class BookKeeping extends CommonObject $this->code_journal = ''; $this->piece_num = ''; } - + /** * Load an accounting document into memory from database * @@ -1103,12 +1169,12 @@ class BookKeeping extends CommonObject $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - + $this->piece_num = $obj->piece_num; $this->code_journal = $obj->code_journal; $this->doc_date = $this->db->jdate($obj->doc_date); @@ -1119,10 +1185,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Return next number movement * @@ -1130,13 +1196,13 @@ class BookKeeping extends CommonObject */ public function getNextNumMvt() { $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); - + if ($result) { $obj = $this->db->fetch_object($result); - + return $obj->max; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1144,7 +1210,7 @@ class BookKeeping extends CommonObject return - 1; } } - + /** * Load all informations of accountancy document * @@ -1158,17 +1224,17 @@ class BookKeeping extends CommonObject $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - + while ( $obj = $this->db->fetch_object($result) ) { - + $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1183,7 +1249,7 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesmvt[] = $line; } } else { @@ -1191,10 +1257,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Export bookkeping * @@ -1207,20 +1273,20 @@ class BookKeeping extends CommonObject $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; - + dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG); - + $resql = $this->db->query($sql); - + if ($resql) { $this->linesexport = array (); - + $num = $this->db->num_rows($resql); while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1235,11 +1301,11 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesexport[] = $line; } $this->db->free($resql); - + return $num; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1247,40 +1313,114 @@ 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 $selectid 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 .= " 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; + $label = dol_trunc($label, $trunclength); + + $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 accounting account + * Description of a root accounting account * * @param string $account Accounting account - * @return string + * @return string */ - function get_compte_desc($account = null) - { + function get_compte_racine($account = null) + { global $conf; $pcgver = $conf->global->CHARTOFACCOUNTS; - $sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category"; - $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 aa.account_number = '" . $account . "'"; - $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 = "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"; + 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); - } - - if(empty($obj->category)){ - return $obj->label; - }else{ - return $obj->label.' ('.$obj->category.')'; - + $obj = $this->db->fetch_object($resql); } + + return $obj->label; + } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); @@ -1288,7 +1428,46 @@ class BookKeeping extends CommonObject return -1; } } - + + + /** + * Description of accounting account + * + * @param string $account Accounting account + * @return string + */ + function get_compte_desc($account = null) + { + global $conf; + $pcgver = $conf->global->CHARTOFACCOUNTS; + $sql = "SELECT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version, cat.label as category"; + $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 aa.account_number = '" . $account . "'"; + $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"; + 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); + } + + if(empty($obj->category)){ + return $obj->label; + }else{ + return $obj->label.' ('.$obj->category.')'; + + } + } else { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); + return -1; + } + } + } /** diff --git a/htdocs/accountancy/tpl/export_journal.tpl.php b/htdocs/accountancy/tpl/export_journal.tpl.php index e9b7c8c005c..f69b47a8017 100644 --- a/htdocs/accountancy/tpl/export_journal.tpl.php +++ b/htdocs/accountancy/tpl/export_journal.tpl.php @@ -1,5 +1,6 @@ + * Copyright (C) 2016 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 @@ -16,12 +17,12 @@ */ $prefix = $conf->global->ACCOUNTING_EXPORT_PREFIX_SPEC; $format = $conf->global->ACCOUNTING_EXPORT_FORMAT; +$nodateexport = $conf->global->ACCOUNTING_EXPORT_NO_DATE_IN_FILENAME; $date_export = dol_print_date($now, '%Y%m%d%H%M%S'); header('Content-Type: text/csv'); -if ($prefix) - $filename = $prefix . "_" . "journal_" . $journal . $date_export . "." . $format; -else - $filename = "journal_" . $journal . $date_export . "." . $format; -header('Content-Disposition: attachment;filename=' . $filename); \ No newline at end of file + +$filename = ($prefix?$prefix . "_":""). "journal_" . $journal . ($nodateexport?"":$date_export) . "." . $format; + +header('Content-Disposition: attachment;filename=' . $filename); diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index e12c49732dd..7604c4fe02c 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -9,6 +9,7 @@ * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Frederic France * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2016 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 @@ -353,7 +354,7 @@ class Adherent extends CommonObject if (count($this->errors)) { - dol_syslog(get_class($this)."::create ".join(',',$this->errors), LOG_ERR); + dol_syslog(get_class($this)."::create ".implode(',',$this->errors), LOG_ERR); $this->db->rollback(); return -3; } diff --git a/htdocs/adherents/list.php b/htdocs/adherents/list.php index 5878aac2755..98e62d4210b 100644 --- a/htdocs/adherents/list.php +++ b/htdocs/adherents/list.php @@ -3,6 +3,7 @@ * Copyright (C) 2002-2003 Jean-Louis Bergamo * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2013-2015 Raphaël Doursenaud + * Copyright (C) 2014-2016 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 @@ -83,7 +84,7 @@ $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search // List of fields to search into when doing a "search in all" $fieldstosearchall = array( 'd.rowid'=>'Ref', - //'d.ref'=>'Ref', + 'd.login'=>'Login', 'd.lastname'=>'Lastname', 'd.firstname'=>'Firstname', 'd.login'=>'Login', @@ -328,7 +329,7 @@ if ($resql) if ($sall) { foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val); - print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall); + print $langs->trans("FilterOnInto", $sall) . implode(', ',$fieldstosearchall); } // Filter on categories diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index 353389c98a8..b147159b3cb 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -3,7 +3,7 @@ * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2010-2013 Juanjo Menent + * Copyright (C) 2010-2016 Juanjo Menent * Copyright (C) 2011-2015 Philippe Grand * Copyright (C) 2011 Remy Younes * Copyright (C) 2012-2015 Marcos García @@ -1085,7 +1085,7 @@ if ($id) require_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php'; $formmail=new FormMail($db); $tmp=$formmail->getAvailableSubstitKey('form'); - print join(', ', $tmp); + print implode(', ', $tmp); print ''; } diff --git a/htdocs/admin/expensereport.php b/htdocs/admin/expensereport.php index 5c8fa9732e4..3023cb7cc66 100644 --- a/htdocs/admin/expensereport.php +++ b/htdocs/admin/expensereport.php @@ -372,7 +372,6 @@ else dol_print_error($db); } - print ''; print ''; print ''; diff --git a/htdocs/admin/ihm.php b/htdocs/admin/ihm.php index 51d0a6174c8..cc1e1792f01 100644 --- a/htdocs/admin/ihm.php +++ b/htdocs/admin/ihm.php @@ -2,6 +2,7 @@ /* Copyright (C) 2001-2005 Rodolphe Quiedeville * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2016 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 @@ -75,28 +76,28 @@ if ($action == 'update') dolibarr_set_const($db, "MAIN_THEME", $_POST["main_theme"],'chaine',0,'',$conf->entity); - $val=(join(',',(colorStringToArray(GETPOST('THEME_ELDY_BACKBODY'),array())))); + $val=(implode(',',(colorStringToArray(GETPOST('THEME_ELDY_BACKBODY'),array())))); if ($val == '') dolibarr_del_const($db, 'THEME_ELDY_BACKBODY', $conf->entity); - else dolibarr_set_const($db, 'THEME_ELDY_BACKBODY', join(',',colorStringToArray(GETPOST('THEME_ELDY_BACKBODY'),array())),'chaine',0,'',$conf->entity); + else dolibarr_set_const($db, 'THEME_ELDY_BACKBODY', implode(',',colorStringToArray(GETPOST('THEME_ELDY_BACKBODY'),array())),'chaine',0,'',$conf->entity); - $val=(join(',',(colorStringToArray(GETPOST('THEME_ELDY_TOPMENU_BACK1'),array())))); + $val=(implode(',',(colorStringToArray(GETPOST('THEME_ELDY_TOPMENU_BACK1'),array())))); if ($val == '') dolibarr_del_const($db, 'THEME_ELDY_TOPMENU_BACK1', $conf->entity); - else dolibarr_set_const($db, 'THEME_ELDY_TOPMENU_BACK1', join(',',colorStringToArray(GETPOST('THEME_ELDY_TOPMENU_BACK1'),array())),'chaine',0,'',$conf->entity); + else dolibarr_set_const($db, 'THEME_ELDY_TOPMENU_BACK1', implode(',',colorStringToArray(GETPOST('THEME_ELDY_TOPMENU_BACK1'),array())),'chaine',0,'',$conf->entity); - $val=(join(',',(colorStringToArray(GETPOST('THEME_ELDY_BACKTITLE1'),array())))); + $val=(implode(',',(colorStringToArray(GETPOST('THEME_ELDY_BACKTITLE1'),array())))); if ($val == '') dolibarr_del_const($db, 'THEME_ELDY_BACKTITLE1', $conf->entity); - else dolibarr_set_const($db, 'THEME_ELDY_BACKTITLE1', join(',',colorStringToArray(GETPOST('THEME_ELDY_BACKTITLE1'),array())),'chaine',0,'',$conf->entity); + else dolibarr_set_const($db, 'THEME_ELDY_BACKTITLE1', implode(',',colorStringToArray(GETPOST('THEME_ELDY_BACKTITLE1'),array())),'chaine',0,'',$conf->entity); - $val=(join(',',(colorStringToArray(GETPOST('THEME_ELDY_TEXTTITLENOTAB'),array())))); + $val=(implode(',',(colorStringToArray(GETPOST('THEME_ELDY_TEXTTITLENOTAB'),array())))); if ($val == '') dolibarr_del_const($db, 'THEME_ELDY_TEXTTITLENOTAB', $conf->entity); - else dolibarr_set_const($db, 'THEME_ELDY_TEXTTITLENOTAB', join(',',colorStringToArray(GETPOST('THEME_ELDY_TEXTTITLENOTAB'),array())),'chaine',0,'',$conf->entity); + else dolibarr_set_const($db, 'THEME_ELDY_TEXTTITLENOTAB', implode(',',colorStringToArray(GETPOST('THEME_ELDY_TEXTTITLENOTAB'),array())),'chaine',0,'',$conf->entity); if (GETPOST('THEME_ELDY_USE_HOVER') == '') dolibarr_del_const($db, "THEME_ELDY_USE_HOVER", $conf->entity); else dolibarr_set_const($db, "THEME_ELDY_USE_HOVER", $_POST["THEME_ELDY_USE_HOVER"], 'chaine', 0, '', $conf->entity); - $val=(join(',',(colorStringToArray(GETPOST('THEME_ELDY_TEXTLINK'),array())))); + $val=(implode(',',(colorStringToArray(GETPOST('THEME_ELDY_TEXTLINK'),array())))); if ($val == '') dolibarr_del_const($db, 'THEME_ELDY_TEXTLINK', $conf->entity); - else dolibarr_set_const($db, 'THEME_ELDY_TEXTLINK', join(',',colorStringToArray(GETPOST('THEME_ELDY_TEXTLINK'),array())),'chaine',0,'',$conf->entity); + else dolibarr_set_const($db, 'THEME_ELDY_TEXTLINK', implode(',',colorStringToArray(GETPOST('THEME_ELDY_TEXTLINK'),array())),'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_SIZE_LISTE_LIMIT", $_POST["main_size_liste_limit"],'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_SIZE_SHORTLISTE_LIMIT", $_POST["main_size_shortliste_limit"],'chaine',0,'',$conf->entity); diff --git a/htdocs/admin/ldap_users.php b/htdocs/admin/ldap_users.php index dbed44ca5d0..45043b8a52b 100644 --- a/htdocs/admin/ldap_users.php +++ b/htdocs/admin/ldap_users.php @@ -4,7 +4,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005 Regis Houssin * Copyright (C) 2006-2011 Laurent Destailleur - * Copyright (C) 2011-2013 Juanjo Menent + * Copyright (C) 2011-2016 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 @@ -437,7 +437,7 @@ if (function_exists("ldap_connect")) print "search: *
\n"; print "userDN: ".$conf->global->LDAP_USER_DN."
\n"; print "useridentifier: ".$conf->global->LDAP_KEY_USERS."
\n"; - print "required_fields: ".join(',',$required_fields)."
\n"; + print "required_fields: ".implode(',',$required_fields)."
\n"; print "=> ".count($liste)." records
\n"; print "\n
"; } diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php index b299a1f18fe..de8a299cece 100644 --- a/htdocs/admin/menus/edit.php +++ b/htdocs/admin/menus/edit.php @@ -243,7 +243,7 @@ if ($action == 'confirm_delete' && $_POST["confirm"] == 'yes') { $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu WHERE rowid = ".$_GET['menuId']; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."menu WHERE rowid = ".GETPOST('menuId', 'int'); $db->query($sql); if ($result == 0) @@ -312,7 +312,7 @@ if ($action == 'create') $parent_rowid = $_GET['menuId']; if ($_GET['menuId']) { - $sql = "SELECT m.rowid, m.mainmenu, m.leftmenu, m.level, m.langs FROM ".MAIN_DB_PREFIX."menu as m WHERE m.rowid = ".$_GET['menuId']; + $sql = "SELECT m.rowid, m.mainmenu, m.leftmenu, m.level, m.langs FROM ".MAIN_DB_PREFIX."menu as m WHERE m.rowid = ".GETPOST('menuId', 'int'); $res = $db->query($sql); if ($res) { diff --git a/htdocs/admin/notification.php b/htdocs/admin/notification.php index e8ac153bea7..a3b3eb50df6 100644 --- a/htdocs/admin/notification.php +++ b/htdocs/admin/notification.php @@ -118,7 +118,11 @@ llxHeader('',$langs->trans("NotificationSetup")); $linkback=''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans("NotificationSetup"),$linkback,'title_setup'); -print $langs->trans("NotificationsDesc").'

'; +print $langs->trans("NotificationsDesc").'
'; +print $langs->trans("NotificationsDescUser").'
'; +if (! empty($conf->societe->enabled)) print $langs->trans("NotificationsDescContact").'
'; +print $langs->trans("NotificationsDescGlobal").'
'; +print '
'; print '
'; print ''; @@ -141,52 +145,53 @@ print ''; print '
'; print '
'.$langs->trans("Name").'
'; -print '
'; +print '

'; -if ($conf->societe->enabled) +// Notification per contacts +$title=$langs->trans("ListOfNotificationsPerUser"); +if (! empty($conf->societe->enabled)) $title=$langs->trans("ListOfNotificationsPerUserOrContact"); +print load_fiche_titre($title,'',''); + +print ''; +print ''; +print ''; +/*print ''; + print '';*/ +//print ''; +print "\n"; + +// Load array of available notifications +$notificationtrigger=new InterfaceNotification($db); +$listofnotifiedevents=$notificationtrigger->getListOfManagedEvents(); + +print ''; +print ''; + +print '
'.$langs->trans("Label").''.$langs->trans("Code").''.$langs->trans("Label").''.$langs->trans("NbOfTargetedContacts").'
'; + +$var=true; +$i=0; +foreach($listofnotifiedevents as $notifiedevent) { - print load_fiche_titre($langs->trans("ListOfNotificationsPerContact"),'',''); + $var=!$var; + $label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']; - print ''; - print ''; - print ''; - print ''; - print ''; - //print ''; - print "\n"; + if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder'); + elseif ($notifiedevent['elementtype'] == 'propal') $elementLabel = $langs->trans('Proposal'); + elseif ($notifiedevent['elementtype'] == 'facture') $elementLabel = $langs->trans('Bill'); + elseif ($notifiedevent['elementtype'] == 'commande') $elementLabel = $langs->trans('Order'); + elseif ($notifiedevent['elementtype'] == 'ficheinter') $elementLabel = $langs->trans('Intervention'); - // Load array of available notifications - $notificationtrigger=new InterfaceNotification($db); - $listofnotifiedevents=$notificationtrigger->getListOfManagedEvents(); - - $var=true; - foreach($listofnotifiedevents as $notifiedevent) - { - $var=!$var; - $label=$langs->trans("Notify_".$notifiedevent['code']); //!=$langs->trans("Notify_".$notifiedevent['code'])?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']; - - if ($notifiedevent['elementtype'] == 'order_supplier') $elementLabel = $langs->trans('SupplierOrder'); - elseif ($notifiedevent['elementtype'] == 'propal') $elementLabel = $langs->trans('Proposal'); - elseif ($notifiedevent['elementtype'] == 'facture') $elementLabel = $langs->trans('Bill'); - elseif ($notifiedevent['elementtype'] == 'commande') $elementLabel = $langs->trans('Order'); - elseif ($notifiedevent['elementtype'] == 'ficheinter') $elementLabel = $langs->trans('Intervention'); - - print ''; - print ''; - print ''; - print ''; - /*print '';*/ - print ''; - } - - print '
'.$langs->trans("Module").''.$langs->trans("Code").''.$langs->trans("Label").''.$langs->trans("NbOfTargetedContacts").'
'.$elementLabel.''.$notifiedevent['code'].''.$label.''; - $tmparray = $notify->getNotificationsArray($notifiedevent['code'], 0); - print count($tmparray); - print '
'; - print '* '.$langs->trans("GoOntoContactCardToAddMore").'
'; - print '
'; + if ($i) print ', '; + print $label; + + $i++; } +print '
'; +print '* '.$langs->trans("GoOntoUserCardToAddMore").'
'; +if (! empty($conf->societe->enabled)) print '** '.$langs->trans("GoOntoContactCardToAddMore").'
'; +print '

'; print load_fiche_titre($langs->trans("ListOfFixedNotifications"),'',''); diff --git a/htdocs/admin/payment.php b/htdocs/admin/payment.php index fa99e2c202b..8ce904aad7c 100644 --- a/htdocs/admin/payment.php +++ b/htdocs/admin/payment.php @@ -69,7 +69,23 @@ if ($action == 'setmod') dolibarr_set_const($db, "PAYMENT_ADDON",$value,'chaine',0,'',$conf->entity); } +if ($action == 'set_FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') +{ + $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'); // No alpha here, we want exact string + $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$freetext,'chaine',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} /* * View @@ -215,6 +231,33 @@ foreach ($dirmodels as $reldir) print ''; +print "
"; + +print load_fiche_titre($langs->trans("OtherOptions"),'',''); + +print ''; +print ''; +print ''; +print ''; +print ''; +print "\n"; + +// Allow payments on different thirdparties bills but same parent company +$var=! $var; +print ''; +print ''; +print ''; +print '\n"; +print ''; + +print '
'.$langs->trans("Parameter").''.$langs->trans("Value").' 
'; +print $langs->trans("PaymentOnDifferentThirdBills"); +print ''; +print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS,1); +print ''; +print ''; +print "
'; + dol_fiche_end(); diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index b78bf1ce0bd..e258011de76 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -49,6 +49,10 @@ if($action) { $res = dolibarr_set_const($db, "STOCK_USERSTOCK_AUTOCREATE", GETPOST('STOCK_USERSTOCK_AUTOCREATE','alpha'),'chaine',0,'',$conf->entity); } + if ($action == 'STOCK_ALLOW_NEGATIVE_TRANSFER') + { + $res = dolibarr_set_const($db, "STOCK_ALLOW_NEGATIVE_TRANSFER", GETPOST('STOCK_ALLOW_NEGATIVE_TRANSFER','alpha'),'chaine',0,'',$conf->entity); + } // Mode of stock decrease if ($action == 'STOCK_CALCULATE_ON_BILL' || $action == 'STOCK_CALCULATE_ON_VALIDATE_ORDER' @@ -319,63 +323,73 @@ $found++; print ''; +print '
'; +print ''; +print ''; +print " \n"; +print " \n"; +print ''."\n"; + +$var=!$var; +print ""; +print ''; +print '\n"; +print "\n"; + // Option to force stock to be enough before adding a line into document -if ($conf->invoice->enabled || $conf->order->enabled || $conf->expedition->enabled) -{ - print '
'; - print '
".$langs->trans("RuleForStockAvailability")." 
'.$langs->trans("WarehouseAllowNegativeTransfer").''; +print "
"; +print ''; +print ""; +print $form->selectyesno("STOCK_ALLOW_NEGATIVE_TRANSFER",$conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER,1); +print ''; +print '
'; +print "
'; - print ''; - print " \n"; - print " \n"; - print ''."\n"; - - if($conf->invoice->enabled) { - $var = !$var; - print ""; - print ''; - print '\n"; - print "\n"; - } - - if($conf->order->enabled) { - $var = !$var; - print ""; - print ''; - print '\n"; - print "\n"; - } - - if($conf->expedition->enabled) { - $var = !$var; - print ""; - print ''; - print '\n"; - print "\n"; - } - print '
".$langs->trans("RuleForStockAvailability")." 
'.$langs->trans("StockMustBeEnoughForInvoice").''; - print "
"; - print ''; - print ""; - print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_INVOICE",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE,1); - print ''; - print '
'; - print "
'.$langs->trans("StockMustBeEnoughForOrder").''; - print "
"; - print ''; - print ""; - print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_ORDER",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER,1); - print ''; - print '
'; - print "
'.$langs->trans("StockMustBeEnoughForShipment").''; - print "
"; - print ''; - print ""; - print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT,1); - print ''; - print '
'; - print "
'; +if($conf->invoice->enabled) { + $var = !$var; + print ""; + print ''.$langs->trans("StockMustBeEnoughForInvoice").''; + print ''; + print "
"; + print ''; + print ""; + print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_INVOICE",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE,1); + print ''; + print '
'; + print "\n"; + print "\n"; } +if($conf->order->enabled) { + $var = !$var; + print ""; + print ''.$langs->trans("StockMustBeEnoughForOrder").''; + print ''; + print "
"; + print ''; + print ""; + print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_ORDER",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER,1); + print ''; + print '
'; + print "\n"; + print "\n"; +} + +if($conf->expedition->enabled) { + $var = !$var; + print ""; + print ''.$langs->trans("StockMustBeEnoughForShipment").''; + print ''; + print "
"; + print ''; + print ""; + print $form->selectyesno("STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT",$conf->global->STOCK_MUST_BE_ENOUGH_FOR_SHIPMENT,1); + print ''; + print '
'; + print "\n"; + print "\n"; +} +print ''; + $virtualdiffersfromphysical=0; if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) @@ -427,6 +441,7 @@ print '' print ''; print "\n"; print "\n"; + print '
'; /* I keep the option/feature, but hidden to end users for the moment. If feature is used by module, no need to have users see it. diff --git a/htdocs/admin/system/phpinfo.php b/htdocs/admin/system/phpinfo.php index dfb897ba27c..ffba92fd4fa 100644 --- a/htdocs/admin/system/phpinfo.php +++ b/htdocs/admin/system/phpinfo.php @@ -2,6 +2,7 @@ /* Copyright (C) 2001-2002 Rodolphe Quiedeville * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2016 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 @@ -87,9 +88,9 @@ foreach($phparray as $key => $value) $valtoshow=$keyvalue; if ($keyparam == 'X-ChromePhp-Data') $valtoshow=dol_trunc($keyvalue,80); print ''; - if ($keyparam == 'Path') $valtoshow=join('; ',explode(';',trim($valtoshow))); - if ($keyparam == 'PATH') $valtoshow=join('; ',explode(';',trim($valtoshow))); - if ($keyparam == '_SERVER["PATH"]') $valtoshow=join('; ',explode(';',trim($valtoshow))); + if ($keyparam == 'Path') $valtoshow=implode('; ',explode(';',trim($valtoshow))); + if ($keyparam == 'PATH') $valtoshow=implode('; ',explode(';',trim($valtoshow))); + if ($keyparam == '_SERVER["PATH"]') $valtoshow=implode('; ',explode(';',trim($valtoshow))); print $valtoshow; print ''; print ''; @@ -104,7 +105,7 @@ foreach($phparray as $key => $value) { print ''; $valtoshow=$keyvalue2; - if ($keyparam == 'disable_functions') $valtoshow=join(', ',explode(',',trim($valtoshow))); + if ($keyparam == 'disable_functions') $valtoshow=implode(', ',explode(',',trim($valtoshow))); //print $keyparam; print $valtoshow; $i++; diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index e759e93a635..406d7b5916c 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1096,21 +1096,36 @@ class ActionComm extends CommonObject */ function getNomUrl($withpicto=0,$maxlength=0,$classname='',$option='',$overwritepicto=0) { - global $conf,$langs; + global $conf,$langs, $hookmanager; - $result=''; - $tooltip = '' . $langs->trans('ShowAction'.$objp->code) . ''; - if (! empty($this->ref)) - $tooltip .= '
' . $langs->trans('Ref') . ': ' . $this->ref; - if (! empty($this->label)) - $tooltip .= '
' . $langs->trans('Title') . ': ' . $this->label; - $label = $this->label; - if (empty($label)) $label=$this->libelle; // For backward compatibility - $linkclose = '" title="'.dol_escape_htmltag($tooltip, 1).'">'; - if ($option=='birthday') $link = ''; + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('actiondao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + $linkclose = ($hookmanager->resPrint ? $hookmanager->resPrint : $linkclose); + + if ($option=='birthday') + $link = 'libelle.'-'.$withpicto; if ($withpicto == 2) { diff --git a/htdocs/comm/action/pertype.php b/htdocs/comm/action/pertype.php index 6138e79cafd..ae11f06cedd 100644 --- a/htdocs/comm/action/pertype.php +++ b/htdocs/comm/action/pertype.php @@ -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)); } @@ -186,7 +186,7 @@ $week = $prev['week']; $day = (int) $day; $next = dol_get_next_day($day, $month, $year); -$next_year = year + 1; +$next_year = $year + 1; $next_month = $month; $next_day = $day; diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 256a31fd947..8ead3188ae7 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -46,6 +46,8 @@ if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherent if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; $langs->load("companies"); +$langs->load('banks'); + if (! empty($conf->contrat->enabled)) $langs->load("contracts"); if (! empty($conf->commande->enabled)) $langs->load("orders"); if (! empty($conf->expedition->enabled)) $langs->load("sendings"); @@ -124,7 +126,15 @@ if (empty($reshook)) if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - // customer preferred shipping method + // Bank account + if ($action == 'setbankaccount' && $user->rights->societe->creer) + { + $object->fetch($id); + $result=$object->setBankAccount(GETPOST('fk_account','int')); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + } + + // customer preferred shipping method if ($action == 'setshippingmethod' && $user->rights->societe->creer) { $object->fetch($id); @@ -337,6 +347,26 @@ if ($id > 0) print ""; print ''; + // Compte bancaire par défaut + print ''; + print ''; + print '
'; + print $langs->trans('BankAccount'); + print ''; + if (($action != 'editbankaccount') && $user->rights->societe->creer) print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; + print ''; + if ($action == 'editbankaccount') + { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'fk_account',1); + } + else + { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'none'); + } + print ""; + print ''; + + // Relative discounts (Discounts-Drawbacks-Rebates) print ''; print ''; + print ''; } print "
'; diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 4711aac7222..a205ff54d1a 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -197,7 +197,7 @@ if (! empty($conf->propal->enabled) && $user->rights->propal->lire) else { $var=!$var; - print '
'.$langs->trans("NoProposal").'
'.$langs->trans("NoProposal").'

"; @@ -277,7 +277,7 @@ if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_propos else { $var=!$var; - print ''.$langs->trans("NoProposal").''; + print ''.$langs->trans("NoProposal").''; } print "
"; @@ -357,7 +357,7 @@ if (! empty($conf->commande->enabled) && $user->rights->commande->lire) else { $var=!$var; - print ''.$langs->trans("NoOrder").''; + print ''.$langs->trans("NoOrder").''; } print "
"; @@ -438,7 +438,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande else { $var=!$var; - print ''.$langs->trans("NoSupplierOrder").''; + print ''.$langs->trans("NoSupplierOrder").''; } print "
"; diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 1e580826e96..cd1734ff0a5 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -2417,7 +2417,7 @@ if ($action == 'create') // Tableau des substitutions $formmail->setSubstitFromObject($object); - $formmail->substit['__PROPREF__'] = $object->ref; + $formmail->substit['__PROPREF__'] = $object->ref; // For backward compatibility // Find the good contact adress $custcontact = ''; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index ffc412fba70..6523688fd8d 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -7,7 +7,7 @@ * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2008 Raphael Bertrand * Copyright (C) 2010-2014 Juanjo Menent - * Copyright (C) 2010-2011 Philippe Grand + * Copyright (C) 2010-2016 Philippe Grand * Copyright (C) 2012-2014 Christophe Battarel * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry @@ -59,24 +59,24 @@ class Propal extends CommonObject * ID of the client * @var int */ - var $socid; + public $socid; - var $contactid; - var $author; - var $ref_client; + public $contactid; + public $author; + public $ref_client; /** * Status of the quote * @var int * @see Propal::STATUS_DRAFT, Propal::STATUS_VALIDATED, Propal::STATUS_SIGNED, Propal::STATUS_NOTSIGNED, Propal::STATUS_BILLED */ - var $statut; + public $statut; /** * @deprecated * @see date_creation */ - var $datec; + public $datec; /** * Creation date @@ -88,7 +88,7 @@ class Propal extends CommonObject * @deprecated * @see date_validation */ - var $datev; + public $datev; /** * Validation date @@ -100,71 +100,73 @@ class Propal extends CommonObject * Date of the quote * @var */ - var $date; + public $date; /** * @deprecated * @see date */ - var $datep; - var $date_livraison; - var $fin_validite; + public $datep; + public $date_livraison; + public $fin_validite; - var $user_author_id; - var $user_valid_id; - var $user_close_id; + public $user_author_id; + public $user_valid_id; + public $user_close_id; /** * @deprecated * @see total_ht */ - var $price; + public $price; /** * @deprecated * @see total_tva */ - var $tva; + public $tva; /** * @deprecated * @see total_ttc */ - var $total; + public $total; - var $cond_reglement_code; - var $mode_reglement_code; - var $remise; - var $remise_percent; - var $remise_absolue; - var $fk_address; - var $address_type; - var $address; - var $availability_id; - var $availability_code; - var $demand_reason_id; - var $demand_reason_code; + public $cond_reglement_code; + public $mode_reglement_code; + public $remise; + public $remise_percent; + public $remise_absolue; + public $fk_address; + public $address_type; + public $address; + public $availability_id; + public $availability_code; + public $demand_reason_id; + public $demand_reason_code; - var $products=array(); - var $extraparams=array(); + public $products=array(); + public $extraparams=array(); /** * @var PropaleLigne[] */ - var $lines = array(); - var $line; + public $lines = array(); + public $line; - var $labelstatut=array(); - var $labelstatut_short=array(); + public $labelstatut=array(); + public $labelstatut_short=array(); - var $specimen; + public $specimen; // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; - + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; + + public $oldcopy; + /** * Draft status */ @@ -223,15 +225,15 @@ class Propal extends CommonObject /** * Add line into array products - * $this->client doit etre charge + * $this->thirdparty should be loaded * * @param int $idproduct Product Id to add * @param int $qty Quantity * @param int $remise_percent Discount effected on Product * @return int <0 if KO, >0 if OK * - * TODO Remplacer les appels a cette fonction par generation objet Ligne - * insere dans tableau $this->products + * TODO Replace calls to this function by generation objet Ligne + * inserted into table $this->products */ function add_product($idproduct, $qty, $remise_percent=0) { @@ -253,7 +255,7 @@ class Propal extends CommonObject $localtax1_tx = get_localtax($tva_tx,1,$mysoc,$this->thirdparty,$tva_npr); $localtax2_tx = get_localtax($tva_tx,2,$mysoc,$this->thirdparty,$tva_npr); - // multiprix + // multiprices if($conf->global->PRODUIT_MULTIPRICES && $this->thirdparty->price_level) { $price = $prod->multiprices[$this->thirdparty->price_level]; @@ -273,7 +275,7 @@ class Propal extends CommonObject $line->tva_tx=$tva_tx; $line->fk_unit=$prod->fk_unit; if ($tva_npr) $line->info_bits = 1; - + $this->lines[]=$line; } } @@ -314,7 +316,7 @@ class Propal extends CommonObject $line->desc=$remise->description; // Description ligne $line->tva_tx=$remise->tva_tx; $line->subprice=-$remise->amount_ht; - $line->fk_product=0; // Id produit predefini + $line->fk_product=0; // Id produit predefined $line->qty=1; $line->remise=0; $line->remise_percent=0; @@ -359,10 +361,10 @@ class Propal extends CommonObject /** * Add a proposal line into database (linked to product/service or not) - * Les parametres sont deja cense etre juste et avec valeurs finales a l'appel - * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini - * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,'',produit) - * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue) + * The parameters are already supposed to be appropriate and with final values to the call + * of this method. Also, for the VAT rate, it must have already been defined + * by whose calling the method get_default_tva (societe_vendeuse, societe_acheteuse, '' product) + * and desc must already have the right value (it's up to the caller to manage multilanguage) * * @param string $desc Description de la ligne * @param float $pu_ht Prix unitaire @@ -444,7 +446,7 @@ class Propal extends CommonObject return -3; } } - + // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker @@ -452,7 +454,7 @@ class Propal extends CommonObject $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; @@ -529,7 +531,7 @@ class Propal extends CommonObject $this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; - + // Mise en option de la ligne if (empty($qty) && empty($special_code)) $this->line->special_code=3; @@ -627,7 +629,7 @@ class Propal extends CommonObject $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -639,7 +641,7 @@ class Propal extends CommonObject $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Anciens indicateurs: $price, $remise (a ne plus utiliser) $price = $pu; if ($remise_percent > 0) @@ -800,7 +802,7 @@ class Propal extends CommonObject $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } - + dol_syslog(get_class($this)."::create"); // Check parameters @@ -1110,7 +1112,7 @@ class Propal extends CommonObject $clonedObj->cond_reglement_id = (! empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0); $clonedObj->mode_reglement_id = (! empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0); $clonedObj->fk_delivery_address = ''; - + /*if (!empty($conf->projet->enabled)) { $project = new Project($db); @@ -1610,11 +1612,12 @@ class Propal extends CommonObject /** * Define proposal date * - * @param User $user Object user that modify - * @param int $date Date - * @return int <0 if KO, >0 if OK + * @param User $user Object user that modify + * @param int $date Date + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function set_date($user, $date) + function set_date($user, $date, $notrigger=0) { if (empty($date)) { @@ -1625,20 +1628,50 @@ class Propal extends CommonObject if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET datep = '".$this->db->idate($date)."'"; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - dol_syslog(get_class($this)."::set_date", LOG_DEBUG); - if ($this->db->query($sql) ) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->date = $date; - $this->datep = $date; // deprecated - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->date = $date; + $this->datep = $date; // deprecated + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->lasterror(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1646,25 +1679,59 @@ class Propal extends CommonObject /** * Define end validity date * - * @param User $user Object user that modify - * @param int $date_fin_validite End of validity date - * @return int <0 if KO, >0 if OK + * @param User $user Object user that modify + * @param int $date_fin_validite End of validity date + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function set_echeance($user, $date_fin_validite) + function set_echeance($user, $date_fin_validite, $notrigger=0) { if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fin_validite = ".($date_fin_validite!=''?"'".$this->db->idate($date_fin_validite)."'":'null'); $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - if ($this->db->query($sql) ) + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->fin_validite = $date_fin_validite; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + + if (! $error) + { + $this->oldcopy= clone $this; + $this->fin_validite = $date_fin_validite; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1672,28 +1739,59 @@ class Propal extends CommonObject /** * Set delivery date * - * @param User $user Object user that modify - * @param int $date_livraison Delivery date - * @return int <0 if ko, >0 if ok + * @param User $user Object user that modify + * @param int $date_livraison Delivery date + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if ko, >0 if ok */ - function set_date_livraison($user, $date_livraison) + function set_date_livraison($user, $date_livraison, $notrigger=0) { if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $sql.= " SET date_livraison = ".($date_livraison!=''?"'".$this->db->idate($date_livraison)."'":'null'); $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->date_livraison = $date_livraison; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->date_livraison = $date_livraison; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_date_livraison Erreur SQL"); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1703,26 +1801,57 @@ class Propal extends CommonObject * * @param User $user Object user that modify * @param int $id Availability id + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_availability($user, $id) + function set_availability($user, $id, $notrigger=0) { if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $sql.= " SET fk_availability = '".$id."'"; $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->fk_availability = $id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->fk_availability = $id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_availability Erreur SQL"); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1732,26 +1861,59 @@ class Propal extends CommonObject * * @param User $user Object user that modify * @param int $id Input reason id + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_demand_reason($user, $id) + function set_demand_reason($user, $id, $notrigger=0) { if (! empty($user->rights->propal->creer)) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $sql.= " SET fk_input_reason = '".$id."'"; $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->fk_input_reason = $id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + + if (! $error) + { + $this->oldcopy= clone $this; + $this->fk_input_reason = $id; + } + + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_demand_reason Erreur SQL"); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1761,26 +1923,56 @@ class Propal extends CommonObject * * @param User $user Object user that modify * @param string $ref_client Customer reference + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if ko, >0 if ok */ - function set_ref_client($user, $ref_client) + function set_ref_client($user, $ref_client, $notrigger=0) { if (! empty($user->rights->propal->creer)) { - dol_syslog('Propale::set_ref_client this->id='.$this->id.', ref_client='.$ref_client); + $error=0; + + $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\''); $sql.= ' WHERE rowid = '.$this->id; - if ($this->db->query($sql) ) + + dol_syslog(__METHOD__.' $this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->ref_client = $ref_client; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->ref_client = $ref_client; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - dol_syslog('Propale::set_ref_client Erreur '.$this->error.' - '.$sql); - return -2; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else @@ -1793,10 +1985,11 @@ class Propal extends CommonObject * Set an overall discount on the proposal * * @param User $user Object user that modify - * @param double $remise Amount discount + * @param double $remise Amount discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if ko, >0 if ok */ - function set_remise_percent($user, $remise) + function set_remise_percent($user, $remise, $notrigger=0) { $remise=trim($remise)?trim($remise):0; @@ -1804,19 +1997,50 @@ class Propal extends CommonObject { $remise = price2num($remise); + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET remise_percent = ".$remise; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - if ($this->db->query($sql) ) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->remise_percent = $remise; - $this->update_price(1); - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->remise_percent = $remise; + $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1825,11 +2049,12 @@ class Propal extends CommonObject /** * Set an absolute overall discount on the proposal * - * @param User $user Object user that modify - * @param double $remise Amount discount + * @param User $user Object user that modify + * @param double $remise Amount discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if ko, >0 if ok */ - function set_remise_absolue($user, $remise) + function set_remise_absolue($user, $remise, $notrigger=0) { $remise=trim($remise)?trim($remise):0; @@ -1837,20 +2062,51 @@ class Propal extends CommonObject { $remise = price2num($remise); + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal "; $sql.= " SET remise_absolue = ".$remise; $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - if ($this->db->query($sql) ) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->remise_absolue = $remise; - $this->update_price(1); - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->remise_absolue = $remise; + $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -1924,9 +2180,10 @@ class Propal extends CommonObject * @param User $user Object user that close * @param int $statut Statut * @param string $note Comment + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function cloture($user, $statut, $note) + function cloture($user, $statut, $note, $notrigger=0) { global $langs,$conf; @@ -1981,15 +2238,24 @@ class Propal extends CommonObject $this->generateDocument($modelpdf, $outputlangs); } - // Call trigger - $result=$this->call_trigger($trigger_name,$user); - if ($result < 0) { $error++; } - // End call triggers + if (! $error) + { + $this->oldcopy= clone $this; + $this->statut = $statut; + $this->date_cloture = $now; + $this->note_private = $note; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger($trigger_name,$user); + if ($result < 0) { $error++; } + // End call triggers + } if ( ! $error ) { - $this->statut = $statut; - $this->db->commit(); return 1; } @@ -2010,20 +2276,55 @@ class Propal extends CommonObject /** * Class invoiced the Propal * - * @return int <0 si ko, >0 si ok + * @param User $user Object user + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 si ko, >0 si ok */ - function classifyBilled() + function classifyBilled(User $user, $notrigger=0) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal SET fk_statut = '.self::STATUS_BILLED; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT.' ;'; - if ($this->db->query($sql) ) + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; $this->statut=self::STATUS_BILLED; - return 1; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_print_error($this->db); + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } @@ -2032,7 +2333,7 @@ class Propal extends CommonObject * * @return int <0 si ko, >0 si ok * @deprecated - * @see classifyBilled() + * @see classifyBilled() */ function classer_facturee() { @@ -2046,22 +2347,55 @@ class Propal extends CommonObject * Set draft status * * @param User $user Object user that modify + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_draft($user) + function set_draft($user, $notrigger=0) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."propal SET fk_statut = ".self::STATUS_DRAFT; $sql.= " WHERE rowid = ".$this->id; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->statut = self::STATUS_DRAFT; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->statut = self::STATUS_DRAFT; $this->brouillon = 1; - return 1; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } @@ -2364,32 +2698,65 @@ class Propal extends CommonObject * Change the delivery time * * @param int $availability_id Id of new delivery time + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int >0 if OK, <0 if KO */ - function availability($availability_id) + function availability($availability_id, $notrigger=0) { - dol_syslog('Propale::availability('.$availability_id.')'); if ($this->statut >= self::STATUS_DRAFT) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal'; $sql .= ' SET fk_availability = '.$availability_id; $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) + + dol_syslog(__METHOD__.' availability('.$availability_id.')', LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->availability_id = $availability_id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->availability_id = $availability_id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_syslog('Propale::availability Erreur '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else { - dol_syslog('Propale::availability, etat propale incompatible'); - $this->error='Etat propale incompatible '.$this->statut; + $error_str='Propal status do not meet requirement '.$this->statut; + dol_syslog(__METHOD__.$error_str, LOG_ERR); + $this->error=$error_str; + $this->errors[]= $this->error; return -2; } } @@ -2398,32 +2765,65 @@ class Propal extends CommonObject * Change source demand * * @param int $demand_reason_id Id of new source demand + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int >0 si ok, <0 si ko */ - function demand_reason($demand_reason_id) + function demand_reason($demand_reason_id, $notrigger=0) { - dol_syslog('Propale::demand_reason('.$demand_reason_id.')'); if ($this->statut >= self::STATUS_DRAFT) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'propal'; $sql .= ' SET fk_input_reason = '.$demand_reason_id; $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) + + dol_syslog(__METHOD__.' demand_reason('.$demand_reason_id.')', LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->demand_reason_id = $demand_reason_id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->demand_reason_id = $demand_reason_id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('PROPAL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_syslog('Propale::demand_reason Erreur '.$sql.' - '.$this->db->error()); - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else { - dol_syslog('Propale::demand_reason, etat propale incompatible'); - $this->error='Etat propale incompatible '.$this->statut; + $error_str='Propal status do not meet requirement '.$this->statut; + dol_syslog(__METHOD__.$error_str, LOG_ERR); + $this->error=$error_str; + $this->errors[]= $this->error; return -2; } } @@ -2507,21 +2907,21 @@ class Propal extends CommonObject */ function LibStatut($statut,$mode=1) { - global $langs; - $langs->load("propal"); + global $langs; + $langs->load("propal"); - if ($statut==self::STATUS_DRAFT) $statuttrans='statut0'; - if ($statut==self::STATUS_VALIDATED) $statuttrans='statut1'; - if ($statut==self::STATUS_SIGNED) $statuttrans='statut3'; - if ($statut==self::STATUS_NOTSIGNED) $statuttrans='statut5'; - if ($statut==self::STATUS_BILLED) $statuttrans='statut6'; + if ($statut==self::STATUS_DRAFT) $statuttrans='statut0'; + if ($statut==self::STATUS_VALIDATED) $statuttrans='statut1'; + if ($statut==self::STATUS_SIGNED) $statuttrans='statut3'; + if ($statut==self::STATUS_NOTSIGNED) $statuttrans='statut5'; + if ($statut==self::STATUS_BILLED) $statuttrans='statut6'; - if ($mode == 0) return $this->labelstatut[$statut]; - if ($mode == 1) return $this->labelstatut_short[$statut]; - if ($mode == 2) return img_picto($this->labelstatut_short[$statut], $statuttrans).' '.$this->labelstatut_short[$statut]; - if ($mode == 3) return img_picto($this->labelstatut[$statut], $statuttrans); - if ($mode == 4) return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut]; - if ($mode == 5) return ''.$this->labelstatut_short[$statut].' '.img_picto($this->labelstatut_short[$statut],$statuttrans); + if ($mode == 0) return $this->labelstatut[$statut]; + if ($mode == 1) return $this->labelstatut_short[$statut]; + if ($mode == 2) return img_picto($this->labelstatut_short[$statut], $statuttrans).' '.$this->labelstatut_short[$statut]; + if ($mode == 3) return img_picto($this->labelstatut[$statut], $statuttrans); + if ($mode == 4) return img_picto($this->labelstatut[$statut],$statuttrans).' '.$this->labelstatut[$statut]; + if ($mode == 5) return ''.$this->labelstatut_short[$statut].' '.img_picto($this->labelstatut_short[$statut],$statuttrans); } @@ -2681,7 +3081,7 @@ class Propal extends CommonObject $prodid = mt_rand(1, $num_prods); $line->fk_product=$prodids[$prodid]; } - + $this->lines[$xnbp]=$line; $this->total_ht += $line->total_ht; @@ -2851,7 +3251,7 @@ class Propal extends CommonObject function getLinesArray() { // For other object, here we call fetch_lines. But fetch_lines does not exists on proposal - + $sql = 'SELECT pt.rowid, pt.label as custom_label, pt.description, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, 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,'; @@ -2911,7 +3311,7 @@ class Propal extends CommonObject $this->lines[$i]->date_start = $this->db->jdate($obj->date_start); $this->lines[$i]->date_end = $this->db->jdate($obj->date_end); $this->lines[$i]->fk_unit = $obj->fk_unit; - + // Multicurrency $this->lines[$i]->fk_multicurrency = $obj->fk_multicurrency; $this->lines[$i]->multicurrency_code = $obj->multicurrency_code; @@ -3096,7 +3496,7 @@ class PropaleLigne extends CommonObjectLine var $multicurrency_total_ht; var $multicurrency_total_tva; var $multicurrency_total_ttc; - + /** * Class line Contructor * @@ -3180,7 +3580,7 @@ class PropaleLigne extends CommonObjectLine $this->multicurrency_total_ht = $objp->multicurrency_total_ht; $this->multicurrency_total_tva = $objp->multicurrency_total_tva; $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc; - + $this->db->free($result); return 1; @@ -3206,7 +3606,7 @@ class PropaleLigne extends CommonObjectLine dol_syslog(get_class($this)."::insert rang=".$this->rang); $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. - + // Clean parameters if (empty($this->tva_tx)) $this->tva_tx=0; if (empty($this->localtax1_tx)) $this->localtax1_tx=0; @@ -3226,7 +3626,7 @@ class PropaleLigne extends CommonObjectLine if (empty($this->pa_ht)) $this->pa_ht=0; // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0 && $pa_ht_isemptystring) + if ($this->pa_ht == 0 && $pa_ht_isemptystring) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -3391,7 +3791,7 @@ class PropaleLigne extends CommonObjectLine $error=0; $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. - + // Clean parameters if (empty($this->tva_tx)) $this->tva_tx=0; if (empty($this->localtax1_tx)) $this->localtax1_tx=0; @@ -3413,7 +3813,7 @@ class PropaleLigne extends CommonObjectLine if (empty($this->pa_ht)) $this->pa_ht=0; // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0 && $pa_ht_isemptystring) + if ($this->pa_ht == 0 && $pa_ht_isemptystring) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -3459,13 +3859,13 @@ class PropaleLigne extends CommonObjectLine $sql.= " , date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null"); $sql.= " , date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null"); $sql.= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); - + // Multicurrency $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice).""; $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; - + $sql.= " WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::update", LOG_DEBUG); diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index 9407553f325..23a4cd67d37 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -135,7 +135,7 @@ if ($action == 'confirm_split' && GETPOST("confirm") == 'yes') } } -if ($action == 'setremise') +if ($action == 'setremise' && $user->rights->societe->creer) { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) @@ -267,39 +267,48 @@ if ($socid > 0) print ''.$langs->trans("CustomerAbsoluteDiscountAllUsers").''; print ''.$remise_all.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").''; - print ''.$langs->trans("CustomerAbsoluteDiscountMy").''; - print ''.$remise_user.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").''; + if (! empty($user->fk_soc)) // No need to show this for external users + { + print ''.$langs->trans("CustomerAbsoluteDiscountMy").''; + print ''.$remise_user.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").''; + } print ''; - print '
'; - - print load_fiche_titre($langs->trans("NewGlobalDiscount"),'',''); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print "
'.$langs->trans("AmountHT").''; - print ' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("VAT").''; - print $form->load_tva('tva_tx',GETPOST('tva_tx'),$mysoc,$object); - print '
'.$langs->trans("NoteReason").'
"; + if ($user->rights->societe->creer) + { + print '
'; + + print load_fiche_titre($langs->trans("NewGlobalDiscount"),'',''); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print "
'.$langs->trans("AmountHT").''; + print ' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("VAT").''; + print $form->load_tva('tva_tx',GETPOST('tva_tx'),$mysoc,$object); + print '
'.$langs->trans("NoteReason").'
"; + } print '
'; dol_fiche_end(); - print '
'; - print ''; - if (! empty($backtopage)) - { - print '     '; - print ''; + if ($user->rights->societe->creer) + { + print '
'; + print ''; + if (! empty($backtopage)) + { + print '     '; + print ''; + } + print '
'; } - print '
'; - print ''; + print ''; print '
'; @@ -425,7 +434,7 @@ if ($socid > 0) print '
'; /* - * Liste ristournes appliquees (=liees a une ligne de facture ou facture) + * List discount consumed (=liees a une ligne de facture ou facture) */ // Remises liees a lignes de factures diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index f3240443a6e..d91ee35fe3e 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -523,7 +523,7 @@ if (empty($reshook)) else if ($action == 'setmode' && $user->rights->commande->creer) { $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); if ($result < 0) - dol_print_error($db, $object->error); + setEventMessages($object->error, $object->errors, 'errors'); } // Multicurrency Code @@ -539,13 +539,13 @@ if (empty($reshook)) else if ($action == 'setavailability' && $user->rights->commande->creer) { $result = $object->availability(GETPOST('availability_id')); if ($result < 0) - dol_print_error($db, $object->error); + setEventMessages($object->error, $object->errors, 'errors'); } else if ($action == 'setdemandreason' && $user->rights->commande->creer) { $result = $object->demand_reason(GETPOST('demand_reason_id')); if ($result < 0) - dol_print_error($db, $object->error); + setEventMessages($object->error, $object->errors, 'errors'); } else if ($action == 'setconditions' && $user->rights->commande->creer) { diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 6f14d407a5d..523efb99cae 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -57,98 +57,100 @@ class Commande extends CommonOrder * Client ID * @var int */ - var $socid; + public $socid; - var $ref_client; - var $ref_int; - var $contactid; + public $ref_client; + public $ref_int; + public $contactid; /** * Status of the order. Check the following constants: * @var int * @see Commande::STATUS_CANCELED, Commande::STATUS_DRAFT, Commande::STATUS_ACCEPTED, Commande::STATUS_CLOSED */ - var $statut; + public $statut; /** * @deprecated * @see billed */ - var $facturee; - var $billed; // billed or not + public $facturee; + public $billed; // billed or not - var $brouillon; - var $cond_reglement_code; + public $brouillon; + public $cond_reglement_code; - var $fk_account; + public $fk_account; /** * It holds the label of the payment mode. Use it in case translation cannot be found. * @var string */ - var $mode_reglement; + public $mode_reglement; /** * Payment mode id * @var int */ - var $mode_reglement_id; + public $mode_reglement_id; /** * Payment mode code * @var string */ - var $mode_reglement_code; + public $mode_reglement_code; /** * Availability delivery time id * @var int */ - var $availability_id; + public $availability_id; /** * Availability delivery time code * @var string */ - var $availability_code; + public $availability_code; /** * Label of availability delivery time. Use it in case translation cannot be found. * @var string */ - var $availability; + public $availability; - var $demand_reason_id; - var $demand_reason_code; - var $address; - var $date; // Date commande + public $demand_reason_id; + public $demand_reason_code; + public $address; + public $date; // Date commande /** * @deprecated * @see date */ - var $date_commande; - var $date_livraison; // Date livraison souhaitee - var $fk_remise_except; - var $remise_percent; - var $remise_absolue; - var $info_bits; - var $rang; - var $special_code; - var $source; // Origin of order - var $extraparams=array(); + public $date_commande; + public $date_livraison; // Date livraison souhaitee + public $fk_remise_except; + public $remise_percent; + public $remise_absolue; + public $info_bits; + public $rang; + public $special_code; + public $source; // Origin of order + public $extraparams=array(); - var $linked_objects=array(); + public $linked_objects=array(); - var $user_author_id; + public $user_author_id; /** * @var OrderLine[] */ - var $lines = array(); + public $lines = array(); // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; - + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; + + public $oldcopy; + /** * ERR Not enough stock */ @@ -450,7 +452,7 @@ class Commande extends CommonOrder if (! empty($conf->stock->enabled) && $conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER == 1) { $result = 0; - + require_once DOL_DOCUMENT_ROOT.'/product/stock/class/mouvementstock.class.php'; $langs->load("agenda"); @@ -469,10 +471,10 @@ class Commande extends CommonOrder if (!$error) { // Call trigger - $result=$this->call_trigger('ORDER_SETDRAFT',$user); + $result=$this->call_trigger('ORDER_UNVALIDATE',$user); if ($result < 0) $error++; } - + if (!$error) { $this->statut=self::STATUS_DRAFT; $this->db->commit(); @@ -701,7 +703,7 @@ class Commande extends CommonOrder // Clean parameters $this->brouillon = 1; // set command as draft - + // 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); @@ -711,7 +713,7 @@ class Commande extends CommonOrder $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } - + dol_syslog(get_class($this)."::create user=".$user->id); // Check parameters @@ -1231,7 +1233,7 @@ class Commande extends CommonOrder if (empty($txlocaltax2)) $txlocaltax2=0; if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0; if (empty($this->fk_multicurrency)) $this->fk_multicurrency=0; - + $remise_percent=price2num($remise_percent); $qty=price2num($qty); $pu_ht=price2num($pu_ht); @@ -1281,7 +1283,7 @@ class Commande extends CommonOrder $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty,$mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; @@ -1294,7 +1296,7 @@ class Commande extends CommonOrder $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Rang to use $rangtouse = $rang; if ($rangtouse == -1) @@ -1596,7 +1598,7 @@ class Commande extends CommonOrder $this->multicurrency_total_ht = $obj->multicurrency_total_ht; $this->multicurrency_total_tva = $obj->multicurrency_total_tva; $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - + $this->extraparams = (array) json_decode($obj->extraparams, true); $this->lines = array(); @@ -1787,7 +1789,7 @@ class Commande extends CommonOrder $line->product_desc = $objp->product_desc; $line->fk_product_type = $objp->fk_product_type; // Produit ou service $line->fk_unit = $objp->fk_unit; - + $line->weight = $objp->weight; $line->weight_units = $objp->weight_units; $line->volume = $objp->volume; @@ -1803,7 +1805,7 @@ class Commande extends CommonOrder $line->multicurrency_total_ht = $objp->multicurrency_total_ht; $line->multicurrency_total_tva = $objp->multicurrency_total_tva; $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc; - + $this->lines[$i] = $line; $i++; @@ -1854,7 +1856,7 @@ class Commande extends CommonOrder /** * Load array this->expeditions of lines of shipments with nb of products sent for each order line * Note: For a dedicated shipment, the fetch_lines can be used to load the qty_asked and qty_shipped. This function is use to return qty_shipped cumulated for the order - * + * * @param int $filtre_statut Filter on shipment status * @return int <0 if KO, Nb of lines found if OK */ @@ -2044,30 +2046,62 @@ class Commande extends CommonOrder * * @param User $user User qui positionne la remise * @param float $remise Discount (percent) + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_remise($user, $remise) + function set_remise($user, $remise, $notrigger=0) { $remise=trim($remise)?trim($remise):0; if ($user->rights->commande->creer) { + $error=0; + + $this->db->begin(); + $remise=price2num($remise); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql.= ' SET remise_percent = '.$remise; $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;'; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->remise_percent = $remise; - $this->update_price(1); - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->remise_percent = $remise; + $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -2078,32 +2112,62 @@ class Commande extends CommonOrder * * @param User $user User qui positionne la remise * @param float $remise Discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_remise_absolue($user, $remise) + function set_remise_absolue($user, $remise, $notrigger=0) { $remise=trim($remise)?trim($remise):0; if ($user->rights->commande->creer) { + $error=0; + + $this->db->begin(); + $remise=price2num($remise); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql.= ' SET remise_absolue = '.$remise; $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut = '.self::STATUS_DRAFT.' ;'; - dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG); - - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->remise_absolue = $remise; - $this->update_price(1); - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->remise_absolue = $remise; + $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -2112,29 +2176,59 @@ class Commande extends CommonOrder /** * Set the order date * - * @param User $user Object user making change - * @param int $date Date - * @return int <0 if KO, >0 if OK + * @param User $user Object user making change + * @param int $date Date + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function set_date($user, $date) + function set_date($user, $date, $notrigger=0) { if ($user->rights->commande->creer) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql.= " SET date_commande = ".($date ? $this->db->idate($date) : 'null'); $sql.= " WHERE rowid = ".$this->id." AND fk_statut = ".self::STATUS_DRAFT; - dol_syslog(get_class($this)."::set_date",LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $resql=$this->db->query($sql); - if ($resql) + if (!$resql) { - $this->date = $date; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->date = $date; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else @@ -2146,29 +2240,59 @@ class Commande extends CommonOrder /** * Set the planned delivery date * - * @param User $user Objet utilisateur qui modifie + * @param User $user Objet utilisateur qui modifie * @param int $date_livraison Date de livraison - * @return int <0 si ko, >0 si ok + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 si ko, >0 si ok */ - function set_date_livraison($user, $date_livraison) + function set_date_livraison($user, $date_livraison, $notrigger=0) { if ($user->rights->commande->creer) { + $error=0; + + $this->db->begin(); + $sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql.= " SET date_livraison = ".($date_livraison ? "'".$this->db->idate($date_livraison)."'" : 'null'); $sql.= " WHERE rowid = ".$this->id; - dol_syslog(get_class($this)."::set_date_livraison", LOG_DEBUG); + dol_syslog(__METHOD__, LOG_DEBUG); $resql=$this->db->query($sql); - if ($resql) + if (!$resql) { - $this->date_livraison = $date_livraison; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->date_livraison = $date_livraison; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else @@ -2177,64 +2301,6 @@ class Commande extends CommonOrder } } - /** - * Set availability - * - * @param User $user Object user making change - * @param int $id If of availability delay - * @return int <0 if KO, >0 if OK - */ - function set_availability($user, $id) - { - if ($user->rights->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande "; - $sql.= " SET fk_availability = '".$id."'"; - $sql.= " WHERE rowid = ".$this->id; - - if ($this->db->query($sql)) - { - $this->fk_availability = $id; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_availability Erreur SQL"); - return -1; - } - } - } - - /** - * Set source of demand - * - * @param User $user Object user making change - * @param int $id Id of source - * @return int <0 if KO, >0 if OK - */ - function set_demand_reason($user, $id) - { - if ($user->rights->commande->creer) - { - $sql = "UPDATE ".MAIN_DB_PREFIX."commande "; - $sql.= " SET fk_input_reason = '".$id."'"; - $sql.= " WHERE rowid = ".$this->id; - - if ($this->db->query($sql)) - { - $this->fk_input_reason = $id; - return 1; - } - else - { - $this->error=$this->db->error(); - dol_syslog(get_class($this)."::set_demand_reason Erreur SQL"); - return -1; - } - } - } - /** * Return list of orders (eventuelly filtered on a user) into an array * @@ -2309,69 +2375,141 @@ class Commande extends CommonOrder } /** - * Change le delai de livraison + * Update delivery delay * * @param int $availability_id Id du nouveau mode + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int >0 if OK, <0 if KO */ - function availability($availability_id) + function availability($availability_id, $notrigger=0) { + global $user; + dol_syslog('Commande::availability('.$availability_id.')'); if ($this->statut >= self::STATUS_DRAFT) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql .= ' SET fk_availability = '.$availability_id; $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->availability_id = $availability_id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->availability_id = $availability_id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_syslog('Commande::availability Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else { - dol_syslog('Commande::availability, etat facture incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; + $error_str='Command status do not meet requirement '.$this->statut; + dol_syslog(__METHOD__.$error_str, LOG_ERR); + $this->error=$error_str; + $this->errors[]= $this->error; return -2; } } /** - * Change la source de la demande + * Update order demand_reason * * @param int $demand_reason_id Id of new demand + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int >0 if ok, <0 if ko */ - function demand_reason($demand_reason_id) + function demand_reason($demand_reason_id, $notrigger=0) { + global $user; + dol_syslog('Commande::demand_reason('.$demand_reason_id.')'); if ($this->statut >= self::STATUS_DRAFT) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande'; $sql .= ' SET fk_input_reason = '.$demand_reason_id; $sql .= ' WHERE rowid='.$this->id; - if ( $this->db->query($sql) ) + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->demand_reason_id = $demand_reason_id; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->demand_reason_id = $demand_reason_id; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - dol_syslog('Commande::demand_reason Erreur '.$sql.' - '.$this->db->error(), LOG_ERR); - $this->error=$this->db->lasterror(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else { - dol_syslog('Commande::demand_reason, etat facture incompatible', LOG_ERR); - $this->error='Etat commande incompatible '.$this->statut; + $error_str='order status do not meet requirement '.$this->statut; + dol_syslog(__METHOD__.$error_str, LOG_ERR); + $this->error=$error_str; + $this->errors[]= $this->error; return -2; } } @@ -2381,27 +2519,57 @@ class Commande extends CommonOrder * * @param User $user User that make change * @param string $ref_client Customer ref + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_ref_client($user, $ref_client) + function set_ref_client($user, $ref_client, $notrigger=0) { if ($user->rights->commande->creer) { - dol_syslog(get_class($this).'::set_ref_client this->id='.$this->id.', ref_client='.$ref_client); + $error=0; + + $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET'; $sql.= ' ref_client = '.(empty($ref_client) ? 'NULL' : '\''.$this->db->escape($ref_client).'\''); $sql.= ' WHERE rowid = '.$this->id; - if ($this->db->query($sql) ) + dol_syslog(__METHOD__.' this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { - $this->ref_client = $ref_client; - return 1; + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; + $this->ref_client = $ref_client; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return 1; } else { - $this->error=$this->db->lasterror(); - return -2; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } else @@ -2413,12 +2581,12 @@ class Commande extends CommonOrder /** * Classify the order as invoiced * - * @param User $user Object user making the change - * @return int <0 if KO, >0 if OK + * @param User $user Object user making the change + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function classifyBilled(User $user) + function classifyBilled(User $user, $notrigger=0) { - global $user; $error = 0; $this->db->begin(); @@ -2429,16 +2597,24 @@ class Commande extends CommonOrder dol_syslog(get_class($this)."::classifyBilled", LOG_DEBUG); if ($this->db->query($sql)) { - // Call trigger - $result=$this->call_trigger('ORDER_CLASSIFY_BILLED',$user); - if ($result < 0) $error++; - // End call triggers if (! $error) { + $this->oldcopy= clone $this; $this->facturee=1; // deprecated $this->billed=1; + } + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('ORDER_CLASSIFY_BILLED',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { $this->db->commit(); return 1; } @@ -2485,25 +2661,32 @@ class Commande extends CommonOrder { global $conf, $user, $langs; $error = 0; - + $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande SET facture = 0'; $sql.= ' WHERE rowid = '.$this->id.' AND fk_statut > '.self::STATUS_DRAFT; - + dol_syslog(get_class($this)."::classifyUnBilled", LOG_DEBUG); if ($this->db->query($sql)) { + if (! $error) + { + $this->oldcopy= clone $this; + $this->facturee=1; // deprecated + $this->billed=1; + } + // Call trigger $result=$this->call_trigger('ORDER_CLASSIFY_UNBILLED',$user); if ($result < 0) $error++; // End call triggers - + if (! $error) { $this->facturee=0; // deprecated $this->billed=0; - + $this->db->commit(); return 1; } @@ -2525,8 +2708,8 @@ class Commande extends CommonOrder return -1; } } - - + + /** * Update a line in database * @@ -2589,7 +2772,7 @@ class Commande extends CommonOrder $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty, $mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; @@ -2602,14 +2785,14 @@ class Commande extends CommonOrder $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Anciens indicateurs: $price, $subprice, $remise (a ne plus utiliser) $price = $pu; - if ($price_base_type == 'TTC') + if ($price_base_type == 'TTC') { $subprice = $tabprice[5]; - } - else + } + else { $subprice = $pu; } @@ -2691,7 +2874,7 @@ class Commande extends CommonOrder $this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; - + // TODO deprecated $this->line->price=$price; $this->line->remise=$remise; @@ -3310,7 +3493,7 @@ class Commande extends CommonOrder $prodid = mt_rand(1, $num_prods); $line->fk_product=$prodids[$prodid]; } - + $this->lines[$xnbp]=$line; $this->total_ht += $line->total_ht; @@ -3442,7 +3625,7 @@ class Commande extends CommonOrder return max($this->date_commande, $this->date_livraison) < ($now - $conf->commande->client->warning_delay); } - + /** * Show the customer delayed info * @@ -3451,11 +3634,11 @@ class Commande extends CommonOrder public function showDelay() { global $conf, $langs; - + if (empty($this->date_livraison)) $text=$langs->trans("OrderDate").' '.dol_print_date($this->date_commande, 'day'); else $text=$text=$langs->trans("DeliveryDate").' '.dol_print_date($this->date_livraison, 'day'); $text.=' '.($conf->commande->client->warning_delay>0?'+':'-').' '.round(abs($conf->commande->client->warning_delay)/3600/24,1).' '.$langs->trans("days").' < '.$langs->trans("Today"); - + return $text; } } @@ -3884,13 +4067,13 @@ class OrderLine extends CommonOrderLine $sql.= " , fk_parent_line=".(! empty($this->fk_parent_line)?$this->fk_parent_line:"null"); if (! empty($this->rang)) $sql.= ", rang=".$this->rang; $sql.= " , fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); - + // Multicurrency $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice).""; $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; - + $sql.= " WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::update", LOG_DEBUG); diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 47cee9903ef..3a062788059 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -48,6 +48,8 @@ $langs->load('companies'); $langs->load('compta'); $langs->load('bills'); +$action=GETPOST('action','alpha'); +$massaction=GETPOST('massaction','alpha'); $orderyear=GETPOST("orderyear","int"); $ordermonth=GETPOST("ordermonth","int"); $orderday=GETPOST("orderday","int"); @@ -70,6 +72,7 @@ $search_sale=GETPOST('search_sale','int'); $search_total_ht=GETPOST('search_total_ht','alpha'); $optioncss = GETPOST('optioncss','alpha'); $billed = GETPOST('billed','int'); +$toselect = GETPOST('toselect', 'array'); // Security check $id = (GETPOST('orderid')?GETPOST('orderid','int'):GETPOST('id','int')); @@ -183,6 +186,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $deliveryyear=''; $viewstatut=''; $billed=''; + $toselect=''; $search_array_options=array(); } @@ -201,6 +205,148 @@ if (empty($reshook)) $error++; } + // TODO Use a common inc.php file + if (! $error && $massaction == 'delete' && $user->rights->commande->supprimer) + { + $db->begin(); + + $objecttmp=new Commande($db); + $nbok = 0; + foreach($toselect as $toselectid) + { + $result=$objecttmp->fetch($toselectid); + if ($result > 0) + { + $result = $objecttmp->delete($user); + if ($result <= 0) + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + else $nbok++; + } + else + { + setEventMessages($objecttmp->error, $objecttmp->errors, 'errors'); + $error++; + break; + } + } + + if (! $error) + { + if ($nbok > 1) setEventMessages($langs->trans("RecordsDeleted", $nbok), null, 'mesgs'); + else setEventMessages($langs->trans("RecordDeleted", $nbok), null, 'mesgs'); + $db->commit(); + } + else + { + $db->rollback(); + } + //var_dump($listofobjectthirdparties);exit; + } + + if (! $error && $massaction == "builddoc" && $user->rights->commande->lire && ! GETPOST('button_search')) + { + 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 Commande($db); + $listofobjectid=array(); + $listofobjectthirdparties=array(); + $listofobjectref=array(); + foreach($toselect as $toselectid) + { + $objecttmp=new Commande($db); // must create new instance because instance is saved into $listofobjectref array for future use + $result=$objecttmp->fetch($toselectid); + if ($result > 0) + { + $listoinvoicesid[$toselectid]=$toselectid; + $thirdpartyid=$objecttmp->fk_soc?$objecttmp->fk_soc:$objecttmp->socid; + $listofobjectthirdparties[$thirdpartyid]=$thirdpartyid; + $listofobjectref[$toselectid]=$objecttmp->ref; + } + } + + $arrayofinclusion=array(); + foreach($listofobjectref as $tmppdf) $arrayofinclusion[]=preg_quote($tmppdf.'.pdf','/'); + $listoffiles = dol_dir_list($conf->commande->dir_output,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true); + + // build list of files with full path + $files = array(); + foreach($listofobjectref as $basename) + { + foreach($listoffiles as $filefound) + { + if (strstr($filefound["name"],$basename)) + { + $files[] = $conf->commande->dir_output.'/'.$basename.'/'.$filefound["name"]; + break; + } + } + } + + // 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)) $newlang=$object->thirdparty->default_lang; + if (! empty($newlang)) + { + $outputlangs = new Translate("",$conf); + $outputlangs->setDefaultLang($newlang); + } + + // Create empty PDF + $pdf=pdf_getInstance(); + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); + + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); + + // Add all others + foreach($files as $file) + { + // Charge un document PDF depuis un fichier. + $pagecount = $pdf->setSourceFile($file); + for ($i = 1; $i <= $pagecount; $i++) + { + $tplidx = $pdf->importPage($i); + $s = $pdf->getTemplatesize($tplidx); + $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L'); + $pdf->useTemplate($tplidx); + } + } + + // Create output dir if not exists + dol_mkdir($diroutputmassaction); + + // Save merged file + $filename=strtolower(dol_sanitizeFileName($langs->transnoentities("Orders"))); + if ($year) $filename.='_'.$year; + if ($month) $filename.='_'.$month; + if ($pagecount) + { + $now=dol_now(); + $file=$diroutputmassaction.'/'.$filename.'_'.dol_print_date($now,'dayhourlog').'.pdf'; + $pdf->Output($file,'F'); + 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'); + } + else + { + setEventMessages($langs->trans('NoPDFAvailableForDocGenAmongChecked'), null, 'errors'); + } + } } @@ -380,6 +526,8 @@ if ($resql) $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; @@ -408,8 +556,14 @@ if ($resql) if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } - //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); - + $arrayofmassactions = array( + //'presend'=>$langs->trans("SendByMail"), + //'builddoc'=>$langs->trans("PDFMerge"), + ); + if ($user->rights->commande->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete"); + if ($massaction == 'presend') $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); + // Lignes des champs de filtre print '
'; if ($optioncss != '') print ''; @@ -420,7 +574,7 @@ if ($resql) print ''; print ''; - print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit); + print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit); if ($sall) { @@ -657,7 +811,7 @@ if ($resql) } // Action column print ''; - $searchpitco=$form->showFilterAndCheckAddButtons(0); + $searchpitco=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1); print $searchpitco; print ''; @@ -1001,7 +1155,14 @@ if ($resql) } // Action column - print ''; + print ''; + if ($massactionbutton) + { + $selected=0; + if (in_array($obj->rowid, $arrayofselected)) $selected=1; + print ''; + } + print ''; if (! $i) $totalarray['nbfield']++; print ''; diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index 5ba06842c30..d4de4e5efb1 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -89,7 +89,8 @@ if ($_POST["action"] == 'add') $account->proprio = trim($_POST["proprio"]); $account->owner_address = trim($_POST["owner_address"]); - $account->account_number = GETPOST('account_number'); + $account_number = GETPOST('account_number','alpha'); + if ($account_number <= 0) { $account->account_number = ''; } else { $account->account_number = $account_number; } $account->accountancy_journal = trim($_POST["accountancy_journal"]); $account->solde = $_POST["solde"]; @@ -171,7 +172,8 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"]) $account->proprio = trim($_POST["proprio"]); $account->owner_address = trim($_POST["owner_address"]); - $account->account_number = GETPOST('account_number'); + $account_number = GETPOST('account_number', 'int'); + if ($account_number <= 0) { $account->account_number = ''; } else { $account->account_number = $account_number; } $account->accountancy_journal = trim($_POST["accountancy_journal"]); $account->currency_code = trim($_POST["account_currency_code"]); diff --git a/htdocs/compta/bank/ligne.php b/htdocs/compta/bank/ligne.php index 873d71de81b..f6709c4d1c5 100644 --- a/htdocs/compta/bank/ligne.php +++ b/htdocs/compta/bank/ligne.php @@ -83,13 +83,13 @@ if ($action == 'confirm_delete_categ' && $confirm == "yes" && $user->rights->ban if ($user->rights->banque->modifier && $action == 'class') { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid." AND fk_categ = ".$_POST["cat1"]; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid." AND fk_categ = ".GETPOST('cat1', 'int'); if (! $db->query($sql)) { dol_print_error($db); } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".$rowid.", ".$_POST["cat1"].")"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".$rowid.", ".GETPOST('cat1', 'int').")"; if (! $db->query($sql)) { dol_print_error($db); diff --git a/htdocs/compta/bank/treso.php b/htdocs/compta/bank/treso.php index 26be80caa68..e9596149e4f 100644 --- a/htdocs/compta/bank/treso.php +++ b/htdocs/compta/bank/treso.php @@ -3,6 +3,7 @@ * Copyright (C) 2008-2009 Laurent Destailleur (Eldy) * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2015 Marcos García * * 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 @@ -166,10 +167,12 @@ if ($_REQUEST["account"] || $_REQUEST["ref"]) // Social contributions $sql3= " SELECT 'social_contribution' as family, cs.rowid as objid, cs.libelle as ref, (-1*cs.amount) as total_ttc, ccs.libelle as type, cs.date_ech as dlr"; + $sql3.= ", cs.fk_account"; $sql3.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; $sql3.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as ccs ON cs.fk_type = ccs.id"; $sql3.= " WHERE cs.entity = ".$conf->entity; $sql3.= " AND cs.paye = 0"; // Not paid + $sql3.= " AND (cs.fk_account IN (0, ".$acct->id.") OR cs.fk_account IS NULL)"; // Id bank account of social contribution $sql3.= " ORDER BY dlr ASC"; $error=0; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 6535cee7c98..b2b39e375d7 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -438,7 +438,7 @@ if (empty($reshook)) } } } - + $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); @@ -1022,7 +1022,7 @@ if (empty($reshook)) dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines or deposit lines"); $result = $srcobject->fetch($object->origin_id); - + // If deposit invoice if ($_POST['type'] == Facture::TYPE_DEPOSIT) { @@ -1183,7 +1183,7 @@ if (empty($reshook)) $error ++; } } - + // Now we create same links to contact than the ones found on origin object if (! empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN)) { @@ -1196,13 +1196,13 @@ if (empty($reshook)) } $sqlcontact = "SELECT code, 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 = $db->query($sqlcontact); if ($resqlcontact) { while($objcontact = $db->fetch_object($resqlcontact)) { - //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n"; + //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n"; $object->add_contact($objcontact->fk_socpeople, $objcontact->code); } } @@ -1214,14 +1214,17 @@ if (empty($reshook)) $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook if ($reshook < 0) + { + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); $error++; + } } else { setEventMessages($object->error, $object->errors, 'errors'); $error++; } - } - else + } + else { // If some invoice's lines coming from page $id = $object->create($user); @@ -1393,7 +1396,7 @@ if (empty($reshook)) // Ecrase $txtva par celui du produit // Ecrase $base_price_type par celui du produit // Replaces $fk_unit with the product's - if (! empty($idprod)) + if (! empty($idprod)) { $prod = new Product($db); $prod->fetch($idprod); @@ -1404,7 +1407,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; @@ -1451,13 +1454,13 @@ if (empty($reshook)) } // 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 ($tva_tx != $prod->tva_tx) + elseif ($tva_tx != $prod->tva_tx) { - if ($price_base_type != 'HT') + if ($price_base_type != 'HT') { $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); } - else + else { $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU'); } @@ -1519,7 +1522,7 @@ if (empty($reshook)) // Local Taxes $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr); $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr); - + $info_bits = 0; if ($tva_npr) $info_bits |= 0x01; @@ -1623,7 +1626,7 @@ if (empty($reshook)) // Add buying price $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : ''); $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value - + // Extrafields $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); @@ -2082,7 +2085,7 @@ if ($action == 'create') $invoice_predefined->fetch(GETPOST('fac_rec','int')); $dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later - + $sql = 'SELECT r.rowid, r.titre, r.total_ttc'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_rec as r'; $sql .= ' WHERE r.fk_soc = ' . $invoice_predefined->socid; @@ -3087,7 +3090,7 @@ else if ($id > 0 || ! empty($ref)) // Remise dispo de type avoir if (! $absolute_discount) print '
'; - // $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer + // $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer $more=' ('.$addcreditnote.')'; $form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, 0, $more); // We allow credit note even if amount is higher } @@ -4038,7 +4041,7 @@ else if ($id > 0 || ! empty($ref)) print '
'; } } - + // Create a credit note if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut > 0 && $user->rights->facture->creer) { @@ -4193,7 +4196,7 @@ else if ($id > 0 || ! empty($ref)) { include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'inv'.$object->id); - } + } $formmail->withfrom = 1; $liste = array(); foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) { @@ -4213,7 +4216,7 @@ else if ($id > 0 || ! empty($ref)) $formmail->withdeliveryreceipt = 1; $formmail->withcancel = 1; // Tableau des substitutions - $formmail->setSubstitFromObject($object); + $formmail->setSubstitFromObject($object, $outputlangs); $formmail->substit['__INVREF__'] = $object->ref; // Find the good contact adress diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 73127f9a1f2..3b1bb17bfa7 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -59,63 +59,63 @@ class Facture extends CommonInvoice */ protected $table_ref_field = 'facnumber'; - var $socid; + public $socid; - var $author; - var $fk_user_author; - var $fk_user_valid; - var $date; // Date invoice - var $date_creation; // Creation date - var $date_validation; // Validation date - var $datem; - var $ref_client; - var $ref_int; + public $author; + public $fk_user_author; + public $fk_user_valid; + public $date; // Date invoice + public $date_creation; // Creation date + public $date_validation; // Validation date + public $datem; + public $ref_client; + public $ref_int; //Check constants for types - var $type = self::TYPE_STANDARD; + public $type = self::TYPE_STANDARD; //var $amount; - var $remise_absolue; - var $remise_percent; - var $total_ht=0; - var $total_tva=0; - var $total_ttc=0; - var $revenuestamp; + public $remise_absolue; + public $remise_percent; + public $total_ht=0; + public $total_tva=0; + public $total_ttc=0; + public $revenuestamp; //! Fermeture apres paiement partiel: discount_vat, badcustomer, abandon //! Fermeture alors que aucun paiement: replaced (si remplace), abandon - var $close_code; + public $close_code; //! Commentaire si mis a paye sans paiement complet - var $close_note; + public $close_note; //! 1 if invoice paid COMPLETELY, 0 otherwise (do not use it anymore, use statut and close_code) - var $paye; + public $paye; //! id of source invoice if replacement invoice or credit note - var $fk_facture_source; - var $linked_objects=array(); - var $date_lim_reglement; - var $cond_reglement_code; // Code in llx_c_paiement - var $mode_reglement_code; // Code in llx_c_paiement - var $fk_bank; // Field to store bank id to use when payment mode is withdraw + public $fk_facture_source; + public $linked_objects=array(); + public $date_lim_reglement; + public $cond_reglement_code; // Code in llx_c_paiement + public $mode_reglement_code; // Code in llx_c_paiement + public $fk_bank; // Field to store bank id to use when payment mode is withdraw /** * @deprecated */ - var $products=array(); + public $products=array(); /** * @var FactureLigne[] */ - var $lines=array(); - var $line; - var $extraparams=array(); - var $specimen; + public $lines=array(); + public $line; + public $extraparams=array(); + public $specimen; - var $fac_rec; + public $fac_rec; // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; /** * @var int Situation cycle reference number @@ -142,6 +142,8 @@ class Facture extends CommonInvoice */ public $tab_next_situation_invoice=array(); + public $oldcopy; + /** * Standard invoice */ @@ -1486,25 +1488,60 @@ class Facture extends CommonInvoice * Set customer ref * * @param string $ref_client Customer ref + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_ref_client($ref_client) + function set_ref_client($ref_client, $notrigger=0) { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; if (empty($ref_client)) $sql .= ' SET ref_client = NULL'; else $sql .= ' SET ref_client = \''.$this->db->escape($ref_client).'\''; $sql .= ' WHERE rowid = '.$this->id; - if ($this->db->query($sql)) + + dol_syslog(__METHOD__.' this->id='.$this->id.', ref_client='.$ref_client, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) + { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) { $this->ref_client = $ref_client; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('BILL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + + $this->ref_client = $ref_client; + + $this->db->commit(); return 1; } else { - dol_print_error($this->db); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } @@ -2070,7 +2107,7 @@ class Facture extends CommonInvoice $i++; } if ($final) { - $this->setFinal(); + $this->setFinal($user); } } } @@ -2760,9 +2797,10 @@ class Facture extends CommonInvoice * * @param User $user User that set discount * @param double $remise Discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if ko, >0 if ok */ - function set_remise($user, $remise) + function set_remise($user, $remise, $notrigger=0) { // Clean parameters if (empty($remise)) $remise=0; @@ -2771,21 +2809,48 @@ class Facture extends CommonInvoice { $remise=price2num($remise); + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; $sql.= ' SET remise_percent = '.$remise; $sql.= ' WHERE rowid = '.$this->id; $sql.= ' AND fk_statut = '.self::STATUS_DRAFT; - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) + { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('BILL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) { $this->remise_percent = $remise; $this->update_price(1); + + $this->db->commit(); return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -2796,14 +2861,19 @@ class Facture extends CommonInvoice * * @param User $user User that set discount * @param double $remise Discount + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function set_remise_absolue($user, $remise) + function set_remise_absolue($user, $remise, $notrigger=0) { if (empty($remise)) $remise=0; if ($user->rights->facture->creer) { + $error=0; + + $this->db->begin(); + $remise=price2num($remise); $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture'; @@ -2811,18 +2881,43 @@ class Facture extends CommonInvoice $sql.= ' WHERE rowid = '.$this->id; $sql.= ' AND fk_statut = '.self::STATUS_DRAFT; - dol_syslog(get_class($this)."::set_remise_absolue", LOG_DEBUG); - - if ($this->db->query($sql)) + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $error) + { + $this->oldcopy= clone $this; $this->remise_absolue = $remise; $this->update_price(1); + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('BILL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { + $this->db->commit(); return 1; } else { - $this->error=$this->db->error(); - return -1; + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; } } } @@ -3449,7 +3544,7 @@ class Facture extends CommonInvoice $clause = " WHERE"; - $sql = "SELECT f.rowid, f.date_lim_reglement as datefin"; + $sql = "SELECT f.rowid, f.date_lim_reglement as datefin,f.fk_statut"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f"; if (!$user->rights->societe->client->voir && !$user->societe_id) { @@ -3479,6 +3574,7 @@ class Facture extends CommonInvoice while ($obj=$this->db->fetch_object($resql)) { $generic_facture->date_lim_reglement = $this->db->jdate($obj->datefin); + $generic_facture->statut = $obj->fk_statut; $response->nbtodo++; @@ -3818,25 +3914,49 @@ class Facture extends CommonInvoice /** * Sets the invoice as a final situation * - * @return int 1 if ok, -1 if error + * @param User $user Object user + * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers + * @return int <0 if KO, >0 if OK */ - function setFinal() + function setFinal(User $user, $notrigger=0) { + $error=0; - $this->db->begin(); + $this->db->begin(); $this->situation_final = 1; - $sql = 'update ' . MAIN_DB_PREFIX . 'facture set situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id; - $resql = $this->db->query($sql); - if ($resql) { - // FIXME: call triggers MODIFY because we modify invoice + $sql = 'UPDATE ' . MAIN_DB_PREFIX . 'facture SET situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id; + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql=$this->db->query($sql); + if (!$resql) + { + $this->errors[]=$this->db->error(); + $error++; + } + + if (! $notrigger && empty($error)) + { + // Call trigger + $result=$this->call_trigger('BILL_MODIFY',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (! $error) + { $this->db->commit(); return 1; - } else { - $this->error = $this->db->lasterror(); - dol_syslog(get_class($this) . "::update Error setFinal " . $sql, LOG_ERR); + } + else + { + foreach($this->errors as $errmsg) + { + dol_syslog(__METHOD__.' Error: '.$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } $this->db->rollback(); - return -1; + return -1*$error; } } @@ -4005,6 +4125,10 @@ class FactureLigne extends CommonInvoiceLine $sql.= ' fd.fk_unit,'; $sql.= ' fd.situation_percent, fd.fk_prev_id,'; $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc'; + $sql.= ' , fd.multicurrency_subprice'; + $sql.= ' , fd.multicurrency_total_ht'; + $sql.= ' , fd.multicurrency_total_tva'; + $sql.= ' , fd.multicurrency_total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as fd'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON fd.fk_product = p.rowid'; $sql.= ' WHERE fd.rowid = '.$rowid; @@ -4055,6 +4179,11 @@ class FactureLigne extends CommonInvoiceLine $this->situation_percent = $objp->situation_percent; $this->fk_prev_id = $objp->fk_prev_id; + $this->multicurrency_subprice = $objp->multicurrency_subprice; + $this->multicurrency_total_ht = $objp->multicurrency_total_ht; + $this->multicurrency_total_tva= $objp->multicurrency_total_tva; + $this->multicurrency_total_ttc= $objp->multicurrency_total_ttc; + $this->db->free($result); return 1; @@ -4308,6 +4437,11 @@ class FactureLigne extends CommonInvoiceLine if (! isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') $this->situation_percent = 100; if (empty($this->pa_ht)) $this->pa_ht=0; + if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice=0; + if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht=0; + if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva=0; + if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc=0; + // Check parameters if ($this->product_type < 0) return -1; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 0e9c6874103..99103ee419a 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -205,12 +205,12 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter") || GETPOS $day=''; $year=''; $month=''; - $toselect=''; $option=''; $filter=''; $day_lim=''; $year_lim=''; $month_lim=''; + $toselect=''; $search_array_options=array(); } @@ -229,6 +229,7 @@ if (empty($reshook)) $error++; } + // TODO Use a common inc.php file if (! $error && $massaction == 'confirm_presend') { $resaction = ''; @@ -522,17 +523,17 @@ if (empty($reshook)) $arrayofinclusion=array(); foreach($listofobjectref as $tmppdf) $arrayofinclusion[]=preg_quote($tmppdf.'.pdf','/'); - $factures = dol_dir_list($conf->facture->dir_output,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true); + $listoffiles = dol_dir_list($conf->facture->dir_output,'all',1,implode('|',$arrayofinclusion),'\.meta$|\.png','date',SORT_DESC,0,true); - // liste les fichiers + // build list of files with full path $files = array(); foreach($listofobjectref as $basename) { - foreach($factures as $facture) + foreach($listoffiles as $filefound) { - if (strstr($facture["name"],$basename)) + if (strstr($filefound["name"],$basename)) { - $files[] = $conf->facture->dir_output.'/'.$basename.'/'.$facture["name"]; + $files[] = $conf->facture->dir_output.'/'.$basename.'/'.$filefound["name"]; break; } } @@ -831,7 +832,12 @@ if ($resql) if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); } - $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); + $arrayofmassactions=array( + 'presend'=>$langs->trans("SendByMail"), + 'builddoc'=>$langs->trans("PDFMerge") + ); + if ($massaction == 'presend') $arrayofmassactions=array(); + $massactionbutton=$form->selectMassAction('', $arrayofmassactions); $i = 0; print ''."\n"; @@ -843,7 +849,7 @@ if ($resql) print ''; print ''; - print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->name:''),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$massactionbutton,$num,$nbtotalofrecords,'title_accountancy.png',0,'','',$limit); + print_barre_liste($langs->trans('BillsCustomers').' '.($socid?' '.$soc->name:''), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy.png', 0, '', '', $limit); if ($massaction == 'presend') { @@ -1183,7 +1189,7 @@ if ($resql) } // Action column print ''; - $searchpitco=$form->showFilterAndCheckAddButtons(1, 'checkforselect', 1); + $searchpitco=$form->showFilterAndCheckAddButtons($massactionbutton?1:0, 'checkforselect', 1); print $searchpitco; print ''; print "\n"; @@ -1423,9 +1429,12 @@ if ($resql) // Action column print ''; - $selected=0; - if (in_array($obj->facid, $arrayofselected)) $selected=1; - print ''; + if ($massactionbutton) + { + $selected=0; + if (in_array($obj->facid, $arrayofselected)) $selected=1; + print ''; + } print '' ; if (! $i) $totalarray['nbfield']++; diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 1c167e04e95..35a56e5afb3 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -199,7 +199,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire) } else { - print ''.$langs->trans("NoInvoice").''; + print ''.$langs->trans("NoInvoice").''; } print "
"; $db->free($resql); @@ -275,7 +275,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture- } else { - print ''.$langs->trans("NoInvoice").''; + print ''.$langs->trans("NoInvoice").''; } print "
"; $db->free($resql); @@ -387,7 +387,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire) { $colspan=5; if (! empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; - print ''.$langs->trans("NoInvoice").''; + print ''.$langs->trans("NoInvoice").''; } print '
'; $db->free($resql); @@ -474,7 +474,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture- { $colspan=5; if (! empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; - print ''.$langs->trans("NoInvoice").''; + print ''.$langs->trans("NoInvoice").''; } print '
'; } @@ -842,7 +842,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire) { $colspan=6; if (! empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; - print ''.$langs->trans("NoInvoice").''; + print ''.$langs->trans("NoInvoice").''; } print '
'; $db->free($resql); @@ -942,7 +942,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture- { $colspan=6; if (! empty($conf->global->MAIN_SHOW_HT_ON_SUMMARY)) $colspan++; - print ''.$langs->trans("NoInvoice").''; + print ''.$langs->trans("NoInvoice").''; } print '
'; } diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index fa1341dcbc6..a9414fcafeb 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -33,6 +33,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $langs->load('companies'); $langs->load('bills'); @@ -518,11 +519,21 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie * List of unpaid invoices */ $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.multicurrency_total_ttc, f.type, '; - $sql.= ' f.datef as df'; + $sql.= ' f.datef as df, f.fk_soc as socid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - $sql.= ' WHERE f.entity = '.$conf->entity; - $sql.= ' AND f.fk_soc = '.$facture->socid; - $sql.= ' AND f.paye = 0'; + + if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)'; + } + + $sql.= ' WHERE f.entity = '.$conf->entity; + $sql.= ' AND (f.fk_soc = '.$facture->socid; + + if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { + $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')'; + } + + $sql.= ') AND f.paye = 0'; $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled if ($facture->type != 2) { @@ -583,6 +594,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $objp = $db->fetch_object($resql); $var=!$var; + $soc = new Societe($db); + $soc->fetch($objp->socid); + $invoice=new Facture($db); $invoice->fetch($objp->facid); $paiement = $invoice->getSommePaiement(); @@ -605,6 +619,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; print $invoice->getNomUrl(1,''); + if($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' '; print "\n"; // Date diff --git a/htdocs/compta/paiement_charge.php b/htdocs/compta/paiement_charge.php index a68f3445305..06a32c3865f 100644 --- a/htdocs/compta/paiement_charge.php +++ b/htdocs/compta/paiement_charge.php @@ -1,5 +1,6 @@ + * Copyright (C) 2016 Frédéric France * * 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 @@ -159,6 +160,8 @@ if ($_GET["action"] == 'create') $charge = new ChargeSociales($db); $charge->fetch($chid); + $charge->accountid=$charge->fk_account?$charge->fk_account:$charge->accountid; + $charge->paiementtype=$charge->mode_reglement_id?$charge->mode_reglement_id:$charge->paiementtype; $total = $charge->amount; @@ -178,16 +181,16 @@ if ($_GET["action"] == 'create') dol_fiche_head('', ''); - print ''; + print '
'; - print ""; + print ""; - print ''; - print '\n"; - print '\n"; - print '\n"; - print '\n"; - print ''; + print ''; + print '\n"; + print '\n"; + print '\n"; + print '\n"; + print ''; $sql = "SELECT sum(p.amount) as total"; $sql.= " FROM ".MAIN_DB_PREFIX."paiementcharge as p"; @@ -199,28 +202,28 @@ if ($_GET["action"] == 'create') $sumpaid = $obj->total; $db->free(); } - print ''; - print ''; + print ''; + print ''; print ''; - print "'; + print "'; print ''; - print '"; print ''; - print '\n"; print ''; print ''; print ''; - print ''; @@ -228,11 +231,11 @@ if ($_GET["action"] == 'create') print ''; - print ''."\n"; + print ''."\n"; print ''; print ''; - print ''; + print ''; print ''; print '
".$langs->trans("SocialContribution")."
".$langs->trans("SocialContribution")."
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("Type")."".$charge->type_libelle."
'.$langs->trans("Period")."".dol_print_date($charge->periode,'day')."
'.$langs->trans("Label").''.$charge->lib."
'.$langs->trans("DateDue")."".dol_print_date($charge->date_ech,'day')."
'.$langs->trans("Amount")."".price($charge->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("Ref").''.$chid.'
'.$langs->trans("Type")."".$charge->type_libelle."
'.$langs->trans("Period")."".dol_print_date($charge->periode,'day')."
'.$langs->trans("Label").''.$charge->lib."
'.$langs->trans("DateDue")."".dol_print_date($charge->date_ech,'day')."
'.$langs->trans("Amount")."".price($charge->amount,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("AlreadyPaid").''.price($sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
'.$langs->trans("RemainderToPay").''.price($total-$sumpaid,0,$outputlangs,1,-1,-1,$conf->currency).'
".$langs->trans("Payment").'".$langs->trans("Payment").'
'.$langs->trans("Date").''; + print '
'.$langs->trans("Date").''; $datepaye = dol_mktime(12, 0, 0, $_POST["remonth"], $_POST["reday"], $_POST["reyear"]); $datepayment=empty($conf->global->MAIN_AUTOFILL_DATE)?(empty($_POST["remonth"])?-1:$datepaye):0; $form->select_date($datepayment,'','','','',"add_payment",1,1); print "
'.$langs->trans("PaymentMode").''; + print '
'.$langs->trans("PaymentMode").''; $form->select_types_paiements(isset($_POST["paiementtype"])?$_POST["paiementtype"]:$charge->paiementtype, "paiementtype"); print "
'.$langs->trans('AccountToDebit').''; + print ''; $form->select_comptes(isset($_POST["accountid"])?$_POST["accountid"]:$charge->accountid, "accountid", 0, '',1); // Show opend bank account list print '
'.$langs->trans('Numero'); print ' ('.$langs->trans("ChequeOrTransferNumber").')'; print '
'.$langs->trans("Comments").'
'; diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index 6e7c9ad93c2..f5a6cc2f6a9 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -1,6 +1,7 @@ * Copyright (C) 2005-2013 Regis Houssin + * Copyright (C) 2016 Frédéric France * * 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 @@ -71,6 +72,23 @@ if ($action == 'reopen' && $user->rights->tax->charges->creer) { } } +// payment mode +if ($action == 'setmode' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); + if ($result < 0) + setEventMessages($object->error, $object->errors, 'errors'); +} + +// bank account +if ($action == 'setbankaccount' && $user->rights->tax->charges->creer) { + $object->fetch($id); + $result=$object->setBankAccount(GETPOST('fk_account', 'int')); + if ($result < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } +} + // Delete social contribution if ($action == 'confirm_delete' && $confirm == 'yes') { @@ -127,6 +145,8 @@ if ($action == 'add' && $user->rights->tax->charges->creer) $object->date_ech=$dateech; $object->periode=$dateperiod; $object->amount=$amount; + $object->mode_reglement_id = GETPOST('mode_reglement_id'); + $object->fk_account = GETPOST('fk_account', 'int'); $id=$object->create($user); if ($id <= 0) @@ -290,6 +310,17 @@ if ($action == 'create') print ''; print ''; print ''; + // Payment Mode + print '' . $langs->trans('PaymentMode') . ''; + $form->select_types_paiements($mode_reglement_id, 'mode_reglement_id'); + print ''; + // Bank Account + if (! empty($conf->banque->enabled)) + { + print '' . $langs->trans('BankAccount') . ''; + $form->select_comptes($fk_account, 'fk_account', 0, '', 1); + print ''; + } // Date due print ''; print ''; @@ -313,7 +344,7 @@ if ($action == 'create') /* *************************************************************************** */ /* */ -/* Mode fiche */ +/* Card Mode */ /* */ /* *************************************************************************** */ if ($id > 0) @@ -382,7 +413,8 @@ if ($id > 0) // Type print "".$langs->trans("Type")."".$object->type_libelle.""; - $rowspan=5; + $rowspan=6; + if (! empty($conf->banque->enabled)) $rowspan++; print ''; /* @@ -422,8 +454,8 @@ if ($id > 0) print ""; print ''.img_object($langs->trans("Payment"),"payment").' '.$objp->rowid.''; print ''.dol_print_date($db->jdate($objp->dp),'day')."\n"; - $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type; - print "".$labeltype.' '.$objp->num_paiement."\n"; + $labeltype=$langs->trans("PaymentType".$objp->type_code)!=("PaymentType".$objp->type_code)?$langs->trans("PaymentType".$objp->type_code):$objp->paiement_type; + print "".$labeltype.' '.$objp->num_paiement."\n"; print ''.price($objp->amount)." ".$langs->trans("Currency".$conf->currency)."\n"; print ""; $totalpaye += $objp->amount; @@ -432,12 +464,12 @@ if ($id > 0) if ($object->paye == 0) { - print "".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."\n"; - print "".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."\n"; + print "".$langs->trans("AlreadyPaid")." :".price($totalpaye)." ".$langs->trans("Currency".$conf->currency)."\n"; + print "".$langs->trans("AmountExpected")." :".price($object->amount)." ".$langs->trans("Currency".$conf->currency)."\n"; $resteapayer = $object->amount - $totalpaye; - print "".$langs->trans("RemainderToPay")." :"; + print "".$langs->trans("RemainderToPay")." :"; print "".price($resteapayer)." ".$langs->trans("Currency".$conf->currency)."\n"; } print ""; @@ -486,6 +518,42 @@ if ($id > 0) print ''.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).''; } + // Mode of payment + print ''; + print ''; + if ($action != 'editmode') + print ''; + print '
'; + print $langs->trans('PaymentMode'); + print 'id . '">' . img_edit($langs->trans('SetMode'), 1) . '
'; + print ''; + if ($action == 'editmode') { + $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id'); + } else { + $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->mode_reglement_id, 'none'); + } + print ''; + + // Bank Account + if (! empty($conf->banque->enabled)) + { + print ''; + print ''; + print '
'; + print $langs->trans('BankAccount'); + print ''; + if ($action != 'editbankaccount' && $user->rights->tax->charges->creer) + print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; + print ''; + if ($action == 'editbankaccount') { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1); + } else { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none'); + } + print ''; + print ''; + } + // Status print ''.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).''; @@ -500,7 +568,7 @@ if ($id > 0) print ''; print '   '; print ''; - print ''; } if ($action == 'edit') print "\n"; diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index e5653ba2ee3..af3acbf4c7f 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -1,6 +1,7 @@ * Copyright (C) 2004-2007 Laurent Destailleur + * Copyright (C) 2016 Frédéric France * * 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 @@ -49,6 +50,7 @@ class ChargeSociales extends CommonObject var $date_creation; var $date_modification; var $date_validation; + var $fk_account; /** @@ -71,13 +73,16 @@ class ChargeSociales extends CommonObject */ function fetch($id, $ref='') { - $sql = "SELECT cs.rowid, cs.date_ech,"; - $sql.= " cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, cs.periode, cs.import_key,"; - $sql.= " c.libelle"; - $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs, ".MAIN_DB_PREFIX."c_chargesociales as c"; - $sql.= " WHERE cs.fk_type = c.id"; - if ($ref) $sql.= " AND cs.rowid = ".$ref; - else $sql.= " AND cs.rowid = ".$id; + $sql = "SELECT cs.rowid, cs.date_ech"; + $sql.= ", cs.libelle as lib, cs.fk_type, cs.amount, cs.paye, cs.periode, cs.import_key"; + $sql.= ", cs.fk_account, cs.fk_mode_reglement"; + $sql.= ", c.libelle"; + $sql.= ', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle'; + $sql.= " FROM ".MAIN_DB_PREFIX."chargesociales as cs"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_chargesociales as c ON cs.fk_type = c.id"; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as p ON cs.fk_mode_reglement = p.id'; + if ($ref) $sql.= " WHERE cs.rowid = ".$ref; + else $sql.= " WHERE cs.rowid = ".$id; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql=$this->db->query($sql); @@ -93,6 +98,10 @@ class ChargeSociales extends CommonObject $this->lib = $obj->lib; $this->type = $obj->fk_type; $this->type_libelle = $obj->libelle; + $this->fk_account = $obj->fk_account; + $this->mode_reglement_id = $obj->fk_mode_reglement; + $this->mode_reglement_code = $obj->mode_reglement_code; + $this->mode_reglement = $obj->mode_reglement_libelle; $this->amount = $obj->amount; $this->paye = $obj->paye; $this->periode = $this->db->jdate($obj->periode); @@ -155,8 +164,11 @@ class ChargeSociales extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, libelle, date_ech, periode, amount, entity)"; - $sql.= " VALUES (".$this->type.",'".$this->db->escape($this->lib)."',"; + $sql = "INSERT INTO ".MAIN_DB_PREFIX."chargesociales (fk_type, fk_account, fk_mode_reglement, libelle, date_ech, periode, amount, entity)"; + $sql.= " VALUES (".$this->type; + $sql.= ", ".($this->fk_account>0?$this->fk_account:'NULL'); + $sql.= ", ".($this->mode_reglement_id>0?"'".$this->mode_reglement_id."'":"NULL"); + $sql.= ", '".$this->db->escape($this->lib)."',"; $sql.= " '".$this->db->idate($this->date_ech)."','".$this->db->idate($this->periode)."',"; $sql.= " '".price2num($newamount)."',"; $sql.= " ".$conf->entity; @@ -216,7 +228,7 @@ class ChargeSociales extends CommonObject // Delete payments if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge where fk_charge='".$this->id."'"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."paiementcharge WHERE fk_charge='".$this->id."'"; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) @@ -228,7 +240,7 @@ class ChargeSociales extends CommonObject if (! $error) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales where rowid='".$this->id."'"; + $sql = "DELETE FROM ".MAIN_DB_PREFIX."chargesociales WHERE rowid='".$this->id."'"; dol_syslog(get_class($this)."::delete", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) diff --git a/htdocs/compta/sociales/index.php b/htdocs/compta/sociales/index.php index b673a5064ed..15ca799c1c2 100644 --- a/htdocs/compta/sociales/index.php +++ b/htdocs/compta/sociales/index.php @@ -2,6 +2,7 @@ /* Copyright (C) 2001-2003 Rodolphe Quiedeville * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2016 Frédéric France * * 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 @@ -255,7 +256,7 @@ if ($resql) // Due date print ''.dol_print_date($db->jdate($obj->date_ech), 'day').''; - print ''.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).''; + print ''.$chargesociale_static->LibStatut($obj->paye,5,$obj->alreadypayed).''; print ''; diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index a2232358a99..77a951eef06 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -904,7 +904,7 @@ else // Statut print ''.$langs->trans("Status").''; - print ''; + print ''; print $object->getLibStatut(4); print ''; diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 259918c5aa9..78752bdba03 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -957,39 +957,53 @@ class Contact extends CommonObject */ function getNomUrl($withpicto=0,$option='',$maxlen=0,$moreparam='') { - global $conf, $langs; + global $conf, $langs, $hookmanager; $result=''; - $label = '' . $langs->trans("ShowContact") . ''; - $label.= '
' . $langs->trans("Name") . ': '.$this->getFullName($langs); - //if ($this->civility_id) $label.= '
' . $langs->trans("Civility") . ': '.$this->civility_id; // TODO Translate cibilty_id code - if (! empty($this->poste)) $label.= '
' . $langs->trans("Poste") . ': '.$this->poste; - $label.= '
' . $langs->trans("EMail") . ': '.$this->email; - $phonelist=array(); - if ($this->phone_pro) $phonelist[]=$this->phone_pro; - if ($this->phone_mobile) $phonelist[]=$this->phone_mobile; - if ($this->phone_perso) $phonelist[]=$this->phone_perso; - $label.= '
' . $langs->trans("Phone") . ': '.join(', ',$phonelist); - $label.= '
' . $langs->trans("Address") . ': '.dol_format_address($this, 1, ' ', $langs); + $label = '' . $langs->trans("ShowContact") . ''; + $label.= '
' . $langs->trans("Name") . ': '.$this->getFullName($langs); + //if ($this->civility_id) $label.= '
' . $langs->trans("Civility") . ': '.$this->civility_id; // TODO Translate cibilty_id code + if (! empty($this->poste)) $label.= '
' . $langs->trans("Poste") . ': '.$this->poste; + $label.= '
' . $langs->trans("EMail") . ': '.$this->email; + $phonelist=array(); + if ($this->phone_pro) $phonelist[]=$this->phone_pro; + if ($this->phone_mobile) $phonelist[]=$this->phone_mobile; + if ($this->phone_perso) $phonelist[]=$this->phone_perso; + $label.= '
' . $langs->trans("Phone") . ': '.join(', ',$phonelist); + $label.= '
' . $langs->trans("Address") . ': '.dol_format_address($this, 1, ' ', $langs); + + $link = 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label=$langs->trans("ShowContact"); + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose.= ' class="classfortooltip">'; - $link = 'global->MAIN_OPTIMIZEFORTEXTBROWSER)) - { - $label=$langs->trans("ShowContact"); - $link.=' alt="'.dol_escape_htmltag($label, 1).'"'; - } - $link.= ' title="'.dol_escape_htmltag($label, 1).'"'; - $link.= ' class="classfortooltip">'; + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('contactdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $linkclose = $hookmanager->resPrint; + + $link.=$linkclose; + $linkend=''; - + if ($option == 'xxx') { $link = ''; $linkend=''; } - - if ($withpicto) $result.=($link.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' '); - $result.=$link.($maxlen?dol_trunc($this->getFullName($langs),$maxlen):$this->getFullName($langs)).$linkend; + + if ($withpicto) $result.=($link.img_object($label, 'contact', 'class="classfortooltip"').$linkend.' '); + $result.=$link.($maxlen?dol_trunc($this->getFullName($langs),$maxlen):$this->getFullName($langs)).$linkend; return $result; } diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index a66c1dab946..5504d43671c 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -57,6 +57,8 @@ $search_email=GETPOST("search_email"); $search_skype=GETPOST("search_skype"); $search_priv=GETPOST("search_priv"); $search_categ=GETPOST("search_categ",'int'); +$search_categ_thirdparty=GETPOST("search_categ_thirdparty",'int'); +$search_categ_supplier=GETPOST("search_categ_supplier",'int'); $search_status=GETPOST("search_status",'int'); $search_type=GETPOST('search_type','alpha'); if ($search_status=='') $search_status=1; // always display activ customer first @@ -191,6 +193,10 @@ if (GETPOST('button_removefilter_x') || GETPOST('button_removefilter.x') || GETP $search_skype=""; $search_priv=""; $search_status=-1; + $search_categ=''; + $search_categ_thirdparty=''; + $search_categ_supplier=''; + $search_array_options=array(); } if ($search_priv < 0) $search_priv=''; @@ -220,7 +226,9 @@ $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as p"; if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as ef on (p.rowid = ef.fk_object)"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc"; -if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_contact as cs ON p.rowid = cs.fk_socpeople"; // We need this table joined to the select in order to filter by categ +if (! empty($search_categ)) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_contact as cc ON p.rowid = cc.fk_socpeople"; // We need this table joined to the select in order to filter by categ +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).')'; if (!$user->rights->societe->client->voir && !$socid) //restriction @@ -243,8 +251,12 @@ else if ($search_priv == '1') $sql .= " AND (p.priv='1' AND p.fk_user_creat=".$user->id.")"; } -if ($search_categ > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ); -if ($search_categ == -2) $sql.= " AND cs.fk_categorie IS NULL"; +if ($search_categ > 0) $sql.= " AND cc.fk_categorie = ".$db->escape($search_categ); +if ($search_categ == -2) $sql.= " AND cc.fk_categorie IS NULL"; +if ($search_categ_thirdparty > 0) $sql.= " AND cs.fk_categorie = ".$db->escape($search_categ_thirdparty); +if ($search_categ_thirdparty == -2) $sql.= " AND cs.fk_categorie IS NULL"; +if ($search_categ_supplier > 0) $sql.= " AND cs2.fk_categorie = ".$db->escape($search_categ_supplier); +if ($search_categ_supplier == -2) $sql.= " AND cs2.fk_categorie IS NULL"; if ($search_firstlast_only) { $sql .= natural_search(array('p.lastname','p.firstname'), $search_firstlast_only); @@ -333,7 +345,7 @@ $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // No $sql.=$hookmanager->resPrint; // Add order -if($view == "recent") +if ($view == "recent") { $sql.= $db->order("p.datec","DESC"); } @@ -350,15 +362,7 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $nbtotalofrecords = $db->num_rows($result); } -// Add limit -if($view == "recent") -{ - $sql.= $db->plimit($limit+1, $offset); -} -else -{ - $sql.= $db->plimit($limit+1, $offset); -} +$sql.= $db->plimit($limit+1, $offset); //print $sql; dol_syslog("contact/list.php", LOG_DEBUG); @@ -374,6 +378,8 @@ if ($result) $param.='&begin='.urlencode($begin).'&view='.urlencode($view).'&userid='.urlencode($userid).'&contactname='.urlencode($sall); $param.='&type='.urlencode($type).'&view='.urlencode($view); if (!empty($search_categ)) $param.='&search_categ='.urlencode($search_categ); + if (!empty($search_categ_thirdparty)) $param.='&search_categ_thirdparty='.urlencode($search_categ_thirdparty); + if (!empty($search_categ_supplier)) $param.='&search_categ_supplier='.urlencode($search_categ_supplier); if ($search_lastname != '') $param.='&search_lastname='.urlencode($search_lastname); if ($search_firstname != '') $param.='&search_firstname='.urlencode($search_firstname); if ($search_societe != '') $param.='&search_societe='.urlencode($search_societe); @@ -423,6 +429,22 @@ if ($result) $moreforfilter.=$langs->trans('Categories'). ': '; $moreforfilter.=$formother->select_categories(Categorie::TYPE_CONTACT,$search_categ,'search_categ',1); $moreforfilter.='
'; + if (empty($type) || $type == 'c' || $type == 'p') + { + $moreforfilter.='
'; + if ($type == 'c') $moreforfilter.=$langs->trans('CustomersCategoriesShort'). ': '; + else if ($type == 'p') $moreforfilter.=$langs->trans('ProspectsCategoriesShort'). ': '; + else $moreforfilter.=$langs->trans('CustomersProspectsCategoriesShort'). ': '; + $moreforfilter.=$formother->select_categories(Categorie::TYPE_CUSTOMER,$search_categ_thirdparty,'search_categ_thirdparty',1); + $moreforfilter.='
'; + } + if (empty($type) || $type == 'f') + { + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('SuppliersCategoriesShort'). ': '; + $moreforfilter.=$formother->select_categories(Categorie::TYPE_SUPPLIER,$search_categ_supplier,'search_categ_supplier',1); + $moreforfilter.='
'; + } } if ($moreforfilter) { diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 5a87d3b3d51..49f8130c5b4 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1513,7 +1513,7 @@ else // Remise if ($objp->remise_percent > 0) { - print ''.$objp->remise_percent."%\n"; + print ''.$objp->remise_percent."%\n"; } else { diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index fd92db95dfc..e08d148064b 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -2422,7 +2422,7 @@ class ContratLigne extends CommonObjectLine $sql.= " p.ref as product_ref,"; $sql.= " p.label as product_label,"; $sql.= " p.description as product_desc,"; - $sql.= " p.type as product_type,"; + $sql.= " p.fk_product_type as product_type,"; $sql.= " t.description,"; $sql.= " t.date_commande,"; $sql.= " t.date_ouverture_prevue as date_ouverture_prevue,"; diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index 350a0435d38..8e81c63c0ee 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -67,20 +67,18 @@ $result = restrictedArea($user, 'contrat', $id); $staticcontrat=new Contrat($db); $staticcontratligne=new ContratLigne($db); -if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers -{ - $search_name=""; - $search_contract=""; - $search_ref_supplier=""; - $search_user=''; - $search_sale=''; - $search_product_category=''; - $sall=""; - $search_status=""; -} - if ($search_status == '') $search_status=1; +$contextpage='contractlist'; + +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array($contextpage)); +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label('contract'); +$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); + // List of fields to search into when doing a "search in all" $fieldstosearchall = array( 'c.ref'=>'Ref', @@ -93,6 +91,35 @@ $fieldstosearchall = array( if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate"; +/* + * Action + */ + +$parameters=array(); +$reshook=$hookmanager->executeHooks('doActions',$parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + +include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php'; + +if (empty($reshook)) +{ + +} + +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + $search_name=""; + $search_contract=""; + $search_ref_supplier=""; + $search_user=''; + $search_sale=''; + $search_product_category=''; + $sall=""; + $search_status=""; + $search_array_options=array(); +} + + /* * View */ diff --git a/htdocs/contrat/services.php b/htdocs/contrat/services.php index d0962ad757e..d2de41391de 100644 --- a/htdocs/contrat/services.php +++ b/htdocs/contrat/services.php @@ -52,15 +52,26 @@ $search_status=GETPOST("search_status","alpha"); $statut=GETPOST('statut')?GETPOST('statut'):1; $socid=GETPOST('socid','int'); +$opouvertureprevuemonth=GETPOST('opouvertureprevuemonth'); +$opouvertureprevueday=GETPOST('opouvertureprevueday'); +$opouvertureprevueyear=GETPOST('opouvertureprevueyear'); +$filter_opouvertureprevue=GETPOST('filter_opouvertureprevue'); + $op1month=GETPOST('op1month'); $op1day=GETPOST('op1day'); $op1year=GETPOST('op1year'); $filter_op1=GETPOST('filter_op1'); + $op2month=GETPOST('op2month'); $op2day=GETPOST('op2day'); $op2year=GETPOST('op2year'); $filter_op2=GETPOST('filter_op2'); +$opcloturemonth=GETPOST('opcloturemonth'); +$opclotureday=GETPOST('opclotureday'); +$opclotureyear=GETPOST('opclotureyear'); +$filter_opcloture=GETPOST('filter_opcloture'); + // Security check $contratid = GETPOST('id','int'); if (! empty($user->societe_id)) $socid=$user->societe_id; @@ -88,12 +99,20 @@ $staticcontrat=new Contrat($db); $staticcontratligne=new ContratLigne($db); $companystatic=new Societe($db); -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 test are required to be compatible with all browsers { $search_name=""; $search_contract=""; $search_service=""; $search_status=-1; + $opouvertureprevuemonth=""; + $opouvertureprevueday=""; + $opouvertureprevueyear=""; + $filter_opouvertureprevue=""; $op1month=""; $op1day=""; $op1year=""; @@ -102,6 +121,10 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both $op2day=""; $op2year=""; $filter_op2=""; + $opcloturemonth=""; + $opclotureday=""; + $opclotureyear=""; + $filter_opcloture=""; $mode=''; $filter=''; } @@ -143,10 +166,14 @@ if ($search_name) $sql.= " AND s.nom LIKE '%".$db->escape($search_name)."%'" if ($search_contract) $sql.= " AND c.rowid = '".$db->escape($search_contract)."'"; if ($search_service) $sql.= " AND (p.ref LIKE '%".$db->escape($search_service)."%' OR p.description LIKE '%".$db->escape($search_service)."%' OR cd.description LIKE '%".$db->escape($search_service)."%')"; if ($socid > 0) $sql.= " AND s.rowid = ".$socid; +$filter_dateouvertureprevue=dol_mktime(0,0,0,$opouvertureprevuemonth,$opouvertureprevueday,$opouvertureprevueyear); $filter_date1=dol_mktime(0,0,0,$op1month,$op1day,$op1year); $filter_date2=dol_mktime(0,0,0,$op2month,$op2day,$op2year); -if (! empty($filter_op1) && $filter_op1 != -1 && $filter_date1 != '') $sql.= " AND date_ouverture_prevue ".$filter_op1." '".$db->idate($filter_date1)."'"; -if (! empty($filter_op2) && $filter_op2 != -1 && $filter_date2 != '') $sql.= " AND date_fin_validite ".$filter_op2." '".$db->idate($filter_date2)."'"; +$filter_datecloture=dol_mktime(0,0,0,$opcloturemonth,$opclotureday,$opclotureyear); +if (! empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1 && $filter_dateouvertureprevue != '') $sql.= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue)."'"; +if (! empty($filter_op1) && $filter_op1 != -1 && $filter_date1 != '') $sql.= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1)."'"; +if (! empty($filter_op2) && $filter_op2 != -1 && $filter_date2 != '') $sql.= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2)."'"; +if (! empty($filter_opcloture) && $filter_opcloture != -1 && $filter_datecloture != '') $sql.= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture)."'"; $totalnboflines=0; $result=$db->query($sql); if ($result) @@ -170,11 +197,15 @@ if ($resql) if ($search_service) $param.='&search_service='.urlencode($search_service); if ($mode) $param.='&mode='.$mode; if ($filter) $param.='&filter='.$filter; + if (! empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1) $param.='&filter_opouvertureprevue='.urlencode($filter_opouvertureprevue); if (! empty($filter_op1) && $filter_op1 != -1) $param.='&filter_op1='.urlencode($filter_op1); if (! empty($filter_op2) && $filter_op2 != -1) $param.='&filter_op2='.urlencode($filter_op2); + if (! empty($filter_opcloture) && $filter_opcloture != -1) $param.='&filter_opcloture='.urlencode($filter_opcloture); + if ($filter_dateouvertureprevue != '') $param.='&opouvertureprevueday='.$opouvertureprevueday.'&opouvertureprevuemonth='.$opouvertureprevuemonth.'&opouvertureprevueyear='.$opouvertureprevueyear; if ($filter_date1 != '') $param.='&op1day='.$op1day.'&op1month='.$op1month.'&op1year='.$op1year; if ($filter_date2 != '') $param.='&op2day='.$op2day.'&op2month='.$op2month.'&op2year='.$op2year; - + if ($filter_datecloture != '') $param.='&opclotureday='.$op2day.'&opcloturemonth='.$op2month.'&opclotureyear='.$op2year; + $title=$langs->trans("ListOfServices"); if ($mode == "0") $title=$langs->trans("ListOfInactiveServices"); // Must use == "0" if ($mode == "4" && $filter != "expired") $title=$langs->trans("ListOfRunningServices"); @@ -191,11 +222,11 @@ if ($resql) print_liste_field_titre($langs->trans("Service"),$_SERVER["PHP_SELF"], "p.description",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Company"),$_SERVER["PHP_SELF"], "s.nom",$param,"","",$sortfield,$sortorder); // Date debut - if ($mode == "0") print_liste_field_titre($langs->trans("DateStartPlannedShort"),$_SERVER["PHP_SELF"], "cd.date_ouverture_prevue",$param,'',' align="center"',$sortfield,$sortorder); - if ($mode == "" || $mode > 0) print_liste_field_titre($langs->trans("DateStartRealShort"),$_SERVER["PHP_SELF"], "cd.date_ouverture",$param,'',' align="center"',$sortfield,$sortorder); + if (($mode == "" || $mode == -1) || $mode == "0") print_liste_field_titre($langs->trans("DateStartPlannedShort"),$_SERVER["PHP_SELF"], "cd.date_ouverture_prevue",$param,'',' align="center"',$sortfield,$sortorder); + if (($mode == "" || $mode == -1) || $mode > 0) print_liste_field_titre($langs->trans("DateStartRealShort"),$_SERVER["PHP_SELF"], "cd.date_ouverture",$param,'',' align="center"',$sortfield,$sortorder); // Date fin - if ($mode == "" || $mode < 5) print_liste_field_titre($langs->trans("DateEndPlannedShort"),$_SERVER["PHP_SELF"], "cd.date_fin_validite",$param,'',' align="center"',$sortfield,$sortorder); - else print_liste_field_titre($langs->trans("DateEndRealShort"),$_SERVER["PHP_SELF"], "cd.date_cloture",$param,'',' align="center"',$sortfield,$sortorder); + if (($mode == "" || $mode == -1) || $mode < 5) print_liste_field_titre($langs->trans("DateEndPlannedShort"),$_SERVER["PHP_SELF"], "cd.date_fin_validite",$param,'',' align="center"',$sortfield,$sortorder); + if (($mode == "" || $mode == -1) || $mode >= 5) print_liste_field_titre($langs->trans("DateEndRealShort"),$_SERVER["PHP_SELF"], "cd.date_cloture",$param,'',' align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"], "cd.statut,c.statut",$param,"","align=\"right\"",$sortfield,$sortorder); print_liste_field_titre('',$_SERVER["PHP_SELF"],"",'','','',$sortfield,$sortorder,'maxwidthsearch '); print "\n"; @@ -214,20 +245,46 @@ if ($resql) print ''; print ''; print ''; - print ''; - $arrayofoperators=array('<'=>'<','>'=>'>'); - print $form->selectarray('filter_op1',$arrayofoperators,$filter_op1,1); - print ' '; - $filter_date1=dol_mktime(0,0,0,$op1month,$op1day,$op1year); - print $form->select_date($filter_date1,'op1',0,0,1,'',1,0,1); - print ''; - print ''; - $arrayofoperators=array('<'=>'<','>'=>'>'); - print $form->selectarray('filter_op2',$arrayofoperators,$filter_op2,1); - print ' '; - $filter_date2=dol_mktime(0,0,0,$op2month,$op2day,$op2year); - print $form->select_date($filter_date2,'op2',0,0,1,'',1,0,1); - print ''; + if (($mode == "" || $mode == -1) || $mode == "0") + { + print ''; + $arrayofoperators=array('<'=>'<','>'=>'>'); + print $form->selectarray('filter_opouvertureprevue',$arrayofoperators,$filter_opouvertureprevue,1); + print ' '; + $filter_dateouvertureprevue=dol_mktime(0,0,0,$opouvertureprevuemonth,$opouvertureprevueday,$opouvertureprevueyear); + print $form->select_date($filter_dateouvertureprevue,'opouvertureprevue',0,0,1,'',1,0,1); + print ''; + } + if (($mode == "" || $mode == -1) || $mode > 0) + { + print ''; + $arrayofoperators=array('<'=>'<','>'=>'>'); + print $form->selectarray('filter_op1',$arrayofoperators,$filter_op1,1); + print ' '; + $filter_date1=dol_mktime(0,0,0,$op1month,$op1day,$op1year); + print $form->select_date($filter_date1,'op1',0,0,1,'',1,0,1); + print ''; + } + if (($mode == "" || $mode == -1) || $mode < 5) + { + print ''; + $arrayofoperators=array('<'=>'<','>'=>'>'); + print $form->selectarray('filter_op2',$arrayofoperators,$filter_op2,1); + print ' '; + $filter_date2=dol_mktime(0,0,0,$op2month,$op2day,$op2year); + print $form->select_date($filter_date2,'op2',0,0,1,'',1,0,1); + print ''; + } + if (($mode == "" || $mode == -1) || $mode >= 5) + { + print ''; + $arrayofoperators=array('<'=>'<','>'=>'>'); + print $form->selectarray('filter_opcloture',$arrayofoperators,$filter_opcloture,1); + print ' '; + $filter_date_cloture=dol_mktime(0,0,0,$opcloturemonth,$opclotureday,$opclotureyear); + print $form->select_date($filter_date_cloture,'opcloture',0,0,1,'',1,0,1); + print ''; + } print ''; $arrayofstatus=array( '0'=>$langs->trans("ServiceStatusInitial"), @@ -287,7 +344,8 @@ if ($resql) print ''; // Start date - if ($mode == "0") { + if (($mode == "" || $mode == -1) || $mode == "0") + { print ''; print ($obj->date_ouverture_prevue?dol_print_date($db->jdate($obj->date_ouverture_prevue)):' '); if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay))) @@ -295,13 +353,19 @@ if ($resql) else print '    '; print ''; } - if ($mode == "" || $mode > 0) print ''.($obj->date_ouverture?dol_print_date($db->jdate($obj->date_ouverture)):' ').''; + if (($mode == "" || $mode == -1) || $mode > 0) + { + print ''.($obj->date_ouverture?dol_print_date($db->jdate($obj->date_ouverture)):' ').''; + } // Date fin - if ($mode == "" || $mode < 5) print ''.($obj->date_fin_validite?dol_print_date($db->jdate($obj->date_fin_validite)):' '); - else print ''.dol_print_date($db->jdate($obj->date_cloture)); + if (($mode == "" || $mode == -1) || $mode < 5) + { + 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) print img_warning($langs->trans("Late")); + else print '    '; + } + if (($mode == "" || $mode == -1) || $mode >= 5) print ''.dol_print_date($db->jdate($obj->date_cloture)); // Icone warning - if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5) print img_warning($langs->trans("Late")); - else print '    '; print ''; print ''; if ($obj->cstatut == 0) // If contract is draft, we say line is also draft diff --git a/htdocs/core/ajax/ajaxdirpreview.php b/htdocs/core/ajax/ajaxdirpreview.php index f1352f8e933..5827b846be9 100644 --- a/htdocs/core/ajax/ajaxdirpreview.php +++ b/htdocs/core/ajax/ajaxdirpreview.php @@ -82,6 +82,7 @@ else // For no ajax call $relativepath=$ecmdir->getRelativePath(); $upload_dir = $conf->ecm->dir_output.'/'.$relativepath; } +if (empty($url)) $url=DOL_URL_ROOT.'/ecm/index.php'; // Load traductions files $langs->load("ecm"); @@ -138,10 +139,10 @@ if (! dol_is_dir($upload_dir)) } print ''."\n"; -print ''."\n"; +print ''."\n"; $param=($sortfield?'&sortfield='.$sortfield:'').($sortorder?'&sortorder='.$sortorder:''); -$url=DOL_URL_ROOT.'/ecm/index.php'; + // Dir scan if ($type == 'directory') diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 4d0ab65a941..48797dd0432 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -35,6 +35,19 @@ $element = GETPOST('element','alpha',2); $table_element = GETPOST('table_element','alpha',2); $fk_element = GETPOST('fk_element','alpha',2); +/* Example: +field:editval_ref_customer (8 first chars will removed to know name of property) +element:contrat +table_element:contrat +fk_element:4 +type:string +value:aaa +loadmethod: +savemethod: +savemethodname: +*/ + + /* * View */ @@ -81,7 +94,7 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ } else $newelement = $element; - if (! empty($user->rights->$newelement->creer) || ! empty($user->rights->$newelement->write) + if (! empty($user->rights->$newelement->creer) || ! empty($user->rights->$newelement->create) || ! empty($user->rights->$newelement->write) || (isset($subelement) && (! empty($user->rights->$newelement->$subelement->creer) || ! empty($user->rights->$newelement->$subelement->write))) || ($element == 'payment' && $user->rights->facture->paiement) || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->creer)) diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index 1b54d917d05..d098106724c 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -132,7 +132,9 @@ class box_graph_invoices_permonth extends ModeleBoxes $mesg = $px1->isGraphKo(); if (! $mesg) { - $px1->SetData($data1); + $langs->load("bills"); + + $px1->SetData($data1); unset($data1); $px1->SetPrecisionY(0); $i=$startyear;$legend=array(); diff --git a/htdocs/core/boxes/box_services_contracts.php b/htdocs/core/boxes/box_services_contracts.php index b45bde124a3..9f71a98e77f 100644 --- a/htdocs/core/boxes/box_services_contracts.php +++ b/htdocs/core/boxes/box_services_contracts.php @@ -128,22 +128,22 @@ class box_services_contracts extends ModeleBoxes } } - $this->info_box_contents[$i][] = array('td' => 'class="tdoverflow maxwidth100onsmartphone" align="left"', + $this->info_box_contents[$i][] = array('td' => 'class="tdoverflowmax100 maxwidth100onsmartphone"', 'text' => $contratlignestatic->getNomUrl(1), 'asis' => 1 ); - $this->info_box_contents[$i][] = array('td' => 'align="left"', + $this->info_box_contents[$i][] = array('td' => '', 'text' => $contractstatic->getNomUrl(1), 'asis' => 1 ); - $this->info_box_contents[$i][] = array('td' => 'align="left"', + $this->info_box_contents[$i][] = array('td' => '', 'text' => $thirdpartytmp->getNomUrl(1), 'asis' => 1 ); - $this->info_box_contents[$i][] = array('td' => 'align="right"', + $this->info_box_contents[$i][] = array('td' => '', 'text' => dol_print_date($datem,'day')); $this->info_box_contents[$i][] = array('td' => 'align="right" width="18"', diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 71540cf16d7..25b593ce120 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2451,19 +2451,19 @@ abstract class CommonObject { if ($justsource) { - $sql.= "fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."'"; + $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; } else if ($justtarget) { - $sql.= "fk_target = '".$targetid."' AND targettype = '".$targettype."'"; + $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; } } else { - $sql.= "(fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."')"; - $sql.= " ".$clause." (fk_target = '".$targetid."' AND targettype = '".$targettype."')"; + $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; + $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; } $sql .= ' ORDER BY sourcetype'; //print $sql; @@ -4128,9 +4128,16 @@ abstract class CommonObject $langs->load('admin'); require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extrafields->fetch_name_optionals_label($this->table_element); + $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) { + if (in_array(substr($key,8), array_keys($target_extrafields))) + $new_array_options[$key] = $value; + } - foreach($this->array_options as $key => $value) + foreach($new_array_options as $key => $value) { $attributeKey = substr($key,8); // Remove 'options_' prefix $attributeType = $extrafields->attribute_type[$attributeKey]; @@ -4193,7 +4200,7 @@ abstract class CommonObject $this->db->query($sql_del); $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."_extrafields (fk_object"; - foreach($this->array_options as $key => $value) + foreach($new_array_options as $key => $value) { $attributeKey = substr($key,8); // Remove 'options_' prefix // Add field of attribut @@ -4201,7 +4208,7 @@ abstract class CommonObject $sql.=",".$attributeKey; } $sql .= ") VALUES (".$this->id; - foreach($this->array_options as $key => $value) + foreach($new_array_options as $key => $value) { $attributeKey = substr($key,8); // Remove 'options_' prefix // Add field o fattribut diff --git a/htdocs/core/class/doleditor.class.php b/htdocs/core/class/doleditor.class.php index ff31823976e..3bfcf9b781e 100644 --- a/htdocs/core/class/doleditor.class.php +++ b/htdocs/core/class/doleditor.class.php @@ -99,7 +99,7 @@ class DolEditor $this->editor->Value = $content; $this->editor->Height = $height; if (! empty($width)) $this->editor->Width = $width; - $this->editor->ToolbarSet = $shorttoolbarname; + $this->editor->ToolbarSet = $shorttoolbarname; // Profile of this toolbar set is deinfed into theme/mytheme/ckeditor/config.js $this->editor->Config['AutoDetectLanguage'] = 'true'; $this->editor->Config['ToolbarLocation'] = $toolbarlocation ? $toolbarlocation : 'In'; $this->editor->Config['ToolbarStartExpanded'] = $toolbarstartexpanded; diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 1a362d143dc..5e8f84f4d24 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -82,6 +82,7 @@ class ExtraFields 'chkbxlst' => 'ExtrafieldCheckBoxFromList', 'link' => 'ExtrafieldLink', 'separate' => 'ExtrafieldSeparator', + 'password' => 'ExtrafieldPassword', ); /** @@ -190,7 +191,7 @@ class ExtraFields } elseif($type=='phone') { $typedb='varchar'; $lengthdb='20'; - }elseif($type=='mail') { + } elseif($type=='mail') { $typedb='varchar'; $lengthdb='128'; } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') ||($type=='checkbox') ||($type=='chkbxlst')){ @@ -199,6 +200,9 @@ class ExtraFields } elseif ($type=='link') { $typedb='int'; $lengthdb='11'; + } elseif($type=='password') { + $typedb='varchar'; + $lengthdb='50'; } else { $typedb=$type; $lengthdb=$length; @@ -417,7 +421,7 @@ class ExtraFields } elseif($type=='phone') { $typedb='varchar'; $lengthdb='20'; - }elseif($type=='mail') { + } elseif($type=='mail') { $typedb='varchar'; $lengthdb='128'; } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') || ($type=='checkbox') || ($type=='chkbxlst')) { @@ -426,6 +430,9 @@ class ExtraFields } elseif ($type=='link') { $typedb='int'; $lengthdb='11'; + } elseif($type=='password') { + $typedb='varchar'; + $lengthdb='50'; } else { $typedb=$type; $lengthdb=$length; @@ -1146,6 +1153,10 @@ class ExtraFields $out.='Error bad setup of extrafield'; } } + elseif ($type == 'password') + { + $out=''; + } if (!empty($hidden)) { $out=''; } @@ -1404,6 +1415,10 @@ class ExtraFields { $value=dol_htmlentitiesbr($value); } + elseif ($type == 'password') + { + $value=preg_replace('/./i','*',$value); + } else { $showsize=round($size); diff --git a/htdocs/core/class/genericobject.class.php b/htdocs/core/class/genericobject.class.php index 32960664c17..c89b5c31fea 100644 --- a/htdocs/core/class/genericobject.class.php +++ b/htdocs/core/class/genericobject.class.php @@ -24,8 +24,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; /** - * \class GenericObject - * \brief Class of a generic business object + * Class of a generic business object */ class GenericObject extends CommonObject diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index 1a7425b0a55..a71ed57ab2c 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -142,7 +142,8 @@ class HookManager 'formObjectOptions', 'formattachOptions', 'formBuilddocLineOptions', - 'getIdProfUrl', + 'getFormMail', + 'getIdProfUrl', 'moveUploadedFile', 'pdf_build_address', 'pdf_writelinedesc', diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 334aabbd362..21a7ccb29a5 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1437,7 +1437,7 @@ class Form $nodatarole=($comboenhancement?' data-role="none"':''); } - $out.= ''; if ($show_empty) $out.= ''."\n"; if ($show_every) $out.= ''."\n"; @@ -1768,7 +1768,7 @@ class Form $optJson = array(); $objp = $this->db->fetch_object($result); - if (!empty($objp->price_by_qty) && $objp->price_by_qty == 1 && !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY) && !empty($objp->price_by_qty) && $objp->price_by_qty == 1) { // Price by quantity will return many prices for the same product $sql = "SELECT rowid, quantity, price, unitprice, remise_percent, remise"; $sql.= " FROM ".MAIN_DB_PREFIX."product_price_by_qty"; @@ -1916,8 +1916,8 @@ class Form $sql.= " WHERE fk_product='".$objp->rowid."'"; $sql.= " AND entity IN (".getEntity('productprice', 1).")"; $sql.= " AND price_level=".$price_level; - $sql.= " ORDER BY date_price, rowid"; - $sql.= " DESC LIMIT 1"; + $sql.= " ORDER BY date_price DESC, rowid DESC"; // Warning DESC must be both on date_price and rowid. + $sql.= " LIMIT 1"; dol_syslog(get_class($this).'::constructProductListOption search price for level '.$price_level.'', LOG_DEBUG); $result2 = $this->db->query($sql); @@ -4263,7 +4263,8 @@ class Form } // Now we get list - $num = $this->load_cache_vatrates($code_country); + $num = $this->load_cache_vatrates($code_country); // If no vat defined, return -1 with message into this->error + if ($num > 0) { // Definition du taux a pre-selectionner (si defaulttx non force et donc vaut -1 ou '') @@ -5929,7 +5930,7 @@ class Form /** * Return HTML to show the search and clear seach button * - * @param int $addcheckuncheckall Add the check all uncheck all button + * @param int $addcheckuncheckall Add the check all/uncheck all checkbox (use javascript) and code to manage this * @param string $cssclass CSS class * @param int $calljsfunction 0=default. 1=call function initCheckForSelect() after changing status of checkboxes * @return string @@ -5944,8 +5945,7 @@ class Form if ($addcheckuncheckall) { if (! empty($conf->use_javascript_ajax)) $out.=''; - } - $out.=''; + if ($calljsfunction) $out.='if (typeof initCheckForSelect == \'function\') { initCheckForSelect(); } else { console.log("No function initCheckForSelect found. Call won\'t be done."); }'; + $out.=' }); + }); + '; + } return $out; } } diff --git a/htdocs/core/class/html.formmail.class.php b/htdocs/core/class/html.formmail.class.php index 4d2062f03c7..c92229cf036 100644 --- a/htdocs/core/class/html.formmail.class.php +++ b/htdocs/core/class/html.formmail.class.php @@ -250,8 +250,9 @@ class FormMail extends Form $hookmanager->initHooks(array('formmail')); $parameters=array( - 'addfileaction' => $addfileaction, - 'removefileaction'=> $removefileaction + 'addfileaction' => $addfileaction, + 'removefileaction'=> $removefileaction, + 'trackid'=> $this->trackid ); $reshook=$hookmanager->executeHooks('getFormMail', $parameters, $this); @@ -927,18 +928,30 @@ class FormMail extends Form /** * Set substit array from object * - * @param Object $object Object to use + * @param Object $object Object to use + * @param Translate $outputlangs Object lang * @return void */ - function setSubstitFromObject($object) + function setSubstitFromObject($object, $outputlangs=null) { global $user; $this->substit['__REF__'] = $object->ref; - $this->substit['__SIGNATURE__'] = $user->signature; $this->substit['__REFCLIENT__'] = $object->ref_client; - $this->substit['__THIRDPARTY_NAME__'] = $object->thirdparty->name; + $this->substit['__REFSUPPLIER__'] = $object->ref_supplier; + + $this->substit['__DATE_YMD__'] = dol_print_date($object->date, 'day', 0, $outputlangs); + $this->substit['__DATE_DUE_YMD__'] = dol_print_date($object->date_lim_reglement, 'day', 0, $outputlangs); + $this->substit['__AMOUNT__'] = price($object->total_ttc); + $this->substit['__AMOUNT_WO_TAX__'] = price($object->total_ht); + + $this->substit['__THIRDPARTY_ID__'] = (is_object($object->thirdparty)?$object->thirdparty->id:''); + $this->substit['__THIRDPARTY_NAME__'] = (is_object($object->thirdparty)?$object->thirdparty->name:''); + + $this->substit['__PROJECT_ID__'] = (is_object($object->projet)?$object->projet->id:''); $this->substit['__PROJECT_REF__'] = (is_object($object->projet)?$object->projet->ref:''); $this->substit['__PROJECT_NAME__'] = (is_object($object->projet)?$object->projet->title:''); + + $this->substit['__SIGNATURE__'] = $user->signature; $this->substit['__PERSONALIZED__'] = ''; $this->substit['__CONTACTCIVNAME__'] = ''; // Will be replace just before sending } diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 3664424764d..2a1d5f5fdaa 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -579,7 +579,7 @@ class FormOther { print "   "; } - print $lines[$i]->label."\n"; + print $lines[$i]->ref.' '.$lines[$i]->label."\n"; $inc++; } diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index d2ad0a6f1ab..0eca137f6d3 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -569,7 +569,7 @@ class FormProjets { $obj = $this->db->fetch_object($resql); - $sellist .='