diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index 68fe9de68d6..d7463d62172 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -26,8 +26,9 @@ Default **language here is english**. So please prepare your contributions in en 1. [Fork](https://help.github.com/articles/fork-a-repo) the [GitHub repository](https://github.com/Dolibarr/dolibarr). 2. Clone your fork. 3. Choose a branch(See the [Branches](#branches) section below). -4. Commit and push your changes. -5. [Make a pull request](https://help.github.com/articles/creating-a-pull-request). +4. Read our developer documentation on the [Dolibarr Wiki](https://wiki.dolibarr.org/index.php?title=Developer_documentation). +5. Commit and push your changes. +6. [Make a pull request](https://help.github.com/articles/creating-a-pull-request). ### Branches diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md deleted file mode 100644 index 432f30f2332..00000000000 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -name: Bug report -about: Create a report to help us fix something that is broken -title: '' -labels: Bug -assignees: '' - ---- - -# Instructions -*This is a template to help you report good issues. You may use [Github Markdown](https://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/) syntax to format your issue report.* -*Please:* -- *replace the bracket enclosed texts with meaningful information* -- *remove any unused sub-section* - - -# Bug -[*Short description*] - -## Environment -- **Version**: [*Affected Dolibarr version(s)*] -- **OS**: [*Server OS type and version*] -- **Web server**: [*Webserver type and version*] -- **PHP**: [*PHP version*] -- **Database**: [*Database type and version*] -- **URL(s)**: [*Affected URL(s)*] - -## Expected and actual behavior -[*Verbose description*] - -## Steps to reproduce the behavior -[*Verbose description*] - -## [Attached files](https://help.github.com/articles/issue-attachments) (Screenshots, screencasts, dolibarr.log, debugging informations…) -[*Files*] diff --git a/.github/ISSUE_TEMPLATE/bug_report.yml b/.github/ISSUE_TEMPLATE/bug_report.yml new file mode 100644 index 00000000000..d7dc3d584e3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.yml @@ -0,0 +1,71 @@ +name: Bug report +description: Create a report to help us fix something that is broken +labels: ["Bug"] + +body: + - type: markdown + attributes: + value: | + This is a template to help you report good issues. You may use [Github Markdown](https://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/) syntax to format your issue report. + + - type: textarea + id: bug + attributes: + label: Bug + description: Please give a short description of the bug + validations: + required: true + + - type: input + id: environment-version + attributes: + label: Environment Version + description: Affected Dolibarr version(s) + + - type: input + id: environment-os + attributes: + label: Environment OS + description: Server OS type and version + + - type: input + id: environment-webserver + attributes: + label: Environment Web server + description: Webserver type and version + + - type: input + id: environment-php + attributes: + label: Environment PHP + description: PHP version + + - type: input + id: environment-database + attributes: + label: Environment Database + description: Database type and version + + - type: input + id: environment-urls + attributes: + label: Environment URL(s) + description: Affected URL(s) + + - type: textarea + id: expected-behaviour + attributes: + label: Expected and actual behavior + description: Verbose description + + - type: textarea + id: reproduce + attributes: + label: Steps to reproduce the behavior + description: Verbose description + + - type: textarea + id: files + attributes: + label: Attached files + description: Screenshots, screencasts, dolibarr.log, debugging informations diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md deleted file mode 100644 index 32e2deff2c1..00000000000 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ /dev/null @@ -1,27 +0,0 @@ ---- -name: Feature request -about: Suggest a new idea for this project -title: '' -labels: Feature request -assignees: '' - ---- - -# Instructions -*This is a template to help you report good issues. You may use [Github Markdown](https://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/) syntax to format your issue report.* -*Please:* -- *replace the bracket enclosed texts with meaningful information* -- *remove any unused sub-section* - - -# Feature Request -[*Short description*] - -## Use case -[*Verbose description*] - -## Suggested implementation -[*Verbose description*] - -## Suggested steps -[*List of tasks to achieve goal*] diff --git a/.github/ISSUE_TEMPLATE/feature_request.yml b/.github/ISSUE_TEMPLATE/feature_request.yml new file mode 100644 index 00000000000..885f3472d18 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.yml @@ -0,0 +1,35 @@ +name: Feature request +description: Suggest a new idea for this project +labels: ["Feature request"] + +body: + - type: markdown + attributes: + value: | + This is a template to help you report good issues. You may use [Github Markdown](https://help.github.com/articles/getting-started-with-writing-and-formatting-on-github/) syntax to format your issue report. + + - type: textarea + id: feature-request + attributes: + label: Feature Request + description: Short description + validations: + required: true + + - type: textarea + id: use-case + attributes: + label: Use case + description: Verbose description + + - type: textarea + id: suggested-implementation + attributes: + label: Suggested implementation + description: Verbose description + + - type: textarea + id: suggested-steps + attributes: + label: Suggested steps + description: List of tasks to achieve goal diff --git a/.travis.yml b/.travis.yml index b48a3667bb0..5d7eb7a1678 100644 --- a/.travis.yml +++ b/.travis.yml @@ -57,7 +57,7 @@ jobs: php: nightly env: DB=mysql - stage: PHP Dev - if: type = push AND branch = 14.0 + if: type = push AND branch = 15.0 php: nightly env: DB=mysql @@ -411,6 +411,12 @@ script: php upgrade.php 13.0.0 14.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade13001400.log php upgrade2.php 13.0.0 14.0.0 > $TRAVIS_BUILD_DIR/upgrade13001400-2.log php step5.php 13.0.0 14.0.0 > $TRAVIS_BUILD_DIR/upgrade13001400-3.log + php upgrade.php 14.0.0 15.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade14001500.log + php upgrade2.php 14.0.0 15.0.0 > $TRAVIS_BUILD_DIR/upgrade14001500-2.log + php step5.php 14.0.0 15.0.0 > $TRAVIS_BUILD_DIR/upgrade14001500-3.log + php upgrade.php 15.0.0 16.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade15001600.log + php upgrade2.php 15.0.0 16.0.0 > $TRAVIS_BUILD_DIR/upgrade15001600-2.log + php step5.php 15.0.0 16.0.0 > $TRAVIS_BUILD_DIR/upgrade15001600-3.log ls -alrt $TRAVIS_BUILD_DIR/ - | diff --git a/ChangeLog b/ChangeLog index 5bab0419c54..a9a42c8d878 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,10 +12,9 @@ NEW: Online proposal signature NEW: Can define some max limit on expense report (per period, per type or expense, ...) NEW: Allow the use of __NEWREF__ to get for example the new reference a draft order will get after validation. NEW: Add option to disable globaly some notifications emails. -NEW: #18326 Workflow: Close order on shipment closing. NEW: #18401 Add __NEWREF__ subtitute to get new object reference. NEW: #18403 Add __URL_SHIPMENT__ substitute to get the URL of a shipment -NEW: #18689 REST API module: add api key generate / modify right. +NEW: #18689 REST API module: add api key generate / modify permission. NEW: #18663 Make "L'Annuaire des Entreprises" the default provider for SIREN verification for French thirdparties. NEW: #18046 Add tags on ticket/categories NEW: #18326 Workflow: Close order on shipment closing. @@ -109,6 +108,13 @@ NEW: External backups can be downloaded from the "About info page". NEW: Add massaction to switch status on sale / on purchase of a product. + Modules +NEW: Stable module Knowledge Management +NEW: Experimental module Event Organization Management +NEW: Experimental module Workstations Management +NEW: Development of module Partnership Management + + For developers: --------------- @@ -116,6 +122,7 @@ NEW: Introduce method hasRight NEW: Can use textarea field into a confirm popup. NEW: Can use the result_mode of mysqli driver. Save memory for list count NEW: #18319 REST API - Shipment: Add 'close' action / endpoint / POST method. +NEW: Add API /approve and /makeOrder for purchase orders. NEW: add action trigger for member excluded NEW: add option MAIN_IBAN_IS_NEVER_MANDATORY, MAIN_IBAN_NOT_MANDATORY, PROPAL_NOT_BILLABLE, PROPAL_REOPEN_UNSIGNED_ONLY, PROPOSAL_ARE_NOT_BILLABLE, TICKETS_MESSAGE_FORCE_MAIL NEW: Add code codebar column on serial/lot structure @@ -134,9 +141,12 @@ NEW: Use lang selector when using a field key 'lang' in modulebuilder NEW: we need to be able to put more filters on deleteByParentField() function NEW: make it easier to set the `keyword`, `keywords` and `description` attributes of an ecm file object NEW: Experimental feature to manage user sessions in database - +NEW: Hidden option API_DISABLE_COMPRESSION is now visible in API setup page. +NEW: Add hook printUnderHeaderPDFline on invoice PDF templates (can be used for example to add a barcode or more information on header of invoices). Following changes may create regressions for some external modules, but were necessary to make Dolibarr better: +* ALL EXTERNAL MODULES THAT WERE NOT CORRECTLY DEVELOPPED WILL NOT WORK ON V15 (All modules that forgot to manage the security token field + into forms will be broken. The security token field is expected since Dolibarr v9 but a lot of external modules did not implement it). * Update hook 'printOriginObjectLine', removed check on product type and special code. Need now reshook. * Old deprecated module "SimplePOS" has been completely removed. Use module "TakePOS" is you need a Point Of Sale. * The method static ActionComm::getActions($db, ...) is no more static. Use $actioncomm->getActions(...) instead (without $db param). @@ -147,8 +157,45 @@ Following changes may create regressions for some external modules, but were nec * Class file expeditionbatch.class.php renamed to expeditionlinebatch.class.php * ExpeditionLineBatch::fetchAll is not static anymore and first parameter $db is removed * ExtraFields->showOutputField parameter 4 'extrafieldsobjectkey' is now required +* CommonObject method add_object_linked now sets targettype to 'mymodule_myobject' instead of 'myobject', + you can use hook 'setLinkedObjectSourceTargetType' to set your usual targettype +***** ChangeLog for 14.0.5 compared to 14.0.4 ***** + +FIX: 13.0: printFieldListWhere called twice on same query +FIX: 14.0.4 fatal error on cron list. +FIX: #19476 +FIX: #19564 +FIX: #19651 +FIX: Accountancy - SQL error on subledger account search in journal +FIX: apply eldy's suggestion to not overwrite existing extrafields of $line +FIX: Can't close a down payment if paid with credit notes. +FIX: better compatibility with multicompany +FIX: contact card: bad colspan value for separator extrafield in creation/modification form +FIX: discounts are applied both when fetching the best supplier price and when displaying it +FIX: double display for contact categorie on societe create card +FIX: fatal error on cron list. +FIX: holiday list: only mass delete if leave request is not in draft, canceled or refused, like in card +FIX: holiday mass deletion: correct return of record deleted +FIX: Holiday month report +FIX: info tab on customer invoice record not found +FIX: line extrafields are inoperative in dispatch cards even when they exist +FIX: list of categories in stats of supplier invoices +FIX: missing default value for more comprehensive +FIX: multicurrency: fields in discount unitialized when creating deposit +FIX: Navigation on bank transaction list +FIX: Can't edit a bank transaction due to bad permission check. +FIX: Option MAIN_DIRECT_STATUS_UPDATE broken. Ajax on/off not saving value in DB after updating to version >=12 +FIX: postgresql compatibility, "" as is not authorized +FIX: printFieldListWhere called twice (at different locations) for the same SQL query, can result in syntax errors +FIX: select too large into addrights (pb of missing parenthesis) +FIX: set optional from post, we can't untick boolean field on product card +FIX: Take into consideration work leave over serveral months +FIX: test if method exist on wrong object +FIX: title for nature of third party in company list +FIX: Urgent onglet contact inaccessible depuis une facture +FIX: wrong syntax of sql request ***** ChangeLog for 14.0.4 compared to 14.0.3 ***** diff --git a/README.md b/README.md index b0f7a2c3761..4e120a4cb91 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ ![Build status](https://img.shields.io/travis/Dolibarr/dolibarr/develop.svg) [![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%205.6-8892BF.svg?style=flat-square)](https://php.net/) [![GitHub release](https://img.shields.io/github/v/release/Dolibarr/dolibarr)](https://github.com/Dolibarr/dolibarr) +[![CII Best Practices](https://bestpractices.coreinfrastructure.org/projects/5521/badge)](https://bestpractices.coreinfrastructure.org/projects/5521) Dolibarr ERP & CRM is a modern software package that helps manage your organization's activity (contacts, suppliers, invoices, orders, stocks, agenda…). diff --git a/SECURITY.md b/SECURITY.md index 9c28e2874b9..cadd4a23791 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -6,13 +6,14 @@ This file contains some policies about the security reports on Dolibarr ERP CRM | Version | Supported | | ---------- | ---------------------- | -| <= 14.0.1 | :x: | -| >= 14.0.2+ | :white_check_mark: except CSRF attacks| +| <= 14.0.4 | :x: | +| >= 14.0.5+ | :white_check_mark: except CSRF attacks| | >= develop | :white_check_mark: | ## Reporting a Vulnerability -To report a vulnerability, please use GitHub security advisory at [https://github.com/Dolibarr/dolibarr/security/advisories/new](https://github.com/Dolibarr/dolibarr/security/advisories/new) (if you have permissions) or alternatively send an email to security@dolibarr.org (for everybody) +To report a vulnerability, for a private report, please use GitHub security advisory at [https://github.com/Dolibarr/dolibarr/security/advisories/new](https://github.com/Dolibarr/dolibarr/security/advisories/new) (if you have permissions). +Alternatively send an email to security@dolibarr.org (for everybody) ## Hunting vulnerabilities on Dolibarr @@ -66,7 +67,7 @@ Scope is the web application (back office) and the APIs. * Remote code execution (RCE) * Local files access and manipulation (LFI, RFI, XXE, SSRF, XSPA) * Code injections (HTML, JS, SQL, PHP, ...) -* Cross-Site Scripting (XSS), except from setup page of module "External web site" (allowing any content here, editable by admin user only, is accepted on purpose or into module "Web site" when permission to edit website content is allowed). +* Cross-Site Scripting (XSS), except from setup page of module "External web site" (allowing any content here, editable by admin user only, is accepted on purpose) and except into module "Web site" when permission to edit website content is allowed (injecting any data in this case is allowed too). * Cross-Site Requests Forgery (CSRF) with real security impact (when using GET URLs, CSRF are qualified only for creating, updating or deleting data from pages restricted to admin users) * Open redirect * Broken authentication & session management diff --git a/build/docker/Dockerfile b/build/docker/Dockerfile index eb8e3ade6dc..ead2a8af1c5 100644 --- a/build/docker/Dockerfile +++ b/build/docker/Dockerfile @@ -39,15 +39,13 @@ RUN chmod +x /usr/local/bin/docker-run.sh RUN pecl install xdebug && docker-php-ext-enable xdebug RUN echo 'zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20180731/xdebug.so"' >> ${PHP_INI_DIR}/php.ini -RUN echo 'xdebug.remote_autostart=1' >> ${PHP_INI_DIR}/php.ini -RUN echo 'xdebug.remote_enable=1' >> ${PHP_INI_DIR}/php.ini -RUN echo 'xdebug.default_enable=1' >> ${PHP_INI_DIR}/php.ini -#RUN echo 'xdebug.remote_host=docker.host' >> ${PHP_INI_DIR}/php.ini -RUN echo 'xdebug.remote_port=9000' >> ${PHP_INI_DIR}/php.ini -RUN echo 'xdebug.remote_connect_back=1' >> ${PHP_INI_DIR}/php.ini -RUN echo 'xdebug.profiler_enable=0' >> ${PHP_INI_DIR}/php.ini -RUN echo 'xdebug.remote_log="/tmp/xdebug.log"' >> ${PHP_INI_DIR}/php.ini -#RUN echo 'localhost docker.host' >> /etc/hosts +RUN echo 'xdebug.mode=debug' >> ${PHP_INI_DIR}/php.ini +RUN echo 'xdebug.start_with_request=yes' >> ${PHP_INI_DIR}/php.ini +RUN echo 'xdebug.client_host=host.docker.internal' >> ${PHP_INI_DIR}/php.ini +RUN echo 'xdebug.client_port=9003' >> ${PHP_INI_DIR}/php.ini +RUN echo 'xdebug.discover_client_host=true' >> ${PHP_INI_DIR}/php.ini +#RUN echo 'xdebug.log="/tmp/xdebug.log"' >> ${PHP_INI_DIR}/php.ini +RUN echo 'xdebug.idekey="netbeans-xdebug"' >> ${PHP_INI_DIR}/php.ini # set up sendmail config, to use maildev RUN echo "account default" > /etc/msmtprc diff --git a/build/docker/docker-compose.yml b/build/docker/docker-compose.yml index b72118de5fb..8994043cd8a 100644 --- a/build/docker/docker-compose.yml +++ b/build/docker/docker-compose.yml @@ -48,6 +48,7 @@ services: - external-pod extra_hosts: - "localhost.localdomain:127.0.0.1" + - "host.docker.internal:host-gateway" mail: image: maildev/maildev diff --git a/dev/resources/iso-normes/Intracommreport-ManuelDebXml.pdf b/dev/resources/iso-normes/Intracommreport-ManuelDebXml.pdf deleted file mode 100644 index fef9f48f53e..00000000000 Binary files a/dev/resources/iso-normes/Intracommreport-ManuelDebXml.pdf and /dev/null differ diff --git a/dev/resources/iso-normes/QR code for invoices.txt b/dev/resources/iso-normes/QR code for invoices.txt new file mode 100644 index 00000000000..a55c9569297 --- /dev/null +++ b/dev/resources/iso-normes/QR code for invoices.txt @@ -0,0 +1,13 @@ +List of QR Code format we found on some invoices +------------------------------------------------ + + +* For SEPA QR payment Code format (Europe) +------------------------------------------ +https://en.wikipedia.org/wiki/EPC_QR_code#Generators + + + +* For ZATCA QR Code format (Saudi Arabia) +----------------------------------------- +https://www.pwc.com/m1/en/services/tax/me-tax-legal-news/2021/saudi-arabia-guide-to-develop-compliant-qr-code-for-simplified-einvoices.html diff --git a/dev/resources/iso-normes/address_format.txt b/dev/resources/iso-normes/address_format.txt index d87e90e79b5..18069cd89fa 100644 --- a/dev/resources/iso-normes/address_format.txt +++ b/dev/resources/iso-normes/address_format.txt @@ -1,3 +1,5 @@ +Address format + https://bitboost.com/ref/international-address-formats.html#Formats https://www.upu.int/en/Postal-Solutions/Programmes-Services/Addressing-Solutions diff --git a/dev/resources/facturx-zugferd/README.txt b/dev/resources/iso-normes/facturx-zugferd/README.txt similarity index 100% rename from dev/resources/facturx-zugferd/README.txt rename to dev/resources/iso-normes/facturx-zugferd/README.txt diff --git a/dev/resources/iso-normes/14-pourquoi le format PDF A.pdf b/dev/resources/iso-normes/format PDF - PDF A.pdf similarity index 100% rename from dev/resources/iso-normes/14-pourquoi le format PDF A.pdf rename to dev/resources/iso-normes/format PDF - PDF A.pdf diff --git a/dev/resources/iso-normes/format_FEC-Lien_outil_de_test_agréé.pdf b/dev/resources/iso-normes/format_FEC - Lien_outil_de_test_agréé.pdf similarity index 100% rename from dev/resources/iso-normes/format_FEC-Lien_outil_de_test_agréé.pdf rename to dev/resources/iso-normes/format_FEC - Lien_outil_de_test_agréé.pdf diff --git a/dev/resources/iso-normes/sample_FEC_file.txt b/dev/resources/iso-normes/format_FEC - fie example.txt similarity index 100% rename from dev/resources/iso-normes/sample_FEC_file.txt rename to dev/resources/iso-normes/format_FEC - fie example.txt diff --git a/dev/resources/intracommreport/manuelDebXml1.2.pdf b/dev/resources/iso-normes/intracommreport/Intracommreport-ManuelDebXml.pdf similarity index 100% rename from dev/resources/intracommreport/manuelDebXml1.2.pdf rename to dev/resources/iso-normes/intracommreport/Intracommreport-ManuelDebXml.pdf diff --git a/dev/resources/iso-normes/Intracommreport-ManuelDesXML.pdf b/dev/resources/iso-normes/intracommreport/Intracommreport-ManuelDesXML.pdf similarity index 100% rename from dev/resources/iso-normes/Intracommreport-ManuelDesXML.pdf rename to dev/resources/iso-normes/intracommreport/Intracommreport-ManuelDesXML.pdf diff --git a/dev/resources/intracommreport/schema_deb.xsd b/dev/resources/iso-normes/intracommreport/schema_deb.xsd similarity index 100% rename from dev/resources/intracommreport/schema_deb.xsd rename to dev/resources/iso-normes/intracommreport/schema_deb.xsd diff --git a/dev/resources/iso-normes/locales.txt b/dev/resources/iso-normes/locales.txt index 67ea5280342..a4459d2a8b1 100644 --- a/dev/resources/iso-normes/locales.txt +++ b/dev/resources/iso-normes/locales.txt @@ -1,3 +1,5 @@ +Date and number format +---------------------- For languages: https://icu4c-demos.unicode.org/icu-bin/icudemos - Locale Explorer -> Error 404 diff --git a/dev/resources/sepa/pain.001.001.03.xsd b/dev/resources/iso-normes/sepa/pain.001.001.03.xsd similarity index 100% rename from dev/resources/sepa/pain.001.001.03.xsd rename to dev/resources/iso-normes/sepa/pain.001.001.03.xsd diff --git a/dev/resources/sepa/pain.008.001.02.xsd b/dev/resources/iso-normes/sepa/pain.008.001.02.xsd similarity index 100% rename from dev/resources/sepa/pain.008.001.02.xsd rename to dev/resources/iso-normes/sepa/pain.008.001.02.xsd diff --git a/dev/resources/sepa/sample-credit-transfer.xml b/dev/resources/iso-normes/sepa/sample-credit-transfer.xml similarity index 100% rename from dev/resources/sepa/sample-credit-transfer.xml rename to dev/resources/iso-normes/sepa/sample-credit-transfer.xml diff --git a/dev/resources/sepa/sample-direct-debit.xml b/dev/resources/iso-normes/sepa/sample-direct-debit.xml similarity index 100% rename from dev/resources/sepa/sample-direct-debit.xml rename to dev/resources/iso-normes/sepa/sample-direct-debit.xml diff --git a/dev/resources/sepa/text.txt b/dev/resources/iso-normes/sepa/text.txt similarity index 100% rename from dev/resources/sepa/text.txt rename to dev/resources/iso-normes/sepa/text.txt diff --git a/dev/resources/iso-normes/world_tax_rates.txt b/dev/resources/iso-normes/world_tax_rates.txt index c007474e5fd..508446b618a 100644 --- a/dev/resources/iso-normes/world_tax_rates.txt +++ b/dev/resources/iso-normes/world_tax_rates.txt @@ -1,3 +1,6 @@ +VAT Rates +--------- + http://www.taxrates.cc/index.html https://en.wikipedia.org/wiki/List_of_countries_by_tax_rates diff --git a/dev/setup/apache/virtualhost b/dev/setup/apache/virtualhost index c3a2dff3e43..8c7682fe3d9 100644 --- a/dev/setup/apache/virtualhost +++ b/dev/setup/apache/virtualhost @@ -1,62 +1,93 @@ -#php_admin_value sendmail_path "/usr/sbin/sendmail -t -i" -#php_admin_value mail.force_extra_parameters "-f postmaster@mydomain.com" -php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f postmaster@mydomain.com" -php_admin_value open_basedir /tmp/:/home/../htdocs + #php_admin_value sendmail_path "/usr/sbin/sendmail -t -i" + #php_admin_value mail.force_extra_parameters "-f postmaster@mydomain.com" + php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f postmaster@mydomain.com" + php_admin_value open_basedir /tmp/:/home/.../htdocs:/home/.../dolibarr_documents: + + ServerName myvirtualalias + ServerAlias myvirtualalias + + UseCanonicalName On + + KeepAlive On + KeepAliveTimeout 5 + MaxKeepAliveRequests 20 + + AddDefaultCharset UTF-8 + + DocumentRoot "/home/.../htdocs" + + + AllowOverride None + Options -Indexes -MultiViews +FollowSymLinks -ExecCGI + Require all granted -ServerName myvirtualalias -ServerAlias myvirtualalias + # To restrict access by a HTTP basic auth + #AuthType Basic + #AuthName "Authenticate to backoffice" + #AuthUserFile /etc/apache2/.htpasswd + #require valid-user + + + # Leaving /public and /api, /dav, .well_known but also wrappers for document and viewimage accessible to everyone + + AuthType None + Require all granted + Satisfy any + + + AuthType None + Require all granted + Satisfy any + + + AuthType None + Require all granted + Satisfy any + + + AuthType None + Require all granted + Satisfy any + + + AuthType None + Require all granted + Satisfy any + -UseCanonicalName On - -AddDefaultCharset UTF-8 - -DocumentRoot "/home/.../htdocs" - - - AllowOverride None - Options -Indexes -MultiViews +FollowSymLinks -ExecCGI - Require all granted - - - - Deny from all - RemoveHandler .phtml .php .php3 .php4 .php5 .php6 .phps .cgi .exe .pl .asp .aspx .shtml .shtm .fcgi .fpl .jsp .htm .html .wml - AddType application/x-httpd-php-source .phtml .php .php3 .php4 .php5 .php6 .phps .cgi .exe .pl .asp .aspx .shtml .shtm .fcgi .fpl .jsp .htm .html .wml - - - -ErrorLog /var/log/apache2/myvirtualalias_error_log -TransferLog /var/log/apache2/myvirtualalias_access_log - -# Compress returned resources of type php pages, text file export, css and javascript -AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript - -AddType text/javascript .jgz -AddEncoding gzip .jgz -ExpiresActive On -ExpiresByType image/x-icon A2592000 -ExpiresByType image/gif A2592000 -ExpiresByType image/png A2592000 -ExpiresByType image/jpeg A2592000 -ExpiresByType text/css A2592000 -ExpiresByType text/javascript A2592000 -ExpiresByType application/x-javascript A2592000 -ExpiresByType application/javascript A2592000 - -SSLEngine On - -# A self-signed (snakeoil) certificate can be created by installing -# the ssl-cert package. See -# /usr/share/doc/apache2.2-common/README.Debian.gz for more info. -# If both key and certificate are stored in the same file, only the -# SSLCertificateFile directive is needed. -SSLCertificateFile /etc/letsencrypt/live/www.mydomain.com/cert.pem -SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomain.com/privkey.pem -SSLCertificateChainFile /etc/letsencrypt/live/www.mydomain.com/chain.pem - -#RewriteEngine on -#RewriteCond %{SERVER_PORT} ^80$ -#RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R] + + ErrorLog /var/log/apache2/myvirtualalias_error_log + TransferLog /var/log/apache2/myvirtualalias_access_log + + # Compress returned resources of type php pages, text file export, css and javascript + AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript + + AddType text/javascript .jgz + AddEncoding gzip .jgz + ExpiresActive On + ExpiresByType image/x-icon A2592000 + ExpiresByType image/gif A2592000 + ExpiresByType image/png A2592000 + ExpiresByType image/jpeg A2592000 + ExpiresByType text/css A2592000 + ExpiresByType text/javascript A2592000 + ExpiresByType application/x-javascript A2592000 + ExpiresByType application/javascript A2592000 + + SSLEngine On + + # A self-signed (snakeoil) certificate can be created by installing + # the ssl-cert package. See + # /usr/share/doc/apache2.2-common/README.Debian.gz for more info. + # If both key and certificate are stored in the same file, only the + # SSLCertificateFile directive is needed. + SSLCertificateFile /etc/letsencrypt/live/www.mydomain.com/cert.pem + SSLCertificateKeyFile /etc/letsencrypt/live/www.mydomain.com/privkey.pem + SSLCertificateChainFile /etc/letsencrypt/live/www.mydomain.com/chain.pem + + #RewriteEngine on + #RewriteCond %{SERVER_PORT} ^80$ + #RewriteRule ^(.*)$ https://%{SERVER_NAME}$1 [L,R] diff --git a/dev/tools/fixdosfiles.sh b/dev/tools/fixdosfiles.sh index 6fd152127fb..4be867aea98 100755 --- a/dev/tools/fixdosfiles.sh +++ b/dev/tools/fixdosfiles.sh @@ -17,14 +17,14 @@ fi # To detec if [ "x$1" = "xlist" ] then - find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'documents\/website' | grep -v 'documents\/mdedias' | grep CRLF -# find . \( -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" \) -exec file "{}" + | grep -v 'documents\/website' | grep -v 'documents\/mdedias' | grep -v 'htdocs\/includes' | grep CRLF + find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'custom\/' | grep -v 'documents\/website' | grep -v 'documents\/medias' | grep -v 'documents\/sellyoursaas' | grep CRLF +# find . \( -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" \) -exec file "{}" + | grep -v 'custom\/' | grep -v 'documents\/website' | grep -v 'documents\/medias' | grep -v 'documents\/sellyoursaas' | grep -v 'htdocs\/includes' | grep CRLF fi # To convert if [ "x$1" = "xfix" ] then - for fic in `find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'documents\/website' | grep -v 'documents\/mdedias' | grep CRLF | awk -F':' '{ print $1 }' ` + for fic in `find . \( -iname "functions" -o -iname "*.md" -o -iname "*.html" -o -iname "*.htm" -o -iname "*.php" -o -iname "*.sh" -o -iname "*.cml" -o -iname "*.css" -o -iname "*.js" -o -iname "*.lang" -o -iname "*.pl" -o -iname "*.sql" -o -iname "*.txt" -o -iname "*.xml" -o -iname "*.pml" \) -exec file "{}" + | grep -v 'custom\/' | grep -v 'documents\/website' | grep -v 'documents\/medias' | grep -v 'documents\/sellyoursaas' | grep CRLF | awk -F':' '{ print $1 }' ` do echo "Fix file $fic" dos2unix "$fic" diff --git a/dev/tools/optimize_images.sh b/dev/tools/optimize_images.sh index 2f8a84c57e7..dd538c5e1aa 100755 --- a/dev/tools/optimize_images.sh +++ b/dev/tools/optimize_images.sh @@ -14,7 +14,8 @@ max_output_size=0 usage() { cat <trans("New"), $langs->trans("Addanaccount"), 'fa fa-plus-circle', './card.php?action=create'); include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php'; - print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_accountancy', 0, $newcardbutton, '', $limit, 0, 0, 1); + print_barre_liste($langs->trans('ListAccounts'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'accounting_account', 0, $newcardbutton, '', $limit, 0, 0, 1); // Box to select active chart of account print $langs->trans("Selectchartofaccounts")." : "; @@ -404,6 +404,11 @@ if ($resql) { $moreforfilter = ''; + $accountstatic = new AccountingAccount($db); + $accountparent = new AccountingAccount($db); + $totalarray = array(); + $totalarray['nbfield'] = 0; + print '
'; print ''."\n"; @@ -466,11 +471,6 @@ if ($resql) { print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch '); print "\n"; - $accountstatic = new AccountingAccount($db); - $accountparent = new AccountingAccount($db); - $totalarray = array(); - $totalarray['nbfield'] = 0; - $i = 0; while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); @@ -615,8 +615,13 @@ if ($resql) { } if ($num == 0) { - $totalarray['nbfield']++; - print ''; + $colspan = 1; + foreach ($arrayfields as $key => $val) { + if (!empty($val['checked'])) { + $colspan++; + } + } + print ''; } print "
'.$langs->trans("None").'
'.$langs->trans("None").'
"; diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index 9430bf33439..91d8257ea7f 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -417,13 +417,13 @@ if ($action == 'create') { print '
'; if (!empty($user->rights->accounting->chartofaccount)) { - print ''.$langs->trans('Modify').''; + print 'id.'">'.$langs->trans('Modify').''; } else { print ''.$langs->trans('Modify').''; } if (!empty($user->rights->accounting->chartofaccount)) { - print ''.$langs->trans('Delete').''; + print 'id.'">'.$langs->trans('Delete').''; } else { print ''.$langs->trans('Delete').''; } diff --git a/htdocs/accountancy/admin/journals_list.php b/htdocs/accountancy/admin/journals_list.php index 8af707c4626..7f000290e1c 100644 --- a/htdocs/accountancy/admin/journals_list.php +++ b/htdocs/accountancy/admin/journals_list.php @@ -58,8 +58,8 @@ $listoffset = GETPOST('listoffset', 'alpha'); $listlimit = GETPOST('listlimit', 'int') > 0 ?GETPOST('listlimit', 'int') : 1000; $active = 1; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/accountancy/admin/productaccount.php b/htdocs/accountancy/admin/productaccount.php index 8503f3acfd6..847891c949b 100644 --- a/htdocs/accountancy/admin/productaccount.php +++ b/htdocs/accountancy/admin/productaccount.php @@ -80,8 +80,8 @@ if (empty($accounting_product_mode)) { } $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : (empty($conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION) ? $conf->liste_limit : $conf->global->ACCOUNTING_LIMIT_LIST_VENTILATION); -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/accountancy/bookkeeping/balance.php b/htdocs/accountancy/bookkeeping/balance.php index 10bce8bf896..3c2e8763fe1 100644 --- a/htdocs/accountancy/bookkeeping/balance.php +++ b/htdocs/accountancy/bookkeeping/balance.php @@ -237,7 +237,7 @@ if ($action != 'export_csv') { print ''; $parameters = array(); - $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + $reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { $button = 'global->ACCOUNTING_EXPORT_FORMAT.')" />'; @@ -417,7 +417,7 @@ if ($action != 'export_csv') { // Show first line of a break print ''; - print ''.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').''; + print ''.$line->numero_compte.($root_account_description ? ' - '.$root_account_description : '').''; print ''; $displayed_account = $root_account_number; diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 195f7fcb26b..dd6a789b9f9 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -674,7 +674,7 @@ if ($action == 'create') { $resultfetch = $accountingaccount->fetch(null, $line->numero_compte, true); print ''; if ($resultfetch > 0) { - $accountingaccount->getNomUrl(0, 1, 1, '', 0); + print $accountingaccount->getNomUrl(0, 1, 1, '', 0); } else { print $line->numero_compte.' ('.$langs->trans("AccountRemovedFromCurrentChartOfAccount").')'; } diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 8b2ba49d1bc..a90400cfd7a 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -766,7 +766,7 @@ if (count($filter)) { } $parameters = array(); -$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { // Button re-export if (!empty($conf->global->ACCOUNTING_REEXPORT)) { diff --git a/htdocs/accountancy/bookkeeping/listbyaccount.php b/htdocs/accountancy/bookkeeping/listbyaccount.php index 22ba2d3f0b1..837a372a32d 100644 --- a/htdocs/accountancy/bookkeeping/listbyaccount.php +++ b/htdocs/accountancy/bookkeeping/listbyaccount.php @@ -473,7 +473,7 @@ print ''; print ''; $parameters = array(); -$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { $newcardbutton = dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param); $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly btnTitleSelected')); @@ -711,8 +711,8 @@ while ($i < min($num, $limit)) { } // Show the break account - print ""; - print ''; + print ''; + print ''; if ($line->numero_compte != "" && $line->numero_compte != '-1') { print length_accountg($line->numero_compte).' : '.$object->get_compte_desc($line->numero_compte); } else { diff --git a/htdocs/accountancy/bookkeeping/listbysubaccount.php b/htdocs/accountancy/bookkeeping/listbysubaccount.php index 101a8897bb5..c6fb95d5ab7 100644 --- a/htdocs/accountancy/bookkeeping/listbysubaccount.php +++ b/htdocs/accountancy/bookkeeping/listbysubaccount.php @@ -473,7 +473,7 @@ print ''; print ''; $parameters = array(); -$reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook +$reshook = $hookmanager->executeHooks('addMoreActionsButtonsList', $parameters, $object, $action); // Note that $action and $object may have been modified by hook if (empty($reshook)) { $newcardbutton = dolGetButtonTitle($langs->trans('ViewFlatList'), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/list.php?'.$param); $newcardbutton .= dolGetButtonTitle($langs->trans('GroupByAccountAccounting'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/accountancy/bookkeeping/listbyaccount.php?'.$param, '', 1, array('morecss' => 'marginleftonly')); @@ -713,8 +713,8 @@ while ($i < min($num, $limit)) { } // Show the break account - print ""; - print ''; + print ''; + print ''; if ($line->subledger_account != "" && $line->subledger_account != '-1') { print $line->subledger_label.' : '.length_accounta($line->subledger_account); } else { diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettering_customer.php b/htdocs/accountancy/bookkeeping/thirdparty_lettering_customer.php index 29a0171fe08..a563b653ac1 100644 --- a/htdocs/accountancy/bookkeeping/thirdparty_lettering_customer.php +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettering_customer.php @@ -48,8 +48,8 @@ $socid = GETPOSTINT("socid"); // if ($user->socid) $socid=$user->socid; $limit = GETPOSTISSET('limit') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == - 1) { $page = 0; @@ -157,7 +157,7 @@ $sql = "SELECT bk.rowid, bk.doc_date, bk.doc_type, bk.doc_ref, "; $sql .= " bk.subledger_account, bk.numero_compte , bk.label_compte, bk.debit, "; $sql .= " bk.credit, bk.montant, bk.sens, bk.code_journal, bk.piece_num, bk.lettering_code"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as bk"; -$sql .= " WHERE (bk.subledger_account = '".$db->escape($object->code_compta)."' AND bk.numero_compte = '".$db->escape($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)."' )"; +$sql .= " WHERE (bk.subledger_account = '".$db->escape($object->code_compta)."' AND bk.numero_compte = '".$db->escape($conf->global->ACCOUNTING_ACCOUNT_CUSTOMER)."' )"; /* if (dol_strlen($search_date_start) || dol_strlen($search_date_end)) { diff --git a/htdocs/accountancy/bookkeeping/thirdparty_lettering_supplier.php b/htdocs/accountancy/bookkeeping/thirdparty_lettering_supplier.php index d62a1e9fc25..5c315bee9fc 100644 --- a/htdocs/accountancy/bookkeeping/thirdparty_lettering_supplier.php +++ b/htdocs/accountancy/bookkeeping/thirdparty_lettering_supplier.php @@ -48,8 +48,8 @@ $socid = GETPOSTINT("socid"); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == - 1) { $page = 0; diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index 07d28b7abdb..0d0d013a69f 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -915,7 +915,7 @@ class AccountancyExport print "Montantdevise".$separator; print "Idevise".$separator; print "DateLimitReglmt".$separator; - print "NumFacture".$separator; + print "NumFacture"; print $end_line; foreach ($objectLines as $line) { @@ -997,13 +997,13 @@ class AccountancyExport print $line->multicurrency_amount . $separator; // FEC:Idevise - print $line->multicurrency_code.$separator; + print $line->multicurrency_code . $separator; // FEC_suppl:DateLimitReglmt - print $date_limit_payment; + print $date_limit_payment . $separator; // FEC_suppl:NumFacture - print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1) . $separator; + print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1); print $end_line; } @@ -1042,7 +1042,7 @@ class AccountancyExport print "Montantdevise".$separator; print "Idevise".$separator; print "DateLimitReglmt".$separator; - print "NumFacture".$separator; + print "NumFacture"; print $end_line; foreach ($objectLines as $line) { @@ -1127,10 +1127,10 @@ class AccountancyExport print $line->multicurrency_code . $separator; // FEC_suppl:DateLimitReglmt - print $date_limit_payment; + print $date_limit_payment . $separator; // FEC_suppl:NumFacture - print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1) . $separator; + print dol_trunc(self::toAnsi($refInvoice), 17, 'right', 'UTF-8', 1); print $end_line; diff --git a/htdocs/accountancy/class/accountingaccount.class.php b/htdocs/accountancy/class/accountingaccount.class.php index 730e52c805a..a4dcac8c1ad 100644 --- a/htdocs/accountancy/class/accountingaccount.class.php +++ b/htdocs/accountancy/class/accountingaccount.class.php @@ -29,6 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; + /** * Class to manage accounting accounts */ @@ -108,6 +109,11 @@ class AccountingAccount extends CommonObject */ public $account_category; + /** + * @var int Label category account + */ + public $account_category_label; + /** * @var int Status */ @@ -148,6 +154,11 @@ class AccountingAccount extends CommonObject */ private $accountingaccount_codetotid_cache = array(); + + const STATUS_ENABLED = 1; + const STATUS_DISABLED = 0; + + /** * Constructor * @@ -158,7 +169,7 @@ class AccountingAccount extends CommonObject global $conf; $this->db = $db; - $this->next_prev_filter = "fk_pcg_version IN (SELECT pcg_version FROM ".MAIN_DB_PREFIX."accounting_system WHERE rowid=".((int) $conf->global->CHARTOFACCOUNTS).")"; // Used to add a filter in Form::showrefnav method + $this->next_prev_filter = "fk_pcg_version IN (SELECT pcg_version FROM ".MAIN_DB_PREFIX."accounting_system WHERE rowid = ".((int) $conf->global->CHARTOFACCOUNTS).")"; // Used to add a filter in Form::showrefnav method } /** @@ -166,7 +177,7 @@ class AccountingAccount extends CommonObject * * @param int $rowid Id * @param string $account_number Account number - * @param int|boolean $limittocurrentchart 1 or true=Load record only if it is into current active char of account + * @param int|boolean $limittocurrentchart 1 or true=Load record only if it is into current active chart of account * @param string $limittoachartaccount 'ABC'=Load record only if it is into chart account with code 'ABC' (better and faster than previous parameter if you have chart of account code). * @return int <0 if KO, 0 if not found, Id of record if OK and found */ @@ -187,13 +198,14 @@ class AccountingAccount extends CommonObject $sql .= " AND a.entity = ".$conf->entity; } if (!empty($limittocurrentchart)) { - $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.'accounting_system WHERE rowid='.$this->db->escape($conf->global->CHARTOFACCOUNTS).')'; + $sql .= ' AND a.fk_pcg_version IN (SELECT pcg_version FROM '.MAIN_DB_PREFIX.'accounting_system WHERE rowid = '.((int) $conf->global->CHARTOFACCOUNTS).')'; } if (!empty($limittoachartaccount)) { $sql .= " AND a.fk_pcg_version = '".$this->db->escape($limittoachartaccount)."'"; } - dol_syslog(get_class($this)."::fetch", LOG_DEBUG); + dol_syslog(get_class($this)."::fetch rowid=".$rowid." account_number=".$account_number, LOG_DEBUG); + $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); @@ -495,7 +507,7 @@ class AccountingAccount extends CommonObject $url .= '&save_lastsearch_values=1'; } - $picto = 'billr'; + $picto = 'accounting_account'; $label = ''; if (empty($this->labelshort) || $withcompletelabel == 1) { @@ -555,7 +567,7 @@ class AccountingAccount extends CommonObject /** * Information on record * - * @param int $id of record + * @param int $id ID of record * @return void */ public function info($id) @@ -685,49 +697,22 @@ class AccountingAccount extends CommonObject public function LibStatut($status, $mode = 0) { // phpcs:enable - global $langs; - $langs->loadLangs(array("users")); - - if ($mode == 0) { - if ($status == 1) { - return $langs->trans('Enabled'); - } elseif ($status == 0) { - return $langs->trans('Disabled'); - } - } elseif ($mode == 1) { - if ($status == 1) { - return $langs->trans('Enabled'); - } elseif ($status == 0) { - return $langs->trans('Disabled'); - } - } elseif ($mode == 2) { - if ($status == 1) { - return img_picto($langs->trans('Enabled'), 'statut4') . ' ' . $langs->trans('Enabled'); - } elseif ($status == 0) { - return img_picto($langs->trans('Disabled'), 'statut5') . ' ' . $langs->trans('Disabled'); - } - } elseif ($mode == 3) { - if ($status == 1) { - return img_picto($langs->trans('Enabled'), 'statut4'); - } elseif ($status == 0) { - return img_picto($langs->trans('Disabled'), 'statut5'); - } - } elseif ($mode == 4) { - if ($status == 1) { - return img_picto($langs->trans('Enabled'), 'statut4') . ' ' . $langs->trans('Enabled'); - } elseif ($status == 0) { - return img_picto($langs->trans('Disabled'), 'statut5') . ' ' . $langs->trans('Disabled'); - } - } elseif ($mode == 5) { - if ($status == 1) { - return $langs->trans('Enabled') . ' ' . img_picto($langs->trans('Enabled'), 'statut4'); - } elseif ($status == 0) { - return $langs->trans('Disabled') . ' ' . img_picto($langs->trans('Disabled'), 'statut5'); - } + if (empty($this->labelStatus) || empty($this->labelStatusShort)) { + global $langs; + $langs->load("users"); + $this->labelStatus[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled'); + $this->labelStatus[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled'); + $this->labelStatusShort[self::STATUS_ENABLED] = $langs->transnoentitiesnoconv('Enabled'); + $this->labelStatusShort[self::STATUS_DISABLED] = $langs->transnoentitiesnoconv('Disabled'); } - } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + $statusType = 'status4'; + if ($status == self::STATUS_DISABLED) { + $statusType = 'status5'; + } + + return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); + } /** * Return Suggest accounting accounts to bind @@ -866,8 +851,8 @@ class AccountingAccount extends CommonObject // Level 3 (define $code_t): Search suggested account for this thirdparty (similar code exists in page index.php to make automatic binding) if (!empty($conf->global->ACCOUNTANCY_USE_PRODUCT_ACCOUNT_ON_THIRDPARTY)) { - if (!empty($buyer->code_compta)) { - $code_t = $buyer->code_compta; + if (!empty($buyer->code_compta_product)) { + $code_t = $buyer->code_compta_product; $suggestedid = $accountingAccount['thirdparty']; $suggestedaccountingaccountfor = 'thridparty'; } diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 9cda04f6155..e96cf9e0997 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -1013,7 +1013,7 @@ class BookKeeping extends CommonObject } elseif ($key == 't.numero_compte>=' || $key == 't.numero_compte<=' || $key == 't.subledger_account>=' || $key == 't.subledger_account<=') { $sqlwhere[] = $key.'\''.$this->db->escape($value).'\''; } elseif ($key == 't.fk_doc' || $key == 't.fk_docdet' || $key == 't.piece_num') { - $sqlwhere[] = $key.'='.$value; + $sqlwhere[] = $key.'='.((int) $value); } elseif ($key == 't.subledger_account' || $key == 't.numero_compte') { $sqlwhere[] = $key.' LIKE \''.$this->db->escape($value).'%\''; } elseif ($key == 't.date_creation>=' || $key == 't.date_creation<=') { @@ -2114,15 +2114,26 @@ class BookKeepingLine public $montant; /** - * @var float Amount + * @var float Amount */ public $amount; + /** + * @var float Multicurrency amount + */ + public $multicurrency_amount; + + /** + * @var float Multicurrency code + */ + public $multicurrency_code; + /** * @var string Sens */ public $sens; public $lettering_code; + public $date_lettering; /** * @var int ID @@ -2153,4 +2164,9 @@ class BookKeepingLine * @var integer|string $date_validation; */ public $date_validation; + + /** + * @var integer|string $date_lim_reglement; + */ + public $date_lim_reglement; } diff --git a/htdocs/accountancy/closure/index.php b/htdocs/accountancy/closure/index.php index fdcc6f54ab3..6b578bcab71 100644 --- a/htdocs/accountancy/closure/index.php +++ b/htdocs/accountancy/closure/index.php @@ -31,7 +31,8 @@ require_once DOL_DOCUMENT_ROOT.'/accountancy/class/bookkeeping.class.php'; // Load translation files required by the page $langs->loadLangs(array("compta", "bills", "other", "accountancy")); -$socid = GETPOST('socid', 'int'); +$validatemonth = GETPOST('validatemonth', 'int'); +$validateyear = GETPOST('validateyear', 'int'); $action = GETPOST('action', 'aZ09'); @@ -68,52 +69,47 @@ if (empty($user->rights->accounting->fiscalyear->write)) { } + /* * Actions */ +$now = dol_now(); + if ($action == 'validate_movements_confirm' && !empty($user->rights->accounting->fiscalyear->write)) { - $result = $object->fetchAll(); + $date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); + $date_end = dol_mktime(23, 59, 59, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); - if ($result < 0) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - // Specify as export : update field date_validated on selected month/year - $error = 0; - $db->begin(); + $error = 0; - $date_start = dol_mktime(0, 0, 0, GETPOST('date_startmonth', 'int'), GETPOST('date_startday', 'int'), GETPOST('date_startyear', 'int')); - $date_end = dol_mktime(23, 59, 59, GETPOST('date_endmonth', 'int'), GETPOST('date_endday', 'int'), GETPOST('date_endyear', 'int')); + $db->begin(); - if (is_array($object->lines)) { - foreach ($object->lines as $movement) { - $now = dol_now(); + // Specify as export : update field date_validated on selected month/year + $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping"; + $sql .= " SET date_validated = '".$db->idate($now)."'"; + $sql .= " WHERE entity = " . ((int) $conf->entity); + $sql .= " AND doc_date >= '" . $db->idate($date_start) . "'"; + $sql .= " AND doc_date <= '" . $db->idate($date_end) . "'"; + $sql .= " AND date_validated IS NULL"; - $sql = " UPDATE ".MAIN_DB_PREFIX."accounting_bookkeeping"; - $sql .= " SET date_validated = '".$db->idate($now)."'"; - $sql .= " WHERE rowid = ".((int) $movement->id); - $sql .= " AND doc_date >= '" . $db->idate($date_start) . "'"; - $sql .= " AND doc_date <= '" . $db->idate($date_end) . "'"; + dol_syslog("/accountancy/closure/index.php action=validate_movement_confirm -> Set movements as validated", LOG_DEBUG); + $result = $db->query($sql); + if (!$result) { + $error++; + } - dol_syslog("/accountancy/closure/index.php :: Function validate_movement_confirm Specify movements as validated", LOG_DEBUG); - $result = $db->query($sql); - if (!$result) { - $error++; - break; - } - } - } + if (!$error) { + $db->commit(); + + setEventMessages($langs->trans("AllMovementsWereRecordedAsValidated"), null, 'mesgs'); - if (!$error) { - $db->commit(); - setEventMessages($langs->trans("AllMovementsWereRecordedAsValidated"), null, 'mesgs'); - } else { - $error++; - $db->rollback(); - setEventMessages($langs->trans("NotAllMovementsCouldBeRecordedAsValidated"), null, 'errors'); - } header("Location: ".$_SERVER['PHP_SELF']."?year=".$year_start); exit; + } else { + $db->rollback(); + + setEventMessages($langs->trans("NotAllMovementsCouldBeRecordedAsValidated"), null, 'errors'); + $action = ''; } } diff --git a/htdocs/accountancy/customer/index.php b/htdocs/accountancy/customer/index.php index e2ed822e35a..7ce226f99d8 100644 --- a/htdocs/accountancy/customer/index.php +++ b/htdocs/accountancy/customer/index.php @@ -120,6 +120,7 @@ if (($action == 'clean' || $action == 'validatehistory') && $user->rights->accou if ($action == 'validatehistory') { $error = 0; $nbbinddone = 0; + $notpossible = 0; $db->begin(); @@ -152,18 +153,17 @@ if ($action == 'validatehistory') { $sql .= " co.code as country_code, co.label as country_label,"; $sql .= " s.tva_intra,"; if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { - $sql .= " spe.accountancy_code_sell as company_code_sell"; + $sql .= " spe.accountancy_code_sell as company_code_sell"; // accounting code for product but stored on thirdparty } else { - $sql .= " s.accountancy_code_sell as company_code_sell"; + $sql .= " s.accountancy_code_sell as company_code_sell"; // accounting code for product but stored on thirdparty } - $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe_perentity as spe ON spe.fk_soc = s.rowid AND spe.entity = " . ((int) $conf->entity); } $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = s.fk_pays "; - $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facturedet as l ON f.rowid = l.fk_facture"; + $sql .= " INNER JOIN ".MAIN_DB_PREFIX."facturedet as l ON f.rowid = l.fk_facture"; // the main table $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON p.rowid = l.fk_product"; if (!empty($conf->global->MAIN_PRODUCT_PERENTITY_SHARED)) { $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_perentity as ppe ON ppe.fk_product = p.rowid AND ppe.entity = " . ((int) $conf->entity); @@ -174,8 +174,7 @@ if ($action == 'validatehistory') { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON " . $alias_product_perentity . ".accountancy_code_sell_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_product_perentity . ".accountancy_code_sell_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa4 ON " . $alias_societe_perentity . ".accountancy_code_sell = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa4.entity = ".$conf->entity; - $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0"; - $sql .= " AND l.product_type <= 2"; + $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0 AND l.product_type <= 2 AND f.entity = ".((int) $conf->entity); if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) { $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'"; } @@ -216,7 +215,7 @@ if ($action == 'validatehistory') { $thirdpartystatic->email = $objp->email; $thirdpartystatic->country_code = $objp->country_code; $thirdpartystatic->tva_intra = $objp->tva_intra; - $thirdpartystatic->code_compta = $objp->company_code_sell; + $thirdpartystatic->code_compta_product = $objp->company_code_sell; // The accounting account for product stored on thirdparty object (for level3 suggestion) $product_static->ref = $objp->product_ref; $product_static->id = $objp->product_id; @@ -256,7 +255,7 @@ if ($action == 'validatehistory') { $suggestedid = 0; $return=$accountingAccount->getAccountingCodeToBind($thirdpartystatic, $mysoc, $product_static, $facture_static, $facture_static_det, $accountingAccountArray, 'customer'); - if (!is_array($return) && $return<0) { + if (!is_array($return) && $return < 0) { setEventMessage($accountingAccount->error, 'errors'); } else { $suggestedid = $return['suggestedid']; @@ -282,17 +281,22 @@ if ($action == 'validatehistory') { } else { $nbbinddone++; } + } else { + $notpossible++; } $i++; } + if ($num_lines > 10000) { + $notpossible += ($num_lines - 10000); + } } if ($error) { $db->rollback(); } else { $db->commit(); - setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone), null, 'mesgs'); + setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone, $notpossible), null, 'mesgs'); } } @@ -628,16 +632,22 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange print ''.$langs->trans('MonthShort'.str_pad($j, 2, '0', STR_PAD_LEFT)).''; } print ''.$langs->trans("Total").''; - $sql = "SELECT '".$db->escape($langs->trans("Vide"))."' AS marge,"; for ($i = 1; $i <= 12; $i++) { $j = $i + ($conf->global->SOCIETE_FISCAL_MONTH_START ? $conf->global->SOCIETE_FISCAL_MONTH_START : 1) - 1; if ($j > 12) { $j -= 12; } - $sql .= " SUM(".$db->ifsql("MONTH(f.datef)=".$j, "(fd.total_ht-(fd.qty * fd.buy_price_ht))", "0").") AS month".str_pad($j, 2, "0", STR_PAD_LEFT).","; + $sql .= " SUM(".$db->ifsql("MONTH(f.datef)=".$j, + " (".$db->ifsql("fd.total_ht < 0", + " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))", + " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").")", + 0).") AS month".str_pad($j, 2, '0', STR_PAD_LEFT).","; } - $sql .= " SUM((fd.total_ht-(fd.qty * fd.buy_price_ht))) as total"; + $sql .= " SUM(".$db->ifsql("fd.total_ht < 0", + " (-1 * (abs(fd.total_ht) - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100))))", + " (fd.total_ht - (fd.buy_price_ht * fd.qty * (fd.situation_percent / 100)))").") as total"; + $sql .= " FROM ".MAIN_DB_PREFIX."facturedet as fd"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON f.rowid = fd.fk_facture"; $sql .= " WHERE f.datef >= '".$db->idate($search_date_start)."'"; @@ -654,7 +664,6 @@ if ($conf->global->MAIN_FEATURES_LEVEL > 0) { // This part of code looks strange } else { $sql .= " AND f.type IN (".Facture::TYPE_STANDARD.", ".Facture::TYPE_REPLACEMENT.", ".Facture::TYPE_CREDIT_NOTE.", ".Facture::TYPE_DEPOSIT.", ".Facture::TYPE_SITUATION.")"; } - dol_syslog('htdocs/accountancy/customer/index.php'); $resql = $db->query($sql); if ($resql) { diff --git a/htdocs/accountancy/customer/list.php b/htdocs/accountancy/customer/list.php index 582877d3599..56f904e79ef 100644 --- a/htdocs/accountancy/customer/list.php +++ b/htdocs/accountancy/customer/list.php @@ -539,13 +539,14 @@ if ($result) { $thirdpartystatic->client = $objp->client; $thirdpartystatic->fournisseur = $objp->fournisseur; $thirdpartystatic->code_client = $objp->code_client; + $thirdpartystatic->code_compta = $objp->code_compta_client; // For backward compatibility $thirdpartystatic->code_compta_client = $objp->code_compta_client; $thirdpartystatic->code_fournisseur = $objp->code_fournisseur; $thirdpartystatic->code_compta_fournisseur = $objp->code_compta_fournisseur; $thirdpartystatic->email = $objp->email; $thirdpartystatic->country_code = $objp->country_code; $thirdpartystatic->tva_intra = $objp->tva_intra; - $thirdpartystatic->code_compta_company = $objp->company_code_sell; + $thirdpartystatic->code_compta_product = $objp->company_code_sell; // The accounting account for product stored on thirdparty object (for level3 suggestion) $product_static->ref = $objp->product_ref; $product_static->id = $objp->product_id; diff --git a/htdocs/accountancy/expensereport/index.php b/htdocs/accountancy/expensereport/index.php index 0987afb0c6a..37abd56a21d 100644 --- a/htdocs/accountancy/expensereport/index.php +++ b/htdocs/accountancy/expensereport/index.php @@ -99,42 +99,69 @@ if (($action == 'clean' || $action == 'validatehistory') && $user->rights->accou if ($action == 'validatehistory') { $error = 0; + $nbbinddone = 0; + $notpossible = 0; + $db->begin(); // Now make the binding - if ($db->type == 'pgsql') { - $sql1 = "UPDATE ".MAIN_DB_PREFIX."expensereport_det"; - $sql1 .= " SET fk_code_ventilation = accnt.rowid"; - $sql1 .= " FROM ".MAIN_DB_PREFIX."c_type_fees as t, ".MAIN_DB_PREFIX."accounting_account as accnt , ".MAIN_DB_PREFIX."accounting_system as syst"; - $sql1 .= " WHERE ".MAIN_DB_PREFIX."expensereport_det.fk_c_type_fees = t.id AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid = ".((int) $conf->global->CHARTOFACCOUNTS).' AND accnt.entity = '.((int) $conf->entity); - $sql1 .= " AND accnt.active = 1 AND t.accountancy_code = accnt.account_number"; - $sql1 .= " AND ".MAIN_DB_PREFIX."expensereport_det.fk_code_ventilation = 0"; - if ($validatemonth && $validateyear) { - $sql1 .= dolSqlDateFilter('date', 0, $validatemonth, $validateyear); - } - } else { - $sql1 = "UPDATE ".MAIN_DB_PREFIX."expensereport_det as erd, ".MAIN_DB_PREFIX."c_type_fees as t, ".MAIN_DB_PREFIX."accounting_account as accnt , ".MAIN_DB_PREFIX."accounting_system as syst"; - $sql1 .= " SET erd.fk_code_ventilation = accnt.rowid"; - $sql1 .= " WHERE erd.fk_c_type_fees = t.id AND accnt.fk_pcg_version = syst.pcg_version AND syst.rowid = ".((int) $conf->global->CHARTOFACCOUNTS).' AND accnt.entity = '.((int) $conf->entity); - $sql1 .= " AND accnt.active = 1 AND t.accountancy_code=accnt.account_number"; - $sql1 .= " AND erd.fk_code_ventilation = 0"; - if ($validatemonth && $validateyear) { - $sql1 .= dolSqlDateFilter('erd.date', 0, $validatemonth, $validateyear); - } + $sql1 = "SELECT erd.rowid, accnt.rowid as suggestedid"; + $sql1 .= " FROM ".MAIN_DB_PREFIX."expensereport_det as erd"; + $sql1 .= " LEFT JOIN ".MAIN_DB_PREFIX."c_type_fees as t ON erd.fk_c_type_fees = t.id"; + $sql1 .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as accnt ON t.accountancy_code = accnt.account_number AND accnt.active = 1 AND accnt.entity =".((int) $conf->entity); + $sql1 .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_system as syst ON accnt.fk_pcg_version = syst.pcg_version AND syst.rowid = ".((int) $conf->global->CHARTOFACCOUNTS).' AND syst.active = 1,'; + $sql1 .= " ".MAIN_DB_PREFIX."expensereport as er"; + $sql1 .= " WHERE erd.fk_expensereport = er.rowid AND er.entity = ".((int) $conf->entity); + $sql1 .= " AND er.fk_statut IN (".ExpenseReport::STATUS_APPROVED.", ".ExpenseReport::STATUS_CLOSED.") AND erd.fk_code_ventilation <= 0"; + if ($validatemonth && $validateyear) { + $sql1 .= dolSqlDateFilter('erd.date', 0, $validatemonth, $validateyear); } dol_syslog('htdocs/accountancy/expensereport/index.php'); - $resql1 = $db->query($sql1); - if (!$resql1) { + $result = $db->query($sql1); + if (!$result) { $error++; - $db->rollback(); setEventMessages($db->lasterror(), null, 'errors'); } else { - $nbbinddone = $db->affected_rows($resql1); + $num_lines = $db->num_rows($result); + $i = 0; + while ($i < min($num_lines, 10000)) { // No more than 10000 at once + $objp = $db->fetch_object($result); + + $lineid = $objp->rowid; + $suggestedid = $objp->suggestedid; + + if ($suggestedid > 0) { + $sqlupdate = "UPDATE ".MAIN_DB_PREFIX."expensereport_det"; + $sqlupdate .= " SET fk_code_ventilation = ".((int) $suggestedid); + $sqlupdate .= " WHERE fk_code_ventilation <= 0 AND rowid = ".((int) $lineid); + + $resqlupdate = $db->query($sqlupdate); + if (!$resqlupdate) { + $error++; + setEventMessages($db->lasterror(), null, 'errors'); + break; + } else { + $nbbinddone++; + } + } else { + $notpossible++; + } + + $i++; + } + if ($num_lines > 10000) { + $notpossible += ($num_lines - 10000); + } + } + + if ($error) { + $db->rollback(); + } else { $db->commit(); - setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone), null, 'mesgs'); + setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone, $notpossible), null, 'mesgs'); } } @@ -157,7 +184,7 @@ print '
'; $y = $year_current; -$buttonbind = ''.$langs->trans("ValidateHistory").''; +$buttonbind = ''.$langs->trans("ValidateHistory").''; print_barre_liste(img_picto('', 'unlink', 'class="paddingright fa-color-unset"').$langs->trans("OverviewOfAmountOfLinesNotBound"), '', '', '', '', '', '', -1, '', '', 0, $buttonbind, '', 0, 1, 1); diff --git a/htdocs/accountancy/expensereport/lines.php b/htdocs/accountancy/expensereport/lines.php index b262f85367a..fb3bf1a6e04 100644 --- a/htdocs/accountancy/expensereport/lines.php +++ b/htdocs/accountancy/expensereport/lines.php @@ -394,11 +394,12 @@ if ($result) { print ''.vatrate($objp->tva_tx.($objp->vat_src_code ? ' ('.$objp->vat_src_code.')' : '')).''; // Accounting account affected - print ''; + print ''; print $accountingaccountstatic->getNomUrl(0, 1, 1, '', 1); print ' '; print img_edit(); print ''; + print ''; print ""; diff --git a/htdocs/accountancy/supplier/index.php b/htdocs/accountancy/supplier/index.php index 1a0c8909829..70434a470f1 100644 --- a/htdocs/accountancy/supplier/index.php +++ b/htdocs/accountancy/supplier/index.php @@ -118,6 +118,7 @@ if (($action == 'clean' || $action == 'validatehistory') && $user->rights->accou if ($action == 'validatehistory') { $error = 0; $nbbinddone = 0; + $notpossible = 0; $db->begin(); @@ -154,7 +155,6 @@ if ($action == 'validatehistory') { } else { $sql .= " s.accountancy_code_buy as company_code_buy"; } - $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = f.fk_soc"; if (!empty($conf->global->MAIN_COMPANY_PERENTITY_SHARED)) { @@ -172,8 +172,7 @@ if ($action == 'validatehistory') { $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa2 ON " . $alias_product_perentity . ".accountancy_code_buy_intra = aa2.account_number AND aa2.active = 1 AND aa2.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa2.entity = ".$conf->entity; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa3 ON " . $alias_product_perentity . ".accountancy_code_buy_export = aa3.account_number AND aa3.active = 1 AND aa3.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa3.entity = ".$conf->entity; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."accounting_account as aa4 ON " . $alias_societe_perentity . ".accountancy_code_buy = aa4.account_number AND aa4.active = 1 AND aa4.fk_pcg_version = '".$db->escape($chartaccountcode)."' AND aa4.entity = ".$conf->entity; - $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0"; - $sql .= " AND l.product_type <= 2"; + $sql .= " WHERE f.fk_statut > 0 AND l.fk_code_ventilation <= 0 AND l.product_type <= 2 AND f.entity = ".((int) $conf->entity); if (!empty($conf->global->ACCOUNTING_DATE_START_BINDING)) { $sql .= " AND f.datef >= '".$db->idate($conf->global->ACCOUNTING_DATE_START_BINDING)."'"; } @@ -212,7 +211,7 @@ if ($action == 'validatehistory') { $thirdpartystatic->email = $objp->email; $thirdpartystatic->country_code = $objp->country_code; $thirdpartystatic->tva_intra = $objp->tva_intra; - $thirdpartystatic->code_compta = $objp->company_code_sell; + $thirdpartystatic->code_compta_product = $objp->company_code_buy; // The accounting account for product stored on thirdparty object (for level3 suggestion) $product_static->ref = $objp->product_ref; $product_static->id = $objp->product_id; @@ -231,7 +230,7 @@ if ($action == 'validatehistory') { $facture_static->ref = $objp->ref; $facture_static->id = $objp->facid; $facture_static->type = $objp->ftype; - $facture_static->datef = $objp->datef; + $facture_static->date = $objp->datef; $facture_static_det->id = $objp->rowid; $facture_static_det->total_ht = $objp->total_ht; @@ -278,17 +277,22 @@ if ($action == 'validatehistory') { } else { $nbbinddone++; } + } else { + $notpossible++; } $i++; } + if ($num_lines > 10000) { + $notpossible += ($num_lines - 10000); + } } if ($error) { $db->rollback(); } else { $db->commit(); - setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone), null, 'mesgs'); + setEventMessages($langs->trans('AutomaticBindingDone', $nbbinddone, $notpossible), null, 'mesgs'); } } diff --git a/htdocs/accountancy/supplier/list.php b/htdocs/accountancy/supplier/list.php index f88c1dd8ccc..6364ce914c6 100644 --- a/htdocs/accountancy/supplier/list.php +++ b/htdocs/accountancy/supplier/list.php @@ -547,7 +547,7 @@ if ($result) { $thirdpartystatic->email = $objp->email; $thirdpartystatic->country_code = $objp->country_code; $thirdpartystatic->tva_intra = $objp->tva_intra; - $thirdpartystatic->code_compta_company = $objp->company_code_buy; + $thirdpartystatic->code_compta_product = $objp->company_code_buy; // The accounting account for product stored on thirdparty object (for level3 suggestion) $product_static->ref = $objp->product_ref; $product_static->id = $objp->product_id; diff --git a/htdocs/adherents/agenda.php b/htdocs/adherents/agenda.php index 3f7114380f3..cb942ba3176 100644 --- a/htdocs/adherents/agenda.php +++ b/htdocs/adherents/agenda.php @@ -39,8 +39,8 @@ $langs->loadLangs(array("companies", "members")); $id = GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('rowid', 'int'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; @@ -136,7 +136,11 @@ if ($object->id > 0) { $linkback = ''.$langs->trans("BackToList").''; - dol_banner_tab($object, 'rowid', $linkback); + $morehtmlref = ''; + $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); + $morehtmlref .= ''; + + dol_banner_tab($object, 'rowid', $linkback, 1, 'rowid', 'ref', $morehtmlref); print '
'; diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 9dcb514cc36..a2e3779d52b 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -918,12 +918,8 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { // When used in standard mode // ----------------------------------------- + // Create mode if ($action == 'create') { - /* ************************************************************************** */ - /* */ - /* Creation mode */ - /* */ - /* ************************************************************************** */ $object->canvas = $canvas; $object->state_id = GETPOST('state_id', 'int'); @@ -953,7 +949,7 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { print load_fiche_titre($langs->trans("NewMember"), '', $object->picto); if ($conf->use_javascript_ajax) { - print "\n".''; print ''; } - print ''; + print ''; print ' '; print ''; print ''; @@ -1339,14 +1339,15 @@ if ($resql) { $labeltoshow = $langs->trans($reg[1]); } else { if ($objp->label == '(payment_salary)') { - $labeltoshow = dol_trunc($langs->trans("SalaryPayment", 40)); + $labeltoshow = $langs->trans("SalaryPayment"); } else { $labeltoshow = dol_escape_htmltag($objp->label); $titletoshow = $objp->label; } } - print ''; - print $labeltoshow; // Already escaped + + + print ''; // Add info about links after description $cachebankaccount = array(); @@ -1355,70 +1356,70 @@ if ($resql) { if ($links[$key]['type'] == 'withdraw') { $banktransferstatic->id = $links[$key]['url_id']; $banktransferstatic->ref = $links[$key]['label']; - print ' '.$banktransferstatic->getNomUrl(0); + print $banktransferstatic->getNomUrl(0).' '; } elseif ($links[$key]['type'] == 'payment') { $paymentstatic->id = $links[$key]['url_id']; $paymentstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment $paymentstatic->date = $db->jdate($objp->do); - print ' '.$paymentstatic->getNomUrl(2); + print $paymentstatic->getNomUrl(2).' '; } elseif ($links[$key]['type'] == 'payment_supplier') { $paymentsupplierstatic->id = $links[$key]['url_id']; $paymentsupplierstatic->ref = $links[$key]['url_id']; // FIXME This is id, not ref of payment - print ' '.$paymentsupplierstatic->getNomUrl(2); + print $paymentsupplierstatic->getNomUrl(2).' '; } elseif ($links[$key]['type'] == 'payment_sc') { $paymentscstatic->id = $links[$key]['url_id']; $paymentscstatic->ref = $links[$key]['url_id']; $paymentscstatic->label = $links[$key]['label']; - print ' '.$paymentscstatic->getNomUrl(2); + print $paymentscstatic->getNomUrl(2).' '; } elseif ($links[$key]['type'] == 'payment_vat') { $paymentvatstatic->id = $links[$key]['url_id']; $paymentvatstatic->ref = $links[$key]['url_id']; - print ' '.$paymentvatstatic->getNomUrl(2); + print $paymentvatstatic->getNomUrl(2).' '; } elseif ($links[$key]['type'] == 'payment_salary') { $paymentsalstatic->id = $links[$key]['url_id']; $paymentsalstatic->ref = $links[$key]['url_id']; $paymentsalstatic->label = $links[$key]['label']; - print ' '.$paymentsalstatic->getNomUrl(2); + print $paymentsalstatic->getNomUrl(2).' '; } elseif ($links[$key]['type'] == 'payment_loan') { print ''; print ' '.img_object($langs->trans('ShowPayment'), 'payment').' '; - print ''; + print ' '; } elseif ($links[$key]['type'] == 'payment_donation') { $paymentdonationstatic->id = $links[$key]['url_id']; $paymentdonationstatic->ref = $links[$key]['url_id']; - print ' '.$paymentdonationstatic->getNomUrl(2); + print $paymentdonationstatic->getNomUrl(2).' '; } elseif ($links[$key]['type'] == 'payment_expensereport') { $paymentexpensereportstatic->id = $links[$key]['url_id']; $paymentexpensereportstatic->ref = $links[$key]['url_id']; - print ' '.$paymentexpensereportstatic->getNomUrl(2); + print $paymentexpensereportstatic->getNomUrl(2).' '; } elseif ($links[$key]['type'] == 'payment_various') { $paymentvariousstatic->id = $links[$key]['url_id']; $paymentvariousstatic->ref = $links[$key]['url_id']; - print ' '.$paymentvariousstatic->getNomUrl(2); + print $paymentvariousstatic->getNomUrl(2).' '; } elseif ($links[$key]['type'] == 'banktransfert') { // Do not show link to transfer since there is no transfer card (avoid confusion). Can already be accessed from transaction detail. if ($objp->amount > 0) { $banklinestatic->fetch($links[$key]['url_id']); $bankstatic->id = $banklinestatic->fk_account; $bankstatic->label = $banklinestatic->bank_account_ref; - print ' ('.$langs->trans("TransferFrom").' '; + print $langs->trans("TransferFrom").' '; print $bankstatic->getNomUrl(1, 'transactions'); print ' '.$langs->trans("toward").' '; $bankstatic->id = $objp->bankid; $bankstatic->label = $objp->bankref; print $bankstatic->getNomUrl(1, ''); - print ')'; + print ' - '; } else { $bankstatic->id = $objp->bankid; $bankstatic->label = $objp->bankref; - print ' ('.$langs->trans("TransferFrom").' '; + print $langs->trans("TransferFrom").' '; print $bankstatic->getNomUrl(1, ''); print ' '.$langs->trans("toward").' '; $banklinestatic->fetch($links[$key]['url_id']); $bankstatic->id = $banklinestatic->fk_account; $bankstatic->label = $banklinestatic->bank_account_ref; print $bankstatic->getNomUrl(1, 'transactions'); - print ')'; + print ' - '; } //var_dump($links); } elseif ($links[$key]['type'] == 'company') { @@ -1430,22 +1431,22 @@ if ($resql) { // Information is already shown using the payment_salary link. No need of this link. } else { // Show link with label $links[$key]['label'] - if (!empty($objp->label) && !empty($links[$key]['label'])) { - print ' - '; - } print ''; if (preg_match('/^\((.*)\)$/i', $links[$key]['label'], $reg)) { // Label generique car entre parentheses. On l'affiche en le traduisant if ($reg[1] == 'paiement') { $reg[1] = 'Payment'; } - print ' '.$langs->trans($reg[1]); + print $langs->trans($reg[1]); } else { - print ' '.$links[$key]['label']; + print $links[$key]['label']; } - print ''; + print ''.($labeltoshow ? ' - ' : ''); } } + + print $labeltoshow; // Already escaped + print ''; if (!$i) { $totalarray['nbfield']++; @@ -1488,7 +1489,7 @@ if ($resql) { // Payment type if (!empty($arrayfields['type']['checked'])) { - print ''; + print ''; $labeltype = ($langs->trans("PaymentTypeShort".$objp->fk_type) != "PaymentTypeShort".$objp->fk_type) ? $langs->trans("PaymentTypeShort".$objp->fk_type) : $langs->getLabelFromKey($db, $objp->fk_type, 'c_paiement', 'code', 'libelle', '', 1); if ($labeltype == 'SOLD') { print ' '; //$langs->trans("InitialBankBalance"); @@ -1514,9 +1515,9 @@ if ($resql) { print ''; $companylinked_id = 0; - $userlinked_id = 0; + $userlinked_id = 0; - //payment line type to define user display and user or company linked + //payment line type to define user display and user or company linked foreach ($links as $key => $value) { if ($links[$key]['type'] == 'payment_sc') { $type_link = 'payment_sc'; @@ -1663,20 +1664,20 @@ if ($resql) { } } - // Action edit/delete + // Action edit/delete and select print ''; // Transaction reconciliated or edit link if ($objp->conciliated && $bankaccount->canBeConciliated() > 0) { // If line not conciliated and account can be conciliated - print ''; + print ''; print img_edit(); print ''; } else { if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { - print ''; + print ''; print img_edit(); print ''; } else { - print ''; + print ''; print img_view(); print ''; } @@ -1686,24 +1687,19 @@ if ($resql) { } } if ($user->rights->banque->modifier) { - print 'rowid.'&id='.$objp->bankid.'&page='.$page.'">'; + print 'rowid.'&page='.$page.$param.($sortfield ? '&sortfield='.$sortfield : '').($sortorder ? '&sortorder='.$sortorder : '').'">'; print img_delete('', 'class="marginleftonly"'); print ''; } } - print ''; - if (!$i) { - $totalarray['nbfield']++; - } // Action column - print ''; if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined $selected = 0; if (in_array($obj->rowid, $arrayofselected)) { $selected = 1; } - print ''; + print ''; } print ''; if (!$i) { diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index 9f000786b7f..5d2bb71109b 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -1060,19 +1060,19 @@ if ($action == 'create') { // IBAN print ''.$langs->trans($ibankey).''; - print ''; + print ''; print ''.$langs->trans($bickey).''; - print ''; + print ''; if ($conf->prelevement->enabled) { print ''.$langs->trans("ICS").' ('.$langs->trans("StandingOrder").')'; - print ''; + print ''; } if ($conf->paymentbybanktransfer->enabled) { print ''.$langs->trans("ICS").' ('.$langs->trans("BankTransfer").')'; - print ''; + print ''; } print ''.$langs->trans("BankAccountDomiciliation").''; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 685c78f5f1b..c2745b31426 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -132,11 +132,19 @@ class Account extends CommonObject public $bic; /** - * IBAN number (International Bank Account Number). Stored into iban_prefix field into database + * IBAN number (International Bank Account Number). Stored into iban_prefix field into database (TODO Rename field in database) * @var string */ public $iban; + /** + * IBAN number + * + * @var string + * @deprecated see $iban + */ + public $iban_prefix; + /** * Name of account holder * @var string diff --git a/htdocs/compta/bank/class/api_bankaccounts.class.php b/htdocs/compta/bank/class/api_bankaccounts.class.php index fd7ed1838f2..23d4c2eefbb 100644 --- a/htdocs/compta/bank/class/api_bankaccounts.class.php +++ b/htdocs/compta/bank/class/api_bankaccounts.class.php @@ -81,8 +81,9 @@ class BankAccounts extends DolibarrApi } // Add sql filters if ($sqlfilters) { - if (!DolibarrApi::_checkFilters($sqlfilters)) { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + $errormessage = ''; + if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) { + throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage); } $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)'; $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; @@ -438,8 +439,9 @@ class BankAccounts extends DolibarrApi // Add sql filters if ($sqlfilters) { - if (!DolibarrApi::_checkFilters($sqlfilters)) { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + $errormessage = ''; + if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) { + throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage); } $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)'; $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; diff --git a/htdocs/compta/bank/document.php b/htdocs/compta/bank/document.php index 389c8195f37..78d45beadf3 100644 --- a/htdocs/compta/bank/document.php +++ b/htdocs/compta/bank/document.php @@ -50,8 +50,8 @@ if ($user->socid) { // Get parameters $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/bank/info.php b/htdocs/compta/bank/info.php index e8514c1e96e..1bbab933e7b 100644 --- a/htdocs/compta/bank/info.php +++ b/htdocs/compta/bank/info.php @@ -30,16 +30,19 @@ require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; $langs->loadLangs(array('banks', 'categories', 'companies')); $id = GETPOST("rowid", 'int'); +$accountid = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('account', 'int')); $ref = GETPOST('ref', 'alpha'); // Security check $fieldvalue = (!empty($id) ? $id : (!empty($ref) ? $ref : '')); + $fieldtype = (!empty($ref) ? 'ref' : 'rowid'); if ($user->socid) { $socid = $user->socid; } -$result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account', '', '', $fieldtype); -if (empty($user->rights->banque->lire) && !$user->rights->banque->consolidate) { + +$result = restrictedArea($user, 'banque', $accountid, 'bank_account'); +if (empty($user->rights->banque->lire) && empty($user->rights->banque->consolidate)) { accessforbidden(); } diff --git a/htdocs/compta/bank/line.php b/htdocs/compta/bank/line.php index f86c50f31cc..bc70d27ba70 100644 --- a/htdocs/compta/bank/line.php +++ b/htdocs/compta/bank/line.php @@ -51,7 +51,8 @@ if (!empty($conf->salaries->enabled)) { } -$id = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('account', 'int')); +$id = GETPOST('rowid', 'int'); +$accountid = (GETPOST('id', 'int') ? GETPOST('id', 'int') : GETPOST('account', 'int')); $ref = GETPOST('ref', 'alpha'); $action = GETPOST('action', 'aZ09'); $confirm = GETPOST('confirm', 'alpha'); @@ -67,8 +68,9 @@ $socid = 0; if ($user->socid) { $socid = $user->socid; } -$result = restrictedArea($user, 'banque', $fieldvalue, 'bank_account', '', '', $fieldtype); -if (empty($user->rights->banque->lire) && !$user->rights->banque->consolidate) { + +$result = restrictedArea($user, 'banque', $accountid, 'bank_account'); +if (empty($user->rights->banque->lire) && empty($user->rights->banque->consolidate)) { accessforbidden(); } @@ -78,6 +80,7 @@ $hookmanager->initHooks(array('bankline')); /* * Actions */ + $parameters = array('socid' => $socid); $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks if ($reshook < 0) { @@ -256,16 +259,20 @@ $form = new Form($db); llxHeader('', $langs->trans("BankTransaction")); +$arrayselected = array(); + $c = new Categorie($db); $cats = $c->containing($rowid, Categorie::TYPE_BANK_LINE); -foreach ($cats as $cat) { - $arrayselected[] = $cat->id; +if (is_array($cats)) { + foreach ($cats as $cat) { + $arrayselected[] = $cat->id; + } } $head = bankline_prepare_head($rowid); -$sql = "SELECT b.rowid,b.dateo as do,b.datev as dv, b.amount, b.label, b.rappro,"; +$sql = "SELECT b.rowid, b.dateo as do, b.datev as dv, b.amount, b.label, b.rappro,"; $sql .= " b.num_releve, b.fk_user_author, b.num_chq, b.fk_type, b.fk_account, b.fk_bordereau as receiptid,"; $sql .= " b.emetteur,b.banque"; $sql .= " FROM ".MAIN_DB_PREFIX."bank as b"; @@ -299,6 +306,7 @@ if ($result) { print ''; print ''; print ''; + print ''; print ''; print dol_get_fiche_head($head, 'bankline', $langs->trans('LineRecord'), 0, 'accountline', 0); @@ -490,9 +498,9 @@ if ($result) { print $form->selectDate($db->jdate($objp->do), 'dateo', '', '', '', 'update', 1, 0, $objp->rappro); if (!$objp->rappro) { print '   '; - print ''; + print ''; print img_edit_remove()." "; - print ''; + print ''; print img_edit_add().""; } print ''; @@ -510,9 +518,9 @@ if ($result) { print $form->selectDate($db->jdate($objp->dv), 'datev', '', '', '', 'update', 1, 0, $objp->rappro); if (!$objp->rappro) { print '   '; - print ''; + print ''; print img_edit_remove()." "; - print ''; + print ''; print img_edit_add().""; } print ''; @@ -569,11 +577,15 @@ if ($result) { // Bank line print ''.$form->editfieldkey('RubriquesTransactions', 'custcats', '', $object, 0).''; $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, null, 'parent', null, null, 1); + $arrayselected = array(); + $c = new Categorie($db); $cats = $c->containing($bankline->id, Categorie::TYPE_BANK_LINE); - foreach ($cats as $cat) { - $arrayselected[] = $cat->id; + if (is_array($cats)) { + foreach ($cats as $cat) { + $arrayselected[] = $cat->id; + } } print img_picto('', 'category', 'class="paddingright"').$form->multiselectarray('custcats', $cate_arbo, $arrayselected, null, null, null, null, "90%"); print ""; @@ -649,10 +661,10 @@ if ($result) { } print ''; - print "".$langs->trans("BankLineConciliated").""; + print ''; if ($user->rights->banque->consolidate) { print ''; - print 'rappro ? ' checked="checked"' : '')).'">'; + print 'rappro ? ' checked="checked"' : '')).'">'; print ''; } else { print ''.yn($objp->rappro).''; diff --git a/htdocs/compta/bank/list.php b/htdocs/compta/bank/list.php index ea656141639..6815a8d664b 100644 --- a/htdocs/compta/bank/list.php +++ b/htdocs/compta/bank/list.php @@ -79,8 +79,8 @@ if (!$allowed) { $diroutputmassaction = $conf->bank->dir_output.'/temp/massgeneration/'.$user->id; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php index ae676209571..3417f05c817 100644 --- a/htdocs/compta/bank/releve.php +++ b/htdocs/compta/bank/releve.php @@ -78,8 +78,8 @@ if ($user->rights->banque->consolidate && $action == 'dvprev' && !empty($dvid)) $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $pageplusone = GETPOST("pageplusone", 'int'); if ($pageplusone) { @@ -331,8 +331,8 @@ if (empty($numref)) { } else { print ''; print ''; - print ''; - print ''; + print ''; + print ''; } print ''; @@ -347,7 +347,7 @@ if (empty($numref)) { $balancestart[$objp->numr] = $obj->amount; $db->free($resql); } - print ''.price($balancestart[$objp->numr], '', $langs, 1, -1, -1, $conf->currency).''; + print ''.price($balancestart[$objp->numr], '', $langs, 1, -1, -1, empty($object->currency_code)?$conf->currency:$object->currency_code).''; // Calculate end amount $sql = "SELECT sum(b.amount) as amount"; @@ -360,11 +360,11 @@ if (empty($numref)) { $content[$objp->numr] = $obj->amount; $db->free($resql); } - print ''.price(($balancestart[$objp->numr] + $content[$objp->numr]), '', $langs, 1, -1, -1, $conf->currency).''; + print ''.price(($balancestart[$objp->numr] + $content[$objp->numr]), '', $langs, 1, -1, -1, empty($object->currency_code)?$conf->currency:$object->currency_code).''; print ''; if ($user->rights->banque->consolidate && $action != 'editbankreceipt') { - print 'numr).'">'.img_edit().''; + print 'numr).'">'.img_edit().''; } print ''; @@ -669,6 +669,7 @@ if (empty($numref)) { var current = $(this); current.click(function() { + console.log("We click on ajaxforbankoperationchange"); var url = "'.$urlajax.'&"+current.attr("href").split("?")[1]; $.get(url, function(data) { diff --git a/htdocs/compta/bank/various_payment/card.php b/htdocs/compta/bank/various_payment/card.php index 72188cdbb4a..0003570fd02 100644 --- a/htdocs/compta/bank/various_payment/card.php +++ b/htdocs/compta/bank/various_payment/card.php @@ -334,11 +334,7 @@ foreach ($bankcateg->fetchAll() as $bankcategory) { $options[$bankcategory->id] = $bankcategory->label; } -/* ************************************************************************** */ -/* */ -/* Create mode */ -/* */ -/* ************************************************************************** */ +// Create mode if ($action == 'create') { // Update fields properties in realtime if (!empty($conf->use_javascript_ajax)) { @@ -350,6 +346,7 @@ if ($action == 'create') { }); function setPaymentType() { + console.log("setPaymentType"); var code = $("#selectpaymenttype option:selected").val(); if (code == \'CHQ\' || code == \'VIR\') { @@ -415,7 +412,8 @@ if ($action == 'create') { if (!empty($conf->banque->enabled)) { print ''; print $form->editfieldkey('BankAccount', 'selectaccountid', '', $object, 0, 'string', '', 1).''; - print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes($accountid, "accountid", 0, '', 2, '', 0, '', 1); // Affiche liste des comptes courant + print img_picto('', 'bank_account', 'class="pictofixedwidth"'); + print $form->select_comptes($accountid, "accountid", 0, '', 2, '', 0, '', 1); // Show list of main accounts (comptes courants) print ''; } diff --git a/htdocs/compta/bank/various_payment/list.php b/htdocs/compta/bank/various_payment/list.php index fec2d025c7a..bbec4f23fc6 100644 --- a/htdocs/compta/bank/various_payment/list.php +++ b/htdocs/compta/bank/various_payment/list.php @@ -77,8 +77,8 @@ if (empty($search_datev_end)) { $search_datev_end = GETPOST("search_datev_end", 'int'); } -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/cashcontrol/cashcontrol_card.php b/htdocs/compta/cashcontrol/cashcontrol_card.php index 2f3004ae1d6..149710c975b 100644 --- a/htdocs/compta/cashcontrol/cashcontrol_card.php +++ b/htdocs/compta/cashcontrol/cashcontrol_card.php @@ -46,8 +46,8 @@ $smonth = (GETPOSTISSET('closemonth') ?GETPOST('closemonth', 'int') : dol_print_ $sday = (GETPOSTISSET('closeday') ?GETPOST('closeday', 'int') : dol_print_date($now, "%d")); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/charges/index.php b/htdocs/compta/charges/index.php index be7c88c0a1a..07c1176b9d2 100644 --- a/htdocs/compta/charges/index.php +++ b/htdocs/compta/charges/index.php @@ -62,8 +62,8 @@ if (!$year) { $search_account = GETPOST('search_account', 'int'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/clients.php b/htdocs/compta/clients.php index b39364690a6..bc1d3790280 100644 --- a/htdocs/compta/clients.php +++ b/htdocs/compta/clients.php @@ -45,8 +45,8 @@ $langs->load("companies"); $mode = GETPOST("mode"); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/deplacement/index.php b/htdocs/compta/deplacement/index.php index d588b7bff80..8af897378f5 100644 --- a/htdocs/compta/deplacement/index.php +++ b/htdocs/compta/deplacement/index.php @@ -38,8 +38,8 @@ if ($user->socid) { $result = restrictedArea($user, 'deplacement', '', ''); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/deplacement/list.php b/htdocs/compta/deplacement/list.php index e7593406ad6..9f92cecc4a7 100644 --- a/htdocs/compta/deplacement/list.php +++ b/htdocs/compta/deplacement/list.php @@ -45,8 +45,8 @@ $search_ref = GETPOST('search_ref', 'int'); $search_name = GETPOST('search_name', 'alpha'); $search_company = GETPOST('search_company', 'alpha'); // $search_amount=GETPOST('search_amount','alpha'); -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; if (empty($page) || $page == -1) { diff --git a/htdocs/compta/facture/card-rec.php b/htdocs/compta/facture/card-rec.php index 2e6ac4b6174..3909d9437b4 100644 --- a/htdocs/compta/facture/card-rec.php +++ b/htdocs/compta/facture/card-rec.php @@ -71,8 +71,8 @@ $year_date_when = GETPOST('year_date_when'); $month_date_when = GETPOST('month_date_when'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; @@ -1354,6 +1354,7 @@ if ($action == 'create') { $dateexample = $object->date_when; } + // Help of substitution key $substitutionarray = getCommonSubstitutionArray($langs, 2, null, $object); $substitutionarray['__INVOICE_PREVIOUS_MONTH__'] = $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%m').')'; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index c50f7a4e8e8..da438af9e01 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -130,6 +130,7 @@ $usercanread = $user->rights->facture->lire; $usercancreate = $user->rights->facture->creer; $usercanissuepayment = $user->rights->facture->paiement; $usercandelete = $user->rights->facture->supprimer; +$usercancreatecontract = $user->rights->contrat->creer; $usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->validate))); $usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->send))); $usercanreopen = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->facture->invoice_advance->reopen))); @@ -264,6 +265,8 @@ if (empty($reshook)) { $result = $object->deleteline(GETPOST('lineid', 'int')); if ($result > 0) { + // reorder lines + $object->line_order(true); // Define output language $outputlangs = $langs; $newlang = ''; @@ -607,7 +610,7 @@ if (empty($reshook)) { // Check parameters // Check for mandatory fields in thirdparty (defined into setup) - $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL'); + $array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL', 'ACCOUNTANCY_CODE_CUSTOMER'); foreach ($array_to_check as $key) { $keymin = strtolower($key); $i = (int) preg_replace('/[^0-9]/', '', $key); @@ -635,6 +638,14 @@ if (empty($reshook)) { setEventMessages($langs->trans("ErrorBadEMail", $object->thirdparty->email).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors'); } } + if ($key == 'ACCOUNTANCY_CODE_CUSTOMER') { + // Check for mandatory + if (!empty($conf->global->SOCIETE_ACCOUNTANCY_CODE_CUSTOMER_INVOICE_MANDATORY) && empty($object->thirdparty->code_compta)) { + $langs->load("errors"); + $error++; + setEventMessages($langs->trans("ErrorAccountancyCodeCustomerIsMandatory", $object->thirdparty->name).' ('.$langs->trans("ForbiddenBySetupRules").')', null, 'errors'); + } + } } } @@ -987,10 +998,13 @@ if (empty($reshook)) { $object->fetch($id); if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0) { $paiement = new Paiement($db); - $result = $paiement->fetch(GETPOST('paiement_id')); + $result = $paiement->fetch(GETPOST('paiement_id', 'int')); if ($result > 0) { $result = $paiement->delete(); // If fetch ok and found - header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + if ($result >= 0) { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$id); + exit; + } } if ($result < 0) { setEventMessages($paiement->error, $paiement->errors, 'errors'); @@ -1121,6 +1135,8 @@ if (empty($reshook)) { $facture_source->fetchPreviousNextSituationInvoice(); } } + + $id = $object->create($user); if ($id < 0) { $error++; @@ -1248,6 +1264,7 @@ if (empty($reshook)) { $line->multicurrency_total_tva = -$line->multicurrency_total_tva; $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc; + $line->context['createcreditnotefrominvoice'] = 1; $result = $line->insert(0, 1); // When creating credit note with same lines than source, we must ignore error if discount alreayd linked $object->lines[] = $line; // insert new line in current object @@ -2886,6 +2903,7 @@ if ($action == 'create') { } $currency_code = $conf->currency; + $fk_account = 0; // Load objectsrc $remise_absolue = 0; @@ -3411,6 +3429,10 @@ if ($action == 'create') { $optionsav .= '
'; print '
'; -$tmp = getCustomerInvoiceLatestEditTable($maxLatestEditCount, $socid); +$tmp = getCustomerInvoiceLatestEditTable($max, $socid); if ($tmp) { print $tmp; print '
'; } -$tmp = getCustomerInvoiceUnpaidOpenTable($max, $socid); +$tmp = getCustomerInvoiceUnpaidOpenTable($maxOpenCount, $socid); if ($tmp) { print $tmp; print '
'; diff --git a/htdocs/compta/facture/info.php b/htdocs/compta/facture/info.php index f8dd1418000..60efaf36e3d 100644 --- a/htdocs/compta/facture/info.php +++ b/htdocs/compta/facture/info.php @@ -39,6 +39,7 @@ $id = GETPOST("facid", "int"); $ref = GETPOST("ref", 'alpha'); $object = new Facture($db); + $extrafields = new ExtraFields($db); // Fetch optionals attributes and labels @@ -62,14 +63,6 @@ $result = restrictedArea($user, 'facture', $object->id, '', '', 'fk_soc', $field * View */ -if (empty($object->id)) { - llxHeader(); - $langs->load('errors'); - echo '
'.$langs->trans("ErrorRecordNotFound").'
'; - llxFooter(); - exit; -} - $form = new Form($db); $title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('Info'); @@ -77,6 +70,13 @@ $help_url = "EN:Customers_Invoices|FR:Factures_Clients|ES:Facturas_a_clientes"; llxHeader('', $title, $help_url); +if (empty($object->id)) { + $langs->load('errors'); + echo '
'.$langs->trans("ErrorRecordNotFound").'
'; + llxFooter(); + exit; +} + $object->fetch_thirdparty(); $object->info($object->id); diff --git a/htdocs/compta/facture/invoicetemplate_list.php b/htdocs/compta/facture/invoicetemplate_list.php index d785ccbce93..a07d95094dd 100644 --- a/htdocs/compta/facture/invoicetemplate_list.php +++ b/htdocs/compta/facture/invoicetemplate_list.php @@ -96,8 +96,8 @@ $search_unit_frequency = GETPOST('search_unit_frequency', 'alpha'); $search_status = GETPOST('search_status', 'int'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 7456a13146d..f526220c071 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -147,8 +147,8 @@ if ($option == 'late') { $filtre = GETPOST('filtre', 'alpha'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) { $page = 0; @@ -1621,6 +1621,18 @@ if ($resql) { $totalarray['val'] = array(); $totalarray['val']['f.total_ht'] = 0; $totalarray['val']['f.total_ttc'] = 0; + + $with_margin_info = false; + if (!empty($conf->margin->enabled) && ( + !empty($arrayfields['total_pa']['checked']) + || !empty($arrayfields['total_margin']['checked']) + || !empty($arrayfields['total_margin_rate']['checked']) + || !empty($arrayfields['total_mark_rate']['checked']) + ) + ) { + $with_margin_info = true; + } + while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); @@ -1706,7 +1718,7 @@ if ($resql) { $facturestatic->alreadypaid = $paiement; $marginInfo = array(); - if (!empty($conf->margin->enabled)) { + if ($with_margin_info === true) { $facturestatic->fetch_lines(); $marginInfo = $formmargin->getMarginInfosArray($facturestatic); } @@ -1736,7 +1748,7 @@ if ($resql) { print ''; if ($contextpage == 'poslist') { - print $obj->ref; + print dol_escape_htmltag($obj->ref); } else { print $facturestatic->getNomUrl(1, '', 200, 0, '', 0, 1); } @@ -1758,7 +1770,7 @@ if ($resql) { // Customer ref if (!empty($arrayfields['f.ref_client']['checked'])) { print ''; - print $obj->ref_client; + print dol_escape_htmltag($obj->ref_client); print ''; if (!$i) { $totalarray['nbfield']++; @@ -1823,7 +1835,7 @@ if ($resql) { if (!empty($arrayfields['p.title']['checked'])) { print ''; if ($obj->project_id > 0) { - print $projectstatic->title; + print dol_escape_htmltag($projectstatic->title); } print ''; if (!$i) { @@ -1835,9 +1847,9 @@ if ($resql) { if (!empty($arrayfields['s.nom']['checked'])) { print ''; if ($contextpage == 'poslist') { - print $companystatic->name; + print dol_escape_htmltag($companystatic->name); } else { - print $companystatic->getNomUrl(1, 'customer'); + print $companystatic->getNomUrl(1, 'customer', 0, 0, -1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1); } print ''; if (!$i) { @@ -1846,8 +1858,8 @@ if ($resql) { } // Alias if (!empty($arrayfields['s.name_alias']['checked'])) { - print ''; - print dol_escape_htmltag((!empty($obj->name_alias) ? $obj->name_alias : '')); + print ''; + print dol_escape_htmltag($companystatic->name_alias); print ''; if (!$i) { $totalarray['nbfield']++; @@ -1903,10 +1915,10 @@ if ($resql) { // Staff if (!empty($arrayfields['staff.code']['checked'])) { print ''; - if (!is_array($staffArray) || count($staffArray) == 0) { - $staffArray = $formcompany->effectif_array(1); + if (!is_array($conf->cache['staff']) || count($conf->cache['staff']) == 0) { + $conf->cache['staff'] = $formcompany->effectif_array(1); } - print $staffArray[$obj->staff_code]; + print $conf->cache['staff'][$obj->staff_code]; print ''; if (!$i) { $totalarray['nbfield']++; @@ -1955,7 +1967,7 @@ if ($resql) { // Amount HT if (!empty($arrayfields['f.total_ht']['checked'])) { - print ''.price($obj->total_ht)."\n"; + print ''.price($obj->total_ht)."\n"; if (!$i) { $totalarray['nbfield']++; } @@ -2085,11 +2097,11 @@ if ($resql) { } if (!empty($arrayfields['f.retained_warranty']['checked'])) { - print ''.(!empty($obj->retained_warranty) ?price($obj->retained_warranty).'%' : ' ').''; + print ''.(!empty($obj->retained_warranty) ? price($obj->retained_warranty).'%' : ' ').''; } if (!empty($arrayfields['dynamount_payed']['checked'])) { - print ''.(!empty($totalpay) ?price($totalpay, 0, $langs) : ' ').''; // TODO Use a denormalized field + print ''.(!empty($totalpay) ? price($totalpay, 0, $langs) : ' ').''; // TODO Use a denormalized field if (!$i) { $totalarray['nbfield']++; } @@ -2116,7 +2128,7 @@ if ($resql) { // Currency if (!empty($arrayfields['f.multicurrency_code']['checked'])) { - print ''.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."\n"; + print ''.dol_escape_htmltag($obj->multicurrency_code).' - '.$langs->trans('Currency'.$obj->multicurrency_code)."\n"; if (!$i) { $totalarray['nbfield']++; } @@ -2194,7 +2206,7 @@ if ($resql) { $totalarray['nbfield']++; } } - // total mark rate + // Total mark rate if (!empty($arrayfields['total_mark_rate']['checked'])) { print ''.(($marginInfo['total_mark_rate'] == '') ? '' : price($marginInfo['total_mark_rate'], null, null, null, null, 2).'%').''; if (!$i) { @@ -2210,7 +2222,7 @@ if ($resql) { print $hookmanager->resPrint; // Date creation if (!empty($arrayfields['f.datec']['checked'])) { - print ''; + print ''; print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser'); print ''; if (!$i) { @@ -2219,7 +2231,7 @@ if ($resql) { } // Date modification if (!empty($arrayfields['f.tms']['checked'])) { - print ''; + print ''; print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser'); print ''; if (!$i) { @@ -2228,7 +2240,7 @@ if ($resql) { } // Date closing if (!empty($arrayfields['f.date_closing']['checked'])) { - print ''; + print ''; print dol_print_date($db->jdate($obj->date_closing), 'dayhour', 'tzuser'); print ''; if (!$i) { diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index d815fad4ba6..cd34a027651 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -52,8 +52,10 @@ if ($user->socid) { $socid = $user->socid; } +$moreparam = ''; if ($type == 'bank-transfer') { $object = new FactureFournisseur($db); + $moreparam = '&type='.$type; } else { $object = new Facture($db); } @@ -221,7 +223,7 @@ $form = new Form($db); $now = dol_now(); if ($type == 'bank-transfer') { - $title = $langs->trans('InvoiceSupplier')." - ".$langs->trans('CreditTransfer'); + $title = $langs->trans('SupplierInvoice')." - ".$langs->trans('CreditTransfer'); $helpurl = ""; } else { $title = $langs->trans('InvoiceCustomer')." - ".$langs->trans('StandingOrders'); @@ -384,7 +386,7 @@ if ($object->id > 0) { $object->totalpaye = $totalpaye; // To give a chance to dol_banner_tab to use already paid amount to show correct status - dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, '', 0, '', ''); + dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref, $moreparam, 0, '', ''); print '
'; print '
'; diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 332f68c1293..c68a686d2bf 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -210,11 +210,11 @@ if (!empty($conf->facture->enabled) && !empty($user->rights->facture->lire)) { print ''; print $tmpinvoice->getNomUrl(1, ''); print ''; - print ''; if ($tmpinvoice->hasDelay()) { + print ''; print img_warning($langs->trans("Late")); + print ''; } - print ''; print ''; $filename = dol_sanitizeFileName($obj->ref); $filedir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($obj->ref); diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index b68374b84b9..635727233d3 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -48,7 +48,7 @@ $paymentnum = GETPOST('num_paiement', 'alpha'); $socid = GETPOST('socid', 'int'); $sortfield = GETPOST('sortfield', 'aZ09comma'); -$sortorder = GETPOST('sortorder', 'alpha'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); $amounts = array(); @@ -726,7 +726,31 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; // Remain to take or to pay back - print ''.price($sign * $remaintopay).''; + print ''; + print price($sign * $remaintopay); + if (!empty($conf->prelevement->enabled)) { + $numdirectdebitopen = 0; + $totaldirectdebit = 0; + $sql = "SELECT COUNT(pfd.rowid) as nb, SUM(pfd.amount) as amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; + $sql .= " WHERE fk_facture = ".((int) $objp->facid); + $sql .= " AND pfd.traite = 0"; + $sql .= " AND pfd.ext_payment_id IS NULL"; + + $result_sql = $db->query($sql); + if ($result_sql) { + $obj = $db->fetch_object($result_sql); + $numdirectdebitopen = $obj->nb; + $totaldirectdebit = $obj->amount; + } else { + dol_print_error($db); + } + if ($numdirectdebitopen) { + $langs->load("withdrawals"); + print img_warning($langs->trans("WarningSomeDirectDebitOrdersAlreadyExists", $numdirectdebitopen, price(price2num($totaldirectdebit, 'MT'), 0, $langs, 1, -1, -1, $conf->currency)), '', 'classfortooltip'); + } + } + print ''; //$test= price(price2num($objp->total_ttc - $paiement - $creditnotes - $deposits)); // Amount diff --git a/htdocs/compta/paiement/card.php b/htdocs/compta/paiement/card.php index ab6f0f5e574..93fdd415513 100644 --- a/htdocs/compta/paiement/card.php +++ b/htdocs/compta/paiement/card.php @@ -295,7 +295,7 @@ print ''; if (!empty($conf->banque->enabled)) { if ($object->fk_account > 0) { if ($object->type_code == 'CHQ' && $bankline->fk_bordereau > 0) { - dol_include_once('/compta/paiement/cheque/class/remisecheque.class.php'); + include_once DOL_DOCUMENT_ROOT.'/compta/paiement/cheque/class/remisecheque.class.php'; $bordereau = new RemiseCheque($db); $bordereau->fetch($bankline->fk_bordereau); diff --git a/htdocs/compta/paiement/cheque/list.php b/htdocs/compta/paiement/cheque/list.php index f4d6c9e2686..d12caf36bbe 100644 --- a/htdocs/compta/paiement/cheque/list.php +++ b/htdocs/compta/paiement/cheque/list.php @@ -45,8 +45,8 @@ $search_account = GETPOST('search_account', 'int'); $search_amount = GETPOST('search_amount', 'alpha'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index aab54e4ef81..2a8522ab05b 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -483,7 +483,7 @@ class Paiement extends CommonObject // Verifier si paiement porte pas sur une facture classee // Si c'est le cas, on refuse la suppression - $billsarray = $this->getBillsArray('fk_statut > 1'); + $billsarray = $this->getBillsArray('f.fk_statut > 1'); if (is_array($billsarray)) { if (count($billsarray)) { $this->error = "ErrorDeletePaymentLinkedToAClosedInvoiceNotPossible"; diff --git a/htdocs/compta/paiement/list.php b/htdocs/compta/paiement/list.php index 0d928cf188f..3732e76b880 100644 --- a/htdocs/compta/paiement/list.php +++ b/htdocs/compta/paiement/list.php @@ -71,8 +71,8 @@ $search_amount = GETPOST("search_amount", 'alpha'); // alpha because we must be $search_status = GETPOST('search_status', 'intcomma'); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { @@ -340,7 +340,6 @@ print ''; print ''; print ''; print ''; -print ''; print ''; print_barre_liste($langs->trans("ReceivedCustomersPayments"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'bill', 0, '', '', $limit, 0, 0, 1); diff --git a/htdocs/compta/paymentbybanktransfer/index.php b/htdocs/compta/paymentbybanktransfer/index.php index b939c59a053..63cd091652a 100644 --- a/htdocs/compta/paymentbybanktransfer/index.php +++ b/htdocs/compta/paymentbybanktransfer/index.php @@ -43,6 +43,8 @@ if ($user->socid) { } $result = restrictedArea($user, 'paymentbybanktransfer', '', ''); +$usercancreate = $user->rights->paymentbybanktransfer->create; + /* * Actions @@ -62,7 +64,12 @@ if (prelevement_check_config('bank-transfer') < 0) { setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByBankTransfer")), null, 'errors'); } -print load_fiche_titre($langs->trans("SuppliersStandingOrdersArea")); +$newcardbutton = ''; +if ($usercancreate) { + $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type=bank-transfer'); +} + +print load_fiche_titre($langs->trans("SuppliersStandingOrdersArea"), $newcardbutton); print '
'; diff --git a/htdocs/compta/prelevement/card.php b/htdocs/compta/prelevement/card.php index 2dce916af2f..3812d72f405 100644 --- a/htdocs/compta/prelevement/card.php +++ b/htdocs/compta/prelevement/card.php @@ -99,22 +99,7 @@ if (empty($reshook)) { } } - // Seems to not be used and replaced with $action == 'infocredit' - if ($action == 'confirm_credite' && GETPOST('confirm', 'alpha') == 'yes') { - if ($object->statut == 2) { - $res = -1; - setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors'); - } else { - $res = $object->set_credite(); - } - - if ($res >= 0) { - header("Location: card.php?id=".$id); - exit; - } - } - - if ($action == 'infotrans' && $user->rights->prelevement->bons->send) { + if ($action == 'infotrans' && (($user->rights->prelevement->bons->send && $object->type != 'bank-transfer') || ($user->rights->paymentbybanktransfer->send && $object->type == 'bank-transfer'))) { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); @@ -147,10 +132,10 @@ if (empty($reshook)) { } // Set direct debit order to credited, create payment and close invoices - if ($action == 'infocredit' && $user->rights->prelevement->bons->credit) { + if ($action == 'infocredit' && (($user->rights->prelevement->bons->credit && $object->type != 'bank-transfer') || ($user->rights->paymentbybanktransfer->debit && $object->type == 'bank-transfer'))) { $dt = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int')); - if ($object->statut == 2) { + if (($object->type != 'bank-transfer' && $object->statut == BonPrelevement::STATUS_CREDITED) || ($object->type == 'bank-transfer' && $object->statut == BonPrelevement::STATUS_DEBITED)) { $error = 1; setEventMessages('WithdrawalCantBeCreditedTwice', array(), 'errors'); } else { @@ -181,12 +166,6 @@ if ($id > 0 || $ref) { print '
'.$object->getErrorString(GETPOST('error', 'alpha')).'
'; } - /*if ($action == 'credite') - { - print $form->formconfirm("card.php?id=".$object->id,$langs->trans("ClassCredited"),$langs->trans("ClassCreditedConfirm"),"confirm_credite",'',1,1); - - }*/ - $linkback = ''.$langs->trans("BackToList").''; dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref'); @@ -303,6 +282,7 @@ if ($id > 0 || $ref) { } if (!empty($object->date_trans) && $object->date_credit == 0 && $user->rights->prelevement->bons->credit && $action == 'setcredited') { + $btnLabel = ($object->type == 'bank-transfer') ? $langs->trans("ClassDebited") : $langs->trans("ClassCredited"); print '
'; print ''; print ''; @@ -314,25 +294,27 @@ if ($id > 0 || $ref) { print ''; print ''; print '
'.$langs->trans("ThisWillAlsoAddPaymentOnInvoice").'
'; - print '
'; + print '
'; print '
'; print '
'; } - // Actions if ($action != 'settransmitted' && $action != 'setcredited') { print "\n".'
'."\n"; - if (empty($object->date_trans) && $user->rights->prelevement->bons->send) { - print ''.$langs->trans("SetToStatusSent").''; + if (empty($object->date_trans)) { + if ($object->type == 'bank-transfer') print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->rights->paymentbybanktransfer->send); + else print dolGetButtonAction($langs->trans("SetToStatusSent"), '', 'default', 'card.php?action=settransmitted&token='.newToken().'&id='.$object->id, '', $user->rights->prelevement->bons->send); } if (!empty($object->date_trans) && $object->date_credit == 0) { - print ''.$langs->trans("ClassCredited").''; + if ($object->type == 'bank-transfer') print dolGetButtonAction($langs->trans("ClassDebited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->rights->paymentbybanktransfer->debit); + else print dolGetButtonAction($langs->trans("ClassCredited"), '', 'default', 'card.php?action=setcredited&token='.newToken().'&id='.$object->id, '', $user->rights->prelevement->bons->credit); } - print ''.$langs->trans("Delete").''; + if ($object->type == 'bank-transfer') print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->rights->paymentbybanktransfer->create); + else print dolGetButtonAction($langs->trans("Delete"), '', 'delete', 'card.php?action=delete&token='.newToken().'&id='.$object->id, '', $user->rights->prelevement->bons->creer); print '
'; } @@ -457,6 +439,8 @@ if ($id > 0 || $ref) { } if ($num > 0) { + $total = price2num($total, 'MT'); + print ''; print ''.$langs->trans("Total").''; print ' '; diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 68b924e2e4d..e5697ab3cb3 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -332,74 +332,6 @@ class BonPrelevement extends CommonObject } } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps - /** - * Set credite and set status of linked invoices. Still used ?? - * - * @return int <0 if KO, >=0 if OK - */ - public function set_credite() - { - // phpcs:enable - global $user, $conf; - - $error = 0; - - if ($this->db->begin()) { - $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_bons"; - $sql .= " SET statut = ".self::STATUS_TRANSFERED; - $sql .= " WHERE rowid = ".((int) $this->id); - $sql .= " AND entity = ".((int) $conf->entity); - - $result = $this->db->query($sql); - if (!$result) { - dol_syslog(get_class($this)."::set_credite Erreur 1"); - $error++; - } - - if (!$error) { - $facs = array(); - $facs = $this->getListInvoices(); - - $num = count($facs); - for ($i = 0; $i < $num; $i++) { - /* Tag invoice as paid */ - dol_syslog(get_class($this)."::set_credite set_paid fac ".$facs[$i]); - $fac = new Facture($this->db); - $fac->fetch($facs[$i]); - $result = $fac->setPaid($user); - } - } - - if (!$error) { - $sql = " UPDATE ".MAIN_DB_PREFIX."prelevement_lignes"; - $sql .= " SET statut = 2"; - $sql .= " WHERE fk_prelevement_bons = ".((int) $this->id); - - if (!$this->db->query($sql)) { - dol_syslog(get_class($this)."::set_credite Erreur 1"); - $error++; - } - } - - /* - * End of procedure - */ - if (!$error) { - $this->db->commit(); - return 0; - } else { - $this->db->rollback(); - dol_syslog(get_class($this)."::set_credite ROLLBACK "); - - return -1; - } - } else { - dol_syslog(get_class($this)."::set_credite Ouverture transaction SQL impossible "); - return -2; - } - } - // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps /** * Set direct debit or credit transfer order to "paid" status. @@ -1551,7 +1483,7 @@ class BonPrelevement extends CommonObject fputs($this->file, ' '.$i.''.$CrLf); fputs($this->file, ' '.$this->total.''.$CrLf); fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.dolEscapeXML(strtoupper($this->raison_sociale)).''.$CrLf); + fputs($this->file, ' '.dolEscapeXML(strtoupper(dol_string_unaccent($this->raison_sociale))).''.$CrLf); fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$CrLf); @@ -1667,7 +1599,7 @@ class BonPrelevement extends CommonObject fputs($this->file, ' '.$i.''.$CrLf); fputs($this->file, ' '.$this->total.''.$CrLf); fputs($this->file, ' '.$CrLf); - fputs($this->file, ' '.dolEscapeXML(strtoupper($this->raison_sociale)).''.$CrLf); + fputs($this->file, ' '.dolEscapeXML(strtoupper(dol_string_unaccent($this->raison_sociale))).''.$CrLf); fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$CrLf); fputs($this->file, ' '.$CrLf); @@ -1917,16 +1849,16 @@ class BonPrelevement extends CommonObject $XML_DEBITOR .= ' '.$CrLf; $XML_DEBITOR .= ' '.$CrLf; $XML_DEBITOR .= ' '.$CrLf; - $XML_DEBITOR .= ' '.dolEscapeXML(strtoupper($row_nom)).''.$CrLf; + $XML_DEBITOR .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).''.$CrLf; $XML_DEBITOR .= ' '.$CrLf; $XML_DEBITOR .= ' '.$row_country_code.''.$CrLf; $addressline1 = strtr($row_address, array(CHR(13) => ", ", CHR(10) => "")); $addressline2 = strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => "")); if (trim($addressline1)) { - $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_unaccent($addressline1), 70, 'right', 'UTF-8', 1)).''.$CrLf; } if (trim($addressline2)) { - $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_DEBITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_unaccent($addressline2), 70, 'right', 'UTF-8', 1)).''.$CrLf; } $XML_DEBITOR .= ' '.$CrLf; $XML_DEBITOR .= ' '.$CrLf; @@ -1968,16 +1900,16 @@ class BonPrelevement extends CommonObject $XML_CREDITOR .= ' '.$CrLf; $XML_CREDITOR .= ' '.$CrLf; $XML_CREDITOR .= ' '.$CrLf; - $XML_CREDITOR .= ' '.dolEscapeXML(strtoupper($row_nom)).''.$CrLf; + $XML_CREDITOR .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($row_nom))).''.$CrLf; $XML_CREDITOR .= ' '.$CrLf; $XML_CREDITOR .= ' '.$row_country_code.''.$CrLf; $addressline1 = strtr($row_address, array(CHR(13) => ", ", CHR(10) => "")); $addressline2 = strtr($row_zip.(($row_zip && $row_town) ? ' ' : ''.$row_town), array(CHR(13) => ", ", CHR(10) => "")); if (trim($addressline1)) { - $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc($addressline1, 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_unaccent($addressline1), 70, 'right', 'UTF-8', 1)).''.$CrLf; } if (trim($addressline2)) { - $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc($addressline2, 70, 'right', 'UTF-8', 1)).''.$CrLf; + $XML_CREDITOR .= ' '.dolEscapeXML(dol_trunc(dol_string_unaccent($addressline2), 70, 'right', 'UTF-8', 1)).''.$CrLf; } $XML_CREDITOR .= ' '.$CrLf; $XML_CREDITOR .= ' '.$CrLf; @@ -2140,16 +2072,16 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$dateTime_ETAD.''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper($this->raison_sociale)).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($this->raison_sociale))).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => "")); $addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP.(($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' '.$configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '').$configuration->global->MAIN_INFO_SOCIETE_TOWN, array(CHR(13) => ", ", CHR(10) => "")); if ($addressline1) { - $XML_SEPA_INFO .= ' '.dolEscapeXML($addressline1).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_unaccent($addressline1), 70, 'right', 'UTF-8', 1)).''.$CrLf; } if ($addressline2) { - $XML_SEPA_INFO .= ' '.dolEscapeXML($addressline2).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_unaccent($addressline2), 70, 'right', 'UTF-8', 1)).''.$CrLf; } $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; @@ -2164,11 +2096,11 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; /* $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$this->raison_sociale.''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($this->raison_sociale))).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ADDRESS.''.$CrLf; - $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN.''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS.'').$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf;*/ $XML_SEPA_INFO .= ' SLEV'.$CrLf; // Field "Responsible of fees". Must be SLEV @@ -2206,16 +2138,16 @@ class BonPrelevement extends CommonObject */ $XML_SEPA_INFO .= ' '.dol_print_date($dateTime_ETAD, 'dayrfc').''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper($this->raison_sociale)).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($this->raison_sociale))).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; $addressline1 = strtr($configuration->global->MAIN_INFO_SOCIETE_ADDRESS, array(CHR(13) => ", ", CHR(10) => "")); $addressline2 = strtr($configuration->global->MAIN_INFO_SOCIETE_ZIP.(($configuration->global->MAIN_INFO_SOCIETE_ZIP || ' '.$configuration->global->MAIN_INFO_SOCIETE_TOWN) ? ' ' : '').$configuration->global->MAIN_INFO_SOCIETE_TOWN, array(CHR(13) => ", ", CHR(10) => "")); if ($addressline1) { - $XML_SEPA_INFO .= ' '.dolEscapeXML($addressline1).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_unaccent($addressline1), 70, 'right', 'UTF-8', 1)).''.$CrLf; } if ($addressline2) { - $XML_SEPA_INFO .= ' '.dolEscapeXML($addressline2).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_trunc(dol_string_unaccent($addressline2), 70, 'right', 'UTF-8', 1)).''.$CrLf; } $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; @@ -2230,11 +2162,11 @@ class BonPrelevement extends CommonObject $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; /* $XML_SEPA_INFO .= ' '.$CrLf; - $XML_SEPA_INFO .= ' '.$this->raison_sociale.''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(strtoupper(dol_string_unaccent($this->raison_sociale))).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$country[1].''.$CrLf; - $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ADDRESS.''.$CrLf; - $XML_SEPA_INFO .= ' '.$conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN.''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ADDRESS).''.$CrLf; + $XML_SEPA_INFO .= ' '.dolEscapeXML(dol_string_unaccent($conf->global->MAIN_INFO_SOCIETE_ZIP.' '.$conf->global->MAIN_INFO_SOCIETE_TOWN).''.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf; $XML_SEPA_INFO .= ' '.$CrLf;*/ $XML_SEPA_INFO .= ' SLEV'.$CrLf; // Field "Responsible of fees". Must be SLEV @@ -2368,4 +2300,78 @@ class BonPrelevement extends CommonObject return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode); } + + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + /** + * Load indicators for dashboard (this->nbtodo and this->nbtodolate) + * + * @param User $user Objet user + * @param string $mode Mode 'direct_debit' or 'credit_transfer' + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK + */ + public function load_board($user, $mode) + { + // phpcs:enable + global $conf, $langs; + + if ($user->socid) { + return -1; // protection pour eviter appel par utilisateur externe + } + + /* + if ($mode == 'direct_debit') { + $sql = "SELECT b.rowid, f.datedue as datefin"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.entity IN (".getEntity('facture').")"; + $sql .= " AND f.total_ttc > 0"; + } else { + $sql = "SELECT b.rowid, f.datedue as datefin"; + $sql .= " FROM ".MAIN_DB_PREFIX."facture_fourn as f"; + $sql .= " WHERE f.entity IN (".getEntity('facture_fourn').")"; + $sql .= " AND f.total_ttc > 0"; + } + + $resql = $this->db->query($sql); + if ($resql) { + $langs->load("banks"); + $now = dol_now(); + + $response = new WorkboardResponse(); + if ($mode == 'direct_debit') { + $response->warning_delay = $conf->prelevement->warning_delay / 60 / 60 / 24; + $response->label = $langs->trans("PendingDirectDebitToComplete"); + $response->labelShort = $langs->trans("PendingDirectDebitToCompleteShort"); + $response->url = DOL_URL_ROOT.'/compta/prelevement/index.php?leftmenu=checks&mainmenu=bank'; + } else { + $response->warning_delay = $conf->paymentbybanktransfer->warning_delay / 60 / 60 / 24; + $response->label = $langs->trans("PendingCreditTransferToComplete"); + $response->labelShort = $langs->trans("PendingCreditTransferToCompleteShort"); + $response->url = DOL_URL_ROOT.'/compta/paymentbybanktransfer/index.php?leftmenu=checks&mainmenu=bank'; + } + $response->img = img_object('', "payment"); + + while ($obj = $this->db->fetch_object($resql)) { + $response->nbtodo++; + + if ($this->db->jdate($obj->datefin) < ($now - $conf->withdraw->warning_delay)) { + $response->nbtodolate++; + } + } + + $response->nbtodo = 0; + $response->nbtodolate = 0; + // Return workboard only if quantity is not 0 + if ($response->nbtodo) { + return $response; + } else { + return 0; + } + } else { + dol_print_error($this->db); + $this->error = $this->db->error(); + return -1; + } + */ + return 0; + } } diff --git a/htdocs/compta/prelevement/demandes.php b/htdocs/compta/prelevement/demandes.php index 5ac0c07ede7..86f1bcf583c 100644 --- a/htdocs/compta/prelevement/demandes.php +++ b/htdocs/compta/prelevement/demandes.php @@ -49,8 +49,8 @@ $search_societe = GETPOST('search_societe', 'alpha'); // Load variable for pagination $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) { $page = 0; diff --git a/htdocs/compta/prelevement/index.php b/htdocs/compta/prelevement/index.php index 92ae9b827e0..4aef7e8b9e4 100644 --- a/htdocs/compta/prelevement/index.php +++ b/htdocs/compta/prelevement/index.php @@ -43,6 +43,8 @@ if ($user->socid) { } $result = restrictedArea($user, 'prelevement', '', 'bons'); +$usercancreate = $user->rights->prelevement->bons->creer; + /* * Actions @@ -62,7 +64,12 @@ if (prelevement_check_config() < 0) { setEventMessages($langs->trans("ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv("PaymentByDirectDebit")), null, 'errors'); } -print load_fiche_titre($langs->trans("CustomersStandingOrdersArea")); +$newcardbutton = ''; +if ($usercancreate) { + $newcardbutton .= dolGetButtonTitle($langs->trans('NewStandingOrder'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/prelevement/create.php?type='); +} + +print load_fiche_titre($langs->trans("CustomersStandingOrdersArea"), $newcardbutton); print '
'; diff --git a/htdocs/compta/prelevement/orders_list.php b/htdocs/compta/prelevement/orders_list.php index be7c72907fd..c80acb39f8e 100644 --- a/htdocs/compta/prelevement/orders_list.php +++ b/htdocs/compta/prelevement/orders_list.php @@ -212,7 +212,7 @@ if ($result) { print ''.price($obj->amount)."\n"; print ''; - print $bon->LibStatut($obj->statut, 3); + print $bon->LibStatut($obj->statut, 5); print ''; print ''."\n"; diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index b5aca49aaae..342360bd454 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -49,11 +49,11 @@ $date_startyear = GETPOST('date_startyear', 'int'); $date_endmonth = GETPOST('date_endmonth', 'int'); $date_endday = GETPOST('date_endday', 'int'); $date_endyear = GETPOST('date_endyear', 'int'); -$showaccountdetail = GETPOST('showaccountdetail', 'aZ09') ?GETPOST('showaccountdetail', 'aZ09') : 'no'; +$showaccountdetail = GETPOST('showaccountdetail', 'aZ09') ? GETPOST('showaccountdetail', 'aZ09') : 'yes'; $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; @@ -210,9 +210,9 @@ if ($modecompta == "CREANCES-DETTES") { $calcmode .= '
('.$langs->trans("SeeReportInDueDebtMode", '{s1}', '{s2}').')'; $calcmode = str_replace(array('{s1}', '{s2}'), array('', ''), $calcmode); $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); - $arraylist = array('no'=>$langs->trans("No"), 'yes'=>$langs->trans("AccountWithNonZeroValues"), 'all'=>$langs->trans("All")); + $arraylist = array('no'=>$langs->trans("CustomerCode"), 'yes'=>$langs->trans("AccountWithNonZeroValues"), 'all'=>$langs->trans("All")); $period .= '     '.$langs->trans("DetailByAccount").' '.$form->selectarray('showaccountdetail', $arraylist, $showaccountdetail, 0); - $periodlink = ($year_start ? "".img_previous()." ".img_next()."" : ""); + $periodlink = ($year_start ? "".img_previous()." ".img_next()."" : ""); $description = $langs->trans("RulesResultBookkeepingPredefined"); $description .= ' ('.$langs->trans("SeePageForSetup", DOL_URL_ROOT.'/accountancy/admin/account.php?mainmenu=accountancy&leftmenu=accountancy_admin', $langs->transnoentitiesnoconv("Accountancy").' / '.$langs->transnoentitiesnoconv("Setup").' / '.$langs->transnoentitiesnoconv("Chartofaccounts")).')'; $builddate = dol_now(); @@ -221,7 +221,7 @@ if ($modecompta == "CREANCES-DETTES") { $hselected = 'report'; -report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array('modecompta'=>$modecompta), $calcmode); +report_header($name, '', $period, $periodlink, $description, $builddate, $exportlink, array('modecompta'=>$modecompta, 'showaccountdetail'=>$showaccountdetail), $calcmode); if (!empty($conf->accounting->enabled) && $modecompta != 'BOOKKEEPING') { print info_admin($langs->trans("WarningReportNotReliable"), 0, 0, 1); @@ -280,7 +280,10 @@ if ($modecompta == 'BOOKKEEPING') { $charofaccountstring = $conf->global->CHARTOFACCOUNTS; $charofaccountstring = dol_getIdFromCode($db, $conf->global->CHARTOFACCOUNTS, 'accounting_system', 'rowid', 'pcg_version'); - $sql = "SELECT f.thirdparty_code as name, -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount"; + $sql = "SELECT -1 as socid, aa.pcg_type, SUM(f.credit - f.debit) as amount"; + if ($showaccountdetail == 'no') { + $sql .= ", f.thirdparty_code as name"; + } $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as f"; $sql .= ", ".MAIN_DB_PREFIX."accounting_account as aa"; $sql .= " WHERE f.numero_compte = aa.account_number"; @@ -290,11 +293,13 @@ if ($modecompta == 'BOOKKEEPING') { if (!empty($date_start) && !empty($date_end)) { $sql .= " AND f.doc_date >= '".$db->idate($date_start)."' AND f.doc_date <= '".$db->idate($date_end)."'"; } - $sql .= " GROUP BY pcg_type DESC, name, socid"; + $sql .= " GROUP BY pcg_type DESC"; + if ($showaccountdetail == 'no') { + $sql .= ", name, socid"; // group by "accounting group" (INCOME/EXPENSE), then "customer". + } $sql .= $db->order($sortfield, $sortorder); $oldpcgtype = ''; - $oldpcgsubtype = ''; dol_syslog("get bookkeeping entries", LOG_DEBUG); $result = $db->query($sql); @@ -305,16 +310,30 @@ if ($modecompta == 'BOOKKEEPING') { while ($i < $num) { $objp = $db->fetch_object($result); - if ($objp->pcg_type != $oldpcgtype) { - print ''.$objp->pcg_type.''; - $oldpcgtype = $objp->pcg_type; + if ($showaccountdetail == 'no') { + if ($objp->pcg_type != $oldpcgtype) { + print ''.$objp->pcg_type.''; + $oldpcgtype = $objp->pcg_type; + } } - print ''; - print ' '; - print ''.$objp->pcg_type.($objp->name ? ' ('.$objp->name.')' : '')."\n"; - print ''.price($objp->amount)."\n"; - print "\n"; + if ($showaccountdetail == 'no') { + print ''; + print ''; + print ''; + print $objp->pcg_type; + print ($objp->name ? ' ('.$objp->name.')' : ' ('.$langs->trans("Unknown").')'); + print "\n"; + print ''.price($objp->amount)."\n"; + print "\n"; + } else { + print ''; + print ''; + print $objp->pcg_type; + print "\n"; + print ''.price($objp->amount)."\n"; + print "\n"; + } $total_ht += (isset($objp->amount) ? $objp->amount : 0); $total_ttc += (isset($objp->amount) ? $objp->amount : 0); @@ -333,7 +352,7 @@ if ($modecompta == 'BOOKKEEPING') { if ($showaccountdetail != 'no') { $tmppredefinedgroupwhere = "pcg_type = '".$db->escape($objp->pcg_type)."'"; $tmppredefinedgroupwhere .= " AND fk_pcg_version = '".$db->escape($charofaccountstring)."'"; - //$tmppredefinedgroupwhere.= " AND thirdparty_code = '".$db->escape($objp->name)."'"; + //$tmppredefinedgroupwhere .= " AND thirdparty_code = '".$db->escape($objp->name)."'"; // Get cpts of category/group $cpts = $AccCat->getCptsCat(0, $tmppredefinedgroupwhere); @@ -361,7 +380,7 @@ if ($modecompta == 'BOOKKEEPING') { $i++; } } else { - print ''.$langs->trans("NoRecordFound").''; + print ''.$langs->trans("NoRecordFound").''; } } else { dol_print_error($db); @@ -418,12 +437,15 @@ if ($modecompta == 'BOOKKEEPING') { while ($i < $num) { $objp = $db->fetch_object($result); - print ' '; + print ''; + print ' '; print "".$langs->trans("Bills").' '.$objp->name."\n"; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price($objp->amount_ht)."\n"; + print ''.price($objp->amount_ht).""; } + print "\n"; print ''.price($objp->amount_ttc)."\n"; $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0); @@ -463,12 +485,15 @@ if ($modecompta == 'BOOKKEEPING') { $objp = $db->fetch_object($result); - print ' '; + print ''; + print ' '; print "".$langs->trans("Bills")." ".$langs->trans("Other")." (".$langs->trans("PaymentsNotLinkedToInvoice").")\n"; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price($objp->amount_ht)."\n"; + print ''.price($objp->amount_ht)."\n"; } + print ''; print ''.price($objp->amount_ttc)."\n"; $total_ht += (isset($objp->amount_ht) ? $objp->amount_ht : 0); @@ -485,7 +510,8 @@ if ($modecompta == 'BOOKKEEPING') { } if ($total_ttc == 0) { - print ' '; + print ''; + print ' '; print ''.$langs->trans("None").''; print ''; } @@ -494,10 +520,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ttc_income += $total_ttc; print ''; + print ''; + print ''; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price($total_ht).''; + print price($total_ht); } - print ''.price($total_ttc).''; + print ''; + print ''.price($total_ttc).''; print ''; /* @@ -554,13 +584,16 @@ if ($modecompta == 'BOOKKEEPING') { $subtotal_ht += $obj->amount; $subtotal_ttc += $obj->amount; - print ' '; + print ''; + print ' '; print "".$langs->trans("Donation")." name."&search_name=".$obj->firstname." ".$obj->lastname."\">".$obj->name." ".$obj->firstname." ".$obj->lastname."\n"; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price($obj->amount).''; + print ''.price($obj->amount).''; } + print ''; print ''.price($obj->amount).''; print ''; $i++; @@ -578,10 +611,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ttc_income += $subtotal_ttc; print ''; + print ''; + print ''; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price($subtotal_ht).''; + print price($subtotal_ht); } - print ''.price($subtotal_ttc).''; + print ''; + print ''.price($subtotal_ttc).''; print ''; } @@ -636,12 +673,15 @@ if ($modecompta == 'BOOKKEEPING') { while ($i < $num) { $objp = $db->fetch_object($result); - print ' '; - print "".$langs->trans("Bills")." socid."\">".$objp->name."\n"; + print ''; + print ' '; + print "".$langs->trans("Bills").' '.$objp->name.''."\n"; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$objp->amount_ht)."\n"; + print ''.price(-$objp->amount_ht).""; } + print "\n"; print ''.price(-$objp->amount_ttc)."\n"; $total_ht -= (isset($objp->amount_ht) ? $objp->amount_ht : 0); @@ -653,7 +693,8 @@ if ($modecompta == 'BOOKKEEPING') { $i++; } } else { - print ' '; + print ''; + print ' '; print ''.$langs->trans("None").''; print ''; } @@ -667,10 +708,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ttc_outcome += $subtotal_ttc; print ''; + print ''; + print ''; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$subtotal_ht).''; + print price(-$subtotal_ht); } - print ''.price(-$subtotal_ttc).''; + print ''; + print ''.price(-$subtotal_ttc).''; print ''; @@ -681,7 +726,7 @@ if ($modecompta == 'BOOKKEEPING') { print ''.$langs->trans("SocialContributionsNondeductibles").''; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.id, c.libelle as label, sum(cs.amount) as amount"; + $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql .= " WHERE cs.fk_type = c.id"; @@ -690,7 +735,7 @@ if ($modecompta == 'BOOKKEEPING') { $sql .= " AND cs.date_ech >= '".$db->idate($date_start)."' AND cs.date_ech <= '".$db->idate($date_end)."'"; } } elseif ($modecompta == 'RECETTES-DEPENSES') { - $sql = "SELECT c.id, c.libelle as label, sum(p.amount) as amount"; + $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p"; @@ -702,7 +747,7 @@ if ($modecompta == 'BOOKKEEPING') { } } $sql .= " AND cs.entity = ".$conf->entity; - $sql .= " GROUP BY c.libelle, c.id"; + $sql .= " GROUP BY c.libelle, c.id, c.accountancy_code"; $newsortfield = $sortfield; if ($newsortfield == 's.nom, s.rowid') { $newsortfield = 'c.libelle, c.id'; @@ -732,17 +777,29 @@ if ($modecompta == 'BOOKKEEPING') { $subtotal_ht += $obj->amount; $subtotal_ttc += $obj->amount; - print ' '; - print ''.$obj->label.''; - if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$obj->amount).''; + $titletoshow = ''; + if ($obj->accountancy_code) { + $titletoshow = $langs->trans("AccountingCode").': '.$obj->accountancy_code; + $tmpaccountingaccount = new AccountingAccount($db); + $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1); + $titletoshow .= ' - '.$langs->trans("AccountingCategory").': '.$tmpaccountingaccount->pcg_type; } + + print ''; + print ' '; + print 'accountancy_code ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.dol_escape_htmltag($obj->label).''; + print ''; + if ($modecompta == 'CREANCES-DETTES') { + print ''.price(-$obj->amount).''; + } + print ''; print ''.price(-$obj->amount).''; print ''; $i++; } } else { - print ' '; + print ''; + print ' '; print ''.$langs->trans("None").''; print ''; } @@ -754,10 +811,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ttc_outcome += $subtotal_ttc; print ''; + print ''; + print ''; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$subtotal_ht).''; + print price(-$subtotal_ht); } - print ''.price(-$subtotal_ttc).''; + print ''; + print ''.price(-$subtotal_ttc).''; print ''; @@ -768,7 +829,7 @@ if ($modecompta == 'BOOKKEEPING') { print ''.$langs->trans("SocialContributionsDeductibles").''; if ($modecompta == 'CREANCES-DETTES') { - $sql = "SELECT c.id, c.libelle as label, sum(cs.amount) as amount"; + $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(cs.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql .= " WHERE cs.fk_type = c.id"; @@ -778,7 +839,7 @@ if ($modecompta == 'BOOKKEEPING') { } $sql .= " AND cs.entity = ".$conf->entity; } elseif ($modecompta == 'RECETTES-DEPENSES') { - $sql = "SELECT c.id, c.libelle as label, sum(p.amount) as amount"; + $sql = "SELECT c.id, c.libelle as label, c.accountancy_code, sum(p.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c"; $sql .= ", ".MAIN_DB_PREFIX."chargesociales as cs"; $sql .= ", ".MAIN_DB_PREFIX."paiementcharge as p"; @@ -790,7 +851,7 @@ if ($modecompta == 'BOOKKEEPING') { } $sql .= " AND cs.entity = ".$conf->entity; } - $sql .= " GROUP BY c.libelle, c.id"; + $sql .= " GROUP BY c.libelle, c.id, c.accountancy_code"; $newsortfield = $sortfield; if ($newsortfield == 's.nom, s.rowid') { $newsortfield = 'c.libelle, c.id'; @@ -819,17 +880,29 @@ if ($modecompta == 'BOOKKEEPING') { $subtotal_ht += $obj->amount; $subtotal_ttc += $obj->amount; - print ' '; - print ''.$obj->label.''; - if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$obj->amount).''; + $titletoshow = ''; + if ($obj->accountancy_code) { + $titletoshow = $langs->trans("AccountingCode").': '.$obj->accountancy_code; + $tmpaccountingaccount = new AccountingAccount($db); + $tmpaccountingaccount->fetch(0, $obj->accountancy_code, 1); + $titletoshow .= ' - '.$langs->trans("AccountingCategory").': '.$tmpaccountingaccount->pcg_type; } + + print ''; + print ' '; + print 'accountancy_code ? ' title="'.dol_escape_htmltag($titletoshow).'"' : '').'>'.dol_escape_htmltag($obj->label).''; + print ''; + if ($modecompta == 'CREANCES-DETTES') { + print ''.price(-$obj->amount).''; + } + print ''; print ''.price(-$obj->amount).''; print ''; $i++; } } else { - print ' '; + print ''; + print ' '; print ''.$langs->trans("None").''; print ''; } @@ -841,10 +914,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ttc_outcome += $subtotal_ttc; print ''; + print ''; + print ''; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$subtotal_ht).''; + print price(-$subtotal_ht); } - print ''.price(-$subtotal_ttc).''; + print ''; + print ''.price(-$subtotal_ttc).''; print ''; @@ -857,7 +934,8 @@ if ($modecompta == 'BOOKKEEPING') { if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'RECETTES-DEPENSES') { if ($modecompta == 'CREANCES-DETTES') { - $column = 'p.datev'; + //$column = 's.dateep'; // We use the date of salary + $column = 'p.datep'; } else { $column = 'p.datep'; } @@ -866,13 +944,14 @@ if ($modecompta == 'BOOKKEEPING') { $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."salary as s ON s.rowid=p.fk_salary"; $sql .= " INNER JOIN ".MAIN_DB_PREFIX."user as u ON u.rowid=s.fk_user"; - $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")"; + $sql .= " WHERE s.entity IN (".getEntity('salary').")"; if (!empty($date_start) && !empty($date_end)) { $sql .= " AND $column >= '".$db->idate($date_start)."' AND $column <= '".$db->idate($date_end)."'"; } $sql .= " GROUP BY u.rowid, u.firstname, u.lastname, s.fk_user, p.label, dm"; // For backward compatibility with old module salary + $column = 'p.datep'; $sql .= " UNION "; $sql .= " SELECT u.rowid, u.firstname, u.lastname, p.fk_user as fk_user, p.label as label, date_format($column,'%Y-%m') as dm, sum(p.amount) as amount"; $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p"; @@ -918,16 +997,18 @@ if ($modecompta == 'BOOKKEEPING') { $userstatic->fetch($obj->fk_user); print "".$langs->trans("Salary")." getFullName($langs))."\">".$obj->firstname." ".$obj->lastname."\n"; - + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$obj->amount).''; + print ''.price(-$obj->amount).''; } + print ''; print ''.price(-$obj->amount).''; print ''; $i++; } } else { - print ' '; + print ''; + print ' '; print ''.$langs->trans("None").''; print ''; } @@ -939,10 +1020,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ttc_outcome += $subtotal_ttc; print ''; + print ''; + print ''; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$subtotal_ht).''; + print price(-$subtotal_ht); } - print ''.price(-$subtotal_ttc).''; + print ''; + print ''.price(-$subtotal_ttc).''; print ''; } @@ -1001,18 +1086,20 @@ if ($modecompta == 'BOOKKEEPING') { $subtotal_ht += $obj->amount_ht; $subtotal_ttc += $obj->amount_ttc; - print ' '; - + print ''; + print ' '; print "".$langs->trans("ExpenseReport")." userid."\">".$obj->firstname." ".$obj->lastname."\n"; - + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$obj->amount_ht).''; + print ''.price(-$obj->amount_ht).''; } + print ''; print ''.price(-$obj->amount_ttc).''; print ''; } } else { - print ' '; + print ''; + print ' '; print ''.$langs->trans("None").''; print ''; } @@ -1024,10 +1111,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ttc_outcome += $subtotal_ttc; print ''; + print ''; + print ''; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$subtotal_ht).''; + print price(-$subtotal_ht); } - print ''.price(-$subtotal_ttc).''; + print ''; + print ''.price(-$subtotal_ttc).''; print ''; } @@ -1064,11 +1155,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ht_outcome += $obj->amount; $total_ttc_outcome += $obj->amount; } - print ' '; + print ''; + print ' '; print "".$langs->trans("Debit")."\n"; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price(-$obj->amount).''; + print ''.price(-$obj->amount).''; } + print ''; print ''.price(-$obj->amount)."\n"; print "\n"; @@ -1083,9 +1177,11 @@ if ($modecompta == 'BOOKKEEPING') { } print ' '; print "".$langs->trans("Credit")."\n"; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price($obj->amount).''; + print ''.price($obj->amount).''; } + print ''; print ''.price($obj->amount)."\n"; print "\n"; @@ -1093,10 +1189,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ht += $subtotal_ht; $total_ttc += $subtotal_ttc; print ''; + print ''; + print ''; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price($subtotal_ht).''; + print price($subtotal_ht); } - print ''.price($subtotal_ttc).''; + print ''; + print ''.price($subtotal_ttc).''; print ''; } else { dol_print_error($db); @@ -1148,10 +1248,14 @@ if ($modecompta == 'BOOKKEEPING') { $total_ttc_income += $subtotal_ttc; print ''; + print ''; + print ''; + print ''; if ($modecompta == 'CREANCES-DETTES') { - print ''.price($subtotal_ht).''; + print price($subtotal_ht); } - print ''.price($subtotal_ttc).''; + print ''; + print ''.price($subtotal_ttc).''; print ''; } else { dol_print_error($db); @@ -1219,7 +1323,8 @@ if ($modecompta == 'BOOKKEEPING') { $total_ht_outcome -= 0; $total_ttc_outcome -= $amount; - print ' '; + print ''; + print ' '; print "".$langs->trans("VATToPay")."\n"; print ' '."\n"; print ''.price($amount)."\n"; @@ -1277,7 +1382,8 @@ if ($modecompta == 'BOOKKEEPING') { $total_ht_income += 0; $total_ttc_income += $amount; - print ' '; + print ''; + print ' '; print ''.$langs->trans("VATToCollect")."\n"; print ' '."\n"; print ''.price($amount)."\n"; @@ -1331,11 +1437,10 @@ if ($modecompta == 'BOOKKEEPING') { $total_ht_outcome -= 0; $total_ttc_outcome -= $amount; - print ' '; + print ''; + print ' '; print "".$langs->trans("VATPaid")."\n"; - if ($modecompta == 'CREANCES-DETTES') { - print ''."\n"; - } + print ''."\n"; print ''.price($amount)."\n"; print "\n"; @@ -1387,11 +1492,10 @@ if ($modecompta == 'BOOKKEEPING') { $total_ht_income += 0; $total_ttc_income += $amount; - print ' '; + print ''; + print ' '; print "".$langs->trans("VATCollected")."\n"; - if ($modecompta == 'CREANCES-DETTES') { - print ''."\n"; - } + print ''."\n"; print ''.price($amount)."\n"; print "\n"; } @@ -1399,10 +1503,10 @@ if ($modecompta == 'BOOKKEEPING') { if ($mysoc->tva_assuj != '0') { // Assujetti print ''; - if ($modecompta == 'CREANCES-DETTES') { - print ' '; - } - print ''.price(price2num($subtotal_ttc, 'MT')).''; + print ''; + print ''; + print ' '; + print ''.price(price2num($subtotal_ttc, 'MT')).''; print ''; } } diff --git a/htdocs/compta/resultat/index.php b/htdocs/compta/resultat/index.php index 2d4ea6fc9e0..6aab9093c05 100644 --- a/htdocs/compta/resultat/index.php +++ b/htdocs/compta/resultat/index.php @@ -60,11 +60,11 @@ $date_end = dol_mktime(23, 59, 59, $date_endmonth, $date_endday, $date_endyear); // We define date_start and date_end if (empty($date_start) || empty($date_end)) { // We define date_start and date_end - $q = GETPOST("q") ?GETPOST("q") : 0; + $q = GETPOST("q") ? GETPOST("q", 'int') : 0; if ($q == 0) { // We define date_start and date_end $year_end = $year_start + ($nbofyear - 1); - $month_start = GETPOST("month") ?GETPOST("month") : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); + $month_start = GETPOST("month") ? GETPOST("month", 'int') : ($conf->global->SOCIETE_FISCAL_MONTH_START ? ($conf->global->SOCIETE_FISCAL_MONTH_START) : 1); if (!GETPOST('month')) { if (!GETPOST("year") && $month_start > $month_current) { $year_start--; @@ -140,6 +140,11 @@ $form = new Form($db); $exportlink = ''; +$encaiss = array(); +$encaiss_ttc = array(); +$decaiss = array(); +$decaiss_ttc = array(); + // Affiche en-tete du rapport if ($modecompta == 'CREANCES-DETTES') { $name = $langs->trans("ReportInOut").', '.$langs->trans("ByYear"); @@ -152,7 +157,7 @@ if ($modecompta == 'CREANCES-DETTES') { } $period = $form->selectDate($date_start, 'date_start', 0, 0, 0, '', 1, 0).' - '.$form->selectDate($date_end, 'date_end', 0, 0, 0, '', 1, 0); $periodlink = ($year_start ? "".img_previous()." ".img_next()."" : ""); - $description = $langs->trans("RulesAmountWithTaxIncluded"); + $description = $langs->trans("RulesAmountWithTaxExcluded"); $description .= '
'.$langs->trans("RulesResultDue"); if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { $description .= "
".$langs->trans("DepositsAreNotIncluded"); @@ -237,10 +242,9 @@ if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mod $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } } - $sql .= " AND f.entity IN (".getEntity('invoice').")"; if ($socid) { - $sql .= " AND f.fk_soc = $socid"; + $sql .= " AND f.fk_soc = ".((int) $socid); } $sql .= " GROUP BY dm"; $sql .= " ORDER BY dm"; @@ -344,8 +348,8 @@ if (!empty($conf->facture->enabled) && ($modecompta == 'CREANCES-DETTES' || $mod $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } } + $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")"; - $sql .= " AND f.entity = ".$conf->entity; if ($socid) { $sql .= " AND f.fk_soc = ".((int) $socid); } @@ -413,10 +417,10 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom while ($i < $num) { $obj = $db->fetch_object($result); - if (!isset($decaiss[$obj->dm])) { + /*if (!isset($decaiss[$obj->dm])) { $decaiss[$obj->dm] = 0; } - $decaiss[$obj->dm] += $obj->amount; + $decaiss[$obj->dm] += $obj->amount;*/ if (!isset($decaiss_ttc[$obj->dm])) { $decaiss_ttc[$obj->dm] = 0; @@ -438,7 +442,7 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom } else { $sql .= " AND f.type IN (0,1,2,3)"; } - $sql .= " AND f.entity = ".$conf->entity; + $sql .= " AND f.entity IN (".getEntity('supplier_invoice').")"; if (!empty($date_start) && !empty($date_end)) { $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'"; } @@ -453,10 +457,10 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom while ($i < $num) { $obj = $db->fetch_object($result); - if (!isset($encaiss[$obj->dm])) { + /*if (!isset($encaiss[$obj->dm])) { $encaiss[$obj->dm] = 0; } - $encaiss[$obj->dm] += $obj->amount; + $encaiss[$obj->dm] += $obj->amount;*/ if (!isset($encaiss_ttc[$obj->dm])) { $encaiss_ttc[$obj->dm] = 0; @@ -474,7 +478,7 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; $sql .= " WHERE amount > 0"; - $sql .= " AND t.entity = ".$conf->entity; + $sql .= " AND t.entity IN (".getEntity('vat').")"; if (!empty($date_start) && !empty($date_end)) { $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; } @@ -489,10 +493,10 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom while ($i < $num) { $obj = $db->fetch_object($result); - if (!isset($decaiss[$obj->dm])) { + /*if (!isset($decaiss[$obj->dm])) { $decaiss[$obj->dm] = 0; } - $decaiss[$obj->dm] += $obj->amount; + $decaiss[$obj->dm] += $obj->amount;*/ if (!isset($decaiss_ttc[$obj->dm])) { $decaiss_ttc[$obj->dm] = 0; @@ -509,7 +513,7 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom $sql = "SELECT sum(t.amount) as amount, date_format(t.datev,'%Y-%m') as dm"; $sql .= " FROM ".MAIN_DB_PREFIX."tva as t"; $sql .= " WHERE amount < 0"; - $sql .= " AND t.entity = ".$conf->entity; + $sql .= " AND t.entity IN (".getEntity('vat').")"; if (!empty($date_start) && !empty($date_end)) { $sql .= " AND t.datev >= '".$db->idate($date_start)."' AND t.datev <= '".$db->idate($date_end)."'"; } @@ -524,10 +528,10 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom while ($i < $num) { $obj = $db->fetch_object($result); - if (!isset($encaiss[$obj->dm])) { + /*if (!isset($encaiss[$obj->dm])) { $encaiss[$obj->dm] = 0; } - $encaiss[$obj->dm] += -$obj->amount; + $encaiss[$obj->dm] += -$obj->amount;*/ if (!isset($encaiss_ttc[$obj->dm])) { $encaiss_ttc[$obj->dm] = 0; @@ -572,7 +576,7 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom } } - $sql .= " AND cs.entity = ".$conf->entity; + $sql .= " AND cs.entity IN (".getEntity('social_contributions').")"; $sql .= " GROUP BY c.libelle, dm"; dol_syslog("get social contributions", LOG_DEBUG); @@ -611,7 +615,8 @@ if (!empty($conf->tax->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecom if (!empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { if ($modecompta == 'CREANCES-DETTES') { - $column = 'p.datev'; + //$column = 's.dateep'; // we use the date of salary + $column = 'p.datep'; } if ($modecompta == "RECETTES-DEPENSES") { $column = 'p.datep'; @@ -620,8 +625,9 @@ if (!empty($conf->salaries->enabled) && ($modecompta == 'CREANCES-DETTES' || $mo $subtotal_ht = 0; $subtotal_ttc = 0; $sql = "SELECT p.label as nom, date_format(".$column.",'%Y-%m') as dm, sum(p.amount) as amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p"; - $sql .= " WHERE p.entity IN (".getEntity('payment_salary').")"; + $sql .= " FROM ".MAIN_DB_PREFIX."payment_salary as p, ".MAIN_DB_PREFIX."salary as s"; + $sql .= " WHERE p.fk_salary = s.rowid"; + $sql .= " AND s.entity IN (".getEntity('salary').")"; if (!empty($date_start) && !empty($date_end)) { $sql .= " AND ".$column." >= '".$db->idate($date_start)."' AND ".$column." <= '".$db->idate($date_end)."'"; } @@ -786,7 +792,8 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->ba // decaiss $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various as p"; - $sql .= ' WHERE p.sens = 0'; + $sql .= " WHERE p.entity IN (".getEntity('variouspayment').")"; + $sql .= ' AND p.sens = 0'; if (!empty($date_start) && !empty($date_end)) { $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } @@ -816,7 +823,8 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->ba // encaiss $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount) AS amount FROM ".MAIN_DB_PREFIX."payment_various AS p"; - $sql .= ' WHERE p.sens = 1'; + $sql .= " WHERE p.entity IN (".getEntity('variouspayment').")"; + $sql .= ' AND p.sens = 1'; if (!empty($date_start) && !empty($date_end)) { $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } @@ -852,8 +860,10 @@ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_VARPAY) && !empty($conf->ba */ if (!empty($conf->global->ACCOUNTING_REPORTS_INCLUDE_LOAN) && !empty($conf->loan->enabled) && ($modecompta == 'CREANCES-DETTES' || $modecompta == "RECETTES-DEPENSES")) { - $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount FROM ".MAIN_DB_PREFIX."payment_loan AS p"; - $sql .= ' WHERE 1 = 1'; + $sql = "SELECT date_format(p.datep, '%Y-%m') AS dm, SUM(p.amount_capital + p.amount_insurance + p.amount_interest) AS amount"; + $sql .= " FROM ".MAIN_DB_PREFIX."payment_loan AS p, ".MAIN_DB_PREFIX."loan as l"; + $sql .= " WHERE l.entity IN (".getEntity('variouspayment').")"; + $sql .= " AND p.fk_loan = l.rowid"; if (!empty($date_start) && !empty($date_end)) { $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'"; } @@ -1025,7 +1035,7 @@ for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) { $case = strftime("%Y-%m", dol_mktime(12, 0, 0, $mois_modulo, 1, $annee_decalage)); print ' '; - if ($modecompta == 'BOOKKEEPING') { + if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING') { if (isset($decaiss[$case]) && $decaiss[$case] != 0) { print ''.price(price2num($decaiss[$case], 'MT')).''; if (!isset($totsorties[$annee])) { @@ -1045,7 +1055,7 @@ for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) { print ""; print ' '; - if ($modecompta == 'BOOKKEEPING') { + if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING') { if (isset($encaiss[$case])) { print ''.price(price2num($encaiss[$case], 'MT')).''; if (!isset($totentrees[$annee])) { @@ -1072,7 +1082,7 @@ for ($mois = 1 + $nb_mois_decalage; $mois <= 12 + $nb_mois_decalage; $mois++) { $nbcols = 0; print ''; -if ($modecompta == 'BOOKKEEPING') { +if ($modecompta == 'CREANCES-DETTES' || $modecompta == 'BOOKKEEPING') { print $langs->trans("Total"); } else { print $langs->trans("TotalTTC"); diff --git a/htdocs/compta/sociales/card.php b/htdocs/compta/sociales/card.php index 98ebe32f970..0ea9b1ba30d 100644 --- a/htdocs/compta/sociales/card.php +++ b/htdocs/compta/sociales/card.php @@ -62,6 +62,9 @@ $label = GETPOST('label', 'alpha'); $actioncode = GETPOST('actioncode'); $fk_user = GETPOST('userid', 'int'); +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('taxcard', 'globalcard')); + // Initialize technical objects $object = new ChargeSociales($db); $extrafields = new ExtraFields($db); @@ -97,7 +100,7 @@ $result = restrictedArea($user, 'tax', $object->id, 'chargesociales', 'charges') * Actions */ -$parameters = array(); +$parameters = array('socid' => $socid); $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'); @@ -446,6 +449,8 @@ if ($id > 0) { $object = new ChargeSociales($db); $result = $object->fetch($id); + $formconfirm = ''; + if ($result > 0) { $head = tax_prepare_head($object); @@ -464,25 +469,36 @@ if ($id > 0) { $formquestion[] = array('type' => 'text', 'name' => 'amount', 'label' => $langs->trans("Amount"), 'value' => price($object->amount), 'morecss' => 'width100'); } - print $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneTax', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 280); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneTax', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 280); } if ($action == 'paid') { $text = $langs->trans('ConfirmPaySocialContribution'); - print $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySocialContribution'), $text, "confirm_paid", '', '', 2); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"]."?id=".$object->id, $langs->trans('PaySocialContribution'), $text, "confirm_paid", '', '', 2); } // Confirmation of the removal of the Social Contribution if ($action == 'delete') { $text = $langs->trans('ConfirmDeleteSocialContribution'); - print $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSocialContribution'), $text, 'confirm_delete', '', '', 2); + $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('DeleteSocialContribution'), $text, 'confirm_delete', '', '', 2); } if ($action == 'edit') { print "
id&action=update\" method=\"post\">"; print ''; } + // Call Hook formConfirm + $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid); + $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + if (empty($reshook)) { + $formconfirm .= $hookmanager->resPrint; + } elseif ($reshook > 0) { + $formconfirm = $hookmanager->resPrint; + } + + // Print form confirm + print $formconfirm; print dol_get_fiche_head($head, 'card', $langs->trans("SocialContribution"), -1, 'bill'); @@ -600,7 +616,7 @@ if ($id > 0) { print ''; print ""; } else { - print ''.$langs->trans("AmountTTC").''.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).''; + print ''.$langs->trans("AmountTTC").''.price($object->amount, 0, $langs, 1, -1, -1, $conf->currency).''; } // Mode of payment @@ -741,8 +757,8 @@ if ($id > 0) { print ''; } - print ''.$langs->trans("AlreadyPaid")." :".price($totalpaye)."\n"; - print ''.$langs->trans("AmountExpected")." :".price($object->amount)."\n"; + print ''.$langs->trans("AlreadyPaid").' :'.price($totalpaye)."\n"; + print ''.$langs->trans("AmountExpected").' :'.price($object->amount)."\n"; $resteapayer = $object->amount - $totalpaye; $cssforamountpaymentcomplete = 'amountpaymentcomplete'; diff --git a/htdocs/compta/sociales/document.php b/htdocs/compta/sociales/document.php index 66800c4d449..6918b2c84ee 100644 --- a/htdocs/compta/sociales/document.php +++ b/htdocs/compta/sociales/document.php @@ -47,8 +47,8 @@ $confirm = GETPOST('confirm', 'alpha'); // Get parameters $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/sociales/list.php b/htdocs/compta/sociales/list.php index f4ef22d1fd5..8d63e52256e 100644 --- a/htdocs/compta/sociales/list.php +++ b/htdocs/compta/sociales/list.php @@ -68,14 +68,13 @@ $search_date_limit_endyear = GETPOST('search_date_limit_endyear', 'int'); $search_date_limit_start = dol_mktime(0, 0, 0, $search_date_limit_startmonth, $search_date_limit_startday, $search_date_limit_startyear); $search_date_limit_end = dol_mktime(23, 59, 59, $search_date_limit_endmonth, $search_date_limit_endday, $search_date_limit_endyear); $search_project_ref = GETPOST('search_project_ref', 'alpha'); -$search_project = GETPOST('search_project', 'alpha'); $search_users = GETPOST('search_users'); $search_type = GETPOST('search_type', 'int'); $search_account = GETPOST('search_account', 'int'); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST("sortorder", 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { @@ -176,7 +175,6 @@ if (empty($reshook)) { $search_date_limit_start = ''; $search_date_limit_end = ''; $search_project_ref = ''; - $search_project = ''; $search_users = ''; $search_type = ''; $search_account = ''; @@ -200,11 +198,11 @@ if (!empty($conf->projet->enabled)) { llxHeader('', $langs->trans("SocialContributions")); $sql = "SELECT cs.rowid, cs.fk_type as type, cs.fk_user,"; -$sql .= " cs.amount, cs.date_ech, cs.libelle as label, cs.paye, cs.periode,"; +$sql .= " cs.amount, cs.date_ech, cs.libelle as label, cs.paye, cs.periode, cs.fk_account,"; if (!empty($conf->projet->enabled)) { $sql .= " p.rowid as project_id, p.ref as project_ref, p.title as project_label,"; } -$sql .= " c.libelle as type_label, cs.fk_account,"; +$sql .= " c.libelle as type_label, c.accountancy_code as type_accountancy_code,"; $sql .= " ba.label as blabel, ba.ref as bref, ba.number as bnumber, ba.account_number, ba.iban_prefix as iban, ba.bic, ba.currency_code, ba.clos,"; $sql .= " SUM(pc.amount) as alreadypayed, pay.code as payment_code"; $sql .= " FROM ".MAIN_DB_PREFIX."c_chargesociales as c,"; @@ -231,7 +229,7 @@ if (!empty($conf->projet->enabled)) { } } if (!empty($search_users)) { - $sql .= ' AND cs.fk_user IN('.implode(', ', $search_users).')'; + $sql .= ' AND cs.fk_user IN ('.$db->sanitize(implode(', ', $search_users)).')'; } if (!empty($search_type) && $search_type > 0) { $sql .= ' AND cs.fk_mode_reglement='.((int) $search_type); @@ -260,7 +258,7 @@ if ($search_date_limit_end) { if ($search_typeid > 0) { $sql .= " AND cs.fk_type = ".((int) $search_typeid); } -$sql .= " GROUP BY cs.rowid, cs.fk_type, cs.fk_user, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, c.libelle, cs.fk_account, ba.label, ba.ref, ba.number, ba.account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.clos, pay.code, u.lastname"; +$sql .= " GROUP BY cs.rowid, cs.fk_type, cs.fk_user, cs.amount, cs.date_ech, cs.libelle, cs.paye, cs.periode, cs.fk_account, c.libelle, c.accountancy_code, ba.label, ba.ref, ba.number, ba.account_number, ba.iban_prefix, ba.bic, ba.currency_code, ba.clos, pay.code, u.lastname"; if (!empty($conf->projet->enabled)) { $sql .= ", p.rowid, p.ref, p.title"; } @@ -455,7 +453,7 @@ if (!empty($arrayfields['cs.periode']['checked'])) { // Filter: Project ref if (!empty($arrayfields['p.ref']['checked'])) { print ''; - print ''; + print ''; print ''; } @@ -561,6 +559,7 @@ while ($i < min($num, $limit)) { $chargesociale_static->ref = $obj->rowid; $chargesociale_static->label = $obj->label; $chargesociale_static->type_label = $obj->type_label; + if (!empty($conf->projet->enabled)) { $projectstatic->id = $obj->project_id; $projectstatic->ref = $obj->project_ref; @@ -595,7 +594,12 @@ while ($i < min($num, $limit)) { // Type if (!empty($arrayfields['cs.fk_type']['checked'])) { - print ''.dol_escape_htmltag($obj->type_label).''; + $typelabeltoshow = $obj->type_label; + $typelabelpopup = $obj->type_label; + if (!empty($conf->accounting->enabled)) { + $typelabelpopup .= ' - '.$langs->trans("AccountancyCode").': '.$obj->type_accountancy_code; + } + print ''.dol_escape_htmltag($typelabeltoshow).''; if (!$i) { $totalarray['nbfield']++; } @@ -651,7 +655,9 @@ while ($i < min($num, $limit)) { // Type if (!empty($arrayfields['cs.fk_mode_reglement']['checked'])) { print ''; - if (!empty($obj->payment_code)) print $langs->trans("PaymentTypeShort".$obj->payment_code); + if (!empty($obj->payment_code)) { + print $langs->trans("PaymentTypeShort".$obj->payment_code); + } print ''; if (!$i) { $totalarray['nbfield']++; diff --git a/htdocs/compta/sociales/payments.php b/htdocs/compta/sociales/payments.php index b2ee4ffce5e..f5cbcc47502 100644 --- a/htdocs/compta/sociales/payments.php +++ b/htdocs/compta/sociales/payments.php @@ -50,8 +50,8 @@ $year = GETPOST("year", 'int'); $search_sc_type = GETPOST('search_sc_type', 'int'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page < 0) { $page = 0; @@ -66,7 +66,7 @@ if (!$sortorder) { $sortorder = "DESC"; } -// Security check +// Security check140px if ($user->socid) { $socid = $user->socid; } @@ -135,8 +135,8 @@ print ''; print ''; print ''; -$sql = "SELECT c.id, c.libelle as label,"; -$sql .= " cs.rowid, cs.libelle, cs.fk_type as type, cs.periode, cs.date_ech, cs.amount as total,"; +$sql = "SELECT c.id, c.libelle as type_label,"; +$sql .= " cs.rowid, cs.libelle as label_sc, cs.fk_type as type, cs.periode, cs.date_ech, cs.amount as total, cs.paye,"; $sql .= " pc.rowid as pid, pc.datep, pc.amount as totalpaye, pc.num_paiement as num_payment, pc.fk_bank,"; $sql .= " pct.code as payment_code,"; $sql .= " u.rowid uid, u.lastname, u.firstname, u.email, u.login, u.admin,"; @@ -231,8 +231,8 @@ print ''; print_liste_field_titre("RefPayment", $_SERVER["PHP_SELF"], "pc.rowid", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("SocialContribution", $_SERVER["PHP_SELF"], "c.libelle", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("TypeContrib", $_SERVER["PHP_SELF"], "cs.fk_type", "", $param, '', $sortfield, $sortorder); -print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "cs.periode", "", $param, 'width="140px"', $sortfield, $sortorder); -print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pc.datep", "", $param, 'align="center"', $sortfield, $sortorder); +print_liste_field_titre("PeriodEndDate", $_SERVER["PHP_SELF"], "cs.periode", "", $param, '', $sortfield, $sortorder, 'center '); +print_liste_field_titre("DatePayment", $_SERVER["PHP_SELF"], "pc.datep", "", $param, '', $sortfield, $sortorder, 'center '); print_liste_field_titre("Employee", $_SERVER["PHP_SELF"], "u.rowid", "", $param, "", $sortfield, $sortorder); print_liste_field_titre("PaymentMode", $_SERVER["PHP_SELF"], "pct.code", "", $param, '', $sortfield, $sortorder); print_liste_field_titre("Numero", $_SERVER["PHP_SELF"], "pc.num_paiement", "", $param, '', $sortfield, $sortorder, '', 'ChequeOrTransferNumber'); @@ -257,26 +257,34 @@ $totalpaye = 0; while ($i < min($num, $limit)) { $obj = $db->fetch_object($resql); - print ''; - // Ref payment + $payment_sc_static->id = $obj->pid; $payment_sc_static->ref = $obj->pid; - print ''.$payment_sc_static->getNomUrl(1)."\n"; - // Label - print ''; + $payment_sc_static->date = $db->jdate($obj->datep); + $socialcontrib->id = $obj->rowid; - $socialcontrib->ref = empty($obj->libelle) ? $obj->label : $obj->libelle; - $socialcontrib->label = empty($obj->libelle) ? $obj->label : $obj->libelle; - print $socialcontrib->getNomUrl(1, '20'); + $socialcontrib->ref = empty($obj->label_sc) ? $obj->type_label : $obj->label_sc; + $socialcontrib->paye = $obj->paye; + // $obj->label_sc is label of social contribution (may be empty) + // $obj->type_label is label of type of social contribution + $socialcontrib->label = empty($obj->label_sc) ? $obj->type_label : $obj->label_sc; + $socialcontrib->type_label = $obj->type_label; + + print ''; + // Ref payment + print ''.$payment_sc_static->getNomUrl(1)."\n"; + // Label + print ''; + print $socialcontrib->getNomUrl(1, ''); print ''; // Type - print ''.$obj->label.''; + print ''.$obj->label.''; // Date $date = $obj->periode; if (empty($date)) { $date = $obj->date_ech; } - print ''.dol_print_date($date, 'day').''; + print ''.dol_print_date($date, 'day').''; // Date payment print ''.dol_print_date($db->jdate($obj->datep), 'day').''; diff --git a/htdocs/compta/stats/cabyprodserv.php b/htdocs/compta/stats/cabyprodserv.php index 021bffe40b4..084516c52df 100644 --- a/htdocs/compta/stats/cabyprodserv.php +++ b/htdocs/compta/stats/cabyprodserv.php @@ -52,8 +52,8 @@ if (GETPOST("modecompta")) { $modecompta = GETPOST("modecompta"); } -$sortorder = GETPOST("sortorder", 'aZ09'); -$sortfield = GETPOST("sortfield", 'aZ09'); +$sortorder = GETPOST("sortorder", 'aZ09comma'); +$sortfield = GETPOST("sortfield", 'aZ09comma'); if (!$sortorder) { $sortorder = "asc"; } diff --git a/htdocs/compta/stats/cabyuser.php b/htdocs/compta/stats/cabyuser.php index 8e3169f1e8c..35d5028e938 100644 --- a/htdocs/compta/stats/cabyuser.php +++ b/htdocs/compta/stats/cabyuser.php @@ -51,8 +51,8 @@ if (GETPOST("modecompta")) { $modecompta = GETPOST("modecompta"); } -$sortorder = GETPOST("sortorder", 'aZ09'); -$sortfield = GETPOST("sortfield", 'aZ09'); +$sortorder = GETPOST("sortorder", 'aZ09comma'); +$sortfield = GETPOST("sortfield", 'aZ09comma'); if (!$sortorder) { $sortorder = "asc"; } diff --git a/htdocs/compta/stats/casoc.php b/htdocs/compta/stats/casoc.php index 10f7956c6b7..76dbc56beef 100644 --- a/htdocs/compta/stats/casoc.php +++ b/htdocs/compta/stats/casoc.php @@ -44,8 +44,8 @@ if (GETPOST("modecompta")) { $modecompta = GETPOST("modecompta"); } -$sortorder = GETPOST("sortorder", 'aZ09'); -$sortfield = GETPOST("sortfield", 'aZ09'); +$sortorder = GETPOST("sortorder", 'aZ09comma'); +$sortfield = GETPOST("sortfield", 'aZ09comma'); if (!$sortorder) { $sortorder = "asc"; } diff --git a/htdocs/compta/stats/supplier_turnover_by_prodserv.php b/htdocs/compta/stats/supplier_turnover_by_prodserv.php index 4e92325a323..f36383ad94b 100644 --- a/htdocs/compta/stats/supplier_turnover_by_prodserv.php +++ b/htdocs/compta/stats/supplier_turnover_by_prodserv.php @@ -36,8 +36,8 @@ if (GETPOST("modecompta")) { $modecompta = GETPOST("modecompta"); } -$sortorder = GETPOST("sortorder", 'aZ09'); -$sortfield = GETPOST("sortfield", 'aZ09'); +$sortorder = GETPOST("sortorder", 'aZ09comma'); +$sortfield = GETPOST("sortfield", 'aZ09comma'); if (!$sortorder) { $sortorder = "asc"; } diff --git a/htdocs/compta/stats/supplier_turnover_by_thirdparty.php b/htdocs/compta/stats/supplier_turnover_by_thirdparty.php index 0ea8418381d..0be2df11190 100644 --- a/htdocs/compta/stats/supplier_turnover_by_thirdparty.php +++ b/htdocs/compta/stats/supplier_turnover_by_thirdparty.php @@ -38,8 +38,8 @@ if (GETPOST("modecompta")) { $modecompta = GETPOST("modecompta"); } -$sortorder = GETPOST("sortorder", 'aZ09'); -$sortfield = GETPOST("sortfield", 'aZ09'); +$sortorder = GETPOST("sortorder", 'aZ09comma'); +$sortfield = GETPOST("sortfield", 'aZ09comma'); if (!$sortorder) { $sortorder = "asc"; } diff --git a/htdocs/compta/tva/card.php b/htdocs/compta/tva/card.php old mode 100755 new mode 100644 index 530d18d17f9..317838009c7 --- a/htdocs/compta/tva/card.php +++ b/htdocs/compta/tva/card.php @@ -196,7 +196,8 @@ if ($action == 'add' && !$cancel) { } $object->amount = $amount; $object->label = GETPOST("label", 'alpha'); - $object->note = GETPOST("note", 'none'); + $object->note = GETPOST("note", 'restricthtml'); + $object->note_private = GETPOST("note", 'restricthtml'); if (empty($object->datep)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("DatePayment")), null, 'errors'); @@ -236,7 +237,7 @@ if ($action == 'add' && !$cancel) { $paiement->amounts = array($object->id=>$amount); // Tableau de montant $paiement->paiementtype = GETPOST("type_payment", 'alphanohtml'); $paiement->num_payment = GETPOST("num_payment", 'alphanohtml'); - $paiement->note = GETPOST("note", 'none'); + $paiement->note = GETPOST("note", 'restricthtml'); if (!$error) { $paymentid = $paiement->create($user, (int) GETPOST('closepaidtva')); diff --git a/htdocs/compta/tva/document.php b/htdocs/compta/tva/document.php index 67de87d0c21..a0573cf2812 100644 --- a/htdocs/compta/tva/document.php +++ b/htdocs/compta/tva/document.php @@ -48,8 +48,8 @@ $confirm = GETPOST('confirm', 'alpha'); // Get parameters $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/tva/list.php b/htdocs/compta/tva/list.php index 8c12dbfd704..f1731420852 100644 --- a/htdocs/compta/tva/list.php +++ b/htdocs/compta/tva/list.php @@ -56,8 +56,8 @@ $search_amount = GETPOST('search_amount', 'alpha'); $search_status = GETPOST('search_status', 'int'); $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST('sortfield', 'alpha'); -$sortorder = GETPOST('sortorder', 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST('page', 'int'); if (empty($page) || $page == -1) { diff --git a/htdocs/compta/tva/payments.php b/htdocs/compta/tva/payments.php index 57e70e70a3d..488882c2649 100644 --- a/htdocs/compta/tva/payments.php +++ b/htdocs/compta/tva/payments.php @@ -46,8 +46,8 @@ if (!$year && $mode != 'tvaonly') { } $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/compta/tva/quadri_detail.php b/htdocs/compta/tva/quadri_detail.php index 4b44959bc1a..15c45d6055b 100644 --- a/htdocs/compta/tva/quadri_detail.php +++ b/htdocs/compta/tva/quadri_detail.php @@ -6,7 +6,7 @@ * Copyright (C) 2014 Ferran Marcet * Copyright (C) 2018-2021 Frédéric France * Copyright (C) 2019 Eric Seigne - * Copyright (C) 2021 Open-Dsi + * Copyright (C) 2021-2022 Open-Dsi * * 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 @@ -47,7 +47,7 @@ $langs->loadLangs(array("other", "compta", "banks", "bills", "companies", "produ $refresh = (GETPOSTISSET('submit') || GETPOSTISSET('vat_rate_show') || GETPOSTISSET('invoice_type')) ? true : false; $invoice_type = GETPOSTISSET('invoice_type') ? GETPOST('invoice_type', 'alpha') : ''; -$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'int') : -1; +$vat_rate_show = GETPOSTISSET('vat_rate_show') ? GETPOST('vat_rate_show', 'alphanohtml') : -1; include DOL_DOCUMENT_ROOT.'/compta/tva/initdatesforvat.inc.php'; @@ -409,7 +409,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) { print ''; print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; @@ -643,7 +643,7 @@ if (!is_array($x_coll) || !is_array($x_paye)) { print ''; print $langs->trans('Rate') . ' : ' . vatrate($rate) . '%'; print ' - ' . img_picto('', 'chevron-down', 'class="paddingrightonly"') . $langs->trans('VATReportShowByRateDetails') . ''; diff --git a/htdocs/contact/agenda.php b/htdocs/contact/agenda.php index 293c4f11aa3..0eed6ba6219 100644 --- a/htdocs/contact/agenda.php +++ b/htdocs/contact/agenda.php @@ -88,8 +88,8 @@ if ($user->socid) { $result = restrictedArea($user, 'contact', $id, 'socpeople&societe', '', '', 'rowid', 0); // If we create a contact with no company (shared contacts), no check on write permission $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; @@ -212,7 +212,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref = '
'; + $morehtmlref = ''; + $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); + $morehtmlref .= ''; + + $morehtmlref .= '
'; if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { $objsoc = new Societe($db); $objsoc->fetch($object->socid); diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index 45923910633..bd0d694eb57 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -532,6 +532,8 @@ if (empty($reshook)) { * View */ +$form = new Form($db); +$formcompany = new FormCompany($db); $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses")); if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $conf->global->MAIN_HTML_TITLE) && $object->lastname) { @@ -540,9 +542,6 @@ if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/contactnameonly/', $c $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; llxHeader('', $title, $help_url); -$form = new Form($db); -$formcompany = new FormCompany($db); - $countrynotdefined = $langs->trans("ErrorSetACountryFirst").' ('.$langs->trans("SeeAbove").')'; $objsoc = new Societe($db); @@ -1284,7 +1283,11 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref = '
'; + $morehtmlref = ''; + $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); + $morehtmlref .= ''; + + $morehtmlref .= '
'; if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { $objsoc->fetch($object->socid); // Thirdparty @@ -1462,14 +1465,6 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action)) { } print ''; - print ''; - print $langs->trans("VCard").''; - print ''; - print img_picto($langs->trans("Download"), 'vcard.png', 'class="paddingrightonly"'); - print $langs->trans("Download"); - print ''; - print ''; - print ""; print '
'; diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index fa1dfb93c7a..bb3f2ae035d 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -1389,24 +1389,25 @@ class Contact extends CommonObject * Return name of contact with link (and eventually picto) * Use $this->id, $this->lastname, $this->firstname, this->civility_id * - * @param int $withpicto Include picto with link + * @param int $withpicto Include picto with link (1=picto + name, 2=picto only, -1=photo+name, -2=photo only) * @param string $option Where the link point to * @param int $maxlen Max length of * @param string $moreparam Add more param into URL * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking * @param int $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link * @return string String with URL */ - public function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $moreparam = '', $save_lastsearch_value = -1, $notooltip = 0) + public function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $moreparam = '', $save_lastsearch_value = -1, $notooltip = 0, $morecss = '') { global $conf, $langs, $hookmanager; $result = ''; $label = ''; - if (!empty($this->photo) && class_exists('Form')) { - $label .= '
'; - $label .= Form::showphoto('contact', $this, 0, 40, 0, '', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. - $label .= '
'; + $label .= '
'; + $label .= Form::showphoto('contact', $this, 0, 40, 0, 'photoref', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip. + $label .= '
'; + //$label .= '
'; } $label .= img_picto('', $this->picto).' '.$langs->trans("Contact").''; @@ -1453,7 +1454,7 @@ class Contact extends CommonObject $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"'; } $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"'; - $linkclose .= ' class="classfortooltip"'; + $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"'; /* $hookmanager->initHooks(array('contactdao')); @@ -1474,14 +1475,14 @@ class Contact extends CommonObject $result .= $linkstart; if ($withpicto) { - if ($withpicto == -2) { - $result .= ''.Form::showphoto('contact', $this, 0, 0, 0, 'userphoto'.($withpicto == -3 ? 'small' : ''), 'mini', 0, 1).''; + if ($withpicto < 0) { + $result .= ''.Form::showphoto('contact', $this, 0, 0, 0, 'userphoto'.($withpicto == -3 ? 'small' : ''), 'mini', 0, 1).''; } else { $result .= img_object(($notooltip ? '' : $label), ( $this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1); } } if ($withpicto != 2 && $withpicto != -2) { - $result .= ($maxlen ?dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs)); + $result .= ''.($maxlen ? dol_trunc($this->getFullName($langs), $maxlen) : $this->getFullName($langs)).''; } $result .= $linkend; diff --git a/htdocs/contact/consumption.php b/htdocs/contact/consumption.php index bb610baa4b0..631bf932640 100644 --- a/htdocs/contact/consumption.php +++ b/htdocs/contact/consumption.php @@ -20,7 +20,7 @@ */ /** - * \file htdocs/societe/consumption.php + * \file htdocs/contact/consumption.php * \ingroup societe * \brief Add a tab on thirpdarty view to list all products/services bought or sells by thirdparty */ @@ -32,10 +32,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php'; require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; -// Security check +$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print') + $id = GETPOST('id', 'int'); -$result = restrictedArea($user, 'contact', $id, 'socpeople&societe'); $object = new Contact($db); if ($id > 0) { $object->fetch($id); @@ -47,8 +47,8 @@ $socid = $object->thirdparty->id; // Sort & Order fields $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; @@ -86,6 +86,8 @@ $langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", " // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('consumptioncontact')); +$result = restrictedArea($user, 'contact', $object->id, 'socpeople&societe'); + /* * Actions @@ -120,7 +122,11 @@ print dol_get_fiche_head($head, 'consumption', $langs->trans("ContactsAddresses" $linkback = ''.$langs->trans("BackToList").''; -$morehtmlref = '
'; +$morehtmlref = ''; +$morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); +$morehtmlref .= ''; + +$morehtmlref .= '
'; if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { $objsoc->fetch($socid); // Thirdparty @@ -196,7 +202,7 @@ if ($type_element == 'fichinter') { // Customer : show products from invoices $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datec as dateprint, f.fk_statut as status, tc.libelle as type_contact_label, '; $tables_from = MAIN_DB_PREFIX.'fichinterdet d'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'fichinter as f ON d.fk_fichinter=f.rowid'; - $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople='.$object->id; + $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople = '.((int) $object->id); $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='fichinter' and tc.source='external' and tc.active=1)"; $where = ' WHERE f.entity IN ('.getEntity('ficheinter').')'; $dateprint = 'f.datec'; @@ -208,7 +214,7 @@ if ($type_element == 'fichinter') { // Customer : show products from invoices $tables_from = MAIN_DB_PREFIX.'facturedet d'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture as f ON d.fk_facture=f.rowid'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid'; - $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople='.$object->id; + $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople = '.((int) $object->id); $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='facture' and tc.source='external' and tc.active=1)"; $where = " WHERE f.entity IN (".getEntity('invoice').")"; $dateprint = 'f.datef'; @@ -221,7 +227,7 @@ if ($type_element == 'fichinter') { // Customer : show products from invoices $tables_from = MAIN_DB_PREFIX.'propaldet d'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propal as c ON d.fk_propal=c.rowid'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid'; - $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople='.$object->id; + $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id); $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='propal' and tc.source='external' and tc.active=1)"; $where = ' WHERE c.entity IN ('.getEntity('propal').')'; $datePrint = 'c.datep'; @@ -234,7 +240,7 @@ if ($type_element == 'fichinter') { // Customer : show products from invoices $tables_from = MAIN_DB_PREFIX.'commandedet d'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande as c ON d.fk_commande=c.rowid'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid'; - $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople='.$object->id; + $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id); $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='commande' and tc.source='external' and tc.active=1)"; $where = ' WHERE c.entity IN ('.getEntity('order').')'; $dateprint = 'c.date_commande'; @@ -247,7 +253,7 @@ if ($type_element == 'fichinter') { // Customer : show products from invoices $tables_from = MAIN_DB_PREFIX.'facture_fourn_det d'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn as f ON d.fk_facture_fourn=f.rowid'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid'; - $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople='.$object->id; + $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=f.rowid AND ec.fk_socpeople = '.((int) $object->id); $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='invoice_supplier' and tc.source='external' and tc.active=1)"; $where = ' WHERE f.entity IN ('.getEntity($documentstatic->element).')'; $dateprint = 'f.datef'; @@ -272,7 +278,7 @@ if ($type_element == 'fichinter') { // Customer : show products from invoices $tables_from = MAIN_DB_PREFIX.'commande_fournisseurdet d'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur as c ON d.fk_commande=c.rowid'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid'; - $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople='.$object->id; + $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id); $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='order_supplier' and tc.source='external' and tc.active=1)"; $where = ' WHERE c.entity IN ('.getEntity($documentstatic->element).')'; $dateprint = 'c.date_valid'; @@ -286,7 +292,7 @@ if ($type_element == 'fichinter') { // Customer : show products from invoices $tables_from = MAIN_DB_PREFIX.'contratdet d'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'contrat as c ON d.fk_contrat=c.rowid'; $tables_from .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product p ON d.fk_product=p.rowid'; - $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople='.$object->id; + $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX.'element_contact ec ON ec.element_id=c.rowid AND ec.fk_socpeople = '.((int) $object->id); $tables_from .= ' INNER JOIN '.MAIN_DB_PREFIX."c_type_contact tc ON (ec.fk_c_type_contact=tc.rowid and tc.element='contrat' and tc.source='external' and tc.active=1)"; $where = ' WHERE c.entity IN ('.getEntity('contrat').')'; $dateprint = 'c.date_valid'; diff --git a/htdocs/contact/document.php b/htdocs/contact/document.php index 1870e7b8d9c..3fac8adea15 100644 --- a/htdocs/contact/document.php +++ b/htdocs/contact/document.php @@ -51,8 +51,8 @@ if (!empty($canvas)) { // Get parameters $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; @@ -130,7 +130,11 @@ if ($object->id) { $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref = '
'; + $morehtmlref = ''; + $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); + $morehtmlref .= ''; + + $morehtmlref .= '
'; if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { $objsoc = new Societe($db); $objsoc->fetch($object->socid); diff --git a/htdocs/contact/list.php b/htdocs/contact/list.php index ec886ce1d4e..66561730829 100644 --- a/htdocs/contact/list.php +++ b/htdocs/contact/list.php @@ -1169,7 +1169,7 @@ while ($i < min($num, $limit)) { } // EMail if (!empty($arrayfields['p.email']['checked'])) { - print ''.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 18, 0, 1).''; + print ''.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 18, 0, 1).''; if (!$i) { $totalarray['nbfield']++; } diff --git a/htdocs/contact/note.php b/htdocs/contact/note.php index 7c722d31211..a3bfb861b0f 100644 --- a/htdocs/contact/note.php +++ b/htdocs/contact/note.php @@ -96,7 +96,11 @@ if ($id > 0) { $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref = '
'; + $morehtmlref = ''; + $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); + $morehtmlref .= ''; + + $morehtmlref .= '
'; if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { $objsoc = new Societe($db); $objsoc->fetch($object->socid); diff --git a/htdocs/contact/perso.php b/htdocs/contact/perso.php index 285f71cae48..e90f8b46bd0 100644 --- a/htdocs/contact/perso.php +++ b/htdocs/contact/perso.php @@ -215,7 +215,11 @@ if ($action == 'edit') { $linkback = ''.$langs->trans("BackToList").''; - $morehtmlref = '
'; + $morehtmlref = ''; + $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard"), 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"'); + $morehtmlref .= ''; + + $morehtmlref .= '
'; if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) { $objsoc = new Societe($db); $objsoc->fetch($object->socid); diff --git a/htdocs/contact/project.php b/htdocs/contact/project.php new file mode 100644 index 00000000000..b05709f019a --- /dev/null +++ b/htdocs/contact/project.php @@ -0,0 +1,117 @@ + + * + * 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/contact/project.php + * \ingroup contact + * \brief Page of third party projects + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; + +$langs->loadLangs(array("contacts", "companies", "projects")); + +// Security check +$id = GETPOST('id', 'int'); +$result = restrictedArea($user, 'contact', $id, 'socpeople&societe'); + +// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context +$hookmanager->initHooks(array('projectcontact')); + +/* + * Actions + */ + +$parameters = array('id' => $id); +$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'); +} + +/* + * View + */ + +$form = new Form($db); + +if ($id) { + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/contact.lib.php'; + + $object = new Contact($db); + + $result = $object->fetch($id); + if (empty($object->thirdparty)) { + $object->fetch_thirdparty(); + } + $socid = $object->thirdparty->id; + $title = $langs->trans("Projects"); + if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) { + $title = $object->name." - ".$title; + } + llxHeader('', $title); + + if (! empty($conf->notification->enabled)) { + $langs->load("mails"); + } + $head = contact_prepare_head($object); + + print dol_get_fiche_head($head, 'project', $langs->trans("Contact"), -1, 'contact'); + + $linkback = ''.$langs->trans("BackToList").''; + + $morehtmlref = '
'; + if (empty($conf->global->SOCIETE_DISABLE_CONTACTS) && !empty($socid)) { + $object->thirdparty->fetch($socid); + // Thirdparty + $morehtmlref .= $langs->trans('ThirdParty').' : '; + if ($object->thirdparty->id > 0) { + $morehtmlref .= $object->thirdparty->getNomUrl(1, 'contact'); + } else { + $morehtmlref .= $langs->trans("ContactNotLinkedToCompany"); + } + } + $morehtmlref .= '
'; + + dol_banner_tab($object, 'id', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom', $morehtmlref); + + print '
'; + + print '
'; + print ''; + + // Civility + print ''; + + print '
'.$langs->trans("UserTitle").''; + print $object->getCivilityLabel(); + print '
'; + + print '
'; + + print dol_get_fiche_end(); + print '
'; + + // Projects list + $result = show_contacts_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?id='.$object->id, 1); +} + +// End of page +llxFooter(); +$db->close(); diff --git a/htdocs/contrat/agenda.php b/htdocs/contrat/agenda.php index eeeccddd671..d654ac38d9f 100644 --- a/htdocs/contrat/agenda.php +++ b/htdocs/contrat/agenda.php @@ -57,8 +57,8 @@ if ($user->socid) { $result = restrictedArea($user, 'contrat', $id, ''); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; @@ -245,6 +245,8 @@ if ($id > 0) { $newcardbutton = ''; if (!empty($conf->agenda->enabled)) { if (!empty($user->rights->agenda->myactions->create) || !empty($user->rights->agenda->allactions->create)) { + $backtopage = $_SERVER['PHP_SELF'].'?id='.$object->id; + $out = '&origin='.$object->element.'&originid='.$object->id.'&backtopage='.urlencode($backtopage); $newcardbutton .= dolGetButtonTitle($langs->trans('AddAction'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/comm/action/card.php?action=create'.$out); } } diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index c52b57e305f..3febcc868a0 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -40,6 +40,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/modules/contract/modules_contract.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; if (!empty($conf->propal->enabled)) { require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; } @@ -248,6 +249,10 @@ if (empty($reshook)) { if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'invoice' || $element == 'facture') { + $element = 'compta/facture'; + $subelement = 'facture'; + } $object->origin = $origin; $object->origin_id = $originid; @@ -1040,6 +1045,10 @@ if ($action == 'create') { if ($element == 'propal') { $element = 'comm/propal'; $subelement = 'propal'; } + if ($element == 'invoice' || $element == 'facture') { + $element = 'compta/facture'; + $subelement = 'facture'; + } dol_include_once('/'.$element.'/class/'.$subelement.'.class.php'); @@ -1537,11 +1546,11 @@ if ($action == 'create') { // Margin if (!empty($conf->margin->enabled) && !empty($conf->global->MARGIN_SHOW_ON_CONTRACT)) { - print ''.price($objp->pa_ht).''; + print ''.price($objp->pa_ht).''; } // Icon move, update et delete (statut contrat 0=brouillon,1=valide,2=ferme) - print ''; + print ''; if ($user->rights->contrat->creer && count($arrayothercontracts) && ($object->statut >= 0)) { print ''; print ''; diff --git a/htdocs/contrat/class/api_contracts.class.php b/htdocs/contrat/class/api_contracts.class.php index ea7886f022c..5e534f3e43c 100644 --- a/htdocs/contrat/class/api_contracts.class.php +++ b/htdocs/contrat/class/api_contracts.class.php @@ -147,8 +147,9 @@ class Contracts extends DolibarrApi } // Add sql filters if ($sqlfilters) { - if (!DolibarrApi::_checkFilters($sqlfilters)) { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + $errormessage = ''; + if (!DolibarrApi::_checkFilters($sqlfilters, $errormessage)) { + throw new RestException(503, 'Error when validating parameter sqlfilters -> '.$errormessage); } $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^\(\)]+)\)'; $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 27e8cc6bf95..b2c9543453b 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -387,7 +387,7 @@ class Contrat extends CommonObject if ($contratline->statut != ContratLigne::STATUS_OPEN) { $contratline->context = $this->context; - $result = $contratline->active_line($user, $date_start, -1, $comment); + $result = $contratline->active_line($user, $date_start, -1, $comment); // This call trigger LINECONTRACT_ACTIVATE if ($result < 0) { $error++; $this->error = $contratline->error; diff --git a/htdocs/contrat/document.php b/htdocs/contrat/document.php index b4cf2fc1fbf..953fd0002d2 100644 --- a/htdocs/contrat/document.php +++ b/htdocs/contrat/document.php @@ -55,8 +55,8 @@ $result = restrictedArea($user, 'contrat', $id); // Get parameters $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/contrat/list.php b/htdocs/contrat/list.php index ed980f9e86e..e6446e3585b 100644 --- a/htdocs/contrat/list.php +++ b/htdocs/contrat/list.php @@ -79,8 +79,8 @@ $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_en $optioncss = GETPOST('optioncss', 'alpha'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/contrat/services_list.php b/htdocs/contrat/services_list.php index 31621ba420a..39dfe336a31 100644 --- a/htdocs/contrat/services_list.php +++ b/htdocs/contrat/services_list.php @@ -39,8 +39,8 @@ $optioncss = GETPOST('optioncss', 'aZ09'); $massaction = GETPOST('massaction', 'alpha'); $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; -$sortfield = GETPOST("sortfield", 'alpha'); -$sortorder = GETPOST("sortorder", 'alpha'); +$sortfield = GETPOST('sortfield', 'aZ09comma'); +$sortorder = GETPOST('sortorder', 'aZ09comma'); $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int'); if (empty($page) || $page == -1) { $page = 0; diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 913c0cb768e..602897d34f9 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -81,7 +81,7 @@ if (!$error && $massaction == 'confirm_presend') { $listofobjectref = array(); $contactidtosend = array(); $attachedfilesThirdpartyObj = array(); - $oneemailperrecipient = (GETPOST('oneemailperrecipient') == 'on' ? 1 : 0); + $oneemailperrecipient = (GETPOST('oneemailperrecipient', 'int') ? 1 : 0); if (!$error) { $thirdparty = new Societe($db); @@ -657,8 +657,8 @@ if ($massaction == 'confirm_createbills') { // Create bills from orders. // If we want one invoice per order or if there is no first invoice yet for this thirdparty. $objecttmp->socid = $cmd->socid; $objecttmp->type = $objecttmp::TYPE_STANDARD; - $objecttmp->cond_reglement_id = ($cmd->cond_reglement_id || $cmd->thirdparty->cond_reglement_id); - $objecttmp->mode_reglement_id = ($cmd->mode_reglement_id || $cmd->thirdparty->mode_reglement_id); + $objecttmp->cond_reglement_id = !empty($cmd->cond_reglement_id) ? $cmd->cond_reglement_id : $cmd->thirdparty->cond_reglement_id; + $objecttmp->mode_reglement_id = !empty($cmd->mode_reglement_id) ? $cmd->mode_reglement_id : $cmd->thirdparty->mode_reglement_id; $objecttmp->fk_project = $cmd->fk_project; $objecttmp->multicurrency_code = $cmd->multicurrency_code; diff --git a/htdocs/core/actions_setmoduleoptions.inc.php b/htdocs/core/actions_setmoduleoptions.inc.php index 43ddd23f13d..fbf526fd58e 100644 --- a/htdocs/core/actions_setmoduleoptions.inc.php +++ b/htdocs/core/actions_setmoduleoptions.inc.php @@ -29,13 +29,13 @@ // $formSetup may be defined -if ($action == 'update' && !empty($formSetup) && is_object($formSetup)) { +if ($action == 'update' && !empty($formSetup) && is_object($formSetup) && !empty($user->admin)) { $formSetup->saveConfFromPost(); return; } -if ($action == 'update' && is_array($arrayofparameters)) { +if ($action == 'update' && is_array($arrayofparameters) && !empty($user->admin)) { $db->begin(); foreach ($arrayofparameters as $key => $val) { @@ -72,8 +72,37 @@ if ($action == 'update' && is_array($arrayofparameters)) { } } +if ($action == 'deletefile' && $modulepart == 'doctemplates' && !empty($user->admin)) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + $keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09'); + + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim(getDolGlobalString($keyforuploaddir)))); + foreach ($listofdir as $key => $tmpdir) { + $tmpdir = preg_replace('/DOL_DATA_ROOT\/*/', '', $tmpdir); // Clean string if we found a hardcoded DOL_DATA_ROOT + if (!$tmpdir) { + unset($listofdir[$key]); + continue; + } + $tmpdir = DOL_DATA_ROOT.'/'.$tmpdir; // Complete with DOL_DATA_ROOT. Only files into DOL_DATA_ROOT can be reach/set + if (!is_dir($tmpdir)) { + if (empty($nomessageinsetmoduleoptions)) { + setEventMessages($langs->trans("ErrorDirNotFound", $tmpdir), null, 'warnings'); + } + } else { + $upload_dir = $tmpdir; + break; // So we take the first directory found into setup $conf->global->$keyforuploaddir + } + } + + $filetodelete = $tmpdir.'/'.GETPOST('file'); + $result = dol_delete_file($filetodelete); + if ($result > 0) { + setEventMessages($langs->trans("FileWasRemoved", GETPOST('file')), null, 'mesgs'); + } +} + // Define constants for submodules that contains parameters (forms with param1, param2, ... and value1, value2, ...) -if ($action == 'setModuleOptions') { +if ($action == 'setModuleOptions' && !empty($user->admin)) { $db->begin(); // Process common param fields @@ -97,20 +126,22 @@ if ($action == 'setModuleOptions') { if (GETPOST('upload', 'alpha') && GETPOST('keyforuploaddir', 'aZ09')) { include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $keyforuploaddir = GETPOST('keyforuploaddir', 'aZ09'); - $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->$keyforuploaddir))); + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim(getDolGlobalString($keyforuploaddir)))); foreach ($listofdir as $key => $tmpdir) { $tmpdir = trim($tmpdir); - $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); + $tmpdir = preg_replace('/DOL_DATA_ROOT\/*/', '', $tmpdir); // Clean string if we found a hardcoded DOL_DATA_ROOT if (!$tmpdir) { unset($listofdir[$key]); continue; } + $tmpdir = DOL_DATA_ROOT.'/'.$tmpdir; // Complete with DOL_DATA_ROOT. Only files into DOL_DATA_ROOT can be reach/set if (!is_dir($tmpdir)) { if (empty($nomessageinsetmoduleoptions)) { setEventMessages($langs->trans("ErrorDirNotFound", $tmpdir), null, 'warnings'); } } else { $upload_dir = $tmpdir; + break; // So we take the first directory found into setup $conf->global->$keyforuploaddir } } if ($upload_dir) { diff --git a/htdocs/core/ajax/check_notifications.php b/htdocs/core/ajax/check_notifications.php index bbbc95a19c5..a5efb52e787 100644 --- a/htdocs/core/ajax/check_notifications.php +++ b/htdocs/core/ajax/check_notifications.php @@ -170,8 +170,10 @@ if (empty($_SESSION['auto_check_events_not_before']) || $time >= $_SESSION['auto $event['code'] = $obj->code; $event['label'] = $obj->label; $event['location'] = $obj->location; - $event['reminder_date_formated'] = dol_print_date($db->jdate($obj->dateremind), 'standard'); - $event['event_date_start_formated'] = dol_print_date($db->jdate($obj->datep), 'standard'); + $event['reminder_date_formated_tzserver'] = dol_print_date($db->jdate($obj->dateremind), 'standard', 'tzserver'); + $event['event_date_start_formated_tzserver'] = dol_print_date($db->jdate($obj->datep), 'standard', 'tzserver'); + $event['reminder_date_formated'] = dol_print_date($db->jdate($obj->dateremind), 'standard', 'tzuser'); + $event['event_date_start_formated'] = dol_print_date($db->jdate($obj->datep), 'standard', 'tzuser'); $eventfound[$obj->id_agenda] = $event; } diff --git a/htdocs/core/ajax/onlineSign.php b/htdocs/core/ajax/onlineSign.php index 488b5051ea5..5110918541f 100644 --- a/htdocs/core/ajax/onlineSign.php +++ b/htdocs/core/ajax/onlineSign.php @@ -51,11 +51,30 @@ if (!defined('NOBROWSERNOTIF')) { include '../../main.inc.php'; $action = GETPOST('action', 'aZ09'); + $signature = GETPOST('signaturebase64'); $ref = GETPOST('ref', 'aZ09'); $mode = GETPOST('mode', 'aZ09'); +$SECUREKEY = GETPOST("securekey"); // Secure key + $error = 0; $response = ""; + +$type = $mode; + +// Check securitykey +$securekeyseed = ''; +if ($type == 'proposal') { + $securekeyseed = $conf->global->PROPOSAL_ONLINE_SIGNATURE_SECURITY_TOKEN; +} + +if (!dol_verifyHash($securekeyseed.$type.$ref, $SECUREKEY, '0')) { + http_response_code(403); + print 'Bad value for securitykey. Value provided '.dol_escape_htmltag($SECUREKEY).' does not match expected value for ref='.dol_escape_htmltag($ref); + exit(-1); +} + + /* * Actions */ @@ -71,62 +90,91 @@ if ($action == "importSignature") { if (!empty($signature) && $signature[0] == "image/png;base64") { $signature = $signature[1]; $data = base64_decode($signature); - $upload_dir = DOL_DATA_ROOT."/".$mode."/".$ref."/"; - $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S"); - $filename = "signatures/".$date."_signature.png"; - if (!is_dir($upload_dir."signatures/")) { - if (!mkdir($upload_dir."signatures/")) { - $response ="error mkdir"; - $error++; + + if ($mode == "propale" || $mode == 'proposal') { + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; + $object = new Propal($db); + $object->fetch(0, $ref); + + $upload_dir = !empty($conf->propal->multidir_output[$object->entity])?$conf->propal->multidir_output[$object->entity]:$conf->propal->dir_output; + $upload_dir .= '/'.dol_sanitizeFileName($object->ref).'/'; + + $date = dol_print_date(dol_now(), "%Y%m%d%H%M%S"); + $filename = "signatures/".$date."_signature.png"; + if (!is_dir($upload_dir."signatures/")) { + if (!dol_mkdir($upload_dir."signatures/")) { + $response ="Error mkdir. Failed to create dir ".$upload_dir."signatures/"; + $error++; + } } - } - if (!$error) { - $return = file_put_contents($upload_dir.$filename, $data); - if ($return == false) { - $response = 'error file_put_content'; - } else { - if ($mode == "propale") { - require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; - require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; - $object = new Propal($db); - $object->fetch(0, $ref); - $pdf = pdf_getInstance(); - $pdf->Open(); - $pdf->AddPage(); - $pagecount = $pdf->setSourceFile($upload_dir.$ref.".pdf"); + if (!$error) { + $return = file_put_contents($upload_dir.$filename, $data); + if ($return == false) { + $error++; + $response = 'Error file_put_content: failed to create signature file.'; + } + } - $tppl = $pdf->importPage(1); - $pdf->useTemplate($tppl); - $pdf->Image($upload_dir.$filename, 129, 239.6, 60, 15); - $pdf->Close(); - $pdf->Output($upload_dir.$ref."_signed-".$date.".pdf", "F"); + if (!$error) { + $newpdffilename = $upload_dir.$ref."_signed-".$date.".pdf"; - $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; - $sql .= " SET fk_statut = ".((int) $object::STATUS_SIGNED).", note_private = '".$object->note_private."', date_signature='".$db->idate(dol_now())."'"; - $sql .= " WHERE rowid = ".((int) $object->id); + $pdf = pdf_getInstance(); + $pdf->Open(); + $pdf->AddPage(); + $pagecount = $pdf->setSourceFile($upload_dir.$ref.".pdf"); // original PDF - dol_syslog(__METHOD__, LOG_DEBUG); - $resql = $db->query($sql); - if (!$resql) { - $error++; - } else { - $num = $db->affected_rows($resql); - } + $tppl = $pdf->importPage(1); + $pdf->useTemplate($tppl); + $pdf->Image($upload_dir.$filename, 129, 239.6, 60, 15); // FIXME Position will be wrong with non A4 format. Use a value from width and height of page minus relative offset. + $pdf->Close(); + $pdf->Output($newpdffilename, "F"); - if (!$error) { - $db->commit(); - $response = "success"; - setEventMessage("PropalSigned"); - } else { - $db->rollback(); - $response = "error sql"; - } + $db->begin(); + + // Index the new file and update the last_main_doc property of object. + $object->indexFile($newpdffilename, 1); + + $online_sign_ip = getUserRemoteIP(); + $online_sign_name = ''; // TODO Ask name on form to sign + + $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; + $sql .= " SET fk_statut = ".((int) $object::STATUS_SIGNED).", note_private = '".$db->escape($object->note_private)."',"; + $sql .= " date_signature = '".$db->idate(dol_now())."',"; + $sql .= " online_sign_ip = '".$db->escape($online_sign_ip)."'"; + if ($online_sign_name) { + $sql .= ", online_sign_name = '".$db->escape($online_sign_name)."'"; + } + $sql .= " WHERE rowid = ".((int) $object->id); + + dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $db->query($sql); + if (!$resql) { + $error++; + } else { + $num = $db->affected_rows($resql); + } + + if (!$error) { + $db->commit(); + $response = "success"; + setEventMessages("PropalSigned", null, 'warnings'); + } else { + $db->rollback(); + $error++; + $response = "error sql"; } } } } else { + $error++; $response = 'error signature_not_found'; } } + +if ($error) { + http_response_code(501); +} + echo $response; diff --git a/htdocs/core/ajax/row.php b/htdocs/core/ajax/row.php index 0b1106ca20a..9853faa8585 100644 --- a/htdocs/core/ajax/row.php +++ b/htdocs/core/ajax/row.php @@ -95,6 +95,8 @@ if (GETPOST('roworder', 'alpha', 3) && GETPOST('table_element_line', 'aZ09', 3) $perm = 1; } elseif ($table_element_line == 'facture_fourn_det' && $user->rights->fournisseur->facture->creer) { $perm = 1; + } elseif ($table_element_line == 'facture_fourn_det_rec' && $user->rights->fournisseur->facture->creer) { + $perm = 1; } elseif ($table_element_line == 'ecm_files' && $fk_element == 'fk_product' && (!empty($user->rights->produit->creer) || !empty($user->rights->service->creer))) { $perm = 1; } elseif ($table_element_line == 'ecm_files' && $fk_element == 'fk_ticket' && !empty($user->rights->ticket->write)) { diff --git a/htdocs/core/ajax/selectsearchbox.php b/htdocs/core/ajax/selectsearchbox.php index 1814b476d06..ae4f7c41515 100644 --- a/htdocs/core/ajax/selectsearchbox.php +++ b/htdocs/core/ajax/selectsearchbox.php @@ -65,58 +65,58 @@ $arrayresult = array(); // Define $searchform if (!empty($conf->adherent->enabled) && empty($conf->global->MAIN_SEARCHFORM_ADHERENT_DISABLED) && $user->rights->adherent->lire) { - $arrayresult['searchintomember'] = array('position'=>8, 'shortcut'=>'M', 'img'=>'object_member', 'label'=>$langs->trans("SearchIntoMembers", $search_boxvalue), 'text'=>img_picto('', 'object_member').' '.$langs->trans("SearchIntoMembers", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/adherents/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintomember'] = array('position'=>8, 'shortcut'=>'M', 'img'=>'object_member', 'label'=>$langs->trans("SearchIntoMembers", $search_boxvalue), 'text'=>img_picto('', 'object_member', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoMembers", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/adherents/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (((!empty($conf->societe->enabled) && (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) || empty($conf->global->SOCIETE_DISABLE_CUSTOMERS))) || ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled) || !empty($conf->supplier_invoice->enabled))) && empty($conf->global->MAIN_SEARCHFORM_SOCIETE_DISABLED) && $user->rights->societe->lire) { - $arrayresult['searchintothirdparty'] = array('position'=>10, 'shortcut'=>'T', 'img'=>'object_company', 'label'=>$langs->trans("SearchIntoThirdparties", $search_boxvalue), 'text'=>img_picto('', 'object_company').' '.$langs->trans("SearchIntoThirdparties", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/societe/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintothirdparty'] = array('position'=>10, 'shortcut'=>'T', 'img'=>'object_company', 'label'=>$langs->trans("SearchIntoThirdparties", $search_boxvalue), 'text'=>img_picto('', 'object_company', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoThirdparties", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/societe/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->societe->enabled) && empty($conf->global->MAIN_SEARCHFORM_CONTACT_DISABLED) && $user->rights->societe->lire) { - $arrayresult['searchintocontact'] = array('position'=>15, 'shortcut'=>'A', 'img'=>'object_contact', 'label'=>$langs->trans("SearchIntoContacts", $search_boxvalue), 'text'=>img_picto('', 'object_contact').' '.$langs->trans("SearchIntoContacts", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/contact/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintocontact'] = array('position'=>15, 'shortcut'=>'A', 'img'=>'object_contact', 'label'=>$langs->trans("SearchIntoContacts", $search_boxvalue), 'text'=>img_picto('', 'object_contact', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoContacts", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/contact/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (((!empty($conf->product->enabled) && $user->rights->produit->lire) || (!empty($conf->service->enabled) && $user->rights->service->lire)) && empty($conf->global->MAIN_SEARCHFORM_PRODUITSERVICE_DISABLED)) { - $arrayresult['searchintoproduct'] = array('position'=>30, 'shortcut'=>'P', 'img'=>'object_product', 'label'=>$langs->trans("SearchIntoProductsOrServices", $search_boxvalue), 'text'=>img_picto('', 'object_product').' '.$langs->trans("SearchIntoProductsOrServices", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/product/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintoproduct'] = array('position'=>30, 'shortcut'=>'P', 'img'=>'object_product', 'label'=>$langs->trans("SearchIntoProductsOrServices", $search_boxvalue), 'text'=>img_picto('', 'object_product', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoProductsOrServices", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/product/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); // search on lot/serial numbers if ( ! empty($conf->productbatch->enabled) ) { - $arrayresult['searchintobatch'] = array('position'=>32, 'shortcut'=>'B', 'img'=>'object_lot', 'label'=>$langs->trans("SearchIntoBatch", $search_boxvalue), 'text'=>img_picto('', 'object_lot').' '.$langs->trans("SearchIntoBatch", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/product/stock/productlot_list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintobatch'] = array('position'=>32, 'shortcut'=>'B', 'img'=>'object_lot', 'label'=>$langs->trans("SearchIntoBatch", $search_boxvalue), 'text'=>img_picto('', 'object_lot', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoBatch", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/product/stock/productlot_list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } } if (!empty($conf->mrp->enabled) && $user->rights->mrp->read && empty($conf->global->MAIN_SEARCHFORM_MRP_DISABLED)) { - $arrayresult['searchintomo'] = array('position'=>35, 'shortcut'=>'', 'img'=>'object_mrp', 'label'=>$langs->trans("SearchIntoMO", $search_boxvalue), 'text'=>img_picto('', 'object_mrp').' '.$langs->trans("SearchIntoMO", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/mrp/mo_list.php'.($search_boxvalue ? '?search_all='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintomo'] = array('position'=>35, 'shortcut'=>'', 'img'=>'object_mrp', 'label'=>$langs->trans("SearchIntoMO", $search_boxvalue), 'text'=>img_picto('', 'object_mrp', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoMO", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/mrp/mo_list.php'.($search_boxvalue ? '?search_all='.urlencode($search_boxvalue) : '')); } if (!empty($conf->projet->enabled) && empty($conf->global->MAIN_SEARCHFORM_PROJECT_DISABLED) && $user->rights->projet->lire) { - $arrayresult['searchintoprojects'] = array('position'=>40, 'shortcut'=>'Q', 'img'=>'object_project', 'label'=>$langs->trans("SearchIntoProjects", $search_boxvalue), 'text'=>img_picto('', 'object_project').' '.$langs->trans("SearchIntoProjects", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/projet/list.php'.($search_boxvalue ? '?search_all='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintoprojects'] = array('position'=>40, 'shortcut'=>'Q', 'img'=>'object_project', 'label'=>$langs->trans("SearchIntoProjects", $search_boxvalue), 'text'=>img_picto('', 'object_project', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoProjects", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/projet/list.php'.($search_boxvalue ? '?search_all='.urlencode($search_boxvalue) : '')); } if (!empty($conf->projet->enabled) && empty($conf->global->MAIN_SEARCHFORM_TASK_DISABLED) && $user->rights->projet->lire) { - $arrayresult['searchintotasks'] = array('position'=>45, 'img'=>'object_projecttask', 'label'=>$langs->trans("SearchIntoTasks", $search_boxvalue), 'text'=>img_picto('', 'object_projecttask').' '.$langs->trans("SearchIntoTasks", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/projet/tasks/list.php'.($search_boxvalue ? '?search_all='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintotasks'] = array('position'=>45, 'img'=>'object_projecttask', 'label'=>$langs->trans("SearchIntoTasks", $search_boxvalue), 'text'=>img_picto('', 'object_projecttask', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoTasks", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/projet/tasks/list.php'.($search_boxvalue ? '?search_all='.urlencode($search_boxvalue) : '')); } if (!empty($conf->propal->enabled) && empty($conf->global->MAIN_SEARCHFORM_CUSTOMER_PROPAL_DISABLED) && $user->rights->propal->lire) { - $arrayresult['searchintopropal'] = array('position'=>60, 'img'=>'object_propal', 'label'=>$langs->trans("SearchIntoCustomerProposals", $search_boxvalue), 'text'=>img_picto('', 'object_propal').' '.$langs->trans("SearchIntoCustomerProposals", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/comm/propal/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintopropal'] = array('position'=>60, 'img'=>'object_propal', 'label'=>$langs->trans("SearchIntoCustomerProposals", $search_boxvalue), 'text'=>img_picto('', 'object_propal', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoCustomerProposals", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/comm/propal/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->commande->enabled) && empty($conf->global->MAIN_SEARCHFORM_CUSTOMER_ORDER_DISABLED) && $user->rights->commande->lire) { - $arrayresult['searchintoorder'] = array('position'=>70, 'img'=>'object_order', 'label'=>$langs->trans("SearchIntoCustomerOrders", $search_boxvalue), 'text'=>img_picto('', 'object_order').' '.$langs->trans("SearchIntoCustomerOrders", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/commande/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintoorder'] = array('position'=>70, 'img'=>'object_order', 'label'=>$langs->trans("SearchIntoCustomerOrders", $search_boxvalue), 'text'=>img_picto('', 'object_order', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoCustomerOrders", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/commande/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->expedition->enabled) && empty($conf->global->MAIN_SEARCHFORM_CUSTOMER_SHIPMENT_DISABLED) && $user->rights->expedition->lire) { - $arrayresult['searchintoshipment'] = array('position'=>80, 'img'=>'object_shipment', 'label'=>$langs->trans("SearchIntoCustomerShipments", $search_boxvalue), 'text'=>img_picto('', 'object_shipment').' '.$langs->trans("SearchIntoCustomerShipments", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/expedition/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintoshipment'] = array('position'=>80, 'img'=>'object_shipment', 'label'=>$langs->trans("SearchIntoCustomerShipments", $search_boxvalue), 'text'=>img_picto('', 'object_shipment', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoCustomerShipments", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/expedition/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->facture->enabled) && empty($conf->global->MAIN_SEARCHFORM_CUSTOMER_INVOICE_DISABLED) && $user->rights->facture->lire) { - $arrayresult['searchintoinvoice'] = array('position'=>90, 'img'=>'object_bill', 'label'=>$langs->trans("SearchIntoCustomerInvoices", $search_boxvalue), 'text'=>img_picto('', 'object_bill').' '.$langs->trans("SearchIntoCustomerInvoices", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/compta/facture/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintoinvoice'] = array('position'=>90, 'img'=>'object_bill', 'label'=>$langs->trans("SearchIntoCustomerInvoices", $search_boxvalue), 'text'=>img_picto('', 'object_bill', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoCustomerInvoices", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/compta/facture/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->supplier_proposal->enabled) && empty($conf->global->MAIN_SEARCHFORM_SUPPLIER_PROPAL_DISABLED) && $user->rights->supplier_proposal->lire) { - $arrayresult['searchintosupplierpropal'] = array('position'=>100, 'img'=>'object_supplier_proposal', 'label'=>$langs->trans("SearchIntoSupplierProposals", $search_boxvalue), 'text'=>img_picto('', 'object_supplier_proposal').' '.$langs->trans("SearchIntoSupplierProposals", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/supplier_proposal/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintosupplierpropal'] = array('position'=>100, 'img'=>'object_supplier_proposal', 'label'=>$langs->trans("SearchIntoSupplierProposals", $search_boxvalue), 'text'=>img_picto('', 'object_supplier_proposal', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoSupplierProposals", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/supplier_proposal/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->commande->lire) || (!empty($conf->supplier_order->enabled) && $user->rights->supplier_order->lire)) && empty($conf->global->MAIN_SEARCHFORM_SUPPLIER_ORDER_DISABLED)) { - $arrayresult['searchintosupplierorder'] = array('position'=>110, 'img'=>'object_supplier_order', 'label'=>$langs->trans("SearchIntoSupplierOrders", $search_boxvalue), 'text'=>img_picto('', 'object_supplier_order').' '.$langs->trans("SearchIntoSupplierOrders", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/fourn/commande/list.php'.($search_boxvalue ? '?search_all='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintosupplierorder'] = array('position'=>110, 'img'=>'object_supplier_order', 'label'=>$langs->trans("SearchIntoSupplierOrders", $search_boxvalue), 'text'=>img_picto('', 'object_supplier_order', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoSupplierOrders", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/fourn/commande/list.php'.($search_boxvalue ? '?search_all='.urlencode($search_boxvalue) : '')); } if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->rights->fournisseur->facture->lire) || (!empty($conf->supplier_invoice->enabled) && $user->rights->supplier_invoice->lire)) && empty($conf->global->MAIN_SEARCHFORM_SUPPLIER_INVOICE_DISABLED)) { - $arrayresult['searchintosupplierinvoice'] = array('position'=>120, 'img'=>'object_supplier_invoice', 'label'=>$langs->trans("SearchIntoSupplierInvoices", $search_boxvalue), 'text'=>img_picto('', 'object_supplier_invoice').' '.$langs->trans("SearchIntoSupplierInvoices", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/fourn/facture/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintosupplierinvoice'] = array('position'=>120, 'img'=>'object_supplier_invoice', 'label'=>$langs->trans("SearchIntoSupplierInvoices", $search_boxvalue), 'text'=>img_picto('', 'object_supplier_invoice', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoSupplierInvoices", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/fourn/facture/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } // Customer payments @@ -125,7 +125,7 @@ if (!empty($conf->facture->enabled) && empty($conf->global->MAIN_SEARCHFORM_CUST 'position'=>170, 'img'=>'object_payment', 'label'=>$langs->trans("SearchIntoCustomerPayments", $search_boxvalue), - 'text'=>img_picto('', 'object_payment').' '.$langs->trans("SearchIntoCustomerPayments", $search_boxvalue), + 'text'=>img_picto('', 'object_payment', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoCustomerPayments", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/compta/paiement/list.php?leftmenu=customers_bills_payment'.($search_boxvalue ? '&sall='.urlencode($search_boxvalue) : '')); } @@ -135,7 +135,7 @@ if (((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_S 'position'=>175, 'img'=>'object_payment', 'label'=>$langs->trans("SearchIntoVendorPayments", $search_boxvalue), - 'text'=>img_picto('', 'object_payment').' '.$langs->trans("SearchIntoVendorPayments", $search_boxvalue), + 'text'=>img_picto('', 'object_payment', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoVendorPayments", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/fourn/paiement/list.php?leftmenu=suppliers_bills_payment'.($search_boxvalue ? '&sall='.urlencode($search_boxvalue) : '')); } @@ -145,29 +145,29 @@ if (!empty($conf->banque->enabled) && empty($conf->global->MAIN_SEARCHFORM_MISC_ 'position'=>180, 'img'=>'object_payment', 'label'=>$langs->trans("SearchIntoMiscPayments", $search_boxvalue), - 'text'=>img_picto('', 'object_payment').' '.$langs->trans("SearchIntoMiscPayments", $search_boxvalue), + 'text'=>img_picto('', 'object_payment', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoMiscPayments", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/compta/bank/various_payment/list.php?leftmenu=tax_various'.($search_boxvalue ? '&sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->contrat->enabled) && empty($conf->global->MAIN_SEARCHFORM_CONTRACT_DISABLED) && $user->rights->contrat->lire) { - $arrayresult['searchintocontract'] = array('position'=>130, 'img'=>'object_contract', 'label'=>$langs->trans("SearchIntoContracts", $search_boxvalue), 'text'=>img_picto('', 'object_contract').' '.$langs->trans("SearchIntoContracts", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/contrat/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintocontract'] = array('position'=>130, 'img'=>'object_contract', 'label'=>$langs->trans("SearchIntoContracts", $search_boxvalue), 'text'=>img_picto('', 'object_contract', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoContracts", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/contrat/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->ficheinter->enabled) && empty($conf->global->MAIN_SEARCHFORM_FICHINTER_DISABLED) && $user->rights->ficheinter->lire) { - $arrayresult['searchintointervention'] = array('position'=>140, 'img'=>'object_intervention', 'label'=>$langs->trans("SearchIntoInterventions", $search_boxvalue), 'text'=>img_picto('', 'object_intervention').' '.$langs->trans("SearchIntoInterventions", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/fichinter/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintointervention'] = array('position'=>140, 'img'=>'object_intervention', 'label'=>$langs->trans("SearchIntoInterventions", $search_boxvalue), 'text'=>img_picto('', 'object_intervention', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoInterventions", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/fichinter/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->ticket->enabled) && empty($conf->global->MAIN_SEARCHFORM_TICKET_DISABLED) && $user->rights->ticket->read) { - $arrayresult['searchintotickets'] = array('position'=>145, 'img'=>'object_ticket', 'label'=>$langs->trans("SearchIntoTickets", $search_boxvalue), 'text'=>img_picto('', 'object_ticket').' '.$langs->trans("SearchIntoTickets", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/ticket/list.php?mainmenu=ticket'.($search_boxvalue ? '&sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintotickets'] = array('position'=>145, 'img'=>'object_ticket', 'label'=>$langs->trans("SearchIntoTickets", $search_boxvalue), 'text'=>img_picto('', 'object_ticket', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoTickets", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/ticket/list.php?mainmenu=ticket'.($search_boxvalue ? '&sall='.urlencode($search_boxvalue) : '')); } // HR if (!empty($conf->user->enabled) && empty($conf->global->MAIN_SEARCHFORM_USER_DISABLED) && $user->rights->user->user->lire) { - $arrayresult['searchintouser'] = array('position'=>200, 'shortcut'=>'U', 'img'=>'object_user', 'label'=>$langs->trans("SearchIntoUsers", $search_boxvalue), 'text'=>img_picto('', 'object_user').' '.$langs->trans("SearchIntoUsers", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/user/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintouser'] = array('position'=>200, 'shortcut'=>'U', 'img'=>'object_user', 'label'=>$langs->trans("SearchIntoUsers", $search_boxvalue), 'text'=>img_picto('', 'object_user', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoUsers", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/user/list.php'.($search_boxvalue ? '?sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->expensereport->enabled) && empty($conf->global->MAIN_SEARCHFORM_EXPENSEREPORT_DISABLED) && $user->rights->expensereport->lire) { - $arrayresult['searchintoexpensereport'] = array('position'=>210, 'img'=>'object_trip', 'label'=>$langs->trans("SearchIntoExpenseReports", $search_boxvalue), 'text'=>img_picto('', 'object_trip').' '.$langs->trans("SearchIntoExpenseReports", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm'.($search_boxvalue ? '&sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintoexpensereport'] = array('position'=>210, 'img'=>'object_trip', 'label'=>$langs->trans("SearchIntoExpenseReports", $search_boxvalue), 'text'=>img_picto('', 'object_trip', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoExpenseReports", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm'.($search_boxvalue ? '&sall='.urlencode($search_boxvalue) : '')); } if (!empty($conf->holiday->enabled) && empty($conf->global->MAIN_SEARCHFORM_HOLIDAY_DISABLED) && $user->rights->holiday->read) { - $arrayresult['searchintoleaves'] = array('position'=>220, 'img'=>'object_holiday', 'label'=>$langs->trans("SearchIntoLeaves", $search_boxvalue), 'text'=>img_picto('', 'object_holiday').' '.$langs->trans("SearchIntoLeaves", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/holiday/list.php?mainmenu=hrm'.($search_boxvalue ? '&sall='.urlencode($search_boxvalue) : '')); + $arrayresult['searchintoleaves'] = array('position'=>220, 'img'=>'object_holiday', 'label'=>$langs->trans("SearchIntoLeaves", $search_boxvalue), 'text'=>img_picto('', 'object_holiday', 'class="pictofixedwidth"').' '.$langs->trans("SearchIntoLeaves", $search_boxvalue), 'url'=>DOL_URL_ROOT.'/holiday/list.php?mainmenu=hrm'.($search_boxvalue ? '&sall='.urlencode($search_boxvalue) : '')); } // Execute hook addSearchEntry diff --git a/htdocs/core/bookmarks_page.php b/htdocs/core/bookmarks_page.php index 9c3b5abb266..dde8df5f82e 100644 --- a/htdocs/core/bookmarks_page.php +++ b/htdocs/core/bookmarks_page.php @@ -111,12 +111,20 @@ if (empty($conf->bookmark->enabled)) { if ($i == 0) { $bookmarkList .= '
'.$langs->trans("NoBookmarks").''; $bookmarkList .= '

'; - - $newcardbutton = ''; - $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bookmarks/card.php?action=create&backtopage='.urlencode(DOL_URL_ROOT.'/bookmarks/list.php'), '', !empty($user->rights->bookmark->creer)); - - $bookmarkList .= '
'.$newcardbutton.'
'; } + + $newcardbutton = ''; + $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bookmarks/card.php?action=create&backtopage='.urlencode(DOL_URL_ROOT.'/bookmarks/list.php'), '', !empty($user->rights->bookmark->creer)); + + // Url to list bookmark + $bookmarkList .= '
'; + $bookmarkList .= '
'; + $bookmarkList .= img_picto('', 'bookmark', 'class="paddingright"').$langs->trans('Bookmarks').''; + $bookmarkList .= '
'; + $bookmarkList .= '
'; + + $bookmarkList .= '
'.$newcardbutton.'
'; + $bookmarkList .= '
'; diff --git a/htdocs/core/boxes/box_accountancy_last_manual_entries.php b/htdocs/core/boxes/box_accountancy_last_manual_entries.php index b1e4a637046..96abd8699f3 100644 --- a/htdocs/core/boxes/box_accountancy_last_manual_entries.php +++ b/htdocs/core/boxes/box_accountancy_last_manual_entries.php @@ -134,7 +134,7 @@ class box_accountancy_last_manual_entries extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="nowraponall right"', + 'td' => 'class="nowraponall right amount"', 'text' => price($amount, 0, $langs, 0, -1, -1, $conf->currency), ); diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index 487c2170a4a..371a7a0dbed 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -174,7 +174,7 @@ class box_activity extends ModeleBoxes $totalnb += $data[$j]->nb; $this->info_box_contents[$line][3] = array( - 'td' => 'class="nowraponall right"', + 'td' => 'class="nowraponall right amount"', 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency), ); $this->info_box_contents[$line][4] = array( @@ -262,7 +262,7 @@ class box_activity extends ModeleBoxes $totalnb += $data[$j]->nb; $this->info_box_contents[$line][3] = array( - 'td' => 'class="nowraponall right"', + 'td' => 'class="nowraponall right amount"', 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency), ); $this->info_box_contents[$line][4] = array( @@ -350,7 +350,7 @@ class box_activity extends ModeleBoxes ); $this->info_box_contents[$line][3] = array( - 'td' => 'class="nowraponall right"', + 'td' => 'class="nowraponall right amount"', 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency) ); @@ -433,7 +433,7 @@ class box_activity extends ModeleBoxes ); $totalnb += $data[$j]->nb; $this->info_box_contents[$line][3] = array( - 'td' => 'class="nowraponall right"', + 'td' => 'class="nowraponall right amount"', 'text' => price($data[$j]->Mnttot, 1, $langs, 0, 0, -1, $conf->currency), ); $this->info_box_contents[$line][4] = array( diff --git a/htdocs/core/boxes/box_commandes.php b/htdocs/core/boxes/box_commandes.php index abf9baf06f3..ae939afe25c 100644 --- a/htdocs/core/boxes/box_commandes.php +++ b/htdocs/core/boxes/box_commandes.php @@ -163,7 +163,7 @@ class box_commandes extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="nowraponall right"', + 'td' => 'class="nowraponall right amount"', 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency), ); diff --git a/htdocs/core/boxes/box_comptes.php b/htdocs/core/boxes/box_comptes.php index f42b7a2ef7c..5570051a065 100644 --- a/htdocs/core/boxes/box_comptes.php +++ b/htdocs/core/boxes/box_comptes.php @@ -141,8 +141,11 @@ class box_comptes extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="right nowraponall"', - 'text' => price($solde, 0, $langs, 1, -1, -1, $objp->currency_code) + 'td' => 'class="nowraponall right amount"', + 'text' => '' + .price($solde, 0, $langs, 1, -1, -1, $objp->currency_code) + .'', + 'asis' => 1, ); $line++; @@ -161,7 +164,7 @@ class box_comptes extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="liste_total right nowraponall"', + 'td' => 'class="liste_total nowraponall right amount"', 'text' => price($solde, 0, $langs, 0, -1, -1, $key) ); $line++; diff --git a/htdocs/core/boxes/box_dolibarr_state_board.php b/htdocs/core/boxes/box_dolibarr_state_board.php index 21bf58b859f..0381b493448 100644 --- a/htdocs/core/boxes/box_dolibarr_state_board.php +++ b/htdocs/core/boxes/box_dolibarr_state_board.php @@ -105,7 +105,8 @@ class box_dolibarr_state_board extends ModeleBoxes 'supplier_invoices', 'contracts', 'interventions', - 'ticket' + 'ticket', + 'dolresource' ); $conditions = array( 'users' => $user->rights->user->user->lire, @@ -132,7 +133,8 @@ class box_dolibarr_state_board extends ModeleBoxes 'projects' => !empty($conf->projet->enabled) && $user->rights->projet->lire, 'expensereports' => !empty($conf->expensereport->enabled) && $user->rights->expensereport->lire, 'holidays' => !empty($conf->holiday->enabled) && $user->rights->holiday->read, - 'ticket' => !empty($conf->ticket->enabled) && $user->rights->ticket->read + 'ticket' => !empty($conf->ticket->enabled) && $user->rights->ticket->read, + 'dolresource' => !empty($conf->resource->enabled) && $user->rights->resource->read ); $classes = array( 'users' => 'User', @@ -156,6 +158,7 @@ class box_dolibarr_state_board extends ModeleBoxes 'expensereports' => 'ExpenseReport', 'holidays' => 'Holiday', 'ticket' => 'Ticket', + 'dolresource' => 'Dolresource' ); $includes = array( 'users' => DOL_DOCUMENT_ROOT . "/user/class/user.class.php", @@ -178,7 +181,8 @@ class box_dolibarr_state_board extends ModeleBoxes 'projects' => DOL_DOCUMENT_ROOT . "/projet/class/project.class.php", 'expensereports' => DOL_DOCUMENT_ROOT . "/expensereport/class/expensereport.class.php", 'holidays' => DOL_DOCUMENT_ROOT . "/holiday/class/holiday.class.php", - 'ticket' => DOL_DOCUMENT_ROOT . "/ticket/class/ticket.class.php" + 'ticket' => DOL_DOCUMENT_ROOT . "/ticket/class/ticket.class.php", + 'dolresource' => DOL_DOCUMENT_ROOT . "/resource/class/dolresource.class.php" ); $links = array( 'users' => DOL_URL_ROOT . '/user/list.php', @@ -201,7 +205,8 @@ class box_dolibarr_state_board extends ModeleBoxes 'projects' => DOL_URL_ROOT . '/projet/list.php?mainmenu=project', 'expensereports' => DOL_URL_ROOT . '/expensereport/list.php?mainmenu=hrm&leftmenu=expensereport', 'holidays' => DOL_URL_ROOT . '/holiday/list.php?mainmenu=hrm&leftmenu=holiday', - 'ticket' => DOL_URL_ROOT . '/ticket/list.php?leftmenu=ticket' + 'ticket' => DOL_URL_ROOT . '/ticket/list.php?leftmenu=ticket', + 'dolresource' => DOL_URL_ROOT . '/resource/list.php?mainmenu=tools', ); $titres = array( 'users' => "Users", @@ -225,6 +230,7 @@ class box_dolibarr_state_board extends ModeleBoxes 'expensereports' => "ExpenseReports", 'holidays' => "Holidays", 'ticket' => "Ticket", + 'dolresource' => "Resources", ); $langfile = array( 'customers' => "companies", diff --git a/htdocs/core/boxes/box_factures_fourn.php b/htdocs/core/boxes/box_factures_fourn.php index ae905d5d468..42a945b9289 100644 --- a/htdocs/core/boxes/box_factures_fourn.php +++ b/htdocs/core/boxes/box_factures_fourn.php @@ -183,7 +183,7 @@ class box_factures_fourn extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="right nowraponall"', + 'td' => 'class="nowraponall right amount"', 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency), ); diff --git a/htdocs/core/boxes/box_factures_fourn_imp.php b/htdocs/core/boxes/box_factures_fourn_imp.php index cfef8801414..a421706e855 100644 --- a/htdocs/core/boxes/box_factures_fourn_imp.php +++ b/htdocs/core/boxes/box_factures_fourn_imp.php @@ -170,7 +170,7 @@ class box_factures_fourn_imp extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="nowraponall right"', + 'td' => 'class="nowraponall right amount"', 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency), ); diff --git a/htdocs/core/boxes/box_funnel_of_prospection.php b/htdocs/core/boxes/box_funnel_of_prospection.php index 89ed2215732..cdaa9298f63 100644 --- a/htdocs/core/boxes/box_funnel_of_prospection.php +++ b/htdocs/core/boxes/box_funnel_of_prospection.php @@ -219,7 +219,7 @@ class box_funnel_of_prospection extends ModeleBoxes if (!$conf->use_javascript_ajax) { $stringtoprint .= ''; $stringtoprint .= ''.$labelStatus.''; - $stringtoprint .= ''.price((isset($valsamount[$status]) ? (float) $valsamount[$status] : 0), 0, '', 1, -1, -1, $conf->currency).''; + $stringtoprint .= ''.price((isset($valsamount[$status]) ? (float) $valsamount[$status] : 0), 0, '', 1, -1, -1, $conf->currency).''; $stringtoprint .= "\n"; } } @@ -277,7 +277,7 @@ class box_funnel_of_prospection extends ModeleBoxes ); $this->info_box_contents[$line][] = array( 'tr' => 'class="oddeven"', - 'td' => 'class="right "', + 'td' => 'class="nowraponall right amount"', 'maxlength' => 500, 'text' => price($totalamount, 0, '', 1, -1, -1, $conf->currency) ); @@ -290,7 +290,7 @@ class box_funnel_of_prospection extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="right "', + 'td' => 'class="nowraponall right amount"', 'maxlength' => 500, 'text' => price(price2num($ponderated_opp_amount, 'MT'), 0, '', 1, -1, -1, $conf->currency) ); diff --git a/htdocs/core/boxes/box_members_last_subscriptions.php b/htdocs/core/boxes/box_members_last_subscriptions.php index 949edd567f3..930b4d3a874 100644 --- a/htdocs/core/boxes/box_members_last_subscriptions.php +++ b/htdocs/core/boxes/box_members_last_subscriptions.php @@ -152,8 +152,8 @@ class box_members_last_subscriptions extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="right" width="18"', - 'text' => ''.price($obj->subscription).'', + 'td' => 'class="nowraponall right amount" width="18"', + 'text' => price($obj->subscription), ); $this->info_box_contents[$line][] = array( diff --git a/htdocs/core/boxes/box_members_subscriptions_by_year.php b/htdocs/core/boxes/box_members_subscriptions_by_year.php index 73c71521603..e7bf916d236 100644 --- a/htdocs/core/boxes/box_members_subscriptions_by_year.php +++ b/htdocs/core/boxes/box_members_subscriptions_by_year.php @@ -179,12 +179,12 @@ class box_members_subscriptions_by_year extends ModeleBoxes 'text' => $Number[$key], ); $this->info_box_contents[$line][] = array( - 'td' => 'class="right"', - 'text' => ''.price($value).'', + 'td' => 'class="nowraponall right amount"', + 'text' => price($value), ); $this->info_box_contents[$line][] = array( - 'td' => 'class="right"', - 'text' => ''.price(price2num($value / $Number[$key], 'MT')).'', + 'td' => 'class="nowraponall right amount"', + 'text' => price(price2num($value / $Number[$key], 'MT')), ); $line++; } @@ -204,12 +204,12 @@ class box_members_subscriptions_by_year extends ModeleBoxes 'text' => $numb, ); $this->info_box_contents[$line][] = array( - 'td' => 'class="liste_total right"', - 'text' => ''.price($tot).'', + 'td' => 'class="liste_total nowraponall right amount"', + 'text' => price($tot), ); $this->info_box_contents[$line][] = array( - 'td' => 'class="liste_total right"', - 'text' => ''.price(price2num($numb > 0 ? ($tot / $numb) : 0, 'MT')).'', + 'td' => 'class="liste_total nowraponall right amount"', + 'text' => price(price2num($numb > 0 ? ($tot / $numb) : 0, 'MT')), ); } } else { diff --git a/htdocs/core/boxes/box_produits.php b/htdocs/core/boxes/box_produits.php index d039881445e..9a0c76503d0 100644 --- a/htdocs/core/boxes/box_produits.php +++ b/htdocs/core/boxes/box_produits.php @@ -180,7 +180,7 @@ class box_produits extends ModeleBoxes } } $this->info_box_contents[$line][] = array( - 'td' => 'class="right"', + 'td' => 'class="nowraponall right amount"', 'text' => $price, ); diff --git a/htdocs/core/boxes/box_produits_alerte_stock.php b/htdocs/core/boxes/box_produits_alerte_stock.php index 5e7ec72d0e1..e074cb76198 100644 --- a/htdocs/core/boxes/box_produits_alerte_stock.php +++ b/htdocs/core/boxes/box_produits_alerte_stock.php @@ -94,12 +94,12 @@ class box_produits_alerte_stock extends ModeleBoxes $sql .= " FROM ".MAIN_DB_PREFIX."product as p"; $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as s on p.rowid = s.fk_product"; $sql .= ' WHERE p.entity IN ('.getEntity($productstatic->element).')'; - $sql .= " AND p.tosell = 1 AND p.seuil_stock_alerte > 0"; + $sql .= " AND p.seuil_stock_alerte > 0"; if (empty($user->rights->produit->lire)) { - $sql .= ' AND p.fk_product_type != 0'; + $sql .= ' AND p.fk_product_type <> 0'; } if (empty($user->rights->service->lire)) { - $sql .= ' AND p.fk_product_type != 1'; + $sql .= ' AND p.fk_product_type <> 1'; } // Add where from hooks if (is_object($hookmanager)) { @@ -163,7 +163,7 @@ class box_produits_alerte_stock extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="tdoverflowmax150 maxwidth150onsmartphone"', + 'td' => 'class="tdoverflowmax100 maxwidth150onsmartphone"', 'text' => $objp->label, ); @@ -186,18 +186,13 @@ class box_produits_alerte_stock extends ModeleBoxes } } - $this->info_box_contents[$line][] = array( - 'td' => 'class="right nowraponall"', - 'text' => $price, - ); + /*$this->info_box_contents[$line][] = array( + 'td' => 'class="nowraponall right amount"', + 'text' => $price.' '.$price_base_type, + );*/ $this->info_box_contents[$line][] = array( - 'td' => 'class="right"', - 'text' => $price_base_type, - ); - - $this->info_box_contents[$line][] = array( - 'td' => 'class="center"', + 'td' => 'class="center nowraponall"', 'text' => price2num($objp->total_stock, 'MS').' / '.$objp->seuil_stock_alerte, 'text2'=>img_warning($langs->transnoentitiesnoconv("StockLowerThanLimit", $objp->seuil_stock_alerte)), ); @@ -210,7 +205,7 @@ class box_produits_alerte_stock extends ModeleBoxes $this->info_box_contents[$line][] = array( 'td' => 'class="right" width="18"', - 'text' => ''.$productstatic->LibStatut($objp->tobuy, 3, 0).'', + 'text' => ''.$productstatic->LibStatut($objp->tobuy, 3, 1).'', 'asis' => 1 ); diff --git a/htdocs/core/boxes/box_propales.php b/htdocs/core/boxes/box_propales.php index 51d313b7254..f3f9496325f 100644 --- a/htdocs/core/boxes/box_propales.php +++ b/htdocs/core/boxes/box_propales.php @@ -160,7 +160,7 @@ class box_propales extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="right nowraponall"', + 'td' => 'class="nowraponall right amount"', 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency), ); diff --git a/htdocs/core/boxes/box_scheduled_jobs.php b/htdocs/core/boxes/box_scheduled_jobs.php index 53cf5c79571..94695034cce 100644 --- a/htdocs/core/boxes/box_scheduled_jobs.php +++ b/htdocs/core/boxes/box_scheduled_jobs.php @@ -170,7 +170,7 @@ class box_scheduled_jobs extends ModeleBoxes ); $this->info_box_contents[$line][] = array( 'td' => 'class="center"', - 'textnoformat' => ($nbjobsinerror ? '
'.$nbjobsinerror.'
' : '
0
') + 'textnoformat' => ($nbjobsinerror ? '
'.$nbjobsinerror.'
' : '
0
') ); } else { $this->info_box_contents[0][0] = array( diff --git a/htdocs/core/boxes/box_supplier_orders.php b/htdocs/core/boxes/box_supplier_orders.php index 2cc34a9255b..89fd7850c5c 100644 --- a/htdocs/core/boxes/box_supplier_orders.php +++ b/htdocs/core/boxes/box_supplier_orders.php @@ -147,7 +147,7 @@ class box_supplier_orders extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="right nowraponall"', + 'td' => 'class="nowraponall right amount"', 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency), ); diff --git a/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php b/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php index f9d2de4b7fc..9a40c3f9aec 100644 --- a/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php +++ b/htdocs/core/boxes/box_supplier_orders_awaiting_reception.php @@ -151,7 +151,7 @@ class box_supplier_orders_awaiting_reception extends ModeleBoxes ); $this->info_box_contents[$line][] = array( - 'td' => 'class="right nowraponall"', + 'td' => 'class="nowraponall right amount"', 'text' => price($objp->total_ht, 0, $langs, 0, -1, -1, $conf->currency), ); diff --git a/htdocs/core/boxes/box_validated_projects.php b/htdocs/core/boxes/box_validated_projects.php index 574ee7b7d80..e57bb1f14d9 100644 --- a/htdocs/core/boxes/box_validated_projects.php +++ b/htdocs/core/boxes/box_validated_projects.php @@ -26,6 +26,7 @@ */ include_once DOL_DOCUMENT_ROOT."/core/boxes/modules_boxes.php"; + /** * Class to manage the box to show last projet */ @@ -63,7 +64,7 @@ class box_validated_projects extends ModeleBoxes $langs->loadLangs(array('boxes', 'projects')); $this->db = $db; - $this->boxlabel = "ProjectsWithTask"; + $this->boxlabel = "ProjectTasksWithoutTimeSpent"; $this->hidden = !($user->rights->projet->lire); @@ -116,7 +117,7 @@ class box_validated_projects extends ModeleBoxes $sql .= " INNER JOIN ".MAIN_DB_PREFIX."element_contact as ec ON ec.element_id = t.rowid AND fk_c_type_contact IN (-1, -2, -3)"; $sql .= " WHERE p.fk_statut = 1"; // Only open projects if ($projectsListId) { - $sql .= ' AND p.rowid IN ('.$this->db->sanitize($projectsListId).')'; // Only project are allowed + $sql .= ' AND p.rowid IN ('.$this->db->sanitize($projectsListId).')'; // Only projects that are allowed } $sql .= " AND t.rowid NOT IN (SELECT fk_task FROM ".MAIN_DB_PREFIX."projet_task_time WHERE fk_user = ".((int) $user->id).")"; $sql .= " GROUP BY p.rowid, p.ref, p.fk_soc, p.dateo"; diff --git a/htdocs/core/class/CSMSFile.class.php b/htdocs/core/class/CSMSFile.class.php index 8d5bcf7dc50..3f082ba6d53 100644 --- a/htdocs/core/class/CSMSFile.class.php +++ b/htdocs/core/class/CSMSFile.class.php @@ -29,8 +29,9 @@ /** * Class to send SMS - * Usage: $smsfile = new CSMSFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to); - * $smsfile->sendfile(); + * Usage: $smsfile = new CSMSFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to); + * $smsfile->socid=...; $smsfile->contact_id=...; $smsfile->member_id=...; $smsfile->fk_project=...; + * $smsfile->sendfile(); */ class CSMSFile { @@ -48,7 +49,8 @@ class CSMSFile public $nostop; public $socid; - public $contactid; + public $contact_id; + public $member_id; public $fk_project; @@ -135,6 +137,7 @@ class CSMSFile $sms->socid = $this->socid; $sms->contact_id = $this->contact_id; + $sms->member_id = $this->member_id; $sms->project = $this->fk_project; $res = $sms->SmsSend(); @@ -167,6 +170,7 @@ class CSMSFile $sms->socid = $this->socid; $sms->contact_id = $this->contact_id; + $sms->member_id = $this->member_id; $sms->fk_project = $this->fk_project; $res = $sms->SmsSend(); diff --git a/htdocs/core/class/ccountry.class.php b/htdocs/core/class/ccountry.class.php index 4f448845e80..7b46b0a08b0 100644 --- a/htdocs/core/class/ccountry.class.php +++ b/htdocs/core/class/ccountry.class.php @@ -111,7 +111,7 @@ class Ccountry // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_country("; + $sql = "INSERT INTO ".$this->db->prefix()."c_country("; $sql .= "rowid,"; $sql .= "code,"; $sql .= "code_iso,"; @@ -135,7 +135,7 @@ class Ccountry // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_country"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_country"); } // Commit or rollback @@ -169,7 +169,7 @@ class Ccountry // extends CommonObject $sql .= " t.code_iso,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_country as t"; + $sql .= " FROM ".$this->db->prefix()."c_country as t"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); } elseif ($code) { @@ -235,7 +235,7 @@ class Ccountry // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_country SET"; + $sql = "UPDATE ".$this->db->prefix()."c_country SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " code_iso=".(isset($this->code_iso) ? "'".$this->db->escape($this->code_iso)."'" : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").","; @@ -278,7 +278,7 @@ class Ccountry // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_country"; + $sql = "DELETE FROM ".$this->db->prefix()."c_country"; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); diff --git a/htdocs/core/class/comment.class.php b/htdocs/core/class/comment.class.php index c2dd055522e..937ca6f7875 100644 --- a/htdocs/core/class/comment.class.php +++ b/htdocs/core/class/comment.class.php @@ -113,7 +113,7 @@ class Comment extends CommonObject $error = 0; // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element." ("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element." ("; $sql .= "description"; $sql .= ", datec"; $sql .= ", fk_element"; @@ -146,7 +146,7 @@ class Comment extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); if (!$notrigger) { // Call trigger @@ -195,7 +195,7 @@ class Comment extends CommonObject $sql .= " c.fk_user_modif,"; $sql .= " c.entity,"; $sql .= " c.import_key"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -254,7 +254,7 @@ class Comment extends CommonObject // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " description=".(isset($this->description) ? "'".$this->db->escape($this->description)."'" : "null").","; $sql .= " datec=".($this->datec != '' ? "'".$this->db->idate($this->datec)."'" : 'null').","; $sql .= " fk_element=".(isset($this->fk_element) ? $this->fk_element : "null").","; @@ -315,7 +315,7 @@ class Comment extends CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid=".((int) $this->id); $resql = $this->db->query($sql); @@ -364,7 +364,7 @@ class Comment extends CommonObject if (!empty($element_type) && !empty($fk_element)) { $sql = "SELECT"; $sql .= " c.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as c"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as c"; $sql .= " WHERE c.fk_element = ".((int) $fk_element); $sql .= " AND c.element_type = '".$this->db->escape($element_type)."'"; $sql .= " AND c.entity = ".$conf->entity; diff --git a/htdocs/core/class/commondocgenerator.class.php b/htdocs/core/class/commondocgenerator.class.php index 5d0242657ef..8a0ce49ce00 100644 --- a/htdocs/core/class/commondocgenerator.class.php +++ b/htdocs/core/class/commondocgenerator.class.php @@ -653,7 +653,7 @@ abstract class CommonDocGenerator if ($columns != "") { $columns = substr($columns, 0, strlen($columns) - 2); - $resql = $this->db->query("SELECT ".$columns." FROM ".MAIN_DB_PREFIX."product_fournisseur_price_extrafields AS ex INNER JOIN ".MAIN_DB_PREFIX."product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '".$this->db->escape($line->ref_supplier)."'"); + $resql = $this->db->query("SELECT ".$columns." FROM ".$this->db->prefix()."product_fournisseur_price_extrafields AS ex INNER JOIN ".$this->db->prefix()."product_fournisseur_price AS f ON ex.fk_object = f.rowid WHERE f.ref_fourn = '".$this->db->escape($line->ref_supplier)."'"); if ($this->db->num_rows($resql) > 0) { $resql = $this->db->fetch_object($resql); diff --git a/htdocs/core/class/commonincoterm.class.php b/htdocs/core/class/commonincoterm.class.php index d0485acc5a9..e74d1428781 100644 --- a/htdocs/core/class/commonincoterm.class.php +++ b/htdocs/core/class/commonincoterm.class.php @@ -60,7 +60,7 @@ trait CommonIncoterm $this->label_incoterms = ''; if (!empty($this->fk_incoterms)) { - $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; + $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; $result = $this->db->query($sql); if ($result) { $res = $this->db->fetch_object($result); @@ -80,7 +80,7 @@ trait CommonIncoterm */ public function getIncotermsForPDF() { - $sql = "SELECT code FROM ".MAIN_DB_PREFIX."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; + $sql = "SELECT code FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -106,7 +106,7 @@ trait CommonIncoterm public function setIncoterms($id_incoterm, $location) { if ($this->id && $this->table_element) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_incoterms = ".($id_incoterm > 0 ? ((int) $id_incoterm) : "null"); $sql .= ", location_incoterms = ".($id_incoterm > 0 ? "'".$this->db->escape($location)."'" : "null"); $sql .= " WHERE rowid = ".((int) $this->id); @@ -116,7 +116,7 @@ trait CommonIncoterm $this->fk_incoterms = $id_incoterm; $this->location_incoterms = $location; - $sql = "SELECT libelle as label_incoterms FROM ".MAIN_DB_PREFIX."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; + $sql = "SELECT libelle as label_incoterms FROM ".$this->db->prefix()."c_incoterms WHERE rowid = ".(int) $this->fk_incoterms; $res = $this->db->query($sql); if ($res) { $obj = $this->db->fetch_object($res); diff --git a/htdocs/core/class/commoninvoice.class.php b/htdocs/core/class/commoninvoice.class.php index c7a5beae245..29fd230a61b 100644 --- a/htdocs/core/class/commoninvoice.class.php +++ b/htdocs/core/class/commoninvoice.class.php @@ -130,8 +130,8 @@ abstract class CommonInvoice extends CommonObject $field = 'fk_facturefourn'; } - $sql = 'SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$table; + $sql = "SELECT sum(amount) as amount, sum(multicurrency_amount) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix().$table; $sql .= " WHERE ".$field." = ".((int) $this->id); dol_syslog(get_class($this)."::getSommePaiement", LOG_DEBUG); @@ -168,6 +168,7 @@ abstract class CommonInvoice extends CommonObject $discountstatic = new DiscountAbsolute($this->db); $result = $discountstatic->getSumDepositsUsed($this, $multicurrency); + if ($result >= 0) { return $result; } else { @@ -225,10 +226,10 @@ abstract class CommonInvoice extends CommonObject { $idarray = array(); - $sql = 'SELECT rowid'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "SELECT rowid"; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE fk_facture_source = ".((int) $this->id); - $sql .= ' AND type = 2'; + $sql .= " AND type = 2"; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -252,10 +253,10 @@ abstract class CommonInvoice extends CommonObject */ public function getIdReplacingInvoice($option = '') { - $sql = 'SELECT rowid'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "SELECT rowid"; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE fk_facture_source = ".((int) $this->id); - $sql .= ' AND type < 2'; + $sql .= " AND type < 2"; if ($option == 'validated') { $sql .= ' AND fk_statut = 1'; } @@ -264,7 +265,7 @@ abstract class CommonInvoice extends CommonObject // and another no, priority is given to the valid one. // Should not happen (unless concurrent access and 2 people have created a // replacement invoice for the same invoice at the same time) - $sql .= ' ORDER BY fk_statut DESC'; + $sql .= " ORDER BY fk_statut DESC"; $resql = $this->db->query($sql); if ($resql) { @@ -307,7 +308,7 @@ abstract class CommonInvoice extends CommonObject } $sql = "SELECT p.ref, pf.amount, pf.multicurrency_amount, p.fk_paiement, p.datep, p.num_paiement as num, t.code".$field3; - $sql .= " FROM ".MAIN_DB_PREFIX.$table." as pf, ".MAIN_DB_PREFIX.$table2." as p, ".MAIN_DB_PREFIX."c_paiement as t"; + $sql .= " FROM ".$this->db->prefix().$table." as pf, ".$this->db->prefix().$table2." as p, ".$this->db->prefix()."c_paiement as t"; $sql .= " WHERE pf.".$field." = ".((int) $this->id); $sql .= " AND pf.".$field2." = p.rowid"; $sql .= ' AND p.fk_paiement = t.id'; @@ -336,12 +337,12 @@ abstract class CommonInvoice extends CommonObject $sql = ''; if ($this->element == 'facture' || $this->element == 'invoice') { $sql = "SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type"; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture as f'; $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $this->id); $sql .= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or deposits (payments from deposits are always null except if FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is set) } elseif ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { $sql = "SELECT rc.amount_ttc as amount, rc.multicurrency_amount_ttc as multicurrency_amount, rc.datec as date, f.ref as ref, rc.description as type"; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; + $sql .= ' FROM '.$this->db->prefix().'societe_remise_except as rc, '.$this->db->prefix().'facture_fourn as f'; $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $this->id); $sql .= ' AND (f.type = 2 OR f.type = 0 OR f.type = 3)'; // Find discount coming from credit note or excess received or deposits (payments from deposits are always null except if FACTURE_DEPOSITS_ARE_JUST_PAYMENTS is set) } @@ -461,7 +462,7 @@ abstract class CommonInvoice extends CommonObject $type = 'supplier_invoice'; } - $sql = " SELECT COUNT(ab.rowid) as nb FROM ".MAIN_DB_PREFIX."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->id); + $sql = " SELECT COUNT(ab.rowid) as nb FROM ".$this->db->prefix()."accounting_bookkeeping as ab WHERE ab.doc_type='".$this->db->escape($type)."' AND ab.fk_doc = ".((int) $this->id); $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_object($resql); @@ -600,8 +601,8 @@ abstract class CommonInvoice extends CommonObject $cdr_type = 0; $cdr_decalage = 0; - $sqltemp = 'SELECT c.type_cdr, c.nbjour, c.decalage'; - $sqltemp .= ' FROM '.MAIN_DB_PREFIX.'c_payment_term as c'; + $sqltemp = "SELECT c.type_cdr, c.nbjour, c.decalage"; + $sqltemp .= " FROM ".$this->db->prefix()."c_payment_term as c"; if (is_numeric($cond_reglement)) { $sqltemp .= " WHERE c.rowid=".((int) $cond_reglement); } else { @@ -696,15 +697,15 @@ abstract class CommonInvoice extends CommonObject $bac = new CompanyBankAccount($this->db); $bac->fetch(0, $this->socid); - $sql = 'SELECT count(*)'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; + $sql = "SELECT count(*)"; + $sql .= " FROM ".$this->db->prefix()."prelevement_facture_demande"; if ($type == 'bank-transfer') { - $sql .= ' WHERE fk_facture_fourn = '.((int) $this->id); + $sql .= " WHERE fk_facture_fourn = ".((int) $this->id); } else { - $sql .= ' WHERE fk_facture = '.((int) $this->id); + $sql .= " WHERE fk_facture = ".((int) $this->id); } - $sql .= ' AND ext_payment_id IS NULL'; // To exclude record done for some online payments - $sql .= ' AND traite = 0'; + $sql .= " AND ext_payment_id IS NULL"; // To exclude record done for some online payments + $sql .= " AND traite = 0"; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); $resql = $this->db->query($sql); @@ -727,7 +728,7 @@ abstract class CommonInvoice extends CommonObject } if (is_numeric($amount) && $amount != 0) { - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande('; + $sql = 'INSERT INTO '.$this->db->prefix().'prelevement_facture_demande('; if ($type == 'bank-transfer') { $sql .= 'fk_facture_fourn, '; } else { @@ -799,7 +800,7 @@ abstract class CommonInvoice extends CommonObject public function demande_prelevement_delete($fuser, $did) { // phpcs:enable - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; + $sql = 'DELETE FROM '.$this->db->prefix().'prelevement_facture_demande'; $sql .= ' WHERE rowid = '.((int) $did); $sql .= ' AND traite = 0'; if ($this->db->query($sql)) { @@ -810,6 +811,64 @@ abstract class CommonInvoice extends CommonObject return -1; } } + + + /** + * Build string for ZATCA QR Code (Arabi Saudia) + * + * @return string String for ZATCA QR Code + */ + public function buildZATCAQRString() + { + global $conf; + + $tmplang = new Translate('', $conf); + $tmplang->setDefaultLang('en_US'); + $tmplang->load("main"); + + $datestring = dol_print_date($this->date, 'dayhourrfc'); + $pricewithtaxstring = price($this->total_ttc, 0, $tmplang, 0, -1, 2); + $pricetaxstring = price($this->total_tva, 0, $tmplang, 0, -1, 2); + + /* + $name = implode(unpack("H*", $this->thirdparty->name)); + $vatnumber = implode(unpack("H*", $this->thirdparty->tva_intra)); + $date = implode(unpack("H*", $datestring)); + $pricewithtax = implode(unpack("H*", price2num($pricewithtaxstring, 2))); + $pricetax = implode(unpack("H*", $pricetaxstring)); + + var_dump(strlen($this->thirdparty->name)); + var_dump(str_pad(dechex('9'), 2, '0', STR_PAD_LEFT)); + var_dump($this->thirdparty->name); + var_dump(implode(unpack("H*", $this->thirdparty->name))); + var_dump(price($this->total_tva, 0, $tmplang, 0, -1, 2)); + + $s = '01'.str_pad(dechex(strlen($this->thirdparty->name)), 2, '0', STR_PAD_LEFT).$name; + $s .= '02'.str_pad(dechex(strlen($this->thirdparty->tva_intra)), 2, '0', STR_PAD_LEFT).$vatnumber; + $s .= '03'.str_pad(dechex(strlen($datestring)), 2, '0', STR_PAD_LEFT).$date; + $s .= '04'.str_pad(dechex(strlen($pricewithtaxstring)), 2, '0', STR_PAD_LEFT).$pricewithtax; + $s .= '05'.str_pad(dechex(strlen($pricetaxstring)), 2, '0', STR_PAD_LEFT).$pricetax; + $s .= ''; // Hash of xml invoice + $s .= ''; // ecda signature + $s .= ''; // ecda public key + $s .= ''; // ecda signature of public key stamp + */ + + // Using TLV format + $s = pack('C1', 1).pack('C1', strlen($this->thirdparty->name)).$this->thirdparty->name; + $s .= pack('C1', 2).pack('C1', strlen($this->thirdparty->tva_intra)).$this->thirdparty->tva_intra; + $s .= pack('C1', 3).pack('C1', strlen($datestring)).$this->date; + $s .= pack('C1', 4).pack('C1', strlen($pricewithtaxstring)).$pricewithtaxstring; + $s .= pack('C1', 5).pack('C1', strlen($pricetaxstring)).$pricetaxstring; + $s .= ''; // Hash of xml invoice + $s .= ''; // ecda signature + $s .= ''; // ecda public key + $s .= ''; // ecda signature of public key stamp + + $s = base64_encode($s); + + return $s; + } } diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index a83cfae3000..fe6364e279f 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -536,7 +536,7 @@ abstract class CommonObject global $db, $conf; $sql = "SELECT rowid, ref, ref_ext"; - $sql .= " FROM ".MAIN_DB_PREFIX.$element; + $sql .= " FROM ".$db->prefix().$element; $sql .= " WHERE entity IN (".getEntity($element).")"; if ($id > 0) { @@ -1041,7 +1041,7 @@ abstract class CommonObject } else { // We look for id type_contact $sql = "SELECT tc.rowid"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact as tc"; $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; $sql .= " AND tc.source='".$this->db->escape($source)."'"; $sql .= " AND tc.code='".$this->db->escape($type_contact)."' AND tc.active=1"; @@ -1079,7 +1079,7 @@ abstract class CommonObject $this->db->begin(); // Insert into database - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; + $sql = "INSERT INTO ".$this->db->prefix()."element_contact"; $sql .= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; $sql .= " VALUES (".$this->id.", ".((int) $fk_socpeople)." , "; $sql .= "'".$this->db->idate($datecreate)."'"; @@ -1148,7 +1148,7 @@ abstract class CommonObject { // phpcs:enable // Insert into database - $sql = "UPDATE ".MAIN_DB_PREFIX."element_contact set"; + $sql = "UPDATE ".$this->db->prefix()."element_contact set"; $sql .= " statut = ".$statut; if ($type_contact_id) { $sql .= ", fk_c_type_contact = ".((int) $type_contact_id); @@ -1182,7 +1182,7 @@ abstract class CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; + $sql = "DELETE FROM ".$this->db->prefix()."element_contact"; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::delete_contact", LOG_DEBUG); @@ -1215,17 +1215,20 @@ abstract class CommonObject public function delete_linked_contact($source = '', $code = '') { // phpcs:enable + $listId = ''; $temp = array(); $typeContact = $this->liste_type_contact($source, '', 0, 0, $code); - foreach ($typeContact as $key => $value) { - array_push($temp, $key); + if (!empty($typeContact)) { + foreach ($typeContact as $key => $value) { + array_push($temp, $key); + } + $listId = implode(",", $temp); } - $listId = implode(",", $temp); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; + $sql = "DELETE FROM ".$this->db->prefix()."element_contact"; $sql .= " WHERE element_id = ".((int) $this->id); - if ($listId) { + if (!empty($listId)) { $sql .= " AND fk_c_type_contact IN (".$this->db->sanitize($listId).")"; } @@ -1264,16 +1267,16 @@ abstract class CommonObject } $sql .= ", t.civility as civility, t.lastname as lastname, t.firstname, t.email"; $sql .= ", tc.source, tc.element, tc.code, tc.libelle"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact tc"; - $sql .= ", ".MAIN_DB_PREFIX."element_contact ec"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact tc"; + $sql .= ", ".$this->db->prefix()."element_contact ec"; if ($source == 'internal') { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user t on ec.fk_socpeople = t.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."user t on ec.fk_socpeople = t.rowid"; } if ($source == 'external' || $source == 'thirdparty') { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople t on ec.fk_socpeople = t.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."socpeople t on ec.fk_socpeople = t.rowid"; } $sql .= " WHERE ec.element_id = ".((int) $this->id); - $sql .= " AND ec.fk_c_type_contact=tc.rowid"; + $sql .= " AND ec.fk_c_type_contact = tc.rowid"; $sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; if ($code) { $sql .= " AND tc.code = '".$this->db->escape($code)."'"; @@ -1345,7 +1348,7 @@ abstract class CommonObject { $sql = "SELECT ec.datecreate, ec.statut, ec.fk_socpeople, ec.fk_c_type_contact,"; $sql .= " tc.code, tc.libelle"; - $sql .= " FROM (".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as tc)"; + $sql .= " FROM (".$this->db->prefix()."element_contact as ec, ".$this->db->prefix()."c_type_contact as tc)"; $sql .= " WHERE ec.rowid =".((int) $rowid); $sql .= " AND ec.fk_c_type_contact=tc.rowid"; $sql .= " AND tc.element = '".$this->db->escape($this->element)."'"; @@ -1390,7 +1393,7 @@ abstract class CommonObject $tab = array(); $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact as tc"; $sql .= " WHERE tc.element='".$this->db->escape($this->element)."'"; if ($activeonly == 1) { $sql .= " AND tc.active=1"; // only the active types @@ -1450,7 +1453,7 @@ abstract class CommonObject $tab = array(); $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position, tc.element"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " FROM ".$this->db->prefix()."c_type_contact as tc"; $sqlWhere = array(); if (!empty($element)) { @@ -1548,14 +1551,14 @@ abstract class CommonObject } $sql = "SELECT ec.fk_socpeople"; - $sql .= " FROM ".MAIN_DB_PREFIX."element_contact as ec,"; + $sql .= " FROM ".$this->db->prefix()."element_contact as ec,"; if ($source == 'internal') { - $sql .= " ".MAIN_DB_PREFIX."user as c,"; + $sql .= " ".$this->db->prefix()."user as c,"; } if ($source == 'external') { - $sql .= " ".MAIN_DB_PREFIX."socpeople as c,"; + $sql .= " ".$this->db->prefix()."socpeople as c,"; } - $sql .= " ".MAIN_DB_PREFIX."c_type_contact as tc"; + $sql .= " ".$this->db->prefix()."c_type_contact as tc"; $sql .= " WHERE ec.element_id = ".((int) $id); $sql .= " AND ec.fk_socpeople = c.rowid"; if ($source == 'internal') { @@ -1662,8 +1665,8 @@ abstract class CommonObject * Looks for an object with ref matching the wildcard provided * It does only work when $this->table_ref_field is set * - * @param string $ref Wildcard - * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO + * @param string $ref Wildcard + * @return int >1 = OK, 0 = Not found or table_ref_field not defined, <0 = KO */ public function fetchOneLike($ref) { @@ -1671,7 +1674,7 @@ abstract class CommonObject return 0; } - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element." WHERE ".$this->table_ref_field." LIKE '".$this->db->escape($ref)."' LIMIT 1"; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element." WHERE ".$this->table_ref_field." LIKE '".$this->db->escape($ref)."' LIMIT 1"; $query = $this->db->query($sql); @@ -1713,7 +1716,7 @@ abstract class CommonObject if ($idtype > 0) { if (empty($this->barcode_type) || empty($this->barcode_type_code) || empty($this->barcode_type_label) || empty($this->barcode_type_coder)) { // If data not already loaded $sql = "SELECT rowid, code, libelle as label, coder"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_barcode_type"; + $sql .= " FROM ".$this->db->prefix()."c_barcode_type"; $sql .= " WHERE rowid = ".((int) $idtype); dol_syslog(get_class($this).'::fetch_barcode', LOG_DEBUG); $resql = $this->db->query($sql); @@ -1850,7 +1853,7 @@ abstract class CommonObject $result = false; - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$table; + $sql = "SELECT rowid FROM ".$this->db->prefix().$table; $sql .= " WHERE ".$field." = '".$this->db->escape($key)."'"; if (!empty($element)) { $sql .= " AND entity IN (".getEntity($element).")"; @@ -1883,7 +1886,7 @@ abstract class CommonObject { $result = false; if (!empty($id) && !empty($field) && !empty($table)) { - $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; + $sql = "SELECT ".$field." FROM ".$this->db->prefix().$table; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); @@ -1941,7 +1944,7 @@ abstract class CommonObject $fk_user_field = 'fk_user_mod'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$table." SET "; + $sql = "UPDATE ".$this->db->prefix().$table." SET "; if ($format == 'text') { $sql .= $field." = '".$this->db->escape($value)."'"; @@ -2041,20 +2044,20 @@ abstract class CommonObject } $restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc; $sql = "SELECT MAX(te.".$fieldid.")"; - $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; + $sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te"; if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= ",".$this->db->prefix()."usergroup_user as ug"; } if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) { $tmparray = explode('@', $this->ismultientitymanaged); - $sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity + $sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity } elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid + $sql .= ", ".$this->db->prefix()."societe as s"; // If we need to link to societe to limit select to socid } elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid } if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; } $sql .= " WHERE te.".$fieldid." < '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) { @@ -2111,20 +2114,20 @@ abstract class CommonObject $this->ref_previous = $row[0]; $sql = "SELECT MIN(te.".$fieldid.")"; - $sql .= " FROM ".(empty($nodbprefix) ?MAIN_DB_PREFIX:'').$this->table_element." as te"; + $sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te"; if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) { - $sql .= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql .= ",".$this->db->prefix()."usergroup_user as ug"; } if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) { $tmparray = explode('@', $this->ismultientitymanaged); - $sql .= ", ".MAIN_DB_PREFIX.$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity + $sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity } elseif ($restrictiononfksoc == 1 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe as s"; // If we need to link to societe to limit select to socid + $sql .= ", ".$this->db->prefix()."societe as s"; // If we need to link to societe to limit select to socid } elseif ($restrictiononfksoc == 2 && $this->element != 'societe' && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid + $sql .= " LEFT JOIN ".$this->db->prefix()."societe as s ON te.fk_soc = s.rowid"; // If we need to link to societe to limit select to socid } if ($restrictiononfksoc && empty($user->rights->societe->client->voir) && !$socid) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; + $sql .= " LEFT JOIN ".$this->db->prefix()."societe_commerciaux as sc ON ".$aliastablesociete.".rowid = sc.fk_soc"; } $sql .= " WHERE te.".$fieldid." > '".$this->db->escape($fieldid == 'rowid' ? $this->id : $this->ref)."'"; // ->ref must always be defined (set to id if field does not exists) if ($restrictiononfksoc == 1 && empty($user->rights->societe->client->voir) && !$socid) { @@ -2223,7 +2226,7 @@ abstract class CommonObject return -1; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; if (!empty($this->fields['fk_project'])) { // Common case if ($projectid) { $sql .= " SET fk_project = ".((int) $projectid); @@ -2266,7 +2269,12 @@ abstract class CommonObject */ public function setPaymentMethods($id) { + global $user; + + $error = 0; $notrigger = 0; + dol_syslog(get_class($this).'::setPaymentMethods('.$id.')'); + if ($this->statut >= 0 || $this->element == 'societe') { // TODO uniformize field name $fieldname = 'fk_mode_reglement'; @@ -2283,7 +2291,7 @@ abstract class CommonObject $fieldname = 'fk_typepayment'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2293,6 +2301,19 @@ abstract class CommonObject if (get_class($this) == 'Fournisseur') { $this->mode_reglement_supplier_id = $id; } + // Triggers + if (!$error && !$notrigger) { + // Call triggers + if (get_class($this) == 'Commande') { + $result = $this->call_trigger('ORDER_MODIFY', $user); + } else { + $result = $this->call_trigger(strtoupper(get_class($this)).'_MODIFY', $user); + } + if ($result < 0) { + $error++; + } + // End call triggers + } return 1; } else { dol_syslog(get_class($this).'::setPaymentMethods Error '.$this->db->error()); @@ -2318,7 +2339,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'multicurrency_code'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = '".$this->db->escape($code)."'"; $sql .= ' WHERE rowid='.((int) $this->id); @@ -2356,7 +2377,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'multicurrency_tx'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".((float) $rate); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2564,7 +2585,7 @@ abstract class CommonObject $fieldname = 'cond_reglement_supplier'; } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2606,7 +2627,7 @@ abstract class CommonObject $fieldname = 'transport_mode_supplier'; } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".(($id > 0 || $id == '0') ? ((int) $id) : 'NULL'); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2641,7 +2662,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'retained_warranty_fk_cond_reglement'; - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element; $sql .= " SET ".$fieldname." = ".((int) $id); $sql .= ' WHERE rowid='.((int) $this->id); @@ -2674,7 +2695,7 @@ abstract class CommonObject $fieldname = 'fk_address'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ".$fieldname." = ".((int) $id); + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET ".$fieldname." = ".((int) $id); $sql .= " WHERE rowid = ".((int) $this->id)." AND fk_statut = 0"; if ($this->db->query($sql)) { @@ -2719,7 +2740,7 @@ abstract class CommonObject } dol_syslog(get_class($this).'::setShippingMethod('.$shipping_method_id.')'); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_shipping_method = ".((int) $shipping_method_id); $sql .= " WHERE rowid=".((int) $this->id); $resql = $this->db->query($sql); @@ -2766,7 +2787,7 @@ abstract class CommonObject } dol_syslog(get_class($this).'::setWarehouse('.$warehouse_id.')'); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_warehouse = ".((int) $warehouse_id); $sql .= " WHERE rowid=".((int) $this->id); @@ -2797,7 +2818,7 @@ abstract class CommonObject $newmodelpdf = dol_trunc($modelpdf, 255); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET model_pdf = '".$this->db->escape($newmodelpdf)."'"; $sql .= " WHERE rowid = ".((int) $this->id); @@ -2843,7 +2864,7 @@ abstract class CommonObject } dol_syslog(get_class($this).'::setBankAccount('.$fk_account.')'); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET fk_account = ".((int) $fk_account); $sql .= " WHERE rowid=".((int) $this->id); @@ -2900,7 +2921,7 @@ abstract class CommonObject // Count number of lines to reorder (according to choice $renum) $nl = 0; - $sql = "SELECT count(rowid) FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT count(rowid) FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); if (!$renum) { $sql .= ' AND rang = 0'; @@ -2922,7 +2943,7 @@ abstract class CommonObject $rows = array(); // We first search all lines that are parent lines (for multilevel details lines) - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); if ($fk_parent_line) { $sql .= ' AND fk_parent_line IS NULL'; @@ -2970,7 +2991,7 @@ abstract class CommonObject { $rows = array(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= ' AND fk_parent_line = '.((int) $id); $sql .= ' ORDER BY rang ASC'; @@ -3048,7 +3069,7 @@ abstract class CommonObject $fieldposition = 'position'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); $sql .= ' WHERE rowid = '.((int) $rowid); dol_syslog(get_class($this)."::updateRangOfLine", LOG_DEBUG); @@ -3094,11 +3115,11 @@ abstract class CommonObject $fieldposition = 'position'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= ' AND rang = '.((int) ($rang - 1)); if ($this->db->query($sql)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang - 1)); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang - 1)); $sql .= ' WHERE rowid = '.((int) $rowid); if (!$this->db->query($sql)) { dol_print_error($this->db); @@ -3125,11 +3146,11 @@ abstract class CommonObject $fieldposition = 'position'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) $rang); $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= ' AND rang = '.((int) ($rang + 1)); if ($this->db->query($sql)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang + 1)); + $sql = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldposition." = ".((int) ($rang + 1)); $sql .= ' WHERE rowid = '.((int) $rowid); if (!$this->db->query($sql)) { dol_print_error($this->db); @@ -3148,7 +3169,7 @@ abstract class CommonObject */ public function getRangOfLine($rowid) { - $sql = "SELECT rang FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rang FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::getRangOfLine", LOG_DEBUG); @@ -3167,7 +3188,7 @@ abstract class CommonObject */ public function getIdOfLine($rang) { - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= " AND rang = ".((int) $rang); $resql = $this->db->query($sql); @@ -3194,7 +3215,7 @@ abstract class CommonObject // Search the last rang with fk_parent_line if ($fk_parent_line) { - $sql = "SELECT max(".$positionfield.") FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT max(".$positionfield.") FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); $sql .= " AND fk_parent_line = ".((int) $fk_parent_line); @@ -3210,7 +3231,7 @@ abstract class CommonObject } } else { // If not, search the last rang of element - $sql = "SELECT max(".$positionfield.") FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT max(".$positionfield.") FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); dol_syslog(get_class($this)."::line_max", LOG_DEBUG); @@ -3237,7 +3258,7 @@ abstract class CommonObject return -1; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ref_ext = '".$this->db->escape($ref_ext)."'"; $sql .= " WHERE ".(isset($this->table_rowid) ? $this->table_rowid : 'rowid')." = ".((int) $this->id); @@ -3288,7 +3309,7 @@ abstract class CommonObject } else { $fieldusermod = "fk_user_modif"; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET note".$newsuffix." = ".(!empty($note) ? ("'".$this->db->escape($note)."'") : "NULL"); $sql .= ", ".$fieldusermod." = ".((int) $user->id); $sql .= " WHERE rowid = ".((int) $this->id); @@ -3357,7 +3378,7 @@ abstract class CommonObject $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_ORDER"; } elseif ($this->element == 'facture' || $this->element == 'invoice') { $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_INVOICE"; - } elseif ($this->element == 'facture_fourn' || $this->element == 'supplier_invoice' || $this->element == 'invoice_supplier') { + } elseif ($this->element == 'facture_fourn' || $this->element == 'supplier_invoice' || $this->element == 'invoice_supplier' || $this->element == 'invoice_supplier_rec') { $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_INVOICE"; } elseif ($this->element == 'order_supplier' || $this->element == 'supplier_order') { $MODULE = "MODULE_DISALLOW_UPDATE_PRICE_SUPPLIER_ORDER"; @@ -3402,6 +3423,9 @@ abstract class CommonObject $fieldtva = 'tva'; $fieldup = 'pu_ht'; } + if ($this->element == 'invoice_supplier_rec') { + $fieldup = 'pu_ht'; + } if ($this->element == 'expensereport') { $fieldup = 'value_unit'; } @@ -3412,7 +3436,7 @@ abstract class CommonObject $sql .= ', situation_percent'; } $sql .= ', multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql .= " FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); if ($exclspec) { $product_field = 'product_type'; @@ -3460,7 +3484,7 @@ abstract class CommonObject //var_dump($diff_when_using_price_ht.' '.$diff_on_current_total); if ($diff_when_using_price_ht && $diff_on_current_total) { - $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".price2num((float) $tmpcal[1]).", total_ttc = ".price2num((float) $tmpcal[2])." WHERE rowid = ".((int) $obj->rowid); + $sqlfix = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldtva." = ".price2num((float) $tmpcal[1]).", total_ttc = ".price2num((float) $tmpcal[2])." WHERE rowid = ".((int) $obj->rowid); dol_syslog('We found unconsistent data into detailed line (diff_when_using_price_ht = '.$diff_when_using_price_ht.' and diff_on_current_total = '.$diff_on_current_total.') for line rowid = '.$obj->rowid." (total vat of line calculated=".$tmpcal[1].", database=".$obj->total_tva."). We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix, LOG_WARNING); $resqlfix = $this->db->query($sqlfix); if (!$resqlfix) { @@ -3504,7 +3528,7 @@ abstract class CommonObject dol_print_error('', $errmsg); exit; } - $sqlfix = "UPDATE ".MAIN_DB_PREFIX.$this->table_element_line." SET ".$fieldtva." = ".price2num($obj->total_tva - $diff).", total_ttc = ".price2num($obj->total_ttc - $diff)." WHERE rowid = ".((int) $obj->rowid); + $sqlfix = "UPDATE ".$this->db->prefix().$this->table_element_line." SET ".$fieldtva." = ".price2num($obj->total_tva - $diff).", total_ttc = ".price2num($obj->total_ttc - $diff)." WHERE rowid = ".((int) $obj->rowid); dol_syslog('We found a difference of '.$diff.' for line rowid = '.$obj->rowid.". We fix the total_vat and total_ttc of line by running sqlfix = ".$sqlfix); $resqlfix = $this->db->query($sqlfix); if (!$resqlfix) { @@ -3552,7 +3576,7 @@ abstract class CommonObject if ($this->element == 'facture' || $this->element == 'facturerec') { $fieldtva = 'total_tva'; } - if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier') { + if ($this->element == 'facture_fourn' || $this->element == 'invoice_supplier' || $this->element == 'invoice_supplier_rec') { $fieldtva = 'total_tva'; } if ($this->element == 'propal') { @@ -3572,7 +3596,7 @@ abstract class CommonObject } if (empty($nodatabaseupdate)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = "UPDATE ".$this->db->prefix().$this->table_element.' SET'; $sql .= " ".$fieldht." = ".((float) price2num($this->total_ht)).","; $sql .= " ".$fieldtva." = ".((float) price2num($this->total_tva)).","; $sql .= " ".$fieldlocaltax1." = ".((float) price2num($this->total_localtax1)).","; @@ -3653,7 +3677,7 @@ abstract class CommonObject $this->db->begin(); $error = 0; - $sql = "INSERT INTO " . MAIN_DB_PREFIX . "element_element ("; + $sql = "INSERT INTO " . $this->db->prefix() . "element_element ("; $sql .= "fk_source"; $sql .= ", sourcetype"; $sql .= ", fk_target"; @@ -3694,23 +3718,23 @@ abstract class CommonObject /** * Fetch array of objects linked to current object (object of enabled modules only). Links are loaded into * this->linkedObjectsIds array + - * this->linkedObjects array if $loadalsoobjects = 1 + * this->linkedObjects array if $loadalsoobjects = 1 or $loadalsoobjects = type * Possible usage for parameters: * - all parameters empty -> we look all link to current object (current object can be source or target) - * - source id+type -> will get target list linked to source - * - target id+type -> will get source list linked to target - * - source id+type + target type -> will get target list of the type - * - target id+type + target source -> will get source list of the type + * - source id+type -> will get list of targets linked to source + * - target id+type -> will get list of sources linked to target + * - source id+type + target type -> will get list of targets of the type linked to source + * - target id+type + source type -> will get list of sources of the type linked to target * - * @param int $sourceid Object source id (if not defined, id of object) - * @param string $sourcetype Object source type (if not defined, element name of object) - * @param int $targetid Object target id (if not defined, id of object) - * @param string $targettype Object target type (if not defined, elemennt name of object) - * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided - * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. - * @param string $orderby SQL 'ORDER BY' clause - * @param int $loadalsoobjects Load also array this->linkedObjects (Use 0 to increase performances) - * @return int <0 if KO, >0 if OK + * @param int $sourceid Object source id (if not defined, id of object) + * @param string $sourcetype Object source type (if not defined, element name of object) + * @param int $targetid Object target id (if not defined, id of object) + * @param string $targettype Object target type (if not defined, element name of object) + * @param string $clause 'OR' or 'AND' clause used when both source id and target id are provided + * @param int $alsosametype 0=Return only links to object that differs from source type. 1=Include also link to objects of same type. + * @param string $orderby SQL 'ORDER BY' clause + * @param int|string $loadalsoobjects Load also array this->linkedObjects. Use 0 to increase performances, Use 1 to load all, Use value of type ('facture', 'facturerec', ...) to load only a type of object. + * @return int <0 if KO, >0 if OK * @see add_object_linked(), updateObjectLinked(), deleteObjectLinked() */ public function fetchObjectLinked($sourceid = null, $sourcetype = '', $targetid = null, $targettype = '', $clause = 'OR', $alsosametype = 1, $orderby = 'sourcetype', $loadalsoobjects = 1) @@ -3760,8 +3784,8 @@ abstract class CommonObject }*/ // Links between objects are stored in table element_element - $sql = 'SELECT rowid, fk_source, sourcetype, fk_target, targettype'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'element_element'; + $sql = "SELECT rowid, fk_source, sourcetype, fk_target, targettype"; + $sql .= " FROM ".$this->db->prefix()."element_element"; $sql .= " WHERE "; if ($justsource || $justtarget) { if ($justsource) { @@ -3779,7 +3803,7 @@ abstract class CommonObject $sql .= "(fk_source = ".((int) $sourceid)." AND sourcetype = '".$this->db->escape($sourcetype)."')"; $sql .= " ".$clause." (fk_target = ".((int) $targetid)." AND targettype = '".$this->db->escape($targettype)."')"; } - $sql .= ' ORDER BY '.$orderby; + $sql .= " ORDER BY ".$orderby; dol_syslog(get_class($this)."::fetchObjectLink", LOG_DEBUG); $resql = $this->db->query($sql); @@ -3892,10 +3916,9 @@ abstract class CommonObject $module = 'mrp'; } - - // Here $module, $classfile and $classname are set + // Here $module, $classfile and $classname are set, we can use them. if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) { - if ($loadalsoobjects) { + if ($loadalsoobjects && (is_numeric($loadalsoobjects) || ($loadalsoobjects === $objecttype))) { dol_include_once('/'.$classpath.'/'.$classfile.'.class.php'); //print '/'.$classpath.'/'.$classfile.'.class.php '.class_exists($classname); if (class_exists($classname)) { @@ -3948,7 +3971,7 @@ abstract class CommonObject $this->db->begin(); $error = 0; - $sql = "UPDATE " . MAIN_DB_PREFIX . "element_element SET "; + $sql = "UPDATE " . $this->db->prefix() . "element_element SET "; if ($updatesource) { $sql .= "fk_source = " . ((int) $sourceid); $sql .= ", sourcetype = '" . $this->db->escape($sourcetype) . "'"; @@ -4037,7 +4060,7 @@ abstract class CommonObject } if (!$error) { - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "element_element"; + $sql = "DELETE FROM " . $this->db->prefix() . "element_element"; $sql .= " WHERE"; if ($rowid > 0) { $sql .= " rowid = " . ((int) $rowid); @@ -4089,7 +4112,7 @@ abstract class CommonObject global $db; - $sql = "SELECT ".$field_select." FROM ".MAIN_DB_PREFIX.$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); + $sql = "SELECT ".$field_select." FROM ".$db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); $resql = $db->query($sql); $TRes = array(); @@ -4118,7 +4141,7 @@ abstract class CommonObject global $db; - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); + $sql = "DELETE FROM ".$db->prefix().$table_element." WHERE ".$field_where." = ".((int) $fk_object_where); $resql = $db->query($sql); if (empty($resql)) { @@ -4171,7 +4194,7 @@ abstract class CommonObject $fieldstatus = 'status'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$elementTable; + $sql = "UPDATE ".$this->db->prefix().$elementTable; $sql .= " SET ".$fieldstatus." = ".((int) $status); // If status = 1 = validated, update also fk_user_valid // TODO Replace the test on $elementTable by doing a test on existence of the field in $this->fields @@ -4272,7 +4295,7 @@ abstract class CommonObject $ref = trim($ref); $sql = "SELECT rowid, canvas"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql .= " FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE entity IN (".getEntity($this->element).")"; if (!empty($id)) { $sql .= " AND rowid = ".((int) $id); @@ -4305,7 +4328,7 @@ abstract class CommonObject */ public function getSpecialCode($lineid) { - $sql = "SELECT special_code FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "SELECT special_code FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE rowid = ".((int) $lineid); $resql = $this->db->query($sql); if ($resql) { @@ -4347,7 +4370,7 @@ abstract class CommonObject foreach ($arraytoscan as $table => $elementname) { //print $id.'-'.$table.'-'.$elementname.'
'; // Check if third party can be deleted - $sql = "SELECT COUNT(*) as nb from ".MAIN_DB_PREFIX.$table; + $sql = "SELECT COUNT(*) as nb from ".$this->db->prefix().$table; $sql .= " WHERE ".$this->fk_element." = ".((int) $id); $resql = $this->db->query($sql); if ($resql) { @@ -4423,7 +4446,7 @@ abstract class CommonObject $total_discount = 0.00; $sql = "SELECT subprice as pu_ht, qty, remise_percent, total_ht"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql .= " FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE ".$this->fk_element." = ".((int) $this->id); dol_syslog(get_class($this).'::getTotalDiscount', LOG_DEBUG); @@ -4563,7 +4586,7 @@ abstract class CommonObject $extraparams = (!empty($this->extraparams) ? json_encode($this->extraparams) : null); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET extraparams = ".(!empty($extraparams) ? "'".$this->db->escape($extraparams)."'" : "null"); $sql .= " WHERE rowid = ".((int) $this->id); @@ -4862,7 +4885,7 @@ abstract class CommonObject */ public function printOriginLinesList($restrictlist = '', $selectedLines = array()) { - global $langs, $hookmanager, $conf, $form; + global $langs, $hookmanager, $conf, $form, $action; print ''; print ''.$langs->trans('Ref').''; @@ -4888,7 +4911,7 @@ abstract class CommonObject if (is_object($hookmanager)) { // Old code is commented on preceding line. $parameters = array('line'=>$line, 'i'=>$i, 'restrictlist'=>$restrictlist, 'selectedLines'=> $selectedLines); if (!empty($line->fk_parent_line)) { $parameters['fk_parent_line'] = $line->fk_parent_line; } - $reshook = $hookmanager->executeHooks('printOriginObjectSubLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks + $reshook = $hookmanager->executeHooks('printOriginObjectLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks } if (empty($reshook)) { $this->printOriginLine($line, '', $restrictlist, '/core/tpl', $selectedLines); @@ -5058,7 +5081,7 @@ abstract class CommonObject // phpcs:enable $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_resources ("; + $sql = "INSERT INTO ".$this->db->prefix()."element_resources ("; $sql .= "resource_id"; $sql .= ", resource_type"; $sql .= ", element_id"; @@ -5101,7 +5124,7 @@ abstract class CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; + $sql = "DELETE FROM ".$this->db->prefix()."element_resources"; $sql .= " WHERE rowid = ".((int) $rowid); dol_syslog(get_class($this)."::delete_resource", LOG_DEBUG); @@ -5292,103 +5315,14 @@ abstract class CommonObject // Index file in database if (!empty($obj->result['fullpath'])) { $destfull = $obj->result['fullpath']; - $upload_dir = dirname($destfull); - $destfile = basename($destfull); - $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir); - if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) { // If not a tmp dir - $filename = basename($destfile); - $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); - $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); - - include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; - $ecmfile = new EcmFiles($this->db); - $result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir.'/' : '').$filename); - - // Set the public "share" key - $setsharekey = false; - if ($this->element == 'propal') { - $useonlinesignature = $conf->global->MAIN_FEATURES_LEVEL; // Replace this with 1 when feature to make online signature is ok - if ($useonlinesignature) { - $setsharekey = true; - } - if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) { - $setsharekey = true; - } - } - if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) { - $setsharekey = true; - } - if ($this->element == 'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) { - $setsharekey = true; - } - if ($this->element == 'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) { - $setsharekey = true; - } - if ($this->element == 'contrat' && !empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD)) { - $setsharekey = true; - } - if ($this->element == 'supplier_proposal' && !empty($conf->global->SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) { - $setsharekey = true; - } - - if ($setsharekey) { - if (empty($ecmfile->share)) { // Because object not found or share not set yet - require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; - $ecmfile->share = getRandomPassword(true); - } - } - - if ($result > 0) { - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content - $ecmfile->fullpath_orig = ''; - $ecmfile->gen_or_uploaded = 'generated'; - $ecmfile->description = ''; // indexed content - $ecmfile->keywords = ''; // keyword content - $result = $ecmfile->update($user); - if ($result < 0) { - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); - } - } else { - $ecmfile->entity = $conf->entity; - $ecmfile->filepath = $rel_dir; - $ecmfile->filename = $filename; - $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content - $ecmfile->fullpath_orig = ''; - $ecmfile->gen_or_uploaded = 'generated'; - $ecmfile->description = ''; // indexed content - $ecmfile->keywords = ''; // keyword content - $ecmfile->src_object_type = $this->table_element; // $this->table_name is 'myobject' or 'mymodule_myobject'. - $ecmfile->src_object_id = $this->id; - - $result = $ecmfile->create($user); - if ($result < 0) { - setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); - } - } - - /*$this->result['fullname']=$destfull; - $this->result['filepath']=$ecmfile->filepath; - $this->result['filename']=$ecmfile->filename;*/ - //var_dump($obj->update_main_doc_field);exit; - - // Update the last_main_doc field into main object (if document generator has property ->update_main_doc_field set) - $update_main_doc_field = 0; - if (!empty($obj->update_main_doc_field)) { - $update_main_doc_field = 1; - } - if ($update_main_doc_field && !empty($this->table_element)) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET last_main_doc = '".$this->db->escape($ecmfile->filepath."/".$ecmfile->filename)."'"; - $sql .= " WHERE rowid = ".((int) $this->id); - - $resql = $this->db->query($sql); - if (!$resql) { - dol_print_error($this->db); - } else { - $this->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename; - } - } + // Update the last_main_doc field into main object (if document generator has property ->update_main_doc_field set) + $update_main_doc_field = 0; + if (!empty($obj->update_main_doc_field)) { + $update_main_doc_field = 1; } + + $this->indexFile($destfull, $update_main_doc_field); } else { dol_syslog('Method ->write_file was called on object '.get_class($obj).' and return a success but the return array ->result["fullpath"] was not set.', LOG_WARNING); } @@ -5417,6 +5351,115 @@ abstract class CommonObject } } + /** + * Index a file into the ECM database + * + * @param string $destfull Full path of file to index + * @param int $update_main_doc_field Update field main_doc file into table of object + * @return int <0 if KO, >0 if OK + */ + public function indexFile($destfull, $update_main_doc_field) + { + global $conf, $user; + + $upload_dir = dirname($destfull); + $destfile = basename($destfull); + $rel_dir = preg_replace('/^'.preg_quote(DOL_DATA_ROOT, '/').'/', '', $upload_dir); + + if (!preg_match('/[\\/]temp[\\/]|[\\/]thumbs|\.meta$/', $rel_dir)) { // If not a tmp dir + $filename = basename($destfile); + $rel_dir = preg_replace('/[\\/]$/', '', $rel_dir); + $rel_dir = preg_replace('/^[\\/]/', '', $rel_dir); + + include_once DOL_DOCUMENT_ROOT.'/ecm/class/ecmfiles.class.php'; + $ecmfile = new EcmFiles($this->db); + $result = $ecmfile->fetch(0, '', ($rel_dir ? $rel_dir.'/' : '').$filename); + + // Set the public "share" key + $setsharekey = false; + if ($this->element == 'propal' || $this->element == 'proposal') { + if (!isset($conf->global->PROPOSAL_ALLOW_ONLINESIGN) || !empty($conf->global->PROPOSAL_ALLOW_ONLINESIGN)) { + $setsharekey = true; // feature to make online signature is not set or set to on (default) + } + if (!empty($conf->global->PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) { + $setsharekey = true; + } + } + if ($this->element == 'commande' && !empty($conf->global->ORDER_ALLOW_EXTERNAL_DOWNLOAD)) { + $setsharekey = true; + } + if ($this->element == 'facture' && !empty($conf->global->INVOICE_ALLOW_EXTERNAL_DOWNLOAD)) { + $setsharekey = true; + } + if ($this->element == 'bank_account' && !empty($conf->global->BANK_ACCOUNT_ALLOW_EXTERNAL_DOWNLOAD)) { + $setsharekey = true; + } + if ($this->element == 'contrat' && !empty($conf->global->CONTRACT_ALLOW_EXTERNAL_DOWNLOAD)) { + $setsharekey = true; + } + if ($this->element == 'supplier_proposal' && !empty($conf->global->SUPPLIER_PROPOSAL_ALLOW_EXTERNAL_DOWNLOAD)) { + $setsharekey = true; + } + + if ($setsharekey) { + if (empty($ecmfile->share)) { // Because object not found or share not set yet + require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php'; + $ecmfile->share = getRandomPassword(true); + } + } + + if ($result > 0) { + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content + $ecmfile->fullpath_orig = ''; + $ecmfile->gen_or_uploaded = 'generated'; + $ecmfile->description = ''; // indexed content + $ecmfile->keywords = ''; // keyword content + $result = $ecmfile->update($user); + if ($result < 0) { + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); + return -1; + } + } else { + $ecmfile->entity = $conf->entity; + $ecmfile->filepath = $rel_dir; + $ecmfile->filename = $filename; + $ecmfile->label = md5_file(dol_osencode($destfull)); // hash of file content + $ecmfile->fullpath_orig = ''; + $ecmfile->gen_or_uploaded = 'generated'; + $ecmfile->description = ''; // indexed content + $ecmfile->keywords = ''; // keyword content + $ecmfile->src_object_type = $this->table_element; // $this->table_name is 'myobject' or 'mymodule_myobject'. + $ecmfile->src_object_id = $this->id; + + $result = $ecmfile->create($user); + if ($result < 0) { + setEventMessages($ecmfile->error, $ecmfile->errors, 'warnings'); + return -1; + } + } + + /*$this->result['fullname']=$destfull; + $this->result['filepath']=$ecmfile->filepath; + $this->result['filename']=$ecmfile->filename;*/ + //var_dump($obj->update_main_doc_field);exit; + + if ($update_main_doc_field && !empty($this->table_element)) { + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET last_main_doc = '".$this->db->escape($ecmfile->filepath."/".$ecmfile->filename)."'"; + $sql .= " WHERE rowid = ".((int) $this->id); + + $resql = $this->db->query($sql); + if (!$resql) { + dol_print_error($this->db); + return -1; + } else { + $this->last_main_doc = $ecmfile->filepath.'/'.$ecmfile->filename; + } + } + } + + return 1; + } + /** * Build thumb * @todo Move this into files.lib.php @@ -5565,7 +5608,7 @@ abstract class CommonObject // Request to get translation values for object $sql = "SELECT rowid, property, lang , value"; - $sql .= " FROM ".MAIN_DB_PREFIX."object_lang"; + $sql .= " FROM ".$this->db->prefix()."object_lang"; $sql .= " WHERE type_object = '".$this->db->escape($element)."'"; $sql .= " AND fk_object = ".((int) $this->id); @@ -5770,7 +5813,7 @@ abstract class CommonObject $sql .= ", ".$name; } } - $sql .= " FROM ".MAIN_DB_PREFIX.$table_element."_extrafields"; + $sql .= " FROM ".$this->db->prefix().$table_element."_extrafields"; $sql .= " WHERE fk_object = ".((int) $rowid); //dol_syslog(get_class($this)."::fetch_optionals get extrafields data for ".$this->table_element, LOG_DEBUG); // Too verbose @@ -5844,7 +5887,7 @@ abstract class CommonObject dol_syslog(get_class($this)."::deleteExtraFields delete", LOG_DEBUG); - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".((int) $this->id); + $sql_del = "DELETE FROM ".$this->db->prefix().$table_element."_extrafields WHERE fk_object = ".((int) $this->id); $resql = $this->db->query($sql_del); if (!$resql) { @@ -6044,10 +6087,10 @@ abstract class CommonObject dol_syslog(get_class($this)."::insertExtraFields delete then insert", LOG_DEBUG); - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX.$table_element."_extrafields WHERE fk_object = ".((int) $this->id); + $sql_del = "DELETE FROM ".$this->db->prefix().$table_element."_extrafields WHERE fk_object = ".((int) $this->id); $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$table_element."_extrafields (fk_object"; + $sql = "INSERT INTO ".$this->db->prefix().$table_element."_extrafields (fk_object"; foreach ($new_array_options as $key => $value) { $attributeKey = substr($key, 8); // Remove 'options_' prefix // Add field of attribut @@ -6090,6 +6133,7 @@ abstract class CommonObject } $sql .= ")"; + $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -6194,13 +6238,13 @@ abstract class CommonObject foreach ($new_array_languages as $key => $langcodearray) { // $key = 'name', 'town', ... foreach ($langcodearray as $langcode => $value) { - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."object_lang"; + $sql_del = "DELETE FROM ".$this->db->prefix()."object_lang"; $sql_del .= " WHERE fk_object = ".((int) $this->id)." AND property = '".$this->db->escape($key)."' AND type_object = '".$this->db->escape($table_element)."'"; $sql_del .= " AND lang = '".$this->db->escape($langcode)."'"; $this->db->query($sql_del); if ($value !== '') { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."object_lang (fk_object, property, type_object, lang, value"; + $sql = "INSERT INTO ".$this->db->prefix()."object_lang (fk_object, property, type_object, lang, value"; $sql .= ") VALUES (".$this->id.", '".$this->db->escape($key)."', '".$this->db->escape($table_element)."', '".$this->db->escape($langcode)."', '".$this->db->escape($value)."'"; $sql .= ")"; @@ -6384,7 +6428,7 @@ abstract class CommonObject $linealreadyfound = 0; // Check if there is already a line for this object (in most cases, it is, but sometimes it is not, for example when extra field has been created after), so we must keep this overload) - $sql = "SELECT COUNT(rowid) as nb FROM ".MAIN_DB_PREFIX.$this->table_element."_extrafields WHERE fk_object = ".((int) $this->id); + $sql = "SELECT COUNT(rowid) as nb FROM ".$this->db->prefix().$this->table_element."_extrafields WHERE fk_object = ".((int) $this->id); $resql = $this->db->query($sql); if ($resql) { $tmpobj = $this->db->fetch_object($resql); @@ -6395,9 +6439,9 @@ abstract class CommonObject if ($linealreadyfound) { if ($this->array_options["options_".$key] === null) { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key." = null"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element."_extrafields SET ".$key." = null"; } else { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key." = '".$this->db->escape($this->array_options["options_".$key])."'"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element."_extrafields SET ".$key." = '".$this->db->escape($this->array_options["options_".$key])."'"; } $sql .= " WHERE fk_object = ".((int) $this->id); } else { @@ -6726,7 +6770,7 @@ abstract class CommonObject $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= " FROM ".MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= " FROM ".$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { @@ -6742,7 +6786,7 @@ abstract class CommonObject //We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= " as main, ".MAIN_DB_PREFIX.$InfoFieldList[0]."_extrafields as extra"; + $sql .= " as main, ".$this->db->prefix().$InfoFieldList[0]."_extrafields as extra"; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -6878,7 +6922,7 @@ abstract class CommonObject $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { @@ -6894,7 +6938,7 @@ abstract class CommonObject // We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; + $sql .= ' as main, '.$this->db->prefix().$InfoFieldList[0].'_extrafields as extra'; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -7239,7 +7283,7 @@ abstract class CommonObject } $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -7322,7 +7366,7 @@ abstract class CommonObject } $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -7575,7 +7619,7 @@ abstract class CommonObject } else { return true; } } elseif (in_array($type, array('double', 'real', 'price'))) { // is numeric - if (!$validate->isDuration($fieldValue)) { + if (!$validate->isNumeric($fieldValue)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } @@ -7615,7 +7659,7 @@ abstract class CommonObject $selectkey = $InfoFieldList[2]; } - if (!isInDb($value_arr, $InfoFieldList[0], $selectkey)) { + if (!$validate->isInDb($value_arr, $InfoFieldList[0], $selectkey)) { $this->setFieldError($fieldKey, $validate->error); return false; } else { return true; } @@ -7766,7 +7810,8 @@ abstract class CommonObject } } - $out .= $extrafields->showSeparator($key, $this, ($colspan + 1), $display_type); + // if colspan=0 or 1, the second column is not extended, so the separator must be on 2 columns + $out .= $extrafields->showSeparator($key, $this, ($colspan ? $colspan + 1 : 2), $display_type); } else { $class = (!empty($extrafields->attributes[$this->table_element]['hidden'][$key]) ? 'hideobject ' : ''); $csstyle = ''; @@ -7865,6 +7910,7 @@ abstract class CommonObject $html_id = !empty($this->id) ? $this->element.'_extras_'.$key.'_'.$this->id : ''; if ($display_type == 'card') { + // a first td column was already output (and may be another on before if MAIN_VIEW_LINE_NUMBER set), so this td is the next one $out .= ''; } elseif ($display_type == 'line') { $out .= '
'; @@ -7993,6 +8039,8 @@ abstract class CommonObject $element = $this->element; if ($element == 'facturerec') { $element = 'facture'; + } elseif ($element == 'invoice_supplier_rec') { + return $user->rights->fournisseur->facture; } return $user->rights->{$element}; @@ -8013,7 +8061,7 @@ abstract class CommonObject public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors = 0) { foreach ($tables as $table) { - $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.((int) $dest_id).' WHERE fk_soc = '.((int) $origin_id); + $sql = 'UPDATE '.$db->prefix().$table.' SET fk_soc = '.((int) $dest_id).' WHERE fk_soc = '.((int) $origin_id); if (!$db->query($sql)) { if ($ignoreerrors) { @@ -8100,7 +8148,7 @@ abstract class CommonObject * @param string $sdir Directory to scan (full absolute path) * @param int $size 0=original size, 1='small' use thumbnail if possible * @param int $nbmax Nombre maximum de photos (0=pas de max) - * @param int $nbbyrow Number of image per line or -1 to use div. Used only if size=1. + * @param int $nbbyrow Number of image per line or -1 to use div separator or 0 to use no separator. Used only if size=1 or 'small'. * @param int $showfilename 1=Show filename * @param int $showaction 1=Show icon with action links (resize, delete) * @param int $maxHeight Max height of original image when size='small' (so we can use original even if small requested). If 0, always use 'small' thumb image. @@ -8219,26 +8267,28 @@ abstract class CommonObject $alt = ''; } + $addphotorefcss = 1; + if ($usesharelink) { if ($val['share']) { if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) { $return .= ''; - $return .= ''; + $return .= ''; } else { $return .= ''; - $return .= ''; + $return .= ''; } } else { $return .= ''; - $return .= ''; + $return .= ''; } } else { if (empty($maxHeight) || $photo_vignette && $imgarray['height'] > $maxHeight) { $return .= ''; - $return .= ''; + $return .= ''; } else { $return .= ''; - $return .= ''; + $return .= ''; } } @@ -8735,12 +8785,12 @@ abstract class CommonObject $this->db->begin(); if (!$error) { - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element; $sql .= " (".implode(", ", $keys).')'; $sql .= " VALUES (".implode(", ", $values).")"; // $values can contains 'abc' or 123 $res = $this->db->query($sql); - if ($res === false) { + if (!$res) { $error++; if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->errors[] = "ErrorRefAlreadyExists"; @@ -8751,13 +8801,13 @@ abstract class CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); } // If we have a field ref with a default value of (PROV) if (!$error) { if (key_exists('ref', $this->fields) && $this->fields['ref']['notnull'] > 0 && key_exists('default', $this->fields['ref']) && $this->fields['ref']['default'] == '(PROV)') { - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET ref = '(PROV".((int) $this->id).")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->id); + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET ref = '(PROV".((int) $this->id).")' WHERE (ref = '(PROV)' OR ref = '') AND rowid = ".((int) $this->id); $resqlupdate = $this->db->query($sql); if ($resqlupdate === false) { @@ -8842,7 +8892,7 @@ abstract class CommonObject } $sql = "SELECT ".$fieldlist; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element.' as t'; if (!empty($id)) { $sql .= ' WHERE t.rowid = '.((int) $id); @@ -8897,7 +8947,7 @@ abstract class CommonObject $objectline = new $objectlineclassname($this->db); $sql = "SELECT ".$objectline->getFieldList('l'); - $sql .= " FROM ".MAIN_DB_PREFIX.$objectline->table_element." as l"; + $sql .= " FROM ".$this->db->prefix().$objectline->table_element." as l"; $sql .= " WHERE l.fk_".$this->db->escape($this->element)." = ".((int) $this->id); if ($morewhere) { $sql .= $morewhere; @@ -8987,12 +9037,12 @@ abstract class CommonObject }*/ } - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET '.implode(', ', $tmp).' WHERE rowid='.((int) $this->id); + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET '.implode(', ', $tmp).' WHERE rowid='.((int) $this->id); $this->db->begin(); if (!$error) { $res = $this->db->query($sql); - if ($res === false) { + if (!$res) { $error++; $this->errors[] = $this->db->lasterror(); } @@ -9044,7 +9094,7 @@ abstract class CommonObject if ($forcechilddeletion) { // Force also delete of childtables that should lock deletion in standard case when option force is off foreach ($this->childtables as $table) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table." WHERE ".$this->fk_element." = ".((int) $this->id); + $sql = "DELETE FROM ".$this->db->prefix().$table." WHERE ".$this->fk_element." = ".((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -9098,7 +9148,7 @@ abstract class CommonObject } } else { // Delete record in child table - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$table." WHERE ".$this->fk_element." = ".((int) $this->id); + $sql = "DELETE FROM ".$this->db->prefix().$table." WHERE ".$this->fk_element." = ".((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { @@ -9138,7 +9188,7 @@ abstract class CommonObject } if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element.' WHERE rowid='.((int) $this->id); + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element.' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { @@ -9177,7 +9227,7 @@ abstract class CommonObject if (!empty($parentId) && !empty($parentField)) { $this->db->begin(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE ".$parentField." = ".(int) $parentId; // Manage filters @@ -9262,7 +9312,7 @@ abstract class CommonObject $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element_line; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element_line; $sql .= " WHERE rowid = ".((int) $idline); dol_syslog(get_class($this)."::deleteLineCommon", LOG_DEBUG); @@ -9316,7 +9366,7 @@ abstract class CommonObject $statusfield = 'fk_statut'; } - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql = "UPDATE ".$this->db->prefix().$this->table_element; $sql .= " SET ".$statusfield." = ".((int) $status); $sql .= " WHERE rowid = ".((int) $this->id); @@ -9553,8 +9603,8 @@ abstract class CommonObject require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $categorystatic = new Categorie($this->db); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type])." (fk_categorie, fk_product)"; - $sql .= " SELECT fk_categorie, $toId FROM ".MAIN_DB_PREFIX."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]); + $sql = "INSERT INTO ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type])." (fk_categorie, fk_product)"; + $sql .= " SELECT fk_categorie, $toId FROM ".$this->db->prefix()."categorie_".(empty($categorystatic->MAP_CAT_TABLE[$type]) ? $type : $categorystatic->MAP_CAT_TABLE[$type]); $sql .= " WHERE fk_product = ".((int) $fromId); if (!$this->db->query($sql)) { @@ -9602,8 +9652,8 @@ abstract class CommonObject } // Delete ecm_files extrafields - $sql = "DELETE FROM ".MAIN_DB_PREFIX."ecm_files_extrafields WHERE fk_object IN ("; - $sql .= " SELECT rowid FROM ".MAIN_DB_PREFIX."ecm_files WHERE filename LIKE '".$this->db->escape($this->ref)."%'"; + $sql = "DELETE FROM ".$this->db->prefix()."ecm_files_extrafields WHERE fk_object IN ("; + $sql .= " SELECT rowid FROM ".$this->db->prefix()."ecm_files WHERE filename LIKE '".$this->db->escape($this->ref)."%'"; $sql .= " AND filepath = '".$this->db->escape($element)."/".$this->db->escape($this->ref)."' AND entity = ".((int) $conf->entity); // No need of getEntity here $sql .= ")"; @@ -9614,7 +9664,7 @@ abstract class CommonObject } // Delete ecm_files - $sql = "DELETE FROM ".MAIN_DB_PREFIX."ecm_files"; + $sql = "DELETE FROM ".$this->db->prefix()."ecm_files"; $sql .= " WHERE filename LIKE '".$this->db->escape($this->ref)."%'"; $sql .= " AND filepath = '".$this->db->escape($element)."/".$this->db->escape($this->ref)."' AND entity = ".((int) $conf->entity); // No need of getEntity here @@ -9627,8 +9677,8 @@ abstract class CommonObject // Delete in database with mode 1 if ($mode == 1) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files_extrafields"; - $sql .= " WHERE fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? "" : "@".$this->module))."' AND src_object_id = ".((int) $this->id).")"; + $sql = 'DELETE FROM '.$this->db->prefix()."ecm_files_extrafields"; + $sql .= " WHERE fk_object IN (SELECT rowid FROM ".$this->db->prefix()."ecm_files WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? "" : "@".$this->module))."' AND src_object_id = ".((int) $this->id).")"; $resql = $this->db->query($sql); if (!$resql) { $this->error = $this->db->lasterror(); @@ -9636,7 +9686,7 @@ abstract class CommonObject return false; } - $sql = 'DELETE FROM '.MAIN_DB_PREFIX."ecm_files"; + $sql = 'DELETE FROM '.$this->db->prefix()."ecm_files"; $sql .= " WHERE src_object_type = '".$this->db->escape($this->table_element.(empty($this->module) ? "" : "@".$this->module))."' AND src_object_id = ".((int) $this->id); $resql = $this->db->query($sql); if (!$resql) { diff --git a/htdocs/core/class/commonobjectline.class.php b/htdocs/core/class/commonobjectline.class.php index d93d0b67ff9..487482a9b3c 100644 --- a/htdocs/core/class/commonobjectline.class.php +++ b/htdocs/core/class/commonobjectline.class.php @@ -93,7 +93,7 @@ abstract class CommonObjectLine extends CommonObject $label_type = 'code'; } - $sql = "SELECT ".$label_type.", code from ".MAIN_DB_PREFIX."c_units where rowid = ".((int) $this->fk_unit); + $sql = "SELECT ".$label_type.", code from ".$this->db->prefix()."c_units where rowid = ".((int) $this->fk_unit); $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 581de47178c..c7d01cab586 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -258,7 +258,7 @@ class Conf // Define all global constants into $this->global->key=value $sql = "SELECT ".$db->decrypt('name')." as name,"; $sql .= " ".$db->decrypt('value')." as value, entity"; - $sql .= " FROM ".MAIN_DB_PREFIX."const"; + $sql .= " FROM ".$db->prefix()."const"; $sql .= " WHERE entity IN (0,".$this->entity.")"; $sql .= " ORDER BY entity"; // This is to have entity 0 first, then entity 1 that overwrite. @@ -889,10 +889,6 @@ class Conf $this->global->MAIN_SIZE_SHORTLIST_LIMIT = 3; } - if (!isset($this->global->THEME_HIDE_BORDER_ON_INPUT)) { - $this->global->THEME_HIDE_BORDER_ON_INPUT = 0; - } - // Save inconsistent option if (empty($this->global->AGENDA_USE_EVENT_TYPE) && (!isset($this->global->AGENDA_DEFAULT_FILTER_TYPE) || $this->global->AGENDA_DEFAULT_FILTER_TYPE == 'AC_NON_AUTO')) { $this->global->AGENDA_DEFAULT_FILTER_TYPE = '0'; // 'AC_NON_AUTO' does not exists when AGENDA_DEFAULT_FILTER_TYPE is not on. diff --git a/htdocs/core/class/coreobject.class.php b/htdocs/core/class/coreobject.class.php index 33510186646..91b176f899d 100644 --- a/htdocs/core/class/coreobject.class.php +++ b/htdocs/core/class/coreobject.class.php @@ -183,7 +183,7 @@ class CoreObject extends CommonObject $this->{$className} = array(); - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX.$childTable." WHERE ".$this->fk_element." = ".((int) $this->id); + $sql = "SELECT rowid FROM ".$this->db->prefix().$childTable." WHERE ".$this->fk_element." = ".((int) $this->id); $res = $this->db->query($sql); if ($res) { diff --git a/htdocs/core/class/cproductnature.class.php b/htdocs/core/class/cproductnature.class.php index 5b343b21dbc..d0c8a5d3933 100644 --- a/htdocs/core/class/cproductnature.class.php +++ b/htdocs/core/class/cproductnature.class.php @@ -102,7 +102,7 @@ class CProductNature // extends CommonObject global $conf, $langs; // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."("; + $sql = "INSERT INTO ".$this->db->prefix().$this->table_element."("; $sql .= "rowid,"; $sql .= "code,"; $sql .= "label,"; @@ -125,7 +125,7 @@ class CProductNature // extends CommonObject $this->db->rollback(); return -1; } else { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); $this->db->commit(); return $this->id; } @@ -148,7 +148,7 @@ class CProductNature // extends CommonObject $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; $sql_where = array(); if ($id) { $sql_where[] = " t.rowid = ".((int) $id); @@ -197,12 +197,12 @@ class CProductNature // extends CommonObject dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { @@ -267,7 +267,7 @@ class CProductNature // extends CommonObject global $conf, $langs; // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql = "UPDATE ".$this->db->prefix().$this->table_element." SET"; $sql .= " code=".(isset($this->code) ? ((int) $this->code) : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape(trim($this->label))."'" : "null").","; $sql .= " active=".(isset($this->active) ? ((int) $this->active) : "null"); @@ -302,7 +302,7 @@ class CProductNature // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element; + $sql = "DELETE FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE rowid=".(int) $this->id; $this->db->begin(); diff --git a/htdocs/core/class/cstate.class.php b/htdocs/core/class/cstate.class.php index 2b9b1d6880e..36c3cb2c0fe 100644 --- a/htdocs/core/class/cstate.class.php +++ b/htdocs/core/class/cstate.class.php @@ -106,7 +106,7 @@ class Cstate // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_departements("; + $sql = "INSERT INTO ".$this->db->prefix()."c_departements("; $sql .= "rowid,"; $sql .= "code_departement,"; $sql .= "nom,"; @@ -128,7 +128,7 @@ class Cstate // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_departements"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_departements"); } // Commit or rollback @@ -161,7 +161,7 @@ class Cstate // extends CommonObject $sql .= " t.code_departement,"; $sql .= " t.nom,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_departements as t"; + $sql .= " FROM ".$this->db->prefix()."c_departements as t"; if ($id) { $sql .= " WHERE t.rowid = ".((int) $id); } elseif ($code) { @@ -219,7 +219,7 @@ class Cstate // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_departements SET"; + $sql = "UPDATE ".$this->db->prefix()."c_departements SET"; $sql .= " code_departement=".(isset($this->code_departement) ? "'".$this->db->escape($this->code_departement)."'" : "null").","; $sql .= " nom=".(isset($this->nom) ? "'".$this->db->escape($this->nom)."'" : "null").","; $sql .= " active=".(isset($this->active) ? $this->active : "null").""; @@ -260,7 +260,7 @@ class Cstate // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_departements"; + $sql = "DELETE FROM ".$this->db->prefix()."c_departements"; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); diff --git a/htdocs/core/class/ctypent.class.php b/htdocs/core/class/ctypent.class.php index c8421c54b1f..6de7de7d5cb 100644 --- a/htdocs/core/class/ctypent.class.php +++ b/htdocs/core/class/ctypent.class.php @@ -105,7 +105,7 @@ class Ctypent // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_typent("; + $sql = "INSERT INTO ".$this->db->prefix()."c_typent("; $sql .= "id,"; $sql .= "code,"; @@ -135,7 +135,7 @@ class Ctypent // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_typent"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_typent"); } // Commit or rollback @@ -170,7 +170,7 @@ class Ctypent // extends CommonObject $sql .= " t.fk_country as country_id,"; $sql .= " t.active,"; $sql .= " t.module"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_typent as t"; + $sql .= " FROM ".$this->db->prefix()."c_typent as t"; if ($id) { $sql .= " WHERE t.id = ".((int) $id); } elseif ($code) { @@ -232,7 +232,7 @@ class Ctypent // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_typent SET"; + $sql = "UPDATE ".$this->db->prefix()."c_typent SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " libelle=".(isset($this->libelle) ? "'".$this->db->escape($this->libelle)."'" : "null").","; $sql .= " active=".(isset($this->active) ? $this->active : "null").","; @@ -275,7 +275,7 @@ class Ctypent // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_typent"; + $sql = "DELETE FROM ".$this->db->prefix()."c_typent"; $sql .= " WHERE id=".$this->id; $this->db->begin(); diff --git a/htdocs/core/class/ctyperesource.class.php b/htdocs/core/class/ctyperesource.class.php index 891bf6bea10..32fe3164ad8 100644 --- a/htdocs/core/class/ctyperesource.class.php +++ b/htdocs/core/class/ctyperesource.class.php @@ -99,7 +99,7 @@ class Ctyperesource // Put here code to add control on parameters values // Insert request - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element.'('; + $sql = 'INSERT INTO '.$this->db->prefix().$this->table_element.'('; $sql .= 'code,'; $sql .= 'label'; @@ -125,7 +125,7 @@ class Ctyperesource } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->id = $this->db->last_insert_id($this->db->prefix().$this->table_element); // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. @@ -163,12 +163,12 @@ class Ctyperesource { dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; - $sql .= ' t.rowid,'; + $sql = "SELECT"; + $sql .= " t.rowid,"; $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; if ($id) { $sql .= " WHERE t.id = ".((int) $id); } elseif ($code) { @@ -228,12 +228,12 @@ class Ctyperesource { dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; - $sql .= ' t.rowid,'; + $sql = "SELECT"; + $sql .= " t.rowid,"; $sql .= " t.code,"; $sql .= " t.label,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; // Manage filter $sqlwhere = array(); @@ -307,7 +307,7 @@ class Ctyperesource // Put here code to add a control on parameters values // Update request - $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element.' SET'; + $sql = 'UPDATE '.$this->db->prefix().$this->table_element.' SET'; $sql .= ' code = '.(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").','; $sql .= ' label = '.(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").','; @@ -376,7 +376,7 @@ class Ctyperesource // If you need to delete child tables to, you can insert them here if (!$error) { - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; + $sql = 'DELETE FROM '.$this->db->prefix().$this->table_element; $sql .= ' WHERE rowid='.((int) $this->id); $resql = $this->db->query($sql); diff --git a/htdocs/core/class/cunits.class.php b/htdocs/core/class/cunits.class.php index 7219f901c9f..d7571b8ca90 100644 --- a/htdocs/core/class/cunits.class.php +++ b/htdocs/core/class/cunits.class.php @@ -112,7 +112,7 @@ class CUnits // extends CommonObject // Put here code to add control on parameters values // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."c_units("; + $sql = "INSERT INTO ".$this->db->prefix()."c_units("; $sql .= "rowid,"; $sql .= "code,"; $sql .= "label,"; @@ -138,7 +138,7 @@ class CUnits // extends CommonObject } if (!$error) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."c_units"); + $this->id = $this->db->last_insert_id($this->db->prefix()."c_units"); } // Commit or rollback @@ -178,7 +178,7 @@ class CUnits // extends CommonObject $sql .= " t.unit_type,"; $sql .= " t.scale,"; $sql .= " t.active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_units as t"; + $sql .= " FROM ".$this->db->prefix()."c_units as t"; $sql_where = array(); if ($id) { $sql_where[] = " t.rowid = ".((int) $id); @@ -237,7 +237,7 @@ class CUnits // extends CommonObject dol_syslog(__METHOD__, LOG_DEBUG); - $sql = 'SELECT'; + $sql = "SELECT"; $sql .= " t.rowid,"; $sql .= " t.code,"; $sql .= " t.sortorder,"; @@ -246,7 +246,7 @@ class CUnits // extends CommonObject $sql .= " t.unit_type,"; $sql .= " t.scale,"; $sql .= " t.active"; - $sql .= ' FROM '.MAIN_DB_PREFIX.'c_units as t'; + $sql .= " FROM ".$this->db->prefix()."c_units as t"; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { @@ -343,7 +343,7 @@ class CUnits // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."c_units SET"; + $sql = "UPDATE ".$this->db->prefix()."c_units SET"; $sql .= " code=".(isset($this->code) ? "'".$this->db->escape($this->code)."'" : "null").","; $sql .= " sortorder=".(isset($this->sortorder) ? "'".$this->db->escape($this->sortorder)."'" : "null").","; $sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null").","; @@ -389,7 +389,7 @@ class CUnits // extends CommonObject global $conf, $langs; $error = 0; - $sql = "DELETE FROM ".MAIN_DB_PREFIX."c_units"; + $sql = "DELETE FROM ".$this->db->prefix()."c_units"; $sql .= " WHERE rowid=".((int) $this->id); $this->db->begin(); @@ -471,7 +471,7 @@ class CUnits // extends CommonObject { $base = 10; // TODO : add base col into unit dictionary table - $unit = $this->db->getRow('SELECT scale, unit_type from '.MAIN_DB_PREFIX.'c_units WHERE rowid = '.intval($id)); + $unit = $this->db->getRow("SELECT scale, unit_type from ".$this->db->prefix()."c_units WHERE rowid = ".intval($id)); if ($unit) { // TODO : if base exist in unit dictionary table remove this convertion exception and update convertion infos in database exemple time hour currently scale 3600 will become scale 2 base 60 if ($unit->unit_type == 'time') { diff --git a/htdocs/core/class/defaultvalues.class.php b/htdocs/core/class/defaultvalues.class.php index f6edb58207c..278b5d5e0e6 100644 --- a/htdocs/core/class/defaultvalues.class.php +++ b/htdocs/core/class/defaultvalues.class.php @@ -259,10 +259,10 @@ class DefaultValues extends CommonObject $records = array(); - $sql = 'SELECT '; + $sql = "SELECT "; $sql .= $this->getFieldList(); - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - $sql .= ' WHERE 1 = 1'; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; + $sql .= " WHERE 1 = 1"; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index 46789352bd7..7939965828a 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -139,9 +139,9 @@ class DiscountAbsolute $sql .= " sr.datec,"; $sql .= " f.ref as ref_facture_source, f.type as type_facture_source,"; $sql .= " fsup.ref as ref_invoice_supplier_source, fsup.type as type_invoice_supplier_source"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."facture_fourn as fsup ON sr.fk_invoice_supplier_source = fsup.rowid"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as sr"; + $sql .= " LEFT JOIN ".$this->db->prefix()."facture as f ON sr.fk_facture_source = f.rowid"; + $sql .= " LEFT JOIN ".$this->db->prefix()."facture_fourn as fsup ON sr.fk_invoice_supplier_source = fsup.rowid"; $sql .= " WHERE sr.entity IN (".getEntity('invoice').")"; if ($rowid) { $sql .= " AND sr.rowid = ".((int) $rowid); @@ -251,7 +251,7 @@ class DiscountAbsolute } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except"; + $sql = "INSERT INTO ".$this->db->prefix()."societe_remise_except"; $sql .= " (entity, datec, fk_soc, discount_type, fk_user, description,"; $sql .= " amount_ht, amount_tva, amount_ttc, tva_tx, vat_src_code,"; $sql .= " multicurrency_amount_ht, multicurrency_amount_tva, multicurrency_amount_ttc,"; @@ -267,7 +267,7 @@ class DiscountAbsolute dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_remise_except"); + $this->id = $this->db->last_insert_id($this->db->prefix()."societe_remise_except"); return $this->id; } else { $this->error = $this->db->lasterror().' - sql='.$sql; @@ -289,7 +289,7 @@ class DiscountAbsolute // Check if we can remove the discount if ($this->fk_facture_source) { $sql = "SELECT COUNT(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except"; $sql .= " WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount $sql .= " OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit $sql .= " AND fk_facture_source = ".((int) $this->fk_facture_source); @@ -312,7 +312,7 @@ class DiscountAbsolute // Check if we can remove the discount if ($this->fk_invoice_supplier_source) { $sql = "SELECT COUNT(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except"; $sql .= " WHERE (fk_invoice_supplier_line IS NOT NULL"; // Not used as absolute simple discount $sql .= " OR fk_invoice_supplier IS NOT NULL)"; // Not used as credit note and not used as deposit $sql .= " AND fk_invoice_supplier_source = ".((int) $this->fk_invoice_supplier_source); @@ -335,7 +335,7 @@ class DiscountAbsolute $this->db->begin(); // Delete but only if not used - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except "; + $sql = "DELETE FROM ".$this->db->prefix()."societe_remise_except "; if ($this->fk_facture_source) { $sql .= " WHERE fk_facture_source = ".((int) $this->fk_facture_source); // Delete all lines of same serie } elseif ($this->fk_invoice_supplier_source) { @@ -353,7 +353,7 @@ class DiscountAbsolute if ($result) { // If source of discount was a credit note or deposit, we change source statut. if ($this->fk_facture_source) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture"; + $sql = "UPDATE ".$this->db->prefix()."facture"; $sql .= " set paye=0, fk_statut=1"; $sql .= " WHERE (type = 2 or type = 3) AND rowid = ".((int) $this->fk_facture_source); @@ -368,7 +368,7 @@ class DiscountAbsolute return -1; } } elseif ($this->fk_invoice_supplier_source) { - $sql = "UPDATE ".MAIN_DB_PREFIX."facture_fourn"; + $sql = "UPDATE ".$this->db->prefix()."facture_fourn"; $sql .= " set paye=0, fk_statut=1"; $sql .= " WHERE (type = 2 or type = 3) AND rowid = ".((int) $this->fk_invoice_supplier_source); @@ -418,7 +418,7 @@ class DiscountAbsolute return -2; } - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; + $sql = "UPDATE ".$this->db->prefix()."societe_remise_except"; if (!empty($this->discount_type)) { if ($rowidline) { $sql .= " SET fk_invoice_supplier_line = ".((int) $rowidline); @@ -464,7 +464,7 @@ class DiscountAbsolute public function unlink_invoice() { // phpcs:enable - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except"; + $sql = "UPDATE ".$this->db->prefix()."societe_remise_except"; if (!empty($this->discount_type)) { $sql .= " SET fk_invoice_supplier_line = NULL, fk_invoice_supplier = NULL"; } else { @@ -501,7 +501,7 @@ class DiscountAbsolute dol_syslog(get_class($this)."::getAvailableDiscounts discount_type=".$discount_type, LOG_DEBUG); $sql = "SELECT SUM(rc.amount_ttc) as amount, SUM(rc.multicurrency_amount_ttc) as multicurrency_amount"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc"; $sql .= " WHERE rc.entity = ".$conf->entity; $sql .= " AND rc.discount_type=".((int) $discount_type); if (!empty($discount_type)) { @@ -553,15 +553,15 @@ class DiscountAbsolute dol_syslog(get_class($this)."::getSumDepositsUsed", LOG_DEBUG); if ($invoice->element == 'facture' || $invoice->element == 'invoice') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; - $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $invoice->id); - $sql .= ' AND f.type = 3'; + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc, ".$this->db->prefix()."facture as f"; + $sql .= " WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = ".((int) $invoice->id); + $sql .= " AND f.type = 3"; } elseif ($invoice->element == 'invoice_supplier') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; - $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $invoice->id); - $sql .= ' AND f.type = 3'; + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc, ".$this->db->prefix()."facture_fourn as f"; + $sql .= " WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = ".((int) $invoice->id); + $sql .= " AND f.type = 3"; } else { $this->error = get_class($this)."::getSumDepositsUsed was called with a bad object as a first parameter"; dol_print_error($this->error); @@ -594,15 +594,15 @@ class DiscountAbsolute dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG); if ($invoice->element == 'facture' || $invoice->element == 'invoice') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture as f'; - $sql .= ' WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = '.((int) $invoice->id); - $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE.", ".$invoice::TYPE_SITUATION).')'; // Find discount coming from credit note or excess received + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc, ".$this->db->prefix()."facture as f"; + $sql .= " WHERE rc.fk_facture_source=f.rowid AND rc.fk_facture = ".((int) $invoice->id); + $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE.", ".$invoice::TYPE_SITUATION).")"; // Find discount coming from credit note or excess received } elseif ($invoice->element == 'invoice_supplier') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc, '.MAIN_DB_PREFIX.'facture_fourn as f'; - $sql .= ' WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = '.((int) $invoice->id); - $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE).')'; // Find discount coming from credit note or excess paid + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc, ".$this->db->prefix()."facture_fourn as f"; + $sql .= " WHERE rc.fk_invoice_supplier_source=f.rowid AND rc.fk_invoice_supplier = ".((int) $invoice->id); + $sql .= " AND f.type IN (".$this->db->sanitize($invoice::TYPE_STANDARD.", ".$invoice::TYPE_CREDIT_NOTE).")"; // Find discount coming from credit note or excess paid } else { $this->error = get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; dol_print_error($this->error); @@ -634,13 +634,13 @@ class DiscountAbsolute dol_syslog(get_class($this)."::getSumCreditNotesUsed", LOG_DEBUG); if ($invoice->element == 'facture' || $invoice->element == 'invoice') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc'; - $sql .= ' WHERE rc.fk_facture IS NULL AND rc.fk_facture_source = '.((int) $invoice->id); + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc"; + $sql .= " WHERE rc.fk_facture IS NULL AND rc.fk_facture_source = ".((int) $invoice->id); } elseif ($invoice->element == 'invoice_supplier') { - $sql = 'SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_remise_except as rc'; - $sql .= ' WHERE rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_source = '.((int) $invoice->id); + $sql = "SELECT sum(rc.amount_ttc) as amount, sum(rc.multicurrency_amount_ttc) as multicurrency_amount"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as rc"; + $sql .= " WHERE rc.fk_invoice_supplier IS NULL AND rc.fk_invoice_supplier_source = ".((int) $invoice->id); } else { $this->error = get_class($this)."::getSumCreditNotesUsed was called with a bad object as a first parameter"; dol_print_error($this->error); diff --git a/htdocs/core/class/doleditor.class.php b/htdocs/core/class/doleditor.class.php index 92761109afa..927674942e7 100644 --- a/htdocs/core/class/doleditor.class.php +++ b/htdocs/core/class/doleditor.class.php @@ -156,7 +156,7 @@ class DolEditor $skin = 'moono-lisa'; // default with ckeditor 4.6 : moono-lisa } - $pluginstodisable = 'flash'; + $pluginstodisable = 'elementspath,save,flash'; if (!empty($conf->dol_optimize_smallscreen)) { $pluginstodisable .= ',scayt,wsc,find,undo'; } diff --git a/htdocs/core/class/dolreceiptprinter.class.php b/htdocs/core/class/dolreceiptprinter.class.php index 2062f1b351c..7653fd24437 100644 --- a/htdocs/core/class/dolreceiptprinter.class.php +++ b/htdocs/core/class/dolreceiptprinter.class.php @@ -61,6 +61,7 @@ * Replaced by month number * Replaced by day number * Replaced by day number + * Replaced by current date * Replaced by object id * Replaced by object ref * Replaced by customer firstname @@ -186,6 +187,7 @@ class dolReceiptPrinter extends Printer 'dol_value_month' => 'DOL_VALUE_MONTH', 'dol_value_day' => 'DOL_VALUE_DAY', 'dol_value_day_letters' => 'DOL_VALUE_DAY', + 'dol_value_currentdate' => 'DOL_VALUE_CURRENTDATE', 'dol_print_payment' => 'DOL_PRINT_PAYMENT', 'dol_print_logo' => 'DOL_PRINT_LOGO', 'dol_print_logo_old' => 'DOL_PRINT_LOGO_OLD', @@ -221,6 +223,7 @@ class dolReceiptPrinter extends Printer 'dol_value_mysoc_idprof6' => 'ProfId6', 'dol_value_mysoc_tva_intra' => 'VATIntra', 'dol_value_mysoc_capital' => 'Capital', + 'dol_value_mysoc_url' => 'Web', 'dol_value_vendor_lastname' => 'VendorLastname', 'dol_value_vendor_firstname' => 'VendorFirstname', 'dol_value_vendor_mail' => 'VendorEmail', @@ -239,9 +242,9 @@ class dolReceiptPrinter extends Printer $error = 0; $line = 0; $obj = array(); - $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt'; - $sql .= ' WHERE entity = '.$conf->entity; + $sql = "SELECT rowid, name, fk_type, fk_profile, parameter"; + $sql .= " FROM ".$this->db->prefix()."printer_receipt"; + $sql .= " WHERE entity = ".$conf->entity; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -307,9 +310,9 @@ class dolReceiptPrinter extends Printer $error = 0; $line = 0; $obj = array(); - $sql = 'SELECT rowid, name, template'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; - $sql .= ' WHERE entity = '.$conf->entity; + $sql = "SELECT rowid, name, template"; + $sql .= " FROM ".$this->db->prefix()."printer_receipt_template"; + $sql .= " WHERE entity = ".$conf->entity; $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -388,7 +391,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt"; + $sql = "INSERT INTO ".$this->db->prefix()."printer_receipt"; $sql .= " (name, fk_type, fk_profile, parameter, entity)"; $sql .= " VALUES ('".$this->db->escape($name)."', ".((int) $type).", ".((int) $profile).", '".$this->db->escape($parameter)."', ".((int) $conf->entity).")"; $resql = $this->db->query($sql); @@ -414,7 +417,7 @@ class dolReceiptPrinter extends Printer global $conf; $error = 0; - $sql = "UPDATE ".MAIN_DB_PREFIX."printer_receipt"; + $sql = "UPDATE ".$this->db->prefix()."printer_receipt"; $sql .= " SET name='".$this->db->escape($name)."'"; $sql .= ", fk_type=".((int) $type); $sql .= ", fk_profile=".((int) $profile); @@ -439,7 +442,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt'; + $sql = 'DELETE FROM '.$this->db->prefix().'printer_receipt'; $sql .= ' WHERE rowid='.((int) $printerid); $resql = $this->db->query($sql); if (!$resql) { @@ -460,7 +463,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = "INSERT INTO ".MAIN_DB_PREFIX."printer_receipt_template"; + $sql = "INSERT INTO ".$this->db->prefix()."printer_receipt_template"; $sql .= " (name, template, entity) VALUES ('".$this->db->escape($name)."'"; $sql .= ", '".$this->db->escape($template)."', ".$conf->entity.")"; $resql = $this->db->query($sql); @@ -481,7 +484,7 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; + $sql = 'DELETE FROM '.$this->db->prefix().'printer_receipt_template'; $sql .= " WHERE rowid = ".((int) $templateid); $sql .= " AND entity = ".$conf->entity; $resql = $this->db->query($sql); @@ -505,7 +508,7 @@ class dolReceiptPrinter extends Printer global $conf; $error = 0; - $sql = "UPDATE ".MAIN_DB_PREFIX."printer_receipt_template"; + $sql = "UPDATE ".$this->db->prefix()."printer_receipt_template"; $sql .= " SET name='".$this->db->escape($name)."'"; $sql .= ", template='".$this->db->escape($template)."'"; $sql .= " WHERE rowid=".((int) $templateid); @@ -584,6 +587,7 @@ class dolReceiptPrinter extends Printer $this->template = str_replace('{dol_value_month}', dol_print_date($object->date, '%m'), $this->template); $this->template = str_replace('{dol_value_day}', dol_print_date($object->date, '%d'), $this->template); $this->template = str_replace('{dol_value_day_letters}', $langs->trans("Day".dol_print_date($object->date, '%m')[1]), $this->template); + $this->template = str_replace('{dol_value_currentdate}', dol_print_date(dol_now(), 'dayhour'), $this->template); $this->template = str_replace('{dol_value_customer_firstname}', $object->thirdparty->firstname, $this->template); $this->template = str_replace('{dol_value_customer_lastname}', $object->thirdparty->lastname, $this->template); @@ -607,6 +611,7 @@ class dolReceiptPrinter extends Printer $this->template = str_replace('{dol_value_mysoc_idprof6}', $mysoc->idprof6, $this->template); $this->template = str_replace('{dol_value_mysoc_tva_intra}', $mysoc->tva_intra, $this->template); $this->template = str_replace('{dol_value_mysoc_capital}', $mysoc->capital, $this->template); + $this->template = str_replace('{dol_value_mysoc_url}', $mysoc->url, $this->template); $this->template = str_replace('{dol_value_vendor_firstname}', $user->firstname, $this->template); $this->template = str_replace('{dol_value_vendor_lastname}', $user->lastname, $this->template); @@ -672,9 +677,9 @@ class dolReceiptPrinter extends Printer $vatarray[$line->tva_tx] += $line->total_tva; } foreach ($vatarray as $vatkey => $vatvalue) { - $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12; - $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); - $this->printer->text($spaces.$vatkey.'% '.str_pad(price($vatvalue), 10, ' ', STR_PAD_LEFT)."\n"); + $spacestoadd = $nbcharactbyline - strlen($vatkey) - 12; + $spaces = str_repeat(' ', $spacestoadd > 0 ? $spacestoadd : 0); + $this->printer->text($spaces.$vatkey.'% '.str_pad(price($vatvalue), 10, ' ', STR_PAD_LEFT)."\n"); } break; case 'DOL_PRINT_OBJECT_TAX1': @@ -802,8 +807,8 @@ class dolReceiptPrinter extends Printer case 'DOL_PRINT_PAYMENT': $sql = "SELECT p.pos_change as pos_change, p.datep as date, p.fk_paiement, p.num_paiement as num, pf.amount as amount, pf.multicurrency_amount,"; $sql .= " cp.code"; - $sql .= " FROM ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p"; - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_paiement as cp ON p.fk_paiement = cp.id"; + $sql .= " FROM ".$this->db->prefix()."paiement_facture as pf, ".$this->db->prefix()."paiement as p"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_paiement as cp ON p.fk_paiement = cp.id"; $sql .= " WHERE pf.fk_paiement = p.rowid AND pf.fk_facture = ".((int) $object->id); $sql .= " ORDER BY p.datep"; $resql = $this->db->query($sql); @@ -829,7 +834,7 @@ class dolReceiptPrinter extends Printer } break; case 'DOL_VALUE_PLACE': - $sql = "SELECT floor, label FROM ".MAIN_DB_PREFIX."takepos_floor_tables where rowid=".((int) str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $object->ref))); + $sql = "SELECT floor, label FROM ".$this->db->prefix()."takepos_floor_tables where rowid=".((int) str_replace(")", "", str_replace("(PROV-POS".$_SESSION["takeposterminal"]."-", "", $object->ref))); $resql = $this->db->query($sql); $obj = $this->db->fetch_object($resql); if ($obj) { @@ -868,10 +873,10 @@ class dolReceiptPrinter extends Printer { global $conf; $error = 0; - $sql = 'SELECT template'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt_template'; - $sql .= ' WHERE rowid = '.((int) $templateid); - $sql .= ' AND entity = '.$conf->entity; + $sql = "SELECT template"; + $sql .= " FROM ".$this->db->prefix()."printer_receipt_template"; + $sql .= " WHERE rowid = ".((int) $templateid); + $sql .= " AND entity = ".$conf->entity; $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_array($resql); @@ -905,10 +910,10 @@ class dolReceiptPrinter extends Printer return; } $error = 0; - $sql = 'SELECT rowid, name, fk_type, fk_profile, parameter'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'printer_receipt'; - $sql .= ' WHERE rowid = '.((int) $printerid); - $sql .= ' AND entity = '.((int) $conf->entity); + $sql = "SELECT rowid, name, fk_type, fk_profile, parameter"; + $sql .= " FROM ".$this->db->prefix()."printer_receipt"; + $sql .= " WHERE rowid = ".((int) $printerid); + $sql .= " AND entity = ".((int) $conf->entity); $resql = $this->db->query($sql); if ($resql) { $obj = $this->db->fetch_array($resql); diff --git a/htdocs/core/class/emailsenderprofile.class.php b/htdocs/core/class/emailsenderprofile.class.php index bb47e71aea8..517fc953830 100644 --- a/htdocs/core/class/emailsenderprofile.class.php +++ b/htdocs/core/class/emailsenderprofile.class.php @@ -347,36 +347,17 @@ class EmailSenderProfile extends CommonObject */ public function info($id) { - $sql = 'SELECT rowid, date_creation as datec, tms as datem,'; - $sql .= ' fk_user_creat, fk_user_modif'; - $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; - $sql .= ' WHERE t.rowid = '.((int) $id); + $sql = "SELECT rowid, date_creation as datec, tms as datem"; + $sql .= " FROM ".$this->db->prefix().$this->table_element." as t"; + $sql .= " WHERE t.rowid = ".((int) $id); $result = $this->db->query($sql); if ($result) { if ($this->db->num_rows($result)) { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; - if ($obj->fk_user_author) { - $cuser = new User($this->db); - $cuser->fetch($obj->fk_user_author); - $this->user_creation = $cuser; - } - - if ($obj->fk_user_valid) { - $vuser = new User($this->db); - $vuser->fetch($obj->fk_user_valid); - $this->user_validation = $vuser; - } - - if ($obj->fk_user_cloture) { - $cluser = new User($this->db); - $cluser->fetch($obj->fk_user_cloture); - $this->user_cloture = $cluser; - } $this->date_creation = $this->db->jdate($obj->datec); $this->date_modification = $this->db->jdate($obj->datem); - $this->date_validation = $this->db->jdate($obj->datev); } $this->db->free($result); diff --git a/htdocs/core/class/events.class.php b/htdocs/core/class/events.class.php index c8799ebbd5e..104f1567d44 100644 --- a/htdocs/core/class/events.class.php +++ b/htdocs/core/class/events.class.php @@ -152,7 +152,7 @@ class Events // extends CommonObject } // Insert request - $sql = "INSERT INTO ".MAIN_DB_PREFIX."events("; + $sql = "INSERT INTO ".$this->db->prefix()."events("; $sql .= "type,"; $sql .= "entity,"; $sql .= "ip,"; @@ -175,7 +175,7 @@ class Events // extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."events"); + $this->id = $this->db->last_insert_id($this->db->prefix()."events"); return $this->id; } else { $this->error = "Error ".$this->db->lasterror(); @@ -202,7 +202,7 @@ class Events // extends CommonObject // Put here code to add control on parameters values // Update request - $sql = "UPDATE ".MAIN_DB_PREFIX."events SET"; + $sql = "UPDATE ".$this->db->prefix()."events SET"; $sql .= " type='".$this->db->escape($this->type)."',"; $sql .= " dateevent='".$this->db->idate($this->dateevent)."',"; $sql .= " description='".$this->db->escape($this->description)."'"; @@ -237,7 +237,7 @@ class Events // extends CommonObject $sql .= " t.ip,"; $sql .= " t.user_agent,"; $sql .= " t.prefix_session"; - $sql .= " FROM ".MAIN_DB_PREFIX."events as t"; + $sql .= " FROM ".$this->db->prefix()."events as t"; $sql .= " WHERE t.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -274,7 +274,7 @@ class Events // extends CommonObject */ public function delete($user) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."events"; + $sql = "DELETE FROM ".$this->db->prefix()."events"; $sql .= " WHERE rowid=".((int) $this->id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 56b81dd5114..abd2c7dd502 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -265,10 +265,10 @@ class ExtraFields 'default' => $default_value ); - $result = $this->db->DDLAddField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); + $result = $this->db->DDLAddField($this->db->prefix().$table, $attrname, $field_desc); if ($result > 0) { if ($unique) { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; + $sql = "ALTER TABLE ".$this->db->prefix().$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; $resql = $this->db->query($sql, 1, 'dml'); } return 1; @@ -353,7 +353,7 @@ class ExtraFields $params = ''; } - $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; + $sql = "INSERT INTO ".$this->db->prefix()."extrafields("; $sql .= " name,"; $sql .= " label,"; $sql .= " type,"; @@ -447,7 +447,7 @@ class ExtraFields if (!$error) { $sql = "SELECT COUNT(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; + $sql .= " FROM ".$this->db->prefix()."extrafields"; $sql .= " WHERE elementtype = '".$this->db->escape($elementtype)."'"; $sql .= " AND name = '".$this->db->escape($attrname)."'"; //$sql.= " AND entity IN (0,".$conf->entity.")"; Do not test on entity here. We want to see if there is still on field remaning in other entities before deleting field in table @@ -455,7 +455,7 @@ class ExtraFields if ($resql) { $obj = $this->db->fetch_object($resql); if ($obj->nb <= 0) { - $result = $this->db->DDLDropField(MAIN_DB_PREFIX.$table, $attrname); // This also drop the unique key + $result = $this->db->DDLDropField($this->db->prefix().$table, $attrname); // This also drop the unique key if ($result < 0) { $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); @@ -492,7 +492,7 @@ class ExtraFields } if (isset($attrname) && $attrname != '' && preg_match("/^\w[a-zA-Z0-9-_]*$/", $attrname)) { - $sql = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; + $sql = "DELETE FROM ".$this->db->prefix()."extrafields"; $sql .= " WHERE name = '".$this->db->escape($attrname)."'"; $sql .= " AND entity IN (0,".$conf->entity.')'; $sql .= " AND elementtype = '".$this->db->escape($elementtype)."'"; @@ -597,7 +597,7 @@ class ExtraFields } if ($type != 'separate') { // No table update when separate type - $result = $this->db->DDLUpdateField(MAIN_DB_PREFIX.$table, $attrname, $field_desc); + $result = $this->db->DDLUpdateField($this->db->prefix().$table, $attrname, $field_desc); } if ($result > 0 || $type == 'separate') { if ($label) { @@ -606,9 +606,9 @@ class ExtraFields if ($result > 0) { $sql = ''; if ($unique) { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; + $sql = "ALTER TABLE ".$this->db->prefix().$table." ADD UNIQUE INDEX uk_".$table."_".$attrname." (".$attrname.")"; } else { - $sql = "ALTER TABLE ".MAIN_DB_PREFIX.$table." DROP INDEX uk_".$table."_".$attrname; + $sql = "ALTER TABLE ".$this->db->prefix().$table." DROP INDEX uk_".$table."_".$attrname; } dol_syslog(get_class($this).'::update', LOG_DEBUG); $resql = $this->db->query($sql, 1, 'dml'); @@ -699,20 +699,20 @@ class ExtraFields if ($entity === '' || $entity != '0') { // We dont want on all entities, we delete all and current - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; + $sql_del = "DELETE FROM ".$this->db->prefix()."extrafields"; $sql_del .= " WHERE name = '".$this->db->escape($attrname)."'"; $sql_del .= " AND entity IN (0, ".($entity === '' ? $conf->entity : $entity).")"; $sql_del .= " AND elementtype = '".$this->db->escape($elementtype)."'"; } else { // We want on all entities ($entities = '0'), we delete on all only (we keep setup specific to each entity) - $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."extrafields"; + $sql_del = "DELETE FROM ".$this->db->prefix()."extrafields"; $sql_del .= " WHERE name = '".$this->db->escape($attrname)."'"; $sql_del .= " AND entity = 0"; $sql_del .= " AND elementtype = '".$this->db->escape($elementtype)."'"; } $resql1 = $this->db->query($sql_del); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."extrafields("; + $sql = "INSERT INTO ".$this->db->prefix()."extrafields("; $sql .= " name,"; // This is code $sql .= " entity,"; $sql .= " label,"; @@ -804,15 +804,12 @@ class ExtraFields if ($elementtype == 'order_supplier') { $elementtype = 'commande_fournisseur'; } - if ($elementtype == 'stock_mouvement') { - $elementtype = 'movement'; - } $array_name_label = array(); // We should not have several time this request. If we have, there is some optimization to do by calling a simple $extrafields->fetch_optionals() in top of code and not into subcode $sql = "SELECT rowid, name, label, type, size, elementtype, fieldunique, fieldrequired, param, pos, alwayseditable, perms, langs, list, printable, totalizable, fielddefault, fieldcomputed, entity, enabled, help"; - $sql .= " FROM ".MAIN_DB_PREFIX."extrafields"; + $sql .= " FROM ".$this->db->prefix()."extrafields"; //$sql.= " WHERE entity IN (0,".$conf->entity.")"; // Filter is done later if ($elementtype) { $sql .= " WHERE elementtype = '".$this->db->escape($elementtype)."'"; // Filed with object->table_element @@ -925,6 +922,7 @@ class ExtraFields // Old usage $label = $this->attribute_label[$key]; $type = $this->attribute_type[$key]; + $list = $this->attribute_list[$key]; $hidden = (empty($list) ? 1 : 0); // If empty, we are sure it is hidden, otherwise we show. If it depends on mode (view/create/edit form or list, this must be filtered by caller) } @@ -1138,7 +1136,7 @@ class ExtraFields $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use curent entity filter if (strpos($InfoFieldList[4], '$ENTITY$') !== false) { @@ -1157,7 +1155,7 @@ class ExtraFields } //We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; + $sql .= ' as main, '.$this->db->prefix().$InfoFieldList[0].'_extrafields as extra'; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -1306,7 +1304,7 @@ class ExtraFields $sqlwhere = ''; $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4])) { // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$') !== false) { @@ -1369,7 +1367,7 @@ class ExtraFields // We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra.') !== false) { - $sql .= ' as main, '.MAIN_DB_PREFIX.$InfoFieldList[0].'_extrafields as extra'; + $sql .= ' as main, '.$this->db->prefix().$InfoFieldList[0].'_extrafields as extra'; $sqlwhere .= " WHERE extra.fk_object=main.".$InfoFieldList[2]." AND ".$InfoFieldList[4]; } else { $sqlwhere .= " WHERE ".$InfoFieldList[4]; @@ -1594,7 +1592,7 @@ class ExtraFields } $sql = "SELECT ".$keyList; - $sql .= ' FROM '.MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= ' FROM '.$this->db->prefix().$InfoFieldList[0]; if (!empty($InfoFieldList[4]) && strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -1698,7 +1696,7 @@ class ExtraFields } $sql = "SELECT ".$keyList; - $sql .= " FROM ".MAIN_DB_PREFIX.$InfoFieldList[0]; + $sql .= " FROM ".$this->db->prefix().$InfoFieldList[0]; if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main'; } @@ -1946,8 +1944,8 @@ class ExtraFields if (!empty($onlykey) && $onlykey != '@GETPOSTISSET' && $key != $onlykey) { continue; } - if (!empty($onlykey) && $onlykey == '@GETPOSTISSET' && !GETPOSTISSET('options_'.$key) && $this->attributes[$object->table_element]['type'][$key] != 'boolean') { - //when unticking boolean field, it's not set in POST + + if (!empty($onlykey) && $onlykey == '@GETPOSTISSET' && !GETPOSTISSET('options_'.$key) && (! in_array($this->attributes[$object->table_element]['type'][$key], array('boolean', 'chkbxlst')))) { continue; } diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 0edae298f46..772c67ff282 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -134,7 +134,7 @@ class Fiscalyear extends CommonObject $this->db->begin(); - $sql = "INSERT INTO ".MAIN_DB_PREFIX."accounting_fiscalyear ("; + $sql = "INSERT INTO ".$this->db->prefix()."accounting_fiscalyear ("; $sql .= "label"; $sql .= ", date_start"; $sql .= ", date_end"; @@ -155,7 +155,7 @@ class Fiscalyear extends CommonObject dol_syslog(get_class($this)."::create", LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."accounting_fiscalyear"); + $this->id = $this->db->last_insert_id($this->db->prefix()."accounting_fiscalyear"); $result = $this->update($user); if ($result > 0) { @@ -191,7 +191,7 @@ class Fiscalyear extends CommonObject $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX."accounting_fiscalyear"; + $sql = "UPDATE ".$this->db->prefix()."accounting_fiscalyear"; $sql .= " SET label = '".$this->db->escape($this->label)."'"; $sql .= ", date_start = '".$this->db->idate($this->date_start)."'"; $sql .= ", date_end = ".($this->date_end ? "'".$this->db->idate($this->date_end)."'" : "null"); @@ -221,7 +221,7 @@ class Fiscalyear extends CommonObject public function fetch($id) { $sql = "SELECT rowid, label, date_start, date_end, statut"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_fiscalyear"; + $sql .= " FROM ".$this->db->prefix()."accounting_fiscalyear"; $sql .= " WHERE rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch", LOG_DEBUG); @@ -253,7 +253,7 @@ class Fiscalyear extends CommonObject { $this->db->begin(); - $sql = "DELETE FROM ".MAIN_DB_PREFIX."accounting_fiscalyear WHERE rowid = ".((int) $id); + $sql = "DELETE FROM ".$this->db->prefix()."accounting_fiscalyear WHERE rowid = ".((int) $id); dol_syslog(get_class($this)."::delete", LOG_DEBUG); $result = $this->db->query($sql); @@ -414,10 +414,10 @@ class Fiscalyear extends CommonObject */ public function info($id) { - $sql = 'SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,'; - $sql .= ' fy.tms'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'accounting_fiscalyear as fy'; - $sql .= ' WHERE fy.rowid = '.((int) $id); + $sql = "SELECT fy.rowid, fy.datec, fy.fk_user_author, fy.fk_user_modif,"; + $sql .= " fy.tms"; + $sql .= " FROM ".$this->db->prefix()."accounting_fiscalyear as fy"; + $sql .= " WHERE fy.rowid = ".((int) $id); dol_syslog(get_class($this)."::fetch info", LOG_DEBUG); $result = $this->db->query($sql); @@ -464,7 +464,7 @@ class Fiscalyear extends CommonObject } $sql = "SELECT count(DISTINCT piece_num) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; + $sql .= " FROM ".$this->db->prefix()."accounting_bookkeeping"; $sql .= " WHERE entity IN (".getEntity('bookkeeping', 0).")"; $sql .= " AND doc_date >= '".$this->db->idate($datestart)."' and doc_date <= '".$this->db->idate($dateend)."'"; @@ -498,7 +498,7 @@ class Fiscalyear extends CommonObject } $sql = "SELECT count(rowid) as nb"; - $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping "; + $sql .= " FROM ".$this->db->prefix()."accounting_bookkeeping "; $sql .= " WHERE entity IN (".getEntity('bookkeeping', 0).")"; $sql .= " AND doc_date >= '".$this->db->idate($datestart)."' and doc_date <= '".$this->db->idate($dateend)."'"; diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index d1b1e08710e..a40ec3e30c3 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -111,7 +111,7 @@ class HookManager if (in_array($context, $arrayhooks) || in_array('all', $arrayhooks)) { // We instantiate action class only if initialized hook is handled by module // Include actions class overwriting hooks - if (empty($this->hooks[$context][$module]) || !is_object($this->hooks[$context][$module])) { // If set to an object value, class was already loaded + if (empty($this->hooks[$context][$module]) || !is_object($this->hooks[$context][$module])) { // If set to an object value, class was already loaded so we do nothing. $path = '/'.$module.'/class/'; $actionfile = 'actions_'.$module.'.class.php'; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 1d63bbaf332..3375e9f7cc4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -204,7 +204,7 @@ class Form */ public function editfieldval($text, $htmlname, $value, $object, $perm, $typeofdata = 'string', $editvalue = '', $extObject = null, $custommsg = null, $moreparam = '', $notabletag = 0, $formatfunc = '', $paramid = 'id') { - global $conf, $langs, $db; + global $conf, $langs; $ret = ''; @@ -886,7 +886,7 @@ class Form $atleastonefavorite = 0; $sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite, eec"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_country"; + $sql .= " FROM ".$this->db->prefix()."c_country"; $sql .= " WHERE active > 0"; //$sql.= " ORDER BY code ASC"; @@ -1009,7 +1009,7 @@ class Form $incotermArray = array(); $sql = "SELECT rowid, code"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_incoterms"; + $sql .= " FROM ".$this->db->prefix()."c_incoterms"; $sql .= " WHERE active > 0"; $sql .= " ORDER BY code ASC"; @@ -1088,7 +1088,7 @@ class Form public function select_type_of_lines($selected = '', $htmlname = 'type', $showempty = 0, $hidetext = 0, $forceall = 0) { // phpcs:enable - global $db, $langs, $user, $conf; + global $langs, $conf; // If product & services are enabled or both disabled. if ($forceall == 1 || (empty($forceall) && !empty($conf->product->enabled) && !empty($conf->service->enabled)) @@ -1155,7 +1155,7 @@ class Form $langs->load("trips"); $sql = "SELECT c.code, c.label"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; + $sql .= " FROM ".$this->db->prefix()."c_type_fees as c"; $sql .= " WHERE active > 0"; $resql = $this->db->query($sql); @@ -1344,12 +1344,12 @@ class Form $sql .= ", s.address, s.zip, s.town"; $sql .= ", dictp.code as country_code"; } - $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sql .= " FROM ".$this->db->prefix()."societe as s"; if (!empty($conf->global->COMPANY_SHOW_ADDRESS_SELECTLIST)) { - $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as dictp ON dictp.rowid = s.fk_pays"; + $sql .= " LEFT JOIN ".$this->db->prefix()."c_country as dictp ON dictp.rowid = s.fk_pays"; } if (empty($user->rights->societe->client->voir) && !$user->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } $sql .= " WHERE s.entity IN (".getEntity('societe').")"; if (!empty($user->socid)) { @@ -1523,7 +1523,7 @@ class Form // On recherche les remises $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql .= " re.description, re.fk_facture_source"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re"; + $sql .= " FROM ".$this->db->prefix()."societe_remise_except as re"; $sql .= " WHERE re.fk_soc = ".(int) $socid; $sql .= " AND re.entity = ".$conf->entity; if ($filter) { @@ -1668,9 +1668,9 @@ class Form if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) { $sql .= ", s.nom as company, s.town AS company_town"; } - $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; + $sql .= " FROM ".$this->db->prefix()."socpeople as sp"; if ($showsoc > 0 || !empty($conf->global->CONTACT_SHOW_EMAIL_PHONE_TOWN_SELECTLIST)) { - $sql .= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid=sp.fk_soc"; + $sql .= " LEFT OUTER JOIN ".$this->db->prefix()."societe as s ON s.rowid=sp.fk_soc"; } $sql .= " WHERE sp.entity IN (".getEntity('socpeople').")"; if ($socid > 0 || $socid == -1) { @@ -1690,11 +1690,16 @@ class Form $out .= 'global->PRODUCT_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />'; + $out .= 'global->PRODUCT_SEARCH_AUTOFOCUS) ? 'autofocus' : '').' />'; if ($hidelabel == 3) { $out .= img_picto($langs->trans("Search"), 'search'); } @@ -2362,6 +2367,69 @@ class Form } } + // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps + + /** + * Return list of BOM for customer in Ajax if Ajax activated or go to select_produits_list + * + * @param int $selected Preselected BOM id + * @param string $htmlname Name of HTML select field (must be unique in page). + * @param int $limit Limit on number of returned lines + * @param int $status Sell status -1=Return all bom, 0=Draft BOM, 1=Validated BOM + * @param int $type type of the BOM (-1=Return all BOM, 0=Return disassemble BOM, 1=Return manufacturing BOM) + * @param string $showempty '' to not show empty line. Translation key to show an empty line. '1' show empty line with no text. + * @param string $morecss Add more css on select + * @param string $nooutput No print, return the output into a string + * @param int $forcecombo Force to use combo box + * @return void|string + */ + public function select_bom($selected = '', $htmlname = 'bom_id', $limit = 0, $status = 1, $type = 1, $showempty = '1', $morecss = '', $nooutput = '', $forcecombo = 0) + { + // phpcs:enable + global $conf, $user, $langs, $db; + + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + + $error = 0; + $out = ''; + + if (!$forcecombo) { + include_once DOL_DOCUMENT_ROOT.'/core/lib/ajax.lib.php'; + $out .= ajax_combobox($htmlname, $events, getDolGlobalInt("PRODUIT_USE_SEARCH_TO_SELECT")); + } + + $out .= ''; + $out.= ''; + $out.= ''; if ($user->admin && empty($noinfoadmin)) { - print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); + $out.= info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1); } - print ajax_combobox($htmlname); + $out.= ajax_combobox($htmlname); + return $out; } @@ -4092,7 +4184,7 @@ class Form // phpcs:enable global $langs; - $num = count($this->cache_transport_mode); + $num = count($this->cache_transport_mode); // TODO Use $conf->cache['payment_mode'] instead of $this->cache_transport_mode if ($num > 0) { return $num; // Cache already loaded } @@ -4102,7 +4194,7 @@ class Form $this->cache_transport_mode = array(); $sql = "SELECT rowid, code, label, active"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_transport_mode"; + $sql .= " FROM ".$this->db->prefix()."c_transport_mode"; $sql .= " WHERE entity IN (".getEntity('c_transport_mode').")"; $resql = $this->db->query($sql); @@ -4220,7 +4312,7 @@ class Form $langs->load("deliveries"); $sql = "SELECT rowid, code, libelle as label"; - $sql .= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; + $sql .= " FROM ".$this->db->prefix()."c_shipment_mode"; $sql .= " WHERE active > 0"; if ($filtre) { $sql .= " AND ".$filtre; @@ -4273,7 +4365,7 @@ class Form */ public function formSelectShippingMethod($page, $selected = '', $htmlname = 'shipping_method_id', $addempty = 0) { - global $langs, $db; + global $langs; $langs->load("deliveries"); @@ -4286,7 +4378,7 @@ class Form print ''; } else { if ($selected) { - $code = $langs->getLabelFromKey($db, $selected, 'c_shipment_mode', 'rowid', 'code'); + $code = $langs->getLabelFromKey($this->db, $selected, 'c_shipment_mode', 'rowid', 'code'); print $langs->trans("SendingMethod".strtoupper($code)); } else { print " "; @@ -4308,9 +4400,9 @@ class Form $langs->load('bills'); - $opt = ''; - $sql = 'SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc'; - $sql .= ' FROM '.MAIN_DB_PREFIX.'facture'; + $opt = ''; + $sql = "SELECT rowid, ref, situation_cycle_ref, situation_counter, situation_final, fk_soc"; + $sql .= ' FROM '.$this->db->prefix().'facture'; $sql .= ' WHERE entity IN ('.getEntity('invoice').')'; $sql .= ' AND situation_counter >= 1'; $sql .= ' AND fk_soc = '.(int) $socid; @@ -4365,7 +4457,7 @@ class Form $return = 'trans("FormatDateShortJavaInput").'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript + $retstring .= ' onChange="dpChangeDay(\''.dol_escape_js($prefix).'\',\''.dol_escape_js($langs->trans("FormatDateShortJavaInput")).'\'); "'; // FormatDateShortInput for dol_print_date / FormatDateShortJavaInput that is same for javascript $retstring .= '>'; // Icone calendrier @@ -6544,7 +6636,7 @@ class Form unset($TDurationTypes[$value]); } - $retstring = ''; foreach ($TDurationTypes as $key => $typeduration) { $retstring .= '\n"; - $optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtypem); + $optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtype); } @@ -7140,7 +7228,7 @@ class Form */ public function selectMembersList($selected = '', $htmlname = 'adherentid', $filtertype = '', $limit = 20, $filterkey = '', $status = 1, $outputmode = 0, $showempty = '1', $forcecombo = 0, $morecss = '') { - global $langs, $conf, $user, $db; + global $langs, $conf; $out = ''; $outarray = array(); @@ -7149,7 +7237,7 @@ class Form $sql = "SELECT "; $sql .= $selectFields; - $sql .= " FROM ".MAIN_DB_PREFIX."adherent as p"; + $sql .= " FROM ".$this->db->prefix()."adherent as p"; $sql .= ' WHERE p.entity IN ('.getEntity('adherent').')'; // Add criteria on ref/label @@ -7224,7 +7312,7 @@ class Form if (empty($outputmode)) return $out; return $outarray; } else { - dol_print_error($db); + dol_print_error($this->db); } } @@ -7241,8 +7329,6 @@ class Form */ protected function constructMemberListOption(&$objp, &$opt, &$optJson, $selected, $filterkey = '') { - global $langs, $conf, $user, $db; - $outkey = ''; $outval = ''; $outref = ''; @@ -7265,7 +7351,7 @@ class Form $outval .= $objRef; $opt .= "\n"; - $optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtypem); + $optJson = array('key'=>$outkey, 'value'=>$outref, 'type'=>$outtype); } /** @@ -7451,15 +7537,15 @@ class Form $num = 0; // Search data - $sql = "SELECT t.rowid, ".$fieldstoshow." FROM ".MAIN_DB_PREFIX.$objecttmp->table_element." as t"; + $sql = "SELECT t.rowid, ".$fieldstoshow." FROM ".$this->db->prefix().$objecttmp->table_element." as t"; if (isset($objecttmp->ismultientitymanaged)) { if (!is_numeric($objecttmp->ismultientitymanaged)) { $tmparray = explode('@', $objecttmp->ismultientitymanaged); - $sql .= " INNER JOIN ".MAIN_DB_PREFIX.$tmparray[1]." as parenttable ON parenttable.rowid = t.".$tmparray[0]; + $sql .= " INNER JOIN ".$this->db->prefix().$tmparray[1]." as parenttable ON parenttable.rowid = t.".$tmparray[0]; } if ($objecttmp->ismultientitymanaged === 'fk_soc@societe') { if (empty($user->rights->societe->client->voir) && !$user->socid) { - $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; + $sql .= ", ".$this->db->prefix()."societe_commerciaux as sc"; } } } @@ -7990,6 +8076,31 @@ class Form } } + // Try also magic suggest + $out .= ''."\n"; - if (is_array($array) && !empty($array)) { - if ($value_as_key) { - $array = array_combine($array, $array); - } - - if (!empty($array)) { - foreach ($array as $key => $value) { - $newval = ($translate ? $langs->trans($value) : $value); - $newval = ($key_in_label ? $key.' - '.$newval : $newval); - - $out .= '
'; + + print "
\n"; + } + + return $i; +} diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index 7b5cc92c75d..c70ea041e0a 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -2270,13 +2270,13 @@ function dol_most_recent_file($dir, $regexfilter = '', $excludefilter = array('( /** * Security check when accessing to a document (used by document.php, viewimage.php and webservices to get documents). - * TODO Replace code that set $accesallowed by a call to restrictedArea() + * TODO Replace code that set $accessallowed by a call to restrictedArea() * * @param string $modulepart Module of document ('module', 'module_user_temp', 'module_user' or 'module_temp'). Exemple: 'medias', 'invoice', 'logs', 'tax-vat', ... * @param string $original_file Relative path with filename, relative to modulepart. * @param string $entity Restrict onto entity (0=no restriction) * @param User $fuser User object (forced) - * @param string $refname Ref of object to check permission for external users (autodetect if not provided) + * @param string $refname Ref of object to check permission for external users (autodetect if not provided) or for hierarchy * @param string $mode Check permission for 'read' or 'write' * @return mixed Array with access information : 'accessallowed' & 'sqlprotectagainstexternals' & 'original_file' (as a full path name) * @see restrictedArea() @@ -2423,6 +2423,30 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $accessallowed = 1; } $original_file = $conf->fournisseur->facture->dir_output.'/'.$original_file; + } elseif (($modulepart == 'holiday') && !empty($conf->holiday->dir_output)) { + if ($fuser->rights->holiday->{$read} || preg_match('/^specimen/i', $original_file)) { + $accessallowed = 1; + // If we known $id of holiday, call checkUserAccessToObject to check permission on properties and hierarchy of leave request + if ($refname && !preg_match('/^specimen/i', $original_file)) { + include_once DOL_DOCUMENT_ROOT.'/holiday/class/holiday.class.php'; + $tmpholiday = new Holiday($db); + $tmpholiday->fetch('', $refname); + $accessallowed = checkUserAccessToObject($user, array('holiday'), $tmpholiday, 'holiday', '', '', 'rowid', ''); + } + } + $original_file = $conf->holiday->dir_output.'/'.$original_file; + } elseif (($modulepart == 'expensereport') && !empty($conf->expensereport->dir_output)) { + if ($fuser->rights->expensereport->{$lire} || preg_match('/^specimen/i', $original_file)) { + $accessallowed = 1; + // If we known $id of expensereport, call checkUserAccessToObject to check permission on properties and hierarchy of expense report + if ($refname && !preg_match('/^specimen/i', $original_file)) { + include_once DOL_DOCUMENT_ROOT.'/expensereport/class/expensereport.class.php'; + $tmpexpensereport = new ExpenseReport($db); + $tmpexpensereport->fetch('', $refname); + $accessallowed = checkUserAccessToObject($user, array('expensereport'), $tmpexpensereport, 'expensereport', '', '', 'rowid', ''); + } + } + $original_file = $conf->expensereport->dir_output.'/'.$original_file; } elseif (($modulepart == 'apercuexpensereport') && !empty($conf->expensereport->dir_output)) { // Wrapping pour les apercu supplier invoice if ($fuser->rights->expensereport->{$lire}) { @@ -2686,7 +2710,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, include_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php'; $tmptask = new Task($db); $tmptask->fetch('', $refname); - $accessallowed = checkUserAccessToObject($user, array('projet_task'), $tmptask->id, 'projet&project', '', '', 'rowid', ''); + $accessallowed = checkUserAccessToObject($user, array('projet_task'), $tmptask->id, 'projet_task&project', '', '', 'rowid', ''); } } $original_file = $conf->projet->dir_output.'/'.$original_file; @@ -2971,9 +2995,9 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, } $ret = array( - 'accessallowed' => $accessallowed, - 'sqlprotectagainstexternals'=>$sqlprotectagainstexternals, - 'original_file'=>$original_file + 'accessallowed' => ($accessallowed ? 1 : 0), + 'sqlprotectagainstexternals' => $sqlprotectagainstexternals, + 'original_file' => $original_file ); return $ret; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 94148722862..4439a38509b 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -17,6 +17,7 @@ * Copyright (C) 2019 Thibault Foucart * Copyright (C) 2020 Open-Dsi * Copyright (C) 2021 Gauthier VERDOL + * Copyright (C) 2022 Anthony Berton * * 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 @@ -641,7 +642,7 @@ function GETPOST($paramname, $check = 'alphanohtml', $method = 0, $filter = null } // Check rule - if (preg_match('/^array/', $check)) { // If 'array' or 'array:restricthtml' or 'array:aZ09' + if (preg_match('/^array/', $check)) { // If 'array' or 'array:restricthtml' or 'array:aZ09' or 'array:intcomma' if (!is_array($out) || empty($out)) { $out = array(); } else { @@ -782,7 +783,7 @@ function checkVal($out = '', $check = 'alphanohtml', $filter = null, $options = // keep lines feed } break; - case 'alphawithlgt': // No " and no ../ but we keep balanced < > tags with no special chars inside. Can be used for email string like "Name " + case 'alphawithlgt': // No " and no ../ but we keep balanced < > tags with no special chars inside. Can be used for email string like "Name ". Less secured than 'alphanohtml' if (!is_array($out)) { $out = trim($out); do { @@ -828,7 +829,10 @@ function checkVal($out = '', $check = 'alphanohtml', $filter = null, $options = // We replace chars from a/A to z/Z encoded with numeric HTML entities with the real char so we won't loose the chars at the next step (preg_replace). // No need to use a loop here, this step is not to sanitize (this is done at next step, this is to try to save chars, even if they are // using a non coventionnel way to be encoded, to not have them sanitized just after) - $out = preg_replace_callback('/&#(x?[0-9][0-9a-f]+;?)/i', 'realCharForNumericEntities', $out); + //$out = preg_replace_callback('/&#(x?[0-9][0-9a-f]+;?)/i', 'realCharForNumericEntities', $out); + $out = preg_replace_callback('/&#(x?[0-9][0-9a-f]+;?)/i', function ($m) { + return realCharForNumericEntities($m); }, $out); + // Now we remove all remaining HTML entities starting with a number. We don't want such entities. $out = preg_replace('/&#x?[0-9]+/i', '', $out); // For example if we have javascript with an entities without the ; to hide the 'a' of 'javascript'. @@ -838,7 +842,7 @@ function checkVal($out = '', $check = 'alphanohtml', $filter = null, $options = // We should also exclude non expected HTML attributes and clean content of some attributes. if (!empty($conf->global->MAIN_RESTRICTHTML_REMOVE_ALSO_BAD_ATTRIBUTES)) { // Warning, the function may add a LF so we are forced to trim to compare with old $out without having always a difference and an infinit loop. - $out = trim(dol_string_onlythesehtmlattributes($out)); + $out = dol_string_onlythesehtmlattributes($out); } // Restore entity ' into ' (restricthtml is for html content so we can use html entity) @@ -1169,23 +1173,34 @@ function dol_sanitizeUrl($stringtoclean, $type = 1) */ function dol_string_unaccent($str) { + global $conf; + if (utf8_check($str)) { + if (extension_loaded('intl') && !empty($conf->global->MAIN_UNACCENT_USE_TRANSLITERATOR)) { + $transliterator = \Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: NFC;', \Transliterator::FORWARD); + return $transliterator->transliterate($str); + } // See http://www.utf8-chartable.de/ $string = rawurlencode($str); $replacements = array( '%C3%80' => 'A', '%C3%81' => 'A', '%C3%82' => 'A', '%C3%83' => 'A', '%C3%84' => 'A', '%C3%85' => 'A', + '%C3%87' => 'C', '%C3%88' => 'E', '%C3%89' => 'E', '%C3%8A' => 'E', '%C3%8B' => 'E', '%C3%8C' => 'I', '%C3%8D' => 'I', '%C3%8E' => 'I', '%C3%8F' => 'I', + '%C3%91' => 'N', '%C3%92' => 'O', '%C3%93' => 'O', '%C3%94' => 'O', '%C3%95' => 'O', '%C3%96' => 'O', + '%C5%A0' => 'S', '%C3%99' => 'U', '%C3%9A' => 'U', '%C3%9B' => 'U', '%C3%9C' => 'U', + '%C3%9D' => 'Y', '%C5%B8' => 'y', '%C3%A0' => 'a', '%C3%A1' => 'a', '%C3%A2' => 'a', '%C3%A3' => 'a', '%C3%A4' => 'a', '%C3%A5' => 'a', '%C3%A7' => 'c', '%C3%A8' => 'e', '%C3%A9' => 'e', '%C3%AA' => 'e', '%C3%AB' => 'e', '%C3%AC' => 'i', '%C3%AD' => 'i', '%C3%AE' => 'i', '%C3%AF' => 'i', '%C3%B1' => 'n', '%C3%B2' => 'o', '%C3%B3' => 'o', '%C3%B4' => 'o', '%C3%B5' => 'o', '%C3%B6' => 'o', + '%C5%A1' => 's', '%C3%B9' => 'u', '%C3%BA' => 'u', '%C3%BB' => 'u', '%C3%BC' => 'u', - '%C3%BF' => 'y' + '%C3%BD' => 'y', '%C3%BF' => 'y' ); $string = strtr($string, $replacements); return rawurldecode($string); @@ -1217,8 +1232,8 @@ function dol_string_unaccent($str) * * @param string $str String to clean * @param string $newstr String to replace forbidden chars with - * @param array|string $badcharstoreplace List of forbidden characters to replace - * @param array|string $badcharstoremove List of forbidden characters to remove + * @param array|string $badcharstoreplace Array of forbidden characters to replace. Use '' to keep default list. + * @param array|string $badcharstoremove Array of forbidden characters to remove. Use '' to keep default list. * @return string Cleaned string * * @see dol_sanitizeFilename(), dol_string_unaccent(), dol_string_nounprintableascii() @@ -1530,6 +1545,7 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename = // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it). $data['ip'] = '???@'.$_SERVER['LOGNAME']; } + // Loop on each log handler and send output foreach ($conf->loghandlers as $loghandlerinstance) { if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) { @@ -1612,7 +1628,7 @@ function dol_fiche_head($links = array(), $active = '0', $title = '', $notab = 0 /** * Show tabs of a record * - * @param array $links Array of tabs + * @param array $links Array of tabs. Note that label into $links[$i][1] must be already HTML escaped. * @param string $active Active tab name * @param string $title Title * @param int $notab -1 or 0=Add tab header, 1=no tab header (if you set this to 1, using print dol_get_fiche_end() to close tab is not required), -2=Add tab header with no seaparation under tab (to start a tab just after) @@ -1650,7 +1666,11 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab $limittitle = 30; $out .= ''; if ($picto) { - $out .= img_picto($title, ($pictoisfullpath ? '' : 'object_').$picto, '', $pictoisfullpath, 0, 0, '', 'imgTabTitle').' '; + $noprefix = $pictoisfullpath; + if (strpos($picto, 'fontawesome_') !== false) { + $noprefix = 1; + } + $out .= img_picto($title, ($noprefix ? '' : 'object_').$picto, '', $pictoisfullpath, 0, 0, '', 'imgTabTitle').' '; } $out .= ''.dol_escape_htmltag(dol_trunc($title, $limittitle)).''; $out .= ''; @@ -1697,8 +1717,8 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab } if ($i < $limittoshow || $isactive) { - // Add a new entry - $out .= '
'; + // Output entry with a visible tab + $out .= '
'; if (isset($links[$i][2]) && $links[$i][2] == 'image') { if (!empty($links[$i][0])) { @@ -1710,7 +1730,8 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab //print "x $i $active ".$links[$i][2]." z"; $out .= '
'; if (!empty($links[$i][0])) { - $out .= ''; + $titletoshow = preg_replace('/<.*$/', '', $links[$i][1]); + $out .= ''; } $out .= $links[$i][1]; if (!empty($links[$i][0])) { @@ -1722,7 +1743,7 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab $out .= '
'; } else { - // The popup with the other tabs + // Add entry into the combo popup with the other tabs if (!$popuptab) { $popuptab = 1; $outmore .= '
'; // The css used to hide/show popup @@ -1759,7 +1780,7 @@ function dol_get_fiche_head($links = array(), $active = '', $title = '', $notab $tabsname = str_replace("@", "", $picto); } $out .= '
'; - $out .= ''.$langs->trans("More").'... ('.$nbintab.')'; // Do not use "reposition" class in the "More". + $out .= ''; // Do not use "reposition" class in the "More". $out .= '
'; $out .= $outmore; $out .= '
'; @@ -1882,7 +1903,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi if ($object->element == 'product') { $width = 80; - $cssclass = 'photoref'; + $cssclass = 'photowithmargin photoref'; $showimage = $object->is_photo_available($conf->product->multidir_output[$entity]); $maxvisiblephotos = (isset($conf->global->PRODUCT_MAX_VISIBLE_PHOTO) ? $conf->global->PRODUCT_MAX_VISIBLE_PHOTO : 5); if ($conf->browser->layout == 'phone') { @@ -1984,7 +2005,7 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi } } } elseif (!$phototoshow) { // example if modulepart = 'societe' or 'photo' - $phototoshow .= $form->showphoto($modulepart, $object, 0, 0, 0, 'photoref', 'small', 1, 0, $maxvisiblephotos); + $phototoshow .= $form->showphoto($modulepart, $object, 0, 0, 0, 'photowithmargin photoref', 'small', 1, 0, $maxvisiblephotos); } if ($phototoshow) { @@ -2004,10 +2025,14 @@ function dol_banner_tab($object, $paramid, $morehtml = '', $shownav = 1, $fieldi $width = 14; $cssclass = 'photorefcenter'; $picto = $object->picto; + $prefix = 'object_'; if ($object->element == 'project' && !$object->public) { $picto = 'project'; // instead of projectpub } - $nophoto = img_picto('No photo', 'object_'.$picto); + if (strpos($picto, 'fontawesome_') !== false) { + $prefix = ''; + } + $nophoto = img_picto('No photo', $prefix.$picto); } $morehtmlleft .= ''; $morehtmlleft .= '
'; @@ -2865,15 +2890,15 @@ function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetwor // Use dictionary definition for picto $dictsocialnetworks[$type]['icon'] $htmllink .= ''; if ($type == 'skype') { - $htmllink .= $value; + $htmllink .= dol_escape_htmltag($value); $htmllink .= ' '; $htmllink .= ''; + $htmllink .= dol_string_nospecial($value, '_', '', array('@')); + $htmllink .= '?call" alt="'.$langs->trans("Call").' '.$value.'" title="'.dol_escape_htmltag($langs->trans("Call").' '.$value).'">'; $htmllink .= ''; $htmllink .= ''; + $htmllink .= dol_string_nospecial($value, '_', '', array('@')); + $htmllink .= '?chat" alt="'.$langs->trans("Chat").' '.$value.'" title="'.dol_escape_htmltag($langs->trans("Chat").' '.$value).'">'; $htmllink .= ''; $htmllink .= ''; if (($cid || $socid) && !empty($conf->agenda->enabled) && $user->rights->agenda->myactions->create) { @@ -2887,9 +2912,9 @@ function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetwor } else { if (!empty($dictsocialnetworks[$type]['url'])) { $link = str_replace('{socialid}', $value, $dictsocialnetworks[$type]['url']); - $htmllink .= ' '.$value.''; + $htmllink .= ' '.dol_escape_htmltag($value).''; } else { - $htmllink .= $value; + $htmllink .= dol_escape_htmltag($value); } } $htmllink .= '
'; @@ -2900,6 +2925,38 @@ function dol_print_socialnetworks($value, $cid, $socid, $type, $dictsocialnetwor return $htmllink; } +/** + * Format profIDs according to country + * + * @param string $profID Value of profID to format + * @param string $profIDtype Type of profID to format ('1', '2', '3', '4', '5', '6' or 'VAT') + * @param string $countrycode Country code to use for formatting + * @param int $addcpButton Add button to copy to clipboard (1 => show only on hoover ; 2 => always display ) + * @param string $separ Separation between numbers for a better visibility example : xxx xxx xxx xxxxx + * @return string Formated profID + */ +function dol_print_profids($profID, $profIDtype, $countrycode = '', $addcpButton = 1, $separ = ' ') +{ + global $mysoc; + + if (empty($profID) || empty($profIDtype)) { + return ''; + } + if (empty($countrycode)) $countrycode = $mysoc->country_code; + $newProfID = $profID; + $id = substr($profIDtype, -1); + $ret = ''; + if (strtoupper($countrycode) == 'FR') { + // France + if ($id == 1 && dol_strlen($newProfID) == 9) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3); + if ($id == 2 && dol_strlen($newProfID) == 14) $newProfID = substr($newProfID, 0, 3).$separ.substr($newProfID, 3, 3).$separ.substr($newProfID, 6, 3).$separ.substr($newProfID, 9, 5); + if ($profIDtype === 'VAT' && dol_strlen($newProfID) == 13) $newProfID = substr($newProfID, 0, 4).$separ.substr($newProfID, 4, 3).$separ.substr($newProfID, 7, 3).$separ.substr($newProfID, 10, 3); + } + if (!empty($addcpButton)) $ret = showValueWithClipboardCPButton(dol_escape_htmltag($profID), ($addcpButton == 1 ? 1 : 0), $newProfID); + else $ret = $newProfID; + return $ret; +} + /** * Format phone numbers according to country * @@ -3592,6 +3649,7 @@ function dol_trunc($string, $size = 40, $trunc = 'right', $stringencoding = 'UTF * Example: picto.png if picto.png is stored into htdocs/theme/mytheme/img * Example: picto.png@mymodule if picto.png is stored into htdocs/mymodule/img * Example: /mydir/mysubdir/picto.png if picto.png is stored into htdocs/mydir/mysubdir (pictoisfullpath must be set to 1) + * Example: fontawesome_envelope-open-text_fas_red_1em if you want to use fontaweseome icons: fontawesome__